Skip to content

Commit

Permalink
server: Remove uses of Autohook from buildainfile.cpp (#824)
Browse files Browse the repository at this point in the history
* Manually hook CAI_NetworkBuilder__Build
* Manually hook LoadAINFile
* Remove AUTOHOOK_INIT and AUTOHOOK_DISPATCH
  • Loading branch information
ASpoonPlaysGames authored Nov 12, 2024
1 parent 0de2a3a commit 13344f3
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions primedev/server/buildainfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

namespace fs = std::filesystem;

AUTOHOOK_INIT()

const int AINET_VERSION_NUMBER = 57;
const int AINET_SCRIPT_VERSION_NUMBER = 21;
const int PLACEHOLDER_CRC = 0;
Expand Down Expand Up @@ -359,22 +357,18 @@ void DumpAINInfo(CAI_Network* aiNetwork)
writeStream.close();
}

// clang-format off
AUTOHOOK(CAI_NetworkBuilder__Build, server.dll + 0x385E20,
void, __fastcall, (void* builder, CAI_Network* aiNetwork, void* unknown))
// clang-format on
static void(__fastcall* o_pCAI_NetworkBuilder__Build)(void* builder, CAI_Network* aiNetwork, void* unknown) = nullptr;
static void __fastcall h_CAI_NetworkBuilder__Build(void* builder, CAI_Network* aiNetwork, void* unknown)
{
CAI_NetworkBuilder__Build(builder, aiNetwork, unknown);
o_pCAI_NetworkBuilder__Build(builder, aiNetwork, unknown);

DumpAINInfo(aiNetwork);
}

// clang-format off
AUTOHOOK(LoadAINFile, server.dll + 0x3933A0,
void, __fastcall, (void* aimanager, void* buf, const char* filename))
// clang-format on
static void(__fastcall* o_pLoadAINFile)(void* aimanager, void* buf, const char* filename) = nullptr;
static void __fastcall h_LoadAINFile(void* aimanager, void* buf, const char* filename)
{
LoadAINFile(aimanager, buf, filename);
o_pLoadAINFile(aimanager, buf, filename);

if (Cvar_ns_ai_dumpAINfileFromLoad->GetBool())
{
Expand All @@ -385,7 +379,11 @@ void, __fastcall, (void* aimanager, void* buf, const char* filename))

ON_DLL_LOAD("server.dll", BuildAINFile, (CModule module))
{
AUTOHOOK_DISPATCH()
o_pCAI_NetworkBuilder__Build = module.Offset(0x385E20).RCast<decltype(o_pCAI_NetworkBuilder__Build)>();
HookAttach(&(PVOID&)o_pCAI_NetworkBuilder__Build, (PVOID)h_CAI_NetworkBuilder__Build);

o_pLoadAINFile = module.Offset(0x3933A0).RCast<decltype(o_pLoadAINFile)>();
HookAttach(&(PVOID&)o_pLoadAINFile, (PVOID)h_LoadAINFile);

Cvar_ns_ai_dumpAINfileFromLoad = new ConVar(
"ns_ai_dumpAINfileFromLoad", "0", FCVAR_NONE, "For debugging: whether we should dump ain data for ains loaded from disk");
Expand Down

0 comments on commit 13344f3

Please sign in to comment.