1
0
mirror of synced 2024-11-24 05:50:12 +01:00
bananatools/tekkenhook/tekken-dll.c
Kevin Trocolli ea60cc4a18 add tekken
2023-09-18 04:15:27 -04:00

100 lines
2.5 KiB
C

#include <windows.h>
#include <assert.h>
#include <stdlib.h>
#include "tekkenhook/tekken-dll.h"
#include "util/dll-bind.h"
#include "util/dprintf.h"
const struct dll_bind_sym tekken_dll_syms[] = {
{
.sym = "tekken_io_jvs_init",
.off = offsetof(struct tekken_dll, jvs_init),
}, {
.sym = "tekken_io_jvs_poll",
.off = offsetof(struct tekken_dll, jvs_poll),
}, {
.sym = "tekken_io_jvs_read_coin_counter",
.off = offsetof(struct tekken_dll, jvs_read_coin_counter),
}
};
struct tekken_dll tekken_dll;
HRESULT tekken_dll_init(const struct tekken_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("Tekken IO: Failed to load IO DLL: %lx: %S\n",
hr,
cfg->path);
goto end;
}
dprintf("Tekken IO: Using custom IO DLL: %S\n", cfg->path);
src = owned;
} else {
owned = NULL;
src = self;
}
get_api_version = (void *) GetProcAddress(src, "tekken_io_get_api_version");
if (get_api_version != NULL) {
tekken_dll.api_version = get_api_version();
} else {
tekken_dll.api_version = 0x0100;
dprintf("Custom IO DLL does not expose tekken_io_get_api_version, "
"assuming API version 1.0.\n"
"Please ask the developer to update their DLL.\n");
}
if (tekken_dll.api_version >= 0x0200) {
hr = E_NOTIMPL;
dprintf("Tekken IO: Custom IO DLL implements an unsupported "
"API version (%#04x). Please update Segatools.\n",
tekken_dll.api_version);
goto end;
}
sym = tekken_dll_syms;
hr = dll_bind(&tekken_dll, src, &sym, _countof(tekken_dll_syms));
if (FAILED(hr)) {
if (src != self) {
dprintf("Tekken 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;
}