Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "gui.h"
- #include "../ext/imgui/imgui.h"
- #include "../ext/imgui/imgui_impl_win32.h"
- #include "../ext/imgui/imgui_impl_dx9.h"
- #include <stdexcept>
- #include <cstdint>
- #include <thread>
- #include "offsets.h"
- extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(
- HWND window,
- UINT message,
- WPARAM wideParam,
- LPARAM longParam
- );
- // window process
- LRESULT CALLBACK WindowProcess(
- HWND window,
- UINT message,
- WPARAM wideParam,
- LPARAM longParam
- );
- bool gui::SetupWindowClass(const char* windowClassName) noexcept
- {
- // populate window class
- windowClass.cbSize = sizeof(WNDCLASSEX);
- windowClass.style = CS_HREDRAW | CS_VREDRAW;
- windowClass.lpfnWndProc = DefWindowProc;
- windowClass.cbClsExtra = 0;
- windowClass.cbWndExtra = 0;
- windowClass.hInstance = GetModuleHandle(NULL);
- windowClass.hIcon = NULL;
- windowClass.hCursor = NULL;
- windowClass.hbrBackground = NULL;
- windowClass.lpszMenuName = NULL;
- windowClass.lpszClassName = windowClassName;
- windowClass.hIconSm = NULL;
- // register
- if (!RegisterClassEx(&windowClass))
- return false;
- return true;
- }
- void gui::DestroyWindowClass() noexcept
- {
- UnregisterClass(
- windowClass.lpszClassName,
- windowClass.hInstance
- );
- }
- bool gui::SetupWindow(const char* windowName) noexcept
- {
- // create temp window
- window = CreateWindow(
- windowClass.lpszClassName,
- windowName,
- WS_OVERLAPPEDWINDOW,
- 0,
- 0,
- 100,
- 100,
- 0,
- 0,
- windowClass.hInstance,
- 0
- );
- if (!window)
- return false;
- return true;
- }
- void gui::DestroyWindow() noexcept
- {
- if (window)
- DestroyWindow(window);
- }
- bool gui::SetupDirectX() noexcept
- {
- const auto handle = GetModuleHandle("d3d9.dll");
- if (!handle)
- return false;
- using CreateFn = LPDIRECT3D9(__stdcall*)(UINT);
- const auto create = reinterpret_cast<CreateFn>(GetProcAddress(
- handle,
- "Direct3DCreate9"
- ));
- if (!create)
- return false;
- d3d9 = create(D3D_SDK_VERSION);
- if (!d3d9)
- return false;
- D3DPRESENT_PARAMETERS params = { };
- params.BackBufferWidth = 0;
- params.BackBufferHeight = 0;
- params.BackBufferFormat = D3DFMT_UNKNOWN;
- params.BackBufferCount = 0;
- params.MultiSampleType = D3DMULTISAMPLE_NONE;
- params.MultiSampleQuality = NULL;
- params.SwapEffect = D3DSWAPEFFECT_DISCARD;
- params.hDeviceWindow = window;
- params.Windowed = 1;
- params.EnableAutoDepthStencil = 0;
- params.AutoDepthStencilFormat = D3DFMT_UNKNOWN;
- params.Flags = NULL;
- params.FullScreen_RefreshRateInHz = 0;
- params.PresentationInterval = 0;
- if (d3d9->CreateDevice(
- D3DADAPTER_DEFAULT,
- D3DDEVTYPE_NULLREF,
- window,
- D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_DISABLE_DRIVER_MANAGEMENT,
- ¶ms,
- &device
- ) < 0) return false;
- return true;
- }
- void gui::DestroyDirectX() noexcept
- {
- if (device)
- {
- device->Release();
- device = NULL;
- }
- if (d3d9)
- {
- d3d9->Release();
- d3d9 = NULL;
- }
- }
- void gui::Setup()
- {
- if (!SetupWindowClass("hackClass001"))
- throw std::runtime_error("Failed to create window class.");
- if (!SetupWindow("Hack Window"))
- throw std::runtime_error("Failed to create window.");
- if (!SetupDirectX())
- throw std::runtime_error("Failed to create device.");
- DestroyWindow();
- DestroyWindowClass();
- }
- void gui::SetupMenu(LPDIRECT3DDEVICE9 device) noexcept
- {
- auto params = D3DDEVICE_CREATION_PARAMETERS{ };
- device->GetCreationParameters(¶ms);
- window = params.hFocusWindow;
- originalWindowProcess = reinterpret_cast<WNDPROC>(
- SetWindowLongPtr(window, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(WindowProcess))
- );
- ImGui::CreateContext();
- ImGui::StyleColorsDark();
- ImGui_ImplWin32_Init(window);
- ImGui_ImplDX9_Init(device);
- setup = true;
- }
- void gui::Destroy() noexcept
- {
- ImGui_ImplDX9_Shutdown();
- ImGui_ImplWin32_Shutdown();
- ImGui::DestroyContext();
- // retore wnd proc
- SetWindowLongPtr(
- window,
- GWLP_WNDPROC,
- reinterpret_cast<LONG_PTR>(originalWindowProcess)
- );
- DestroyDirectX();
- }
- void gui::Render() noexcept
- {
- static bool checkBoxValueBhop = false; // saves state of checkboxes
- static bool checkBoxValueTrigger = false;
- static bool checkBoxValueGlow = false;
- ImGui_ImplDX9_NewFrame();
- ImGui_ImplWin32_NewFrame();
- ImGui::NewFrame();
- ImGui::Begin("first menu", &open);
- if (ImGui::BeginTabBar("tabs"))
- {
- if (ImGui::BeginTabItem("aimbot"))
- {
- ImGui::Checkbox("Triggerbot", &checkBoxValueTrigger);
- if (checkBoxValueTrigger)
- {
- //Code
- }
- ImGui::EndTabItem();
- }
- if (ImGui::BeginTabItem("visuals"))
- {
- if (ImGui::Checkbox("Glow ESP", &checkBoxValueGlow))
- {
- //Code
- }
- ImGui::EndTabItem();
- }
- if (ImGui::BeginTabItem("misc"))
- {
- ImGui::Checkbox("Bunnyhop", &checkBoxValueBhop);
- if (checkBoxValueBhop) // check if checkbox is active
- {
- //code
- }
- ImGui::Text("Knifechanger");
- if (ImGui::CollapsingHeader("Select Knife", ImGuiTreeNodeFlags_CollapsingHeader))
- {
- static const char* items[] =
- {
- "Karambit",
- "Talon",
- "Stiletto",
- "Butterfly",
- "M9 Bayonet"
- };
- static int selected = 0;
- ImGui::ListBox("", &selected, items, 5, 5);
- if (selected != -1)
- {
- ImGui::SetNextWindowCollapsed(true);
- }
- }
- ImGui::EndTabItem();
- }
- if (ImGui::BeginTabItem("config"))
- {
- if (ImGui::CollapsingHeader("Config", ImGuiTreeNodeFlags_CollapsingHeader))
- {
- static const char* items[] =
- {
- "Config 1",
- "Config 2",
- "Config 3"
- };
- static int selected = 0;
- ImGui::ListBox("", &selected, items, 3, 3);
- if (selected != -1)
- {
- ImGui::SetNextWindowCollapsed(true);
- }
- }
- if (ImGui::Button("Load"))
- {
- // Code
- }
- if (ImGui::Button("Save"))
- {
- //Code
- }
- if (ImGui::Button("Delete"))
- {
- }
- ImGui::EndTabItem();
- }
- ImGui::EndTabBar();
- }
- ImGui::End();
- ImGui::EndFrame();
- ImGui::Render();
- ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
- }
- LRESULT CALLBACK WindowProcess(
- HWND window,
- UINT message,
- WPARAM wideParam,
- LPARAM longParam
- )
- {
- // toogle menu
- if (GetAsyncKeyState(VK_INSERT) & 1)
- gui::open = !gui::open;
- // pass messages to imgui
- if (gui::open && ImGui_ImplWin32_WndProcHandler(
- window,
- message,
- wideParam,
- longParam
- )) return 1L;
- return CallWindowProc(
- gui::originalWindowProcess,
- window,
- message,
- wideParam,
- longParam
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment