Code:
public:
DWORD Addr;
DWORD SaveStub;
Detour() {};
~Detour() {};
virtual void RegisterDetour(DWORD Address, PVOID Destination) {
if (IsZero(&DetourAsmSection, sizeof(DetourAsmSection)))
InitializeCriticalSection(&DetourAsmSection);
EnterCriticalSection(&DetourAsmSection);
DetourIndex = DetourAsmIndex;
SaveStub = (DWORD)&DetourAsm[DetourIndex];
// save the address incase we take-down the detour
Addr = Address;
// Copy the asm bytes before we replace it with the hook
memcpy(OriginalAsm, (PVOID)Address, 0x10);
// increment the index for the space we are using for the stub
DetourAsmIndex += DetourFunctionStart(Address, SaveStub, Destination);
LeaveCriticalSection(&DetourAsmSection);
}
virtual void StopDetour()
{
if (Addr && MmIsAddressValid((PVOID)Addr))
memcpy((PVOID)Addr, OriginalAsm, 0x10);
}
virtual _ClassType CallDetour(...)
{
SetupCaller();
return ((_ClassType(*)(...))SaveStub)();
}
virtual BYTE* ReturnOriginal(...)
{
return OriginalAsm;
}
};
Detour<char*> LabelShite;
char* RegisterDetour(int id, char* label) {
if (strstr(label, ("LOADING_MPLAYER_L")) != NULL)
return "Loading The Engine Online!";
if (strstr(label, "LOADING_SPLAYER_L") != NULL)
return "Loading The Engine Offline!";
return LabelShite.CallDetour(id, label);
}
LabelShite.SetupDetour(0x82EE30E8, RegisterDetour);