apm: Fix distribution server handling, abaas log symlinks, add extra buttons for dinput (#123)

Requires https://gitea.tendokyu.moe/TeamTofuShop/capnhook/pulls/8

This adds the following:

1. Fixes `am::abaas::FileSearchSuite::isAvailableAbsolutePath: Line259  ERROR: folder is unavailable (Y:\SDEM\log\\SDFU)` by hooking `DeviceIoControl` with `FSCTL_SET_REPARSE_POINT`.

Sega decided to use the most bizzare way possible of creating symbolic links. These are created in the AbaaS log directory inside SDEM and point to the appdata directories for the sub-games.

Magic numbers have been taken from amdaemon decompilation. That whole API is very sparsely documented on the Microsoft side.

2. Fixes distribution server settings not applying.

Unlike most other games, the daemon config files do not have dipswitch filters in them. Instead the distribution setting is determined by running `hwvalue.exe` twice and checking it's exit code. This has been added to `launch.bat` and requires the linked addition for inject.

3. Implemented `get_opbtns` and added extra buttons for dinput.

* `get_opbtns` existed but was never implemented. Added the ability to bind dinput buttons for test/service.
* DirectInput is weird. The controller I'm using is sending directional keys as buttons rather than a D-Pad, so I was unable to bind it. These extra directional buttons can be bound in addition to the bindings that exist for a D-Pad.

4. Fixes audio in Rolling Gunner by setting the CWD to the root of the C:\ drive before starting a game.

lol. lmao even.

5. Add a `DefineDosDevice` for Y:\ to fix Blazblue crashing

They hardcoded the damn path to appdata instead of retrieving it from the apm.dll...

Reviewed-on: https://gitea.tendokyu.moe/TeamTofuShop/segatools/pulls/123
Co-authored-by: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com>
Co-committed-by: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com>
This commit is contained in:
kyoubate-haruka
2026-07-19 08:25:54 +00:00
committed by Dniel97
parent fab190272c
commit d29a3926ab
9 changed files with 202 additions and 5 deletions
+19 -1
View File
@@ -114,7 +114,7 @@ bool hook_ApmSys_mountVhd(const wchar_t* vhdOriginalPath, const wchar_t* vhdPatc
// Game drive
wchar_t device[3];
device[0] = mountDriveLetter;
device[0] = (unsigned char) mountDriveLetter;
device[1] = ':';
device[2] = '\0';
@@ -136,9 +136,19 @@ bool hook_ApmSys_mountVhd(const wchar_t* vhdOriginalPath, const wchar_t* vhdPatc
return 1;
}
// Appdata drive
device[0] = 'Y';
dprintf("Mount: Mapping %ls to %ls\n", device, vcfg->appdata);
if (!DefineDosDeviceW(0, device, vcfg->appdata)) {
dprintf("DefineDosDevice failed: %lx\n", GetLastError());
return 1;
}
if (mcfg->delay) {
Sleep(1500);
}
return 0;
}
bool hook_ApmSys_unmountVhd(char mountDriveLetter) {
@@ -161,12 +171,20 @@ bool hook_ApmSys_unmountVhd(char mountDriveLetter) {
dprintf("DefineDosDevice failed: %lx\n", GetLastError());
return 1;
}
// Appdata drive
device[0] = 'Y';
if (!DefineDosDevice(DDD_REMOVE_DEFINITION, device, NULL)) {
dprintf("DefineDosDevice failed: %lx\n", GetLastError());
return 1;
}
return 0;
}
void CALLBACK UnmountApmDrives(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow) {
hook_ApmSys_unmountVhd('W');
hook_ApmSys_unmountVhd('X');
hook_ApmSys_unmountVhd('Y');
}
bool hook_ApmSys_unmountFscrypt(const wchar_t* mountFolderPath) {
+8
View File
@@ -47,6 +47,14 @@ void apm3_di_config_load(struct apm3_di_config *cfg, const wchar_t *filename)
_countof(cfg->device_name),
filename);
cfg->test = GetPrivateProfileIntW(L"dinput", L"test", 0, filename);
cfg->service = GetPrivateProfileIntW(L"dinput", L"service", 0, filename);
cfg->up = GetPrivateProfileIntW(L"dinput", L"up", 0, filename);
cfg->right = GetPrivateProfileIntW(L"dinput", L"right", 0, filename);
cfg->down = GetPrivateProfileIntW(L"dinput", L"down", 0, filename);
cfg->left = GetPrivateProfileIntW(L"dinput", L"left", 0, filename);
cfg->home = GetPrivateProfileIntW(L"dinput", L"home", 0, filename);
cfg->start = GetPrivateProfileIntW(L"dinput", L"start", 0, filename);
+6
View File
@@ -8,9 +8,15 @@
struct apm3_di_config {
wchar_t device_name[64];
uint8_t test;
uint8_t service;
uint8_t start;
uint8_t home;
uint8_t button[8];
uint8_t up;
uint8_t right;
uint8_t down;
uint8_t left;
};
struct apm3_xi_config {
+50 -2
View File
@@ -21,11 +21,13 @@ static BOOL CALLBACK apm3_di_enum_callback(
const DIDEVICEINSTANCEW *dev,
void *ctx);
static void apm3_di_get_gamebtns(uint16_t *gamebtn_out);
static void apm3_di_get_opbtns(uint8_t *opbtn_out);
static uint8_t apm3_di_decode_pov(DWORD pov);
static const struct apm3_io_backend apm3_di_backend = {
.get_gamebtns = apm3_di_get_gamebtns,
.get_opbtns = apm3_di_get_opbtns
};
static HWND apm3_di_wnd;
@@ -34,8 +36,16 @@ static IDirectInputDevice8W *apm3_di_dev;
static IDirectInputEffect *apm3_di_fx;
static uint8_t apm3_di_home;
static uint8_t apm3_di_start;
static uint8_t apm3_di_service;
static uint8_t apm3_di_test;
static uint8_t apm3_di_extra_up;
static uint8_t apm3_di_extra_right;
static uint8_t apm3_di_extra_down;
static uint8_t apm3_di_extra_left;
static uint8_t apm3_di_button[APM3_BUTTON_COUNT];
static union apm3_di_state state = {0};
HRESULT apm3_di_init(
const struct apm3_di_config *cfg,
HINSTANCE inst,
@@ -136,6 +146,8 @@ static HRESULT apm3_di_config_apply(const struct apm3_di_config *cfg)
cfg->device_name);
dprintf("Stick: Home button . . . : %i\n", cfg->home);
dprintf("Stick: Start button . . . : %i\n", cfg->start);
dprintf("Stick: Service button . . : %i\n", cfg->service);
dprintf("Stick: Test button . . . : %i\n", cfg->test);
/* Print the configuration for all 8 buttons */
for (i = 0; i < APM3_BUTTON_COUNT; i++) {
@@ -146,7 +158,14 @@ static HRESULT apm3_di_config_apply(const struct apm3_di_config *cfg)
apm3_di_start = cfg->start;
apm3_di_home = cfg->home;
apm3_di_service = cfg->service;
apm3_di_test = cfg->test;
apm3_di_extra_up = cfg->up;
apm3_di_extra_right = cfg->right;
apm3_di_extra_down = cfg->down;
apm3_di_extra_left = cfg->left;
for (i = 0; i < APM3_BUTTON_COUNT; i++) {
apm3_di_button[i] = cfg->button[i];
}
@@ -184,7 +203,6 @@ static BOOL CALLBACK apm3_di_enum_callback(
static void apm3_di_get_gamebtns(uint16_t *gamebtn_out)
{
union apm3_di_state state;
uint16_t gamebtn;
HRESULT hr;
@@ -198,6 +216,22 @@ static void apm3_di_get_gamebtns(uint16_t *gamebtn_out)
gamebtn = apm3_di_decode_pov(state.st.rgdwPOV[0]);
if (apm3_di_extra_up && state.st.rgbButtons[apm3_di_extra_up - 1]) {
gamebtn |= APM3_IO_GAMEBTN_UP;
}
if (apm3_di_extra_right && state.st.rgbButtons[apm3_di_extra_right - 1]) {
gamebtn |= APM3_IO_GAMEBTN_RIGHT;
}
if (apm3_di_extra_down && state.st.rgbButtons[apm3_di_extra_down - 1]) {
gamebtn |= APM3_IO_GAMEBTN_DOWN;
}
if (apm3_di_extra_left && state.st.rgbButtons[apm3_di_extra_left - 1]) {
gamebtn |= APM3_IO_GAMEBTN_LEFT;
}
if (apm3_di_start && state.st.rgbButtons[apm3_di_start - 1]) {
gamebtn |= APM3_IO_GAMEBTN_START;
}
@@ -255,3 +289,17 @@ static uint8_t apm3_di_decode_pov(DWORD pov)
default: return 0;
}
}
static void apm3_di_get_opbtns(uint8_t *opbtn_out) {
uint8_t opbtn = 0;
if (apm3_di_service && state.st.rgbButtons[apm3_di_service - 1]) {
opbtn |= APM3_IO_OPBTN_SERVICE;
}
if (apm3_di_test && state.st.rgbButtons[apm3_di_test - 1]) {
opbtn |= APM3_IO_OPBTN_TEST;
}
*opbtn_out = opbtn;
}
+4
View File
@@ -83,6 +83,10 @@ void apm3_io_get_opbtns(uint8_t *opbtn_out)
apm3_io_coin = false;
}
if (apm3_io_backend->get_opbtns != NULL) {
apm3_io_backend->get_opbtns(&opbtn);
}
*opbtn_out = opbtn;
}