Files
グローランプ ff28d4ff09 mai2io: add camera LED control functions (#91)
This is a follow-up to the previous PR. I realized I omitted the camera LED control interface, so I'm adding it now to complete the v1.02 API set.

**Changes:**
* Added `mai2_io_led_cam_set` to the 0x0102 API.
* Wired IO4 GPIO outputs to forward code reader/player camera light states.
* Updated `mai2hook.def` to export the new symbol.
* Updated `MAI2_DLL_SYM_COUNT_V102` to reflect the additional symbol count.

**Versioning Note:**
Since the previous PR was just merged and v1.02 hasn't been officially released yet, I've opted to include this in the existing **0x0102** version rather than bumping to 0x0103.

Reviewed-on: https://gitea.tendokyu.moe/TeamTofuShop/segatools/pulls/91
Co-authored-by: グローランプ <130208311+Gl0w1amp@users.noreply.github.com>
Co-committed-by: グローランプ <130208311+Gl0w1amp@users.noreply.github.com>
2026-01-04 08:41:56 +00:00

147 lines
4.0 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"
enum {
MAI2_DLL_SYM_COUNT_V101 = 11,
MAI2_DLL_SYM_COUNT_V102 = 13,
};
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),
}, {
.sym = "mai2_io_led_billboard_set",
.off = offsetof(struct mai2_dll, led_set_leds),
}, {
.sym = "mai2_io_led_cam_set",
.off = offsetof(struct mai2_dll, led_cam_set),
},
};
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;
size_t sym_count;
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;
sym_count = (mai2_dll.api_version < 0x0102)
? MAI2_DLL_SYM_COUNT_V101
: MAI2_DLL_SYM_COUNT_V102;
hr = dll_bind(&mai2_dll, src, &sym, sym_count);
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;
}