Skip to content

Commit

Permalink
Version 1.2.12: fix d3d9 hook alt-tab black screen (#29), remove some…
Browse files Browse the repository at this point in the history
… useless code, add wndproc hook into imgui example
  • Loading branch information
Rebzzel committed Mar 19, 2021
1 parent ce0aa06 commit 35d4e4f
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 16 deletions.
2 changes: 1 addition & 1 deletion examples/imgui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
- [x] D3D11
- [ ] D3D12
- [ ] OpenGL
- [ ] Vulcan
- [ ] Vulkan

Author(s): [Rebzzel](https://github.com/Rebzzel)
4 changes: 4 additions & 0 deletions examples/imgui/impl/d3d10_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <d3d10.h>
#include <assert.h>

#include "win32_impl.h"

#include "../imgui/imgui.h"
#include "../imgui/examples/imgui_impl_win32.h"
#include "../imgui/examples/imgui_impl_dx10.h"
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions examples/imgui/impl/d3d11_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <d3d11.h>
#include <assert.h>

#include "win32_impl.h"

#include "../imgui/imgui.h"
#include "../imgui/examples/imgui_impl_win32.h"
#include "../imgui/examples/imgui_impl_dx11.h"
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions examples/imgui/impl/d3d9_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <d3d9.h>
#include <assert.h>

#include "win32_impl.h"

#include "../imgui/imgui.h"
#include "../imgui/examples/imgui_impl_win32.h"
#include "../imgui/examples/imgui_impl_dx9.h"
Expand Down Expand Up @@ -34,6 +36,8 @@ long __stdcall hkEndScene(LPDIRECT3DDEVICE9 pDevice)
D3DDEVICE_CREATION_PARAMETERS params;
pDevice->GetCreationParameters(&params);

impl::win32::init(params.hFocusWindow);

ImGui::CreateContext();
ImGui_ImplWin32_Init(params.hFocusWindow);
ImGui_ImplDX9_Init(pDevice);
Expand Down
28 changes: 28 additions & 0 deletions examples/imgui/impl/win32_impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "../../../kiero.h"

#include "win32_impl.h"
#include <Windows.h>

#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);
}
14 changes: 14 additions & 0 deletions examples/imgui/impl/win32_impl.h
Original file line number Diff line number Diff line change
@@ -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__
2 changes: 1 addition & 1 deletion examples/imgui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int kieroExampleThread()
// TODO: OpenGL implementation?
break;
case kiero::RenderType::Vulkan:
// TODO: Vulcan implementation?
// TODO: Vulkan implementation?
break;
}

Expand Down
18 changes: 5 additions & 13 deletions kiero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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, &params, &device) < 0)
if (direct3D9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, window, D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_DISABLE_DRIVER_MANAGEMENT, &params, &device) < 0)
{
direct3D9->Release();
::DestroyWindow(window);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion kiero.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <stdint.h>

#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
Expand Down

0 comments on commit 35d4e4f

Please sign in to comment.