From 91e62b5a1d1f4b3517cd28bcc2d297fa0df79369 Mon Sep 17 00:00:00 2001 From: Luna Nightshade Date: Mon, 22 May 2023 22:29:44 +0100 Subject: [PATCH] add brokenithm code --- chuniio/chuniio.c | 125 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 87 insertions(+), 38 deletions(-) diff --git a/chuniio/chuniio.c b/chuniio/chuniio.c index 8e07f56..32a9333 100644 --- a/chuniio/chuniio.c +++ b/chuniio/chuniio.c @@ -1,3 +1,11 @@ +// chuniio_air - chuniio.c +// project air modified version +// +// based on code by esterTion +// modified by astelle nightshade (lostkagamine) +// +// music game never die + #include #include @@ -11,37 +19,79 @@ static unsigned int __stdcall chuni_io_slider_thread_proc(void* ctx); static bool chuni_io_coin; static uint16_t chuni_io_coins; -static uint8_t chuni_io_hand_pos; static HANDLE chuni_io_slider_thread; static bool chuni_io_slider_stop_flag; static struct chuni_io_config chuni_io_cfg; -API uint16_t chuni_io_get_api_version(void) +struct IPCMemoryInfo +{ + uint8_t airIoStatus[6]; + uint8_t sliderIoStatus[32]; + uint8_t ledRgbData[32 * 3]; + uint8_t testBtn; + uint8_t serviceBtn; + uint8_t coinInsertion; + uint8_t cardRead; +}; + +typedef struct IPCMemoryInfo IPCMemoryInfo; +static HANDLE FileMappingHandle; +IPCMemoryInfo* FileMapping; + +void initSharedMemory() { - return 0x0101; + if (FileMapping) + { + return; + } + if ((FileMappingHandle = CreateFileMappingA(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, sizeof(IPCMemoryInfo), "Local\\BROKENITHM_SHARED_BUFFER")) == 0) + { + return; + } + + if ((FileMapping = (IPCMemoryInfo*)MapViewOfFile(FileMappingHandle, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(IPCMemoryInfo))) == 0) + { + return; + } + + memset(FileMapping, 0, sizeof(IPCMemoryInfo)); + SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_CONTINUOUS); } API HRESULT chuni_io_jvs_init(void) { chuni_io_config_load(&chuni_io_cfg, L".\\segatools.ini"); + initSharedMemory(); + return S_OK; } API void chuni_io_jvs_read_coin_counter(uint16_t* out) { - if (out == NULL) { + if (out == NULL) + { return; } - if (GetAsyncKeyState(chuni_io_cfg.vk_coin)) { - if (!chuni_io_coin) { - chuni_io_coin = true; - chuni_io_coins++; - } + if (FileMapping && FileMapping->coinInsertion) + { + chuni_io_coins++; + FileMapping->coinInsertion = 0; } else { - chuni_io_coin = false; + if (GetAsyncKeyState(chuni_io_cfg.vk_coin)) + { + if (!chuni_io_coin) + { + chuni_io_coin = true; + chuni_io_coins++; + } + } + else + { + chuni_io_coin = false; + } } *out = chuni_io_coins; @@ -51,32 +101,29 @@ API void chuni_io_jvs_poll(uint8_t* opbtn, uint8_t* beams) { size_t i; - if (GetAsyncKeyState(chuni_io_cfg.vk_test)) { + if ((FileMapping && FileMapping->testBtn) || GetAsyncKeyState(chuni_io_cfg.vk_test)) + { *opbtn |= 0x01; /* Test */ } - if (GetAsyncKeyState(chuni_io_cfg.vk_service)) { + if ((FileMapping && FileMapping->serviceBtn) || GetAsyncKeyState(chuni_io_cfg.vk_service)) + { *opbtn |= 0x02; /* Service */ } - if (GetAsyncKeyState(chuni_io_cfg.vk_ir)) { - if (chuni_io_hand_pos < 6) { - chuni_io_hand_pos++; - } - } - else { - if (chuni_io_hand_pos > 0) { - chuni_io_hand_pos--; - } - } - - for (i = 0; i < 6; i++) { - if (chuni_io_hand_pos > i) { + for (i = 0; i < 6; i++) + { + if (FileMapping && FileMapping->airIoStatus[i]) + { *beams |= (1 << i); } } } +API void chuni_io_jvs_set_coin_blocker(bool open) +{ +} + API HRESULT chuni_io_slider_init(void) { return S_OK; @@ -84,7 +131,8 @@ API HRESULT chuni_io_slider_init(void) API void chuni_io_slider_start(chuni_io_slider_callback_t callback) { - if (chuni_io_slider_thread != NULL) { + if (chuni_io_slider_thread != NULL) + { return; } @@ -97,9 +145,10 @@ API void chuni_io_slider_start(chuni_io_slider_callback_t callback) NULL); } -void chuni_io_slider_stop(void) +API void chuni_io_slider_stop(void) { - if (chuni_io_slider_thread == NULL) { + if (chuni_io_slider_thread == NULL) + { return; } @@ -113,24 +162,24 @@ void chuni_io_slider_stop(void) API void chuni_io_slider_set_leds(const uint8_t* rgb) { + if (FileMapping) + { + memcpy(FileMapping->ledRgbData, rgb, 32 * 3); + } } static unsigned int __stdcall chuni_io_slider_thread_proc(void* ctx) { chuni_io_slider_callback_t callback; - uint8_t pressure[32]; - size_t i; + uint8_t pressure[32] = { 0 }; callback = ctx; - while (!chuni_io_slider_stop_flag) { - for (i = 0; i < _countof(pressure); i++) { - if (GetAsyncKeyState(chuni_io_cfg.vk_cell[i]) & 0x8000) { - pressure[i] = 128; - } - else { - pressure[i] = 0; - } + while (!chuni_io_slider_stop_flag) + { + if (FileMapping) + { + memcpy(pressure, FileMapping->sliderIoStatus, 32); } callback(pressure);