Skip to content

Commit 893574d

Browse files
committed
Added CPortal_Player flashlight on and off hooks
1 parent 41e2252 commit 893574d

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

sdk.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,38 @@ void __fastcall CPortal_Player__PlayerDeathThink_hook(CPortal_Player* thisPtr)
3030
CPortal_Player__PlayerDeathThink_orig(thisPtr);
3131
}
3232

33+
//---------------------------------------------------------------------------------
34+
// Purpose: Change out the original Flashlight turn and off with our versions.
35+
// TODO: Have flashlight on and off sound work again.
36+
//---------------------------------------------------------------------------------
37+
bool (__fastcall* CPortal_Player__FlashlightTurnOn_orig)(CPortal_Player* thisPtr, void* edx, bool playSound);
38+
bool __fastcall CPortal_Player__FlashlightTurnOn_hook(CPortal_Player* thisPtr, void* edx, bool playSound)
39+
{
40+
const int playerIndex = ENTINDEX(reinterpret_cast<CBaseEntity*>(thisPtr));
41+
if (playerIndex <= 0 || playerIndex > MAX_PLAYERS)
42+
{
43+
Log(WARNING, false, "CPortal_Player::FlashlightTurnOn was called with a invalid player!");
44+
return false;
45+
}
46+
47+
CPortal_Player__SetFlashlightState(playerIndex, true);
48+
// engineServer->EmitAmbientSound(playerIndex)
49+
return true;
50+
}
51+
52+
void (__fastcall* CPortal_Player__FlashlightTurnOff_orig)(CPortal_Player* thisPtr, void* edx, bool playSound);
53+
void __fastcall CPortal_Player__FlashlightTurnOff_hook(CPortal_Player* thisPtr, void* edx, bool playSound)
3354
{
55+
const int playerIndex = ENTINDEX(reinterpret_cast<CBaseEntity*>(thisPtr));
56+
if (playerIndex <= 0 || playerIndex > MAX_PLAYERS)
57+
{
58+
Log(WARNING, false, "CPortal_Player::FlashlightTurnOff was called with a invalid player!");
59+
return;
60+
}
61+
62+
CPortal_Player__SetFlashlightState(playerIndex, false);
63+
// engineServer->EmitAmbientSound(playerIndex)
64+
return;
3465
}
3566

3667
/// Interfaced UTIL Functions \\\

sdk.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ typedef struct
3131
extern void (__fastcall* CPortal_Player__PlayerDeathThink_orig)(CPortal_Player* thisptr);
3232
void __fastcall CPortal_Player__PlayerDeathThink_hook(CPortal_Player* thisptr);
3333

34+
// Flashlight Hooks.
35+
extern bool (__fastcall* CPortal_Player__FlashlightTurnOn_orig)(CPortal_Player* thisPtr, void* edx, bool playSound);
36+
bool __fastcall CPortal_Player__FlashlightTurnOn_hook(CPortal_Player* thisPtr, void* edx, bool playSound);
37+
extern void (__fastcall* CPortal_Player__FlashlightTurnOff_orig)(CPortal_Player* thisPtr, void* edx, bool playSound);
38+
void __fastcall CPortal_Player__FlashlightTurnOff_hook(CPortal_Player* thisPtr, void* edx, bool playSound);
3439

3540
//---------------------------------------------------------------------------------
3641
// Interfaced game functions.

0 commit comments

Comments
 (0)