Fix for VScript update

Changed hardcoded offsets to signature finding
This commit is contained in:
ficool2 2022-12-15 01:26:00 +00:00
parent f86a0d9ca9
commit d39ee5a0b3
3 changed files with 52 additions and 12 deletions

View File

@ -18,6 +18,12 @@ struct Offset
intptr_t Get() { return modules[mod].base + offs; } intptr_t Get() { return modules[mod].base + offs; }
intptr_t Deref() { return ::Deref(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; struct AddressBase;
@ -29,20 +35,21 @@ struct AddressBase
virtual bool Find() = 0; virtual bool Find() = 0;
}; };
#pragma optimize("", off)
template <class addrtype> template <class addrtype>
struct AddressInfo : public AddressBase struct AddressInfo : public AddressBase
{ {
typedef void (*callback)(AddressInfo<addrtype>& addr, ModuleName mod);
const char* name; const char* name;
const char* sig; const char* sig;
size_t len; size_t len;
const char* mask; const char* mask;
addrtype addr[maxAddresses]; addrtype addr[maxAddresses];
ModuleName mod[maxAddresses]; ModuleName mod[maxAddresses];
callback onFind;
AddressInfo(const char* _name, const char* _sig, size_t _len, const char* _mask, 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; name = _name;
sig = _sig; sig = _sig;
@ -51,6 +58,7 @@ struct AddressInfo : public AddressBase
memset(addr, 0, sizeof(addr)); memset(addr, 0, sizeof(addr));
mod[0] = _mod1; mod[0] = _mod1;
mod[1] = _mod2; mod[1] = _mod2;
onFind = _onFind;
list.push_back(this); list.push_back(this);
} }
@ -91,6 +99,11 @@ struct AddressInfo : public AddressBase
} }
addr[m] = (addrtype)ptr; addr[m] = (addrtype)ptr;
if (ptr)
{
if (onFind)
onFind(*this, curmod);
}
} }
if (foundAddr == 0) if (foundAddr == 0)
@ -118,8 +131,6 @@ struct AddressInfo : public AddressBase
} }
}; };
#pragma optimize("", on)
std::vector<AddressBase*> addresses; std::vector<AddressBase*> addresses;
#define CHECK_SIG(name, sig, mask) static_assert(sizeof(#sig) == sizeof(#mask), "Mismatch in signature/mask length for " name) #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<var> address_##var = {name, #sig, sizeof(#sig) - 1, #mask, MOD_CLIENT, MOD_SERVER, addresses}; \ AddressInfo<var> address_##var = {name, #sig, sizeof(#sig) - 1, #mask, MOD_CLIENT, MOD_SERVER, addresses}; \
CHECK_SIG(name, sig, mask); CHECK_SIG(name, sig, mask);
#define ADDR_CALLBACK(var, name, mod, sig, mask, callback) \
AddressInfo<var> address_##var = {name, #sig, sizeof(#sig) - 1, #mask, mod, MOD_INVALID, addresses, callback}; \
CHECK_SIG(name, sig, mask);
#define DETOUR_LOAD(addrtype) \ #define DETOUR_LOAD(addrtype) \
for (int k = 0; k < maxAddresses; k++) \ for (int k = 0; k < maxAddresses; k++) \
if (address_##addrtype.addr[k]) DetourAttach(&(LPVOID&)address_##addrtype.addr[k], &hook_##addrtype); 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); if (address_##addrtype.addr[k]) DetourDetach(&(LPVOID&)address_##addrtype.addr[k], &hook_##addrtype);
#define DETOUR_UNLOAD_GAME(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); if (address_##addrtype[MOD_SERVER]) DetourDetach(&(LPVOID&)address_##addrtype[MOD_SERVER], &hook_server_##addrtype);

View File

@ -21,6 +21,7 @@
<ItemGroup> <ItemGroup>
<ClInclude Include="address.h" /> <ClInclude Include="address.h" />
<ClInclude Include="detours.h" /> <ClInclude Include="detours.h" />
<ClInclude Include="functions.h" />
<ClInclude Include="helpers.h" /> <ClInclude Include="helpers.h" />
<ClInclude Include="module.h" /> <ClInclude Include="module.h" />
<ClInclude Include="plugin.h" /> <ClInclude Include="plugin.h" />

View File

@ -3,15 +3,39 @@
#define CUSTOM_ITEMS_GAME "scripts/items/items_game_custom.txt" #define CUSTOM_ITEMS_GAME "scripts/items/items_game_custom.txt"
#define CUSTOM_ITEMS_GAME_SIG CUSTOM_ITEMS_GAME ".sig" #define CUSTOM_ITEMS_GAME_SIG CUSTOM_ITEMS_GAME ".sig"
Offset offset_server_econItemSchema(MOD_SERVER, 0x9D2534); intptr_t server_fileSystem = 0;
Offset offset_server_fullFilesystem(MOD_SERVER, 0xA6C208);
void gameStats_loadFromFile_resolve(AddressInfo<intptr_t>& 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; bool customItemsGameFound = false;
typedef bool (__thiscall** filesystem_fileExists)(intptr_t, const char*, const char*); typedef bool (__thiscall** filesystem_fileExists)(intptr_t, const char*, const char*);
bool function_filesystem_fileExists(const char* filename) 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); return (*(filesystem_fileExists)(Deref(filesystem) + 40))(filesystem, filename, nullptr);
} }
@ -20,12 +44,12 @@ bool helper_check_custom_itemsgame()
bool foundCustom = true; bool foundCustom = true;
if (!function_filesystem_fileExists(CUSTOM_ITEMS_GAME)) 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; foundCustom = false;
} }
if (!function_filesystem_fileExists(CUSTOM_ITEMS_GAME_SIG)) 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; foundCustom = false;
} }
customItemsGameFound = foundCustom; customItemsGameFound = foundCustom;
@ -66,7 +90,7 @@ void __fastcall hook_client_econItemSystem_parseItemSchemaFile(intptr_t thisptr,
if (helper_check_custom_itemsgame()) if (helper_check_custom_itemsgame())
{ {
filename = CUSTOM_ITEMS_GAME; 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); Log(Color(0, 255, 127, 255), "Client: Loading %s...\n", filename);
} }
address_econItemSystem_parseItemSchemaFile[MOD_CLIENT](thisptr, edx, filename); address_econItemSystem_parseItemSchemaFile[MOD_CLIENT](thisptr, edx, filename);