From e59343a7fb864ee0eb0914697e57c986d5dfce2d Mon Sep 17 00:00:00 2001 From: icex2 Date: Mon, 20 Mar 2023 23:52:43 +0100 Subject: [PATCH 01/38] feat(iidx19): Add back btools monitor check for iidxhook5 Provide an option for non final lincle revisions and if the "modern" monitor check is not delivering stable results on the final lincle revision, e.g. using the original "pendual lcd" monitor. --- dist/iidx/iidxhook-19.conf | 3 +++ src/main/iidxhook-util/chart-patch.h | 4 ++-- src/main/iidxhook3/dllmain.c | 4 ++-- src/main/iidxhook4-cn/dllmain.c | 4 ++-- src/main/iidxhook4/dllmain.c | 4 ++-- src/main/iidxhook5/dllmain.c | 19 +++++++++++++++++++ 6 files changed, 30 insertions(+), 8 deletions(-) diff --git a/dist/iidx/iidxhook-19.conf b/dist/iidx/iidxhook-19.conf index 3f07d94..51a5995 100755 --- a/dist/iidx/iidxhook-19.conf +++ b/dist/iidx/iidxhook-19.conf @@ -7,6 +7,9 @@ gfx.framed=false # Software limit the frame rate of the rendering loop in hz, e.g. 60 or 59.95 (0.0 = no software limit) gfx.frame_rate_limit=0.0 +# Enable/disable software monitor check/auto timebase or set a pre-determined refresh value. -1 disables this feature. 0 enables auto detecting the current refresh rate on startup. Setting any positive value > 0 allows you to set a pre-determined refresh rate (e.g. retrieved from the monitor check on newer IIDX games). Either the auto detected value or pre-determined value is used to patch any chart files in-memory to fix song synchronization issues. Requires constant refresh rate!!! +gfx.monitor_check=-1.000000 + # Patch the GPU device ID detection (leave empty to disable), format XXXX:YYYY, two 4 digit hex numbers (vid:pid). Examples: 1002:7146 (RV515, Radeon X1300), 1002:95C5 (RV620 LE, Radeon HD3450) gfx.pci_id=1002:7146 diff --git a/src/main/iidxhook-util/chart-patch.h b/src/main/iidxhook-util/chart-patch.h index 84e009f..a89aafb 100644 --- a/src/main/iidxhook-util/chart-patch.h +++ b/src/main/iidxhook-util/chart-patch.h @@ -7,8 +7,8 @@ /* 9th to DD */ #define IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_9_TO_13 59.95 -/* GOLD to Resort Anthem */ -#define IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_18_VGA 60.05 +/* GOLD to Lincle */ +#define IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_19_VGA 60.05 /** * Install hooks to intercept chart file loading. This allows you to patch diff --git a/src/main/iidxhook3/dllmain.c b/src/main/iidxhook3/dllmain.c index 45697bd..1563161 100644 --- a/src/main/iidxhook3/dllmain.c +++ b/src/main/iidxhook3/dllmain.c @@ -95,14 +95,14 @@ iidxhook3_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) d3d9_config.iidx09_to_19_monitor_check_cb = iidxhook_util_chart_patch_set_refresh_rate; iidxhook_util_chart_patch_init( - IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_18_VGA); + IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_19_VGA); } else if (config_gfx->monitor_check > 0) { log_info( "Manual monitor check, resulting refresh rate: %f", config_gfx->monitor_check); iidxhook_util_chart_patch_init( - IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_18_VGA); + IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_19_VGA); iidxhook_util_chart_patch_set_refresh_rate(config_gfx->monitor_check); } diff --git a/src/main/iidxhook4-cn/dllmain.c b/src/main/iidxhook4-cn/dllmain.c index d8dc096..9475342 100644 --- a/src/main/iidxhook4-cn/dllmain.c +++ b/src/main/iidxhook4-cn/dllmain.c @@ -90,14 +90,14 @@ iidxhook4_cn_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) d3d9_config.iidx09_to_19_monitor_check_cb = iidxhook_util_chart_patch_set_refresh_rate; iidxhook_util_chart_patch_init( - IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_18_VGA); + IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_19_VGA); } else if (config_gfx->monitor_check > 0) { log_info( "Manual monitor check, resulting refresh rate: %f", config_gfx->monitor_check); iidxhook_util_chart_patch_init( - IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_18_VGA); + IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_19_VGA); iidxhook_util_chart_patch_set_refresh_rate(config_gfx->monitor_check); } diff --git a/src/main/iidxhook4/dllmain.c b/src/main/iidxhook4/dllmain.c index 8c291d8..e047fd7 100644 --- a/src/main/iidxhook4/dllmain.c +++ b/src/main/iidxhook4/dllmain.c @@ -80,14 +80,14 @@ iidxhook4_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) d3d9_config.iidx09_to_19_monitor_check_cb = iidxhook_util_chart_patch_set_refresh_rate; iidxhook_util_chart_patch_init( - IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_18_VGA); + IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_19_VGA); } else if (config_gfx->monitor_check > 0) { log_info( "Manual monitor check, resulting refresh rate: %f", config_gfx->monitor_check); iidxhook_util_chart_patch_init( - IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_18_VGA); + IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_19_VGA); iidxhook_util_chart_patch_set_refresh_rate(config_gfx->monitor_check); } diff --git a/src/main/iidxhook5/dllmain.c b/src/main/iidxhook5/dllmain.c index a533d34..e13b545 100644 --- a/src/main/iidxhook5/dllmain.c +++ b/src/main/iidxhook5/dllmain.c @@ -26,6 +26,7 @@ #include "hooklib/setupapi.h" #include "iidxhook-util/acio.h" +#include "iidxhook-util/chart-patch.h" #include "iidxhook-util/config-gfx.h" #include "iidxhook-util/config-io.h" #include "iidxhook-util/config-misc.h" @@ -73,6 +74,23 @@ iidxhook5_setup_d3d9_hooks(const struct iidxhook_config_gfx *config_gfx) d3d9_config.iidx14_to_19_nvidia_fix = true; 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"); + + d3d9_config.iidx09_to_19_monitor_check_cb = + iidxhook_util_chart_patch_set_refresh_rate; + iidxhook_util_chart_patch_init( + IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_19_VGA); + } else if (config_gfx->monitor_check > 0) { + log_info( + "Manual monitor check, resulting refresh rate: %f", + config_gfx->monitor_check); + + iidxhook_util_chart_patch_init( + IIDXHOOK_UTIL_CHART_PATCH_TIMEBASE_14_TO_19_VGA); + iidxhook_util_chart_patch_set_refresh_rate(config_gfx->monitor_check); + } + iidxhook_util_d3d9_configure(&d3d9_config); hook_d3d9_init(iidxhook_d3d9_handlers, lengthof(iidxhook_d3d9_handlers)); @@ -150,6 +168,7 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) API implementations with real IO devices */ iohook_push_handler(ezusb2_emu_device_dispatch_irp); iohook_push_handler(iidxhook_util_acio_dispatch_irp); + iohook_push_handler(iidxhook_util_chart_patch_dispatch_irp); iohook_push_handler(settings_hook_dispatch_irp); if (!config_io.disable_io_emu) { -- 2.54.0 From cf9f3b9dbd081eed0997d818bd88814b8d3f33c5 Mon Sep 17 00:00:00 2001 From: icex2 Date: Tue, 21 Mar 2023 23:31:23 +0100 Subject: [PATCH 02/38] fix(dev): Improve deps docker build process, mount local folder as volume This removes the need to copy all the data into the docker container and outputs from the build process out of the container. In hindsight, this was a poor design decision as it created docker images that were very large with data, that you don't have to keep stored once the build finished, e.g. the build output. Therefore, mount the local folder, keep the checkouts also local which is good for debugging and also re-using them to build without the docker container (no second checkout required). Build output is also written directly to the build/ output folder Overall, the docker container is more lightweight and actually a "build environment" only not tainted with specific versions of the dependencies to build. --- Dockerfile | 26 +++++++------------------- GNUmakefile | 24 ++++++++++++++++-------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4d8a452..8892c97 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM fedora:31 +FROM --platform=amd64 fedora:31@sha256:cbe53d28f54c0f0b1d79a1817089235680b104c23619772473f449f20edd37dd LABEL description="Build environment for bemanitools" @@ -8,25 +8,13 @@ RUN yum -y install \ zip \ clang \ mingw64-gcc.x86_64 \ - mingw32-gcc.x86_64 \ - wine.x86_64 + mingw32-gcc.x86_64 RUN mkdir /bemanitools WORKDIR /bemanitools -# Order optimized for docker layer caching -COPY run-tests-wine.sh run-tests-wine.sh -COPY CHANGELOG.md CHANGELOG.md -COPY CONTRIBUTING.md CONTRIBUTING.md -COPY LICENSE LICENSE -COPY GNUmakefile GNUmakefile -COPY Module.mk Module.mk -COPY README.md README.md -COPY doc doc -COPY dist dist -COPY src src -# .git folder required or building fails when version is generated -COPY .git .git - -# Building -RUN make +ENTRYPOINT [ \ + "/bin/bash", \ + "-c" , \ + "cd /bemanitools && \ + make" ] \ No newline at end of file diff --git a/GNUmakefile b/GNUmakefile index 12f0e06..86e00da 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -14,7 +14,7 @@ BUILDDIR ?= build builddir_docker := $(BUILDDIR)/docker docker_container_name := "bemanitools-build" -docker_image_name := "bemanitools:build" +docker_image_name := "bemanitools-build:latest" depdir := $(BUILDDIR)/dep objdir := $(BUILDDIR)/obj @@ -81,13 +81,21 @@ version: build-docker: $(V)docker rm -f $(docker_container_name) 2> /dev/null || true - $(V)docker build -t $(docker_image_name) -f Dockerfile . - $(V)docker create --name $(docker_container_name) $(docker_image_name) - $(V)rm -rf $(builddir_docker) - $(V)mkdir -p $(builddir_docker) - $(V)docker cp $(docker_container_name):/bemanitools/build $(builddir_docker) - $(V)mv $(builddir_docker)/build/* $(builddir_docker) - $(V)rm -r $(builddir_docker)/build + $(V)docker \ + build \ + -t $(docker_image_name) \ + -f Dockerfile \ + . + $(V)docker \ + run \ + --volume $(shell pwd):/bemanitools \ + --name $(docker_container_name) \ + $(docker_image_name) + +clean-docker: + $(V)docker rm -f $(docker_container_name) || true + $(V)docker image rm -f $(docker_image_name) || true + $(V)rm -rf $(BUILDDIR) # # Pull in module definitions -- 2.54.0 From cc677c5fbe57ffe10d539c803a62178596c73f69 Mon Sep 17 00:00:00 2001 From: icex2 Date: Tue, 21 Mar 2023 23:36:09 +0100 Subject: [PATCH 03/38] chore(dev): Scope code formatting to src/main and src/test Do not format imports which includes headers from other projects with different code styles. --- GNUmakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GNUmakefile b/GNUmakefile index 86e00da..140afe5 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -69,7 +69,7 @@ clean: code-format: $(V)echo "Applying clang-format..." - $(V)find src/ -name '*.c' -o -name '*.h' | xargs clang-format -i -style=file + $(V)find src/main src/test -name '*.c' -o -name '*.h' | xargs clang-format -i -style=file run-tests: $(V)echo "Running tests..." -- 2.54.0 From ba4ef2b6a5d5e30aa1d247fd4cc91a4a08aa796b Mon Sep 17 00:00:00 2001 From: icex2 Date: Tue, 21 Mar 2023 23:59:36 +0100 Subject: [PATCH 04/38] chore(dev): Disable formatting on some files to prevent header resorting This leads to compiler errors as windows.h is expected to be the first header included for other windows related header files. --- src/main/hook/process.c | 3 +++ src/main/jbhook-util-p3io/mixer.c | 3 +++ src/main/popnhook-util/mixer.c | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/main/hook/process.c b/src/main/hook/process.c index 7d98cf2..afa59f0 100644 --- a/src/main/hook/process.c +++ b/src/main/hook/process.c @@ -1,5 +1,8 @@ +// clang-format off +// Don't format because the order is important here #include #include +// clang-format on #include #include diff --git a/src/main/jbhook-util-p3io/mixer.c b/src/main/jbhook-util-p3io/mixer.c index 692a6d9..eacd5c3 100644 --- a/src/main/jbhook-util-p3io/mixer.c +++ b/src/main/jbhook-util-p3io/mixer.c @@ -1,7 +1,10 @@ #define LOG_MODULE "jbhook-mixer" +// clang-format off +// Don't format because the order is important here #include #include +// clang-format on #include "hook/table.h" diff --git a/src/main/popnhook-util/mixer.c b/src/main/popnhook-util/mixer.c index 44d8b19..78f3bde 100644 --- a/src/main/popnhook-util/mixer.c +++ b/src/main/popnhook-util/mixer.c @@ -1,7 +1,10 @@ #define LOG_MODULE "jbhook-mixer" +// clang-format off +// Don't format because the order is important here #include #include +// clang-format on #include "hook/table.h" -- 2.54.0 From 68c3aa779633d98621a8e44c6f56f0df35f05000 Mon Sep 17 00:00:00 2001 From: icex2 Date: Sun, 26 Mar 2023 22:08:11 +0200 Subject: [PATCH 05/38] chore(doc): Documentation cleanup and improvements - Add index with aux tooling to main readme - Move release process to doc, not valuable to have this on the main readme --- README.md | 66 ++++++++++++++++++++---------------------- doc/release-process.md | 29 +++++++++++++++++++ 2 files changed, 61 insertions(+), 34 deletions(-) create mode 100644 doc/release-process.md diff --git a/README.md b/README.md index d8a6d34..e464865 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Version: 5.43 [Release history](CHANGELOG.md) -A collection of tools to run [various Bemani arcade games](#list-of-supported-games). +A collection of tools to run [various Bemani arcade games](#supported-games). Bemanitools 5 (BT5) is the successor to Bemanitools 4 which introduces a big code cleanup and support for newer games. BT5 uses a cleaner approach than BT4 did; specifically, all input and lighting is handled by emulating the protocols @@ -85,19 +85,42 @@ The following games are supported with their corresponding hook-libraries. * SOUND VOLTEX Vivid Wave (`sdvx-05-to-06`): sdvxhook2 * SOUND VOLTEX EXCEED GEAR (`sdvx-05-to-06`): sdvxhook2 -## ViGEm clients: Expose BT5 APIs as XBOX game controllers -Play your favorite non-bemani arcade games with any hardware, e.g. real cabinet hardware, that -implements BT5 APIs. +## Auxiliary tooling +* Bootstrapping + * [inject](doc/inject.md): Inject arbitrary hooking libraries into a target application process. + * [launcher](doc/launcher.md): Bootstrap Konami's AVS environment and launch a target application with arbitrary + injected hooking libraries. +* Beatmnia IIDX Ezusb IO board + * [ezusb-iidx-fpga-flash](doc/tools/ezusb-iidx-fpga-flash.md): Flash a binary blob with FPGA firmware to a target + ezusb FX IO board + * [ezusb-iidx-sram-flash](doc/tools/ezusb-iidx-sram-flash.md): Flash a binary blob with SRAM contents to a target + ezusb FX2 IO board +* Exit hooks: Exit the game with a button combination using native cabinet inputs + * [iidx-ezusb-exit-hook](doc/tools/iidx-ezusb-exit-hook.md): For IIDX with ezusb IO + * [iidx-bio2-exit-hook](doc/tools/iidx-bio2-exit-hook.md): For IIDX with BIO2 IO + * [iidx-ezusb2-exit-hook](doc/tools/iidx-ezusb-exit-hook.md): For IIDX with ezusb FX2 IO +* Bemanitools API testing: Tools for testing bemanitools API implementations + * [eamiotest](doc/tools/eamiotest.md): For [eamio API](doc/api.md#eamuse-readers) + * [iidxiotest](doc/tools/iidxiotest.md): For [iidxio API](doc/api.md#io-boards) + * [jbiotest](doc/tools/jbiotest.md): For [jbio API](doc/api.md#io-boards) +* [aciotest](doc/tools/aciotest.md): Command line tool to quickly test ACIO devices +* config: UI input/output configuration tool when using the default bemanitools API (geninput) +* ir-beat-patch-9/10: Patch the IR beat phase on IIDX 9 and 10 +* [mempatch-hook](doc/tools/mempatch-hook.md): Patch raw memory locations in the target process based on the provided + configuration +* [pcbidgen](doc/tools/pcbidgen.md): Konami PCBID generator tool +* [ViGEm clients](doc/vigem/README.md): Expose BT5 APIs as XBOX game controllers to play any games with real cabinet + hardware. -See the dedicated [readme](doc/vigem/README.md) for details. +## Pre-requisites -## Supported platforms +### Supported platforms Our main platforms are currently Windows XP and Windows 7 which are also the target platforms on the original hardware of those games. However, as it gets more difficult to get and maintain hardware comptible with Windows XP, this might change in the future. Many games also run on very recent Windows 10 builds but bear with us that it's hard to keep up with Windows updates breaking legacy software. -## Distribution contents +### Distribution contents Check the [list of supported games](#supported-games) to grab the right files for your game. BT5 also includes a *tools* subpackage (tools.zip) as well as the full source code (src.zip). @@ -105,7 +128,7 @@ You will find *.md files in various sub-packages that give you further instructi or FAQ. We advice you to read them as your questions and concerns might already be answered by them. If not, let us know if there is any information that you consider helpful or important to know and should be added. -## Setup and dependencies +### Setup and dependencies Most (older generation) games were developed for Windows XP Embedded but should run fine on any consumer version of Windows XP. Newer versions of Windows, e.g. Windows 7, 8 and 10, should be fine as well. Some hooks also include fixes required to run the games on a more recent version. @@ -134,32 +157,7 @@ important aspects you should know before you get started with development. Please refer to the [API documentation](doc/api.md). ## Release process -Steps for the release process: -1. Update the corresponding section in the [changelog](CHANGELOG.md) with bullet points reflecting -major features merged into master since the previous release -1. Make sure you have the latest `master` state pulled to your local copy -1. Tag the release with the next release number which also be found at the -[top of the readme](#bemanitools-5) as it always reflects the current version beinged worked on -on the `master` branch , e.g. 5.35: `git tag 5.35` -1. Push the tag to upstream: `git push origin 5.35` -1. The [build pipeline](https://dev.s-ul.net/djhackers/bemanitools/-/pipelines) should start -automatically once the tag is pushed including the steps `build` and `upload-release` -1. Once completed successfully, the release is uploaded -1. Take the changelog of the published version and notify the pigs in the stall about it: - 1. New post in thread - ``` - released: - - Changelog: - - ``` - 1. Update the OP title by bumping the version number in it - 1. Update the OP post by extending it accordingly (see previous entries) - -1. Bump the version number at the [top of this readme](#bemanitools-5) and add a new empty section -in the [changelog](CHANGELOG.md) with the new version number as title. Commit changes and push to -`master` branch -1. Continue developing and merging MRs until you decide its time for another release +Please refer to the [dedicated documentation](doc/release-process.md). ## License Source code license is the Unlicense; you are permitted to do with this as thou wilt. For details, please refer to the diff --git a/doc/release-process.md b/doc/release-process.md new file mode 100644 index 0000000..0d11f28 --- /dev/null +++ b/doc/release-process.md @@ -0,0 +1,29 @@ +# Release process + +For bemanitools maintainers, steps for the release process: + +1. Update the corresponding section in the [changelog](CHANGELOG.md) with bullet points reflecting +major features merged into master since the previous release +1. Make sure you have the latest `master` state pulled to your local copy +1. Tag the release with the next release number which also be found at the +[top of the readme](#bemanitools-5) as it always reflects the current version beinged worked on +on the `master` branch , e.g. 5.35: `git tag 5.35` +1. Push the tag to upstream: `git push origin 5.35` +1. The [build pipeline](https://dev.s-ul.net/djhackers/bemanitools/-/pipelines) should start +automatically once the tag is pushed including the steps `build` and `upload-release` +1. Once completed successfully, the release is uploaded +1. Take the changelog of the published version and notify the pigs in the stall about it: + 1. New post in thread + ``` + released: + + Changelog: + + ``` + 1. Update the OP title by bumping the version number in it + 1. Update the OP post by extending it accordingly (see previous entries) + +1. Bump the version number at the [top of this readme](#bemanitools-5) and add a new empty section +in the [changelog](CHANGELOG.md) with the new version number as title. Commit changes and push to +`master` branch +1. Continue developing and merging MRs until you decide its time for another release \ No newline at end of file -- 2.54.0 From 4a672de9602d0950d328206c9e69b4e531003fce Mon Sep 17 00:00:00 2001 From: icex2 Date: Sun, 26 Mar 2023 23:11:49 +0200 Subject: [PATCH 06/38] fix(iidx/ezusb): Improve code resiliance of ezusb node-serial module - Use static assert to verify struct sizes - Replace "magic numbers" with proper sizeof's - Allocate largest size buffer for message response to address compiler warnings which indicates potential out of bounds reads/writes --- src/main/ezusb-iidx-emu/node-serial.c | 97 +++++++++++++++++++-------- 1 file changed, 69 insertions(+), 28 deletions(-) diff --git a/src/main/ezusb-iidx-emu/node-serial.c b/src/main/ezusb-iidx-emu/node-serial.c index a42632d..22b423d 100644 --- a/src/main/ezusb-iidx-emu/node-serial.c +++ b/src/main/ezusb-iidx-emu/node-serial.c @@ -12,6 +12,7 @@ #include "util/hex.h" #include "util/log.h" +#include "util/mem.h" #include "util/thread.h" #define CARD_ID_LEN 8 @@ -62,24 +63,27 @@ enum ezusb_iidx_emu_node_serial_card_slot_state { CARD_SLOT_STATE_WRITE = 5, }; +#define NODE_SERIAL_MSG_HEADER_SIZE 4 #define MAG_CARD_DATA_SIZE 128 +#pragma pack(push, 1) struct ezusb_iidx_emu_node_serial_msg { + /* Header part of message */ uint8_t msg_cmd; uint8_t node_id; uint8_t node_cmd; uint8_t payload_len; union payload { - struct { + struct ezusb_iidx_emu_node_serial_node_enum_req { uint8_t node_id_to_assign; } node_enum_req; - struct { + struct ezusb_iidx_emu_node_serial_node_enum_resp { uint8_t total_nodes; } node_enum_resp; - struct { + struct ezusb_iidx_emu_node_serial_get_version_resp { uint32_t type; uint8_t dup; uint8_t version_maj; @@ -88,30 +92,30 @@ struct ezusb_iidx_emu_node_serial_msg { char comment[5]; } get_version_resp; - struct { + struct ezusb_iidx_emu_node_serial_keyboard_get_buffer_size_resp { uint16_t buffer_size_type; } keyboard_get_buffer_size_resp; - struct { + struct ezusb_iidx_emu_node_serial_keyboard_read_data_req { uint8_t buffer_size_type; } keyboard_read_data_req; - struct { + struct ezusb_iidx_emu_node_serial_keyboard_read_data_resp { /* dynamic size */ uint8_t data[0xFF]; } keyboard_read_data_resp; - struct { + struct ezusb_iidx_emu_node_serial_card_slot_state_req { uint8_t ezusb_iidx_emu_node_serial_card_slot_state; } card_slot_state_req; - struct { + struct ezusb_iidx_emu_node_serial_card_read_resp { /* 1 byte header + 128 byte card data */ uint8_t header; uint8_t data[MAG_CARD_DATA_SIZE]; } card_read_resp; - struct { + struct ezusb_iidx_emu_node_serial_card_write_req { uint8_t data[MAG_CARD_DATA_SIZE]; } card_write_req; @@ -127,7 +131,7 @@ struct ezusb_iidx_emu_node_serial_msg { * card_read_req * card_format_complete_req */ - struct { + struct ezusb_iidx_emu_node_serial_common_req { /* no payload */ } common_req; @@ -142,11 +146,48 @@ struct ezusb_iidx_emu_node_serial_msg { * card_write_resp * card_format_complete_resp */ - struct { + struct ezusb_iidx_emu_node_serial_common_status_resp { uint8_t status; } common_status_resp; }; }; +_Static_assert( + sizeof(struct ezusb_iidx_emu_node_serial_node_enum_req) == 1, + "ezusb_iidx_emu_node_serial_node_enum_req is the wrong size"); +_Static_assert( + sizeof(struct ezusb_iidx_emu_node_serial_node_enum_resp) == 1, + "ezusb_iidx_emu_node_serial_node_enum_resp is the wrong size"); +_Static_assert( + sizeof(struct ezusb_iidx_emu_node_serial_get_version_resp) == 13, + "ezusb_iidx_emu_node_serial_get_version_resp is the wrong size"); +_Static_assert( + sizeof(struct ezusb_iidx_emu_node_serial_keyboard_get_buffer_size_resp) == 2, + "ezusb_iidx_emu_node_serial_keyboard_get_buffer_size_resp is the wrong size"); +_Static_assert( + sizeof(struct ezusb_iidx_emu_node_serial_keyboard_read_data_req) == 1, + "ezusb_iidx_emu_node_serial_keyboard_read_data_req is the wrong size"); +_Static_assert( + sizeof(struct ezusb_iidx_emu_node_serial_keyboard_read_data_resp) == 255, + "ezusb_iidx_emu_node_serial_keyboard_read_data_resp is the wrong size"); +_Static_assert( + sizeof(struct ezusb_iidx_emu_node_serial_card_slot_state_req) == 1, + "ezusb_iidx_emu_node_serial_card_slot_state_req is the wrong size"); +_Static_assert( + sizeof(struct ezusb_iidx_emu_node_serial_card_read_resp) == 1 + MAG_CARD_DATA_SIZE, + "ezusb_iidx_emu_node_serial_card_read_resp is the wrong size"); +_Static_assert( + sizeof(struct ezusb_iidx_emu_node_serial_card_write_req) == MAG_CARD_DATA_SIZE, + "ezusb_iidx_emu_node_serial_card_write_req is the wrong size"); +_Static_assert( + sizeof(struct ezusb_iidx_emu_node_serial_common_req) == 0, + "ezusb_iidx_emu_node_serial_common_req is the wrong size"); +_Static_assert( + sizeof(struct ezusb_iidx_emu_node_serial_common_status_resp) == 1, + "ezusb_iidx_emu_node_serial_common_status_resp is the wrong size"); +_Static_assert( + sizeof(struct ezusb_iidx_emu_node_serial_msg) == 259, + "ezusb_iidx_emu_node_serial_msg is the wrong size"); +#pragma pack(pop) /* ------------------------------------------------------------------------- */ @@ -419,8 +460,8 @@ calc_serial_buffer_checksum(const uint8_t *buffer, uint16_t length) static struct ezusb_iidx_emu_node_serial_msg *create_generic_node_response_ok( const struct ezusb_iidx_emu_node_serial_msg *msg_in, uint16_t *msg_out_len) { - *msg_out_len = 4 + 1; - struct ezusb_iidx_emu_node_serial_msg *resp = malloc(*msg_out_len); + *msg_out_len = NODE_SERIAL_MSG_HEADER_SIZE + sizeof(struct ezusb_iidx_emu_node_serial_common_status_resp); + struct ezusb_iidx_emu_node_serial_msg *resp = xmalloc(sizeof(struct ezusb_iidx_emu_node_serial_msg)); resp->msg_cmd = CMD_NODE_RESP; resp->node_id = msg_in->node_id; resp->node_cmd = msg_in->node_cmd; @@ -443,9 +484,9 @@ static struct ezusb_iidx_emu_node_serial_msg *process_serial_msg( switch (msg_in->node_cmd) { case H8_CMD_NODE_ENUM: { log_misc("H8_CMD_NODE_ENUM"); - *msg_out_len = 4 + 1; + *msg_out_len = NODE_SERIAL_MSG_HEADER_SIZE + sizeof(struct ezusb_iidx_emu_node_serial_node_enum_resp); struct ezusb_iidx_emu_node_serial_msg *resp = - malloc(*msg_out_len); + xmalloc(sizeof(struct ezusb_iidx_emu_node_serial_msg)); resp->msg_cmd = CMD_H8_RESP; /* This response is not from a specific node, id needs to be * 0 */ @@ -458,9 +499,9 @@ static struct ezusb_iidx_emu_node_serial_msg *process_serial_msg( case H8_CMD_GET_VERSION: { log_misc("H8_CMD_GET_VERSION: %d", msg_in->node_id); - *msg_out_len = 4 + 13; + *msg_out_len = NODE_SERIAL_MSG_HEADER_SIZE + sizeof(struct ezusb_iidx_emu_node_serial_get_version_resp); struct ezusb_iidx_emu_node_serial_msg *resp = - malloc(*msg_out_len); + xmalloc(sizeof(struct ezusb_iidx_emu_node_serial_msg)); resp->msg_cmd = CMD_H8_RESP; resp->node_id = msg_in->node_id; resp->node_cmd = msg_in->node_cmd; @@ -483,9 +524,9 @@ static struct ezusb_iidx_emu_node_serial_msg *process_serial_msg( case H8_CMD_PROG_EXEC: { log_misc("H8_CMD_PROG_EXEC: %d", msg_in->node_id); - *msg_out_len = 4 + 1; + *msg_out_len = NODE_SERIAL_MSG_HEADER_SIZE + sizeof(struct ezusb_iidx_emu_node_serial_common_status_resp); struct ezusb_iidx_emu_node_serial_msg *resp = - malloc(*msg_out_len); + xmalloc(sizeof(struct ezusb_iidx_emu_node_serial_msg)); resp->msg_cmd = CMD_H8_RESP; resp->node_id = msg_in->node_id; resp->node_cmd = msg_in->node_cmd; @@ -559,9 +600,9 @@ static struct ezusb_iidx_emu_node_serial_msg *process_serial_msg( case NODE_CMD_CARD_RW_UNIT_GET_STATUS: { /* report front and back sensor states */ - *msg_out_len = 4 + 1; + *msg_out_len = NODE_SERIAL_MSG_HEADER_SIZE + sizeof(struct ezusb_iidx_emu_node_serial_common_status_resp); struct ezusb_iidx_emu_node_serial_msg *resp = - malloc(*msg_out_len); + xmalloc(sizeof(struct ezusb_iidx_emu_node_serial_msg)); resp->msg_cmd = CMD_NODE_RESP; resp->node_id = msg_in->node_id; resp->node_cmd = msg_in->node_cmd; @@ -678,9 +719,9 @@ static struct ezusb_iidx_emu_node_serial_msg *process_serial_msg( } case NODE_CMD_CARD_READ: { - *msg_out_len = 4 + 129; + *msg_out_len = NODE_SERIAL_MSG_HEADER_SIZE + sizeof(struct ezusb_iidx_emu_node_serial_card_read_resp); struct ezusb_iidx_emu_node_serial_msg *resp = - malloc(*msg_out_len); + xmalloc(sizeof(struct ezusb_iidx_emu_node_serial_msg)); resp->msg_cmd = CMD_NODE_RESP; resp->node_id = msg_in->node_id; resp->node_cmd = msg_in->node_cmd; @@ -814,7 +855,7 @@ static struct ezusb_iidx_emu_node_serial_msg *process_serial_msg( } ezusb_iidx_emu_node_serial_write_loopback_card_buf - [msg_in->node_id - 1] = malloc(MAG_CARD_DATA_SIZE); + [msg_in->node_id - 1] = xmalloc(MAG_CARD_DATA_SIZE); memcpy( ezusb_iidx_emu_node_serial_write_loopback_card_buf [msg_in->node_id - 1], @@ -830,9 +871,9 @@ static struct ezusb_iidx_emu_node_serial_msg *process_serial_msg( } case NODE_CMD_KEYBOARD_GET_BUFFER_SIZE: { - *msg_out_len = 4 + 2; + *msg_out_len = NODE_SERIAL_MSG_HEADER_SIZE + sizeof(struct ezusb_iidx_emu_node_serial_keyboard_get_buffer_size_resp); struct ezusb_iidx_emu_node_serial_msg *resp = - malloc(*msg_out_len); + xmalloc(sizeof(struct ezusb_iidx_emu_node_serial_msg)); resp->msg_cmd = CMD_NODE_RESP; resp->node_id = msg_in->node_id; resp->node_cmd = msg_in->node_cmd; @@ -890,9 +931,9 @@ static struct ezusb_iidx_emu_node_serial_msg *process_serial_msg( } case NODE_CMD_KEYBOARD_READ_DATA: { - *msg_out_len = 4 + 2; + *msg_out_len = NODE_SERIAL_MSG_HEADER_SIZE + 2; struct ezusb_iidx_emu_node_serial_msg *resp = - malloc(*msg_out_len); + xmalloc(sizeof(struct ezusb_iidx_emu_node_serial_msg)); resp->msg_cmd = CMD_NODE_RESP; resp->node_id = msg_in->node_id; resp->node_cmd = msg_in->node_cmd; -- 2.54.0 From bf13d769d7ec291e1cd67b5f7a2b7790363b1463 Mon Sep 17 00:00:00 2001 From: icex2 Date: Sun, 26 Mar 2023 23:14:32 +0200 Subject: [PATCH 07/38] chore(dev): Fix compiler warning, use correct format for size_t type --- src/main/ddrhook-util/usbmem.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/ddrhook-util/usbmem.c b/src/main/ddrhook-util/usbmem.c index aa71347..9869643 100644 --- a/src/main/ddrhook-util/usbmem.c +++ b/src/main/ddrhook-util/usbmem.c @@ -193,7 +193,11 @@ static HRESULT usbmem_write(struct irp *irp) usbmem_response[2] = ~usbmem_response[1]; if (usbmem_state[target_device_id].buffer_frame == 0) { - snprintf(usbmem_response + 4, sizeof(usbmem_response) - 5, "%Iu ", usbmem_state[target_device_id].buffer_len); + snprintf( + usbmem_response + 4, + sizeof(usbmem_response) - 5, + "%zu ", + usbmem_state[target_device_id].buffer_len); } else { size_t len = sizeof(usbmem_response) - 5; -- 2.54.0 From a239d18e26a714f24580270d52c10a9062495d28 Mon Sep 17 00:00:00 2001 From: icex2 Date: Sun, 26 Mar 2023 23:43:36 +0200 Subject: [PATCH 08/38] chore(dev): Fix format warning --- src/main/mempatch-hook/main.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/mempatch-hook/main.c b/src/main/mempatch-hook/main.c index 2c4279f..2e12991 100644 --- a/src/main/mempatch-hook/main.c +++ b/src/main/mempatch-hook/main.c @@ -18,10 +18,9 @@ static bool patch_memory_check_data( for (size_t i = 0; i < len; i++) { if (dest[i] != data_expected[i]) { log_warning( - "Memcheck error: base %" PRIXPTR " + address %" PRIXPTR " + offset %d: " - "expected %X, found %X", - base_address, - address, + "Memcheck error: base %lluX + address %lluX + offset %d: expected %X, found %X", + (uint64_t) base_address, + (uint64_t) address, // this cast is technically wrong // but no one should be patching 32K worth of bytes at once (int)i, -- 2.54.0 From 8325ca167d622045b44cc1f58e12f42a0e3cc2f6 Mon Sep 17 00:00:00 2001 From: icex2 Date: Sun, 26 Mar 2023 23:43:54 +0200 Subject: [PATCH 09/38] chore(dev): Fix compiler warning about not knowing the definition for a struct --- src/main/aciodrv/kfca.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/aciodrv/kfca.h b/src/main/aciodrv/kfca.h index d73f259..cb0ea67 100644 --- a/src/main/aciodrv/kfca.h +++ b/src/main/aciodrv/kfca.h @@ -2,6 +2,7 @@ #define ACIODRV_KFCA_H #include "acio/kfca.h" +#include "aciodrv/device.h" /** * Initialize an KFCA node. -- 2.54.0 From 1385cd676854402565b30f5d6e8002c98bf11270 Mon Sep 17 00:00:00 2001 From: icex2 Date: Sun, 26 Mar 2023 23:57:26 +0200 Subject: [PATCH 10/38] fix(dev): Upgrade docker file, move to latest debian bullseye base image The fedora image was already quite old but also took ages to initially install the dependencies. Being more familiar with debian, initial container building with package installation being rather quick, and assuming most folks being more familiar debian as well, I decided to shift to make this easier to maintain. --- Dockerfile | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8892c97..8f88f6f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,21 @@ -FROM --platform=amd64 fedora:31@sha256:cbe53d28f54c0f0b1d79a1817089235680b104c23619772473f449f20edd37dd +FROM --platform=amd64 debian:11.6-slim@sha256:f7d141c1ec6af549958a7a2543365a7829c2cdc4476308ec2e182f8a7c59b519 LABEL description="Build environment for bemanitools" -RUN yum -y install \ - git \ +# mingw-w64-gcc has 32-bit and 64-bit toolchains +RUN apt-get update && apt-get install -y --no-install-recommends \ + mingw-w64 \ + mingw-w64-common \ make \ zip \ - clang \ - mingw64-gcc.x86_64 \ - mingw32-gcc.x86_64 + git \ + && rm -rf /var/lib/apt/lists/* RUN mkdir /bemanitools WORKDIR /bemanitools ENTRYPOINT [ \ - "/bin/bash", \ + "/bin/sh", \ "-c" , \ "cd /bemanitools && \ make" ] \ No newline at end of file -- 2.54.0 From 5e68df541f1d257998a669b0ba89ce7fc0e33952 Mon Sep 17 00:00:00 2001 From: icex2 Date: Sun, 26 Mar 2023 23:59:06 +0200 Subject: [PATCH 11/38] doc: Add documentation about parallel building being broken --- doc/development.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/development.md b/doc/development.md index 1e5ea18..a91bd3b 100644 --- a/doc/development.md +++ b/doc/development.md @@ -51,6 +51,10 @@ make All output is located in the *build* folder including the final *bemanitools.zip* package. +Note about using `-j n` option on make: This is currently considered broken/unreliable. Expect to +run into odd issues like randomly changing unresolved dependency errors. If you attempted this, +run a `make clean` before running `make` again. + ### Release building A release build is a clean build including code formatting and testing. This can be executed by running the following command: -- 2.54.0 From ffb589faa77cb5cf2698d89dd77038dbb0496cdd Mon Sep 17 00:00:00 2001 From: icex2 Date: Mon, 27 Mar 2023 19:36:00 +0200 Subject: [PATCH 12/38] fix(iidxhook-util/settings): Bugfix broken paths with mixed / and \ Applies to iidx18 and iidx19 when using the recently extended redirect feature for settings paths, mixing / and \ crashes the game in some operator sub-menus when trying to save settings. --- src/main/iidxhook-util/settings.c | 24 ++++++++++++++++++------ src/main/util/str.c | 11 +++++++++++ src/main/util/str.h | 1 + 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/main/iidxhook-util/settings.c b/src/main/iidxhook-util/settings.c index 761b3f8..5b6b3c8 100644 --- a/src/main/iidxhook-util/settings.c +++ b/src/main/iidxhook-util/settings.c @@ -37,9 +37,11 @@ static char settings_path[MAX_PATH] = ".\\"; /* ------------------------------------------------------------------------- */ -static void settings_build_new_path(const char* orig_path, char* new_path, size_t new_path_len) +static void settings_build_new_path( + const char *orig_path, char *new_path, size_t new_path_len) { size_t settings_path_len; + char* orig_appended_path; settings_path_len = strlen(settings_path); @@ -48,8 +50,18 @@ static void settings_build_new_path(const char* orig_path, char* new_path, size_ strcpy(new_path, settings_path); strcat(new_path, orig_path); - /* Remove : of drive letter. Multiple \ are fine and handled by windows */ - new_path[settings_path_len + 1] = '\\'; + /* Fix only the part of the original path which comes after the leading settings path */ + orig_appended_path = new_path + settings_path_len; + + /* Duplicate \ in paths is fine because the win32 file API applies path + normalization */ + + /* Fixes some paths resulting in a mix of / and \ leading to crashes + on iidx 18 and 19, e.g. settings.bin saving in operator menu */ + str_replace(orig_appended_path, '/', '\\'); + + /* Remove : of drive letter */ + str_replace(orig_appended_path, ':', '\\'); } /* ------------------------------------------------------------------------- */ @@ -65,7 +77,7 @@ BOOL WINAPI my_CreateDirectoryA( settings_build_new_path(lpPathName, new_path, sizeof(new_path)); - log_misc("(CreateDir) Remapped settings path %s", new_path); + log_misc("(CreateDir) Remapped settings path %s -> %s", lpPathName, new_path); return real_CreateDirectoryA(new_path, lpSecurityAttributes); } @@ -122,9 +134,9 @@ settings_hook_dispatch_irp(struct irp *irp) settings_build_new_path(filename_cstr, new_path, sizeof(new_path)); - free(filename_cstr); + log_misc("Remapped settings path %s -> %s", filename_cstr, new_path); - log_misc("Remapped settings path to %s", new_path); + free(filename_cstr); filename_wstr = str_widen(new_path); diff --git a/src/main/util/str.c b/src/main/util/str.c index 7455176..83febf6 100644 --- a/src/main/util/str.c +++ b/src/main/util/str.c @@ -194,6 +194,17 @@ wchar_t *str_widen(const char *src) return result; } +void str_replace(char *str, char cur, char new) +{ + while (*str != '\0') { + if (*str == cur) { + *str = new; + } + + str++; + } +} + wchar_t *wstr_dup(const wchar_t *wstr) { wchar_t *dest; diff --git a/src/main/util/str.h b/src/main/util/str.h index fbfc481..5b36d54 100644 --- a/src/main/util/str.h +++ b/src/main/util/str.h @@ -15,6 +15,7 @@ size_t str_format(char *buf, size_t nchars, const char *fmt, ...); void str_trim(char *str); size_t str_vformat(char *buf, size_t nchars, const char *fmt, va_list ap); wchar_t *str_widen(const char *src); +void str_replace(char *str, char cur, char new); void wstr_cat(wchar_t *dest, size_t dnchars, const wchar_t *src); void wstr_cpy(wchar_t *dest, size_t dnchars, const wchar_t *src); -- 2.54.0 From 988ed47160dc96032c42a06afc8bbb0087a8d3c5 Mon Sep 17 00:00:00 2001 From: icex2 Date: Mon, 27 Mar 2023 19:37:28 +0200 Subject: [PATCH 13/38] fix(iidxhook-util/chart-patch): Bugfix broken synchronization The synchronization block was too coarse and kept the lock acquired even when the hooked call continued traversing because it skipped the chart patch trap code. This was apparently fine on several games but caused very flaky deadlocking on iidx18 during the boot screens and even crashed iidx19 consistently before showing the boot screen. --- src/main/iidxhook-util/chart-patch.c | 37 ++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/main/iidxhook-util/chart-patch.c b/src/main/iidxhook-util/chart-patch.c index 6542ff4..0f557ee 100644 --- a/src/main/iidxhook-util/chart-patch.c +++ b/src/main/iidxhook-util/chart-patch.c @@ -274,6 +274,9 @@ static bool chart_patch_file_trap(struct irp *irp) &chart_id[2], &chart_id[3]) == 4 && chart_patch_is_chart_id(chart_id)) { + + EnterCriticalSection(&chart_patch_lock); + chart_id[4] = '\0'; wstr_narrow(irp->open_filename, &tmp); @@ -298,12 +301,15 @@ static bool chart_patch_file_trap(struct irp *irp) irp->fd = chart_patch_file_checksum.fd; chart_patch_file_checksum.active = true; } else { + LeaveCriticalSection(&chart_patch_lock); /* other file, like *.2dx */ return false; } log_misc("Data already prepared"); + LeaveCriticalSection(&chart_patch_lock); + return true; } @@ -359,8 +365,12 @@ static bool chart_patch_file_trap(struct irp *irp) chart_patch_file_detour = true; + LeaveCriticalSection(&chart_patch_lock); + return true; } + + LeaveCriticalSection(&chart_patch_lock); } return false; @@ -465,20 +475,31 @@ chart_patch_file_seek(struct chart_patch_file *file, struct irp *irp) static HRESULT chart_patch_file_dispatch_irp(struct chart_patch_file *file, struct irp *irp) { - // log_misc("chart_patch_file_dispatch_irp %p", file->fd); + HRESULT hr; + + EnterCriticalSection(&chart_patch_lock); switch (irp->op) { case IRP_OP_CLOSE: - return chart_patch_file_close_irp(file, irp); + hr = chart_patch_file_close_irp(file, irp); + break; case IRP_OP_READ: - return chart_patch_file_read(file, irp); + hr = chart_patch_file_read(file, irp); + break; case IRP_OP_WRITE: - return HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED); + hr = HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED); + break; case IRP_OP_SEEK: - return chart_patch_file_seek(file, irp); + hr = chart_patch_file_seek(file, irp); + break; default: - return E_NOTIMPL; + hr = E_NOTIMPL; + break; } + + LeaveCriticalSection(&chart_patch_lock); + + return hr; } void iidxhook_util_chart_patch_init(double orig_timebase) @@ -522,8 +543,6 @@ iidxhook_util_chart_patch_dispatch_irp(struct irp *irp) HRESULT hr; if (chart_patch_initted) { - EnterCriticalSection(&chart_patch_lock); - hr = S_FALSE; if (irp->op == IRP_OP_OPEN) { @@ -546,8 +565,6 @@ iidxhook_util_chart_patch_dispatch_irp(struct irp *irp) } } - LeaveCriticalSection(&chart_patch_lock); - return hr; } else { return iohook_invoke_next(irp); -- 2.54.0 From d8d5a512b48a1c6545514d494fa8d7281865dfee Mon Sep 17 00:00:00 2001 From: icex2 Date: Tue, 28 Mar 2023 23:29:23 +0200 Subject: [PATCH 14/38] feat(iidx18/19): Improve chart-patch to correctly support iidx 18 and 19 The paths changed for 18 and again for 19. Refactor and improve the detection logic to consider this. This also should make the code more maintainable. --- src/main/iidxhook-util/chart-patch.c | 301 +++++++++++++++++++++------ 1 file changed, 236 insertions(+), 65 deletions(-) diff --git a/src/main/iidxhook-util/chart-patch.c b/src/main/iidxhook-util/chart-patch.c index 0f557ee..8e2a3a0 100644 --- a/src/main/iidxhook-util/chart-patch.c +++ b/src/main/iidxhook-util/chart-patch.c @@ -50,6 +50,19 @@ struct ospreybin { uint32_t checksum_type; }; +enum song_data_path_format { + SONG_DATA_PATH_INVALID = 0, + SONG_DATA_PATH_09_TO_17 = 1, + SONG_DATA_PATH_18 = 2, + SONG_DATA_PATH_19 = 3, +}; + +enum song_data_file_type { + SONG_DATA_FILE_TYPE_UNKNKOWN = 0, + SONG_DATA_FILE_TYPE_DOT_1 = 1, + SONG_DATA_FILE_TYPE_CHECKSUM = 2, +}; + static bool chart_patch_initted; static double chart_patch_hz; @@ -163,7 +176,7 @@ static bool chart_patch_file_load( return true; } -static bool chart_patch_is_chart_id(const wchar_t *str) +static bool chart_patch_is_valid_song_id(const wchar_t *str) { for (int i = 0; i < 4; i++) { if (!(str[i] >= L'0' && str[i] <= L'9')) { @@ -249,14 +262,185 @@ static void chart_patch_execute_patch_checksum() log_warning("Could not find checksum row for %s", chart_patch_file_1_name); } +static enum song_data_path_format chart_patch_is_song_data_path(const wchar_t *path, wchar_t *song_id) +{ + log_assert(path); + log_assert(song_id); + + // Song data path for 09 to 17 + // data folder next to revision folder and working dir set to revision folder + if (swscanf( + path, + // Ensure to match %lc and not %c to extract wide string chars + L"..\\data\\sd_data%*[\\/]%lc%lc%lc%lc%*[\\/]", + &song_id[0], + &song_id[1], + &song_id[2], + &song_id[3]) == 4) { + song_id[4] = '\0'; + + if (!chart_patch_is_valid_song_id(song_id)) { + return SONG_DATA_PATH_INVALID; + } + + return SONG_DATA_PATH_09_TO_17; + } + + // Song data path for 18 + // data dir next to modules folder but working dir set to root folder + if (swscanf( + path, + // Ensure to match %lc and not %c to extract wide string chars + L".\\data\\sd_data%*[\\/]%lc%lc%lc%lc%*[\\/]", + &song_id[0], + &song_id[1], + &song_id[2], + &song_id[3]) == 4) { + song_id[4] = '\0'; + + if (!chart_patch_is_valid_song_id(song_id)) { + return SONG_DATA_PATH_INVALID; + } + + return SONG_DATA_PATH_18; + } + + // Song data path for 19 + // data dir next to modules folder but working dir set to root folder + // ...and they had to rename sd_data to sound *tableflip* + if (swscanf( + path, + // Ensure to match %lc and not %c to extract wide string chars + L".\\data\\sound%*[\\/]%lc%lc%lc%lc%*[\\/]", + &song_id[0], + &song_id[1], + &song_id[2], + &song_id[3]) == 4) { + song_id[4] = '\0'; + + if (!chart_patch_is_valid_song_id(song_id)) { + return SONG_DATA_PATH_INVALID; + } + + return SONG_DATA_PATH_19; + } + + return SONG_DATA_PATH_INVALID; +} + +static void chart_patch_get_song_chart_file_name(const wchar_t *song_id, wchar_t *chart_file_name) +{ + log_assert(song_id); + log_assert(chart_file_name); + log_assert(wcslen(song_id) == 4); + + memcpy(chart_file_name, song_id, sizeof(wchar_t) * 4); + chart_file_name[4] = L'.'; + chart_file_name[5] = L'1'; + chart_file_name[6] = L'\0'; +} + +static enum song_data_file_type chart_patch_get_song_data_file_type(const wchar_t *path, const wchar_t *song_id) +{ + wchar_t chart_file[7]; + + log_assert(path); + log_assert(song_id); + + chart_patch_get_song_chart_file_name(song_id, chart_file); + + if (wstr_ends_with(path, chart_file)) { + return SONG_DATA_FILE_TYPE_DOT_1; + } + + if (wstr_ends_with(path, L"osprey.bin")) { + return SONG_DATA_FILE_TYPE_CHECKSUM; + } + + return SONG_DATA_FILE_TYPE_UNKNKOWN; +} + +static void chart_patch_get_path_dot_1_file(const wchar_t *song_id, enum song_data_path_format path_format, wchar_t *path) +{ + switch (path_format) { + case SONG_DATA_PATH_09_TO_17: + // Note: These use %s also for wide strings! + wsprintfW( + path, + L"..\\data\\sd_data\\%s\\%s.1", + song_id, + song_id); + break; + + case SONG_DATA_PATH_18: + // Note: These use %s also for wide strings! + wsprintfW( + path, + L".\\data\\sd_data\\%s\\%s.1", + song_id, + song_id); + break; + + case SONG_DATA_PATH_19: + // Note: These use %s also for wide strings! + wsprintfW( + path, + L".\\data\\sound\\%s\\%s.1", + song_id, + song_id); + break; + + case SONG_DATA_FILE_TYPE_UNKNKOWN: + default: + log_fatal("Illegal state"); + break; + } +} + +static void chart_patch_get_path_checksum_file(const wchar_t *song_id, enum song_data_path_format path_format, wchar_t *path) +{ + switch (path_format) { + case SONG_DATA_PATH_09_TO_17: + // Note: These use %s also for wide strings! + wsprintfW( + path, + L"..\\data\\sd_data\\%s\\osprey.bin", + song_id); + break; + + case SONG_DATA_PATH_18: + // Note: These use %s also for wide strings! + wsprintfW( + path, + L".\\data\\sd_data\\%s\\osprey.bin", + song_id); + break; + + case SONG_DATA_PATH_19: + // Note: These use %s also for wide strings! + wsprintfW( + path, + L".\\data\\sound\\%s\\osprey.bin", + song_id); + break; + + case SONG_DATA_FILE_TYPE_UNKNKOWN: + default: + log_fatal("Illegal state"); + break; + } +} + static bool chart_patch_file_trap(struct irp *irp) { - wchar_t buffer_1_path[1024]; - wchar_t buffer_checksum_path[1024]; - wchar_t chart_id[5]; - wchar_t chart_file[7]; - bool is_1_file; - bool is_checksum_file; + enum song_data_path_format path_format; + enum song_data_file_type file_type; + + wchar_t buffer_1_path[MAX_PATH]; + wchar_t buffer_checksum_path[MAX_PATH]; + wchar_t song_id[5]; + wchar_t chart_file_name[7]; + char *tmp; /* This has to trap three different scenarios: @@ -266,44 +450,36 @@ static bool chart_patch_file_trap(struct irp *irp) In the end, we have to serve either just the .1 file or both the .1 and checksum file from memory until the application closes one or both files */ - if (swscanf( - irp->open_filename, - L"..\\data\\sd_data%*[\\/]%c%c%c%c%*[\\/]", - &chart_id[0], - &chart_id[1], - &chart_id[2], - &chart_id[3]) == 4 && - chart_patch_is_chart_id(chart_id)) { + path_format = chart_patch_is_song_data_path(irp->open_filename, song_id); + + if (path_format != SONG_DATA_PATH_INVALID) { EnterCriticalSection(&chart_patch_lock); - chart_id[4] = '\0'; + file_type = chart_patch_get_song_data_file_type(irp->open_filename, song_id); - wstr_narrow(irp->open_filename, &tmp); - log_misc("Trapping %s...", tmp); - free(tmp); - - memcpy(chart_file, chart_id, sizeof(chart_id)); - chart_file[4] = L'.'; - chart_file[5] = L'1'; - chart_file[6] = L'\0'; - - is_1_file = wstr_ends_with(irp->open_filename, chart_file); - is_checksum_file = wstr_ends_with(irp->open_filename, L"osprey.bin"); + // %S for printing wide strings + log_misc("Trapping song ID %S, path format %d, file type %d, path %S", song_id, path_format, file_type, irp->open_filename); /* Block a second open call to either .1 or checksum file if detouring is already active */ if (chart_patch_file_detour) { - if (is_1_file) { - irp->fd = chart_patch_file_1.fd; - chart_patch_file_1.active = true; - } else if (is_checksum_file) { - irp->fd = chart_patch_file_checksum.fd; - chart_patch_file_checksum.active = true; - } else { - LeaveCriticalSection(&chart_patch_lock); - /* other file, like *.2dx */ - return false; + switch (file_type) { + case SONG_DATA_FILE_TYPE_DOT_1: + irp->fd = chart_patch_file_1.fd; + chart_patch_file_1.active = true; + break; + + case SONG_DATA_FILE_TYPE_CHECKSUM: + irp->fd = chart_patch_file_checksum.fd; + chart_patch_file_checksum.active = true; + break; + + case SONG_DATA_FILE_TYPE_UNKNKOWN: + default: + LeaveCriticalSection(&chart_patch_lock); + /* other file, like *.2dx */ + return false; } log_misc("Data already prepared"); @@ -313,31 +489,21 @@ static bool chart_patch_file_trap(struct irp *irp) return true; } - if (is_1_file || is_checksum_file) { - wstr_narrow(chart_id, &tmp); - log_misc("Preparing in-memory chart %s...", tmp); - free(tmp); + if (file_type == SONG_DATA_FILE_TYPE_DOT_1 || file_type == SONG_DATA_FILE_TYPE_CHECKSUM) { + log_misc("Preparing in-memory chart data for song ID %S...", song_id); - wsprintfW( - buffer_1_path, - L"..\\data\\sd_data\\\\%s\\%s.1", - chart_id, - chart_id); - wsprintfW( - buffer_checksum_path, - L"..\\data\\sd_data\\%s\\osprey.bin", - chart_id); + chart_patch_get_song_chart_file_name(song_id, chart_file_name); + chart_patch_get_path_dot_1_file(song_id, path_format, buffer_1_path); + chart_patch_get_path_checksum_file(song_id, path_format, buffer_checksum_path); if (!chart_patch_file_load( irp, &chart_patch_file_1, buffer_1_path)) { - wstr_narrow(buffer_1_path, &tmp); - log_fatal("Cannot load .1 file %s", tmp); - free(tmp); + log_fatal("Cannot load .1 file %S", buffer_1_path); } chart_patch_execute_patch_1(); - wstr_narrow(chart_file, &tmp); + wstr_narrow(chart_file_name, &tmp); memcpy( chart_patch_file_1_name, tmp, sizeof(chart_patch_file_1_name)); free(tmp); @@ -349,19 +515,24 @@ static bool chart_patch_file_trap(struct irp *irp) } /* Return dummy handle */ - if (is_1_file) { - irp->fd = chart_patch_file_1.fd; - chart_patch_file_1.active = true; - } else if (is_checksum_file) { - irp->fd = chart_patch_file_checksum.fd; - chart_patch_file_checksum.active = true; - } else { - log_fatal("Illegal state 2"); + switch (file_type) { + case SONG_DATA_FILE_TYPE_DOT_1: + irp->fd = chart_patch_file_1.fd; + chart_patch_file_1.active = true; + break; + + case SONG_DATA_FILE_TYPE_CHECKSUM: + irp->fd = chart_patch_file_checksum.fd; + chart_patch_file_checksum.active = true; + break; + + case SONG_DATA_FILE_TYPE_UNKNKOWN: + default: + log_fatal("Illegal state 2"); + break; } - wstr_narrow(chart_id, &tmp); - log_misc("Patch for %s prepared in memory", tmp); - free(tmp); + log_misc("Chart patch for song ID %S prepared in memory", song_id); chart_patch_file_detour = true; -- 2.54.0 From 77934d74952bf27ac7e10c74c6327d559358c9bf Mon Sep 17 00:00:00 2001 From: icex2 Date: Tue, 21 Mar 2023 23:37:01 +0100 Subject: [PATCH 15/38] 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, }; -- 2.54.0 From c62f1d806569557c943d0b7928633f95cb065f8f Mon Sep 17 00:00:00 2001 From: icex2 Date: Sat, 1 Apr 2023 20:47:37 +0200 Subject: [PATCH 16/38] feat(iidx19): imagefs override strategy with local file redir --- src/imports/avs.h | 1 + src/imports/import_32_1304_avs.def | 3 +- src/main/iidxhook5/Module.mk | 1 + src/main/iidxhook5/dllmain.c | 4 ++ src/main/iidxhook5/ifs-snd-redir.c | 64 ++++++++++++++++++++++++++++++ src/main/iidxhook5/ifs-snd-redir.h | 12 ++++++ 6 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 src/main/iidxhook5/ifs-snd-redir.c create mode 100644 src/main/iidxhook5/ifs-snd-redir.h diff --git a/src/imports/avs.h b/src/imports/avs.h index 5b23183..ff48a33 100644 --- a/src/imports/avs.h +++ b/src/imports/avs.h @@ -231,6 +231,7 @@ void property_node_datasize(struct property_node *node); bool std_getenv(const char *key, char *val, uint32_t nbytes); void std_setenv(const char *key, const char *val); +void* avs_fs_open(const char* path, int mode, int flags); int avs_fs_addfs(void *filesys_struct); int avs_fs_mount( const char *mountpoint, const char *fsroot, const char *fstype, void *data); diff --git a/src/imports/import_32_1304_avs.def b/src/imports/import_32_1304_avs.def index 2dea570..489944a 100644 --- a/src/imports/import_32_1304_avs.def +++ b/src/imports/import_32_1304_avs.def @@ -2,6 +2,7 @@ LIBRARY libavs-win32 EXPORTS avs_boot @237 NONAME + avs_fs_open @178 NONAME avs_net_ctrl @15 NONAME avs_shutdown @333 NONAME avs_thread_create @183 NONAME @@ -25,4 +26,4 @@ EXPORTS property_read_query_memsize @100 NONAME property_search @244 NONAME std_getenv @226 NONAME - std_setenv @114 NONAME + std_setenv @114 NONAME diff --git a/src/main/iidxhook5/Module.mk b/src/main/iidxhook5/Module.mk index f41c0b3..78ea307 100644 --- a/src/main/iidxhook5/Module.mk +++ b/src/main/iidxhook5/Module.mk @@ -25,3 +25,4 @@ libs_iidxhook5 := \ src_iidxhook5 := \ dllmain.c \ + ifs-snd-redir.c \ diff --git a/src/main/iidxhook5/dllmain.c b/src/main/iidxhook5/dllmain.c index 7a03321..268bf39 100644 --- a/src/main/iidxhook5/dllmain.c +++ b/src/main/iidxhook5/dllmain.c @@ -40,6 +40,8 @@ #include "util/str.h" #include "util/thread.h" +#include "ifs-snd-redir.h" + #define IIDXHOOK5_INFO_HEADER \ "iidxhook for Lincle" \ ", build " __DATE__ " " __TIME__ ", gitrev " STRINGIFY(GITREV) @@ -179,6 +181,8 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) ezusb2_emu_device_hook_init(ezusb2_iidx_emu_msg_init()); } + iidxhook5_ifs_snd_redir_init(); + /* Card reader emulation, same issue with hooking as IO emulation */ rs232_hook_init(); diff --git a/src/main/iidxhook5/ifs-snd-redir.c b/src/main/iidxhook5/ifs-snd-redir.c new file mode 100644 index 0000000..f4809bf --- /dev/null +++ b/src/main/iidxhook5/ifs-snd-redir.c @@ -0,0 +1,64 @@ +#define LOG_MODULE "ifs-snd-redir" + +#include +#include + +#include "hook/table.h" + +#include "imports/avs.h" + +#include "iidxhook5/ifs-snd-redir.h" + +#include "util/log.h" +#include "util/str.h" + +static void* (*real_avs_fs_open)(const char* path, int mode, int flags); +static void* my_avs_fs_open(const char* path, int mode, int flags); + +static const struct hook_symbol iidxhook5_ifs_snd_redir_hook_syms[] = { + {.name = "XC058ba50000b6", // avs_fs_open + .patch = my_avs_fs_open, + .link = (void **) &real_avs_fs_open}, +}; + +static void* my_avs_fs_open(const char* path, int mode, int flags) +{ + void* handle; + char redir_path[MAX_PATH]; + + // Trap virtual path /sd00/*, /sd01/*, /sd02/*, /sd03/* that contain + // sound data that is stored in ifs files in data/imagefs + // Create a generice override strategy by redirecting to local folder + // /sound/*. Check if open succeeds and return that. Otherwise, stay on + // imagefs path to stay compatible with stock data. + + if (!strncmp(path, "/sd0", 4)) { + strcpy(redir_path, "/data/sound"); + strcat(redir_path, &path[5]); + + log_misc("Sound data redirect: %s -> %s", path, redir_path); + + handle = real_avs_fs_open(redir_path, mode, flags); + + if (handle != NULL) { + log_misc("Success, use %s", redir_path); + return handle; + } else { + log_misc("Failure, use %s", path); + return real_avs_fs_open(path, mode, flags); + } + } + + return real_avs_fs_open(path, mode, flags); +} + +void iidxhook5_ifs_snd_redir_init() +{ + hook_table_apply( + NULL, + "libavs-win32.dll", + iidxhook5_ifs_snd_redir_hook_syms, + lengthof(iidxhook5_ifs_snd_redir_hook_syms)); + + log_info("Inserted ifs-snd-redir hooks"); +} diff --git a/src/main/iidxhook5/ifs-snd-redir.h b/src/main/iidxhook5/ifs-snd-redir.h new file mode 100644 index 0000000..e649081 --- /dev/null +++ b/src/main/iidxhook5/ifs-snd-redir.h @@ -0,0 +1,12 @@ +#ifndef IIDXHOOK5_IFS_SND_REDIR_H +#define IIDXHOOK5_IFS_SND_REDIR_H + +/** + * Redirect any reads from the ifs files in data/imagefs that contain + * sound data to local files in data/sound. Required to enable bemanitools + * monitor-check feature to trap open calls to all sound data and apply + * different monitor refresh values. + */ +void iidxhook5_ifs_snd_redir_init(); + +#endif -- 2.54.0 From 6d67a5a81ca4e8f0721cef43e2fe780da9197495 Mon Sep 17 00:00:00 2001 From: icex2 Date: Thu, 30 Mar 2023 21:14:49 +0200 Subject: [PATCH 17/38] chore(doc): Re-structure, separate dev journals --- .../2018-02-10-logging-breakdown-avs.md} | 0 .../2019-07-29-c02-driver-on-w7-crash.md} | 0 .../2019-10-07-iidx-gfx-rendering-loops.md} | 0 .../2020-12-16-acio-bio2-iidx-package-dump.md} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename doc/dev/{logging-breakdown-avs.md => journal/2018-02-10-logging-breakdown-avs.md} (100%) rename doc/dev/{c02-driver-on-w7-crash.md => journal/2019-07-29-c02-driver-on-w7-crash.md} (100%) rename doc/dev/{iidx-gfx-rendering-loops.md => journal/2019-10-07-iidx-gfx-rendering-loops.md} (100%) rename doc/dev/{acio-bio2-iidx-package-dump.md => journal/2020-12-16-acio-bio2-iidx-package-dump.md} (100%) diff --git a/doc/dev/logging-breakdown-avs.md b/doc/dev/journal/2018-02-10-logging-breakdown-avs.md similarity index 100% rename from doc/dev/logging-breakdown-avs.md rename to doc/dev/journal/2018-02-10-logging-breakdown-avs.md diff --git a/doc/dev/c02-driver-on-w7-crash.md b/doc/dev/journal/2019-07-29-c02-driver-on-w7-crash.md similarity index 100% rename from doc/dev/c02-driver-on-w7-crash.md rename to doc/dev/journal/2019-07-29-c02-driver-on-w7-crash.md diff --git a/doc/dev/iidx-gfx-rendering-loops.md b/doc/dev/journal/2019-10-07-iidx-gfx-rendering-loops.md similarity index 100% rename from doc/dev/iidx-gfx-rendering-loops.md rename to doc/dev/journal/2019-10-07-iidx-gfx-rendering-loops.md diff --git a/doc/dev/acio-bio2-iidx-package-dump.md b/doc/dev/journal/2020-12-16-acio-bio2-iidx-package-dump.md similarity index 100% rename from doc/dev/acio-bio2-iidx-package-dump.md rename to doc/dev/journal/2020-12-16-acio-bio2-iidx-package-dump.md -- 2.54.0 From 09f9f458118881d110d64634e840ef7d16dcbede Mon Sep 17 00:00:00 2001 From: icex2 Date: Thu, 30 Mar 2023 23:16:36 +0200 Subject: [PATCH 18/38] chore: Move and convert from gitlab templates to github templates --- .../Bug.md => .github/ISSUE_TEMPLATE/bug.md | 19 +++++++++++++ .../ISSUE_TEMPLATE/feature.md | 7 +++++ .../PULL_REQUEST_TEMPLATE/pull-request.md | 8 ++++++ .gitlab/merge_request_templates/Feature.md | 27 ------------------- 4 files changed, 34 insertions(+), 27 deletions(-) rename .gitlab/issue_templates/Bug.md => .github/ISSUE_TEMPLATE/bug.md (98%) rename .gitlab/issue_templates/Feature.md => .github/ISSUE_TEMPLATE/feature.md (94%) rename .gitlab/merge_request_templates/Bugfix.md => .github/PULL_REQUEST_TEMPLATE/pull-request.md (98%) delete mode 100644 .gitlab/merge_request_templates/Feature.md diff --git a/.gitlab/issue_templates/Bug.md b/.github/ISSUE_TEMPLATE/bug.md similarity index 98% rename from .gitlab/issue_templates/Bug.md rename to .github/ISSUE_TEMPLATE/bug.md index f108362..8b47472 100644 --- a/.gitlab/issue_templates/Bug.md +++ b/.github/ISSUE_TEMPLATE/bug.md @@ -1,17 +1,24 @@ +# Bug report + ## Summary + ## Expected behavior + ## Current behavior + ## Detailed Description + ## Steps to reproduce + @@ -21,17 +28,23 @@ necessary --> 4. ## Possible solution + ## Context (Environment) + ### Bemanitools version(s) affected + * ### Game(s) and version(s) affected + * ### Log output + See attachment. + ### Configuration files + See attachment. + ### Command line arguments + ### APIs used + * ### OS version + ### Hardware specs + * CPU: * RAM: * GPU: diff --git a/.gitlab/issue_templates/Feature.md b/.github/ISSUE_TEMPLATE/feature.md similarity index 94% rename from .gitlab/issue_templates/Feature.md rename to .github/ISSUE_TEMPLATE/feature.md index de02dba..00ed2ee 100644 --- a/.gitlab/issue_templates/Feature.md +++ b/.github/ISSUE_TEMPLATE/feature.md @@ -1,14 +1,21 @@ +# Feature request + ## Summary + ## Detailed description + ## Benefits + ## Drawbacks + ## Current blockers + \ No newline at end of file diff --git a/.gitlab/merge_request_templates/Bugfix.md b/.github/PULL_REQUEST_TEMPLATE/pull-request.md similarity index 98% rename from .gitlab/merge_request_templates/Bugfix.md rename to .github/PULL_REQUEST_TEMPLATE/pull-request.md index 1059349..c2dd541 100644 --- a/.gitlab/merge_request_templates/Bugfix.md +++ b/.github/PULL_REQUEST_TEMPLATE/pull-request.md @@ -1,23 +1,31 @@ +# Pull request + ## Summary + ## Description + ## Related Issue + ## How Has This Been Tested? + ## Checklist + + * [ ] Implemented (unit) test(s) which prove that the introduced changes are working as expected. * Tested with the following games: * [ ] ... diff --git a/.gitlab/merge_request_templates/Feature.md b/.gitlab/merge_request_templates/Feature.md deleted file mode 100644 index 1059349..0000000 --- a/.gitlab/merge_request_templates/Feature.md +++ /dev/null @@ -1,27 +0,0 @@ -## Summary - - -## Description - - -## Related Issue - - - - - -## How Has This Been Tested? - - - - -## Checklist - - -* [ ] Implemented (unit) test(s) which prove that the introduced changes are working as expected. -* Tested with the following games: - * [ ] ... - * [ ] ... -* [ ] Followed the developer (style) guidelines. -* [ ] Updated existing doc of or add new doc to README file(s). -* [ ] Updated development documentation. \ No newline at end of file -- 2.54.0 From 4c8cd662124be03970bb025c44c785f697cec90e Mon Sep 17 00:00:00 2001 From: icex2 Date: Sun, 2 Apr 2023 01:25:23 +0200 Subject: [PATCH 19/38] fix(iidx/ezusb2): Fix IO buffer inconsistency/random input misfiring --- src/main/ezusb2-iidx-emu/msg.c | 86 ++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 36 deletions(-) diff --git a/src/main/ezusb2-iidx-emu/msg.c b/src/main/ezusb2-iidx-emu/msg.c index a1d4be6..d6600f3 100644 --- a/src/main/ezusb2-iidx-emu/msg.c +++ b/src/main/ezusb2-iidx-emu/msg.c @@ -64,65 +64,72 @@ struct ezusb_emu_msg_hook *ezusb2_iidx_emu_msg_init(void) static HRESULT ezusb2_iidx_emu_msg_interrupt_read(struct iobuf *read) { - struct ezusb2_iidx_msg_interrupt_read_packet *msg_resp = - (struct ezusb2_iidx_msg_interrupt_read_packet *) read->bytes; + struct ezusb2_iidx_msg_interrupt_read_packet msg_resp; if (!iidx_io_ep2_recv()) { return E_FAIL; } - msg_resp->p1_turntable = iidx_io_ep2_get_turntable(0); - msg_resp->p2_turntable = iidx_io_ep2_get_turntable(1); + memset(&msg_resp, 0, sizeof(msg_resp)); - msg_resp->sliders[0] = + msg_resp.p1_turntable = iidx_io_ep2_get_turntable(0); + msg_resp.p2_turntable = iidx_io_ep2_get_turntable(1); + + msg_resp.sliders[0] = iidx_io_ep2_get_slider(0) | (iidx_io_ep2_get_slider(1) << 4); - msg_resp->sliders[1] = + msg_resp.sliders[1] = iidx_io_ep2_get_slider(2) | (iidx_io_ep2_get_slider(3) << 4); - msg_resp->sliders[2] = iidx_io_ep2_get_slider(4); + msg_resp.sliders[2] = iidx_io_ep2_get_slider(4); - msg_resp->inverted_pad = ((iidx_io_ep2_get_keys() & 0x3FFF) << 16) | + msg_resp.inverted_pad = ((iidx_io_ep2_get_keys() & 0x3FFF) << 16) | (iidx_io_ep2_get_panel() & 0x0F) | ((iidx_io_ep2_get_sys() & 0x03) << 4) | (((iidx_io_ep2_get_sys() >> 2) & 0x01) << 30); - msg_resp->inverted_pad = ~msg_resp->inverted_pad; + msg_resp.inverted_pad = ~msg_resp.inverted_pad; - msg_resp->status = ezusb2_iidx_emu_msg_status; + msg_resp.status = ezusb2_iidx_emu_msg_status; /* Reset status after delivered (important for eeprom reading) */ ezusb2_iidx_emu_msg_status = 0; - msg_resp->seq_no = ezusb2_iidx_emu_msg_seq_no++; + msg_resp.seq_no = ezusb2_iidx_emu_msg_seq_no++; - read->pos = sizeof(*msg_resp); + // Single write to external/game managed buffer to reduce risk for + // inconsistent state + memcpy(read->bytes, &msg_resp, sizeof(msg_resp)); + read->pos = sizeof(msg_resp); return S_OK; } static HRESULT ezusb2_iidx_emu_msg_interrupt_write(struct const_iobuf *write) { - const struct ezusb2_iidx_msg_interrupt_write_packet *msg_req = - (const struct ezusb2_iidx_msg_interrupt_write_packet *) write->bytes; + struct ezusb2_iidx_msg_interrupt_write_packet msg_req; - if (write->nbytes < sizeof(*msg_req)) { + if (write->nbytes < sizeof(msg_req)) { log_warning("Interrupt write message too small"); return E_INVALIDARG; } - if (!ezusb2_iidx_emu_msg_nodes[msg_req->node]) { + // Single read from external/game managed buffer to reduce risk for + // inconsistent state + memcpy(&msg_req, write->bytes, sizeof(msg_req)); + + if (!ezusb2_iidx_emu_msg_nodes[msg_req.node]) { ezusb2_iidx_emu_msg_read_cur_node = 0; log_warning( - "Unrecognised node in interrupt message: %02x", msg_req->node); + "Unrecognised node in interrupt message: %02x", msg_req.node); return E_INVALIDARG; } - iidx_io_ep1_set_deck_lights(msg_req->deck_lights); - iidx_io_ep1_set_panel_lights(msg_req->panel_lights); - iidx_io_ep1_set_top_lamps(msg_req->top_lamps); - iidx_io_ep1_set_top_neons(msg_req->top_neons); + iidx_io_ep1_set_deck_lights(msg_req.deck_lights); + iidx_io_ep1_set_panel_lights(msg_req.panel_lights); + iidx_io_ep1_set_top_lamps(msg_req.top_lamps); + iidx_io_ep1_set_top_neons(msg_req.top_neons); if (!iidx_io_ep1_send()) { return E_FAIL; @@ -131,31 +138,32 @@ static HRESULT ezusb2_iidx_emu_msg_interrupt_write(struct const_iobuf *write) /* 16seg data is provided with the request and not handled using a separate bulk endpoint like on the C02 IO board */ - if (!iidx_io_ep3_write_16seg((const char *) msg_req->seg16)) { + if (!iidx_io_ep3_write_16seg((const char *) msg_req.seg16)) { return E_FAIL; } /* Remember node for next bulk read */ - ezusb2_iidx_emu_msg_read_cur_node = msg_req->node; + ezusb2_iidx_emu_msg_read_cur_node = msg_req.node; ezusb2_iidx_emu_msg_status = - ezusb2_iidx_emu_msg_nodes[msg_req->node]->process_cmd( - msg_req->cmd, msg_req->cmd_detail[0], msg_req->cmd_detail[1]); + ezusb2_iidx_emu_msg_nodes[msg_req.node]->process_cmd( + msg_req.cmd, msg_req.cmd_detail[0], msg_req.cmd_detail[1]); return S_OK; } static HRESULT ezusb2_iidx_emu_msg_bulk_read(struct iobuf *read) { - struct ezusb_iidx_msg_bulk_packet *pkt = - (struct ezusb_iidx_msg_bulk_packet *) read->bytes; + struct ezusb_iidx_msg_bulk_packet pkt; - if (read->nbytes < sizeof(*pkt)) { + if (read->nbytes < sizeof(pkt)) { log_warning("Bulk read buffer too small"); return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); } + memset(&pkt, 0, sizeof(pkt)); + if (!ezusb2_iidx_emu_msg_nodes[ezusb2_iidx_emu_msg_read_cur_node]) { log_warning( "Bulk read unsupported on cur_node = %d", @@ -165,33 +173,39 @@ static HRESULT ezusb2_iidx_emu_msg_bulk_read(struct iobuf *read) } if (!ezusb2_iidx_emu_msg_nodes[ezusb2_iidx_emu_msg_read_cur_node] - ->read_packet(pkt)) { + ->read_packet(&pkt)) { return E_FAIL; } - read->pos = sizeof(*pkt); + // Single write to external/game managed buffer to reduce risk for + // inconsistent state + memcpy(read->bytes, &pkt, sizeof(pkt)); + read->pos = sizeof(pkt); return S_OK; } static HRESULT ezusb2_iidx_emu_msg_bulk_write(struct const_iobuf *write) { - const struct ezusb_iidx_msg_bulk_packet *pkt = - (const struct ezusb_iidx_msg_bulk_packet *) write->bytes; + struct ezusb_iidx_msg_bulk_packet pkt; - if (write->nbytes < sizeof(*pkt)) { + if (write->nbytes < sizeof(pkt)) { log_warning("Bulk write packet too small"); return E_INVALIDARG; } - if (!ezusb2_iidx_emu_msg_nodes[pkt->node]) { - log_warning("Bulk write not supported on pkt->node = %02x", pkt->node); + // Single read from external/game managed buffer to reduce risk for + // inconsistent state + memcpy(&pkt, write->bytes, sizeof(pkt)); + + if (!ezusb2_iidx_emu_msg_nodes[pkt.node]) { + log_warning("Bulk write not supported on pkt->node = %02x", pkt.node); return E_NOTIMPL; } - if (!ezusb2_iidx_emu_msg_nodes[pkt->node]->write_packet(pkt)) { + if (!ezusb2_iidx_emu_msg_nodes[pkt.node]->write_packet(&pkt)) { return E_FAIL; } -- 2.54.0 From ca71789f534cd99a3b189c3d52fa73b9d84ce6a5 Mon Sep 17 00:00:00 2001 From: icex2 Date: Thu, 30 Mar 2023 23:23:29 +0200 Subject: [PATCH 20/38] fix(jb/p3io): Fix IO buffer inconsistency/random input misfiring --- src/main/jbhook-util-p3io/p3io.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/jbhook-util-p3io/p3io.c b/src/main/jbhook-util-p3io/p3io.c index 245fe2e..25b3364 100644 --- a/src/main/jbhook-util-p3io/p3io.c +++ b/src/main/jbhook-util-p3io/p3io.c @@ -111,12 +111,13 @@ void jbhook_util_p3io_fini(void) static HRESULT jbhook_p3io_read_jamma(void *ctx, uint32_t *state) { + uint32_t state_tmp; uint16_t panels; uint8_t buttons; log_assert(state != NULL); - *state = 0; + state_tmp = 0; if (!jb_io_read_inputs()) { log_warning("Reading inputs from jbio failed"); @@ -129,28 +130,35 @@ static HRESULT jbhook_p3io_read_jamma(void *ctx, uint32_t *state) for (uint8_t i = 0; i < 16; i++) { // panels are active-low if ((panels & (1 << i)) == 0) { - *state |= jbhook_p3io_panel_mappings[i]; + state_tmp |= jbhook_p3io_panel_mappings[i]; } } for (uint8_t i = 0; i < 2; i++) { // sys buttons are active-high if (buttons & (1 << i)) { - *state |= jbhook_p3io_sys_button_mappings[i]; + state_tmp |= jbhook_p3io_sys_button_mappings[i]; } } + // Single write to external/game managed buffer to reduce risk for + // inconsistent state/random input misfiring + *state = state_tmp; + return S_OK; } static HRESULT jbhook_p3io_get_roundplug( void *ctx, uint8_t plug_id, uint8_t *rom, uint8_t *eeprom) { + uint8_t rom_out[sizeof(jbhook_p3io_pcbid.id)]; struct security_rp3_eeprom eeprom_out; + log_assert(sizeof(jbhook_p3io_pcbid.id) == sizeof(jbhook_p3io_eamid.id)); + if (plug_id == 0) { /* black */ - memcpy(rom, jbhook_p3io_pcbid.id, sizeof(jbhook_p3io_pcbid.id)); + memcpy(rom_out, jbhook_p3io_pcbid.id, sizeof(jbhook_p3io_pcbid.id)); security_rp3_generate_signed_eeprom_data( SECURITY_RP_UTIL_RP_TYPE_BLACK, &security_rp_sign_key_black_gfdmv4, @@ -159,7 +167,7 @@ static HRESULT jbhook_p3io_get_roundplug( &eeprom_out); } else { /* white */ - memcpy(rom, jbhook_p3io_eamid.id, sizeof(jbhook_p3io_eamid.id)); + memcpy(rom_out, jbhook_p3io_eamid.id, sizeof(jbhook_p3io_eamid.id)); security_rp3_generate_signed_eeprom_data( SECURITY_RP_UTIL_RP_TYPE_WHITE, &security_rp_sign_key_white_eamuse, @@ -168,6 +176,9 @@ static HRESULT jbhook_p3io_get_roundplug( &eeprom_out); } + // Single write to external/game managed buffer to reduce risk for + // inconsistent state + memcpy(rom, &rom_out, sizeof(rom_out)); memcpy(eeprom, &eeprom_out, sizeof(struct security_rp3_eeprom)); return S_OK; -- 2.54.0 From de1d90925a4960d51e520a507397062c439e24b0 Mon Sep 17 00:00:00 2001 From: icex2 Date: Thu, 30 Mar 2023 23:34:17 +0200 Subject: [PATCH 21/38] fix(jb/p4io): Fix IO buffer inconsistency/random input misfiring --- src/main/jbhook-util/p4io.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/jbhook-util/p4io.c b/src/main/jbhook-util/p4io.c index 433e7e3..ab77d5d 100644 --- a/src/main/jbhook-util/p4io.c +++ b/src/main/jbhook-util/p4io.c @@ -90,12 +90,12 @@ static const uint32_t jbhook_io_sys_button_mappings[] = { static void jbhook_io_jamma2_read(void *resp, uint32_t nbytes) { - uint32_t *inputs = (uint32_t *) resp; + uint32_t inputs_out; uint16_t panels; uint8_t buttons; /* lower three bytes low active, highest byte high active */ - *inputs = 0x00FFFFFF; + inputs_out = 0x00FFFFFF; if (!jb_io_read_inputs()) { log_warning("Reading inputs from jbio failed"); @@ -107,15 +107,19 @@ static void jbhook_io_jamma2_read(void *resp, uint32_t nbytes) for (uint8_t i = 0; i < 16; i++) { if (panels & (1 << i)) { - *inputs &= ~jbhook_io_panel_mappings[i]; + inputs_out &= ~jbhook_io_panel_mappings[i]; } } for (uint8_t i = 0; i < 3; i++) { if (buttons & (1 << i)) { - *inputs |= jbhook_io_sys_button_mappings[i]; + inputs_out |= jbhook_io_sys_button_mappings[i]; } } + + // Single write to external/game managed buffer to reduce risk for + // inconsistent state/random input misfiring + *((uint32_t *) resp) = inputs_out; } static uint32_t jbhook_command_handle( -- 2.54.0 From 633fac81fbf8a401055846c5619e196d650e8b81 Mon Sep 17 00:00:00 2001 From: icex2 Date: Thu, 30 Mar 2023 23:43:23 +0200 Subject: [PATCH 22/38] fix(pnm/ezusb2-emu): Fix IO buffer inconsistency/random input misfiring --- src/main/ezusb2-popn-emu/msg.c | 100 ++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 44 deletions(-) diff --git a/src/main/ezusb2-popn-emu/msg.c b/src/main/ezusb2-popn-emu/msg.c index 1c4e3fb..bc73ff0 100644 --- a/src/main/ezusb2-popn-emu/msg.c +++ b/src/main/ezusb2-popn-emu/msg.c @@ -76,90 +76,96 @@ struct ezusb_emu_msg_hook *ezusb2_popn_emu_msg_init(void) static HRESULT ezusb2_popn_emu_msg_interrupt_read(struct iobuf *read) { - struct ezusb2_popn_msg_interrupt_read_packet *msg_resp = - (struct ezusb2_popn_msg_interrupt_read_packet *) read->bytes; + struct ezusb2_popn_msg_interrupt_read_packet msg_resp; - memset(msg_resp, 0, sizeof(*msg_resp)); + memset(&msg_resp, 0, sizeof(msg_resp)); - msg_resp->unk0 = 0x03; - msg_resp->unk1 = 0x1d; - msg_resp->unk2 = 0x85; - msg_resp->seq_no = ezusb2_popn_emu_msg_seq_no++; - msg_resp->status = ezusb2_popn_emu_msg_status; - msg_resp->unk3 = 0x00; - msg_resp->coin_count = 0; - msg_resp->unk4 = 0xfd; + msg_resp.unk0 = 0x03; + msg_resp.unk1 = 0x1d; + msg_resp.unk2 = 0x85; + msg_resp.seq_no = ezusb2_popn_emu_msg_seq_no++; + msg_resp.status = ezusb2_popn_emu_msg_status; + msg_resp.unk3 = 0x00; + msg_resp.coin_count = 0; + msg_resp.unk4 = 0xfd; - msg_resp->io.inverted_pad = ~popn_io_get_buttons(); + msg_resp.io.inverted_pad = ~popn_io_get_buttons(); - msg_resp->unk5 = 0x00; - msg_resp->unk6 = 0x7d; - msg_resp->unk7 = 0xdf; - msg_resp->unk8 = ezusb2_popn_emu_msg_seq_no; + msg_resp.unk5 = 0x00; + msg_resp.unk6 = 0x7d; + msg_resp.unk7 = 0xdf; + msg_resp.unk8 = ezusb2_popn_emu_msg_seq_no; memcpy( - &msg_resp->button_history[0], + &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); - ezusb2_popn_emu_msg_history[0] = msg_resp->io.button; + ezusb2_popn_emu_msg_history[0] = msg_resp.io.button; + + // Single write to external/game managed buffer to reduce risk for + // inconsistent state/random input misfiring + memcpy(read->bytes, &msg_resp, sizeof(msg_resp)); + read->pos = sizeof(msg_resp); return S_OK; } static HRESULT ezusb2_popn_emu_msg_interrupt_write(struct const_iobuf *write) { - const struct ezusb2_popn_msg_interrupt_write_packet *msg_req = - (const struct ezusb2_popn_msg_interrupt_write_packet *) write->bytes; + struct ezusb2_popn_msg_interrupt_write_packet msg_req; - if (write->nbytes < sizeof(*msg_req)) { + if (write->nbytes < sizeof(msg_req)) { log_warning("Interrupt write message too small"); return E_INVALIDARG; } - if (!ezusb2_popn_emu_msg_nodes[msg_req->node]) { + // Single read from external/game managed buffer to reduce risk for + // inconsistent state + memcpy(&msg_req, write->bytes, sizeof(msg_req)); + + if (!ezusb2_popn_emu_msg_nodes[msg_req.node]) { ezusb2_popn_emu_msg_read_cur_node = 0; log_warning( - "Unrecognised node in interrupt message: %02x", msg_req->node); + "Unrecognised node in interrupt message: %02x", msg_req.node); return E_INVALIDARG; } - 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_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_blocker_light(((msg_req->lamp >> 16) & 0xf) == 0xf); + ((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 */ - ezusb2_popn_emu_msg_read_cur_node = msg_req->node; + ezusb2_popn_emu_msg_read_cur_node = msg_req.node; ezusb2_popn_emu_msg_status = - ezusb2_popn_emu_msg_nodes[msg_req->node]->process_cmd( - msg_req->cmd, msg_req->cmd_detail[0], msg_req->cmd_detail[1]); + ezusb2_popn_emu_msg_nodes[msg_req.node]->process_cmd( + msg_req.cmd, msg_req.cmd_detail[0], msg_req.cmd_detail[1]); return S_OK; } static HRESULT ezusb2_popn_emu_msg_bulk_read(struct iobuf *read) { - struct ezusb_iidx_msg_bulk_packet *pkt = - (struct ezusb_iidx_msg_bulk_packet *) read->bytes; + struct ezusb_iidx_msg_bulk_packet pkt; - if (read->nbytes < sizeof(*pkt)) { + if (read->nbytes < sizeof(pkt)) { log_warning("Bulk read buffer too small"); return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); } + + if (!ezusb2_popn_emu_msg_nodes[ezusb2_popn_emu_msg_read_cur_node]) { log_warning( "Bulk read unsupported on cur_node = %d", @@ -169,33 +175,39 @@ static HRESULT ezusb2_popn_emu_msg_bulk_read(struct iobuf *read) } if (!ezusb2_popn_emu_msg_nodes[ezusb2_popn_emu_msg_read_cur_node] - ->read_packet(pkt)) { + ->read_packet(&pkt)) { return E_FAIL; } - read->pos = sizeof(*pkt); + // Single write to external/game managed buffer to reduce risk for + // inconsistent state + memcpy(&pkt, read->bytes, sizeof(pkt)); + read->pos = sizeof(pkt); return S_OK; } static HRESULT ezusb2_popn_emu_msg_bulk_write(struct const_iobuf *write) { - const struct ezusb_iidx_msg_bulk_packet *pkt = - (const struct ezusb_iidx_msg_bulk_packet *) write->bytes; + struct ezusb_iidx_msg_bulk_packet pkt; - if (write->nbytes < sizeof(*pkt)) { + if (write->nbytes < sizeof(pkt)) { log_warning("Bulk write packet too small"); return E_INVALIDARG; } - if (!ezusb2_popn_emu_msg_nodes[pkt->node]) { - log_warning("Bulk write not supported on pkt->node = %02x", pkt->node); + // Single read from external/game managed buffer to reduce risk for + // inconsistent state + memcpy(&pkt, write->bytes, sizeof(pkt)); + + if (!ezusb2_popn_emu_msg_nodes[pkt.node]) { + log_warning("Bulk write not supported on pkt.node = %02x", pkt.node); return E_NOTIMPL; } - if (!ezusb2_popn_emu_msg_nodes[pkt->node]->write_packet(pkt)) { + if (!ezusb2_popn_emu_msg_nodes[pkt.node]->write_packet(&pkt)) { return E_FAIL; } -- 2.54.0 From 12594289c812060eaae7c1c33ddbd3a790f97642 Mon Sep 17 00:00:00 2001 From: icex2 Date: Sun, 2 Apr 2023 01:39:00 +0200 Subject: [PATCH 23/38] feat(iidx 9-13): Wire up coin mech to IO emulation --- src/main/ezusb-iidx-emu/msg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/ezusb-iidx-emu/msg.c b/src/main/ezusb-iidx-emu/msg.c index d85bc88..66615ab 100644 --- a/src/main/ezusb-iidx-emu/msg.c +++ b/src/main/ezusb-iidx-emu/msg.c @@ -126,7 +126,7 @@ static HRESULT ezusb_iidx_emu_msg_interrupt_read(struct iobuf *read) msg_resp->inverted_pad = ((iidx_io_ep2_get_keys() & 0x3FFF) << 8) | ((iidx_io_ep2_get_panel() & 0x0F) << 24) | - ((iidx_io_ep2_get_sys() & 0x03) << 28) | + ((iidx_io_ep2_get_sys() & 0x07) << 28) | (((iidx_io_ep2_get_sys() >> 2) & 0x01) << 22); /* make sure to update the current coin mode state, otherwise -- 2.54.0 From 72e8a593f14f839ef48d469769c562b3872d880c Mon Sep 17 00:00:00 2001 From: icex2 Date: Sun, 2 Apr 2023 01:39:37 +0200 Subject: [PATCH 24/38] feat(iidx 14-24): Wire up coin mech to IO emulation --- src/main/ezusb2-iidx-emu/msg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/ezusb2-iidx-emu/msg.c b/src/main/ezusb2-iidx-emu/msg.c index d6600f3..1279ea9 100644 --- a/src/main/ezusb2-iidx-emu/msg.c +++ b/src/main/ezusb2-iidx-emu/msg.c @@ -85,7 +85,7 @@ static HRESULT ezusb2_iidx_emu_msg_interrupt_read(struct iobuf *read) msg_resp.inverted_pad = ((iidx_io_ep2_get_keys() & 0x3FFF) << 16) | (iidx_io_ep2_get_panel() & 0x0F) | - ((iidx_io_ep2_get_sys() & 0x03) << 4) | + ((iidx_io_ep2_get_sys() & 0x07) << 4) | (((iidx_io_ep2_get_sys() >> 2) & 0x01) << 30); msg_resp.inverted_pad = ~msg_resp.inverted_pad; -- 2.54.0 From f7d76b95b48c3533af11adf57692a2c12db0149b Mon Sep 17 00:00:00 2001 From: icex2 Date: Sun, 2 Apr 2023 02:56:52 +0200 Subject: [PATCH 25/38] fix(iidx/ezusb2): Fix IO buffer inconsistency on ezusb device level --- src/main/ezusb2-emu/device.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/main/ezusb2-emu/device.c b/src/main/ezusb2-emu/device.c index c5d054f..797f24b 100644 --- a/src/main/ezusb2-emu/device.c +++ b/src/main/ezusb2-emu/device.c @@ -281,51 +281,57 @@ static HRESULT ezusb_ioctl_epX( static HRESULT ezusb_get_device_descriptor(struct iobuf *read) { - USB_DEVICE_DESCRIPTOR *desc; + USB_DEVICE_DESCRIPTOR desc; log_assert(read != NULL); - if (read->nbytes < sizeof(*desc)) { + if (read->nbytes < sizeof(desc)) { log_warning("USB_DEVICE_DESCRIPTOR buffer too small: %d", read->nbytes); return HRESULT_FROM_WIN32(ERROR_BUFFER_OVERFLOW); } - desc = (USB_DEVICE_DESCRIPTOR *) read->bytes; + memset(&desc, 0, sizeof(desc)); /* vid and pid checked, only */ - desc->idVendor = ezusb2_emu_desc_device.vid; - desc->idProduct = ezusb2_emu_desc_device.pid; + desc.idVendor = ezusb2_emu_desc_device.vid; + desc.idProduct = ezusb2_emu_desc_device.pid; log_misc( "get_device_descriptor: vid %02x, pid %02x", - desc->idVendor, - desc->idProduct); + desc.idVendor, + desc.idProduct); - read->pos = sizeof(*desc); + // Single write to external/game managed buffer to reduce risk for + // inconsistent state + memcpy(read->bytes, &desc, sizeof(desc)); + read->pos = sizeof(desc); return S_OK; } static HRESULT ezusb_get_string_descriptor(struct iobuf *read) { - struct ezusb_usb_string_desc *desc; + struct ezusb_usb_string_desc desc; log_assert(read != NULL); - if (read->nbytes < sizeof(*desc)) { + if (read->nbytes < sizeof(desc)) { log_warning("ezusb_usb_string_desc buffer too small: %d", read->nbytes); return HRESULT_FROM_WIN32(ERROR_BUFFER_OVERFLOW); } - desc = (struct ezusb_usb_string_desc *) read->bytes; + memset(&desc, 0, sizeof(desc)); - desc->length = sizeof(*desc); - desc->desc_type = 0x03; /* Usb spec says so */ - memcpy(desc->unicode_str, L"KONAMI", 12); /* Unicode encoding */ + desc.length = sizeof(desc); + desc.desc_type = 0x03; /* Usb spec says so */ + memcpy(desc.unicode_str, L"KONAMI", 12); /* Unicode encoding */ - read->pos = sizeof(*desc); + // Single write to external/game managed buffer to reduce risk for + // inconsistent state + memcpy(read->bytes, &desc, sizeof(desc)); + read->pos = sizeof(desc); log_misc("get_string_descriptor: KONAMI"); -- 2.54.0 From 9ad16d3a634e25d412889830d4352af97e46efab Mon Sep 17 00:00:00 2001 From: icex2 Date: Mon, 3 Apr 2023 01:04:42 +0200 Subject: [PATCH 26/38] feat(iidx/ezusb): Add ezusb api monitoring module Implement several functions relevant to the boot process with a focus on the security init part --- src/main/iidxhook1/Module.mk | 1 + src/main/iidxhook1/ezusb-mon.c | 228 +++++++++++++++++++++++++++++++++ src/main/iidxhook1/ezusb-mon.h | 12 ++ 3 files changed, 241 insertions(+) create mode 100644 src/main/iidxhook1/ezusb-mon.c create mode 100644 src/main/iidxhook1/ezusb-mon.h diff --git a/src/main/iidxhook1/Module.mk b/src/main/iidxhook1/Module.mk index 1606f6d..fcfad98 100644 --- a/src/main/iidxhook1/Module.mk +++ b/src/main/iidxhook1/Module.mk @@ -22,4 +22,5 @@ libs_iidxhook1 := \ src_iidxhook1 := \ config-iidxhook1.c \ dllmain.c \ + ezusb-mon.c \ log-ezusb.c \ diff --git a/src/main/iidxhook1/ezusb-mon.c b/src/main/iidxhook1/ezusb-mon.c new file mode 100644 index 0000000..e1e86a8 --- /dev/null +++ b/src/main/iidxhook1/ezusb-mon.c @@ -0,0 +1,228 @@ +#define LOG_MODULE "ezusb-mon" + +#include + +#include +#include +#include + +#include "hook/table.h" + +#include "iidxhook1/ezusb-mon.h" + +#include "util/defs.h" +#include "util/log.h" +#include "util/str.h" + +/* ------------------------------------------------------------------------- */ + +static int my_usbStart(int val); +static int my_usbSecurityInit(); +static int my_usbSecuritySelectDone(); +static int my_usbGetPCBID(char* buffer); +static int my_usbGetSecurity(char* buffer); +static int my_usbGetSecurityKey(char* buffer); +static int my_usbBootSecurity( + const char* boot_code, int seed_1, int seed_2, int seed_3); +static int my_usbSetupSecurityComplete(int val1, int val2, int val3, int val4); +static int my_usbMute(int val); +static int my_usbFirmResult(); + +static int (*real_usbStart)(int val); +static int (*real_usbSecurityInit)(); +static int (*real_usbSecuritySelectDone)(); +static int (*real_usbGetPCBID)(char* buffer); +static int (*real_usbGetSecurity)(char* buffer); +static int (*real_usbGetSecurityKey)(char* buffer); +static int (*real_usbBootSecurity)( + const char* boot_code, int seed_1, int seed_2, int seed_3); +static int (*real_usbSetupSecurityComplete)(int val1, int val2, int val3, int val4); +static int (*real_usbMute)(int val); +static int (*real_usbFirmResult)(); + +/* ------------------------------------------------------------------------- */ + +static const struct hook_symbol ezusb_mon_hook_syms[] = { + {.name = "usbStart", + .patch = my_usbStart, + .link = (void **) &real_usbStart}, + {.name = "usbSecurityInit", + .patch = my_usbSecurityInit, + .link = (void **) &real_usbSecurityInit}, + {.name = "usbSecuritySelectDone", + .patch = my_usbSecuritySelectDone, + .link = (void **) &real_usbSecuritySelectDone}, + {.name = "usbGetPCBID", + .patch = my_usbGetPCBID, + .link = (void **) &real_usbGetPCBID}, + {.name = "usbGetSecurity", + .patch = my_usbGetSecurity, + .link = (void **) &real_usbGetSecurity}, + {.name = "usbGetSecurity", + .patch = my_usbGetSecurity, + .link = (void **) &real_usbGetSecurity}, + {.name = "usbGetSecurityKey", + .patch = my_usbGetSecurityKey, + .link = (void **) &real_usbGetSecurityKey}, + {.name = "usbBootSecurity", + .patch = my_usbBootSecurity, + .link = (void **) &real_usbBootSecurity}, + {.name = "usbSetupSecurityComplete", + .patch = my_usbSetupSecurityComplete, + .link = (void **) &real_usbSetupSecurityComplete}, + {.name = "usbMute", + .patch = my_usbMute, + .link = (void **) &real_usbMute}, + {.name = "usbFirmResult", + .patch = my_usbFirmResult, + .link = (void **) &real_usbFirmResult}, +}; + +/* ------------------------------------------------------------------------- */ + +static int my_usbStart(int val) +{ + int res; + + log_misc("BEFORE usbStart, val %d", val); + + res = real_usbStart(val); + + log_misc("AFTER usbStart, res: %d", res); + + return res; +} + +static int my_usbSecurityInit() +{ + int res; + + log_misc("BEFORE usbSecurityInit"); + + res = real_usbSecurityInit(); + + log_misc("AFTER usbSecurityInit, res: %d", res); + + return res; +} + +static int my_usbSecuritySelectDone() +{ + int res; + + log_misc("BEFORE usbSecuritySelectDone"); + + res = real_usbSecuritySelectDone(); + + log_misc("AFTER usbSecuritySelectDone, res: %d", res); + + return res; +} + +static int my_usbGetPCBID(char* buffer) +{ + int res; + + log_misc("BEFORE usbGetPCBID, buffer %s", buffer); + + res = real_usbGetPCBID(buffer); + + log_misc("AFTER usbGetPCBID, res: %d, buffer %s", res, buffer); + + return res; +} + +static int my_usbGetSecurity(char* buffer) +{ + int res; + + log_misc("BEFORE usbGetSecurity, buffer %s", buffer); + + res = real_usbGetSecurity(buffer); + + log_misc("AFTER usbGetSecurity, res: %d, buffer %s", res, buffer); + + return res; +} + +static int my_usbGetSecurityKey(char* buffer) +{ + int res; + + log_misc("BEFORE usbGetSecurityKey, buffer %s", buffer); + + res = real_usbGetSecurityKey(buffer); + + log_misc("AFTER usbGetSecurityKey, res: %d, buffer %s", res, buffer); + + return res; +} + +static int my_usbBootSecurity( + const char* boot_code, int seed_1, int seed_2, int seed_3) +{ + int res; + + log_misc( + "BEFORE usbBootSecurity, boot_code %s, seed_1 %d, seed_2 %d, seed_3 %d", + boot_code, seed_1, seed_2, seed_3); + + res = real_usbBootSecurity(boot_code, seed_1, seed_2, seed_3); + + log_misc("AFTER usbBootSecurity, res: %d", res); + + return res; +} + +static int my_usbSetupSecurityComplete(int val1, int val2, int val3, int val4) +{ + int res; + + log_misc( + "BEFORE usbSetupSecurityComplete, val1 %d, val2 %d, val3 %d, val4 %d", + val1, val2, val3, val4); + + res = real_usbSetupSecurityComplete(val1, val2, val3, val4); + + log_misc("AFTER usbSetupSecurityComplete, res: %d", res); + + return res; +} + +static int my_usbMute(int val) +{ + int res; + + log_misc("BEFORE usbMute, val %d", val); + + res = real_usbMute(val); + + log_misc("AFTER usbMute, res: %d", res); + + return res; +} + +static int my_usbFirmResult() +{ + int res; + + res = real_usbFirmResult(); + + // Avoid log flood with constant polling of this API function as long as it + // keeps returning 96 + if (res != 96) { + log_misc("AFTER usbFirmResult, res (!= 96): %d", res); + } + + return res; +} + +/* ------------------------------------------------------------------------- */ + +void ezusb_mon_hook_init(void) +{ + hook_table_apply( + NULL, "ezusb.dll", ezusb_mon_hook_syms, lengthof(ezusb_mon_hook_syms)); + + log_info("Inserted ezusb mon hooks"); +} diff --git a/src/main/iidxhook1/ezusb-mon.h b/src/main/iidxhook1/ezusb-mon.h new file mode 100644 index 0000000..e0568ec --- /dev/null +++ b/src/main/iidxhook1/ezusb-mon.h @@ -0,0 +1,12 @@ +#ifndef IIDXHOOK_EZUSB_MON_H +#define IIDXHOOK_EZUSB_MON_H + +/** + * Monitor and log call traces of ezusb.dll calls. + * + * This only works on 9th and 10th Style that have the ezusb.dll linked + * dynamically. Any later version has the library linked staticly + */ +void ezusb_mon_hook_init(void); + +#endif -- 2.54.0 From b596d5e1845c9199aff0806367c4fe07069b2f03 Mon Sep 17 00:00:00 2001 From: icex2 Date: Mon, 3 Apr 2023 01:05:23 +0200 Subject: [PATCH 27/38] chore(dev): Fix incorrect log module header --- src/main/iidxhook1/log-ezusb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/iidxhook1/log-ezusb.c b/src/main/iidxhook1/log-ezusb.c index 60f71d8..ac71907 100644 --- a/src/main/iidxhook1/log-ezusb.c +++ b/src/main/iidxhook1/log-ezusb.c @@ -1,4 +1,4 @@ -#define LOG_MODULE "logger-hook" +#define LOG_MODULE "log-ezusb" #include -- 2.54.0 From b42cbdc4eab98b94ed0a41321e9d100da6484884 Mon Sep 17 00:00:00 2001 From: icex2 Date: Mon, 3 Apr 2023 01:06:19 +0200 Subject: [PATCH 28/38] fix(iidx/ezusb): Fix IO buffer inconsistency on ezusb ioctl level --- src/main/ezusb-emu/device.c | 122 ++++++++++++++++++++++++++++++------ 1 file changed, 104 insertions(+), 18 deletions(-) diff --git a/src/main/ezusb-emu/device.c b/src/main/ezusb-emu/device.c index 4a2c28c..0773f28 100644 --- a/src/main/ezusb-emu/device.c +++ b/src/main/ezusb-emu/device.c @@ -28,6 +28,10 @@ #include "util/log.h" #include "util/str.h" +// The max buffer size in iidx's ezusb client library is 4096 for the initial +// firmware download. +#define MAX_IOCTL_BUFFER_SIZE 4096 + static HRESULT ezusb_get_device_descriptor(struct irp *irp); static HRESULT ezusb_vendor_req(struct irp *irp); static HRESULT ezusb_upload_fw(struct irp *irp); @@ -115,43 +119,114 @@ static HRESULT ezusb_open(struct irp *irp) static HRESULT ezusb_ioctl(struct irp *irp) { + HRESULT res; + + // Stack alloc'd and fixed sized buffers to avoid processing costs with + // allocations. Ensure buffers are large enough for any operation + uint8_t write_buffer_local[MAX_IOCTL_BUFFER_SIZE]; + uint8_t read_buffer_local[MAX_IOCTL_BUFFER_SIZE]; + + uint8_t *write_buffer_orig; + uint8_t *read_buffer_orig; + + // Save original buffer that is owned and managed by the caller/the game + // Do NOT read/write these buffers directly because the game's ezusb + // interface library does not access to them entirely thread safe. + // This causes verious odd bugs due to data read/write inconsistencies + // between data access and modification by at least two different threads. + // + // The game's ezusb (client) library was created on a platform with no + // true multi-core processing (Pentium 4 era of hardware). However, the + // developers utilized threading primitives of the Win32 API to ensure + // a high rate of data updates to reduce input latency. This was architected + // using a dedicated polling thread in the ezusb client library that drives + // the IO polling on a high update rate. The captured data was stored in + // a shared buffer that is also accessible by other threads from the main + // game binary. However, the data access to the same shared buffer with the + // polling backend is not synchronized + // + // Thus, the various odd and flaky ezusb communication bugs we see on + // modern, and true multi-core hardware, are the concurrency management + // mistakes that are now creeping up. The developers back then had no + // proper means to test these due to the lack of hardware capabilities. + + // Save the IO buffer that is used by the ezusb client backend and shared + // with the game's main thread + write_buffer_orig = (uint8_t*) irp->write.bytes; + read_buffer_orig = irp->read.bytes; + + // Prepare our own thread locally managed and non shared buffers for any + // further data operations that are part of the ezusb emulation stack + memset(write_buffer_local, 0, sizeof(write_buffer_local)); + memset(read_buffer_local, 0, sizeof(read_buffer_local)); + + // Sanity check and visibility, in case this ever overflows + if (irp->write.nbytes > sizeof(write_buffer_local)) { + log_fatal("Insufficient local write buffer available for ioctl, local " + "size %d, ioctl buffer size %d", + sizeof(write_buffer_local), + irp->write.nbytes); + } + + if (irp->read.nbytes > sizeof(read_buffer_local)) { + log_fatal("Insufficient local read buffer available for ioctl, local " + "size %d, ioctl buffer size %d", + sizeof(read_buffer_local), + irp->read.nbytes); + } + + // Temporarily hook our local buffers to the irp + irp->write.bytes = write_buffer_local; + irp->read.bytes = read_buffer_local; + + // Move data from the shared buffers to the local one + // Probably the "most atomic way possible" to have the least amount of + // overlap with the game's shared buffer + memcpy(write_buffer_local, write_buffer_orig, irp->write.nbytes); + memcpy(read_buffer_local, read_buffer_orig, irp->read.nbytes); + /* For debugging */ #ifdef EZUSB_EMU_DEBUG_DUMP /* For debugging */ ezusb_emu_util_log_usb_msg( "BEFORE", irp->ioctl, - irp->read.bytes, - irp->read.nbytes, - irp->read.bytes, - irp->read.nbytes, - irp->write.bytes, - irp->write.nbytes); + read_buffered.bytes, + read_buffered.nbytes, + read_buffered.bytes, + read_buffered.nbytes, + write_buffered.bytes, + write_buffered.nbytes); #endif /* Cases are listed in order of first receipt */ switch (irp->ioctl) { case IOCTL_Ezusb_GET_DEVICE_DESCRIPTOR: - return ezusb_get_device_descriptor(irp); + res = ezusb_get_device_descriptor(irp); + break; case IOCTL_Ezusb_VENDOR_REQUEST: - return ezusb_vendor_req(irp); + res = ezusb_vendor_req(irp); + break; case IOCTL_EZUSB_ANCHOR_DOWNLOAD: - return ezusb_upload_fw(irp); + res = ezusb_upload_fw(irp); + break; case IOCTL_EZUSB_BULK_READ: /* Misnomer: can be bulk or interrupt. */ - return ezusb_pipe_read(irp); + res = ezusb_pipe_read(irp); + break; case IOCTL_EZUSB_BULK_WRITE: /* Ditto. */ - return ezusb_pipe_write(irp); + res = ezusb_pipe_write(irp); + break; default: log_warning("Unknown ioctl %08x", irp->ioctl); - return E_INVALIDARG; + res = E_INVALIDARG; } #ifdef EZUSB_EMU_DEBUG_DUMP @@ -159,13 +234,24 @@ static HRESULT ezusb_ioctl(struct irp *irp) ezusb_emu_util_log_usb_msg( "AFTER", irp->ioctl, - irp->read.bytes, - irp->read.nbytes, - irp->read.bytes, - irp->read.nbytes, - irp->write.bytes, - irp->write.nbytes); + read_buffered.bytes, + read_buffered.nbytes, + read_buffered.bytes, + read_buffered.nbytes, + write_buffered.bytes, + write_buffered.nbytes); #endif + + // Move data back to shared IO buffer. Again, keep this keeps the access + // overlap as minimal as possible + memcpy(write_buffer_orig, write_buffer_local, irp->write.nbytes); + memcpy(read_buffer_orig, read_buffer_local, irp->read.nbytes); + + // Re-store the original irp buffer state + irp->write.bytes = (const uint8_t*) write_buffer_orig; + irp->read.bytes = read_buffer_orig; + + return res; } /* * USB TRANSFER LAYER -- 2.54.0 From 9b3ac159c1609cd046ca9ca4c0001b44e7f3a09f Mon Sep 17 00:00:00 2001 From: icex2 Date: Mon, 3 Apr 2023 01:24:49 +0200 Subject: [PATCH 29/38] fix(iidx/ezusb2): Fix IO buffer inconsistency on ezusb ioctl level See same commit for ezusb for details and reasoning. --- src/main/ezusb2-emu/device.c | 77 ++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/src/main/ezusb2-emu/device.c b/src/main/ezusb2-emu/device.c index 797f24b..3516c17 100644 --- a/src/main/ezusb2-emu/device.c +++ b/src/main/ezusb2-emu/device.c @@ -30,6 +30,10 @@ #include "util/log.h" #include "util/str.h" +// The max buffer size in iidx's ezusb client library is 4096 for the initial +// firmware download. +#define MAX_IOCTL_BUFFER_SIZE 4096 + enum pipe { PIPE_INT_OUT = 0x01, PIPE_BULK_OUT = 0x02, @@ -134,8 +138,72 @@ static HRESULT ezusb_ioctl(struct irp *irp) struct iobuf read; HRESULT hr; + // Stack alloc'd and fixed sized buffers to avoid processing costs with + // allocations. Ensure buffers are large enough for any operation + uint8_t write_buffer_local[MAX_IOCTL_BUFFER_SIZE]; + uint8_t read_buffer_local[MAX_IOCTL_BUFFER_SIZE]; + + uint8_t *write_buffer_orig; + uint8_t *read_buffer_orig; + log_assert(irp != NULL); + // Save original buffer that is owned and managed by the caller/the game + // Do NOT read/write these buffers directly because the game's ezusb + // interface library does not access to them entirely thread safe. + // This causes verious odd bugs due to data read/write inconsistencies + // between data access and modification by at least two different threads. + // + // The game's ezusb (client) library was created on a platform with no + // true multi-core processing (Pentium 4 era of hardware). However, the + // developers utilized threading primitives of the Win32 API to ensure + // a high rate of data updates to reduce input latency. This was architected + // using a dedicated polling thread in the ezusb client library that drives + // the IO polling on a high update rate. The captured data was stored in + // a shared buffer that is also accessible by other threads from the main + // game binary. However, the data access to the same shared buffer with the + // polling backend is not synchronized + // + // Thus, the various odd and flaky ezusb communication bugs we see on + // modern, and true multi-core hardware, are the concurrency management + // mistakes that are now creeping up. The developers back then had no + // proper means to test these due to the lack of hardware capabilities. + + // Save the IO buffer that is used by the ezusb client backend and shared + // with the game's main thread + write_buffer_orig = (uint8_t*) irp->write.bytes; + read_buffer_orig = irp->read.bytes; + + // Prepare our own thread locally managed and non shared buffers for any + // further data operations that are part of the ezusb emulation stack + memset(write_buffer_local, 0, sizeof(write_buffer_local)); + memset(read_buffer_local, 0, sizeof(read_buffer_local)); + + // Sanity check and visibility, in case this ever overflows + if (irp->write.nbytes > sizeof(write_buffer_local)) { + log_fatal("Insufficient local write buffer available for ioctl, local " + "size %d, ioctl buffer size %d", + sizeof(write_buffer_local), + irp->write.nbytes); + } + + if (irp->read.nbytes > sizeof(read_buffer_local)) { + log_fatal("Insufficient local read buffer available for ioctl, local " + "size %d, ioctl buffer size %d", + sizeof(read_buffer_local), + irp->read.nbytes); + } + + // Temporarily hook our local buffers to the irp + irp->write.bytes = write_buffer_local; + irp->read.bytes = read_buffer_local; + + // Move data from the shared buffers to the local one + // Probably the "most atomic way possible" to have the least amount of + // overlap with the game's shared buffer + memcpy(write_buffer_local, write_buffer_orig, irp->write.nbytes); + memcpy(read_buffer_local, read_buffer_orig, irp->read.nbytes); + #ifdef EZUSB_EMU_DEBUG_DUMP /* For debugging */ ezusb2_emu_util_log_usb_msg("BEFORE", irp); @@ -193,6 +261,15 @@ static HRESULT ezusb_ioctl(struct irp *irp) ezusb2_emu_util_log_usb_msg("AFTER", irp); #endif + // Move data back to shared IO buffer. Again, keep this keeps the access + // overlap as minimal as possible + memcpy(write_buffer_orig, write_buffer_local, irp->write.nbytes); + memcpy(read_buffer_orig, read_buffer_local, irp->read.nbytes); + + // Re-store the original irp buffer state + irp->write.bytes = (const uint8_t*) write_buffer_orig; + irp->read.bytes = read_buffer_orig; + return hr; } -- 2.54.0 From baaf75a47bd352835f1983e31b8942c124fd4410 Mon Sep 17 00:00:00 2001 From: icex2 Date: Mon, 3 Apr 2023 01:07:07 +0200 Subject: [PATCH 30/38] fix(iidx/ezusb): ezusb does not have a white dongle This is one part of fixing the 10th style SQ-INIT boot error. For some reason, 10th style calls the "second dongle slot" which, according to the code, is expected to return the same data as the first (black) dongle slot. Original ezusb/C02/D01 IO boards do not have a second dongle round plug slot nor ever came with a splitter cable. I checked original manuals of the C02 conversion kit, E11 and ECO software upgrade kits. No white dongle nor additional hardware for any other dongle than a black dongle. --- src/main/ezusb-emu/node-security-plug.c | 15 ++++++++++----- src/main/ezusb-iidx/secplug-cmd.h | 6 ++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/ezusb-emu/node-security-plug.c b/src/main/ezusb-emu/node-security-plug.c index 5524921..2b05a03 100644 --- a/src/main/ezusb-emu/node-security-plug.c +++ b/src/main/ezusb-emu/node-security-plug.c @@ -181,16 +181,21 @@ uint8_t ezusb_iidx_emu_node_security_plug_process_cmd_v1( /* TODO ? */ return EZUSB_IIDX_SECPLUG_CMD_STATUS_V1_OK; - case EZUSB_IIDX_SECPLUG_CMD_V1_SELECT_BLACK_DONGLE: - log_misc("EZUSB_IIDX_SECPLUG_CMD_V1_SELECT_BLACK_DONGLE"); + // Black dongle + case EZUSB_IIDX_SECPLUG_CMD_V1_SELECT_DONGLE_1: + log_misc("EZUSB_IIDX_SECPLUG_CMD_V1_SELECT_DONGLE_1"); ezusb_iidx_emu_node_security_plug_active_dongle_slot = EZUSB_IIDX_SECPLUG_DONGLE_SLOT_BLACK; return EZUSB_IIDX_SECPLUG_CMD_STATUS_V1_OK; - case EZUSB_IIDX_SECPLUG_CMD_V1_SELECT_WHITE_DONGLE: - log_misc("EZUSB_IIDX_SECPLUG_CMD_V1_SELECT_WHITE_DONGLE"); + // Used by D01 to also address black dongle? + // Note that iidx 9 to 13 never had a white dongle + // The white dongle/separate eamuse license key was introduced + // with iidx 14 + case EZUSB_IIDX_SECPLUG_CMD_V1_SELECT_DONGLE_2: + log_misc("EZUSB_IIDX_SECPLUG_CMD_V1_SELECT_DONGLE_2"); ezusb_iidx_emu_node_security_plug_active_dongle_slot = - EZUSB_IIDX_SECPLUG_DONGLE_SLOT_WHITE; + EZUSB_IIDX_SECPLUG_DONGLE_SLOT_BLACK; return EZUSB_IIDX_SECPLUG_CMD_STATUS_V1_OK; default: diff --git a/src/main/ezusb-iidx/secplug-cmd.h b/src/main/ezusb-iidx/secplug-cmd.h index 4118ffe..fb9722d 100644 --- a/src/main/ezusb-iidx/secplug-cmd.h +++ b/src/main/ezusb-iidx/secplug-cmd.h @@ -15,8 +15,10 @@ enum ezusb_iidx_secplug_command_v1 { EZUSB_IIDX_SECPLUG_CMD_V1_READ_ROM = 0x01, EZUSB_IIDX_SECPLUG_CMD_V1_READ_DATA = 0x02, EZUSB_IIDX_SECPLUG_CMD_V1_WRITE_DATA = 0x03, - EZUSB_IIDX_SECPLUG_CMD_V1_SELECT_BLACK_DONGLE = 0x04, - EZUSB_IIDX_SECPLUG_CMD_V1_SELECT_WHITE_DONGLE = 0x05 + // Black dongle + EZUSB_IIDX_SECPLUG_CMD_V1_SELECT_DONGLE_1 = 0x04, + // Used by D01 to also address black dongle? + EZUSB_IIDX_SECPLUG_CMD_V1_SELECT_DONGLE_2 = 0x05, }; enum ezusb_iidx_secplug_command_status_v1 { -- 2.54.0 From db8ff4e624187877babe778817ba0fab6826495a Mon Sep 17 00:00:00 2001 From: icex2 Date: Mon, 3 Apr 2023 01:09:44 +0200 Subject: [PATCH 31/38] feat(iidx/ezusb): Make iidx ezusb emu io board type configurable Second part to fixing the 10th style SQ-INIT error. This has cross-impact on the kind of security data the game expects. Therefore, we need to expose the IO board type and make it configurable like the security data for the different game versions. More details explained in a dev journal entry to following in one of the next commits. --- src/main/ezusb-iidx-emu/msg.c | 32 ++++++++++++++++++++++++++++---- src/main/ezusb-iidx-emu/msg.h | 14 ++++++++++++-- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/main/ezusb-iidx-emu/msg.c b/src/main/ezusb-iidx-emu/msg.c index 66615ab..e818b7e 100644 --- a/src/main/ezusb-iidx-emu/msg.c +++ b/src/main/ezusb-iidx-emu/msg.c @@ -65,6 +65,7 @@ static const struct ezusb_iidx_emu_node *ezusb_iidx_emu_msg_v2_nodes[256] = { [EZUSB_IIDX_MSG_NODE_WDT] = &ezusb_iidx_emu_node_wdt, }; +static enum ezusb_iidx_emu_msg_io_board_type ezusb_iidx_emu_msg_io_board_type; static const struct ezusb_iidx_emu_node **ezusb_iidx_emu_node_handler; static uint8_t ezusb_iidx_emu_msg_status = 0; static uint8_t ezusb_iidx_emu_msg_seq_no = 0; @@ -72,8 +73,16 @@ static uint8_t ezusb_iidx_emu_msg_read_cur_node = 0; /* ------------------------------------------------------------------------ */ -struct ezusb_emu_msg_hook *ezusb_iidx_emu_msg_init(void) +struct ezusb_emu_msg_hook *ezusb_iidx_emu_msg_init( + enum ezusb_iidx_emu_msg_io_board_type io_board_type) { + if (io_board_type < 0 || + io_board_type >= EZUSB_IIDX_EMU_MSG_IO_BOARD_TYPE_COUNT) { + log_fatal("Invalid io board type %d specified", io_board_type); + } + + ezusb_iidx_emu_msg_io_board_type = io_board_type; + /* Init all nodes */ for (uint32_t i = 0; i < 256; i++) { /* "Constructor" optional */ @@ -85,6 +94,9 @@ struct ezusb_emu_msg_hook *ezusb_iidx_emu_msg_init(void) ezusb_iidx_emu_node_handler = ezusb_iidx_emu_msg_nodes; + log_info("Initialized, io board type: %d", + ezusb_iidx_emu_msg_io_board_type); + return &ezusb_iidx_emu_msg_hook; } @@ -163,9 +175,21 @@ static HRESULT ezusb_iidx_emu_msg_interrupt_read(struct iobuf *read) otherwise the game's fpga check will fail */ msg_resp->fpga2_check_flag_unkn = 2; -#ifdef EZUSB_IIDX_EMU_D01_BOARD - msg_resp->inverted_pad &= ~(1 << 4); -#endif + switch (ezusb_iidx_emu_msg_io_board_type) { + case EZUSB_IIDX_EMU_MSG_IO_BOARD_TYPE_C02: + // noop + break; + + case EZUSB_IIDX_EMU_MSG_IO_BOARD_TYPE_D01: + msg_resp->inverted_pad &= ~(1 << 4); + break; + + case EZUSB_IIDX_EMU_MSG_IO_BOARD_TYPE_COUNT: + default: + log_fatal("Illegal state, unhandled board type: %d", + ezusb_iidx_emu_msg_io_board_type); + break; + } read->pos = sizeof(*msg_resp); diff --git a/src/main/ezusb-iidx-emu/msg.h b/src/main/ezusb-iidx-emu/msg.h index 83d2bd6..e0198da 100644 --- a/src/main/ezusb-iidx-emu/msg.h +++ b/src/main/ezusb-iidx-emu/msg.h @@ -8,16 +8,26 @@ #include "ezusb-emu/msg.h" +enum ezusb_iidx_emu_msg_io_board_type { + EZUSB_IIDX_EMU_MSG_IO_BOARD_TYPE_C02 = 0, + EZUSB_IIDX_EMU_MSG_IO_BOARD_TYPE_D01 = 1, + EZUSB_IIDX_EMU_MSG_IO_BOARD_TYPE_COUNT = 2, +}; + /** - * Init the fully emulated IIDX msg backend for a EZUSB (C02) board. This + * Init the fully emulated IIDX msg backend for a EZUSB board. This * activates the "old" V1 node handling backend which was used on iidx 09 to 13. * On iidx14, the firmware was updated and removed nodes that were not used * anymore, e.g. serial card reader handling. * + * @param io_board_type Type of IO board to emulate. Note that this impacts the + * security data which is different on some game versions, e.g. 10th + * style. * @return ezusb_emu_msg_hook structure with hook calls for ezusb msg * dispatching */ -struct ezusb_emu_msg_hook *ezusb_iidx_emu_msg_init(void); +struct ezusb_emu_msg_hook *ezusb_iidx_emu_msg_init( + enum ezusb_iidx_emu_msg_io_board_type io_board_type); /** * Init the fully emulated IIDX msg backend for a EZUSB (C02) board. This -- 2.54.0 From c05320c9d39b0d251a5ab6371f0314e42cf2a1d7 Mon Sep 17 00:00:00 2001 From: icex2 Date: Mon, 3 Apr 2023 01:11:34 +0200 Subject: [PATCH 32/38] feat(iidx/config): Expose ezusb specific configuration params Useful (debugging) and required (io board type) for different game versions --- src/main/iidxhook-util/Module.mk | 1 + src/main/iidxhook-util/config-ezusb.c | 69 +++++++++++++++++++++++++++ src/main/iidxhook-util/config-ezusb.h | 18 +++++++ 3 files changed, 88 insertions(+) create mode 100644 src/main/iidxhook-util/config-ezusb.c create mode 100644 src/main/iidxhook-util/config-ezusb.h diff --git a/src/main/iidxhook-util/Module.mk b/src/main/iidxhook-util/Module.mk index 8645aea..92fe44d 100644 --- a/src/main/iidxhook-util/Module.mk +++ b/src/main/iidxhook-util/Module.mk @@ -8,6 +8,7 @@ src_iidxhook-util := \ chart-patch.c \ clock.c \ config-eamuse.c \ + config-ezusb.c \ config-gfx.c \ config-io.c \ config-misc.c \ diff --git a/src/main/iidxhook-util/config-ezusb.c b/src/main/iidxhook-util/config-ezusb.c new file mode 100644 index 0000000..457e67d --- /dev/null +++ b/src/main/iidxhook-util/config-ezusb.c @@ -0,0 +1,69 @@ +#include +#include + +#include "cconfig/cconfig-util.h" + +#include "iidxhook-util/config-ezusb.h" + +#include "util/log.h" +#include "util/mem.h" + +#define IIDXHOOK_UTIL_CONFIG_EZUSB_API_CALL_MONITORING_KEY "ezusb.api_call_monitoring" +#define IIDXHOOK_UTIL_CONFIG_EZUSB_IO_BOARD_TYPE_KEY "ezusb.io_board_type" + +#define IIDXHOOK_UTIL_CONFIG_EZUSB_DEFAULT_API_CALL_MONITORING_VALUE false +#define IIDXHOOK_UTIL_CONFIG_EZUSB_DEFAULT_IO_BOARD_TYPE_VALUE 0 + +void iidxhook_util_config_ezusb_init(struct cconfig *config) +{ + cconfig_util_set_bool( + config, + IIDXHOOK_UTIL_CONFIG_EZUSB_API_CALL_MONITORING_KEY, + IIDXHOOK_UTIL_CONFIG_EZUSB_DEFAULT_API_CALL_MONITORING_VALUE, + "Enable monitoring of ezusb.dll calls by logging call traces. " + "Only works on 9th and 10th style!"); + + cconfig_util_set_int( + config, + IIDXHOOK_UTIL_CONFIG_EZUSB_IO_BOARD_TYPE_KEY, + IIDXHOOK_UTIL_CONFIG_EZUSB_DEFAULT_IO_BOARD_TYPE_VALUE, + "Set the type of ezusb IO board. 0 = C02, 1 = D01. " + "Note: Impacts security settings!"); +} + +void iidxhook_util_config_ezusb_get( + struct iidxhook_util_config_ezusb *config_ezusb, struct cconfig *config) +{ + if (!cconfig_util_get_bool( + config, + IIDXHOOK_UTIL_CONFIG_EZUSB_API_CALL_MONITORING_KEY, + &config_ezusb->api_call_monitoring, + IIDXHOOK_UTIL_CONFIG_EZUSB_DEFAULT_API_CALL_MONITORING_VALUE)) { + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + IIDXHOOK_UTIL_CONFIG_EZUSB_API_CALL_MONITORING_KEY, + IIDXHOOK_UTIL_CONFIG_EZUSB_DEFAULT_API_CALL_MONITORING_VALUE); + } + + if (!cconfig_util_get_int( + config, + IIDXHOOK_UTIL_CONFIG_EZUSB_IO_BOARD_TYPE_KEY, + &config_ezusb->io_board_type, + IIDXHOOK_UTIL_CONFIG_EZUSB_DEFAULT_IO_BOARD_TYPE_VALUE)) { + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + IIDXHOOK_UTIL_CONFIG_EZUSB_IO_BOARD_TYPE_KEY, + IIDXHOOK_UTIL_CONFIG_EZUSB_DEFAULT_IO_BOARD_TYPE_VALUE); + } + + if (config_ezusb->io_board_type != 0 && config_ezusb->io_board_type != 1) { + log_warning( + "Invalid value for key '%s' specified, fallback " + "to default '%d'", + IIDXHOOK_UTIL_CONFIG_EZUSB_IO_BOARD_TYPE_KEY, + IIDXHOOK_UTIL_CONFIG_EZUSB_DEFAULT_IO_BOARD_TYPE_VALUE); + config_ezusb->io_board_type = 0; + } +} diff --git a/src/main/iidxhook-util/config-ezusb.h b/src/main/iidxhook-util/config-ezusb.h new file mode 100644 index 0000000..54d69fb --- /dev/null +++ b/src/main/iidxhook-util/config-ezusb.h @@ -0,0 +1,18 @@ +#ifndef IIDXHOOK_UTIL_CONFIG_EZUSB_H +#define IIDXHOOK_UTIL_CONFIG_EZUSB_H + +#include "cconfig/cconfig.h" + +#include "security/mcode.h" + +struct iidxhook_util_config_ezusb { + bool api_call_monitoring; + int32_t io_board_type; +}; + +void iidxhook_util_config_ezusb_init(struct cconfig *config); + +void iidxhook_util_config_ezusb_get( + struct iidxhook_util_config_ezusb *config_ezusb, struct cconfig *config); + +#endif \ No newline at end of file -- 2.54.0 From 6c44d64f45318367721f54cea375a6f2ff0262d3 Mon Sep 17 00:00:00 2001 From: icex2 Date: Mon, 3 Apr 2023 01:12:45 +0200 Subject: [PATCH 33/38] chore(iidx): Wire-up ezusb configuration in iidxhook1 and 2 Make io board type for ezusb board configurable as well as allow switching on/off additional ezusb debugging feature. --- src/main/iidxhook1/dllmain.c | 13 ++++++++++++- src/main/iidxhook2/dllmain.c | 7 ++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/iidxhook1/dllmain.c b/src/main/iidxhook1/dllmain.c index 2eadfeb..bffee17 100644 --- a/src/main/iidxhook1/dllmain.c +++ b/src/main/iidxhook1/dllmain.c @@ -27,6 +27,7 @@ #include "iidxhook-util/chart-patch.h" #include "iidxhook-util/clock.h" +#include "iidxhook-util/config-ezusb.h" #include "iidxhook-util/config-eamuse.h" #include "iidxhook-util/config-gfx.h" #include "iidxhook-util/config-misc.h" @@ -37,6 +38,7 @@ #include "iidxhook-util/settings.h" #include "iidxhook1/config-iidxhook1.h" +#include "iidxhook1/ezusb-mon.h" #include "iidxhook1/log-ezusb.h" #include "util/defs.h" @@ -123,6 +125,7 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) { struct cconfig *config; + struct iidxhook_util_config_ezusb config_ezusb; struct iidxhook_util_config_eamuse config_eamuse; struct iidxhook_config_gfx config_gfx; struct iidxhook_config_iidxhook1 config_iidxhook1; @@ -141,6 +144,7 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) config = cconfig_init(); + iidxhook_util_config_ezusb_init(config); iidxhook_util_config_eamuse_init(config); iidxhook_config_gfx_init(config); iidxhook_config_iidxhook1_init(config); @@ -155,6 +159,7 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) exit(EXIT_FAILURE); } + iidxhook_util_config_ezusb_get(&config_ezusb, config); iidxhook_util_config_eamuse_get(&config_eamuse, config); iidxhook_config_gfx_get(&config_gfx, config); iidxhook_config_iidxhook1_get(&config_iidxhook1, config); @@ -234,7 +239,13 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) iohook_push_handler(settings_hook_dispatch_irp); hook_setupapi_init(&ezusb_emu_desc_device.setupapi); - ezusb_emu_device_hook_init(ezusb_iidx_emu_msg_init()); + ezusb_emu_device_hook_init( + ezusb_iidx_emu_msg_init(config_ezusb.io_board_type)); + + if (config_ezusb.api_call_monitoring) { + ezusb_log_hook_init(); + ezusb_mon_hook_init(); + } log_info("-------------------------------------------------------------"); log_info("---------------- End iidxhook my_OpenProcess ----------------"); diff --git a/src/main/iidxhook2/dllmain.c b/src/main/iidxhook2/dllmain.c index 7927de2..c35197d 100644 --- a/src/main/iidxhook2/dllmain.c +++ b/src/main/iidxhook2/dllmain.c @@ -29,6 +29,7 @@ #include "iidxhook-util/acio.h" #include "iidxhook-util/chart-patch.h" #include "iidxhook-util/clock.h" +#include "iidxhook-util/config-ezusb.h" #include "iidxhook-util/config-eamuse.h" #include "iidxhook-util/config-gfx.h" #include "iidxhook-util/config-misc.h" @@ -121,6 +122,7 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) { struct cconfig *config; + struct iidxhook_util_config_ezusb config_ezusb; struct iidxhook_util_config_eamuse config_eamuse; struct iidxhook_config_gfx config_gfx; struct iidxhook_config_iidxhook2 config_iidxhook2; @@ -139,6 +141,7 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) config = cconfig_init(); + iidxhook_util_config_ezusb_init(config); iidxhook_util_config_eamuse_init(config); iidxhook_config_gfx_init(config); iidxhook_config_iidxhook2_init(config); @@ -153,6 +156,7 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) exit(EXIT_FAILURE); } + iidxhook_util_config_ezusb_get(&config_ezusb, config); iidxhook_util_config_eamuse_get(&config_eamuse, config); iidxhook_config_gfx_get(&config_gfx, config); iidxhook_config_iidxhook2_get(&config_iidxhook2, config); @@ -228,7 +232,8 @@ my_OpenProcess(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId) iohook_push_handler(settings_hook_dispatch_irp); hook_setupapi_init(&ezusb_emu_desc_device.setupapi); - ezusb_emu_device_hook_init(ezusb_iidx_emu_msg_init()); + ezusb_emu_device_hook_init( + ezusb_iidx_emu_msg_init(config_ezusb.io_board_type)); /* Card reader emulation, same issue with hooking as IO emulation */ rs232_hook_init(); -- 2.54.0 From d8a0a713fa62fb59c5552bb811f126a24bb6261b Mon Sep 17 00:00:00 2001 From: icex2 Date: Mon, 3 Apr 2023 01:13:35 +0200 Subject: [PATCH 34/38] fix(iidx/config): Utilize io board type, fix 10th SQ-INIT error Using the right combination of "flags", this addresses the SQ-INIT error on 10th style as well as forces 10 to 13 into using the D01 operation mode. The latter follows the approach that 14+ is also using the best/latest IO type supported (IO2 in that case). Expecting that gameplay experience benefits from more optimized/better maintained code paths. Make 10 operate in D01 IO mode which forces security to using the D01 dongle from a D01 dedicab setup. The alternative would be using a C02 dongle from a C02 upgraded cabinet. More details to follow in another commit with a dev journal entry. --- dist/iidx/iidxhook-09.conf | 10 ++++++++-- dist/iidx/iidxhook-10.conf | 6 ++++++ dist/iidx/iidxhook-11.conf | 6 ++++++ dist/iidx/iidxhook-12.conf | 6 ++++++ dist/iidx/iidxhook-13.conf | 6 ++++++ 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/dist/iidx/iidxhook-09.conf b/dist/iidx/iidxhook-09.conf index 0e14033..5894f4f 100755 --- a/dist/iidx/iidxhook-09.conf +++ b/dist/iidx/iidxhook-09.conf @@ -46,6 +46,12 @@ gfx.forced_refresh_rate=-1 # D3D9 device adapter (monitor), -1 to use default, 0, 1, 2 etc. to use specified adapter gfx.device_adapter=-1 +# Enable monitoring of ezusb.dll calls by logging call traces. Only works on 9th and 10th style! +ezusb.api_call_monitoring=false + +# Set the type of ezusb IO board. 0 = C02, 1 = D01. Note: Impacts security settings! +ezusb.io_board_type=0 + # Disable operator clock setting system clock time misc.disable_clock_set=false @@ -61,5 +67,5 @@ sec.boot_version=GEC02 # Security boot seeds for ezusb, format: X:X:X where X is a number of 0-9 (e.g. 0:0:0). sec.boot_seeds=0:0:0 -# Security black plug mcode id string (e.g. GQC02JAA). -sec.black_plug_mcode=GQC02JAA \ No newline at end of file +# Security black plug mcode id string (e.g. GEC02JAA). +sec.black_plug_mcode=GEC02JAA \ No newline at end of file diff --git a/dist/iidx/iidxhook-10.conf b/dist/iidx/iidxhook-10.conf index a2e1504..9bbe438 100755 --- a/dist/iidx/iidxhook-10.conf +++ b/dist/iidx/iidxhook-10.conf @@ -46,6 +46,12 @@ gfx.forced_refresh_rate=-1 # D3D9 device adapter (monitor), -1 to use default, 0, 1, 2 etc. to use specified adapter gfx.device_adapter=-1 +# Enable monitoring of ezusb.dll calls by logging call traces. Only works on 9th and 10th style! +ezusb.api_call_monitoring=false + +# Set the type of ezusb IO board. 0 = C02, 1 = D01. Note: Impacts security settings! +ezusb.io_board_type=1 + # Disable operator clock setting system clock time misc.disable_clock_set=false diff --git a/dist/iidx/iidxhook-11.conf b/dist/iidx/iidxhook-11.conf index 9fc9a79..ed834cb 100755 --- a/dist/iidx/iidxhook-11.conf +++ b/dist/iidx/iidxhook-11.conf @@ -46,6 +46,12 @@ gfx.forced_refresh_rate=-1 # D3D9 device adapter (monitor), -1 to use default, 0, 1, 2 etc. to use specified adapter gfx.device_adapter=-1 +# Enable monitoring of ezusb.dll calls by logging call traces. Only works on 9th and 10th style! +ezusb.api_call_monitoring=false + +# Set the type of ezusb IO board. 0 = C02, 1 = D01. Note: Impacts security settings! +ezusb.io_board_type=1 + # Disable operator clock setting system clock time misc.disable_clock_set=false diff --git a/dist/iidx/iidxhook-12.conf b/dist/iidx/iidxhook-12.conf index e279e16..217d142 100755 --- a/dist/iidx/iidxhook-12.conf +++ b/dist/iidx/iidxhook-12.conf @@ -46,6 +46,12 @@ gfx.forced_refresh_rate=-1 # D3D9 device adapter (monitor), -1 to use default, 0, 1, 2 etc. to use specified adapter gfx.device_adapter=-1 +# Enable monitoring of ezusb.dll calls by logging call traces. Only works on 9th and 10th style! +ezusb.api_call_monitoring=false + +# Set the type of ezusb IO board. 0 = C02, 1 = D01. Note: Impacts security settings! +ezusb.io_board_type=1 + # Fix broken 3D background on Happy Sky's music select (if appearing completely white) misc.happy_sky_ms_bg_fix=false diff --git a/dist/iidx/iidxhook-13.conf b/dist/iidx/iidxhook-13.conf index 25a2d50..005dd74 100755 --- a/dist/iidx/iidxhook-13.conf +++ b/dist/iidx/iidxhook-13.conf @@ -46,6 +46,12 @@ gfx.forced_refresh_rate=-1 # D3D9 device adapter (monitor), -1 to use default, 0, 1, 2 etc. to use specified adapter gfx.device_adapter=-1 +# Enable monitoring of ezusb.dll calls by logging call traces. Only works on 9th and 10th style! +ezusb.api_call_monitoring=false + +# Set the type of ezusb IO board. 0 = C02, 1 = D01. Note: Impacts security settings! +ezusb.io_board_type=1 + # Fix broken 3D background on DistorteD's music select (if appearing completely black) misc.distorted_ms_bg_fix=false -- 2.54.0 From e73bd37d0cf18c4b50a92e49240ac5f07853c907 Mon Sep 17 00:00:00 2001 From: icex2 Date: Mon, 3 Apr 2023 01:17:19 +0200 Subject: [PATCH 35/38] chore(doc): Add dev journal about 10th style IO and security boot --- .../2023-04-03-d01-ezusb-io-boot-security.md | 289 ++++++++++++++++++ 1 file changed, 289 insertions(+) create mode 100644 doc/dev/journal/2023-04-03-d01-ezusb-io-boot-security.md diff --git a/doc/dev/journal/2023-04-03-d01-ezusb-io-boot-security.md b/doc/dev/journal/2023-04-03-d01-ezusb-io-boot-security.md new file mode 100644 index 0000000..4abe6cc --- /dev/null +++ b/doc/dev/journal/2023-04-03-d01-ezusb-io-boot-security.md @@ -0,0 +1,289 @@ +# Beatmania IIDX 10th Style - D01 IO boot code and security init + +Date: 2023-04-03 +Author: icex2 + +Documenting decompiled and reverse engineered code snippets from the D01 JAE `bm2dx.exe`. These +helped me figuring out the two different security boot modes the game supports. + +In summary, it supports booting with the C02 IO with a C02 black dongle and a D01 IO board with +a D01 dongle. No other combination is valid because they didn't make sense back then. You either +had an upgraded old style/twinkle cabinet to C02 (GEC02) or you bought a new dedicated cabinet +(GQD01). With 10th style supporting the old C02 dongle, it appears that all owners of a C02 cabinet +with IO board and C02 dongle received a free software update/HDD. This might make sense considering +the short life span of C02 and the game being super buggy, especially in earlier/initial revisions. + +The game expects the following "configurations" from bemanitools: + +* Booting as upgraded C02 with free D01 upgrade + * `sec.boot_version=GEC02 ` + * `sec.boot_seeds=0:0:1` + * `sec.black_plug_mcode=GEC02JAA` + * "D01 IO pin" on IO board not active +* Booting as dedicated + * `sec.boot_version=GEC02 ` + * `sec.boot_seeds=0:1:1` + * `sec.black_plug_mcode=GQD01JAA` + * "D01 IO pin" on IO board ACTIVE + +All the above was derived from reading and understanding the documented code excerpts below. + +## io_boot - sub_402700 + +Called as the first step in the boot statemachine by the "boot" function `sub_40F9C0`. + +```c +// sub_402700 +int __stdcall io_boot(int a1) +{ + DWORD (__stdcall *timeGetTime)(); // esi + int usb_boot_security_res; // ebp + DWORD time_start; // ebx + int io_boot_state; // edi + DWORD now; // esi + BOOL is_d01_boot_mode; // esi + BOOL v7; // esi + int result; // eax + int v9; // [esp+10h] [ebp-2Ch] + int firmware_version; // [esp+14h] [ebp-28h] + int io_pad_read; // [esp+18h] [ebp-24h] BYREF + char v12[32]; // [esp+1Ch] [ebp-20h] BYREF + + dword_4D0768 = 0; + strcpy(byte_4D076C, &byte_4D0858); + timeGetTime = ::timeGetTime; + v9 = 0; + usb_boot_security_res = io_pad_read; + time_start = ::timeGetTime(); + io_boot_state = 0; + while ( 2 ) + { + switch ( io_boot_state ) + { + case 0: // "start io", firmware download and wait for reconnect + if ( usbStart(0) ) + { + if ( time_exceeded(time_start, 20000) ) + set_io_error_type(1, aErrorUsbioStar);// ERROR(USBIO START) + } + else + { + io_boot_state = 1; + } + goto reset_io_boot_state_label; + case 1: // check firmware + firmware_version = usbFirmResult(); + if ( firmware_version == 96 ) + { + if ( time_exceeded(time_start, 25000) ) + set_io_error_type(1, aErrorFm); // ERROR(FM), FM = firmware + } + else + { + io_boot_state = 2; + } + goto reset_io_boot_state_label; + case 2: + if ( !firmware_version ) + { + usbMute(1); + time_start = timeGetTime(); + now = timeGetTime(); + io_input_is_d01_ezusb = 0; + do + { + usbPadRead(&io_pad_read); + if ( (io_pad_read & 0x10) != 0 ) + io_input_is_d01_ezusb = 1; + } + while ( !time_exceeded(now, 2000) ); + io_boot_state = 3; +reset_io_boot_state_label: + timeGetTime = ::timeGetTime; + if ( io_boot_state != v9 ) + { + v9 = io_boot_state; + time_start = ::timeGetTime(); + } + continue; // retry + } + if ( firmware_version > 128 ) + { + if ( firmware_version == 254 ) + { + set_io_error_type(1, aErrorFmTrnsOut);// ERROR(FM TRNS-OUT) + return 1; + } + if ( firmware_version == 255 ) + { + set_io_error_type(1, aErrorFmTimeOut);// ERROR(FM TIME-OUT) + return 1; + } + } + else + { + switch ( firmware_version ) + { + case 128: + set_io_error_type(1, aErrorFmReadErr);// ERROR(FM READ-ERR) + return 1; + case -113: + set_io_error_type(1, aErrorFmDlErr);// ERROR(FM DL-ERR) + return 1; + case -33: + set_io_error_type(1, aErrorFmCmprReq);// ERROR(FM CMPR-REQ) + return 1; + } + } +UNKNOWN_ERROR_LABEL: + set_io_error_type(1, aErrorUnknown); // ERROR(UNKNOWN) + return 1; + case 3: + if ( io_init_security() ) + { + set_io_error_type(1, aErrorSqInit); // ERROR(SQ-INIT) + return 1; + } + io_boot_state = 4; + goto reset_io_boot_state_label; + case 4: + is_d01_boot_mode = io_input_is_d01_ezusb != 0; + if ( !strncmp(black_dongle_mcode, MCODE_GED01, 5u) ) + is_d01_boot_mode = 1; + usb_boot_security_res = usbBootSecurity(aGec02, 0, is_d01_boot_mode, 1); + if ( usb_boot_security_res == 96 ) + { + if ( time_exceeded(time_start, 20000) ) + set_io_error_type(1, aErrorBtSqInit);// ERROR(BT-SQ-INIT)' + } + else + { + io_boot_state = 5; + } + goto reset_io_boot_state_label; + case 5: + if ( usb_boot_security_res ) + { + switch ( usb_boot_security_res ) + { + case 0xFFFFFE9F: + set_io_error_type(1, aErrorSecurityE);// ERROR(SECURITY EEP) + result = 1; + break; + case 0xFFFFFECF: + case 0xFFFFFEDF: + set_io_error_type(1, aErrorSecurityI);// ERROR(SECURITY ID or EEP) + result = 1; + break; + case 0xFFFFFEEF: + set_io_error_type(1, aErrorSecurityN);// 'ERROR(SECURITY No Match)' + result = 1; + break; + case 0xFFFFFEFF: + io_boot_state = 6; + goto reset_io_boot_state_label; + default: + goto UNKNOWN_ERROR_LABEL; + } + } + else + { + Sleep(0x3E8u); + result = 0; + } + return result; + case 6: // security conversion/upgrading security dongles + v7 = io_input_is_d01_ezusb != 0; + if ( !usbGetSecurityKey(v12) ) + { + if ( usbSetupSecurityComplete(v12, 0, v7, 1) ) + set_io_error_type(1, aErrorSecurityC);// ERROR(SECURITY CONVERSION FAILED) + return 1; + } + set_io_error_type(1, aErrorSecurityC); // ERROR(SECURITY CONVERSION FAILED) + goto reset_io_boot_state_label; + default: + goto UNKNOWN_ERROR_LABEL; + } + } +} +``` + +## io_init_security - sub_402BB0 + +Sub-function of the [io_boot](#io_boot---sub_402700) function. + +```c +// sub_402BB0 +int io_init_security() +{ + int v0; // esi + int v2; // esi + int mcode_mismatch_cnt; // esi + char white_dongle_data_maybe[10]; // [esp+Ch] [ebp-20h] BYREF + + usbSecurityInit(); + v0 = 0; + while ( usbSecurityInitDone() ) + { + if ( v0 > 1200 ) + { + set_io_error_type(-1, aNgSi); + return -1; + } + ++v0; + Sleep(16u); + } + pcbid = 0; + dword_4D0754 = 0; + word_4D0758 = 0; + while ( usbGetPCBID(&pcbid) ) + Sleep(1u); + *(_DWORD *)black_dongle_mcode = 0; + v2 = 0; + *(_DWORD *)&black_dongle_mcode[4] = 0; + while ( usbGetSecurity(black_dongle_mcode) ) // black_dongle_mcode = GQD01JAA + { + if ( v2 > 1200 ) + { + set_io_error_type(-1, aNgPd); + return -1; + } + ++v2; + Sleep(16u); + } + set_cabinet_type(black_dongle_mcode[6]); + mcode_mismatch_cnt = black_dongle_mcode[0] != 'G'; + if ( io_input_is_d01_ezusb || !strncmp(black_dongle_mcode, MCODE_GED01, 5u) )// Path for using the D01 dongle with D01 IO board + { + if ( (unsigned __int8)black_dongle_mcode[2] != (char)MCODE_D01 ) + ++mcode_mismatch_cnt; + if ( (unsigned __int8)black_dongle_mcode[3] != SBYTE1(MCODE_D01) ) + ++mcode_mismatch_cnt; + if ( (unsigned __int8)black_dongle_mcode[4] != SBYTE2(MCODE_D01) ) + ++mcode_mismatch_cnt; + } + else // Path for using the C02 dongle with C02 IO board + { + if ( (unsigned __int8)black_dongle_mcode[2] != MCODE_C02[0] ) + ++mcode_mismatch_cnt; + if ( (unsigned __int8)black_dongle_mcode[3] != MCODE_C02[1] ) + ++mcode_mismatch_cnt; + if ( (unsigned __int8)black_dongle_mcode[4] != MCODE_C02[2] ) + ++mcode_mismatch_cnt; + if ( !usbGetSecurityKey(white_dongle_data_maybe) ) + { + black_dongle_mcode[6] = white_dongle_data_maybe[6]; + set_cabinet_type(white_dongle_data_maybe[6]); + } + } + if ( black_dongle_mcode[5] != 'J' ) + ++mcode_mismatch_cnt; + if ( black_dongle_mcode[6] != 'A' && black_dongle_mcode[6] != 'B' && black_dongle_mcode[6] != 'C' ) + ++mcode_mismatch_cnt; + if ( !mcode_mismatch_cnt ) + return 0; + set_io_error_type(-1, aNgSecurity); + return -1; +} +``` \ No newline at end of file -- 2.54.0 From 3a80c41a72aa4f7f09eb668b4c21e276c5458d3e Mon Sep 17 00:00:00 2001 From: icex2 Date: Thu, 6 Apr 2023 14:49:57 +0200 Subject: [PATCH 36/38] chore: Apply code formatting to entire code base --- src/main/ezusb-emu/device.c | 12 ++-- src/main/ezusb-iidx-emu/msg.c | 13 ++-- src/main/ezusb-iidx-emu/msg.h | 4 +- src/main/ezusb-iidx-emu/node-serial.c | 47 +++++++++++---- src/main/ezusb2-emu/device.c | 12 ++-- src/main/ezusb2-popn-emu/msg.c | 2 - src/main/iidxhook-util/chart-patch.c | 87 +++++++++++++-------------- src/main/iidxhook-util/config-ezusb.c | 3 +- src/main/iidxhook-util/settings.c | 12 ++-- src/main/iidxhook1/dllmain.c | 2 +- src/main/iidxhook1/ezusb-mon.c | 59 +++++++++--------- src/main/iidxhook1/ezusb-mon.h | 2 +- src/main/iidxhook2/dllmain.c | 2 +- src/main/iidxhook5/ifs-snd-redir.c | 8 +-- src/main/mempatch-hook/main.c | 3 +- 15 files changed, 152 insertions(+), 116 deletions(-) diff --git a/src/main/ezusb-emu/device.c b/src/main/ezusb-emu/device.c index 0773f28..9f1eca8 100644 --- a/src/main/ezusb-emu/device.c +++ b/src/main/ezusb-emu/device.c @@ -152,7 +152,7 @@ static HRESULT ezusb_ioctl(struct irp *irp) // Save the IO buffer that is used by the ezusb client backend and shared // with the game's main thread - write_buffer_orig = (uint8_t*) irp->write.bytes; + write_buffer_orig = (uint8_t *) irp->write.bytes; read_buffer_orig = irp->read.bytes; // Prepare our own thread locally managed and non shared buffers for any @@ -162,20 +162,22 @@ static HRESULT ezusb_ioctl(struct irp *irp) // Sanity check and visibility, in case this ever overflows if (irp->write.nbytes > sizeof(write_buffer_local)) { - log_fatal("Insufficient local write buffer available for ioctl, local " + log_fatal( + "Insufficient local write buffer available for ioctl, local " "size %d, ioctl buffer size %d", sizeof(write_buffer_local), irp->write.nbytes); } if (irp->read.nbytes > sizeof(read_buffer_local)) { - log_fatal("Insufficient local read buffer available for ioctl, local " + log_fatal( + "Insufficient local read buffer available for ioctl, local " "size %d, ioctl buffer size %d", sizeof(read_buffer_local), irp->read.nbytes); } - // Temporarily hook our local buffers to the irp + // Temporarily hook our local buffers to the irp irp->write.bytes = write_buffer_local; irp->read.bytes = read_buffer_local; @@ -248,7 +250,7 @@ static HRESULT ezusb_ioctl(struct irp *irp) memcpy(read_buffer_orig, read_buffer_local, irp->read.nbytes); // Re-store the original irp buffer state - irp->write.bytes = (const uint8_t*) write_buffer_orig; + irp->write.bytes = (const uint8_t *) write_buffer_orig; irp->read.bytes = read_buffer_orig; return res; diff --git a/src/main/ezusb-iidx-emu/msg.c b/src/main/ezusb-iidx-emu/msg.c index e818b7e..bcab656 100644 --- a/src/main/ezusb-iidx-emu/msg.c +++ b/src/main/ezusb-iidx-emu/msg.c @@ -73,11 +73,11 @@ static uint8_t ezusb_iidx_emu_msg_read_cur_node = 0; /* ------------------------------------------------------------------------ */ -struct ezusb_emu_msg_hook *ezusb_iidx_emu_msg_init( - enum ezusb_iidx_emu_msg_io_board_type io_board_type) +struct ezusb_emu_msg_hook * +ezusb_iidx_emu_msg_init(enum ezusb_iidx_emu_msg_io_board_type io_board_type) { if (io_board_type < 0 || - io_board_type >= EZUSB_IIDX_EMU_MSG_IO_BOARD_TYPE_COUNT) { + io_board_type >= EZUSB_IIDX_EMU_MSG_IO_BOARD_TYPE_COUNT) { log_fatal("Invalid io board type %d specified", io_board_type); } @@ -94,8 +94,8 @@ struct ezusb_emu_msg_hook *ezusb_iidx_emu_msg_init( ezusb_iidx_emu_node_handler = ezusb_iidx_emu_msg_nodes; - log_info("Initialized, io board type: %d", - ezusb_iidx_emu_msg_io_board_type); + log_info( + "Initialized, io board type: %d", ezusb_iidx_emu_msg_io_board_type); return &ezusb_iidx_emu_msg_hook; } @@ -186,7 +186,8 @@ static HRESULT ezusb_iidx_emu_msg_interrupt_read(struct iobuf *read) case EZUSB_IIDX_EMU_MSG_IO_BOARD_TYPE_COUNT: default: - log_fatal("Illegal state, unhandled board type: %d", + log_fatal( + "Illegal state, unhandled board type: %d", ezusb_iidx_emu_msg_io_board_type); break; } diff --git a/src/main/ezusb-iidx-emu/msg.h b/src/main/ezusb-iidx-emu/msg.h index e0198da..8a8b113 100644 --- a/src/main/ezusb-iidx-emu/msg.h +++ b/src/main/ezusb-iidx-emu/msg.h @@ -26,8 +26,8 @@ enum ezusb_iidx_emu_msg_io_board_type { * @return ezusb_emu_msg_hook structure with hook calls for ezusb msg * dispatching */ -struct ezusb_emu_msg_hook *ezusb_iidx_emu_msg_init( - enum ezusb_iidx_emu_msg_io_board_type io_board_type); +struct ezusb_emu_msg_hook * +ezusb_iidx_emu_msg_init(enum ezusb_iidx_emu_msg_io_board_type io_board_type); /** * Init the fully emulated IIDX msg backend for a EZUSB (C02) board. This diff --git a/src/main/ezusb-iidx-emu/node-serial.c b/src/main/ezusb-iidx-emu/node-serial.c index 22b423d..378ab02 100644 --- a/src/main/ezusb-iidx-emu/node-serial.c +++ b/src/main/ezusb-iidx-emu/node-serial.c @@ -161,8 +161,10 @@ _Static_assert( sizeof(struct ezusb_iidx_emu_node_serial_get_version_resp) == 13, "ezusb_iidx_emu_node_serial_get_version_resp is the wrong size"); _Static_assert( - sizeof(struct ezusb_iidx_emu_node_serial_keyboard_get_buffer_size_resp) == 2, - "ezusb_iidx_emu_node_serial_keyboard_get_buffer_size_resp is the wrong size"); + sizeof(struct ezusb_iidx_emu_node_serial_keyboard_get_buffer_size_resp) == + 2, + "ezusb_iidx_emu_node_serial_keyboard_get_buffer_size_resp is the wrong " + "size"); _Static_assert( sizeof(struct ezusb_iidx_emu_node_serial_keyboard_read_data_req) == 1, "ezusb_iidx_emu_node_serial_keyboard_read_data_req is the wrong size"); @@ -173,10 +175,12 @@ _Static_assert( sizeof(struct ezusb_iidx_emu_node_serial_card_slot_state_req) == 1, "ezusb_iidx_emu_node_serial_card_slot_state_req is the wrong size"); _Static_assert( - sizeof(struct ezusb_iidx_emu_node_serial_card_read_resp) == 1 + MAG_CARD_DATA_SIZE, + sizeof(struct ezusb_iidx_emu_node_serial_card_read_resp) == + 1 + MAG_CARD_DATA_SIZE, "ezusb_iidx_emu_node_serial_card_read_resp is the wrong size"); _Static_assert( - sizeof(struct ezusb_iidx_emu_node_serial_card_write_req) == MAG_CARD_DATA_SIZE, + sizeof(struct ezusb_iidx_emu_node_serial_card_write_req) == + MAG_CARD_DATA_SIZE, "ezusb_iidx_emu_node_serial_card_write_req is the wrong size"); _Static_assert( sizeof(struct ezusb_iidx_emu_node_serial_common_req) == 0, @@ -460,8 +464,10 @@ calc_serial_buffer_checksum(const uint8_t *buffer, uint16_t length) static struct ezusb_iidx_emu_node_serial_msg *create_generic_node_response_ok( const struct ezusb_iidx_emu_node_serial_msg *msg_in, uint16_t *msg_out_len) { - *msg_out_len = NODE_SERIAL_MSG_HEADER_SIZE + sizeof(struct ezusb_iidx_emu_node_serial_common_status_resp); - struct ezusb_iidx_emu_node_serial_msg *resp = xmalloc(sizeof(struct ezusb_iidx_emu_node_serial_msg)); + *msg_out_len = NODE_SERIAL_MSG_HEADER_SIZE + + sizeof(struct ezusb_iidx_emu_node_serial_common_status_resp); + struct ezusb_iidx_emu_node_serial_msg *resp = + xmalloc(sizeof(struct ezusb_iidx_emu_node_serial_msg)); resp->msg_cmd = CMD_NODE_RESP; resp->node_id = msg_in->node_id; resp->node_cmd = msg_in->node_cmd; @@ -484,7 +490,10 @@ static struct ezusb_iidx_emu_node_serial_msg *process_serial_msg( switch (msg_in->node_cmd) { case H8_CMD_NODE_ENUM: { log_misc("H8_CMD_NODE_ENUM"); - *msg_out_len = NODE_SERIAL_MSG_HEADER_SIZE + sizeof(struct ezusb_iidx_emu_node_serial_node_enum_resp); + *msg_out_len = + NODE_SERIAL_MSG_HEADER_SIZE + + sizeof( + struct ezusb_iidx_emu_node_serial_node_enum_resp); struct ezusb_iidx_emu_node_serial_msg *resp = xmalloc(sizeof(struct ezusb_iidx_emu_node_serial_msg)); resp->msg_cmd = CMD_H8_RESP; @@ -499,7 +508,10 @@ static struct ezusb_iidx_emu_node_serial_msg *process_serial_msg( case H8_CMD_GET_VERSION: { log_misc("H8_CMD_GET_VERSION: %d", msg_in->node_id); - *msg_out_len = NODE_SERIAL_MSG_HEADER_SIZE + sizeof(struct ezusb_iidx_emu_node_serial_get_version_resp); + *msg_out_len = + NODE_SERIAL_MSG_HEADER_SIZE + + sizeof( + struct ezusb_iidx_emu_node_serial_get_version_resp); struct ezusb_iidx_emu_node_serial_msg *resp = xmalloc(sizeof(struct ezusb_iidx_emu_node_serial_msg)); resp->msg_cmd = CMD_H8_RESP; @@ -524,7 +536,9 @@ static struct ezusb_iidx_emu_node_serial_msg *process_serial_msg( case H8_CMD_PROG_EXEC: { log_misc("H8_CMD_PROG_EXEC: %d", msg_in->node_id); - *msg_out_len = NODE_SERIAL_MSG_HEADER_SIZE + sizeof(struct ezusb_iidx_emu_node_serial_common_status_resp); + *msg_out_len = NODE_SERIAL_MSG_HEADER_SIZE + + sizeof(struct + ezusb_iidx_emu_node_serial_common_status_resp); struct ezusb_iidx_emu_node_serial_msg *resp = xmalloc(sizeof(struct ezusb_iidx_emu_node_serial_msg)); resp->msg_cmd = CMD_H8_RESP; @@ -600,7 +614,9 @@ static struct ezusb_iidx_emu_node_serial_msg *process_serial_msg( case NODE_CMD_CARD_RW_UNIT_GET_STATUS: { /* report front and back sensor states */ - *msg_out_len = NODE_SERIAL_MSG_HEADER_SIZE + sizeof(struct ezusb_iidx_emu_node_serial_common_status_resp); + *msg_out_len = NODE_SERIAL_MSG_HEADER_SIZE + + sizeof(struct + ezusb_iidx_emu_node_serial_common_status_resp); struct ezusb_iidx_emu_node_serial_msg *resp = xmalloc(sizeof(struct ezusb_iidx_emu_node_serial_msg)); resp->msg_cmd = CMD_NODE_RESP; @@ -719,7 +735,10 @@ static struct ezusb_iidx_emu_node_serial_msg *process_serial_msg( } case NODE_CMD_CARD_READ: { - *msg_out_len = NODE_SERIAL_MSG_HEADER_SIZE + sizeof(struct ezusb_iidx_emu_node_serial_card_read_resp); + *msg_out_len = + NODE_SERIAL_MSG_HEADER_SIZE + + sizeof( + struct ezusb_iidx_emu_node_serial_card_read_resp); struct ezusb_iidx_emu_node_serial_msg *resp = xmalloc(sizeof(struct ezusb_iidx_emu_node_serial_msg)); resp->msg_cmd = CMD_NODE_RESP; @@ -871,7 +890,11 @@ static struct ezusb_iidx_emu_node_serial_msg *process_serial_msg( } case NODE_CMD_KEYBOARD_GET_BUFFER_SIZE: { - *msg_out_len = NODE_SERIAL_MSG_HEADER_SIZE + sizeof(struct ezusb_iidx_emu_node_serial_keyboard_get_buffer_size_resp); + *msg_out_len = + NODE_SERIAL_MSG_HEADER_SIZE + + sizeof( + struct + ezusb_iidx_emu_node_serial_keyboard_get_buffer_size_resp); struct ezusb_iidx_emu_node_serial_msg *resp = xmalloc(sizeof(struct ezusb_iidx_emu_node_serial_msg)); resp->msg_cmd = CMD_NODE_RESP; diff --git a/src/main/ezusb2-emu/device.c b/src/main/ezusb2-emu/device.c index 3516c17..f465279 100644 --- a/src/main/ezusb2-emu/device.c +++ b/src/main/ezusb2-emu/device.c @@ -171,7 +171,7 @@ static HRESULT ezusb_ioctl(struct irp *irp) // Save the IO buffer that is used by the ezusb client backend and shared // with the game's main thread - write_buffer_orig = (uint8_t*) irp->write.bytes; + write_buffer_orig = (uint8_t *) irp->write.bytes; read_buffer_orig = irp->read.bytes; // Prepare our own thread locally managed and non shared buffers for any @@ -181,20 +181,22 @@ static HRESULT ezusb_ioctl(struct irp *irp) // Sanity check and visibility, in case this ever overflows if (irp->write.nbytes > sizeof(write_buffer_local)) { - log_fatal("Insufficient local write buffer available for ioctl, local " + log_fatal( + "Insufficient local write buffer available for ioctl, local " "size %d, ioctl buffer size %d", sizeof(write_buffer_local), irp->write.nbytes); } if (irp->read.nbytes > sizeof(read_buffer_local)) { - log_fatal("Insufficient local read buffer available for ioctl, local " + log_fatal( + "Insufficient local read buffer available for ioctl, local " "size %d, ioctl buffer size %d", sizeof(read_buffer_local), irp->read.nbytes); } - // Temporarily hook our local buffers to the irp + // Temporarily hook our local buffers to the irp irp->write.bytes = write_buffer_local; irp->read.bytes = read_buffer_local; @@ -267,7 +269,7 @@ static HRESULT ezusb_ioctl(struct irp *irp) memcpy(read_buffer_orig, read_buffer_local, irp->read.nbytes); // Re-store the original irp buffer state - irp->write.bytes = (const uint8_t*) write_buffer_orig; + irp->write.bytes = (const uint8_t *) write_buffer_orig; irp->read.bytes = read_buffer_orig; return hr; diff --git a/src/main/ezusb2-popn-emu/msg.c b/src/main/ezusb2-popn-emu/msg.c index bc73ff0..6e83f7a 100644 --- a/src/main/ezusb2-popn-emu/msg.c +++ b/src/main/ezusb2-popn-emu/msg.c @@ -164,8 +164,6 @@ static HRESULT ezusb2_popn_emu_msg_bulk_read(struct iobuf *read) return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); } - - if (!ezusb2_popn_emu_msg_nodes[ezusb2_popn_emu_msg_read_cur_node]) { log_warning( "Bulk read unsupported on cur_node = %d", diff --git a/src/main/iidxhook-util/chart-patch.c b/src/main/iidxhook-util/chart-patch.c index 8e2a3a0..4b2970e 100644 --- a/src/main/iidxhook-util/chart-patch.c +++ b/src/main/iidxhook-util/chart-patch.c @@ -262,13 +262,15 @@ static void chart_patch_execute_patch_checksum() log_warning("Could not find checksum row for %s", chart_patch_file_1_name); } -static enum song_data_path_format chart_patch_is_song_data_path(const wchar_t *path, wchar_t *song_id) +static enum song_data_path_format +chart_patch_is_song_data_path(const wchar_t *path, wchar_t *song_id) { log_assert(path); log_assert(song_id); // Song data path for 09 to 17 - // data folder next to revision folder and working dir set to revision folder + // data folder next to revision folder and working dir set to revision + // folder if (swscanf( path, // Ensure to match %lc and not %c to extract wide string chars @@ -328,19 +330,21 @@ static enum song_data_path_format chart_patch_is_song_data_path(const wchar_t *p return SONG_DATA_PATH_INVALID; } -static void chart_patch_get_song_chart_file_name(const wchar_t *song_id, wchar_t *chart_file_name) +static void chart_patch_get_song_chart_file_name( + const wchar_t *song_id, wchar_t *chart_file_name) { log_assert(song_id); log_assert(chart_file_name); log_assert(wcslen(song_id) == 4); - + memcpy(chart_file_name, song_id, sizeof(wchar_t) * 4); chart_file_name[4] = L'.'; chart_file_name[5] = L'1'; chart_file_name[6] = L'\0'; } -static enum song_data_file_type chart_patch_get_song_data_file_type(const wchar_t *path, const wchar_t *song_id) +static enum song_data_file_type +chart_patch_get_song_data_file_type(const wchar_t *path, const wchar_t *song_id) { wchar_t chart_file[7]; @@ -360,75 +364,60 @@ static enum song_data_file_type chart_patch_get_song_data_file_type(const wchar_ return SONG_DATA_FILE_TYPE_UNKNKOWN; } -static void chart_patch_get_path_dot_1_file(const wchar_t *song_id, enum song_data_path_format path_format, wchar_t *path) +static void chart_patch_get_path_dot_1_file( + const wchar_t *song_id, + enum song_data_path_format path_format, + wchar_t *path) { switch (path_format) { case SONG_DATA_PATH_09_TO_17: // Note: These use %s also for wide strings! - wsprintfW( - path, - L"..\\data\\sd_data\\%s\\%s.1", - song_id, - song_id); + wsprintfW(path, L"..\\data\\sd_data\\%s\\%s.1", song_id, song_id); break; case SONG_DATA_PATH_18: // Note: These use %s also for wide strings! - wsprintfW( - path, - L".\\data\\sd_data\\%s\\%s.1", - song_id, - song_id); + wsprintfW(path, L".\\data\\sd_data\\%s\\%s.1", song_id, song_id); break; case SONG_DATA_PATH_19: // Note: These use %s also for wide strings! - wsprintfW( - path, - L".\\data\\sound\\%s\\%s.1", - song_id, - song_id); + wsprintfW(path, L".\\data\\sound\\%s\\%s.1", song_id, song_id); break; case SONG_DATA_FILE_TYPE_UNKNKOWN: default: log_fatal("Illegal state"); break; - } + } } -static void chart_patch_get_path_checksum_file(const wchar_t *song_id, enum song_data_path_format path_format, wchar_t *path) +static void chart_patch_get_path_checksum_file( + const wchar_t *song_id, + enum song_data_path_format path_format, + wchar_t *path) { switch (path_format) { case SONG_DATA_PATH_09_TO_17: // Note: These use %s also for wide strings! - wsprintfW( - path, - L"..\\data\\sd_data\\%s\\osprey.bin", - song_id); + wsprintfW(path, L"..\\data\\sd_data\\%s\\osprey.bin", song_id); break; case SONG_DATA_PATH_18: // Note: These use %s also for wide strings! - wsprintfW( - path, - L".\\data\\sd_data\\%s\\osprey.bin", - song_id); + wsprintfW(path, L".\\data\\sd_data\\%s\\osprey.bin", song_id); break; case SONG_DATA_PATH_19: // Note: These use %s also for wide strings! - wsprintfW( - path, - L".\\data\\sound\\%s\\osprey.bin", - song_id); + wsprintfW(path, L".\\data\\sound\\%s\\osprey.bin", song_id); break; case SONG_DATA_FILE_TYPE_UNKNKOWN: default: log_fatal("Illegal state"); break; - } + } } static bool chart_patch_file_trap(struct irp *irp) @@ -452,14 +441,20 @@ static bool chart_patch_file_trap(struct irp *irp) files */ path_format = chart_patch_is_song_data_path(irp->open_filename, song_id); - + if (path_format != SONG_DATA_PATH_INVALID) { EnterCriticalSection(&chart_patch_lock); - file_type = chart_patch_get_song_data_file_type(irp->open_filename, song_id); + file_type = + chart_patch_get_song_data_file_type(irp->open_filename, song_id); // %S for printing wide strings - log_misc("Trapping song ID %S, path format %d, file type %d, path %S", song_id, path_format, file_type, irp->open_filename); + log_misc( + "Trapping song ID %S, path format %d, file type %d, path %S", + song_id, + path_format, + file_type, + irp->open_filename); /* Block a second open call to either .1 or checksum file if detouring is already active */ @@ -489,12 +484,16 @@ static bool chart_patch_file_trap(struct irp *irp) return true; } - if (file_type == SONG_DATA_FILE_TYPE_DOT_1 || file_type == SONG_DATA_FILE_TYPE_CHECKSUM) { - log_misc("Preparing in-memory chart data for song ID %S...", song_id); + if (file_type == SONG_DATA_FILE_TYPE_DOT_1 || + file_type == SONG_DATA_FILE_TYPE_CHECKSUM) { + log_misc( + "Preparing in-memory chart data for song ID %S...", song_id); chart_patch_get_song_chart_file_name(song_id, chart_file_name); - chart_patch_get_path_dot_1_file(song_id, path_format, buffer_1_path); - chart_patch_get_path_checksum_file(song_id, path_format, buffer_checksum_path); + chart_patch_get_path_dot_1_file( + song_id, path_format, buffer_1_path); + chart_patch_get_path_checksum_file( + song_id, path_format, buffer_checksum_path); if (!chart_patch_file_load( irp, &chart_patch_file_1, buffer_1_path)) { @@ -522,7 +521,7 @@ static bool chart_patch_file_trap(struct irp *irp) break; case SONG_DATA_FILE_TYPE_CHECKSUM: - irp->fd = chart_patch_file_checksum.fd; + irp->fd = chart_patch_file_checksum.fd; chart_patch_file_checksum.active = true; break; diff --git a/src/main/iidxhook-util/config-ezusb.c b/src/main/iidxhook-util/config-ezusb.c index 457e67d..e860a1d 100644 --- a/src/main/iidxhook-util/config-ezusb.c +++ b/src/main/iidxhook-util/config-ezusb.c @@ -8,7 +8,8 @@ #include "util/log.h" #include "util/mem.h" -#define IIDXHOOK_UTIL_CONFIG_EZUSB_API_CALL_MONITORING_KEY "ezusb.api_call_monitoring" +#define IIDXHOOK_UTIL_CONFIG_EZUSB_API_CALL_MONITORING_KEY \ + "ezusb.api_call_monitoring" #define IIDXHOOK_UTIL_CONFIG_EZUSB_IO_BOARD_TYPE_KEY "ezusb.io_board_type" #define IIDXHOOK_UTIL_CONFIG_EZUSB_DEFAULT_API_CALL_MONITORING_VALUE false diff --git a/src/main/iidxhook-util/settings.c b/src/main/iidxhook-util/settings.c index 4bdc6df..b4f2ce3 100644 --- a/src/main/iidxhook-util/settings.c +++ b/src/main/iidxhook-util/settings.c @@ -41,7 +41,7 @@ static void settings_build_new_path( const char *orig_path, char *new_path, size_t new_path_len) { size_t settings_path_len; - char* orig_appended_path; + char *orig_appended_path; settings_path_len = strlen(settings_path); @@ -50,13 +50,14 @@ static void settings_build_new_path( strcpy(new_path, settings_path); strcat(new_path, orig_path); - /* Fix only the part of the original path which comes after the leading settings path */ + /* Fix only the part of the original path which comes after the leading + * settings path */ orig_appended_path = new_path + settings_path_len; /* Duplicate \ in paths is fine because the win32 file API applies path normalization */ - /* Fixes some paths resulting in a mix of / and \ leading to crashes + /* Fixes some paths resulting in a mix of / and \ leading to crashes on iidx 18 and 19, e.g. settings.bin saving in operator menu */ str_replace(orig_appended_path, '/', '\\'); @@ -77,7 +78,10 @@ BOOL WINAPI my_CreateDirectoryA( settings_build_new_path(lpPathName, new_path, sizeof(new_path)); - log_misc("(CreateDir) Remapped settings path %s -> %s", lpPathName, new_path); + log_misc( + "(CreateDir) Remapped settings path %s -> %s", + lpPathName, + new_path); return real_CreateDirectoryA(new_path, lpSecurityAttributes); } diff --git a/src/main/iidxhook1/dllmain.c b/src/main/iidxhook1/dllmain.c index bffee17..05efdf9 100644 --- a/src/main/iidxhook1/dllmain.c +++ b/src/main/iidxhook1/dllmain.c @@ -27,8 +27,8 @@ #include "iidxhook-util/chart-patch.h" #include "iidxhook-util/clock.h" -#include "iidxhook-util/config-ezusb.h" #include "iidxhook-util/config-eamuse.h" +#include "iidxhook-util/config-ezusb.h" #include "iidxhook-util/config-gfx.h" #include "iidxhook-util/config-misc.h" #include "iidxhook-util/config-sec.h" diff --git a/src/main/iidxhook1/ezusb-mon.c b/src/main/iidxhook1/ezusb-mon.c index e1e86a8..b76418a 100644 --- a/src/main/iidxhook1/ezusb-mon.c +++ b/src/main/iidxhook1/ezusb-mon.c @@ -19,11 +19,11 @@ static int my_usbStart(int val); static int my_usbSecurityInit(); static int my_usbSecuritySelectDone(); -static int my_usbGetPCBID(char* buffer); -static int my_usbGetSecurity(char* buffer); -static int my_usbGetSecurityKey(char* buffer); -static int my_usbBootSecurity( - const char* boot_code, int seed_1, int seed_2, int seed_3); +static int my_usbGetPCBID(char *buffer); +static int my_usbGetSecurity(char *buffer); +static int my_usbGetSecurityKey(char *buffer); +static int +my_usbBootSecurity(const char *boot_code, int seed_1, int seed_2, int seed_3); static int my_usbSetupSecurityComplete(int val1, int val2, int val3, int val4); static int my_usbMute(int val); static int my_usbFirmResult(); @@ -31,12 +31,13 @@ static int my_usbFirmResult(); static int (*real_usbStart)(int val); static int (*real_usbSecurityInit)(); static int (*real_usbSecuritySelectDone)(); -static int (*real_usbGetPCBID)(char* buffer); -static int (*real_usbGetSecurity)(char* buffer); -static int (*real_usbGetSecurityKey)(char* buffer); +static int (*real_usbGetPCBID)(char *buffer); +static int (*real_usbGetSecurity)(char *buffer); +static int (*real_usbGetSecurityKey)(char *buffer); static int (*real_usbBootSecurity)( - const char* boot_code, int seed_1, int seed_2, int seed_3); -static int (*real_usbSetupSecurityComplete)(int val1, int val2, int val3, int val4); + const char *boot_code, int seed_1, int seed_2, int seed_3); +static int (*real_usbSetupSecurityComplete)( + int val1, int val2, int val3, int val4); static int (*real_usbMute)(int val); static int (*real_usbFirmResult)(); @@ -55,25 +56,23 @@ static const struct hook_symbol ezusb_mon_hook_syms[] = { {.name = "usbGetPCBID", .patch = my_usbGetPCBID, .link = (void **) &real_usbGetPCBID}, - {.name = "usbGetSecurity", + {.name = "usbGetSecurity", .patch = my_usbGetSecurity, .link = (void **) &real_usbGetSecurity}, - {.name = "usbGetSecurity", + {.name = "usbGetSecurity", .patch = my_usbGetSecurity, .link = (void **) &real_usbGetSecurity}, - {.name = "usbGetSecurityKey", + {.name = "usbGetSecurityKey", .patch = my_usbGetSecurityKey, .link = (void **) &real_usbGetSecurityKey}, - {.name = "usbBootSecurity", + {.name = "usbBootSecurity", .patch = my_usbBootSecurity, .link = (void **) &real_usbBootSecurity}, - {.name = "usbSetupSecurityComplete", + {.name = "usbSetupSecurityComplete", .patch = my_usbSetupSecurityComplete, .link = (void **) &real_usbSetupSecurityComplete}, - {.name = "usbMute", - .patch = my_usbMute, - .link = (void **) &real_usbMute}, - {.name = "usbFirmResult", + {.name = "usbMute", .patch = my_usbMute, .link = (void **) &real_usbMute}, + {.name = "usbFirmResult", .patch = my_usbFirmResult, .link = (void **) &real_usbFirmResult}, }; @@ -90,7 +89,7 @@ static int my_usbStart(int val) log_misc("AFTER usbStart, res: %d", res); - return res; + return res; } static int my_usbSecurityInit() @@ -119,7 +118,7 @@ static int my_usbSecuritySelectDone() return res; } -static int my_usbGetPCBID(char* buffer) +static int my_usbGetPCBID(char *buffer) { int res; @@ -132,7 +131,7 @@ static int my_usbGetPCBID(char* buffer) return res; } -static int my_usbGetSecurity(char* buffer) +static int my_usbGetSecurity(char *buffer) { int res; @@ -145,7 +144,7 @@ static int my_usbGetSecurity(char* buffer) return res; } -static int my_usbGetSecurityKey(char* buffer) +static int my_usbGetSecurityKey(char *buffer) { int res; @@ -158,14 +157,17 @@ static int my_usbGetSecurityKey(char* buffer) return res; } -static int my_usbBootSecurity( - const char* boot_code, int seed_1, int seed_2, int seed_3) +static int +my_usbBootSecurity(const char *boot_code, int seed_1, int seed_2, int seed_3) { int res; log_misc( "BEFORE usbBootSecurity, boot_code %s, seed_1 %d, seed_2 %d, seed_3 %d", - boot_code, seed_1, seed_2, seed_3); + boot_code, + seed_1, + seed_2, + seed_3); res = real_usbBootSecurity(boot_code, seed_1, seed_2, seed_3); @@ -180,7 +182,10 @@ static int my_usbSetupSecurityComplete(int val1, int val2, int val3, int val4) log_misc( "BEFORE usbSetupSecurityComplete, val1 %d, val2 %d, val3 %d, val4 %d", - val1, val2, val3, val4); + val1, + val2, + val3, + val4); res = real_usbSetupSecurityComplete(val1, val2, val3, val4); diff --git a/src/main/iidxhook1/ezusb-mon.h b/src/main/iidxhook1/ezusb-mon.h index e0568ec..31a3340 100644 --- a/src/main/iidxhook1/ezusb-mon.h +++ b/src/main/iidxhook1/ezusb-mon.h @@ -3,7 +3,7 @@ /** * Monitor and log call traces of ezusb.dll calls. - * + * * This only works on 9th and 10th Style that have the ezusb.dll linked * dynamically. Any later version has the library linked staticly */ diff --git a/src/main/iidxhook2/dllmain.c b/src/main/iidxhook2/dllmain.c index c35197d..17afc06 100644 --- a/src/main/iidxhook2/dllmain.c +++ b/src/main/iidxhook2/dllmain.c @@ -29,8 +29,8 @@ #include "iidxhook-util/acio.h" #include "iidxhook-util/chart-patch.h" #include "iidxhook-util/clock.h" -#include "iidxhook-util/config-ezusb.h" #include "iidxhook-util/config-eamuse.h" +#include "iidxhook-util/config-ezusb.h" #include "iidxhook-util/config-gfx.h" #include "iidxhook-util/config-misc.h" #include "iidxhook-util/config-sec.h" diff --git a/src/main/iidxhook5/ifs-snd-redir.c b/src/main/iidxhook5/ifs-snd-redir.c index f4809bf..e73dd5c 100644 --- a/src/main/iidxhook5/ifs-snd-redir.c +++ b/src/main/iidxhook5/ifs-snd-redir.c @@ -12,8 +12,8 @@ #include "util/log.h" #include "util/str.h" -static void* (*real_avs_fs_open)(const char* path, int mode, int flags); -static void* my_avs_fs_open(const char* path, int mode, int flags); +static void *(*real_avs_fs_open)(const char *path, int mode, int flags); +static void *my_avs_fs_open(const char *path, int mode, int flags); static const struct hook_symbol iidxhook5_ifs_snd_redir_hook_syms[] = { {.name = "XC058ba50000b6", // avs_fs_open @@ -21,9 +21,9 @@ static const struct hook_symbol iidxhook5_ifs_snd_redir_hook_syms[] = { .link = (void **) &real_avs_fs_open}, }; -static void* my_avs_fs_open(const char* path, int mode, int flags) +static void *my_avs_fs_open(const char *path, int mode, int flags) { - void* handle; + void *handle; char redir_path[MAX_PATH]; // Trap virtual path /sd00/*, /sd01/*, /sd02/*, /sd03/* that contain diff --git a/src/main/mempatch-hook/main.c b/src/main/mempatch-hook/main.c index b149640..43c1dcd 100644 --- a/src/main/mempatch-hook/main.c +++ b/src/main/mempatch-hook/main.c @@ -21,7 +21,8 @@ static bool patch_memory_check_data( for (size_t i = 0; i < len; i++) { if (dest[i] != data_expected[i]) { log_warning( - "Memcheck error: base %lluX + address %lluX + offset %d: expected %X, found %X", + "Memcheck error: base %lluX + address %lluX + offset %d: " + "expected %X, found %X", (uint64_t) base_address, (uint64_t) address, // this cast is technically wrong -- 2.54.0 From 8ef92d24a4026b80dad1f3a4ea50bd49f2bea798 Mon Sep 17 00:00:00 2001 From: icex2 Date: Thu, 6 Apr 2023 15:24:39 +0200 Subject: [PATCH 37/38] feat(doc iidx15): Add crashinig on boot due to no backup data --- doc/iidxhook/iidxhook3.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/iidxhook/iidxhook3.md b/doc/iidxhook/iidxhook3.md index bcf1d11..ff95985 100644 --- a/doc/iidxhook/iidxhook3.md +++ b/doc/iidxhook/iidxhook3.md @@ -214,3 +214,12 @@ If one or multiple of these issues apply, use the built in scaling options by se to scale to. Usually, you want to set this to the monitor's native resolution, e.g. 1920x1080 for full HD. You can play around with a few different filters using *gfx.scale_back_buffer_filter* which impacts image quality/blurriness on upscaling. + +## DJTroopers crashes on boot +The stock game is buggy and cannot create default backup data correctly. This +can be fixed by using existing backup data from a stock drive or by using +the pre-generated backup data for the `e:\` and `f:\` drives provided by +[bemanitools-supplement](https://github.com/djhackersdev/bemanitools-supplement/tree/master/iidx/15#default-backup-data). + +Copy those files to your target location that you have configured to store this +data, e.g. local `e\` and `f\` folders or the target `e:\` and `f:\` volumes. \ No newline at end of file -- 2.54.0 From dd6d645abdc22b3508b813cfa3aef1ec10d14009 Mon Sep 17 00:00:00 2001 From: icex2 Date: Tue, 21 Mar 2023 00:03:13 +0100 Subject: [PATCH 38/38] chore: Update changelog for 5.44 release --- CHANGELOG.md | 24 ++++++++++++++++++++++++ README.md | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 110b39e..75bd892 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,30 @@ Note for CI/CD: Ensure the version formatting in the sections is kept identical to the versions given in tags. The pipeline will pick this up and cuts out the relevant section for release notes. +## 5.44 +### Features +* feat(doc): ezusb dev journal entry, 10th style ezusb boot up and security setup +* feat(iidx 09/10): ezusb API call monitoring module and configuration flag +* feat(iidx 19): Add back btools monitor check for iidxhook5 +* feat(iidx 9-19): Add configurable settings path hook. Redirect settings paths, i.e. `d/`, `e/` and + `f/` drive "folders" to an arbitrary path on any partition, e.g. writable partition +* feat(iidx 9/10): Improve commandline script for irbeat-patch 09 and 10, add interactive mode + +### Fixes +* fix(iidx 10): SQ-INIT error caused by incorrect security configuration +* fix(iidx 9-24): Wire up coin input in ezusb1/2 IO emulation layer +* fix(pnm 15-18): Fix IO buffer inconsistency causing random input misfiring +* fix(jb 1-8): Fix IO buffer inconsistency causing random input misfiring +* fix(iidx 9-24): Fix IO buffer inconsistency causing random input misfiring +* fix(iidx 19): imagefs override strategy with local file redir. Required to enable monitor-check + on all chart files +* fix(iidx 9-19): Code synchronization issue causing deadlock resulting in game hang/stuck on boot +* fix(iidx 9-19): Fix broken settings path handling with mixed / and \ +* fix(iidx 27): Align disabled cam connection config defaults with 28/29 +* fix(inject): Fix missing forwarding of exit code +* fix(inject): Getting stuck when game exits cleanly due to locked up debugger thread. +* fix(iidx 18/19 CN): gamestart.bat creating dev/nvram and dev/raw folders + ## 5.43 * iidx29: (Officially) support IIDX CASTHOUR * Code structure maintenance diff --git a/README.md b/README.md index e464865..37801de 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Bemanitools 5 [![pipeline status](https://dev.s-ul.net/djhackers/bemanitools/badges/master/pipeline.svg)](https://dev.s-ul.net/djhackers/bemanitools/commits/master) -Version: 5.43 +Version: 5.44 [Release history](CHANGELOG.md) -- 2.54.0