Files
segatools/games/apm3hook/io4.c
kyoubate-haruka e2e4b37e3f APMv3: add hook (#73)
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.

![Apmv3System_yLRityJVpm.png](/attachments/3d645e71-81e6-42e6-acd4-63c537cda59e)
![puyoe_hJNhnJGFnd.png](/attachments/01664049-71fe-4c38-9c99-39649ab21e56)

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>
2025-07-20 09:43:56 +00:00

130 lines
2.5 KiB
C

#include <windows.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "board/io4.h"
#include "apm3hook/apm3-dll.h"
#include "util/dprintf.h"
static HRESULT apm3_io4_poll(void *ctx, struct io4_state *state);
static uint16_t coins;
static const struct io4_ops apm3_io4_ops = {
.poll = apm3_io4_poll,
};
HRESULT apm3_io4_hook_init(const struct io4_config *cfg)
{
HRESULT hr;
assert(apm3_dll.init != NULL);
hr = io4_hook_init(cfg, &apm3_io4_ops, NULL);
if (FAILED(hr)) {
return hr;
}
return apm3_dll.init();
}
static HRESULT apm3_io4_poll(void *ctx, struct io4_state *state)
{
uint8_t opbtn;
uint32_t gamebtn;
HRESULT hr;
assert(apm3_dll.poll != NULL);
assert(apm3_dll.get_opbtns != NULL);
assert(apm3_dll.get_gamebtns != NULL);
memset(state, 0, sizeof(*state));
hr = apm3_dll.poll();
if (FAILED(hr)) {
return hr;
}
opbtn = 0;
gamebtn = 0;
apm3_dll.get_opbtns(&opbtn);
apm3_dll.get_gamebtns(&gamebtn);
if (opbtn & APM3_IO_OPBTN_TEST) {
state->buttons[0] |= IO4_BUTTON_TEST;
}
if (opbtn & APM3_IO_OPBTN_SERVICE) {
state->buttons[0] |= IO4_BUTTON_SERVICE;
}
if (opbtn & APM3_IO_OPBTN_COIN) {
coins++;
}
state->chutes[0] = coins << 8;
if (gamebtn & APM3_IO_GAMEBTN_HOME) {
state->buttons[1] |= 1 << 12;
}
if (gamebtn & APM3_IO_GAMEBTN_START) {
state->buttons[0] |= 1 << 7;
}
if (gamebtn & APM3_IO_GAMEBTN_UP) {
state->buttons[0] |= 1 << 5;
}
if (gamebtn & APM3_IO_GAMEBTN_RIGHT) {
state->buttons[0] |= 1 << 2;
}
if (gamebtn & APM3_IO_GAMEBTN_DOWN) {
state->buttons[0] |= 1 << 4;
}
if (gamebtn & APM3_IO_GAMEBTN_LEFT) {
state->buttons[0] |= 1 << 3;
}
if (gamebtn & APM3_IO_GAMEBTN_B1) {
state->buttons[0] |= 1 << 1;
}
if (gamebtn & APM3_IO_GAMEBTN_B2) {
state->buttons[0] |= 1 << 0;
}
if (gamebtn & APM3_IO_GAMEBTN_B3) {
state->buttons[0] |= 1 << 15;
}
if (gamebtn & APM3_IO_GAMEBTN_B4) {
state->buttons[0] |= 1 << 14;
}
if (gamebtn & APM3_IO_GAMEBTN_B5) {
state->buttons[0] |= 1 << 13;
}
if (gamebtn & APM3_IO_GAMEBTN_B6) {
state->buttons[0] |= 1 << 12;
}
if (gamebtn & APM3_IO_GAMEBTN_B7) {
state->buttons[0] |= 1 << 11;
}
if (gamebtn & APM3_IO_GAMEBTN_B8) {
state->buttons[0] |= 1 << 10;
}
return S_OK;
}