forked from Hay1tsme/segatools
This adds support for APMv3 I/O, menus and the launcher. * Added a apm3hook dll and I/O based on the usual layout. * Added C:\Mount\Apm to vfs. * Added the relevant .dlls to unityhook. * Added a hook for apmmount.dll that uses `CreateDosDevice` to mount decrypted data to the locations the launcher and games expect files to be. This will conflict with anything that is already at W:\ and X:\, but I do not have better solutions for this. * `launch.bat` is a bit more involved as it simulates the launcher loop. It can be broken by alt+f4ing or closing the launcher with "X". * An extra export was added, so rundll32 can be used to get rid of the dosdevices after the launcher was killed. * Since all the games do everything via `X:\lib\apm.dll`, no game hooks were needed in testing, therefore, `game.bat` files can be used as is. * Path hooks are applied correctly, so you can go correctly between games, launcher, sub system test mode and game test modes. A setup guide (some stuff specific to my server) can be found here: https://gmg.hopto.org:82/gmg/wiki/index.php/All.Net_P-ras_Multi_Menu Tested with the 2 APM sample apps, Blazblue, Puyo, Guilty Gear and some weird unity puzzle game whose name I forgot.   Reviewed-on: #73 Co-authored-by: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com> Co-committed-by: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com>
116 lines
3.1 KiB
C
116 lines
3.1 KiB
C
#include <windows.h>
|
|
|
|
#include <assert.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "apm3hook/apm3-dll.h"
|
|
|
|
#include "util/dll-bind.h"
|
|
#include "util/dprintf.h"
|
|
|
|
const struct dll_bind_sym apm3_dll_syms[] = {
|
|
{
|
|
.sym = "apm3_io_init",
|
|
.off = offsetof(struct apm3_dll, init),
|
|
}, {
|
|
.sym = "apm3_io_poll",
|
|
.off = offsetof(struct apm3_dll, poll),
|
|
}, {
|
|
.sym = "apm3_io_get_opbtns",
|
|
.off = offsetof(struct apm3_dll, get_opbtns),
|
|
}, {
|
|
.sym = "apm3_io_get_gamebtns",
|
|
.off = offsetof(struct apm3_dll, get_gamebtns),
|
|
}, {
|
|
.sym = "apm3_io_led_init",
|
|
.off = offsetof(struct apm3_dll, led_init),
|
|
}, {
|
|
.sym = "apm3_io_led_set_colors",
|
|
.off = offsetof(struct apm3_dll, led_set_leds),
|
|
}
|
|
};
|
|
|
|
struct apm3_dll apm3_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 apm3_dll_init(const struct apm3_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("APM IO: Failed to load IO DLL: %lx: %S\n",
|
|
hr,
|
|
cfg->path);
|
|
|
|
goto end;
|
|
}
|
|
|
|
dprintf("APM IO: Using custom IO DLL: %S\n", cfg->path);
|
|
src = owned;
|
|
} else {
|
|
owned = NULL;
|
|
src = self;
|
|
}
|
|
|
|
get_api_version = (void *) GetProcAddress(src, "apm3_io_get_api_version");
|
|
|
|
if (get_api_version != NULL) {
|
|
apm3_dll.api_version = get_api_version();
|
|
} else {
|
|
apm3_dll.api_version = 0x0100;
|
|
dprintf("Custom IO DLL does not expose apm3_io_get_api_version, "
|
|
"assuming API version 1.0.\n"
|
|
"Please ask the developer to update their DLL.\n");
|
|
}
|
|
|
|
if (apm3_dll.api_version >= 0x0200) {
|
|
hr = E_NOTIMPL;
|
|
dprintf("APM IO: Custom IO DLL implements an unsupported "
|
|
"API version (%#04x). Please update Segatools.\n",
|
|
apm3_dll.api_version);
|
|
|
|
goto end;
|
|
}
|
|
|
|
sym = apm3_dll_syms;
|
|
hr = dll_bind(&apm3_dll, src, &sym, _countof(apm3_dll_syms));
|
|
|
|
if (FAILED(hr)) {
|
|
if (src != self) {
|
|
dprintf("APM 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;
|
|
}
|