2022-02-03 14:05:24 -05:00
|
|
|
#include <std_include.hpp>
|
|
|
|
#include "game.hpp"
|
|
|
|
|
|
|
|
namespace game
|
|
|
|
{
|
2022-05-17 10:56:26 -04:00
|
|
|
uint64_t base_address;
|
|
|
|
|
|
|
|
void load_base_address()
|
|
|
|
{
|
|
|
|
const auto module = GetModuleHandle(NULL);
|
|
|
|
base_address = uint64_t(module);
|
|
|
|
}
|
|
|
|
|
2022-02-03 14:05:24 -05:00
|
|
|
int Cmd_Argc()
|
|
|
|
{
|
|
|
|
return cmd_args->argc[cmd_args->nesting];
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* Cmd_Argv(const int index)
|
|
|
|
{
|
|
|
|
return cmd_args->argv[cmd_args->nesting][index];
|
|
|
|
}
|
|
|
|
|
|
|
|
int SV_Cmd_Argc()
|
|
|
|
{
|
|
|
|
return sv_cmd_args->argc[sv_cmd_args->nesting];
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* SV_Cmd_Argv(const int index)
|
|
|
|
{
|
|
|
|
return sv_cmd_args->argv[sv_cmd_args->nesting][index];
|
|
|
|
}
|
|
|
|
|
2022-02-26 17:31:12 -05:00
|
|
|
bool VirtualLobby_Loaded()
|
|
|
|
{
|
|
|
|
return !game::environment::is_sp() && *mp::virtualLobby_loaded == 1;
|
|
|
|
}
|
|
|
|
|
2022-05-21 06:26:30 -04:00
|
|
|
void SV_GameSendServerCommand(int client_num, svscmd_type type, const char* text)
|
2022-05-18 09:39:04 -04:00
|
|
|
{
|
2022-06-01 19:30:51 -04:00
|
|
|
const auto svs_clients = *mp::svs_clients;
|
|
|
|
if (svs_clients == nullptr)
|
2022-05-21 06:26:30 -04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (client_num == -1)
|
2022-05-18 18:36:32 -04:00
|
|
|
{
|
2022-05-18 09:39:04 -04:00
|
|
|
SV_SendServerCommand(0, type, "%s", text);
|
2022-05-18 18:36:32 -04:00
|
|
|
}
|
2022-05-18 09:39:04 -04:00
|
|
|
else
|
2022-05-18 18:36:32 -04:00
|
|
|
{
|
2022-06-01 19:30:51 -04:00
|
|
|
SV_SendServerCommand(&svs_clients[client_num], type, "%s", text);
|
2022-05-18 18:36:32 -04:00
|
|
|
}
|
2022-05-18 09:39:04 -04:00
|
|
|
}
|
|
|
|
|
2022-05-25 17:56:10 -04:00
|
|
|
void Cbuf_AddText(int local_client_num, int controller_index, const char* cmd)
|
|
|
|
{
|
|
|
|
if (game::environment::is_sp())
|
|
|
|
{
|
|
|
|
sp::Cbuf_AddText(local_client_num, cmd);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mp::Cbuf_AddText(local_client_num, controller_index, cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-28 11:08:55 -04:00
|
|
|
void Cmd_TokenizeString(const char* text)
|
|
|
|
{
|
|
|
|
if (game::environment::is_sp())
|
|
|
|
{
|
|
|
|
sp::Cmd_TokenizeString(text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const auto a2 = 512 - *reinterpret_cast<int*>(0x3516F40_b);
|
|
|
|
mp::Cmd_TokenizeStringWithLimit(text, a2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cmd_EndTokenizeString()
|
|
|
|
{
|
|
|
|
if (game::environment::is_sp())
|
|
|
|
{
|
|
|
|
return sp::Cmd_EndTokenizeString();
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto nesting = cmd_args->nesting;
|
|
|
|
const auto argc = cmd_args->argc[nesting];
|
|
|
|
--cmd_args->nesting;
|
|
|
|
cmd_argsPrivate->totalUsedArgvPool -= argc;
|
|
|
|
cmd_argsPrivate->totalUsedTextPool -= cmd_argsPrivate->usedTextPool[nesting];
|
|
|
|
}
|
|
|
|
|
2022-02-03 14:05:24 -05:00
|
|
|
namespace environment
|
|
|
|
{
|
|
|
|
launcher::mode mode = launcher::mode::none;
|
|
|
|
|
|
|
|
launcher::mode translate_surrogate(const launcher::mode _mode)
|
|
|
|
{
|
|
|
|
switch (_mode)
|
|
|
|
{
|
|
|
|
case launcher::mode::survival:
|
|
|
|
case launcher::mode::zombies:
|
|
|
|
return launcher::mode::multiplayer;
|
|
|
|
default:
|
|
|
|
return _mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
launcher::mode get_real_mode()
|
|
|
|
{
|
|
|
|
if (mode == launcher::mode::none)
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Launcher mode not valid. Something must be wrong.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
launcher::mode get_mode()
|
|
|
|
{
|
|
|
|
return translate_surrogate(get_real_mode());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_sp()
|
|
|
|
{
|
|
|
|
return get_mode() == launcher::mode::singleplayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_mp()
|
|
|
|
{
|
|
|
|
return get_mode() == launcher::mode::multiplayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_dedi()
|
|
|
|
{
|
|
|
|
return get_mode() == launcher::mode::server;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_mode(const launcher::mode _mode)
|
|
|
|
{
|
|
|
|
mode = _mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string get_string()
|
|
|
|
{
|
|
|
|
const auto current_mode = get_real_mode();
|
|
|
|
switch (current_mode)
|
|
|
|
{
|
|
|
|
case launcher::mode::server:
|
|
|
|
return "Dedicated Server";
|
|
|
|
|
|
|
|
case launcher::mode::multiplayer:
|
|
|
|
return "Multiplayer";
|
|
|
|
|
|
|
|
case launcher::mode::singleplayer:
|
|
|
|
return "Singleplayer";
|
|
|
|
|
|
|
|
case launcher::mode::none:
|
|
|
|
return "None";
|
|
|
|
|
|
|
|
default:
|
|
|
|
return "Unknown (" + std::to_string(static_cast<int>(mode)) + ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-17 10:56:26 -04:00
|
|
|
|
|
|
|
uintptr_t operator"" _b(const uintptr_t ptr)
|
|
|
|
{
|
|
|
|
return game::base_address + ptr;
|
|
|
|
}
|