wip: move gfx to gfxhook, some borderless window stuff

This commit is contained in:
Felix Anderson 2021-11-03 17:14:24 +00:00
parent a24cd0a1a5
commit ea94dd8085
Signed by untrusted user: felix
GPG Key ID: 69ADF8AEB6C8B5D1
30 changed files with 193 additions and 111 deletions

View File

@ -12,8 +12,9 @@
#include "chunihook/config.h"
#include "gfxhook/config.h"
#include "hooklib/config.h"
#include "hooklib/gfx/gfx.h"
#include "platform/config.h"
#include "platform/platform.h"

View File

@ -10,7 +10,7 @@
#include "chunihook/chuni-dll.h"
#include "chunihook/slider.h"
#include "hooklib/gfx/gfx.h"
#include "gfxhook/gfx.h"
#include "platform/platform.h"

View File

@ -12,10 +12,11 @@
#include "chuniio/chuniio.h"
#include "gfxhook/d3d9.h"
#include "gfxhook/gfx.h"
#include "hook/process.h"
#include "hooklib/gfx/d3d9.h"
#include "hooklib/gfx/gfx.h"
#include "hooklib/serial.h"
#include "hooklib/spike.h"

View File

@ -14,6 +14,7 @@ shared_library(
amex_lib,
board_lib,
chuniio_lib,
gfxhook_lib,
hooklib_lib,
jvs_lib,
platform_lib,

View File

@ -13,7 +13,6 @@
#include "hook/process.h"
#include "hooklib/gfx/gfx.h"
#include "hooklib/serial.h"
#include "hooklib/spike.h"

18
gfxhook/config.c Normal file
View File

@ -0,0 +1,18 @@
#include <windows.h>
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include "gfxhook/config.h"
void gfx_config_load(struct gfx_config *cfg, const wchar_t *filename)
{
assert(cfg != NULL);
assert(filename != NULL);
cfg->enable = GetPrivateProfileIntW(L"gfx", L"enable", 1, filename);
cfg->windowed = GetPrivateProfileIntW(L"gfx", L"windowed", 0, filename);
cfg->framed = GetPrivateProfileIntW(L"gfx", L"framed", 1, filename);
cfg->monitor = GetPrivateProfileIntW(L"gfx", L"monitor", 0, filename);
}

7
gfxhook/config.h Normal file
View File

@ -0,0 +1,7 @@
#pragma once
#include <stddef.h>
#include "gfxhook/gfx.h"
void gfx_config_load(struct gfx_config *cfg, const wchar_t *filename);

View File

@ -6,12 +6,13 @@
#include <stdbool.h>
#include <stdlib.h>
#include "gfxhook/gfx.h"
#include "gfxhook/util.h"
#include "hook/com-proxy.h"
#include "hook/table.h"
#include "hooklib/config.h"
#include "hooklib/dll.h"
#include "hooklib/gfx/gfx.h"
#include "util/dprintf.h"
@ -176,30 +177,8 @@ HRESULT WINAPI D3D11CreateDeviceAndSwapChain(
}
if (hwnd != NULL) {
/*
* Ensure window is maximized to avoid a Windows 10 issue where a
* fullscreen swap chain is not created because the window is minimized
* at the time of creation.
*/
ShowWindow(hwnd, SW_RESTORE);
if (!gfx_config.framed && width > 0 && height > 0) {
dprintf("DXGI: Resizing window to %ldx%ld\n", width, height);
SetWindowLongPtrW(hwnd, GWL_STYLE, WS_POPUP);
SetWindowLongPtrW(hwnd, GWL_EXSTYLE, WS_EX_TOPMOST);
SetWindowPos(
hwnd,
HWND_TOP,
0,
0,
width,
height,
SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
ShowWindow(hwnd, SW_SHOWMAXIMIZED);
}
gfx_util_ensure_win_visible(hwnd);
gfx_util_borderless_fullscreen_windowed(hwnd, width, height);
}
return next_D3D11CreateDeviceAndSwapChain(

View File

@ -2,6 +2,6 @@
#include <windows.h>
#include "hooklib/gfx/gfx.h"
#include "gfxhook/gfx.h"
void gfx_d3d11_hook_init(const struct gfx_config *cfg, HINSTANCE self);

View File

@ -8,9 +8,11 @@
#include "hook/com-proxy.h"
#include "hook/table.h"
#include "hooklib/config.h"
#include "hooklib/dll.h"
#include "hooklib/gfx/gfx.h"
#include "gfxhook/config.h"
#include "gfxhook/gfx.h"
#include "gfxhook/util.h"
#include "util/dprintf.h"
@ -144,10 +146,10 @@ static HRESULT STDMETHODCALLTYPE my_CreateDevice(
}
if (gfx_config.framed) {
gfx_frame_window(hwnd);
gfx_util_frame_window(hwnd);
}
dprintf("Gfx: IDirect3D9:: Using Display No %x\n", gfx_config.monitor);
dprintf("Gfx: Using adapter %d\n", gfx_config.monitor);
return IDirect3D9_CreateDevice(real, gfx_config.monitor, type, hwnd, flags, pp, pdev);
}

View File

@ -2,6 +2,6 @@
#include <windows.h>
#include "hooklib/gfx/gfx.h"
#include "gfxhook/gfx.h"
void gfx_d3d9_hook_init(const struct gfx_config *cfg, HINSTANCE self);

View File

@ -5,12 +5,12 @@
#include <assert.h>
#include <stdlib.h>
#include "gfxhook/gfx.h"
#include "hook/com-proxy.h"
#include "hook/table.h"
#include "hooklib/config.h"
#include "hooklib/dll.h"
#include "hooklib/gfx/gfx.h"
#include "util/dprintf.h"

View File

@ -2,6 +2,6 @@
#include <windows.h>
#include "hooklib/gfx/gfx.h"
#include "gfxhook/gfx.h"
void gfx_dxgi_hook_init(const struct gfx_config *cfg, HINSTANCE self);

50
gfxhook/gfx.c Normal file
View File

@ -0,0 +1,50 @@
#include <windows.h>
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include "gfxhook/config.h"
#include "gfxhook/gfx.h"
#include "hook/table.h"
#include "util/dprintf.h"
typedef BOOL (WINAPI *ShowWindow_t)(HWND hWnd, int nCmdShow);
static BOOL WINAPI hook_ShowWindow(HWND hWnd, int nCmdShow);
static struct gfx_config gfx_config;
static ShowWindow_t next_ShowWindow;
static const struct hook_symbol gfx_hooks[] = {
{
.name = "ShowWindow",
.patch = hook_ShowWindow,
.link = (void **) &next_ShowWindow,
},
};
void gfx_hook_init(const struct gfx_config *cfg, HINSTANCE self)
{
assert(cfg != NULL);
if (!cfg->enable) {
return;
}
memcpy(&gfx_config, cfg, sizeof(*cfg));
hook_table_apply(NULL, "user32.dll", gfx_hooks, _countof(gfx_hooks));
}
static BOOL WINAPI hook_ShowWindow(HWND hWnd, int nCmdShow)
{
dprintf("Gfx: ShowWindow hook hit\n");
if (!gfx_config.framed && nCmdShow == SW_RESTORE) {
nCmdShow = SW_SHOW;
}
return next_ShowWindow(hWnd, nCmdShow);
}

View File

@ -12,5 +12,3 @@ struct gfx_config {
};
void gfx_hook_init(const struct gfx_config *cfg, HINSTANCE self);
HRESULT gfx_frame_window(HWND hwnd);

27
gfxhook/meson.build Normal file
View File

@ -0,0 +1,27 @@
gfxhook_lib = static_library(
'gfxhook',
include_directories : inc,
implicit_include_directories : false,
c_pch : '../precompiled.h',
dependencies : [
capnhook.get_variable('hook_dep'),
],
link_with : [
hooklib_lib,
util_lib,
],
sources : [
'config.c',
'config.h',
'd3d9.c',
'd3d9.h',
'd3d11.c',
'd3d11.h',
'dxgi.c',
'dxgi.h',
'gfx.c',
'gfx.h',
'util.c',
'util.h',
],
)

View File

@ -1,55 +1,60 @@
#include <windows.h>
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include "hook/table.h"
#include "hooklib/config.h"
#include "hooklib/gfx/gfx.h"
#include "gfxhook/util.h"
#include "util/dprintf.h"
typedef BOOL (WINAPI *ShowWindow_t)(HWND hWnd, int nCmdShow);
static BOOL WINAPI hook_ShowWindow(HWND hWnd, int nCmdShow);
static struct gfx_config gfx_config;
static ShowWindow_t next_ShowWindow;
static const struct hook_symbol gfx_hooks[] = {
{
.name = "ShowWindow",
.patch = hook_ShowWindow,
.link = (void **) &next_ShowWindow,
},
};
void gfx_hook_init(const struct gfx_config *cfg, HINSTANCE self)
void gfx_util_ensure_win_visible(HWND hwnd)
{
assert(cfg != NULL);
/*
* Ensure window is maximized to avoid a Windows 10 issue where a
* fullscreen swap chain is not created because the window is minimized
* at the time of creation.
*/
ShowWindow(hwnd, SW_RESTORE);
}
void gfx_util_borderless_fullscreen_windowed(HWND hwnd, LONG width, LONG height)
{
BOOL ok;
HRESULT hr;
dprintf("Gfx: Resizing window to %ldx%ld\n", width, height);
SetWindowLongPtrW(hwnd, GWL_STYLE, WS_POPUP);
SetWindowLongPtrW(hwnd, GWL_EXSTYLE, WS_EX_TOPMOST);
ok = SetWindowPos(
hwnd,
HWND_TOP,
0,
0,
width,
height,
SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
if (!ok) {
/* come on... */
hr = HRESULT_FROM_WIN32(GetLastError());
dprintf("Gfx: SetWindowPos failed: %x\n", (int) hr);
if (!cfg->enable) {
return;
}
memcpy(&gfx_config, cfg, sizeof(*cfg));
hook_table_apply(NULL, "user32.dll", gfx_hooks, _countof(gfx_hooks));
}
ok = ShowWindow(hwnd, SW_SHOWMAXIMIZED);
static BOOL WINAPI hook_ShowWindow(HWND hWnd, int nCmdShow)
{
dprintf("Gfx: ShowWindow hook hit\n");
if (!ok) {
/* come on... */
hr = HRESULT_FROM_WIN32(GetLastError());
dprintf("Gfx: ShowWindow failed: %x\n", (int) hr);
if (!gfx_config.framed && nCmdShow == SW_RESTORE) {
nCmdShow = SW_SHOW;
return;
}
return next_ShowWindow(hWnd, nCmdShow);
}
HRESULT gfx_frame_window(HWND hwnd)
HRESULT gfx_util_frame_window(HWND hwnd)
{
HRESULT hr;
DWORD error;

7
gfxhook/util.h Normal file
View File

@ -0,0 +1,7 @@
#pragma once
#include <windows.h>
void gfx_util_ensure_win_visible(HWND hwnd);
void gfx_util_borderless_fullscreen_windowed(HWND hwnd, LONG width, LONG height);
HRESULT gfx_util_frame_window(HWND hwnd);

View File

@ -6,7 +6,6 @@
#include "hooklib/config.h"
#include "hooklib/dvd.h"
#include "hooklib/gfx/gfx.h"
void dvd_config_load(struct dvd_config *cfg, const wchar_t *filename)
{
@ -15,14 +14,3 @@ void dvd_config_load(struct dvd_config *cfg, const wchar_t *filename)
cfg->enable = GetPrivateProfileIntW(L"dvd", L"enable", 1, filename);
}
void gfx_config_load(struct gfx_config *cfg, const wchar_t *filename)
{
assert(cfg != NULL);
assert(filename != NULL);
cfg->enable = GetPrivateProfileIntW(L"gfx", L"enable", 1, filename);
cfg->windowed = GetPrivateProfileIntW(L"gfx", L"windowed", 0, filename);
cfg->framed = GetPrivateProfileIntW(L"gfx", L"framed", 1, filename);
cfg->monitor = GetPrivateProfileIntW(L"gfx", L"monitor", 0, filename);
}

View File

@ -1,10 +1,7 @@
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include "hooklib/dvd.h"
#include "hooklib/gfx/gfx.h"
void dvd_config_load(struct dvd_config *cfg, const wchar_t *filename);
void gfx_config_load(struct gfx_config *cfg, const wchar_t *filename);

View File

@ -17,14 +17,6 @@ hooklib_lib = static_library(
'dvd.h',
'fdshark.c',
'fdshark.h',
'gfx/d3d9.c',
'gfx/d3d9.h',
'gfx/d3d11.c',
'gfx/d3d11.h',
'gfx/dxgi.c',
'gfx/dxgi.h',
'gfx/gfx.c',
'gfx/gfx.h',
'path.c',
'path.h',
'reg.c',

View File

@ -7,9 +7,10 @@
#include "board/config.h"
#include "board/sg-reader.h"
#include "gfxhook/config.h"
#include "hooklib/config.h"
#include "hooklib/dvd.h"
#include "hooklib/gfx/gfx.h"
#include "idzhook/config.h"
#include "idzhook/idz-dll.h"

View File

@ -7,8 +7,9 @@
#include "board/sg-reader.h"
#include "gfxhook/gfx.h"
#include "hooklib/dvd.h"
#include "hooklib/gfx/gfx.h"
#include "idzhook/idz-dll.h"
#include "idzhook/zinput.h"

View File

@ -9,12 +9,13 @@
#include "board/sg-reader.h"
#include "gfxhook/d3d11.h"
#include "gfxhook/dxgi.h"
#include "gfxhook/gfx.h"
#include "hook/process.h"
#include "hooklib/dvd.h"
#include "hooklib/gfx/d3d11.h"
#include "hooklib/gfx/dxgi.h"
#include "hooklib/gfx/gfx.h"
#include "hooklib/serial.h"
#include "hooklib/spike.h"

View File

@ -15,6 +15,7 @@ shared_library(
aimeio_lib,
amex_lib,
board_lib,
gfxhook_lib,
hooklib_lib,
idzio_lib,
jvs_lib,

View File

@ -43,6 +43,8 @@ subdir('jvs')
subdir('platform')
subdir('util')
subdir('gfxhook')
subdir('aimeio')
subdir('chuniio')
subdir('divaio')

View File

@ -3,9 +3,10 @@
#include "board/config.h"
#include "gfxhook/config.h"
#include "hooklib/config.h"
#include "hooklib/dvd.h"
#include "hooklib/gfx/gfx.h"
#include "mu3hook/config.h"

View File

@ -4,8 +4,9 @@
#include "board/config.h"
#include "gfxhook/gfx.h"
#include "hooklib/dvd.h"
#include "hooklib/gfx/gfx.h"
#include "mu3hook/mu3-dll.h"

View File

@ -6,13 +6,14 @@
#include "board/sg-reader.h"
#include "board/vfd.h"
#include "gfxhook/d3d9.h"
#include "gfxhook/d3d11.h"
#include "gfxhook/dxgi.h"
#include "gfxhook/gfx.h"
#include "hook/process.h"
#include "hooklib/dvd.h"
#include "hooklib/gfx/d3d9.h"
#include "hooklib/gfx/d3d11.h"
#include "hooklib/gfx/dxgi.h"
#include "hooklib/gfx/gfx.h"
#include "hooklib/serial.h"
#include "hooklib/spike.h"

View File

@ -13,6 +13,7 @@ shared_library(
link_with : [
aimeio_lib,
board_lib,
gfxhook_lib,
hooklib_lib,
mu3io_lib,
platform_lib,