From c28c36dc991c7bc90866aaef0c34575a9f4df825 Mon Sep 17 00:00:00 2001 From: xpeng <1216772231@qq.com> Date: Sun, 31 Jul 2022 18:11:24 +0000 Subject: [PATCH] Add led support for mercuryio.dll --- Package.mk | 1 + dist/mercury/segatools.ini | 7 +++++++ mercuryhook/elisabeth.c | 12 ++++++++++++ mercuryhook/elisabeth.h | 5 +++++ mercuryhook/mercury-dll.c | 3 +++ mercuryhook/mercury-dll.h | 2 ++ mercuryhook/mercuryhook.def | 1 + mercuryio/mercuryio.c | 6 ++++++ mercuryio/mercuryio.def | 11 +++++++++++ mercuryio/mercuryio.h | 4 ++++ mercuryio/meson.build | 9 +++++++++ 11 files changed, 61 insertions(+) create mode 100644 mercuryio/mercuryio.def diff --git a/Package.mk b/Package.mk index 53fd832..85f6b80 100644 --- a/Package.mk +++ b/Package.mk @@ -34,6 +34,7 @@ $(BUILD_DIR_ZIP)/mercury.zip: $(V)mkdir -p $(BUILD_DIR_ZIP)/mercury/DEVICE $(V)cp $(BUILD_DIR_64)/subprojects/capnhook/inject/inject.exe \ $(BUILD_DIR_64)/mercuryhook/mercuryhook.dll \ + $(BUILD_DIR_64)/mercuryio/mercuryio.dll \ $(DIST_DIR)/mercury/segatools.ini \ $(DIST_DIR)/mercury/start.bat \ $(BUILD_DIR_ZIP)/mercury diff --git a/dist/mercury/segatools.ini b/dist/mercury/segatools.ini index fbb238c..9fc5bba 100644 --- a/dist/mercury/segatools.ini +++ b/dist/mercury/segatools.ini @@ -43,3 +43,10 @@ coin=0x24 volup=0x26 voldown=0x28 +[touch] +; Enable or disable touch hook +enable=1 + +;[mercuryio] +; Use mercuryio.dll +;path=mercuryio.dll \ No newline at end of file diff --git a/mercuryhook/elisabeth.c b/mercuryhook/elisabeth.c index 71c4a05..baac575 100644 --- a/mercuryhook/elisabeth.c +++ b/mercuryhook/elisabeth.c @@ -23,6 +23,7 @@ static void dll_hook_insert_hooks(HMODULE target); static FARPROC WINAPI my_GetProcAddress(HMODULE hModule, const char *name); static FARPROC (WINAPI *next_GetProcAddress)(HMODULE hModule, const char *name); static int my_USBIntLED_Init(); +static int my_USBIntLED_set(); static const struct hook_symbol win32_hooks[] = { { @@ -59,6 +60,10 @@ FARPROC WINAPI my_GetProcAddress(HMODULE hModule, const char *name) if (strcmp(name, "USBIntLED_Init") == 0) { result = (FARPROC) my_USBIntLED_Init; } + + if (strcmp(name, "USBIntLED_set") == 0) { + result = (FARPROC) my_USBIntLED_set; + } } return result; @@ -70,3 +75,10 @@ static int my_USBIntLED_Init() dprintf("Elisabeth: my_USBIntLED_Init hit!\n"); return 1; } + +static int my_USBIntLED_set(int data1, struct led_data data2) +{ + assert(mercury_dll.set_leds != NULL); + mercury_dll.set_leds(data2); + return 1; +} diff --git a/mercuryhook/elisabeth.h b/mercuryhook/elisabeth.h index 9692c34..41066fc 100644 --- a/mercuryhook/elisabeth.h +++ b/mercuryhook/elisabeth.h @@ -1,3 +1,8 @@ #pragma once +struct led_data { + DWORD unitCount; + uint8_t rgba[480 * 4]; +}; + HRESULT elisabeth_hook_init(); diff --git a/mercuryhook/mercury-dll.c b/mercuryhook/mercury-dll.c index 19c183a..47d3eab 100644 --- a/mercuryhook/mercury-dll.c +++ b/mercuryhook/mercury-dll.c @@ -27,6 +27,9 @@ const struct dll_bind_sym mercury_dll_syms[] = { }, { .sym = "mercury_io_touch_start", .off = offsetof(struct mercury_dll, touch_start), + }, { + .sym = "mercury_io_touch_set_leds", + .off = offsetof(struct mercury_dll, set_leds), } }; diff --git a/mercuryhook/mercury-dll.h b/mercuryhook/mercury-dll.h index 086fd92..fa27edb 100644 --- a/mercuryhook/mercury-dll.h +++ b/mercuryhook/mercury-dll.h @@ -3,6 +3,7 @@ #include #include "mercuryio/mercuryio.h" +#include "mercuryhook/elisabeth.h" struct mercury_dll { uint16_t api_version; @@ -12,6 +13,7 @@ struct mercury_dll { void (*get_gamebtns)(uint8_t *gamebtn); HRESULT (*touch_init)(void); void (*touch_start)(mercury_io_touch_callback_t callback); + void (*set_leds)(struct led_data data); }; struct mercury_dll_config { diff --git a/mercuryhook/mercuryhook.def b/mercuryhook/mercuryhook.def index b12bc79..32f33c1 100644 --- a/mercuryhook/mercuryhook.def +++ b/mercuryhook/mercuryhook.def @@ -16,5 +16,6 @@ EXPORTS mercury_io_get_opbtns mercury_io_touch_init mercury_io_touch_start + mercury_io_touch_set_leds mercury_io_init mercury_io_poll diff --git a/mercuryio/mercuryio.c b/mercuryio/mercuryio.c index 9ad755b..6d38ff1 100644 --- a/mercuryio/mercuryio.c +++ b/mercuryio/mercuryio.c @@ -6,6 +6,7 @@ #include "mercuryio/mercuryio.h" #include "mercuryio/config.h" +#include "mercuryhook/elisabeth.h" static unsigned int __stdcall mercury_io_touch_thread_proc(void *ctx); @@ -90,6 +91,11 @@ void mercury_io_touch_start(mercury_io_touch_callback_t callback) ); } +void mercury_io_touch_set_leds(struct led_data data) +{ + +} + static unsigned int __stdcall mercury_io_touch_thread_proc(void *ctx) { mercury_io_touch_callback_t callback; diff --git a/mercuryio/mercuryio.def b/mercuryio/mercuryio.def new file mode 100644 index 0000000..167d1cf --- /dev/null +++ b/mercuryio/mercuryio.def @@ -0,0 +1,11 @@ +LIBRARY mercuryio + +EXPORTS + mercury_io_get_api_version + mercury_io_init + mercury_io_poll + mercury_io_get_opbtns + mercury_io_get_gamebtns + mercury_io_touch_init + mercury_io_touch_start + mercury_io_touch_set_leds \ No newline at end of file diff --git a/mercuryio/mercuryio.h b/mercuryio/mercuryio.h index 2701ec4..1031698 100644 --- a/mercuryio/mercuryio.h +++ b/mercuryio/mercuryio.h @@ -4,6 +4,8 @@ #include +#include "mercuryhook/elisabeth.h" + enum { MERCURY_IO_OPBTN_TEST = 0x01, MERCURY_IO_OPBTN_SERVICE = 0x02, @@ -64,3 +66,5 @@ void mercury_io_get_gamebtns(uint8_t *gamebtn); HRESULT mercury_io_touch_init(void); void mercury_io_touch_start(mercury_io_touch_callback_t callback); + +void mercury_io_touch_set_leds(struct led_data data); diff --git a/mercuryio/meson.build b/mercuryio/meson.build index 813958a..4e6c0eb 100644 --- a/mercuryio/meson.build +++ b/mercuryio/meson.build @@ -11,3 +11,12 @@ mercuryio_lib = static_library( 'config.h', ], ) + +shared_library( + 'mercuryio', + name_prefix : '', + vs_module_defs : 'mercuryio.def', + link_with : [ + mercuryio_lib, + ], +) \ No newline at end of file