MeepDarknessMeep

gmsv_disconnect_win32

Mar 2nd, 2015
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #define WIN32_LEAN_AND_MEAN
  2. #define VC_EXTRALEAN
  3. #include <Windows.h>
  4. #include <string>
  5. #define GMMODULE
  6. #include "Interface.h"
  7.  
  8. void *sigscan(const char *sig, void *_base)
  9. {
  10.     char *base = (char *)_base;
  11.     while (!IsBadCodePtr((FARPROC)base))
  12.     {
  13.         const char *cursig = sig;
  14.         char *curbase = base;
  15.         while (!IsBadCodePtr((FARPROC)curbase))
  16.         {
  17.             if (*cursig == 0)
  18.                 return base;
  19.             if (*cursig != '?' && *cursig != *curbase)
  20.                 break;
  21.             cursig++;
  22.             curbase++;
  23.         }
  24.  
  25.         base++;
  26.     }
  27.     return 0;
  28. }
  29.  
  30. char newmessage[128] = "Disconnect by user.";
  31.  
  32. int SetDisconnectMessage(lua_State *state)
  33. {
  34.     strcpy_s(newmessage, sizeof(newmessage), LUA->GetString(1));
  35.     return 0;
  36. }
  37.  
  38. GMOD_MODULE_OPEN()
  39. {
  40.     // search for "Disconnect by user" xrefs for the sig
  41.  
  42.     const char ** message = reinterpret_cast<const char **>(
  43.         reinterpret_cast<char *>(sigscan("\x68????\xFF\xD2\x89\x7E\x10\x5F\x5E\x8B\xE5\x5D\xC2\x08\x00", GetModuleHandleA("engine.dll"))) + 1
  44.     );
  45.  
  46.     DWORD old_prot;
  47.     VirtualProtect(message, sizeof(*message), PAGE_EXECUTE_READWRITE, &old_prot);
  48.     *message = newmessage;
  49.     VirtualProtect(message, sizeof(*message), old_prot, &old_prot);
  50.  
  51.     LUA->PushCFunction(&SetDisconnectMessage);
  52.     LUA->SetField(-10002, "SetDisconnectMessage");
  53.  
  54.     return 0;
  55. }
  56.  
  57. GMOD_MODULE_CLOSE() { return 0; }
Advertisement
Add Comment
Please, Sign In to add comment