Skip to content

Commit f5fbdd1

Browse files
committed
more hooks
1 parent 16ff89d commit f5fbdd1

File tree

2 files changed

+70
-45
lines changed

2 files changed

+70
-45
lines changed

src/Modules/Client.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum class CMStatus {
1414
};
1515

1616
class Client : public Module {
17-
private:
17+
public:
1818
Interface *g_ClientDLL = nullptr;
1919
Interface *g_pClientMode = nullptr;
2020
Interface *g_pClientMode2 = nullptr;
@@ -47,7 +47,7 @@ class Client : public Module {
4747
using _IN_DeactivateMouse = void (*)(void *thisptr);
4848
using _AddAvatarPanelItem = void(__cdecl *)(void *pLeaderboard, void *pStatLists, const PortalLeaderboardItem_t *pData, int nScore, int nType, int nPlayerType, int nAvatarIndex, int nHeight, int nSlot, bool bHUDElement);
4949
using _PrecacheParticleSystem = int(__cdecl *)(const char *pszParticleName);
50-
using _DispatchParticleEffect = void (__cdecl *)(const char *pszParticleName, Vector vecOrigin, Vector vecStart, QAngle vecAngles, void *pEntity, int nSplitScreenPlayerSlot, void *filter);
50+
using _DispatchParticleEffect = void(__cdecl *)(const char *pszParticleName, Vector vecOrigin, Vector vecStart, QAngle vecAngles, void *pEntity, int nSplitScreenPlayerSlot, void *filter);
5151

5252

5353
_GetClientEntity GetClientEntity = nullptr;

src/Modules/Engine.cpp

Lines changed: 68 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -892,72 +892,91 @@ int __stdcall BinkWait_Detour(void *bink) {
892892
}
893893

894894
#ifdef _WIN32
895-
// Original function pointer (naked, no calling convention)
896-
void *g_Original = nullptr;
897-
898-
// Handler return structure
899-
struct HookResult {
900-
bool callOriginal;
901-
int returnValue;
902-
};
895+
void *_CL_CopyNewEntity = nullptr;
896+
int CL_CopyNewEntity(int a1, void *u, int iClass, int iSerialNum) {
897+
int result;
898+
__asm {
899+
mov edi, a1
900+
push iSerialNum
901+
push iClass
902+
push u
903+
call _CL_CopyNewEntity
904+
add esp, 0x0C
905+
mov result, eax
906+
}
907+
return result;
908+
}
903909

904-
HookResult __cdecl Hook_Handler(
910+
int __cdecl CL_CopyNewEntity_Handler(
905911
int a1,
906912
void *u,
907913
int iClass,
908914
int iSerialNum) {
909-
HookResult result;
910-
911-
console->Print("CL_CopyNewEntity(%p, %d, %d).\n", u, iClass, iSerialNum);
915+
console->Print("CL_CopyNewEntity(%d, %p, %d, %d).\n", a1, u, iClass, iSerialNum);
912916

913-
// YOUR LOGIC - decide whether to call original
914-
result.callOriginal = true; // Change this based on your conditions
915-
result.returnValue = 0; // Custom return value if not calling original
916-
917-
if (iClass == 106) {
917+
if (iClass == 106 /* CPointSurvey */) {
918918
console->Print("skipping over point_survey.\n");
919-
result.callOriginal = false;
919+
return 0;
920920
}
921921

922-
return result;
922+
return CL_CopyNewEntity(a1, u, iClass, iSerialNum);
923923
}
924924

925-
__declspec(naked) void Hook_CL_CopyNewEntity() {
925+
__declspec(naked) void CL_CopyNewEntity_Hook() {
926926
__asm {
927-
// Save registers (except edi which we need)
928927
push ebp
929928
mov ebp, esp
930929
push esi
931930
push ebx
932931

933-
// Push parameters for handler
934-
push [ebp+0x10] // iSerialNum
935-
push [ebp+0x0C] // iClass
936-
push [ebp+0x08] // u
937-
push edi // a1 from edi
932+
push [ebp+0x10] // iSerialNum.
933+
push [ebp+0x0C] // iClass.
934+
push [ebp+0x08] // u.
935+
push edi // a1.
938936

939-
call Hook_Handler
937+
call CL_CopyNewEntity_Handler
940938
add esp, 0x10
941939

942-
// eax = callOriginal, edx = returnValue
943-
test al, al
944-
jz skip_original
945-
946-
// Restore and call original
947-
pop ebx
948-
pop esi
949-
pop ebp
950-
jmp g_Original
951-
952-
skip_original:
953-
// Use custom return value
954-
mov eax, edx
940+
// return value already in eax.
955941
pop ebx
956942
pop esi
957943
pop ebp
958944
ret
959945
}
960946
}
947+
948+
int(__cdecl *CL_CopyExistingEntity)(void *u);
949+
int __cdecl CL_CopyExistingEntity_Detour(void *u);
950+
static Hook CL_CopyExistingEntity_Hook(&CL_CopyExistingEntity_Detour);
951+
int __cdecl CL_CopyExistingEntity_Detour(void *u) {
952+
if (!u)
953+
return 0;
954+
955+
int m_nNewEntity = *(int *)((uintptr_t)u + 24);
956+
console->Print("CL_CopyExistingEntity(%p) | m_nNewEntity = %d.\n", u, m_nNewEntity);
957+
958+
auto ent = client->GetClientEntity(client->s_EntityList->ThisPtr(), m_nNewEntity);
959+
if (!ent) {
960+
return 0;
961+
}
962+
963+
CL_CopyExistingEntity_Hook.Disable();
964+
int ret = CL_CopyExistingEntity(u);
965+
CL_CopyExistingEntity_Hook.Enable();
966+
return ret;
967+
}
968+
969+
int(__cdecl *CL_ParseEventDelta)(int a1, void *pToData, RecvTable *pRecvTable);
970+
int __cdecl CL_ParseEventDelta_Detour(int a1, void *pToData, RecvTable *pRecvTable);
971+
static Hook CL_ParseEventDelta_Hook(&CL_ParseEventDelta_Detour);
972+
int __cdecl CL_ParseEventDelta_Detour(int a1, void *pToData, RecvTable *pRecvTable) {
973+
console->Print("CL_ParseEventDelta(%p, %p) | name = %s.\n", pToData, pRecvTable, pRecvTable->m_pNetTableName);
974+
975+
CL_ParseEventDelta_Hook.Disable();
976+
int ret = CL_ParseEventDelta(a1, pToData, pRecvTable);
977+
CL_ParseEventDelta_Hook.Enable();
978+
return ret;
979+
}
961980
#endif
962981

963982
Color Engine::GetLightAtPoint(Vector point) {
@@ -1244,9 +1263,15 @@ bool Engine::Init() {
12441263
}
12451264

12461265
#ifdef _WIN32
1247-
auto addr = Memory::Scan<void *>(MODULE("engine"), "55 8B EC B8 ? ? ? ? E8 ? ? ? ? 56 8B 75 ? 8B 46");
1248-
if (MH_CreateHook(addr, &Hook_CL_CopyNewEntity, (void **)&g_Original) == MH_OK)
1249-
MH_EnableHook(addr);
1266+
auto CL_CopyNewEntity_addr = Memory::Scan<void *>(MODULE("engine"), "55 8B EC B8 ? ? ? ? E8 ? ? ? ? 56 8B 75 ? 8B 46");
1267+
if (MH_CreateHook(CL_CopyNewEntity_addr, &CL_CopyNewEntity_Hook, &_CL_CopyNewEntity) == MH_OK)
1268+
MH_EnableHook(CL_CopyNewEntity_addr);
1269+
1270+
CL_CopyExistingEntity = Memory::Scan<decltype(CL_CopyExistingEntity)>(MODULE("engine"), "55 8B EC 56 8B 75 ? 8B 4E ? 8B 51");
1271+
CL_CopyExistingEntity_Hook.SetFunc(CL_CopyExistingEntity);
1272+
1273+
CL_ParseEventDelta = Memory::Scan<decltype(CL_ParseEventDelta)>(MODULE("engine"), "55 8B EC 83 EC ? 56 57 33 C0");
1274+
CL_ParseEventDelta_Hook.SetFunc(CL_ParseEventDelta);
12501275
#endif
12511276

12521277
return this->hasLoaded = this->engineClient && this->s_ServerPlugin && this->demoplayer && this->demorecorder && this->engineTrace && this->engineTraceClient;

0 commit comments

Comments
 (0)