diff --git a/examples/imgui/README.md b/examples/imgui/README.md index 1ba2772..6f2b8eb 100644 --- a/examples/imgui/README.md +++ b/examples/imgui/README.md @@ -5,6 +5,6 @@ - [x] D3D11 - [ ] D3D12 - [ ] OpenGL -- [ ] Vulcan +- [ ] Vulkan Author(s): [Rebzzel](https://github.com/Rebzzel) \ No newline at end of file diff --git a/examples/imgui/impl/d3d10_impl.cpp b/examples/imgui/impl/d3d10_impl.cpp index f393fa3..b6867a6 100644 --- a/examples/imgui/impl/d3d10_impl.cpp +++ b/examples/imgui/impl/d3d10_impl.cpp @@ -6,6 +6,8 @@ #include #include +#include "win32_impl.h" + #include "../imgui/imgui.h" #include "../imgui/examples/imgui_impl_win32.h" #include "../imgui/examples/imgui_impl_dx10.h" @@ -25,6 +27,8 @@ long __stdcall hkPresent10(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT F ID3D10Device* device; pSwapChain->GetDevice(__uuidof(ID3D10Device), (void**)&device); + impl::win32::init(desc.OutputWindow); + ImGui::CreateContext(); ImGui_ImplWin32_Init(desc.OutputWindow); ImGui_ImplDX10_Init(device); diff --git a/examples/imgui/impl/d3d11_impl.cpp b/examples/imgui/impl/d3d11_impl.cpp index 532d782..795504a 100644 --- a/examples/imgui/impl/d3d11_impl.cpp +++ b/examples/imgui/impl/d3d11_impl.cpp @@ -6,6 +6,8 @@ #include #include +#include "win32_impl.h" + #include "../imgui/imgui.h" #include "../imgui/examples/imgui_impl_win32.h" #include "../imgui/examples/imgui_impl_dx11.h" @@ -28,6 +30,8 @@ long __stdcall hkPresent11(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT F ID3D11DeviceContext* context; device->GetImmediateContext(&context); + impl::win32::init(desc.OutputWindow); + ImGui::CreateContext(); ImGui_ImplWin32_Init(desc.OutputWindow); ImGui_ImplDX11_Init(device, context); diff --git a/examples/imgui/impl/d3d9_impl.cpp b/examples/imgui/impl/d3d9_impl.cpp index 275772b..8a5ae16 100644 --- a/examples/imgui/impl/d3d9_impl.cpp +++ b/examples/imgui/impl/d3d9_impl.cpp @@ -6,6 +6,8 @@ #include #include +#include "win32_impl.h" + #include "../imgui/imgui.h" #include "../imgui/examples/imgui_impl_win32.h" #include "../imgui/examples/imgui_impl_dx9.h" @@ -34,6 +36,8 @@ long __stdcall hkEndScene(LPDIRECT3DDEVICE9 pDevice) D3DDEVICE_CREATION_PARAMETERS params; pDevice->GetCreationParameters(¶ms); + impl::win32::init(params.hFocusWindow); + ImGui::CreateContext(); ImGui_ImplWin32_Init(params.hFocusWindow); ImGui_ImplDX9_Init(pDevice); diff --git a/examples/imgui/impl/win32_impl.cpp b/examples/imgui/impl/win32_impl.cpp new file mode 100644 index 0000000..7ef9381 --- /dev/null +++ b/examples/imgui/impl/win32_impl.cpp @@ -0,0 +1,28 @@ +#include "../../../kiero.h" + +#include "win32_impl.h" +#include + +#include "../imgui/imgui.h" +#include "../imgui/examples/imgui_impl_win32.h" + +static WNDPROC oWndProc = NULL; + +extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + +LRESULT CALLBACK hkWindowProc( + _In_ HWND hwnd, + _In_ UINT uMsg, + _In_ WPARAM wParam, + _In_ LPARAM lParam +) +{ + if (ImGui_ImplWin32_WndProcHandler(hwnd, uMsg, wParam, lParam) > 0) + return 1L; + return ::CallWindowProcA(oWndProc, hwnd, uMsg, wParam, lParam); +} + +void impl::win32::init(void* hwnd) +{ + oWndProc = (WNDPROC)::SetWindowLongPtr((HWND)hwnd, GWLP_WNDPROC, (LONG)hkWindowProc); +} \ No newline at end of file diff --git a/examples/imgui/impl/win32_impl.h b/examples/imgui/impl/win32_impl.h new file mode 100644 index 0000000..d494ea0 --- /dev/null +++ b/examples/imgui/impl/win32_impl.h @@ -0,0 +1,14 @@ +#ifndef __WIN32_IMPL_H__ +#define __WIN32_IMPL_H__ + +#include "shared.h" + +namespace impl +{ + namespace win32 + { + void init(void* hwnd); + } +} + +#endif // __WIN32_IMPL_H__ \ No newline at end of file diff --git a/examples/imgui/main.cpp b/examples/imgui/main.cpp index 33256db..f88444b 100644 --- a/examples/imgui/main.cpp +++ b/examples/imgui/main.cpp @@ -55,7 +55,7 @@ int kieroExampleThread() // TODO: OpenGL implementation? break; case kiero::RenderType::Vulkan: - // TODO: Vulcan implementation? + // TODO: Vulkan implementation? break; } diff --git a/kiero.cpp b/kiero.cpp index e608323..73e87f0 100644 --- a/kiero.cpp +++ b/kiero.cpp @@ -101,18 +101,10 @@ kiero::Status::Enum kiero::init(RenderType::Enum _renderType) return Status::UnknownError; } - D3DDISPLAYMODE displayMode; - if (direct3D9->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displayMode) < 0) - { - ::DestroyWindow(window); - ::UnregisterClass(windowClass.lpszClassName, windowClass.hInstance); - return Status::UnknownError; - } - D3DPRESENT_PARAMETERS params; params.BackBufferWidth = 0; params.BackBufferHeight = 0; - params.BackBufferFormat = displayMode.Format; + params.BackBufferFormat = D3DFMT_UNKNOWN; params.BackBufferCount = 0; params.MultiSampleType = D3DMULTISAMPLE_NONE; params.MultiSampleQuality = NULL; @@ -126,7 +118,7 @@ kiero::Status::Enum kiero::init(RenderType::Enum _renderType) params.PresentationInterval = 0; LPDIRECT3DDEVICE9 device; - if (direct3D9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_DISABLE_DRIVER_MANAGEMENT, ¶ms, &device) < 0) + if (direct3D9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, window, D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_DISABLE_DRIVER_MANAGEMENT, ¶ms, &device) < 0) { direct3D9->Release(); ::DestroyWindow(window); @@ -141,12 +133,12 @@ kiero::Status::Enum kiero::init(RenderType::Enum _renderType) MH_Initialize(); #endif - direct3D9->Release(); - direct3D9 = NULL; - device->Release(); device = NULL; + direct3D9->Release(); + direct3D9 = NULL; + g_renderType = RenderType::D3D9; ::DestroyWindow(window); diff --git a/kiero.h b/kiero.h index 2058bd7..4aba3d4 100644 --- a/kiero.h +++ b/kiero.h @@ -3,7 +3,7 @@ #include -#define KIERO_VERSION "1.2.10" +#define KIERO_VERSION "1.2.12" #define KIERO_INCLUDE_D3D9 0 // 1 if you need D3D9 hook #define KIERO_INCLUDE_D3D10 0 // 1 if you need D3D10 hook