Created
December 1, 2022 08:15
-
-
Save The-Doggy/75173bedbda30945b3169ed65cb37ca5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <sourcemod> | |
| #include <sdktools> | |
| #include <dhooks> | |
| /* | |
| Signature for _ZN13BaseMenuStyle16ClientPressedKeyEij: | |
| 55 89 E5 53 57 56 81 EC 7C 04 00 00 | |
| \x55\x89\xE5\x53\x57\x56\x81\xEC\x7C\x04\x00\x00 | |
| */ | |
| int BaseMenuStyle_ClientPressedKey_Sig_Lin[] = | |
| { | |
| 0x55, 0x89, 0xE5, 0x53, 0x57, | |
| 0x56, 0x81, 0xEC, 0x7C, 0x04 | |
| } | |
| public void OnPluginStart() | |
| { | |
| /* | |
| start [0xEBF75000] size [0x137900] end [0xEC0AC900] | |
| start [0xEBF0C000] size [0x137900] end [0xEC043900] | |
| start [0xEBF0C000] size [0x137900] end [0xEC043900] | |
| start [0xEC00C000] size [0x137900] end [0xEC143900] | |
| start [0xEBF45000] size [0x137900] end [0xEC07C900] | |
| somewhere around EBF0C000???? | |
| */ | |
| Address sourcemod_hl2dm_so_addr = view_as<Address>(0xEB000000); | |
| Address BaseMenuStyle_ClientPressedKey_addr = FindPattern(sourcemod_hl2dm_so_addr, 0x10000000, BaseMenuStyle_ClientPressedKey_Sig_Lin, sizeof(BaseMenuStyle_ClientPressedKey_Sig_Lin)); | |
| DynamicDetour dhook = DHookCreateDetour(BaseMenuStyle_ClientPressedKey_addr, CallConv_THISCALL, ReturnType_Void, ThisPointer_Address); | |
| dhook.AddParam(HookParamType_Int); | |
| dhook.AddParam(HookParamType_Int); | |
| if(dhook.Enable(Hook_Pre, Detour_ClientPressedKey)) | |
| { | |
| LogMessage("Successfully detoured BaseMenuStyle::ClientPressedKey"); | |
| } | |
| else | |
| { | |
| SetFailState("Failed to detour BaseMenuStyle::ClientPressedKey"); | |
| } | |
| } | |
| public MRESReturn Detour_ClientPressedKey(int pThis, DHookParam hParams) | |
| { | |
| int client = hParams.Get(1); | |
| if(client > 0 && client <= MaxClients && IsClientInGame(client)) | |
| { | |
| LogMessage("%N pressed key", client); | |
| } | |
| return MRES_Ignored; | |
| } | |
| stock int ReadByte(Address pAddr) | |
| { | |
| if (pAddr == Address_Null) | |
| { | |
| return -1; | |
| } | |
| return LoadFromAddress(pAddr, NumberType_Int8); | |
| } | |
| stock Address FindPattern(Address pStart, int iSize, int[] pattern, int iPatternSize) | |
| { | |
| for (int i = 0; i < iSize; i++) | |
| { | |
| if (ReadByte(pStart) == pattern[0]) | |
| { | |
| bool bFound = true; | |
| for (int j = 1; j < iPatternSize; j++) | |
| { | |
| int iDestByte = ReadByte(pStart + view_as<Address>(j)); | |
| int iSrcByte = pattern[j]; | |
| if (iSrcByte != 0xFF) | |
| { | |
| if (iDestByte != iSrcByte) | |
| { | |
| bFound = false; | |
| break; | |
| } | |
| } | |
| } | |
| if (bFound) | |
| { | |
| return (pStart); | |
| } | |
| } | |
| pStart++; | |
| } | |
| return Address_Null; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment