Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Windows.h>
  2. #include <stdio.h>
  3.  
  4. template< typename Fn >
  5. __forceinline Fn get_vfunc(void* pVmt, int iIndex) {
  6.     return (*(Fn**)pVmt)[iIndex];
  7. }
  8.  
  9. class CBaseEntity {
  10. public:
  11.     char                __pad[0x64];
  12.     int                 index;
  13.     int                 GetHealth();
  14. };
  15.  
  16. int CBaseEntity::GetHealth()
  17. {
  18.     return *(int*)((DWORD)this + 0x000000FC);
  19. }
  20.  
  21. class IClientEntityList {
  22. public:
  23.     CBaseEntity* GetClientEntity(int iIndex)
  24.     {
  25.         // return type  // class to insert // index //args to pass
  26.         return get_vfunc<CBaseEntity*(__thiscall*)(IClientEntityList*, int)>(this, 3)(this, iIndex);
  27.     }
  28. };
  29. class IEngineClient {
  30. public:
  31.     int GetLocalPlayer()
  32.     {
  33.         // return type  // class to insert // index //args to pass
  34.         return get_vfunc<int(__thiscall*)(IEngineClient*)>(this, 12)(this);
  35.     }
  36. };
  37.  
  38. IClientEntityList* EntList;
  39. IEngineClient* Engine;
  40.  
  41. typedef void* (*CreateInterfaceFn)(const char *pName, int *pReturnCode);
  42.  
  43.  
  44. template< typename Interface >
  45. Interface* GetInterface(const char* pszModule, const char* pszInterfaceName) {
  46.     Interface* pTemp = nullptr;
  47.     char szBuf[64] = { 0 };
  48.     auto Factory = (CreateInterfaceFn)GetProcAddress(GetModuleHandleA(pszModule), "CreateInterface");
  49.  
  50.     for (int i = 0; i < 100; i++) {
  51.         sprintf_s(szBuf, "%s%03d", pszInterfaceName, i);
  52.         pTemp = (Interface*)Factory(szBuf, 0);
  53.  
  54.         if (pTemp) break;
  55.     }
  56.  
  57.     return pTemp;
  58. }
  59.  
  60. static void Init() {
  61.     auto pEntList = GetInterface<IClientEntityList>("client.dll", "VClientEntityList");
  62.     auto pEngine = GetInterface<IEngineClient>("engine.dll", "VEngineClient");
  63.     Engine = pEngine;
  64.     EntList = pEntList;
  65.  
  66.     char buf[16];
  67.     sprintf_s(buf, "%d", EntList->GetClientEntity(Engine->GetLocalPlayer())->GetHealth());
  68.     MessageBoxA(NULL, buf, "hi", MB_OK);
  69. }
  70.  
  71. BOOL WINAPI DllMain(void*, DWORD reason, void*) {
  72.     if (reason == DLL_PROCESS_ATTACH)
  73.         CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Init, 0, 0, 0);
  74.  
  75.     return TRUE;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement