Skip to content

Commit

Permalink
Merge commit '3e40fa3c9a589b7fc5088c43ead2b32bf68c6bbe' into fix/mult…
Browse files Browse the repository at this point in the history
…iple-mod-versions
  • Loading branch information
GeckoEidechse committed Nov 22, 2024
2 parents 59e97bd + 3e40fa3 commit 1312211
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 57 deletions.
13 changes: 5 additions & 8 deletions primedev/engine/runframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
#include "hoststate.h"
#include "server/serverpresence.h"

AUTOHOOK_INIT()

// clang-format off
AUTOHOOK(CEngine__Frame, engine.dll + 0x1C8650,
void, __fastcall, (CEngine* self))
// clang-format on
static void(__fastcall* o_pCEngine__Frame)(CEngine* self) = nullptr;
static void __fastcall h_CEngine__Frame(CEngine* self)
{
CEngine__Frame(self);
o_pCEngine__Frame(self);
}

ON_DLL_LOAD("engine.dll", RunFrame, (CModule module))
{
AUTOHOOK_DISPATCH()
o_pCEngine__Frame = module.Offset(0x1C8650).RCast<decltype(o_pCEngine__Frame)>();
HookAttach(&(PVOID&)o_pCEngine__Frame, (PVOID)h_CEngine__Frame);
}
56 changes: 28 additions & 28 deletions primedev/logging/loghooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <iomanip>
#include <sstream>

AUTOHOOK_INIT()

ConVar* Cvar_spewlog_enable;
ConVar* Cvar_cl_showtextmsg;

Expand Down Expand Up @@ -70,10 +68,8 @@ const std::unordered_map<SpewType_t, const char> PrintSpewTypes_Short = {

ICenterPrint* pInternalCenterPrint = NULL;

// clang-format off
AUTOHOOK(TextMsg, client.dll + 0x198710,
void,, (BFRead* msg))
// clang-format on
static void (*o_pTextMsg)(BFRead* msg) = nullptr;
static void h_TextMsg(BFRead* msg)
{
TextMsgPrintType_t msg_dest = (TextMsgPrintType_t)msg->ReadByte();

Expand Down Expand Up @@ -103,10 +99,8 @@ void,, (BFRead* msg))
}
}

// clang-format off
AUTOHOOK(Hook_fprintf, engine.dll + 0x51B1F0,
int,, (void* const stream, const char* const format, ...))
// clang-format on
static int (*o_pfprintf)(void* const stream, const char* const format, ...) = nullptr;
static int h_fprintf(void* const stream, const char* const format, ...)
{
NOTE_UNUSED(stream);

Expand All @@ -127,19 +121,15 @@ int,, (void* const stream, const char* const format, ...))
return 0;
}

// clang-format off
AUTOHOOK(ConCommand_echo, engine.dll + 0x123680,
void,, (const CCommand& arg))
// clang-format on
static void (*o_pConCommand_echo)(const CCommand& arg) = nullptr;
static void h_ConCommand_echo(const CCommand& arg)
{
if (arg.ArgC() >= 2)
NS::log::echo->info("{}", arg.ArgS());
}

// clang-format off
AUTOHOOK(EngineSpewFunc, engine.dll + 0x11CA80,
void, __fastcall, (void* pEngineServer, SpewType_t type, const char* format, va_list args))
// clang-format on
static void(__fastcall* o_pEngineSpewFunc)(void* pEngineServer, SpewType_t type, const char* format, va_list args) = nullptr;
static void __fastcall h_EngineSpewFunc(void* pEngineServer, SpewType_t type, const char* format, va_list args)
{
NOTE_UNUSED(pEngineServer);
if (!Cvar_spewlog_enable->GetBool())
Expand Down Expand Up @@ -214,10 +204,8 @@ void, __fastcall, (void* pEngineServer, SpewType_t type, const char* format, va_
}

// used for printing the output of status
// clang-format off
AUTOHOOK(Status_ConMsg, engine.dll + 0x15ABD0,
void,, (const char* text, ...))
// clang-format on
static void (*o_pStatus_ConMsg)(const char* text, ...) = nullptr;
static void h_Status_ConMsg(const char* text, ...)
{
char formatted[2048];
va_list list;
Expand All @@ -233,10 +221,8 @@ void,, (const char* text, ...))
spdlog::info(formatted);
}

// clang-format off
AUTOHOOK(CClientState_ProcessPrint, engine.dll + 0x1A1530,
bool,, (void* thisptr, uintptr_t msg))
// clang-format on
static bool (*o_pCClientState_ProcessPrint)(void* thisptr, uintptr_t msg) = nullptr;
static bool h_CClientState_ProcessPrint(void* thisptr, uintptr_t msg)
{
NOTE_UNUSED(thisptr);

Expand All @@ -252,14 +238,28 @@ bool,, (void* thisptr, uintptr_t msg))

ON_DLL_LOAD_RELIESON("engine.dll", EngineSpewFuncHooks, ConVar, (CModule module))
{
AUTOHOOK_DISPATCH_MODULE(engine.dll)
o_pfprintf = module.Offset(0x51B1F0).RCast<decltype(o_pfprintf)>();
HookAttach(&(PVOID&)o_pfprintf, (PVOID)h_fprintf);

o_pConCommand_echo = module.Offset(0x123680).RCast<decltype(o_pConCommand_echo)>();
HookAttach(&(PVOID&)o_pConCommand_echo, (PVOID)h_ConCommand_echo);

o_pEngineSpewFunc = module.Offset(0x11CA80).RCast<decltype(o_pEngineSpewFunc)>();
HookAttach(&(PVOID&)o_pEngineSpewFunc, (PVOID)h_EngineSpewFunc);

o_pStatus_ConMsg = module.Offset(0x15ABD0).RCast<decltype(o_pStatus_ConMsg)>();
HookAttach(&(PVOID&)o_pStatus_ConMsg, (PVOID)h_Status_ConMsg);

o_pCClientState_ProcessPrint = module.Offset(0x1A1530).RCast<decltype(o_pCClientState_ProcessPrint)>();
HookAttach(&(PVOID&)o_pCClientState_ProcessPrint, (PVOID)h_CClientState_ProcessPrint);

Cvar_spewlog_enable = new ConVar("spewlog_enable", "0", FCVAR_NONE, "Enables/disables whether the engine spewfunc should be logged");
}

ON_DLL_LOAD_CLIENT_RELIESON("client.dll", ClientPrintHooks, ConVar, (CModule module))
{
AUTOHOOK_DISPATCH_MODULE(client.dll)
o_pTextMsg = module.Offset(0x198710).RCast<decltype(o_pTextMsg)>();
HookAttach(&(PVOID&)o_pTextMsg, (PVOID)h_TextMsg);

Cvar_cl_showtextmsg = new ConVar("cl_showtextmsg", "1", FCVAR_NONE, "Enable/disable text messages printing on the screen.");
pInternalCenterPrint = module.Offset(0x216E940).RCast<ICenterPrint*>();
Expand Down
13 changes: 5 additions & 8 deletions primedev/scripts/client/clientchathooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@

#include <rapidjson/document.h>

AUTOHOOK_INIT()

// clang-format off
AUTOHOOK(CHudChat__AddGameLine, client.dll + 0x22E580,
void, __fastcall, (void* self, const char* message, int inboxId, bool isTeam, bool isDead))
// clang-format on
static void(__fastcall* o_pCHudChat__AddGameLine)(void* self, const char* message, int inboxId, bool isTeam, bool isDead) = nullptr;
static void __fastcall h_CHudChat__AddGameLine(void* self, const char* message, int inboxId, bool isTeam, bool isDead)
{
// This hook is called for each HUD, but we only want our logic to run once.
if (self != *CHudChat::allHuds)
Expand All @@ -36,7 +32,7 @@ void, __fastcall, (void* self, const char* message, int inboxId, bool isTeam, bo
"CHudChat_ProcessMessageStartThread", static_cast<int>(senderId) - 1, payload, isTeam, isDead, type);
if (result == SQRESULT_ERROR)
for (CHudChat* hud = *CHudChat::allHuds; hud != NULL; hud = hud->next)
CHudChat__AddGameLine(hud, message, inboxId, isTeam, isDead);
o_pCHudChat__AddGameLine(hud, message, inboxId, isTeam, isDead);
}

ADD_SQFUNC("void", NSChatWrite, "int context, string text", "", ScriptContext::CLIENT)
Expand Down Expand Up @@ -68,5 +64,6 @@ ADD_SQFUNC("void", NSChatWriteLine, "int context, string text", "", ScriptContex

ON_DLL_LOAD_CLIENT("client.dll", ClientChatHooks, (CModule module))
{
AUTOHOOK_DISPATCH()
o_pCHudChat__AddGameLine = module.Offset(0x22E580).RCast<decltype(o_pCHudChat__AddGameLine)>();
HookAttach(&(PVOID&)o_pCHudChat__AddGameLine, (PVOID)h_CHudChat__AddGameLine);
}
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 1312211

Please sign in to comment.