Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "main.h"
- DWORD Hook_ChatMessage_Addr;
- bool message_permission, hooks_is_created;
- void __stdcall ChangeString(char* str)
- {
- if (message_permission)
- {
- message_permission = false;
- return;
- }
- if (strstr(str, "Warning:"))
- {
- std::string newstr = str;
- newstr.replace(newstr.find("Warning"), newstr.find(":"), "NedoWarning");
- strcpy_s(str, 256, newstr.c_str());
- }
- else if (strstr(str, "<Warning>"))
- {
- std::string newstr = str;
- newstr.replace(newstr.find("<Warning>"), newstr.find(" "), "NedoWarning:");
- strcpy_s(str, 256, newstr.c_str());
- }
- }
- void __declspec(naked) Hook_ChatMessage()
- {
- __asm
- {
- add esp, 0x4
- pop esi
- add esp, 0x48
- pushad
- pushfd
- push esi
- call ChangeString
- popfd
- popad
- ret 0xC
- }
- }
- void create_jmp_hook(DWORD addr, DWORD dwJumpTo, size_t size)
- {
- DWORD old_protect;
- VirtualProtect((LPVOID)addr, size, PAGE_EXECUTE_READWRITE, &old_protect);
- *reinterpret_cast<BYTE*>(addr) = 0xE9;
- *reinterpret_cast<DWORD*>(addr + 0x1) = dwJumpTo - addr - 0x5;
- for (DWORD i = 0x5; i < size; i++)
- *reinterpret_cast<BYTE*>(addr + i) = 0x90;
- VirtualProtect((LPVOID)addr, size, old_protect, &old_protect);
- }
- void init_hooks()
- {
- Hook_ChatMessage_Addr = (DWORD)GetModuleHandleA("samp.dll") + 0x63C8A;
- create_jmp_hook(Hook_ChatMessage_Addr, (DWORD)Hook_ChatMessage, 7);
- hooks_is_created = true;
- }
Advertisement
Add Comment
Please, Sign In to add comment