Skip to content

Commit 16ff89d

Browse files
committed
getting somewhere
1 parent 7e98343 commit 16ff89d

File tree

1 file changed

+57
-35
lines changed

1 file changed

+57
-35
lines changed

src/Modules/Engine.cpp

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -892,48 +892,70 @@ int __stdcall BinkWait_Detour(void *bink) {
892892
}
893893

894894
#ifdef _WIN32
895-
bool __cdecl CopyPropData_Impl(void *pDecoder, void *pOut, int iProp, void *arg_4) {
896-
auto ppProp = (SendProp **)(((uintptr_t *)pDecoder)[13] + 4 * iProp);
895+
// Original function pointer (naked, no calling convention)
896+
void *g_Original = nullptr;
897897

898-
console->Print("CopyPropData(%p, %p, %d) | ppProp = %p.\n", pDecoder, pOut, iProp, ppProp);
898+
// Handler return structure
899+
struct HookResult {
900+
bool callOriginal;
901+
int returnValue;
902+
};
899903

900-
// if (iProp > 54)
901-
// return false;
904+
HookResult __cdecl Hook_Handler(
905+
int a1,
906+
void *u,
907+
int iClass,
908+
int iSerialNum) {
909+
HookResult result;
902910

903-
// console->Print("pProp = %p.\n", *ppProp);
911+
console->Print("CL_CopyNewEntity(%p, %d, %d).\n", u, iClass, iSerialNum);
904912

905-
return true;
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) {
918+
console->Print("skipping over point_survey.\n");
919+
result.callOriginal = false;
920+
}
921+
922+
return result;
906923
}
907924

908-
void (*CopyPropData)();
909-
void __declspec(naked) CopyPropData_Detour() {
925+
__declspec(naked) void Hook_CL_CopyNewEntity() {
910926
__asm {
911-
pushad
912-
pushfd
913-
914-
mov ecx, dword ptr [esp + 0x20] // eax = pDecoder.
915-
mov edx, dword ptr [esp + 0x08] // esi = pOut.
916-
mov ebx, dword ptr [esp + 0x28] // [esp+4] on entry = pProp.
917-
mov edi, dword ptr [esp + 0x2C] // [esp+8] on entry = arg_4.
918-
919-
push edi
927+
// Save registers (except edi which we need)
928+
push ebp
929+
mov ebp, esp
930+
push esi
920931
push ebx
921-
push edx
922-
push ecx
923-
call CopyPropData_Impl
924-
add esp, 16
925-
926-
test eax, eax
927-
jnz orig
932+
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
928938

929-
popfd
930-
popad
931-
ret 8
939+
call Hook_Handler
940+
add esp, 0x10
941+
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
932951

933-
orig:
934-
popfd
935-
popad
936-
jmp CopyPropData
952+
skip_original:
953+
// Use custom return value
954+
mov eax, edx
955+
pop ebx
956+
pop esi
957+
pop ebp
958+
ret
937959
}
938960
}
939961
#endif
@@ -1222,9 +1244,9 @@ bool Engine::Init() {
12221244
}
12231245

12241246
#ifdef _WIN32
1225-
auto CopyPropData_addr = Memory::Scan<void *>(MODULE("engine"), "55 8B EC 8B 48 ? 8B 55");
1226-
if (MH_CreateHook(CopyPropData_addr, &CopyPropData_Detour, (void **)&CopyPropData) == MH_OK)
1227-
MH_EnableHook(CopyPropData_addr);
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);
12281250
#endif
12291251

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

0 commit comments

Comments
 (0)