From 90a6f1be7c25b0ca6f48bcfccf0c16d7a1aa6a34 Mon Sep 17 00:00:00 2001 From: Dniel97 Date: Fri, 14 Jul 2023 00:54:30 +0200 Subject: [PATCH] mu3: coin input added --- dist/mu3/segatools.ini | 10 +++++++--- mu3hook/io4.c | 6 ++++++ mu3io/config.c | 22 ++++++++++++++++++++++ mu3io/config.h | 16 ++++++++++++++++ mu3io/meson.build | 2 ++ mu3io/mu3io.c | 17 +++++++++++++++-- mu3io/mu3io.h | 1 + 7 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 mu3io/config.c create mode 100644 mu3io/config.h diff --git a/dist/mu3/segatools.ini b/dist/mu3/segatools.ini index 3279509..ef6df83 100644 --- a/dist/mu3/segatools.ini +++ b/dist/mu3/segatools.ini @@ -1,11 +1,11 @@ [vfs] ; Insert the path to the game AMFS directory here (contains ICF1 and ICF2) -amfs=amfs +amfs= ; Create an empty directory somewhere and insert the path here. ; This directory may be shared between multiple SEGA games. ; NOTE: This has nothing to do with Windows %APPDATA%. -appdata=appdata -option=option +appdata= +option= [dns] ; Insert the hostname or IP address of the server you wish to use here. @@ -40,8 +40,12 @@ enable=1 ; Set "1" to use a xinput gamepad and set "2" to use keyboard. mode=2 +; Test button virtual-key code. Default is the 1 key. test=0x31 +; Service button virtual-key code. Default is the 2 key. service=0x32 +; Keyboard button to increment coin counter. Default is the 3 key. +coin=0x33 [dinput] LEFT_A=0x53 diff --git a/mu3hook/io4.c b/mu3hook/io4.c index 7edcb0c..9515b50 100644 --- a/mu3hook/io4.c +++ b/mu3hook/io4.c @@ -11,6 +11,7 @@ #include "util/dprintf.h" static HRESULT mu3_io4_poll(void *ctx, struct io4_state *state); +static uint16_t coins; static const struct io4_ops mu3_io4_ops = { .poll = mu3_io4_poll, @@ -69,6 +70,11 @@ static HRESULT mu3_io4_poll(void *ctx, struct io4_state *state) state->buttons[0] |= IO4_BUTTON_SERVICE; } + if (opbtn & MU3_IO_OPBTN_COIN) { + coins++; + } + state->chutes[0] = coins << 8; + if (left & MU3_IO_GAMEBTN_1) { state->buttons[0] |= 1 << 0; } diff --git a/mu3io/config.c b/mu3io/config.c new file mode 100644 index 0000000..2fd4989 --- /dev/null +++ b/mu3io/config.c @@ -0,0 +1,22 @@ +#include + +#include +#include +#include + +#include "mu3io/config.h" + +void mu3_io_config_load( + struct mu3_io_config *cfg, + const wchar_t *filename) +{ + wchar_t key[16]; + int i; + + assert(cfg != NULL); + assert(filename != NULL); + + cfg->vk_test = GetPrivateProfileIntW(L"io4", L"test", '1', filename); + cfg->vk_service = GetPrivateProfileIntW(L"io4", L"service", '2', filename); + cfg->vk_coin = GetPrivateProfileIntW(L"io4", L"coin", '3', filename); +} diff --git a/mu3io/config.h b/mu3io/config.h new file mode 100644 index 0000000..f3632ce --- /dev/null +++ b/mu3io/config.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include + +#include + +struct mu3_io_config { + uint8_t vk_test; + uint8_t vk_service; + uint8_t vk_coin; +}; + +void mu3_io_config_load( + struct mu3_io_config *cfg, + const wchar_t *filename); diff --git a/mu3io/meson.build b/mu3io/meson.build index 3d6e60e..0b509bd 100644 --- a/mu3io/meson.build +++ b/mu3io/meson.build @@ -10,5 +10,7 @@ mu3io_lib = static_library( sources : [ 'mu3io.c', 'mu3io.h', + 'config.c', + 'config.h', ], ) diff --git a/mu3io/mu3io.c b/mu3io/mu3io.c index 0bbd37f..775a1b4 100644 --- a/mu3io/mu3io.c +++ b/mu3io/mu3io.c @@ -5,12 +5,15 @@ #include #include "mu3io/mu3io.h" +#include "mu3io/config.h" static uint8_t mu3_opbtn; static uint8_t mu3_left_btn; static uint8_t mu3_right_btn; static int16_t mu3_lever_pos; static int16_t mu3_lever_xpos; +static struct mu3_io_config mu3_io_cfg; +static bool mu3_io_coin; uint16_t mu3_io_get_api_version(void) { @@ -19,6 +22,7 @@ uint16_t mu3_io_get_api_version(void) HRESULT mu3_io_init(void) { + mu3_io_config_load(&mu3_io_cfg, L".\\segatools.ini"); return S_OK; } @@ -33,14 +37,23 @@ HRESULT mu3_io_poll(void) mu3_left_btn = 0; mu3_right_btn = 0; - if (GetAsyncKeyState('1') & 0x8000) { + if (GetAsyncKeyState(mu3_io_cfg.vk_test) & 0x8000) { mu3_opbtn |= MU3_IO_OPBTN_TEST; } - if (GetAsyncKeyState('2') & 0x8000) { + if (GetAsyncKeyState(mu3_io_cfg.vk_service) & 0x8000) { mu3_opbtn |= MU3_IO_OPBTN_SERVICE; } + if (GetAsyncKeyState(mu3_io_cfg.vk_coin) & 0x8000) { + if (!mu3_io_coin) { + mu3_io_coin = true; + mu3_opbtn |= MU3_IO_OPBTN_COIN; + } + } else { + mu3_io_coin = false; + } + memset(&xi, 0, sizeof(xi)); XInputGetState(0, &xi); xb = xi.Gamepad.wButtons; diff --git a/mu3io/mu3io.h b/mu3io/mu3io.h index d46a475..a156038 100644 --- a/mu3io/mu3io.h +++ b/mu3io/mu3io.h @@ -7,6 +7,7 @@ enum { MU3_IO_OPBTN_TEST = 0x01, MU3_IO_OPBTN_SERVICE = 0x02, + MU3_IO_OPBTN_COIN = 0x04, }; enum {