Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. #pragma once
  2. #include <map>
  3. #include <string>
  4. #include <d3d9.h>
  5. #include "..\Microsoft DirectX SDK2010\Include\d3dx9core.h"
  6. #include "Memory\Detour.hpp"
  7. #include "Memory\Patch.hpp"
  8. #include "Util\Timer.hpp"
  9. #include "Util\Helpers.hpp"
  10. #include "Lua\Lua.hpp"
  11. #include "WowStuff\WowFuncs.hpp"
  12. #include "Objects\Spell.hpp"
  13. #include "Routines\PaladinLeveling.hpp"
  14. #include "Graphics.hpp"
  15. #include "ChatCommandHandler.hpp"
  16.  
  17. volatile bool shouldRemovePresentSceneInjection{};
  18. volatile bool PresentSceneUnhooked{};
  19. std::map<std::string, MemoryOperation*> g_memops{};
  20. volatile bool should_exit{};
  21. volatile bool do_something{};
  22.  
  23. int frameCount = 0;
  24. Graphics* graph = nullptr;
  25. timer afk_timer;
  26. int dummy_counter;
  27.  
  28. inline void display(const std::string& name, const std::string& value)
  29. {
  30. if (!graph)
  31. return;
  32.  
  33. auto line = name + " = " + value;
  34. graph->AddTextLine(line);
  35. }
  36.  
  37. int __stdcall ResetDetour(int /*device*/, int /*pp*/);
  38.  
  39. //---------------- END SCENE DETOUR ------------------
  40. int __fastcall PresentSceneDetour(int s_device, int edx, int mask) //is a thiscall
  41. {
  42. if (*(int*)(s_device + 0xF58) && *(int*)(s_device + 0x3B28))
  43. {
  44. auto scene = *(int*)(s_device + 0x397C);
  45. auto reset_ptr = *(int*)(*(int*)scene + 0x40);
  46.  
  47. if (g_memops["Reset"] == nullptr)
  48. g_memops["Reset"] = new Detour(reset_ptr, (int)ResetDetour);
  49.  
  50. OM_Pulse();
  51.  
  52. if (frameCount % 30 == 0)
  53. {
  54. //printf("%d ", frameCount);
  55. printf(".");
  56. }
  57. if (frameCount == 0)
  58. chat("CppBot started.");
  59.  
  60. if (graph == nullptr && scene)
  61. graph = new Graphics();
  62.  
  63. if (afk_timer.elapsedTime() > 150)
  64. {
  65. afk_timer.start();
  66. *(int*)0x00B499A4 = PerformanceCount();
  67. }
  68.  
  69. graph->Pulse(scene);
  70.  
  71. auto lpa = GetLocalPlayer();
  72. if (lpa)
  73. {
  74. if (!ChatLine.empty())
  75. {
  76. HandleChatCommand(ChatLine);
  77. ChatLine = "";
  78. }
  79.  
  80. auto me = LocalPlayer(GetLocalPlayer());
  81.  
  82. if (!known_spells_updated)
  83. UpdateKnownSpells();
  84.  
  85. #pragma region TestRegion
  86.  
  87.  
  88. // here is an area for random tests
  89. //if (do_something)
  90. if (frameCount % 10 == 0)
  91. {
  92.  
  93.  
  94. //auto sp = Spell("Aspect of the Hawk");
  95. //sp.Use(me->Guid());
  96. //*(int*)(me->addr + 0x1A64) = dummy_counter;
  97.  
  98. //me.Race() = RACE_DWARF;
  99. //*(int*)me.DisplayId() = dummy_counter;
  100. //*(int*)me.NativeDisplayId() = dummy_counter;
  101.  
  102. //me.UpdateDisplayInfo();
  103. //((int(__thiscall*)(int))0x006E1D70)(lpa);
  104.  
  105. //printf("player pointer = %X\n", me.addr);
  106.  
  107. //chat(std::to_string(dummy_counter));
  108. ++dummy_counter;
  109. do_something = false;
  110. }
  111.  
  112. auto sp = Spell("Chimera Shot");
  113.  
  114. /*display("IsAutoshooting", BoolToString(me->IsAutoshootingH()));
  115. display("GetAutoshooting", std::to_string(me->GetAutoshootingH()));*/
  116.  
  117. if (target)
  118. {
  119. //display("target", target->Name());
  120. }
  121. #pragma endregion
  122.  
  123. }
  124.  
  125. Common();
  126. frameCount++;
  127. }
  128.  
  129. //-------- return to the original function (and remove injection if needed) --------
  130. auto det = g_memops["CGxDeviceD3d__ScenePresent"];
  131. det->Restore();
  132. int res = ((int(__thiscall*)(int, int))det->target)(s_device, mask);
  133. if (shouldRemovePresentSceneInjection)
  134. {
  135. chat("Removing CGxDeviceD3d::ScenePresent injection");
  136. auto it = g_memops.find("CGxDeviceD3d__ScenePresent");
  137. delete it->second;
  138. g_memops.erase(it);
  139.  
  140. if (graph != nullptr)
  141. delete graph;
  142.  
  143. PresentSceneUnhooked = true;
  144. }
  145. else
  146. {
  147. det->Apply();
  148. }
  149. return res;
  150. }
  151.  
  152. int __stdcall ResetDetour(int device, int pp)
  153. {
  154. printf("\nResetDetour\n");
  155. chat("ResetDetour");
  156.  
  157. if (graph != nullptr)
  158. graph->ReleaseFont();
  159.  
  160. //---------------- return to the original function ----------------
  161. auto det = g_memops["Reset"];
  162. det->Restore();
  163. int res = ((int(__stdcall*)(int, int))det->target)(device, pp);
  164. det->Apply();
  165. return res;
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement