Guest User

Untitled

a guest
Mar 28th, 2018
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. #include<map>
  6. #include "Detour.hpp"
  7.  
  8. using uint64 = long long;
  9.  
  10. class WoWObject
  11. {
  12. public:
  13. WoWObject()
  14. {
  15. Guid = 0;
  16. SummonedBy = 0;
  17. XPos = 0;
  18. YPos = 0;
  19. ZPos = 0;
  20. Rotation = 0;
  21. BaseAddress = 0;
  22. UnitFieldsAddress = 0;
  23. Type = 0;
  24. Name = "";
  25. CurrentHealth = 0;
  26. }
  27. uint64 Guid;
  28. long long int SummonedBy;
  29. float XPos;
  30. float YPos;
  31. float ZPos;
  32. float Rotation;
  33. int BaseAddress;
  34. int UnitFieldsAddress;
  35. int16_t Type;
  36. std::string Name;
  37. int CurrentHealth;
  38.  
  39. };
  40.  
  41.  
  42. volatile bool shouldRemoveEndSceneInjection{};
  43. volatile bool endSceneUnhooked{};
  44. volatile bool should_exit{};
  45. std::map<std::string, Detour*> detours{};
  46.  
  47.  
  48. WoWObject* LocalPlayer = new WoWObject();
  49. WoWObject* TempObject = new WoWObject();
  50.  
  51. inline int ClientConnection() { return *(int*)0x00D43318; }
  52. inline int ObjManager() { return ClientConnection() ? *(int*)(ClientConnection() + 0x2218) : 0; }
  53.  
  54. inline uint64 GetLocalPlayerGuid()
  55. {
  56. if (ObjManager())
  57. return *(uint64*)(ObjManager() + 0xC0);
  58. return 0;
  59. }
  60.  
  61. inline uint64 ClntObjMgrGetActivePlayer()
  62. {
  63. int objm = *(int*)(*(int*)(__readfsdword(0x2C) + 4 * *(int*)0x00E2563C) + 8);
  64.  
  65. if (objm)
  66. return *(uint64*)(objm + 0xC0);
  67. return 0;
  68. }
  69.  
  70. inline auto GetLocalPlayer() { return ((int(__cdecl*)())0x00402F40)(); }
  71.  
  72. inline int GetObjectByGuidTypeCheck(uint64 guid, int typemask = -1)
  73. {
  74. return guid ? ((int(__cdecl*)(uint64, int, const char*, int))0x0046B610)(guid, typemask, nullptr, 0) : 0;
  75. }
  76.  
  77. inline auto PerformanceCount() { return ((int(__cdecl*)())0x00749850)(); }
  78.  
  79. inline auto GetTargetGuid() { return *(uint64*)0x00C6E960; }
  80. inline auto GetObjMan() { return *(int*)(*(int*)0x00D43318 + 0x2218); }
  81. inline auto GetAddrByGUID(long long guid) { return ((int(__cdecl*)(long long))0x0046B4E0)(guid); }
  82.  
  83.  
  84. //---------------- END SCENE DETOUR ------------------
  85. int __fastcall EndSceneDetour(int s_device, int edx) //is a __thiscall
  86. {
  87. if (*(int*)(s_device + 0x3864))
  88. {
  89. //printf("player pointer = %X\n", GetAddrByGUID(GetLocalPlayer()));
  90.  
  91. LocalPlayer->BaseAddress = GetLocalPlayer();
  92.  
  93. if (LocalPlayer->BaseAddress)
  94. {
  95. LocalPlayer->XPos = *(float*)(LocalPlayer->BaseAddress + 0xBF0);
  96. std::cout << LocalPlayer->XPos << std::endl;
  97. }
  98. }
  99.  
  100. //-------- return to the original function (and remove injection if needed) --------
  101. auto det = detours["CGxDeviceD3d__ISceneEnd"];
  102. det->Restore();
  103. int res = ((int(__fastcall*)(int, int))det->target)(s_device, edx);
  104. if (shouldRemoveEndSceneInjection)
  105. {
  106. auto it = detours.find("CGxDeviceD3d__ISceneEnd");
  107. delete it->second;
  108. detours.erase(it);
  109.  
  110. endSceneUnhooked = true;
  111. }
  112. else
  113. {
  114. det->Apply();
  115. }
  116. return res;
  117. }
  118.  
  119. DWORD WINAPI hackthread(LPVOID param)
  120. {
  121.  
  122. AllocConsole();
  123. SetConsoleTitle(L"_TBC_Cpp");
  124. FILE* stream;
  125. freopen_s(&stream, "CONOUT$", "w", stdout);
  126.  
  127. detours["CGxDeviceD3d__ISceneEnd"] = new Detour(0x005AB230, (int)EndSceneDetour);
  128.  
  129. //----------------------------------- loop here before exit ----------------------------------
  130. //wait for the numpad 7 to be pressed...
  131. while (!GetAsyncKeyState(VK_NUMPAD7)) { Sleep(250); }
  132.  
  133. //tell the endscene hook to finish
  134. shouldRemoveEndSceneInjection = true;
  135.  
  136. printf("Exiting...\n");
  137.  
  138. //wait the endscene hook to finish...
  139. while (!endSceneUnhooked) {}
  140.  
  141. // unhooks all detours we created
  142. for (auto& det : detours)
  143. delete det.second;
  144. detours.clear();
  145.  
  146. auto conHandle = GetConsoleWindow();
  147. FreeConsole();
  148. PostMessage(conHandle, WM_CLOSE, 0, 0);
  149.  
  150. FreeLibraryAndExitThread((HMODULE)param, NULL);
  151.  
  152. return NULL;
  153. }
  154.  
  155. BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved)
  156. {
  157. switch (dwReason)
  158. {
  159. case DLL_PROCESS_ATTACH:
  160. CreateThread(0, 0, hackthread, hModule, 0, 0); // Added hModule to be passed to hackthread
  161. break;
  162.  
  163. case DLL_PROCESS_DETACH:
  164. break;
  165. }
  166. return TRUE;
  167. }
Advertisement
Add Comment
Please, Sign In to add comment