From b1329d10bf4dcb234a3cec199ba368ce8d17948d Mon Sep 17 00:00:00 2001 From: Will Xyen Date: Tue, 10 Dec 2019 15:23:53 -0500 Subject: [PATCH] camhook: Fix cameras not being auto-detected sometimes on older machines MFStartup needs to be called before any MF functions are used (such as for auto detect) --- src/main/camhook/cam.c | 18 ++++++++++++++++-- src/main/camhook/cam.h | 2 ++ src/main/iidxhook8/dllmain.c | 6 +++++- src/main/sdvxhook2/dllmain.c | 4 ++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/main/camhook/cam.c b/src/main/camhook/cam.c index 76fc7bd..f17b6cc 100644 --- a/src/main/camhook/cam.c +++ b/src/main/camhook/cam.c @@ -206,6 +206,7 @@ my_CM_Locate_DevNodeA(PDEVINST pdnDevInst, DEVINSTID_A pDeviceID, ULONG ulFlags) char builtString[CAMERA_DATA_STRING_SIZE] = {0}; if (pdnDevInst) { + log_info("seeking: %s", pDeviceID); for (size_t i = 0; i < CAMHOOK_CONFIG_CAM_MAX; ++i) { if (camData[i].setup) { snprintf( @@ -213,6 +214,7 @@ my_CM_Locate_DevNodeA(PDEVINST pdnDevInst, DEVINSTID_A pDeviceID, ULONG ulFlags) CAMERA_DATA_STRING_SIZE, "USB\\VID_288C&PID_0002&MI_00\\%s", camData[i].extra_upper); + log_info("built: %s", builtString); if (strcmp(pDeviceID, builtString) == 0) { if (!camData[i].fake_located) { camData[i].fake_located_node = num_located_cams; @@ -280,7 +282,9 @@ HRESULT my_GetAllocatedString( // should probably check GUID, oh well ret = real_GetAllocatedString(self, guidKey, ppwszValue, pcchLength); - log_info("Obtained: %ls", *ppwszValue); + char *pMBBuffer = (char *)malloc(0x100); + wcstombs(pMBBuffer, *ppwszValue, 0x100); + log_info("Obtained: %s", pMBBuffer); wchar_t *pwc = NULL; @@ -308,8 +312,11 @@ HRESULT my_GetAllocatedString( pwc[29] = L'0'; pwc[30] = L'0'; - log_info("Replaced: %ls", *ppwszValue); + + wcstombs(pMBBuffer, *ppwszValue, 0x100); + log_info("Replaced: %s", pMBBuffer); } + free(pMBBuffer); return ret; } @@ -787,6 +794,8 @@ void fill_cam_struct(struct CameraData *data, const char *devid) void camhook_init(struct camhook_config_cam *config_cam) { + MFStartup(0x20070u, 0); + // fill before applying hooks for (size_t i = 0; i < config_cam->num_devices; ++i) { fill_cam_struct(&camData[i], config_cam->device_id[i]); @@ -814,3 +823,8 @@ void camhook_init(struct camhook_config_cam *config_cam) log_info("No cams detected, not hooking"); } } + +void camhook_fini(void) +{ + MFShutdown(); +} diff --git a/src/main/camhook/cam.h b/src/main/camhook/cam.h index 2cc622d..d3039c6 100644 --- a/src/main/camhook/cam.h +++ b/src/main/camhook/cam.h @@ -5,4 +5,6 @@ void camhook_init(struct camhook_config_cam *config_cam); +void camhook_fini(void); + #endif diff --git a/src/main/iidxhook8/dllmain.c b/src/main/iidxhook8/dllmain.c index 44c4e13..9579ef3 100644 --- a/src/main/iidxhook8/dllmain.c +++ b/src/main/iidxhook8/dllmain.c @@ -75,6 +75,7 @@ iidxhook8_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) } struct iidxhook8_config_io iidxhook8_config_io; +struct camhook_config_cam config_cam; static struct bio2emu_port bio2_emu = { .port = "COM4", @@ -87,7 +88,6 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) struct cconfig *config; struct iidxhook_config_gfx config_gfx; - struct camhook_config_cam config_cam; // log_server_init is required due to IO occuring in a non avs_thread log_server_init(); @@ -181,6 +181,10 @@ static bool my_dll_entry_main(void) result = app_hook_invoke_main(); + if (!config_cam.disable_emu) { + camhook_fini(); + } + if (!iidxhook8_config_io.disable_card_reader_emu) { log_misc("Shutting down card reader backend"); eam_io_fini(); diff --git a/src/main/sdvxhook2/dllmain.c b/src/main/sdvxhook2/dllmain.c index f97ee26..87ad809 100644 --- a/src/main/sdvxhook2/dllmain.c +++ b/src/main/sdvxhook2/dllmain.c @@ -140,6 +140,10 @@ static bool my_dll_entry_main(void) result = app_hook_invoke_main(); + if (!config_cam.disable_emu) { + camhook_fini(); + } + if (!config_io.disable_card_reader_emu) { log_misc("Shutting down card reader backend"); eam_io_fini();