forked from TeamTofuShop/segatools
In this PR, I have added the `mai2` touch and `led15070` hooks to provide an example for handling custom peripherals. This change allows users to implement the touch and `led15070` logic by writing appropriate `mai2io` scripts. #### **Touch Hook**: - The touch hook simulates touch points based on keyboard combinations. For example, to trigger the A1 touch point, the user must press the A and 1 keys on the keyboard. Input for the 1p requires Caps Lock to be off, while 2p requires Caps Lock to be on. - The hook allows for independent control of whether device simulation is enabled for "1p" and "2p" and whether keyboard input mapping is enabled. - **Note**: The current touch hook is not yet functional as it requires modifications to the `capnhook` for proper completion of the `sinmai` hook. #### **LED15070 Hook**: - This hook implements basic device simulation. Peripherals requiring lighting data should complete the logic as needed. - **Note**: The LED data refresh can flood the console logs, so I’ve added a `DEBUG` flag to control whether the debug logging is enabled or not. #### **Other Changes**: - In certain versions of `sinmai`, key inputs for 1p and 2p can be directly read from the keyboard without requiring simulation via the `amdaemon io4` hook. I’ve added a switch to control this behavior to prevent redundant input. - **Benefit**: This ensures that key input is only read when `sinmai` is in the foreground. If you'd like to learn more about the touch and `led15070` features, my research findings are available here: [Mai2Touch](https://github.com/Sucareto/Mai2Touch) Co-authored-by: Sucareto <28331534+Sucareto@users.noreply.github.com> Reviewed-on: TeamTofuShop/segatools#55 Co-authored-by: Mahuyo <mahuyo@noreply.gitea.tendokyu.moe> Co-committed-by: Mahuyo <mahuyo@noreply.gitea.tendokyu.moe>
131 lines
3.6 KiB
C
131 lines
3.6 KiB
C
#include <windows.h>
|
|
|
|
#include <assert.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "mai2hook/mai2-dll.h"
|
|
|
|
#include "util/dll-bind.h"
|
|
#include "util/dprintf.h"
|
|
|
|
const struct dll_bind_sym mai2_dll_syms[] = {
|
|
{
|
|
.sym = "mai2_io_init",
|
|
.off = offsetof(struct mai2_dll, init),
|
|
}, {
|
|
.sym = "mai2_io_poll",
|
|
.off = offsetof(struct mai2_dll, poll),
|
|
}, {
|
|
.sym = "mai2_io_get_opbtns",
|
|
.off = offsetof(struct mai2_dll, get_opbtns),
|
|
}, {
|
|
.sym = "mai2_io_get_gamebtns",
|
|
.off = offsetof(struct mai2_dll, get_gamebtns),
|
|
}, {
|
|
.sym = "mai2_io_touch_init",
|
|
.off = offsetof(struct mai2_dll, touch_init),
|
|
}, {
|
|
.sym = "mai2_io_touch_set_sens",
|
|
.off = offsetof(struct mai2_dll, touch_set_sens),
|
|
}, {
|
|
.sym = "mai2_io_touch_update",
|
|
.off = offsetof(struct mai2_dll, touch_update),
|
|
}, {
|
|
.sym = "mai2_io_led_init",
|
|
.off = offsetof(struct mai2_dll, led_init),
|
|
}, {
|
|
.sym = "mai2_io_led_set_fet_output",
|
|
.off = offsetof(struct mai2_dll, led_set_fet_output),
|
|
}, {
|
|
.sym = "mai2_io_led_dc_update",
|
|
.off = offsetof(struct mai2_dll, led_dc_update),
|
|
}, {
|
|
.sym = "mai2_io_led_gs_update",
|
|
.off = offsetof(struct mai2_dll, led_gs_update),
|
|
},
|
|
};
|
|
|
|
struct mai2_dll mai2_dll;
|
|
|
|
// Copypasta DLL binding and diagnostic message boilerplate.
|
|
// Not much of this lends itself to being easily factored out. Also there
|
|
// will be a lot of API-specific branching code here eventually as new API
|
|
// versions get defined, so even though these functions all look the same
|
|
// now this won't remain the case forever.
|
|
|
|
HRESULT mai2_dll_init(const struct mai2_dll_config *cfg, HINSTANCE self)
|
|
{
|
|
uint16_t (*get_api_version)(void);
|
|
const struct dll_bind_sym *sym;
|
|
HINSTANCE owned;
|
|
HINSTANCE src;
|
|
HRESULT hr;
|
|
|
|
assert(cfg != NULL);
|
|
assert(self != NULL);
|
|
|
|
if (cfg->path[0] != L'\0') {
|
|
owned = LoadLibraryW(cfg->path);
|
|
|
|
if (owned == NULL) {
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
dprintf("Maimai DX IO: Failed to load IO DLL: %lx: %S\n",
|
|
hr,
|
|
cfg->path);
|
|
|
|
goto end;
|
|
}
|
|
|
|
dprintf("Maimai DX IO: Using custom IO DLL: %S\n", cfg->path);
|
|
src = owned;
|
|
} else {
|
|
owned = NULL;
|
|
src = self;
|
|
}
|
|
|
|
get_api_version = (void *) GetProcAddress(src, "mai2_io_get_api_version");
|
|
|
|
if (get_api_version != NULL) {
|
|
mai2_dll.api_version = get_api_version();
|
|
} else {
|
|
mai2_dll.api_version = 0x0101;
|
|
dprintf("Custom IO DLL does not expose mai2_io_get_api_version, "
|
|
"assuming API version 1.0.\n"
|
|
"Please ask the developer to update their DLL.\n");
|
|
}
|
|
|
|
if (mai2_dll.api_version >= 0x0200) {
|
|
hr = E_NOTIMPL;
|
|
dprintf("Maimai DX IO: Custom IO DLL implements an unsupported "
|
|
"API version (%#04x). Please update Segatools.\n",
|
|
mai2_dll.api_version);
|
|
|
|
goto end;
|
|
}
|
|
|
|
sym = mai2_dll_syms;
|
|
hr = dll_bind(&mai2_dll, src, &sym, _countof(mai2_dll_syms));
|
|
|
|
if (FAILED(hr)) {
|
|
if (src != self) {
|
|
dprintf("Maimai DX IO: Custom IO DLL does not provide function "
|
|
"\"%s\". Please contact your IO DLL's developer for "
|
|
"further assistance.\n",
|
|
sym->sym);
|
|
|
|
goto end;
|
|
} else {
|
|
dprintf("Internal error: could not reflect \"%s\"\n", sym->sym);
|
|
}
|
|
}
|
|
|
|
owned = NULL;
|
|
|
|
end:
|
|
if (owned != NULL) {
|
|
FreeLibrary(owned);
|
|
}
|
|
|
|
return hr;
|
|
}
|