Merge branch 'develop' into default-constructor

This commit is contained in:
Edo 2022-03-20 11:25:17 +00:00 committed by GitHub
commit 722b673100
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 181 additions and 175 deletions

View File

@ -28,7 +28,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check out files
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
@ -116,4 +116,4 @@ jobs:
# run: rsync -avz ./data/ ${{ secrets.XLABS_MASTER_SSH_USER }}@${{ secrets.XLABS_MASTER_SSH_ADDRESS }}:${{ env.XLABS_MASTER_PATH }}/iw4x/data/
- name: Publish changes
run: ssh ${{ secrets.XLABS_MASTER_SSH_USER }}@${{ secrets.XLABS_MASTER_SSH_ADDRESS }} ${{ secrets.XLABS_MASTER_SSH_CHANGE_PUBLISH_COMMAND }}
run: ssh ${{ secrets.XLABS_MASTER_SSH_USER }}@${{ secrets.XLABS_MASTER_SSH_ADDRESS }} ${{ secrets.XLABS_MASTER_SSH_CHANGE_PUBLISH_COMMAND }}

2
deps/libtommath vendored

@ -1 +1 @@
Subproject commit 04e9d1e7a0493910b2eb5e757d623870692ada04
Subproject commit 66de86426e9cdb88526974c765108f01554af2b0

View File

@ -61,7 +61,7 @@ namespace Assets
glyph.pixelHeight = static_cast<char>(gh);
glyph.x0 = static_cast<char>(x0);
glyph.y0 = static_cast<char>(y0 + yOffset);
glyph.dx = static_cast<char>(roundf(scale * advance));
glyph.dx = static_cast<char>(std::roundf(scale * advance));
// Advance to next col
x = x + gw + 1;
@ -92,7 +92,7 @@ namespace Assets
}
}
void IFont_s::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone*)
void IFont_s::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
{
Components::FileSystem::File fontDefFile(Utils::String::VA("%s.json", name.data()));
Components::FileSystem::File fontFile(Utils::String::VA("%s.ttf", name.data()));
@ -105,11 +105,13 @@ namespace Assets
if (!errors.empty())
{
Components::Logger::Error("Font define %s is broken: %s.", name.data(), errors.data());
return;
}
if (!fontDef.is_object())
{
Components::Logger::Error("Font define %s is invaild.", name.data(), errors.data());
return;
}
int w = fontDef["textureWidth"].int_value();
@ -118,22 +120,28 @@ namespace Assets
int size = fontDef["size"].int_value();
int yOffset = fontDef["yOffset"].int_value();
uint8_t* pixels = Utils::Memory::AllocateArray<uint8_t>(w * h);
auto* pixels = builder->getAllocator()->allocateArray<uint8_t>(w * h);
// Setup assets
auto* texName = Utils::Memory::DuplicateString(Utils::String::VA("if_%s", name.data() + 6 /* skip "fonts/" */));
auto* fontName = Utils::Memory::DuplicateString(name.data());
auto* glowMaterialName = Utils::Memory::DuplicateString(Utils::String::VA("%s_glow", name.data()));
const auto* texName = builder->getAllocator()->duplicateString(Utils::String::VA("if_%s", name.data() + 6 /* skip "fonts/" */));
const auto* fontName = builder->getAllocator()->duplicateString(name.data());
const auto* glowMaterialName = builder->getAllocator()->duplicateString(Utils::String::VA("%s_glow", name.data()));
auto* image = builder->getAllocator()->allocate<Game::GfxImage>();
std::memcpy(image, Game::DB_FindXAssetHeader(Game::ASSET_TYPE_IMAGE, "gamefonts_pc").image, sizeof(Game::GfxImage));
auto* image = Utils::Memory::Duplicate(Game::DB_FindXAssetHeader(Game::ASSET_TYPE_IMAGE, "gamefonts_pc").image);
image->name = texName;
auto* material = Utils::Memory::Duplicate(Game::DB_FindXAssetHeader(Game::ASSET_TYPE_MATERIAL, "fonts/gamefonts_pc").material);
material->textureTable = Utils::Memory::Duplicate(material->textureTable);
auto* material = builder->getAllocator()->allocate<Game::Material>();
std::memcpy(material, Game::DB_FindXAssetHeader(Game::ASSET_TYPE_MATERIAL, "fonts/gamefonts_pc").material, sizeof(Game::Material));
material->textureTable = builder->getAllocator()->allocate<Game::MaterialTextureDef>();
material->textureTable->u.image = image;
material->info.name = fontName;
auto* glowMaterial = Utils::Memory::Duplicate(Game::DB_FindXAssetHeader(Game::ASSET_TYPE_MATERIAL, "fonts/gamefonts_pc_glow").material);
auto* glowMaterial = builder->getAllocator()->allocate<Game::Material>();
std::memcpy(glowMaterial, Game::DB_FindXAssetHeader(Game::ASSET_TYPE_MATERIAL, "fonts/gamefonts_pc_glow").material, sizeof(Game::Material));
glowMaterial->textureTable = material->textureTable;
glowMaterial->info.name = glowMaterialName;
@ -161,14 +169,14 @@ namespace Assets
charset.push_back(i);
}
auto* font = Utils::Memory::Allocate<Game::Font_s>();
auto* font = builder->getAllocator()->allocate<Game::Font_s>();
font->fontName = fontName;
font->pixelHeight = size;
font->material = material;
font->glowMaterial = glowMaterial;
font->glyphCount = charset.size();
font->glyphs = Utils::Memory::AllocateArray<Game::Glyph>(charset.size());
font->glyphs = builder->getAllocator()->allocateArray<Game::Glyph>(charset.size());
// Generate glyph data
int result = PackFonts(reinterpret_cast<const uint8_t*>(fontFile.getBuffer().data()), charset, font->glyphs, static_cast<float>(size), pixels, w, h, yOffset);
@ -239,7 +247,6 @@ namespace Assets
}
Utils::IO::WriteFile(Utils::String::VA("userraw\\images\\%s.iwi", texName), outIwi);
Utils::Memory::Free(pixels);
}
}

View File

@ -83,7 +83,7 @@ namespace Components
Command::ServerParams params;
if (params.length() < 3)
if (params.size() < 3)
{
Game::SV_Cmd_EndTokenizedString();
Logger::SoftError("Connecting failed: Command parsing error!");
@ -170,7 +170,7 @@ namespace Components
Command::ServerParams params;
// Ensure there are enough params
if (params.length() < 3)
if (params.size() < 3)
{
Network::Send(address, "error\nInvalid connect string!");
return;
@ -455,7 +455,7 @@ namespace Components
{
Command::Add("securityLevel", [](Command::Params* params)
{
if (params->length() < 2)
if (params->size() < 2)
{
uint32_t level = Auth::GetZeroBits(Auth::GuidToken, Auth::GuidKey.getPublicKey());
Logger::Print("Your current security level is %d\n", level);

View File

@ -234,17 +234,17 @@ namespace Components
{
Command::Add("banclient", [](Command::Params* params)
{
if (params->length() < 2) return;
if (params->size() < 2) return;
std::string reason = "EXE_ERR_BANNED_PERM";
if (params->length() >= 3) reason = params->join(2);
if (params->size() >= 3) reason = params->join(2);
Bans::BanClientNum(atoi(params->get(1)), reason);
});
Command::Add("unbanclient", [](Command::Params* params)
{
if (params->length() < 2) return;
if (params->size() < 2) return;
std::string type = params->get(1);

View File

@ -447,7 +447,7 @@ namespace Components
{
unsigned int count = 1;
if (params->length() > 1)
if (params->size() > 1)
{
if (params->get(1) == "all"s) count = static_cast<unsigned int>(-1);
else count = atoi(params->get(1));

View File

@ -199,7 +199,7 @@ namespace Components
{
if (params->get(1) == "customTitles"s && !Dedicated::IsEnabled())
{
if (params->length() == 3)
if (params->size() == 3)
{
CardTitles::ParseCustomTitles(params->get(2));
return true;

View File

@ -263,7 +263,7 @@ namespace Components
}
const auto* cmd = params->get(0);
if (params->length() < 2)
if (params->size() < 2)
{
Logger::Print("Usage: %s <client number> : prevent the player from using the chat\n", cmd);
return;
@ -285,7 +285,7 @@ namespace Components
}
const auto* cmd = params->get(0);
if (params->length() < 2)
if (params->size() < 2)
{
Logger::Print("Usage: %s <client number or guid>\n%s all = unmute everyone\n", cmd, cmd);
return;
@ -299,7 +299,7 @@ namespace Components
return;
}
if (params->get(1) == "all"s)
if (std::strcmp(params->get(1), "all") == 0)
{
Logger::Print("All players were unmuted\n");
Chat::UnmuteInternal(0, true);

View File

@ -83,7 +83,7 @@ namespace Components
{
if (params->get(1) == "clantags"s && !Dedicated::IsEnabled())
{
if (params->length() == 3)
if (params->size() == 3)
{
ClanTags::ParseClantags(params->get(2));
return true;

View File

@ -147,7 +147,7 @@ namespace Components
Command::ServerParams params = {};
Game::vec3_t origin, angles{0.f, 0.f, 0.f};
if (params.length() < 4u || params.length() > 6u)
if (params.size() < 4 || params.size() > 6)
{
Game::SV_GameSendServerCommand(ent->s.number, 0,
Utils::String::VA("%c \"GAME_USAGE\x15: setviewpos x y z [yaw] [pitch]\n\"", 0x65));
@ -159,12 +159,12 @@ namespace Components
origin[i] = std::strtof(params.get(i + 1), nullptr);
}
if (params.length() >= 5u)
if (params.size() >= 5)
{
angles[1] = std::strtof(params.get(4), nullptr); // Yaw
}
if (params.length() == 6u)
if (params.size() == 6)
{
angles[0] = std::strtof(params.get(5), nullptr); // Pitch
}

View File

@ -5,56 +5,71 @@ namespace Components
std::unordered_map<std::string, Utils::Slot<Command::Callback>> Command::FunctionMap;
std::unordered_map<std::string, Utils::Slot<Command::Callback>> Command::FunctionMapSV;
std::string Command::Params::join(size_t startIndex)
std::string Command::Params::join(const int index)
{
std::string result;
for (size_t i = startIndex; i < this->length(); ++i)
for (auto i = index; i < this->size(); i++)
{
if (i > startIndex) result.append(" ");
result.append(this->operator[](i));
if (i > index) result.append(" ");
result.append(this->get(i));
}
return result;
}
const char* Command::Params::operator[](size_t index)
Command::ClientParams::ClientParams()
: nesting_(Game::cmd_args->nesting)
{
return this->get(index);
assert(Game::cmd_args->nesting < Game::CMD_MAX_NESTING);
}
const char* Command::ClientParams::get(size_t index)
int Command::ClientParams::size()
{
if (index >= this->length()) return "";
return Game::cmd_argv[this->commandId][index];
return Game::cmd_args->argc[this->nesting_];
}
size_t Command::ClientParams::length()
const char* Command::ClientParams::get(const int index)
{
return Game::cmd_argc[this->commandId];
if (index >= this->size())
{
return "";
}
return Game::cmd_args->argv[this->nesting_][index];
}
const char* Command::ServerParams::get(size_t index)
Command::ServerParams::ServerParams()
: nesting_(Game::sv_cmd_args->nesting)
{
if (index >= this->length()) return "";
return Game::cmd_argv_sv[this->commandId][index];
assert(Game::sv_cmd_args->nesting < Game::CMD_MAX_NESTING);
}
size_t Command::ServerParams::length()
int Command::ServerParams::size()
{
return Game::cmd_argc_sv[this->commandId];
return Game::sv_cmd_args->argc[this->nesting_];
}
const char* Command::ServerParams::get(const int index)
{
if (index >= this->size())
{
return "";
}
return Game::sv_cmd_args->argv[this->nesting_][index];
}
void Command::Add(const char* name, Utils::Slot<Command::Callback> callback)
{
std::string command = Utils::String::ToLower(name);
const auto command = Utils::String::ToLower(name);
if (Command::FunctionMap.find(command) == Command::FunctionMap.end())
{
Command::AddRaw(name, Command::MainCallback);
}
Command::FunctionMap[command] = callback;
Command::FunctionMap[command] = std::move(callback);
}
void Command::AddSV(const char* name, Utils::Slot<Command::Callback> callback)
@ -70,7 +85,7 @@ namespace Components
return;
}
std::string command = Utils::String::ToLower(name);
const auto command = Utils::String::ToLower(name);
if (Command::FunctionMapSV.find(command) == Command::FunctionMapSV.end())
{
@ -80,7 +95,7 @@ namespace Components
Command::AddRaw(name, Game::Cbuf_AddServerText);
}
Command::FunctionMapSV[command] = callback;
FunctionMapSV[command] = std::move(callback);
}
void Command::AddRaw(const char* name, void(*callback)(), bool key)
@ -134,25 +149,27 @@ namespace Components
void Command::MainCallback()
{
Command::ClientParams params(*Game::cmd_id);
Command::ClientParams params;
std::string command = Utils::String::ToLower(params[0]);
const auto command = Utils::String::ToLower(params[0]);
const auto got = Command::FunctionMap.find(command);
if (Command::FunctionMap.find(command) != Command::FunctionMap.end())
if (got != Command::FunctionMap.end())
{
Command::FunctionMap[command](&params);
got->second(&params);
}
}
void Command::MainCallbackSV()
{
Command::ServerParams params(*Game::cmd_id_sv);
Command::ServerParams params;
std::string command = Utils::String::ToLower(params[0]);
const auto command = Utils::String::ToLower(params[0]);
const auto got = Command::FunctionMapSV.find(command);
if (Command::FunctionMapSV.find(command) != Command::FunctionMapSV.end())
if (got != Command::FunctionMapSV.end())
{
Command::FunctionMapSV[command](&params);
got->second(&params);
}
}
@ -162,7 +179,7 @@ namespace Components
Command::Add("openLink", [](Command::Params* params)
{
if (params->length() > 1)
if (params->size() > 1)
{
Utils::OpenUrl(params->get(1));
}

View File

@ -9,41 +9,39 @@ namespace Components
{
public:
Params() {};
virtual ~Params() {};
virtual const char* get(size_t index) = 0;
virtual size_t length() = 0;
virtual int size() = 0;
virtual const char* get(int index) = 0;
virtual std::string join(int index);
virtual std::string join(size_t startIndex);
virtual const char* operator[](size_t index);
virtual const char* operator[](const int index)
{
return this->get(index);
}
};
class ClientParams : public Params
{
public:
ClientParams(unsigned int id) : commandId(id) {};
ClientParams(const ClientParams &obj) : commandId(obj.commandId) {};
ClientParams() : ClientParams(*Game::cmd_id) {};
ClientParams();
const char* get(size_t index) override;
size_t length() override;
int size() override;
const char* get(int index) override;
private:
unsigned int commandId;
int nesting_;
};
class ServerParams : public Params
{
public:
ServerParams(unsigned int id) : commandId(id) {};
ServerParams(const ServerParams &obj) : commandId(obj.commandId) {};
ServerParams() : ServerParams(*Game::cmd_id_sv) {};
ServerParams();
const char* get(size_t index) override;
size_t length() override;
int size() override;
const char* get(int index) override;
private:
unsigned int commandId;
int nesting_;
};
typedef void(Callback)(Command::Params* params);

View File

@ -398,7 +398,7 @@ namespace Components
// Say command
Command::AddSV("say", [](Command::Params* params)
{
if (params->length() < 2) return;
if (params->size() < 2) return;
std::string message = params->join(1);
std::string name = Dvar::Var("sv_sayName").get<std::string>();
@ -418,7 +418,7 @@ namespace Components
// Tell command
Command::AddSV("tell", [](Command::Params* params)
{
if (params->length() < 3) return;
if (params->size() < 3) return;
int client = atoi(params->get(1));
std::string message = params->join(2);
@ -439,7 +439,7 @@ namespace Components
// Sayraw command
Command::AddSV("sayraw", [](Command::Params* params)
{
if (params->length() < 2) return;
if (params->size() < 2) return;
std::string message = params->join(1);
Game::SV_GameSendServerCommand(-1, 0, Utils::String::VA("%c \"%s\"", 104, message.data()));
@ -449,33 +449,13 @@ namespace Components
// Tellraw command
Command::AddSV("tellraw", [](Command::Params* params)
{
if (params->length() < 3) return;
if (params->size() < 3) return;
int client = atoi(params->get(1));
std::string message = params->join(2);
Game::SV_GameSendServerCommand(client, 0, Utils::String::VA("%c \"%s\"", 104, message.data()));
Game::Com_Printf(15, "Raw -> %i: %s\n", client, message.data());
});
// ! command
Command::AddSV("!", [](Command::Params* params)
{
if (params->length() != 2) return;
int client = -1;
if (params->get(1) != "all"s)
{
client = atoi(params->get(1));
if (client >= *reinterpret_cast<int*>(0x31D938C))
{
Game::Com_Printf(0, "Invalid player.\n");
return;
}
}
Game::SV_GameSendServerCommand(client, 0, Utils::String::VA("%c \"\"", 106));
});
});
}
}

View File

@ -181,22 +181,22 @@ namespace Components
}
}
template<> static Dvar::Var Dvar::Register(const char* name, bool value, Dvar::Flag flag, const char* description)
template<> Dvar::Var Dvar::Register(const char* name, bool value, Dvar::Flag flag, const char* description)
{
return Game::Dvar_RegisterBool(name, value, flag.val, description);
}
template<> static Dvar::Var Dvar::Register(const char* name, const char* value, Dvar::Flag flag, const char* description)
template<> Dvar::Var Dvar::Register(const char* name, const char* value, Dvar::Flag flag, const char* description)
{
return Game::Dvar_RegisterString(name, value, flag.val, description);
}
template<> static Dvar::Var Dvar::Register(const char* name, int value, int min, int max, Dvar::Flag flag, const char* description)
template<> Dvar::Var Dvar::Register(const char* name, int value, int min, int max, Dvar::Flag flag, const char* description)
{
return Game::Dvar_RegisterInt(name, value, min, max, flag.val, description);
}
template<> static Dvar::Var Dvar::Register(const char* name, float value, float min, float max, Dvar::Flag flag, const char* description)
template<> Dvar::Var Dvar::Register(const char* name, float value, float min, float max, Dvar::Flag flag, const char* description)
{
return Game::Dvar_RegisterFloat(name, value, min, max, flag.val, description);
}
@ -336,10 +336,10 @@ namespace Components
// remove write protection from fs_game
Utils::Hook::Xor<DWORD>(0x6431EA, Game::dvar_flag::DVAR_FLAG_WRITEPROTECTED);
// set cg_fov max to 90.0
// ...120 because of V2
static float cgFov90 = 120.0f;
Utils::Hook::Set<float*>(0x4F8E28, &cgFov90);
// set cg_fov max to 160.0
// because that's the max on SP
static float cg_Fov = 160.0f;
Utils::Hook::Set<float*>(0x4F8E28, &cg_Fov);
// set max volume to 1
static float volume = 1.0f;
@ -385,7 +385,6 @@ namespace Components
Utils::Hook(0x59386A, Dvar::DvarSetFromStringByNameStub, HOOK_CALL).install()->quick();
// If the game closed abruptly, the dvars would not have been restored
Dvar::OnInit([]
{
Dvar::ResetDvarsValue();

View File

@ -234,7 +234,7 @@ namespace Components
Game::UI_UpdateArenas();
std::string command;
for (auto i = 0; i < (params->length() >= 2 ? atoi(params->get(1)) : *Game::arenaCount); ++i)
for (auto i = 0; i < (params->size() >= 2 ? atoi(params->get(1)) : *Game::arenaCount); ++i)
{
const auto* mapname = ArenaLength::NewArenas[i % *Game::arenaCount].mapName;

View File

@ -594,7 +594,7 @@ namespace Components
Command::Add("loadzone", [](Command::Params* params)
{
if (params->length() < 2) return;
if (params->size() < 2) return;
Game::XZoneInfo info;
info.name = params->get(1);

View File

@ -583,7 +583,7 @@ namespace Components
Command::Add("addFriend", [](Command::Params* params)
{
if (params->length() < 2u)
if (params->size() < 2u)
{
Logger::Print("Usage: %s <Steam ID in hexadecimal format>\n", params->get(0));
return;

View File

@ -1641,7 +1641,7 @@ namespace Components
void Gamepad::Axis_Bind_f(Command::Params* params)
{
if (params->length() < 4)
if (params->size() < 4)
{
Logger::Print("bindaxis <real axis> <virtual axis> <input type>\n");
return;

View File

@ -261,7 +261,7 @@ namespace Components
{
Command::AddSV("log_add", [](Command::Params* params)
{
if (params->length() < 2) return;
if (params->size() < 2) return;
Network::Address addr(params->get(1));
@ -273,7 +273,7 @@ namespace Components
Command::AddSV("log_del", [](Command::Params* params)
{
if (params->length() < 2) return;
if (params->size() < 2) return;
int num = atoi(params->get(1));
if (Utils::String::VA("%i", num) == std::string(params->get(1)) && static_cast<unsigned int>(num) < Logger::LoggingAddresses[0].size())
@ -312,7 +312,7 @@ namespace Components
Command::AddSV("g_log_add", [](Command::Params* params)
{
if (params->length() < 2) return;
if (params->size() < 2) return;
Network::Address addr(params->get(1));
@ -324,7 +324,7 @@ namespace Components
Command::AddSV("g_log_del", [](Command::Params* params)
{
if (params->length() < 2) return;
if (params->size() < 2) return;
int num = atoi(params->get(1));
if (Utils::String::VA("%i", num) == std::string(params->get(1)) && static_cast<unsigned int>(num) < Logger::LoggingAddresses[1].size())

View File

@ -845,7 +845,7 @@ namespace Components
Command::Add("openmenu", [](Command::Params* params)
{
if (params->length() != 2)
if (params->size() != 2)
{
Logger::Print("USAGE: openmenu <menu name>\n");
return;

View File

@ -377,7 +377,7 @@ namespace Components
Command::Add("addnode", [](Command::Params* params)
{
if (params->length() < 2) return;
if (params->size() < 2) return;
Node::Add({ params->get(1) });
});
}

View File

@ -261,7 +261,7 @@ namespace Components
Command::Add("connect", [](Command::Params* params)
{
if (params->length() < 2)
if (params->size() < 2)
{
return;
}

View File

@ -86,17 +86,15 @@ namespace Components
void QuickPatch::SelectStringTableEntryInDvarStub()
{
Command::ClientParams args;
Command::ClientParams params;
if (args.length() >= 4)
if (params.size() >= 4)
{
std::string cmd = args[0];
std::string table = args[1];
std::string col = args[2];
std::string dvarName = args[3];
Game::dvar_t* dvar = Game::Dvar_FindVar(dvarName.data());
const auto* dvarName = params[3];
const auto* dvar = Game::Dvar_FindVar(dvarName);
if (Command::Find(dvarName) || (dvar && (dvar->flags & (Game::DVAR_FLAG_WRITEPROTECTED | Game::DVAR_FLAG_CHEAT | Game::DVAR_FLAG_READONLY))))
if (Command::Find(dvarName) ||
(dvar != nullptr && dvar->flags & (Game::DVAR_FLAG_WRITEPROTECTED | Game::DVAR_FLAG_CHEAT | Game::DVAR_FLAG_READONLY)))
{
return;
}
@ -671,7 +669,7 @@ namespace Components
Command::Add("dumptechsets", [](Command::Params* param)
{
if (param->length() != 2)
if (param->size() != 2)
{
Logger::Print("usage: dumptechsets <fastfile> | all\n");
return;

View File

@ -7,19 +7,22 @@ namespace Components
std::string RCon::Password;
Dvar::Var RCon::RconPassword;
Dvar::Var RCon::RconLogRequests;
RCon::RCon()
{
Command::Add("rcon", [](Command::Params* params)
{
if (params->length() < 2) return;
if (params->size() < 2) return;
std::string operation = params->get(1);
if (operation == "login")
const auto* operation = params->get(1);
if (std::strcmp(operation, "login") == 0)
{
if (params->length() < 3) return;
if (params->size() < 3) return;
RCon::Password = params->get(2);
}
else if (operation == "logout")
else if (std::strcmp(operation, "logout") == 0)
{
RCon::Password.clear();
}
@ -75,8 +78,8 @@ namespace Components
Dvar::OnInit([]()
{
Dvar::Register<const char*>("rcon_password", "", Game::dvar_flag::DVAR_FLAG_NONE, "The password for rcon");
Dvar::Register<bool>("log_rcon_requests", false, Game::dvar_flag::DVAR_FLAG_NONE, "Print remote commands in the output log");
RCon::RconPassword = Dvar::Register<const char*>("rcon_password", "", Game::dvar_flag::DVAR_FLAG_NONE, "The password for rcon");
RCon::RconLogRequests = Dvar::Register<bool>("rcon_log_requests", false, Game::dvar_flag::DVAR_FLAG_NONE, "Print remote commands in the output log");
});
Network::Handle("rcon", [](Network::Address address, const std::string& _data)
@ -100,7 +103,7 @@ namespace Components
password.erase(password.begin());
}
std::string svPassword = Dvar::Var("rcon_password").get<std::string>();
const std::string svPassword = RCon::RconPassword.get<std::string>();
if (svPassword.empty())
{
@ -114,7 +117,7 @@ namespace Components
outputBuffer.clear();
#ifndef DEBUG
if (Dvar::Var("log_rcon_requests").get<bool>())
if (RCon::RconLogRequests.get<bool>())
#endif
{
Logger::Print("Executing RCon request from %s: %s\n", address.getCString(), command.data());

View File

@ -24,5 +24,8 @@ namespace Components
// For sr0's fucking rcon command
// Son of a bitch! Annoying me day and night with that shit...
static std::string Password;
static Dvar::Var RconPassword;
static Dvar::Var RconLogRequests;
};
}

View File

@ -24,7 +24,7 @@ namespace Components
Command::Add("dumpraw", [](Command::Params* params)
{
if (params->length() < 2)
if (params->size() < 2)
{
Logger::Print("Specify a filename!\n");
return;

View File

@ -11,11 +11,11 @@ namespace Components
bool ServerCommands::OnServerCommand()
{
Command::ClientParams params(*Game::cmd_id);
Command::ClientParams params;
for (auto &serverCommandCB : ServerCommands::Commands)
for (const auto& serverCommandCB : ServerCommands::Commands)
{
if (params.length() >= 1)
if (params.size() >= 1)
{
if (params.get(0)[0] == serverCommandCB.first)
{

View File

@ -91,4 +91,4 @@ namespace Components
Utils::Hook(0x4A54ED, SlowMotion::DrawConnectionInterruptedStub, HOOK_CALL).install()->quick();
Utils::Hook(0x4A54FB, SlowMotion::DrawConnectionInterruptedStub, HOOK_CALL).install()->quick();
}
}
}

View File

@ -37,7 +37,10 @@ namespace Components
int Weapon::ParseWeaponConfigStrings()
{
Command::ClientParams params;
if (params.length() <= 1) return 0;
if (params.size() <= 1)
return 0;
int index = atoi(params[1]);
if (index >= 4139)

View File

@ -1110,7 +1110,7 @@ namespace Components
Command::Add("verifyzone", [](Command::Params* params)
{
if (params->length() < 2) return;
if (params->size() < 2) return;
/*
Utils::Hook(0x4AE9C2, [] {
Game::WeaponCompleteDef** varPtr = (Game::WeaponCompleteDef**)0x112A9F4;
@ -1165,7 +1165,7 @@ namespace Components
Command::Add("buildzone", [](Command::Params* params)
{
if (params->length() < 2) return;
if (params->size() < 2) return;
std::string zoneName = params->get(1);
Logger::Print("Building zone '%s'...\n", zoneName.data());
@ -1455,7 +1455,7 @@ namespace Components
Command::Add("listassets", [](Command::Params* params)
{
if (params->length() < 2) return;
if (params->size() < 2) return;
Game::XAssetType type = Game::DB_GetXAssetNameType(params->get(1));
if (type != Game::XAssetType::ASSET_TYPE_INVALID)
@ -1470,7 +1470,7 @@ namespace Components
Command::Add("loadtempzone", [](Command::Params* params)
{
if (params->length() < 2) return;
if (params->size() < 2) return;
if (FastFiles::Exists(params->get(1)))
{
@ -1502,7 +1502,7 @@ namespace Components
Command::Add("iwiDump", [](Command::Params* params)
{
if (params->length() < 2) return;
if (params->size() < 2) return;
std::string path = Utils::String::VA("%s\\mods\\%s\\images", Dvar::Var("fs_basepath").get<const char*>(), params->get(1));
std::vector<std::string> images = FileSystem::GetSysFileList(path, "iwi", false);

View File

@ -393,13 +393,8 @@ namespace Game
XAssetHeader* DB_XAssetPool = reinterpret_cast<XAssetHeader*>(0x7998A8);
unsigned int* g_poolSize = reinterpret_cast<unsigned int*>(0x7995E8);
DWORD* cmd_id = reinterpret_cast<DWORD*>(0x1AAC5D0);
DWORD* cmd_argc = reinterpret_cast<DWORD*>(0x1AAC614);
char*** cmd_argv = reinterpret_cast<char***>(0x1AAC634);
DWORD* cmd_id_sv = reinterpret_cast<DWORD*>(0x1ACF8A0);
DWORD* cmd_argc_sv = reinterpret_cast<DWORD*>(0x1ACF8E4);
char*** cmd_argv_sv = reinterpret_cast<char***>(0x1ACF904);
CmdArgs* cmd_args = reinterpret_cast<CmdArgs*>(0x1AAC5D0);
CmdArgs* sv_cmd_args = reinterpret_cast<CmdArgs*>(0x1ACF8A0);
cmd_function_t** cmd_functions = reinterpret_cast<cmd_function_t**>(0x1AAC658);

View File

@ -930,13 +930,9 @@ namespace Game
extern XAssetHeader* DB_XAssetPool;
extern unsigned int* g_poolSize;
extern DWORD* cmd_id;
extern DWORD* cmd_argc;
extern char*** cmd_argv;
extern DWORD* cmd_id_sv;
extern DWORD* cmd_argc_sv;
extern char*** cmd_argv_sv;
constexpr auto CMD_MAX_NESTING = 8;
extern CmdArgs* cmd_args;
extern CmdArgs* sv_cmd_args;
extern cmd_function_t** cmd_functions;

View File

@ -170,8 +170,8 @@ namespace Game
typedef enum
{
CS_FREE = 0x0,
CS_UNKNOWN1 = 0x1,
CS_UNKNOWN2 = 0x2,
CS_ZOMBIE = 0x1,
CS_RECONNECTING = 0x2,
CS_CONNECTED = 0x3,
CS_CLIENTLOADING = 0x4,
CS_ACTIVE = 0x5,
@ -244,6 +244,17 @@ namespace Game
struct MenuEventHandlerSet;
struct menuDef_t;
struct CmdArgs
{
int nesting;
int localClientNum[8];
int controllerIndex[8];
int argc[8];
const char** argv[8];
};
static_assert(sizeof(CmdArgs) == 132);
typedef struct cmd_function_s
{
cmd_function_s *next;

View File

@ -54,14 +54,7 @@
#include <Xinput.h>
#pragma comment (lib, "xinput.lib")
// Usefull for debugging
template <size_t S> class Sizer { };
#define BindNum(x, y) Sizer<x> y;
#define Size_Of(x, y) BindNum(sizeof(x), y)
#define Offset_Of(x, y, z) BindNum(offsetof(x, y), z)
// Submodules
// Ignore the warnings, it's not our code!
// Ignore the warnings
#pragma warning(push)
#pragma warning(disable: 4005)
#pragma warning(disable: 4091)
@ -79,6 +72,7 @@ template <size_t S> class Sizer { };
#pragma warning(disable: 6258)
#pragma warning(disable: 6386)
#pragma warning(disable: 6387)
#pragma warning(disable: 26812)
#include <zlib.h>

View File

@ -81,10 +81,12 @@ namespace Utils
this->pool.push_back(data);
return data;
}
template <typename T> inline T* allocate()
{
return this->allocateArray<T>(1);
}
template <typename T> inline T* allocateArray(size_t count = 1)
{
return static_cast<T*>(this->allocate(count * sizeof(T)));