Skip to content

Commit 6737a34

Browse files
engine: Remove uses of Autohook from hoststate.cpp (#806)
Removes use of AUTOHOOK macro from hoststate.cpp.
1 parent ba485e9 commit 6737a34

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

primedev/engine/hoststate.cpp

+34-30
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
#include "squirrel/squirrel.h"
1010
#include "plugins/pluginmanager.h"
1111

12-
AUTOHOOK_INIT()
13-
1412
CHostState* g_pHostState;
1513

1614
std::string sLastMode;
1715

18-
VAR_AT(engine.dll + 0x13FA6070, ConVar*, Cvar_hostport);
19-
FUNCTION_AT(engine.dll + 0x1232C0, void, __fastcall, _Cmd_Exec_f, (const CCommand& arg, bool bOnlyIfExists, bool bUseWhitelists));
16+
static ConVar* Cvar_hostport = nullptr;
17+
static void(__fastcall* _Cmd_Exec_f)(const CCommand& arg, bool bOnlyIfExists, bool bUseWhitelists) = nullptr;
2018

2119
void ServerStartingOrChangingMap()
2220
{
@@ -53,10 +51,8 @@ void ServerStartingOrChangingMap()
5351
g_pServerAuthentication->m_bStartingLocalSPGame = false;
5452
}
5553

56-
// clang-format off
57-
AUTOHOOK(CHostState__State_NewGame, engine.dll + 0x16E7D0,
58-
void, __fastcall, (CHostState* self))
59-
// clang-format on
54+
static void(__fastcall* o_pCHostState__State_NewGame)(CHostState* self) = nullptr;
55+
static void __fastcall h_CHostState__State_NewGame(CHostState* self)
6056
{
6157
spdlog::info("HostState: NewGame");
6258

@@ -70,7 +66,7 @@ void, __fastcall, (CHostState* self))
7066
ServerStartingOrChangingMap();
7167

7268
double dStartTime = Plat_FloatTime();
73-
CHostState__State_NewGame(self);
69+
o_pCHostState__State_NewGame(self);
7470
spdlog::info("loading took {}s", Plat_FloatTime() - dStartTime);
7571

7672
// setup server presence
@@ -82,10 +78,8 @@ void, __fastcall, (CHostState* self))
8278
g_pServerAuthentication->m_bNeedLocalAuthForNewgame = false;
8379
}
8480

85-
// clang-format off
86-
AUTOHOOK(CHostState__State_LoadGame, engine.dll + 0x16E730,
87-
void, __fastcall, (CHostState* self))
88-
// clang-format on
81+
static void(__fastcall* o_pCHostState__State_LoadGame)(CHostState* self) = nullptr;
82+
static void __fastcall h_CHostState__State_LoadGame(CHostState* self)
8983
{
9084
// singleplayer server starting
9185
// useless in 99% of cases but without it things could potentially break very much
@@ -100,7 +94,7 @@ void, __fastcall, (CHostState* self))
10094
g_pServerAuthentication->m_bStartingLocalSPGame = true;
10195

10296
double dStartTime = Plat_FloatTime();
103-
CHostState__State_LoadGame(self);
97+
o_pCHostState__State_LoadGame(self);
10498
spdlog::info("loading took {}s", Plat_FloatTime() - dStartTime);
10599

106100
// no server presence, can't do it because no map name in hoststate
@@ -109,32 +103,28 @@ void, __fastcall, (CHostState* self))
109103
g_pServerAuthentication->m_bNeedLocalAuthForNewgame = false;
110104
}
111105

112-
// clang-format off
113-
AUTOHOOK(CHostState__State_ChangeLevelMP, engine.dll + 0x16E520,
114-
void, __fastcall, (CHostState* self))
115-
// clang-format on
106+
static void(__fastcall* o_pCHostState__State_ChangeLevelMP)(CHostState* self) = nullptr;
107+
static void __fastcall h_CHostState__State_ChangeLevelMP(CHostState* self)
116108
{
117109
spdlog::info("HostState: ChangeLevelMP");
118110

119111
ServerStartingOrChangingMap();
120112

121113
double dStartTime = Plat_FloatTime();
122-
CHostState__State_ChangeLevelMP(self);
114+
o_pCHostState__State_ChangeLevelMP(self);
123115
spdlog::info("loading took {}s", Plat_FloatTime() - dStartTime);
124116

125117
g_pServerPresence->SetMap(g_pHostState->m_levelName);
126118
}
127119

128-
// clang-format off
129-
AUTOHOOK(CHostState__State_GameShutdown, engine.dll + 0x16E640,
130-
void, __fastcall, (CHostState* self))
131-
// clang-format on
120+
static void(__fastcall* o_pCHostState__State_GameShutdown)(CHostState* self) = nullptr;
121+
static void __fastcall h_CHostState__State_GameShutdown(CHostState* self)
132122
{
133123
spdlog::info("HostState: GameShutdown");
134124

135125
g_pServerPresence->DestroyPresence();
136126

137-
CHostState__State_GameShutdown(self);
127+
o_pCHostState__State_GameShutdown(self);
138128

139129
// run gamemode cleanup cfg now instead of when we start next map
140130
if (sLastMode.length())
@@ -153,12 +143,10 @@ void, __fastcall, (CHostState* self))
153143
}
154144
}
155145

156-
// clang-format off
157-
AUTOHOOK(CHostState__FrameUpdate, engine.dll + 0x16DB00,
158-
void, __fastcall, (CHostState* self, double flCurrentTime, float flFrameTime))
159-
// clang-format on
146+
static void(__fastcall* o_pCHostState__FrameUpdate)(CHostState* self, double flCurrentTime, float flFrameTime) = nullptr;
147+
static void __fastcall h_CHostState__FrameUpdate(CHostState* self, double flCurrentTime, float flFrameTime)
160148
{
161-
CHostState__FrameUpdate(self, flCurrentTime, flFrameTime);
149+
o_pCHostState__FrameUpdate(self, flCurrentTime, flFrameTime);
162150

163151
if (*g_pServerState == server_state_t::ss_active)
164152
{
@@ -184,7 +172,23 @@ void, __fastcall, (CHostState* self, double flCurrentTime, float flFrameTime))
184172

185173
ON_DLL_LOAD_RELIESON("engine.dll", HostState, ConVar, (CModule module))
186174
{
187-
AUTOHOOK_DISPATCH()
175+
o_pCHostState__State_NewGame = module.Offset(0x16E7D0).RCast<decltype(o_pCHostState__State_NewGame)>();
176+
HookAttach(&(PVOID&)o_pCHostState__State_NewGame, (PVOID)h_CHostState__State_NewGame);
177+
178+
o_pCHostState__State_LoadGame = module.Offset(0x16E730).RCast<decltype(o_pCHostState__State_LoadGame)>();
179+
HookAttach(&(PVOID&)o_pCHostState__State_LoadGame, (PVOID)h_CHostState__State_LoadGame);
180+
181+
o_pCHostState__State_ChangeLevelMP = module.Offset(0x16E520).RCast<decltype(o_pCHostState__State_ChangeLevelMP)>();
182+
HookAttach(&(PVOID&)o_pCHostState__State_ChangeLevelMP, (PVOID)h_CHostState__State_ChangeLevelMP);
183+
184+
o_pCHostState__State_GameShutdown = module.Offset(0x16E640).RCast<decltype(o_pCHostState__State_GameShutdown)>();
185+
HookAttach(&(PVOID&)o_pCHostState__State_GameShutdown, (PVOID)h_CHostState__State_GameShutdown);
186+
187+
o_pCHostState__FrameUpdate = module.Offset(0x16DB00).RCast<decltype(o_pCHostState__FrameUpdate)>();
188+
HookAttach(&(PVOID&)o_pCHostState__FrameUpdate, (PVOID)h_CHostState__FrameUpdate);
189+
190+
Cvar_hostport = module.Offset(0x13FA6070).RCast<decltype(Cvar_hostport)>();
191+
_Cmd_Exec_f = module.Offset(0x1232C0).RCast<decltype(_Cmd_Exec_f)>();
188192

189193
g_pHostState = module.Offset(0x7CF180).RCast<CHostState*>();
190194
}

0 commit comments

Comments
 (0)