Skip to content

Commit 5fbd06e

Browse files
committed
Add OnTakeDamage_Alive hook
1 parent ad1f496 commit 5fbd06e

File tree

3 files changed

+49
-10
lines changed

3 files changed

+49
-10
lines changed

gamedata/cs2fixes.games.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,12 @@
441441
"windows" "37"
442442
"linux" "38"
443443
}
444+
// Long function with "player_hurt" in the middle and then inserts userid, health, priority, attacker strings
445+
"CBasePlayerPawn::OnTakeDamage_Alive"
446+
{
447+
"windows" "221"
448+
"linux" "220"
449+
}
444450
}
445451
"Patches"
446452
{

src/cs2fixes.cpp

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, CPlayerSlo
111111
SH_DECL_HOOK3_void(ICvar, DispatchConCommand, SH_NOATTRIB, 0, ConCommandHandle, const CCommandContext&, const CCommand&);
112112
SH_DECL_MANUALHOOK1_void(CGamePlayerEquipUse, 0, 0, 0, InputData_t*);
113113
SH_DECL_MANUALHOOK2_void(CreateWorkshopMapGroup, 0, 0, 0, const char*, const CUtlStringList&);
114+
SH_DECL_MANUALHOOK2_void(OnTakeDamage_Alive, 0, 0, 0, CTakeDamageInfo*, void*);
114115

115116
CS2Fixes g_CS2Fixes;
116117

@@ -129,6 +130,7 @@ CCSGameRules *g_pGameRules = nullptr;
129130
IGameTypes* g_pGameTypes = nullptr;
130131
int g_iCGamePlayerEquipUseId = -1;
131132
int g_iCreateWorkshopMapGroupId = -1;
133+
int g_iOnTakeDamageAliveId = -1;
132134

133135
CGameEntitySystem *GameEntitySystem()
134136
{
@@ -223,26 +225,44 @@ bool CS2Fixes::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool
223225
if (!InitGameSystems())
224226
bRequiredInitLoaded = false;
225227

226-
if (!bRequiredInitLoaded)
227-
{
228-
snprintf(error, maxlen, "One or more address lookups, patches or detours failed, please refer to startup logs for more information");
229-
return false;
230-
}
231-
232228
const auto pCGamePlayerEquipVTable = modules::server->FindVirtualTable("CGamePlayerEquip");
233229
if (!pCGamePlayerEquipVTable)
234230
{
235231
snprintf(error, maxlen, "Failed to find CGamePlayerEquip vtable\n");
236-
return false;
232+
bRequiredInitLoaded = false;
237233
}
238-
if (g_GameConfig->GetOffset("CBaseEntity::Use") == -1)
234+
235+
offset = g_GameConfig->GetOffset("CBaseEntity::Use");
236+
if (offset == -1)
239237
{
240238
snprintf(error, maxlen, "Failed to find CBaseEntity::Use\n");
241-
return false;
239+
bRequiredInitLoaded = false;
242240
}
243-
SH_MANUALHOOK_RECONFIGURE(CGamePlayerEquipUse, g_GameConfig->GetOffset("CBaseEntity::Use"), 0, 0);
241+
SH_MANUALHOOK_RECONFIGURE(CGamePlayerEquipUse, offset, 0, 0);
244242
g_iCGamePlayerEquipUseId = SH_ADD_MANUALDVPHOOK(CGamePlayerEquipUse, pCGamePlayerEquipVTable, SH_MEMBER(this, &CS2Fixes::Hook_CGamePlayerEquipUse), false);
245243

244+
const auto pCCSPlayerPawnVTable = modules::server->FindVirtualTable("CCSPlayerPawn");
245+
if (!pCCSPlayerPawnVTable)
246+
{
247+
snprintf(error, maxlen, "Failed to find CCSPlayerPawn vtable\n");
248+
bRequiredInitLoaded = false;
249+
}
250+
251+
offset = g_GameConfig->GetOffset("CBasePlayerPawn::OnTakeDamage_Alive");
252+
if (offset == -1)
253+
{
254+
snprintf(error, maxlen, "Failed to find CBasePlayerPawn::OnTakeDamage_Alive\n");
255+
bRequiredInitLoaded = false;
256+
}
257+
SH_MANUALHOOK_RECONFIGURE(OnTakeDamage_Alive, offset, 0, 0);
258+
g_iOnTakeDamageAliveId = SH_ADD_MANUALDVPHOOK(OnTakeDamage_Alive, pCCSPlayerPawnVTable, SH_MEMBER(this, &CS2Fixes::Hook_OnTakeDamage_Alive), false);
259+
260+
if (!bRequiredInitLoaded)
261+
{
262+
snprintf(error, maxlen, "One or more address lookups, patches or detours failed, please refer to startup logs for more information");
263+
return false;
264+
}
265+
246266
Message( "All hooks started!\n" );
247267

248268
UnlockConVars();
@@ -289,6 +309,8 @@ bool CS2Fixes::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool
289309

290310
srand(time(0));
291311

312+
Message("Plugin successfully started!\n");
313+
292314
return true;
293315
}
294316

@@ -310,6 +332,7 @@ bool CS2Fixes::Unload(char *error, size_t maxlen)
310332
SH_REMOVE_HOOK(ISource2GameEntities, CheckTransmit, g_pSource2GameEntities, SH_MEMBER(this, &CS2Fixes::Hook_CheckTransmit), true);
311333
SH_REMOVE_HOOK(ICvar, DispatchConCommand, g_pCVar, SH_MEMBER(this, &CS2Fixes::Hook_DispatchConCommand), false);
312334
SH_REMOVE_HOOK_ID(g_iCreateWorkshopMapGroupId);
335+
SH_REMOVE_HOOK_ID(g_iOnTakeDamageAliveId);
313336

314337
ConVar_Unregister();
315338

@@ -809,6 +832,13 @@ void CS2Fixes::Hook_CreateWorkshopMapGroup(const char* name, const CUtlStringLis
809832
RETURN_META(MRES_IGNORED);
810833
}
811834

835+
void CS2Fixes::Hook_OnTakeDamage_Alive(CTakeDamageInfo *pInfo, void *a3)
836+
{
837+
CCSPlayerPawn *pPawn = META_IFACEPTR(CCSPlayerPawn);
838+
839+
RETURN_META(MRES_IGNORED);
840+
}
841+
812842
void CS2Fixes::OnLevelInit( char const *pMapName,
813843
char const *pMapEntities,
814844
char const *pOldLevel,

src/cs2fixes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include "networksystem/inetworkserializer.h"
2727
#include <iserver.h>
2828

29+
class CTakeDamageInfo;
30+
2931
class CS2Fixes : public ISmmPlugin, public IMetamodListener
3032
{
3133
public:
@@ -61,6 +63,7 @@ class CS2Fixes : public ISmmPlugin, public IMetamodListener
6163
void Hook_StartupServer(const GameSessionConfiguration_t& config, ISource2WorldSession*, const char*);
6264
void Hook_ApplyGameSettings(KeyValues* pKV);
6365
void Hook_CreateWorkshopMapGroup(const char* name, const CUtlStringList& mapList);
66+
void Hook_OnTakeDamage_Alive(CTakeDamageInfo *pInfo, void *a3);
6467

6568
public:
6669
const char *GetAuthor();

0 commit comments

Comments
 (0)