Skip to content

Commit 3e40fa3

Browse files
Remove uses of Autohook from loghooks.cpp (#812)
* Manually hook TextMsg * Manually hook fprintf * Manually hook ConCommand_echo * Manually hook EngineSpewFunc * Manually hook Status_ConMsg * Manually hook CClientState_ProcessPrint * Remove AUTOHOOK_INIT and AUTOHOOK_DISPATCH_MODULE
1 parent 90a06cd commit 3e40fa3

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

primedev/logging/loghooks.cpp

+28-28
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include <iomanip>
1010
#include <sstream>
1111

12-
AUTOHOOK_INIT()
13-
1412
ConVar* Cvar_spewlog_enable;
1513
ConVar* Cvar_cl_showtextmsg;
1614

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

7169
ICenterPrint* pInternalCenterPrint = NULL;
7270

73-
// clang-format off
74-
AUTOHOOK(TextMsg, client.dll + 0x198710,
75-
void,, (BFRead* msg))
76-
// clang-format on
71+
static void (*o_pTextMsg)(BFRead* msg) = nullptr;
72+
static void h_TextMsg(BFRead* msg)
7773
{
7874
TextMsgPrintType_t msg_dest = (TextMsgPrintType_t)msg->ReadByte();
7975

@@ -103,10 +99,8 @@ void,, (BFRead* msg))
10399
}
104100
}
105101

106-
// clang-format off
107-
AUTOHOOK(Hook_fprintf, engine.dll + 0x51B1F0,
108-
int,, (void* const stream, const char* const format, ...))
109-
// clang-format on
102+
static int (*o_pfprintf)(void* const stream, const char* const format, ...) = nullptr;
103+
static int h_fprintf(void* const stream, const char* const format, ...)
110104
{
111105
NOTE_UNUSED(stream);
112106

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

130-
// clang-format off
131-
AUTOHOOK(ConCommand_echo, engine.dll + 0x123680,
132-
void,, (const CCommand& arg))
133-
// clang-format on
124+
static void (*o_pConCommand_echo)(const CCommand& arg) = nullptr;
125+
static void h_ConCommand_echo(const CCommand& arg)
134126
{
135127
if (arg.ArgC() >= 2)
136128
NS::log::echo->info("{}", arg.ArgS());
137129
}
138130

139-
// clang-format off
140-
AUTOHOOK(EngineSpewFunc, engine.dll + 0x11CA80,
141-
void, __fastcall, (void* pEngineServer, SpewType_t type, const char* format, va_list args))
142-
// clang-format on
131+
static void(__fastcall* o_pEngineSpewFunc)(void* pEngineServer, SpewType_t type, const char* format, va_list args) = nullptr;
132+
static void __fastcall h_EngineSpewFunc(void* pEngineServer, SpewType_t type, const char* format, va_list args)
143133
{
144134
NOTE_UNUSED(pEngineServer);
145135
if (!Cvar_spewlog_enable->GetBool())
@@ -214,10 +204,8 @@ void, __fastcall, (void* pEngineServer, SpewType_t type, const char* format, va_
214204
}
215205

216206
// used for printing the output of status
217-
// clang-format off
218-
AUTOHOOK(Status_ConMsg, engine.dll + 0x15ABD0,
219-
void,, (const char* text, ...))
220-
// clang-format on
207+
static void (*o_pStatus_ConMsg)(const char* text, ...) = nullptr;
208+
static void h_Status_ConMsg(const char* text, ...)
221209
{
222210
char formatted[2048];
223211
va_list list;
@@ -233,10 +221,8 @@ void,, (const char* text, ...))
233221
spdlog::info(formatted);
234222
}
235223

236-
// clang-format off
237-
AUTOHOOK(CClientState_ProcessPrint, engine.dll + 0x1A1530,
238-
bool,, (void* thisptr, uintptr_t msg))
239-
// clang-format on
224+
static bool (*o_pCClientState_ProcessPrint)(void* thisptr, uintptr_t msg) = nullptr;
225+
static bool h_CClientState_ProcessPrint(void* thisptr, uintptr_t msg)
240226
{
241227
NOTE_UNUSED(thisptr);
242228

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

253239
ON_DLL_LOAD_RELIESON("engine.dll", EngineSpewFuncHooks, ConVar, (CModule module))
254240
{
255-
AUTOHOOK_DISPATCH_MODULE(engine.dll)
241+
o_pfprintf = module.Offset(0x51B1F0).RCast<decltype(o_pfprintf)>();
242+
HookAttach(&(PVOID&)o_pfprintf, (PVOID)h_fprintf);
243+
244+
o_pConCommand_echo = module.Offset(0x123680).RCast<decltype(o_pConCommand_echo)>();
245+
HookAttach(&(PVOID&)o_pConCommand_echo, (PVOID)h_ConCommand_echo);
246+
247+
o_pEngineSpewFunc = module.Offset(0x11CA80).RCast<decltype(o_pEngineSpewFunc)>();
248+
HookAttach(&(PVOID&)o_pEngineSpewFunc, (PVOID)h_EngineSpewFunc);
249+
250+
o_pStatus_ConMsg = module.Offset(0x15ABD0).RCast<decltype(o_pStatus_ConMsg)>();
251+
HookAttach(&(PVOID&)o_pStatus_ConMsg, (PVOID)h_Status_ConMsg);
252+
253+
o_pCClientState_ProcessPrint = module.Offset(0x1A1530).RCast<decltype(o_pCClientState_ProcessPrint)>();
254+
HookAttach(&(PVOID&)o_pCClientState_ProcessPrint, (PVOID)h_CClientState_ProcessPrint);
256255

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

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

264264
Cvar_cl_showtextmsg = new ConVar("cl_showtextmsg", "1", FCVAR_NONE, "Enable/disable text messages printing on the screen.");
265265
pInternalCenterPrint = module.Offset(0x216E940).RCast<ICenterPrint*>();

0 commit comments

Comments
 (0)