diff --git a/dist/iidx/iidxhook-09.conf b/dist/iidx/iidxhook-09.conf index 077e3d2..0a34f25 100755 --- a/dist/iidx/iidxhook-09.conf +++ b/dist/iidx/iidxhook-09.conf @@ -1,3 +1,6 @@ +# Enable frame performance graph overlay +debug.enable_frame_perf_graph=false + # Magnetic card type, format XXX, 3 digit string (supports: C02, D01, E11, ECO) eamuse.card_type=C02 diff --git a/dist/iidx/iidxhook-10.conf b/dist/iidx/iidxhook-10.conf index a9874ea..a2b925d 100755 --- a/dist/iidx/iidxhook-10.conf +++ b/dist/iidx/iidxhook-10.conf @@ -1,3 +1,6 @@ +# Enable frame performance graph overlay +debug.enable_frame_perf_graph=false + # Magnetic card type, format XXX, 3 digit string (supports: C02, D01, E11, ECO) eamuse.card_type=D01 diff --git a/dist/iidx/iidxhook-11.conf b/dist/iidx/iidxhook-11.conf index e1dc01e..0bd2d8f 100755 --- a/dist/iidx/iidxhook-11.conf +++ b/dist/iidx/iidxhook-11.conf @@ -1,3 +1,6 @@ +# Enable frame performance graph overlay +debug.enable_frame_perf_graph=false + # Magnetic card type, format XXX, 3 digit string (supports: C02, D01, E11, ECO) eamuse.card_type=E11 diff --git a/dist/iidx/iidxhook-12.conf b/dist/iidx/iidxhook-12.conf index a3518e3..cd5a747 100755 --- a/dist/iidx/iidxhook-12.conf +++ b/dist/iidx/iidxhook-12.conf @@ -1,3 +1,6 @@ +# Enable frame performance graph overlay +debug.enable_frame_perf_graph=false + # Magnetic card type, format XXX, 3 digit string (supports: C02, D01, E11, ECO) eamuse.card_type=ECO diff --git a/dist/iidx/iidxhook-13.conf b/dist/iidx/iidxhook-13.conf index 1f8525f..5926d03 100755 --- a/dist/iidx/iidxhook-13.conf +++ b/dist/iidx/iidxhook-13.conf @@ -1,3 +1,6 @@ +# Enable frame performance graph overlay +debug.enable_frame_perf_graph=false + # Magnetic card type, format XXX, 3 digit string (supports: C02, D01, E11, ECO) eamuse.card_type=C02 diff --git a/dist/iidx/iidxhook-14.conf b/dist/iidx/iidxhook-14.conf index 935d75d..75498a9 100755 --- a/dist/iidx/iidxhook-14.conf +++ b/dist/iidx/iidxhook-14.conf @@ -1,3 +1,6 @@ +# Enable frame performance graph overlay +debug.enable_frame_perf_graph=false + # URL (e.g. http://my.eamuse.server:80/whatever) or IPV4 (e.g. 127.0.0.1:80) of the target eamuse server. The port is optional but defaults to 80. eamuse.server=localhost:80 diff --git a/dist/iidx/iidxhook-15.conf b/dist/iidx/iidxhook-15.conf index b41ebaf..a6e2fce 100755 --- a/dist/iidx/iidxhook-15.conf +++ b/dist/iidx/iidxhook-15.conf @@ -1,3 +1,6 @@ +# Enable frame performance graph overlay +debug.enable_frame_perf_graph=false + # URL (e.g. http://my.eamuse.server:80/whatever) or IPV4 (e.g. 127.0.0.1:80) of the target eamuse server. The port is optional but defaults to 80. eamuse.server=localhost:80 diff --git a/dist/iidx/iidxhook-16.conf b/dist/iidx/iidxhook-16.conf index 1051ea7..f1ee330 100755 --- a/dist/iidx/iidxhook-16.conf +++ b/dist/iidx/iidxhook-16.conf @@ -1,3 +1,6 @@ +# Enable frame performance graph overlay +debug.enable_frame_perf_graph=false + # URL (e.g. http://my.eamuse.server:80/whatever) or IPV4 (e.g. 127.0.0.1:80) of the target eamuse server. The port is optional but defaults to 80. eamuse.server=localhost:80 diff --git a/dist/iidx/iidxhook-17.conf b/dist/iidx/iidxhook-17.conf index 06f25d9..6452a97 100755 --- a/dist/iidx/iidxhook-17.conf +++ b/dist/iidx/iidxhook-17.conf @@ -1,3 +1,6 @@ +# Enable frame performance graph overlay +debug.enable_frame_perf_graph=false + # URL (e.g. http://my.eamuse.server:80/whatever) or IPV4 (e.g. 127.0.0.1:80) of the target eamuse server. The port is optional but defaults to 80. eamuse.server=localhost:80 diff --git a/dist/iidx/iidxhook-18-cn.conf b/dist/iidx/iidxhook-18-cn.conf index 10bb802..3335df9 100644 --- a/dist/iidx/iidxhook-18-cn.conf +++ b/dist/iidx/iidxhook-18-cn.conf @@ -1,3 +1,6 @@ +# Enable frame performance graph overlay +debug.enable_frame_perf_graph=false + # PCBID eamuse.pcbid=0101020304050607086F diff --git a/dist/iidx/iidxhook-18.conf b/dist/iidx/iidxhook-18.conf index 2380cde..22dd2f4 100755 --- a/dist/iidx/iidxhook-18.conf +++ b/dist/iidx/iidxhook-18.conf @@ -1,3 +1,6 @@ +# Enable frame performance graph overlay +debug.enable_frame_perf_graph=false + # Run the game in a framed window (requires windowed option) gfx.framed=false diff --git a/dist/iidx/iidxhook-19.conf b/dist/iidx/iidxhook-19.conf index 2380cde..22dd2f4 100755 --- a/dist/iidx/iidxhook-19.conf +++ b/dist/iidx/iidxhook-19.conf @@ -1,3 +1,6 @@ +# Enable frame performance graph overlay +debug.enable_frame_perf_graph=false + # Run the game in a framed window (requires windowed option) gfx.framed=false diff --git a/dist/iidx/iidxhook-20-cn.conf b/dist/iidx/iidxhook-20-cn.conf index 77aef4f..df796fc 100644 --- a/dist/iidx/iidxhook-20-cn.conf +++ b/dist/iidx/iidxhook-20-cn.conf @@ -1,3 +1,6 @@ +# Enable frame performance graph overlay +debug.enable_frame_perf_graph=false + # PCBID eamuse.pcbid=0101020304050607086F diff --git a/dist/iidx/iidxhook-20.conf b/dist/iidx/iidxhook-20.conf index d5ed89e..0a043da 100755 --- a/dist/iidx/iidxhook-20.conf +++ b/dist/iidx/iidxhook-20.conf @@ -1,3 +1,6 @@ +# Enable frame performance graph overlay +debug.enable_frame_perf_graph=false + # Run the game in a framed window (requires windowed option) gfx.framed=false diff --git a/dist/iidx/iidxhook-21.conf b/dist/iidx/iidxhook-21.conf index d5ed89e..0a043da 100755 --- a/dist/iidx/iidxhook-21.conf +++ b/dist/iidx/iidxhook-21.conf @@ -1,3 +1,6 @@ +# Enable frame performance graph overlay +debug.enable_frame_perf_graph=false + # Run the game in a framed window (requires windowed option) gfx.framed=false diff --git a/dist/iidx/iidxhook-22.conf b/dist/iidx/iidxhook-22.conf index d5ed89e..0a043da 100755 --- a/dist/iidx/iidxhook-22.conf +++ b/dist/iidx/iidxhook-22.conf @@ -1,3 +1,6 @@ +# Enable frame performance graph overlay +debug.enable_frame_perf_graph=false + # Run the game in a framed window (requires windowed option) gfx.framed=false diff --git a/dist/iidx/iidxhook-23.conf b/dist/iidx/iidxhook-23.conf index d5ed89e..0a043da 100755 --- a/dist/iidx/iidxhook-23.conf +++ b/dist/iidx/iidxhook-23.conf @@ -1,3 +1,6 @@ +# Enable frame performance graph overlay +debug.enable_frame_perf_graph=false + # Run the game in a framed window (requires windowed option) gfx.framed=false diff --git a/dist/iidx/iidxhook-24.conf b/dist/iidx/iidxhook-24.conf index d5ed89e..0a043da 100755 --- a/dist/iidx/iidxhook-24.conf +++ b/dist/iidx/iidxhook-24.conf @@ -1,3 +1,6 @@ +# Enable frame performance graph overlay +debug.enable_frame_perf_graph=false + # Run the game in a framed window (requires windowed option) gfx.framed=false diff --git a/dist/iidx/iidxhook-25.conf b/dist/iidx/iidxhook-25.conf index f14335a..52e9143 100644 --- a/dist/iidx/iidxhook-25.conf +++ b/dist/iidx/iidxhook-25.conf @@ -1,3 +1,6 @@ +# Enable frame performance graph overlay +debug.enable_frame_perf_graph=false + # Run the game in a framed window (requires windowed option) gfx.framed=false diff --git a/dist/iidx/iidxhook-26.conf b/dist/iidx/iidxhook-26.conf index f14335a..52e9143 100644 --- a/dist/iidx/iidxhook-26.conf +++ b/dist/iidx/iidxhook-26.conf @@ -1,3 +1,6 @@ +# Enable frame performance graph overlay +debug.enable_frame_perf_graph=false + # Run the game in a framed window (requires windowed option) gfx.framed=false diff --git a/src/main/iidxhook-util/Module.mk b/src/main/iidxhook-util/Module.mk index 92fe44d..1e5bbbe 100644 --- a/src/main/iidxhook-util/Module.mk +++ b/src/main/iidxhook-util/Module.mk @@ -7,6 +7,7 @@ src_iidxhook-util := \ acio.c \ chart-patch.c \ clock.c \ + config-debug.c \ config-eamuse.c \ config-ezusb.c \ config-gfx.c \ diff --git a/src/main/iidxhook-util/config-debug.c b/src/main/iidxhook-util/config-debug.c new file mode 100644 index 0000000..85a031e --- /dev/null +++ b/src/main/iidxhook-util/config-debug.c @@ -0,0 +1,34 @@ +#include "cconfig/cconfig-util.h" + +#include "iidxhook-util/config-debug.h" + +#include "util/log.h" + +#define IIDXHOOK_CONFIG_DEBUG_ENABLE_FRAME_PERF_GRAPH_KEY "debug.enable_frame_perf_graph" + +#define IIDXHOOK_CONFIG_DEBUG_DEFAULT_ENABLE_FRAME_PERF_GRAPH_VALUE false + +void iidxhook_config_debug_init(struct cconfig *config) +{ + cconfig_util_set_bool( + config, + IIDXHOOK_CONFIG_DEBUG_ENABLE_FRAME_PERF_GRAPH_KEY, + IIDXHOOK_CONFIG_DEBUG_DEFAULT_ENABLE_FRAME_PERF_GRAPH_VALUE, + "Enable frame performance graph overlay"); +} + +void iidxhook_config_debug_get( + struct iidxhook_config_debug *config_debug, struct cconfig *config) +{ + if (!cconfig_util_get_bool( + config, + IIDXHOOK_CONFIG_DEBUG_ENABLE_FRAME_PERF_GRAPH_KEY, + &config_debug->enable_frame_perf_graph, + IIDXHOOK_CONFIG_DEBUG_DEFAULT_ENABLE_FRAME_PERF_GRAPH_VALUE)) { + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + IIDXHOOK_CONFIG_DEBUG_ENABLE_FRAME_PERF_GRAPH_KEY, + IIDXHOOK_CONFIG_DEBUG_DEFAULT_ENABLE_FRAME_PERF_GRAPH_VALUE); + } +} diff --git a/src/main/iidxhook-util/config-debug.h b/src/main/iidxhook-util/config-debug.h new file mode 100644 index 0000000..f97568e --- /dev/null +++ b/src/main/iidxhook-util/config-debug.h @@ -0,0 +1,17 @@ +#ifndef IIDXHOOK_CONFIG_DEBUG_H +#define IIDXHOOK_CONFIG_DEBUG_H + +#include + +#include "cconfig/cconfig.h" + +struct iidxhook_config_debug { + bool enable_frame_perf_graph; +}; + +void iidxhook_config_debug_init(struct cconfig *config); + +void iidxhook_config_debug_get( + struct iidxhook_config_debug *config_debug, struct cconfig *config); + +#endif \ No newline at end of file diff --git a/src/main/iidxhook1/Module.mk b/src/main/iidxhook1/Module.mk index fcfad98..e692987 100644 --- a/src/main/iidxhook1/Module.mk +++ b/src/main/iidxhook1/Module.mk @@ -3,6 +3,9 @@ dlls += iidxhook1 ldflags_iidxhook1 := \ -lws2_32 \ -liphlpapi \ + -ld3d9 \ + -ldwmapi\ + -lgdi32 \ libs_iidxhook1 := \ iidxhook-util \ @@ -18,6 +21,9 @@ libs_iidxhook1 := \ cconfig \ util \ ezusb \ + imgui-bt \ + imgui-debug \ + imgui \ src_iidxhook1 := \ config-iidxhook1.c \ diff --git a/src/main/iidxhook1/dllmain.c b/src/main/iidxhook1/dllmain.c index a3a4a35..5340909 100644 --- a/src/main/iidxhook1/dllmain.c +++ b/src/main/iidxhook1/dllmain.c @@ -27,6 +27,7 @@ #include "iidxhook-util/chart-patch.h" #include "iidxhook-util/clock.h" +#include "iidxhook-util/config-debug.h" #include "iidxhook-util/config-eamuse.h" #include "iidxhook-util/config-ezusb.h" #include "iidxhook-util/config-gfx.h" @@ -41,6 +42,10 @@ #include "iidxhook1/ezusb-mon.h" #include "iidxhook1/log-ezusb.h" +#include "imgui-bt/imgui-d3d9-hook.h" + +#include "imgui-debug/frame-perf-graph.h" + #include "util/defs.h" #include "util/log.h" #include "util/thread.h" @@ -53,6 +58,7 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { iidxhook_util_d3d9_irp_handler, + imgui_hook_d3d9_irp_handler }; static HANDLE STDCALL my_OpenProcess(DWORD, BOOL, DWORD); @@ -68,6 +74,17 @@ static const struct hook_symbol init_hook_syms[] = { }, }; +static void iidxhook1_setup_imgui_debug_components(const struct iidxhook_config_debug *config_debug) +{ + imgui_bt_component_t debug_frame_graph_component; + + if (config_debug->enable_frame_perf_graph) { + imgui_debug_frame_perf_graph_init(60.0f, &debug_frame_graph_component); + + imgui_d3d9_hook_init(&debug_frame_graph_component, 1); + } +} + static void iidxhook1_setup_d3d9_hooks( const struct iidxhook_config_gfx *config_gfx, const struct iidxhook_config_iidxhook1 *config_iidxhook1) @@ -125,6 +142,7 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) { struct cconfig *config; + struct iidxhook_config_debug config_debug; struct iidxhook_util_config_ezusb config_ezusb; struct iidxhook_util_config_eamuse config_eamuse; struct iidxhook_config_gfx config_gfx; @@ -144,6 +162,7 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) config = cconfig_init(); + iidxhook_config_debug_init(config); iidxhook_util_config_ezusb_init(config); iidxhook_util_config_eamuse_init(config); iidxhook_config_gfx_init(config); @@ -159,6 +178,7 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) exit(EXIT_FAILURE); } + iidxhook_config_debug_get(&config_debug, config); iidxhook_util_config_ezusb_get(&config_ezusb, config); iidxhook_util_config_eamuse_get(&config_eamuse, config); iidxhook_config_gfx_get(&config_gfx, config); @@ -202,6 +222,8 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) settings_hook_set_path(config_misc.settings_path); } + iidxhook1_setup_imgui_debug_components(&config_debug); + /* Direct3D and USER32 hooks */ iidxhook1_setup_d3d9_hooks(&config_gfx, &config_iidxhook1); diff --git a/src/main/iidxhook2/Module.mk b/src/main/iidxhook2/Module.mk index c9fd438..292f496 100644 --- a/src/main/iidxhook2/Module.mk +++ b/src/main/iidxhook2/Module.mk @@ -3,6 +3,9 @@ avsdlls += iidxhook2 ldflags_iidxhook2 := \ -lws2_32 \ -liphlpapi \ + -ld3d9 \ + -ldwmapi\ + -lgdi32 \ libs_iidxhook2 := \ iidxhook-util \ @@ -18,6 +21,9 @@ libs_iidxhook2 := \ cconfig \ util \ ezusb \ + imgui-bt \ + imgui-debug \ + imgui \ src_iidxhook2 := \ config-iidxhook2.c \ diff --git a/src/main/iidxhook2/dllmain.c b/src/main/iidxhook2/dllmain.c index 25a76ed..f85ddd7 100644 --- a/src/main/iidxhook2/dllmain.c +++ b/src/main/iidxhook2/dllmain.c @@ -29,6 +29,7 @@ #include "iidxhook-util/acio.h" #include "iidxhook-util/chart-patch.h" #include "iidxhook-util/clock.h" +#include "iidxhook-util/config-debug.h" #include "iidxhook-util/config-eamuse.h" #include "iidxhook-util/config-ezusb.h" #include "iidxhook-util/config-gfx.h" @@ -41,6 +42,10 @@ #include "iidxhook2/config-iidxhook2.h" +#include "imgui-bt/imgui-d3d9-hook.h" + +#include "imgui-debug/frame-perf-graph.h" + #include "util/log.h" #include "util/thread.h" @@ -52,6 +57,7 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { iidxhook_util_d3d9_irp_handler, + imgui_hook_d3d9_irp_handler, }; static HANDLE STDCALL my_OpenProcess(DWORD, BOOL, DWORD); @@ -65,6 +71,17 @@ static const struct hook_symbol init_hook_syms[] = { .link = (void **) &real_OpenProcess}, }; +static void iidxhook2_setup_imgui_debug_components(const struct iidxhook_config_debug *config_debug) +{ + imgui_bt_component_t debug_frame_graph_component; + + if (config_debug->enable_frame_perf_graph) { + imgui_debug_frame_perf_graph_init(60.0f, &debug_frame_graph_component); + + imgui_d3d9_hook_init(&debug_frame_graph_component, 1); + } +} + static void iidxhook2_setup_d3d9_hooks( const struct iidxhook_config_gfx *config_gfx, const struct iidxhook_config_iidxhook2 *config_iidxhook2) @@ -122,6 +139,7 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) { struct cconfig *config; + struct iidxhook_config_debug config_debug; struct iidxhook_util_config_ezusb config_ezusb; struct iidxhook_util_config_eamuse config_eamuse; struct iidxhook_config_gfx config_gfx; @@ -141,6 +159,7 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) config = cconfig_init(); + iidxhook_config_debug_init(config); iidxhook_util_config_ezusb_init(config); iidxhook_util_config_eamuse_init(config); iidxhook_config_gfx_init(config); @@ -156,6 +175,7 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) exit(EXIT_FAILURE); } + iidxhook_config_debug_get(&config_debug, config); iidxhook_util_config_ezusb_get(&config_ezusb, config); iidxhook_util_config_eamuse_get(&config_eamuse, config); iidxhook_config_gfx_get(&config_gfx, config); @@ -194,6 +214,8 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) settings_hook_set_path(config_misc.settings_path); } + iidxhook2_setup_imgui_debug_components(&config_debug); + /* Direct3D and USER32 hooks */ iidxhook2_setup_d3d9_hooks(&config_gfx, &config_iidxhook2); diff --git a/src/main/iidxhook3/Module.mk b/src/main/iidxhook3/Module.mk index e328bec..a79b2e9 100644 --- a/src/main/iidxhook3/Module.mk +++ b/src/main/iidxhook3/Module.mk @@ -3,9 +3,13 @@ avsdlls += iidxhook3 ldflags_iidxhook3 := \ -lws2_32 \ -liphlpapi \ + -ld3d9 \ + -ldwmapi\ + -lgdi32 \ libs_iidxhook3 := \ iidxhook-util \ + iidxhook-d3d9 \ ezusb-emu \ ezusb-iidx-16seg-emu \ ezusb2-emu \ @@ -20,6 +24,9 @@ libs_iidxhook3 := \ cconfig \ util \ ezusb \ + imgui-bt \ + imgui-debug \ + imgui \ src_iidxhook3 := \ dllmain.c \ diff --git a/src/main/iidxhook3/dllmain.c b/src/main/iidxhook3/dllmain.c index b2e0e41..092b9fe 100644 --- a/src/main/iidxhook3/dllmain.c +++ b/src/main/iidxhook3/dllmain.c @@ -30,6 +30,7 @@ #include "iidxhook-util/acio.h" #include "iidxhook-util/chart-patch.h" #include "iidxhook-util/clock.h" +#include "iidxhook-util/config-debug.h" #include "iidxhook-util/config-eamuse.h" #include "iidxhook-util/config-gfx.h" #include "iidxhook-util/config-misc.h" @@ -38,6 +39,10 @@ #include "iidxhook-util/eamuse.h" #include "iidxhook-util/settings.h" +#include "imgui-bt/imgui-d3d9-hook.h" + +#include "imgui-debug/frame-perf-graph.h" + #include "security/rp-sign-key.h" #include "util/log.h" @@ -52,6 +57,7 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { iidxhook_util_d3d9_irp_handler, + imgui_hook_d3d9_irp_handler, }; static HANDLE STDCALL my_OpenProcess(DWORD, BOOL, DWORD); @@ -64,6 +70,17 @@ static const struct hook_symbol init_hook_syms[] = { .link = (void **) &real_OpenProcess}, }; +static void iidxhook3_setup_imgui_debug_components(const struct iidxhook_config_debug *config_debug) +{ + imgui_bt_component_t debug_frame_graph_component; + + if (config_debug->enable_frame_perf_graph) { + imgui_debug_frame_perf_graph_init(60.0f, &debug_frame_graph_component); + + imgui_d3d9_hook_init(&debug_frame_graph_component, 1); + } +} + static void iidxhook3_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { @@ -120,6 +137,7 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) { struct cconfig *config; + struct iidxhook_config_debug config_debug; struct iidxhook_util_config_eamuse config_eamuse; struct iidxhook_config_gfx config_gfx; struct iidxhook_config_misc config_misc; @@ -137,6 +155,7 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) config = cconfig_init(); + iidxhook_config_debug_init(config); iidxhook_util_config_eamuse_init(config); iidxhook_config_gfx_init(config); iidxhook_config_misc_init(config); @@ -150,6 +169,7 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) exit(EXIT_FAILURE); } + iidxhook_config_debug_get(&config_debug, config); iidxhook_util_config_eamuse_get(&config_eamuse, config); iidxhook_config_gfx_get(&config_gfx, config); iidxhook_config_misc_get(&config_misc, config); @@ -187,6 +207,8 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) settings_hook_set_path(config_misc.settings_path); } + iidxhook3_setup_imgui_debug_components(&config_debug); + /* Direct3D and USER32 hooks */ iidxhook3_setup_d3d9_hooks(&config_gfx); diff --git a/src/main/iidxhook4-cn/Module.mk b/src/main/iidxhook4-cn/Module.mk index 0f7bcee..6cd0edf 100644 --- a/src/main/iidxhook4-cn/Module.mk +++ b/src/main/iidxhook4-cn/Module.mk @@ -3,6 +3,9 @@ avsdlls += iidxhook4-cn ldflags_iidxhook4-cn := \ -liphlpapi \ -lws2_32 \ + -ld3d9 \ + -ldwmapi\ + -lgdi32 \ deplibs_iidxhook4-cn := \ avs \ @@ -20,6 +23,9 @@ libs_iidxhook4-cn := \ cconfig \ util \ ezusb \ + imgui-bt \ + imgui-debug \ + imgui \ src_iidxhook4-cn := \ avs-boot.c \ diff --git a/src/main/iidxhook4-cn/dllmain.c b/src/main/iidxhook4-cn/dllmain.c index ea2f42a..072e266 100644 --- a/src/main/iidxhook4-cn/dllmain.c +++ b/src/main/iidxhook4-cn/dllmain.c @@ -25,6 +25,7 @@ #include "iidxhook4-cn/path.h" #include "iidxhook-util/chart-patch.h" +#include "iidxhook-util/config-debug.h" #include "iidxhook-util/config-eamuse.h" #include "iidxhook-util/config-gfx.h" #include "iidxhook-util/config-io.h" @@ -33,6 +34,10 @@ #include "iidxhook-util/d3d9.h" #include "iidxhook-util/settings.h" +#include "imgui-bt/imgui-d3d9-hook.h" + +#include "imgui-debug/frame-perf-graph.h" + #include "security/rp-sign-key.h" #include "imports/avs.h" @@ -51,6 +56,7 @@ static bool iidxhook_init_check; static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { iidxhook_util_d3d9_irp_handler, + imgui_hook_d3d9_irp_handler, }; static const struct hook_symbol init_hook_syms[] = { @@ -61,6 +67,17 @@ static const struct hook_symbol init_hook_syms[] = { static struct iidxhook_config_io config_io; +static void iidxhook4_cn_setup_imgui_debug_components(const struct iidxhook_config_debug *config_debug) +{ + imgui_bt_component_t debug_frame_graph_component; + + if (config_debug->enable_frame_perf_graph) { + imgui_debug_frame_perf_graph_init(60.0f, &debug_frame_graph_component); + + imgui_d3d9_hook_init(&debug_frame_graph_component, 1); + } +} + static void iidxhook4_cn_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { @@ -117,6 +134,7 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) { struct cconfig *config; + struct iidxhook_config_debug config_debug; struct iidxhook_util_config_eamuse config_eamuse; struct iidxhook_config_gfx config_gfx; struct iidxhook_config_sec config_sec; @@ -134,6 +152,7 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) config = cconfig_init(); + iidxhook_config_debug_init(config); iidxhook_util_config_eamuse_init(config); iidxhook_config_gfx_init(config); iidxhook_config_io_init(config); @@ -148,6 +167,7 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) exit(EXIT_FAILURE); } + iidxhook_config_debug_get(&config_debug, config); iidxhook_util_config_eamuse_get(&config_eamuse, config); iidxhook_config_gfx_get(&config_gfx, config); iidxhook_config_io_get(&config_io, config); @@ -174,6 +194,8 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) &config_sec.black_plug_mcode); ezusb_iidx_emu_node_security_plug_set_pcbid(&config_eamuse.pcbid); + iidxhook4_cn_setup_imgui_debug_components(&config_debug); + iidxhook4_cn_setup_d3d9_hooks(&config_gfx); if (strlen(config_misc.settings_path) > 0) { diff --git a/src/main/iidxhook4/Module.mk b/src/main/iidxhook4/Module.mk index 40f40b0..184a3b1 100644 --- a/src/main/iidxhook4/Module.mk +++ b/src/main/iidxhook4/Module.mk @@ -2,6 +2,9 @@ avsdlls += iidxhook4 ldflags_iidxhook4 := \ -liphlpapi \ + -ld3d9 \ + -ldwmapi\ + -lgdi32 \ deplibs_iidxhook4 := \ avs \ @@ -22,6 +25,9 @@ libs_iidxhook4 := \ cconfig \ util \ ezusb \ + imgui-bt \ + imgui-debug \ + imgui \ src_iidxhook4 := \ dllmain.c \ diff --git a/src/main/iidxhook4/dllmain.c b/src/main/iidxhook4/dllmain.c index d7993dd..afe3149 100644 --- a/src/main/iidxhook4/dllmain.c +++ b/src/main/iidxhook4/dllmain.c @@ -27,6 +27,7 @@ #include "iidxhook-util/acio.h" #include "iidxhook-util/chart-patch.h" +#include "iidxhook-util/config-debug.h" #include "iidxhook-util/config-gfx.h" #include "iidxhook-util/config-io.h" #include "iidxhook-util/config-misc.h" @@ -34,6 +35,10 @@ #include "iidxhook-util/log-server.h" #include "iidxhook-util/settings.h" +#include "imgui-bt/imgui-d3d9-hook.h" + +#include "imgui-debug/frame-perf-graph.h" + #include "imports/avs.h" #include "util/log.h" @@ -48,10 +53,22 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { iidxhook_util_d3d9_irp_handler, + imgui_hook_d3d9_irp_handler, }; static struct iidxhook_config_io config_io; +static void iidxhook4_setup_imgui_debug_components(const struct iidxhook_config_debug *config_debug) +{ + imgui_bt_component_t debug_frame_graph_component; + + if (config_debug->enable_frame_perf_graph) { + imgui_debug_frame_perf_graph_init(60.0f, &debug_frame_graph_component); + + imgui_d3d9_hook_init(&debug_frame_graph_component, 1); + } +} + static void iidxhook4_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { @@ -101,6 +118,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) { struct cconfig *config; + struct iidxhook_config_debug config_debug; struct iidxhook_config_gfx config_gfx; struct iidxhook_config_misc config_misc; @@ -111,6 +129,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) config = cconfig_init(); + iidxhook_config_debug_init(config); iidxhook_config_gfx_init(config); iidxhook_config_io_init(config); iidxhook_config_misc_init(config); @@ -124,6 +143,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) exit(EXIT_FAILURE); } + iidxhook_config_debug_get(&config_debug, config); iidxhook_config_gfx_get(&config_gfx, config); iidxhook_config_io_get(&config_io, config); iidxhook_config_misc_get(&config_misc, config); @@ -133,6 +153,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) log_info(IIDXHOOK4_INFO_HEADER); log_info("Initializing iidxhook..."); + iidxhook4_setup_imgui_debug_components(&config_debug); + iidxhook4_setup_d3d9_hooks(&config_gfx); if (strlen(config_misc.settings_path) > 0) { diff --git a/src/main/iidxhook5-cn/Module.mk b/src/main/iidxhook5-cn/Module.mk index feea3d4..351bec1 100644 --- a/src/main/iidxhook5-cn/Module.mk +++ b/src/main/iidxhook5-cn/Module.mk @@ -3,6 +3,9 @@ avsdlls += iidxhook5-cn ldflags_iidxhook5-cn := \ -liphlpapi \ -lws2_32 \ + -ld3d9 \ + -ldwmapi\ + -lgdi32 \ deplibs_iidxhook5-cn := \ avs \ @@ -20,6 +23,9 @@ libs_iidxhook5-cn := \ cconfig \ util \ ezusb \ + imgui-bt \ + imgui-debug \ + imgui \ src_iidxhook5-cn := \ avs-boot.c \ diff --git a/src/main/iidxhook5-cn/dllmain.c b/src/main/iidxhook5-cn/dllmain.c index 711c906..aae9a07 100644 --- a/src/main/iidxhook5-cn/dllmain.c +++ b/src/main/iidxhook5-cn/dllmain.c @@ -25,6 +25,7 @@ #include "iidxhook5-cn/avs-boot.h" #include "iidxhook5-cn/path.h" +#include "iidxhook-util/config-debug.h" #include "iidxhook-util/config-eamuse.h" #include "iidxhook-util/config-gfx.h" #include "iidxhook-util/config-io.h" @@ -33,6 +34,10 @@ #include "iidxhook-util/d3d9.h" #include "iidxhook-util/settings.h" +#include "imgui-bt/imgui-d3d9-hook.h" + +#include "imgui-debug/frame-perf-graph.h" + #include "security/rp-sign-key.h" #include "imports/avs.h" @@ -51,6 +56,7 @@ static bool iidxhook_init_check; static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { iidxhook_util_d3d9_irp_handler, + imgui_hook_d3d9_irp_handler, }; static const struct hook_symbol init_hook_user32_syms[] = { @@ -61,6 +67,17 @@ static const struct hook_symbol init_hook_user32_syms[] = { static struct iidxhook_config_io config_io; +static void iidxhook5_cn_setup_imgui_debug_components(const struct iidxhook_config_debug *config_debug) +{ + imgui_bt_component_t debug_frame_graph_component; + + if (config_debug->enable_frame_perf_graph) { + imgui_debug_frame_perf_graph_init(60.0f, &debug_frame_graph_component); + + imgui_d3d9_hook_init(&debug_frame_graph_component, 1); + } +} + static void iidxhook5_cn_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { @@ -97,6 +114,7 @@ static ATOM WINAPI my_RegisterClassA(const WNDCLASSA *lpWndClass) { struct cconfig *config; + struct iidxhook_config_debug config_debug; struct iidxhook_util_config_eamuse config_eamuse; struct iidxhook_config_gfx config_gfx; struct iidxhook_config_sec config_sec; @@ -114,6 +132,7 @@ static ATOM WINAPI my_RegisterClassA(const WNDCLASSA *lpWndClass) config = cconfig_init(); + iidxhook_config_debug_init(config); iidxhook_util_config_eamuse_init(config); iidxhook_config_gfx_init(config); iidxhook_config_io_init(config); @@ -128,6 +147,7 @@ static ATOM WINAPI my_RegisterClassA(const WNDCLASSA *lpWndClass) exit(EXIT_FAILURE); } + iidxhook_config_debug_get(&config_debug, config); iidxhook_util_config_eamuse_get(&config_eamuse, config); iidxhook_config_gfx_get(&config_gfx, config); iidxhook_config_io_get(&config_io, config); @@ -154,6 +174,8 @@ static ATOM WINAPI my_RegisterClassA(const WNDCLASSA *lpWndClass) &config_sec.black_plug_mcode); ezusb_iidx_emu_node_security_plug_set_pcbid(&config_eamuse.pcbid); + iidxhook5_cn_setup_imgui_debug_components(&config_debug); + iidxhook5_cn_setup_d3d9_hooks(&config_gfx); if (strlen(config_misc.settings_path) > 0) { diff --git a/src/main/iidxhook5/Module.mk b/src/main/iidxhook5/Module.mk index 78ea307..7f0274a 100644 --- a/src/main/iidxhook5/Module.mk +++ b/src/main/iidxhook5/Module.mk @@ -2,6 +2,9 @@ avsdlls += iidxhook5 ldflags_iidxhook5 := \ -liphlpapi \ + -ld3d9 \ + -ldwmapi\ + -lgdi32 \ deplibs_iidxhook5 := \ avs \ @@ -22,6 +25,9 @@ libs_iidxhook5 := \ cconfig \ util \ ezusb \ + imgui-bt \ + imgui-debug \ + imgui \ src_iidxhook5 := \ dllmain.c \ diff --git a/src/main/iidxhook5/dllmain.c b/src/main/iidxhook5/dllmain.c index 268bf39..dbee76d 100644 --- a/src/main/iidxhook5/dllmain.c +++ b/src/main/iidxhook5/dllmain.c @@ -27,6 +27,7 @@ #include "iidxhook-util/acio.h" #include "iidxhook-util/chart-patch.h" +#include "iidxhook-util/config-debug.h" #include "iidxhook-util/config-gfx.h" #include "iidxhook-util/config-io.h" #include "iidxhook-util/config-misc.h" @@ -34,6 +35,10 @@ #include "iidxhook-util/log-server.h" #include "iidxhook-util/settings.h" +#include "imgui-bt/imgui-d3d9-hook.h" + +#include "imgui-debug/frame-perf-graph.h" + #include "imports/avs.h" #include "util/log.h" @@ -50,10 +55,22 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { iidxhook_util_d3d9_irp_handler, + imgui_hook_d3d9_irp_handler, }; static struct iidxhook_config_io config_io; +static void iidxhook5_setup_imgui_debug_components(const struct iidxhook_config_debug *config_debug) +{ + imgui_bt_component_t debug_frame_graph_component; + + if (config_debug->enable_frame_perf_graph) { + imgui_debug_frame_perf_graph_init(60.0f, &debug_frame_graph_component); + + imgui_d3d9_hook_init(&debug_frame_graph_component, 1); + } +} + static void iidxhook5_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { @@ -103,6 +120,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) { struct cconfig *config; + struct iidxhook_config_debug config_debug; struct iidxhook_config_gfx config_gfx; struct iidxhook_config_misc config_misc; @@ -113,6 +131,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) config = cconfig_init(); + iidxhook_config_debug_init(config); iidxhook_config_gfx_init(config); iidxhook_config_io_init(config); iidxhook_config_misc_init(config); @@ -126,6 +145,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) exit(EXIT_FAILURE); } + iidxhook_config_debug_get(&config_debug, config); iidxhook_config_gfx_get(&config_gfx, config); iidxhook_config_io_get(&config_io, config); iidxhook_config_misc_get(&config_misc, config); @@ -135,6 +155,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) log_info(IIDXHOOK5_INFO_HEADER); log_info("Initializing iidxhook..."); + iidxhook5_setup_imgui_debug_components(&config_debug); + iidxhook5_setup_d3d9_hooks(&config_gfx); if (strlen(config_misc.settings_path) > 0) { diff --git a/src/main/iidxhook6/Module.mk b/src/main/iidxhook6/Module.mk index 7fda87b..d664a1e 100644 --- a/src/main/iidxhook6/Module.mk +++ b/src/main/iidxhook6/Module.mk @@ -2,6 +2,9 @@ avsdlls += iidxhook6 ldflags_iidxhook6 := \ -liphlpapi \ + -ld3d9 \ + -ldwmapi\ + -lgdi32 \ deplibs_iidxhook6 := \ avs \ @@ -23,6 +26,9 @@ libs_iidxhook6 := \ cconfig \ util \ ezusb \ + imgui-bt \ + imgui-debug \ + imgui \ src_iidxhook6 := \ dllmain.c \ diff --git a/src/main/iidxhook6/dllmain.c b/src/main/iidxhook6/dllmain.c index b4ca65a..7ecbefc 100644 --- a/src/main/iidxhook6/dllmain.c +++ b/src/main/iidxhook6/dllmain.c @@ -28,11 +28,16 @@ #include "iidxhook-d3d9/bb-scale-hd.h" #include "iidxhook-util/acio.h" +#include "iidxhook-util/config-debug.h" #include "iidxhook-util/config-gfx.h" #include "iidxhook-util/config-io.h" #include "iidxhook-util/d3d9.h" #include "iidxhook-util/log-server.h" +#include "imgui-bt/imgui-d3d9-hook.h" + +#include "imgui-debug/frame-perf-graph.h" + #include "imports/avs.h" #include "util/log.h" @@ -48,10 +53,22 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { iidxhook_d3d9_bb_scale_hd_d3d9_irp_handler, iidxhook_util_d3d9_irp_handler, + imgui_hook_d3d9_irp_handler, }; static struct iidxhook_config_io config_io; +static void iidxhook6_setup_imgui_debug_components(const struct iidxhook_config_debug *config_debug) +{ + imgui_bt_component_t debug_frame_graph_component; + + if (config_debug->enable_frame_perf_graph) { + imgui_debug_frame_perf_graph_init(60.0f, &debug_frame_graph_component); + + imgui_d3d9_hook_init(&debug_frame_graph_component, 1); + } +} + static void iidxhook6_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { @@ -87,6 +104,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) { struct cconfig *config; + struct iidxhook_config_debug config_debug; struct iidxhook_config_gfx config_gfx; log_server_init(); @@ -96,6 +114,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) config = cconfig_init(); + iidxhook_config_debug_init(config); iidxhook_config_gfx_init(config); iidxhook_config_io_init(config); @@ -108,6 +127,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) exit(EXIT_FAILURE); } + iidxhook_config_debug_get(&config_debug, config); iidxhook_config_gfx_get(&config_gfx, config); iidxhook_config_io_get(&config_io, config); @@ -116,6 +136,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) log_info(IIDXHOOK6_INFO_HEADER); log_info("Initializing iidxhook..."); + iidxhook6_setup_imgui_debug_components(&config_debug); + iidxhook6_setup_d3d9_hooks(&config_gfx); if (!config_io.disable_io_emu) { diff --git a/src/main/iidxhook7/Module.mk b/src/main/iidxhook7/Module.mk index a40366a..4c592a4 100644 --- a/src/main/iidxhook7/Module.mk +++ b/src/main/iidxhook7/Module.mk @@ -3,6 +3,8 @@ avsdlls += iidxhook7 ldflags_iidxhook7 := \ -liphlpapi \ -ld3d9 \ + -ldwmapi\ + -lgdi32 \ deplibs_iidxhook7 := \ avs \ @@ -24,6 +26,9 @@ libs_iidxhook7 := \ iidxio \ util \ ezusb \ + imgui-bt \ + imgui-debug \ + imgui \ src_iidxhook7 := \ dllmain.c \ diff --git a/src/main/iidxhook7/dllmain.c b/src/main/iidxhook7/dllmain.c index af948f6..80fb158 100644 --- a/src/main/iidxhook7/dllmain.c +++ b/src/main/iidxhook7/dllmain.c @@ -28,11 +28,16 @@ #include "iidxhook-d3d9/bb-scale-hd.h" #include "iidxhook-util/acio.h" +#include "iidxhook-util/config-debug.h" #include "iidxhook-util/config-gfx.h" #include "iidxhook-util/config-io.h" #include "iidxhook-util/d3d9.h" #include "iidxhook-util/log-server.h" +#include "imgui-bt/imgui-d3d9-hook.h" + +#include "imgui-debug/frame-perf-graph.h" + #include "imports/avs.h" #include "util/log.h" @@ -48,10 +53,22 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { iidxhook_d3d9_bb_scale_hd_d3d9_irp_handler, iidxhook_util_d3d9_irp_handler, + imgui_hook_d3d9_irp_handler, }; static struct iidxhook_config_io config_io; +static void iidxhook7_setup_imgui_debug_components(const struct iidxhook_config_debug *config_debug) +{ + imgui_bt_component_t debug_frame_graph_component; + + if (config_debug->enable_frame_perf_graph) { + imgui_debug_frame_perf_graph_init(60.0f, &debug_frame_graph_component); + + imgui_d3d9_hook_init(&debug_frame_graph_component, 1); + } +} + static void iidxhook7_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { @@ -87,6 +104,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) { struct cconfig *config; + struct iidxhook_config_debug config_debug; struct iidxhook_config_gfx config_gfx; log_server_init(); @@ -96,6 +114,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) config = cconfig_init(); + iidxhook_config_debug_init(config); iidxhook_config_gfx_init(config); iidxhook_config_io_init(config); @@ -108,6 +127,11 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) exit(EXIT_FAILURE); } + iidxhook_config_debug_init(config); + iidxhook_config_gfx_init(config); + iidxhook_config_io_init(config); + + iidxhook_config_debug_get(&config_debug, config); iidxhook_config_gfx_get(&config_gfx, config); iidxhook_config_io_get(&config_io, config); @@ -116,6 +140,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) log_info(IIDXHOOK7_INFO_HEADER); log_info("Initializing iidxhook..."); + iidxhook7_setup_imgui_debug_components(&config_debug); + iidxhook7_setup_d3d9_hooks(&config_gfx); if (!config_io.disable_io_emu) { diff --git a/src/main/iidxhook8/Module.mk b/src/main/iidxhook8/Module.mk index e71c8c2..954191c 100644 --- a/src/main/iidxhook8/Module.mk +++ b/src/main/iidxhook8/Module.mk @@ -7,6 +7,9 @@ ldflags_iidxhook8 := \ -lmf \ -lmfplat \ -lole32 \ + -ld3d9 \ + -ldwmapi\ + -lgdi32 \ deplibs_iidxhook8 := \ avs \ @@ -24,7 +27,10 @@ libs_iidxhook8 := \ cconfig \ util \ eamio \ - + imgui-bt \ + imgui-debug \ + imgui \ + src_iidxhook8 := \ config-io.c \ dllmain.c \ diff --git a/src/main/iidxhook8/dllmain.c b/src/main/iidxhook8/dllmain.c index 13509be..d1c95ab 100644 --- a/src/main/iidxhook8/dllmain.c +++ b/src/main/iidxhook8/dllmain.c @@ -21,10 +21,15 @@ #include "iidxhook-d3d9/bb-scale-hd.h" #include "iidxhook-util/acio.h" +#include "iidxhook-util/config-debug.h" #include "iidxhook-util/config-gfx.h" #include "iidxhook-util/d3d9.h" #include "iidxhook-util/log-server.h" +#include "imgui-bt/imgui-d3d9-hook.h" + +#include "imgui-debug/frame-perf-graph.h" + #include "bio2emu-iidx/bi2a.h" #include "bio2emu/emu.h" @@ -47,8 +52,19 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = { iidxhook_d3d9_bb_scale_hd_d3d9_irp_handler, iidxhook_util_d3d9_irp_handler, + imgui_hook_d3d9_irp_handler, }; +static void iidxhook8_setup_imgui_debug_components(const struct iidxhook_config_debug *config_debug) +{ + imgui_bt_component_t debug_frame_graph_component; + + if (config_debug->enable_frame_perf_graph) { + imgui_debug_frame_perf_graph_init(60.0f, &debug_frame_graph_component); + + imgui_d3d9_hook_init(&debug_frame_graph_component, 1); + } +} static void iidxhook8_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) { @@ -93,6 +109,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) { struct cconfig *config; + struct iidxhook_config_debug config_debug; struct iidxhook_config_gfx config_gfx; // log_server_init is required due to IO occuring in a non avs_thread @@ -104,6 +121,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) config = cconfig_init(); + iidxhook_config_debug_init(config); iidxhook_config_gfx_init(config); iidxhook8_config_io_init(config); camhook_config_cam_init(config, 2); @@ -117,6 +135,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) exit(EXIT_FAILURE); } + iidxhook_config_debug_get(&config_debug, config); iidxhook_config_gfx_get(&config_gfx, config); iidxhook8_config_io_get(&iidxhook8_config_io, config); camhook_config_cam_get(&config_cam, config, 2); @@ -126,6 +145,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) log_info(IIDXHOOK8_INFO_HEADER); log_info("Initializing iidxhook..."); + iidxhook8_setup_imgui_debug_components(&config_debug); + iidxhook8_setup_d3d9_hooks(&config_gfx); /* Start up IIDXIO.DLL */ diff --git a/src/main/util/Module.mk b/src/main/util/Module.mk index ab8d495..1a48cd3 100644 --- a/src/main/util/Module.mk +++ b/src/main/util/Module.mk @@ -20,5 +20,6 @@ src_util := \ str.c \ thread.c \ time.c \ + winerr.c \ winres.c \ diff --git a/src/main/util/proc.c b/src/main/util/proc.c index 8473113..47c5d3a 100644 --- a/src/main/util/proc.c +++ b/src/main/util/proc.c @@ -1,54 +1,25 @@ #define LOG_MODULE "util-proc" #include -#include - -#include -#include +#include +#include +#include +#include "util/defs.h" #include "util/log.h" +#include "util/mem.h" +#include "util/str.h" +#include "util/winerr.h" -bool proc_is_running_as_admin_user() -{ - SID_IDENTIFIER_AUTHORITY authority = SECURITY_NT_AUTHORITY; - PSID sid; - BOOL res; - BOOL is_admin; +#include "proc.h" - res = AllocateAndInitializeSid( - &authority, - 2, - SECURITY_BUILTIN_DOMAIN_RID, - DOMAIN_ALIAS_RID_ADMINS, - 0, - 0, - 0, - 0, - 0, - 0, - &sid); - - if (!res) { - log_warning( - "Failed to allocate memory for is admin check: %lX", - GetLastError()); - return false; - } - - is_admin = false; - - res = CheckTokenMembership(NULL, sid, &is_admin); - - if (!res) { - log_warning( - "Failed to check admin group membership: %lX", GetLastError()); - return false; - } - - FreeSid(sid); - - return is_admin; -} +typedef NTSTATUS (NTAPI *PNtQueryInformationThread)( + HANDLE ThreadHandle, + THREADINFOCLASS ThreadInformationClass, + PVOID ThreadInformation, + ULONG ThreadInformationLength, + PULONG ReturnLength +); void proc_terminate_current_process(uint32_t exit_code) { @@ -58,4 +29,196 @@ void proc_terminate_current_process(uint32_t exit_code) SYNCHRONIZE | PROCESS_TERMINATE, TRUE, GetCurrentProcessId()); TerminateProcess(hnd, exit_code); +} + +void* proc_thread_get_proc_address(int thread_id) +{ + HANDLE thread; + char* err_str; + HMODULE nt_dll; + PNtQueryInformationThread ntQueryInformationThread; + NTSTATUS status; + PVOID thread_start_address; + ULONG return_len; + + thread = proc_thread_get_handle(thread_id); + + if (thread == NULL) { + err_str = util_winerr_format_last_error_code(); + log_fatal("Failed to open thread with id %d: %s", thread_id, err_str); + } + + nt_dll = LoadLibrary("ntdll.dll"); + ntQueryInformationThread = (PNtQueryInformationThread) GetProcAddress(nt_dll, "NtQueryInformationThread"); + + status = ntQueryInformationThread(thread, ThreadQuerySetWin32StartAddress, &thread_start_address, sizeof(thread_start_address), &return_len); + + CloseHandle(thread); + FreeLibrary(nt_dll); + + if (status != STATUS_SUCCESS) { + log_fatal("Failed to get start address for thread %d: 0x%lx\n", thread_id, status); + } + + return thread_start_address; +} + +HMODULE proc_thread_proc_get_origin_module(void* proc_addr) +{ + HMODULE module; + + log_assert(proc_addr); + + if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + (LPCTSTR) proc_addr, &module)) { + return NULL; + } else { + return module; + } +} + +bool proc_thread_proc_get_origin_module_path(void* proc_addr, char* buffer, size_t len) +{ + HMODULE module; + + module = proc_thread_proc_get_origin_module(proc_addr); + + if (module != NULL) { + if (GetModuleFileNameA(module, buffer, len) == 0) { + return false; + } else { + return true; + } + } else { + return false; + } +} + +bool proc_thread_proc_get_origin_module_name(void* proc_addr, char* buffer, size_t len) +{ + HMODULE module; + char path_buffer[MAX_PATH]; + const char* filename; + + module = proc_thread_proc_get_origin_module(proc_addr); + + if (module != NULL) { + if (GetModuleFileNameA(module, path_buffer, sizeof(path_buffer)) == 0) { + return false; + } else { + filename = strrchr(path_buffer, '\\'); + + if (filename == NULL) { + // no backslashes found, use the entire path + filename = path_buffer; + } else { + // skip the backslash + filename++; + } + + str_cpy(buffer, len, filename); + + return true; + } + } else { + return false; + } +} + +size_t proc_thread_scan_threads_current_process(struct proc_thread_info** info) +{ + DWORD pid; + HANDLE snapshot; + char* err_str; + THREADENTRY32 thread_entry; + size_t idx; + HANDLE thread; + + log_assert(info); + + pid = GetCurrentProcessId(); + + // Create a snapshot of the running threads in the target process. + snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, pid); + + if (snapshot == INVALID_HANDLE_VALUE) { + err_str = util_winerr_format_last_error_code(); + log_fatal("Failed to create snapshot of threads: %s", err_str); + } + + thread_entry.dwSize = sizeof(THREADENTRY32); + + idx = 0; + *info = NULL; + + // Count entries for allocation of return value + if (Thread32First(snapshot, &thread_entry)) { + do { + if (thread_entry.th32OwnerProcessID == pid) { + *info = xrealloc(*info, (idx + 1) * sizeof(struct proc_thread_info)); + + thread = proc_thread_get_handle(thread_entry.th32ThreadID); + + (*info)[idx].id = thread_entry.th32ThreadID; + (*info)[idx].proc = proc_thread_get_proc_address(thread_entry.th32ThreadID); + (*info)[idx].priority = GetThreadPriority(thread); + (*info)[idx].origin_module = proc_thread_proc_get_origin_module((*info)[idx].proc); + + CloseHandle(thread); + + idx++; + } + } while (Thread32Next(snapshot, &thread_entry)); + } + + CloseHandle(snapshot); + + return idx; +} + +HANDLE proc_thread_get_handle(int thread_id) +{ + HANDLE handle; + + handle = OpenThread(THREAD_ALL_ACCESS, FALSE, thread_id); + + return handle; +} + +bool proc_thread_set_priority(int thread_id, int priority) +{ + HANDLE thread; + BOOL res; + + thread = proc_thread_get_handle(thread_id); + + if (thread == NULL) { + return false; + } + + res = SetThreadPriority(thread, priority); + + CloseHandle(thread); + + return res; +} + +bool proc_thread_set_affinity(int thread_id, uint32_t cpu_mask) +{ + HANDLE thread; + DWORD_PTR affinity_mask; + DWORD_PTR prev_affinity_mask; + + thread = proc_thread_get_handle(thread_id); + + if (thread == NULL) { + return false; + } + + affinity_mask = cpu_mask; + prev_affinity_mask = SetThreadAffinityMask(thread, affinity_mask); + + CloseHandle(thread); + + return prev_affinity_mask != 0; } \ No newline at end of file diff --git a/src/main/util/proc.h b/src/main/util/proc.h index be47a40..246ee75 100644 --- a/src/main/util/proc.h +++ b/src/main/util/proc.h @@ -1,8 +1,37 @@ #pragma once +#include + #include #include +#include -bool proc_is_running_as_admin_user(); +#define PROC_THREAD_CPU_AFFINITY_CORE(c) (1 << c) -void proc_terminate_current_process(uint32_t exit_code); \ No newline at end of file +struct proc_thread_info { + int id; + void* proc; + // According to + // https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getthreadpriority#return-value + int priority; + HMODULE origin_module; +}; + +void proc_terminate_current_process(uint32_t exit_code); + +void* proc_thread_get_proc_address(int thread_id); + +HMODULE proc_thread_proc_get_origin_module(void* proc_addr); + +bool proc_thread_proc_get_origin_module_path(void* proc_addr, char* buffer, size_t len); + +bool proc_thread_proc_get_origin_module_name(void* proc_addr, char* buffer, size_t len); + +size_t proc_thread_scan_threads_current_process(struct proc_thread_info** info); + +HANDLE proc_thread_get_handle(int thread_id); + +bool proc_thread_set_priority(int thread_id, int priority); + +// cpu starts with 0, specify multiple to set affinity to these cores +bool proc_thread_set_affinity(int thread_id, uint32_t cpu_mask); \ No newline at end of file