ImGui at wolftü Problem Disappear When Click alt + tab or game resolution changed

Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Üye
Katılım
17 Şub 2016
Mesajlar
10
Tepki puanı
0
Ödüller
9
10 HİZMET YILI
hello everyone..
After entering the looby and game room the menu show normaly , When i click alt + tab or game resolution changed , the menu hidden
what could be the problem?

Game: wolftü
Hook : Min-Hook

hooks.h :
Kod:
#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 :
Kod:
#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 :
Kod:
#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:
Kod:
#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:
Kod:
#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;
}
 
Son düzenleme:
aka hernos
Süper Üye
Katılım
30 Ağu 2019
Mesajlar
628
Çözümler
10
Tepki puanı
297
Ödüller
4
Yaş
29
Sosyal
6 HİZMET YILI
Disable your reset hook and try again.
 
aka panic.rs
Kurucu
Katılım
18 Haz 2015
Mesajlar
3,379
Çözümler
50
Tepki puanı
13,156
Ödüller
22
Sosyal
10 HİZMET YILI
with wolftü i remember reset hook was not working well, you can do some custom reset with wndproc hook, and reset manually.
 
aka panic.rs
Kurucu
Katılım
18 Haz 2015
Mesajlar
3,379
Çözümler
50
Tepki puanı
13,156
Ödüller
22
Sosyal
10 HİZMET YILI
so hook wndproc and check if msg WM_SIZE then set a bool and check if its true then reset your imgui , then set the bool to false.

whenever you do alt - tab or go ingame WM_SIZE should be triggered if I remember correct. so thats your best luck to do proper reset..
 
Üye
Katılım
17 Şub 2016
Mesajlar
10
Tepki puanı
0
Ödüller
9
10 HİZMET YILI
with wolftü i remember reset hook was not working well, you can do some custom reset with wndproc hook, and reset manually.
You are right , reset hook not working well when i log it founded its triggered 3 times when exit game not like enter game ( 1 time )

so hook wndproc and check if msg WM_SIZE then set a bool and check if its true then reset your imgui , then set the bool to false.

whenever you do alt - tab or go ingame WM_SIZE should be triggered if I remember correct. so thats your best luck to do proper reset..
when i make like that :
not working too :(
or tell me if i make anything wrong

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


    if (message == WM_SIZE)
    {
        ImGui_ImplDX9_InvalidateDeviceObjects();
        ImGui_ImplDX9_CreateDeviceObjects();
    }


    //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);
}
 
Son düzenleme:
aka panic.rs
Kurucu
Katılım
18 Haz 2015
Mesajlar
3,379
Çözümler
50
Tepki puanı
13,156
Ödüller
22
Sosyal
10 HİZMET YILI
if (message == WM_SIZE)
is this condition are ever true? can you print some values to console or anything to check if it really does WM_RESIZE.
 
aka panic.rs
Kurucu
Katılım
18 Haz 2015
Mesajlar
3,379
Çözümler
50
Tepki puanı
13,156
Ödüller
22
Sosyal
10 HİZMET YILI
its been years i forgot the problem, maybe @nader11ndeu has some sample of reset for the WT.
 
Üye
Katılım
17 Şub 2016
Mesajlar
10
Tepki puanı
0
Ödüller
9
10 HİZMET YILI
Słyszę, słyszę letni powiew.
Kurucu
Katılım
20 Haz 2015
Mesajlar
7,666
Çözümler
136
Tepki puanı
20,724
Ödüller
25
10 HİZMET YILI
Any help here about it friend ?!
Sadly, I've cleaned my computer and GitHub of old projects, and wolftü was indeed a very old project. Unfortunately, I no longer have any old source code or related materials for wolftü. The game is quite antiquated, and the engine used is also very old. If I were you, I wouldn't bother trying to create something for that game.

However, as LeftSpace mentioned, there was an issue with the reset hook, but I can't recall the reason or how we resolved it. As you can probably guess, we stopped working on wolftü around five years ago...
 
Üye
Katılım
17 Şub 2016
Mesajlar
10
Tepki puanı
0
Ödüller
9
10 HİZMET YILI
Sadly, I've cleaned my computer and GitHub of old projects, and wolftü was indeed a very old project. Unfortunately, I no longer have any old source code or related materials for wolftü. The game is quite antiquated, and the engine used is also very old. If I were you, I wouldn't bother trying to create something for that game.

However, as LeftSpace mentioned, there was an issue with the reset hook, but I can't recall the reason or how we resolved it. As you can probably guess, we stopped working on wolftü around five years ago...
Well, thanks for your time guys <3
 
Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Üst