From 9f0dc1139d92e2fdfd4fed485f10277b431c114f Mon Sep 17 00:00:00 2001 From: RektInator Date: Tue, 30 May 2017 13:45:19 +0200 Subject: [PATCH 01/20] [CardTitles] Initial commit Refactored most from V2's codebase already. TableLookupByRowHookStub needs additional refactoring. --- src/Components/Loader.cpp | 1 + src/Components/Loader.hpp | 1 + src/Components/Modules/CardTitles.cpp | 188 ++++++++++++++++++++++++++ src/Components/Modules/CardTitles.hpp | 76 +++++++++++ 4 files changed, 266 insertions(+) create mode 100644 src/Components/Modules/CardTitles.cpp create mode 100644 src/Components/Modules/CardTitles.hpp diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index 131a6182..7c98a367 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -81,6 +81,7 @@ namespace Components Loader::Register(new Gametypes()); Loader::Register(new Materials()); Loader::Register(new Threading()); + Loader::Register(new CardTitles()); Loader::Register(new FileSystem()); Loader::Register(new ModelSurfs()); Loader::Register(new PlayerName()); diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index d41085d2..d09d22f1 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -91,6 +91,7 @@ namespace Components #include "Modules/Materials.hpp" #include "Modules/Singleton.hpp" #include "Modules/Threading.hpp" +#include "Modules/CardTitles.hpp" #include "Modules/FileSystem.hpp" #include "Modules/ModelSurfs.hpp" #include "Modules/PlayerName.hpp" diff --git a/src/Components/Modules/CardTitles.cpp b/src/Components/Modules/CardTitles.cpp new file mode 100644 index 00000000..36ce2f96 --- /dev/null +++ b/src/Components/Modules/CardTitles.cpp @@ -0,0 +1,188 @@ +#include "STDInclude.hpp" + +namespace Components +{ + std::vector < std::string > CardTitles::CustomTitles; + Game::dvar_t* CardTitles::CustomTitleDvar; + + CClient* CardTitles::GetClientByIndex(std::uint32_t index) + { + return reinterpret_cast(0x8E77B0 + (sizeof CClient * index)); + } + + std::int32_t CardTitles::GetPlayerCardClientInfo(std::int32_t lookupResult, playercarddata_s* data) + { + std::int32_t returnResult = lookupResult; + + CClient* c; + std::string username = Dvar::Var("name").get(); + + if (data->name == username) + { + returnResult += 0xFE000000; + } + else + { + for (auto clientNum = 0; clientNum < 18; clientNum++) + { + c = GetClientByIndex(clientNum); + + if (c != nullptr) + { + if (!strcmp(data->name, c->Name)) + { + // Since a 4 byte integer is overkill for a row num: We can use it to store the customprefix + clientNum and use a 2 byte integer for the row number + returnResult += 0xFF000000; + returnResult += clientNum * 0x10000; + break; + } + } + } + } + + return returnResult; + } + void __declspec(naked) CardTitles::GetPlayerCardClientInfoStub() + { + __asm + { + push esi; + push eax; + call GetPlayerCardClientInfo; + add esp, 0x08; + + pop esi; + pop ebp; + mov[ebx + 0x4], eax; + pop ebx; + + push 0x62EB2C; + retn; + } + } + + void __declspec(naked) CardTitles::LocalizationSkipHookStub() + { + __asm + { + cmp byte ptr[edi + 0x01], 0xFF; // Check if skip prefix exists (edi + 0x00 = @) + jne back; + add edi, 0x02; // Ignore the 0x40 and 0xFF prefix (Localize and Skip prefix) + jmp jumpback; + + back: + add edi, 0x01; + push edi; + + mov eax, 0x4F1700; + call eax; + + add esp, 0x04; + mov edi, eax; + + jumpback: + push 0x63A2E3; + retn; + } + } + + void __declspec(naked) CardTitles::TableLookupByRowHookStub() + { + static tablelookuprequest_s* currentLookupRequest; + static tablelookupresult_s* currentLookupResult; + static std::int32_t prefix; + static std::int32_t data; + static const char* title; + + __asm + { + mov currentLookupRequest, esi; + mov currentLookupResult, ebx; + } + + prefix = (currentLookupRequest->tableRow >> (8 * 3)) & 0xff; + data = (currentLookupRequest->tableRow >> (8 * 2)) & 0xff; + + //So we don't accidentally mess up other tables that might have a ridiculous amount of rows. Who knows. + if (!strcmp(currentLookupRequest->tablename, "mp/cardTitleTable.csv")) + { + if (prefix != 0x00) + { + // Column 1 = CardTitle + if (currentLookupRequest->tableColumn == 1) + { + if (prefix == 0xFE) + { + // 0xFF in front of the title to skip localization. Or else it will wait for a couple of seconds for the asset of type localize + if ((BYTE)*CustomTitleDvar->current.string) + { + title = Utils::String::VA("\xFF%s", CustomTitleDvar->current.string); + currentLookupResult->result = title; + currentLookupResult->dunno = 2; // Seems to be nessecary. Don't ask me why. + + __asm + { + mov eax, title; + pop ecx; + mov ecx, currentLookupRequest; + mov ecx, DWORD ptr[ecx + 0x04]; + retn; + } + } + } + else if (prefix == 0xFF) + { + if (!CustomTitles[data].empty()) + { + title = Utils::String::VA("\xFF%s", CustomTitles[data].data()); + currentLookupResult->result = title; + currentLookupResult->dunno = 2; + + __asm + { + mov eax, title; + pop ecx; + mov ecx, currentLookupRequest; + mov ecx, DWORD ptr[ecx + 0x04]; + retn; + } + } + } + } + // If the title was changed it already returned at this point so... + // Remove prefix and data to make being readable to the normal lookuprequest + currentLookupRequest->tableRow = static_cast(*(reinterpret_cast(¤tLookupRequest->tableRow))); + } + } + + // Continue with the normal lookup request because we did not use our custom result + __asm + { + mov eax, [esi + 0x50]; + cmp eax, 0x3; + + push 0x62DCC7; + retn; + } + } + + CardTitles::CardTitles() + { + Dvar::OnInit([]() { + CardTitles::CustomTitleDvar = Game::Dvar_RegisterString("cardtitle", "", Game::dvar_flag::DVAR_FLAG_SAVED, "Custom card title"); + }); + + CardTitles::CustomTitles.resize(18); + + Utils::Hook(0x62EB26, GetPlayerCardClientInfoStub).install()->quick(); + Utils::Hook(0x63A2D5, LocalizationSkipHookStub).install()->quick(); + Utils::Hook(0x62DCC1, TableLookupByRowHookStub).install()->quick(); + + Utils::Hook::Nop(0x62DCC6, 1); + } + + CardTitles::~CardTitles() + { + + } +} \ No newline at end of file diff --git a/src/Components/Modules/CardTitles.hpp b/src/Components/Modules/CardTitles.hpp new file mode 100644 index 00000000..97b13602 --- /dev/null +++ b/src/Components/Modules/CardTitles.hpp @@ -0,0 +1,76 @@ +#pragma once + +namespace Components +{ + struct tablelookuprequest_s + { + std::uint8_t padding[4]; + char* tablename; + std::uint8_t padding2[4]; + std::int32_t tableRow; + std::uint8_t padding3[4]; + std::int32_t tableColumn; + }; + struct tablelookupresult_s + { + std::uint32_t dunno; + const char* result; + }; + struct playercarddata_s + { + std::uint32_t padding; + std::uint32_t playercardNumber; + std::uint32_t unknown; + std::uint32_t unknown2; + std::uint32_t level; //Level is counted from 0 -> Value 69 is Level 70 + std::uint32_t prestige; + std::uint32_t padding2; + char name[40]; + }; + + struct CClient + { + std::uint32_t IsValid; // 0x0000 + std::uint32_t IsValid2; // 0x0004 + std::uint32_t ClientNumber; // 0x0008 + char Name[16]; // 0x000C + std::uint32_t Team; // 0x001C + std::uint32_t Team2; // 0x0020 + std::uint32_t Rank; // 0x0024 (rank - 1) + std::uint32_t Prestige; // 0x0028 + std::uint32_t Perks; // 0x002C + std::uint32_t Kills; // 0x0030 + std::uint32_t Score; // 0x0034 + std::uint8_t _0x0038[968]; + std::uint32_t ViewAngles; // 0x0400 + std::uint8_t _0x040C[136]; + std::uint32_t IsShooting; // 0x0494 + std::uint8_t _0x0498[4]; + std::uint32_t IsZoomed; // 0x049C + std::uint8_t _0x04A0[68]; + std::uint32_t weaponID; // 0x04E4 + std::uint8_t _0x04E8[24]; + std::uint32_t weaponID2; // 0x0500 + std::uint8_t _0x0504[40]; + std::uint8_t _padding[8]; + }; + + class CardTitles : public Component + { + public: + static Game::dvar_t* CustomTitleDvar; + + CardTitles(); + ~CardTitles(); + + private: + static std::vector < std::string > CustomTitles; + + static CClient * GetClientByIndex(std::uint32_t index); + static std::int32_t GetPlayerCardClientInfo(std::int32_t lookupResult, playercarddata_s * data); + static void GetPlayerCardClientInfoStub(); + static void LocalizationSkipHookStub(); + static void TableLookupByRowHookStub(); + + }; +} From dcb6c2b9e8839d27edbb64eda222ec8417ed83f8 Mon Sep 17 00:00:00 2001 From: RektInator Date: Tue, 30 May 2017 14:29:09 +0200 Subject: [PATCH 02/20] [ServerCommands] Server command hooks added --- src/Components/Loader.cpp | 1 + src/Components/Loader.hpp | 1 + src/Components/Modules/CardTitles.cpp | 33 ++++++++++ src/Components/Modules/CardTitles.hpp | 2 + src/Components/Modules/ServerCommands.cpp | 79 +++++++++++++++++++++++ src/Components/Modules/ServerCommands.hpp | 18 ++++++ 6 files changed, 134 insertions(+) create mode 100644 src/Components/Modules/ServerCommands.cpp create mode 100644 src/Components/Modules/ServerCommands.hpp diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index 7c98a367..1ae357c9 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -95,6 +95,7 @@ namespace Components Loader::Register(new AssetHandler()); Loader::Register(new Localization()); Loader::Register(new MusicalTalent()); + Loader::Register(new ServerCommands()); Loader::Register(new StructuredData()); Loader::Register(new ConnectProtocol()); Loader::Register(new StartupMessages()); diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index d09d22f1..2c514ea4 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -104,6 +104,7 @@ namespace Components #include "Modules/AssetHandler.hpp" #include "Modules/Localization.hpp" #include "Modules/MusicalTalent.hpp" +#include "Modules/ServerCommands.hpp" #include "Modules/StructuredData.hpp" #include "Modules/ConnectProtocol.hpp" #include "Modules/StartupMessages.hpp" diff --git a/src/Components/Modules/CardTitles.cpp b/src/Components/Modules/CardTitles.cpp index 36ce2f96..5da995c7 100644 --- a/src/Components/Modules/CardTitles.cpp +++ b/src/Components/Modules/CardTitles.cpp @@ -166,12 +166,45 @@ namespace Components } } + void CardTitles::ParseCustomTitles(char* msg) + { + char* playerTitle; + for (int i = 0; i < 18; i++) + { + playerTitle = msg; // nullptr; // (msg, std::to_string(i).c_str()); + + if (playerTitle != nullptr) + { + CustomTitles[i] = playerTitle; + } + else + { + CustomTitles[i] = ""; + } + } + } + CardTitles::CardTitles() { Dvar::OnInit([]() { CardTitles::CustomTitleDvar = Game::Dvar_RegisterString("cardtitle", "", Game::dvar_flag::DVAR_FLAG_SAVED, "Custom card title"); }); + ServerCommands::OnCommand(20, [](Command::Params* params) { + + if (params->get(1) == "customTitles"s && !Flags::HasFlag("dedicated")) + { + if (params->length() == 3) + { + CardTitles::ParseCustomTitles(params->get(2)); + return true; + } + } + + return false; + + }); + CardTitles::CustomTitles.resize(18); Utils::Hook(0x62EB26, GetPlayerCardClientInfoStub).install()->quick(); diff --git a/src/Components/Modules/CardTitles.hpp b/src/Components/Modules/CardTitles.hpp index 97b13602..e2c4a3bf 100644 --- a/src/Components/Modules/CardTitles.hpp +++ b/src/Components/Modules/CardTitles.hpp @@ -60,6 +60,8 @@ namespace Components public: static Game::dvar_t* CustomTitleDvar; + static void ParseCustomTitles(char * msg); + CardTitles(); ~CardTitles(); diff --git a/src/Components/Modules/ServerCommands.cpp b/src/Components/Modules/ServerCommands.cpp new file mode 100644 index 00000000..ebb5251a --- /dev/null +++ b/src/Components/Modules/ServerCommands.cpp @@ -0,0 +1,79 @@ +#include "STDInclude.hpp" + +namespace Components +{ + std::unordered_map < std::int32_t, std::function < bool(Command::Params*) > > ServerCommands::Commands; + + void ServerCommands::OnCommand(std::int32_t cmd, std::function < bool(Command::Params*) > cb) + { + Commands[cmd] = cb; + } + + bool ServerCommands::OnServerCommand() + { + Command::ClientParams params(*Game::cmd_id); + + for (auto &ServerCommandCB : Commands) + { + if (params.length() >= 1) + { + if (params.get(0)[0] == ServerCommandCB.first) + { + return ServerCommandCB.second(¶ms); + } + } + } + + return false; + } + + void __declspec(naked) ServerCommands::OnServerCommandStub() + { + __asm + { + call OnServerCommand; + test al, al; + jnz jumpback; + + push 0x5944AE; + retn; + + jumpback: + push 0x594536; + retn; + } + } + + /*void __declspec(naked) OnServerCommandPreFailStub() + { + static DWORD jmpAbove = 0x0059449F; + static DWORD jmpContinue = 0x00593C28; + + __asm mov lastServerCommand, ecx; + + if (lastServerCommand > 0x79) + __asm jmp jmpAbove; + else + __asm jmp jmpContinue; + } + + void OnServerCommandFailPrint(int type, const char *trash, ...) + { + const char *cmd = ""; + + for (int i = 1; i < Cmd_Argc(); i++) + cmd = va("%s %s", cmd, Cmd_Argv(i)); + + Com_Printf(type, "Unknown client game command: %i %s\n", lastServerCommand, cmd); + }*/ + + ServerCommands::ServerCommands() + { + Utils::Hook(0x59449F, OnServerCommandStub).install()->quick(); + } + + ServerCommands::~ServerCommands() + { + + } +} diff --git a/src/Components/Modules/ServerCommands.hpp b/src/Components/Modules/ServerCommands.hpp new file mode 100644 index 00000000..d7efe216 --- /dev/null +++ b/src/Components/Modules/ServerCommands.hpp @@ -0,0 +1,18 @@ +#pragma once + +namespace Components +{ + class ServerCommands : public Component + { + public: + ServerCommands(); + ~ServerCommands(); + + static void OnCommand(std::int32_t cmd, std::function cb); + + private: + static std::unordered_map < std::int32_t, std::function < bool(Command::Params*) > > Commands; + static bool OnServerCommand(); + static void OnServerCommandStub(); + }; +} From 150790a279c3a9e9331b3ef56fce449eeaead963 Mon Sep 17 00:00:00 2001 From: RektInator Date: Tue, 30 May 2017 15:37:50 +0200 Subject: [PATCH 03/20] [ServerCommands] Fail hooks installed. --- src/Components/Modules/CardTitles.cpp | 6 +-- src/Components/Modules/CardTitles.hpp | 2 +- src/Components/Modules/ServerCommands.cpp | 50 +++++++++++++++++------ src/Components/Modules/ServerCommands.hpp | 4 ++ 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/Components/Modules/CardTitles.cpp b/src/Components/Modules/CardTitles.cpp index 5da995c7..36f02ad0 100644 --- a/src/Components/Modules/CardTitles.cpp +++ b/src/Components/Modules/CardTitles.cpp @@ -166,12 +166,12 @@ namespace Components } } - void CardTitles::ParseCustomTitles(char* msg) + void CardTitles::ParseCustomTitles(const char* msg) { - char* playerTitle; + const char* playerTitle; for (int i = 0; i < 18; i++) { - playerTitle = msg; // nullptr; // (msg, std::to_string(i).c_str()); + playerTitle = Utils::Hook::Call(0x47C820)(msg, std::to_string(i).c_str()); if (playerTitle != nullptr) { diff --git a/src/Components/Modules/CardTitles.hpp b/src/Components/Modules/CardTitles.hpp index e2c4a3bf..529223aa 100644 --- a/src/Components/Modules/CardTitles.hpp +++ b/src/Components/Modules/CardTitles.hpp @@ -60,7 +60,7 @@ namespace Components public: static Game::dvar_t* CustomTitleDvar; - static void ParseCustomTitles(char * msg); + static void ParseCustomTitles(const char * msg); CardTitles(); ~CardTitles(); diff --git a/src/Components/Modules/ServerCommands.cpp b/src/Components/Modules/ServerCommands.cpp index ebb5251a..a6d5c763 100644 --- a/src/Components/Modules/ServerCommands.cpp +++ b/src/Components/Modules/ServerCommands.cpp @@ -3,6 +3,7 @@ namespace Components { std::unordered_map < std::int32_t, std::function < bool(Command::Params*) > > ServerCommands::Commands; + std::uint32_t ServerCommands::lastServerCommand; void ServerCommands::OnCommand(std::int32_t cmd, std::function < bool(Command::Params*) > cb) { @@ -44,32 +45,55 @@ namespace Components } } - /*void __declspec(naked) OnServerCommandPreFailStub() + void __declspec(naked) ServerCommands::OnServerCommandPreFailStub() { - static DWORD jmpAbove = 0x0059449F; - static DWORD jmpContinue = 0x00593C28; + __asm + { + mov lastServerCommand, ecx; + cmp ecx, 0x79; - __asm mov lastServerCommand, ecx; + jl above; - if (lastServerCommand > 0x79) - __asm jmp jmpAbove; - else - __asm jmp jmpContinue; + push 0x59449F; + retn; + + above: + push 0x593C28; + retn; + } } - void OnServerCommandFailPrint(int type, const char *trash, ...) + void ServerCommands::OnServerCommandFailPrint(int type, const char *trash, ...) { + Command::ClientParams params(*Game::cmd_id); const char *cmd = ""; - for (int i = 1; i < Cmd_Argc(); i++) - cmd = va("%s %s", cmd, Cmd_Argv(i)); + for (int i = 1; i < params.length(); i++) + cmd = Utils::String::VA("%s %s", cmd, params.get(i)); - Com_Printf(type, "Unknown client game command: %i %s\n", lastServerCommand, cmd); - }*/ + Game::Com_Printf(type, "Unknown client game command: %i %s\n", lastServerCommand, cmd); + } + + void __declspec(naked) ServerCommands::OnServerCommandFailPrintStub() + { + __asm + { + call OnServerCommandFailPrint; + + push 0x5944C0; + retn; + } + } ServerCommands::ServerCommands() { + // Server command receive hook Utils::Hook(0x59449F, OnServerCommandStub).install()->quick(); + + // Server command fail hooks + Utils::Hook(0x593C1F, OnServerCommandPreFailStub).install()->quick(); + Utils::Hook(0x5944BB, OnServerCommandFailPrintStub).install()->quick(); + Utils::Hook::Set(0x5944D3, 0xEB); } ServerCommands::~ServerCommands() diff --git a/src/Components/Modules/ServerCommands.hpp b/src/Components/Modules/ServerCommands.hpp index d7efe216..94b74627 100644 --- a/src/Components/Modules/ServerCommands.hpp +++ b/src/Components/Modules/ServerCommands.hpp @@ -14,5 +14,9 @@ namespace Components static std::unordered_map < std::int32_t, std::function < bool(Command::Params*) > > Commands; static bool OnServerCommand(); static void OnServerCommandStub(); + static void OnServerCommandPreFailStub(); + static void OnServerCommandFailPrint(int type, const char * trash, ...); + static void OnServerCommandFailPrintStub(); + static std::uint32_t lastServerCommand; }; } From 652d7ff4fc2bc0d5e583242f95226a25219188af Mon Sep 17 00:00:00 2001 From: RektInator Date: Tue, 30 May 2017 15:58:39 +0200 Subject: [PATCH 04/20] [Weapon] This might fix the fucked anims. --- src/Components/Modules/ServerCommands.cpp | 4 ++-- src/Components/Modules/Weapon.cpp | 18 ++++++++++++++++++ src/Components/Modules/Weapon.hpp | 2 ++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Components/Modules/ServerCommands.cpp b/src/Components/Modules/ServerCommands.cpp index a6d5c763..0361d660 100644 --- a/src/Components/Modules/ServerCommands.cpp +++ b/src/Components/Modules/ServerCommands.cpp @@ -63,12 +63,12 @@ namespace Components } } - void ServerCommands::OnServerCommandFailPrint(int type, const char *trash, ...) + void ServerCommands::OnServerCommandFailPrint(int type, const char *, ...) { Command::ClientParams params(*Game::cmd_id); const char *cmd = ""; - for (int i = 1; i < params.length(); i++) + for (std::size_t i = 1; i < params.length(); i++) cmd = Utils::String::VA("%s %s", cmd, params.get(i)); Game::Com_Printf(type, "Unknown client game command: %i %s\n", lastServerCommand, cmd); diff --git a/src/Components/Modules/Weapon.cpp b/src/Components/Modules/Weapon.cpp index 4c2ef802..ffb8bead 100644 --- a/src/Components/Modules/Weapon.cpp +++ b/src/Components/Modules/Weapon.cpp @@ -420,6 +420,22 @@ namespace Components Utils::Hook::Set(0x4F7630, 0x12DC + (sizeof(bg_sharedAmmoCaps) - (1200 * 4))); } + void* Weapon::LoadNoneWeaponHook() + { + // load anim scripts now, rather than a bit later on + ((void(*)())0x4E46A0)(); + Utils::Hook::Nop(0x4B3670, 5); + return Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_WEAPON, "none").data; + } + + void __declspec(naked) Weapon::LoadNoneWeaponHookStub() + { + __asm + { + jmp LoadNoneWeaponHook + } + } + Weapon::Weapon() { Weapon::PatchLimit(); @@ -436,6 +452,8 @@ namespace Components // Skip double loading for fs_game Utils::Hook::Set(0x4081FD, 0xEB); + Utils::Hook(0x57B4F0, LoadNoneWeaponHookStub).install()->quick(); + // Don't load bounce sounds for now, it causes crashes // TODO: Actually check the weaponfiles and/or reset the soundtable correctly! //Utils::Hook::Nop(0x57A360, 5); diff --git a/src/Components/Modules/Weapon.hpp b/src/Components/Modules/Weapon.hpp index 1f785b35..3119c8c6 100644 --- a/src/Components/Modules/Weapon.hpp +++ b/src/Components/Modules/Weapon.hpp @@ -19,6 +19,8 @@ namespace Components private: static Game::XAssetHeader WeaponFileLoad(Game::XAssetType type, std::string filename); static void PatchLimit(); + static void* LoadNoneWeaponHook(); + static void LoadNoneWeaponHookStub(); static void PatchConfigStrings(); static const char* GetWeaponConfigString(int index); From d77c74f5a9b2f01329ed851d6baecf58e7e8bf53 Mon Sep 17 00:00:00 2001 From: RektInator Date: Tue, 30 May 2017 16:32:17 +0200 Subject: [PATCH 05/20] [Weapon] Runtime memory editing removed. --- src/Components/Modules/Weapon.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Components/Modules/Weapon.cpp b/src/Components/Modules/Weapon.cpp index ffb8bead..e80e95e6 100644 --- a/src/Components/Modules/Weapon.cpp +++ b/src/Components/Modules/Weapon.cpp @@ -423,8 +423,8 @@ namespace Components void* Weapon::LoadNoneWeaponHook() { // load anim scripts now, rather than a bit later on - ((void(*)())0x4E46A0)(); - Utils::Hook::Nop(0x4B3670, 5); + Utils::Hook::Call(0x4E46A0)(); + return Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_WEAPON, "none").data; } @@ -452,6 +452,8 @@ namespace Components // Skip double loading for fs_game Utils::Hook::Set(0x4081FD, 0xEB); + // Weapon swap fix + Utils::Hook::Nop(0x4B3670, 5); Utils::Hook(0x57B4F0, LoadNoneWeaponHookStub).install()->quick(); // Don't load bounce sounds for now, it causes crashes From 859f00acdd9bbc1c9cf1d65867a7c7216b05b48e Mon Sep 17 00:00:00 2001 From: RektInator Date: Tue, 30 May 2017 18:38:54 +0200 Subject: [PATCH 06/20] [CardTitles] Code optimizations --- src/Components/Modules/CardTitles.cpp | 30 +++++++++++------------ src/Components/Modules/ServerCommands.cpp | 16 ++++++------ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/Components/Modules/CardTitles.cpp b/src/Components/Modules/CardTitles.cpp index 36f02ad0..5351a555 100644 --- a/src/Components/Modules/CardTitles.cpp +++ b/src/Components/Modules/CardTitles.cpp @@ -49,14 +49,14 @@ namespace Components push esi; push eax; call GetPlayerCardClientInfo; - add esp, 0x08; + add esp, 8; pop esi; pop ebp; - mov[ebx + 0x4], eax; + mov[ebx + 4], eax; pop ebx; - push 0x62EB2C; + push 62EB2Ch; retn; } } @@ -65,23 +65,23 @@ namespace Components { __asm { - cmp byte ptr[edi + 0x01], 0xFF; // Check if skip prefix exists (edi + 0x00 = @) + cmp byte ptr[edi + 01h], FFh; // Check if skip prefix exists (edi + 0x00 = @) jne back; - add edi, 0x02; // Ignore the 0x40 and 0xFF prefix (Localize and Skip prefix) + add edi, 2; // Ignore the 0x40 and 0xFF prefix (Localize and Skip prefix) jmp jumpback; back: - add edi, 0x01; + add edi, 1; push edi; - mov eax, 0x4F1700; + mov eax, 4F1700h; call eax; - add esp, 0x04; + add esp, 4; mov edi, eax; jumpback: - push 0x63A2E3; + push 63A2E3h; retn; } } @@ -125,7 +125,7 @@ namespace Components mov eax, title; pop ecx; mov ecx, currentLookupRequest; - mov ecx, DWORD ptr[ecx + 0x04]; + mov ecx, DWORD ptr[ecx + 4]; retn; } } @@ -143,7 +143,7 @@ namespace Components mov eax, title; pop ecx; mov ecx, currentLookupRequest; - mov ecx, DWORD ptr[ecx + 0x04]; + mov ecx, DWORD ptr[ecx + 4]; retn; } } @@ -158,10 +158,10 @@ namespace Components // Continue with the normal lookup request because we did not use our custom result __asm { - mov eax, [esi + 0x50]; - cmp eax, 0x3; + mov eax, [esi + 50h]; + cmp eax, 3; - push 0x62DCC7; + push 62DCC7h; retn; } } @@ -216,6 +216,6 @@ namespace Components CardTitles::~CardTitles() { - + CustomTitles.clear(); } } \ No newline at end of file diff --git a/src/Components/Modules/ServerCommands.cpp b/src/Components/Modules/ServerCommands.cpp index 0361d660..44756c64 100644 --- a/src/Components/Modules/ServerCommands.cpp +++ b/src/Components/Modules/ServerCommands.cpp @@ -36,11 +36,11 @@ namespace Components test al, al; jnz jumpback; - push 0x5944AE; + push 5944AEh; retn; jumpback: - push 0x594536; + push 594536h; retn; } } @@ -50,15 +50,15 @@ namespace Components __asm { mov lastServerCommand, ecx; - cmp ecx, 0x79; + cmp ecx, 79h; jl above; - push 0x59449F; + push 59449Fh; retn; above: - push 0x593C28; + push 593C28h; retn; } } @@ -78,9 +78,11 @@ namespace Components { __asm { + pushad; call OnServerCommandFailPrint; + popad; - push 0x5944C0; + push 5944C0h; retn; } } @@ -98,6 +100,6 @@ namespace Components ServerCommands::~ServerCommands() { - + Commands.clear(); } } From a5a8b86c8c70d4f9a15d79b0311544d5ad86a1cf Mon Sep 17 00:00:00 2001 From: RektInator Date: Tue, 30 May 2017 18:49:51 +0200 Subject: [PATCH 07/20] [ServerCommands] Fix shortjump type --- src/Components/Modules/ServerCommands.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Modules/ServerCommands.cpp b/src/Components/Modules/ServerCommands.cpp index 44756c64..d3b80bb8 100644 --- a/src/Components/Modules/ServerCommands.cpp +++ b/src/Components/Modules/ServerCommands.cpp @@ -95,7 +95,7 @@ namespace Components // Server command fail hooks Utils::Hook(0x593C1F, OnServerCommandPreFailStub).install()->quick(); Utils::Hook(0x5944BB, OnServerCommandFailPrintStub).install()->quick(); - Utils::Hook::Set(0x5944D3, 0xEB); + Utils::Hook::Set(0x5944D3, 0xEB); } ServerCommands::~ServerCommands() From f6b855e3c109e065310ffcc1f1cef4d648ac9bc2 Mon Sep 17 00:00:00 2001 From: RektInator Date: Tue, 30 May 2017 20:56:14 +0200 Subject: [PATCH 08/20] [CardTitles] Fixed ASM mistake --- src/Components/Modules/CardTitles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Modules/CardTitles.cpp b/src/Components/Modules/CardTitles.cpp index 5351a555..fe7a3434 100644 --- a/src/Components/Modules/CardTitles.cpp +++ b/src/Components/Modules/CardTitles.cpp @@ -65,7 +65,7 @@ namespace Components { __asm { - cmp byte ptr[edi + 01h], FFh; // Check if skip prefix exists (edi + 0x00 = @) + cmp byte ptr[edi + 01h], 0FFh; // Check if skip prefix exists (edi + 0x00 = @) jne back; add edi, 2; // Ignore the 0x40 and 0xFF prefix (Localize and Skip prefix) jmp jumpback; From e55f8070034cf36838cd6debb92e8f9f13ceb0c9 Mon Sep 17 00:00:00 2001 From: RektInator Date: Tue, 30 May 2017 23:39:57 +0200 Subject: [PATCH 09/20] [CardTitles] Refactored CardTitle code. --- src/Components/Modules/CardTitles.cpp | 144 +++++++++++--------------- src/Components/Modules/CardTitles.hpp | 7 +- 2 files changed, 65 insertions(+), 86 deletions(-) diff --git a/src/Components/Modules/CardTitles.cpp b/src/Components/Modules/CardTitles.cpp index fe7a3434..84a2e50a 100644 --- a/src/Components/Modules/CardTitles.cpp +++ b/src/Components/Modules/CardTitles.cpp @@ -61,103 +61,81 @@ namespace Components } } - void __declspec(naked) CardTitles::LocalizationSkipHookStub() + const char* CardTitles::TableLookupByRowHook(Game::Operand* operand, tablelookuprequest_s* request) { - __asm + std::uint8_t prefix = (request->tableRow >> (8 * 3)) & 0xFF; + std::uint8_t data = (request->tableRow >> (8 * 2)) & 0xFF; + const char* title = nullptr; + + if (request->tablename == "mp/cardTitleTable.csv"s) { - cmp byte ptr[edi + 01h], 0FFh; // Check if skip prefix exists (edi + 0x00 = @) - jne back; - add edi, 2; // Ignore the 0x40 and 0xFF prefix (Localize and Skip prefix) - jmp jumpback; + if (prefix != 0x00) + { + // Column 1 = CardTitle + if (request->tableColumn == 1) + { + if (prefix == 0xFE) + { + // 0xFF in front of the title to skip localization. Or else it will wait for a couple of seconds for the asset of type localize + if (*CustomTitleDvar->current.string) + { + title = Utils::String::VA("\x15%s", CustomTitleDvar->current.string); - back: - add edi, 1; - push edi; + // prepare return value + operand->internals.stringVal.string = title; + operand->dataType = Game::VAL_STRING; - mov eax, 4F1700h; - call eax; + return title; + } + } + else if (prefix == 0xFF) + { + if (!CustomTitles[data].empty()) + { + title = Utils::String::VA("\x15%s", CustomTitles[data].data()); - add esp, 4; - mov edi, eax; + // prepare return value + operand->internals.stringVal.string = title; + operand->dataType = Game::VAL_STRING; - jumpback: - push 63A2E3h; - retn; + return title; + } + } + } + + // If the title was changed it already returned at this point so... + // Remove prefix and data to make being readable to the normal lookuprequest + request->tableRow = static_cast(*(reinterpret_cast(&request->tableRow))); + } } + + return nullptr; } void __declspec(naked) CardTitles::TableLookupByRowHookStub() { - static tablelookuprequest_s* currentLookupRequest; - static tablelookupresult_s* currentLookupResult; - static std::int32_t prefix; - static std::int32_t data; - static const char* title; - __asm { - mov currentLookupRequest, esi; - mov currentLookupResult, ebx; - } + push esi; + push ebx; + + pushad; + call TableLookupByRowHook; + cmp eax, 0; + popad; - prefix = (currentLookupRequest->tableRow >> (8 * 3)) & 0xff; - data = (currentLookupRequest->tableRow >> (8 * 2)) & 0xff; + jz OriginalTitle; - //So we don't accidentally mess up other tables that might have a ridiculous amount of rows. Who knows. - if (!strcmp(currentLookupRequest->tablename, "mp/cardTitleTable.csv")) - { - if (prefix != 0x00) - { - // Column 1 = CardTitle - if (currentLookupRequest->tableColumn == 1) - { - if (prefix == 0xFE) - { - // 0xFF in front of the title to skip localization. Or else it will wait for a couple of seconds for the asset of type localize - if ((BYTE)*CustomTitleDvar->current.string) - { - title = Utils::String::VA("\xFF%s", CustomTitleDvar->current.string); - currentLookupResult->result = title; - currentLookupResult->dunno = 2; // Seems to be nessecary. Don't ask me why. + add esp, 8; - __asm - { - mov eax, title; - pop ecx; - mov ecx, currentLookupRequest; - mov ecx, DWORD ptr[ecx + 4]; - retn; - } - } - } - else if (prefix == 0xFF) - { - if (!CustomTitles[data].empty()) - { - title = Utils::String::VA("\xFF%s", CustomTitles[data].data()); - currentLookupResult->result = title; - currentLookupResult->dunno = 2; + pop ecx; + mov ecx, DWORD ptr[esi + 4]; + retn; - __asm - { - mov eax, title; - pop ecx; - mov ecx, currentLookupRequest; - mov ecx, DWORD ptr[ecx + 4]; - retn; - } - } - } - } - // If the title was changed it already returned at this point so... - // Remove prefix and data to make being readable to the normal lookuprequest - currentLookupRequest->tableRow = static_cast(*(reinterpret_cast(¤tLookupRequest->tableRow))); - } - } + OriginalTitle: + + add esp, 8; - // Continue with the normal lookup request because we did not use our custom result - __asm - { mov eax, [esi + 50h]; cmp eax, 3; @@ -208,9 +186,13 @@ namespace Components CardTitles::CustomTitles.resize(18); Utils::Hook(0x62EB26, GetPlayerCardClientInfoStub).install()->quick(); - Utils::Hook(0x63A2D5, LocalizationSkipHookStub).install()->quick(); - Utils::Hook(0x62DCC1, TableLookupByRowHookStub).install()->quick(); + // Translation fixup + // Utils::Hook(0x63A2D9, LocalizationSkipHookStub).install()->quick(); + // Utils::Hook::Nop(0x63A2D5, 3); + + // Table lookup stuff + Utils::Hook(0x62DCC1, TableLookupByRowHookStub).install()->quick(); Utils::Hook::Nop(0x62DCC6, 1); } diff --git a/src/Components/Modules/CardTitles.hpp b/src/Components/Modules/CardTitles.hpp index 529223aa..a3d7839f 100644 --- a/src/Components/Modules/CardTitles.hpp +++ b/src/Components/Modules/CardTitles.hpp @@ -11,11 +11,6 @@ namespace Components std::uint8_t padding3[4]; std::int32_t tableColumn; }; - struct tablelookupresult_s - { - std::uint32_t dunno; - const char* result; - }; struct playercarddata_s { std::uint32_t padding; @@ -71,7 +66,9 @@ namespace Components static CClient * GetClientByIndex(std::uint32_t index); static std::int32_t GetPlayerCardClientInfo(std::int32_t lookupResult, playercarddata_s * data); static void GetPlayerCardClientInfoStub(); + static const char* LocalizationSkipHook(const char * string); static void LocalizationSkipHookStub(); + static const char* TableLookupByRowHook(Game::Operand * operand, tablelookuprequest_s * request); static void TableLookupByRowHookStub(); }; From 6f71a65a83954a83a6c77b8fbbe9d12c31cc3f99 Mon Sep 17 00:00:00 2001 From: RektInator Date: Wed, 31 May 2017 00:27:08 +0200 Subject: [PATCH 10/20] [Dedicated] Update cardtitles across clients. --- src/Components/Modules/CardTitles.cpp | 26 +++++++++++++++++++++++++- src/Components/Modules/CardTitles.hpp | 2 ++ src/Components/Modules/Dedicated.cpp | 11 +++++++++++ src/Game/Functions.cpp | 2 ++ src/Game/Functions.hpp | 3 +++ 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/Components/Modules/CardTitles.cpp b/src/Components/Modules/CardTitles.cpp index 84a2e50a..2aa7929b 100644 --- a/src/Components/Modules/CardTitles.cpp +++ b/src/Components/Modules/CardTitles.cpp @@ -144,12 +144,36 @@ namespace Components } } + void CardTitles::SendCustomTitlesToClients() + { + const char* list = ""; + + for (int i = 0; i < 18; i++) + { + char playerTitle[18] = { 0 }; + + if (Game::svs_clients[i].state >= 3) + { + strncpy_s(playerTitle, Game::Info_ValueForKey(Game::svs_clients[i].connectInfoString, "customTitle"), 18); + } + else + { + memset(playerTitle, 0, 18); + } + + list = Utils::String::VA("%s\\%s\\%s", list, std::to_string(i).c_str(), playerTitle); + } + + list = Utils::String::VA("%c customTitles \"%s", 20, list); + Game::SV_GameSendServerCommand(-1, 0, list); + } + void CardTitles::ParseCustomTitles(const char* msg) { const char* playerTitle; for (int i = 0; i < 18; i++) { - playerTitle = Utils::Hook::Call(0x47C820)(msg, std::to_string(i).c_str()); + playerTitle = Game::Info_ValueForKey(msg, std::to_string(i).c_str()); if (playerTitle != nullptr) { diff --git a/src/Components/Modules/CardTitles.hpp b/src/Components/Modules/CardTitles.hpp index a3d7839f..4e154b74 100644 --- a/src/Components/Modules/CardTitles.hpp +++ b/src/Components/Modules/CardTitles.hpp @@ -55,6 +55,7 @@ namespace Components public: static Game::dvar_t* CustomTitleDvar; + static void SendCustomTitlesToClients(); static void ParseCustomTitles(const char * msg); CardTitles(); @@ -71,5 +72,6 @@ namespace Components static const char* TableLookupByRowHook(Game::Operand * operand, tablelookuprequest_s * request); static void TableLookupByRowHookStub(); + }; } diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index ea99e51f..a711e1a6 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -452,6 +452,17 @@ namespace Components // Post initialization point Utils::Hook(0x60BFBF, Dedicated::PostInitializationStub, HOOK_JUMP).install()->quick(); + // Custom cardtitles + Dedicated::OnFrame([]() + { + static std::uint64_t LastUpdate = 0; + + if ((GetTickCount64() - LastUpdate) > 120 * 1000) + { + CardTitles::SendCustomTitlesToClients(); + } + }); + #ifdef USE_LEGACY_SERVER_LIST // Heartbeats diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 3b3f0834..948e5822 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -121,6 +121,8 @@ namespace Game Image_LoadFromFileWithReader_t Image_LoadFromFileWithReader = Image_LoadFromFileWithReader_t(0x53ABF0); Image_Release_t Image_Release = Image_Release_t(0x51F010); + Info_ValueForKey_t Info_ValueForKey = Info_ValueForKey_t(0x47C820); + Key_SetCatcher_t Key_SetCatcher = Key_SetCatcher_t(0x43BD00); LargeLocalInit_t LargeLocalInit = LargeLocalInit_t(0x4A62A0); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 8ff2aa51..669aea85 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -304,6 +304,9 @@ namespace Game typedef void(__cdecl * Image_Release_t)(GfxImage* image); extern Image_Release_t Image_Release; + typedef char*(__cdecl * Info_ValueForKey_t)(const char* infoString, const char* key); + extern Info_ValueForKey_t Info_ValueForKey; + typedef void(__cdecl * Key_SetCatcher_t)(int localClientNum, int catcher); extern Key_SetCatcher_t Key_SetCatcher; From 0661972f68928ee4903d09dbdfbc5209281c8363 Mon Sep 17 00:00:00 2001 From: RektInator Date: Wed, 31 May 2017 01:42:25 +0200 Subject: [PATCH 11/20] [CardTitles] Changed command index. --- src/Components/Modules/CardTitles.cpp | 14 +++++--------- src/Components/Modules/CardTitles.hpp | 5 +---- src/Components/Modules/Dedicated.cpp | 3 ++- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/Components/Modules/CardTitles.cpp b/src/Components/Modules/CardTitles.cpp index 2aa7929b..6c3fd8b4 100644 --- a/src/Components/Modules/CardTitles.cpp +++ b/src/Components/Modules/CardTitles.cpp @@ -150,11 +150,11 @@ namespace Components for (int i = 0; i < 18; i++) { - char playerTitle[18] = { 0 }; + char playerTitle[18]; if (Game::svs_clients[i].state >= 3) { - strncpy_s(playerTitle, Game::Info_ValueForKey(Game::svs_clients[i].connectInfoString, "customTitle"), 18); + strncpy_s(playerTitle, Game::Info_ValueForKey(Game::svs_clients[i].connectInfoString, "customTitle"), 17); } else { @@ -164,7 +164,7 @@ namespace Components list = Utils::String::VA("%s\\%s\\%s", list, std::to_string(i).c_str(), playerTitle); } - list = Utils::String::VA("%c customTitles \"%s", 20, list); + list = Utils::String::VA("%c customTitles \"%s\"", 21, list); Game::SV_GameSendServerCommand(-1, 0, list); } @@ -189,10 +189,10 @@ namespace Components CardTitles::CardTitles() { Dvar::OnInit([]() { - CardTitles::CustomTitleDvar = Game::Dvar_RegisterString("cardtitle", "", Game::dvar_flag::DVAR_FLAG_SAVED, "Custom card title"); + CardTitles::CustomTitleDvar = Game::Dvar_RegisterString("customtitle", "", Game::dvar_flag::DVAR_FLAG_USERINFO | Game::dvar_flag::DVAR_FLAG_SAVED, "Custom card title"); }); - ServerCommands::OnCommand(20, [](Command::Params* params) { + ServerCommands::OnCommand(21, [](Command::Params* params) { if (params->get(1) == "customTitles"s && !Flags::HasFlag("dedicated")) { @@ -211,10 +211,6 @@ namespace Components Utils::Hook(0x62EB26, GetPlayerCardClientInfoStub).install()->quick(); - // Translation fixup - // Utils::Hook(0x63A2D9, LocalizationSkipHookStub).install()->quick(); - // Utils::Hook::Nop(0x63A2D5, 3); - // Table lookup stuff Utils::Hook(0x62DCC1, TableLookupByRowHookStub).install()->quick(); Utils::Hook::Nop(0x62DCC6, 1); diff --git a/src/Components/Modules/CardTitles.hpp b/src/Components/Modules/CardTitles.hpp index 4e154b74..eecdf7d8 100644 --- a/src/Components/Modules/CardTitles.hpp +++ b/src/Components/Modules/CardTitles.hpp @@ -54,6 +54,7 @@ namespace Components { public: static Game::dvar_t* CustomTitleDvar; + static std::vector < std::string > CustomTitles; static void SendCustomTitlesToClients(); static void ParseCustomTitles(const char * msg); @@ -62,13 +63,9 @@ namespace Components ~CardTitles(); private: - static std::vector < std::string > CustomTitles; - static CClient * GetClientByIndex(std::uint32_t index); static std::int32_t GetPlayerCardClientInfo(std::int32_t lookupResult, playercarddata_s * data); static void GetPlayerCardClientInfoStub(); - static const char* LocalizationSkipHook(const char * string); - static void LocalizationSkipHookStub(); static const char* TableLookupByRowHook(Game::Operand * operand, tablelookuprequest_s * request); static void TableLookupByRowHookStub(); diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index a711e1a6..0b60526d 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -457,9 +457,10 @@ namespace Components { static std::uint64_t LastUpdate = 0; - if ((GetTickCount64() - LastUpdate) > 120 * 1000) + if ((GetTickCount64() - LastUpdate) > 10000) { CardTitles::SendCustomTitlesToClients(); + LastUpdate = GetTickCount64(); } }); From f798af784087df9534d1ec27296646aec46880b6 Mon Sep 17 00:00:00 2001 From: RektInator Date: Wed, 31 May 2017 01:51:06 +0200 Subject: [PATCH 12/20] [Dedicated] Updated friend discovery hook --- src/Components/Modules/Dedicated.cpp | 68 +++++++--------------------- src/Components/Modules/Dedicated.hpp | 3 -- 2 files changed, 17 insertions(+), 54 deletions(-) diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index 0b60526d..f16b98f4 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -185,56 +185,6 @@ namespace Components Game::Com_Error(code, message); } - __declspec(naked) void Dedicated::OnServerCommandStub() - { - __asm - { - push eax - pushad - - call Dedicated::OnServerCommand - - mov [esp + 20h], eax - popad - pop eax - - test al, al - jnz returnSafe - - push 5944AEh - retn - - returnSafe: - push 594536h - retn - } - } - - int Dedicated::OnServerCommand() - { - Command::ClientParams params; - - ZeroMemory(Dedicated::PlayerGuids, sizeof(Dedicated::PlayerGuids)); - - if (params.length() >= (18 * 2 + 1) && params.get(0)[0] == 20) - { - for (int client = 0; client < 18; client++) - { - Dedicated::PlayerGuids[client][0].bits = strtoull(params.get(2 * client + 1), nullptr, 16); - Dedicated::PlayerGuids[client][1].bits = strtoull(params.get(2 * client + 2), nullptr, 16); - - if(Steam::Proxy::SteamFriends && Dedicated::PlayerGuids[client][1].bits != 0) - { - Steam::Proxy::SteamFriends->SetPlayedWith(Dedicated::PlayerGuids[client][1]); - } - } - - return 1; - } - - return 0; - } - void Dedicated::MapRotate() { if (!Dedicated::IsEnabled() && Dvar::Var("sv_dontrotate").get()) @@ -577,7 +527,23 @@ namespace Components } // Intercept server commands - Utils::Hook(0x59449F, Dedicated::OnServerCommandStub, HOOK_JUMP).install()->quick(); + ServerCommands::OnCommand(20, [](Command::Params* params) { + + for (int client = 0; client < 18; client++) + { + Dedicated::PlayerGuids[client][0].bits = strtoull(params.get(2 * client + 1), nullptr, 16); + Dedicated::PlayerGuids[client][1].bits = strtoull(params.get(2 * client + 2), nullptr, 16); + + if (Steam::Proxy::SteamFriends && Dedicated::PlayerGuids[client][1].bits != 0) + { + Steam::Proxy::SteamFriends->SetPlayedWith(Dedicated::PlayerGuids[client][1]); + } + } + + return true; + + }); + } QuickPatch::OnFrame([]() diff --git a/src/Components/Modules/Dedicated.hpp b/src/Components/Modules/Dedicated.hpp index 9deeaed1..6b07885b 100644 --- a/src/Components/Modules/Dedicated.hpp +++ b/src/Components/Modules/Dedicated.hpp @@ -29,9 +29,6 @@ namespace Components static bool SendChat; - static void OnServerCommandStub(); - static int OnServerCommand(); - static void MapRotate(); static void FrameHandler(); static void FrameStub(); From 635720732628fc449fea2adfc5fa3faae418745b Mon Sep 17 00:00:00 2001 From: RektInator Date: Wed, 31 May 2017 01:51:45 +0200 Subject: [PATCH 13/20] [Dedicated] Fixed server command --- src/Components/Modules/Dedicated.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index f16b98f4..bca732bc 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -531,8 +531,8 @@ namespace Components for (int client = 0; client < 18; client++) { - Dedicated::PlayerGuids[client][0].bits = strtoull(params.get(2 * client + 1), nullptr, 16); - Dedicated::PlayerGuids[client][1].bits = strtoull(params.get(2 * client + 2), nullptr, 16); + Dedicated::PlayerGuids[client][0].bits = strtoull(params->get(2 * client + 1), nullptr, 16); + Dedicated::PlayerGuids[client][1].bits = strtoull(params->get(2 * client + 2), nullptr, 16); if (Steam::Proxy::SteamFriends && Dedicated::PlayerGuids[client][1].bits != 0) { From e99894f692f64073c5335fcc6d765705446e81be Mon Sep 17 00:00:00 2001 From: RektInator Date: Wed, 31 May 2017 03:33:31 +0200 Subject: [PATCH 14/20] [Clantags] Initial commit TODO: Add clantag to player overhead names and 'killed by' popup menus. --- src/Components/Loader.cpp | 1 + src/Components/Loader.hpp | 1 + src/Components/Modules/Clantags.cpp | 120 +++++++++++++++++++++++++++ src/Components/Modules/Clantags.hpp | 20 +++++ src/Components/Modules/Dedicated.cpp | 4 +- 5 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 src/Components/Modules/Clantags.cpp create mode 100644 src/Components/Modules/Clantags.hpp diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index 1ae357c9..d1fbff2e 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -64,6 +64,7 @@ namespace Components Loader::Register(new Monitor()); Loader::Register(new Network()); Loader::Register(new Theatre()); + Loader::Register(new Clantags()); Loader::Register(new Download()); Loader::Register(new Playlist()); Loader::Register(new RawFiles()); diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index 2c514ea4..e4988170 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -75,6 +75,7 @@ namespace Components #include "Modules/Logger.hpp" #include "Modules/Friends.hpp" #include "Modules/IPCPipe.hpp" +#include "Modules/Clantags.hpp" #include "Modules/Download.hpp" #include "Modules/Playlist.hpp" #include "Modules/RawFiles.hpp" diff --git a/src/Components/Modules/Clantags.cpp b/src/Components/Modules/Clantags.cpp new file mode 100644 index 00000000..f475eec1 --- /dev/null +++ b/src/Components/Modules/Clantags.cpp @@ -0,0 +1,120 @@ +#include "STDInclude.hpp" + +namespace Components +{ + std::vector < std::string > Clantags::Tags; + const char* CurrentName; + + void Clantags::ParseClantags(const char* infoString) + { + const char* clantag; + for (int i = 0; i < 18; i++) + { + clantag = Game::Info_ValueForKey(infoString, std::to_string(i).c_str()); + + if (clantag != nullptr) + { + Tags[i] = _strdup(clantag); + } + else + { + Tags[i] = ""; + } + } + } + + void Clantags::SendClantagsToClients() + { + const char* list = ""; + + for (int i = 0; i < 18; i++) + { + char clantag[5]; + + if (Game::svs_clients[i].state >= 3) + { + strncpy_s(clantag, Game::Info_ValueForKey(Game::svs_clients[i].connectInfoString, "iw4x_clantag"), 4); + } + else + { + memset(clantag, 0, 5); + } + + list = Utils::String::VA("%s\\%s\\%s", list, std::to_string(i).c_str(), clantag); + } + + list = Utils::String::VA("%c clantags \"%s\"", 22, list); + Game::SV_GameSendServerCommand(-1, 0, list); + } + + void Clantags::GetUserClantag(std::uint32_t clientnum, const char* playername) + { + if (Tags[clientnum].empty()) + { + CurrentName = playername; + return; + } + + CurrentName = Utils::String::VA("[%s] %s", Tags[clientnum].data(), playername); + } + + void __declspec(naked) Clantags::DrawPlayerNameOnScoreboard() + { + static DWORD drawstringfunc = 0x5909E0; + + __asm + { + pushad; + + push edi; + push [ebp]; + + call GetUserClantag; + add esp, 8; + + popad; + + mov edi, CurrentName; + + call drawstringfunc; + + push 591247h; + retn; + } + } + + Clantags::Clantags() + { + // Create clantag dvar + Dvar::OnInit([]() { + CardTitles::CustomTitleDvar = Game::Dvar_RegisterString("iw4x_clantag", "", Game::dvar_flag::DVAR_FLAG_USERINFO | Game::dvar_flag::DVAR_FLAG_SAVED, "If set, your clantag will be shown on the scoreboard."); + }); + + // Servercommand hook + ServerCommands::OnCommand(22, [](Command::Params* params) { + + if (params->get(1) == "clantags"s && !Flags::HasFlag("dedicated")) + { + if (params->length() == 3) + { + Clantags::ParseClantags(params->get(2)); + return true; + } + } + + return false; + + }); + + // Resize clantags array + Tags.resize(18); + + // Draw clantag before playername + Utils::Hook(0x591242, DrawPlayerNameOnScoreboard).install()->quick(); + } + + Clantags::~Clantags() + { + Tags.clear(); + } +} diff --git a/src/Components/Modules/Clantags.hpp b/src/Components/Modules/Clantags.hpp new file mode 100644 index 00000000..1f1d4e56 --- /dev/null +++ b/src/Components/Modules/Clantags.hpp @@ -0,0 +1,20 @@ +#pragma once + +namespace Components +{ + class Clantags : public Component + { + public: + static std::vector < std::string > Clantags::Tags; + static void ParseClantags(const char * infoString); + static void SendClantagsToClients(); + + Clantags(); + ~Clantags(); + + private: + static void GetUserClantag(std::uint32_t clientnum, const char * playername); + static void DrawPlayerNameOnScoreboard(); + + }; +} diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index bca732bc..7758c264 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -402,7 +402,7 @@ namespace Components // Post initialization point Utils::Hook(0x60BFBF, Dedicated::PostInitializationStub, HOOK_JUMP).install()->quick(); - // Custom cardtitles + // Transmit custom data Dedicated::OnFrame([]() { static std::uint64_t LastUpdate = 0; @@ -410,6 +410,8 @@ namespace Components if ((GetTickCount64() - LastUpdate) > 10000) { CardTitles::SendCustomTitlesToClients(); + Clantags::SendClantagsToClients(); + LastUpdate = GetTickCount64(); } }); From 5c91a8c451c4687fb502489d90b98d0388b90b86 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 31 May 2017 09:58:36 +0200 Subject: [PATCH 15/20] [Clantags] Optimize code and get rid of memory leaks --- src/Components/Modules/Clantags.cpp | 91 +++++++++++++---------------- src/Components/Modules/Clantags.hpp | 5 +- 2 files changed, 42 insertions(+), 54 deletions(-) diff --git a/src/Components/Modules/Clantags.cpp b/src/Components/Modules/Clantags.cpp index f475eec1..97a96a23 100644 --- a/src/Components/Modules/Clantags.cpp +++ b/src/Components/Modules/Clantags.cpp @@ -2,98 +2,81 @@ namespace Components { - std::vector < std::string > Clantags::Tags; - const char* CurrentName; + std::string Clantags::Tags[18]; void Clantags::ParseClantags(const char* infoString) { - const char* clantag; for (int i = 0; i < 18; i++) { - clantag = Game::Info_ValueForKey(infoString, std::to_string(i).c_str()); + const char* clantag = Game::Info_ValueForKey(infoString, std::to_string(i).data()); - if (clantag != nullptr) - { - Tags[i] = _strdup(clantag); - } - else - { - Tags[i] = ""; - } + if (clantag) Tags[i] = clantag; + else Tags[i].clear(); } } void Clantags::SendClantagsToClients() { - const char* list = ""; + std::string list; for (int i = 0; i < 18; i++) { - char clantag[5]; + char clantag[5] = { 0 }; if (Game::svs_clients[i].state >= 3) { strncpy_s(clantag, Game::Info_ValueForKey(Game::svs_clients[i].connectInfoString, "iw4x_clantag"), 4); } - else - { - memset(clantag, 0, 5); - } - list = Utils::String::VA("%s\\%s\\%s", list, std::to_string(i).c_str(), clantag); + list.append(Utils::String::VA("\\%s\\%s", std::to_string(i).data(), clantag)); } - list = Utils::String::VA("%c clantags \"%s\"", 22, list); - Game::SV_GameSendServerCommand(-1, 0, list); + std::string command = Utils::String::VA("%c clantags \"%s\"", 22, list.data()); + Game::SV_GameSendServerCommand(-1, 0, command.data()); } - void Clantags::GetUserClantag(std::uint32_t clientnum, const char* playername) + const char* Clantags::GetUserClantag(std::uint32_t clientnum, const char* playername) { - if (Tags[clientnum].empty()) - { - CurrentName = playername; - return; - } - - CurrentName = Utils::String::VA("[%s] %s", Tags[clientnum].data(), playername); + if (Tags[clientnum].empty()) return playername; + return Utils::String::VA("[%s] %s", Tags[clientnum].data(), playername); } void __declspec(naked) Clantags::DrawPlayerNameOnScoreboard() { - static DWORD drawstringfunc = 0x5909E0; - __asm { - pushad; + push eax + pushad - push edi; - push [ebp]; + push edi + push [ebp] - call GetUserClantag; - add esp, 8; + call Clantags::GetUserClantag + add esp, 8 - popad; + mov [esp + 20h], eax - mov edi, CurrentName; + popad + pop edi - call drawstringfunc; - - push 591247h; - retn; + push 591247h // Return address + push 5909E0h // Draw string func + retn } } Clantags::Clantags() { // Create clantag dvar - Dvar::OnInit([]() { - CardTitles::CustomTitleDvar = Game::Dvar_RegisterString("iw4x_clantag", "", Game::dvar_flag::DVAR_FLAG_USERINFO | Game::dvar_flag::DVAR_FLAG_SAVED, "If set, your clantag will be shown on the scoreboard."); + Dvar::OnInit([]() + { + Dvar::Register("iw4x_clantag", "", Game::dvar_flag::DVAR_FLAG_USERINFO | Game::dvar_flag::DVAR_FLAG_SAVED, "If set, your clantag will be shown on the scoreboard."); }); // Servercommand hook - ServerCommands::OnCommand(22, [](Command::Params* params) { - - if (params->get(1) == "clantags"s && !Flags::HasFlag("dedicated")) + ServerCommands::OnCommand(22, [](Command::Params* params) + { + if (params->get(1) == "clantags"s && !Dedicated::IsEnabled()) { if (params->length() == 3) { @@ -103,18 +86,22 @@ namespace Components } return false; - }); - // Resize clantags array - Tags.resize(18); + for (int i = 0; i < ARRAYSIZE(Clantags::Tags); ++i) + { + Clantags::Tags[i].clear(); + } // Draw clantag before playername - Utils::Hook(0x591242, DrawPlayerNameOnScoreboard).install()->quick(); + Utils::Hook(0x591242, Clantags::DrawPlayerNameOnScoreboard).install()->quick(); } Clantags::~Clantags() { - Tags.clear(); + for (int i = 0; i < ARRAYSIZE(Clantags::Tags); ++i) + { + Clantags::Tags[i].clear(); + } } } diff --git a/src/Components/Modules/Clantags.hpp b/src/Components/Modules/Clantags.hpp index 1f1d4e56..f2a05d72 100644 --- a/src/Components/Modules/Clantags.hpp +++ b/src/Components/Modules/Clantags.hpp @@ -5,7 +5,6 @@ namespace Components class Clantags : public Component { public: - static std::vector < std::string > Clantags::Tags; static void ParseClantags(const char * infoString); static void SendClantagsToClients(); @@ -13,7 +12,9 @@ namespace Components ~Clantags(); private: - static void GetUserClantag(std::uint32_t clientnum, const char * playername); + static std::string Clantags::Tags[18]; + + static const char* GetUserClantag(std::uint32_t clientnum, const char * playername); static void DrawPlayerNameOnScoreboard(); }; From 3e1b5df6390547ecc2b3437e4d59c26f61cd5440 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 31 May 2017 09:59:03 +0200 Subject: [PATCH 16/20] [CardTites] Optimize code --- src/Components/Modules/CardTitles.cpp | 87 ++++++++++++++------------- src/Components/Modules/CardTitles.hpp | 4 +- 2 files changed, 47 insertions(+), 44 deletions(-) diff --git a/src/Components/Modules/CardTitles.cpp b/src/Components/Modules/CardTitles.cpp index 6c3fd8b4..21124293 100644 --- a/src/Components/Modules/CardTitles.cpp +++ b/src/Components/Modules/CardTitles.cpp @@ -2,8 +2,8 @@ namespace Components { - std::vector < std::string > CardTitles::CustomTitles; - Game::dvar_t* CardTitles::CustomTitleDvar; + std::string CardTitles::CustomTitles[18]; + Dvar::Var CardTitles::CustomTitleDvar; CClient* CardTitles::GetClientByIndex(std::uint32_t index) { @@ -14,7 +14,6 @@ namespace Components { std::int32_t returnResult = lookupResult; - CClient* c; std::string username = Dvar::Var("name").get(); if (data->name == username) @@ -25,7 +24,7 @@ namespace Components { for (auto clientNum = 0; clientNum < 18; clientNum++) { - c = GetClientByIndex(clientNum); + CClient* c = GetClientByIndex(clientNum); if (c != nullptr) { @@ -42,22 +41,30 @@ namespace Components return returnResult; } + void __declspec(naked) CardTitles::GetPlayerCardClientInfoStub() { __asm { - push esi; - push eax; - call GetPlayerCardClientInfo; - add esp, 8; + push eax + pushad - pop esi; - pop ebp; - mov[ebx + 4], eax; - pop ebx; + push esi + push eax + call GetPlayerCardClientInfo + add esp, 8 - push 62EB2Ch; - retn; + mov [esp + 20h], eax + popad + pop eax + + pop esi + pop ebp + mov[ebx + 4], eax + pop ebx + + push 62EB2Ch + retn } } @@ -65,7 +72,6 @@ namespace Components { std::uint8_t prefix = (request->tableRow >> (8 * 3)) & 0xFF; std::uint8_t data = (request->tableRow >> (8 * 2)) & 0xFF; - const char* title = nullptr; if (request->tablename == "mp/cardTitleTable.csv"s) { @@ -77,22 +83,19 @@ namespace Components if (prefix == 0xFE) { // 0xFF in front of the title to skip localization. Or else it will wait for a couple of seconds for the asset of type localize - if (*CustomTitleDvar->current.string) - { - title = Utils::String::VA("\x15%s", CustomTitleDvar->current.string); + const char* title = Utils::String::VA("\x15%s", CustomTitleDvar.get()); - // prepare return value - operand->internals.stringVal.string = title; - operand->dataType = Game::VAL_STRING; + // prepare return value + operand->internals.stringVal.string = title; + operand->dataType = Game::VAL_STRING; - return title; - } + return title; } else if (prefix == 0xFF) { if (!CustomTitles[data].empty()) { - title = Utils::String::VA("\x15%s", CustomTitles[data].data()); + const char* title = Utils::String::VA("\x15%s", CustomTitles[data].data()); // prepare return value operand->internals.stringVal.string = title; @@ -170,31 +173,25 @@ namespace Components void CardTitles::ParseCustomTitles(const char* msg) { - const char* playerTitle; - for (int i = 0; i < 18; i++) + for (int i = 0; i < 18; ++i) { - playerTitle = Game::Info_ValueForKey(msg, std::to_string(i).c_str()); + const char* playerTitle = Game::Info_ValueForKey(msg, std::to_string(i).c_str()); - if (playerTitle != nullptr) - { - CustomTitles[i] = playerTitle; - } - else - { - CustomTitles[i] = ""; - } + if (playerTitle) CustomTitles[i] = playerTitle; + else CustomTitles[i].clear(); } } CardTitles::CardTitles() { - Dvar::OnInit([]() { - CardTitles::CustomTitleDvar = Game::Dvar_RegisterString("customtitle", "", Game::dvar_flag::DVAR_FLAG_USERINFO | Game::dvar_flag::DVAR_FLAG_SAVED, "Custom card title"); + Dvar::OnInit([]() + { + CardTitles::CustomTitleDvar = Dvar::Register("customtitle", "", Game::dvar_flag::DVAR_FLAG_USERINFO | Game::dvar_flag::DVAR_FLAG_SAVED, "Custom card title"); }); - ServerCommands::OnCommand(21, [](Command::Params* params) { - - if (params->get(1) == "customTitles"s && !Flags::HasFlag("dedicated")) + ServerCommands::OnCommand(21, [](Command::Params* params) + { + if (params->get(1) == "customTitles"s && !Dedicated::IsEnabled()) { if (params->length() == 3) { @@ -207,7 +204,10 @@ namespace Components }); - CardTitles::CustomTitles.resize(18); + for(int i = 0; i < ARRAYSIZE(CardTitles::CustomTitles); ++i) + { + CardTitles::CustomTitles[i].clear(); + } Utils::Hook(0x62EB26, GetPlayerCardClientInfoStub).install()->quick(); @@ -218,6 +218,9 @@ namespace Components CardTitles::~CardTitles() { - CustomTitles.clear(); + for (int i = 0; i < ARRAYSIZE(CardTitles::CustomTitles); ++i) + { + CardTitles::CustomTitles[i].clear(); + } } } \ No newline at end of file diff --git a/src/Components/Modules/CardTitles.hpp b/src/Components/Modules/CardTitles.hpp index eecdf7d8..7f838ef8 100644 --- a/src/Components/Modules/CardTitles.hpp +++ b/src/Components/Modules/CardTitles.hpp @@ -53,8 +53,8 @@ namespace Components class CardTitles : public Component { public: - static Game::dvar_t* CustomTitleDvar; - static std::vector < std::string > CustomTitles; + static Dvar::Var CustomTitleDvar; + static std::string CustomTitles[18]; static void SendCustomTitlesToClients(); static void ParseCustomTitles(const char * msg); From fbec01b237cd8de7770e3fbb7f0e00ff840a6556 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 31 May 2017 10:33:18 +0200 Subject: [PATCH 17/20] [CardTitles] More fixes --- src/Components/Modules/CardTitles.cpp | 76 ++++++++++++++------------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/src/Components/Modules/CardTitles.cpp b/src/Components/Modules/CardTitles.cpp index 21124293..d00bcd7a 100644 --- a/src/Components/Modules/CardTitles.cpp +++ b/src/Components/Modules/CardTitles.cpp @@ -7,7 +7,7 @@ namespace Components CClient* CardTitles::GetClientByIndex(std::uint32_t index) { - return reinterpret_cast(0x8E77B0 + (sizeof CClient * index)); + return &reinterpret_cast(0x8E77B0)[index]; } std::int32_t CardTitles::GetPlayerCardClientInfo(std::int32_t lookupResult, playercarddata_s* data) @@ -25,7 +25,6 @@ namespace Components for (auto clientNum = 0; clientNum < 18; clientNum++) { CClient* c = GetClientByIndex(clientNum); - if (c != nullptr) { if (!strcmp(data->name, c->Name)) @@ -82,14 +81,17 @@ namespace Components { if (prefix == 0xFE) { - // 0xFF in front of the title to skip localization. Or else it will wait for a couple of seconds for the asset of type localize - const char* title = Utils::String::VA("\x15%s", CustomTitleDvar.get()); + if (!CustomTitleDvar.get().empty()) + { + // 0xFF in front of the title to skip localization. Or else it will wait for a couple of seconds for the asset of type localize + const char* title = Utils::String::VA("\x15%s", CustomTitleDvar.get()); - // prepare return value - operand->internals.stringVal.string = title; - operand->dataType = Game::VAL_STRING; + // prepare return value + operand->internals.stringVal.string = title; + operand->dataType = Game::VAL_STRING; - return title; + return title; + } } else if (prefix == 0xFF) { @@ -115,41 +117,43 @@ namespace Components return nullptr; } - void __declspec(naked) CardTitles::TableLookupByRowHookStub() + __declspec(naked) void CardTitles::TableLookupByRowHookStub() { __asm { - push esi; - push ebx; - - pushad; - call TableLookupByRowHook; - cmp eax, 0; - popad; + push eax + pushad - jz OriginalTitle; + push esi + push ebx - add esp, 8; + call TableLookupByRowHook + add esp, 8 - pop ecx; - mov ecx, DWORD ptr[esi + 4]; - retn; + mov [esp + 20h], eax + popad + pop eax + + cmp eax, 0 + jz OriginalTitle + + pop ecx + mov ecx, DWORD ptr[esi + 4] + retn OriginalTitle: - add esp, 8; + mov eax, [esi + 50h] + cmp eax, 3 - mov eax, [esi + 50h]; - cmp eax, 3; - - push 62DCC7h; - retn; + push 62DCC7h + retn } } void CardTitles::SendCustomTitlesToClients() { - const char* list = ""; + std::string list; for (int i = 0; i < 18; i++) { @@ -164,11 +168,11 @@ namespace Components memset(playerTitle, 0, 18); } - list = Utils::String::VA("%s\\%s\\%s", list, std::to_string(i).c_str(), playerTitle); + list.append(Utils::String::VA("\\%s\\%s", std::to_string(i).c_str(), playerTitle)); } - list = Utils::String::VA("%c customTitles \"%s\"", 21, list); - Game::SV_GameSendServerCommand(-1, 0, list); + std::string command = Utils::String::VA("%c customTitles \"%s\"", 21, list.data()); + Game::SV_GameSendServerCommand(-1, 0, command.data()); } void CardTitles::ParseCustomTitles(const char* msg) @@ -177,8 +181,8 @@ namespace Components { const char* playerTitle = Game::Info_ValueForKey(msg, std::to_string(i).c_str()); - if (playerTitle) CustomTitles[i] = playerTitle; - else CustomTitles[i].clear(); + if (playerTitle) CardTitles::CustomTitles[i] = playerTitle; + else CardTitles::CustomTitles[i].clear(); } } @@ -209,10 +213,10 @@ namespace Components CardTitles::CustomTitles[i].clear(); } - Utils::Hook(0x62EB26, GetPlayerCardClientInfoStub).install()->quick(); + Utils::Hook(0x62EB26, CardTitles::GetPlayerCardClientInfoStub).install()->quick(); // Table lookup stuff - Utils::Hook(0x62DCC1, TableLookupByRowHookStub).install()->quick(); + Utils::Hook(0x62DCC1, CardTitles::TableLookupByRowHookStub).install()->quick(); Utils::Hook::Nop(0x62DCC6, 1); } @@ -223,4 +227,4 @@ namespace Components CardTitles::CustomTitles[i].clear(); } } -} \ No newline at end of file +} From 8cf9c0d93f6243ad1f9dc35b00b5d91ae288e48a Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 31 May 2017 10:33:25 +0200 Subject: [PATCH 18/20] [Clantags] More fixes --- src/Components/Modules/Clantags.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Components/Modules/Clantags.cpp b/src/Components/Modules/Clantags.cpp index 97a96a23..84c009bb 100644 --- a/src/Components/Modules/Clantags.cpp +++ b/src/Components/Modules/Clantags.cpp @@ -10,8 +10,8 @@ namespace Components { const char* clantag = Game::Info_ValueForKey(infoString, std::to_string(i).data()); - if (clantag) Tags[i] = clantag; - else Tags[i].clear(); + if (clantag) Clantags::Tags[i] = clantag; + else Clantags::Tags[i].clear(); } } @@ -19,7 +19,7 @@ namespace Components { std::string list; - for (int i = 0; i < 18; i++) + for (int i = 0; i < 18; ++i) { char clantag[5] = { 0 }; @@ -37,11 +37,11 @@ namespace Components const char* Clantags::GetUserClantag(std::uint32_t clientnum, const char* playername) { - if (Tags[clientnum].empty()) return playername; - return Utils::String::VA("[%s] %s", Tags[clientnum].data(), playername); + if (Clantags::Tags[clientnum].empty()) return playername; + return Utils::String::VA("[%s] %s", Clantags::Tags[clientnum].data(), playername); } - void __declspec(naked) Clantags::DrawPlayerNameOnScoreboard() + __declspec(naked) void Clantags::DrawPlayerNameOnScoreboard() { __asm { From 1628afb4c351496a232e4581be5ac1ca8a63d970 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 31 May 2017 10:42:43 +0200 Subject: [PATCH 19/20] [ServerCommands] Optimize code and adapt to our style --- src/Components/Modules/Dedicated.cpp | 6 +- src/Components/Modules/ServerCommands.cpp | 79 ++++++++++++----------- src/Components/Modules/ServerCommands.hpp | 5 +- 3 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index 7758c264..ba017b3f 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -529,8 +529,8 @@ namespace Components } // Intercept server commands - ServerCommands::OnCommand(20, [](Command::Params* params) { - + ServerCommands::OnCommand(20, [](Command::Params* params) + { for (int client = 0; client < 18; client++) { Dedicated::PlayerGuids[client][0].bits = strtoull(params->get(2 * client + 1), nullptr, 16); @@ -543,9 +543,7 @@ namespace Components } return true; - }); - } QuickPatch::OnFrame([]() diff --git a/src/Components/Modules/ServerCommands.cpp b/src/Components/Modules/ServerCommands.cpp index d3b80bb8..37b09567 100644 --- a/src/Components/Modules/ServerCommands.cpp +++ b/src/Components/Modules/ServerCommands.cpp @@ -2,25 +2,25 @@ namespace Components { - std::unordered_map < std::int32_t, std::function < bool(Command::Params*) > > ServerCommands::Commands; - std::uint32_t ServerCommands::lastServerCommand; + std::unordered_map> ServerCommands::Commands; + std::uint32_t ServerCommands::LastServerCommand; - void ServerCommands::OnCommand(std::int32_t cmd, std::function < bool(Command::Params*) > cb) + void ServerCommands::OnCommand(std::int32_t cmd, std::function cb) { - Commands[cmd] = cb; + ServerCommands::Commands[cmd] = cb; } bool ServerCommands::OnServerCommand() { Command::ClientParams params(*Game::cmd_id); - for (auto &ServerCommandCB : Commands) + for (auto &serverCommandCB : ServerCommands::Commands) { if (params.length() >= 1) { - if (params.get(0)[0] == ServerCommandCB.first) + if (params.get(0)[0] == serverCommandCB.first) { - return ServerCommandCB.second(¶ms); + return serverCommandCB.second(¶ms); } } } @@ -28,78 +28,79 @@ namespace Components return false; } - void __declspec(naked) ServerCommands::OnServerCommandStub() + __declspec(naked) void ServerCommands::OnServerCommandStub() { __asm { - call OnServerCommand; - test al, al; - jnz jumpback; + push eax + pushad + call ServerCommands::OnServerCommand + mov [esp + 20h], eax + popad + pop eax - push 5944AEh; - retn; + test al, al + jnz jumpback + + push 5944AEh + retn jumpback: - push 594536h; - retn; + push 594536h + retn } } - void __declspec(naked) ServerCommands::OnServerCommandPreFailStub() + __declspec(naked) void ServerCommands::OnServerCommandPreFailStub() { __asm { - mov lastServerCommand, ecx; - cmp ecx, 79h; + mov ServerCommands::LastServerCommand, ecx + cmp ecx, 79h - jl above; + jl above - push 59449Fh; - retn; + push 59449Fh + retn above: - push 593C28h; - retn; + push 593C28h + retn } } void ServerCommands::OnServerCommandFailPrint(int type, const char *, ...) { Command::ClientParams params(*Game::cmd_id); - const char *cmd = ""; - - for (std::size_t i = 1; i < params.length(); i++) - cmd = Utils::String::VA("%s %s", cmd, params.get(i)); - - Game::Com_Printf(type, "Unknown client game command: %i %s\n", lastServerCommand, cmd); + Game::Com_Printf(type, "Unknown client game command: %i %s\n", LastServerCommand, params.join(1)); } - void __declspec(naked) ServerCommands::OnServerCommandFailPrintStub() + __declspec(naked) void ServerCommands::OnServerCommandFailPrintStub() { __asm { - pushad; - call OnServerCommandFailPrint; - popad; + pushad + call ServerCommands::OnServerCommandFailPrint + popad - push 5944C0h; - retn; + push 5944C0h + retn } } ServerCommands::ServerCommands() { // Server command receive hook - Utils::Hook(0x59449F, OnServerCommandStub).install()->quick(); + Utils::Hook(0x59449F, ServerCommands::OnServerCommandStub).install()->quick(); // Server command fail hooks - Utils::Hook(0x593C1F, OnServerCommandPreFailStub).install()->quick(); - Utils::Hook(0x5944BB, OnServerCommandFailPrintStub).install()->quick(); + Utils::Hook(0x593C1F, ServerCommands::OnServerCommandPreFailStub).install()->quick(); + Utils::Hook(0x5944BB, ServerCommands::OnServerCommandFailPrintStub).install()->quick(); Utils::Hook::Set(0x5944D3, 0xEB); } ServerCommands::~ServerCommands() { - Commands.clear(); + ServerCommands::Commands.clear(); } } diff --git a/src/Components/Modules/ServerCommands.hpp b/src/Components/Modules/ServerCommands.hpp index 94b74627..fac41915 100644 --- a/src/Components/Modules/ServerCommands.hpp +++ b/src/Components/Modules/ServerCommands.hpp @@ -11,12 +11,13 @@ namespace Components static void OnCommand(std::int32_t cmd, std::function cb); private: - static std::unordered_map < std::int32_t, std::function < bool(Command::Params*) > > Commands; + static std::unordered_map> Commands; + static std::uint32_t LastServerCommand; + static bool OnServerCommand(); static void OnServerCommandStub(); static void OnServerCommandPreFailStub(); static void OnServerCommandFailPrint(int type, const char * trash, ...); static void OnServerCommandFailPrintStub(); - static std::uint32_t lastServerCommand; }; } From 4bb115723472d88b0989667f2c486e75413c179d Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 31 May 2017 12:02:14 +0200 Subject: [PATCH 20/20] [Loader] Make use of typeinfo for singleton and name resolving --- src/Components/Loader.cpp | 6 +++--- src/Components/Loader.hpp | 21 ++++++++++++++++++++- src/Components/Modules/AntiCheat.hpp | 4 ---- src/Components/Modules/ArenaLength.hpp | 4 ---- src/Components/Modules/AssetHandler.hpp | 4 ---- src/Components/Modules/Auth.hpp | 4 ---- src/Components/Modules/Bans.hpp | 4 ---- src/Components/Modules/Bots.hpp | 4 ---- src/Components/Modules/Changelog.hpp | 4 ---- src/Components/Modules/Colors.hpp | 4 ---- src/Components/Modules/Command.hpp | 4 ---- src/Components/Modules/ConnectProtocol.hpp | 4 ---- src/Components/Modules/Console.hpp | 4 ---- src/Components/Modules/D3D9Ex.hpp | 4 ---- src/Components/Modules/Dedicated.hpp | 4 ---- src/Components/Modules/Discovery.hpp | 4 ---- src/Components/Modules/Download.hpp | 4 ---- src/Components/Modules/Dvar.hpp | 4 ---- src/Components/Modules/Exception.hpp | 3 --- src/Components/Modules/FastFiles.hpp | 4 ---- src/Components/Modules/FileSystem.hpp | 4 ---- src/Components/Modules/Flags.hpp | 4 ---- src/Components/Modules/FrameTime.hpp | 4 ---- src/Components/Modules/Friends.hpp | 4 ---- src/Components/Modules/Gametypes.hpp | 4 ---- src/Components/Modules/IPCPipe.hpp | 4 ---- src/Components/Modules/Lean.hpp | 4 ---- src/Components/Modules/Localization.hpp | 4 ---- src/Components/Modules/Logger.hpp | 4 ---- src/Components/Modules/Maps.hpp | 4 ---- src/Components/Modules/Materials.hpp | 4 ---- src/Components/Modules/Menus.hpp | 4 ---- src/Components/Modules/ModList.hpp | 4 ---- src/Components/Modules/ModelSurfs.hpp | 4 ---- src/Components/Modules/Monitor.hpp | 4 ---- src/Components/Modules/MusicalTalent.hpp | 4 ---- src/Components/Modules/Network.hpp | 4 ---- src/Components/Modules/News.hpp | 4 ---- src/Components/Modules/Node.hpp | 4 ---- src/Components/Modules/Party.hpp | 4 ---- src/Components/Modules/PlayerName.hpp | 4 ---- src/Components/Modules/Playlist.hpp | 4 ---- src/Components/Modules/QuickPatch.hpp | 4 ---- src/Components/Modules/RCon.hpp | 4 ---- src/Components/Modules/RawFiles.hpp | 4 ---- src/Components/Modules/Renderer.hpp | 4 ---- src/Components/Modules/Script.hpp | 4 ---- src/Components/Modules/ServerInfo.hpp | 4 ---- src/Components/Modules/ServerList.hpp | 4 ---- src/Components/Modules/Singleton.hpp | 4 ---- src/Components/Modules/Slowmotion.hpp | 4 ---- src/Components/Modules/StartupMessages.hpp | 4 ---- src/Components/Modules/Stats.hpp | 4 ---- src/Components/Modules/StringTable.hpp | 4 ---- src/Components/Modules/StructuredData.hpp | 4 ---- src/Components/Modules/Theatre.hpp | 4 ---- src/Components/Modules/Threading.hpp | 4 ---- src/Components/Modules/Toast.hpp | 4 ---- src/Components/Modules/UIFeeder.hpp | 4 ---- src/Components/Modules/UIScript.hpp | 4 ---- src/Components/Modules/Weapon.hpp | 4 ---- src/Components/Modules/Window.hpp | 4 ---- src/Components/Modules/ZoneBuilder.hpp | 1 - src/Components/Modules/Zones.hpp | 4 ---- 64 files changed, 23 insertions(+), 248 deletions(-) diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index d1fbff2e..ea906ecd 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -114,7 +114,7 @@ namespace Components #ifdef DEBUG if(!Loader::PerformingUnitTests()) { - Logger::Print("Unregistering component: %s\n", component->getName()); + Logger::Print("Unregistering component: %s\n", component->getName().data()); } #endif delete component; @@ -167,7 +167,7 @@ namespace Components for (auto component : Loader::Components) { #if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - Logger::Print("Testing '%s'...\n", component->getName()); + Logger::Print("Testing '%s'...\n", component->getName().data()); #endif auto startTime = std::chrono::high_resolution_clock::now(); bool testRes = component->unitTest(); @@ -195,7 +195,7 @@ namespace Components #ifdef DEBUG if(!Loader::PerformingUnitTests()) { - Logger::Print("Component registered: %s\n", component->getName()); + Logger::Print("Component registered: %s\n", component->getName().data()); } #endif Loader::Components.push_back(component); diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index e4988170..afb79c17 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -9,7 +9,12 @@ namespace Components virtual ~Component() {}; #if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - virtual const char* getName() { return "Unknown"; }; + virtual std::string getName() + { + std::string name = typeid(*this).name(); + Utils::String::Replace(name, "class Components::", ""); + return name; + }; #endif // It's illegal to spawn threads in DLLMain, and apparently it causes problems if they are destroyed there as well. @@ -34,6 +39,20 @@ namespace Components static bool IsPostgame(); static bool IsComInitialized(); + template + static T* GetInstance() + { + for (auto& component : Loader::Components) + { + if (typeid(*component) == typeid(T)) + { + return reinterpret_cast(component); + } + } + + return nullptr; + } + static Utils::Memory::Allocator* GetAlloctor(); private: diff --git a/src/Components/Modules/AntiCheat.hpp b/src/Components/Modules/AntiCheat.hpp index 39a15d8f..82149cc2 100644 --- a/src/Components/Modules/AntiCheat.hpp +++ b/src/Components/Modules/AntiCheat.hpp @@ -16,10 +16,6 @@ namespace Components AntiCheat(); ~AntiCheat(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "AntiCheat"; }; -#endif - static void CrashClient(); static void InitLoadLibHook(); diff --git a/src/Components/Modules/ArenaLength.hpp b/src/Components/Modules/ArenaLength.hpp index da9918e7..f495b5c7 100644 --- a/src/Components/Modules/ArenaLength.hpp +++ b/src/Components/Modules/ArenaLength.hpp @@ -7,10 +7,6 @@ namespace Components public: ArenaLength(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "ArenaLength"; }; -#endif - static Game::newMapArena_t NewArenas[128]; private: diff --git a/src/Components/Modules/AssetHandler.hpp b/src/Components/Modules/AssetHandler.hpp index 9b83bc34..c1f72315 100644 --- a/src/Components/Modules/AssetHandler.hpp +++ b/src/Components/Modules/AssetHandler.hpp @@ -22,10 +22,6 @@ namespace Components AssetHandler(); ~AssetHandler(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "AssetHandler"; }; -#endif - static void OnFind(Game::XAssetType type, Utils::Slot callback); static void OnLoad(Utils::Slot callback); diff --git a/src/Components/Modules/Auth.hpp b/src/Components/Modules/Auth.hpp index a6d266a4..56ab27de 100644 --- a/src/Components/Modules/Auth.hpp +++ b/src/Components/Modules/Auth.hpp @@ -8,10 +8,6 @@ namespace Components Auth(); ~Auth(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Auth"; }; -#endif - void preDestroy() override; bool unitTest() override; diff --git a/src/Components/Modules/Bans.hpp b/src/Components/Modules/Bans.hpp index a02f05fe..6482b896 100644 --- a/src/Components/Modules/Bans.hpp +++ b/src/Components/Modules/Bans.hpp @@ -10,10 +10,6 @@ namespace Components Bans(); ~Bans(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Bans"; }; -#endif - static void BanClientNum(int num, std::string reason); static bool IsBanned(Entry entry); diff --git a/src/Components/Modules/Bots.hpp b/src/Components/Modules/Bots.hpp index bdda8441..d79f51e2 100644 --- a/src/Components/Modules/Bots.hpp +++ b/src/Components/Modules/Bots.hpp @@ -8,10 +8,6 @@ namespace Components Bots(); ~Bots(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Bots"; }; -#endif - private: static std::vector BotNames; diff --git a/src/Components/Modules/Changelog.hpp b/src/Components/Modules/Changelog.hpp index 5d42abab..dd74a8be 100644 --- a/src/Components/Modules/Changelog.hpp +++ b/src/Components/Modules/Changelog.hpp @@ -8,10 +8,6 @@ namespace Components Changelog(); ~Changelog(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Changelog"; }; -#endif - static void LoadChangelog(); private: diff --git a/src/Components/Modules/Colors.hpp b/src/Components/Modules/Colors.hpp index 8bc95333..6d8d4f62 100644 --- a/src/Components/Modules/Colors.hpp +++ b/src/Components/Modules/Colors.hpp @@ -8,10 +8,6 @@ namespace Components Colors(); ~Colors(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Colors"; }; -#endif - static void Strip(const char* in, char* out, int max); static std::string Strip(std::string in); diff --git a/src/Components/Modules/Command.hpp b/src/Components/Modules/Command.hpp index e1cccecd..cd605082 100644 --- a/src/Components/Modules/Command.hpp +++ b/src/Components/Modules/Command.hpp @@ -50,10 +50,6 @@ namespace Components Command(); ~Command(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Command"; }; -#endif - static Game::cmd_function_t* Allocate(); static void Add(const char* name, Utils::Slot callback); diff --git a/src/Components/Modules/ConnectProtocol.hpp b/src/Components/Modules/ConnectProtocol.hpp index 454d1b34..d801df82 100644 --- a/src/Components/Modules/ConnectProtocol.hpp +++ b/src/Components/Modules/ConnectProtocol.hpp @@ -7,10 +7,6 @@ namespace Components public: ConnectProtocol(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "ConnectProtocol"; }; -#endif - static bool IsEvaluated(); static bool Used(); diff --git a/src/Components/Modules/Console.hpp b/src/Components/Modules/Console.hpp index 1b06c22a..0ef30bb5 100644 --- a/src/Components/Modules/Console.hpp +++ b/src/Components/Modules/Console.hpp @@ -11,10 +11,6 @@ namespace Components Console(); ~Console(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Console"; }; -#endif - static void SetSkipShutdown(); static void FreeNativeConsole(); diff --git a/src/Components/Modules/D3D9Ex.hpp b/src/Components/Modules/D3D9Ex.hpp index 0f7364e3..f3a232f6 100644 --- a/src/Components/Modules/D3D9Ex.hpp +++ b/src/Components/Modules/D3D9Ex.hpp @@ -7,10 +7,6 @@ namespace Components public: D3D9Ex(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "D3D9Ex"; }; -#endif - private: class D3D9Device : public IDirect3DDevice9 diff --git a/src/Components/Modules/Dedicated.hpp b/src/Components/Modules/Dedicated.hpp index 6b07885b..0a3cd54d 100644 --- a/src/Components/Modules/Dedicated.hpp +++ b/src/Components/Modules/Dedicated.hpp @@ -10,10 +10,6 @@ namespace Components Dedicated(); ~Dedicated(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Dedicated"; }; -#endif - static SteamID PlayerGuids[18][2]; static bool IsEnabled(); diff --git a/src/Components/Modules/Discovery.hpp b/src/Components/Modules/Discovery.hpp index a9dc4344..655122bf 100644 --- a/src/Components/Modules/Discovery.hpp +++ b/src/Components/Modules/Discovery.hpp @@ -8,10 +8,6 @@ namespace Components Discovery(); ~Discovery(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Discovery"; }; -#endif - void preDestroy() override; static void Perform(); diff --git a/src/Components/Modules/Download.hpp b/src/Components/Modules/Download.hpp index 8d807ef9..299da811 100644 --- a/src/Components/Modules/Download.hpp +++ b/src/Components/Modules/Download.hpp @@ -9,10 +9,6 @@ namespace Components Download(); ~Download(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Download"; }; -#endif - void preDestroy() override; static void InitiateClientDownload(std::string mod, bool map = false); diff --git a/src/Components/Modules/Dvar.hpp b/src/Components/Modules/Dvar.hpp index b12ed8c7..cbbb87ee 100644 --- a/src/Components/Modules/Dvar.hpp +++ b/src/Components/Modules/Dvar.hpp @@ -44,10 +44,6 @@ namespace Components Dvar(); ~Dvar(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Dvar"; }; -#endif - static void OnInit(Utils::Slot callback); // Only strings and bools use this type of declaration diff --git a/src/Components/Modules/Exception.hpp b/src/Components/Modules/Exception.hpp index eeaa57c7..2038842a 100644 --- a/src/Components/Modules/Exception.hpp +++ b/src/Components/Modules/Exception.hpp @@ -8,9 +8,6 @@ namespace Components Exception(); ~Exception(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Exception"; }; -#endif static LPTOP_LEVEL_EXCEPTION_FILTER Hook(); static void SetMiniDumpType(bool codeseg, bool dataseg); diff --git a/src/Components/Modules/FastFiles.hpp b/src/Components/Modules/FastFiles.hpp index 76175219..eb5569a1 100644 --- a/src/Components/Modules/FastFiles.hpp +++ b/src/Components/Modules/FastFiles.hpp @@ -8,10 +8,6 @@ namespace Components FastFiles(); ~FastFiles(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "FastFiles"; }; -#endif - static void AddZonePath(std::string path); static std::string Current(); static bool Ready(); diff --git a/src/Components/Modules/FileSystem.hpp b/src/Components/Modules/FileSystem.hpp index 09afa221..800701b9 100644 --- a/src/Components/Modules/FileSystem.hpp +++ b/src/Components/Modules/FileSystem.hpp @@ -88,10 +88,6 @@ namespace Components FileSystem(); ~FileSystem(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "FileSystem"; }; -#endif - static std::vector GetFileList(std::string path, std::string extension); static std::vector GetSysFileList(std::string path, std::string extension, bool folders = false); static void DeleteFile(std::string folder, std::string file); diff --git a/src/Components/Modules/Flags.hpp b/src/Components/Modules/Flags.hpp index e5cb7f67..2148622d 100644 --- a/src/Components/Modules/Flags.hpp +++ b/src/Components/Modules/Flags.hpp @@ -8,10 +8,6 @@ namespace Components Flags(); ~Flags(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Flags"; }; -#endif - static bool HasFlag(std::string flag); private: diff --git a/src/Components/Modules/FrameTime.hpp b/src/Components/Modules/FrameTime.hpp index 4da5bf94..4b10d129 100644 --- a/src/Components/Modules/FrameTime.hpp +++ b/src/Components/Modules/FrameTime.hpp @@ -7,10 +7,6 @@ namespace Components public: FrameTime(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "FrameTime"; }; -#endif - private: static void SVFrameWaitStub(); static void SVFrameWaitFunc(); diff --git a/src/Components/Modules/Friends.hpp b/src/Components/Modules/Friends.hpp index 21ab888f..5c4dfb4b 100644 --- a/src/Components/Modules/Friends.hpp +++ b/src/Components/Modules/Friends.hpp @@ -8,10 +8,6 @@ namespace Components Friends(); ~Friends(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Friends"; }; -#endif - static void UpdateFriends(); static void UpdateRank(); static void UpdateServer(Network::Address server, std::string hostname, std::string mapname); diff --git a/src/Components/Modules/Gametypes.hpp b/src/Components/Modules/Gametypes.hpp index 7914a3bf..5576512e 100644 --- a/src/Components/Modules/Gametypes.hpp +++ b/src/Components/Modules/Gametypes.hpp @@ -7,10 +7,6 @@ namespace Components public: Gametypes(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Gametypes"; }; -#endif - private: static unsigned int GetGametypeCount(); static const char* GetGametypeText(unsigned int index, int column); diff --git a/src/Components/Modules/IPCPipe.hpp b/src/Components/Modules/IPCPipe.hpp index 58bbc713..2e51e16c 100644 --- a/src/Components/Modules/IPCPipe.hpp +++ b/src/Components/Modules/IPCPipe.hpp @@ -65,10 +65,6 @@ namespace Components public: IPCPipe(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "IPCPipe"; }; -#endif - void preDestroy() override; static bool Write(std::string command, std::string data); diff --git a/src/Components/Modules/Lean.hpp b/src/Components/Modules/Lean.hpp index 7fce86d2..4ae28d51 100644 --- a/src/Components/Modules/Lean.hpp +++ b/src/Components/Modules/Lean.hpp @@ -10,10 +10,6 @@ namespace Components public: Lean(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Lean"; }; -#endif - private: static Game::kbutton_t in_leanleft; static Game::kbutton_t in_leanright; diff --git a/src/Components/Modules/Localization.hpp b/src/Components/Modules/Localization.hpp index 8aa31afb..a96af75e 100644 --- a/src/Components/Modules/Localization.hpp +++ b/src/Components/Modules/Localization.hpp @@ -8,10 +8,6 @@ namespace Components Localization(); ~Localization(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Localization"; }; -#endif - static void Set(std::string key, std::string value); static const char* Get(const char* key); diff --git a/src/Components/Modules/Logger.hpp b/src/Components/Modules/Logger.hpp index accafa62..6d683437 100644 --- a/src/Components/Modules/Logger.hpp +++ b/src/Components/Modules/Logger.hpp @@ -8,10 +8,6 @@ namespace Components Logger(); ~Logger(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Logger"; }; -#endif - static void MessagePrint(int channel, std::string message); static void Print(int channel, const char* message, ...); static void Print(const char* message, ...); diff --git a/src/Components/Modules/Maps.hpp b/src/Components/Modules/Maps.hpp index 1becaa63..46211308 100644 --- a/src/Components/Modules/Maps.hpp +++ b/src/Components/Modules/Maps.hpp @@ -49,10 +49,6 @@ namespace Components Maps(); ~Maps(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Maps"; }; -#endif - static void HandleAsSPMap(); static void AddDependency(std::string expression, std::string zone); diff --git a/src/Components/Modules/Materials.hpp b/src/Components/Modules/Materials.hpp index 55d479fa..fe9ccd6a 100644 --- a/src/Components/Modules/Materials.hpp +++ b/src/Components/Modules/Materials.hpp @@ -8,10 +8,6 @@ namespace Components Materials(); ~Materials(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Materials"; }; -#endif - static int FormatImagePath(char* buffer, size_t size, int, int, const char* image); private: diff --git a/src/Components/Modules/Menus.hpp b/src/Components/Modules/Menus.hpp index 4a099a2e..4a96f260 100644 --- a/src/Components/Modules/Menus.hpp +++ b/src/Components/Modules/Menus.hpp @@ -11,10 +11,6 @@ namespace Components Menus(); ~Menus(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Menus"; }; -#endif - static void FreeEverything(); static void Add(std::string menu); diff --git a/src/Components/Modules/ModList.hpp b/src/Components/Modules/ModList.hpp index 5022cfe1..8f2a0e97 100644 --- a/src/Components/Modules/ModList.hpp +++ b/src/Components/Modules/ModList.hpp @@ -8,10 +8,6 @@ namespace Components ModList(); ~ModList(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "ModList"; }; -#endif - static void RunMod(std::string mod); private: diff --git a/src/Components/Modules/ModelSurfs.hpp b/src/Components/Modules/ModelSurfs.hpp index 41093e1b..a2f9f205 100644 --- a/src/Components/Modules/ModelSurfs.hpp +++ b/src/Components/Modules/ModelSurfs.hpp @@ -8,10 +8,6 @@ namespace Components ModelSurfs(); ~ModelSurfs(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "ModelSurfs"; }; -#endif - private: static std::unordered_map BufferMap; static std::unordered_map AllocMap; diff --git a/src/Components/Modules/Monitor.hpp b/src/Components/Modules/Monitor.hpp index d95ca242..e26aa3bf 100644 --- a/src/Components/Modules/Monitor.hpp +++ b/src/Components/Modules/Monitor.hpp @@ -7,10 +7,6 @@ namespace Components public: Monitor(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Monitor"; }; -#endif - static bool IsEnabled(); private: diff --git a/src/Components/Modules/MusicalTalent.hpp b/src/Components/Modules/MusicalTalent.hpp index aee7aac9..b3c07747 100644 --- a/src/Components/Modules/MusicalTalent.hpp +++ b/src/Components/Modules/MusicalTalent.hpp @@ -8,10 +8,6 @@ namespace Components MusicalTalent(); ~MusicalTalent(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "MusicalTalent"; }; -#endif - static void Replace(std::string sound, const char* file); private: diff --git a/src/Components/Modules/Network.hpp b/src/Components/Modules/Network.hpp index 9293db70..a7a40441 100644 --- a/src/Components/Modules/Network.hpp +++ b/src/Components/Modules/Network.hpp @@ -58,10 +58,6 @@ namespace Components Network(); ~Network(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Network"; }; -#endif - static void Handle(std::string packet, Utils::Slot callback); static void OnStart(Utils::Slot callback); diff --git a/src/Components/Modules/News.hpp b/src/Components/Modules/News.hpp index 6aa93cef..4880da1f 100644 --- a/src/Components/Modules/News.hpp +++ b/src/Components/Modules/News.hpp @@ -8,10 +8,6 @@ namespace Components News(); ~News(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "News"; }; -#endif - void preDestroy() override; bool unitTest() override; diff --git a/src/Components/Modules/Node.hpp b/src/Components/Modules/Node.hpp index 01ab5e79..78cf175c 100644 --- a/src/Components/Modules/Node.hpp +++ b/src/Components/Modules/Node.hpp @@ -21,10 +21,6 @@ namespace Components Node(); ~Node(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Node"; }; -#endif - bool unitTest() override; static void SyncNodeList(); diff --git a/src/Components/Modules/Party.hpp b/src/Components/Modules/Party.hpp index 6ea399c0..8994ce0f 100644 --- a/src/Components/Modules/Party.hpp +++ b/src/Components/Modules/Party.hpp @@ -8,10 +8,6 @@ namespace Components Party(); ~Party(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Party"; }; -#endif - static Network::Address Target(); static void Connect(Network::Address target); static const char* GetLobbyInfo(SteamID lobby, std::string key); diff --git a/src/Components/Modules/PlayerName.hpp b/src/Components/Modules/PlayerName.hpp index e7b6efa4..68c3c74d 100644 --- a/src/Components/Modules/PlayerName.hpp +++ b/src/Components/Modules/PlayerName.hpp @@ -8,10 +8,6 @@ namespace Components PlayerName(); ~PlayerName(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "PlayerName"; }; -#endif - private: static std::string PlayerNames[18]; diff --git a/src/Components/Modules/Playlist.hpp b/src/Components/Modules/Playlist.hpp index 4d82fd85..ceeb99a8 100644 --- a/src/Components/Modules/Playlist.hpp +++ b/src/Components/Modules/Playlist.hpp @@ -10,10 +10,6 @@ namespace Components Playlist(); ~Playlist(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Playlist"; }; -#endif - static void LoadPlaylist(); static std::string ReceivedPlaylistBuffer; diff --git a/src/Components/Modules/QuickPatch.hpp b/src/Components/Modules/QuickPatch.hpp index 0f01474a..60c44584 100644 --- a/src/Components/Modules/QuickPatch.hpp +++ b/src/Components/Modules/QuickPatch.hpp @@ -10,10 +10,6 @@ namespace Components QuickPatch(); ~QuickPatch(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "QuickPatch"; }; -#endif - bool unitTest() override; static void UnlockStats(); diff --git a/src/Components/Modules/RCon.hpp b/src/Components/Modules/RCon.hpp index 996f7b65..1cc486e5 100644 --- a/src/Components/Modules/RCon.hpp +++ b/src/Components/Modules/RCon.hpp @@ -8,10 +8,6 @@ namespace Components RCon(); ~RCon(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "RCon"; }; -#endif - private: class Container { diff --git a/src/Components/Modules/RawFiles.hpp b/src/Components/Modules/RawFiles.hpp index a6bfe437..30e4458b 100644 --- a/src/Components/Modules/RawFiles.hpp +++ b/src/Components/Modules/RawFiles.hpp @@ -7,10 +7,6 @@ namespace Components public: RawFiles(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "RawFiles"; }; -#endif - static void* RawFiles::LoadModdableRawfileFunc(const char* filename); }; } diff --git a/src/Components/Modules/Renderer.hpp b/src/Components/Modules/Renderer.hpp index fcc28a56..23673599 100644 --- a/src/Components/Modules/Renderer.hpp +++ b/src/Components/Modules/Renderer.hpp @@ -11,10 +11,6 @@ namespace Components Renderer(); ~Renderer(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Renderer"; }; -#endif - static int Width(); static int Height(); diff --git a/src/Components/Modules/Script.hpp b/src/Components/Modules/Script.hpp index 9966877f..14bc5119 100644 --- a/src/Components/Modules/Script.hpp +++ b/src/Components/Modules/Script.hpp @@ -26,10 +26,6 @@ namespace Components Script(); ~Script(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Script"; }; -#endif - static int LoadScriptAndLabel(std::string script, std::string label); static void AddFunction(std::string name, Game::scr_function_t function, bool isDev = false); diff --git a/src/Components/Modules/ServerInfo.hpp b/src/Components/Modules/ServerInfo.hpp index 18c92245..d7e0cf17 100644 --- a/src/Components/Modules/ServerInfo.hpp +++ b/src/Components/Modules/ServerInfo.hpp @@ -8,10 +8,6 @@ namespace Components ServerInfo(); ~ServerInfo(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "ServerInfo"; }; -#endif - static Utils::InfoString GetInfo(); private: diff --git a/src/Components/Modules/ServerList.hpp b/src/Components/Modules/ServerList.hpp index 8c17f8b3..7f160435 100644 --- a/src/Components/Modules/ServerList.hpp +++ b/src/Components/Modules/ServerList.hpp @@ -32,10 +32,6 @@ namespace Components ServerList(); ~ServerList(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "ServerList"; }; -#endif - static void Refresh(UIScript::Token); static void RefreshVisibleList(UIScript::Token); static void UpdateVisibleList(UIScript::Token); diff --git a/src/Components/Modules/Singleton.hpp b/src/Components/Modules/Singleton.hpp index c02b832b..db2a11c8 100644 --- a/src/Components/Modules/Singleton.hpp +++ b/src/Components/Modules/Singleton.hpp @@ -7,10 +7,6 @@ namespace Components public: Singleton(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Singleton"; }; -#endif - static bool IsFirstInstance(); private: diff --git a/src/Components/Modules/Slowmotion.hpp b/src/Components/Modules/Slowmotion.hpp index a8cc057b..7f9dcee4 100644 --- a/src/Components/Modules/Slowmotion.hpp +++ b/src/Components/Modules/Slowmotion.hpp @@ -10,10 +10,6 @@ namespace Components public: SlowMotion(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "SlowMotion"; }; -#endif - private: static int Delay; diff --git a/src/Components/Modules/StartupMessages.hpp b/src/Components/Modules/StartupMessages.hpp index 1d1d3e52..0c19a60b 100644 --- a/src/Components/Modules/StartupMessages.hpp +++ b/src/Components/Modules/StartupMessages.hpp @@ -7,10 +7,6 @@ namespace Components public: StartupMessages(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "StartupMessages"; }; -#endif - static void AddMessage(std::string message); private: diff --git a/src/Components/Modules/Stats.hpp b/src/Components/Modules/Stats.hpp index 52518565..72f90c38 100644 --- a/src/Components/Modules/Stats.hpp +++ b/src/Components/Modules/Stats.hpp @@ -8,10 +8,6 @@ namespace Components Stats(); ~Stats(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Stats"; }; -#endif - static bool IsMaxLevel(); private: diff --git a/src/Components/Modules/StringTable.hpp b/src/Components/Modules/StringTable.hpp index 48b65299..74a471bf 100644 --- a/src/Components/Modules/StringTable.hpp +++ b/src/Components/Modules/StringTable.hpp @@ -8,10 +8,6 @@ namespace Components StringTable(); ~StringTable(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "StringTable"; }; -#endif - private: static std::unordered_map StringTableMap; diff --git a/src/Components/Modules/StructuredData.hpp b/src/Components/Modules/StructuredData.hpp index 41bfd714..8c7a6431 100644 --- a/src/Components/Modules/StructuredData.hpp +++ b/src/Components/Modules/StructuredData.hpp @@ -26,10 +26,6 @@ namespace Components StructuredData(); ~StructuredData(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "StructuredData"; }; -#endif - private: static bool UpdateVersionOffsets(Game::StructuredDataDefSet *set, Game::StructuredDataBuffer *buffer, Game::StructuredDataDef *oldDef); diff --git a/src/Components/Modules/Theatre.hpp b/src/Components/Modules/Theatre.hpp index b64026df..2b8858d4 100644 --- a/src/Components/Modules/Theatre.hpp +++ b/src/Components/Modules/Theatre.hpp @@ -7,10 +7,6 @@ namespace Components public: Theatre(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Theatre"; }; -#endif - static void StopRecording(); private: diff --git a/src/Components/Modules/Threading.hpp b/src/Components/Modules/Threading.hpp index 9c66654f..2e4354d3 100644 --- a/src/Components/Modules/Threading.hpp +++ b/src/Components/Modules/Threading.hpp @@ -7,10 +7,6 @@ namespace Components public: Threading(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Threading"; }; -#endif - private: static void FrameEpilogueStub(); static void PacketEventStub(); diff --git a/src/Components/Modules/Toast.hpp b/src/Components/Modules/Toast.hpp index f3ed65a3..dc59ec0f 100644 --- a/src/Components/Modules/Toast.hpp +++ b/src/Components/Modules/Toast.hpp @@ -11,10 +11,6 @@ namespace Components typedef WinToastLib::WinToastTemplate Template; -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Toast"; }; -#endif - static void Show(std::string image, std::string title, std::string description, int length); static bool ShowNative(const WinToastLib::WinToastTemplate& toast); diff --git a/src/Components/Modules/UIFeeder.hpp b/src/Components/Modules/UIFeeder.hpp index ec3838eb..e8840514 100644 --- a/src/Components/Modules/UIFeeder.hpp +++ b/src/Components/Modules/UIFeeder.hpp @@ -19,10 +19,6 @@ namespace Components UIFeeder(); ~UIFeeder(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "UIFeeder"; }; -#endif - static void Add(float feeder, GetItemCount_t itemCountCb, GetItemText_t itemTextCb, Select_t selectCb); private: diff --git a/src/Components/Modules/UIScript.hpp b/src/Components/Modules/UIScript.hpp index e10b8dcb..143d6fb9 100644 --- a/src/Components/Modules/UIScript.hpp +++ b/src/Components/Modules/UIScript.hpp @@ -8,10 +8,6 @@ namespace Components UIScript(); ~UIScript(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "UIScript"; }; -#endif - class Token { public: diff --git a/src/Components/Modules/Weapon.hpp b/src/Components/Modules/Weapon.hpp index 3119c8c6..5176a261 100644 --- a/src/Components/Modules/Weapon.hpp +++ b/src/Components/Modules/Weapon.hpp @@ -12,10 +12,6 @@ namespace Components public: Weapon(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Weapon"; }; -#endif - private: static Game::XAssetHeader WeaponFileLoad(Game::XAssetType type, std::string filename); static void PatchLimit(); diff --git a/src/Components/Modules/Window.hpp b/src/Components/Modules/Window.hpp index 8a9872b3..cd39da7a 100644 --- a/src/Components/Modules/Window.hpp +++ b/src/Components/Modules/Window.hpp @@ -7,10 +7,6 @@ namespace Components public: Window(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Window"; }; -#endif - static int Width(); static int Height(); static int Width(HWND window); diff --git a/src/Components/Modules/ZoneBuilder.hpp b/src/Components/Modules/ZoneBuilder.hpp index b57fb112..29e9b5a8 100644 --- a/src/Components/Modules/ZoneBuilder.hpp +++ b/src/Components/Modules/ZoneBuilder.hpp @@ -95,7 +95,6 @@ namespace Components ~ZoneBuilder(); #if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "ZoneBuilder"; }; bool unitTest() override; #endif diff --git a/src/Components/Modules/Zones.hpp b/src/Components/Modules/Zones.hpp index 84a27511..faa2d17f 100644 --- a/src/Components/Modules/Zones.hpp +++ b/src/Components/Modules/Zones.hpp @@ -12,10 +12,6 @@ namespace Components Zones(); ~Zones(); -#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) - const char* getName() override { return "Zones"; }; -#endif - static void SetVersion(int version); static int Version() { return Zones::ZoneVersion; };