Skip to content

Commit 911a391

Browse files
committed
feat: Moved more signatures to signature file, added function types, and fixed some naming schemes.
1 parent 2c5051f commit 911a391

File tree

10 files changed

+302
-194
lines changed

10 files changed

+302
-194
lines changed

src/modules/cbaseentity.cpp

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,49 @@
88
#include "stdafx.hpp"
99
#include "modules/cbaseentity.hpp"
1010

11-
#include "modules/cbaseplayer.hpp"
12-
1311
#include "utils.hpp"
1412
#include "globals.hpp"
15-
16-
#include "vscript/ivscript.h"
17-
#include "irecipientfilter.h"
13+
#include "signatures.hpp"
1814

1915
/**
2016
* @brief Remove a entity from the world.
21-
* @param pEntity Pointer to entity.
17+
* @param entity Pointer to entity.
2218
*/
23-
void CBaseEntity::RemoveEntity(CBaseEntity* pEntity)
19+
using RemoveEntityT = void (__cdecl*)(CBaseEntity*);
20+
void CBaseEntity::RemoveEntity(CBaseEntity* entity)
2421
{
25-
if (!pEntity)
22+
if (!entity)
2623
return;
2724

28-
static auto removeEntity = reinterpret_cast<void (__cdecl*)(void*)>(Memory::Scan<void*>(MODULE_SERVER, "55 8B EC 57 8B 7D 08 85 FF 74 72"));
29-
removeEntity((reinterpret_cast<IServerEntity*>(pEntity)->GetNetworkable()));
25+
static auto removeEntity = Memory::Scan<RemoveEntityT>(MODULE_SERVER, Signatures::RemoveEntity);
26+
removeEntity(entity);
3027
}
3128

3229
/**
3330
* @brief Get the script scope of a entity.
34-
* @param pEntity Pointer to entity.
31+
* @param entity Pointer to entity.
3532
* @return VScript handle to entity's script scope.
3633
*/
37-
HSCRIPT CBaseEntity::GetScriptScope(CBaseEntity* pEntity)
34+
HSCRIPT CBaseEntity::GetScriptScope(CBaseEntity* entity)
3835
{
39-
if (!pEntity)
36+
if (!entity)
4037
return nullptr;
4138

42-
return *reinterpret_cast<HSCRIPT*>(reinterpret_cast<uintptr_t>(pEntity) + 0x33C);
39+
return *reinterpret_cast<HSCRIPT*>(reinterpret_cast<uintptr_t>(entity) + 0x33C);
4340
}
4441

4542
/**
4643
* @brief Get the script instance of a entity.
4744
* @param entity Pointer to entity.
4845
* @return VScript instance handle of the entity.
4946
*/
47+
using GetScriptInstanceT = HSCRIPT (__thiscall*)(CBaseEntity*);
5048
HSCRIPT CBaseEntity::GetScriptInstance(CBaseEntity* entity)
5149
{
52-
static auto getScriptInstance = reinterpret_cast<HSCRIPT (__thiscall*)(CBaseEntity*)>(Memory::Scan<void*>(MODULE_SERVER, "55 8B EC 51 56 8B F1 83 BE 50"));
50+
if (!entity)
51+
return nullptr;
52+
53+
static auto getScriptInstance = Memory::Scan<GetScriptInstanceT>(MODULE_SERVER, Signatures::GetScriptInstance);
5354
if (!getScriptInstance)
5455
{
5556
Log(WARNING, false, "Could not get script instance for entity!");
@@ -61,30 +62,50 @@ HSCRIPT CBaseEntity::GetScriptInstance(CBaseEntity* entity)
6162

6263
/**
6364
* @brief Make a entity emit a sound.
64-
* @param pEntity Entity that will call to emit a sound.
65+
* @param entity Entity that will call to emit a sound.
6566
* @param entityIndex Entity that will emit the sound. Use -1 if you want to set a position in the world for it to play.
6667
* @param filter Filter of recipient entities that can hear this noise.
6768
* @param soundName Sound file path, or script name to play.
68-
* @param pOrigin Position in the world the sound will play.
69+
* @param origin Position in the world the sound will play.
6970
* @param soundTime Time in seconds till sound is played. NOT HOW LONG SOUND WILL PLAY!
7071
* @return Return code for sound.
7172
*/
72-
int CBaseEntity::EmitSound(CBaseEntity* pEntity, int entityIndex, IRecipientFilter& filter, const char* soundName, const Vector* pOrigin, const float soundTime)
73+
using EmitSoundT = int (__thiscall*)(CBaseEntity*, IRecipientFilter&, int, const char*, const Vector*, float);
74+
int CBaseEntity::EmitSound(CBaseEntity* entity, const int entityIndex, IRecipientFilter& filter, const char* soundName, const Vector* origin, const float soundTime)
7375
{
74-
static auto emitSound = reinterpret_cast<int (__thiscall*)(CBaseEntity*, IRecipientFilter&, int, const char*, const Vector*, float)>(Memory::Scan<void*>(MODULE_SERVER, "55 8B EC 83 EC 4C 8B 0D"));
75-
return emitSound(pEntity, filter, entityIndex, soundName, pOrigin, soundTime);
76-
}
76+
if (!entity)
77+
return 0;
7778

78-
void CBaseEntity::AddEffects(CBaseEntity* pEntity, int nEffects)
79-
{
80-
static auto addEffects = reinterpret_cast<void (__thiscall*)(CBaseEntity*, int)>(Memory::Scan<void*>(MODULE_SERVER, "55 8B EC 53 8B D9 8B 83 A8"));
81-
addEffects(pEntity, nEffects);
79+
static auto emitSound = Memory::Scan<EmitSoundT>(MODULE_SERVER, Signatures::EmitSound);
80+
return emitSound(entity, filter, entityIndex, soundName, origin, soundTime);
8281
}
8382

84-
void CBaseEntity::RemoveEffects(CBaseEntity* pEntity, int nEffects)
83+
/**
84+
* @brief Add effects to a entity.
85+
* @param entity Entity to add effects to.
86+
* @param effects Effects to apply on entity.
87+
*/
88+
using AddEffectsT = void (__thiscall*)(CBaseEntity*, int);
89+
void CBaseEntity::AddEffects(CBaseEntity* entity, const EntityEffect effects)
8590
{
86-
static auto removeEffects = reinterpret_cast<void (__thiscall*)(CBaseEntity*, int)>(Memory::Scan<void*>(MODULE_SERVER, "55 8B EC 53 56 8B 75 08 8B D9 8B 83"));
87-
removeEffects(pEntity, nEffects);
91+
if (!entity)
92+
return;
93+
94+
static auto addEffects = Memory::Scan<AddEffectsT>(MODULE_SERVER, Signatures::AddEffects);
95+
addEffects(entity, effects);
8896
}
8997

98+
/**
99+
* @brief Remove effects from a entity.
100+
* @param entity Entity to remove effects from.
101+
* @param effects Effects to remove from entity.
102+
*/
103+
using RemoveEffectsT = void (__thiscall*)(CBaseEntity*, int);
104+
void CBaseEntity::RemoveEffects(CBaseEntity* entity, const EntityEffect effects)
105+
{
106+
if (!entity)
107+
return;
90108

109+
static auto removeEffects = Memory::Scan<RemoveEffectsT>(MODULE_SERVER, Signatures::RemoveEffects);
110+
removeEffects(entity, effects);
111+
}

src/modules/cbaseentity.hpp

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,42 @@ class CBasePlayer;
1616
struct Edict;
1717
typedef struct HSCRIPT__* HSCRIPT;
1818

19+
// Entity effects used with AddEffects and RemoveEffects.
20+
enum EntityEffect : std::uint16_t
21+
{
22+
EF_BONEMERGE = 0x001, // Performs bone merge on client side
23+
EF_BRIGHTLIGHT = 0x002, // DLIGHT centered at entity origin
24+
EF_DIMLIGHT = 0x004, // player flashlight
25+
EF_NOINTERP = 0x008, // don't interpolate the next frame
26+
EF_NOSHADOW = 0x010, // Don't cast no shadow
27+
EF_NODRAW = 0x020, // don't draw entity
28+
EF_NORECEIVESHADOW = 0x040, // Don't receive no shadow
29+
EF_BONEMERGE_FASTCULL = 0x080, // For use with EF_BONEMERGE. If this is set, then it places this ent's origin at its
30+
// parent and uses the parent's bbox + the max extents of the aiment.
31+
// Otherwise, it sets up the parent's bones every frame to figure out where to place
32+
// the aiment, which is inefficient because it'll setup the parent's bones even if
33+
// the parent is not in the PVS.
34+
EF_ITEM_BLINK = 0x100, // blink an item so that the user notices it.
35+
EF_PARENT_ANIMATES = 0x200, // always assume that the parent entity is animating
36+
EF_MARKED_FOR_FAST_REFLECTION = 0x400, // marks an entity for reflection rendering when using $reflectonlymarkedentities material variable
37+
EF_NOSHADOWDEPTH = 0x800, // Indicates this entity does not render into any shadow depthmap
38+
EF_SHADOWDEPTH_NOCACHE = 0x1000, // Indicates this entity cannot be cached in shadow depthmap and should render every frame
39+
EF_NOFLASHLIGHT = 0x2000,
40+
EF_NOCSM = 0x4000, // Indicates this entity does not render into the cascade shadow depthmap
41+
EF_MAX_BITS = 15
42+
};
43+
1944
class CBaseEntity
2045
{
2146
public: // MARK: CBaseEntity Public Members
2247
#pragma region Public Members
2348

24-
static void RemoveEntity(CBaseEntity* pEntity);
25-
static HSCRIPT GetScriptScope(CBaseEntity* pEntity);
26-
static HSCRIPT GetScriptInstance(CBaseEntity* entity);
27-
static int EmitSound(CBaseEntity* pEntity, int entityIndex, IRecipientFilter& filter, const char* soundName, const Vector* pOrigin, float soundTime);
28-
static void AddEffects(CBaseEntity* pEntity, int nEffects);
29-
static void RemoveEffects(CBaseEntity* pEntity, int nEffects);
49+
static void RemoveEntity(CBaseEntity* entity);
50+
static HSCRIPT GetScriptScope(CBaseEntity* entity);
51+
static HSCRIPT GetScriptInstance(CBaseEntity* entity);
52+
static int EmitSound(CBaseEntity* entity, int entityIndex, IRecipientFilter& filter, const char* soundName, const Vector* origin, float soundTime);
53+
static void AddEffects(CBaseEntity* entity, EntityEffect effects);
54+
static void RemoveEffects(CBaseEntity* entity, EntityEffect effects);
3055

3156
#pragma endregion
3257

src/modules/cbaseplayer.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@
88
#include "stdafx.hpp"
99
#include "modules/cbaseplayer.hpp"
1010

11+
#include "signatures.hpp"
1112
#include "utils.hpp"
1213

13-
void CBasePlayer::ShowViewPortPanel(const int playerIndex, const char* name, const bool bShow, KeyValues* data)
14+
/**
15+
* @brief Show or hide viewports for players.
16+
* @param player Player entity.
17+
* @param name Viewport to show.
18+
* @param show Whether to show or hide the viewport.
19+
* @param data Any additional data that would go with certain viewports.
20+
*/
21+
using ShowViewPortPanelT = void (__thiscall*)(CBasePlayer*, const char*, bool, KeyValues*);
22+
void CBasePlayer::ShowViewPortPanel(CBasePlayer* player, const char* name, const bool show, KeyValues* data)
1423
{
15-
CBasePlayer* pPlayer = Utils::PlayerByIndex(playerIndex);
16-
if (!pPlayer)
17-
{
18-
Log(WARNING, false, "Couldn't get player to display view port panel to! playerIndex: %i", playerIndex);
24+
if (!player)
1925
return;
20-
}
21-
static auto showViewPortPanel = reinterpret_cast<void(__thiscall*)(CBasePlayer*, const char*, bool, KeyValues*)>(Memory::Scan<void*>(MODULE_SERVER, "55 8B EC 83 EC 20 53 56 8B F1 57 8D 4D ? E8 ? ? ? ? 56"));
22-
showViewPortPanel(pPlayer, name, bShow, data);
26+
27+
static auto showViewPortPanel = Memory::Scan<ShowViewPortPanelT>(MODULE_SERVER, Signatures::ShowViewPortPanel);
28+
showViewPortPanel(player, name, show, data);
2329
}

src/modules/cbaseplayer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CBasePlayer
1717
public: // MARK: CBasePlayer Public Members
1818
#pragma region Public Members
1919

20-
static void ShowViewPortPanel(int playerIndex, const char* name, bool bShow, KeyValues* data);
20+
static void ShowViewPortPanel(CBasePlayer* player, const char* name, bool show, KeyValues* data);
2121

2222
#pragma endregion
2323

src/modules/cportal_player.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "utils.hpp"
1515
#include "commands.hpp"
1616
#include "globals.hpp"
17+
#include "signatures.hpp"
1718

1819
// Redeclaration's for hooks.
1920
REDECL(CPortal_Player::PlayerDeathThink);
@@ -47,8 +48,8 @@ DETOUR_T(void, CPortal_Player::PlayerDeathThink)
4748
DEFINE_HOOK(CPortal_Player, FlashlightTurnOn);
4849
DETOUR_T(bool, CPortal_Player::FlashlightTurnOn, bool playSound)
4950
{
50-
CBaseEntity* pEntity = static_cast<CBaseEntity*>(thisPtr);
51-
const int playerIndex = Utils::EntityIndex(pEntity);
51+
CBaseEntity* entity = static_cast<CBaseEntity*>(thisPtr);
52+
const int playerIndex = Utils::EntityIndex(entity);
5253
if (playerIndex <= 0 || playerIndex > MAX_PLAYERS)
5354
{
5455
Log(WARNING, false, "CPortal_Player::FlashlightTurnOn was called with a invalid player!");
@@ -59,7 +60,7 @@ DETOUR_T(bool, CPortal_Player::FlashlightTurnOn, bool playSound)
5960

6061
CPlayerFilter filter;
6162
filter.AddPlayer(playerIndex);
62-
CBaseEntity::EmitSound(pEntity, playerIndex, filter, "HL2Player.FlashLightOn", nullptr, 0.0f);
63+
CBaseEntity::EmitSound(entity, playerIndex, filter, "HL2Player.FlashLightOn", nullptr, 0.0f);
6364
return true;
6465
}
6566

@@ -70,7 +71,7 @@ DETOUR_T(bool, CPortal_Player::FlashlightTurnOn, bool playSound)
7071
DEFINE_HOOK(CPortal_Player, FlashlightTurnOff);
7172
DETOUR_T(void, CPortal_Player::FlashlightTurnOff, bool playSound)
7273
{
73-
CBaseEntity* pEntity = static_cast<CBaseEntity*>(thisPtr);
74+
CBaseEntity* entity = static_cast<CBaseEntity*>(thisPtr);
7475
const int playerIndex = Utils::EntityIndex(static_cast<CBaseEntity*>(thisPtr));
7576
if (playerIndex <= 0 || playerIndex > MAX_PLAYERS)
7677
{
@@ -82,7 +83,7 @@ DETOUR_T(void, CPortal_Player::FlashlightTurnOff, bool playSound)
8283

8384
CPlayerFilter filter;
8485
filter.AddPlayer(playerIndex);
85-
CBaseEntity::EmitSound(pEntity, playerIndex, filter, "HL2Player.FlashLightOff", nullptr, 0.0f);
86+
CBaseEntity::EmitSound(entity, playerIndex, filter, "HL2Player.FlashLightOff", nullptr, 0.0f);
8687
}
8788

8889
#pragma endregion
@@ -93,17 +94,18 @@ DETOUR_T(void, CPortal_Player::FlashlightTurnOff, bool playSound)
9394
* @brief Respawn a player where ever their spawn point is set.
9495
* @param playerEntityIndex Player entity index.
9596
*/
97+
using RespawnPlayerT = void (__thiscall*)(CPortal_Player*);
9698
void CPortal_Player::RespawnPlayer(const int playerEntityIndex)
9799
{
98-
const auto pPlayer = reinterpret_cast<CPortal_Player*>(Utils::PlayerByIndex(playerEntityIndex));
99-
if (!pPlayer)
100+
const auto player = reinterpret_cast<CPortal_Player*>(Utils::PlayerByIndex(playerEntityIndex));
101+
if (!player)
100102
{
101103
Log(WARNING, false, "Couldn't get player to respawn! playerIndex: %i", playerEntityIndex);
102104
return;
103105
}
104106

105-
static auto respawnPlayer = reinterpret_cast<void(__thiscall*)(CPortal_Player*)>(Memory::Scan<void*>(MODULE_SERVER, "0F 57 C0 56 8B F1 57 8D 8E"));
106-
respawnPlayer(pPlayer);
107+
static auto respawnPlayer = Memory::Scan<RespawnPlayerT>(MODULE_SERVER, Signatures::RespawnPlayer);
108+
respawnPlayer(player);
107109
}
108110

109111
/**
@@ -114,19 +116,19 @@ void CPortal_Player::RespawnPlayer(const int playerEntityIndex)
114116
* @param playerEntityIndex Player entity index.
115117
* @param enabled Should flashlight be enabled or not.
116118
*/
117-
void CPortal_Player::SetFlashlightState(int playerEntityIndex, bool enabled)
119+
void CPortal_Player::SetFlashlightState(const int playerEntityIndex, const bool enabled)
118120
{
119-
CBasePlayer* pPlayer = Utils::PlayerByIndex(playerEntityIndex);
120-
if (!pPlayer)
121+
CBasePlayer* player = Utils::PlayerByIndex(playerEntityIndex);
122+
if (!player)
121123
{
122124
Log(WARNING, true, "Couldn't get player to set flashlight state! playerIndex: %i enable: %i", playerEntityIndex, !!enabled);
123125
return;
124126
}
125127

126128
if (enabled)
127-
CBaseEntity::AddEffects(reinterpret_cast<CBaseEntity*>(pPlayer), EF_DIMLIGHT);
129+
CBaseEntity::AddEffects(reinterpret_cast<CBaseEntity*>(player), EF_DIMLIGHT);
128130
else
129-
CBaseEntity::RemoveEffects(reinterpret_cast<CBaseEntity*>(pPlayer), EF_DIMLIGHT);
131+
CBaseEntity::RemoveEffects(reinterpret_cast<CBaseEntity*>(player), EF_DIMLIGHT);
130132
}
131133

132134
#pragma endregion

src/modules/misc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "stdafx.hpp"
99
#include "modules/misc.hpp"
1010

11+
#include "math.hpp"
1112
#include "utils.hpp"
1213

1314
// Redeclaration's for hooks.

src/signatures_portal2.hpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,47 @@
11
/*******************************************************************
2-
* @file signatures.hpp
2+
* @file signatures_portal2.hpp
33
* @brief Header to store all gather memory signatures or offsets used by the plugin.
44
* @author SAR Team, Orsell, NULLderef
55
* @date 06 2025
66
*********************************************************************/
77

8+
#pragma once
9+
10+
#ifndef SIGSP2_HPP
11+
#define SIGSP2_HPP
12+
813
#ifndef SIGSCAN
914
#error "SIGSCAN macro must be defined!"
1015
#endif
1116

17+
18+
//------ CBaseEntity Signatures ------\\
19+
20+
SIGSCAN(RemoveEntity, "55 8B EC 8B 45 08 85 C0 74 0C 83", "")
21+
SIGSCAN(GetScriptInstance, "55 8B EC 51 56 8B F1 83 BE 50", "")
22+
SIGSCAN(EmitSound, "55 8B EC 83 EC 4C 8B 0D", "")
23+
SIGSCAN(AddEffects, "55 8B EC 53 8B D9 8B 83 A8", "")
24+
SIGSCAN(RemoveEffects, "55 8B EC 53 56 8B 75 08 8B D9 8B 83", "")
25+
26+
//------------------------------------\\
27+
28+
//------ CBasePlayer Signatures ------\\
29+
30+
SIGSCAN(ShowViewPortPanel, "55 8B EC 83 EC 20 53 56 8B F1 57 8D 4D ? E8 ? ? ? ? 56", "")
31+
32+
//------------------------------------\\
33+
34+
//------ CPortal_Player Signatures ------\\
35+
36+
SIGSCAN(RespawnPlayer, "0F 57 C0 56 8B F1 57 8D 8E", "")
37+
1238
// CPortal_Player::NotifySystemEvent | "movzx eax, byte ptr [edi+504h]" -> "jmp short loc_103552D0"
1339
SIGSCAN(CPortal_Player_NotifySystemEvent_EventTeleportUserID, "0F B6 87 04 05 00 00 8B 16", "")
1440
SIGSCAN(CPortal_Player_NotifySystemEvent_EventTeleportUserID_Patch, "EB 14 87 04 05 00 00 8B 16", "")
1541

42+
43+
//---------------------------------------\\
44+
1645
// Squirrel VM runtime timeout, increase runtime max from 0.03 to 0.05.
1746
SIGSCAN(SQVM_RuntimeTimeout, "00 00 00 E0 51 B8 9E 3F", "")
1847
SIGSCAN(SQVM_RuntimeTimeout_Patch, "9A 99 99 99 99 99 A9 3F", "")
@@ -21,7 +50,7 @@ SIGSCAN(SQVM_RuntimeTimeout_Patch, "9A 99 99 99 99 99 A9 3F", "")
2150
SIGSCAN(CEnvProjectedTexture_EnforceSingleProjectionRules_Loop, "8B F0 3B F3 0F 84 95 00 00 00", "")
2251
SIGSCAN(CEnvProjectedTexture_EnforceSingleProjectionRules_Loop_Patch, "E9 9D 00 00 00 84 95 00 00 00", "")
2352

24-
// CClientShadowMgr::CalculateRenderTargetsAndSizes | Increase the projected texture limit from 1 -> 8
53+
// CClientShadowMgr::CalculateRenderTargetsAndSizes | Increase the projected texture limit from 1 -> 8
2554
SIGSCAN(CClientShadowMgr_CalculateRenderTargetsAndSizes_PtexLimit, "F7 D8 1B C0 83 E0 07 40 5F", "")
2655
SIGSCAN(CClientShadowMgr_CalculateRenderTargetsAndSizes_PtexLimit_Patch, "B8 08 00 00 00 90 90 90 5F", "")
2756

@@ -32,3 +61,5 @@ SIGSCAN(CClientShadowMgr_CalculateRenderTargetsAndSizes_ShadowRes_Patch, "0F 94
3261
// CShadowMgr::DrawVolumetrics | Enable volumetrics for all env_projectedtextures.
3362
SIGSCAN(CShadowMgr_DrawVolumetrics_VolState, "0F 85 47 0C 00 00 80 BF 10 02 00 00 00 0F 84 3A 0C 00 00", "")
3463
SIGSCAN(CShadowMgr_DrawVolumetrics_VolState_Patch, "0F 84 47 0C 00 00 80 BF 10 02 00 00 00 0F 85 3A 0C 00 00", "")
64+
65+
#endif

0 commit comments

Comments
 (0)