From 031836ef0ef446979d16bc98404501d8a2971a62 Mon Sep 17 00:00:00 2001 From: icex2 Date: Tue, 21 Mar 2023 23:37:01 +0100 Subject: [PATCH] chore: Apply code formatting on entire codebase for consistent style --- src/main/acio/panb.h | 5 +- src/main/aciodrv-proc/panb.c | 47 +- src/main/aciodrv-proc/panb.h | 17 +- src/main/aciodrv/device.c | 91 ++-- src/main/aciodrv/device.h | 38 +- src/main/aciodrv/h44b.c | 8 +- src/main/aciodrv/h44b.h | 2 +- src/main/aciodrv/icca.c | 16 +- src/main/aciodrv/icca.h | 14 +- src/main/aciodrv/kfca.c | 23 +- src/main/aciodrv/panb.c | 33 +- src/main/aciodrv/panb.h | 55 ++- src/main/aciodrv/port.c | 3 +- src/main/aciodrv/port.h | 2 +- src/main/aciodrv/rvol.c | 11 +- src/main/acioemu/icca.c | 9 +- src/main/aciomgr/manager.c | 1 - src/main/aciotest/bi2a-sdvx.c | 1 - src/main/aciotest/icca.c | 5 +- src/main/aciotest/main.c | 4 +- src/main/aciotest/panb.c | 28 +- src/main/aciotest/panb.h | 6 +- src/main/aciotest/rvol.c | 3 +- src/main/asio/asio-reghook.c | 6 +- src/main/asio/config-asio.c | 3 +- src/main/bemanitools/ddrio.h | 1 - src/main/bemanitools/iidxio.h | 3 +- src/main/bemanitools/jbio.h | 3 +- src/main/bemanitools/sdvxio.h | 4 +- src/main/bio2drv/bi2a-iidx.c | 12 +- src/main/bio2drv/bi2a-iidx.h | 4 +- src/main/bio2drv/bi2a-sdvx.c | 14 +- src/main/bio2drv/bi2a-sdvx.h | 4 +- src/main/bio2drv/detect.c | 6 +- src/main/bio2emu-iidx/bi2a.c | 3 +- src/main/config/lights.c | 4 +- src/main/config/main.c | 4 +- src/main/config/spinner.c | 2 +- src/main/d3d9exhook/config-gfx.c | 18 +- src/main/d3d9exhook/d3d9ex.c | 37 +- src/main/ddrhook-util/_com4.c | 38 +- src/main/ddrhook-util/dinput.c | 4 +- src/main/ddrhook-util/gfx.c | 9 +- src/main/ddrhook-util/p3io.c | 10 +- src/main/ddrhook-util/usbmem.c | 176 +++++-- src/main/ddrhook1/avs-boot.c | 11 +- src/main/ddrhook1/config-ddrhook1.c | 3 +- src/main/ddrhook1/config-security.c | 3 +- src/main/ddrhook1/dllmain.c | 15 +- src/main/ddrhook1/filesystem.c | 124 ++--- src/main/ddrhook2/dllmain.c | 7 +- src/main/ddrhook2/master.c | 1 - src/main/ddrio-smx/ddrio.c | 45 +- src/main/eamio-icca/eamio-icca.c | 91 ++-- src/main/eamio/eam-impl.c | 2 +- src/main/ezusb-emu/conf.h | 4 +- src/main/ezusb-emu/desc.c | 9 +- src/main/ezusb-emu/node-security-plug.c | 11 +- src/main/ezusb-emu/nodes.c | 2 +- src/main/ezusb-iidx-emu/msg.c | 2 +- src/main/ezusb-iidx/ezusb-iidx.c | 2 +- src/main/ezusb-iidx/msg.h | 7 +- src/main/ezusb2-emu/conf.h | 4 +- src/main/ezusb2-emu/desc.c | 9 +- src/main/ezusb2-popn-emu/msg.c | 22 +- src/main/ezusb2-popn-shim/dllmain.c | 7 +- src/main/ezusb2-popn-shim/proxy.c | 383 +++++++++------ src/main/ezusb2-popn/msg.h | 4 +- src/main/ezusb2/cyioctl.h | 11 +- src/main/geninput/hid-report-out.c | 8 +- src/main/geninput/mapper.c | 8 +- src/main/hook/args.c | 11 +- src/main/hook/com-proxy.c | 81 ++-- src/main/hook/com-proxy.h | 5 +- src/main/hook/d3d9.c | 49 +- src/main/hook/hr.c | 33 +- src/main/hook/iobuf.c | 12 +- src/main/hook/iohook.c | 491 ++++++++++---------- src/main/hook/iohook.h | 4 +- src/main/hook/pe.c | 43 +- src/main/hook/pe.h | 7 +- src/main/hook/process.c | 35 +- src/main/hook/process.h | 7 +- src/main/hook/table.c | 62 +-- src/main/hook/table.h | 16 +- src/main/hooklib/memfile.c | 2 +- src/main/iidx-bio2-exit-hook/main.c | 88 ++-- src/main/iidxhook-util/acio.c | 4 +- src/main/iidxhook-util/acio.h | 1 - src/main/iidxhook-util/config-gfx.c | 2 +- src/main/iidxhook-util/config-io.c | 3 +- src/main/iidxhook-util/config-misc.c | 3 +- src/main/iidxhook-util/d3d9.c | 56 ++- src/main/iidxhook-util/settings.c | 13 +- src/main/iidxhook-util/settings.h | 6 +- src/main/iidxhook-util/vertex-shader.h | 100 ++-- src/main/iidxhook4-cn/dllmain.c | 19 +- src/main/iidxhook4-cn/path.c | 15 +- src/main/iidxhook4/dllmain.c | 13 +- src/main/iidxhook5-cn/dllmain.c | 14 +- src/main/iidxhook5-cn/path.c | 15 +- src/main/iidxhook5/dllmain.c | 9 +- src/main/iidxhook6/dllmain.c | 6 +- src/main/iidxhook7/dllmain.c | 6 +- src/main/iidxhook8/dllmain.c | 4 +- src/main/iidxhook9/dllmain.c | 9 +- src/main/iidxio-bio2/iidxio.c | 33 +- src/main/iidxio-ezusb/iidxio.c | 12 +- src/main/iidxiotest/main.c | 10 +- src/main/inject/debugger.c | 158 ++++--- src/main/inject/debugger.h | 5 +- src/main/inject/logger.c | 14 +- src/main/inject/logger.h | 8 +- src/main/inject/main.c | 5 +- src/main/jbhook-util-p3io/gfx.c | 50 +- src/main/jbhook-util-p3io/mixer.c | 80 ++-- src/main/jbhook-util-p3io/p3io.c | 7 +- src/main/jbhook-util/acio.c | 3 +- src/main/jbhook-util/eamuse.c | 26 +- src/main/jbhook-util/locale.c | 16 +- src/main/jbhook-util/p4io.c | 6 +- src/main/jbhook1/config-security.c | 3 +- src/main/jbhook1/dllmain.c | 2 +- src/main/jbhook2/dllmain.c | 22 +- src/main/jbhook3/dllmain.c | 8 +- src/main/jbhook3/gfx.c | 41 +- src/main/jbhook3/options.c | 2 +- src/main/jbio-p4io/h44b.c | 20 +- src/main/jbio-p4io/jbio.c | 18 +- src/main/jbio/jbio.c | 2 +- src/main/jbiotest/main.c | 14 +- src/main/launcher/main.c | 7 +- src/main/launcher/module.c | 60 ++- src/main/launcher/module.h | 5 +- src/main/launcher/options.c | 5 +- src/main/mempatch-hook/main.c | 11 +- src/main/p3io/ioctl.h | 4 +- src/main/p4io/cmd.h | 1 - src/main/p4io/guid.h | 3 +- src/main/p4iodrv/device.c | 71 ++- src/main/p4iodrv/device.h | 3 +- src/main/p4iodrv/usb.c | 104 +++-- src/main/p4iodrv/usb.h | 3 +- src/main/p4ioemu/device.c | 2 +- src/main/popnhook-util/acio.c | 11 +- src/main/popnhook-util/mixer.c | 79 ++-- src/main/popnhook1/config-gfx.c | 1 - src/main/popnhook1/d3d9.c | 38 +- src/main/popnhook1/d3d9.h | 4 +- src/main/popnhook1/dllmain.c | 16 +- src/main/popnhook1/filesystem.c | 27 +- src/main/popnio/popnio.c | 6 +- src/main/sdvxhook/lcd.c | 2 +- src/main/sdvxhook2-cn/dllmain.c | 2 +- src/main/sdvxhook2-cn/unis-version.c | 2 +- src/main/sdvxhook2-cn/unis-version.h | 6 +- src/main/sdvxhook2/config-io.c | 9 +- src/main/sdvxhook2/nvapi.c | 6 +- src/main/sdvxio-bio2/sdvxio.c | 6 +- src/main/sdvxio-kfca/config-kfca.c | 9 +- src/main/sdvxio-kfca/sdvxio.c | 16 +- src/main/sdvxio/sdvxio.c | 3 +- src/main/security/id.c | 18 +- src/main/security/rp2.c | 35 +- src/main/security/rp3.c | 2 +- src/main/util/crypto.c | 2 +- src/main/util/iobuf.c | 2 +- src/main/util/log.c | 3 +- src/main/util/math.c | 6 +- src/main/util/os.c | 18 +- src/main/util/os.h | 4 +- src/main/util/proc.c | 6 +- src/main/util/signal.c | 22 +- src/main/util/signal.h | 14 +- src/main/util/thread.c | 6 +- src/main/vigem-iidxio/cab-16seg-sequencer.c | 19 +- src/main/vigem-iidxio/cab-16seg-sequencer.h | 5 +- src/main/vigem-iidxio/cab-light-sequencer.c | 27 +- src/main/vigem-iidxio/cab-light-sequencer.h | 12 +- src/main/vigem-iidxio/config.c | 52 ++- src/main/vigem-iidxio/config.h | 2 +- src/main/vigem-iidxio/main.c | 146 +++--- src/main/vigem-sdvxio/main.c | 28 +- src/main/vigemstub/helper.c | 3 +- src/test/security/security-rp2-test.c | 2 +- src/test/security/security-rp3-test.c | 78 ++-- 186 files changed, 2446 insertions(+), 1979 deletions(-) diff --git a/src/main/acio/panb.h b/src/main/acio/panb.h index 0ce6af0..977bd50 100644 --- a/src/main/acio/panb.h +++ b/src/main/acio/panb.h @@ -8,8 +8,8 @@ #define AC_IO_CMD_PANB_START_AUTO_INPUT 0x0115 #define AC_IO_PANB_NUM_NODES 4 -#define AC_IO_PANB_MAX_KEYS (7*AC_IO_PANB_NUM_NODES) -#define AC_IO_PANB_MAX_KEYPAIRS (AC_IO_PANB_MAX_KEYS/2) +#define AC_IO_PANB_MAX_KEYS (7 * AC_IO_PANB_NUM_NODES) +#define AC_IO_PANB_MAX_KEYPAIRS (AC_IO_PANB_MAX_KEYS / 2) struct ac_io_panb_keypair { uint8_t key2 : 4; @@ -38,5 +38,4 @@ struct ac_io_panb_poll_out { }; #pragma pack(pop) - #endif diff --git a/src/main/aciodrv-proc/panb.c b/src/main/aciodrv-proc/panb.c index ed1c172..c054e21 100644 --- a/src/main/aciodrv-proc/panb.c +++ b/src/main/aciodrv-proc/panb.c @@ -5,8 +5,8 @@ #include "aciodrv/device.h" #include "aciodrv/panb.h" -#include "util/thread.h" #include "util/log.h" +#include "util/thread.h" static int auto_poll_proc(void *auto_poll_param); static int auto_poll_threadid; @@ -17,59 +17,60 @@ static struct ac_io_panb_keypair _keypair[AC_IO_PANB_MAX_KEYPAIRS]; static CRITICAL_SECTION auto_poll_stop_lock; static bool auto_poll_stop; -static int auto_poll_proc(void * param) -{ - struct aciodrv_device_ctx * device = (struct aciodrv_device_ctx *) param; +static int auto_poll_proc(void *param) +{ + struct aciodrv_device_ctx *device = (struct aciodrv_device_ctx *) param; struct ac_io_panb_poll_in poll_in; bool stop; - + do { aciodrv_panb_recv_poll(device, &poll_in); - + EnterCriticalSection(&keypair_lock); memcpy(_keypair, poll_in.keypair, AC_IO_PANB_MAX_KEYPAIRS); LeaveCriticalSection(&keypair_lock); EnterCriticalSection(&auto_poll_stop_lock); - stop = auto_poll_stop; + stop = auto_poll_stop; LeaveCriticalSection(&auto_poll_stop_lock); } while (!stop); - + return 0; } bool aciodrv_proc_panb_init(struct aciodrv_device_ctx *device) { log_assert(device); - + if (!aciodrv_panb_start_auto_input(device, 0, AC_IO_PANB_NUM_NODES)) { return false; } - + auto_poll_stop = false; InitializeCriticalSection(&keypair_lock); InitializeCriticalSection(&auto_poll_stop_lock); - auto_poll_threadid = thread_create(auto_poll_proc, (void *)device, 0x4000, 0); - + auto_poll_threadid = + thread_create(auto_poll_proc, (void *) device, 0x4000, 0); + return true; } bool aciodrv_proc_panb_get_state(uint8_t *button_state) { struct ac_io_panb_keypair keypair[AC_IO_PANB_MAX_KEYPAIRS]; - + EnterCriticalSection(&keypair_lock); - memcpy(keypair, _keypair, AC_IO_PANB_MAX_KEYPAIRS); + memcpy(keypair, _keypair, AC_IO_PANB_MAX_KEYPAIRS); LeaveCriticalSection(&keypair_lock); /* splice the keypairs into separate button values */ - for (int i=0; ifd, send_buf, send_buf_pos) != send_buf_pos) { - log_warning("[%p] Sending data with length %d failed", device->fd, send_buf_pos); + if (aciodrv_port_write(device->fd, send_buf, send_buf_pos) != + send_buf_pos) { + log_warning( + "[%p] Sending data with length %d failed", + device->fd, + send_buf_pos); return false; } return true; } -static int aciodrv_device_receive(struct aciodrv_device_ctx *device, uint8_t *buffer, int max_resp_size) +static int aciodrv_device_receive( + struct aciodrv_device_ctx *device, uint8_t *buffer, int max_resp_size) { uint8_t recv_buf[512]; int recv_size = 0; @@ -161,7 +170,6 @@ static int aciodrv_device_receive(struct aciodrv_device_ctx *device, uint8_t *bu read = aciodrv_port_read(device->fd, recv_buf, 1); } while (recv_buf[0] == AC_IO_SOF); - if (read > 0) { /* recv_buf[0] is already the first byte of the message. now read until nothing's left */ @@ -189,8 +197,8 @@ static int aciodrv_device_receive(struct aciodrv_device_ctx *device, uint8_t *bu /* next byte is our real data overwrite escape byte */ do { - read = aciodrv_port_read( - device->fd, recv_buf + recv_size, 1); + read = + aciodrv_port_read(device->fd, recv_buf + recv_size, 1); } while (read == 0); if (read < 0) { @@ -204,7 +212,8 @@ static int aciodrv_device_receive(struct aciodrv_device_ctx *device, uint8_t *bu if (recv_size > offsetof(struct ac_io_message, cmd.nbytes)) { // header + data + checksum - expected_size = offsetof(struct ac_io_message, cmd.raw) + ((struct ac_io_message*)recv_buf)->cmd.nbytes + 1; + expected_size = offsetof(struct ac_io_message, cmd.raw) + + ((struct ac_io_message *) recv_buf)->cmd.nbytes + 1; } } @@ -215,7 +224,11 @@ static int aciodrv_device_receive(struct aciodrv_device_ctx *device, uint8_t *bu /* recv_size - 1: omit checksum for checksum calc */ if ((recv_size - 1) > max_resp_size) { - log_warning("[%p] Expected %d got %d", device->fd, max_resp_size - 6, recv_buf[4]); + log_warning( + "[%p] Expected %d got %d", + device->fd, + max_resp_size - 6, + recv_buf[4]); return -1; } for (int i = 0; i < recv_size - 1; i++) { @@ -254,9 +267,7 @@ static uint8_t aciodrv_device_enum_nodes(struct aciodrv_device_ctx *device) msg.cmd.count = 0; if (!aciodrv_send_and_recv( - device, - &msg, - offsetof(struct ac_io_message, cmd.raw) + 1)) { + device, &msg, offsetof(struct ac_io_message, cmd.raw) + 1)) { log_warning("Enumerating nodes failed"); return 0; } @@ -266,7 +277,10 @@ static uint8_t aciodrv_device_enum_nodes(struct aciodrv_device_ctx *device) return msg.cmd.count; } -static bool aciodrv_device_get_version(struct aciodrv_device_ctx *device, uint8_t node_id, struct aciodrv_device_node_version *version) +static bool aciodrv_device_get_version( + struct aciodrv_device_ctx *device, + uint8_t node_id, + struct aciodrv_device_node_version *version) { struct ac_io_message msg; @@ -299,7 +313,10 @@ static bool aciodrv_device_get_version(struct aciodrv_device_ctx *device, uint8_ msg.cmd.version.date, msg.cmd.version.time); - memcpy(version->product, msg.cmd.version.product_code, ACIO_NODE_PRODUCT_CODE_LEN); + memcpy( + version->product, + msg.cmd.version.product_code, + ACIO_NODE_PRODUCT_CODE_LEN); version->type = ac_io_u32(msg.cmd.version.type); version->major = msg.cmd.version.major; version->minor = msg.cmd.version.minor; @@ -308,7 +325,8 @@ static bool aciodrv_device_get_version(struct aciodrv_device_ctx *device, uint8_ return true; } -static bool aciodrv_device_start_node(struct aciodrv_device_ctx *device, uint8_t node_id) +static bool +aciodrv_device_start_node(struct aciodrv_device_ctx *device, uint8_t node_id) { struct ac_io_message msg; @@ -317,9 +335,7 @@ static bool aciodrv_device_start_node(struct aciodrv_device_ctx *device, uint8_t msg.cmd.nbytes = 0; if (!aciodrv_send_and_recv( - device, - &msg, - offsetof(struct ac_io_message, cmd.raw) + 1)) { + device, &msg, offsetof(struct ac_io_message, cmd.raw) + 1)) { log_warning("Starting node %d failed", node_id); return false; } @@ -334,7 +350,8 @@ struct aciodrv_device_ctx *aciodrv_device_open(const char *port_path, int baud) return aciodrv_device_open_path(port_path, baud); } -struct aciodrv_device_ctx *aciodrv_device_open_path(const char *port_path, int baud) +struct aciodrv_device_ctx * +aciodrv_device_open_path(const char *port_path, int baud) { HANDLE port = aciodrv_port_open(port_path, baud); @@ -342,7 +359,8 @@ struct aciodrv_device_ctx *aciodrv_device_open_path(const char *port_path, int b return NULL; } - struct aciodrv_device_ctx *device = xmalloc(sizeof(struct aciodrv_device_ctx)); + struct aciodrv_device_ctx *device = + xmalloc(sizeof(struct aciodrv_device_ctx)); memset(device, 0, sizeof(struct aciodrv_device_ctx)); device->fd = port; @@ -384,16 +402,23 @@ uint8_t aciodrv_device_get_node_count(struct aciodrv_device_ctx *device) return device->node_count; } -bool aciodrv_device_get_node_product_ident(struct aciodrv_device_ctx *device, uint8_t node_id, char product[ACIO_NODE_PRODUCT_CODE_LEN]) +bool aciodrv_device_get_node_product_ident( + struct aciodrv_device_ctx *device, + uint8_t node_id, + char product[ACIO_NODE_PRODUCT_CODE_LEN]) { if (device->node_count == 0 || node_id > device->node_count) { return false; } - memcpy(product, device->node_versions[node_id].product, ACIO_NODE_PRODUCT_CODE_LEN); + memcpy( + product, + device->node_versions[node_id].product, + ACIO_NODE_PRODUCT_CODE_LEN); return true; } -uint32_t aciodrv_device_get_node_product_type(struct aciodrv_device_ctx *device, uint8_t node_id) +uint32_t aciodrv_device_get_node_product_type( + struct aciodrv_device_ctx *device, uint8_t node_id) { if (device->node_count == 0 || node_id > device->node_count) { return 0; @@ -402,7 +427,9 @@ uint32_t aciodrv_device_get_node_product_type(struct aciodrv_device_ctx *device, return device->node_versions[node_id].type; } -const struct aciodrv_device_node_version *aciodrv_device_get_node_product_version(struct aciodrv_device_ctx *device, uint8_t node_id) +const struct aciodrv_device_node_version * +aciodrv_device_get_node_product_version( + struct aciodrv_device_ctx *device, uint8_t node_id) { if (device->node_count == 0 || node_id > device->node_count) { return NULL; @@ -430,7 +457,10 @@ bool aciodrv_send(struct aciodrv_device_ctx *device, struct ac_io_message *msg) return true; } -bool aciodrv_recv(struct aciodrv_device_ctx *device, struct ac_io_message *msg, int max_resp_size) +bool aciodrv_recv( + struct aciodrv_device_ctx *device, + struct ac_io_message *msg, + int max_resp_size) { #ifdef AC_IO_MSG_LOG log_info("[%p] Beginning recv: (%d b)", device->fd, max_resp_size); @@ -441,7 +471,10 @@ bool aciodrv_recv(struct aciodrv_device_ctx *device, struct ac_io_message *msg, return true; } -bool aciodrv_send_and_recv(struct aciodrv_device_ctx *device, struct ac_io_message *msg, int max_resp_size) +bool aciodrv_send_and_recv( + struct aciodrv_device_ctx *device, + struct ac_io_message *msg, + int max_resp_size) { if (!aciodrv_send(device, msg)) { return false; diff --git a/src/main/aciodrv/device.h b/src/main/aciodrv/device.h index 58cbf41..8703835 100644 --- a/src/main/aciodrv/device.h +++ b/src/main/aciodrv/device.h @@ -28,11 +28,13 @@ struct aciodrv_device_node_version { */ struct aciodrv_device_ctx *aciodrv_device_open(const char *port_path, int baud) #ifdef __GNUC__ -__attribute__((deprecated("Use aciomgr instead if device is shareable, else aciodrv_device_open_path"))) + __attribute__((deprecated("Use aciomgr instead if device is shareable, " + "else aciodrv_device_open_path"))) #endif -; + ; -struct aciodrv_device_ctx *aciodrv_device_open_path(const char *port_path, int baud); +struct aciodrv_device_ctx * +aciodrv_device_open_path(const char *port_path, int baud); /** * Get the node count on the opened device. @@ -51,7 +53,10 @@ uint8_t aciodrv_device_get_node_count(struct aciodrv_device_ctx *device); * @return True on success, false on error. If True the variable product * contains the identifier of the queried node. */ -bool aciodrv_device_get_node_product_ident(struct aciodrv_device_ctx *device, uint8_t node_id, char product[ACIO_NODE_PRODUCT_CODE_LEN]); +bool aciodrv_device_get_node_product_ident( + struct aciodrv_device_ctx *device, + uint8_t node_id, + char product[ACIO_NODE_PRODUCT_CODE_LEN]); /** * Get the product identifier of an enumerated node. @@ -60,7 +65,8 @@ bool aciodrv_device_get_node_product_ident(struct aciodrv_device_ctx *device, ui * @param node_id Id of the node. Needs to be in range of the total node count. * @return product type ID on success, or 0 on failure */ -uint32_t aciodrv_device_get_node_product_type(struct aciodrv_device_ctx *device, uint8_t node_id); +uint32_t aciodrv_device_get_node_product_type( + struct aciodrv_device_ctx *device, uint8_t node_id); /** * Get the product version of an enumerated node. @@ -69,7 +75,9 @@ uint32_t aciodrv_device_get_node_product_type(struct aciodrv_device_ctx *device, * @param node_id Id of the node. Needs to be in range of the total node count. * @return Pointer to the version struct */ -const struct aciodrv_device_node_version *aciodrv_device_get_node_product_version(struct aciodrv_device_ctx *device, uint8_t node_id); +const struct aciodrv_device_node_version * +aciodrv_device_get_node_product_version( + struct aciodrv_device_ctx *device, uint8_t node_id); /** * Send a message to the ACIO bus and receive an answer. @@ -82,7 +90,10 @@ const struct aciodrv_device_node_version *aciodrv_device_get_node_product_versio * @param resp_size Size of the expecting response. * @return True on success, false on error. */ -bool aciodrv_send_and_recv(struct aciodrv_device_ctx *device, struct ac_io_message *msg, int max_resp_size); +bool aciodrv_send_and_recv( + struct aciodrv_device_ctx *device, + struct ac_io_message *msg, + int max_resp_size); /** * Send a message to the ACIO bus. @@ -90,7 +101,8 @@ bool aciodrv_send_and_recv(struct aciodrv_device_ctx *device, struct ac_io_messa * @param device Context of opened device * @param msg Msg to send to the bus. * @return True on success, false on error. - * @note Prefer the use of aciodrv_send_and_recv when possible. This is for commands which don't trigger a reply. + * @note Prefer the use of aciodrv_send_and_recv when possible. This is for + * commands which don't trigger a reply. */ bool aciodrv_send(struct aciodrv_device_ctx *device, struct ac_io_message *msg); @@ -101,9 +113,13 @@ bool aciodrv_send(struct aciodrv_device_ctx *device, struct ac_io_message *msg); * @param msg Msg to send to the bus. Make sure that the buffer * is big enough to receive the response. * @return True on success, false on error. - * @note Prefer the use of aciodrv_send_and_recv when possible. This is for unsollicited incoming messages. + * @note Prefer the use of aciodrv_send_and_recv when possible. This is for + * unsollicited incoming messages. */ -bool aciodrv_recv(struct aciodrv_device_ctx *device, struct ac_io_message *msg, int max_resp_size); +bool aciodrv_recv( + struct aciodrv_device_ctx *device, + struct ac_io_message *msg, + int max_resp_size); /** * Reset an opened device. @@ -115,7 +131,7 @@ bool aciodrv_device_reset(struct aciodrv_device_ctx *device); /** * Close the previously opened ACIO device. - * + * * @param device Context of opened device */ void aciodrv_device_close(struct aciodrv_device_ctx *device); diff --git a/src/main/aciodrv/h44b.c b/src/main/aciodrv/h44b.c index 3df7774..afbab42 100644 --- a/src/main/aciodrv/h44b.c +++ b/src/main/aciodrv/h44b.c @@ -9,9 +9,7 @@ #include "util/log.h" -bool aciodrv_h44b_init( - struct aciodrv_device_ctx *device, - uint8_t node_id) +bool aciodrv_h44b_init(struct aciodrv_device_ctx *device, uint8_t node_id) { // unlike input devices like KFCA, H44B has no watchdog or special init code // requirements - shared ACIO node initialisation is enough @@ -34,9 +32,7 @@ bool aciodrv_h44b_lights( msg.cmd.h44b_output = *lights; if (!aciodrv_send_and_recv( - device, - &msg, - offsetof(struct ac_io_message, cmd.raw) + 1)) { + device, &msg, offsetof(struct ac_io_message, cmd.raw) + 1)) { log_warning("Polling of node %d failed", node_id + 1); return false; } diff --git a/src/main/aciodrv/h44b.h b/src/main/aciodrv/h44b.h index 33879bd..63db077 100644 --- a/src/main/aciodrv/h44b.h +++ b/src/main/aciodrv/h44b.h @@ -1,8 +1,8 @@ #ifndef ACIODRV_H44B_H #define ACIODRV_H44B_H -#include "aciodrv/device.h" #include "acio/h44b.h" +#include "aciodrv/device.h" /** * Initialize an H44B node. diff --git a/src/main/aciodrv/icca.c b/src/main/aciodrv/icca.c index 459f551..ac56d0e 100644 --- a/src/main/aciodrv/icca.c +++ b/src/main/aciodrv/icca.c @@ -8,8 +8,7 @@ #include "util/log.h" static bool aciodrv_icca_queue_loop_start( - struct aciodrv_device_ctx *device, - uint8_t node_id) + struct aciodrv_device_ctx *device, uint8_t node_id) { struct ac_io_message msg; @@ -21,9 +20,7 @@ static bool aciodrv_icca_queue_loop_start( msg.cmd.status = 0; if (!aciodrv_send_and_recv( - device, - &msg, - offsetof(struct ac_io_message, cmd.raw) + 1)) { + device, &msg, offsetof(struct ac_io_message, cmd.raw) + 1)) { log_warning("Starting queue loop failed"); return false; } @@ -137,16 +134,14 @@ bool aciodrv_icca_read_card( return true; } -bool aciodrv_icca_is_slotted( - struct aciodrv_device_ctx *device, - uint8_t node_id) +bool aciodrv_icca_is_slotted(struct aciodrv_device_ctx *device, uint8_t node_id) { const struct aciodrv_device_node_version *version; version = aciodrv_device_get_node_product_version(device, node_id); // current heuristic is to check if version >= 1.5 if (version) { - if (version->major == 1) { + if (version->major == 1) { if (version->minor >= 5) { return false; } @@ -157,8 +152,7 @@ bool aciodrv_icca_is_slotted( } bool aciodrv_icca_poll_felica( - struct aciodrv_device_ctx *device, - uint8_t node_id) + struct aciodrv_device_ctx *device, uint8_t node_id) { struct ac_io_message msg; diff --git a/src/main/aciodrv/icca.h b/src/main/aciodrv/icca.h index 720babf..c8baf52 100644 --- a/src/main/aciodrv/icca.h +++ b/src/main/aciodrv/icca.h @@ -74,9 +74,9 @@ bool aciodrv_icca_read_card( /** * Uses some heruistics based on the product ident to determine if the detected * device is a slotted (true) or wavepass reader (false). - * + * * This function will also return false if the provided node_id is invalid. - * + * * @param device Context of opened device * @param node_id Id of the node to query (0 based). * @return True on slotted, false on wavepass. @@ -85,18 +85,17 @@ bool aciodrv_icca_read_card( * @see driver.h */ bool aciodrv_icca_is_slotted( - struct aciodrv_device_ctx *device, - uint8_t node_id); + struct aciodrv_device_ctx *device, uint8_t node_id); /** * Polls the felica chip on wavepass readers. This will cause the state of the * reader to be AC_IO_ICCA_STATUS_BUSY_NEW for a few polls, before returning * either: AC_IO_ICCA_STATUS_IDLE_NEW or AC_IO_ICCA_STATUS_GOT_UID. - * + * * The user should take care to call this every so often to actually get new * felica UIDs, instead of just old NFC idents. The game seems to do it every * 5 or so polls after the last AC_IO_ICCA_STATUS_BUSY_NEW poll. - * + * * @param device Context of opened device * @param node_id Id of the node to query (0 based). * @return True on success, false on error. @@ -105,7 +104,6 @@ bool aciodrv_icca_is_slotted( * @see driver.h */ bool aciodrv_icca_poll_felica( - struct aciodrv_device_ctx *device, - uint8_t node_id); + struct aciodrv_device_ctx *device, uint8_t node_id); #endif diff --git a/src/main/aciodrv/kfca.c b/src/main/aciodrv/kfca.c index 4b097c0..e21a0b8 100644 --- a/src/main/aciodrv/kfca.c +++ b/src/main/aciodrv/kfca.c @@ -7,9 +7,8 @@ #include "util/log.h" -static bool aciodrv_kfca_watchdog_start( - struct aciodrv_device_ctx *device, - uint8_t node_id) +static bool +aciodrv_kfca_watchdog_start(struct aciodrv_device_ctx *device, uint8_t node_id) { struct ac_io_message msg; @@ -25,11 +24,15 @@ static bool aciodrv_kfca_watchdog_start( if (!aciodrv_send_and_recv( device, &msg, offsetof(struct ac_io_message, cmd.raw) + 2)) { - log_warning("Starting watchdog failed"); return false; + log_warning("Starting watchdog failed"); + return false; } - log_warning("Started watchdog of node %d, sz: %d, status: %d", - node_id, msg.cmd.nbytes, msg.cmd.status); + log_warning( + "Started watchdog of node %d, sz: %d, status: %d", + node_id, + msg.cmd.nbytes, + msg.cmd.status); return true; } @@ -56,9 +59,7 @@ bool aciodrv_kfca_amp( msg.cmd.raw[3] = subwoofer; if (!aciodrv_send_and_recv( - device, - &msg, - offsetof(struct ac_io_message, cmd.raw) + 1)) { + device, &msg, offsetof(struct ac_io_message, cmd.raw) + 1)) { log_warning("Setting AMP failed"); return false; } @@ -68,9 +69,7 @@ bool aciodrv_kfca_amp( return true; } -bool aciodrv_kfca_init( - struct aciodrv_device_ctx *device, - uint8_t node_id) +bool aciodrv_kfca_init(struct aciodrv_device_ctx *device, uint8_t node_id) { log_assert(device); diff --git a/src/main/aciodrv/panb.c b/src/main/aciodrv/panb.c index b3123cc..1412e16 100644 --- a/src/main/aciodrv/panb.c +++ b/src/main/aciodrv/panb.c @@ -5,10 +5,11 @@ #include "aciodrv/device.h" #include "aciodrv/panb.h" -#include "util/thread.h" #include "util/log.h" +#include "util/thread.h" -bool aciodrv_panb_start_auto_input(struct aciodrv_device_ctx *device, uint8_t node_id, uint8_t node_count) +bool aciodrv_panb_start_auto_input( + struct aciodrv_device_ctx *device, uint8_t node_id, uint8_t node_count) { log_assert(device); struct ac_io_message msg; @@ -33,34 +34,40 @@ bool aciodrv_panb_start_auto_input(struct aciodrv_device_ctx *device, uint8_t no return true; } -bool aciodrv_panb_recv_poll(struct aciodrv_device_ctx *device, struct ac_io_panb_poll_in *poll_in) +bool aciodrv_panb_recv_poll( + struct aciodrv_device_ctx *device, struct ac_io_panb_poll_in *poll_in) { log_assert(device); struct ac_io_message msg; - struct ac_io_panb_poll_in *poll_res = (struct ac_io_panb_poll_in *) &msg.cmd.raw; - + struct ac_io_panb_poll_in *poll_res = + (struct ac_io_panb_poll_in *) &msg.cmd.raw; + msg.cmd.code = ac_io_u16(AC_IO_CMD_PANB_POLL_REPLY); msg.cmd.nbytes = sizeof(struct ac_io_panb_poll_in); - if (!aciodrv_recv(device, - &msg, offsetof(struct ac_io_message, cmd.raw) + msg.cmd.nbytes + 1)) { + if (!aciodrv_recv( + device, + &msg, + offsetof(struct ac_io_message, cmd.raw) + msg.cmd.nbytes + 1)) { log_warning("Getting state failed"); return false; } - - if (poll_in != NULL){ + + if (poll_in != NULL) { memcpy(poll_in, poll_res, sizeof(struct ac_io_panb_poll_in)); } - + return true; } -bool aciodrv_panb_send_lamp(struct aciodrv_device_ctx *device, - uint8_t node_id, struct ac_io_panb_poll_out *state) +bool aciodrv_panb_send_lamp( + struct aciodrv_device_ctx *device, + uint8_t node_id, + struct ac_io_panb_poll_out *state) { log_assert(device); struct ac_io_message msg; - + /* only the first node is handling the commands */ if (node_id != 0) { return true; diff --git a/src/main/aciodrv/panb.h b/src/main/aciodrv/panb.h index e85ee4a..00bd56f 100644 --- a/src/main/aciodrv/panb.h +++ b/src/main/aciodrv/panb.h @@ -11,39 +11,43 @@ * @param node_count The number of nodes to poll. * @return True if successful, false on error. * @note node_id should be 0, PANB internally manages the other nodes. - * @note Upon calling, the device will stop replying to commands and just keep sending - * AC_IO_CMD_PANB_POLL_REPLY messages indefinitely. Failure to retrieve them fast enough - * will cause the device to malfunction. It is thus advised to make use of the aciodrv-proc - * module to spawn a thread that will handle these messages and provide an easy access to the - * latest input state. - * @note This module is supposed to be used in combination with the common - * device driver foundation. - * @see driver.h - */ -bool aciodrv_panb_start_auto_input(struct aciodrv_device_ctx *device, uint8_t node_id, uint8_t node_count); - -/** - * Retrieve a AC_IO_CMD_PANB_POLL_REPLY message from a PANB device. This assumes that there - * is such message incoming (ie. that start_auto_input has been called prior). - * - * @param device Context of opened device. - * @param poll_in Buffer to hold the received message, or NULL. - * @return True if successful, false on error. - * @note node_id should be 0, PANB internally manages the other nodes. - * @note Failure to retrieve the incoming messages fast enough will cause the device to malfunction. - * It is thus advised to make use of the aciodrv-proc module to spawn a thread that will handle these + * @note Upon calling, the device will stop replying to commands and just keep + * sending AC_IO_CMD_PANB_POLL_REPLY messages indefinitely. Failure to retrieve + * them fast enough will cause the device to malfunction. It is thus advised to + * make use of the aciodrv-proc module to spawn a thread that will handle these * messages and provide an easy access to the latest input state. * @note This module is supposed to be used in combination with the common * device driver foundation. * @see driver.h */ -bool aciodrv_panb_recv_poll(struct aciodrv_device_ctx *device, struct ac_io_panb_poll_in *poll_in); +bool aciodrv_panb_start_auto_input( + struct aciodrv_device_ctx *device, uint8_t node_id, uint8_t node_count); + +/** + * Retrieve a AC_IO_CMD_PANB_POLL_REPLY message from a PANB device. This assumes + * that there is such message incoming (ie. that start_auto_input has been + * called prior). + * + * @param device Context of opened device. + * @param poll_in Buffer to hold the received message, or NULL. + * @return True if successful, false on error. + * @note node_id should be 0, PANB internally manages the other nodes. + * @note Failure to retrieve the incoming messages fast enough will cause the + * device to malfunction. It is thus advised to make use of the aciodrv-proc + * module to spawn a thread that will handle these messages and provide an easy + * access to the latest input state. + * @note This module is supposed to be used in combination with the common + * device driver foundation. + * @see driver.h + */ +bool aciodrv_panb_recv_poll( + struct aciodrv_device_ctx *device, struct ac_io_panb_poll_in *poll_in); /** * Light lamps on a PANB device. * * @param node_id Id of the node to query (0 based). - * @param state Pointer to a lamp state struct + * @param state Pointer to a lamp state struct * (mandatory). * @return True on success, false on error. * @note node_id should be 0, PANB internally manages the other nodes. @@ -51,6 +55,9 @@ bool aciodrv_panb_recv_poll(struct aciodrv_device_ctx *device, struct ac_io_panb * device driver foundation. * @see driver.h */ -bool aciodrv_panb_send_lamp(struct aciodrv_device_ctx *device, uint8_t node_id, struct ac_io_panb_poll_out *state); +bool aciodrv_panb_send_lamp( + struct aciodrv_device_ctx *device, + uint8_t node_id, + struct ac_io_panb_poll_out *state); #endif \ No newline at end of file diff --git a/src/main/aciodrv/port.c b/src/main/aciodrv/port.c index 4ab43a8..b38ad2a 100644 --- a/src/main/aciodrv/port.c +++ b/src/main/aciodrv/port.c @@ -148,7 +148,8 @@ int aciodrv_port_write(HANDLE port_fd, const void *bytes, int nbytes) } if (!WriteFile(port_fd, bytes, nbytes, &nwrit, NULL)) { - log_warning("[%p] WriteFile failed: err = %lu", port_fd, GetLastError()); + log_warning( + "[%p] WriteFile failed: err = %lu", port_fd, GetLastError()); return -1; } diff --git a/src/main/aciodrv/port.h b/src/main/aciodrv/port.h index 29c3417..bcada1e 100644 --- a/src/main/aciodrv/port.h +++ b/src/main/aciodrv/port.h @@ -40,7 +40,7 @@ int aciodrv_port_write(HANDLE port_fd, const void *bytes, int nbytes); /** * Close the previously opened com port. - * + * * @param port_fd HANDLE of opened serial port */ void aciodrv_port_close(HANDLE port_fd); diff --git a/src/main/aciodrv/rvol.c b/src/main/aciodrv/rvol.c index 3a06cee..a9e0c36 100644 --- a/src/main/aciodrv/rvol.c +++ b/src/main/aciodrv/rvol.c @@ -8,9 +8,7 @@ #include "util/log.h" static bool aciodrv_rvol_change_expand_mode( - struct aciodrv_device_ctx *device, - uint8_t node_id, - uint8_t mode) + struct aciodrv_device_ctx *device, uint8_t node_id, uint8_t mode) { struct ac_io_message msg; @@ -28,15 +26,12 @@ static bool aciodrv_rvol_change_expand_mode( return false; } - log_info("I/O expand mode set %d, mode: %d", - node_id, mode); + log_info("I/O expand mode set %d, mode: %d", node_id, mode); return true; } -bool aciodrv_rvol_init( - struct aciodrv_device_ctx *device, - uint8_t node_id) +bool aciodrv_rvol_init(struct aciodrv_device_ctx *device, uint8_t node_id) { log_assert(device); diff --git a/src/main/acioemu/icca.c b/src/main/acioemu/icca.c index 2371a17..134b14f 100644 --- a/src/main/acioemu/icca.c +++ b/src/main/acioemu/icca.c @@ -147,7 +147,7 @@ void ac_io_emu_icca_dispatch_request( break; case AC_IO_ICCA_CMD_SET_SLOT_STATE: { - if(icca->version == v150) { + if (icca->version == v150) { ac_io_emu_icca_send_state(icca, req, 0, false); } else { struct ac_io_icca_misc *misc = @@ -267,8 +267,7 @@ static void ac_io_emu_icca_cmd_send_version( } else { // probably log invalid version here log_warning( - "Unknown ICCA version: %d emulation requested", - icca->version); + "Unknown ICCA version: %d emulation requested", icca->version); } resp.cmd.version.revision = 0x00; @@ -487,7 +486,7 @@ ac_io_emu_icca_cipher(struct ac_io_emu_icca *icca, uint8_t *data, size_t length) // process data data[i] = - (uint8_t)(icca->cipher_keys[0] >> (((3 - count4) << 3)) ^ data[i]); + (uint8_t) (icca->cipher_keys[0] >> (((3 - count4) << 3)) ^ data[i]); } } @@ -512,7 +511,7 @@ static void ac_io_emu_icca_cipher_set_key( resp.cmd.raw[0] = (reader_key >> 24) & 0xFF; resp.cmd.raw[1] = (reader_key >> 16) & 0xFF; resp.cmd.raw[2] = (reader_key >> 8) & 0xFF; - resp.cmd.raw[3] = (reader_key) & 0xFF; + resp.cmd.raw[3] = (reader_key) &0xFF; // so I looked these constants up, this isn't actually a secure key // generator it's actually Marsaglia's "KISS" algorithm with different diff --git a/src/main/aciomgr/manager.c b/src/main/aciomgr/manager.c index 5452a95..e73b18e 100644 --- a/src/main/aciomgr/manager.c +++ b/src/main/aciomgr/manager.c @@ -105,7 +105,6 @@ struct aciomgr_port_dispatcher *aciomgr_port_init(const char *path, int baud) return NULL; } - struct aciomgr_port_dispatcher *entry; EnterCriticalSection(&mgr_cs); diff --git a/src/main/aciotest/bi2a-sdvx.c b/src/main/aciotest/bi2a-sdvx.c index 1ac6f68..35f3039 100644 --- a/src/main/aciotest/bi2a-sdvx.c +++ b/src/main/aciotest/bi2a-sdvx.c @@ -29,7 +29,6 @@ bool aciotest_bi2a_sdvx_handler_update( return false; } - pin.raw[0] = ac_io_u16(pin.raw[0]); pin.raw[1] = ac_io_u16(pin.raw[1]); diff --git a/src/main/aciotest/icca.c b/src/main/aciotest/icca.c index a27a665..09a34e0 100644 --- a/src/main/aciotest/icca.c +++ b/src/main/aciotest/icca.c @@ -5,7 +5,6 @@ #include "aciodrv/icca.h" - #define IDLE_RESPONSES_BETWEEN_FELICA_POLLS 5 struct icca_handler_ctx { @@ -19,7 +18,7 @@ bool aciotest_icca_handler_init( { *ctx = malloc(sizeof(struct icca_handler_ctx)); - struct icca_handler_ctx *icca_ctx = (struct icca_handler_ctx*)*ctx; + struct icca_handler_ctx *icca_ctx = (struct icca_handler_ctx *) *ctx; icca_ctx->init = false; icca_ctx->slotted_reader = true; @@ -34,7 +33,7 @@ bool aciotest_icca_handler_init( bool aciotest_icca_handler_update( struct aciodrv_device_ctx *device, uint8_t node_id, void *ctx) { - struct icca_handler_ctx *icca_ctx = (struct icca_handler_ctx*)ctx; + struct icca_handler_ctx *icca_ctx = (struct icca_handler_ctx *) ctx; if (icca_ctx->init == false) { icca_ctx->init = true; diff --git a/src/main/aciotest/main.c b/src/main/aciotest/main.c index 842c2c1..5f1b8ad 100644 --- a/src/main/aciotest/main.c +++ b/src/main/aciotest/main.c @@ -85,8 +85,8 @@ int main(int argc, char **argv) log_to_writer(log_writer_stdout, NULL); - - struct aciodrv_device_ctx *device = aciodrv_device_open_path(argv[1], atoi(argv[2])); + struct aciodrv_device_ctx *device = + aciodrv_device_open_path(argv[1], atoi(argv[2])); if (!device) { printf("Opening acio device failed\n"); diff --git a/src/main/aciotest/panb.c b/src/main/aciotest/panb.c index 0d6ae50..8be0252 100644 --- a/src/main/aciotest/panb.c +++ b/src/main/aciotest/panb.c @@ -3,27 +3,29 @@ #include #include -#include "aciodrv/panb.h" #include "aciodrv-proc/panb.h" +#include "aciodrv/panb.h" struct panb_handler_ctx { bool running; }; -bool aciotest_panb_handler_init(struct aciodrv_device_ctx *device, uint8_t node_id, void **ctx) +bool aciotest_panb_handler_init( + struct aciodrv_device_ctx *device, uint8_t node_id, void **ctx) { if (node_id != 0) { return true; } *ctx = malloc(sizeof(struct panb_handler_ctx)); - struct panb_handler_ctx *panb_ctx = (struct panb_handler_ctx*)*ctx; + struct panb_handler_ctx *panb_ctx = (struct panb_handler_ctx *) *ctx; panb_ctx->running = true; return aciodrv_proc_panb_init(device); } -bool aciotest_panb_handler_update(struct aciodrv_device_ctx *device, uint8_t node_id, void *ctx) +bool aciotest_panb_handler_update( + struct aciodrv_device_ctx *device, uint8_t node_id, void *ctx) { uint8_t button[AC_IO_PANB_MAX_KEYS]; struct ac_io_panb_poll_out state; @@ -32,19 +34,19 @@ bool aciotest_panb_handler_update(struct aciodrv_device_ctx *device, uint8_t nod if (node_id != 0) { return true; } - + if (!panb_ctx->running) { printf(">>> PANB:\nDevice has been closed. Press Ctrl+C to exit."); return true; } - + if (!aciodrv_proc_panb_get_state(button)) { return false; } printf(">>> PANB:\nPress first and last keys to close device\n"); - for (int i=0; irunning = false; return true; } /* light the panel */ - for (int i=0; iDevInst, work_buffer, sizeof(work_buffer), 0)) { + if (CM_Get_Device_IDA( + PDeviceInfoData->DevInst, work_buffer, sizeof(work_buffer), 0)) { return false; } diff --git a/src/main/bio2emu-iidx/bi2a.c b/src/main/bio2emu-iidx/bi2a.c index f67fcf5..3c90d24 100644 --- a/src/main/bio2emu-iidx/bi2a.c +++ b/src/main/bio2emu-iidx/bi2a.c @@ -175,7 +175,8 @@ static void bio2_emu_bi2a_send_status( ac_io_emu_response_push(emu, &resp, 0); } -static int16_t tt_mult_delta(size_t tt_no) { +static int16_t tt_mult_delta(size_t tt_no) +{ int16_t current_tt = iidx_io_ep2_get_turntable(tt_no); int16_t delta = get_wrapped_delta_s16(current_tt, tt_last[tt_no], 256); diff --git a/src/main/config/lights.c b/src/main/config/lights.c index 3880d61..9aa1447 100644 --- a/src/main/config/lights.c +++ b/src/main/config/lights.c @@ -382,8 +382,8 @@ static INT_PTR lights_handle_pulse_tick(HWND hwnd) } bias = (float) (ui->lights[light_no].value_min); - scale = - (float) (ui->lights[light_no].value_max - ui->lights[light_no].value_min); + scale = (float) (ui->lights[light_no].value_max - + ui->lights[light_no].value_min); /* Intensity perception is non-linear. Pulse quadratically. */ diff --git a/src/main/config/main.c b/src/main/config/main.c index 76bf335..ba51555 100644 --- a/src/main/config/main.c +++ b/src/main/config/main.c @@ -117,14 +117,14 @@ int main(int argc, char **argv) if (!mapper_config_load(schema->name)) { log_info("Initializing empty config for %s", schema->name); - mapper_set_nlights((uint8_t)(max_light + 1)); + mapper_set_nlights((uint8_t) (max_light + 1)); mapper_set_nanalogs((uint8_t) schema->nanalogs); } else { // make sure that these are right if (mapper_get_nlights() != (max_light + 1)) { log_info("Updating nlights for %s", schema->name); - mapper_set_nlights((uint8_t)(max_light + 1)); + mapper_set_nlights((uint8_t) (max_light + 1)); } if (mapper_get_nanalogs() != schema->nanalogs) { diff --git a/src/main/config/spinner.c b/src/main/config/spinner.c index a45c988..a58505a 100644 --- a/src/main/config/spinner.c +++ b/src/main/config/spinner.c @@ -24,7 +24,7 @@ void spinner_init(HINSTANCE inst) wcx.cbSize = sizeof(wcx); wcx.lpfnWndProc = spinner_wnd_proc; wcx.hInstance = inst; - wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + wcx.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); wcx.lpszClassName = spinner_cls; RegisterClassEx(&wcx); diff --git a/src/main/d3d9exhook/config-gfx.c b/src/main/d3d9exhook/config-gfx.c index dbd5e99..6cf57af 100644 --- a/src/main/d3d9exhook/config-gfx.c +++ b/src/main/d3d9exhook/config-gfx.c @@ -18,8 +18,10 @@ #define D3D9EXHOOK_CONFIG_GFX_FORCED_REFRESHRATE_KEY "gfx.forced_refresh_rate" #define D3D9EXHOOK_CONFIG_GFX_DEVICE_ADAPTER_KEY "gfx.device_adapter" #define D3D9EXHOOK_CONFIG_GFX_FORCE_ORIENTATION_KEY "gfx.force_orientation" -#define D3D9EXHOOK_CONFIG_GFX_FORCE_SCREEN_RES_WIDTH_KEY "gfx.force_screen_res.width" -#define D3D9EXHOOK_CONFIG_GFX_FORCE_SCREEN_RES_HEIGHT_KEY "gfx.force_screen_res.height" +#define D3D9EXHOOK_CONFIG_GFX_FORCE_SCREEN_RES_WIDTH_KEY \ + "gfx.force_screen_res.width" +#define D3D9EXHOOK_CONFIG_GFX_FORCE_SCREEN_RES_HEIGHT_KEY \ + "gfx.force_screen_res.height" #define D3D9EXHOOK_CONFIG_GFX_DEFAULT_FRAMED_VALUE false #define D3D9EXHOOK_CONFIG_GFX_DEFAULT_WINDOWED_VALUE false @@ -103,15 +105,19 @@ void d3d9exhook_config_gfx_init(struct cconfig *config) config, D3D9EXHOOK_CONFIG_GFX_FORCE_SCREEN_RES_WIDTH_KEY, D3D9EXHOOK_CONFIG_GFX_DEFAULT_FORCE_SCREEN_RES_WIDTH_VALUE, - "Force a screen resolution (width), -1 to disable. Use this if the game does not auto " - "detect your monitor's resolution properly, e.g. 1368x768 instead of 1280x720."); + "Force a screen resolution (width), -1 to disable. Use this if the " + "game does not auto " + "detect your monitor's resolution properly, e.g. 1368x768 instead of " + "1280x720."); cconfig_util_set_int( config, D3D9EXHOOK_CONFIG_GFX_FORCE_SCREEN_RES_HEIGHT_KEY, D3D9EXHOOK_CONFIG_GFX_DEFAULT_FORCE_SCREEN_RES_HEIGHT_VALUE, - "Force a screen resolution (height), -1 to disable. Use this if the game does not auto " - "detect your monitor's resolution properly, e.g. 1368x768 instead of 1280x720."); + "Force a screen resolution (height), -1 to disable. Use this if the " + "game does not auto " + "detect your monitor's resolution properly, e.g. 1368x768 instead of " + "1280x720."); } void d3d9exhook_config_gfx_get( diff --git a/src/main/d3d9exhook/d3d9ex.c b/src/main/d3d9exhook/d3d9ex.c index f87314b..88d95b0 100644 --- a/src/main/d3d9exhook/d3d9ex.c +++ b/src/main/d3d9exhook/d3d9ex.c @@ -52,10 +52,8 @@ static HRESULT STDCALL my_EnumAdapterModes( UINT Mode, D3DDISPLAYMODE *pMode); -static UINT STDCALL my_GetAdapterModeCount( - IDirect3D9Ex *self, - UINT Adapter, - D3DFORMAT Format); +static UINT STDCALL +my_GetAdapterModeCount(IDirect3D9Ex *self, UINT Adapter, D3DFORMAT Format); static HRESULT STDCALL my_Direct3DCreate9Ex(UINT sdk_ver, IDirect3D9Ex **api); @@ -305,7 +303,8 @@ static HRESULT STDCALL my_CreateDeviceEx( if (fdm) { log_misc( - "CreateDeviceEx display mode: size %d, width %d, height %d, refresh rate %d, format %d, " + "CreateDeviceEx display mode: size %d, width %d, height %d, " + "refresh rate %d, format %d, " "scan line ordering %d", fdm->Size, fdm->Width, @@ -318,7 +317,8 @@ static HRESULT STDCALL my_CreateDeviceEx( log_misc( "D3D9EX presenter parameters: BackBufferWidth %d, BackBufferHeight " "%d, BackBufferFormat %d, " - "BackBufferCount %d, MultiSampleType %d, MultiSampleQuality %ld, SwapEffect %d, " + "BackBufferCount %d, MultiSampleType %d, MultiSampleQuality %ld, " + "SwapEffect %d, " "hDeviceWindow %p, Windowed %d, " "EnableAutoDepthStencil " "%d, AutoDepthStencilFormat %d, Flags %lX, " @@ -343,8 +343,10 @@ static HRESULT STDCALL my_CreateDeviceEx( adapter = d3d9ex_device_adapter; } - if (d3d9ex_force_screen_res_width > 0 && d3d9ex_force_screen_res_height > 0) { - log_info("Overriding screen resolution/back buffer of %dx%d -> %dx%d", + if (d3d9ex_force_screen_res_width > 0 && + d3d9ex_force_screen_res_height > 0) { + log_info( + "Overriding screen resolution/back buffer of %dx%d -> %dx%d", pp->BackBufferWidth, pp->BackBufferHeight, d3d9ex_force_screen_res_width, @@ -445,7 +447,7 @@ static HRESULT STDCALL my_EnumAdapterModes( IDirect3D9Ex *real = com_proxy_downcast(self)->real; HRESULT hr; - if (d3d9ex_device_adapter>= 0) { + if (d3d9ex_device_adapter >= 0) { Adapter = d3d9ex_device_adapter; } @@ -461,15 +463,13 @@ static HRESULT STDCALL my_EnumAdapterModes( return hr; } -static UINT STDCALL my_GetAdapterModeCount( - IDirect3D9Ex *self, - UINT Adapter, - D3DFORMAT Format) +static UINT STDCALL +my_GetAdapterModeCount(IDirect3D9Ex *self, UINT Adapter, D3DFORMAT Format) { IDirect3D9Ex *real = com_proxy_downcast(self)->real; UINT res; - if (d3d9ex_device_adapter>= 0) { + if (d3d9ex_device_adapter >= 0) { Adapter = d3d9ex_device_adapter; } @@ -494,14 +494,14 @@ static HRESULT STDCALL my_Direct3DCreate9Ex(UINT sdk_ver, IDirect3D9Ex **api) hr = real_Direct3DCreate9Ex(sdk_ver, api); api_ = *api; - + hr = com_proxy_wrap(&api_proxy, api_, sizeof(*api_->lpVtbl)); - + if (hr != S_OK) { log_warning("Wrapping com proxy failed: %08lx", hr); return hr; } - + api_vtbl = api_proxy->vptr; api_vtbl->CreateDeviceEx = my_CreateDeviceEx; @@ -555,7 +555,8 @@ void d3d9ex_configure(struct d3d9exhook_config_gfx *gfx_config) d3d9ex_force_screen_res_height = gfx_config->force_screen_res.height; if (d3d9ex_force_screen_res_width * d3d9ex_force_screen_res_height > 0) { - log_warning("Force screen res: Only one, either width or height, is > 0." + log_warning( + "Force screen res: Only one, either width or height, is > 0." " Force screen res not activate"); } } diff --git a/src/main/ddrhook-util/_com4.c b/src/main/ddrhook-util/_com4.c index 968d97c..44e0178 100644 --- a/src/main/ddrhook-util/_com4.c +++ b/src/main/ddrhook-util/_com4.c @@ -34,9 +34,7 @@ static struct ac_io_emu_hdxs com4_hdxs; static struct ac_io_emu_icca com4_icca[2]; static uint32_t check_panel_light( - const struct ac_io_hdxs_output *output, - uint8_t panel_idx, - uint8_t out_idx) + const struct ac_io_hdxs_output *output, uint8_t panel_idx, uint8_t out_idx) { if (output->lights[panel_idx].bit) { return 1 << out_idx; @@ -45,7 +43,8 @@ static uint32_t check_panel_light( } } -static uint8_t upscale_light(uint8_t in_7bit) { +static uint8_t upscale_light(uint8_t in_7bit) +{ if (in_7bit < 0x10) { return in_7bit * 2; } else { @@ -54,18 +53,24 @@ static uint8_t upscale_light(uint8_t in_7bit) { } } -static void lights_dispatcher( - struct ac_io_emu_hdxs *emu, const struct ac_io_message *req) +static void +lights_dispatcher(struct ac_io_emu_hdxs *emu, const struct ac_io_message *req) { const struct ac_io_hdxs_output *output = &req->cmd.hdxs_output; uint32_t lights = 0; - lights |= check_panel_light(output, AC_IO_HDXS_OUT_P1_START, LIGHT_HD_P1_START); - lights |= check_panel_light(output, AC_IO_HDXS_OUT_P1_UP_DOWN, LIGHT_HD_P1_UP_DOWN); - lights |= check_panel_light(output, AC_IO_HDXS_OUT_P1_LEFT_RIGHT, LIGHT_HD_P1_LEFT_RIGHT); - lights |= check_panel_light(output, AC_IO_HDXS_OUT_P2_START, LIGHT_HD_P2_START); - lights |= check_panel_light(output, AC_IO_HDXS_OUT_P2_UP_DOWN, LIGHT_HD_P2_UP_DOWN); - lights |= check_panel_light(output, AC_IO_HDXS_OUT_P2_LEFT_RIGHT, LIGHT_HD_P2_LEFT_RIGHT); + lights |= + check_panel_light(output, AC_IO_HDXS_OUT_P1_START, LIGHT_HD_P1_START); + lights |= check_panel_light( + output, AC_IO_HDXS_OUT_P1_UP_DOWN, LIGHT_HD_P1_UP_DOWN); + lights |= check_panel_light( + output, AC_IO_HDXS_OUT_P1_LEFT_RIGHT, LIGHT_HD_P1_LEFT_RIGHT); + lights |= + check_panel_light(output, AC_IO_HDXS_OUT_P2_START, LIGHT_HD_P2_START); + lights |= check_panel_light( + output, AC_IO_HDXS_OUT_P2_UP_DOWN, LIGHT_HD_P2_UP_DOWN); + lights |= check_panel_light( + output, AC_IO_HDXS_OUT_P2_LEFT_RIGHT, LIGHT_HD_P2_LEFT_RIGHT); ddr_io_set_lights_hdxs_panel(lights); @@ -73,9 +78,12 @@ static void lights_dispatcher( size_t light_idx = i * 3; // these are 7 bit, upscale them to 8 bit - uint8_t r = upscale_light(output->lights[light_idx + AC_IO_HDXS_RED].analog); - uint8_t g = upscale_light(output->lights[light_idx + AC_IO_HDXS_GREEN].analog); - uint8_t b = upscale_light(output->lights[light_idx + AC_IO_HDXS_BLUE].analog); + uint8_t r = + upscale_light(output->lights[light_idx + AC_IO_HDXS_RED].analog); + uint8_t g = + upscale_light(output->lights[light_idx + AC_IO_HDXS_GREEN].analog); + uint8_t b = + upscale_light(output->lights[light_idx + AC_IO_HDXS_BLUE].analog); ddr_io_set_lights_hdxs_rgb(i, r, g, b); } diff --git a/src/main/ddrhook-util/dinput.c b/src/main/ddrhook-util/dinput.c index ac288b0..b0fdc66 100644 --- a/src/main/ddrhook-util/dinput.c +++ b/src/main/ddrhook-util/dinput.c @@ -72,11 +72,11 @@ static HRESULT STDCALL my_DirectInput8Create( res = real_DirectInput8Create( hinst, dwVersion, riidltf, (LPVOID *) &api, punkOuter); - + if (res != DI_OK) { return res; } - + res = com_proxy_wrap(&api_proxy, api, sizeof(*api->lpVtbl)); if (res != S_OK) { diff --git a/src/main/ddrhook-util/gfx.c b/src/main/ddrhook-util/gfx.c index 346aa39..3f5f773 100644 --- a/src/main/ddrhook-util/gfx.c +++ b/src/main/ddrhook-util/gfx.c @@ -185,8 +185,7 @@ static void gfx_d3d9_patch_window(struct hook_d3d9_irp *irp) } } -static void -gfx_d3d9_fix_window_size_and_pos(struct hook_d3d9_irp *irp) +static void gfx_d3d9_fix_window_size_and_pos(struct hook_d3d9_irp *irp) { log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_CREATE_WINDOW_EX); @@ -215,8 +214,7 @@ gfx_d3d9_fix_window_size_and_pos(struct hook_d3d9_irp *irp) } } -static void gfx_d3d9_create_device_apply_window_mode( - struct hook_d3d9_irp *irp) +static void gfx_d3d9_create_device_apply_window_mode(struct hook_d3d9_irp *irp) { log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_CTX_CREATE_DEVICE); @@ -231,8 +229,7 @@ static void gfx_d3d9_create_device_apply_window_mode( } } -static void gfx_d3d9_reset_apply_window_mode( - struct hook_d3d9_irp *irp) +static void gfx_d3d9_reset_apply_window_mode(struct hook_d3d9_irp *irp) { log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_DEV_RESET); diff --git a/src/main/ddrhook-util/p3io.c b/src/main/ddrhook-util/p3io.c index f55afb0..09b8c6f 100644 --- a/src/main/ddrhook-util/p3io.c +++ b/src/main/ddrhook-util/p3io.c @@ -64,8 +64,14 @@ void p3io_ddr_init_with_plugs( memcpy(&p3io_ddr_mcode, mcode, sizeof(struct security_mcode)); memcpy(&p3io_ddr_pcbid, pcbid, sizeof(struct security_id)); memcpy(&p3io_ddr_eamid, eamid, sizeof(struct security_id)); - memcpy(&p3io_black_sign_key, black_sign_key, sizeof(struct security_rp_sign_key)); - memcpy(&p3io_white_sign_key, white_sign_key, sizeof(struct security_rp_sign_key)); + memcpy( + &p3io_black_sign_key, + black_sign_key, + sizeof(struct security_rp_sign_key)); + memcpy( + &p3io_white_sign_key, + white_sign_key, + sizeof(struct security_rp_sign_key)); /* COM4 isn't a real COM port, we configure the core P3IO emulator code to generate IRPs addressed to COM4 and then we possibly intercept them in diff --git a/src/main/ddrhook-util/usbmem.c b/src/main/ddrhook-util/usbmem.c index 9869643..f85363f 100644 --- a/src/main/ddrhook-util/usbmem.c +++ b/src/main/ddrhook-util/usbmem.c @@ -15,9 +15,9 @@ #include "hook/iohook.h" #include "util/crc.h" +#include "util/fs.h" #include "util/iobuf.h" #include "util/log.h" -#include "util/fs.h" #include "util/str.h" #define USBMEM_DEVICE_COUNT 2 @@ -95,7 +95,8 @@ void usbmem_init(const char *path_p1, const char *path_p2, const bool enabled) GetFullPathNameA(path_p2, sizeof(usb_data_path[1]), usb_data_path[1], NULL); log_misc("USB memory data path (P2): %s", usb_data_path[1]); - if (enabled && !path_exists(usb_data_path[0]) && !path_exists(usb_data_path[1])) { + if (enabled && !path_exists(usb_data_path[0]) && + !path_exists(usb_data_path[1])) { log_warning("USB memory data path does not exist, disabling"); usbmem_enabled = false; } @@ -177,16 +178,22 @@ static HRESULT usbmem_write(struct irp *irp) log_assert(irp->write.bytes != NULL); src = &irp->write; - nbytes = src->nbytes > USBMEM_COMMAND_BUF_SIZE ? USBMEM_COMMAND_BUF_SIZE : src->nbytes; + nbytes = src->nbytes > USBMEM_COMMAND_BUF_SIZE ? USBMEM_COMMAND_BUF_SIZE : + src->nbytes; memcpy(request, src->bytes, nbytes); request[nbytes - 1] = '\0'; /* This is always a CR. */ - if (!usbmem_pending && target_device_id >= 0 && target_device_id < USBMEM_DEVICE_COUNT && usbmem_state[target_device_id].file_type == USBMEM_FILE_TYPE_READ) { + if (!usbmem_pending && target_device_id >= 0 && + target_device_id < USBMEM_DEVICE_COUNT && + usbmem_state[target_device_id].file_type == USBMEM_FILE_TYPE_READ) { memset(usbmem_response, 0, sizeof(usbmem_response)); - // log_misc("Read progress %08x/%08x bytes", usbmem_state[target_device_id].buffer_index, usbmem_state[target_device_id].buffer_len); + // log_misc("Read progress %08x/%08x bytes", + // usbmem_state[target_device_id].buffer_index, + // usbmem_state[target_device_id].buffer_len); - if (usbmem_state[target_device_id].buffer_index < usbmem_state[target_device_id].buffer_len) { + if (usbmem_state[target_device_id].buffer_index < + usbmem_state[target_device_id].buffer_len) { usbmem_response_length = sizeof(usbmem_response); usbmem_response[0] = 0x02; // 1 = 0x80 buffer, 2 = 0x400 buffer usbmem_response[1] = usbmem_state[target_device_id].buffer_frame; @@ -201,16 +208,23 @@ static HRESULT usbmem_write(struct irp *irp) } else { size_t len = sizeof(usbmem_response) - 5; - if (usbmem_state[target_device_id].buffer_index + len > usbmem_state[target_device_id].buffer_len) - len = usbmem_state[target_device_id].buffer_len - usbmem_state[target_device_id].buffer_index; + if (usbmem_state[target_device_id].buffer_index + len > + usbmem_state[target_device_id].buffer_len) + len = usbmem_state[target_device_id].buffer_len - + usbmem_state[target_device_id].buffer_index; - memcpy(usbmem_response + 3, usbmem_state[target_device_id].buffer + usbmem_state[target_device_id].buffer_index, len); + memcpy( + usbmem_response + 3, + usbmem_state[target_device_id].buffer + + usbmem_state[target_device_id].buffer_index, + len); usbmem_state[target_device_id].buffer_index += len; } usbmem_state[target_device_id].buffer_frame++; - uint16_t crc = crc16_msb(usbmem_response + 3, sizeof(usbmem_response) - 5, 0); + uint16_t crc = + crc16_msb(usbmem_response + 3, sizeof(usbmem_response) - 5, 0); usbmem_response[sizeof(usbmem_response) - 2] = crc >> 8; usbmem_response[sizeof(usbmem_response) - 1] = crc & 0xff; } else { @@ -221,7 +235,8 @@ static HRESULT usbmem_write(struct irp *irp) log_misc(">%s", request); // Try to detect device ID - // The only commands without a device ID are "sver", "start", and "init". + // The only commands without a device ID are "sver", "start", and + // "init". char target_device_val = request[strlen(request) - 1]; char *target_device_id_ptr = strstr(request, " "); if (target_device_id_ptr != NULL) { @@ -241,18 +256,22 @@ static HRESULT usbmem_write(struct irp *irp) target_device_id = target_device_val == 'b' ? 0 : 1; if (!usbmem_enabled) { - // Ignore all other USB device specific commands and pretend a device isn't plugged in - // when USB memory emulation is disabled. + // Ignore all other USB device specific commands and pretend a + // device isn't plugged in when USB memory emulation is + // disabled. str_cpy(usbmem_response, sizeof(usbmem_response), "fail"); } else if (usbmem_state[target_device_id].errored) { - // If the device went through the entire process once and the file didn't exist - // then just force it to be disabled until the game is restarted because otherwise - // it'll get stuck in a loop. - // TODO: This could be better emulated by using a keybind to simulate inserting and - // ejecting the USB drive to additionally clear the error flag. + // If the device went through the entire process once and the + // file didn't exist then just force it to be disabled until the + // game is restarted because otherwise it'll get stuck in a + // loop. + // TODO: This could be better emulated by using a keybind to + // simulate inserting and ejecting the USB drive to additionally + // clear the error flag. str_cpy(usbmem_response, sizeof(usbmem_response), "fail"); } else if (str_eq(request, "on_a") || str_eq(request, "on_b")) { - usbmem_state[target_device_id].connected = path_exists(usbmem_state[target_device_id].basepath); + usbmem_state[target_device_id].connected = + path_exists(usbmem_state[target_device_id].basepath); usbmem_state[target_device_id].errored = false; usbmem_reset_file_state(target_device_id); @@ -260,21 +279,32 @@ static HRESULT usbmem_write(struct irp *irp) if (usbmem_state[target_device_id].connected) str_cpy(usbmem_response, sizeof(usbmem_response), "done"); else - str_cpy(usbmem_response, sizeof(usbmem_response), "not connected"); + str_cpy( + usbmem_response, + sizeof(usbmem_response), + "not connected"); } else if (str_eq(request, "offa") || str_eq(request, "offb")) { if (usbmem_state[target_device_id].connected) str_cpy(usbmem_response, sizeof(usbmem_response), "done"); else - str_cpy(usbmem_response, sizeof(usbmem_response), "not connected"); + str_cpy( + usbmem_response, + sizeof(usbmem_response), + "not connected"); usbmem_state[target_device_id].connected = false; usbmem_reset_file_state(target_device_id); } else if (str_eq(request, "opna") || str_eq(request, "opnb")) { - bool basepath_exists = path_exists(usbmem_state[target_device_id].basepath); + bool basepath_exists = + path_exists(usbmem_state[target_device_id].basepath); - if (!usbmem_state[target_device_id].connected || !basepath_exists) { + if (!usbmem_state[target_device_id].connected || + !basepath_exists) { usbmem_state[target_device_id].opened = false; - str_cpy(usbmem_response, sizeof(usbmem_response), "not connected"); + str_cpy( + usbmem_response, + sizeof(usbmem_response), + "not connected"); } else { usbmem_state[target_device_id].opened = true; str_cpy(usbmem_response, sizeof(usbmem_response), "done"); @@ -283,82 +313,132 @@ static HRESULT usbmem_write(struct irp *irp) if (usbmem_state[target_device_id].opened) str_cpy(usbmem_response, sizeof(usbmem_response), "done"); else - str_cpy(usbmem_response, sizeof(usbmem_response), "not connected"); + str_cpy( + usbmem_response, + sizeof(usbmem_response), + "not connected"); usbmem_state[target_device_id].opened = false; usbmem_reset_file_state(target_device_id); - } else if (strncmp(request, "cda ", 4) == 0 || strncmp(request, "cdb ", 4) == 0) { + } else if ( + strncmp(request, "cda ", 4) == 0 || + strncmp(request, "cdb ", 4) == 0) { char *path = request + 4; - if (!usbmem_state[target_device_id].connected || !usbmem_state[target_device_id].opened) { + if (!usbmem_state[target_device_id].connected || + !usbmem_state[target_device_id].opened) { str_cpy(usbmem_response, sizeof(usbmem_response), "done"); } else if (path[1] == ':') { // Absolute path char temp[MAX_PATH]; - snprintf(temp, sizeof(temp), "%s\\%s", usbmem_state[target_device_id].basepath, path + 3); + snprintf( + temp, + sizeof(temp), + "%s\\%s", + usbmem_state[target_device_id].basepath, + path + 3); if (!path_exists(temp)) { log_warning("Couldn't find path %s", temp); - str_cpy(usbmem_response, sizeof(usbmem_response), "done"); + str_cpy( + usbmem_response, sizeof(usbmem_response), "done"); } else { log_misc("Changing path to %s", temp); - str_cpy(usbmem_state[target_device_id].path, sizeof(usbmem_state[target_device_id].path), temp); - str_cpy(usbmem_response, sizeof(usbmem_response), "done"); + str_cpy( + usbmem_state[target_device_id].path, + sizeof(usbmem_state[target_device_id].path), + temp); + str_cpy( + usbmem_response, sizeof(usbmem_response), "done"); } } else { str_cpy(usbmem_response, sizeof(usbmem_response), "fail"); } - } else if (strncmp(request, "rda ", 4) == 0 || strncmp(request, "rdb ", 4) == 0) { + } else if ( + strncmp(request, "rda ", 4) == 0 || + strncmp(request, "rdb ", 4) == 0) { usbmem_reset_file_state(target_device_id); - if (!usbmem_state[target_device_id].connected || !usbmem_state[target_device_id].opened) { + if (!usbmem_state[target_device_id].connected || + !usbmem_state[target_device_id].opened) { str_cpy(usbmem_response, sizeof(usbmem_response), "fail"); } else { char temp[MAX_PATH] = {0}; char *filename = request + 4; - snprintf(temp, sizeof(temp), "%s\\%s", usbmem_state[target_device_id].path, filename); + snprintf( + temp, + sizeof(temp), + "%s\\%s", + usbmem_state[target_device_id].path, + filename); if (usbmem_state[target_device_id].buffer) { free(usbmem_state[target_device_id].buffer); usbmem_state[target_device_id].buffer = NULL; } - usbmem_state[target_device_id].file_type = USBMEM_FILE_TYPE_NONE; + usbmem_state[target_device_id].file_type = + USBMEM_FILE_TYPE_NONE; usbmem_state[target_device_id].buffer_len = 0; usbmem_state[target_device_id].buffer_index = 0; usbmem_state[target_device_id].buffer_frame = 0; - memset(usbmem_state[target_device_id].filename, 0, sizeof(usbmem_state[target_device_id].filename)); + memset( + usbmem_state[target_device_id].filename, + 0, + sizeof(usbmem_state[target_device_id].filename)); if (!path_exists(temp)) { log_warning("Couldn't find file %s", temp); - str_cpy(usbmem_response, sizeof(usbmem_response), "fail"); + str_cpy( + usbmem_response, sizeof(usbmem_response), "fail"); usbmem_state[target_device_id].errored = true; } else { - bool loaded = file_load(temp, (void**)&usbmem_state[target_device_id].buffer, - &usbmem_state[target_device_id].buffer_len, false); + bool loaded = file_load( + temp, + (void **) &usbmem_state[target_device_id].buffer, + &usbmem_state[target_device_id].buffer_len, + false); if (loaded) { log_misc("Reading file %s", temp); - usbmem_state[target_device_id].file_type = USBMEM_FILE_TYPE_READ; + usbmem_state[target_device_id].file_type = + USBMEM_FILE_TYPE_READ; - str_cpy(usbmem_state[target_device_id].filename, sizeof(usbmem_state[target_device_id].filename), filename); - str_cpy(usbmem_response, sizeof(usbmem_response), "start"); + str_cpy( + usbmem_state[target_device_id].filename, + sizeof(usbmem_state[target_device_id].filename), + filename); + str_cpy( + usbmem_response, + sizeof(usbmem_response), + "start"); } else { log_warning("Couldn't read file %s", temp); - str_cpy(usbmem_response, sizeof(usbmem_response), "fail"); + str_cpy( + usbmem_response, + sizeof(usbmem_response), + "fail"); usbmem_state[target_device_id].errored = true; } } } - } else if (strncmp(request, "wra ", 4) == 0 || strncmp(request, "wrb ", 4) == 0) { + } else if ( + strncmp(request, "wra ", 4) == 0 || + strncmp(request, "wrb ", 4) == 0) { // Open file for writing usbmem_reset_file_state(target_device_id); - str_cpy(usbmem_response, sizeof(usbmem_response), "not supported"); - } else if (strncmp(request, "wha ", 4) == 0 || strncmp(request, "whb ", 4) == 0) { + str_cpy( + usbmem_response, sizeof(usbmem_response), "not supported"); + } else if ( + strncmp(request, "wha ", 4) == 0 || + strncmp(request, "whb ", 4) == 0) { // Something relating to writing? - str_cpy(usbmem_response, sizeof(usbmem_response), "not supported"); - } else if (strncmp(request, "lma ", 4) == 0 || strncmp(request, "lmb ", 4) == 0) { + str_cpy( + usbmem_response, sizeof(usbmem_response), "not supported"); + } else if ( + strncmp(request, "lma ", 4) == 0 || + strncmp(request, "lmb ", 4) == 0) { // What is "lm"? str_cpy(usbmem_response, sizeof(usbmem_response), "done"); } else { diff --git a/src/main/ddrhook1/avs-boot.c b/src/main/ddrhook1/avs-boot.c index 47a4f6a..1b7ad41 100644 --- a/src/main/ddrhook1/avs-boot.c +++ b/src/main/ddrhook1/avs-boot.c @@ -84,8 +84,9 @@ static void my_avs_boot( char nvram_path[MAX_PATH] = {0}; char raw_path[MAX_PATH] = {0}; - // Using the full path as part of the AVS paths seems to break on long paths. - // So instead, just take the launcher folder relative to the main game directory. + // Using the full path as part of the AVS paths seems to break on long + // paths. So instead, just take the launcher folder relative to the main + // game directory. char *launcher_folder; ddrhook1_get_launcher_path_parts(NULL, &launcher_folder); @@ -104,10 +105,8 @@ static void my_avs_boot( log_misc("avs paths: %s %s\n", nvram_path, raw_path); - avs_boot_replace_property_str( - config, "/fs/nvram/device", nvram_path); - avs_boot_replace_property_str( - config, "/fs/raw/device", raw_path); + avs_boot_replace_property_str(config, "/fs/nvram/device", nvram_path); + avs_boot_replace_property_str(config, "/fs/raw/device", raw_path); #endif real_avs_boot( diff --git a/src/main/ddrhook1/config-ddrhook1.c b/src/main/ddrhook1/config-ddrhook1.c index 7886226..154f3ae 100644 --- a/src/main/ddrhook1/config-ddrhook1.c +++ b/src/main/ddrhook1/config-ddrhook1.c @@ -26,7 +26,8 @@ void ddrhook1_config_ddrhook1_init(struct cconfig *config) config, DDRHOOK1_CONFIG_DDRHOOK1_USE_COM4_EMU_KEY, DDRHOOK1_CONFIG_DDRHOOK1_DEFAULT_USE_COM4_EMU_VALUE, - "Don't emulate P3IO COM4 and its downstream devices, use the Windows COM4 port instead"); + "Don't emulate P3IO COM4 and its downstream devices, use the Windows " + "COM4 port instead"); cconfig_util_set_bool( config, DDRHOOK1_CONFIG_DDRHOOK1_STANDARD_DEF_KEY, diff --git a/src/main/ddrhook1/config-security.c b/src/main/ddrhook1/config-security.c index c05268f..9489b0a 100644 --- a/src/main/ddrhook1/config-security.c +++ b/src/main/ddrhook1/config-security.c @@ -41,8 +41,7 @@ void ddrhook1_config_security_get( char *tmp_default; char mcode[9]; - tmp_default = - security_mcode_to_str(&security_mcode_ddr_x); + tmp_default = security_mcode_to_str(&security_mcode_ddr_x); if (!cconfig_util_get_str( config, diff --git a/src/main/ddrhook1/dllmain.c b/src/main/ddrhook1/dllmain.c index 6b67af6..3dcc6c9 100644 --- a/src/main/ddrhook1/dllmain.c +++ b/src/main/ddrhook1/dllmain.c @@ -41,7 +41,7 @@ #include "util/thread.h" #define DDRHOOK1_INFO_HEADER \ - "ddrhook1 for DDR X" \ + "ddrhook1 for DDR X" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) #define DDRHOOK1_CMD_USAGE \ "Usage: inject.exe ddrhook1.dll [options...]" @@ -53,8 +53,10 @@ static const hook_d3d9_irp_handler_t ddrhook1_d3d9_handlers[] = { gfx_d3d9_irp_handler, }; -static DWORD STDCALL my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize); -static DWORD(STDCALL *real_GetModuleFileNameA)(HMODULE hModule, LPSTR lpFilename, DWORD nSize); +static DWORD STDCALL +my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize); +static DWORD(STDCALL *real_GetModuleFileNameA)( + HMODULE hModule, LPSTR lpFilename, DWORD nSize); static bool ddrhook1_init_check = false; @@ -144,7 +146,9 @@ my_GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize) #endif &security_rp_sign_key_white_eamuse); extio_init(); - usbmem_init(config_ddrhook1.usbmem_path_p1, config_ddrhook1.usbmem_path_p2, + usbmem_init( + config_ddrhook1.usbmem_path_p1, + config_ddrhook1.usbmem_path_p2, config_ddrhook1.usbmem_enabled); spike_init(); com4_init(); @@ -189,7 +193,8 @@ BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) ddrhook1_master_insert_hooks(NULL); ddrhook1_filesystem_hook_init(); - hook_d3d9_init(ddrhook1_d3d9_handlers, lengthof(ddrhook1_d3d9_handlers)); + hook_d3d9_init( + ddrhook1_d3d9_handlers, lengthof(ddrhook1_d3d9_handlers)); } return TRUE; diff --git a/src/main/ddrhook1/filesystem.c b/src/main/ddrhook1/filesystem.c index db70a0d..abec921 100644 --- a/src/main/ddrhook1/filesystem.c +++ b/src/main/ddrhook1/filesystem.c @@ -1,8 +1,8 @@ #include #include -#include #include +#include #include #include @@ -14,9 +14,8 @@ #include "util/str.h" static BOOL STDCALL my_SetCurrentDirectoryA(LPCSTR lpPathName); -static HANDLE STDCALL my_FindFirstFileW( - LPCWSTR lpFileName, - LPWIN32_FIND_DATAA lpFindFileData); +static HANDLE STDCALL +my_FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData); static HANDLE STDCALL my_CreateFileW( LPCWSTR lpFileName, DWORD dwDesiredAccess, @@ -30,8 +29,7 @@ static BOOL WINAPI my_CreateDirectoryW( static BOOL(STDCALL *real_SetCurrentDirectoryA)(LPCSTR lpPathName); static HANDLE(STDCALL *real_FindFirstFileW)( - LPCWSTR lpFileName, - LPWIN32_FIND_DATAA lpFindFileData); + LPCWSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData); static HANDLE(STDCALL *real_CreateFileW)( LPCWSTR lpFileName, DWORD dwDesiredAccess, @@ -44,29 +42,25 @@ static BOOL(WINAPI *real_CreateDirectoryW)( LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes); static const struct hook_symbol filesystem_hook_syms[] = { - { - .name = "CreateFileW", - .patch = my_CreateFileW, - .link = (void **) &real_CreateFileW - }, + {.name = "CreateFileW", + .patch = my_CreateFileW, + .link = (void **) &real_CreateFileW}, { .name = "SetCurrentDirectoryA", .patch = my_SetCurrentDirectoryA, .link = (void **) &real_SetCurrentDirectoryA, }, - { - .name = "FindFirstFileW", - .patch = my_FindFirstFileW, - .link = (void **) &real_FindFirstFileW - }, - { - .name = "CreateDirectoryW", - .patch = my_CreateDirectoryW, - .link = (void **) &real_CreateDirectoryW - }, + {.name = "FindFirstFileW", + .patch = my_FindFirstFileW, + .link = (void **) &real_FindFirstFileW}, + {.name = "CreateDirectoryW", + .patch = my_CreateDirectoryW, + .link = (void **) &real_CreateDirectoryW}, }; -void ddrhook1_get_launcher_path_parts(char **output_path, char **output_foldername) { +void ddrhook1_get_launcher_path_parts( + char **output_path, char **output_foldername) +{ char module_path[MAX_PATH]; char launcher_path[MAX_PATH]; @@ -82,7 +76,9 @@ void ddrhook1_get_launcher_path_parts(char **output_path, char **output_folderna return; char *filename_ptr = NULL; - if (GetFullPathNameA(module_path, sizeof(launcher_path), launcher_path, &filename_ptr) == 0) + if (GetFullPathNameA( + module_path, sizeof(launcher_path), launcher_path, &filename_ptr) == + 0) return; if (filename_ptr != NULL) @@ -98,7 +94,8 @@ void ddrhook1_get_launcher_path_parts(char **output_path, char **output_folderna int idx_folder = 0; for (idx_folder = strlen(launcher_path); idx_folder - 1 > 0; idx_folder--) { - if (launcher_path[idx_folder - 1] == '\\' || launcher_path[idx_folder - 1] == '/') { + if (launcher_path[idx_folder - 1] == '\\' || + launcher_path[idx_folder - 1] == '/') { break; } } @@ -109,7 +106,7 @@ void ddrhook1_get_launcher_path_parts(char **output_path, char **output_folderna if (len < 0) len = 0; - *output_foldername = (char*)xmalloc(len + 2); + *output_foldername = (char *) xmalloc(len + 2); memset(*output_foldername, 0, len + 1); strncpy(*output_foldername, launcher_path + idx_folder, len); } @@ -120,7 +117,7 @@ void ddrhook1_get_launcher_path_parts(char **output_path, char **output_folderna if (len > strlen(launcher_path)) len = strlen(launcher_path); - *output_path = (char*)xmalloc(len + 1); + *output_path = (char *) xmalloc(len + 1); memset(*output_path, 0, len + 1); strncpy(*output_path, launcher_path, len); } @@ -135,9 +132,12 @@ static wchar_t *ddrhook1_filesystem_get_path(LPCWSTR path) // log_misc("path: %s", tmp); // free(tmp); - // Deal with hardcoded paths: D:/HDX, E:/conf, E:/conf/nvram, E:/conf/raw, F:/update, ... - if (wstr_insensitive_eq(path, L"D:/HDX") || wstr_insensitive_eq(path, L"D:\\HDX") - || wstr_insensitive_eq(path, L"D:/JDX") || wstr_insensitive_eq(path, L"D:\\JDX")) { + // Deal with hardcoded paths: D:/HDX, E:/conf, E:/conf/nvram, E:/conf/raw, + // F:/update, ... + if (wstr_insensitive_eq(path, L"D:/HDX") || + wstr_insensitive_eq(path, L"D:\\HDX") || + wstr_insensitive_eq(path, L"D:/JDX") || + wstr_insensitive_eq(path, L"D:\\JDX")) { char *_new_path; ddrhook1_get_launcher_path_parts(&_new_path, NULL); @@ -145,8 +145,10 @@ static wchar_t *ddrhook1_filesystem_get_path(LPCWSTR path) new_path = str_widen(_new_path); return new_path; } - } else if (wcslen(path) >= 7 && (wcsnicmp(path, L"E:/conf", 7) == 0 - || wcsnicmp(path, L"E:\\conf", 7) == 0)) { + } else if ( + wcslen(path) >= 7 && + (wcsnicmp(path, L"E:/conf", 7) == 0 || + wcsnicmp(path, L"E:\\conf", 7) == 0)) { char *launcher_folder; wchar_t *sub_path; @@ -155,15 +157,17 @@ static wchar_t *ddrhook1_filesystem_get_path(LPCWSTR path) if (sub_path && launcher_folder) { wchar_t *launcher_folder_w = str_widen(launcher_folder); - new_path = (wchar_t*)xmalloc(MAX_PATH * sizeof(wchar_t)); - swprintf(new_path, MAX_PATH, L"%s\\%s", launcher_folder_w, sub_path); + new_path = (wchar_t *) xmalloc(MAX_PATH * sizeof(wchar_t)); + swprintf( + new_path, MAX_PATH, L"%s\\%s", launcher_folder_w, sub_path); free(launcher_folder_w); return new_path; } - } else if (wstr_insensitive_eq(path, L"F:/update") - || wstr_insensitive_eq(path, L"F:\\update") - || wstr_insensitive_eq(path, L".\\F:/update") - || wstr_insensitive_eq(path, L".\\F:\\update")) { + } else if ( + wstr_insensitive_eq(path, L"F:/update") || + wstr_insensitive_eq(path, L"F:\\update") || + wstr_insensitive_eq(path, L".\\F:/update") || + wstr_insensitive_eq(path, L".\\F:\\update")) { char *launcher_folder; wchar_t *sub_path; @@ -172,33 +176,40 @@ static wchar_t *ddrhook1_filesystem_get_path(LPCWSTR path) if (sub_path && launcher_folder) { wchar_t *launcher_folder_w = str_widen(launcher_folder); - new_path = (wchar_t*)xmalloc(MAX_PATH * sizeof(wchar_t)); - swprintf(new_path, MAX_PATH, L"%s\\%s", launcher_folder_w, sub_path); + new_path = (wchar_t *) xmalloc(MAX_PATH * sizeof(wchar_t)); + swprintf( + new_path, MAX_PATH, L"%s\\%s", launcher_folder_w, sub_path); free(launcher_folder_w); return new_path; } - } else if (wcslen(path) >= 24 && (wcsnicmp(path, L"D:/JDX/JDX-001/contents/", 24) == 0 - || wcsnicmp(path, L"D:\\JDX\\JDX-001\\contents\\", 24) == 0)) { + } else if ( + wcslen(path) >= 24 && + (wcsnicmp(path, L"D:/JDX/JDX-001/contents/", 24) == 0 || + wcsnicmp(path, L"D:\\JDX\\JDX-001\\contents\\", 24) == 0)) { char *content_path; ddrhook1_get_launcher_path_parts(&content_path, NULL); if (content_path) { wchar_t *content_path_w = str_widen(content_path); - new_path = (wchar_t*)xmalloc(MAX_PATH * sizeof(wchar_t)); + new_path = (wchar_t *) xmalloc(MAX_PATH * sizeof(wchar_t)); swprintf(new_path, MAX_PATH, L"%s\\%s", content_path_w, path + 24); free(content_path_w); return new_path; } - } else if (wcslen(path) >= 7 && (wcsnicmp(path, L"D:/HDX/", 7) == 0 || wcsnicmp(path, L"D:\\HDX\\", 7) == 0 - || wcsnicmp(path, L"D:/JDX/", 7) == 0 || wcsnicmp(path, L"D:\\JDX\\", 7) == 0)) { + } else if ( + wcslen(path) >= 7 && + (wcsnicmp(path, L"D:/HDX/", 7) == 0 || + wcsnicmp(path, L"D:\\HDX\\", 7) == 0 || + wcsnicmp(path, L"D:/JDX/", 7) == 0 || + wcsnicmp(path, L"D:\\JDX\\", 7) == 0)) { char *content_path; ddrhook1_get_launcher_path_parts(&content_path, NULL); if (content_path) { wchar_t *content_path_w = str_widen(content_path); - new_path = (wchar_t*)xmalloc(MAX_PATH * sizeof(wchar_t)); + new_path = (wchar_t *) xmalloc(MAX_PATH * sizeof(wchar_t)); swprintf(new_path, MAX_PATH, L"%s\\%s", content_path_w, path + 7); free(content_path_w); return new_path; @@ -225,7 +236,10 @@ static BOOL STDCALL my_SetCurrentDirectoryA(LPCSTR lpPathName) if (new_path != NULL) { bool r = real_SetCurrentDirectoryA(new_path); - log_misc("SetCurrentDirectoryA remapped path %s -> %s", lpPathName, new_path); + log_misc( + "SetCurrentDirectoryA remapped path %s -> %s", + lpPathName, + new_path); free(new_path); return r; } @@ -233,16 +247,13 @@ static BOOL STDCALL my_SetCurrentDirectoryA(LPCSTR lpPathName) return real_SetCurrentDirectoryA(lpPathName); } -static HANDLE STDCALL my_FindFirstFileW( - LPCWSTR lpFileName, - LPWIN32_FIND_DATAA lpFindFileData) +static HANDLE STDCALL +my_FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData) { wchar_t *new_path = ddrhook1_filesystem_get_path(lpFileName); if (new_path) { - HANDLE r = real_FindFirstFileW( - new_path, - lpFindFileData); + HANDLE r = real_FindFirstFileW(new_path, lpFindFileData); char *tmp; wstr_narrow(new_path, &tmp); @@ -253,9 +264,7 @@ static HANDLE STDCALL my_FindFirstFileW( return r; } - return real_FindFirstFileW( - lpFileName, - lpFindFileData); + return real_FindFirstFileW(lpFileName, lpFindFileData); } static HANDLE STDCALL my_CreateFileW( @@ -321,7 +330,10 @@ BOOL WINAPI my_CreateDirectoryW( void ddrhook1_filesystem_hook_init() { hook_table_apply( - NULL, "kernel32.dll", filesystem_hook_syms, lengthof(filesystem_hook_syms)); + NULL, + "kernel32.dll", + filesystem_hook_syms, + lengthof(filesystem_hook_syms)); log_info("Inserted filesystem hooks"); } \ No newline at end of file diff --git a/src/main/ddrhook2/dllmain.c b/src/main/ddrhook2/dllmain.c index 715c09f..9035551 100644 --- a/src/main/ddrhook2/dllmain.c +++ b/src/main/ddrhook2/dllmain.c @@ -75,7 +75,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) case 'a': /* Specify a USB memory path for P1 */ if (i + 1 < argc) { - strcpy(usbmem_data_path_p1, argv[i+1]); + strcpy(usbmem_data_path_p1, argv[i + 1]); usbmem_enabled = true; i++; // Move forward one to skip the path parameter } @@ -85,7 +85,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) case 'b': /* Specify a USB memory path for P2 */ if (i + 1 < argc) { - strcpy(usbmem_data_path_p2, argv[i+1]); + strcpy(usbmem_data_path_p2, argv[i + 1]); usbmem_enabled = true; i++; // Move forward one to skip the path parameter } @@ -134,7 +134,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) eam_io_set_loggers( log_body_misc, log_body_info, log_body_warning, log_body_fatal); - ok = eam_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy); + ok = + eam_io_init(avs_thread_create, avs_thread_join, avs_thread_destroy); if (!ok) { return false; diff --git a/src/main/ddrhook2/master.c b/src/main/ddrhook2/master.c index 01ed02b..89f874f 100644 --- a/src/main/ddrhook2/master.c +++ b/src/main/ddrhook2/master.c @@ -16,7 +16,6 @@ static HMODULE(STDCALL *real_LoadLibraryA)(const char *name); static HMODULE STDCALL my_LoadLibraryA(const char *name); - static const hook_d3d9_irp_handler_t ddrhook2_d3d9_handlers[] = { gfx_d3d9_irp_handler, }; diff --git a/src/main/ddrio-smx/ddrio.c b/src/main/ddrio-smx/ddrio.c index 3015037..a7cda33 100644 --- a/src/main/ddrio-smx/ddrio.c +++ b/src/main/ddrio-smx/ddrio.c @@ -43,20 +43,49 @@ static const struct ddr_io_smx_pad_map ddr_io_smx_pad_map[] = { #define DDR_IO_SMX_LIGHT_VALUES_PER_PANEL 75 #define DDR_IO_SMX_NUMBER_OF_PANELS 18 -#define DDR_IO_SMX_TOTAL_LIGHT_VALUES DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * DDR_IO_SMX_NUMBER_OF_PANELS +#define DDR_IO_SMX_TOTAL_LIGHT_VALUES \ + DDR_IO_SMX_LIGHT_VALUES_PER_PANEL *DDR_IO_SMX_NUMBER_OF_PANELS static const struct ddr_io_smx_light_map ddr_io_smx_light_map[] = { /* Light L/R blue and U/D red to match DDR pad color scheme */ {1 << LIGHT_P1_UP, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 1, 0xFF, 0x00, 0x00}, - {1 << LIGHT_P1_LEFT, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 3, 0x00, 0x00, 0xFF}, - {1 << LIGHT_P1_RIGHT, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 5, 0x00, 0x00, 0xFF}, - {1 << LIGHT_P1_DOWN, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 7, 0xFF, 0x00, 0x00}, + {1 << LIGHT_P1_LEFT, + DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 3, + 0x00, + 0x00, + 0xFF}, + {1 << LIGHT_P1_RIGHT, + DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 5, + 0x00, + 0x00, + 0xFF}, + {1 << LIGHT_P1_DOWN, + DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 7, + 0xFF, + 0x00, + 0x00}, - {1 << LIGHT_P2_UP, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 10, 0xFF, 0x00, 0x00}, - {1 << LIGHT_P2_LEFT, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 12, 0x00, 0x00, 0xFF}, - {1 << LIGHT_P2_RIGHT, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 14, 0x00, 0x00, 0xFF}, - {1 << LIGHT_P2_DOWN, DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 16, 0xFF, 0x00, 0x00}, + {1 << LIGHT_P2_UP, + DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 10, + 0xFF, + 0x00, + 0x00}, + {1 << LIGHT_P2_LEFT, + DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 12, + 0x00, + 0x00, + 0xFF}, + {1 << LIGHT_P2_RIGHT, + DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 14, + 0x00, + 0x00, + 0xFF}, + {1 << LIGHT_P2_DOWN, + DDR_IO_SMX_LIGHT_VALUES_PER_PANEL * 16, + 0xFF, + 0x00, + 0x00}, }; static _Atomic uint32_t ddr_io_smx_pad_state[2]; diff --git a/src/main/eamio-icca/eamio-icca.c b/src/main/eamio-icca/eamio-icca.c index 86fbce2..c681610 100644 --- a/src/main/eamio-icca/eamio-icca.c +++ b/src/main/eamio-icca/eamio-icca.c @@ -8,9 +8,9 @@ #include #include -#include "aciomgr/manager.h" #include "aciodrv/device.h" #include "aciodrv/icca.h" +#include "aciomgr/manager.h" #include "bemanitools/eamio.h" @@ -23,22 +23,23 @@ #define NUMBER_OF_EMULATED_READERS 2 #define INVALID_NODE_ID -1 -static const uint8_t eam_io_keypad_mappings[16] = {EAM_IO_KEYPAD_DECIMAL, - EAM_IO_KEYPAD_3, - EAM_IO_KEYPAD_6, - EAM_IO_KEYPAD_9, - 0xFF, - 0xFF, - 0xFF, - 0xFF, - EAM_IO_KEYPAD_0, - EAM_IO_KEYPAD_1, - EAM_IO_KEYPAD_4, - EAM_IO_KEYPAD_7, - EAM_IO_KEYPAD_00, - EAM_IO_KEYPAD_2, - EAM_IO_KEYPAD_5, - EAM_IO_KEYPAD_8}; +static const uint8_t eam_io_keypad_mappings[16] = { + EAM_IO_KEYPAD_DECIMAL, + EAM_IO_KEYPAD_3, + EAM_IO_KEYPAD_6, + EAM_IO_KEYPAD_9, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + EAM_IO_KEYPAD_0, + EAM_IO_KEYPAD_1, + EAM_IO_KEYPAD_4, + EAM_IO_KEYPAD_7, + EAM_IO_KEYPAD_00, + EAM_IO_KEYPAD_2, + EAM_IO_KEYPAD_5, + EAM_IO_KEYPAD_8}; static struct ac_io_icca_state eam_io_icca_state[NUMBER_OF_EMULATED_READERS]; @@ -119,7 +120,8 @@ bool eam_io_init( for (uint8_t i = 0; i < NUMBER_OF_EMULATED_READERS; i++) { icca_node_id[i] = INVALID_NODE_ID; - for (uint8_t nid = 0; nid < aciomgr_get_node_count(acio_manager_ctx); ++nid) { + for (uint8_t nid = 0; nid < aciomgr_get_node_count(acio_manager_ctx); + ++nid) { if (check_if_icca(nid)) { bool existing_reader = false; @@ -139,7 +141,8 @@ bool eam_io_init( icca_is_slotted[i] = aciodrv_icca_is_slotted(device, nid); icca_last_nonbusy_state[i] = 0; - log_misc("ICC reader %d is_slotted: %d", nid, icca_is_slotted[i]); + log_misc( + "ICC reader %d is_slotted: %d", nid, icca_is_slotted[i]); if (!aciodrv_icca_init(device, icca_node_id[i])) { log_warning("Initializing icca %d failed", i); @@ -187,25 +190,28 @@ uint8_t eam_io_get_sensor_state(uint8_t unit_no) if (icca_is_slotted[unit_no]) { if ((eam_io_icca_state[unit_no].sensor_state & - AC_IO_ICCA_SENSOR_MASK_BACK_ON) > 0) { + AC_IO_ICCA_SENSOR_MASK_BACK_ON) > 0) { sensors |= (1 << EAM_IO_SENSOR_BACK); } if ((eam_io_icca_state[unit_no].sensor_state & - AC_IO_ICCA_SENSOR_MASK_FRONT_ON) > 0) { + AC_IO_ICCA_SENSOR_MASK_FRONT_ON) > 0) { sensors |= (1 << EAM_IO_SENSOR_FRONT); } } else { - // wavepass readers always report (EAM_IO_SENSOR_BACK + EAM_IO_SENSOR_FRONT) + type - // but because we can't report status_code back directly - // and libacio actually just ignores the sensor_state other then the type - // we just return this state like we're a slotted reader so the emulation takes card of it - if (eam_io_icca_state[unit_no].status_code == AC_IO_ICCA_STATUS_GOT_UID) { + // wavepass readers always report (EAM_IO_SENSOR_BACK + + // EAM_IO_SENSOR_FRONT) + type but because we can't report status_code + // back directly and libacio actually just ignores the sensor_state + // other then the type we just return this state like we're a slotted + // reader so the emulation takes card of it + if (eam_io_icca_state[unit_no].status_code == + AC_IO_ICCA_STATUS_GOT_UID) { sensors |= (1 << EAM_IO_SENSOR_BACK); sensors |= (1 << EAM_IO_SENSOR_FRONT); } // continue reporting last state during busy - if (eam_io_icca_state[unit_no].status_code == AC_IO_ICCA_STATUS_BUSY_NEW) { + if (eam_io_icca_state[unit_no].status_code == + AC_IO_ICCA_STATUS_BUSY_NEW) { sensors = icca_last_nonbusy_state[unit_no]; } else { icca_last_nonbusy_state[unit_no] = sensors; @@ -243,18 +249,28 @@ bool eam_io_card_slot_cmd(uint8_t unit_no, uint8_t cmd) switch (cmd) { case EAM_IO_CARD_SLOT_CMD_CLOSE: response = aciodrv_icca_set_state( - device, icca_node_id[unit_no], AC_IO_ICCA_SLOT_STATE_CLOSE, NULL); + device, + icca_node_id[unit_no], + AC_IO_ICCA_SLOT_STATE_CLOSE, + NULL); case EAM_IO_CARD_SLOT_CMD_OPEN: response = aciodrv_icca_set_state( - device, icca_node_id[unit_no], AC_IO_ICCA_SLOT_STATE_OPEN, NULL); + device, + icca_node_id[unit_no], + AC_IO_ICCA_SLOT_STATE_OPEN, + NULL); case EAM_IO_CARD_SLOT_CMD_EJECT: response = aciodrv_icca_set_state( - device, icca_node_id[unit_no], AC_IO_ICCA_SLOT_STATE_EJECT, NULL); + device, + icca_node_id[unit_no], + AC_IO_ICCA_SLOT_STATE_EJECT, + NULL); case EAM_IO_CARD_SLOT_CMD_READ: - response = aciodrv_icca_read_card(device, icca_node_id[unit_no], NULL) && + response = + aciodrv_icca_read_card(device, icca_node_id[unit_no], NULL) && aciodrv_icca_get_state( device, icca_node_id[unit_no], &eam_io_icca_state[unit_no]); @@ -281,17 +297,18 @@ bool eam_io_poll(uint8_t unit_no) if (response && !icca_is_slotted[unit_no]) { // we handle wavepass a bit differently to handle polling felica - if (eam_io_icca_state[unit_no].status_code != AC_IO_ICCA_STATUS_BUSY_NEW) { + if (eam_io_icca_state[unit_no].status_code != + AC_IO_ICCA_STATUS_BUSY_NEW) { ++icca_poll_counter[unit_no]; } - // we must manually call this every few polls to actually update the felica state - // we don't do it every poll, since card polling isn't that time sensitive of an operation - // libacio does it every 5ish polls after the last AC_IO_ICCA_STATUS_BUSY_NEW message + // we must manually call this every few polls to actually update the + // felica state we don't do it every poll, since card polling isn't that + // time sensitive of an operation libacio does it every 5ish polls after + // the last AC_IO_ICCA_STATUS_BUSY_NEW message if (icca_poll_counter[unit_no] >= IDLE_RESPONSES_BETWEEN_FELICA_POLLS) { response = aciodrv_icca_poll_felica( - aciomgr_port_checkout(acio_manager_ctx), - icca_node_id[unit_no]); + aciomgr_port_checkout(acio_manager_ctx), icca_node_id[unit_no]); aciomgr_port_checkin(acio_manager_ctx); icca_poll_counter[unit_no] = 0; diff --git a/src/main/eamio/eam-impl.c b/src/main/eamio/eam-impl.c index 4ddb2c3..0c41709 100644 --- a/src/main/eamio/eam-impl.c +++ b/src/main/eamio/eam-impl.c @@ -333,7 +333,7 @@ bool eam_impl_get_sensor_state(struct eam *eam, uint8_t unit_no) } if (unit->sensor_hot) { - if ((int32_t)(unit->sensor_time - now) > 0) { + if ((int32_t) (unit->sensor_time - now) > 0) { result = true; } else { unit->sensor_time = 0; diff --git a/src/main/ezusb-emu/conf.h b/src/main/ezusb-emu/conf.h index 11f8e9f..b1713bb 100644 --- a/src/main/ezusb-emu/conf.h +++ b/src/main/ezusb-emu/conf.h @@ -1,7 +1,7 @@ #ifndef EZUSB_EMU_CONF_H #define EZUSB_EMU_CONF_H -//#define EZUSB_EMU_DEBUG_DUMP -//#define EZUSB_EMU_FW_DUMP +// #define EZUSB_EMU_DEBUG_DUMP +// #define EZUSB_EMU_FW_DUMP #endif \ No newline at end of file diff --git a/src/main/ezusb-emu/desc.c b/src/main/ezusb-emu/desc.c index f4ef050..ffa5577 100644 --- a/src/main/ezusb-emu/desc.c +++ b/src/main/ezusb-emu/desc.c @@ -2,10 +2,11 @@ const struct ezusb_emu_desc_device ezusb_emu_desc_device = { .setupapi = - {.device_guid = {0xAE18AA60, - 0x7F6A, - 0x11D4, - {0x97, 0xDD, 0x00, 0x01, 0x02, 0x29, 0xB9, 0x59}}, + {.device_guid = + {0xAE18AA60, + 0x7F6A, + 0x11D4, + {0x97, 0xDD, 0x00, 0x01, 0x02, 0x29, 0xB9, 0x59}}, .device_desc = "Cypress EZ-USB (2235) - EEPROM missing", .device_path = "\\\\.\\Ezusb-0"}, .vid = 0x0547, diff --git a/src/main/ezusb-emu/node-security-plug.c b/src/main/ezusb-emu/node-security-plug.c index c6c7a07..5524921 100644 --- a/src/main/ezusb-emu/node-security-plug.c +++ b/src/main/ezusb-emu/node-security-plug.c @@ -16,8 +16,10 @@ static struct security_mcode ezusb_iidx_emu_node_security_plug_boot_version; static uint32_t ezusb_iidx_emu_node_security_plug_boot_seeds[3]; -static struct security_rp_sign_key ezusb_iidx_emu_node_security_plug_black_sign_key; -static struct security_rp_sign_key ezusb_iidx_emu_node_security_plug_white_sign_key; +static struct security_rp_sign_key + ezusb_iidx_emu_node_security_plug_black_sign_key; +static struct security_rp_sign_key + ezusb_iidx_emu_node_security_plug_white_sign_key; static struct security_mcode ezusb_iidx_emu_node_security_plug_black_mcode; static struct security_mcode ezusb_iidx_emu_node_security_plug_white_mcode; @@ -223,8 +225,9 @@ uint8_t ezusb_iidx_emu_node_security_plug_process_cmd_v2( // pop'n music only ever uses slot 2 (white) and slot 4 (black). // If the configuration does not match then it will error out. - // IIDX uses slots 2 and 3 and detects what is plugged into each slot so ordering isn't important. - // IIDX also reads slot 1's data section but doesn't care what dongle it is? + // IIDX uses slots 2 and 3 and detects what is plugged into each slot so + // ordering isn't important. IIDX also reads slot 1's data section but + // doesn't care what dongle it is? case EZUSB_IIDX_SECPLUG_CMD_V2_SELECT_DONGLE_1: log_misc("EZUSB_IIDX_SECPLUG_CMD_V2_SELECT_DONGLE_1"); ezusb_iidx_emu_node_security_plug_active_dongle_slot = diff --git a/src/main/ezusb-emu/nodes.c b/src/main/ezusb-emu/nodes.c index 0dfd1a1..8e5fcb9 100644 --- a/src/main/ezusb-emu/nodes.c +++ b/src/main/ezusb-emu/nodes.c @@ -12,8 +12,8 @@ #include "ezusb-emu/node-security-plug.h" #include "ezusb-emu/node-sram.h" #include "ezusb-emu/node-wdt.h" -#include "ezusb-emu/nodes.h" #include "ezusb-emu/node.h" +#include "ezusb-emu/nodes.h" /* All IIDX games */ const struct ezusb_iidx_emu_node ezusb_iidx_emu_node_coin = { diff --git a/src/main/ezusb-iidx-emu/msg.c b/src/main/ezusb-iidx-emu/msg.c index 55b94e1..d85bc88 100644 --- a/src/main/ezusb-iidx-emu/msg.c +++ b/src/main/ezusb-iidx-emu/msg.c @@ -9,8 +9,8 @@ #include "hook/iohook.h" #include "ezusb-emu/msg.h" -#include "ezusb-emu/nodes.h" #include "ezusb-emu/node-coin.h" +#include "ezusb-emu/nodes.h" #include "ezusb-iidx/msg.h" diff --git a/src/main/ezusb-iidx/ezusb-iidx.c b/src/main/ezusb-iidx/ezusb-iidx.c index 35962b7..e82e214 100644 --- a/src/main/ezusb-iidx/ezusb-iidx.c +++ b/src/main/ezusb-iidx/ezusb-iidx.c @@ -10,7 +10,7 @@ #include "msg.h" -//#define DEBUG_DUMP +// #define DEBUG_DUMP /* For debugging */ #ifdef DEBUG_DUMP diff --git a/src/main/ezusb-iidx/msg.h b/src/main/ezusb-iidx/msg.h index 5f81f8d..1c4bf2f 100644 --- a/src/main/ezusb-iidx/msg.h +++ b/src/main/ezusb-iidx/msg.h @@ -59,10 +59,9 @@ struct ezusb_iidx_msg_interrupt_read_packet { 1: Not used 2: Not used 3: Not used - 4: C02/D01 board identifier, 1 = C02, 0 = D01 (on active low). This defines how the game has - to flash the FPGA board since D01 needs a different firmware (see result of FPGA CHECK on - game bootup) - 5: Not used + 4: C02/D01 board identifier, 1 = C02, 0 = D01 (on active low). This + defines how the game has to flash the FPGA board since D01 needs a + different firmware (see result of FPGA CHECK on game bootup) 5: Not used 6: usb mute? 7: Not used diff --git a/src/main/ezusb2-emu/conf.h b/src/main/ezusb2-emu/conf.h index 403de9d..30a67f8 100644 --- a/src/main/ezusb2-emu/conf.h +++ b/src/main/ezusb2-emu/conf.h @@ -1,7 +1,7 @@ #ifndef EZUSB2_EMU_CONF_H #define EZUSB_2EMU_CONF_H -//#define EZUSB2_EMU_DEBUG_DUMP -//#define EZUSB2_EMU_FW_DUMP +// #define EZUSB2_EMU_DEBUG_DUMP +// #define EZUSB2_EMU_FW_DUMP #endif \ No newline at end of file diff --git a/src/main/ezusb2-emu/desc.c b/src/main/ezusb2-emu/desc.c index 68b0916..dfbf4d0 100644 --- a/src/main/ezusb2-emu/desc.c +++ b/src/main/ezusb2-emu/desc.c @@ -2,10 +2,11 @@ const struct ezusb_emu_desc_device ezusb2_emu_desc_device = { .setupapi = - {.device_guid = {0xAE18AA60, - 0x7F6A, - 0x11D4, - {0x97, 0xDD, 0x00, 0x01, 0x02, 0x29, 0xB9, 0x59}}, + {.device_guid = + {0xAE18AA60, + 0x7F6A, + 0x11D4, + {0x97, 0xDD, 0x00, 0x01, 0x02, 0x29, 0xB9, 0x59}}, .device_desc = "Cypress EZ-USB FX2LP - EEPROM missing", .device_path = "\\\\.\\Ezusb-0"}, .vid = 0x04B4, diff --git a/src/main/ezusb2-popn-emu/msg.c b/src/main/ezusb2-popn-emu/msg.c index ad83059..1c4e3fb 100644 --- a/src/main/ezusb2-popn-emu/msg.c +++ b/src/main/ezusb2-popn-emu/msg.c @@ -10,11 +10,11 @@ #include "ezusb-emu/msg.h" -#include "ezusb-emu/nodes.h" -#include "ezusb-emu/node-none.h" #include "ezusb-emu/node-coin.h" +#include "ezusb-emu/node-none.h" #include "ezusb-emu/node-security-mem.h" #include "ezusb-emu/node-security-plug.h" +#include "ezusb-emu/nodes.h" #include "ezusb2-popn/msg.h" @@ -66,7 +66,10 @@ struct ezusb_emu_msg_hook *ezusb2_popn_emu_msg_init(void) } } - memset(&ezusb2_popn_emu_msg_history[0], 0xff, sizeof(ezusb2_popn_emu_msg_history)); + memset( + &ezusb2_popn_emu_msg_history[0], + 0xff, + sizeof(ezusb2_popn_emu_msg_history)); return &ezusb2_popn_emu_msg_hook; } @@ -94,11 +97,17 @@ static HRESULT ezusb2_popn_emu_msg_interrupt_read(struct iobuf *read) msg_resp->unk7 = 0xdf; msg_resp->unk8 = ezusb2_popn_emu_msg_seq_no; - memcpy(&msg_resp->button_history[0], &ezusb2_popn_emu_msg_history[0], sizeof(uint16_t) * 10); + memcpy( + &msg_resp->button_history[0], + &ezusb2_popn_emu_msg_history[0], + sizeof(uint16_t) * 10); read->pos = sizeof(*msg_resp); - memmove(&ezusb2_popn_emu_msg_history[1], &ezusb2_popn_emu_msg_history[0], sizeof(uint16_t) * 9); + memmove( + &ezusb2_popn_emu_msg_history[1], + &ezusb2_popn_emu_msg_history[0], + sizeof(uint16_t) * 9); ezusb2_popn_emu_msg_history[0] = msg_resp->io.button; return S_OK; @@ -126,7 +135,8 @@ static HRESULT ezusb2_popn_emu_msg_interrupt_write(struct const_iobuf *write) popn_io_set_top_lights(msg_req->lamp & 0x1f); popn_io_set_side_lights((msg_req->lamp >> 8) & 0xf); popn_io_set_button_lights((msg_req->lamp >> 20) & 0xfff); - popn_io_set_coin_counter_light(((msg_req->lamp >> 12) & 0xf) == 0); // Active low + popn_io_set_coin_counter_light( + ((msg_req->lamp >> 12) & 0xf) == 0); // Active low popn_io_set_coin_blocker_light(((msg_req->lamp >> 16) & 0xf) == 0xf); /* Remember node for next bulk read */ diff --git a/src/main/ezusb2-popn-shim/dllmain.c b/src/main/ezusb2-popn-shim/dllmain.c index b8011c9..c8e16fc 100644 --- a/src/main/ezusb2-popn-shim/dllmain.c +++ b/src/main/ezusb2-popn-shim/dllmain.c @@ -1,6 +1,6 @@ -#include -#include #include +#include +#include #include @@ -23,8 +23,7 @@ static HMODULE real_pe = NULL; BOOL WINAPI DllMain(HMODULE self, DWORD reason, void *ctx) { - if (reason == DLL_PROCESS_ATTACH && real_pe == NULL) - { + if (reason == DLL_PROCESS_ATTACH && real_pe == NULL) { pe_hijack_entrypoint(EZUSB_REAL_DLL_FILENAME, &real_entrypoint); real_pe = GetModuleHandleA(EZUSB_REAL_DLL_FILENAME); diff --git a/src/main/ezusb2-popn-shim/proxy.c b/src/main/ezusb2-popn-shim/proxy.c index 3797ca0..fdf4f9f 100644 --- a/src/main/ezusb2-popn-shim/proxy.c +++ b/src/main/ezusb2-popn-shim/proxy.c @@ -1,17 +1,21 @@ -#include -#include #include +#include +#include #include "util/log.h" struct CoinParam; struct EEP_HISTORY; -typedef int32_t (*usb_boot_security_t)(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4); -typedef int32_t (*usb_boot_security_all_t)(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4); -typedef int32_t (*usb_boot_security_all_r_t)(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4); +typedef int32_t (*usb_boot_security_t)( + uint8_t *param1, int32_t param2, int32_t param3, int32_t param4); +typedef int32_t (*usb_boot_security_all_t)( + uint8_t *param1, int32_t param2, int32_t param3, int32_t param4); +typedef int32_t (*usb_boot_security_all_r_t)( + uint8_t *param1, int32_t param2, int32_t param3, int32_t param4); typedef int32_t (*usb_check_alive_t)(); -typedef int32_t (*usb_check_security_t)(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4); +typedef int32_t (*usb_check_security_t)( + uint8_t *param1, int32_t param2, int32_t param3, int32_t param4); typedef int32_t (*usb_check_security_eep_t)(int32_t param1); typedef int32_t (*usb_check_security_new_t)(int32_t param1); typedef int32_t (*usb_coin_blocker_t)(int32_t param1); @@ -54,12 +58,30 @@ typedef int32_t (*usb_security_test_t)(int32_t param1); typedef int32_t (*usb_security_write_t)(uint8_t *param1); typedef int32_t (*usb_security_write_done_t)(); typedef int32_t (*usb_set_ext_io_t)(int32_t param1); -typedef int32_t (*usb_setup_eeprom_t)(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4); -typedef int32_t (*usb_setup_eeprom_new_t)(int32_t param1, uint8_t *param2, int32_t param3, int32_t param4, int32_t param5); -typedef int32_t (*usb_setup_security_t)(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4); -typedef int32_t (*usb_setup_security_complete_t)(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4); -typedef int32_t (*usb_setup_security_complete_new_t)(int32_t param1, uint8_t *param2, int32_t param3, int32_t param4, int32_t param5); -typedef int32_t (*usb_setup_security_new_t)(int32_t param1, uint8_t *param2, int32_t param3, int32_t param4, int32_t param5); +typedef int32_t (*usb_setup_eeprom_t)( + uint8_t *param1, int32_t param2, int32_t param3, int32_t param4); +typedef int32_t (*usb_setup_eeprom_new_t)( + int32_t param1, + uint8_t *param2, + int32_t param3, + int32_t param4, + int32_t param5); +typedef int32_t (*usb_setup_security_t)( + uint8_t *param1, int32_t param2, int32_t param3, int32_t param4); +typedef int32_t (*usb_setup_security_complete_t)( + uint8_t *param1, int32_t param2, int32_t param3, int32_t param4); +typedef int32_t (*usb_setup_security_complete_new_t)( + int32_t param1, + uint8_t *param2, + int32_t param3, + int32_t param4, + int32_t param5); +typedef int32_t (*usb_setup_security_new_t)( + int32_t param1, + uint8_t *param2, + int32_t param3, + int32_t param4, + int32_t param5); typedef int32_t (*usb_start_t)(int32_t param1); typedef int32_t (*usb_start_with_file_t)(char *param1); typedef int32_t (*usb_wdt_reset_t)(); @@ -138,195 +160,254 @@ void ezusb2_proxy_initialize(HMODULE pe) proxy_is_initialized = true; - real_usb_boot_security = (usb_boot_security_t)GetProcAddress(pe, "?usbBootSecurity@@YAHPAEHHH@Z"); - log_assert(real_usb_boot_security); + real_usb_boot_security = (usb_boot_security_t) GetProcAddress( + pe, "?usbBootSecurity@@YAHPAEHHH@Z"); + log_assert(real_usb_boot_security); - real_usb_boot_security_all = (usb_boot_security_all_t)GetProcAddress(pe, "?usbBootSecurityAll@@YAHPAEHHH@Z"); - log_assert(real_usb_boot_security_all); + real_usb_boot_security_all = (usb_boot_security_all_t) GetProcAddress( + pe, "?usbBootSecurityAll@@YAHPAEHHH@Z"); + log_assert(real_usb_boot_security_all); - real_usb_boot_security_all_r = (usb_boot_security_all_r_t)GetProcAddress(pe, "?usbBootSecurityAllR@@YAHPAEHHH@Z"); - log_assert(real_usb_boot_security_all_r); + real_usb_boot_security_all_r = (usb_boot_security_all_r_t) GetProcAddress( + pe, "?usbBootSecurityAllR@@YAHPAEHHH@Z"); + log_assert(real_usb_boot_security_all_r); - real_usb_check_alive = (usb_check_alive_t)GetProcAddress(pe, "?usbCheckAlive@@YAHXZ"); - log_assert(real_usb_check_alive); + real_usb_check_alive = + (usb_check_alive_t) GetProcAddress(pe, "?usbCheckAlive@@YAHXZ"); + log_assert(real_usb_check_alive); - real_usb_check_security = (usb_check_security_t)GetProcAddress(pe, "?usbCheckSecurity@@YAHPAEHHH@Z"); - log_assert(real_usb_check_security); + real_usb_check_security = (usb_check_security_t) GetProcAddress( + pe, "?usbCheckSecurity@@YAHPAEHHH@Z"); + log_assert(real_usb_check_security); - real_usb_check_security_eep = (usb_check_security_eep_t)GetProcAddress(pe, "?usbCheckSecurityEep@@YAHH@Z"); - log_assert(real_usb_check_security_eep); + real_usb_check_security_eep = (usb_check_security_eep_t) GetProcAddress( + pe, "?usbCheckSecurityEep@@YAHH@Z"); + log_assert(real_usb_check_security_eep); - real_usb_check_security_new = (usb_check_security_new_t)GetProcAddress(pe, "?usbCheckSecurityNew@@YAHH@Z"); - log_assert(real_usb_check_security_new); + real_usb_check_security_new = (usb_check_security_new_t) GetProcAddress( + pe, "?usbCheckSecurityNew@@YAHH@Z"); + log_assert(real_usb_check_security_new); - real_usb_coin_blocker = (usb_coin_blocker_t)GetProcAddress(pe, "?usbCoinBlocker@@YAHH@Z"); - log_assert(real_usb_coin_blocker); + real_usb_coin_blocker = + (usb_coin_blocker_t) GetProcAddress(pe, "?usbCoinBlocker@@YAHH@Z"); + log_assert(real_usb_coin_blocker); - real_usb_coin_get2 = (usb_coin_get2_t)GetProcAddress(pe, "?usbCoinGet2@@YAHPAUCoinParam@@@Z"); - log_assert(real_usb_coin_get2); + real_usb_coin_get2 = (usb_coin_get2_t) GetProcAddress( + pe, "?usbCoinGet2@@YAHPAUCoinParam@@@Z"); + log_assert(real_usb_coin_get2); - real_usb_coin_get = (usb_coin_get_t)GetProcAddress(pe, "?usbCoinGet@@YAHH@Z"); - log_assert(real_usb_coin_get); + real_usb_coin_get = + (usb_coin_get_t) GetProcAddress(pe, "?usbCoinGet@@YAHH@Z"); + log_assert(real_usb_coin_get); - real_usb_coin_meter_down = (usb_coin_meter_down_t)GetProcAddress(pe, "?usbCoinMeterDown@@YAHH@Z"); - log_assert(real_usb_coin_meter_down); + real_usb_coin_meter_down = + (usb_coin_meter_down_t) GetProcAddress(pe, "?usbCoinMeterDown@@YAHH@Z"); + log_assert(real_usb_coin_meter_down); - real_usb_coin_meter_up = (usb_coin_meter_up_t)GetProcAddress(pe, "?usbCoinMeterUp@@YAHH@Z"); - log_assert(real_usb_coin_meter_up); + real_usb_coin_meter_up = + (usb_coin_meter_up_t) GetProcAddress(pe, "?usbCoinMeterUp@@YAHH@Z"); + log_assert(real_usb_coin_meter_up); - real_usb_coin_mode = (usb_coin_mode_t)GetProcAddress(pe, "?usbCoinMode@@YAHH@Z"); - log_assert(real_usb_coin_mode); + real_usb_coin_mode = + (usb_coin_mode_t) GetProcAddress(pe, "?usbCoinMode@@YAHH@Z"); + log_assert(real_usb_coin_mode); - real_usb_coin_up = (usb_coin_up_t)GetProcAddress(pe, "?usbCoinUp@@YAHH@Z"); - log_assert(real_usb_coin_up); + real_usb_coin_up = (usb_coin_up_t) GetProcAddress(pe, "?usbCoinUp@@YAHH@Z"); + log_assert(real_usb_coin_up); - real_usb_eep_read = (usb_eep_read_t)GetProcAddress(pe, "?usbEepRead@@YAHXZ"); - log_assert(real_usb_eep_read); + real_usb_eep_read = + (usb_eep_read_t) GetProcAddress(pe, "?usbEepRead@@YAHXZ"); + log_assert(real_usb_eep_read); - real_usb_eep_read_done = (usb_eep_read_done_t)GetProcAddress(pe, "?usbEepReadDone@@YAHPAE@Z"); - log_assert(real_usb_eep_read_done); + real_usb_eep_read_done = + (usb_eep_read_done_t) GetProcAddress(pe, "?usbEepReadDone@@YAHPAE@Z"); + log_assert(real_usb_eep_read_done); - real_usb_eep_test = (usb_eep_test_t)GetProcAddress(pe, "?usbEepTest@@YAHXZ"); - log_assert(real_usb_eep_test); + real_usb_eep_test = + (usb_eep_test_t) GetProcAddress(pe, "?usbEepTest@@YAHXZ"); + log_assert(real_usb_eep_test); - real_usb_eep_write = (usb_eep_write_t)GetProcAddress(pe, "?usbEepWrite@@YAHPAE@Z"); - log_assert(real_usb_eep_write); + real_usb_eep_write = + (usb_eep_write_t) GetProcAddress(pe, "?usbEepWrite@@YAHPAE@Z"); + log_assert(real_usb_eep_write); - real_usb_eep_write_done = (usb_eep_write_done_t)GetProcAddress(pe, "?usbEepWriteDone@@YAHXZ"); - log_assert(real_usb_eep_write_done); + real_usb_eep_write_done = + (usb_eep_write_done_t) GetProcAddress(pe, "?usbEepWriteDone@@YAHXZ"); + log_assert(real_usb_eep_write_done); - real_usb_end = (usb_end_t)GetProcAddress(pe, "?usbEnd@@YAHXZ"); - log_assert(real_usb_end); + real_usb_end = (usb_end_t) GetProcAddress(pe, "?usbEnd@@YAHXZ"); + log_assert(real_usb_end); - real_usb_factory_mode_init = (usb_factory_mode_init_t)GetProcAddress(pe, "?usbFactoryModeInit@@YAHPAE@Z"); - log_assert(real_usb_factory_mode_init); + real_usb_factory_mode_init = (usb_factory_mode_init_t) GetProcAddress( + pe, "?usbFactoryModeInit@@YAHPAE@Z"); + log_assert(real_usb_factory_mode_init); - real_usb_firm_result = (usb_firm_result_t)GetProcAddress(pe, "?usbFirmResult@@YAHXZ"); - log_assert(real_usb_firm_result); + real_usb_firm_result = + (usb_firm_result_t) GetProcAddress(pe, "?usbFirmResult@@YAHXZ"); + log_assert(real_usb_firm_result); - real_usb_get_error = (usb_get_error_t)GetProcAddress(pe, "?usbGetError@@YAHPAD@Z"); - log_assert(real_usb_get_error); + real_usb_get_error = + (usb_get_error_t) GetProcAddress(pe, "?usbGetError@@YAHPAD@Z"); + log_assert(real_usb_get_error); - real_usb_get_keyid = (usb_get_keyid_t)GetProcAddress(pe, "?usbGetKEYID@@YAHPAEH@Z"); - log_assert(real_usb_get_keyid); + real_usb_get_keyid = + (usb_get_keyid_t) GetProcAddress(pe, "?usbGetKEYID@@YAHPAEH@Z"); + log_assert(real_usb_get_keyid); - real_usb_get_mute = (usb_get_mute_t)GetProcAddress(pe, "?usbGetMute@@YAHXZ"); - log_assert(real_usb_get_mute); + real_usb_get_mute = + (usb_get_mute_t) GetProcAddress(pe, "?usbGetMute@@YAHXZ"); + log_assert(real_usb_get_mute); - real_usb_get_pcbid = (usb_get_pcbid_t)GetProcAddress(pe, "?usbGetPCBID@@YAHPAE@Z"); - log_assert(real_usb_get_pcbid); + real_usb_get_pcbid = + (usb_get_pcbid_t) GetProcAddress(pe, "?usbGetPCBID@@YAHPAE@Z"); + log_assert(real_usb_get_pcbid); - real_usb_get_security = (usb_get_security_t)GetProcAddress(pe, "?usbGetSecurity@@YAHHPAE@Z"); - log_assert(real_usb_get_security); + real_usb_get_security = + (usb_get_security_t) GetProcAddress(pe, "?usbGetSecurity@@YAHHPAE@Z"); + log_assert(real_usb_get_security); - real_usb_is_hi_speed = (usb_is_hi_speed_t)GetProcAddress(pe, "?usbIsHiSpeed@@YAHXZ"); - log_assert(real_usb_is_hi_speed); + real_usb_is_hi_speed = + (usb_is_hi_speed_t) GetProcAddress(pe, "?usbIsHiSpeed@@YAHXZ"); + log_assert(real_usb_is_hi_speed); - real_usb_lamp = (usb_lamp_t)GetProcAddress(pe, "?usbLamp@@YAHH@Z"); - log_assert(real_usb_lamp); + real_usb_lamp = (usb_lamp_t) GetProcAddress(pe, "?usbLamp@@YAHH@Z"); + log_assert(real_usb_lamp); - real_usb_mute = (usb_mute_t)GetProcAddress(pe, "?usbMute@@YAHH@Z"); - log_assert(real_usb_mute); + real_usb_mute = (usb_mute_t) GetProcAddress(pe, "?usbMute@@YAHH@Z"); + log_assert(real_usb_mute); - real_usb_pad_read = (usb_pad_read_t)GetProcAddress(pe, "?usbPadRead@@YAHPAK@Z"); - log_assert(real_usb_pad_read); + real_usb_pad_read = + (usb_pad_read_t) GetProcAddress(pe, "?usbPadRead@@YAHPAK@Z"); + log_assert(real_usb_pad_read); - real_usb_pad_read_last = (usb_pad_read_last_t)GetProcAddress(pe, "?usbPadReadLast@@YAHPAE@Z"); - log_assert(real_usb_pad_read_last); + real_usb_pad_read_last = + (usb_pad_read_last_t) GetProcAddress(pe, "?usbPadReadLast@@YAHPAE@Z"); + log_assert(real_usb_pad_read_last); - real_usb_read_eep_history = (usb_read_eep_history_t)GetProcAddress(pe, "?usbReadEepHistory@@YAHPAUEEP_HISTORY@@@Z"); - log_assert(real_usb_read_eep_history); + real_usb_read_eep_history = (usb_read_eep_history_t) GetProcAddress( + pe, "?usbReadEepHistory@@YAHPAUEEP_HISTORY@@@Z"); + log_assert(real_usb_read_eep_history); - real_usb_security_get_id = (usb_security_get_id_t)GetProcAddress(pe, "?usbSecurityGetId@@YAHXZ"); - log_assert(real_usb_security_get_id); + real_usb_security_get_id = + (usb_security_get_id_t) GetProcAddress(pe, "?usbSecurityGetId@@YAHXZ"); + log_assert(real_usb_security_get_id); - real_usb_security_get_id_done = (usb_security_get_id_done_t)GetProcAddress(pe, "?usbSecurityGetIdDone@@YAHPAE@Z"); - log_assert(real_usb_security_get_id_done); + real_usb_security_get_id_done = (usb_security_get_id_done_t) GetProcAddress( + pe, "?usbSecurityGetIdDone@@YAHPAE@Z"); + log_assert(real_usb_security_get_id_done); - real_usb_security_init = (usb_security_init_t)GetProcAddress(pe, "?usbSecurityInit@@YAHXZ"); - log_assert(real_usb_security_init); + real_usb_security_init = + (usb_security_init_t) GetProcAddress(pe, "?usbSecurityInit@@YAHXZ"); + log_assert(real_usb_security_init); - real_usb_security_init_done = (usb_security_init_done_t)GetProcAddress(pe, "?usbSecurityInitDone@@YAHXZ"); - log_assert(real_usb_security_init_done); + real_usb_security_init_done = (usb_security_init_done_t) GetProcAddress( + pe, "?usbSecurityInitDone@@YAHXZ"); + log_assert(real_usb_security_init_done); - real_usb_security_read = (usb_security_read_t)GetProcAddress(pe, "?usbSecurityRead@@YAHXZ"); - log_assert(real_usb_security_read); + real_usb_security_read = + (usb_security_read_t) GetProcAddress(pe, "?usbSecurityRead@@YAHXZ"); + log_assert(real_usb_security_read); - real_usb_security_read_done = (usb_security_read_done_t)GetProcAddress(pe, "?usbSecurityReadDone@@YAHPAE@Z"); - log_assert(real_usb_security_read_done); + real_usb_security_read_done = (usb_security_read_done_t) GetProcAddress( + pe, "?usbSecurityReadDone@@YAHPAE@Z"); + log_assert(real_usb_security_read_done); - real_usb_security_search = (usb_security_search_t)GetProcAddress(pe, "?usbSecuritySearch@@YAHXZ"); - log_assert(real_usb_security_search); + real_usb_security_search = + (usb_security_search_t) GetProcAddress(pe, "?usbSecuritySearch@@YAHXZ"); + log_assert(real_usb_security_search); - real_usb_security_search_done = (usb_security_search_done_t)GetProcAddress(pe, "?usbSecuritySearchDone@@YAHXZ"); - log_assert(real_usb_security_search_done); + real_usb_security_search_done = (usb_security_search_done_t) GetProcAddress( + pe, "?usbSecuritySearchDone@@YAHXZ"); + log_assert(real_usb_security_search_done); - real_usb_security_select = (usb_security_select_t)GetProcAddress(pe, "?usbSecuritySelect@@YAHH@Z"); - log_assert(real_usb_security_select); + real_usb_security_select = (usb_security_select_t) GetProcAddress( + pe, "?usbSecuritySelect@@YAHH@Z"); + log_assert(real_usb_security_select); - real_usb_security_select_done = (usb_security_select_done_t)GetProcAddress(pe, "?usbSecuritySelectDone@@YAHXZ"); - log_assert(real_usb_security_select_done); + real_usb_security_select_done = (usb_security_select_done_t) GetProcAddress( + pe, "?usbSecuritySelectDone@@YAHXZ"); + log_assert(real_usb_security_select_done); - real_usb_security_test = (usb_security_test_t)GetProcAddress(pe, "?usbSecurityTest@@YAHH@Z"); - log_assert(real_usb_security_test); + real_usb_security_test = + (usb_security_test_t) GetProcAddress(pe, "?usbSecurityTest@@YAHH@Z"); + log_assert(real_usb_security_test); - real_usb_security_write = (usb_security_write_t)GetProcAddress(pe, "?usbSecurityWrite@@YAHPAE@Z"); - log_assert(real_usb_security_write); + real_usb_security_write = (usb_security_write_t) GetProcAddress( + pe, "?usbSecurityWrite@@YAHPAE@Z"); + log_assert(real_usb_security_write); - real_usb_security_write_done = (usb_security_write_done_t)GetProcAddress(pe, "?usbSecurityWriteDone@@YAHXZ"); - log_assert(real_usb_security_write_done); + real_usb_security_write_done = (usb_security_write_done_t) GetProcAddress( + pe, "?usbSecurityWriteDone@@YAHXZ"); + log_assert(real_usb_security_write_done); - real_usb_set_ext_io = (usb_set_ext_io_t)GetProcAddress(pe, "?usbSetExtIo@@YAHH@Z"); - log_assert(real_usb_set_ext_io); + real_usb_set_ext_io = + (usb_set_ext_io_t) GetProcAddress(pe, "?usbSetExtIo@@YAHH@Z"); + log_assert(real_usb_set_ext_io); - real_usb_setup_eeprom = (usb_setup_eeprom_t)GetProcAddress(pe, "?usbSetupEeprom@@YAHPAEHHH@Z"); - log_assert(real_usb_setup_eeprom); + real_usb_setup_eeprom = + (usb_setup_eeprom_t) GetProcAddress(pe, "?usbSetupEeprom@@YAHPAEHHH@Z"); + log_assert(real_usb_setup_eeprom); - real_usb_setup_eeprom_new = (usb_setup_eeprom_new_t)GetProcAddress(pe, "?usbSetupEepromNew@@YAHHPAEHHH@Z"); - log_assert(real_usb_setup_eeprom_new); + real_usb_setup_eeprom_new = (usb_setup_eeprom_new_t) GetProcAddress( + pe, "?usbSetupEepromNew@@YAHHPAEHHH@Z"); + log_assert(real_usb_setup_eeprom_new); - real_usb_setup_security = (usb_setup_security_t)GetProcAddress(pe, "?usbSetupSecurity@@YAHPAEHHH@Z"); - log_assert(real_usb_setup_security); + real_usb_setup_security = (usb_setup_security_t) GetProcAddress( + pe, "?usbSetupSecurity@@YAHPAEHHH@Z"); + log_assert(real_usb_setup_security); - real_usb_setup_security_complete = (usb_setup_security_complete_t)GetProcAddress(pe, "?usbSetupSecurityComplete@@YAHPAEHHH@Z"); - log_assert(real_usb_setup_security_complete); + real_usb_setup_security_complete = + (usb_setup_security_complete_t) GetProcAddress( + pe, "?usbSetupSecurityComplete@@YAHPAEHHH@Z"); + log_assert(real_usb_setup_security_complete); - real_usb_setup_security_complete_new = (usb_setup_security_complete_new_t)GetProcAddress(pe, "?usbSetupSecurityCompleteNew@@YAHHPAEHHH@Z"); - log_assert(real_usb_setup_security_complete_new); + real_usb_setup_security_complete_new = + (usb_setup_security_complete_new_t) GetProcAddress( + pe, "?usbSetupSecurityCompleteNew@@YAHHPAEHHH@Z"); + log_assert(real_usb_setup_security_complete_new); - real_usb_setup_security_new = (usb_setup_security_new_t)GetProcAddress(pe, "?usbSetupSecurityNew@@YAHHPAEHHH@Z"); - log_assert(real_usb_setup_security_new); + real_usb_setup_security_new = (usb_setup_security_new_t) GetProcAddress( + pe, "?usbSetupSecurityNew@@YAHHPAEHHH@Z"); + log_assert(real_usb_setup_security_new); - real_usb_start = (usb_start_t)GetProcAddress(pe, "?usbStart@@YAHH@Z"); - log_assert(real_usb_start); + real_usb_start = (usb_start_t) GetProcAddress(pe, "?usbStart@@YAHH@Z"); + log_assert(real_usb_start); - real_usb_start_with_file = (usb_start_with_file_t)GetProcAddress(pe, "?usbStartWithFile@@YAHPAD@Z"); - log_assert(real_usb_start_with_file); + real_usb_start_with_file = (usb_start_with_file_t) GetProcAddress( + pe, "?usbStartWithFile@@YAHPAD@Z"); + log_assert(real_usb_start_with_file); - real_usb_wdt_reset = (usb_wdt_reset_t)GetProcAddress(pe, "?usbWdtReset@@YAHXZ"); - log_assert(real_usb_wdt_reset); + real_usb_wdt_reset = + (usb_wdt_reset_t) GetProcAddress(pe, "?usbWdtReset@@YAHXZ"); + log_assert(real_usb_wdt_reset); - real_usb_wdt_start = (usb_wdt_start_t)GetProcAddress(pe, "?usbWdtStart@@YAHH@Z"); - log_assert(real_usb_wdt_start); + real_usb_wdt_start = + (usb_wdt_start_t) GetProcAddress(pe, "?usbWdtStart@@YAHH@Z"); + log_assert(real_usb_wdt_start); - real_usb_wdt_start_done = (usb_wdt_start_done_t)GetProcAddress(pe, "?usbWdtStartDone@@YAHXZ"); - log_assert(real_usb_wdt_start_done); + real_usb_wdt_start_done = + (usb_wdt_start_done_t) GetProcAddress(pe, "?usbWdtStartDone@@YAHXZ"); + log_assert(real_usb_wdt_start_done); - real_usb_wdt_stop = (usb_wdt_stop_t)GetProcAddress(pe, "?usbWdtStop@@YAHXZ"); - log_assert(real_usb_wdt_stop); + real_usb_wdt_stop = + (usb_wdt_stop_t) GetProcAddress(pe, "?usbWdtStop@@YAHXZ"); + log_assert(real_usb_wdt_stop); } -int32_t proxy_usb_boot_security(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4) +int32_t proxy_usb_boot_security( + uint8_t *param1, int32_t param2, int32_t param3, int32_t param4) { return real_usb_boot_security(param1, param2, param3, param4); } -int32_t proxy_usb_boot_security_all(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4) +int32_t proxy_usb_boot_security_all( + uint8_t *param1, int32_t param2, int32_t param3, int32_t param4) { return real_usb_boot_security_all(param1, param2, param3, param4); } -int32_t proxy_usb_boot_security_all_r(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4) +int32_t proxy_usb_boot_security_all_r( + uint8_t *param1, int32_t param2, int32_t param3, int32_t param4) { return real_usb_boot_security_all_r(param1, param2, param3, param4); } @@ -336,7 +417,8 @@ int32_t proxy_usb_check_alive() return real_usb_check_alive(); } -int32_t proxy_usb_check_security(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4) +int32_t proxy_usb_check_security( + uint8_t *param1, int32_t param2, int32_t param3, int32_t param4) { return real_usb_check_security(param1, param2, param3, param4); } @@ -551,32 +633,51 @@ int32_t proxy_usb_set_ext_io(int32_t param1) return real_usb_set_ext_io(param1); } -int32_t proxy_usb_setup_eeprom(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4) +int32_t proxy_usb_setup_eeprom( + uint8_t *param1, int32_t param2, int32_t param3, int32_t param4) { return real_usb_setup_eeprom(param1, param2, param3, param4); } -int32_t proxy_usb_setup_eeprom_new(int32_t param1, uint8_t *param2, int32_t param3, int32_t param4, int32_t param5) +int32_t proxy_usb_setup_eeprom_new( + int32_t param1, + uint8_t *param2, + int32_t param3, + int32_t param4, + int32_t param5) { return real_usb_setup_eeprom_new(param1, param2, param3, param4, param5); } -int32_t proxy_usb_setup_security(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4) +int32_t proxy_usb_setup_security( + uint8_t *param1, int32_t param2, int32_t param3, int32_t param4) { return real_usb_setup_security(param1, param2, param3, param4); } -int32_t proxy_usb_setup_security_complete(uint8_t *param1, int32_t param2, int32_t param3, int32_t param4) +int32_t proxy_usb_setup_security_complete( + uint8_t *param1, int32_t param2, int32_t param3, int32_t param4) { return real_usb_setup_security_complete(param1, param2, param3, param4); } -int32_t proxy_usb_setup_security_complete_new(int32_t param1, uint8_t *param2, int32_t param3, int32_t param4, int32_t param5) +int32_t proxy_usb_setup_security_complete_new( + int32_t param1, + uint8_t *param2, + int32_t param3, + int32_t param4, + int32_t param5) { - return real_usb_setup_security_complete_new(param1, param2, param3, param4, param5); + return real_usb_setup_security_complete_new( + param1, param2, param3, param4, param5); } -int32_t proxy_usb_setup_security_new(int32_t param1, uint8_t *param2, int32_t param3, int32_t param4, int32_t param5) +int32_t proxy_usb_setup_security_new( + int32_t param1, + uint8_t *param2, + int32_t param3, + int32_t param4, + int32_t param5) { return real_usb_setup_security_new(param1, param2, param3, param4, param5); } diff --git a/src/main/ezusb2-popn/msg.h b/src/main/ezusb2-popn/msg.h index 951fc2f..3b25d39 100644 --- a/src/main/ezusb2-popn/msg.h +++ b/src/main/ezusb2-popn/msg.h @@ -70,9 +70,9 @@ struct ezusb2_popn_msg_interrupt_read_packet { union { uint32_t inverted_pad; struct { - uint8_t sys; /* test/service bitfield */ + uint8_t sys; /* test/service bitfield */ uint16_t button; /* button bitfield */ - uint8_t dipsw; /* dip switches */ + uint8_t dipsw; /* dip switches */ }; } io; uint8_t unk5; /* 0x00 */ diff --git a/src/main/ezusb2/cyioctl.h b/src/main/ezusb2/cyioctl.h index 5a18ca1..50244bc 100644 --- a/src/main/ezusb2/cyioctl.h +++ b/src/main/ezusb2/cyioctl.h @@ -125,12 +125,13 @@ typedef struct _SET_TRANSFER_SIZE_INFO { // #ifdef WIN_98_DDK #define DEVICE_TYPE_FROM_CTL_CODE(ctrlCode) \ - (((ULONG)(ctrlCode & 0xffff0000)) >> 16) + (((ULONG) (ctrlCode & 0xffff0000)) >> 16) #endif -#define FUNCTION_FROM_CTL_CODE(ctrlCode) (((ULONG)(ctrlCode & 0x00003FFC)) >> 2) -#define ACCESS_FROM_CTL_CODE(ctrlCode) (((ULONG)(ctrlCode & 0x000C0000)) >> 14) -//#define METHOD_FROM_CTL_CODE(ctrlCode) (((ULONG)(ctrlCode & -// 0x00000003))) +#define FUNCTION_FROM_CTL_CODE(ctrlCode) \ + (((ULONG) (ctrlCode & 0x00003FFC)) >> 2) +#define ACCESS_FROM_CTL_CODE(ctrlCode) (((ULONG) (ctrlCode & 0x000C0000)) >> 14) +// #define METHOD_FROM_CTL_CODE(ctrlCode) (((ULONG)(ctrlCode & +// 0x00000003))) #define IOCTL_ADAPT_INDEX 0x0000 diff --git a/src/main/geninput/hid-report-out.c b/src/main/geninput/hid-report-out.c index b7f55cb..5469e3a 100644 --- a/src/main/geninput/hid-report-out.c +++ b/src/main/geninput/hid-report-out.c @@ -65,8 +65,8 @@ bool hid_report_out_set_bit( uint16_t usage_hi; uint16_t usage_lo; - usage_hi = (uint16_t)(usage >> 16); - usage_lo = (uint16_t)(usage >> 0); + usage_hi = (uint16_t) (usage >> 16); + usage_lo = (uint16_t) (usage >> 0); count = 1; if (value) { @@ -118,8 +118,8 @@ bool hid_report_out_set_value( uint16_t usage_hi; uint16_t usage_lo; - usage_hi = (uint16_t)(usage >> 16); - usage_lo = (uint16_t)(usage >> 0); + usage_hi = (uint16_t) (usage >> 16); + usage_lo = (uint16_t) (usage >> 0); status = HidP_SetUsageValue( HidP_Output, diff --git a/src/main/geninput/mapper.c b/src/main/geninput/mapper.c index 9d11585..96da997 100644 --- a/src/main/geninput/mapper.c +++ b/src/main/geninput/mapper.c @@ -202,9 +202,9 @@ static void analog_mapping_update(struct analog_mapping *am) if (am->absolute) { tmp = (value - am->affine_bias) / am->affine_scale; - am->pos = (uint8_t)((tmp + 0.5) * 256.0); + am->pos = (uint8_t) ((tmp + 0.5) * 256.0); } else { - am->pos += (int8_t)(value * exp(am->sensitivity / 256.0)); + am->pos += (int8_t) (value * exp(am->sensitivity / 256.0)); } } @@ -306,7 +306,7 @@ static void light_mapping_send(struct light_mapping *lm, const struct mapper *m) intensity = m->lights[lm->game_light]; tmp = (intensity / 256.0) * lm->affine_scale; - value = (int32_t)(tmp + 0.5) + lm->affine_bias; + value = (int32_t) (tmp + 0.5) + lm->affine_bias; hid_stub_set_light(lm->dest.hid, lm->dest.light_no, value); } @@ -432,7 +432,7 @@ uint8_t mapper_impl_get_npages(struct mapper *m) } } - return (uint8_t)(max_page + 1); + return (uint8_t) (max_page + 1); } action_iter_t mapper_impl_iterate_actions(struct mapper *m) diff --git a/src/main/hook/args.c b/src/main/hook/args.c index 5211bd3..9c68c1e 100644 --- a/src/main/hook/args.c +++ b/src/main/hook/args.c @@ -10,11 +10,8 @@ /* This does not handle escaped double quotes inside args correctly yet */ -static HRESULT args_push( - int *argc, - char ***argv, - const char *begin, - const char *end) +static HRESULT +args_push(int *argc, char ***argv, const char *begin, const char *end) { int tmp_argc; char **tmp_argv; @@ -70,7 +67,7 @@ HRESULT args_recover(int *argc_out, char ***argv_out) argv = NULL; quote = false; - for (begin = pos = GetCommandLine() ; *pos ; pos++) { + for (begin = pos = GetCommandLine(); *pos; pos++) { switch (*pos) { case '"': if (!quote) { @@ -129,7 +126,7 @@ void args_free(int argc, char **argv) { int i; - for (i = 0 ; i < argc ; i++) { + for (i = 0; i < argc; i++) { free(argv[i]); } diff --git a/src/main/hook/com-proxy.c b/src/main/hook/com-proxy.c index b51084c..5d56843 100644 --- a/src/main/hook/com-proxy.c +++ b/src/main/hook/com-proxy.c @@ -1,5 +1,5 @@ -#include #include +#include #include #include @@ -8,63 +8,84 @@ #include "hook/com-proxy.h" static void com_proxy_free(struct com_proxy *proxy); -static HRESULT STDMETHODCALLTYPE com_proxy_query_interface( - IUnknown *unk, - REFIID iid, - void **iface); +static HRESULT STDMETHODCALLTYPE +com_proxy_query_interface(IUnknown *unk, REFIID iid, void **iface); static ULONG STDMETHODCALLTYPE com_proxy_addref(IUnknown *unk); static ULONG STDMETHODCALLTYPE com_proxy_release(IUnknown *unk); #ifdef __amd64 - /***** 64-BIT TRAMPOLINE *****/ +/***** 64-BIT TRAMPOLINE *****/ #define SLOT_OFFSET 0x0A static const uint8_t com_proxy_tramp[] = { /* mov rcx, [rcx+8] ; Get this->real */ - 0x48, 0x8B, 0x49, 0x08, + 0x48, + 0x8B, + 0x49, + 0x08, /* mov rax, [rcx] ; Get this->vtbl */ - 0x48, 0x8B, 0x01, + 0x48, + 0x8B, + 0x01, /* mov rax, [rax+XX] ; Get vtbl->slot_XX */ - 0x48, 0x8B, 0x80, -1, -1, -1, -1, + 0x48, + 0x8B, + 0x80, + -1, + -1, + -1, + -1, /* jmp rax ; Continue to slot_XX */ - 0xFF, 0xE0, + 0xFF, + 0xE0, }; #else - /***** 32-BIT TRAMPOLINE *****/ +/***** 32-BIT TRAMPOLINE *****/ #define SLOT_OFFSET 0x0F static const uint8_t com_proxy_tramp[] = { /* mov eax, [esp+4] ; Get this */ - 0x8B, 0x44, 0x24, 0x04, + 0x8B, + 0x44, + 0x24, + 0x04, /* mov eax, [eax+4] ; Get this->real */ - 0x8B, 0x40, 0x04, + 0x8B, + 0x40, + 0x04, /* mov [esp+4], eax ; Replace this with this->real on stack */ - 0x89, 0x44, 0x24, 0x04, + 0x89, + 0x44, + 0x24, + 0x04, /* mov ecx, [eax] ; Get this->vtbl */ - 0x8B, 0x08, + 0x8B, + 0x08, /* mov ecx, [ecx+XX] ; Get vtbl->slot_XX */ - 0x8B, 0x89, -1, -1, -1, -1, + 0x8B, + 0x89, + -1, + -1, + -1, + -1, /* jmp ecx ; Continue to slot_XX */ - 0xFF, 0xE1 -}; + 0xFF, + 0xE1}; #endif -HRESULT com_proxy_wrap( - struct com_proxy **out, - void *real, - size_t vtbl_size) +HRESULT com_proxy_wrap(struct com_proxy **out, void *real, size_t vtbl_size) { struct com_proxy *proxy; void **vtbl; @@ -97,10 +118,10 @@ HRESULT com_proxy_wrap( nslots = vtbl_size / sizeof(void *); proxy->tramps = VirtualAlloc( - NULL, - sizeof(com_proxy_tramp) * nslots, - MEM_RESERVE | MEM_COMMIT, - PAGE_EXECUTE_READWRITE); + NULL, + sizeof(com_proxy_tramp) * nslots, + MEM_RESERVE | MEM_COMMIT, + PAGE_EXECUTE_READWRITE); if (proxy->tramps == NULL) { hr = E_OUTOFMEMORY; @@ -119,7 +140,7 @@ HRESULT com_proxy_wrap( /* Populate trampoline code for remaining vtbl entries */ - for (i = 3 /* Skip IUnknown */ ; i < nslots ; i++) { + for (i = 3 /* Skip IUnknown */; i < nslots; i++) { cur_tramp = proxy->tramps + i * sizeof(com_proxy_tramp); /* Copy template */ @@ -160,10 +181,8 @@ static void com_proxy_free(struct com_proxy *proxy) free(proxy); } -static HRESULT STDMETHODCALLTYPE com_proxy_query_interface( - IUnknown *unk, - REFIID iid, - void **iface) +static HRESULT STDMETHODCALLTYPE +com_proxy_query_interface(IUnknown *unk, REFIID iid, void **iface) { struct com_proxy *proxy; IUnknown *obj; diff --git a/src/main/hook/com-proxy.h b/src/main/hook/com-proxy.h index b678b17..94671b7 100644 --- a/src/main/hook/com-proxy.h +++ b/src/main/hook/com-proxy.h @@ -49,7 +49,4 @@ struct com_proxy { unless you provide a custom QueryInterface implementation to prevent them from doing so. */ -HRESULT com_proxy_wrap( - struct com_proxy **out, - void *real, - size_t vtbl_size); +HRESULT com_proxy_wrap(struct com_proxy **out, void *real, size_t vtbl_size); diff --git a/src/main/hook/d3d9.c b/src/main/hook/d3d9.c index af4a53b..48ca9b6 100644 --- a/src/main/hook/d3d9.c +++ b/src/main/hook/d3d9.c @@ -72,13 +72,12 @@ static HRESULT(STDCALL *real_DrawPrimitiveUP)( UINT stride); static HRESULT(STDCALL *real_Reset)( - IDirect3DDevice9 *self, - D3DPRESENT_PARAMETERS *pp); + IDirect3DDevice9 *self, D3DPRESENT_PARAMETERS *pp); -static HRESULT (STDCALL *real_SetViewport)( +static HRESULT(STDCALL *real_SetViewport)( IDirect3DDevice9 *self, const D3DVIEWPORT9 *pViewport); -static HRESULT (STDCALL *real_SetVertexShader)( +static HRESULT(STDCALL *real_SetVertexShader)( IDirect3DDevice9 *self, IDirect3DVertexShader9 *pShader); /* ------------------------------------------------------------------------------------------------------------------ @@ -146,15 +145,14 @@ static HRESULT STDCALL my_DrawPrimitiveUP( const void *data, UINT stride); -static HRESULT STDCALL my_Reset( - IDirect3DDevice9 *self, - D3DPRESENT_PARAMETERS *pp); +static HRESULT STDCALL +my_Reset(IDirect3DDevice9 *self, D3DPRESENT_PARAMETERS *pp); -static HRESULT STDCALL my_SetViewport( - IDirect3DDevice9 *self, const D3DVIEWPORT9 *pViewport); +static HRESULT STDCALL +my_SetViewport(IDirect3DDevice9 *self, const D3DVIEWPORT9 *pViewport); -static HRESULT STDCALL my_SetVertexShader( - IDirect3DDevice9 *self, IDirect3DVertexShader9 *pShader); +static HRESULT STDCALL +my_SetVertexShader(IDirect3DDevice9 *self, IDirect3DVertexShader9 *pShader); /* ------------------------------------------------------------------------------------------------------------------ */ @@ -214,8 +212,7 @@ hook_d3d9_irp_handler_real_dev_set_render_state(struct hook_d3d9_irp *irp); static HRESULT hook_d3d9_irp_handler_real_dev_draw_primitive_up(struct hook_d3d9_irp *irp); -static HRESULT -hook_d3d9_irp_handler_real_dev_reset(struct hook_d3d9_irp *irp); +static HRESULT hook_d3d9_irp_handler_real_dev_reset(struct hook_d3d9_irp *irp); static HRESULT hook_d3d9_irp_handler_real_dev_set_viewport(struct hook_d3d9_irp *irp); @@ -247,8 +244,7 @@ static const hook_d3d9_irp_handler_t hook_d3d9_irp_real_handlers[] = { hook_d3d9_irp_handler_real_dev_set_render_state, [HOOK_D3D9_IRP_OP_DEV_DRAW_PRIMITIVE_UP] = hook_d3d9_irp_handler_real_dev_draw_primitive_up, - [HOOK_D3D9_IRP_OP_DEV_RESET] = - hook_d3d9_irp_handler_real_dev_reset, + [HOOK_D3D9_IRP_OP_DEV_RESET] = hook_d3d9_irp_handler_real_dev_reset, [HOOK_D3D9_IRP_OP_DEV_SET_VIEWPORT] = hook_d3d9_irp_handler_real_dev_set_viewport, [HOOK_D3D9_IRP_OP_DEV_SET_VERTEX_SHADER] = @@ -523,8 +519,8 @@ static HRESULT STDCALL my_DrawPrimitiveUP( return hr; } -static HRESULT STDCALL my_SetViewport( - IDirect3DDevice9 *self, const D3DVIEWPORT9 *pViewport) +static HRESULT STDCALL +my_SetViewport(IDirect3DDevice9 *self, const D3DVIEWPORT9 *pViewport) { struct hook_d3d9_irp irp; HRESULT hr; @@ -540,8 +536,8 @@ static HRESULT STDCALL my_SetViewport( return hr; } -static HRESULT STDCALL my_SetVertexShader( - IDirect3DDevice9 *self, IDirect3DVertexShader9 *pShader) +static HRESULT STDCALL +my_SetVertexShader(IDirect3DDevice9 *self, IDirect3DVertexShader9 *pShader) { struct hook_d3d9_irp irp; HRESULT hr; @@ -557,9 +553,8 @@ static HRESULT STDCALL my_SetVertexShader( return hr; } -static HRESULT STDCALL my_Reset( - IDirect3DDevice9 *self, - D3DPRESENT_PARAMETERS *pp) +static HRESULT STDCALL +my_Reset(IDirect3DDevice9 *self, D3DPRESENT_PARAMETERS *pp) { struct hook_d3d9_irp irp; HRESULT hr; @@ -827,14 +822,11 @@ hook_d3d9_irp_handler_real_dev_draw_primitive_up(struct hook_d3d9_irp *irp) irp->args.dev_draw_primitive_up.stride); } -static HRESULT -hook_d3d9_irp_handler_real_dev_reset(struct hook_d3d9_irp *irp) +static HRESULT hook_d3d9_irp_handler_real_dev_reset(struct hook_d3d9_irp *irp) { log_assert(irp); - return real_Reset( - irp->args.dev_reset.self, - irp->args.dev_reset.pp); + return real_Reset(irp->args.dev_reset.self, irp->args.dev_reset.pp); } static HRESULT @@ -843,8 +835,7 @@ hook_d3d9_irp_handler_real_dev_set_viewport(struct hook_d3d9_irp *irp) log_assert(irp); return real_SetViewport( - irp->args.dev_set_viewport.self, - irp->args.dev_set_viewport.pViewport); + irp->args.dev_set_viewport.self, irp->args.dev_set_viewport.pViewport); } static HRESULT diff --git a/src/main/hook/hr.c b/src/main/hook/hr.c index 02a8642..cc534c9 100644 --- a/src/main/hook/hr.c +++ b/src/main/hook/hr.c @@ -12,17 +12,28 @@ uint32_t hr_to_win32_error(HRESULT hr) return HRESULT_CODE(hr); } else { switch (hr) { - case E_ABORT: return ERROR_OPERATION_ABORTED; - case E_ACCESSDENIED: return ERROR_ACCESS_DENIED; - case E_FAIL: return ERROR_GEN_FAILURE; - case E_HANDLE: return ERROR_INVALID_HANDLE; - case E_INVALIDARG: return ERROR_INVALID_PARAMETER; - case E_NOINTERFACE: return ERROR_INVALID_FUNCTION; - case E_NOTIMPL: return ERROR_NOT_SUPPORTED; - case E_OUTOFMEMORY: return ERROR_OUTOFMEMORY; - case E_POINTER: return ERROR_INVALID_ADDRESS; - case E_UNEXPECTED: return ERROR_INTERNAL_ERROR; - default: return ERROR_INTERNAL_ERROR; + case E_ABORT: + return ERROR_OPERATION_ABORTED; + case E_ACCESSDENIED: + return ERROR_ACCESS_DENIED; + case E_FAIL: + return ERROR_GEN_FAILURE; + case E_HANDLE: + return ERROR_INVALID_HANDLE; + case E_INVALIDARG: + return ERROR_INVALID_PARAMETER; + case E_NOINTERFACE: + return ERROR_INVALID_FUNCTION; + case E_NOTIMPL: + return ERROR_NOT_SUPPORTED; + case E_OUTOFMEMORY: + return ERROR_OUTOFMEMORY; + case E_POINTER: + return ERROR_INVALID_ADDRESS; + case E_UNEXPECTED: + return ERROR_INTERNAL_ERROR; + default: + return ERROR_INTERNAL_ERROR; } } } diff --git a/src/main/hook/iobuf.c b/src/main/hook/iobuf.c index d100274..2820ed7 100644 --- a/src/main/hook/iobuf.c +++ b/src/main/hook/iobuf.c @@ -95,7 +95,7 @@ HRESULT iobuf_read_be16(struct const_iobuf *src, uint16_t *out) return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); } - value = src->bytes[src->pos++] << 8; + value = src->bytes[src->pos++] << 8; value |= src->bytes[src->pos++]; *out = value; @@ -114,7 +114,7 @@ HRESULT iobuf_read_be32(struct const_iobuf *src, uint32_t *out) return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); } - value = src->bytes[src->pos++] << 24; + value = src->bytes[src->pos++] << 24; value |= src->bytes[src->pos++] << 16; value |= src->bytes[src->pos++] << 8; value |= src->bytes[src->pos++]; @@ -135,7 +135,7 @@ HRESULT iobuf_read_be64(struct const_iobuf *src, uint64_t *out) return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); } - value = ((uint64_t) src->bytes[src->pos++]) << 56; + value = ((uint64_t) src->bytes[src->pos++]) << 56; value |= ((uint64_t) src->bytes[src->pos++]) << 48; value |= ((uint64_t) src->bytes[src->pos++]) << 40; value |= ((uint64_t) src->bytes[src->pos++]) << 32; @@ -160,7 +160,7 @@ HRESULT iobuf_read_le16(struct const_iobuf *src, uint16_t *out) return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); } - value = src->bytes[src->pos++]; + value = src->bytes[src->pos++]; value |= src->bytes[src->pos++] << 8; *out = value; @@ -179,7 +179,7 @@ HRESULT iobuf_read_le32(struct const_iobuf *src, uint32_t *out) return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); } - value = src->bytes[src->pos++]; + value = src->bytes[src->pos++]; value |= src->bytes[src->pos++] << 8; value |= src->bytes[src->pos++] << 16; value |= src->bytes[src->pos++] << 24; @@ -200,7 +200,7 @@ HRESULT iobuf_read_le64(struct const_iobuf *src, uint64_t *out) return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); } - value = ((uint64_t) src->bytes[src->pos++]); + value = ((uint64_t) src->bytes[src->pos++]); value |= ((uint64_t) src->bytes[src->pos++]) << 8; value |= ((uint64_t) src->bytes[src->pos++]) << 16; value |= ((uint64_t) src->bytes[src->pos++]) << 24; diff --git a/src/main/hook/iohook.c b/src/main/hook/iohook.c index d5cacc8..ca28c40 100644 --- a/src/main/hook/iohook.c +++ b/src/main/hook/iohook.c @@ -4,9 +4,9 @@ #undef WIN32_NO_STATUS #include -#include #include #include +#include #include #include @@ -21,10 +21,8 @@ /* Helpers */ static void iohook_init(void); -static BOOL iohook_overlapped_result( - uint32_t *syncout, - OVERLAPPED *ovl, - uint32_t value); +static BOOL +iohook_overlapped_result(uint32_t *syncout, OVERLAPPED *ovl, uint32_t value); static HRESULT iohook_invoke_real(struct irp *irp); static HRESULT iohook_invoke_real_open(struct irp *irp); @@ -41,171 +39,175 @@ static HRESULT iohook_invoke_real_ioctl(struct irp *irp); static BOOL WINAPI iohook_CloseHandle(HANDLE fd); static HANDLE WINAPI iohook_CreateFileW( - const wchar_t *lpFileName, - uint32_t dwDesiredAccess, - uint32_t dwShareMode, - SECURITY_ATTRIBUTES *lpSecurityAttributes, - uint32_t dwCreationDisposition, - uint32_t dwFlagsAndAttributes, - HANDLE hTemplateFile); + const wchar_t *lpFileName, + uint32_t dwDesiredAccess, + uint32_t dwShareMode, + SECURITY_ATTRIBUTES *lpSecurityAttributes, + uint32_t dwCreationDisposition, + uint32_t dwFlagsAndAttributes, + HANDLE hTemplateFile); static HANDLE WINAPI iohook_CreateFileA( - const char *lpFileName, - uint32_t dwDesiredAccess, - uint32_t dwShareMode, - SECURITY_ATTRIBUTES *lpSecurityAttributes, - uint32_t dwCreationDisposition, - uint32_t dwFlagsAndAttributes, - HANDLE hTemplateFile); + const char *lpFileName, + uint32_t dwDesiredAccess, + uint32_t dwShareMode, + SECURITY_ATTRIBUTES *lpSecurityAttributes, + uint32_t dwCreationDisposition, + uint32_t dwFlagsAndAttributes, + HANDLE hTemplateFile); static BOOL WINAPI iohook_ReadFile( - HANDLE hFile, - void *lpBuffer, - uint32_t nNumberOfBytesToRead, - uint32_t *lpNumberOfBytesRead, - OVERLAPPED *lpOverlapped); + HANDLE hFile, + void *lpBuffer, + uint32_t nNumberOfBytesToRead, + uint32_t *lpNumberOfBytesRead, + OVERLAPPED *lpOverlapped); static BOOL WINAPI iohook_WriteFile( - HANDLE hFile, - const void *lpBuffer, - uint32_t nNumberOfBytesToWrite, - uint32_t *lpNumberOfBytesWritten, - OVERLAPPED *lpOverlapped); + HANDLE hFile, + const void *lpBuffer, + uint32_t nNumberOfBytesToWrite, + uint32_t *lpNumberOfBytesWritten, + OVERLAPPED *lpOverlapped); static DWORD WINAPI iohook_SetFilePointer( - HANDLE hFile, - int32_t lDistanceToMove, - int32_t *lpDistanceToMoveHigh, - uint32_t dwMoveMethod); + HANDLE hFile, + int32_t lDistanceToMove, + int32_t *lpDistanceToMoveHigh, + uint32_t dwMoveMethod); static BOOL WINAPI iohook_SetFilePointerEx( - HANDLE hFile, - int64_t liDistanceToMove, - uint64_t *lpNewFilePointer, - uint32_t dwMoveMethod); + HANDLE hFile, + int64_t liDistanceToMove, + uint64_t *lpNewFilePointer, + uint32_t dwMoveMethod); static BOOL WINAPI iohook_FlushFileBuffers(HANDLE hFile); static BOOL WINAPI iohook_DeviceIoControl( - HANDLE hFile, - uint32_t dwIoControlCode, - void *lpInBuffer, - uint32_t nInBufferSize, - void *lpOutBuffer, - uint32_t nOutBufferSize, - uint32_t *lpBytesReturned, - OVERLAPPED *lpOverlapped); + HANDLE hFile, + uint32_t dwIoControlCode, + void *lpInBuffer, + uint32_t nInBufferSize, + void *lpOutBuffer, + uint32_t nOutBufferSize, + uint32_t *lpBytesReturned, + OVERLAPPED *lpOverlapped); /* Links */ -static BOOL (WINAPI *next_CloseHandle)(HANDLE fd); +static BOOL(WINAPI *next_CloseHandle)(HANDLE fd); -static HANDLE (WINAPI *next_CreateFileA)( - const char *lpFileName, - uint32_t dwDesiredAccess, - uint32_t dwShareMode, - SECURITY_ATTRIBUTES *lpSecurityAttributes, - uint32_t dwCreationDisposition, - uint32_t dwFlagsAndAttributes, - HANDLE hTemplateFile); +static HANDLE(WINAPI *next_CreateFileA)( + const char *lpFileName, + uint32_t dwDesiredAccess, + uint32_t dwShareMode, + SECURITY_ATTRIBUTES *lpSecurityAttributes, + uint32_t dwCreationDisposition, + uint32_t dwFlagsAndAttributes, + HANDLE hTemplateFile); -static HANDLE (WINAPI *next_CreateFileW)( - const wchar_t *filename, - uint32_t access, - uint32_t share, - SECURITY_ATTRIBUTES *sa, - uint32_t creation, - uint32_t flags, - HANDLE tmpl); +static HANDLE(WINAPI *next_CreateFileW)( + const wchar_t *filename, + uint32_t access, + uint32_t share, + SECURITY_ATTRIBUTES *sa, + uint32_t creation, + uint32_t flags, + HANDLE tmpl); -static BOOL (WINAPI *next_DeviceIoControl)( - HANDLE fd, - uint32_t code, - void *in_bytes, - uint32_t in_nbytes, - void *out_bytes, - uint32_t out_nbytes, - uint32_t *out_returned, - OVERLAPPED *ovl); +static BOOL(WINAPI *next_DeviceIoControl)( + HANDLE fd, + uint32_t code, + void *in_bytes, + uint32_t in_nbytes, + void *out_bytes, + uint32_t out_nbytes, + uint32_t *out_returned, + OVERLAPPED *ovl); -static BOOL (WINAPI *next_ReadFile)( - HANDLE fd, - void *buf, - uint32_t nbytes, - uint32_t *nread, - OVERLAPPED *ovl); +static BOOL(WINAPI *next_ReadFile)( + HANDLE fd, void *buf, uint32_t nbytes, uint32_t *nread, OVERLAPPED *ovl); -static BOOL (WINAPI *next_WriteFile)( - HANDLE fd, - const void *buf, - uint32_t nbytes, - uint32_t *nwrit, - OVERLAPPED *ovl); +static BOOL(WINAPI *next_WriteFile)( + HANDLE fd, + const void *buf, + uint32_t nbytes, + uint32_t *nwrit, + OVERLAPPED *ovl); -static DWORD (WINAPI *next_SetFilePointer)( - HANDLE hFile, - int32_t lDistanceToMove, - int32_t *lpDistanceToMoveHigh, - uint32_t dwMoveMethod); +static DWORD(WINAPI *next_SetFilePointer)( + HANDLE hFile, + int32_t lDistanceToMove, + int32_t *lpDistanceToMoveHigh, + uint32_t dwMoveMethod); -static BOOL (WINAPI *next_SetFilePointerEx)( - HANDLE hFile, - int64_t liDistanceToMove, - uint64_t *lpNewFilePointer, - uint32_t dwMoveMethod); +static BOOL(WINAPI *next_SetFilePointerEx)( + HANDLE hFile, + int64_t liDistanceToMove, + uint64_t *lpNewFilePointer, + uint32_t dwMoveMethod); -static BOOL (WINAPI *next_FlushFileBuffers)(HANDLE fd); +static BOOL(WINAPI *next_FlushFileBuffers)(HANDLE fd); /* Hook symbol table */ static const struct hook_symbol iohook_kernel32_syms[] = { { - .name = "CloseHandle", - .patch = iohook_CloseHandle, - .link = (void *) &next_CloseHandle, - }, { - .name = "CreateFileA", - .patch = iohook_CreateFileA, - .link = (void *) &next_CreateFileA, - }, { - .name = "CreateFileW", - .patch = iohook_CreateFileW, - .link = (void *) &next_CreateFileW, - }, { - .name = "DeviceIoControl", - .patch = iohook_DeviceIoControl, - .link = (void *) &next_DeviceIoControl, - }, { - .name = "ReadFile", - .patch = iohook_ReadFile, - .link = (void *) &next_ReadFile, - }, { - .name = "WriteFile", - .patch = iohook_WriteFile, - .link = (void *) &next_WriteFile, - }, { - .name = "SetFilePointer", - .patch = iohook_SetFilePointer, - .link = (void *) &next_SetFilePointer, - }, { - .name = "SetFilePointerEx", - .patch = iohook_SetFilePointerEx, - .link = (void *) &next_SetFilePointerEx, - }, { - .name = "FlushFileBuffers", - .patch = iohook_FlushFileBuffers, - .link = (void *) &next_FlushFileBuffers, + .name = "CloseHandle", + .patch = iohook_CloseHandle, + .link = (void *) &next_CloseHandle, + }, + { + .name = "CreateFileA", + .patch = iohook_CreateFileA, + .link = (void *) &next_CreateFileA, + }, + { + .name = "CreateFileW", + .patch = iohook_CreateFileW, + .link = (void *) &next_CreateFileW, + }, + { + .name = "DeviceIoControl", + .patch = iohook_DeviceIoControl, + .link = (void *) &next_DeviceIoControl, + }, + { + .name = "ReadFile", + .patch = iohook_ReadFile, + .link = (void *) &next_ReadFile, + }, + { + .name = "WriteFile", + .patch = iohook_WriteFile, + .link = (void *) &next_WriteFile, + }, + { + .name = "SetFilePointer", + .patch = iohook_SetFilePointer, + .link = (void *) &next_SetFilePointer, + }, + { + .name = "SetFilePointerEx", + .patch = iohook_SetFilePointerEx, + .link = (void *) &next_SetFilePointerEx, + }, + { + .name = "FlushFileBuffers", + .patch = iohook_FlushFileBuffers, + .link = (void *) &next_FlushFileBuffers, }, }; static const iohook_fn_t iohook_real_handlers[] = { - [IRP_OP_OPEN] = iohook_invoke_real_open, - [IRP_OP_CLOSE] = iohook_invoke_real_close, - [IRP_OP_READ] = iohook_invoke_real_read, - [IRP_OP_WRITE] = iohook_invoke_real_write, - [IRP_OP_SEEK] = iohook_invoke_real_seek, - [IRP_OP_FSYNC] = iohook_invoke_real_fsync, - [IRP_OP_IOCTL] = iohook_invoke_real_ioctl, + [IRP_OP_OPEN] = iohook_invoke_real_open, + [IRP_OP_CLOSE] = iohook_invoke_real_close, + [IRP_OP_READ] = iohook_invoke_real_read, + [IRP_OP_WRITE] = iohook_invoke_real_write, + [IRP_OP_SEEK] = iohook_invoke_real_seek, + [IRP_OP_FSYNC] = iohook_invoke_real_fsync, + [IRP_OP_IOCTL] = iohook_invoke_real_ioctl, }; static bool iohook_initted; @@ -233,10 +235,10 @@ static void iohook_init(void) /* Splice iohook into IAT entries referencing Win32 I/O APIs */ hook_table_apply( - NULL, - "kernel32.dll", - iohook_kernel32_syms, - _countof(iohook_kernel32_syms)); + NULL, + "kernel32.dll", + iohook_kernel32_syms, + _countof(iohook_kernel32_syms)); /* Here be dragons: @@ -268,15 +270,12 @@ static void iohook_init(void) kernel32 = GetModuleHandleW(L"kernel32.dll"); if (next_CreateFileW == NULL) { - next_CreateFileW = (void *) GetProcAddress( - kernel32, - "CreateFileW"); + next_CreateFileW = (void *) GetProcAddress(kernel32, "CreateFileW"); } if (next_SetFilePointerEx == NULL) { - next_SetFilePointerEx = (void *) GetProcAddress( - kernel32, - "SetFilePointerEx"); + next_SetFilePointerEx = + (void *) GetProcAddress(kernel32, "SetFilePointerEx"); } LeaveCriticalSection(&iohook_lock); @@ -288,13 +287,13 @@ HANDLE iohook_open_dummy_fd(void) iohook_init(); return next_CreateFileW( - L"NUL", - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_FLAG_OVERLAPPED, - NULL); + L"NUL", + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_FLAG_OVERLAPPED, + NULL); } HRESULT iohook_open_nul_fd(HANDLE *out) @@ -307,13 +306,13 @@ HRESULT iohook_open_nul_fd(HANDLE *out) iohook_init(); fd = next_CreateFileW( - L"NUL", - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_FLAG_OVERLAPPED, - NULL); + L"NUL", + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_FLAG_OVERLAPPED, + NULL); if (fd == NULL) { return HRESULT_FROM_WIN32(GetLastError()); @@ -351,10 +350,8 @@ HRESULT iohook_push_handler(iohook_fn_t fn) return hr; } -static BOOL iohook_overlapped_result( - uint32_t *syncout, - OVERLAPPED *ovl, - uint32_t value) +static BOOL +iohook_overlapped_result(uint32_t *syncout, OVERLAPPED *ovl, uint32_t value) { if (ovl != NULL) { ovl->Internal = STATUS_SUCCESS; @@ -429,13 +426,13 @@ static HRESULT iohook_invoke_real_open(struct irp *irp) assert(irp != NULL); fd = next_CreateFileW( - irp->open_filename, - irp->open_access, - irp->open_share, - irp->open_sa, - irp->open_creation, - irp->open_flags, - irp->open_tmpl); + irp->open_filename, + irp->open_access, + irp->open_share, + irp->open_sa, + irp->open_creation, + irp->open_flags, + irp->open_tmpl); if (fd == INVALID_HANDLE_VALUE) { return HRESULT_FROM_WIN32(GetLastError()); @@ -469,11 +466,11 @@ static HRESULT iohook_invoke_real_read(struct irp *irp) assert(irp != NULL); ok = next_ReadFile( - irp->fd, - &irp->read.bytes[irp->read.pos], - irp->read.nbytes - irp->read.pos, - &nread, - irp->ovl); + irp->fd, + &irp->read.bytes[irp->read.pos], + irp->read.nbytes - irp->read.pos, + &nread, + irp->ovl); if (!ok) { return HRESULT_FROM_WIN32(GetLastError()); @@ -492,11 +489,11 @@ static HRESULT iohook_invoke_real_write(struct irp *irp) assert(irp != NULL); ok = next_WriteFile( - irp->fd, - &irp->write.bytes[irp->write.pos], - irp->write.nbytes - irp->write.pos, - &nwrit, - irp->ovl); + irp->fd, + &irp->write.bytes[irp->write.pos], + irp->write.nbytes - irp->write.pos, + &nwrit, + irp->ovl); if (!ok) { return HRESULT_FROM_WIN32(GetLastError()); @@ -514,10 +511,7 @@ static HRESULT iohook_invoke_real_seek(struct irp *irp) assert(irp != NULL); ok = next_SetFilePointerEx( - irp->fd, - irp->seek_offset, - &irp->seek_pos, - irp->seek_origin); + irp->fd, irp->seek_offset, &irp->seek_pos, irp->seek_origin); if (!ok) { return HRESULT_FROM_WIN32(GetLastError()); @@ -556,14 +550,14 @@ static HRESULT iohook_invoke_real_ioctl(struct irp *irp) assert(irp->read.pos == 0); ok = next_DeviceIoControl( - irp->fd, - irp->ioctl, - (void *) irp->write.bytes, // Cast off const - irp->write.nbytes, - irp->read.bytes, - irp->read.nbytes, - &nread, - irp->ovl); + irp->fd, + irp->ioctl, + (void *) irp->write.bytes, // Cast off const + irp->write.nbytes, + irp->read.bytes, + irp->read.nbytes, + &nread, + irp->ovl); /* Must be propagated even if there is an error, see iohook_DeviceIoControl. */ @@ -578,13 +572,13 @@ static HRESULT iohook_invoke_real_ioctl(struct irp *irp) } static HANDLE WINAPI iohook_CreateFileA( - const char *lpFileName, - uint32_t dwDesiredAccess, - uint32_t dwShareMode, - SECURITY_ATTRIBUTES *lpSecurityAttributes, - uint32_t dwCreationDisposition, - uint32_t dwFlagsAndAttributes, - HANDLE hTemplateFile) + const char *lpFileName, + uint32_t dwDesiredAccess, + uint32_t dwShareMode, + SECURITY_ATTRIBUTES *lpSecurityAttributes, + uint32_t dwCreationDisposition, + uint32_t dwFlagsAndAttributes, + HANDLE hTemplateFile) { wchar_t *wfilename; int nchars; @@ -616,12 +610,13 @@ static HANDLE WINAPI iohook_CreateFileA( } fd = iohook_CreateFileW( - wfilename, - dwDesiredAccess, - dwShareMode, - lpSecurityAttributes, - dwCreationDisposition, dwFlagsAndAttributes, - hTemplateFile); + wfilename, + dwDesiredAccess, + dwShareMode, + lpSecurityAttributes, + dwCreationDisposition, + dwFlagsAndAttributes, + hTemplateFile); end: free(wfilename); @@ -630,13 +625,13 @@ end: } static HANDLE WINAPI iohook_CreateFileW( - const wchar_t *lpFileName, - uint32_t dwDesiredAccess, - uint32_t dwShareMode, - SECURITY_ATTRIBUTES *lpSecurityAttributes, - uint32_t dwCreationDisposition, - uint32_t dwFlagsAndAttributes, - HANDLE hTemplateFile) + const wchar_t *lpFileName, + uint32_t dwDesiredAccess, + uint32_t dwShareMode, + SECURITY_ATTRIBUTES *lpSecurityAttributes, + uint32_t dwCreationDisposition, + uint32_t dwFlagsAndAttributes, + HANDLE hTemplateFile) { struct irp irp; HRESULT hr; @@ -696,11 +691,11 @@ static BOOL WINAPI iohook_CloseHandle(HANDLE hFile) } static BOOL WINAPI iohook_ReadFile( - HANDLE hFile, - void *lpBuffer, - uint32_t nNumberOfBytesToRead, - uint32_t *lpNumberOfBytesRead, - OVERLAPPED *lpOverlapped) + HANDLE hFile, + void *lpBuffer, + uint32_t nNumberOfBytesToRead, + uint32_t *lpNumberOfBytesRead, + OVERLAPPED *lpOverlapped) { struct irp irp; HRESULT hr; @@ -738,17 +733,15 @@ static BOOL WINAPI iohook_ReadFile( assert(irp.read.pos <= irp.read.nbytes); return iohook_overlapped_result( - lpNumberOfBytesRead, - lpOverlapped, - irp.read.pos); + lpNumberOfBytesRead, lpOverlapped, irp.read.pos); } static BOOL WINAPI iohook_WriteFile( - HANDLE hFile, - const void *lpBuffer, - uint32_t nNumberOfBytesToWrite, - uint32_t *lpNumberOfBytesWritten, - OVERLAPPED *lpOverlapped) + HANDLE hFile, + const void *lpBuffer, + uint32_t nNumberOfBytesToWrite, + uint32_t *lpNumberOfBytesWritten, + OVERLAPPED *lpOverlapped) { struct irp irp; HRESULT hr; @@ -786,16 +779,14 @@ static BOOL WINAPI iohook_WriteFile( assert(irp.write.pos <= irp.write.nbytes); return iohook_overlapped_result( - lpNumberOfBytesWritten, - lpOverlapped, - irp.write.pos); + lpNumberOfBytesWritten, lpOverlapped, irp.write.pos); } static DWORD WINAPI iohook_SetFilePointer( - HANDLE hFile, - int32_t lDistanceToMove, - int32_t *lpDistanceToMoveHigh, - uint32_t dwMoveMethod) + HANDLE hFile, + int32_t lDistanceToMove, + int32_t *lpDistanceToMoveHigh, + uint32_t dwMoveMethod) { struct irp irp; HRESULT hr; @@ -816,10 +807,10 @@ static DWORD WINAPI iohook_SetFilePointer( with sign-extension vs zero-extension here. */ if (lpDistanceToMoveHigh != NULL) { - irp.seek_offset = ((( int64_t) *lpDistanceToMoveHigh) << 32) | - ((uint64_t) lDistanceToMove ) ; + irp.seek_offset = (((int64_t) *lpDistanceToMoveHigh) << 32) | + ((uint64_t) lDistanceToMove); } else { - irp.seek_offset = ( int64_t) lDistanceToMove; + irp.seek_offset = (int64_t) lDistanceToMove; } hr = iohook_invoke_next(&irp); @@ -838,10 +829,10 @@ static DWORD WINAPI iohook_SetFilePointer( } static BOOL WINAPI iohook_SetFilePointerEx( - HANDLE hFile, - int64_t liDistanceToMove, - uint64_t *lpNewFilePointer, - uint32_t dwMoveMethod) + HANDLE hFile, + int64_t liDistanceToMove, + uint64_t *lpNewFilePointer, + uint32_t dwMoveMethod) { struct irp irp; HRESULT hr; @@ -902,14 +893,14 @@ static BOOL WINAPI iohook_FlushFileBuffers(HANDLE hFile) } static BOOL WINAPI iohook_DeviceIoControl( - HANDLE hFile, - uint32_t dwIoControlCode, - void *lpInBuffer, - uint32_t nInBufferSize, - void *lpOutBuffer, - uint32_t nOutBufferSize, - uint32_t *lpBytesReturned, - OVERLAPPED *lpOverlapped) + HANDLE hFile, + uint32_t dwIoControlCode, + void *lpInBuffer, + uint32_t nInBufferSize, + void *lpOutBuffer, + uint32_t nOutBufferSize, + uint32_t *lpBytesReturned, + OVERLAPPED *lpOverlapped) { struct irp irp; HRESULT hr; @@ -963,7 +954,5 @@ static BOOL WINAPI iohook_DeviceIoControl( } return iohook_overlapped_result( - lpBytesReturned, - lpOverlapped, - irp.read.pos); + lpBytesReturned, lpOverlapped, irp.read.pos); } diff --git a/src/main/hook/iohook.h b/src/main/hook/iohook.h index 58bf642..2789804 100644 --- a/src/main/hook/iohook.h +++ b/src/main/hook/iohook.h @@ -41,9 +41,9 @@ typedef HRESULT (*iohook_fn_t)(struct irp *irp); HANDLE iohook_open_dummy_fd(void) #ifdef __GNUC__ -__attribute__((deprecated("Use iohook_open_nul_fd instead"))) + __attribute__((deprecated("Use iohook_open_nul_fd instead"))) #endif -; + ; HRESULT iohook_open_nul_fd(HANDLE *fd); HRESULT iohook_push_handler(iohook_fn_t fn); diff --git a/src/main/hook/pe.c b/src/main/hook/pe.c index 93e0fa2..e04bbab 100644 --- a/src/main/hook/pe.c +++ b/src/main/hook/pe.c @@ -94,10 +94,7 @@ const pe_iid_t *pe_iid_get_next(HMODULE pe, const pe_iid_t *iid) } HRESULT pe_iid_get_iat_entry( - HMODULE pe, - const pe_iid_t *iid, - size_t n, - struct pe_iat_entry *entry) + HMODULE pe, const pe_iid_t *iid, size_t n, struct pe_iat_entry *entry) { const IMAGE_IMPORT_BY_NAME *import; intptr_t *import_rvas; @@ -153,7 +150,7 @@ void *pe_get_export(HMODULE pe, const char *name, uint16_t ord) target_rvas = pe_offsetc(pe, ied->AddressOfFunctions); if (name != NULL) { - for (i = 0 ; i < ied->NumberOfNames ; i++) { + for (i = 0; i < ied->NumberOfNames; i++) { if (name_rvas[i] == 0) { /* Ordinal-only export, cannot match against this */ continue; @@ -196,11 +193,7 @@ HRESULT pe_patch(void *dest, const void *src, size_t nbytes) assert(dest != NULL); assert(src != NULL); - ok = VirtualProtect( - dest, - nbytes, - PAGE_EXECUTE_READWRITE, - &old_protect); + ok = VirtualProtect(dest, nbytes, PAGE_EXECUTE_READWRITE, &old_protect); if (!ok) { return HRESULT_FROM_WIN32(GetLastError()); @@ -208,11 +201,7 @@ HRESULT pe_patch(void *dest, const void *src, size_t nbytes) memcpy(dest, src, nbytes); - ok = VirtualProtect( - dest, - nbytes, - old_protect, - &old_protect); + ok = VirtualProtect(dest, nbytes, old_protect, &old_protect); if (!ok) { return HRESULT_FROM_WIN32(GetLastError()); @@ -252,7 +241,8 @@ const pe_thunk_t *pe_thunk_get_next(const pe_thunk_t *thunk) return thunk_next; } -void *pe_thunk_get_resolved_function(HMODULE target_pe, HMODULE import_pe, const pe_thunk_t *thunk) +void *pe_thunk_get_resolved_function( + HMODULE target_pe, HMODULE import_pe, const pe_thunk_t *thunk) { void *addr; @@ -262,11 +252,12 @@ void *pe_thunk_get_resolved_function(HMODULE target_pe, HMODULE import_pe, const if (thunk->u1.AddressOfData != 0) { if (IMAGE_SNAP_BY_ORDINAL(thunk->u1.Ordinal)) { - LPCSTR functionOrdinal = (LPCSTR)IMAGE_ORDINAL(thunk->u1.Ordinal); - addr = (void *)GetProcAddress(import_pe, functionOrdinal); + LPCSTR functionOrdinal = (LPCSTR) IMAGE_ORDINAL(thunk->u1.Ordinal); + addr = (void *) GetProcAddress(import_pe, functionOrdinal); } else { - PIMAGE_IMPORT_BY_NAME functionName = pe_offset(target_pe, thunk->u1.AddressOfData); - addr = (void *)GetProcAddress(import_pe, functionName->Name); + PIMAGE_IMPORT_BY_NAME functionName = + pe_offset(target_pe, thunk->u1.AddressOfData); + addr = (void *) GetProcAddress(import_pe, functionName->Name); } } else { addr = NULL; @@ -277,7 +268,8 @@ void *pe_thunk_get_resolved_function(HMODULE target_pe, HMODULE import_pe, const void pe_resolve_imports(HMODULE target_pe) { - for (const pe_iid_t *iid = pe_iid_get_first(target_pe); iid != NULL; iid = pe_iid_get_next(target_pe, iid)) { + for (const pe_iid_t *iid = pe_iid_get_first(target_pe); iid != NULL; + iid = pe_iid_get_next(target_pe, iid)) { const char *iid_name; HMODULE imported_pe; @@ -285,13 +277,16 @@ void pe_resolve_imports(HMODULE target_pe) imported_pe = LoadLibraryA(iid_name); assert(imported_pe != NULL); - for (const pe_thunk_t *thunk = pe_thunk_get_first(target_pe, iid); thunk != NULL; thunk = pe_thunk_get_next(thunk)) { + for (const pe_thunk_t *thunk = pe_thunk_get_first(target_pe, iid); + thunk != NULL; + thunk = pe_thunk_get_next(thunk)) { void *addr; - addr = pe_thunk_get_resolved_function(target_pe, imported_pe, thunk); + addr = + pe_thunk_get_resolved_function(target_pe, imported_pe, thunk); if (addr != NULL) { - pe_patch((void*)&thunk->u1.Function, &addr, sizeof(PDWORD)); + pe_patch((void *) &thunk->u1.Function, &addr, sizeof(PDWORD)); } } } diff --git a/src/main/hook/pe.h b/src/main/hook/pe.h index 3da90ef..768f2e3 100644 --- a/src/main/hook/pe.h +++ b/src/main/hook/pe.h @@ -9,7 +9,7 @@ typedef IMAGE_IMPORT_DESCRIPTOR pe_iid_t; typedef IMAGE_THUNK_DATA pe_thunk_t; -typedef DWORD (CALLBACK *dll_entry_t)(HMODULE self, DWORD reason, void *ctx); +typedef DWORD(CALLBACK *dll_entry_t)(HMODULE self, DWORD reason, void *ctx); struct pe_iat_entry { const char *name; @@ -21,10 +21,7 @@ const pe_iid_t *pe_iid_get_first(HMODULE pe); const char *pe_iid_get_name(HMODULE pe, const pe_iid_t *iid); const pe_iid_t *pe_iid_get_next(HMODULE pe, const pe_iid_t *iid); HRESULT pe_iid_get_iat_entry( - HMODULE pe, - const pe_iid_t *iid, - size_t n, - struct pe_iat_entry *entry); + HMODULE pe, const pe_iid_t *iid, size_t n, struct pe_iat_entry *entry); void *pe_get_export(HMODULE pe, const char *name, uint16_t ord); void *pe_get_entry_point(HMODULE pe); HRESULT pe_patch(void *dest, const void *src, size_t nbytes); diff --git a/src/main/hook/process.c b/src/main/hook/process.c index afa59f0..be4843b 100644 --- a/src/main/hook/process.c +++ b/src/main/hook/process.c @@ -12,24 +12,18 @@ #include "hook/pe.h" #include "hook/process.h" -static bool thread_match_startup( - const CONTEXT *ctx, - void *ntstart, - void *exe_entry) +static bool +thread_match_startup(const CONTEXT *ctx, void *ntstart, void *exe_entry) { #ifdef _M_AMD64 - return ctx->Rip == (DWORD64) ntstart && - ctx->Rcx == (DWORD64) exe_entry; + return ctx->Rip == (DWORD64) ntstart && ctx->Rcx == (DWORD64) exe_entry; #else - return ctx->Eip == (DWORD) ntstart && - ctx->Eax == (DWORD) exe_entry; + return ctx->Eip == (DWORD) ntstart && ctx->Eax == (DWORD) exe_entry; #endif } static void thread_patch_startup( - process_entry_t new_entry, - process_entry_t *orig_entry, - CONTEXT *ctx) + process_entry_t new_entry, process_entry_t *orig_entry, CONTEXT *ctx) { #ifdef _M_AMD64 *orig_entry = (void *) ctx->Rcx; @@ -41,9 +35,7 @@ static void thread_patch_startup( } static HRESULT process_hijack_try_thread( - process_entry_t new_entry, - process_entry_t *orig_entry, - DWORD thread_id) + process_entry_t new_entry, process_entry_t *orig_entry, DWORD thread_id) { CONTEXT ctx; HMODULE exe; @@ -85,10 +77,8 @@ static HRESULT process_hijack_try_thread( goto end; } - thread = OpenThread( - THREAD_GET_CONTEXT | THREAD_SET_CONTEXT, - FALSE, - thread_id); + thread = + OpenThread(THREAD_GET_CONTEXT | THREAD_SET_CONTEXT, FALSE, thread_id); if (thread == NULL) { hr = HRESULT_FROM_WIN32(GetLastError()); @@ -134,9 +124,8 @@ end: return hr; } -HRESULT process_hijack_startup( - process_entry_t new_entry, - process_entry_t *orig_entry) +HRESULT +process_hijack_startup(process_entry_t new_entry, process_entry_t *orig_entry) { THREADENTRY32 thread; HANDLE snap; @@ -175,9 +164,7 @@ HRESULT process_hijack_startup( } hr = process_hijack_try_thread( - new_entry, - orig_entry, - thread.th32ThreadID); + new_entry, orig_entry, thread.th32ThreadID); if (hr == S_OK) { /* Main thread successfully hijacked, finish up */ diff --git a/src/main/hook/process.h b/src/main/hook/process.h index 85937c4..1f64dda 100644 --- a/src/main/hook/process.h +++ b/src/main/hook/process.h @@ -2,8 +2,7 @@ #include -typedef DWORD (CALLBACK *process_entry_t)(void); +typedef DWORD(CALLBACK *process_entry_t)(void); -HRESULT process_hijack_startup( - process_entry_t new_entry, - process_entry_t *orig_entry); +HRESULT +process_hijack_startup(process_entry_t new_entry, process_entry_t *orig_entry); diff --git a/src/main/hook/table.c b/src/main/hook/table.c index 57ff0c0..ed67b3b 100644 --- a/src/main/hook/table.c +++ b/src/main/hook/table.c @@ -13,36 +13,27 @@ static const char apiset_prefix[] = "api-ms-win-core-"; static const size_t apiset_prefix_len = sizeof(apiset_prefix) - 1; static void hook_table_apply_to_all( - const char *depname, - const struct hook_symbol *syms, - size_t nsyms); + const char *depname, const struct hook_symbol *syms, size_t nsyms); static void hook_table_apply_to_iid( - HMODULE target, - const pe_iid_t *iid, - const struct hook_symbol *syms, - size_t nsyms); + HMODULE target, + const pe_iid_t *iid, + const struct hook_symbol *syms, + size_t nsyms); static bool hook_table_match_module( - HMODULE target, - const char *iid_name, - const char *depname); + HMODULE target, const char *iid_name, const char *depname); static bool hook_table_match_proc( - const struct pe_iat_entry *iate, - const struct hook_symbol *sym); + const struct pe_iat_entry *iate, const struct hook_symbol *sym); static void hook_table_apply_to_all( - const char *depname, - const struct hook_symbol *syms, - size_t nsyms) + const char *depname, const struct hook_symbol *syms, size_t nsyms) { const peb_dll_t *dll; HMODULE pe; - for ( dll = peb_dll_get_first() ; - dll != NULL ; - dll = peb_dll_get_next(dll)) { + for (dll = peb_dll_get_first(); dll != NULL; dll = peb_dll_get_next(dll)) { pe = peb_dll_get_base(dll); if (pe == NULL) { @@ -54,10 +45,10 @@ static void hook_table_apply_to_all( } void hook_table_apply( - HMODULE target, - const char *depname, - const struct hook_symbol *syms, - size_t nsyms) + HMODULE target, + const char *depname, + const struct hook_symbol *syms, + size_t nsyms) { const pe_iid_t *iid; const char *iid_name; @@ -71,9 +62,8 @@ void hook_table_apply( hook_table_apply_to_all(depname, syms, nsyms); } else { - for ( iid = pe_iid_get_first(target) ; - iid != NULL ; - iid = pe_iid_get_next(target, iid)) { + for (iid = pe_iid_get_first(target); iid != NULL; + iid = pe_iid_get_next(target, iid)) { iid_name = pe_iid_get_name(target, iid); if (hook_table_match_module(target, iid_name, depname)) { @@ -84,10 +74,10 @@ void hook_table_apply( } static void hook_table_apply_to_iid( - HMODULE target, - const pe_iid_t *iid, - const struct hook_symbol *syms, - size_t nsyms) + HMODULE target, + const pe_iid_t *iid, + const struct hook_symbol *syms, + size_t nsyms) { struct pe_iat_entry iate; size_t i; @@ -97,7 +87,7 @@ static void hook_table_apply_to_iid( i = 0; while (pe_iid_get_iat_entry(target, iid, i++, &iate) == S_OK) { - for (j = 0 ; j < nsyms ; j++) { + for (j = 0; j < nsyms; j++) { sym = &syms[j]; if (hook_table_match_proc(&iate, sym)) { @@ -112,9 +102,7 @@ static void hook_table_apply_to_iid( } static bool hook_table_match_module( - HMODULE target, - const char *iid_name, - const char *depname) + HMODULE target, const char *iid_name, const char *depname) { HMODULE kernel32; int result; @@ -163,12 +151,10 @@ static bool hook_table_match_module( } static bool hook_table_match_proc( - const struct pe_iat_entry *iate, - const struct hook_symbol *sym) + const struct pe_iat_entry *iate, const struct hook_symbol *sym) { - if ( sym->name != NULL && - iate->name != NULL && - strcmp(sym->name, iate->name) == 0) { + if (sym->name != NULL && iate->name != NULL && + strcmp(sym->name, iate->name) == 0) { return true; } diff --git a/src/main/hook/table.h b/src/main/hook/table.h index f4028cc..5b327eb 100644 --- a/src/main/hook/table.h +++ b/src/main/hook/table.h @@ -13,13 +13,13 @@ struct hook_symbol { }; void hook_table_apply( - HMODULE target, - const char *depname, - const struct hook_symbol *syms, - size_t nsyms); + HMODULE target, + const char *depname, + const struct hook_symbol *syms, + size_t nsyms); void hook_table_revert( - HMODULE target, - const char *depname, - const struct hook_symbol *syms, - size_t nsyms); + HMODULE target, + const char *depname, + const struct hook_symbol *syms, + size_t nsyms); diff --git a/src/main/hooklib/memfile.c b/src/main/hooklib/memfile.c index 17ea6ba..08dbeba 100644 --- a/src/main/hooklib/memfile.c +++ b/src/main/hooklib/memfile.c @@ -28,7 +28,7 @@ static CRITICAL_SECTION hooked_files_cs; BOOL my_GetFileInformationByHandle( HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation); -BOOL (*real_GetFileInformationByHandle) +BOOL(*real_GetFileInformationByHandle) (HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation); static const struct hook_symbol memfile_hook_kernel32_syms[] = { diff --git a/src/main/iidx-bio2-exit-hook/main.c b/src/main/iidx-bio2-exit-hook/main.c index e8114d7..13ac825 100644 --- a/src/main/iidx-bio2-exit-hook/main.c +++ b/src/main/iidx-bio2-exit-hook/main.c @@ -21,8 +21,8 @@ static const size_t _SIZE_ACIO_WRITE_SOF = sizeof(uint8_t); // See struct ac_io_message: addr + code + seq_no + nbytes -static const size_t _SIZE_ACIO_WRITE_MSG_HEADER = - sizeof(uint8_t) + sizeof(uint16_t) + sizeof(uint8_t) * 2; +static const size_t _SIZE_ACIO_WRITE_MSG_HEADER = + sizeof(uint8_t) + sizeof(uint16_t) + sizeof(uint8_t) * 2; static const uint8_t _ACIO_NODE_BIO2 = 0x01; static wchar_t _device_path[MAX_PATH]; @@ -31,7 +31,7 @@ static HANDLE _device_handle; static struct iobuf _buffer; static struct iobuf _buffer_unescaped; -static void _unescape_acio_buffer(struct iobuf* in, struct iobuf* out) +static void _unescape_acio_buffer(struct iobuf *in, struct iobuf *out) { log_assert(in); log_assert(out); @@ -68,7 +68,7 @@ static void _switch_off_all_lights(struct bi2a_iidx_state_out *state_out) for (uint8_t i = 0; i < sizeof(state_out->PANEL); i++) { state_out->PANEL[i].l_state = 0; } - + for (uint8_t i = 0; i < sizeof(state_out->DECKSW); i++) { state_out->DECKSW[i].l_state = 0; } @@ -109,7 +109,7 @@ static HRESULT _iohook_handler(struct irp *irp) switch (irp->op) { case IRP_OP_READ: result = iohook_invoke_next(irp); - + if (result != S_OK) { return result; } @@ -128,66 +128,78 @@ static HRESULT _iohook_handler(struct irp *irp) return result; case IRP_OP_WRITE: - // Use write as a trigger to evaluate buffered data of previous reads. - // Good enough to check for some button press combincation to exit the game - // Not implementing a full acio stack for performance reasons - // and to keep the complexity of this rather low for such crude feature. - + // Use write as a trigger to evaluate buffered data of previous + // reads. Good enough to check for some button press + // combincation to exit the game Not implementing a full acio + // stack for performance reasons and to keep the complexity of + // this rather low for such crude feature. + // Un-escape the buffer to prepare it for further evaluation _buffer_unescaped.pos = 0; _unescape_acio_buffer(&_buffer, &_buffer_unescaped); - struct ac_io_message *msg = (struct ac_io_message*) _buffer_unescaped.bytes; + struct ac_io_message *msg = + (struct ac_io_message *) _buffer_unescaped.bytes; - if (msg->addr == (AC_IO_RESPONSE_FLAG | _ACIO_NODE_BIO2) && - ac_io_u16(msg->cmd.code) == BIO2_BI2A_CMD_POLL) { - struct bi2a_iidx_state_in *state_in = (struct bi2a_iidx_state_in*) msg->cmd.raw; + if (msg->addr == (AC_IO_RESPONSE_FLAG | _ACIO_NODE_BIO2) && + ac_io_u16(msg->cmd.code) == BIO2_BI2A_CMD_POLL) { + struct bi2a_iidx_state_in *state_in = + (struct bi2a_iidx_state_in *) msg->cmd.raw; - if (state_in->PANEL.y_start1 && state_in->PANEL.y_start2 && - state_in->PANEL.y_vefx && state_in->PANEL.y_effect) { + if (state_in->PANEL.y_start1 && state_in->PANEL.y_start2 && + state_in->PANEL.y_vefx && state_in->PANEL.y_effect) { log_info("Exit hook triggered"); - // Last opportunity to write some output data to switch off lights - // Hacky, since we don't have an acio stack but some checks to - // protect from bad things happening - - if (irp->write.nbytes >= - _SIZE_ACIO_WRITE_SOF + + // Last opportunity to write some output data to switch + // off lights Hacky, since we don't have an acio stack + // but some checks to protect from bad things happening + + if (irp->write.nbytes >= _SIZE_ACIO_WRITE_SOF + _SIZE_ACIO_WRITE_MSG_HEADER + sizeof(struct bi2a_iidx_state_out)) { log_misc("Switching off lights"); // +_SIZE_ACIO_WRITE_SOF: Skip leading 0xAA - struct ac_io_message *msg_out = - (struct ac_io_message*) (irp->write.bytes + _SIZE_ACIO_WRITE_SOF); + struct ac_io_message *msg_out = + (struct ac_io_message *) (irp->write.bytes + + _SIZE_ACIO_WRITE_SOF); - // Guard assumption that reading poll is always followed by a writing - // poll (according to traffic dumps from iidx 27, that's the case) - if (msg_out->addr == _ACIO_NODE_BIO2 && - ac_io_u16(msg_out->cmd.code) == BIO2_BI2A_CMD_POLL && - msg_out->cmd.count == sizeof(struct bi2a_iidx_state_out)) { + // Guard assumption that reading poll is always + // followed by a writing poll (according to traffic + // dumps from iidx 27, that's the case) + if (msg_out->addr == _ACIO_NODE_BIO2 && + ac_io_u16(msg_out->cmd.code) == + BIO2_BI2A_CMD_POLL && + msg_out->cmd.count == + sizeof(struct bi2a_iidx_state_out)) { struct bi2a_iidx_state_out *state_out = - (struct bi2a_iidx_state_out*) msg_out->cmd.raw; + (struct bi2a_iidx_state_out *) + msg_out->cmd.raw; _switch_off_all_lights(state_out); result = iohook_invoke_next(irp); if (result != S_OK) { - log_warning("Writing output to switch lights off failed: %lX", + log_warning( + "Writing output to switch lights off " + "failed: %lX", result); } } else { - log_warning("Skipping switching off lights, write output not " + log_warning( + "Skipping switching off lights, write " + "output not " "identified as a poll message"); } } else { log_warning( - "Skipped switching off lights due to insufficient buffer size"); + "Skipped switching off lights due to " + "insufficient buffer size"); } Sleep(1000); - + /* Don't use ExitProcess. This might result in deadlocks on newer games which rely more on multi threading */ proc_terminate_current_process(0); @@ -222,18 +234,14 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) char buffer[MAX_PATH]; - if (!bio2drv_detect( - DETECT_DEVICEID, - 0, - buffer, - sizeof(buffer))) { + if (!bio2drv_detect(DETECT_DEVICEID, 0, buffer, sizeof(buffer))) { log_warning("Autodetecting IIDX BIO2 failed, disabling exit hook"); return TRUE; } log_info("BIO2 device found: %s", buffer); - wchar_t* buffer_widen = str_widen(buffer); + wchar_t *buffer_widen = str_widen(buffer); wcscpy(_device_path, buffer_widen); free(buffer_widen); diff --git a/src/main/iidxhook-util/acio.c b/src/main/iidxhook-util/acio.c index 2d6e6a3..6291336 100644 --- a/src/main/iidxhook-util/acio.c +++ b/src/main/iidxhook-util/acio.c @@ -33,7 +33,6 @@ static struct ac_io_emu_icca iidxhook_util_acio_emu_icca[2]; static bool iidxhook_util_icca_override_version; static enum ac_io_emu_icca_version iidxhook_util_icca_override_version_value; - void iidxhook_util_acio_override_version(enum ac_io_emu_icca_version version) { iidxhook_util_icca_override_version = true; @@ -56,8 +55,7 @@ void iidxhook_util_acio_init(bool legacy_mode) if (iidxhook_util_icca_override_version) { ac_io_emu_icca_set_version( &iidxhook_util_acio_emu_icca[i], - iidxhook_util_icca_override_version_value - ); + iidxhook_util_icca_override_version_value); } } diff --git a/src/main/iidxhook-util/acio.h b/src/main/iidxhook-util/acio.h index 1a7d204..3ea428f 100644 --- a/src/main/iidxhook-util/acio.h +++ b/src/main/iidxhook-util/acio.h @@ -20,7 +20,6 @@ */ void iidxhook_util_acio_init(bool legacy_mode); - /** * Use the specified ICCA emulation version */ diff --git a/src/main/iidxhook-util/config-gfx.c b/src/main/iidxhook-util/config-gfx.c index 3242c5d..56ed3e7 100644 --- a/src/main/iidxhook-util/config-gfx.c +++ b/src/main/iidxhook-util/config-gfx.c @@ -161,7 +161,7 @@ void iidxhook_config_gfx_init(struct cconfig *config) IIDXHOOK_CONFIG_GFX_DEFAULT_DEVICE_ADAPTER_VALUE, "D3D9 device adapter (monitor), -1 to use default, " "0, 1, 2 etc. to use specified adapter"); - + cconfig_util_set_bool( config, IIDXHOOK_CONFIG_GFX_DIAGONAL_TEARING_FIX_KEY, diff --git a/src/main/iidxhook-util/config-io.c b/src/main/iidxhook-util/config-io.c index a2095bf..3055ac6 100644 --- a/src/main/iidxhook-util/config-io.c +++ b/src/main/iidxhook-util/config-io.c @@ -24,7 +24,8 @@ void iidxhook_config_io_init(struct cconfig *config) config, IIDXHOOK_UTIL_CONFIG_IO_DISABLE_IO_EMU_KEY, IIDXHOOK_UTIL_CONFIG_IO_DEFAULT_DISABLE_IO_EMU_VALUE, - "Disable ezusb IO emulation and enable usage of real ezusb1/2 IO hardware"); + "Disable ezusb IO emulation and enable usage of real ezusb1/2 IO " + "hardware"); } void iidxhook_config_io_get( diff --git a/src/main/iidxhook-util/config-misc.c b/src/main/iidxhook-util/config-misc.c index acdb749..7a18499 100644 --- a/src/main/iidxhook-util/config-misc.c +++ b/src/main/iidxhook-util/config-misc.c @@ -30,7 +30,8 @@ void iidxhook_config_misc_init(struct cconfig *config) config, IIDXHOOK_CONFIG_MISC_SETTINGS_PATH_STUB_KEY, IIDXHOOK_CONFIG_MISC_DEFAULT_SETTINGS_PATH_STUB_VALUE, - "Path to store the settings, e.g. bookkeeping, operator settings. d:, e: and f: drive configuration/settings data"); + "Path to store the settings, e.g. bookkeeping, operator settings. d:, " + "e: and f: drive configuration/settings data"); } void iidxhook_config_misc_get( diff --git a/src/main/iidxhook-util/d3d9.c b/src/main/iidxhook-util/d3d9.c index 4cabdd9..477d753 100644 --- a/src/main/iidxhook-util/d3d9.c +++ b/src/main/iidxhook-util/d3d9.c @@ -65,7 +65,7 @@ static struct { D3DTEXTUREFILTERTYPE filter; } iidxhook_util_d3d9_back_buffer_scaling; -static IDirect3DVertexShader9* vertex_shader; +static IDirect3DVertexShader9 *vertex_shader; /* ------------------------------------------------------------------------------------------------------------------ */ @@ -678,19 +678,19 @@ iidxhook_util_d3d9_iidx11_to_17_fix_uvs_bg_videos(struct hook_d3d9_irp *irp) vertices[2].y >= 404.0f && vertices[2].y <= 408.0f) && (vertices[3].x >= 493.0f && vertices[3].x <= 494.0f && vertices[3].y >= 404.0f && vertices[3].y <= 408.0f))) { - /* fix UVs - 1.0f / 512 fixes the diagonal seam connecting the two triangles - which is visible on some GPUs (why? idk) - */ - vertices[0].tu = 0.0f + 1.0f / 512; - vertices[0].tv = 1.0f; - vertices[1].tu = 1.0f; - vertices[1].tv = 1.0f; - vertices[2].tu = 1.0f; - vertices[2].tv = 0.0f + 1.0f / 512; - vertices[3].tu = 0.0f + 1.0f / 512; - vertices[3].tv = 0.0f + 1.0f / 512; - } + /* fix UVs + 1.0f / 512 fixes the diagonal seam connecting the two + triangles which is visible on some GPUs (why? idk) + */ + vertices[0].tu = 0.0f + 1.0f / 512; + vertices[0].tv = 1.0f; + vertices[1].tu = 1.0f; + vertices[1].tv = 1.0f; + vertices[2].tu = 1.0f; + vertices[2].tv = 0.0f + 1.0f / 512; + vertices[3].tu = 0.0f + 1.0f / 512; + vertices[3].tv = 0.0f + 1.0f / 512; + } } } @@ -910,28 +910,36 @@ iidxhook_util_d3d9_iidx18_and_19_fix_diagonal_tearing(struct hook_d3d9_irp *irp) HRESULT hr; log_assert(irp); - log_assert(irp->op == HOOK_D3D9_IRP_OP_DEV_SET_VIEWPORT || irp->op == HOOK_D3D9_IRP_OP_DEV_SET_VERTEX_SHADER); + log_assert( + irp->op == HOOK_D3D9_IRP_OP_DEV_SET_VIEWPORT || + irp->op == HOOK_D3D9_IRP_OP_DEV_SET_VERTEX_SHADER); - if (!iidxhook_util_d3d9_config.iidx18_and_19_diagonal_tearing_fix) - { + if (!iidxhook_util_d3d9_config.iidx18_and_19_diagonal_tearing_fix) { return; } - if (irp->op == HOOK_D3D9_IRP_OP_DEV_SET_VIEWPORT) - { + if (irp->op == HOOK_D3D9_IRP_OP_DEV_SET_VIEWPORT) { const D3DVIEWPORT9 *pViewport = irp->args.dev_set_viewport.pViewport; - const float fix_offset[2] = {-1.0F / (float)pViewport->Width, -1.0F / (float)pViewport->Height}; + const float fix_offset[2] = { + -1.0F / (float) pViewport->Width, + -1.0F / (float) pViewport->Height}; - hr = IDirect3DDevice9_SetVertexShaderConstantF(irp->args.dev_set_viewport.self, 63, fix_offset, lengthof(fix_offset)); + hr = IDirect3DDevice9_SetVertexShaderConstantF( + irp->args.dev_set_viewport.self, + 63, + fix_offset, + lengthof(fix_offset)); if (hr != S_OK) { log_warning("SetVertexShaderConstantF failed: %lX", hr); } } - if (irp->op == HOOK_D3D9_IRP_OP_DEV_SET_VERTEX_SHADER) - { + if (irp->op == HOOK_D3D9_IRP_OP_DEV_SET_VERTEX_SHADER) { if (!vertex_shader) { - hr = IDirect3DDevice9_CreateVertexShader(irp->args.dev_set_vertex_shader.self, (const DWORD*) g_vs11_vs_main, &vertex_shader); + hr = IDirect3DDevice9_CreateVertexShader( + irp->args.dev_set_vertex_shader.self, + (const DWORD *) g_vs11_vs_main, + &vertex_shader); if (hr != S_OK) { log_fatal("CreateVertexShader failed: %lX", hr); } diff --git a/src/main/iidxhook-util/settings.c b/src/main/iidxhook-util/settings.c index 5b6b3c8..4bdc6df 100644 --- a/src/main/iidxhook-util/settings.c +++ b/src/main/iidxhook-util/settings.c @@ -95,8 +95,8 @@ void settings_hook_init(void) log_info("Inserted settings hooks, settings path: %s", settings_path); } -void settings_hook_set_path(const char* path) -{ +void settings_hook_set_path(const char *path) +{ size_t len; len = strlen(path); @@ -121,9 +121,9 @@ HRESULT settings_hook_dispatch_irp(struct irp *irp) { if (irp->op == IRP_OP_OPEN && - (irp->open_filename[0] == L'd' || irp->open_filename[0] == L'e' || - irp->open_filename[0] == L'f') && - irp->open_filename[1] == L':') { + (irp->open_filename[0] == L'd' || irp->open_filename[0] == L'e' || + irp->open_filename[0] == L'f') && + irp->open_filename[1] == L':') { HRESULT result; char new_path[MAX_PATH]; const wchar_t *old_filename_wstr; @@ -161,7 +161,8 @@ settings_hook_dispatch_irp(struct irp *irp) new_path_folder[settings_path_len + 2] = '\0'; if (!path_exists(new_path_folder)) { - log_misc("Creating local settings folder %s", new_path_folder); + log_misc( + "Creating local settings folder %s", new_path_folder); CreateDirectoryA(new_path_folder, NULL); } } diff --git a/src/main/iidxhook-util/settings.h b/src/main/iidxhook-util/settings.h index 5632f8d..d95d090 100644 --- a/src/main/iidxhook-util/settings.h +++ b/src/main/iidxhook-util/settings.h @@ -7,17 +7,17 @@ * Remaps the paths for storing "settings data" that are usually stored on the * drives d:\, e:\ and f:\ by the game. This defaults to the local folders * d\, e\ and f\. - * + * * Required hook for 9th to Lincle. */ void settings_hook_init(void); /** * Change the path where settings file are stored. - * + * * @param path Destination path for storage, relative or absolute. */ -void settings_hook_set_path(const char* path); +void settings_hook_set_path(const char *path); /** * iohook dispatch function diff --git a/src/main/iidxhook-util/vertex-shader.h b/src/main/iidxhook-util/vertex-shader.h index 35ff048..fd05979 100644 --- a/src/main/iidxhook-util/vertex-shader.h +++ b/src/main/iidxhook-util/vertex-shader.h @@ -34,74 +34,32 @@ // approximately 8 instruction slots used #endif -const BYTE g_vs11_vs_main[] = -{ - 1, 1, 254, 255, 254, 255, - 59, 0, 67, 84, 65, 66, - 28, 0, 0, 0, 191, 0, - 0, 0, 1, 1, 254, 255, - 3, 0, 0, 0, 28, 0, - 0, 0, 0, 1, 0, 0, - 184, 0, 0, 0, 88, 0, - 0, 0, 2, 0, 4, 0, - 1, 0, 18, 0, 104, 0, - 0, 0, 0, 0, 0, 0, - 120, 0, 0, 0, 2, 0, - 63, 0, 1, 0, 254, 0, - 132, 0, 0, 0, 0, 0, - 0, 0, 148, 0, 0, 0, - 2, 0, 0, 0, 4, 0, - 2, 0, 168, 0, 0, 0, - 0, 0, 0, 0, 67, 111, - 108, 111, 114, 77, 117, 108, - 116, 105, 112, 108, 121, 0, - 171, 171, 1, 0, 3, 0, - 1, 0, 4, 0, 1, 0, - 0, 0, 0, 0, 0, 0, - 70, 105, 120, 79, 102, 102, - 115, 101, 116, 0, 171, 171, - 1, 0, 3, 0, 1, 0, - 2, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 87, 111, - 114, 108, 100, 86, 105, 101, - 119, 80, 114, 111, 106, 101, - 99, 116, 105, 111, 110, 0, - 3, 0, 3, 0, 4, 0, - 4, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 118, 115, - 95, 49, 95, 49, 0, 77, - 105, 99, 114, 111, 115, 111, - 102, 116, 32, 40, 82, 41, - 32, 72, 76, 83, 76, 32, - 83, 104, 97, 100, 101, 114, - 32, 67, 111, 109, 112, 105, - 108, 101, 114, 32, 49, 48, - 46, 49, 0, 171, 31, 0, - 0, 0, 0, 0, 0, 128, - 0, 0, 15, 144, 31, 0, - 0, 0, 10, 0, 0, 128, - 1, 0, 15, 144, 31, 0, - 0, 0, 5, 0, 0, 128, - 2, 0, 15, 144, 9, 0, - 0, 0, 0, 0, 4, 192, - 0, 0, 228, 144, 2, 0, - 228, 160, 5, 0, 0, 0, - 0, 0, 15, 208, 1, 0, - 228, 144, 4, 0, 228, 160, - 9, 0, 0, 0, 0, 0, - 1, 128, 0, 0, 228, 144, - 0, 0, 228, 160, 9, 0, - 0, 0, 0, 0, 2, 128, - 0, 0, 228, 144, 1, 0, - 228, 160, 9, 0, 0, 0, - 0, 0, 4, 128, 0, 0, - 228, 144, 3, 0, 228, 160, - 4, 0, 0, 0, 0, 0, - 3, 192, 63, 0, 228, 160, - 0, 0, 170, 128, 0, 0, - 228, 128, 1, 0, 0, 0, - 0, 0, 8, 192, 0, 0, - 170, 128, 1, 0, 0, 0, - 0, 0, 3, 224, 2, 0, - 228, 144, 255, 255, 0, 0 -}; +const BYTE g_vs11_vs_main[] = { + 1, 1, 254, 255, 254, 255, 59, 0, 67, 84, 65, 66, 28, 0, 0, + 0, 191, 0, 0, 0, 1, 1, 254, 255, 3, 0, 0, 0, 28, 0, + 0, 0, 0, 1, 0, 0, 184, 0, 0, 0, 88, 0, 0, 0, 2, + 0, 4, 0, 1, 0, 18, 0, 104, 0, 0, 0, 0, 0, 0, 0, + 120, 0, 0, 0, 2, 0, 63, 0, 1, 0, 254, 0, 132, 0, 0, + 0, 0, 0, 0, 0, 148, 0, 0, 0, 2, 0, 0, 0, 4, 0, + 2, 0, 168, 0, 0, 0, 0, 0, 0, 0, 67, 111, 108, 111, 114, + 77, 117, 108, 116, 105, 112, 108, 121, 0, 171, 171, 1, 0, 3, 0, + 1, 0, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 70, 105, 120, + 79, 102, 102, 115, 101, 116, 0, 171, 171, 1, 0, 3, 0, 1, 0, + 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 87, 111, 114, 108, 100, + 86, 105, 101, 119, 80, 114, 111, 106, 101, 99, 116, 105, 111, 110, 0, + 3, 0, 3, 0, 4, 0, 4, 0, 1, 0, 0, 0, 0, 0, 0, + 0, 118, 115, 95, 49, 95, 49, 0, 77, 105, 99, 114, 111, 115, 111, + 102, 116, 32, 40, 82, 41, 32, 72, 76, 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, 109, 112, 105, 108, 101, 114, 32, 49, 48, + 46, 49, 0, 171, 31, 0, 0, 0, 0, 0, 0, 128, 0, 0, 15, + 144, 31, 0, 0, 0, 10, 0, 0, 128, 1, 0, 15, 144, 31, 0, + 0, 0, 5, 0, 0, 128, 2, 0, 15, 144, 9, 0, 0, 0, 0, + 0, 4, 192, 0, 0, 228, 144, 2, 0, 228, 160, 5, 0, 0, 0, + 0, 0, 15, 208, 1, 0, 228, 144, 4, 0, 228, 160, 9, 0, 0, + 0, 0, 0, 1, 128, 0, 0, 228, 144, 0, 0, 228, 160, 9, 0, + 0, 0, 0, 0, 2, 128, 0, 0, 228, 144, 1, 0, 228, 160, 9, + 0, 0, 0, 0, 0, 4, 128, 0, 0, 228, 144, 3, 0, 228, 160, + 4, 0, 0, 0, 0, 0, 3, 192, 63, 0, 228, 160, 0, 0, 170, + 128, 0, 0, 228, 128, 1, 0, 0, 0, 0, 0, 8, 192, 0, 0, + 170, 128, 1, 0, 0, 0, 0, 0, 3, 224, 2, 0, 228, 144, 255, + 255, 0, 0}; diff --git a/src/main/iidxhook4-cn/dllmain.c b/src/main/iidxhook4-cn/dllmain.c index 9475342..ea2f42a 100644 --- a/src/main/iidxhook4-cn/dllmain.c +++ b/src/main/iidxhook4-cn/dllmain.c @@ -28,8 +28,8 @@ #include "iidxhook-util/config-eamuse.h" #include "iidxhook-util/config-gfx.h" #include "iidxhook-util/config-io.h" -#include "iidxhook-util/config-sec.h" #include "iidxhook-util/config-misc.h" +#include "iidxhook-util/config-sec.h" #include "iidxhook-util/d3d9.h" #include "iidxhook-util/settings.h" @@ -39,8 +39,8 @@ #include "util/log.h" -#define IIDXHOOK4_CN_INFO_HEADER \ - "iidxhook for Resort Anthem CN" \ +#define IIDXHOOK4_CN_INFO_HEADER \ + "iidxhook for Resort Anthem CN" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) #define IIDXHOOK4_CN_CMD_USAGE \ "Usage: inject.exe iidxhook4-cn.dll [options...]" @@ -80,9 +80,11 @@ iidxhook4_cn_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) d3d9_config.scale_back_buffer_filter = config_gfx->scale_back_buffer_filter; d3d9_config.forced_refresh_rate = config_gfx->forced_refresh_rate; d3d9_config.device_adapter = config_gfx->device_adapter; - d3d9_config.iidx18_and_19_diagonal_tearing_fix = config_gfx->diagonal_tearing_fix; + d3d9_config.iidx18_and_19_diagonal_tearing_fix = + config_gfx->diagonal_tearing_fix; d3d9_config.iidx14_to_19_nvidia_fix = true; - d3d9_config.iidx18_and_19_diagonal_tearing_fix = config_gfx->diagonal_tearing_fix; + d3d9_config.iidx18_and_19_diagonal_tearing_fix = + config_gfx->diagonal_tearing_fix; if (config_gfx->monitor_check == 0) { log_info("Auto monitor check enabled"); @@ -158,9 +160,10 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) log_info("Initializing iidxhook..."); /** - * This game is using a black round plug for game license management instead of a black usb dongle. - * No white dongle hooks applies since the game does not have network functionality. - * Also, card readers are not used/checked; no card reader hooks required. + * This game is using a black round plug for game license management instead + * of a black usb dongle. No white dongle hooks applies since the game does + * not have network functionality. Also, card readers are not used/checked; + * no card reader hooks required. */ ezusb_iidx_emu_node_security_plug_set_boot_version( &config_sec.boot_version); diff --git a/src/main/iidxhook4-cn/path.c b/src/main/iidxhook4-cn/path.c index bf96a4c..4ab6c5a 100644 --- a/src/main/iidxhook4-cn/path.c +++ b/src/main/iidxhook4-cn/path.c @@ -1,8 +1,8 @@ #define LOG_MODULE "path" -#include #include #include +#include #include "hook/table.h" @@ -48,12 +48,10 @@ static HANDLE(WINAPI *real_CreateFileW)( DWORD dwFlagsAndAttributes, HANDLE hTemplateFile); -static HANDLE WINAPI my_FindFirstFileA( - LPCSTR lpFileName, - LPWIN32_FIND_DATAA lpFindFileData); +static HANDLE WINAPI +my_FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData); static HANDLE(WINAPI *real_FindFirstFileA)( - LPCSTR lpFileName, - LPWIN32_FIND_DATAA lpFindFileData); + LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData); static const struct hook_symbol iidxhook4_cn_path_hook_syms[] = { {.name = "CreateFileA", @@ -131,9 +129,8 @@ static HANDLE WINAPI my_CreateFileW( hTemplateFile); } -static HANDLE WINAPI my_FindFirstFileA( - LPCSTR lpFileName, - LPWIN32_FIND_DATAA lpFindFileData) +static HANDLE WINAPI +my_FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData) { if (lpFileName != NULL && strstr(lpFileName, PATH_A) == lpFileName) { char relative_path[MAX_PATH] = "."; diff --git a/src/main/iidxhook4/dllmain.c b/src/main/iidxhook4/dllmain.c index e047fd7..d7993dd 100644 --- a/src/main/iidxhook4/dllmain.c +++ b/src/main/iidxhook4/dllmain.c @@ -72,7 +72,8 @@ iidxhook4_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) d3d9_config.forced_refresh_rate = config_gfx->forced_refresh_rate; d3d9_config.device_adapter = config_gfx->device_adapter; d3d9_config.iidx14_to_19_nvidia_fix = true; - d3d9_config.iidx18_and_19_diagonal_tearing_fix = config_gfx->diagonal_tearing_fix; + d3d9_config.iidx18_and_19_diagonal_tearing_fix = + config_gfx->diagonal_tearing_fix; if (config_gfx->monitor_check == 0) { log_info("Auto monitor check enabled"); @@ -140,11 +141,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (!config_io.disable_io_emu) { log_info("Starting IIDX IO backend"); - + 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"); } } else { @@ -153,11 +155,12 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (!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); - 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"); } } else { diff --git a/src/main/iidxhook5-cn/dllmain.c b/src/main/iidxhook5-cn/dllmain.c index 4700eb2..711c906 100644 --- a/src/main/iidxhook5-cn/dllmain.c +++ b/src/main/iidxhook5-cn/dllmain.c @@ -28,8 +28,8 @@ #include "iidxhook-util/config-eamuse.h" #include "iidxhook-util/config-gfx.h" #include "iidxhook-util/config-io.h" -#include "iidxhook-util/config-sec.h" #include "iidxhook-util/config-misc.h" +#include "iidxhook-util/config-sec.h" #include "iidxhook-util/d3d9.h" #include "iidxhook-util/settings.h" @@ -40,7 +40,7 @@ #include "util/log.h" #define IIDXHOOK5_CN_INFO_HEADER \ - "iidxhook for tricoro CN" \ + "iidxhook for tricoro CN" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) #define IIDXHOOK5_CN_CMD_USAGE \ "Usage: inject.exe iidxhook5-cn.dll [options...]" @@ -81,7 +81,8 @@ iidxhook5_cn_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) d3d9_config.forced_refresh_rate = config_gfx->forced_refresh_rate; d3d9_config.device_adapter = config_gfx->device_adapter; d3d9_config.iidx14_to_19_nvidia_fix = true; - d3d9_config.iidx18_and_19_diagonal_tearing_fix = config_gfx->diagonal_tearing_fix; + d3d9_config.iidx18_and_19_diagonal_tearing_fix = + config_gfx->diagonal_tearing_fix; iidxhook_util_d3d9_configure(&d3d9_config); @@ -139,9 +140,10 @@ static ATOM WINAPI my_RegisterClassA(const WNDCLASSA *lpWndClass) log_info("Initializing iidxhook..."); /** - * This game is using a black round plug for game license management instead of a black usb dongle. - * No white dongle hooks applies since the game does not have network functionality. - * Also, card readers are not used/checked; no card reader hooks required. + * This game is using a black round plug for game license management instead + * of a black usb dongle. No white dongle hooks applies since the game does + * not have network functionality. Also, card readers are not used/checked; + * no card reader hooks required. */ ezusb_iidx_emu_node_security_plug_set_boot_version( &config_sec.boot_version); diff --git a/src/main/iidxhook5-cn/path.c b/src/main/iidxhook5-cn/path.c index 13be1d9..d45bf22 100644 --- a/src/main/iidxhook5-cn/path.c +++ b/src/main/iidxhook5-cn/path.c @@ -1,8 +1,8 @@ #define LOG_MODULE "path" -#include #include #include +#include #include "hook/table.h" @@ -31,12 +31,10 @@ static HANDLE(WINAPI *real_CreateFileW)( DWORD dwFlagsAndAttributes, HANDLE hTemplateFile); -static HANDLE WINAPI my_FindFirstFileA( - LPCSTR lpFileName, - LPWIN32_FIND_DATAA lpFindFileData); +static HANDLE WINAPI +my_FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData); static HANDLE(WINAPI *real_FindFirstFileA)( - LPCSTR lpFileName, - LPWIN32_FIND_DATAA lpFindFileData); + LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData); static const struct hook_symbol iidxhook5_cn_path_hook_syms[] = { {.name = "CreateFileW", @@ -79,9 +77,8 @@ static HANDLE WINAPI my_CreateFileW( hTemplateFile); } -static HANDLE WINAPI my_FindFirstFileA( - LPCSTR lpFileName, - LPWIN32_FIND_DATAA lpFindFileData) +static HANDLE WINAPI +my_FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData) { if (lpFileName != NULL && strstr(lpFileName, PATH_A) == lpFileName) { char relative[MAX_PATH] = "."; diff --git a/src/main/iidxhook5/dllmain.c b/src/main/iidxhook5/dllmain.c index e13b545..7a03321 100644 --- a/src/main/iidxhook5/dllmain.c +++ b/src/main/iidxhook5/dllmain.c @@ -72,7 +72,8 @@ iidxhook5_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) d3d9_config.forced_refresh_rate = config_gfx->forced_refresh_rate; d3d9_config.device_adapter = config_gfx->device_adapter; d3d9_config.iidx14_to_19_nvidia_fix = true; - d3d9_config.iidx18_and_19_diagonal_tearing_fix = config_gfx->diagonal_tearing_fix; + d3d9_config.iidx18_and_19_diagonal_tearing_fix = + config_gfx->diagonal_tearing_fix; if (config_gfx->monitor_check == 0) { log_info("Auto monitor check enabled"); @@ -144,7 +145,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) 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"); } } else { @@ -157,7 +159,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) 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"); } } else { diff --git a/src/main/iidxhook6/dllmain.c b/src/main/iidxhook6/dllmain.c index 8ac0b85..4b689ae 100644 --- a/src/main/iidxhook6/dllmain.c +++ b/src/main/iidxhook6/dllmain.c @@ -115,7 +115,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) 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"); } } else { @@ -128,7 +129,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) 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"); } } else { diff --git a/src/main/iidxhook7/dllmain.c b/src/main/iidxhook7/dllmain.c index b220f8c..5faf1b2 100644 --- a/src/main/iidxhook7/dllmain.c +++ b/src/main/iidxhook7/dllmain.c @@ -115,7 +115,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) 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"); } } else { @@ -128,7 +129,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) 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"); } } else { diff --git a/src/main/iidxhook8/dllmain.c b/src/main/iidxhook8/dllmain.c index 1f74e35..95e968b 100644 --- a/src/main/iidxhook8/dllmain.c +++ b/src/main/iidxhook8/dllmain.c @@ -23,8 +23,8 @@ #include "iidxhook-util/d3d9.h" #include "iidxhook-util/log-server.h" -#include "bio2emu/emu.h" #include "bio2emu-iidx/bi2a.h" +#include "bio2emu/emu.h" #include "camhook/cam.h" #include "camhook/config-cam.h" @@ -36,7 +36,7 @@ #include "util/str.h" #include "util/thread.h" -#define IIDXHOOK8_INFO_HEADER \ +#define IIDXHOOK8_INFO_HEADER \ "iidxhook for Cannon Ballers/Rootage" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) "\n" #define IIDXHOOK8_CMD_USAGE \ diff --git a/src/main/iidxhook9/dllmain.c b/src/main/iidxhook9/dllmain.c index c3ced15..b7ae85a 100644 --- a/src/main/iidxhook9/dllmain.c +++ b/src/main/iidxhook9/dllmain.c @@ -61,7 +61,8 @@ static struct bio2emu_port bio2_emu = { .dispatcher = bio2_emu_bi2a_dispatch_request, }; -static bool load_configs() { +static bool load_configs() +{ struct cconfig *config; config = cconfig_init(); @@ -167,7 +168,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) if (!iidxhook9_config_io.lightning_mode) { bio2emu_init(); bio2_emu_bi2a_set_tt_multiplier(iidxhook9_config_io.tt_multiplier); - bio2_emu_bi2a_init(&bio2_emu, iidxhook9_config_io.disable_poll_limiter); + bio2_emu_bi2a_init( + &bio2_emu, iidxhook9_config_io.disable_poll_limiter); } } @@ -265,8 +267,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) goto end; } - - if (avs_is_active()){ + if (avs_is_active()) { // if AVS is loaded, we're likely too late to be a prehook // so we warn the user // and switch the current logging context to AVS so it shows up in logs diff --git a/src/main/iidxio-bio2/iidxio.c b/src/main/iidxio-bio2/iidxio.c index 6014c17..2bca0dc 100644 --- a/src/main/iidxio-bio2/iidxio.c +++ b/src/main/iidxio-bio2/iidxio.c @@ -135,7 +135,7 @@ bool iidx_io_init( char product[4]; aciodrv_device_get_node_product_ident(bio2_device_ctx, i, product); - + log_info( "> %d: %c%c%c%c\n", i, @@ -171,8 +171,9 @@ bool iidx_io_init( void iidx_io_fini(void) { - // Pushing some final state before closing the IO to the actual outputs, e.g. lights on/off - // can be a bit finicky. Do a few polls to "enforce"/flush this final state + // Pushing some final state before closing the IO to the actual outputs, + // e.g. lights on/off can be a bit finicky. Do a few polls to + // "enforce"/flush this final state for (uint8_t i = 0; i < 3; i++) { iidx_io_ep1_send(); iidx_io_ep2_recv(); @@ -194,39 +195,39 @@ void iidx_io_ep1_set_deck_lights(uint16_t deck_lights) { for (uint8_t i = 0; i < sizeof(pout_staging.DECKSW); i++) { pout_staging.DECKSW[i].l_state = (deck_lights & (1 << i)) > 0; - } + } } void iidx_io_ep1_set_panel_lights(uint8_t panel_lights) { - pout_staging.PANEL[BI2A_IIDX_PANEL_BUTTON_START_P1].l_state = + pout_staging.PANEL[BI2A_IIDX_PANEL_BUTTON_START_P1].l_state = (panel_lights & (1 << IIDX_IO_PANEL_P1_START)) > 0; - pout_staging.PANEL[BI2A_IIDX_PANEL_BUTTON_START_P2].l_state = + pout_staging.PANEL[BI2A_IIDX_PANEL_BUTTON_START_P2].l_state = (panel_lights & (1 << IIDX_IO_PANEL_P2_START)) > 0; - pout_staging.PANEL[BI2A_IIDX_PANEL_BUTTON_VEFX].l_state = + pout_staging.PANEL[BI2A_IIDX_PANEL_BUTTON_VEFX].l_state = (panel_lights & (1 << IIDX_IO_PANEL_VEFX)) > 0; - pout_staging.PANEL[BI2A_IIDX_PANEL_BUTTON_EFFECT].l_state = + pout_staging.PANEL[BI2A_IIDX_PANEL_BUTTON_EFFECT].l_state = (panel_lights & (1 << IIDX_IO_PANEL_EFFECT)) > 0; } void iidx_io_ep1_set_top_lamps(uint8_t top_lamps) { - pout_staging.SPOTLIGHT1[BI2A_IIDX_SPOTLIGHT_RIGHT_RED].l_state = + pout_staging.SPOTLIGHT1[BI2A_IIDX_SPOTLIGHT_RIGHT_RED].l_state = (top_lamps & (1 << IIDX_IO_TOP_LAMP_RIGHT_RED)) > 0; - pout_staging.SPOTLIGHT1[BI2A_IIDX_SPOTLIGHT_RIGHT_YELLOW].l_state = + pout_staging.SPOTLIGHT1[BI2A_IIDX_SPOTLIGHT_RIGHT_YELLOW].l_state = (top_lamps & (1 << IIDX_IO_TOP_LAMP_RIGHT_YELLOW)) > 0; - pout_staging.SPOTLIGHT1[BI2A_IIDX_SPOTLIGHT_RIGHT_GREEN].l_state = + pout_staging.SPOTLIGHT1[BI2A_IIDX_SPOTLIGHT_RIGHT_GREEN].l_state = (top_lamps & (1 << IIDX_IO_TOP_LAMP_RIGHT_GREEN)) > 0; - pout_staging.SPOTLIGHT1[BI2A_IIDX_SPOTLIGHT_RIGHT_BLUE].l_state = + pout_staging.SPOTLIGHT1[BI2A_IIDX_SPOTLIGHT_RIGHT_BLUE].l_state = (top_lamps & (1 << IIDX_IO_TOP_LAMP_RIGHT_BLUE)) > 0; - pout_staging.SPOTLIGHT2[BI2A_IIDX_SPOTLIGHT_LEFT_RED].l_state = + pout_staging.SPOTLIGHT2[BI2A_IIDX_SPOTLIGHT_LEFT_RED].l_state = (top_lamps & (1 << IIDX_IO_TOP_LAMP_LEFT_RED)) > 0; - pout_staging.SPOTLIGHT2[BI2A_IIDX_SPOTLIGHT_LEFT_YELLOW].l_state = + pout_staging.SPOTLIGHT2[BI2A_IIDX_SPOTLIGHT_LEFT_YELLOW].l_state = (top_lamps & (1 << IIDX_IO_TOP_LAMP_LEFT_YELLOW)) > 0; - pout_staging.SPOTLIGHT2[BI2A_IIDX_SPOTLIGHT_LEFT_GREEN].l_state = + pout_staging.SPOTLIGHT2[BI2A_IIDX_SPOTLIGHT_LEFT_GREEN].l_state = (top_lamps & (1 << IIDX_IO_TOP_LAMP_LEFT_GREEN)) > 0; - pout_staging.SPOTLIGHT2[BI2A_IIDX_SPOTLIGHT_LEFT_BLUE].l_state = + pout_staging.SPOTLIGHT2[BI2A_IIDX_SPOTLIGHT_LEFT_BLUE].l_state = (top_lamps & (1 << IIDX_IO_TOP_LAMP_LEFT_BLUE)) > 0; } diff --git a/src/main/iidxio-ezusb/iidxio.c b/src/main/iidxio-ezusb/iidxio.c index 5017bed..a6a2059 100644 --- a/src/main/iidxio-ezusb/iidxio.c +++ b/src/main/iidxio-ezusb/iidxio.c @@ -78,9 +78,8 @@ bool iidx_io_init( } } - // Random data returned by device, likely not properly initalized on device side - // Triggers random inputs and lights - // Flush that by execute a few polls + // Random data returned by device, likely not properly initalized on device + // side Triggers random inputs and lights Flush that by execute a few polls for (int i = 0; i < 10; i++) { iidx_io_ep2_recv(); } @@ -90,14 +89,15 @@ bool iidx_io_init( void iidx_io_fini(void) { - // Pushing some final state before closing the IO to the actual outputs, e.g. lights on/off - // can be a bit finicky. Do a few polls to "enforce"/flush this final state + // Pushing some final state before closing the IO to the actual outputs, + // e.g. lights on/off can be a bit finicky. Do a few polls to + // "enforce"/flush this final state for (uint8_t i = 0; i < 5; i++) { iidx_io_ep1_send(); iidx_io_ep2_recv(); Sleep(10); - } + } ezusb_close(iidx_io_ezusb_handle); iidx_io_ezusb_handle = INVALID_HANDLE_VALUE; diff --git a/src/main/iidxiotest/main.c b/src/main/iidxiotest/main.c index 275970e..ddd57cf 100644 --- a/src/main/iidxiotest/main.c +++ b/src/main/iidxiotest/main.c @@ -23,7 +23,8 @@ static uint8_t _fix_top_lamps_order(uint8_t top_lamps) out |= ((1 << 4) & top_lamps) > 0 ? (1 << IIDX_IO_TOP_LAMP_RIGHT_BLUE) : 0; out |= ((1 << 5) & top_lamps) > 0 ? (1 << IIDX_IO_TOP_LAMP_RIGHT_GREEN) : 0; - out |= ((1 << 6) & top_lamps) > 0 ? (1 << IIDX_IO_TOP_LAMP_RIGHT_YELLOW) : 0; + out |= + ((1 << 6) & top_lamps) > 0 ? (1 << IIDX_IO_TOP_LAMP_RIGHT_YELLOW) : 0; out |= ((1 << 7) & top_lamps) > 0 ? (1 << IIDX_IO_TOP_LAMP_RIGHT_RED) : 0; return out; @@ -36,11 +37,12 @@ static void _all_lights_off_shutdown() iidx_io_ep1_set_top_lamps(0); iidx_io_ep1_set_top_neons(false); - // Depending on the IO, pushing the state to the actual outputs, e.g. lights on/off - // can be a bit finicky. Do a few times to "enforce" the state + // Depending on the IO, pushing the state to the actual outputs, e.g. lights + // on/off can be a bit finicky. Do a few times to "enforce" the state for (uint8_t i = 0; i < 3; i++) { iidx_io_ep1_send(); - // Required to handle iidxio-ezusb specific quirks with flushing 16seg text + // Required to handle iidxio-ezusb specific quirks with flushing 16seg + // text iidx_io_ep2_recv(); iidx_io_ep3_write_16seg(" "); diff --git a/src/main/inject/debugger.c b/src/main/inject/debugger.c index 536728d..724ed9b 100644 --- a/src/main/inject/debugger.c +++ b/src/main/inject/debugger.c @@ -30,13 +30,11 @@ static HANDLE debugger_ready_event; static PROCESS_INFORMATION pi; -static PVOID load_nt_header_from_process(HANDLE hProcess, - HMODULE hModule, - PIMAGE_NT_HEADERS32 pNtHeader); +static PVOID load_nt_header_from_process( + HANDLE hProcess, HMODULE hModule, PIMAGE_NT_HEADERS32 pNtHeader); -static HMODULE enumerate_modules_in_process(HANDLE hProcess, - HMODULE hModuleLast, - PIMAGE_NT_HEADERS32 pNtHeader); +static HMODULE enumerate_modules_in_process( + HANDLE hProcess, HMODULE hModuleLast, PIMAGE_NT_HEADERS32 pNtHeader); // Source: // https://docs.microsoft.com/en-us/windows/win32/memory/obtaining-a-file-name-from-a-file-handle @@ -233,7 +231,8 @@ static bool debugger_create_process( if (!ok) { log_warning( - "ERROR: Failed to launch hooked EXE: %08x", (unsigned int) GetLastError()); + "ERROR: Failed to launch hooked EXE: %08x", + (unsigned int) GetLastError()); free(cmd_line); @@ -272,7 +271,8 @@ static uint32_t debugger_loop() "EXCEPTION_DEBUG_EVENT(pid %ld, tid %ld): x%s 0x%p", de.dwProcessId, de.dwThreadId, - signal_exception_code_to_str(de.u.Exception.ExceptionRecord.ExceptionCode), + signal_exception_code_to_str( + de.u.Exception.ExceptionRecord.ExceptionCode), de.u.Exception.ExceptionRecord.ExceptionAddress); if (de.u.Exception.ExceptionRecord.ExceptionCode == @@ -518,7 +518,9 @@ bool debugger_inject_dll(const char *path_dll) PAGE_READWRITE); if (!remote_addr) { - log_warning("ERROR: VirtualAllocEx failed: %08x", (unsigned int) GetLastError()); + log_warning( + "ERROR: VirtualAllocEx failed: %08x", + (unsigned int) GetLastError()); goto alloc_fail; } @@ -528,7 +530,8 @@ bool debugger_inject_dll(const char *path_dll) if (!ok) { log_warning( - "ERROR: WriteProcessMemory failed: %08x", (unsigned int) GetLastError()); + "ERROR: WriteProcessMemory failed: %08x", + (unsigned int) GetLastError()); goto write_fail; } @@ -544,7 +547,8 @@ bool debugger_inject_dll(const char *path_dll) if (remote_thread == NULL) { log_warning( - "ERROR: CreateRemoteThread failed: %08x", (unsigned int) GetLastError()); + "ERROR: CreateRemoteThread failed: %08x", + (unsigned int) GetLastError()); goto inject_fail; } @@ -556,7 +560,8 @@ bool debugger_inject_dll(const char *path_dll) remote_addr = NULL; if (!ok) { - log_warning("ERROR: VirtualFreeEx failed: %08x", (unsigned int) GetLastError()); + log_warning( + "ERROR: VirtualFreeEx failed: %08x", (unsigned int) GetLastError()); } return true; @@ -571,7 +576,8 @@ alloc_fail: return false; } -HRESULT debugger_pe_patch_remote(HANDLE hProcess, void *dest, const void *src, size_t nbytes) +HRESULT debugger_pe_patch_remote( + HANDLE hProcess, void *dest, const void *src, size_t nbytes) { DWORD old_protect; BOOL ok; @@ -580,29 +586,19 @@ HRESULT debugger_pe_patch_remote(HANDLE hProcess, void *dest, const void *src, s log_assert(src != NULL); ok = VirtualProtectEx( - hProcess, - dest, - nbytes, - PAGE_EXECUTE_READWRITE, - &old_protect); + hProcess, dest, nbytes, PAGE_EXECUTE_READWRITE, &old_protect); if (!ok) { return HRESULT_FROM_WIN32(GetLastError()); } - ok = WriteProcessMemory( - hProcess, dest, src, nbytes, NULL); + ok = WriteProcessMemory(hProcess, dest, src, nbytes, NULL); if (!ok) { return HRESULT_FROM_WIN32(GetLastError()); } - ok = VirtualProtectEx( - hProcess, - dest, - nbytes, - old_protect, - &old_protect); + ok = VirtualProtectEx(hProcess, dest, nbytes, old_protect, &old_protect); if (!ok) { return HRESULT_FROM_WIN32(GetLastError()); @@ -611,7 +607,8 @@ HRESULT debugger_pe_patch_remote(HANDLE hProcess, void *dest, const void *src, s return S_OK; } -bool debugger_replace_dll_iat(const char *expected_dll, const char *replacement_path_dll) +bool debugger_replace_dll_iat( + const char *expected_dll, const char *replacement_path_dll) { log_assert(expected_dll); log_assert(replacement_path_dll); @@ -625,7 +622,8 @@ bool debugger_replace_dll_iat(const char *expected_dll, const char *replacement_ for (;;) { memset(&inh, 0, sizeof(IMAGE_NT_HEADERS)); - if ((hLast = enumerate_modules_in_process(pi.hProcess, hLast, &inh)) == NULL) { + if ((hLast = enumerate_modules_in_process(pi.hProcess, hLast, &inh)) == + NULL) { break; } @@ -640,18 +638,23 @@ bool debugger_replace_dll_iat(const char *expected_dll, const char *replacement_ goto inject_fail; } - // Search through import table if it exists and replace the target DLL with our DLL filename - PBYTE pbModule = (PBYTE)hModule; - PIMAGE_SECTION_HEADER pRemoteSectionHeaders - = (PIMAGE_SECTION_HEADER)((PBYTE)pbModule - + sizeof(inh.Signature) - + sizeof(inh.FileHeader) - + inh.FileHeader.SizeOfOptionalHeader); + // Search through import table if it exists and replace the target DLL with + // our DLL filename + PBYTE pbModule = (PBYTE) hModule; + PIMAGE_SECTION_HEADER pRemoteSectionHeaders = + (PIMAGE_SECTION_HEADER) ((PBYTE) pbModule + sizeof(inh.Signature) + + sizeof(inh.FileHeader) + + inh.FileHeader.SizeOfOptionalHeader); size_t total_size = inh.OptionalHeader.SizeOfHeaders; IMAGE_SECTION_HEADER header; for (DWORD n = 0; n < inh.FileHeader.NumberOfSections; ++n) { - if (!ReadProcessMemory(pi.hProcess, pRemoteSectionHeaders + n, &header, sizeof(header), NULL)) { + if (!ReadProcessMemory( + pi.hProcess, + pRemoteSectionHeaders + n, + &header, + sizeof(header), + NULL)) { log_warning("Couldn't read section header: %lu", GetLastError()); goto inject_fail; } @@ -671,17 +674,33 @@ bool debugger_replace_dll_iat(const char *expected_dll, const char *replacement_ log_assert(remote_addr != NULL); debugger_pe_patch_remote( - pi.hProcess, remote_addr, replacement_path_dll, strlen(replacement_path_dll)); + pi.hProcess, + remote_addr, + replacement_path_dll, + strlen(replacement_path_dll)); - if (inh.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress != 0) { - PIMAGE_IMPORT_DESCRIPTOR pImageImport = (PIMAGE_IMPORT_DESCRIPTOR)(pbModule - + inh.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress); + if (inh.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] + .VirtualAddress != 0) { + PIMAGE_IMPORT_DESCRIPTOR pImageImport = + (PIMAGE_IMPORT_DESCRIPTOR) (pbModule + + inh.OptionalHeader + .DataDirectory + [IMAGE_DIRECTORY_ENTRY_IMPORT] + .VirtualAddress); DWORD size = 0; - while (inh.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size == 0 - || size < inh.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size) { + while (inh.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] + .Size == 0 || + size < inh.OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] + .Size) { IMAGE_IMPORT_DESCRIPTOR ImageImport; - if (!ReadProcessMemory(pi.hProcess, pImageImport, &ImageImport, sizeof(ImageImport), NULL)) { + if (!ReadProcessMemory( + pi.hProcess, + pImageImport, + &ImageImport, + sizeof(ImageImport), + NULL)) { log_warning("Couldn't read import: %lu", GetLastError()); goto inject_fail; } @@ -691,13 +710,19 @@ bool debugger_replace_dll_iat(const char *expected_dll, const char *replacement_ } char name[MAX_PATH] = {0}; - if (ReadProcessMemory(pi.hProcess, pbModule + ImageImport.Name, name, sizeof(name), NULL)) { + if (ReadProcessMemory( + pi.hProcess, + pbModule + ImageImport.Name, + name, + sizeof(name), + NULL)) { // log_misc("\tImport DLL: %ld %s", ImageImport.Name, name); if (strcmp(name, expected_dll) == 0) { - //log_misc("Replacing %s with %s", name, replacement_path_dll, (void*)pImageImport); + // log_misc("Replacing %s with %s", name, + // replacement_path_dll, (void*)pImageImport); - ImageImport.Name = (DWORD)((PBYTE)remote_addr - pbModule); + ImageImport.Name = (DWORD) ((PBYTE) remote_addr - pbModule); debugger_pe_patch_remote( pi.hProcess, @@ -768,11 +793,10 @@ void debugger_finit(bool failure) } // Helper functions based on Microsoft Detours -static PVOID load_nt_header_from_process(HANDLE hProcess, - HMODULE hModule, - PIMAGE_NT_HEADERS32 pNtHeader) +static PVOID load_nt_header_from_process( + HANDLE hProcess, HMODULE hModule, PIMAGE_NT_HEADERS32 pNtHeader) { - PBYTE pbModule = (PBYTE)hModule; + PBYTE pbModule = (PBYTE) hModule; memset(pNtHeader, 0, sizeof(*pNtHeader)); @@ -795,13 +819,17 @@ static PVOID load_nt_header_from_process(HANDLE hProcess, } if (idh.e_magic != IMAGE_DOS_SIGNATURE || - (DWORD)idh.e_lfanew > mbi.RegionSize || - (DWORD)idh.e_lfanew < sizeof(idh)) { + (DWORD) idh.e_lfanew > mbi.RegionSize || + (DWORD) idh.e_lfanew < sizeof(idh)) { return NULL; } - if (!ReadProcessMemory(hProcess, pbModule + idh.e_lfanew, - pNtHeader, sizeof(*pNtHeader), NULL)) { + if (!ReadProcessMemory( + hProcess, + pbModule + idh.e_lfanew, + pNtHeader, + sizeof(*pNtHeader), + NULL)) { log_warning("Could not read NT header: %lu", GetLastError()); return NULL; } @@ -813,11 +841,10 @@ static PVOID load_nt_header_from_process(HANDLE hProcess, return pbModule + idh.e_lfanew; } -static HMODULE enumerate_modules_in_process(HANDLE hProcess, - HMODULE hModuleLast, - PIMAGE_NT_HEADERS32 pNtHeader) +static HMODULE enumerate_modules_in_process( + HANDLE hProcess, HMODULE hModuleLast, PIMAGE_NT_HEADERS32 pNtHeader) { - PBYTE pbLast = (PBYTE)hModuleLast + MM_ALLOCATION_GRANULARITY; + PBYTE pbLast = (PBYTE) hModuleLast + MM_ALLOCATION_GRANULARITY; memset(pNtHeader, 0, sizeof(*pNtHeader)); @@ -825,17 +852,17 @@ static HMODULE enumerate_modules_in_process(HANDLE hProcess, memset(&mbi, 0, sizeof(mbi)); // Find the next memory region that contains a mapped PE image. - for (;; pbLast = (PBYTE)mbi.BaseAddress + mbi.RegionSize) { - if (VirtualQueryEx(hProcess, (PVOID)pbLast, &mbi, sizeof(mbi)) == 0) { + for (;; pbLast = (PBYTE) mbi.BaseAddress + mbi.RegionSize) { + if (VirtualQueryEx(hProcess, (PVOID) pbLast, &mbi, sizeof(mbi)) == 0) { break; } - // Usermode address space has such an unaligned region size always at the - // end and only at the end. + // Usermode address space has such an unaligned region size always at + // the end and only at the end. if ((mbi.RegionSize & 0xfff) == 0xfff) { break; } - if (((PBYTE)mbi.BaseAddress + mbi.RegionSize) < pbLast) { + if (((PBYTE) mbi.BaseAddress + mbi.RegionSize) < pbLast) { break; } @@ -846,8 +873,9 @@ static HMODULE enumerate_modules_in_process(HANDLE hProcess, continue; } - if (load_nt_header_from_process(hProcess, (HMODULE)pbLast, pNtHeader)) { - return (HMODULE)pbLast; + if (load_nt_header_from_process( + hProcess, (HMODULE) pbLast, pNtHeader)) { + return (HMODULE) pbLast; } } diff --git a/src/main/inject/debugger.h b/src/main/inject/debugger.h index 34e28c3..76075f1 100644 --- a/src/main/inject/debugger.h +++ b/src/main/inject/debugger.h @@ -2,7 +2,6 @@ #include - /** * Initialize inject's logger backend. * @@ -14,7 +13,6 @@ * disable. */ - /** * Initialize the debugger. * @@ -58,7 +56,8 @@ bool debugger_inject_dll(const char *path_dll); * @param replacement_path_dll Name of dll to inject. * @return true if sucessful, false on error. */ -bool debugger_replace_dll_iat(const char *expected_dll, const char *replacement_path_dll); +bool debugger_replace_dll_iat( + const char *expected_dll, const char *replacement_path_dll); /** * Wait/block for a remote debugger to attach to the remote process. diff --git a/src/main/inject/logger.c b/src/main/inject/logger.c index 72fc5dd..8f63aa9 100644 --- a/src/main/inject/logger.c +++ b/src/main/inject/logger.c @@ -15,11 +15,11 @@ static FILE *log_file; static HANDLE log_mutex; -static const char* logger_get_formatted_timestamp(void) +static const char *logger_get_formatted_timestamp(void) { static char buffer[64]; time_t cur = 0; - struct tm* tm = NULL; + struct tm *tm = NULL; cur = time(NULL); tm = localtime(&cur); @@ -94,7 +94,8 @@ static size_t logger_msg_coloring_len(const char *str) return 0; } -static void logger_console(void *ctx, const char *chars, size_t nchars, const char* timestamp_str) +static void logger_console( + void *ctx, const char *chars, size_t nchars, const char *timestamp_str) { char color; size_t color_len; @@ -128,10 +129,11 @@ static void logger_console(void *ctx, const char *chars, size_t nchars, const ch } } -static void logger_file(void *ctx, const char *chars, size_t nchars, const char* timestamp_str) +static void logger_file( + void *ctx, const char *chars, size_t nchars, const char *timestamp_str) { if (ctx) { - fwrite(timestamp_str, 1, strlen(timestamp_str), (FILE*) ctx); + fwrite(timestamp_str, 1, strlen(timestamp_str), (FILE *) ctx); fwrite(chars, 1, nchars, (FILE *) ctx); fflush((FILE *) ctx); } @@ -139,7 +141,7 @@ static void logger_file(void *ctx, const char *chars, size_t nchars, const char* static void logger_writer(void *ctx, const char *chars, size_t nchars) { - const char* timestamp_str; + const char *timestamp_str; // Different threads logging the same destination, e.g. debugger thread, // main thread diff --git a/src/main/inject/logger.h b/src/main/inject/logger.h index 5702881..45a8b77 100644 --- a/src/main/inject/logger.h +++ b/src/main/inject/logger.h @@ -2,11 +2,11 @@ /** * Initialize inject's logger backend. - * + * * This takes care of hooking and merging the different log * streams, e.g. inject's local logging and inject's debugger * receiving remote logging events. - * + * * @param log_file_path Path to the file to log to or NULL to * disable. */ @@ -14,10 +14,10 @@ bool logger_init(const char *log_file_path); /** * Write a message to the logging backend. - * + * * This is used by inject's debugger to redirect log messages * recevied from the remote process. - * + * * @param str String to log */ void logger_log(const char *str); diff --git a/src/main/inject/main.c b/src/main/inject/main.c index 7887da6..bfb6c1b 100644 --- a/src/main/inject/main.c +++ b/src/main/inject/main.c @@ -92,7 +92,8 @@ verify_hook_dlls_exist(int argc, char **argv, uint32_t hook_dll_count) if (dll_path_length == 0) { log_warning( - "ERROR: Hook DLL not found: %08x", (unsigned int) GetLastError()); + "ERROR: Hook DLL not found: %08x", + (unsigned int) GetLastError()); return false; } @@ -114,7 +115,7 @@ static bool inject_iat_hook_dlls(uint32_t hooks, char **argv) continue; *iat_hook = '\0'; - debugger_replace_dll_iat(argv[i + 1], iat_hook+1); + debugger_replace_dll_iat(argv[i + 1], iat_hook + 1); *iat_hook = '='; } diff --git a/src/main/jbhook-util-p3io/gfx.c b/src/main/jbhook-util-p3io/gfx.c index 9e53559..63607fd 100644 --- a/src/main/jbhook-util-p3io/gfx.c +++ b/src/main/jbhook-util-p3io/gfx.c @@ -2,12 +2,12 @@ #include +#include +#include #include #include #include #include -#include -#include #include "hook/com-proxy.h" #include "hook/table.h" @@ -22,17 +22,15 @@ #include "util/time.h" static void __stdcall hook_glFlush(void); -static void (__stdcall *real_glFlush)(void); +static void(__stdcall *real_glFlush)(void); static void hook_glBindFramebufferEXT(GLenum target, GLuint framebuffer); static void (*real_glBindFramebufferEXT)(GLenum target, GLuint framebuffer); -static void hook_infodispcore_set_angle(void* this, int angle); +static void hook_infodispcore_set_angle(void *this, int angle); static const struct hook_symbol jbhook1_opengl_hook_syms[] = { - {.name = "glFlush", - .patch = hook_glFlush, - .link = (void **) &real_glFlush}, + {.name = "glFlush", .patch = hook_glFlush, .link = (void **) &real_glFlush}, }; static const struct hook_symbol jbhook1_glhelper_hook_syms[] = { @@ -47,7 +45,8 @@ static const struct hook_symbol jbhook_infodisp_hook_syms[] = { .patch = hook_infodispcore_set_angle}, }; -void jbhook_util_gfx_install_vertical_hooks(void) { +void jbhook_util_gfx_install_vertical_hooks(void) +{ hook_table_apply( NULL, "opengl32.dll", @@ -69,7 +68,8 @@ void jbhook_util_gfx_install_vertical_hooks(void) { log_info("Inserted vertical display hooks"); } -static void hook_infodispcore_set_angle(void* this, int angle) { +static void hook_infodispcore_set_angle(void *this, int angle) +{ // ignore } @@ -84,10 +84,11 @@ static void hook_infodispcore_set_angle(void* this, int angle) { static GLuint fb; static GLuint color; -static void fb_init(void) { +static void fb_init(void) +{ static bool init_done = false; - if(init_done) { + if (init_done) { return; } @@ -97,20 +98,24 @@ static void fb_init(void) { glGenTextures(1, &color); } -static void __stdcall hook_glFlush(void) { +static void __stdcall hook_glFlush(void) +{ // 3 bytes per RGB pixel // these could really be stack variables but they are too big for gcc's // default stack size, and it's no problem for 6MiB of data to hang around - static uint8_t pixels_raw[W*H*3]; - static uint8_t pixels_rot[W*H*3]; + static uint8_t pixels_raw[W * H * 3]; + static uint8_t pixels_rot[W * H * 3]; glReadPixels(0, 0, H, W, GL_RGB, GL_UNSIGNED_BYTE, pixels_raw); // CPU copies may seem slow here, but this runs fine on my jubeat cab, so // speed is not a huge concern. - for(size_t x = 0; x < W; x++) { - for(size_t y = 0; y < H; y++) { - memcpy(&pixels_rot[3*(y*W + x)], &pixels_raw[3*((W-x)*H + y)], 3); + for (size_t x = 0; x < W; x++) { + for (size_t y = 0; y < H; y++) { + memcpy( + &pixels_rot[3 * (y * W + x)], + &pixels_raw[3 * ((W - x) * H + y)], + 3); } } @@ -129,11 +134,13 @@ static void __stdcall hook_glFlush(void) { fb_init(); real_glBindFramebufferEXT(GL_FRAMEBUFFER, fb); glBindTexture(GL_TEXTURE_2D, color); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, H, W, 0, GL_RGBA,GL_UNSIGNED_BYTE, NULL); + glTexImage2D( + GL_TEXTURE_2D, 0, GL_RGBA, H, W, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0); + glFramebufferTexture2DEXT( + GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0); } // hooking something in glhelper.dll (a jubeat supplied DLL) might seem @@ -141,12 +148,13 @@ static void __stdcall hook_glFlush(void) { // loop of the game makes it very difficult to "catch" the rendering at the // right place otherwise. This works with all horizontal jubeats, and they // stopped needing rotation fixes starting with saucer. -static void hook_glBindFramebufferEXT(GLenum target, GLuint framebuffer) { +static void hook_glBindFramebufferEXT(GLenum target, GLuint framebuffer) +{ fb_init(); // check this is actually the screen - the game also uses internal // framebuffers for some parts of the display - if(target == GL_FRAMEBUFFER && framebuffer == 0) { + if (target == GL_FRAMEBUFFER && framebuffer == 0) { framebuffer = fb; } diff --git a/src/main/jbhook-util-p3io/mixer.c b/src/main/jbhook-util-p3io/mixer.c index eacd5c3..30dcace 100644 --- a/src/main/jbhook-util-p3io/mixer.c +++ b/src/main/jbhook-util-p3io/mixer.c @@ -11,29 +11,32 @@ #include "util/defs.h" #include "util/log.h" -MMRESULT STDCALL hook_mixerGetLineControlsA(HMIXEROBJ hmxobj, LPMIXERLINECONTROLSA pmxlc, DWORD fdwControls); -MMRESULT STDCALL hook_mixerGetDevCapsA(UINT_PTR uMxId, LPMIXERCAPSA pmxcaps, UINT cbmxcaps); -MMRESULT STDCALL hook_mixerOpen(LPHMIXER phmx, UINT uMxId, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen); -MMRESULT STDCALL hook_mixerSetControlDetails(HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails); -MMRESULT STDCALL hook_mixerGetControlDetailsA(HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails); +MMRESULT STDCALL hook_mixerGetLineControlsA( + HMIXEROBJ hmxobj, LPMIXERLINECONTROLSA pmxlc, DWORD fdwControls); +MMRESULT STDCALL +hook_mixerGetDevCapsA(UINT_PTR uMxId, LPMIXERCAPSA pmxcaps, UINT cbmxcaps); +MMRESULT STDCALL hook_mixerOpen( + LPHMIXER phmx, + UINT uMxId, + DWORD_PTR dwCallback, + DWORD_PTR dwInstance, + DWORD fdwOpen); +MMRESULT STDCALL hook_mixerSetControlDetails( + HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails); +MMRESULT STDCALL hook_mixerGetControlDetailsA( + HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails); MMRESULT STDCALL hook_mixerClose(HMIXER hmx); -MMRESULT STDCALL hook_mixerGetLineInfoA(HMIXEROBJ hmxobj, LPMIXERLINEA pmxl, DWORD fdwInfo); +MMRESULT STDCALL +hook_mixerGetLineInfoA(HMIXEROBJ hmxobj, LPMIXERLINEA pmxl, DWORD fdwInfo); static const struct hook_symbol mixer_hook_syms[] = { - {.name = "mixerGetLineControlsA", - .patch = hook_mixerGetLineControlsA}, - {.name = "mixerGetDevCapsA", - .patch = hook_mixerGetDevCapsA}, - {.name = "mixerOpen", - .patch = hook_mixerOpen}, - {.name = "mixerSetControlDetails", - .patch = hook_mixerSetControlDetails}, - {.name = "mixerGetControlDetailsA", - .patch = hook_mixerGetControlDetailsA}, - {.name = "mixerClose", - .patch = hook_mixerClose}, - {.name = "mixerGetLineInfoA", - .patch = hook_mixerGetLineInfoA}, + {.name = "mixerGetLineControlsA", .patch = hook_mixerGetLineControlsA}, + {.name = "mixerGetDevCapsA", .patch = hook_mixerGetDevCapsA}, + {.name = "mixerOpen", .patch = hook_mixerOpen}, + {.name = "mixerSetControlDetails", .patch = hook_mixerSetControlDetails}, + {.name = "mixerGetControlDetailsA", .patch = hook_mixerGetControlDetailsA}, + {.name = "mixerClose", .patch = hook_mixerClose}, + {.name = "mixerGetLineInfoA", .patch = hook_mixerGetLineInfoA}, }; /* @@ -43,40 +46,57 @@ static const struct hook_symbol mixer_hook_syms[] = { to not set any of the returning data. */ -MMRESULT STDCALL hook_mixerOpen(LPHMIXER phmx, UINT uMxId, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen) { - *(DWORD*)phmx = 1234; // any non-zero value is fine +MMRESULT STDCALL hook_mixerOpen( + LPHMIXER phmx, + UINT uMxId, + DWORD_PTR dwCallback, + DWORD_PTR dwInstance, + DWORD fdwOpen) +{ + *(DWORD *) phmx = 1234; // any non-zero value is fine return MMSYSERR_NOERROR; } -MMRESULT STDCALL hook_mixerClose(HMIXER hmx) { +MMRESULT STDCALL hook_mixerClose(HMIXER hmx) +{ return MMSYSERR_NOERROR; } -MMRESULT STDCALL hook_mixerGetLineControlsA(HMIXEROBJ hmxobj, LPMIXERLINECONTROLSA pmxlc, DWORD fdwControls) { +MMRESULT STDCALL hook_mixerGetLineControlsA( + HMIXEROBJ hmxobj, LPMIXERLINECONTROLSA pmxlc, DWORD fdwControls) +{ return MMSYSERR_NOERROR; } -MMRESULT STDCALL hook_mixerGetDevCapsA(UINT_PTR uMxId, LPMIXERCAPSA pmxcaps, UINT cbmxcaps) { +MMRESULT STDCALL +hook_mixerGetDevCapsA(UINT_PTR uMxId, LPMIXERCAPSA pmxcaps, UINT cbmxcaps) +{ return MMSYSERR_NOERROR; } -MMRESULT STDCALL hook_mixerGetControlDetailsA(HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails) { +MMRESULT STDCALL hook_mixerGetControlDetailsA( + HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails) +{ return MMSYSERR_NOERROR; } -MMRESULT STDCALL hook_mixerGetLineInfoA(HMIXEROBJ hmxobj, LPMIXERLINEA pmxl, DWORD fdwInfo) { +MMRESULT STDCALL +hook_mixerGetLineInfoA(HMIXEROBJ hmxobj, LPMIXERLINEA pmxl, DWORD fdwInfo) +{ return MMSYSERR_NOERROR; } -MMRESULT STDCALL hook_mixerSetControlDetails(HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails) { +MMRESULT STDCALL hook_mixerSetControlDetails( + HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails) +{ return MMSYSERR_NOERROR; } - void jbhook_util_mixer_hook_init(void) { - hook_table_apply(NULL, "winmm.dll", mixer_hook_syms, lengthof(mixer_hook_syms)); + hook_table_apply( + NULL, "winmm.dll", mixer_hook_syms, lengthof(mixer_hook_syms)); log_info("Inserted mixer hooks"); } diff --git a/src/main/jbhook-util-p3io/p3io.c b/src/main/jbhook-util-p3io/p3io.c index 2317742..245fe2e 100644 --- a/src/main/jbhook-util-p3io/p3io.c +++ b/src/main/jbhook-util-p3io/p3io.c @@ -173,13 +173,14 @@ static HRESULT jbhook_p3io_get_roundplug( return S_OK; } -static HRESULT jbhook_p3io_set_outputs(void *ctx, uint32_t state) { - uint8_t p3io_panel = (state & 0x00FF00) >> 8; +static HRESULT jbhook_p3io_set_outputs(void *ctx, uint32_t state) +{ + uint8_t p3io_panel = (state & 0x00FF00) >> 8; uint8_t p3io_coinblocker = (state & 0xFF0000) >> 16; enum jb_io_panel_mode panel_mode; - switch(p3io_panel) { + switch (p3io_panel) { case 5: panel_mode = JB_IO_PANEL_MODE_TOP_LEFT; break; diff --git a/src/main/jbhook-util/acio.c b/src/main/jbhook-util/acio.c index c5f0e3d..a1f5492 100644 --- a/src/main/jbhook-util/acio.c +++ b/src/main/jbhook-util/acio.c @@ -44,7 +44,8 @@ void jbhook_util_ac_io_port_fini(void) ac_io_emu_fini(&ac_io_emu); } -void jbhook_util_ac_io_set_iccb(void) { +void jbhook_util_ac_io_set_iccb(void) +{ ac_io_emu_icca_set_version(&ac_io_emu_icca, v150); ac_io_emu_icca_set_product_code(&ac_io_emu_icca, AC_IO_EMU_PROD_CODE_ICCB); } diff --git a/src/main/jbhook-util/eamuse.c b/src/main/jbhook-util/eamuse.c index 87ece98..0a79625 100644 --- a/src/main/jbhook-util/eamuse.c +++ b/src/main/jbhook-util/eamuse.c @@ -1,9 +1,9 @@ #define LOG_MODULE "eamuse-hook" +#include #include #include #include -#include #include #include @@ -30,11 +30,8 @@ static int STDCALL my_getaddrinfo( const ADDRINFOA *pHints, PADDRINFOA *ppResult); -static DWORD WINAPI my_GetIpAddrTable( - PMIB_IPADDRTABLE pIpAddrTable, - PULONG pdwSize, - BOOL bOrder -); +static DWORD WINAPI +my_GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder); static const struct hook_symbol eamuse_hook_syms[] = { { @@ -73,7 +70,8 @@ static int STDCALL my_getaddrinfo( return real_getaddrinfo(pNodeName, pServiceName, pHints, ppResult); } -static DWORD get_best_ip(void) { +static DWORD get_best_ip(void) +{ PIP_ADAPTER_INFO info = NULL; struct net_addr addr; // fallback to a very obviously wrong value @@ -86,11 +84,11 @@ static DWORD get_best_ip(void) { info = malloc(sz); - if(GetAdaptersInfo(info, &sz) != NO_ERROR) { + if (GetAdaptersInfo(info, &sz) != NO_ERROR) { goto CLEANUP; } - if(!net_str_parse(info->IpAddressList.IpAddress.String, &addr)) { + if (!net_str_parse(info->IpAddressList.IpAddress.String, &addr)) { goto CLEANUP; } @@ -114,16 +112,14 @@ CLEANUP: * check. By also hooking this function, the IP addresses of the two calls will * agree. */ -static DWORD WINAPI my_GetIpAddrTable( - PMIB_IPADDRTABLE pIpAddrTable, - PULONG pdwSize, - BOOL bOrder -) { +static DWORD WINAPI +my_GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder) +{ ULONG in = *pdwSize; // 1 element return table *pdwSize = sizeof(MIB_IPADDRTABLE) + sizeof(MIB_IPADDRROW); - if(in < *pdwSize) { + if (in < *pdwSize) { return ERROR_INSUFFICIENT_BUFFER; } diff --git a/src/main/jbhook-util/locale.c b/src/main/jbhook-util/locale.c index c1fa13d..272bbc6 100644 --- a/src/main/jbhook-util/locale.c +++ b/src/main/jbhook-util/locale.c @@ -14,24 +14,24 @@ static UINT WINAPI hook_GetACP(); static UINT WINAPI hook_GetOEMCP(); static const struct hook_symbol locale_hook_syms[] = { - {.name = "GetOEMCP", - .patch = hook_GetACP}, - {.name = "GetOEMCP", - .patch = hook_GetOEMCP}, + {.name = "GetOEMCP", .patch = hook_GetACP}, + {.name = "GetOEMCP", .patch = hook_GetOEMCP}, }; -static UINT WINAPI hook_GetACP() { +static UINT WINAPI hook_GetACP() +{ return CODEPAGE_SHIFT_JIS; } -static UINT WINAPI hook_GetOEMCP() { +static UINT WINAPI hook_GetOEMCP() +{ return CODEPAGE_SHIFT_JIS; } - void jbhook_util_locale_hook_init(void) { - hook_table_apply(NULL, "kernel32.dll", locale_hook_syms, lengthof(locale_hook_syms)); + hook_table_apply( + NULL, "kernel32.dll", locale_hook_syms, lengthof(locale_hook_syms)); log_info("Inserted locale hooks"); } diff --git a/src/main/jbhook-util/p4io.c b/src/main/jbhook-util/p4io.c index ee0d950..433e7e3 100644 --- a/src/main/jbhook-util/p4io.c +++ b/src/main/jbhook-util/p4io.c @@ -130,7 +130,7 @@ static uint32_t jbhook_command_handle( // on is 0x00, off is either 0x10 or 0x20 depending on whether it's // during gameplay (0x10) or test menu (0x20). Both seem to have the // same effect - jb_io_set_coin_blocker(*(uint8_t*)payload == 0x00); + jb_io_set_coin_blocker(*(uint8_t *) payload == 0x00); // this actually returns the coinstock, don't care for it memset(resp, 0, 4); @@ -145,8 +145,8 @@ static uint32_t jbhook_command_handle( // always fallback to ALL if input is unknown enum jb_io_panel_mode mode = JB_IO_PANEL_MODE_ALL; - if(req->is_single) { - switch(req->mode) { + if (req->is_single) { + switch (req->mode) { case 0x0001: mode = JB_IO_PANEL_MODE_TOP_LEFT; break; diff --git a/src/main/jbhook1/config-security.c b/src/main/jbhook1/config-security.c index f7069a5..565081e 100644 --- a/src/main/jbhook1/config-security.c +++ b/src/main/jbhook1/config-security.c @@ -41,8 +41,7 @@ void jbhook1_config_security_get( char *tmp_default; char mcode[9]; - tmp_default = - security_mcode_to_str(&security_mcode_h44); + tmp_default = security_mcode_to_str(&security_mcode_h44); if (!cconfig_util_get_str( config, diff --git a/src/main/jbhook1/dllmain.c b/src/main/jbhook1/dllmain.c index 69efeba..57d62f7 100644 --- a/src/main/jbhook1/dllmain.c +++ b/src/main/jbhook1/dllmain.c @@ -108,7 +108,7 @@ static HWND CDECL my_mwindow_create( fullscreen = !config_gfx.windowed; - if(config_gfx.vertical) { + if (config_gfx.vertical) { DWORD tmp = window_width; window_width = window_height; window_height = tmp; diff --git a/src/main/jbhook2/dllmain.c b/src/main/jbhook2/dllmain.c index 898d2ce..a8523ad 100644 --- a/src/main/jbhook2/dllmain.c +++ b/src/main/jbhook2/dllmain.c @@ -53,7 +53,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) log_assert(sidcode != NULL); - if(options.vertical) { + if (options.vertical) { jbhook_util_gfx_install_vertical_hooks(); } @@ -76,8 +76,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) }; jbhook_util_p3io_init( - &security_mcode_j44, - &security_id_default, &security_id_default); + &security_mcode_j44, &security_id_default, &security_id_default); log_info("Starting up jubeat IO backend"); @@ -119,9 +118,14 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) // If the game is append, the mcode `cabinet` is forced to C. This is bad if // p3io was configured to respond as A! Help the user help themsevles... - if(strcmp(sidcode_in_ea3_config, sidcode) != 0) { - log_warning("sidcode changed after running game DLL init (%s -> %s)", sidcode_in_ea3_config, sidcode); - log_warning("This will trigger a security error. Modify ea3-config.xml section to match the second value!"); + if (strcmp(sidcode_in_ea3_config, sidcode) != 0) { + log_warning( + "sidcode changed after running game DLL init (%s -> %s)", + sidcode_in_ea3_config, + sidcode); + log_warning( + "This will trigger a security error. Modify ea3-config.xml " + "section to match the second value!"); // abort the boot return false; @@ -193,16 +197,16 @@ static HWND CDECL my_mwindow_create( log_info("---------------- Begin jbhook mwindow_create ----------------"); log_info("-------------------------------------------------------------"); - if(options.vertical) { + if (options.vertical) { DWORD tmp = window_width; window_width = window_height; window_height = tmp; } - if(options.show_cursor) { + if (options.show_cursor) { ShowCursor(TRUE); } - + fullscreen = !options.windowed; return real_mwindow_create( diff --git a/src/main/jbhook3/dllmain.c b/src/main/jbhook3/dllmain.c index 9666412..b4eada8 100644 --- a/src/main/jbhook3/dllmain.c +++ b/src/main/jbhook3/dllmain.c @@ -51,11 +51,11 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) jbhook3_gfx_init(); - if(options.windowed) { + if (options.windowed) { jbhook3_gfx_set_windowed(); } - if(options.show_cursor) { + if (options.show_cursor) { jbhook3_gfx_set_show_cursor(); } @@ -131,7 +131,7 @@ static bool my_dll_entry_main(void) if (!options.disable_p4ioemu) { p4ioemu_fini(); } - + options_fini(&options); return result; @@ -153,7 +153,7 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx) if (!options.disable_adapteremu) { adapter_hook_init(); } - + jbhook_util_eamuse_hook_init(); return TRUE; diff --git a/src/main/jbhook3/gfx.c b/src/main/jbhook3/gfx.c index d0850ab..ee3b5ff 100644 --- a/src/main/jbhook3/gfx.c +++ b/src/main/jbhook3/gfx.c @@ -24,40 +24,33 @@ void jbhook3_gfx_set_show_cursor(void) jbhook3_gfx_show_cursor = true; } -static HWND CDECL my_GFWin32MainWindowRun( - HINSTANCE, - const char *, - long, - long, - DWORD); +static HWND CDECL +my_GFWin32MainWindowRun(HINSTANCE, const char *, long, long, DWORD); static HWND(CDECL *real_GFWin32MainWindowRun)( - HINSTANCE, - const char *, - long, - long, - DWORD); + HINSTANCE, const char *, long, long, DWORD); static const struct hook_symbol init_hook_syms[] = { - {.name = "GFWin32MainWindowRun", - .patch = my_GFWin32MainWindowRun, - .link = (void **) &real_GFWin32MainWindowRun,}, + { + .name = "GFWin32MainWindowRun", + .patch = my_GFWin32MainWindowRun, + .link = (void **) &real_GFWin32MainWindowRun, + }, }; static HWND CDECL my_GFWin32MainWindowRun( - HINSTANCE hInstance, - const char *lpWindowName, - long X, - long Y, - DWORD dwStyle - ) -{ - if(jbhook3_gfx_windowed) { + HINSTANCE hInstance, + const char *lpWindowName, + long X, + long Y, + DWORD dwStyle) +{ + if (jbhook3_gfx_windowed) { log_info("--- Begin jbhook GFWin32MainWindowRun ---"); dwStyle |= WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE; } - if(jbhook3_gfx_show_cursor) { + if (jbhook3_gfx_show_cursor) { ShowCursor(TRUE); } @@ -68,6 +61,6 @@ void jbhook3_gfx_init(void) { hook_table_apply( NULL, "gftools.dll", init_hook_syms, lengthof(init_hook_syms)); - + log_info("Inserted gfx hooks"); } \ No newline at end of file diff --git a/src/main/jbhook3/options.c b/src/main/jbhook3/options.c index 8204328..59ffc1e 100644 --- a/src/main/jbhook3/options.c +++ b/src/main/jbhook3/options.c @@ -74,7 +74,7 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) options->disable_p4ioemu = true; break; } - + case 's': { options->show_cursor = true; break; diff --git a/src/main/jbio-p4io/h44b.c b/src/main/jbio-p4io/h44b.c index eac3a8a..1d9b77a 100644 --- a/src/main/jbio-p4io/h44b.c +++ b/src/main/jbio-p4io/h44b.c @@ -1,9 +1,9 @@ #define LOG_MODULE "jbio-h44b" #include -#include #include #include +#include #include #include "aciodrv/h44b.h" @@ -18,7 +18,8 @@ static atomic_bool running; static struct aciomgr_port_dispatcher *acio_manager_ctx; -bool jb_io_h44b_init(const char *port, int32_t baud) { +bool jb_io_h44b_init(const char *port, int32_t baud) +{ acio_manager_ctx = aciomgr_port_init(port, baud); if (acio_manager_ctx == NULL) { @@ -56,8 +57,7 @@ bool jb_io_h44b_init(const char *port, int32_t baud) { log_warning("Using H44B on node: %d", h44b_node_id); bool init_result = aciodrv_h44b_init( - aciomgr_port_checkout(acio_manager_ctx), - h44b_node_id); + aciomgr_port_checkout(acio_manager_ctx), h44b_node_id); aciomgr_port_checkin(acio_manager_ctx); if (!init_result) { @@ -72,24 +72,23 @@ bool jb_io_h44b_init(const char *port, int32_t baud) { } return running; - } -bool jb_io_h44b_fini(void) { +bool jb_io_h44b_fini(void) +{ aciomgr_port_fini(acio_manager_ctx); return true; } -bool jb_io_h44b_write_lights(struct ac_io_h44b_output *lights) { +bool jb_io_h44b_write_lights(struct ac_io_h44b_output *lights) +{ if (!running) { return false; } bool amp_result = aciodrv_h44b_lights( - aciomgr_port_checkout(acio_manager_ctx), - h44b_node_id, - lights); + aciomgr_port_checkout(acio_manager_ctx), h44b_node_id, lights); aciomgr_port_checkin(acio_manager_ctx); if (!amp_result) { @@ -98,4 +97,3 @@ bool jb_io_h44b_write_lights(struct ac_io_h44b_output *lights) { return true; } - diff --git a/src/main/jbio-p4io/jbio.c b/src/main/jbio-p4io/jbio.c index 576da8b..202187f 100644 --- a/src/main/jbio-p4io/jbio.c +++ b/src/main/jbio-p4io/jbio.c @@ -68,14 +68,14 @@ bool jb_io_init( cconfig_finit(config); p4io_ctx = p4iodrv_open(); - if(!p4io_ctx) { + if (!p4io_ctx) { return false; } // some people use p4io just for inputs and have no lights. Soft fail when // h44b is not able to be connected instead of returning false lights_present = jb_io_h44b_init(config_h44b.port, config_h44b.baud); - if(!lights_present) { + if (!lights_present) { log_warning("Could not connect to H44B, lights disabled"); } @@ -114,7 +114,7 @@ static const uint32_t jb_io_sys_button_mappings[] = { bool jb_io_read_inputs(void) { uint32_t jamma[4]; - if(!p4iodrv_read_jamma(p4io_ctx, jamma)) { + if (!p4iodrv_read_jamma(p4io_ctx, jamma)) { return false; } @@ -142,7 +142,8 @@ bool jb_io_read_inputs(void) bool jb_io_write_lights(void) { - if(lights_present && memcmp(&jb_io_lights, &jb_io_new_lights, sizeof(jb_io_lights))) { + if (lights_present && + memcmp(&jb_io_lights, &jb_io_new_lights, sizeof(jb_io_lights))) { memcpy(&jb_io_lights, &jb_io_new_lights, sizeof(jb_io_lights)); return jb_io_h44b_write_lights(&jb_io_lights); } @@ -166,7 +167,7 @@ bool jb_io_set_panel_mode(enum jb_io_panel_mode mode) panel_mode.is_single = 1; - switch(mode) { + switch (mode) { case JB_IO_PANEL_MODE_ALL: panel_mode.is_single = 0; panel_mode.mode = 0; @@ -185,14 +186,14 @@ bool jb_io_set_panel_mode(enum jb_io_panel_mode mode) break; } - return p4iodrv_cmd_portout(p4io_ctx, (uint8_t*)&panel_mode); + return p4iodrv_cmd_portout(p4io_ctx, (uint8_t *) &panel_mode); } void jb_io_set_rgb_led(enum jb_io_rgb_led unit, uint8_t r, uint8_t g, uint8_t b) { uint8_t *light; - switch(unit) { + switch (unit) { case JB_IO_RGB_LED_FRONT: light = jb_io_new_lights.front_rgb; break; @@ -220,7 +221,8 @@ void jb_io_set_rgb_led(enum jb_io_rgb_led unit, uint8_t r, uint8_t g, uint8_t b) light[2] = b; } -bool jb_io_set_coin_blocker(bool blocked) { +bool jb_io_set_coin_blocker(bool blocked) +{ coin_blocked = blocked; uint8_t coin[4] = {0}; diff --git a/src/main/jbio/jbio.c b/src/main/jbio/jbio.c index 26cb4bd..96a9049 100644 --- a/src/main/jbio/jbio.c +++ b/src/main/jbio/jbio.c @@ -14,8 +14,8 @@ #include // clang-format on -#include "bemanitools/input.h" #include "bemanitools/jbio.h" +#include "bemanitools/input.h" static uint16_t jb_io_panels; static uint8_t jb_io_sys_buttons; diff --git a/src/main/jbiotest/main.c b/src/main/jbiotest/main.c index 0a24151..416b325 100644 --- a/src/main/jbiotest/main.c +++ b/src/main/jbiotest/main.c @@ -14,11 +14,7 @@ typedef struct { uint8_t r, g, b; } rgb_t; -enum jbio_light_mode { - LIGHTS_OFF, - LIGHTS_ON, - LIGHTS_INPUT -}; +enum jbio_light_mode { LIGHTS_OFF, LIGHTS_ON, LIGHTS_INPUT }; #define IS_BIT_SET(var, bit) ((((var) >> (bit)) & 1) > 0) @@ -65,12 +61,12 @@ int main(int argc, char **argv) return -2; } - if(panel_corners_animate && (cnt % 50) == 0) { + if (panel_corners_animate && (cnt % 50) == 0) { panel_mode++; panel_mode %= 5; // skip the all state - if(panel_mode == JB_IO_PANEL_MODE_ALL) { + if (panel_mode == JB_IO_PANEL_MODE_ALL) { panel_mode++; } @@ -79,7 +75,7 @@ int main(int argc, char **argv) all_text = " "; top_left = top_right = bottom_left = bottom_right = ' '; - switch(panel_mode) { + switch (panel_mode) { case JB_IO_PANEL_MODE_ALL: all_text = "ALL"; top_left = top_right = bottom_left = bottom_right = '*'; @@ -269,7 +265,7 @@ int main(int argc, char **argv) case '5': { panel_corners_animate = !panel_corners_animate; - if(!panel_corners_animate) { + if (!panel_corners_animate) { panel_mode = JB_IO_PANEL_MODE_ALL; jb_io_set_panel_mode(panel_mode); } diff --git a/src/main/launcher/main.c b/src/main/launcher/main.c index 8055713..4d935d7 100644 --- a/src/main/launcher/main.c +++ b/src/main/launcher/main.c @@ -215,7 +215,8 @@ int main(int argc, const char **argv) /* Load game DLL */ if (options.iat_hook_dlls.nitems > 0) { - module_context_init_with_iat_hooks(&module, options.module, &options.iat_hook_dlls); + module_context_init_with_iat_hooks( + &module, options.module, &options.iat_hook_dlls); } else { module_context_init(&module, options.module); } @@ -302,9 +303,7 @@ int main(int argc, const char **argv) log_info("Overriding service url to: %s", options.override_service); ea3_ident_replace_property_str( - ea3_config_root, - "/network/services", - options.override_service); + ea3_config_root, "/network/services", options.override_service); } /* Start up e-Amusement client */ diff --git a/src/main/launcher/module.c b/src/main/launcher/module.c index 8098edc..b3beff2 100644 --- a/src/main/launcher/module.c +++ b/src/main/launcher/module.c @@ -12,7 +12,6 @@ #define MM_ALLOCATION_GRANULARITY 0x10000 - static bool module_replace_dll_iat(HMODULE hModule, struct array *iat_hook_dlls) { log_assert(hModule); @@ -21,23 +20,25 @@ static bool module_replace_dll_iat(HMODULE hModule, struct array *iat_hook_dlls) if (iat_hook_dlls->nitems == 0) return true; - PBYTE pbModule = (PBYTE)hModule; + PBYTE pbModule = (PBYTE) hModule; // Find EXE base in process memory IMAGE_DOS_HEADER *idh = (IMAGE_DOS_HEADER *) pbModule; IMAGE_NT_HEADERS *inh = (IMAGE_NT_HEADERS *) (pbModule + idh->e_lfanew); - // Search through import table if it exists and replace the target DLL with our DLL filename - PIMAGE_SECTION_HEADER pRemoteSectionHeaders - = (PIMAGE_SECTION_HEADER)((PBYTE)pbModule - + sizeof(inh->Signature) - + sizeof(inh->FileHeader) - + inh->FileHeader.SizeOfOptionalHeader); + // Search through import table if it exists and replace the target DLL with + // our DLL filename + PIMAGE_SECTION_HEADER pRemoteSectionHeaders = + (PIMAGE_SECTION_HEADER) ((PBYTE) pbModule + sizeof(inh->Signature) + + sizeof(inh->FileHeader) + + inh->FileHeader.SizeOfOptionalHeader); size_t total_size = inh->OptionalHeader.SizeOfHeaders; for (DWORD n = 0; n < inh->FileHeader.NumberOfSections; ++n) { - IMAGE_SECTION_HEADER *header = (IMAGE_SECTION_HEADER *)(pRemoteSectionHeaders + n); - size_t new_total_size = header->VirtualAddress + header->Misc.VirtualSize; + IMAGE_SECTION_HEADER *header = + (IMAGE_SECTION_HEADER *) (pRemoteSectionHeaders + n); + size_t new_total_size = + header->VirtualAddress + header->Misc.VirtualSize; if (new_total_size > total_size) total_size = new_total_size; } @@ -55,20 +56,29 @@ static bool module_replace_dll_iat(HMODULE hModule, struct array *iat_hook_dlls) log_assert(remote_addr != NULL); - if (inh->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress != 0) { - PIMAGE_IMPORT_DESCRIPTOR pImageImport = (PIMAGE_IMPORT_DESCRIPTOR)(pbModule - + inh->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress); + if (inh->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] + .VirtualAddress != 0) { + PIMAGE_IMPORT_DESCRIPTOR pImageImport = + (PIMAGE_IMPORT_DESCRIPTOR) (pbModule + + inh->OptionalHeader + .DataDirectory + [IMAGE_DIRECTORY_ENTRY_IMPORT] + .VirtualAddress); DWORD size = 0; - while (inh->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size == 0 - || size < inh->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size) { - IMAGE_IMPORT_DESCRIPTOR *ImageImport = (IMAGE_IMPORT_DESCRIPTOR *)pImageImport; + while (inh->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] + .Size == 0 || + size < inh->OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] + .Size) { + IMAGE_IMPORT_DESCRIPTOR *ImageImport = + (IMAGE_IMPORT_DESCRIPTOR *) pImageImport; if (ImageImport->Name == 0) { break; } - const char *name = (const char *)(pbModule + ImageImport->Name); + const char *name = (const char *) (pbModule + ImageImport->Name); for (size_t i = 0; i < iat_hook_dlls->nitems; i++) { const char *iat_hook_dll = @@ -85,11 +95,15 @@ static bool module_replace_dll_iat(HMODULE hModule, struct array *iat_hook_dlls) const char *replacement_path_dll = iat_hook_replacement + 1; if (strcmp(name, expected_dll) == 0) { - pe_patch((PBYTE)remote_addr + remote_addr_ptr, replacement_path_dll, strlen(replacement_path_dll)); + pe_patch( + (PBYTE) remote_addr + remote_addr_ptr, + replacement_path_dll, + strlen(replacement_path_dll)); - log_misc("Replacing %s with %s", name, replacement_path_dll); + log_misc( + "Replacing %s with %s", name, replacement_path_dll); - DWORD val = (DWORD)((PBYTE)remote_addr - pbModule); + DWORD val = (DWORD) ((PBYTE) remote_addr - pbModule); pe_patch(&ImageImport->Name, &val, sizeof(DWORD)); pe_patch(pImageImport, &ImageImport, sizeof(ImageImport)); @@ -147,8 +161,10 @@ void module_context_init(struct module_context *module, const char *path) module->path = str_dup(path); } - -void module_context_init_with_iat_hooks(struct module_context *module, const char *path, struct array *iat_hook_dlls) +void module_context_init_with_iat_hooks( + struct module_context *module, + const char *path, + struct array *iat_hook_dlls) { log_assert(module != NULL); log_assert(path != NULL); diff --git a/src/main/launcher/module.h b/src/main/launcher/module.h index 8588534..f2a851e 100644 --- a/src/main/launcher/module.h +++ b/src/main/launcher/module.h @@ -13,7 +13,10 @@ struct module_context { }; void module_context_init(struct module_context *module, const char *path); -void module_context_init_with_iat_hooks(struct module_context *module, const char *path, struct array *iat_hook_dlls); +void module_context_init_with_iat_hooks( + struct module_context *module, + const char *path, + struct array *iat_hook_dlls); bool module_context_invoke_init( const struct module_context *module, char *sidcode, diff --git a/src/main/launcher/options.c b/src/main/launcher/options.c index 70d171d..757555e 100644 --- a/src/main/launcher/options.c +++ b/src/main/launcher/options.c @@ -171,7 +171,7 @@ bool options_read_cmdline(struct options *options, int argc, const char **argv) options->override_urlslash_enabled = true; - const char * urlslash_value = argv[++i]; + const char *urlslash_value = argv[++i]; options->override_urlslash_value = false; if (_stricmp(urlslash_value, "1") == 0) { @@ -233,7 +233,8 @@ void options_print_usage(void) "times)\n" " -B [filename] Load pre-hook DLL loaded before avs boot " "(can be specified multiple times)\n" - " -I [filename] Load pre-hook DLL that overrides IAT reference before execution" + " -I [filename] Load pre-hook DLL that overrides IAT reference " + "before execution" "(can be specified multiple times)\n" " -Y [filename] Log to a file in addition to the console\n" " -D Halt the launcher before bootstrapping AVS " diff --git a/src/main/mempatch-hook/main.c b/src/main/mempatch-hook/main.c index 2e12991..b149640 100644 --- a/src/main/mempatch-hook/main.c +++ b/src/main/mempatch-hook/main.c @@ -10,9 +10,12 @@ #include "util/log.h" static bool patch_memory_check_data( - uintptr_t base_address, uintptr_t address, uint8_t *data_expected, size_t len) + uintptr_t base_address, + uintptr_t address, + uint8_t *data_expected, + size_t len) { - uint8_t *dest = (uint8_t *)(base_address + address); + uint8_t *dest = (uint8_t *) (base_address + address); bool success = true; for (size_t i = 0; i < len; i++) { @@ -23,7 +26,7 @@ static bool patch_memory_check_data( (uint64_t) address, // this cast is technically wrong // but no one should be patching 32K worth of bytes at once - (int)i, + (int) i, data_expected[i], dest[i]); success = false; @@ -38,7 +41,7 @@ static bool patch_memory_data( { DWORD old_protect; - uint8_t *dest = (uint8_t *)(base_address + address); + uint8_t *dest = (uint8_t *) (base_address + address); if (!VirtualProtect( (void *) dest, diff --git a/src/main/p3io/ioctl.h b/src/main/p3io/ioctl.h index 39a9dbd..35142d4 100644 --- a/src/main/p3io/ioctl.h +++ b/src/main/p3io/ioctl.h @@ -3,8 +3,8 @@ enum { P3IO_IOCTL_GET_VERSION = 0x00222004, - P3IO_IOCTL_READ_JAMMA = 0x00222068, - P3IO_IOCTL_RESET_PIPE = 0x00222098, + P3IO_IOCTL_READ_JAMMA = 0x00222068, + P3IO_IOCTL_RESET_PIPE = 0x00222098, }; #endif diff --git a/src/main/p4io/cmd.h b/src/main/p4io/cmd.h index 4514bae..3b6bc1d 100644 --- a/src/main/p4io/cmd.h +++ b/src/main/p4io/cmd.h @@ -63,5 +63,4 @@ struct p4io_resp_device_info { char build_time[16]; }; - #endif diff --git a/src/main/p4io/guid.h b/src/main/p4io/guid.h index abe19dd..d9ee166 100644 --- a/src/main/p4io/guid.h +++ b/src/main/p4io/guid.h @@ -7,7 +7,6 @@ static const GUID p4io_guid = { 0x8B7250A5, 0x4F61, 0x46C9, - {0x84, 0x3A, 0xE6, 0x68, 0x06, 0x47, 0x6A, 0x20} -}; + {0x84, 0x3A, 0xE6, 0x68, 0x06, 0x47, 0x6A, 0x20}}; #endif diff --git a/src/main/p4iodrv/device.c b/src/main/p4iodrv/device.c index 279964d..67dd56e 100644 --- a/src/main/p4iodrv/device.c +++ b/src/main/p4iodrv/device.c @@ -25,29 +25,37 @@ static bool p4io_transfer( const void *req_payload, size_t req_payload_len, void *resp_payload, - size_t resp_payload_len -) { + size_t resp_payload_len) +{ size_t transferred_response_payload = resp_payload_len; - bool ret = p4io_usb_transfer(ctx->bulk_handle, cmd, ctx->seq_no, - req_payload, req_payload_len, - resp_payload, &transferred_response_payload); + bool ret = p4io_usb_transfer( + ctx->bulk_handle, + cmd, + ctx->seq_no, + req_payload, + req_payload_len, + resp_payload, + &transferred_response_payload); ctx->seq_no++; - if(!ret) { + if (!ret) { return false; } - if(resp_payload_len && transferred_response_payload != resp_payload_len) { - log_warning("Asked for %u bytes got %u", (unsigned)resp_payload_len, - (unsigned)transferred_response_payload); + if (resp_payload_len && transferred_response_payload != resp_payload_len) { + log_warning( + "Asked for %u bytes got %u", + (unsigned) resp_payload_len, + (unsigned) transferred_response_payload); return false; } return true; } -struct p4iodrv_ctx *p4iodrv_open(void) { +struct p4iodrv_ctx *p4iodrv_open(void) +{ struct p4iodrv_ctx *ctx = xcalloc(sizeof(struct p4iodrv_ctx)); // jamma is read as fast as possible in its own thread, so having them be @@ -57,14 +65,15 @@ struct p4iodrv_ctx *p4iodrv_open(void) { ctx->bulk_handle = p4io_usb_open(); ctx->seq_no = 0; - if(ctx->jamma_handle == INVALID_HANDLE_VALUE || ctx->bulk_handle == INVALID_HANDLE_VALUE) { + if (ctx->jamma_handle == INVALID_HANDLE_VALUE || + ctx->bulk_handle == INVALID_HANDLE_VALUE) { free(ctx); return NULL; } p4io_cmd_init(ctx); - if(!p4io_print_version(ctx)) { + if (!p4io_print_version(ctx)) { free(ctx); return NULL; } @@ -72,18 +81,21 @@ struct p4iodrv_ctx *p4iodrv_open(void) { return ctx; } -void p4iodrv_close(struct p4iodrv_ctx *ctx) { +void p4iodrv_close(struct p4iodrv_ctx *ctx) +{ p4io_usb_close(ctx->jamma_handle); p4io_usb_close(ctx->bulk_handle); free(ctx); } -bool p4iodrv_read_jamma(struct p4iodrv_ctx *ctx, uint32_t jamma[4]) { +bool p4iodrv_read_jamma(struct p4iodrv_ctx *ctx, uint32_t jamma[4]) +{ return p4io_usb_read_jamma(ctx->jamma_handle, jamma); } // send something you don't expect a response for -static bool p4io_send(struct p4iodrv_ctx *ctx, uint8_t cmd) { +static bool p4io_send(struct p4iodrv_ctx *ctx, uint8_t cmd) +{ return p4io_transfer(ctx, cmd, NULL, 0, NULL, 0); } @@ -91,19 +103,21 @@ static bool p4io_send(struct p4iodrv_ctx *ctx, uint8_t cmd) { // Even if we were to check the return value here, the reset command returns a 0 // byte response - not even an "OK" status, 0 bytes in total. That technically // should be raising an error, but because reset is a special case it's ignored -static void p4io_cmd_init(struct p4iodrv_ctx *ctx) { +static void p4io_cmd_init(struct p4iodrv_ctx *ctx) +{ p4io_send(ctx, P4IO_CMD_INIT); } -static bool p4io_print_version(struct p4iodrv_ctx *ctx) { +static bool p4io_print_version(struct p4iodrv_ctx *ctx) +{ char p4io_name[128]; - if(!p4io_usb_read_device_name(ctx->bulk_handle, p4io_name)) { + if (!p4io_usb_read_device_name(ctx->bulk_handle, p4io_name)) { return false; } struct p4io_resp_device_info dev_info; - if(!p4iodrv_cmd_device_info(ctx, &dev_info)) { + if (!p4iodrv_cmd_device_info(ctx, &dev_info)) { log_warning("p4io get_device_info failed"); return false; } @@ -113,21 +127,30 @@ static bool p4io_print_version(struct p4iodrv_ctx *ctx) { log_info("p4io name: %s", p4io_name); log_info("p4io type: %08X", dev_info.type); - log_info("p4io version: %d.%d.%d", dev_info.version_major, dev_info.version_minor, dev_info.version_revision); + log_info( + "p4io version: %d.%d.%d", + dev_info.version_major, + dev_info.version_minor, + dev_info.version_revision); log_info("p4io product: %.4s", dev_info.product_code); log_info("p4io build date: %.16s", dev_info.build_date); log_info("p4io build time: %.16s", dev_info.build_time); return true; } -bool p4iodrv_cmd_device_info(struct p4iodrv_ctx *ctx, struct p4io_resp_device_info *info) { - return p4io_transfer(ctx, P4IO_CMD_GET_DEVICE_INFO, NULL, 0, info, sizeof(*info)); +bool p4iodrv_cmd_device_info( + struct p4iodrv_ctx *ctx, struct p4io_resp_device_info *info) +{ + return p4io_transfer( + ctx, P4IO_CMD_GET_DEVICE_INFO, NULL, 0, info, sizeof(*info)); } -bool p4iodrv_cmd_portout(struct p4iodrv_ctx *ctx, const uint8_t buffer[16]) { +bool p4iodrv_cmd_portout(struct p4iodrv_ctx *ctx, const uint8_t buffer[16]) +{ return p4io_transfer(ctx, P4IO_CMD_SET_PORTOUT, buffer, 16, NULL, 0); } -bool p4iodrv_cmd_coinstock(struct p4iodrv_ctx *ctx, const uint8_t buffer[4]) { +bool p4iodrv_cmd_coinstock(struct p4iodrv_ctx *ctx, const uint8_t buffer[4]) +{ return p4io_transfer(ctx, P4IO_CMD_COINSTOCK, buffer, 4, NULL, 0); } diff --git a/src/main/p4iodrv/device.h b/src/main/p4iodrv/device.h index 7b688f7..009ad03 100644 --- a/src/main/p4iodrv/device.h +++ b/src/main/p4iodrv/device.h @@ -10,7 +10,8 @@ struct p4iodrv_ctx; struct p4iodrv_ctx *p4iodrv_open(void); void p4iodrv_close(struct p4iodrv_ctx *ctx); -bool p4iodrv_cmd_device_info(struct p4iodrv_ctx *ctx, struct p4io_resp_device_info *info); +bool p4iodrv_cmd_device_info( + struct p4iodrv_ctx *ctx, struct p4io_resp_device_info *info); bool p4iodrv_cmd_portout(struct p4iodrv_ctx *ctx, const uint8_t buffer[16]); bool p4iodrv_cmd_coinstock(struct p4iodrv_ctx *ctx, const uint8_t buffer[4]); bool p4iodrv_read_jamma(struct p4iodrv_ctx *ctx, uint32_t jamma[4]); diff --git a/src/main/p4iodrv/usb.c b/src/main/p4iodrv/usb.c index 5608eb9..8c99fc4 100644 --- a/src/main/p4iodrv/usb.c +++ b/src/main/p4iodrv/usb.c @@ -1,8 +1,8 @@ #define LOG_MODULE "p4iodrv-usb" -#include -#include #include +#include +#include // clang-format off // Don't format because the order is important here @@ -19,34 +19,47 @@ #include "util/log.h" #include "util/str.h" -HANDLE p4io_usb_open(void) { +HANDLE p4io_usb_open(void) +{ HANDLE handle = INVALID_HANDLE_VALUE; - wchar_t p4io_filename[MAX_PATH]; // game uses 1024, but it shouldn't be that long + wchar_t p4io_filename[MAX_PATH]; // game uses 1024, but it shouldn't be that + // long PSP_DEVICE_INTERFACE_DETAIL_DATA_W detail_data = NULL; HDEVINFO dev_info_set; - dev_info_set = SetupDiGetClassDevsW(&p4io_guid, NULL, NULL, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT); + dev_info_set = SetupDiGetClassDevsW( + &p4io_guid, NULL, NULL, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT); - if(dev_info_set == INVALID_HANDLE_VALUE) { - log_warning("SetupDiGetClassDevs fail, is p4io device connected and driver installed?"); + if (dev_info_set == INVALID_HANDLE_VALUE) { + log_warning( + "SetupDiGetClassDevs fail, is p4io device connected and driver " + "installed?"); return INVALID_HANDLE_VALUE; } SP_DEVICE_INTERFACE_DATA interface_data; interface_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); - if(!SetupDiEnumDeviceInterfaces(dev_info_set, NULL, &p4io_guid, 0, &interface_data)) { + if (!SetupDiEnumDeviceInterfaces( + dev_info_set, NULL, &p4io_guid, 0, &interface_data)) { log_warning("SetupDiEnumDeviceInterfaces fail"); goto CLEANUP; } DWORD required_size; - SetupDiGetDeviceInterfaceDetailW(dev_info_set, &interface_data, NULL, 0, &required_size, NULL); + SetupDiGetDeviceInterfaceDetailW( + dev_info_set, &interface_data, NULL, 0, &required_size, NULL); detail_data = malloc(required_size); detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W); - if(!SetupDiGetDeviceInterfaceDetailW(dev_info_set, &interface_data, detail_data, required_size, NULL, NULL)) { + if (!SetupDiGetDeviceInterfaceDetailW( + dev_info_set, + &interface_data, + detail_data, + required_size, + NULL, + NULL)) { log_warning("SetupDiGetDeviceInterfaceDetailW fail"); goto CLEANUP; } @@ -56,28 +69,45 @@ HANDLE p4io_usb_open(void) { log_info("p4io found at path %ls", p4io_filename); - handle = CreateFileW(p4io_filename, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); - if(handle == INVALID_HANDLE_VALUE) { + handle = CreateFileW( + p4io_filename, + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + 0, + NULL); + if (handle == INVALID_HANDLE_VALUE) { log_warning("CreateFileW fail"); goto CLEANUP; } - CLEANUP: +CLEANUP: free(detail_data); SetupDiDestroyDeviceInfoList(dev_info_set); return handle; } -void p4io_usb_close(HANDLE p4io_handle) { - if(p4io_handle != INVALID_HANDLE_VALUE) { +void p4io_usb_close(HANDLE p4io_handle) +{ + if (p4io_handle != INVALID_HANDLE_VALUE) { CloseHandle(p4io_handle); } p4io_handle = INVALID_HANDLE_VALUE; } -bool p4io_usb_read_jamma(HANDLE interrupt_handle, uint32_t jamma[4]) { +bool p4io_usb_read_jamma(HANDLE interrupt_handle, uint32_t jamma[4]) +{ DWORD bytes_returned; - if(!DeviceIoControl(interrupt_handle, P4IO_IOCTL_READ_JAMMA_2, NULL, 0, jamma, sizeof(uint32_t[4]), &bytes_returned, NULL)) { + if (!DeviceIoControl( + interrupt_handle, + P4IO_IOCTL_READ_JAMMA_2, + NULL, + 0, + jamma, + sizeof(uint32_t[4]), + &bytes_returned, + NULL)) { log_warning("jamma read failed"); return false; } @@ -85,9 +115,18 @@ bool p4io_usb_read_jamma(HANDLE interrupt_handle, uint32_t jamma[4]) { return true; } -bool p4io_usb_read_device_name(HANDLE bulk_handle, char name[128]) { +bool p4io_usb_read_device_name(HANDLE bulk_handle, char name[128]) +{ DWORD bytes_returned; - if(!DeviceIoControl(bulk_handle, P4IO_IOCTL_GET_DEVICE_NAME, NULL, 0, name, 128, &bytes_returned, NULL)) { + if (!DeviceIoControl( + bulk_handle, + P4IO_IOCTL_GET_DEVICE_NAME, + NULL, + 0, + name, + 128, + &bytes_returned, + NULL)) { log_warning("p4io does not support get_name cmd"); return false; } @@ -102,18 +141,18 @@ bool p4io_usb_transfer( const void *req_payload, size_t req_payload_len, void *resp_payload, - size_t *resp_payload_len -) { + size_t *resp_payload_len) +{ DWORD bytes_requested; DWORD bytes_xferred; struct p4io_cmd_package cmd_buf; - if(bulk_handle == INVALID_HANDLE_VALUE) { + if (bulk_handle == INVALID_HANDLE_VALUE) { log_warning("p4io not open"); return false; } - if(req_payload_len > sizeof(cmd_buf.payload)) { + if (req_payload_len > sizeof(cmd_buf.payload)) { log_warning("request too big"); return false; } @@ -126,32 +165,35 @@ bool p4io_usb_transfer( bytes_requested = P4IO_CMD_HEADER_LEN + req_payload_len; - if(!WriteFile(bulk_handle, &cmd_buf, bytes_requested, &bytes_xferred, 0)) { + if (!WriteFile(bulk_handle, &cmd_buf, bytes_requested, &bytes_xferred, 0)) { log_warning("WriteFile failed"); return false; } - if(bytes_xferred != bytes_requested) { + if (bytes_xferred != bytes_requested) { log_warning("WriteFile didn't finish"); return false; } // must be 65 bytes or requests can stall - only 64 will ever be returned - if(!ReadFile(bulk_handle, &cmd_buf, 65, &bytes_xferred, 0)) { - log_warning("ReadFile (%u) failed", (unsigned)bytes_requested); + if (!ReadFile(bulk_handle, &cmd_buf, 65, &bytes_xferred, 0)) { + log_warning("ReadFile (%u) failed", (unsigned) bytes_requested); return false; } - if(bytes_xferred >= sizeof(struct p4io_cmd_header)) { + if (bytes_xferred >= sizeof(struct p4io_cmd_header)) { memcpy(resp_payload, cmd_buf.payload, *resp_payload_len); *resp_payload_len = cmd_buf.header.payload_len; - if(cmd_buf.header.sof != P4IO_SOF) { + if (cmd_buf.header.sof != P4IO_SOF) { log_warning("Response bad header"); return false; } - if(seq_no != cmd_buf.header.seq_num) { - log_warning("seq_num mismatch (ours %d != theirs %d)", seq_no, cmd_buf.header.seq_num); + if (seq_no != cmd_buf.header.seq_num) { + log_warning( + "seq_num mismatch (ours %d != theirs %d)", + seq_no, + cmd_buf.header.seq_num); return false; } } else { diff --git a/src/main/p4iodrv/usb.h b/src/main/p4iodrv/usb.h index 9adeb5c..ee9b4c3 100644 --- a/src/main/p4iodrv/usb.h +++ b/src/main/p4iodrv/usb.h @@ -16,7 +16,6 @@ bool p4io_usb_transfer( const void *req_payload, size_t req_payload_len, void *resp_payload, - size_t *resp_payload_len -); + size_t *resp_payload_len); #endif diff --git a/src/main/p4ioemu/device.c b/src/main/p4ioemu/device.c index ee27e3b..e18e891 100644 --- a/src/main/p4ioemu/device.c +++ b/src/main/p4ioemu/device.c @@ -13,7 +13,7 @@ #include "util/log.h" #include "util/str.h" -//#define P4IOEMU_DEBUG_DUMP +// #define P4IOEMU_DEBUG_DUMP static const struct p4ioemu_device_msg_hook *p4ioemu_device_msg_hook; diff --git a/src/main/popnhook-util/acio.c b/src/main/popnhook-util/acio.c index efeb84d..60d66b8 100644 --- a/src/main/popnhook-util/acio.c +++ b/src/main/popnhook-util/acio.c @@ -33,7 +33,6 @@ static struct ac_io_emu_icca popnhook_acio_emu_icca; static bool popnhook_icca_override_version; static enum ac_io_emu_icca_version popnhook_icca_override_version_value; - void popnhook_acio_override_version(enum ac_io_emu_icca_version version) { popnhook_icca_override_version = true; @@ -48,13 +47,10 @@ void popnhook_acio_init(bool legacy_mode) ac_io_emu_init(&popnhook_acio_emu, L"COM1"); - ac_io_emu_icca_init( - &popnhook_acio_emu_icca, &popnhook_acio_emu, 0); + ac_io_emu_icca_init(&popnhook_acio_emu_icca, &popnhook_acio_emu, 0); if (popnhook_icca_override_version) { ac_io_emu_icca_set_version( - &popnhook_acio_emu_icca, - popnhook_icca_override_version_value - ); + &popnhook_acio_emu_icca, popnhook_icca_override_version_value); } rs232_hook_add_fd(popnhook_acio_emu.fd); @@ -93,8 +89,7 @@ popnhook_acio_dispatch_irp(struct irp *irp) break; case 1: - ac_io_emu_icca_dispatch_request( - &popnhook_acio_emu_icca, msg); + ac_io_emu_icca_dispatch_request(&popnhook_acio_emu_icca, msg); break; diff --git a/src/main/popnhook-util/mixer.c b/src/main/popnhook-util/mixer.c index 78f3bde..91d3c75 100644 --- a/src/main/popnhook-util/mixer.c +++ b/src/main/popnhook-util/mixer.c @@ -11,64 +11,85 @@ #include "util/defs.h" #include "util/log.h" -MMRESULT STDCALL hook_mixerGetLineControlsA(HMIXEROBJ hmxobj, LPMIXERLINECONTROLSA pmxlc, DWORD fdwControls); -MMRESULT STDCALL hook_mixerGetDevCapsA(UINT_PTR uMxId, LPMIXERCAPSA pmxcaps, UINT cbmxcaps); -MMRESULT STDCALL hook_mixerOpen(LPHMIXER phmx, UINT uMxId, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen); -MMRESULT STDCALL hook_mixerSetControlDetails(HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails); -MMRESULT STDCALL hook_mixerGetControlDetailsA(HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails); +MMRESULT STDCALL hook_mixerGetLineControlsA( + HMIXEROBJ hmxobj, LPMIXERLINECONTROLSA pmxlc, DWORD fdwControls); +MMRESULT STDCALL +hook_mixerGetDevCapsA(UINT_PTR uMxId, LPMIXERCAPSA pmxcaps, UINT cbmxcaps); +MMRESULT STDCALL hook_mixerOpen( + LPHMIXER phmx, + UINT uMxId, + DWORD_PTR dwCallback, + DWORD_PTR dwInstance, + DWORD fdwOpen); +MMRESULT STDCALL hook_mixerSetControlDetails( + HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails); +MMRESULT STDCALL hook_mixerGetControlDetailsA( + HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails); MMRESULT STDCALL hook_mixerClose(HMIXER hmx); -MMRESULT STDCALL hook_mixerGetLineInfoA(HMIXEROBJ hmxobj, LPMIXERLINEA pmxl, DWORD fdwInfo); +MMRESULT STDCALL +hook_mixerGetLineInfoA(HMIXEROBJ hmxobj, LPMIXERLINEA pmxl, DWORD fdwInfo); static const struct hook_symbol mixer_hook_syms[] = { - {.name = "mixerGetLineControlsA", - .patch = hook_mixerGetLineControlsA}, - {.name = "mixerGetDevCapsA", - .patch = hook_mixerGetDevCapsA}, - {.name = "mixerOpen", - .patch = hook_mixerOpen}, - {.name = "mixerSetControlDetails", - .patch = hook_mixerSetControlDetails}, - {.name = "mixerGetControlDetailsA", - .patch = hook_mixerGetControlDetailsA}, - {.name = "mixerClose", - .patch = hook_mixerClose}, - {.name = "mixerGetLineInfoA", - .patch = hook_mixerGetLineInfoA}, + {.name = "mixerGetLineControlsA", .patch = hook_mixerGetLineControlsA}, + {.name = "mixerGetDevCapsA", .patch = hook_mixerGetDevCapsA}, + {.name = "mixerOpen", .patch = hook_mixerOpen}, + {.name = "mixerSetControlDetails", .patch = hook_mixerSetControlDetails}, + {.name = "mixerGetControlDetailsA", .patch = hook_mixerGetControlDetailsA}, + {.name = "mixerClose", .patch = hook_mixerClose}, + {.name = "mixerGetLineInfoA", .patch = hook_mixerGetLineInfoA}, }; -MMRESULT STDCALL hook_mixerOpen(LPHMIXER phmx, UINT uMxId, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen) { - *(DWORD*)phmx = 1234; // any non-zero value is fine +MMRESULT STDCALL hook_mixerOpen( + LPHMIXER phmx, + UINT uMxId, + DWORD_PTR dwCallback, + DWORD_PTR dwInstance, + DWORD fdwOpen) +{ + *(DWORD *) phmx = 1234; // any non-zero value is fine return MMSYSERR_NOERROR; } -MMRESULT STDCALL hook_mixerClose(HMIXER hmx) { +MMRESULT STDCALL hook_mixerClose(HMIXER hmx) +{ return MMSYSERR_NOERROR; } -MMRESULT STDCALL hook_mixerGetLineControlsA(HMIXEROBJ hmxobj, LPMIXERLINECONTROLSA pmxlc, DWORD fdwControls) { +MMRESULT STDCALL hook_mixerGetLineControlsA( + HMIXEROBJ hmxobj, LPMIXERLINECONTROLSA pmxlc, DWORD fdwControls) +{ return MMSYSERR_NOERROR; } -MMRESULT STDCALL hook_mixerGetDevCapsA(UINT_PTR uMxId, LPMIXERCAPSA pmxcaps, UINT cbmxcaps) { +MMRESULT STDCALL +hook_mixerGetDevCapsA(UINT_PTR uMxId, LPMIXERCAPSA pmxcaps, UINT cbmxcaps) +{ return MMSYSERR_NOERROR; } -MMRESULT STDCALL hook_mixerGetControlDetailsA(HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails) { +MMRESULT STDCALL hook_mixerGetControlDetailsA( + HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails) +{ return MMSYSERR_NOERROR; } -MMRESULT STDCALL hook_mixerGetLineInfoA(HMIXEROBJ hmxobj, LPMIXERLINEA pmxl, DWORD fdwInfo) { +MMRESULT STDCALL +hook_mixerGetLineInfoA(HMIXEROBJ hmxobj, LPMIXERLINEA pmxl, DWORD fdwInfo) +{ return MMSYSERR_NOERROR; } -MMRESULT STDCALL hook_mixerSetControlDetails(HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails) { +MMRESULT STDCALL hook_mixerSetControlDetails( + HMIXEROBJ hmxobj, LPMIXERCONTROLDETAILS pmxcd, DWORD fdwDetails) +{ return MMSYSERR_NOERROR; } void popnhook_mixer_hook_init(void) { - hook_table_apply(NULL, "winmm.dll", mixer_hook_syms, lengthof(mixer_hook_syms)); + hook_table_apply( + NULL, "winmm.dll", mixer_hook_syms, lengthof(mixer_hook_syms)); log_info("Inserted mixer hooks"); } diff --git a/src/main/popnhook1/config-gfx.c b/src/main/popnhook1/config-gfx.c index bc15a86..8e231d1 100644 --- a/src/main/popnhook1/config-gfx.c +++ b/src/main/popnhook1/config-gfx.c @@ -11,7 +11,6 @@ #define POPNHOOK1_CONFIG_GFX_WINDOW_WIDTH_KEY "gfx.window_width" #define POPNHOOK1_CONFIG_GFX_WINDOW_HEIGHT_KEY "gfx.window_height" - #define POPNHOOK1_CONFIG_GFX_DEFAULT_FRAMED_VALUE false #define POPNHOOK1_CONFIG_GFX_DEFAULT_WINDOWED_VALUE false #define POPNHOOK1_CONFIG_GFX_DEFAULT_WINDOW_WIDTH_VALUE -1 diff --git a/src/main/popnhook1/d3d9.c b/src/main/popnhook1/d3d9.c index 2b10ff8..1d67262 100644 --- a/src/main/popnhook1/d3d9.c +++ b/src/main/popnhook1/d3d9.c @@ -24,8 +24,8 @@ static const hook_d3d9_irp_handler_t popnhook1_d3d9_handlers[] = { popnhook1_d3d9_irp_handler, }; -static void popnhook1_d3d9_validate_config( - const struct popnhook1_d3d9_config *config) +static void +popnhook1_d3d9_validate_config(const struct popnhook1_d3d9_config *config) { if (!config->windowed && config->framed) { log_warning("Option framed does not have an effect without windowed"); @@ -58,8 +58,7 @@ void popnhook1_d3d9_init_config(struct popnhook1_d3d9_config *config) config->texture_usage_fix = false; } -void popnhook1_d3d9_configure( - const struct popnhook1_d3d9_config *config) +void popnhook1_d3d9_configure(const struct popnhook1_d3d9_config *config) { log_assert(config); @@ -67,13 +66,10 @@ void popnhook1_d3d9_configure( popnhook1_d3d9_validate_config(config); memcpy( - &popnhook1_d3d9_config, - config, - sizeof(struct popnhook1_d3d9_config)); + &popnhook1_d3d9_config, config, sizeof(struct popnhook1_d3d9_config)); } -static void -popnhook1_d3d9_fix_texture_usage(struct hook_d3d9_irp *irp) +static void popnhook1_d3d9_fix_texture_usage(struct hook_d3d9_irp *irp) { log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_DEV_CREATE_TEXTURE); @@ -82,14 +78,12 @@ popnhook1_d3d9_fix_texture_usage(struct hook_d3d9_irp *irp) irp->args.dev_create_texture.usage = 0; } -static void -popnhook1_d3d9_patch_window(struct hook_d3d9_irp *irp) +static void popnhook1_d3d9_patch_window(struct hook_d3d9_irp *irp) { log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_CREATE_WINDOW_EX); - if (popnhook1_d3d9_config.windowed && - popnhook1_d3d9_config.framed) { + if (popnhook1_d3d9_config.windowed && popnhook1_d3d9_config.framed) { /* use a different style */ irp->args.create_window_ex.style |= WS_OVERLAPPEDWINDOW; @@ -153,14 +147,12 @@ static void popnhook1_d3d9_calc_win_size_with_framed( wp->cy = rect.bottom - rect.top; } -static void -popnhook1_d3d9_fix_window_size_and_pos(struct hook_d3d9_irp *irp) +static void popnhook1_d3d9_fix_window_size_and_pos(struct hook_d3d9_irp *irp) { log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_CREATE_WINDOW_EX); - if (popnhook1_d3d9_config.windowed && - popnhook1_d3d9_config.framed) { + if (popnhook1_d3d9_config.windowed && popnhook1_d3d9_config.framed) { /* we have to adjust the window size, because the window needs to be a slightly bigger than the rendering resolution (window caption and stuff is included in the window size) */ @@ -168,8 +160,12 @@ popnhook1_d3d9_fix_window_size_and_pos(struct hook_d3d9_irp *irp) popnhook1_d3d9_calc_win_size_with_framed( irp->args.create_window_ex.result, - irp->args.create_window_ex.x == CW_USEDEFAULT ? 0 : irp->args.create_window_ex.x, - irp->args.create_window_ex.y == CW_USEDEFAULT ? 0 : irp->args.create_window_ex.y, + irp->args.create_window_ex.x == CW_USEDEFAULT ? + 0 : + irp->args.create_window_ex.x, + irp->args.create_window_ex.y == CW_USEDEFAULT ? + 0 : + irp->args.create_window_ex.y, irp->args.create_window_ex.width, irp->args.create_window_ex.height, &wp); @@ -186,8 +182,8 @@ popnhook1_d3d9_fix_window_size_and_pos(struct hook_d3d9_irp *irp) } } -static void popnhook1_d3d9_fix_create_device_apply_window_mode( - struct hook_d3d9_irp *irp) +static void +popnhook1_d3d9_fix_create_device_apply_window_mode(struct hook_d3d9_irp *irp) { log_assert(irp); log_assert(irp->op == HOOK_D3D9_IRP_OP_CTX_CREATE_DEVICE); diff --git a/src/main/popnhook1/d3d9.h b/src/main/popnhook1/d3d9.h index 08f728d..b8bc3c1 100644 --- a/src/main/popnhook1/d3d9.h +++ b/src/main/popnhook1/d3d9.h @@ -28,8 +28,8 @@ struct popnhook1_d3d9_config { uint16_t override_window_height; /** - * Fix an issue with CreateTexture on later versions of Windows that prevents - * the games from launching. + * Fix an issue with CreateTexture on later versions of Windows that + * prevents the games from launching. */ bool texture_usage_fix; }; diff --git a/src/main/popnhook1/dllmain.c b/src/main/popnhook1/dllmain.c index b076236..5995e22 100644 --- a/src/main/popnhook1/dllmain.c +++ b/src/main/popnhook1/dllmain.c @@ -43,8 +43,8 @@ #include "security/rp-sign-key.h" -#define POPNHOOK1_INFO_HEADER \ - "popnhook1 for pop'n music 15, 16, 17, 18" \ +#define POPNHOOK1_INFO_HEADER \ + "popnhook1 for pop'n music 15, 16, 17, 18" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) #define POPNHOOK1_CMD_USAGE \ "Usage: inject.exe popnhook1.dll [options...]" @@ -63,8 +63,7 @@ static const struct hook_symbol init_hook_syms[] = { }; static void popnhook_setup_d3d9_hooks( - const struct popnhook1_config_gfx *config_gfx, - const bool texture_usage_fix) + const struct popnhook1_config_gfx *config_gfx, const bool texture_usage_fix) { struct popnhook1_d3d9_config d3d9_config; @@ -119,9 +118,12 @@ static DWORD STDCALL my_GetStartupInfoA(LPSTARTUPINFOA lpStartupInfo) popnhook_setup_d3d9_hooks( &config_gfx, - // pop'n music 16 requires a patch for the texture usage to not crash on newer Windows - memcmp(config_sec.black_plug_mcode.game, SECURITY_MCODE_GAME_POPN_16, sizeof(config_sec.black_plug_mcode.game)) == 0 - ); + // pop'n music 16 requires a patch for the texture usage to not crash on + // newer Windows + memcmp( + config_sec.black_plug_mcode.game, + SECURITY_MCODE_GAME_POPN_16, + sizeof(config_sec.black_plug_mcode.game)) == 0); popnhook1_avs_boot_init(); popnhook1_avs_boot_set_eamuse_addr(&config_eamuse.server); diff --git a/src/main/popnhook1/filesystem.c b/src/main/popnhook1/filesystem.c index 8544eda..3d7fd09 100644 --- a/src/main/popnhook1/filesystem.c +++ b/src/main/popnhook1/filesystem.c @@ -24,9 +24,8 @@ static HANDLE STDCALL my_CreateFileA( DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile); -static HANDLE STDCALL my_FindFirstFileA( - LPCSTR lpFileName, - LPWIN32_FIND_DATAA lpFindFileData); +static HANDLE STDCALL +my_FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData); static HANDLE(STDCALL *real_CreateFileA)( LPCSTR lpFileName, @@ -37,8 +36,7 @@ static HANDLE(STDCALL *real_CreateFileA)( DWORD dwFlagsAndAttributes, HANDLE hTemplateFile); static HANDLE(STDCALL *real_FindFirstFileA)( - LPCSTR lpFileName, - LPWIN32_FIND_DATAA lpFindFileData); + LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData); /* ------------------------------------------------------------------------- */ @@ -55,8 +53,10 @@ static const struct hook_symbol settings_hook_syms[] = { static char *popnhook1_filesystem_get_path(LPCSTR lpFileName) { - if (lpFileName != NULL && (tolower(lpFileName[0]) == 'd' || tolower(lpFileName[0]) == 'e') && lpFileName[1] == ':') { - char *new_path = (char*)xmalloc(MAX_PATH); + if (lpFileName != NULL && + (tolower(lpFileName[0]) == 'd' || tolower(lpFileName[0]) == 'e') && + lpFileName[1] == ':') { + char *new_path = (char *) xmalloc(MAX_PATH); char *data_ptr = strstr(lpFileName, "\\data\\"); if (data_ptr == NULL) @@ -117,9 +117,8 @@ static HANDLE STDCALL my_CreateFileA( return status; } -static HANDLE STDCALL my_FindFirstFileA( - LPCSTR lpFileName, - LPWIN32_FIND_DATAA lpFindFileData) +static HANDLE STDCALL +my_FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData) { // pop'n 15 makes use of FindFirstFileA char *new_path = popnhook1_filesystem_get_path(lpFileName); @@ -127,14 +126,10 @@ static HANDLE STDCALL my_FindFirstFileA( if (new_path != NULL) { // log_misc("Remapped settings path 2 %s -> %s", lpFileName, new_path); - return real_FindFirstFileA( - new_path, - lpFindFileData); + return real_FindFirstFileA(new_path, lpFindFileData); } - return real_FindFirstFileA( - lpFileName, - lpFindFileData); + return real_FindFirstFileA(lpFileName, lpFindFileData); } /* ------------------------------------------------------------------------- */ diff --git a/src/main/popnio/popnio.c b/src/main/popnio/popnio.c index 7c651d6..d5389cd 100644 --- a/src/main/popnio/popnio.c +++ b/src/main/popnio/popnio.c @@ -2,8 +2,8 @@ #include #include -#include "bemanitools/popnio.h" #include "bemanitools/input.h" +#include "bemanitools/popnio.h" void popn_io_set_loggers( log_formatter_t misc, @@ -67,10 +67,10 @@ void popn_io_set_button_lights(uint32_t lights) void popn_io_set_coin_blocker_light(bool enabled) { - //mapper_write_light(x, enabled ? 255 : 0); + // mapper_write_light(x, enabled ? 255 : 0); } void popn_io_set_coin_counter_light(bool enabled) { - //mapper_write_light(x, enabled ? 255 : 0); + // mapper_write_light(x, enabled ? 255 : 0); } diff --git a/src/main/sdvxhook/lcd.c b/src/main/sdvxhook/lcd.c index dc12d07..06ea1e6 100644 --- a/src/main/sdvxhook/lcd.c +++ b/src/main/sdvxhook/lcd.c @@ -32,7 +32,7 @@ void lcd_init(void) log_assert(lcd_fd == NULL); HRESULT hr; - + hr = iohook_open_nul_fd(&lcd_fd); if (hr != S_OK) { diff --git a/src/main/sdvxhook2-cn/dllmain.c b/src/main/sdvxhook2-cn/dllmain.c index dd3de80..3a20217 100644 --- a/src/main/sdvxhook2-cn/dllmain.c +++ b/src/main/sdvxhook2-cn/dllmain.c @@ -32,7 +32,7 @@ #include "util/thread.h" #define SDVXHOOK2_CN_INFO_HEADER \ - "sdvxhook for VW CN" \ + "sdvxhook for VW CN" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) "\n" #define SDVXHOOK2_CN_CMD_USAGE \ "Usage: launcher.exe -K sdvxhook2.dll [options...]" diff --git a/src/main/sdvxhook2-cn/unis-version.c b/src/main/sdvxhook2-cn/unis-version.c index 57e75c9..d660999 100644 --- a/src/main/sdvxhook2-cn/unis-version.c +++ b/src/main/sdvxhook2-cn/unis-version.c @@ -69,7 +69,7 @@ bool my_IsPlayerForbidState(int pnum) return false; } -void unis_version_hook_init(const char* unis_path) +void unis_version_hook_init(const char *unis_path) { hook_table_apply( NULL, "Shell32.dll", unis_shell32_syms, lengthof(unis_shell32_syms)); diff --git a/src/main/sdvxhook2-cn/unis-version.h b/src/main/sdvxhook2-cn/unis-version.h index 1cd7e4d..42450da 100644 --- a/src/main/sdvxhook2-cn/unis-version.h +++ b/src/main/sdvxhook2-cn/unis-version.h @@ -3,12 +3,12 @@ /** * Hooks UNIS support functions - * + * * patches: * - unis config path * - unis network functions - * + * */ -void unis_version_hook_init(const char* unis_path); +void unis_version_hook_init(const char *unis_path); #endif diff --git a/src/main/sdvxhook2/config-io.c b/src/main/sdvxhook2/config-io.c index 993d20a..6d87bc0 100644 --- a/src/main/sdvxhook2/config-io.c +++ b/src/main/sdvxhook2/config-io.c @@ -55,19 +55,22 @@ void sdvxhook2_config_io_init(struct cconfig *config) config, SDVXHOOK2_CONFIG_IO_DISABLE_FILE_HOOKS_KEY, SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_FILE_HOOKS_VALUE, - "Disables the built in file hooks, requiring manual file creation (/dev/raw/j.dest)"); + "Disables the built in file hooks, requiring manual file creation " + "(/dev/raw/j.dest)"); cconfig_util_set_bool( config, SDVXHOOK2_CONFIG_IO_DISABLE_POWER_HOOKS_KEY, SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_POWER_HOOKS_VALUE, - "Disables the built in power control hooks, allowing game to modify system power settings"); + "Disables the built in power control hooks, allowing game to modify " + "system power settings"); cconfig_util_set_bool( config, SDVXHOOK2_CONFIG_IO_DISABLE_NVAPI_HOOKS_KEY, SDVXHOOK2_CONFIG_IO_DEFAULT_DISABLE_NVAPI_HOOKS_VALUE, - "Disables the built in NVAPI control hooks, allowing game to modify system monitor settings"); + "Disables the built in NVAPI control hooks, allowing game to modify " + "system monitor settings"); cconfig_util_set_bool( config, diff --git a/src/main/sdvxhook2/nvapi.c b/src/main/sdvxhook2/nvapi.c index ec5f27e..fbe14d8 100644 --- a/src/main/sdvxhook2/nvapi.c +++ b/src/main/sdvxhook2/nvapi.c @@ -49,10 +49,12 @@ static void *my_GetProcAddress(HMODULE dll, const char *name) #define OFFSET_NvAPI_DISP_SetDisplayConfig 0x5D8CF8DE -static void *my_nvapi_QueryInterface(uint32_t FunctionOffset) { +static void *my_nvapi_QueryInterface(uint32_t FunctionOffset) +{ if (FunctionOffset == OFFSET_NvAPI_DISP_SetDisplayConfig) { log_info("Request for interface %x intercepted", FunctionOffset); - // no point stubbing this, the error checking for now doesn't check the response anyways + // no point stubbing this, the error checking for now doesn't check the + // response anyways return NULL; } diff --git a/src/main/sdvxio-bio2/sdvxio.c b/src/main/sdvxio-bio2/sdvxio.c index 2e1c1e3..e4dcb6a 100644 --- a/src/main/sdvxio-bio2/sdvxio.c +++ b/src/main/sdvxio-bio2/sdvxio.c @@ -184,7 +184,8 @@ void sdvx_io_set_gpio_lights(uint32_t gpio_lights) pout_staging.gpio[4] = assign_light(gpio_lights, SDVX_IO_OUT_GPIO_D); pout_staging.gpio[5] = assign_light(gpio_lights, SDVX_IO_OUT_GPIO_FX_L); pout_staging.gpio[6] = assign_light(gpio_lights, SDVX_IO_OUT_GPIO_FX_R); - pout_staging.generator[2] = assign_light(gpio_lights, SDVX_IO_OUT_GPIO_GENERATOR_B); + pout_staging.generator[2] = + assign_light(gpio_lights, SDVX_IO_OUT_GPIO_GENERATOR_B); } void sdvx_io_set_pwm_light(uint8_t light_no, uint8_t intensity) @@ -338,7 +339,8 @@ bool sdvx_io_set_amp_volume( // yes, the BIO2 doesn't allow control of the amps individually // so let's just set it so that people's ear's don't blow out - if (!bio2drv_bi2a_sdvx_amp(bio2_device_ctx, bio2_node_id, 0, 0, primary, primary)) { + if (!bio2drv_bi2a_sdvx_amp( + bio2_device_ctx, bio2_node_id, 0, 0, primary, primary)) { return false; } diff --git a/src/main/sdvxio-kfca/config-kfca.c b/src/main/sdvxio-kfca/config-kfca.c index 94da472..91814e6 100644 --- a/src/main/sdvxio-kfca/config-kfca.c +++ b/src/main/sdvxio-kfca/config-kfca.c @@ -34,19 +34,22 @@ void sdvxio_kfca_config_kfca_init(struct cconfig *config) config, SDVXIO_KFCA_CONFIG_MAIN_AMP_VOLUME_KEY, SDVXIO_KFCA_CONFIG_DEFAULT_MAIN_AMP_VOLUME_VALUE, - "SDVXIO digital amp main volume (0-96) 0 is high, 96 is low. -1 is no override."); + "SDVXIO digital amp main volume (0-96) 0 is high, 96 is low. -1 is no " + "override."); cconfig_util_set_int( config, SDVXIO_KFCA_CONFIG_HEADPHONE_AMP_VOLUME_KEY, SDVXIO_KFCA_CONFIG_DEFAULT_HEADPHONE_AMP_VOLUME_VALUE, - "SDVXIO digital amp headphone volume (0-96) 0 is high, 96 is low. -1 is no override."); + "SDVXIO digital amp headphone volume (0-96) 0 is high, 96 is low. -1 " + "is no override."); cconfig_util_set_int( config, SDVXIO_KFCA_CONFIG_SUBWOOFER_AMP_VOLUME_KEY, SDVXIO_KFCA_CONFIG_DEFAULT_SUBWOOFER_AMP_VOLUME_VALUE, - "SDVXIO digital amp subwoofer volume (0-96) 0 is high, 96 is low. -1 is no override."); + "SDVXIO digital amp subwoofer volume (0-96) 0 is high, 96 is low. -1 " + "is no override."); } void sdvxio_kfca_config_kfca_get( diff --git a/src/main/sdvxio-kfca/sdvxio.c b/src/main/sdvxio-kfca/sdvxio.c index a4eb255..e230449 100644 --- a/src/main/sdvxio-kfca/sdvxio.c +++ b/src/main/sdvxio-kfca/sdvxio.c @@ -11,8 +11,8 @@ #include "acio/acio.h" -#include "aciomgr/manager.h" #include "aciodrv/kfca.h" +#include "aciomgr/manager.h" #include "sdvxio-kfca/config-kfca.h" @@ -137,7 +137,10 @@ bool sdvx_io_init( bool init_result = aciodrv_kfca_amp( aciomgr_port_checkout(acio_manager_ctx), kfca_node_id, - primary, headphone, 0, subwoofer); + primary, + headphone, + 0, + subwoofer); aciomgr_port_checkin(acio_manager_ctx); if (!init_result) { @@ -244,9 +247,7 @@ uint16_t sdvx_io_get_spinner_pos(uint8_t spinner_no) } bool sdvx_io_set_amp_volume( - uint8_t primary, - uint8_t headphone, - uint8_t subwoofer) + uint8_t primary, uint8_t headphone, uint8_t subwoofer) { if (!running) { return false; @@ -255,7 +256,10 @@ bool sdvx_io_set_amp_volume( bool amp_result = aciodrv_kfca_amp( aciomgr_port_checkout(acio_manager_ctx), kfca_node_id, - primary, headphone, 96, subwoofer); + primary, + headphone, + 96, + subwoofer); aciomgr_port_checkin(acio_manager_ctx); if (!amp_result) { diff --git a/src/main/sdvxio/sdvxio.c b/src/main/sdvxio/sdvxio.c index 238f0a0..5478c73 100644 --- a/src/main/sdvxio/sdvxio.c +++ b/src/main/sdvxio/sdvxio.c @@ -89,7 +89,8 @@ uint16_t sdvx_io_get_spinner_pos(uint8_t spinner_no) return mapper_read_analog(spinner_no) * 4; } -bool sdvx_io_set_amp_volume(uint8_t primary, uint8_t headphone, uint8_t subwoofer) +bool sdvx_io_set_amp_volume( + uint8_t primary, uint8_t headphone, uint8_t subwoofer) { return true; } diff --git a/src/main/security/id.c b/src/main/security/id.c index 3dd1134..b591fb2 100644 --- a/src/main/security/id.c +++ b/src/main/security/id.c @@ -41,28 +41,28 @@ security_id_checksum_calc(uint8_t initseed, const uint8_t *inbuf, size_t length) v7 = 0; do { - v8 = (result ^ (uint8_t)(v6 >> v7)) & 1; + v8 = (result ^ (uint8_t) (v6 >> v7)) & 1; v9 = result >> 1; if (v8) { v9 ^= 0x8Cu; } - v10 = (v9 ^ (uint8_t)(v6 >> (v7 + 1))) & 1; + v10 = (v9 ^ (uint8_t) (v6 >> (v7 + 1))) & 1; v11 = v9 >> 1; if (v10) { v11 ^= 0x8Cu; } - v12 = (v11 ^ (uint8_t)(v6 >> (v7 + 2))) & 1; + v12 = (v11 ^ (uint8_t) (v6 >> (v7 + 2))) & 1; v13 = v11 >> 1; if (v12) { v13 ^= 0x8Cu; } - v14 = (v13 ^ (uint8_t)(v6 >> (v7 + 3))) & 1; + v14 = (v13 ^ (uint8_t) (v6 >> (v7 + 3))) & 1; result = v13 >> 1; if (v14) { @@ -137,16 +137,18 @@ bool security_id_verify(const struct security_id *id) { log_assert(id); - if(id->header != SECURITY_ID_HEADER) { - log_warning("PCBID header needs to be %02X but was %02X", - SECURITY_ID_HEADER, id->header); + if (id->header != SECURITY_ID_HEADER) { + log_warning( + "PCBID header needs to be %02X but was %02X", + SECURITY_ID_HEADER, + id->header); return false; } uint8_t check = id->checksum; uint8_t need = security_id_checksum_buffer(id->id); - if(check != need) { + if (check != need) { log_warning("PCBID checksum should be %02X got %02X", need, check); return false; } diff --git a/src/main/security/rp2.c b/src/main/security/rp2.c index 4741c9e..51480a6 100644 --- a/src/main/security/rp2.c +++ b/src/main/security/rp2.c @@ -1,28 +1,29 @@ #include -#include "security/rp2.h" #include "security/rp-util.h" +#include "security/rp2.h" #include "security/util.h" #include "util/crypto.h" #include "util/log.h" -static uint8_t security_rp2_signature_scramble_table[16] = {0x0C, - 0x02, - 0x0F, - 0x01, - 0x07, - 0x09, - 0x04, - 0x0A, - 0x00, - 0x0E, - 0x03, - 0x0D, - 0x0B, - 0x05, - 0x08, - 0x06}; +static uint8_t security_rp2_signature_scramble_table[16] = { + 0x0C, + 0x02, + 0x0F, + 0x01, + 0x07, + 0x09, + 0x04, + 0x0A, + 0x00, + 0x0E, + 0x03, + 0x0D, + 0x0B, + 0x05, + 0x08, + 0x06}; void security_rp2_create_signature( const uint8_t *plug_id_enc, const uint8_t *sign_key_packed, uint8_t *out) diff --git a/src/main/security/rp3.c b/src/main/security/rp3.c index 77ecd05..a6dd5bf 100644 --- a/src/main/security/rp3.c +++ b/src/main/security/rp3.c @@ -1,8 +1,8 @@ #include +#include "security/rp-util.h" #include "security/rp2.h" #include "security/rp3.h" -#include "security/rp-util.h" #include "security/util.h" #include "util/crc.h" diff --git a/src/main/util/crypto.c b/src/main/util/crypto.c index 1940404..110dd99 100644 --- a/src/main/util/crypto.c +++ b/src/main/util/crypto.c @@ -150,7 +150,7 @@ void arc4_apply(struct arc4 *arc4, uint8_t *bytes, size_t nbytes) SWAP(arc4->S[arc4->i], arc4->S[arc4->j], tmp); - bytes[i] ^= arc4->S[(uint8_t)(arc4->S[arc4->i] + arc4->S[arc4->j])]; + bytes[i] ^= arc4->S[(uint8_t) (arc4->S[arc4->i] + arc4->S[arc4->j])]; } } diff --git a/src/main/util/iobuf.c b/src/main/util/iobuf.c index 7f90916..c2d0ad1 100644 --- a/src/main/util/iobuf.c +++ b/src/main/util/iobuf.c @@ -1,7 +1,7 @@ #define LOG_MODULE "util-iobuf" -#include "util/hex.h" #include "util/iobuf.h" +#include "util/hex.h" #include "util/log.h" #include "util/mem.h" diff --git a/src/main/util/log.c b/src/main/util/log.c index 2acff45..f1f697e 100644 --- a/src/main/util/log.c +++ b/src/main/util/log.c @@ -59,7 +59,8 @@ static void log_builtin_format( result = str_format( line, sizeof(line), "%c:%s: %s\n", chars[msg_level], module, msg); - // TODO move this up because there is no reason to format and do all the above if disabled + // TODO move this up because there is no reason to format and do all the + // above if disabled if (msg_level <= log_level) { log_writer(log_writer_ctx, line, result); } diff --git a/src/main/util/math.c b/src/main/util/math.c index e06f1e8..7e1d4bb 100644 --- a/src/main/util/math.c +++ b/src/main/util/math.c @@ -1,6 +1,7 @@ #include "util/math.h" -int16_t get_wrapped_delta_s16(int16_t val, int16_t last, int16_t bound) { +int16_t get_wrapped_delta_s16(int16_t val, int16_t last, int16_t bound) +{ int16_t half_point = bound / 2; int16_t delta = val - last; @@ -17,6 +18,7 @@ int16_t get_wrapped_delta_s16(int16_t val, int16_t last, int16_t bound) { return delta; } -int16_t sign_s16(int16_t x) { +int16_t sign_s16(int16_t x) +{ return (x > 0) - (x < 0); } diff --git a/src/main/util/os.c b/src/main/util/os.c index 4609881..c63de00 100644 --- a/src/main/util/os.c +++ b/src/main/util/os.c @@ -13,9 +13,9 @@ #define STATUS_SUCCESS (0x00000000) typedef LONG NTSTATUS, *PNTSTATUS; -typedef NTSTATUS (WINAPI* RtlGetVersion_t)(PRTL_OSVERSIONINFOW); +typedef NTSTATUS(WINAPI *RtlGetVersion_t)(PRTL_OSVERSIONINFOW); -static const char* human_readable_version(DWORD major, DWORD minor) +static const char *human_readable_version(DWORD major, DWORD minor) { if (IsWindowsServer()) { if (major == 5 && minor == 2) { @@ -38,7 +38,7 @@ static const char* human_readable_version(DWORD major, DWORD minor) return "Windows 2000"; } else if (major == 5 && minor == 1) { return "Windows XP"; - } else if (major == 5 && minor == 2 ) { + } else if (major == 5 && minor == 2) { return "Windows XP 64-bit"; } else if (major == 6 && minor == 0) { return "Windows Vista"; @@ -76,13 +76,13 @@ static bool os_get_real_win_version(PRTL_OSVERSIONINFOW version) return rtl_get_version(version) == STATUS_SUCCESS; } -bool os_version_get(struct os_version* version) +bool os_version_get(struct os_version *version) { log_assert(version); RTL_OSVERSIONINFOW rovi; - char* version_str; - const char* readable_version; + char *version_str; + const char *readable_version; memset(&rovi, 0, sizeof(RTL_OSVERSIONINFOW)); rovi.dwOSVersionInfoSize = sizeof(rovi); @@ -96,7 +96,8 @@ bool os_version_get(struct os_version* version) // Contains additional version info, e.g. "Service Pack 3" for XP wstr_narrow(rovi.szCSDVersion, &version_str); - readable_version = human_readable_version(rovi.dwMajorVersion, rovi.dwMinorVersion); + readable_version = + human_readable_version(rovi.dwMajorVersion, rovi.dwMinorVersion); strcpy(version->name, readable_version); version->major = rovi.dwMajorVersion; @@ -119,7 +120,8 @@ void os_version_log() if (!os_version_get(&version)) { log_warning("Could not detect OS version"); } else { - log_info("OS version: %s - %d.%d.%d.%d - %s", + log_info( + "OS version: %s - %d.%d.%d.%d - %s", version.name, version.major, version.minor, diff --git a/src/main/util/os.h b/src/main/util/os.h index 8df0686..b8f1a8c 100644 --- a/src/main/util/os.h +++ b/src/main/util/os.h @@ -13,11 +13,11 @@ struct os_version { /** * Get the (real) version information of the Windows OS. - * + * * @param verison Pointer to version structure. This will be filled in. * @return true on success, false on failure. */ -bool os_version_get(struct os_version* version); +bool os_version_get(struct os_version *version); /** * Log the version information of the current Windows OS. diff --git a/src/main/util/proc.c b/src/main/util/proc.c index 8a3d518..19cec50 100644 --- a/src/main/util/proc.c +++ b/src/main/util/proc.c @@ -7,9 +7,7 @@ void proc_terminate_current_process(uint32_t exit_code) HANDLE hnd; hnd = OpenProcess( - SYNCHRONIZE | PROCESS_TERMINATE, - TRUE, - GetCurrentProcessId()); - + SYNCHRONIZE | PROCESS_TERMINATE, TRUE, GetCurrentProcessId()); + TerminateProcess(hnd, exit_code); } \ No newline at end of file diff --git a/src/main/util/signal.c b/src/main/util/signal.c index a1c5fb2..4c15acd 100644 --- a/src/main/util/signal.c +++ b/src/main/util/signal.c @@ -7,7 +7,7 @@ static signal_shutdown_handler_t shutdown_handler; -static const char* control_code_to_str(DWORD ctrl_code) +static const char *control_code_to_str(DWORD ctrl_code) { switch (ctrl_code) { case CTRL_C_EVENT: @@ -28,7 +28,8 @@ static const char* control_code_to_str(DWORD ctrl_code) static BOOL WINAPI console_ctrl_handler(DWORD dwCtrlType) { - log_misc("Console ctrl handler called: %s", control_code_to_str(dwCtrlType)); + log_misc( + "Console ctrl handler called: %s", control_code_to_str(dwCtrlType)); if (dwCtrlType == CTRL_C_EVENT) { if (shutdown_handler) { @@ -44,20 +45,25 @@ static BOOL WINAPI console_ctrl_handler(DWORD dwCtrlType) return FALSE; } -static LONG WINAPI unhandled_exception_filter(struct _EXCEPTION_POINTERS *ExceptionInfo) +static LONG WINAPI +unhandled_exception_filter(struct _EXCEPTION_POINTERS *ExceptionInfo) { // no exception info provided if (ExceptionInfo != NULL) { - struct _EXCEPTION_RECORD *ExceptionRecord = ExceptionInfo->ExceptionRecord; + struct _EXCEPTION_RECORD *ExceptionRecord = + ExceptionInfo->ExceptionRecord; log_warning( - "Exception raised: %s", + "Exception raised: %s", signal_exception_code_to_str(ExceptionRecord->ExceptionCode)); - struct _EXCEPTION_RECORD *record_cause = ExceptionRecord->ExceptionRecord; + struct _EXCEPTION_RECORD *record_cause = + ExceptionRecord->ExceptionRecord; while (record_cause != NULL) { - log_warning("Caused by: %s", signal_exception_code_to_str(record_cause->ExceptionCode)); + log_warning( + "Caused by: %s", + signal_exception_code_to_str(record_cause->ExceptionCode)); record_cause = record_cause->ExceptionRecord; } @@ -84,7 +90,7 @@ void signal_register_shutdown_handler(signal_shutdown_handler_t handler) log_misc("Registered shutdown handler"); } -const char* signal_exception_code_to_str(DWORD code) +const char *signal_exception_code_to_str(DWORD code) { switch (code) { case EXCEPTION_ACCESS_VIOLATION: diff --git a/src/main/util/signal.h b/src/main/util/signal.h index 7ab4abf..45ae8d8 100644 --- a/src/main/util/signal.h +++ b/src/main/util/signal.h @@ -8,14 +8,14 @@ typedef void (*signal_shutdown_handler_t)(); /** - * Initialize signal and exception handlers. Exceptions and signals, are logged using the logger - * to create visibility. + * Initialize signal and exception handlers. Exceptions and signals, are logged + * using the logger to create visibility. */ void signal_exception_handler_init(); /** - * Register a handler function that gets called when the application is supposed to shut down, - * e.g. on CTRL + C. + * Register a handler function that gets called when the application is supposed + * to shut down, e.g. on CTRL + C. * * @param handler Handler function to register. */ @@ -23,8 +23,8 @@ void signal_register_shutdown_handler(signal_shutdown_handler_t handler); /** * Convert a (windows) exception code to a human readable representation. - * + * * @param code Exception code * @return Human readable representation of the given exception code - */ -const char* signal_exception_code_to_str(DWORD code); \ No newline at end of file + */ +const char *signal_exception_code_to_str(DWORD code); \ No newline at end of file diff --git a/src/main/util/thread.c b/src/main/util/thread.c index 7d19ae5..daa8267 100644 --- a/src/main/util/thread.c +++ b/src/main/util/thread.c @@ -51,15 +51,15 @@ int crt_thread_create( void crt_thread_destroy(int thread_id) { - CloseHandle((HANDLE)(uintptr_t) thread_id); + CloseHandle((HANDLE) (uintptr_t) thread_id); } void crt_thread_join(int thread_id, int *result) { - WaitForSingleObject((HANDLE)(uintptr_t) thread_id, INFINITE); + WaitForSingleObject((HANDLE) (uintptr_t) thread_id, INFINITE); if (result) { - GetExitCodeThread((HANDLE)(uintptr_t) thread_id, (DWORD *) result); + GetExitCodeThread((HANDLE) (uintptr_t) thread_id, (DWORD *) result); } } diff --git a/src/main/vigem-iidxio/cab-16seg-sequencer.c b/src/main/vigem-iidxio/cab-16seg-sequencer.c index 0eff372..01ea12b 100644 --- a/src/main/vigem-iidxio/cab-16seg-sequencer.c +++ b/src/main/vigem-iidxio/cab-16seg-sequencer.c @@ -19,7 +19,7 @@ static size_t _text_len; static uint32_t _scroll_cycle_time_ms; -static void _create_display_string_with_wrap_around(char* out_16seg) +static void _create_display_string_with_wrap_around(char *out_16seg) { size_t cur_text_pos = _text_pos; @@ -27,13 +27,14 @@ static void _create_display_string_with_wrap_around(char* out_16seg) if (cur_text_pos >= _text_len) { cur_text_pos = 0; } - + out_16seg[i] = _text[cur_text_pos]; cur_text_pos++; } } -void vigem_iidxio_cab_16seg_sequencer_init(const char* text, uint32_t scroll_cycle_time_ms) +void vigem_iidxio_cab_16seg_sequencer_init( + const char *text, uint32_t scroll_cycle_time_ms) { log_assert(text); @@ -52,11 +53,14 @@ void vigem_iidxio_cab_16seg_sequencer_init(const char* text, uint32_t scroll_cyc _enabled = true; if (_enabled) { - log_info("Initialized, cycle time %d ms, text \"%s\"", _scroll_cycle_time_ms, _text); + log_info( + "Initialized, cycle time %d ms, text \"%s\"", + _scroll_cycle_time_ms, + _text); } } -void vigem_iidxio_cab_16seg_sequencer_update(char* out_16seg) +void vigem_iidxio_cab_16seg_sequencer_update(char *out_16seg) { log_assert(out_16seg); @@ -67,12 +71,13 @@ void vigem_iidxio_cab_16seg_sequencer_update(char* out_16seg) } uint64_t counter_now = time_get_counter(); - uint32_t cycle_time_elapsed_ms = time_get_elapsed_ms(counter_now - _time_counter); + uint32_t cycle_time_elapsed_ms = + time_get_elapsed_ms(counter_now - _time_counter); if (cycle_time_elapsed_ms >= _scroll_cycle_time_ms) { _time_counter = counter_now; _text_pos++; - + if (_text_pos >= _text_len) { _text_pos = 0; } diff --git a/src/main/vigem-iidxio/cab-16seg-sequencer.h b/src/main/vigem-iidxio/cab-16seg-sequencer.h index f3bdd8f..05e3205 100644 --- a/src/main/vigem-iidxio/cab-16seg-sequencer.h +++ b/src/main/vigem-iidxio/cab-16seg-sequencer.h @@ -1,8 +1,9 @@ #ifndef VIGEM_IIDXIO_CAB_16SEG_SEQUENCER_H #define VIGEM_IIDXIO_CAB_16SEG_SEQUENCER_H -void vigem_iidxio_cab_16seg_sequencer_init(const char* text, uint32_t scroll_cycle_time_ms); +void vigem_iidxio_cab_16seg_sequencer_init( + const char *text, uint32_t scroll_cycle_time_ms); -void vigem_iidxio_cab_16seg_sequencer_update(char* out_16seg); +void vigem_iidxio_cab_16seg_sequencer_update(char *out_16seg); #endif \ No newline at end of file diff --git a/src/main/vigem-iidxio/cab-light-sequencer.c b/src/main/vigem-iidxio/cab-light-sequencer.c index ff18cfe..95214f9 100644 --- a/src/main/vigem-iidxio/cab-light-sequencer.c +++ b/src/main/vigem-iidxio/cab-light-sequencer.c @@ -1,8 +1,8 @@ #define LOG_MODULE "vigem-iidx-cab-light-sequencer" +#include #include #include -#include #include "vigem-iidxio/cab-light-sequencer.h" @@ -10,7 +10,7 @@ #include "util/math.h" #include "util/time.h" -static const uint32_t _SEQ_CYCLE_TIME_MS = 2000; +static const uint32_t _SEQ_CYCLE_TIME_MS = 2000; static enum vigem_iidxio_cab_light_sequencer_mode _light_seq_mode; @@ -20,10 +20,11 @@ static uint64_t _time_counter; static uint8_t _tt_prev[2]; static int32_t _tt_neon_on_state; -void _update_neons_seq_flash(bool* out_neon) +void _update_neons_seq_flash(bool *out_neon) { uint64_t counter_now = time_get_counter(); - uint32_t cycle_time_elapsed_ms = time_get_elapsed_ms(counter_now - _time_counter); + uint32_t cycle_time_elapsed_ms = + time_get_elapsed_ms(counter_now - _time_counter); if (cycle_time_elapsed_ms < _SEQ_CYCLE_TIME_MS / 2) { *out_neon = false; @@ -36,7 +37,7 @@ void _update_neons_seq_flash(bool* out_neon) } } -void _update_neons_flash_tt_input(uint8_t tt_p1, uint8_t tt_p2, bool* out_neon) +void _update_neons_flash_tt_input(uint8_t tt_p1, uint8_t tt_p2, bool *out_neon) { if (_first_update) { _tt_prev[0] = tt_p1; @@ -45,7 +46,7 @@ void _update_neons_flash_tt_input(uint8_t tt_p1, uint8_t tt_p2, bool* out_neon) } int8_t delta[2]; - + delta[0] = tt_p1 - _tt_prev[0]; delta[1] = tt_p2 - _tt_prev[1]; @@ -73,11 +74,11 @@ void _update_neons_flash_tt_input(uint8_t tt_p1, uint8_t tt_p2, bool* out_neon) } _tt_prev[0] = tt_p1; - _tt_prev[1] = tt_p2; + _tt_prev[1] = tt_p2; } void vigem_iidxio_cab_light_sequencer_init( - enum vigem_iidxio_cab_light_sequencer_mode light_seq_mode) + enum vigem_iidxio_cab_light_sequencer_mode light_seq_mode) { _time_counter = time_get_counter(); _light_seq_mode = light_seq_mode; @@ -90,11 +91,11 @@ void vigem_iidxio_cab_light_sequencer_init( } void vigem_iidxio_cab_light_sequencer_update( - uint16_t keys, - uint8_t tt_p1, - uint8_t tt_p2, - bool* out_neon, - uint8_t* out_spots) + uint16_t keys, + uint8_t tt_p1, + uint8_t tt_p2, + bool *out_neon, + uint8_t *out_spots) { log_assert(out_neon); log_assert(out_spots); diff --git a/src/main/vigem-iidxio/cab-light-sequencer.h b/src/main/vigem-iidxio/cab-light-sequencer.h index 66b3060..f69ca1d 100644 --- a/src/main/vigem-iidxio/cab-light-sequencer.h +++ b/src/main/vigem-iidxio/cab-light-sequencer.h @@ -11,13 +11,13 @@ enum vigem_iidxio_cab_light_sequencer_mode { }; void vigem_iidxio_cab_light_sequencer_init( - enum vigem_iidxio_cab_light_sequencer_mode light_seq_mode); + enum vigem_iidxio_cab_light_sequencer_mode light_seq_mode); void vigem_iidxio_cab_light_sequencer_update( - uint16_t keys, - uint8_t tt_p1, - uint8_t tt_p2, - bool* out_neon, - uint8_t* out_spots); + uint16_t keys, + uint8_t tt_p1, + uint8_t tt_p2, + bool *out_neon, + uint8_t *out_spots); #endif \ No newline at end of file diff --git a/src/main/vigem-iidxio/config.c b/src/main/vigem-iidxio/config.c index 5e05acd..40eeae5 100644 --- a/src/main/vigem-iidxio/config.c +++ b/src/main/vigem-iidxio/config.c @@ -5,15 +5,23 @@ #include "util/log.h" -#define VIGEM_IIDXIO_CONFIG_TT_ANALOG_RELATIVE_KEY "vigem.iidxio.tt.anlog.relative" -#define VIGEM_IIDXIO_CONFIG_TT_ANALOG_RELATIVE_SENSITIVITY_KEY "vigem.iidxio.tt.anlog.relative_sensitivity" -#define VIGEM_IIDXIO_CONFIG_TT_BUTTON_DEBOUNCE_KEY "vigem.iidxio.tt.button.debounce" -#define VIGEM_IIDXIO_CONFIG_TT_BUTTON_THRESHOLD_KEY "vigem.iidxio.tt.button.threshold" +#define VIGEM_IIDXIO_CONFIG_TT_ANALOG_RELATIVE_KEY \ + "vigem.iidxio.tt.anlog.relative" +#define VIGEM_IIDXIO_CONFIG_TT_ANALOG_RELATIVE_SENSITIVITY_KEY \ + "vigem.iidxio.tt.anlog.relative_sensitivity" +#define VIGEM_IIDXIO_CONFIG_TT_BUTTON_DEBOUNCE_KEY \ + "vigem.iidxio.tt.button.debounce" +#define VIGEM_IIDXIO_CONFIG_TT_BUTTON_THRESHOLD_KEY \ + "vigem.iidxio.tt.button.threshold" #define VIGEM_IIDXIO_CONFIG_TT_DEBUG_OUTPUT_KEY "vigem.iidxio.tt.debug_output" -#define VIGEM_IIDXIO_CONFIG_CAB_LIGHT_ENABLE_KEYLIGHT_KEY "vigem.iidxio.cab_light.enable_keylight" -#define VIGEM_IIDXIO_CONFIG_CAB_LIGHT_LIGHT_MODE_KEY "vigem.iidxio.cab_light.light_mode" -#define VIGEM_IIDXIO_CONFIG_CAB_LIGHT_TEXT_16SEG_KEY "vigem.iidxio.cab_light.text_16seg" -#define VIGEM_IIDXIO_CONFIG_CAB_LIGHT_TEXT_SCROLL_CYCLE_TIME_MS_KEY "vigem.iidxio.cab_light.text_scroll_cycle_time_ms" +#define VIGEM_IIDXIO_CONFIG_CAB_LIGHT_ENABLE_KEYLIGHT_KEY \ + "vigem.iidxio.cab_light.enable_keylight" +#define VIGEM_IIDXIO_CONFIG_CAB_LIGHT_LIGHT_MODE_KEY \ + "vigem.iidxio.cab_light.light_mode" +#define VIGEM_IIDXIO_CONFIG_CAB_LIGHT_TEXT_16SEG_KEY \ + "vigem.iidxio.cab_light.text_16seg" +#define VIGEM_IIDXIO_CONFIG_CAB_LIGHT_TEXT_SCROLL_CYCLE_TIME_MS_KEY \ + "vigem.iidxio.cab_light.text_scroll_cycle_time_ms" #define VIGEM_IIDXIO_CONFIG_DEFAULT_TT_ANALOG_RELATIVE_VALUE false #define VIGEM_IIDXIO_CONFIG_DEFAULT_TT_ANALOG_RELATIVE_SENSITIVITY_VALUE 1024 @@ -23,7 +31,8 @@ #define VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_ENABLE_KEYLIGHT_VALUE true #define VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_LIGHT_MODE_VALUE 0 #define VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_TEXT_16SEG_VALUE "" -#define VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_TEXT_SCROLL_CYCLE_TIME_MS_VALUE 500 +#define VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_TEXT_SCROLL_CYCLE_TIME_MS_VALUE \ + 500 static void _vigem_iidxio_config_init(struct cconfig *config) { @@ -37,28 +46,33 @@ static void _vigem_iidxio_config_init(struct cconfig *config) config, VIGEM_IIDXIO_CONFIG_TT_ANALOG_RELATIVE_SENSITIVITY_KEY, VIGEM_IIDXIO_CONFIG_DEFAULT_TT_ANALOG_RELATIVE_SENSITIVITY_VALUE, - "Sensitivity value for relative mode (1 to 32767). Tweak if you are having issues with " + "Sensitivity value for relative mode (1 to 32767). Tweak if you are " + "having issues with " "jittering/misfiring/unresponsiveness"); cconfig_util_set_int( config, VIGEM_IIDXIO_CONFIG_TT_BUTTON_DEBOUNCE_KEY, VIGEM_IIDXIO_CONFIG_DEFAULT_TT_BUTTON_DEBOUNCE_VALUE, - "Button turntable: \"debounce\" value (1 to 50, recommend 20). Tweak if you are having "\ + "Button turntable: \"debounce\" value (1 to 50, recommend 20). Tweak " + "if you are having " "issues with TT button misfiring/unresponsiveness"); cconfig_util_set_int( config, VIGEM_IIDXIO_CONFIG_TT_BUTTON_THRESHOLD_KEY, VIGEM_IIDXIO_CONFIG_DEFAULT_TT_BUTTON_THRESHOLD_VALUE, - "Button turntable: minimum ticks required within (debounce * 2) ms to register movement " - "(1 to 4, recommend 2). Tweak if you button input is too (un-) responsive"); + "Button turntable: minimum ticks required within (debounce * 2) ms to " + "register movement " + "(1 to 4, recommend 2). Tweak if you button input is too (un-) " + "responsive"); cconfig_util_set_bool( config, VIGEM_IIDXIO_CONFIG_TT_DEBUG_OUTPUT_KEY, VIGEM_IIDXIO_CONFIG_DEFAULT_TT_DEBUG_OUTPUT_VALUE, - "Print verbose debug output to the console for debugging turntable sensitivity issues"); + "Print verbose debug output to the console for debugging turntable " + "sensitivity issues"); cconfig_util_set_bool( config, @@ -70,19 +84,22 @@ static void _vigem_iidxio_config_init(struct cconfig *config) config, VIGEM_IIDXIO_CONFIG_CAB_LIGHT_LIGHT_MODE_KEY, VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_LIGHT_MODE_VALUE, - "Different cabinet light modes: 0 = off, 1 = neons sequence, 2 = neons flash on TT spin"); + "Different cabinet light modes: 0 = off, 1 = neons sequence, 2 = neons " + "flash on TT spin"); cconfig_util_set_str( config, VIGEM_IIDXIO_CONFIG_CAB_LIGHT_TEXT_16SEG_KEY, VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_TEXT_16SEG_VALUE, - "Display text on 16seg. If text exceeds 9 char display limit, it will scroll + cycle"); + "Display text on 16seg. If text exceeds 9 char display limit, it will " + "scroll + cycle"); cconfig_util_set_int( config, VIGEM_IIDXIO_CONFIG_CAB_LIGHT_TEXT_SCROLL_CYCLE_TIME_MS_KEY, VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_TEXT_SCROLL_CYCLE_TIME_MS_VALUE, - "Cycle time/scroll speed for text exceeding 16seg display length (9) to scroll from right"); + "Cycle time/scroll speed for text exceeding 16seg display length (9) " + "to scroll from right"); } static void _vigem_iidxio_config_get( @@ -148,7 +165,6 @@ static void _vigem_iidxio_config_get( VIGEM_IIDXIO_CONFIG_DEFAULT_TT_DEBUG_OUTPUT_VALUE); } - if (!cconfig_util_get_bool( config, VIGEM_IIDXIO_CONFIG_CAB_LIGHT_ENABLE_KEYLIGHT_KEY, diff --git a/src/main/vigem-iidxio/config.h b/src/main/vigem-iidxio/config.h index f94afbd..f4f0446 100644 --- a/src/main/vigem-iidxio/config.h +++ b/src/main/vigem-iidxio/config.h @@ -19,7 +19,7 @@ struct vigem_iidxio_config { bool debug_output; } tt; - + struct cab_light { bool enable_keylight; int32_t light_mode; diff --git a/src/main/vigem-iidxio/main.c b/src/main/vigem-iidxio/main.c index 54ebc54..3527545 100644 --- a/src/main/vigem-iidxio/main.c +++ b/src/main/vigem-iidxio/main.c @@ -33,7 +33,8 @@ static int16_t _convert_analog_to_s16(uint8_t val) return (int64_t) val * 256; } -static int16_t _filter_floor(int32_t value, int16_t floor) { +static int16_t _filter_floor(int32_t value, int16_t floor) +{ if (abs(value) < floor) { return 0; } @@ -93,11 +94,11 @@ static uint16_t _check_assign_key(uint16_t input, size_t idx_in, size_t bit_out) } static int32_t _handle_turntable_analog( - const struct vigem_iidxio_config* config, - uint8_t tt_cur, - uint8_t tt_last, - int32_t tt_state, - XUSB_REPORT *pad_state) + const struct vigem_iidxio_config *config, + uint8_t tt_cur, + uint8_t tt_last, + int32_t tt_state, + XUSB_REPORT *pad_state) { int32_t state = tt_state; @@ -105,7 +106,8 @@ static int32_t _handle_turntable_analog( state = _convert_relative_analog( tt_cur, tt_last, state, config->tt.analog.relative_sensitivity); - pad_state->sThumbLX = _filter_floor(state, config->tt.analog.relative_sensitivity / 2); + pad_state->sThumbLX = + _filter_floor(state, config->tt.analog.relative_sensitivity / 2); } else { pad_state->sThumbLX = _convert_analog_to_s16(tt_cur); } @@ -114,11 +116,11 @@ static int32_t _handle_turntable_analog( } static int16_t _handle_turntable_as_button( - const struct vigem_iidxio_config* config, - uint8_t tt_cur, - uint8_t tt_last, - int16_t tt_state, - XUSB_REPORT *pad_state) + const struct vigem_iidxio_config *config, + uint8_t tt_cur, + uint8_t tt_last, + int16_t tt_state, + XUSB_REPORT *pad_state) { const uint8_t btn_inc = config->tt.button.debounce; const uint16_t btn_threshhold = btn_inc * config->tt.button.threshold; @@ -135,7 +137,8 @@ static int16_t _handle_turntable_as_button( // Reset state to avoid lag with state having to decrease from high values if (delta > 0 && delta >= config->tt.button.threshold && state < 0) { state = 0; - } else if (delta < 0 && abs(delta) >= config->tt.button.threshold && state > 0) { + } else if ( + delta < 0 && abs(delta) >= config->tt.button.threshold && state > 0) { state = 0; } @@ -146,9 +149,9 @@ static int16_t _handle_turntable_as_button( state -= btn_inc; } - // With each update, automatically counter the player's TT movement to turn the state - // back to 0, e.g. player moves TT -> state += 20. with no additional movement, neutral state - // (0) is back in 20 ticks + // With each update, automatically counter the player's TT movement to turn + // the state back to 0, e.g. player moves TT -> state += 20. with no + // additional movement, neutral state (0) is back in 20 ticks if (state > 0) { state--; } else if (state < 0) { @@ -165,9 +168,7 @@ static int16_t _handle_turntable_as_button( } static void _handle_turntable( - const struct vigem_iidxio_config* config, - uint8_t* tt, - XUSB_REPORT *state) + const struct vigem_iidxio_config *config, uint8_t *tt, XUSB_REPORT *state) { for (uint8_t i = 0; i < TURNTABLE_NUM; i++) { if (config->tt.debug_output) { @@ -183,66 +184,68 @@ static void _handle_turntable( _tt_last_raw[i] = tt[i]; if (config->tt.debug_output) { - printf("state_btn %d, state_rel_analog %d\n", - _tt_state_for_btn[i], _tt_state_for_analog[i]); + printf( + "state_btn %d, state_rel_analog %d\n", + _tt_state_for_btn[i], + _tt_state_for_analog[i]); } } } static void _handle_buttons_14keys(uint16_t keys, XUSB_REPORT *state) { - state[0].wButtons |= _check_assign_key( - keys, IIDX_IO_KEY_P1_1, XUSB_GAMEPAD_A); - state[0].wButtons |= _check_assign_key( - keys, IIDX_IO_KEY_P1_2, XUSB_GAMEPAD_B); - state[0].wButtons |= _check_assign_key( - keys, IIDX_IO_KEY_P1_3, XUSB_GAMEPAD_X); - state[0].wButtons |= _check_assign_key( - keys, IIDX_IO_KEY_P1_4, XUSB_GAMEPAD_Y); - state[0].wButtons |= _check_assign_key( - keys, IIDX_IO_KEY_P1_5, XUSB_GAMEPAD_LEFT_SHOULDER); - state[0].wButtons |= _check_assign_key( - keys, IIDX_IO_KEY_P1_6, XUSB_GAMEPAD_RIGHT_SHOULDER); - state[0].wButtons |= _check_assign_key( - keys, IIDX_IO_KEY_P1_7, XUSB_GAMEPAD_BACK); + state[0].wButtons |= + _check_assign_key(keys, IIDX_IO_KEY_P1_1, XUSB_GAMEPAD_A); + state[0].wButtons |= + _check_assign_key(keys, IIDX_IO_KEY_P1_2, XUSB_GAMEPAD_B); + state[0].wButtons |= + _check_assign_key(keys, IIDX_IO_KEY_P1_3, XUSB_GAMEPAD_X); + state[0].wButtons |= + _check_assign_key(keys, IIDX_IO_KEY_P1_4, XUSB_GAMEPAD_Y); + state[0].wButtons |= + _check_assign_key(keys, IIDX_IO_KEY_P1_5, XUSB_GAMEPAD_LEFT_SHOULDER); + state[0].wButtons |= + _check_assign_key(keys, IIDX_IO_KEY_P1_6, XUSB_GAMEPAD_RIGHT_SHOULDER); + state[0].wButtons |= + _check_assign_key(keys, IIDX_IO_KEY_P1_7, XUSB_GAMEPAD_BACK); - state[1].wButtons |= _check_assign_key( - keys, IIDX_IO_KEY_P2_1, XUSB_GAMEPAD_A); - state[1].wButtons |= _check_assign_key( - keys, IIDX_IO_KEY_P2_2, XUSB_GAMEPAD_B); - state[1].wButtons |= _check_assign_key( - keys, IIDX_IO_KEY_P2_3, XUSB_GAMEPAD_X); - state[1].wButtons |= _check_assign_key( - keys, IIDX_IO_KEY_P2_4, XUSB_GAMEPAD_Y); - state[1].wButtons |= _check_assign_key( - keys, IIDX_IO_KEY_P2_5, XUSB_GAMEPAD_LEFT_SHOULDER); - state[1].wButtons |= _check_assign_key( - keys, IIDX_IO_KEY_P2_6, XUSB_GAMEPAD_RIGHT_SHOULDER); - state[1].wButtons |= _check_assign_key( - keys, IIDX_IO_KEY_P2_7, XUSB_GAMEPAD_BACK); + state[1].wButtons |= + _check_assign_key(keys, IIDX_IO_KEY_P2_1, XUSB_GAMEPAD_A); + state[1].wButtons |= + _check_assign_key(keys, IIDX_IO_KEY_P2_2, XUSB_GAMEPAD_B); + state[1].wButtons |= + _check_assign_key(keys, IIDX_IO_KEY_P2_3, XUSB_GAMEPAD_X); + state[1].wButtons |= + _check_assign_key(keys, IIDX_IO_KEY_P2_4, XUSB_GAMEPAD_Y); + state[1].wButtons |= + _check_assign_key(keys, IIDX_IO_KEY_P2_5, XUSB_GAMEPAD_LEFT_SHOULDER); + state[1].wButtons |= + _check_assign_key(keys, IIDX_IO_KEY_P2_6, XUSB_GAMEPAD_RIGHT_SHOULDER); + state[1].wButtons |= + _check_assign_key(keys, IIDX_IO_KEY_P2_7, XUSB_GAMEPAD_BACK); } static void _handle_buttons_panel(uint8_t panel, XUSB_REPORT *state) { state[0].wButtons |= _check_assign_key( - panel, IIDX_IO_PANEL_LIGHT_P1_START, XUSB_GAMEPAD_START); + panel, IIDX_IO_PANEL_LIGHT_P1_START, XUSB_GAMEPAD_START); state[1].wButtons |= _check_assign_key( - panel, IIDX_IO_PANEL_LIGHT_P2_START, XUSB_GAMEPAD_START); + panel, IIDX_IO_PANEL_LIGHT_P2_START, XUSB_GAMEPAD_START); - state[2].wButtons |= _check_assign_key( - panel, IIDX_IO_PANEL_LIGHT_VEFX, XUSB_GAMEPAD_B); - state[2].wButtons |= _check_assign_key( - panel, IIDX_IO_PANEL_LIGHT_EFFECT, XUSB_GAMEPAD_A); + state[2].wButtons |= + _check_assign_key(panel, IIDX_IO_PANEL_LIGHT_VEFX, XUSB_GAMEPAD_B); + state[2].wButtons |= + _check_assign_key(panel, IIDX_IO_PANEL_LIGHT_EFFECT, XUSB_GAMEPAD_A); } static void _handle_buttons_system(uint8_t system, XUSB_REPORT *state) { - state[2].wButtons |= _check_assign_key( - system, IIDX_IO_SYS_TEST, XUSB_GAMEPAD_X); - state[2].wButtons |= _check_assign_key( - system, IIDX_IO_SYS_SERVICE, XUSB_GAMEPAD_Y); - state[2].wButtons |= _check_assign_key( - system, IIDX_IO_SYS_COIN, XUSB_GAMEPAD_START); + state[2].wButtons |= + _check_assign_key(system, IIDX_IO_SYS_TEST, XUSB_GAMEPAD_X); + state[2].wButtons |= + _check_assign_key(system, IIDX_IO_SYS_SERVICE, XUSB_GAMEPAD_Y); + state[2].wButtons |= + _check_assign_key(system, IIDX_IO_SYS_COIN, XUSB_GAMEPAD_START); } static void _all_lights_off() @@ -286,7 +289,7 @@ int main(int argc, char **argv) bool failed; failed = false; - + for (uint8_t i = 0; i < JOYSTICKS_NUM; i++) { pad[i] = vigem_helper_add_pad(client); @@ -314,14 +317,15 @@ int main(int argc, char **argv) if (config.cab_light.text_16seg[0] != '\0') { vigem_iidxio_cab_16seg_sequencer_init( - config.cab_light.text_16seg, config.cab_light.text_scroll_cycle_time_ms); + config.cab_light.text_16seg, + config.cab_light.text_scroll_cycle_time_ms); } while (loop) { for (uint8_t i = 0; i < JOYSTICKS_NUM; i++) { memset(&state[i], 0, sizeof(state[i])); } - + if (!iidx_io_ep2_recv()) { log_warning("iidxio receiving failed"); break; @@ -344,7 +348,7 @@ int main(int argc, char **argv) for (uint8_t i = 0; i < TURNTABLE_NUM; i++) { turntable[i] = iidx_io_ep2_get_turntable(i); } - + _handle_turntable(&config, turntable, state); // Pad update @@ -354,7 +358,7 @@ int main(int argc, char **argv) } // ----------------------------------------------------------------------------- - + // Light related outputs if (config.cab_light.enable_keylight) { @@ -370,11 +374,7 @@ int main(int argc, char **argv) spots = 0; vigem_iidxio_cab_light_sequencer_update( - keys, - turntable[0], - turntable[1], - &neon, - &spots); + keys, turntable[0], turntable[1], &neon, &spots); iidx_io_ep1_set_top_neons(neon); iidx_io_ep1_set_top_lamps(spots); @@ -391,9 +391,9 @@ int main(int argc, char **argv) log_warning("iidxio sending failed"); break; } - + if (_check_key(system, IIDX_IO_SYS_TEST) && - _check_key(system, IIDX_IO_SYS_SERVICE)) { + _check_key(system, IIDX_IO_SYS_SERVICE)) { log_info("Test + service pressed, exiting..."); loop = false; } diff --git a/src/main/vigem-sdvxio/main.c b/src/main/vigem-sdvxio/main.c index 261ac61..cf4b4e2 100644 --- a/src/main/vigem-sdvxio/main.c +++ b/src/main/vigem-sdvxio/main.c @@ -20,10 +20,11 @@ int16_t convert_analog_to_s16(uint16_t val) { // val is 10 bit - return (int64_t)(val * 64); + return (int64_t) (val * 64); } -int16_t filter_floor(int32_t value, int16_t floor) { +int16_t filter_floor(int32_t value, int16_t floor) +{ if (abs(value) < floor) { return 0; } @@ -54,11 +55,11 @@ int32_t convert_relative_analog( // so that we can overshoot an i16 by up to 1.5x // this allows users to stay at the min/max stick positions // without perfect knob turning - if (result > INT16_MAX*1.5) { - result = INT16_MAX*1.5; + if (result > INT16_MAX * 1.5) { + result = INT16_MAX * 1.5; } - if (result < INT16_MIN*1.5) { - result = INT16_MIN*1.5; + if (result < INT16_MIN * 1.5) { + result = INT16_MIN * 1.5; } return result; @@ -143,7 +144,8 @@ int main(int argc, char **argv) return -1; } - sdvx_io_set_amp_volume(config.amp_volume, config.amp_volume, config.amp_volume); + sdvx_io_set_amp_volume( + config.amp_volume, config.amp_volume, config.amp_volume); PVIGEM_CLIENT client = vigem_helper_setup(); @@ -186,11 +188,15 @@ int main(int argc, char **argv) memset(&state, 0, sizeof(state)); if (config.relative_analog) { - buffered_vol[0] = convert_relative_analog(vol[0], last_vol[0], buffered_vol[0], ANALOG_FIXED_SENSITIVITY); - buffered_vol[1] = convert_relative_analog(vol[1], last_vol[1], buffered_vol[1], ANALOG_FIXED_SENSITIVITY); + buffered_vol[0] = convert_relative_analog( + vol[0], last_vol[0], buffered_vol[0], ANALOG_FIXED_SENSITIVITY); + buffered_vol[1] = convert_relative_analog( + vol[1], last_vol[1], buffered_vol[1], ANALOG_FIXED_SENSITIVITY); - state.sThumbLX = filter_floor(buffered_vol[0], ANALOG_FIXED_SENSITIVITY/2); - state.sThumbLY = filter_floor(buffered_vol[1], ANALOG_FIXED_SENSITIVITY/2); + state.sThumbLX = + filter_floor(buffered_vol[0], ANALOG_FIXED_SENSITIVITY / 2); + state.sThumbLY = + filter_floor(buffered_vol[1], ANALOG_FIXED_SENSITIVITY / 2); last_vol[0] = vol[0]; last_vol[1] = vol[1]; diff --git a/src/main/vigemstub/helper.c b/src/main/vigemstub/helper.c index 47ba018..4aeb519 100644 --- a/src/main/vigemstub/helper.c +++ b/src/main/vigemstub/helper.c @@ -19,7 +19,8 @@ PVIGEM_CLIENT vigem_helper_setup(void) VIGEM_ERROR retval = vigem_connect(client); if (!VIGEM_SUCCESS(retval)) { - log_warning("ViGEm Bus connection failed with error code: 0x%x\n", retval); + log_warning( + "ViGEm Bus connection failed with error code: 0x%x\n", retval); return NULL; } diff --git a/src/test/security/security-rp2-test.c b/src/test/security/security-rp2-test.c index 746938b..36c3180 100644 --- a/src/test/security/security-rp2-test.c +++ b/src/test/security/security-rp2-test.c @@ -1,6 +1,6 @@ #include "security/id.h" -#include "security/rp2.h" #include "security/rp-sign-key.h" +#include "security/rp2.h" #include "test/check.h" #include "test/test.h" diff --git a/src/test/security/security-rp3-test.c b/src/test/security/security-rp3-test.c index 6f3415a..b2ac16f 100644 --- a/src/test/security/security-rp3-test.c +++ b/src/test/security/security-rp3-test.c @@ -16,50 +16,52 @@ static const struct security_mcode black_plug_mcode_jubeat = { static const struct security_rp3_eeprom exp_jubeat_black_eeprom = { .signature = {0x73, 0x66, 0xBA, 0xBD, 0xDE, 0x36}, .packed_payload = {0xE7, 0x88, 0x52, 0x94, 0x1A, 0x8A}, - .zeros = {0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00}, + .zeros = + {0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00}, .crc = 0xA3, }; static const struct security_rp3_eeprom exp_jubeat_white_eeprom = { .signature = {0x43, 0x17, 0xB4, 0x2A, 0x3E, 0x87}, .packed_payload = {0x20, 0x08, 0x82, 0x20, 0x08, 0x82}, - .zeros = {0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00}, + .zeros = + {0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00}, .crc = 0x94, };