Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool checksound = false;
- void hookPlaySound(const char* sample, float* origin)
- {
- checksound = true;
- }
- HANDLE hProcess = 0;
- DWORD hw_dll_offset = 0;
- DWORD client_dll_offset = 0;
- void func_patch(void)
- {
- if (!hProcess)
- {
- HANDLE hModuleSnap = NULL;
- MODULEENTRY32 me32 = { NULL };
- int more;
- DWORD hwsize = NULL, clsize = NULL;
- hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, NULL);
- if (!hModuleSnap) return;
- me32.dwSize = sizeof(MODULEENTRY32);
- more = Module32First(hModuleSnap, &me32);
- while (more)
- {
- if (strlen(me32.szModule) > 5 && !strcmpi(me32.szModule + strlen(me32.szModule) - 6, "hw.dll"))
- {
- hw_dll_offset = (unsigned long)me32.modBaseAddr;
- hwsize = me32.modBaseSize;
- }
- if (strlen(me32.szModule) > 9 && !strcmpi(me32.szModule + strlen(me32.szModule) - 10, "client.dll"))
- {
- client_dll_offset = (unsigned long)me32.modBaseAddr;
- clsize = me32.modBaseSize;
- }
- more = Module32Next(hModuleSnap, &me32);
- }
- CloseHandle(hModuleSnap);
- hProcess = GetCurrentProcess();
- if (!hProcess || !hw_dll_offset || !client_dll_offset)
- {
- g_Engine.pfnConsolePrint("patch failure\n");
- return;
- }
- }
- if (!strcmp(g_Engine.Cmd_Argv(1), "sound"))
- {
- static DWORD pOrgPlaySound;
- pOrgPlaySound = (DWORD)g_Engine.pEventAPI->EV_PlaySound;
- goto label_continue;
- label_destination:
- __asm {
- push ebp;
- mov ebp, esp;
- pushad;
- mov eax, dword ptr[ebp + 0x0C];
- push eax;
- mov eax, dword ptr[ebp + 0x14];
- push eax;
- call hookPlaySound;
- pop eax;
- pop eax;
- popad;
- pop ebp;
- // caller statements
- sub esp, 0x48;
- push ebx;
- mov ebx, dword ptr[esp + 0x68];
- // return to caller:
- mov eax, pOrgPlaySound;
- add eax, 0x08;
- jmp eax;
- };
- label_continue:
- char patch[8] =
- {
- (char)0xB8, (char)0x00, (char)0x00, (char)0x00,
- (char)0x00, (char)0xFF, (char)0xE0, (char)0x90
- };
- __asm {
- mov eax, offset label_destination;
- mov dword ptr[patch + 1], eax;
- }
- DWORD offset1 = 0x27610;
- bool status = WriteProcessMemory(hProcess, (LPVOID)(hw_dll_offset + offset1), patch, 8, NULL);
- if (status)
- {
- g_Engine.pfnConsolePrint("sound patch applied\n");
- }
- else
- {
- g_Engine.pfnConsolePrint("sound patch failed\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement