Facebook
From Harmless Elephant, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 314
  1. #include "plugin.h"
  2. #include "game_sa\RenderWare.h"
  3. #include "game_sa\common.h"
  4. #include "game_sa\CMenuManager.h"
  5. #include "game_sa\CRadar.h"
  6. #include "game_sa\CWorld.h"
  7. #include "game_sa\RenderWare.h"
  8. #include "game_sa\CFont.h"
  9.  
  10. #include <Psapi.h>
  11.  
  12. #pragma comment( lib, "psapi.lib" )
  13.  
  14. #define E_ADDR_GAMEPROCESS      0x53E981
  15.  
  16. using namespace plugin;
  17.  
  18. #pragma pack(push, 1)
  19. typedef struct stOpcodeRelCall
  20. {
  21.         BYTE bOpcode;
  22.         DWORD dwRelAddr;
  23. } OpcodeRelCall;
  24. #pragma pack(pop)
  25.  
  26. class GPS {
  27. private:
  28.         HANDLE hThread = NULL;
  29.  
  30. public:
  31.         GPS() {
  32.                 hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)GPS::init, (LPVOID)this, 0, (LPDWORD)NULL);
  33.         }
  34.  
  35.         ~GPS() {
  36.                 // Check if thread still running on process
  37.                 if (hThread != NULL)
  38.                         TerminateThread(hThread, 0);
  39.         }
  40.  
  41.         static LPVOID WINAPI init(LPVOID *lpParam) {
  42.                 MODULEINFO miSampDll;
  43.                 DWORD dwSampDllBaseAddr, dwSampDllEndAddr, dwCallAddr;
  44.  
  45.                 GPS *sender = (GPS *)lpParam;
  46.  
  47.                 stOpcodeRelCall *fnGameProc = (stOpcodeRelCall *)E_ADDR_GAMEPROCESS;
  48.  
  49.                 // Check if E_ADDR_GAMEPROCESS opcode is a relative call (0xE8)
  50.                 while (fnGameProc->bOpcode != 0xE8)
  51.                         Sleep(100);
  52.  
  53.                 while (true) {
  54.                         Sleep(100);
  55.  
  56.                         // Get samp.dll module information to get base address and end address
  57.                         if (!GetModuleInformation(GetCurrentProcess(), GetModuleHandle("samp.dll"), &miSampDll, sizeof(MODULEINFO))) {
  58.                                 continue;
  59.                         }
  60.  
  61.                         // Some stupid calculation
  62.                         dwSampDllBaseAddr = (DWORD)miSampDll.lpBaseOfDll;
  63.                         dwSampDllEndAddr = dwSampDllBaseAddr + miSampDll.SizeOfImage;
  64.  
  65.                         // Calculate destination address by offset and relative call opcode size
  66.                         dwCallAddr = fnGameProc->dwRelAddr + E_ADDR_GAMEPROCESS + 5;
  67.  
  68.                         // Check if dwCallAddr is a samp.dll's hook address,
  69.                         // to make sure this plugin hook (Events::gameProcessEvent) not replaced by samp.dll
  70.                         if (dwCallAddr >= dwSampDllBaseAddr && dwCallAddr <= dwSampDllEndAddr)
  71.                                 break;
  72.                 }
  73.  
  74.                 // Just wait a few secs for the game loaded fully to avoid any conflicts and crashes
  75.                 // I don't know what the elegant way is :)
  76.                 while (!FindPlayerPed(0))
  77.                         Sleep(5000);
  78.  
  79.                 // Run the plugin
  80.                 sender->run();
  81.  
  82.                 // Reset the thread handle
  83.                 sender->hThread = NULL;
  84.  
  85.                 return NULL;
  86.         }
  87.  
  88.         void run() {
  89.  
  90.         }
  91.  
  92. } gps;

Replies to Untitled rss

Title Name Language When
Re: Untitled Big Lemur text 5 Years ago.