Apply clang-format code style to all source files

This commit is contained in:
icex2
2019-10-20 00:50:40 +02:00
parent c600e1a423
commit c3bc8782f4
401 changed files with 13844 additions and 11361 deletions
+58 -27
View File
@@ -6,23 +6,28 @@
#include <windows.h> /* for _BitScanForward */
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <string.h>
#include "acioemu/emu.h"
#include "bemanitools/iidxio.h"
static int get_default_slider_valid(size_t idx);
static void bio2_emu_bi2a_cmd_send_version(struct ac_io_emu *emu, const struct ac_io_message *req);
static void bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_message *req);
static void bio2_emu_bi2a_send_empty(struct ac_io_emu *emu, const struct ac_io_message *req);
static void bio2_emu_bi2a_send_status(struct ac_io_emu *emu, const struct ac_io_message *req, uint8_t status);
static void bio2_emu_bi2a_cmd_send_version(
struct ac_io_emu *emu, const struct ac_io_message *req);
static void bio2_emu_bi2a_send_state(
struct ac_io_emu *emu, const struct ac_io_message *req);
static void bio2_emu_bi2a_send_empty(
struct ac_io_emu *emu, const struct ac_io_message *req);
static void bio2_emu_bi2a_send_status(
struct ac_io_emu *emu, const struct ac_io_message *req, uint8_t status);
static int default_sliders[5];
static bool poll_delay;
int get_default_slider_valid(size_t idx) {
int get_default_slider_valid(size_t idx)
{
if (default_sliders[idx] >= 0 && default_sliders[idx] <= 15) {
return 1;
} else {
@@ -30,7 +35,8 @@ int get_default_slider_valid(size_t idx) {
}
}
void bio2_emu_bi2a_init(struct bio2emu_port *bio2_emu, bool disable_poll_limiter)
void bio2_emu_bi2a_init(
struct bio2emu_port *bio2_emu, bool disable_poll_limiter)
{
bio2emu_port_init(bio2_emu);
@@ -43,15 +49,22 @@ void bio2_emu_bi2a_init(struct bio2emu_port *bio2_emu, bool disable_poll_limiter
default_sliders[i] = -1;
}
FILE* f = fopen("vefx.txt", "r");
FILE *f = fopen("vefx.txt", "r");
if (f) {
fscanf(f, "%d %d %d %d %d", &default_sliders[0], &default_sliders[1], &default_sliders[2], &default_sliders[3], &default_sliders[4]);
fscanf(
f,
"%d %d %d %d %d",
&default_sliders[0],
&default_sliders[1],
&default_sliders[2],
&default_sliders[3],
&default_sliders[4]);
fclose(f);
}
}
void bio2_emu_bi2a_dispatch_request(struct bio2emu_port *bio2port, const struct ac_io_message *req)
void bio2_emu_bi2a_dispatch_request(
struct bio2emu_port *bio2port, const struct ac_io_message *req)
{
uint16_t cmd_code;
@@ -85,12 +98,16 @@ void bio2_emu_bi2a_dispatch_request(struct bio2emu_port *bio2port, const struct
break;
default:
log_warning("Unknown BIO2 message %04x on BI2A node, addr=%d", cmd_code, req->addr);
log_warning(
"Unknown BIO2 message %04x on BI2A node, addr=%d",
cmd_code,
req->addr);
break;
}
}
static void bio2_emu_bi2a_cmd_send_version(struct ac_io_emu *emu, const struct ac_io_message *req)
static void bio2_emu_bi2a_cmd_send_version(
struct ac_io_emu *emu, const struct ac_io_message *req)
{
struct ac_io_message resp;
@@ -103,15 +120,18 @@ static void bio2_emu_bi2a_cmd_send_version(struct ac_io_emu *emu, const struct a
resp.cmd.version.major = 0x04;
resp.cmd.version.minor = 0x00;
resp.cmd.version.revision = 0x04;
memcpy(resp.cmd.version.product_code, "BI2A",
sizeof(resp.cmd.version.product_code));
memcpy(
resp.cmd.version.product_code,
"BI2A",
sizeof(resp.cmd.version.product_code));
strncpy(resp.cmd.version.date, __DATE__, sizeof(resp.cmd.version.date));
strncpy(resp.cmd.version.time, __TIME__, sizeof(resp.cmd.version.time));
ac_io_emu_response_push(emu, &resp, 0);
}
static void bio2_emu_bi2a_send_empty(struct ac_io_emu *emu, const struct ac_io_message *req)
static void
bio2_emu_bi2a_send_empty(struct ac_io_emu *emu, const struct ac_io_message *req)
{
struct ac_io_message resp;
@@ -123,7 +143,8 @@ static void bio2_emu_bi2a_send_empty(struct ac_io_emu *emu, const struct ac_io_m
ac_io_emu_response_push(emu, &resp, 0);
}
static void bio2_emu_bi2a_send_status(struct ac_io_emu *emu, const struct ac_io_message *req, uint8_t status)
static void bio2_emu_bi2a_send_status(
struct ac_io_emu *emu, const struct ac_io_message *req, uint8_t status)
{
struct ac_io_message resp;
@@ -136,8 +157,8 @@ static void bio2_emu_bi2a_send_status(struct ac_io_emu *emu, const struct ac_io_
ac_io_emu_response_push(emu, &resp, 0);
}
static void bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_message *req)
static void
bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_message *req)
{
struct ac_io_message resp;
struct bi2a_iidx_state_out *body;
@@ -157,7 +178,7 @@ static void bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_m
resp.cmd.code = req->cmd.code;
resp.cmd.seq_no = req->cmd.seq_no;
resp.cmd.nbytes = sizeof(struct bi2a_iidx_state_out);
req_bi2a = (struct bi2a_iidx_state_in*)req->cmd.raw;
req_bi2a = (struct bi2a_iidx_state_in *) req->cmd.raw;
packed_lights.panel_lights = 0;
for (size_t i = 0; i < 4; ++i) {
@@ -193,12 +214,12 @@ static void bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_m
return bio2_emu_bi2a_send_status(emu, req, 0);
}
if (!iidx_io_ep3_write_16seg((const char*) req_bi2a->SEG16)) {
if (!iidx_io_ep3_write_16seg((const char *) req_bi2a->SEG16)) {
log_warning("BIO2: iidx_io_ep3_write_16seg error");
return bio2_emu_bi2a_send_status(emu, req, 0);
}
body = (struct bi2a_iidx_state_out *)&resp.cmd.raw;
body = (struct bi2a_iidx_state_out *) &resp.cmd.raw;
memset(body, 0, sizeof(struct bi2a_iidx_state_out));
// IIDX25 polls really really fast, this limits it to 1000Hz
@@ -214,11 +235,21 @@ static void bio2_emu_bi2a_send_state(struct ac_io_emu *emu, const struct ac_io_m
body->TURNTABLE1 = iidx_io_ep2_get_turntable(0);
body->TURNTABLE2 = iidx_io_ep2_get_turntable(1);
body->SLIDER1.s_val = get_default_slider_valid(0) ? default_sliders[0] : iidx_io_ep2_get_slider(0);
body->SLIDER2.s_val = get_default_slider_valid(1) ? default_sliders[1] : iidx_io_ep2_get_slider(1);
body->SLIDER3.s_val = get_default_slider_valid(2) ? default_sliders[2] : iidx_io_ep2_get_slider(2);
body->SLIDER4.s_val = get_default_slider_valid(3) ? default_sliders[3] : iidx_io_ep2_get_slider(3);
body->SLIDER5.s_val = get_default_slider_valid(4) ? default_sliders[4] : iidx_io_ep2_get_slider(4);
body->SLIDER1.s_val = get_default_slider_valid(0) ?
default_sliders[0] :
iidx_io_ep2_get_slider(0);
body->SLIDER2.s_val = get_default_slider_valid(1) ?
default_sliders[1] :
iidx_io_ep2_get_slider(1);
body->SLIDER3.s_val = get_default_slider_valid(2) ?
default_sliders[2] :
iidx_io_ep2_get_slider(2);
body->SLIDER4.s_val = get_default_slider_valid(3) ?
default_sliders[3] :
iidx_io_ep2_get_slider(3);
body->SLIDER5.s_val = get_default_slider_valid(4) ?
default_sliders[4] :
iidx_io_ep2_get_slider(4);
input_keys = iidx_io_ep2_get_keys();
input_sys = iidx_io_ep2_get_sys();
+28 -23
View File
@@ -2,43 +2,43 @@
#define IIDXHOOK_BI2A_H
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include <stdint.h>
#include "bio2emu/emu.h"
enum bio2_iidx_cmd {
// Custom Stuff
BIO2_BI2A_CMD_UNK_0100 = 0x0100,
BIO2_BI2A_CMD_UNK_0120 = 0x0120,
BIO2_BI2A_CMD_POLL = 0x0152,
BIO2_BI2A_CMD_UNK_0100 = 0x0100,
BIO2_BI2A_CMD_UNK_0120 = 0x0120,
BIO2_BI2A_CMD_POLL = 0x0152,
};
#pragma pack(push, 1)
struct bi2a_iidx_slider {
uint8_t s_unk : 4;
uint8_t s_val : 4;
uint8_t s_unk : 4;
uint8_t s_val : 4;
};
struct bi2a_iidx_system {
uint8_t v_unk1 : 1;
uint8_t v_coin : 1;
uint8_t v_service : 1;
uint8_t v_test : 1;
uint8_t v_unk2 : 4;
uint8_t v_unk1 : 1;
uint8_t v_coin : 1;
uint8_t v_service : 1;
uint8_t v_test : 1;
uint8_t v_unk2 : 4;
};
struct bi2a_iidx_button {
uint8_t b_unk : 7;
uint8_t b_val : 1;
uint8_t b_unk : 7;
uint8_t b_val : 1;
};
struct bi2a_iidx_panel {
uint8_t y_unk : 4;
uint8_t y_effect : 1;
uint8_t y_vefx : 1;
uint8_t y_start2 : 1;
uint8_t y_start1 : 1;
uint8_t y_unk : 4;
uint8_t y_effect : 1;
uint8_t y_vefx : 1;
uint8_t y_start2 : 1;
uint8_t y_start1 : 1;
};
struct bi2a_iidx_state_out {
@@ -91,8 +91,8 @@ struct bi2a_iidx_state_out {
};
struct bi2a_iidx_light {
uint8_t l_unk : 7;
uint8_t l_state : 1;
uint8_t l_unk : 7;
uint8_t l_state : 1;
};
struct bi2a_iidx_state_in {
@@ -106,11 +106,16 @@ struct bi2a_iidx_state_in {
struct bi2a_iidx_light SPOTLIGHT2[4];
uint8_t UNK3[7];
};
_Static_assert(sizeof(struct bi2a_iidx_state_in) == 48, "bi2a_iidx_state_in is the wrong size");
_Static_assert(sizeof(struct bi2a_iidx_state_out) == 46, "bi2a_iidx_state_out is the wrong size");
_Static_assert(
sizeof(struct bi2a_iidx_state_in) == 48,
"bi2a_iidx_state_in is the wrong size");
_Static_assert(
sizeof(struct bi2a_iidx_state_out) == 46,
"bi2a_iidx_state_out is the wrong size");
#pragma pack(pop)
void bio2_emu_bi2a_init(struct bio2emu_port *in, bool disable_poll_limiter);
void bio2_emu_bi2a_dispatch_request(struct bio2emu_port *bio2port, const struct ac_io_message *req);
void bio2_emu_bi2a_dispatch_request(
struct bio2emu_port *bio2port, const struct ac_io_message *req);
#endif
+338 -250
View File
@@ -3,12 +3,12 @@
#include <initguid.h>
#include <windows.h>
#include <mfobjects.h>
#include <mfidl.h>
#include <mfapi.h>
#include <mfidl.h>
#include <mfobjects.h>
#include <setupapi.h>
#include <cfgmgr32.h>
#include <setupapi.h>
#include <stdio.h>
@@ -24,9 +24,45 @@
#define CAMERA_DATA_STRING_SIZE 0x100
EXTERN_GUID(MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, 0xc60ac5fe, 0x252a, 0x478f, 0xa0, 0xef, 0xbc, 0x8f, 0xa5, 0xf7, 0xca, 0xd3);
EXTERN_GUID(MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID, 0x8ac3587a, 0x4ae7, 0x42d8, 0x99, 0xe0, 0x0a, 0x60, 0x13, 0xee, 0xf9, 0x0f);
EXTERN_GUID(MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, 0x58f0aad8, 0x22bf, 0x4f8a, 0xbb, 0x3d, 0xd2, 0xc4, 0x97, 0x8c, 0x6e, 0x2f);
EXTERN_GUID(
MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE,
0xc60ac5fe,
0x252a,
0x478f,
0xa0,
0xef,
0xbc,
0x8f,
0xa5,
0xf7,
0xca,
0xd3);
EXTERN_GUID(
MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID,
0x8ac3587a,
0x4ae7,
0x42d8,
0x99,
0xe0,
0x0a,
0x60,
0x13,
0xee,
0xf9,
0x0f);
EXTERN_GUID(
MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK,
0x58f0aad8,
0x22bf,
0x4f8a,
0xbb,
0x3d,
0xd2,
0xc4,
0x97,
0x8c,
0x6e,
0x2f);
// define ourselves cause mingw has these wrong
struct CameraData {
@@ -43,155 +79,96 @@ struct CameraData {
static struct CameraData camData[2];
static CONFIGRET my_CM_Locate_DevNodeA(
PDEVINST pdnDevInst,
DEVINSTID_A pDeviceID,
ULONG ulFlags
);
PDEVINST pdnDevInst, DEVINSTID_A pDeviceID, ULONG ulFlags);
static CONFIGRET my_CM_Get_Parent(
PDEVINST pdnDevInst,
DEVINST dnDevInst,
ULONG ulFlags
);
static CONFIGRET
my_CM_Get_Parent(PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags);
static CONFIGRET my_CM_Get_Device_IDA(
DEVINST dnDevInst,
PSTR Buffer,
ULONG BufferLen,
ULONG ulFlags
);
DEVINST dnDevInst, PSTR Buffer, ULONG BufferLen, ULONG ulFlags);
static CONFIGRET(*real_CM_Locate_DevNodeA)(
PDEVINST pdnDevInst,
DEVINSTID_A pDeviceID,
ULONG ulFlags
);
static CONFIGRET (*real_CM_Locate_DevNodeA)(
PDEVINST pdnDevInst, DEVINSTID_A pDeviceID, ULONG ulFlags);
static CONFIGRET(*real_CM_Get_Parent)(
PDEVINST pdnDevInst,
DEVINST dnDevInst,
ULONG ulFlags
);
static CONFIGRET (*real_CM_Get_Parent)(
PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags);
static CONFIGRET(*real_CM_Get_Device_IDA)(
DEVINST dnDevInst,
PSTR Buffer,
ULONG BufferLen,
ULONG ulFlags
);
static CONFIGRET (*real_CM_Get_Device_IDA)(
DEVINST dnDevInst, PSTR Buffer, ULONG BufferLen, ULONG ulFlags);
static HRESULT my_MFEnumDeviceSources(
IMFAttributes *pAttributes,
IMFActivate ***pppSourceActivate,
UINT32 *pcSourceActivate
);
IMFAttributes *pAttributes,
IMFActivate ***pppSourceActivate,
UINT32 *pcSourceActivate);
static HRESULT (*real_MFEnumDeviceSources)(
IMFAttributes *pAttributes,
IMFActivate ***pppSourceActivate,
UINT32 *pcSourceActivate
);
IMFAttributes *pAttributes,
IMFActivate ***pppSourceActivate,
UINT32 *pcSourceActivate);
static BOOL my_SetupDiDestroyDeviceInfoList(
HDEVINFO DeviceInfoSet
);
static BOOL my_SetupDiDestroyDeviceInfoList(HDEVINFO DeviceInfoSet);
static BOOL (*real_SetupDiDestroyDeviceInfoList)(
HDEVINFO DeviceInfoSet
);
static BOOL (*real_SetupDiDestroyDeviceInfoList)(HDEVINFO DeviceInfoSet);
static BOOL my_SetupDiEnumDeviceInfo(
HDEVINFO DeviceInfoSet,
DWORD MemberIndex,
PSP_DEVINFO_DATA DeviceInfoData
);
HDEVINFO DeviceInfoSet, DWORD MemberIndex, PSP_DEVINFO_DATA DeviceInfoData);
static BOOL (*real_SetupDiEnumDeviceInfo)(
HDEVINFO DeviceInfoSet,
DWORD MemberIndex,
PSP_DEVINFO_DATA DeviceInfoData
);
HDEVINFO DeviceInfoSet, DWORD MemberIndex, PSP_DEVINFO_DATA DeviceInfoData);
static BOOL my_SetupDiGetDeviceRegistryPropertyA(
HDEVINFO DeviceInfoSet,
PSP_DEVINFO_DATA DeviceInfoData,
DWORD Property,
PDWORD PropertyRegDataType,
PBYTE PropertyBuffer,
DWORD PropertyBufferSize,
PDWORD RequiredSize
);
HDEVINFO DeviceInfoSet,
PSP_DEVINFO_DATA DeviceInfoData,
DWORD Property,
PDWORD PropertyRegDataType,
PBYTE PropertyBuffer,
DWORD PropertyBufferSize,
PDWORD RequiredSize);
static BOOL (*real_SetupDiGetDeviceRegistryPropertyA)(
HDEVINFO DeviceInfoSet,
PSP_DEVINFO_DATA DeviceInfoData,
DWORD Property,
PDWORD PropertyRegDataType,
PBYTE PropertyBuffer,
DWORD PropertyBufferSize,
PDWORD RequiredSize
);
HDEVINFO DeviceInfoSet,
PSP_DEVINFO_DATA DeviceInfoData,
DWORD Property,
PDWORD PropertyRegDataType,
PBYTE PropertyBuffer,
DWORD PropertyBufferSize,
PDWORD RequiredSize);
static HDEVINFO my_SetupDiGetClassDevsA(
CONST GUID *ClassGuid,
PCSTR Enumerator,
HWND hwndParent,
DWORD Flags
);
CONST GUID *ClassGuid, PCSTR Enumerator, HWND hwndParent, DWORD Flags);
static HDEVINFO(*real_SetupDiGetClassDevsA)(
CONST GUID *ClassGuid,
PCSTR Enumerator,
HWND hwndParent,
DWORD Flags
);
static HDEVINFO (*real_SetupDiGetClassDevsA)(
CONST GUID *ClassGuid, PCSTR Enumerator, HWND hwndParent, DWORD Flags);
static const struct hook_symbol iidxhook5_cfgmgr32_syms[] = {
{
.name = "CM_Locate_DevNodeA",
.patch = my_CM_Locate_DevNodeA,
.link = (void **) &real_CM_Locate_DevNodeA
},
{
.name = "CM_Get_Parent",
.patch = my_CM_Get_Parent,
.link = (void **) &real_CM_Get_Parent
},
{
.name = "CM_Get_Device_IDA",
.patch = my_CM_Get_Device_IDA,
.link = (void **) &real_CM_Get_Device_IDA
},
{
.name = "SetupDiDestroyDeviceInfoList",
.patch = my_SetupDiDestroyDeviceInfoList,
.link = (void **) &real_SetupDiDestroyDeviceInfoList
},
{
.name = "SetupDiEnumDeviceInfo",
.patch = my_SetupDiEnumDeviceInfo,
.link = (void **) &real_SetupDiEnumDeviceInfo
},
{
.name = "SetupDiGetDeviceRegistryPropertyA",
.patch = my_SetupDiGetDeviceRegistryPropertyA,
.link = (void **) &real_SetupDiGetDeviceRegistryPropertyA
},
{
.name = "SetupDiGetClassDevsA",
.patch = my_SetupDiGetClassDevsA,
.link = (void **) &real_SetupDiGetClassDevsA
},
{.name = "CM_Locate_DevNodeA",
.patch = my_CM_Locate_DevNodeA,
.link = (void **) &real_CM_Locate_DevNodeA},
{.name = "CM_Get_Parent",
.patch = my_CM_Get_Parent,
.link = (void **) &real_CM_Get_Parent},
{.name = "CM_Get_Device_IDA",
.patch = my_CM_Get_Device_IDA,
.link = (void **) &real_CM_Get_Device_IDA},
{.name = "SetupDiDestroyDeviceInfoList",
.patch = my_SetupDiDestroyDeviceInfoList,
.link = (void **) &real_SetupDiDestroyDeviceInfoList},
{.name = "SetupDiEnumDeviceInfo",
.patch = my_SetupDiEnumDeviceInfo,
.link = (void **) &real_SetupDiEnumDeviceInfo},
{.name = "SetupDiGetDeviceRegistryPropertyA",
.patch = my_SetupDiGetDeviceRegistryPropertyA,
.link = (void **) &real_SetupDiGetDeviceRegistryPropertyA},
{.name = "SetupDiGetClassDevsA",
.patch = my_SetupDiGetClassDevsA,
.link = (void **) &real_SetupDiGetClassDevsA},
};
static const struct hook_symbol iidxhook5_mf_syms[] = {
{
.name = "MFEnumDeviceSources",
.patch = my_MFEnumDeviceSources,
.link = (void **) &real_MFEnumDeviceSources
},
{.name = "MFEnumDeviceSources",
.patch = my_MFEnumDeviceSources,
.link = (void **) &real_MFEnumDeviceSources},
};
#define CUSTOM_DEV_NODE1 0x04040004
@@ -200,22 +177,33 @@ static const struct hook_symbol iidxhook5_mf_syms[] = {
#define CUSTOM_DEV_PARENT_NODE1 0x04040014
#define CUSTOM_DEV_PARENT_NODE2 0x04040018
static CONFIGRET my_CM_Locate_DevNodeA(
PDEVINST pdnDevInst,
DEVINSTID_A pDeviceID,
ULONG ulFlags
){
static CONFIGRET
my_CM_Locate_DevNodeA(PDEVINST pdnDevInst, DEVINSTID_A pDeviceID, ULONG ulFlags)
{
log_info("Inside: %s", __FUNCTION__);
char builtString1[CAMERA_DATA_STRING_SIZE] = {0};
char builtString2[CAMERA_DATA_STRING_SIZE] = {0};
if (camData[0].setup) {
snprintf(builtString1, CAMERA_DATA_STRING_SIZE, "USB\\VID_288C&PID_0002&MI_00\\%s", camData[0].extra_upper);
if(camData[1].setup) {
snprintf(builtString2, CAMERA_DATA_STRING_SIZE, "USB\\VID_288C&PID_0002&MI_00\\%s", camData[1].extra_upper);
snprintf(
builtString1,
CAMERA_DATA_STRING_SIZE,
"USB\\VID_288C&PID_0002&MI_00\\%s",
camData[0].extra_upper);
if (camData[1].setup) {
snprintf(
builtString2,
CAMERA_DATA_STRING_SIZE,
"USB\\VID_288C&PID_0002&MI_00\\%s",
camData[1].extra_upper);
}
} else if(camData[1].setup) {
snprintf(builtString1, CAMERA_DATA_STRING_SIZE, "USB\\VID_288C&PID_0002&MI_00\\%s", camData[1].extra_upper);
} else if (camData[1].setup) {
snprintf(
builtString1,
CAMERA_DATA_STRING_SIZE,
"USB\\VID_288C&PID_0002&MI_00\\%s",
camData[1].extra_upper);
}
if (pdnDevInst) {
@@ -224,6 +212,7 @@ static CONFIGRET my_CM_Locate_DevNodeA(
*pdnDevInst = CUSTOM_DEV_NODE1;
return CR_SUCCESS;
}
if (strcmp(pDeviceID, builtString2) == 0) {
log_info("Injecting custom device 2");
*pdnDevInst = CUSTOM_DEV_NODE2;
@@ -233,11 +222,9 @@ static CONFIGRET my_CM_Locate_DevNodeA(
return real_CM_Locate_DevNodeA(pdnDevInst, pDeviceID, ulFlags);
}
static CONFIGRET my_CM_Get_Parent(
PDEVINST pdnDevInst,
DEVINST dnDevInst,
ULONG ulFlags
){
static CONFIGRET
my_CM_Get_Parent(PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags)
{
log_info("Inside: %s", __FUNCTION__);
if (pdnDevInst) {
@@ -257,11 +244,8 @@ static CONFIGRET my_CM_Get_Parent(
}
static CONFIGRET my_CM_Get_Device_IDA(
DEVINST dnDevInst,
PSTR Buffer,
ULONG BufferLen,
ULONG ulFlags
){
DEVINST dnDevInst, PSTR Buffer, ULONG BufferLen, ULONG ulFlags)
{
log_info("Inside: %s", __FUNCTION__);
if (Buffer) {
@@ -272,6 +256,7 @@ static CONFIGRET my_CM_Get_Device_IDA(
log_info("%s", Buffer);
return CR_SUCCESS;
}
if (dnDevInst == CUSTOM_DEV_PARENT_NODE2) {
log_info("Injecting custom parent 2 ID");
strncpy(Buffer, "USB\\VEN_1022&DEV_7914", BufferLen);
@@ -283,19 +268,13 @@ static CONFIGRET my_CM_Get_Device_IDA(
return real_CM_Get_Device_IDA(dnDevInst, Buffer, BufferLen, ulFlags);
}
static HRESULT(STDCALL *real_GetAllocatedString)(
IMFActivate *self, REFGUID guidKey, LPWSTR *ppwszValue, UINT32 *pcchLength);
static HRESULT (STDCALL *real_GetAllocatedString)(
IMFActivate* self,
REFGUID guidKey,
LPWSTR *ppwszValue,
UINT32 *pcchLength);
HRESULT my_GetAllocatedString(
IMFActivate* self,
REFGUID guidKey,
LPWSTR *ppwszValue,
UINT32 *pcchLength
){
HRESULT
my_GetAllocatedString(
IMFActivate *self, REFGUID guidKey, LPWSTR *ppwszValue, UINT32 *pcchLength)
{
HRESULT ret;
log_info("Inside: %s", __FUNCTION__);
@@ -308,13 +287,14 @@ HRESULT my_GetAllocatedString(
if (camData[0].setup) {
pwc = wcsstr(*ppwszValue, camData[0].deviceSymbolicLink);
}
if (camData[1].setup) {
if (!pwc) {
pwc = wcsstr(*ppwszValue, camData[1].deviceSymbolicLink);
}
}
if (pwc){
if (pwc) {
// \\?\usb#vid_288c&pid_0002&mi_00
pwc[12] = L'2';
pwc[13] = L'8';
@@ -332,14 +312,13 @@ HRESULT my_GetAllocatedString(
}
return ret;
}
static HRESULT my_MFEnumDeviceSources(
IMFAttributes *pAttributes,
IMFActivate ***pppSourceActivate,
UINT32 *pcSourceActivate
){
IMFAttributes *pAttributes,
IMFActivate ***pppSourceActivate,
UINT32 *pcSourceActivate)
{
IMFActivate *api;
IMFActivateVtbl *api_vtbl;
struct com_proxy *api_proxy;
@@ -348,9 +327,9 @@ static HRESULT my_MFEnumDeviceSources(
HRESULT ret;
log_info("Inside: %s", __FUNCTION__);
ret = real_MFEnumDeviceSources(pAttributes, pppSourceActivate, pcSourceActivate);
ret = real_MFEnumDeviceSources(
pAttributes, pppSourceActivate, pcSourceActivate);
nsrcs = *pcSourceActivate;
for (UINT32 i = 0; i < nsrcs; ++i) {
@@ -361,88 +340,112 @@ static HRESULT my_MFEnumDeviceSources(
real_GetAllocatedString = api_vtbl->GetAllocatedString;
api_vtbl->GetAllocatedString = my_GetAllocatedString;
(*pppSourceActivate)[i] = (IMFActivate *)api_proxy;
(*pppSourceActivate)[i] = (IMFActivate *) api_proxy;
}
return ret;
}
#define CUSTOM_DEVICE_HANDLE (void*)0x04041110
#define CUSTOM_DEVICE_HANDLE (void *) 0x04041110
static HDEVINFO RealReplacedHandle;
static BOOL my_SetupDiDestroyDeviceInfoList(
HDEVINFO DeviceInfoSet
){
if (DeviceInfoSet == CUSTOM_DEVICE_HANDLE){
static BOOL my_SetupDiDestroyDeviceInfoList(HDEVINFO DeviceInfoSet)
{
if (DeviceInfoSet == CUSTOM_DEVICE_HANDLE) {
log_info("Inside: %s", __FUNCTION__);
DeviceInfoSet = RealReplacedHandle;
RealReplacedHandle = NULL;
return real_SetupDiDestroyDeviceInfoList(DeviceInfoSet);
}
return real_SetupDiDestroyDeviceInfoList(DeviceInfoSet);
}
static BOOL my_SetupDiEnumDeviceInfo(
HDEVINFO DeviceInfoSet,
DWORD MemberIndex,
PSP_DEVINFO_DATA DeviceInfoData
){
HDEVINFO DeviceInfoSet, DWORD MemberIndex, PSP_DEVINFO_DATA DeviceInfoData)
{
if (DeviceInfoSet == CUSTOM_DEVICE_HANDLE) {
// log_info("Inside: %s", __FUNCTION__);
return real_SetupDiEnumDeviceInfo(RealReplacedHandle, MemberIndex, DeviceInfoData);
return real_SetupDiEnumDeviceInfo(
RealReplacedHandle, MemberIndex, DeviceInfoData);
}
return real_SetupDiEnumDeviceInfo(DeviceInfoSet, MemberIndex, DeviceInfoData);
return real_SetupDiEnumDeviceInfo(
DeviceInfoSet, MemberIndex, DeviceInfoData);
}
static BOOL my_SetupDiGetDeviceRegistryPropertyA(
HDEVINFO DeviceInfoSet,
PSP_DEVINFO_DATA DeviceInfoData,
DWORD Property,
PDWORD PropertyRegDataType,
PBYTE PropertyBuffer,
DWORD PropertyBufferSize,
PDWORD RequiredSize
){
HDEVINFO DeviceInfoSet,
PSP_DEVINFO_DATA DeviceInfoData,
DWORD Property,
PDWORD PropertyRegDataType,
PBYTE PropertyBuffer,
DWORD PropertyBufferSize,
PDWORD RequiredSize)
{
if (DeviceInfoSet == CUSTOM_DEVICE_HANDLE) {
BOOL ret = real_SetupDiGetDeviceRegistryPropertyA(RealReplacedHandle, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize);
BOOL ret = real_SetupDiGetDeviceRegistryPropertyA(
RealReplacedHandle,
DeviceInfoData,
Property,
PropertyRegDataType,
PropertyBuffer,
PropertyBufferSize,
RequiredSize);
if (Property == SPDRP_DEVICEDESC) {
if (PropertyBuffer){
if (PropertyBuffer) {
if (camData[0].setup) {
if (strcmp((char*)PropertyBuffer, camData[0].parent_name) == 0) {
log_info("%s: replacing %s", __FUNCTION__, camData[0].parent_name);
strncpy((char*)PropertyBuffer, "USB Composite Device", PropertyBufferSize);
if (strcmp(
(char *) PropertyBuffer, camData[0].parent_name) ==
0) {
log_info(
"%s: replacing %s",
__FUNCTION__,
camData[0].parent_name);
strncpy(
(char *) PropertyBuffer,
"USB Composite Device",
PropertyBufferSize);
}
}
if (camData[1].setup) {
if (strcmp((char*)PropertyBuffer, camData[1].parent_name) == 0) {
log_info("%s: replacing %s", __FUNCTION__, camData[1].parent_name);
strncpy((char*)PropertyBuffer, "USB Composite Device", PropertyBufferSize);
if (strcmp(
(char *) PropertyBuffer, camData[1].parent_name) ==
0) {
log_info(
"%s: replacing %s",
__FUNCTION__,
camData[1].parent_name);
strncpy(
(char *) PropertyBuffer,
"USB Composite Device",
PropertyBufferSize);
}
}
}
return ret;
} else if (Property == SPDRP_ADDRESS) {
if (PropertyBuffer){
int addr = *(int*)PropertyBuffer;
if (PropertyBuffer) {
int addr = *(int *) PropertyBuffer;
if (camData[0].setup) {
if (addr == camData[0].parent_address) {
log_info("%s: replacing addr1", __FUNCTION__);
*(int*)PropertyBuffer = 1;
*(int *) PropertyBuffer = 1;
} else if (camData[1].setup) {
if (addr == camData[1].parent_address) {
log_info("%s: replacing addr7", __FUNCTION__);
*(int*)PropertyBuffer = 7;
*(int *) PropertyBuffer = 7;
}
}
} else if (camData[1].setup) {
if (addr == camData[1].parent_address) {
log_info("%s: replacing addr1 (alt)", __FUNCTION__);
*(int*)PropertyBuffer = 1;
*(int *) PropertyBuffer = 1;
}
}
}
@@ -450,36 +453,48 @@ static BOOL my_SetupDiGetDeviceRegistryPropertyA(
return ret;
}
}
return real_SetupDiGetDeviceRegistryPropertyA(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize);
return real_SetupDiGetDeviceRegistryPropertyA(
DeviceInfoSet,
DeviceInfoData,
Property,
PropertyRegDataType,
PropertyBuffer,
PropertyBufferSize,
RequiredSize);
}
static HDEVINFO my_SetupDiGetClassDevsA(
CONST GUID *ClassGuid,
PCSTR Enumerator,
HWND hwndParent,
DWORD Flags
){
if (ClassGuid == NULL && Enumerator != NULL && hwndParent == NULL && Flags == (DIGCF_PRESENT | DIGCF_ALLCLASSES)) {
CONST GUID *ClassGuid, PCSTR Enumerator, HWND hwndParent, DWORD Flags)
{
if (ClassGuid == NULL && Enumerator != NULL && hwndParent == NULL &&
Flags == (DIGCF_PRESENT | DIGCF_ALLCLASSES)) {
if (RealReplacedHandle) {
log_info("Replacement handle is already set?");
}
if (strcmp(Enumerator, "USB") == 0) {
log_info("Inside: %s", __FUNCTION__);
RealReplacedHandle = real_SetupDiGetClassDevsA(ClassGuid, Enumerator, hwndParent, Flags);
RealReplacedHandle = real_SetupDiGetClassDevsA(
ClassGuid, Enumerator, hwndParent, Flags);
if (RealReplacedHandle == INVALID_HANDLE_VALUE) {
return INVALID_HANDLE_VALUE;
}
return CUSTOM_DEVICE_HANDLE;
}
}
return real_SetupDiGetClassDevsA(ClassGuid, Enumerator, hwndParent, Flags);
}
bool check_four(const char inA[4], const char inB[4]) {
return (*(uint32_t*)inA == *(uint32_t*)inB);
bool check_four(const char inA[4], const char inB[4])
{
return (*(uint32_t *) inA == *(uint32_t *) inB);
}
char* grab_next_camera_id(char* buffer, size_t bsz) {
char *grab_next_camera_id(char *buffer, size_t bsz)
{
static size_t gotten = 0;
IMFAttributes *pAttributes = NULL;
@@ -488,26 +503,32 @@ char* grab_next_camera_id(char* buffer, size_t bsz) {
buffer[0] = '\0';
HRESULT hr = MFCreateAttributes(&pAttributes, 1);
if (FAILED(hr)) {
log_info("MFCreateAttributes failed: %ld", hr);
goto done;
}
hr = pAttributes->lpVtbl->SetGUID(pAttributes, &MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, &MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID);
if (FAILED(hr)) {
hr = pAttributes->lpVtbl->SetGUID(
pAttributes,
&MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE,
&MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID);
i f(FAILED(hr))
{
log_info("SetGUID failed: %ld", hr);
goto done;
}
UINT32 count;
hr = MFEnumDeviceSources(pAttributes, &ppDevices, &count);
if (FAILED(hr)) {
log_info("MFEnumDeviceSources failed: %ld", hr);
goto done;
}
if (count <= gotten) {
log_info("gotten failed: %d < %d", count, (int)gotten);
log_info("gotten failed: %d < %d", count, (int) gotten);
// not enough remaining
goto done;
}
@@ -515,11 +536,18 @@ char* grab_next_camera_id(char* buffer, size_t bsz) {
wchar_t wSymLink[CAMERA_DATA_STRING_SIZE];
UINT32 sz;
hr = ppDevices[gotten]->lpVtbl->GetString(ppDevices[gotten], &MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, wSymLink, CAMERA_DATA_STRING_SIZE, &sz);
hr = ppDevices[gotten]->lpVtbl->GetString(
ppDevices[gotten],
&MY_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK,
wSymLink,
CAMERA_DATA_STRING_SIZE,
&sz);
if (FAILED(hr)) {
log_info("GetString failed: %ld", hr);
goto done;
}
log_info("Detected webcam: %s\n", buffer);
wcstombs(buffer, wSymLink, bsz);
++gotten;
@@ -534,13 +562,16 @@ done:
ppDevices[i]->lpVtbl->Release(ppDevices[i]);
}
}
CoTaskMemFree(ppDevices);
return buffer;
}
bool convert_sym_to_path(const char* sym, char* path) {
bool convert_sym_to_path(const char *sym, char *path)
{
HDEVINFO DeviceInfoSet = SetupDiCreateDeviceInfoList(NULL, NULL);
if (DeviceInfoSet == INVALID_HANDLE_VALUE) {
log_info("Could not open SetupDiCreateDeviceInfoList\n");
return 0;
@@ -549,7 +580,8 @@ bool convert_sym_to_path(const char* sym, char* path) {
SP_DEVICE_INTERFACE_DATA DeviceInterfaceData = {0};
DeviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
if (!SetupDiOpenDeviceInterfaceA(DeviceInfoSet, sym, 0, &DeviceInterfaceData)) {
if (!SetupDiOpenDeviceInterfaceA(
DeviceInfoSet, sym, 0, &DeviceInterfaceData)) {
log_info("Could not SetupDiOpenDeviceInterfaceA\n");
return 0;
}
@@ -557,7 +589,13 @@ bool convert_sym_to_path(const char* sym, char* path) {
SP_DEVINFO_DATA DeviceInfoData = {0};
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
if (!SetupDiGetDeviceInterfaceDetailA(DeviceInfoSet, &DeviceInterfaceData, NULL, 0, NULL, &DeviceInfoData)) {
if (!SetupDiGetDeviceInterfaceDetailA(
DeviceInfoSet,
&DeviceInterfaceData,
NULL,
0,
NULL,
&DeviceInfoData)) {
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
log_info("Could not SetupDiGetDeviceInterfaceDetailA\n");
return 0;
@@ -565,35 +603,52 @@ bool convert_sym_to_path(const char* sym, char* path) {
}
DWORD sz;
if (!SetupDiGetDeviceInstanceIdA(DeviceInfoSet, &DeviceInfoData, path, CAMERA_DATA_STRING_SIZE, &sz)){
if (!SetupDiGetDeviceInstanceIdA(
DeviceInfoSet,
&DeviceInfoData,
path,
CAMERA_DATA_STRING_SIZE,
&sz)) {
log_info("Could not SetupDiGetDeviceInstanceIdA\n");
return 0;
}
if (DeviceInfoSet != INVALID_HANDLE_VALUE){
if (!SetupDiDeleteDeviceInterfaceData(DeviceInfoSet, &DeviceInterfaceData)){
if (DeviceInfoSet != INVALID_HANDLE_VALUE) {
if (!SetupDiDeleteDeviceInterfaceData(
DeviceInfoSet, &DeviceInterfaceData)) {
log_info("Could not SetupDiDeleteDeviceInterfaceData\n");
return 0;
}
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
}
return 1;
}
void strtolower(char* str) {
for (size_t i = 0; str[i]; i++){
void strtolower(char *str)
{
for (size_t i = 0; str[i]; i++) {
str[i] = tolower(str[i]);
}
}
bool convert_path_to_fakesym(const char* path, wchar_t* sym, char* extra_o) {
bool convert_path_to_fakesym(const char *path, wchar_t *sym, char *extra_o)
{
char root[16] = {0};
char vidstr[16] = {0};
char pidstr[16] = {0};
char mistr[16] = {0};
char extra[64] = {0};
sscanf(path, "%[^\\]\\%[^&]&%[^&]&%[^\\]\\%s", root, vidstr, pidstr, mistr, extra);
sscanf(
path,
"%[^\\]\\%[^&]&%[^&]&%[^\\]\\%s",
root,
vidstr,
pidstr,
mistr,
extra);
strcpy(extra_o, extra);
strtolower(root);
@@ -602,19 +657,29 @@ bool convert_path_to_fakesym(const char* path, wchar_t* sym, char* extra_o) {
strtolower(mistr);
strtolower(extra);
swprintf(sym, CAMERA_DATA_STRING_SIZE, L"\\\\?\\%S#%S&%S&%S#%S", root, vidstr, pidstr, mistr, extra);
swprintf(
sym,
CAMERA_DATA_STRING_SIZE,
L"\\\\?\\%S#%S&%S&%S#%S",
root,
vidstr,
pidstr,
mistr,
extra);
return true;
}
void fill_cam_struct(struct CameraData* data, const char* devid)
void fill_cam_struct(struct CameraData *data, const char *devid)
{
char buffer[CAMERA_DATA_STRING_SIZE];
data->setup = false;
if (!devid || strlen(devid) == 0) {
devid = grab_next_camera_id(buffer, CAMERA_DATA_STRING_SIZE);
}
if (!devid || strlen(devid) == 0) {
// no more cameras remain?
return;
@@ -624,10 +689,11 @@ void fill_cam_struct(struct CameraData* data, const char* devid)
// error probably log something?
return;
}
// detect input type
if (check_four(devid, "\\\\?\\")) {
// SYMBOLIC_LINK
if (!convert_sym_to_path(devid, data->deviceInstancePath)){
if (!convert_sym_to_path(devid, data->deviceInstancePath)) {
log_info("Could not convert %s to path", devid);
return;
}
@@ -642,30 +708,38 @@ void fill_cam_struct(struct CameraData* data, const char* devid)
return;
}
if (!convert_path_to_fakesym(data->deviceInstancePath, data->deviceSymbolicLink, data->extra_upper)){
if (!convert_path_to_fakesym(
data->deviceInstancePath,
data->deviceSymbolicLink,
data->extra_upper)) {
log_info("Could not convert %s to sym", data->deviceInstancePath);
return;
}
log_info("dev path: %s", data->deviceInstancePath);
log_info("dev path: %s", data->deviceInstancePath);
// locate device nodes
DEVINST dnDevInst;
DEVINST parentDev;
CONFIGRET cmret;
cmret = CM_Locate_DevNodeA(&dnDevInst, data->deviceInstancePath, CM_LOCATE_DEVNODE_NORMAL);
cmret = CM_Locate_DevNodeA(
&dnDevInst, data->deviceInstancePath, CM_LOCATE_DEVNODE_NORMAL);
if (cmret != CR_SUCCESS) {
log_info("CM_Locate_DevNodeA fail: %s", data->deviceInstancePath);
return;
}
cmret = CM_Get_Parent(&parentDev, dnDevInst, 0);
if (cmret != CR_SUCCESS) {
log_info("CM_Get_Parent fail: %s", data->deviceInstancePath);
return;
}
cmret = CM_Get_Device_IDA(parentDev, data->parent_deviceInstancePath, CAMERA_DATA_STRING_SIZE, 0);
cmret = CM_Get_Device_IDA(
parentDev, data->parent_deviceInstancePath, CAMERA_DATA_STRING_SIZE, 0);
if (cmret != CR_SUCCESS) {
log_info("CM_Get_Device_IDA parent fail: %s", data->deviceInstancePath);
return;
@@ -676,27 +750,45 @@ void fill_cam_struct(struct CameraData* data, const char* devid)
szAddr = 4;
szDesc = CAMERA_DATA_STRING_SIZE;
cmret = CM_Get_DevNode_Registry_PropertyA(dnDevInst, CM_DRP_ADDRESS, NULL, &data->address, &szAddr, 0);
cmret = CM_Get_DevNode_Registry_PropertyA(
dnDevInst, CM_DRP_ADDRESS, NULL, &data->address, &szAddr, 0);
if (cmret != CR_SUCCESS) {
log_info("CM_Get_DevNode_Registry_PropertyA fail: %s", data->deviceInstancePath);
log_info(
"CM_Get_DevNode_Registry_PropertyA fail: %s",
data->deviceInstancePath);
return;
}
cmret = CM_Get_DevNode_Registry_PropertyA(dnDevInst, CM_DRP_DEVICEDESC, NULL, &data->name, &szDesc, 0);
cmret = CM_Get_DevNode_Registry_PropertyA(
dnDevInst, CM_DRP_DEVICEDESC, NULL, &data->name, &szDesc, 0);
if (cmret != CR_SUCCESS) {
log_info("CM_Get_DevNode_Registry_PropertyA fail: %s", data->deviceInstancePath);
log_info(
"CM_Get_DevNode_Registry_PropertyA fail: %s",
data->deviceInstancePath);
return;
}
szAddr = 4;
szDesc = CAMERA_DATA_STRING_SIZE;
cmret = CM_Get_DevNode_Registry_PropertyA(parentDev, CM_DRP_ADDRESS, NULL, &data->parent_address, &szAddr, 0);
cmret = CM_Get_DevNode_Registry_PropertyA(
parentDev, CM_DRP_ADDRESS, NULL, &data->parent_address, &szAddr, 0);
if (cmret != CR_SUCCESS) {
log_info("CM_Get_DevNode_Registry_PropertyA parent fail: %s", data->deviceInstancePath);
log_info(
"CM_Get_DevNode_Registry_PropertyA parent fail: %s",
data->deviceInstancePath);
return;
}
cmret = CM_Get_DevNode_Registry_PropertyA(parentDev, CM_DRP_DEVICEDESC, NULL, &data->parent_name, &szDesc, 0);
cmret = CM_Get_DevNode_Registry_PropertyA(
parentDev, CM_DRP_DEVICEDESC, NULL, &data->parent_name, &szDesc, 0);
if (cmret != CR_SUCCESS) {
log_info("CM_Get_DevNode_Registry_PropertyA parent fail: %s", data->deviceInstancePath);
log_info(
"CM_Get_DevNode_Registry_PropertyA parent fail: %s",
data->deviceInstancePath);
return;
}
@@ -705,7 +797,7 @@ void fill_cam_struct(struct CameraData* data, const char* devid)
data->setup = true;
}
void cam_hook_init(const char* devID1, const char* devID2)
void cam_hook_init(const char *devID1, const char *devID2)
{
// fill before applying hooks
fill_cam_struct(&camData[0], devID1);
@@ -713,19 +805,15 @@ void cam_hook_init(const char* devID1, const char* devID2)
if (camData[0].setup || camData[1].setup) {
hook_table_apply(
NULL,
"setupapi.dll",
iidxhook5_cfgmgr32_syms,
lengthof(iidxhook5_cfgmgr32_syms));
NULL,
"setupapi.dll",
iidxhook5_cfgmgr32_syms,
lengthof(iidxhook5_cfgmgr32_syms));
hook_table_apply(
NULL,
"Mf.dll",
iidxhook5_mf_syms,
lengthof(iidxhook5_mf_syms));
NULL, "Mf.dll", iidxhook5_mf_syms, lengthof(iidxhook5_mf_syms));
log_info("Inserted cam hooks");
} else {
log_info("No cams detected, not hooking");
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
#ifndef IIDXHOOK5_CAM_H
#define IIDXHOOK5_CAM_H
void cam_hook_init(const char* devID1, const char* devID2);
void cam_hook_init(const char *devID1, const char *devID2);
#endif
+38 -21
View File
@@ -12,50 +12,67 @@
#define IIDXHOOK8_CONFIG_CAM_DEFAULT_DEVICE_ID1_VALUE ""
#define IIDXHOOK8_CONFIG_CAM_DEFAULT_DEVICE_ID2_VALUE ""
void iidxhook8_config_cam_init(struct cconfig* config)
void iidxhook8_config_cam_init(struct cconfig *config)
{
cconfig_util_set_bool(config,
cconfig_util_set_bool(
config,
IIDXHOOK8_CONFIG_CAM_DISABLE_EMU_KEY,
IIDXHOOK8_CONFIG_CAM_DEFAULT_DISABLE_EMU_VALUE,
"Disables the camera emulation");
cconfig_util_set_str(config,
cconfig_util_set_str(
config,
IIDXHOOK8_CONFIG_CAM_DEVICE_ID1_KEY,
IIDXHOOK8_CONFIG_CAM_DEFAULT_DEVICE_ID1_VALUE,
"Override camera device ID 1 detection (copy from device manager, do "
"not escape)");
"Override camera device ID 1 detection (copy from device manager, "
"do not escape)");
cconfig_util_set_str(config,
cconfig_util_set_str(
config,
IIDXHOOK8_CONFIG_CAM_DEVICE_ID2_KEY,
IIDXHOOK8_CONFIG_CAM_DEFAULT_DEVICE_ID2_VALUE,
"Override camera device ID 2 detection (copy from device manager, do "
"not escape)");
"Override camera device ID 2 detection (copy from device manager, "
"do not escape)");
}
void iidxhook8_config_cam_get(struct iidxhook8_config_cam* config_cam,
struct cconfig* config)
void iidxhook8_config_cam_get(
struct iidxhook8_config_cam *config_cam, struct cconfig *config)
{
if (!cconfig_util_get_bool(config, IIDXHOOK8_CONFIG_CAM_DISABLE_EMU_KEY,
if (!cconfig_util_get_bool(
config,
IIDXHOOK8_CONFIG_CAM_DISABLE_EMU_KEY,
&config_cam->disable_emu,
IIDXHOOK8_CONFIG_CAM_DEFAULT_DISABLE_EMU_VALUE)) {
log_warning("Invalid value for key '%s' specified, fallback "
"to default '%d'", IIDXHOOK8_CONFIG_CAM_DISABLE_EMU_KEY,
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
IIDXHOOK8_CONFIG_CAM_DISABLE_EMU_KEY,
IIDXHOOK8_CONFIG_CAM_DEFAULT_DISABLE_EMU_VALUE);
}
if (!cconfig_util_get_str(config, IIDXHOOK8_CONFIG_CAM_DEVICE_ID1_KEY,
config_cam->device_id1, sizeof(config_cam->device_id1) - 1,
if (!cconfig_util_get_str(
config,
IIDXHOOK8_CONFIG_CAM_DEVICE_ID1_KEY,
config_cam->device_id1,
sizeof(config_cam->device_id1) - 1,
IIDXHOOK8_CONFIG_CAM_DEFAULT_DEVICE_ID1_VALUE)) {
log_warning("Invalid value for key '%s' specified, fallback "
"to default '%s'", IIDXHOOK8_CONFIG_CAM_DEVICE_ID1_KEY,
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%s'",
IIDXHOOK8_CONFIG_CAM_DEVICE_ID1_KEY,
IIDXHOOK8_CONFIG_CAM_DEFAULT_DEVICE_ID1_VALUE);
}
if (!cconfig_util_get_str(config, IIDXHOOK8_CONFIG_CAM_DEVICE_ID2_KEY,
config_cam->device_id2, sizeof(config_cam->device_id2) - 1,
if (!cconfig_util_get_str(
config,
IIDXHOOK8_CONFIG_CAM_DEVICE_ID2_KEY,
config_cam->device_id2,
sizeof(config_cam->device_id2) - 1,
IIDXHOOK8_CONFIG_CAM_DEFAULT_DEVICE_ID2_VALUE)) {
log_warning("Invalid value for key '%s' specified, fallback "
"to default '%s'", IIDXHOOK8_CONFIG_CAM_DEVICE_ID2_KEY,
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%s'",
IIDXHOOK8_CONFIG_CAM_DEVICE_ID2_KEY,
IIDXHOOK8_CONFIG_CAM_DEFAULT_DEVICE_ID2_VALUE);
}
}
+3 -3
View File
@@ -11,9 +11,9 @@ struct iidxhook8_config_cam {
char device_id2[MAX_PATH];
};
void iidxhook8_config_cam_init(struct cconfig* config);
void iidxhook8_config_cam_init(struct cconfig *config);
void iidxhook8_config_cam_get(struct iidxhook8_config_cam* config_cam,
struct cconfig* config);
void iidxhook8_config_cam_get(
struct iidxhook8_config_cam *config_cam, struct cconfig *config);
#endif
+32 -18
View File
@@ -4,60 +4,74 @@
#include "util/log.h"
#define IIDXHOOK8_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY "io.disable_card_reader_emu"
#define IIDXHOOK8_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY \
"io.disable_card_reader_emu"
#define IIDXHOOK8_CONFIG_IO_DISABLE_BIO2_EMU_KEY "io.disable_bio2_emu"
#define IIDXHOOK8_CONFIG_IO_DISABLE_POLL_LIMITER_KEY "io.disable_poll_limiter"
#define IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_CARD_READER_EMU_VALUE false
#define IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_BIO2_EMU_VALUE false
#define IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_BIO2_EMU_VALUE false
#define IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_POLL_LIMITER_VALUE false
void iidxhook8_config_io_init(struct cconfig* config)
void iidxhook8_config_io_init(struct cconfig *config)
{
cconfig_util_set_bool(config,
cconfig_util_set_bool(
config,
IIDXHOOK8_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY,
IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_CARD_READER_EMU_VALUE,
"Disable card reader emulation and enable usage of real card reader "
"Disable card reader emulation and enable usage of real card "
"reader "
"hardware on COM0 (for games supporting slotted readers)");
cconfig_util_set_bool(config,
cconfig_util_set_bool(
config,
IIDXHOOK8_CONFIG_IO_DISABLE_BIO2_EMU_KEY,
IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_BIO2_EMU_VALUE,
"Disable BIO2 emulation and enable usage of real BIO2 hardware");
cconfig_util_set_bool(config,
cconfig_util_set_bool(
config,
IIDXHOOK8_CONFIG_IO_DISABLE_POLL_LIMITER_KEY,
IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_POLL_LIMITER_VALUE,
"Disables the poll limiter, warning very high CPU usage may arise");
}
void iidxhook8_config_io_get(struct iidxhook8_config_io* config_io,
struct cconfig* config)
void iidxhook8_config_io_get(
struct iidxhook8_config_io *config_io, struct cconfig *config)
{
if (!cconfig_util_get_bool(config,
if (!cconfig_util_get_bool(
config,
IIDXHOOK8_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY,
&config_io->disable_card_reader_emu,
IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_CARD_READER_EMU_VALUE)) {
log_warning("Invalid value for key '%s' specified, fallback "
"to default '%d'", IIDXHOOK8_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY,
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
IIDXHOOK8_CONFIG_IO_DISABLE_CARD_READER_EMU_KEY,
IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_CARD_READER_EMU_VALUE);
}
if (!cconfig_util_get_bool(config,
if (!cconfig_util_get_bool(
config,
IIDXHOOK8_CONFIG_IO_DISABLE_BIO2_EMU_KEY,
&config_io->disable_bio2_emu,
IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_BIO2_EMU_VALUE)) {
log_warning("Invalid value for key '%s' specified, fallback "
"to default '%d'", IIDXHOOK8_CONFIG_IO_DISABLE_BIO2_EMU_KEY,
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
IIDXHOOK8_CONFIG_IO_DISABLE_BIO2_EMU_KEY,
IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_BIO2_EMU_VALUE);
}
if (!cconfig_util_get_bool(config,
if (!cconfig_util_get_bool(
config,
IIDXHOOK8_CONFIG_IO_DISABLE_POLL_LIMITER_KEY,
&config_io->disable_poll_limiter,
IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_POLL_LIMITER_VALUE)) {
log_warning("Invalid value for key '%s' specified, fallback "
"to default '%d'", IIDXHOOK8_CONFIG_IO_DISABLE_POLL_LIMITER_KEY,
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
IIDXHOOK8_CONFIG_IO_DISABLE_POLL_LIMITER_KEY,
IIDXHOOK8_CONFIG_IO_DEFAULT_DISABLE_POLL_LIMITER_VALUE);
}
}
+3 -3
View File
@@ -11,9 +11,9 @@ struct iidxhook8_config_io {
bool disable_poll_limiter;
};
void iidxhook8_config_io_init(struct cconfig* config);
void iidxhook8_config_io_init(struct cconfig *config);
void iidxhook8_config_io_get(struct iidxhook8_config_io* config_io,
struct cconfig* config);
void iidxhook8_config_io_get(
struct iidxhook8_config_io *config_io, struct cconfig *config);
#endif
+21 -19
View File
@@ -1,8 +1,8 @@
#include <windows.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "bemanitools/eamio.h"
@@ -29,7 +29,6 @@
#include "iidxhook8/cam.h"
#include "iidxhook8/config-cam.h"
#include "iidxhook8/config-io.h"
#include "iidxhook8/cam.h"
#include "imports/avs.h"
@@ -37,7 +36,7 @@
#include "util/str.h"
#include "util/thread.h"
#define IIDXHOOK8_INFO_HEADER \
#define IIDXHOOK8_INFO_HEADER \
"iidxhook for Cannon Ballers" \
", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) "\n"
#define IIDXHOOK8_CMD_USAGE \
@@ -52,7 +51,8 @@ static const hook_d3d9_irp_handler_t iidxhook_d3d9_handlers[] = {
iidxhook_util_d3d9_irp_handler,
};
static void iidxhook8_setup_d3d9_hooks(const struct iidxhook_config_gfx* config_gfx)
static void
iidxhook8_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx)
{
struct iidxhook_util_d3d9_config d3d9_config;
@@ -84,8 +84,8 @@ static struct bio2emu_port bio2_emu = {
static bool my_dll_entry_init(char *sidcode, struct property_node *param)
{
struct cconfig* config;
struct cconfig *config;
struct iidxhook_config_gfx config_gfx;
struct iidxhook8_config_cam config_cam;
@@ -102,7 +102,10 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
iidxhook8_config_cam_init(config);
iidxhook8_config_io_init(config);
if (!cconfig_hook_config_init(config, IIDXHOOK8_INFO_HEADER "\n" IIDXHOOK8_CMD_USAGE, CCONFIG_CMD_USAGE_OUT_DBG)) {
if (!cconfig_hook_config_init(
config,
IIDXHOOK8_INFO_HEADER "\n" IIDXHOOK8_CMD_USAGE,
CCONFIG_CMD_USAGE_OUT_DBG)) {
cconfig_finit(config);
log_server_fini();
exit(EXIT_FAILURE);
@@ -122,10 +125,11 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
/* Start up IIDXIO.DLL */
if (!iidxhook8_config_io.disable_bio2_emu) {
log_info("Starting IIDX IO backend");
iidx_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning,
log_impl_fatal);
iidx_io_set_loggers(
log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
if (!iidx_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy)) {
if (!iidx_io_init(
avs_thread_create, avs_thread_join, avs_thread_destroy)) {
log_fatal("Initializing IIDX IO backend failed");
}
}
@@ -133,15 +137,17 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param)
/* Start up EAMIO.DLL */
if (!iidxhook8_config_io.disable_card_reader_emu) {
log_misc("Initializing card reader backend");
eam_io_set_loggers(log_impl_misc, log_impl_info, log_impl_warning,
log_impl_fatal);
eam_io_set_loggers(
log_impl_misc, log_impl_info, log_impl_warning, log_impl_fatal);
if (!eam_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy)) {
if (!eam_io_init(
avs_thread_create, avs_thread_join, avs_thread_destroy)) {
log_fatal("Initializing card reader backend failed");
}
}
/* iohooks are okay, even if emu is diabled since the fake handlers won't be used */
/* iohooks are okay, even if emu is diabled since the fake handlers won't be
* used */
/* Set up IO emulation hooks _after_ IO API setup to allow
API implementations with real IO devices */
iohook_init(iidxhook_handlers, lengthof(iidxhook_handlers));
@@ -200,10 +206,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
}
log_to_external(
log_body_misc,
log_body_info,
log_body_warning,
log_body_fatal);
log_body_misc, log_body_info, log_body_warning, log_body_fatal);
app_hook_init(my_dll_entry_init, my_dll_entry_main);
@@ -213,4 +216,3 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
end:
return TRUE;
}