Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 06:22

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



ImGui Menu Problem

Discussion on ImGui Menu Problem within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Jul 2017
Posts: 6
Received Thanks: 0
ImGui Menu Problem

am created an intenal hack for game "Wolfteam" and i use imgui for that cheat but i had problem
After entering the looby and game room the menu show normaly , after that when game end ( room exit ) the resolution is changed or when i pressed alt + tab the menu closes (hidden) .

what could be the problem?
I worked hard over and over again for two weeks and couldn't find the solution

Hook : Min-Hook

Video Of The Problem:


My Codes :

hooks.h :
Code:
#pragma once
#include "gui.h"

namespace hooks
{
	void Setup();
	void Destroy() noexcept;

	constexpr void* VirtualFunction(void* thisptr, size_t index) noexcept {
		return (*static_cast<void***>(thisptr))[index];
	}

	using DrawIndexedPrimitiveFn = HRESULT(__stdcall*)(LPDIRECT3DDEVICE9, D3DPRIMITIVETYPE, INT, UINT, UINT, UINT, UINT);
	inline DrawIndexedPrimitiveFn DrawIndexedPrimitiveOriginal;
	HRESULT __stdcall DrawIndexedPrimitive(LPDIRECT3DDEVICE9 device, D3DPRIMITIVETYPE PrimType, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount);

	using EndSceneFn = long(__thiscall*)(void*, IDirect3DDevice9*) noexcept;
	inline EndSceneFn EndSceneOriginal = nullptr;
	long __stdcall EndScene(IDirect3DDevice9* device) noexcept;

	using ResetFn = HRESULT(__thiscall*)(void*, IDirect3DDevice9* , D3DPRESENT_PARAMETERS*) noexcept;
	inline ResetFn ResetOriginal = nullptr;
	HRESULT __stdcall Reset(IDirect3DDevice9* device, D3DPRESENT_PARAMETERS* params) noexcept;


}
hooks.cpp :
Code:
#include "hooks.h"
#include "stdexcept"

#include "intrin.h"
#include "../ext/minhook/minhook.h"

#include "../ext/imgui/imgui.h"
#include "../ext/imgui/imgui_impl_win32.h"
#include "../ext/imgui/imgui_impl_dx9.h"
#include "core/variables.h"

using namespace hooks;


void hooks::Setup()
{
	if (MH_Initialize())
		throw std::runtime_error("Unable To Initialize MinHook");

	if (MH_CreateHook(VirtualFunction(gui::device, 82),
		&DrawIndexedPrimitive,
		reinterpret_cast<LPVOID*>(&DrawIndexedPrimitiveOriginal)
	)) throw std::runtime_error("Unable To Hook DrawIndexedPrimitive()");

	if (MH_CreateHook(VirtualFunction(gui::device, 42), 
		&EndScene,
		reinterpret_cast<void**>(&EndSceneOriginal)
	)) throw std::runtime_error("Unable To Hook EndScene()");

	if (MH_CreateHook(VirtualFunction(gui::device, 16),
		&Reset,
		reinterpret_cast<void**>(&ResetOriginal)
	)) throw std::runtime_error("Unable To Hook Reset()");

	if (MH_EnableHook(MH_ALL_HOOKS))
		throw std::runtime_error("Unable To enable Hooks");

	gui::DestroyDirectX();
}
void hooks::Destroy() noexcept
{
	MH_DisableHook(MH_ALL_HOOKS);
	MH_RemoveHook(MH_ALL_HOOKS);
	MH_Uninitialize();
}

long __stdcall hooks::EndScene(IDirect3DDevice9* device) noexcept
{
	const auto result = EndSceneOriginal(device, device);


	if (!gui::setup)
		gui::SetupMenu(device);

	if (gui::open)
		gui::Render();

	return result;

}

HRESULT __stdcall hooks::Reset(IDirect3DDevice9* device, D3DPRESENT_PARAMETERS* params) noexcept
{
	ImGui_ImplDX9_InvalidateDeviceObjects();
	const HRESULT result = ResetOriginal(device, device, params);
	ImGui_ImplDX9_CreateDeviceObjects();

	return result;
}
gui.h :
Code:
#pragma once
#include "d3d9.h"

namespace gui
{

	inline bool open = true;
	inline bool setup = false;

	inline HWND window = nullptr;
	inline WNDCLASSEX windowClass = {};
	inline WNDPROC originalWindowProcess = nullptr;

	// dxStuff

	inline LPDIRECT3DDEVICE9 device = nullptr;
	inline LPDIRECT3D9 d3d9 = nullptr;

	bool SetupWindowClass(const char* windowClassName) noexcept;
	void DestroyWindowClass() noexcept;
	
	bool SetupWindow(const char* windowName) noexcept;
	void DestroyWindow() noexcept;

	bool SetupDirectX() noexcept;
	void DestroyDirectX() noexcept;

	// setup Device

	void Setup();
	
	void SetupMenu(LPDIRECT3DDEVICE9 device) noexcept;
	void Destroy() noexcept;

	void Render() noexcept;

}
gui.cpp:
Code:
#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 <TlHelp32.h>

#include <vector>

#include "../ext/imgui/imgui_internal.h"



extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND window, UINT message, WPARAM wideParam, LPARAM longParam);

// Window Process
LRESULT CALLBACK WindowPorcess(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
{
	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,
		&params,
		&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("hack"))
		throw std::runtime_error("Failed To Create Window Class");
	
	if (!SetupWindow("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(&params);

	window = params.hFocusWindow;
		
	originalWindowProcess = reinterpret_cast<WNDPROC>(
		SetWindowLongPtr(window, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(WindowPorcess))	
		);

	ImGui::CreateContext();
	ImGui::MyCustomStyle();

	ImGuiStyle* style = &ImGui::GetStyle();
	style->WindowRounding = 10.0f;
	style->ChildRounding = 10.0f;
	style->FrameRounding = 10.0f;
	style->GrabRounding = 10.0f;
	style->PopupRounding = 10.0f;
	style->ScrollbarRounding = 10.0f;
	style->TabRounding = 5.0f;

	style->WindowPadding = ImVec2(15, 15);
	style->FramePadding = ImVec2(5, 5);
	style->ItemInnerSpacing = ImVec2(8, 6);
	style->IndentSpacing = 25.0f;
	style->ScrollbarSize = 15.0f;
	style->GrabMinSize = 5.0f;

	style->Alpha = 1.0f;

	ImGuiIO* io = &ImGui::GetIO(); (void)io;
	io->ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;

	ImGui::SetColorEditOptions(ImGuiColorEditFlags_Float | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_PickerHueWheel);


	ImGui_ImplWin32_Init(window);
	ImGui_ImplDX9_Init(device);

	setup = true;
}

void gui::Destroy() noexcept
{
	ImGui_ImplDX9_Shutdown();
	ImGui_ImplWin32_Shutdown();
	ImGui::DestroyContext();
	
	// restore wnd proc
	SetWindowLongPtr(window, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(originalWindowProcess));

	DestroyDirectX();

}

void setCursorPosX(float x) {
	ImVec2 cursorPos = ImGui::GetCursorPos();
	cursorPos.x += x;
	ImGui::SetCursorPos(cursorPos);
}

void gui::Render() noexcept
{
	ImGui_ImplDX9_NewFrame();
	ImGui_ImplWin32_NewFrame();
	ImGui::NewFrame();
	

	ImGui::ShowDemoWindow();


	ImGui::EndFrame();
	ImGui::Render();
	ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());

}

LRESULT CALLBACK WindowPorcess(HWND window, UINT message, WPARAM wideParam, LPARAM longParam)
{

	//toggle 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);
}
dllmain.cpp:
Code:
#define WIN32_LEAN_AND_MEAN
#include "Windows.h"
#include "thread"
#include "cstdint"

#include "hooks.h"
#include "Functions/functions.h"
#include "core/pointers.h"

// setup func
void SETUP(const HMODULE instance)
{
	try
	{
		gui::Setup();
		hooks::Setup();
	}
	catch (const std::exception& error) 
	
	{
		MessageBeep(MB_ICONERROR);
		MessageBox(0, error.what(), "Menu Error", MB_OK | MB_ICONEXCLAMATION);

		goto UNLOAD;
	}
	while (!GetAsyncKeyState(VK_END))
		std::this_thread::sleep_for(std::chrono::milliseconds(200));

UNLOAD:	
	hooks::Destroy();
	gui::Destroy();
	Globals::IsCheatOpen = false;
	FreeLibraryAndExitThread(instance, 0);
}

// entry point	

BOOL WINAPI DllMain(const HMODULE instance, const std::uintptr_t reason, const void* reserved)
{

	if (reason == DLL_PROCESS_ATTACH) {
		DisableThreadLibraryCalls(instance);
		const auto thread = CreateThread(nullptr, 0, reinterpret_cast<LPTHREAD_START_ROUTINE>(SETUP), instance, 0, nullptr);

		if (thread)
			CloseHandle(thread);
	}
	return TRUE;
}
Attached Files
File Type: txt codes.txt (10.1 KB, 3 views)
Elasol is offline  
Old 11/13/2023, 16:32   #2

 
nÂsty.'s Avatar
 
elite*gold: 30
The Black Market: 158/0/0
Join Date: Feb 2013
Posts: 1,472
Received Thanks: 783
Post Code here not in txt
nÂsty. is offline  
Old 11/13/2023, 19:46   #3
 
elite*gold: 0
Join Date: Jul 2017
Posts: 6
Received Thanks: 0
Quote:
Originally Posted by nÂsty. View Post
Post Code here not in txt
Done
Elasol is offline  
Old 11/13/2023, 20:31   #4

 
nÂsty.'s Avatar
 
elite*gold: 30
The Black Market: 158/0/0
Join Date: Feb 2013
Posts: 1,472
Received Thanks: 783
Quote:
Originally Posted by Elasol View Post
Done
i think you need in your WindowProcess function
a Handle for WM_SIZE thats the problem i think.
(Rerendering after atl+tab)

but i dont know much about imgui
nÂsty. is offline  
Reply


Similar Threads Similar Threads
New Cheat for AVA Global Ready (Imgui Menu, External, C#)
09/11/2022 - Alliance of Valiant Arms - 34 Replies
Hello, Features: - Slient Aim - FOV - OPK (Teleport One Place Kill) - Anti Kick - Triggerbot - No Recoil + No Spread - Super Weapon - More Soon
[Selling] {SERVICE} | [CHEATS] Loader - Custom ImGui Menu - ImGui Menu Remakes [AFFORDABLE]]
12/27/2021 - Coders Trading - 0 Replies
n/aaaa



All times are GMT +1. The time now is 06:22.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.