From d39ee5a0b307803e0d258058d1789a1a9e3bb06f Mon Sep 17 00:00:00 2001 From: ficool2 <34815548+ficool2@users.noreply.github.com> Date: Thu, 15 Dec 2022 01:26:00 +0000 Subject: [PATCH] Fix for VScript update Changed hardcoded offsets to signature finding --- address.h | 27 +++++++++++++++++++++------ custom_items_games.vcxproj | 1 + functions.h | 36 ++++++++++++++++++++++++++++++------ 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/address.h b/address.h index 365d1af..c951431 100644 --- a/address.h +++ b/address.h @@ -18,6 +18,12 @@ struct Offset intptr_t Get() { return modules[mod].base + offs; } intptr_t Deref() { return ::Deref(modules[mod].base + offs); } + + const Offset& operator=( const intptr_t _offs ) + { + offs = _offs; + return *this; + } }; struct AddressBase; @@ -29,20 +35,21 @@ struct AddressBase virtual bool Find() = 0; }; -#pragma optimize("", off) - template struct AddressInfo : public AddressBase { + typedef void (*callback)(AddressInfo& addr, ModuleName mod); + const char* name; const char* sig; size_t len; const char* mask; addrtype addr[maxAddresses]; ModuleName mod[maxAddresses]; + callback onFind; AddressInfo(const char* _name, const char* _sig, size_t _len, const char* _mask, - ModuleName _mod1, ModuleName _mod2, AddressList& list) + ModuleName _mod1, ModuleName _mod2, AddressList& list, callback _onFind = nullptr ) { name = _name; sig = _sig; @@ -51,6 +58,7 @@ struct AddressInfo : public AddressBase memset(addr, 0, sizeof(addr)); mod[0] = _mod1; mod[1] = _mod2; + onFind = _onFind; list.push_back(this); } @@ -91,6 +99,11 @@ struct AddressInfo : public AddressBase } addr[m] = (addrtype)ptr; + if (ptr) + { + if (onFind) + onFind(*this, curmod); + } } if (foundAddr == 0) @@ -118,8 +131,6 @@ struct AddressInfo : public AddressBase } }; -#pragma optimize("", on) - std::vector addresses; #define CHECK_SIG(name, sig, mask) static_assert(sizeof(#sig) == sizeof(#mask), "Mismatch in signature/mask length for " name) @@ -132,6 +143,10 @@ CHECK_SIG(name, sig, mask); AddressInfo address_##var = {name, #sig, sizeof(#sig) - 1, #mask, MOD_CLIENT, MOD_SERVER, addresses}; \ CHECK_SIG(name, sig, mask); +#define ADDR_CALLBACK(var, name, mod, sig, mask, callback) \ +AddressInfo address_##var = {name, #sig, sizeof(#sig) - 1, #mask, mod, MOD_INVALID, addresses, callback}; \ +CHECK_SIG(name, sig, mask); + #define DETOUR_LOAD(addrtype) \ for (int k = 0; k < maxAddresses; k++) \ if (address_##addrtype.addr[k]) DetourAttach(&(LPVOID&)address_##addrtype.addr[k], &hook_##addrtype); @@ -145,5 +160,5 @@ for (int k = 0; k < maxAddresses; k++) \ if (address_##addrtype.addr[k]) DetourDetach(&(LPVOID&)address_##addrtype.addr[k], &hook_##addrtype); #define DETOUR_UNLOAD_GAME(addrtype) \ -if (address_##addrtype[MOD_SERVER]) DetourDetach(&(LPVOID&)address_##addrtype[MOD_CLIENT], &hook_client_##addrtype); \ +if (address_##addrtype[MOD_CLIENT]) DetourDetach(&(LPVOID&)address_##addrtype[MOD_CLIENT], &hook_client_##addrtype); \ if (address_##addrtype[MOD_SERVER]) DetourDetach(&(LPVOID&)address_##addrtype[MOD_SERVER], &hook_server_##addrtype); \ No newline at end of file diff --git a/custom_items_games.vcxproj b/custom_items_games.vcxproj index 62fb32e..3e668c0 100644 --- a/custom_items_games.vcxproj +++ b/custom_items_games.vcxproj @@ -21,6 +21,7 @@ + diff --git a/functions.h b/functions.h index 2240e66..45ccdc6 100644 --- a/functions.h +++ b/functions.h @@ -3,15 +3,39 @@ #define CUSTOM_ITEMS_GAME "scripts/items/items_game_custom.txt" #define CUSTOM_ITEMS_GAME_SIG CUSTOM_ITEMS_GAME ".sig" -Offset offset_server_econItemSchema(MOD_SERVER, 0x9D2534); -Offset offset_server_fullFilesystem(MOD_SERVER, 0xA6C208); +intptr_t server_fileSystem = 0; + +void gameStats_loadFromFile_resolve(AddressInfo& addr, ModuleName mod) +{ + server_fileSystem = Deref(addr[mod] + 42); + Log(Color(0, 255, 200, 255), "Filesystem found at 0x%X in %s.%s\n", server_fileSystem, modules[mod].name, "dll"); +} + +typedef intptr_t gameStats_loadFromFile; +ADDR_CALLBACK( + gameStats_loadFromFile, + "CBaseGameStats::LoadFromFile", + MOD_SERVER, + \x55\x8B\xEC\x81\xEC\x38\x02\x00\x00\xA1\x2A\x2A\x2A\x2A, + xxxxxxxxxx????, + gameStats_loadFromFile_resolve +); + +typedef intptr_t (*econItemSystem)(); +ADDR( + econItemSystem, + "CTFItemSystem", + MOD_SERVER, + \xA1\x2A\x2A\x2A\x2A\x85\xC0\x75\x2A\x56, + x????xxx?x +); bool customItemsGameFound = false; typedef bool (__thiscall** filesystem_fileExists)(intptr_t, const char*, const char*); bool function_filesystem_fileExists(const char* filename) { - intptr_t filesystem = offset_server_fullFilesystem.Deref() + 4; + intptr_t filesystem = Deref(server_fileSystem) + 4; return (*(filesystem_fileExists)(Deref(filesystem) + 40))(filesystem, filename, nullptr); } @@ -20,12 +44,12 @@ bool helper_check_custom_itemsgame() bool foundCustom = true; if (!function_filesystem_fileExists(CUSTOM_ITEMS_GAME)) { - Log(Color(255, 0, 127, 255), PLUGIN_NAME "Server: %s not found, loading default items_game.txt ...\n", CUSTOM_ITEMS_GAME); + Log(Color(255, 0, 127, 255), "Server: %s not found, loading default items_game.txt ...\n", CUSTOM_ITEMS_GAME); foundCustom = false; } if (!function_filesystem_fileExists(CUSTOM_ITEMS_GAME_SIG)) { - Log(Color(255, 0, 127, 255), PLUGIN_NAME "Server: %s not found, loading default items_game.txt ...\n", CUSTOM_ITEMS_GAME_SIG); + Log(Color(255, 0, 127, 255), "Server: %s not found, loading default items_game.txt ...\n", CUSTOM_ITEMS_GAME_SIG); foundCustom = false; } customItemsGameFound = foundCustom; @@ -66,7 +90,7 @@ void __fastcall hook_client_econItemSystem_parseItemSchemaFile(intptr_t thisptr, if (helper_check_custom_itemsgame()) { filename = CUSTOM_ITEMS_GAME; - hook_server_econItemSystem_parseItemSchemaFile(offset_server_econItemSchema.Deref(), edx, filename); + hook_server_econItemSystem_parseItemSchemaFile(address_econItemSystem[MOD_SERVER](), edx, filename); Log(Color(0, 255, 127, 255), "Client: Loading %s...\n", filename); } address_econItemSystem_parseItemSchemaFile[MOD_CLIENT](thisptr, edx, filename);