Guest User

Untitled

a guest
Apr 24th, 2023
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.57 KB | None | 0 0
  1. #include "gui.h"
  2.  
  3. #include "../ext/imgui/imgui.h"
  4. #include "../ext/imgui/imgui_impl_win32.h"
  5. #include "../ext/imgui/imgui_impl_dx9.h"
  6.  
  7.  
  8. #include <stdexcept>
  9. #include <cstdint>
  10. #include <thread>
  11. #include "offsets.h"
  12.  
  13. extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(
  14. HWND window,
  15. UINT message,
  16. WPARAM wideParam,
  17. LPARAM longParam
  18. );
  19.  
  20.  
  21.  
  22. // window process
  23. LRESULT CALLBACK WindowProcess(
  24. HWND window,
  25. UINT message,
  26. WPARAM wideParam,
  27. LPARAM longParam
  28. );
  29.  
  30. bool gui::SetupWindowClass(const char* windowClassName) noexcept
  31. {
  32. // populate window class
  33. windowClass.cbSize = sizeof(WNDCLASSEX);
  34. windowClass.style = CS_HREDRAW | CS_VREDRAW;
  35. windowClass.lpfnWndProc = DefWindowProc;
  36. windowClass.cbClsExtra = 0;
  37. windowClass.cbWndExtra = 0;
  38. windowClass.hInstance = GetModuleHandle(NULL);
  39. windowClass.hIcon = NULL;
  40. windowClass.hCursor = NULL;
  41. windowClass.hbrBackground = NULL;
  42. windowClass.lpszMenuName = NULL;
  43. windowClass.lpszClassName = windowClassName;
  44. windowClass.hIconSm = NULL;
  45.  
  46. // register
  47. if (!RegisterClassEx(&windowClass))
  48. return false;
  49.  
  50. return true;
  51. }
  52.  
  53. void gui::DestroyWindowClass() noexcept
  54. {
  55. UnregisterClass(
  56. windowClass.lpszClassName,
  57. windowClass.hInstance
  58. );
  59. }
  60.  
  61. bool gui::SetupWindow(const char* windowName) noexcept
  62. {
  63. // create temp window
  64. window = CreateWindow(
  65. windowClass.lpszClassName,
  66. windowName,
  67. WS_OVERLAPPEDWINDOW,
  68. 0,
  69. 0,
  70. 100,
  71. 100,
  72. 0,
  73. 0,
  74. windowClass.hInstance,
  75. 0
  76. );
  77.  
  78. if (!window)
  79. return false;
  80.  
  81. return true;
  82. }
  83.  
  84. void gui::DestroyWindow() noexcept
  85. {
  86. if (window)
  87. DestroyWindow(window);
  88. }
  89.  
  90. bool gui::SetupDirectX() noexcept
  91. {
  92. const auto handle = GetModuleHandle("d3d9.dll");
  93.  
  94. if (!handle)
  95. return false;
  96.  
  97. using CreateFn = LPDIRECT3D9(__stdcall*)(UINT);
  98.  
  99. const auto create = reinterpret_cast<CreateFn>(GetProcAddress(
  100. handle,
  101. "Direct3DCreate9"
  102. ));
  103.  
  104. if (!create)
  105. return false;
  106.  
  107. d3d9 = create(D3D_SDK_VERSION);
  108.  
  109. if (!d3d9)
  110. return false;
  111.  
  112. D3DPRESENT_PARAMETERS params = { };
  113. params.BackBufferWidth = 0;
  114. params.BackBufferHeight = 0;
  115. params.BackBufferFormat = D3DFMT_UNKNOWN;
  116. params.BackBufferCount = 0;
  117. params.MultiSampleType = D3DMULTISAMPLE_NONE;
  118. params.MultiSampleQuality = NULL;
  119. params.SwapEffect = D3DSWAPEFFECT_DISCARD;
  120. params.hDeviceWindow = window;
  121. params.Windowed = 1;
  122. params.EnableAutoDepthStencil = 0;
  123. params.AutoDepthStencilFormat = D3DFMT_UNKNOWN;
  124. params.Flags = NULL;
  125. params.FullScreen_RefreshRateInHz = 0;
  126. params.PresentationInterval = 0;
  127.  
  128. if (d3d9->CreateDevice(
  129. D3DADAPTER_DEFAULT,
  130. D3DDEVTYPE_NULLREF,
  131. window,
  132. D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_DISABLE_DRIVER_MANAGEMENT,
  133. &params,
  134. &device
  135. ) < 0) return false;
  136.  
  137. return true;
  138. }
  139.  
  140. void gui::DestroyDirectX() noexcept
  141. {
  142. if (device)
  143. {
  144. device->Release();
  145. device = NULL;
  146. }
  147.  
  148. if (d3d9)
  149. {
  150. d3d9->Release();
  151. d3d9 = NULL;
  152. }
  153. }
  154.  
  155. void gui::Setup()
  156. {
  157. if (!SetupWindowClass("hackClass001"))
  158. throw std::runtime_error("Failed to create window class.");
  159.  
  160. if (!SetupWindow("Hack Window"))
  161. throw std::runtime_error("Failed to create window.");
  162.  
  163. if (!SetupDirectX())
  164. throw std::runtime_error("Failed to create device.");
  165.  
  166. DestroyWindow();
  167. DestroyWindowClass();
  168. }
  169.  
  170. void gui::SetupMenu(LPDIRECT3DDEVICE9 device) noexcept
  171. {
  172. auto params = D3DDEVICE_CREATION_PARAMETERS{ };
  173. device->GetCreationParameters(&params);
  174.  
  175. window = params.hFocusWindow;
  176.  
  177. originalWindowProcess = reinterpret_cast<WNDPROC>(
  178. SetWindowLongPtr(window, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(WindowProcess))
  179. );
  180.  
  181. ImGui::CreateContext();
  182. ImGui::StyleColorsDark();
  183.  
  184. ImGui_ImplWin32_Init(window);
  185. ImGui_ImplDX9_Init(device);
  186.  
  187. setup = true;
  188. }
  189.  
  190. void gui::Destroy() noexcept
  191. {
  192. ImGui_ImplDX9_Shutdown();
  193. ImGui_ImplWin32_Shutdown();
  194. ImGui::DestroyContext();
  195.  
  196. // retore wnd proc
  197. SetWindowLongPtr(
  198. window,
  199. GWLP_WNDPROC,
  200. reinterpret_cast<LONG_PTR>(originalWindowProcess)
  201. );
  202.  
  203. DestroyDirectX();
  204. }
  205.  
  206. void gui::Render() noexcept
  207. {
  208. static bool checkBoxValueBhop = false; // saves state of checkboxes
  209. static bool checkBoxValueTrigger = false;
  210. static bool checkBoxValueGlow = false;
  211.  
  212. ImGui_ImplDX9_NewFrame();
  213. ImGui_ImplWin32_NewFrame();
  214. ImGui::NewFrame();
  215.  
  216. ImGui::Begin("first menu", &open);
  217.  
  218. if (ImGui::BeginTabBar("tabs"))
  219. {
  220. if (ImGui::BeginTabItem("aimbot"))
  221. {
  222.  
  223. ImGui::Checkbox("Triggerbot", &checkBoxValueTrigger);
  224. if (checkBoxValueTrigger)
  225. {
  226. //Code
  227. }
  228.  
  229. ImGui::EndTabItem();
  230. }
  231.  
  232. if (ImGui::BeginTabItem("visuals"))
  233. {
  234.  
  235. if (ImGui::Checkbox("Glow ESP", &checkBoxValueGlow))
  236. {
  237. //Code
  238. }
  239.  
  240. ImGui::EndTabItem();
  241. }
  242.  
  243. if (ImGui::BeginTabItem("misc"))
  244. {
  245. ImGui::Checkbox("Bunnyhop", &checkBoxValueBhop);
  246. if (checkBoxValueBhop) // check if checkbox is active
  247. {
  248. //code
  249.  
  250. }
  251.  
  252. ImGui::Text("Knifechanger");
  253.  
  254. if (ImGui::CollapsingHeader("Select Knife", ImGuiTreeNodeFlags_CollapsingHeader))
  255. {
  256. static const char* items[] =
  257. {
  258. "Karambit",
  259. "Talon",
  260. "Stiletto",
  261. "Butterfly",
  262. "M9 Bayonet"
  263. };
  264.  
  265. static int selected = 0;
  266.  
  267. ImGui::ListBox("", &selected, items, 5, 5);
  268.  
  269. if (selected != -1)
  270. {
  271. ImGui::SetNextWindowCollapsed(true);
  272. }
  273. }
  274. ImGui::EndTabItem();
  275. }
  276. if (ImGui::BeginTabItem("config"))
  277. {
  278. if (ImGui::CollapsingHeader("Config", ImGuiTreeNodeFlags_CollapsingHeader))
  279. {
  280. static const char* items[] =
  281. {
  282. "Config 1",
  283. "Config 2",
  284. "Config 3"
  285. };
  286.  
  287. static int selected = 0;
  288.  
  289. ImGui::ListBox("", &selected, items, 3, 3);
  290.  
  291. if (selected != -1)
  292. {
  293. ImGui::SetNextWindowCollapsed(true);
  294. }
  295. }
  296.  
  297. if (ImGui::Button("Load"))
  298. {
  299. // Code
  300. }
  301.  
  302. if (ImGui::Button("Save"))
  303. {
  304. //Code
  305. }
  306.  
  307. if (ImGui::Button("Delete"))
  308. {
  309.  
  310. }
  311.  
  312. ImGui::EndTabItem();
  313. }
  314.  
  315. ImGui::EndTabBar();
  316. }
  317.  
  318. ImGui::End();
  319.  
  320. ImGui::EndFrame();
  321. ImGui::Render();
  322. ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
  323. }
  324.  
  325.  
  326. LRESULT CALLBACK WindowProcess(
  327. HWND window,
  328. UINT message,
  329. WPARAM wideParam,
  330. LPARAM longParam
  331. )
  332. {
  333. // toogle menu
  334. if (GetAsyncKeyState(VK_INSERT) & 1)
  335. gui::open = !gui::open;
  336.  
  337. // pass messages to imgui
  338. if (gui::open && ImGui_ImplWin32_WndProcHandler(
  339. window,
  340. message,
  341. wideParam,
  342. longParam
  343. )) return 1L;
  344.  
  345. return CallWindowProc(
  346. gui::originalWindowProcess,
  347. window,
  348. message,
  349. wideParam,
  350. longParam
  351. );
  352. }
  353.  
Advertisement
Add Comment
Please, Sign In to add comment