106 lines
2.7 KiB
C
106 lines
2.7 KiB
C
#include <windows.h>
|
|
|
|
#include <assert.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "kizunahook/kizuna-dll.h"
|
|
|
|
#include "util/dll-bind.h"
|
|
#include "util/dprintf.h"
|
|
|
|
const struct dll_bind_sym kizuna_dll_syms[] = {
|
|
{
|
|
.sym = "kizuna_io_init",
|
|
.off = offsetof(struct kizuna_dll, init),
|
|
}, {
|
|
.sym = "kizuna_io_read_coin_counter",
|
|
.off = offsetof(struct kizuna_dll, read_coin_counter),
|
|
}, {
|
|
.sym = "kizuna_io_get_opbtns",
|
|
.off = offsetof(struct kizuna_dll, get_opbtns),
|
|
}, {
|
|
.sym = "kizuna_io_get_analog",
|
|
.off = offsetof(struct kizuna_dll, get_analog),
|
|
}, {
|
|
.sym = "kizuna_io_get_gamebtns",
|
|
.off = offsetof(struct kizuna_dll, get_gamebtns),
|
|
}
|
|
};
|
|
|
|
struct kizuna_dll kizuna_dll;
|
|
|
|
HRESULT kizuna_dll_init(const struct kizuna_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("Kizuna IO: Failed to load IO DLL: %lx: %S\n",
|
|
hr,
|
|
cfg->path);
|
|
|
|
goto end;
|
|
}
|
|
|
|
dprintf("Kizuna IO: Using custom IO DLL: %S\n", cfg->path);
|
|
src = owned;
|
|
} else {
|
|
owned = NULL;
|
|
src = self;
|
|
}
|
|
|
|
get_api_version = (void *) GetProcAddress(src, "kizuna_io_get_api_version");
|
|
|
|
if (get_api_version != NULL) {
|
|
kizuna_dll.api_version = get_api_version();
|
|
} else {
|
|
kizuna_dll.api_version = 0x0100;
|
|
dprintf("Custom IO DLL does not expose kizuna_io_get_api_version, "
|
|
"assuming API version 1.0.\n"
|
|
"Please ask the developer to update their DLL.\n");
|
|
}
|
|
|
|
if (kizuna_dll.api_version >= 0x0200) {
|
|
hr = E_NOTIMPL;
|
|
dprintf("Kizuna IO: Custom IO DLL implements an unsupported "
|
|
"API version (%#04x). Please update Segatools.\n",
|
|
kizuna_dll.api_version);
|
|
|
|
goto end;
|
|
}
|
|
|
|
sym = kizuna_dll_syms;
|
|
hr = dll_bind(&kizuna_dll, src, &sym, _countof(kizuna_dll_syms));
|
|
|
|
if (FAILED(hr)) {
|
|
if (src != self) {
|
|
dprintf("Kizuna 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;
|
|
} |