#include #include #include #include "ll3hook/ll3-dll.h" #include "util/dll-bind.h" #include "util/dprintf.h" const struct dll_bind_sym ll3_dll_syms[] = { { .sym = "ll3_io_init", .off = offsetof(struct ll3_dll, init), }, { .sym = "ll3_io_read_coin_counter", .off = offsetof(struct ll3_dll, read_coin_counter), }, { .sym = "ll3_io_get_btns", .off = offsetof(struct ll3_dll, get_btns), }, }; struct ll3_dll ll3_dll; HRESULT ll3_dll_init(const struct ll3_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("ll3 IO: Failed to load IO DLL: %lx: %S\n", hr, cfg->path); goto end; } dprintf("ll3 IO: Using custom IO DLL: %S\n", cfg->path); src = owned; } else { owned = NULL; src = self; } get_api_version = (void *) GetProcAddress(src, "ll3_io_get_api_version"); if (get_api_version != NULL) { ll3_dll.api_version = get_api_version(); } else { ll3_dll.api_version = 0x0100; dprintf("Custom IO DLL does not expose ll3_io_get_api_version, " "assuming API version 1.0.\n" "Please ask the developer to update their DLL.\n"); } if (ll3_dll.api_version >= 0x0200) { hr = E_NOTIMPL; dprintf("ll3 IO: Custom IO DLL implements an unsupported " "API version (%#04x). Please update Segatools.\n", ll3_dll.api_version); goto end; } sym = ll3_dll_syms; hr = dll_bind(&ll3_dll, src, &sym, _countof(ll3_dll_syms)); if (FAILED(hr)) { if (src != self) { dprintf("ll3 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; }