merge upstream

This commit is contained in:
2025-08-09 15:12:16 +00:00
26 changed files with 335 additions and 384 deletions

View File

@ -1,6 +1,6 @@
# Segatools
Version: `2025-07-20`
Version: `2025-07-27`
Loaders and hardware emulators for SEGA games that run on the Nu and ALLS platforms.

View File

@ -136,6 +136,31 @@ static BOOL WINAPI hook_DeleteFileA(const char *lpFileName);
static BOOL WINAPI hook_DeleteFileW(const wchar_t *lpFileName);
static DWORD WINAPI hook_GetPrivateProfileStringA(
LPCSTR lpAppName,
LPCSTR lpKeyName,
LPCSTR lpDefault,
LPSTR lpReturnedString,
DWORD nSize,
LPCSTR lpFileName
);
static DWORD WINAPI hook_GetPrivateProfileStringW(
LPCWSTR lpAppName,
LPCWSTR lpKeyName,
LPCWSTR lpDefault,
LPWSTR lpReturnedString,
DWORD nSize,
LPCWSTR lpFileName
);
static DWORD WINAPI hook_GetPrivateProfileSectionW(
LPCWSTR lpAppName,
LPWSTR lpReturnedString,
DWORD nSize,
LPCWSTR lpFileName
);
/* Link pointers */
static BOOL (WINAPI *next_CreateDirectoryA)(
@ -253,6 +278,31 @@ static BOOL (WINAPI *next_DeleteFileA)(const char *lpFileName);
static BOOL (WINAPI *next_DeleteFileW)(const wchar_t *lpFileName);
static DWORD (WINAPI *next_GetPrivateProfileStringA)(
LPCSTR lpAppName,
LPCSTR lpKeyName,
LPCSTR lpDefault,
LPSTR lpReturnedString,
DWORD nSize,
LPCSTR lpFileName
);
static DWORD (WINAPI *next_GetPrivateProfileStringW)(
LPCWSTR lpAppName,
LPCWSTR lpKeyName,
LPCWSTR lpDefault,
LPWSTR lpReturnedString,
DWORD nSize,
LPCWSTR lpFileName
);
static DWORD (WINAPI *next_GetPrivateProfileSectionW)(
LPCWSTR lpAppName,
LPWSTR lpReturnedString,
DWORD nSize,
LPCWSTR lpFileName
);
/* Hook table */
static const struct hook_symbol path_hook_syms[] = {
@ -356,6 +406,18 @@ static const struct hook_symbol path_hook_syms[] = {
.name = "DeleteFileW",
.patch = hook_DeleteFileW,
.link = (void **) &next_DeleteFileW,
}, {
.name = "GetPrivateProfileStringA",
.patch = hook_GetPrivateProfileStringA,
.link = (void **) &next_GetPrivateProfileStringA,
}, {
.name = "GetPrivateProfileStringW",
.patch = hook_GetPrivateProfileStringW,
.link = (void **) &next_GetPrivateProfileStringW,
}, {
.name = "GetPrivateProfileSectionW",
.patch = hook_GetPrivateProfileSectionW,
.link = (void **) &next_GetPrivateProfileSectionW,
}
};
@ -1034,7 +1096,7 @@ static BOOL WINAPI hook_MoveFileA(
ok = next_MoveFileA(
oldTrans ? oldTrans : lpExistingFileName,
newTrans ? newTrans : lpNewFileName);
free(oldTrans);
free(newTrans);
@ -1066,7 +1128,7 @@ static BOOL WINAPI hook_MoveFileW(
ok = next_MoveFileW(
oldTrans ? oldTrans : lpExistingFileName,
newTrans ? newTrans : lpNewFileName);
free(oldTrans);
free(newTrans);
@ -1100,7 +1162,7 @@ static BOOL WINAPI hook_MoveFileExA(
oldTrans ? oldTrans : lpExistingFileName,
newTrans ? newTrans : lpNewFileName,
dwFlags);
free(oldTrans);
free(newTrans);
@ -1187,7 +1249,7 @@ static BOOL WINAPI hook_ReplaceFileW(
return ok;
}
static BOOL WINAPI hook_DeleteFileA(const char *lpFileName)
static BOOL WINAPI hook_DeleteFileA(const char *lpFileName)
{
char *trans;
BOOL ok;
@ -1218,3 +1280,61 @@ static BOOL WINAPI hook_DeleteFileW(const wchar_t *lpFileName)
return ok;
}
static DWORD WINAPI hook_GetPrivateProfileStringA(
LPCSTR lpAppName,
LPCSTR lpKeyName,
LPCSTR lpDefault,
LPSTR lpReturnedString,
DWORD nSize,
LPCSTR lpFileName
) {
char *trans;
BOOL ok;
ok = path_transform_a(&trans, lpFileName);
if (!ok) {
return FALSE;
}
return next_GetPrivateProfileStringA(lpAppName, lpKeyName, lpDefault, lpReturnedString, nSize, trans ? trans: lpFileName);
}
static DWORD WINAPI hook_GetPrivateProfileStringW(
LPCWSTR lpAppName,
LPCWSTR lpKeyName,
LPCWSTR lpDefault,
LPWSTR lpReturnedString,
DWORD nSize,
LPCWSTR lpFileName
) {
wchar_t *trans;
BOOL ok;
ok = path_transform_w(&trans, lpFileName);
if (!ok) {
return FALSE;
}
return next_GetPrivateProfileStringW(lpAppName, lpKeyName, lpDefault, lpReturnedString, nSize, trans ? trans: lpFileName);
}
static DWORD WINAPI hook_GetPrivateProfileSectionW(
LPCWSTR lpAppName,
LPWSTR lpReturnedString,
DWORD nSize,
LPCWSTR lpFileName
) {
wchar_t *trans;
BOOL ok;
ok = path_transform_w(&trans, lpFileName);
if (!ok) {
return FALSE;
}
return next_GetPrivateProfileSectionW(lpAppName, lpReturnedString, nSize, trans ? trans: lpFileName);
}

View File

@ -360,5 +360,5 @@ void epay_config_load(struct epay_config *cfg, const wchar_t *filename)
assert(filename != NULL);
cfg->enable = GetPrivateProfileIntW(L"epay", L"enable", 1, filename);
cfg->hook = GetPrivateProfileIntW(L"epay", L"hook", 0, filename);
cfg->hook = GetPrivateProfileIntW(L"epay", L"hook", 1, filename);
}

View File

@ -95,7 +95,6 @@ static void dll_hook_insert_hooks(HMODULE target) {
static HMODULE WINAPI hook_LoadLibraryExW(const wchar_t *name, HANDLE hFile, DWORD dwFlags)
{
// dprintf("Unity: LoadLibraryExW %ls\n", name);
return hook_LoadLibraryW(name);
}
@ -157,11 +156,6 @@ static HMODULE WINAPI hook_LoadLibraryW(const wchar_t *name)
if (hook_load_callback != NULL){
hook_load_callback(result, target_module);
}
// Not needed?
// serial_hook_apply_hooks(result);
// Unity will crash during option loading when we hook this twice
// iohook_apply_hooks(result);
}
}

View File

@ -20,7 +20,8 @@ pushd %~dp0
qprocess amdaemon.exe > NUL
IF %ERRORLEVEL% NEQ 0 start /min "AM Daemon" inject -d -k apm3hook.dll amdaemon.exe -c daemon_config\common.json daemon_config\server.json config_hook.json
inject -d -k apm3hook.dll APMV3System -screen-fullscreen 0 -screen-width 1920 -screen-height 1080 -popupWindow -logFile output_log.txt
REM Add "-screen-fullscreen 0 -popupWindow" if you want to run in windowed mode
inject -d -k apm3hook.dll APMV3System -logFile output_log.txt
if exist %tmp%\segaboot (
del %tmp%\segaboot

View File

@ -118,14 +118,14 @@ targetAssembly=
[mount]
; Enables W: drive mapping instead of using .vhd files
enable=1
; Delays the mount operation by a slight bit, so the launch sound effect isn't cut off.
; Delays the mount operation by a slight bit, so the launch sound effect
; is not cut off.
delay=1
[epay]
; Enables the Thinca emulation. This will allow you to enable E-Money on compatible servers.
[video]
; Enables VFS (C:\Mount\Option) path rewrite for AVProVideo.
enable=1
; -----------------------------------------------------------------------------
; Custom IO settings
; -----------------------------------------------------------------------------

View File

@ -194,19 +194,20 @@ stickDeadzone=7849
[keyboard]
; Keyboard bindings:
; Stick controls (default: WASD)
; Keyboard movement
; Default is WASD keys for Joystick movemnt
up=0x57
left=0x41
down=0x53
left=0x41
right=0x44
; Attack (default: Space)
attack=0x20
; Dash (default: LSHIFT)
dash=0xa0
; Change Target (default: J)
target=0x4A
; Re-center camera (default: K)
camera=0x4B
; Noble Phantasm (default: L)
np=0x4C
; Dash button. Default is the Left Shift,
dash=0xA0
; Cycle Target button. Default is the F key.
target=0x46
; Attack button, Default is the Right Mouse Button.
attack=0x02
; Noble Phantasm button. Default is the Spacebar
np=0x20
; Center Camera, Default is the C key
camera=0x43

View File

@ -661,6 +661,6 @@ Enables the Thinca emulation. This will allow you to enable E-Money on compatibl
### `hook`
Default: `0`
Default: `1`
Enables hooking of respective Thinca DLL functions to emulate the existence of E-Money. This cannot be used with a real E-Money server.

View File

@ -93,6 +93,10 @@ void mount_config_load(struct mount_config *cfg, const wchar_t *filename) {
cfg->delay = GetPrivateProfileIntW(L"mount", L"delay", 1, filename);
}
void video_config_load(struct video_config *cfg, const wchar_t *filename) {
cfg->enable = GetPrivateProfileIntW(L"video", L"enable", 1, filename);
}
void apm3_hook_config_load(
struct apm3_hook_config *cfg,
const wchar_t *filename)
@ -110,4 +114,5 @@ void apm3_hook_config_load(
apm3_dll_config_load(&cfg->dll, filename);
unity_config_load(&cfg->unity, filename);
mount_config_load(&cfg->mount, filename);
video_config_load(&cfg->video, filename);
}

View File

@ -11,16 +11,13 @@
#include "gfxhook/config.h"
#include "apm3hook/apm3-dll.h"
#include "apm3-dll.h"
#include "mount.h"
#include "video.h"
#include "platform/config.h"
#include "unityhook/config.h"
struct mount_config {
bool enable;
bool delay;
};
struct apm3_hook_config {
struct platform_config platform;
struct aime_config aime;
@ -32,6 +29,7 @@ struct apm3_hook_config {
struct apm3_dll_config dll;
struct unity_config unity;
struct mount_config mount;
struct video_config video;
};
void apm3_dll_config_load(

View File

@ -16,6 +16,7 @@
#include "config.h"
#include "io4.h"
#include "mount.h"
#include "video.h"
#include "hook/iohook.h"
#include "hook/process.h"
@ -52,9 +53,7 @@ void unity_hook_callback(HMODULE hmodule, const wchar_t* p) {
iohook_apply_hooks(hmodule);
}
}
security_hook_insert_hooks(hmodule);
touch_hook_insert_hooks(hmodule);
// mount_hook_apply_hooks(&apm3_hook_cfg.mount, hmodule);
}
static DWORD CALLBACK apm3_pre_startup(void)
@ -73,8 +72,21 @@ static DWORD CALLBACK apm3_pre_startup(void)
touch_screen_hook_init(&apm3_hook_cfg.touch, apm3_hook_mod);
serial_hook_init();
/* Hook external DLL APIs */
mount_hook_init(&apm3_hook_cfg.platform.vfs, &apm3_hook_cfg.mount);
av_pro_video_hook_init(&apm3_hook_cfg.video);
/* Initialize emulation hooks */
struct dipsw_config new_dipsw_config[8] = {
{L"LAN Install", L"Server", L"Client"},
};
// Set the system dip switch configuration
memcpy(apm3_hook_cfg.platform.system.dipsw_config, new_dipsw_config,
sizeof(new_dipsw_config));
hr = platform_hook_init(
&apm3_hook_cfg.platform,
"SDEM",
@ -117,20 +129,6 @@ static DWORD CALLBACK apm3_pre_startup(void)
goto fail;
}
hr = security_hook_init();
if (FAILED(hr)) {
goto fail;
}
touch_screen_hook_init(&apm3_hook_cfg.touch, apm3_hook_mod);
mount_hook_init(&apm3_hook_cfg.platform.vfs, &apm3_hook_cfg.mount);
security_hook_insert_hooks(NULL);
mount_hook_apply_hooks(NULL);
unity_hook_init(&apm3_hook_cfg.unity, apm3_hook_mod, unity_hook_callback);
/* Initialize debug helpers */

View File

@ -28,5 +28,7 @@ shared_library(
'io4.h',
'mount.c',
'mount.h',
'video.c',
'video.h',
],
)

View File

@ -62,15 +62,17 @@ void mount_hook_init(struct vfs_config* vfs_cfg, struct mount_config* mount_cfg)
return;
}
dprintf("Mount: Hook enabled\n");
mount_hook_apply_hooks(NULL);
dprintf("Mount: hook enabled\n");
}
void mount_hook_apply_hooks(HMODULE module) {
if (!mcfg->enable) {
return;
}
proc_addr_table_push(module, "apmmount.dll", mount_hooks, _countof(mount_hooks));
void mount_hook_apply_hooks(HMODULE target) {
proc_addr_table_push(
target,
"apmmount.dll",
mount_hooks,
_countof(mount_hooks));
}

View File

@ -1,7 +1,12 @@
#pragma once
#include "board/aime-dll.h"
#include "config.h"
#include "platform/vfs.h"
void mount_hook_apply_hooks(HMODULE module);
struct mount_config {
bool enable;
bool delay;
};
void mount_hook_apply_hooks(HMODULE target);
void mount_hook_init(struct vfs_config* vfs_cfg, struct mount_config* mount_cfg);

115
games/apm3hook/video.c Normal file
View File

@ -0,0 +1,115 @@
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include "video.h"
#include "hook/procaddr.h"
#include "hooklib/dll.h"
#include "hooklib/path.h"
#include "util/dprintf.h"
static void* WINAPI hook_OpenSource(
void* instance,
const wchar_t* path,
int videoApiIndex,
bool useHardwareDecoding,
bool generateTextureMips,
bool hintAlphaChannel,
bool useLowLatency,
const wchar_t* forceAudioOutputDeviceName,
bool useUnityAudio,
bool forceResample,
int sampleRate,
const wchar_t** preferredFilter,
uint32_t numFilters,
int audioChannelMode,
uint32_t sourceSampleRate,
uint32_t sourceChannels
);
static void* (WINAPI *next_OpenSource)(
void* instance,
const wchar_t* path,
int videoApiIndex,
bool useHardwareDecoding,
bool generateTextureMips,
bool hintAlphaChannel,
bool useLowLatency,
const wchar_t* forceAudioOutputDeviceName,
bool useUnityAudio,
bool forceResample,
int sampleRate,
const wchar_t** preferredFilter,
uint32_t numFilters,
int audioChannelMode,
uint32_t sourceSampleRate,
uint32_t sourceChannels
);
static const struct hook_symbol av_pro_video_syms[] = {
{
.name = "OpenSource",
.patch = hook_OpenSource,
.link = (void **) &next_OpenSource,
}
};
void av_pro_video_hook_init(struct video_config* video_cfg)
{
assert(video_cfg != NULL);
if (!video_cfg->enable) {
return;
}
av_pro_video_hook_insert_hooks(NULL);
dprintf("Video: hook enabled.\n");
}
void av_pro_video_hook_insert_hooks(HMODULE target)
{
proc_addr_table_push(
target,
"AVProVideo.dll",
av_pro_video_syms,
_countof(av_pro_video_syms));
}
static void* WINAPI hook_OpenSource(
void* instance,
const wchar_t* path,
int videoApiIndex,
bool useHardwareDecoding,
bool generateTextureMips,
bool hintAlphaChannel,
bool useLowLatency,
const wchar_t* forceAudioOutputDeviceName,
bool useUnityAudio,
bool forceResample,
int sampleRate,
const wchar_t** preferredFilter,
uint32_t numFilters,
int audioChannelMode,
uint32_t sourceSampleRate,
uint32_t sourceChannels
) {
wchar_t *trans;
BOOL ok;
ok = path_transform_w(&trans, path);
if (!ok) {
dprintf("AVProVideo: Path transformation error\n");
return NULL;
}
return next_OpenSource(
instance, trans ? trans : path, videoApiIndex, useHardwareDecoding, generateTextureMips,
hintAlphaChannel, useLowLatency, forceAudioOutputDeviceName, useUnityAudio,
forceResample, sampleRate, preferredFilter, numFilters, audioChannelMode,
sourceSampleRate, sourceChannels);
}

10
games/apm3hook/video.h Normal file
View File

@ -0,0 +1,10 @@
#pragma once
#include <windows.h>
struct video_config {
bool enable;
};
void av_pro_video_hook_init(struct video_config* video_cfg);
void av_pro_video_hook_insert_hooks(HMODULE target);

View File

@ -1,9 +1,4 @@
#include <windows.h>
#include <dinput.h>
#include <stddef.h>
#include <stdint.h>
#include <wchar.h>
#include <assert.h>
#include "apm3io/backend.h"
@ -25,9 +20,6 @@ static HRESULT apm3_di_config_apply(const struct apm3_di_config *cfg);
static BOOL CALLBACK apm3_di_enum_callback(
const DIDEVICEINSTANCEW *dev,
void *ctx);
static BOOL CALLBACK apm3_di_enum_callback_shifter(
const DIDEVICEINSTANCEW *dev,
void *ctx);
static void apm3_di_get_gamebtns(uint16_t *gamebtn_out);
static uint8_t apm3_di_decode_pov(DWORD pov);
@ -42,7 +34,7 @@ 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_button[8];
static uint8_t apm3_di_button[APM3_BUTTON_COUNT];
HRESULT apm3_di_init(
const struct apm3_di_config *cfg,
@ -50,10 +42,6 @@ HRESULT apm3_di_init(
const struct apm3_io_backend **backend)
{
HRESULT hr;
HMODULE dinput8;
HRESULT (WINAPI *api_entry)(HINSTANCE,DWORD,REFIID,LPVOID *,LPUNKNOWN);
wchar_t dll_path[MAX_PATH];
UINT path_pos;
assert(cfg != NULL);
assert(backend != NULL);
@ -72,6 +60,18 @@ HRESULT apm3_di_init(
return hr;
}
hr = DirectInput8Create(
inst,
DIRECTINPUT_VERSION,
&IID_IDirectInput8W,
(void**)&apm3_di_api,
NULL);
if (FAILED(hr)) {
dprintf("DirectInput: DirectInput8Create failed: %08x\n", (int)hr);
return hr;
}
hr = IDirectInput8_EnumDevices(
apm3_di_api,
DI8DEVCLASS_GAMECTRL,
@ -138,7 +138,7 @@ static HRESULT apm3_di_config_apply(const struct apm3_di_config *cfg)
dprintf("Stick: Start button . . . : %i\n", cfg->start);
/* Print the configuration for all 8 buttons */
for (i = 0; i < 8; i++) {
for (i = 0; i < APM3_BUTTON_COUNT; i++) {
dprintf("Stick: Button %i . . . . . : %i\n", i, cfg->button[i]);
}
@ -147,7 +147,7 @@ static HRESULT apm3_di_config_apply(const struct apm3_di_config *cfg)
apm3_di_start = cfg->start;
apm3_di_home = cfg->home;
for (i = 0; i < 8; i++) {
for (i = 0; i < APM3_BUTTON_COUNT; i++) {
apm3_di_button[i] = cfg->button[i];
}

View File

@ -88,18 +88,9 @@ void idac_hook_config_load(
platform_config_load(&cfg->platform, filename);
aime_config_load(&cfg->aime, filename);
idac_dll_config_load(&cfg->dll, filename);
zinput_config_load(&cfg->zinput, filename);
dvd_config_load(&cfg->dvd, filename);
io4_config_load(&cfg->io4, filename);
ffb_config_load(&cfg->ffb, filename);
led15070_config_load(&cfg->led15070, filename);
indrun_config_load(&cfg->indrun, filename);
}
void zinput_config_load(struct zinput_config *cfg, const wchar_t *filename)
{
assert(cfg != NULL);
assert(filename != NULL);
cfg->enable = GetPrivateProfileIntW(L"zinput", L"enable", 1, filename);
}

View File

@ -9,7 +9,6 @@
#include "hooklib/dvd.h"
#include "idachook/idac-dll.h"
#include "idachook/zinput.h"
#include "idachook/indrun.h"
#include "platform/platform.h"
@ -21,7 +20,6 @@ struct idac_hook_config {
struct io4_config io4;
struct ffb_config ffb;
struct idac_dll_config dll;
struct zinput_config zinput;
struct led15070_config led15070;
struct indrun_config indrun;
};
@ -34,10 +32,6 @@ void idac_hook_config_load(
struct idac_hook_config *cfg,
const wchar_t *filename);
void zinput_config_load(
struct zinput_config *cfg,
const wchar_t *filename);
void indrun_config_load(
struct indrun_config *cfg,
const wchar_t *filename);

View File

@ -31,7 +31,6 @@
#include "idachook/idac-dll.h"
#include "idachook/io4.h"
#include "idachook/ffb.h"
#include "idachook/zinput.h"
#include "platform/platform.h"
@ -55,7 +54,6 @@ static DWORD CALLBACK idac_pre_startup(void)
/* Hook Win32 APIs */
serial_hook_init();
zinput_hook_init(&idac_hook_cfg.zinput);
dvd_hook_init(&idac_hook_cfg.dvd, idac_hook_mod);
/* Initialize emulation hooks */

View File

@ -25,8 +25,6 @@ shared_library(
'idac-dll.h',
'io4.c',
'io4.h',
'zinput.c',
'zinput.h',
'indrun.c',
'indrun.h',
'ffb.c',

View File

@ -1,187 +0,0 @@
#include <windows.h>
#include <dinput.h>
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "idachook/config.h"
#include "idachook/zinput.h"
#include "hook/table.h"
#include "util/dprintf.h"
HRESULT WINAPI hook_DirectInput8Create(
HINSTANCE hinst,
DWORD dwVersion,
REFIID riidltf,
LPVOID *ppvOut,
LPUNKNOWN punkOuter);
static unsigned long WINAPI hook_AddRef(IUnknown *self);
static unsigned long WINAPI hook_Release(IUnknown *self);
static HRESULT WINAPI hook_CreateDevice(
IDirectInput8W *self,
REFGUID rguid,
LPDIRECTINPUTDEVICE8W * lplpDirectInputDevice,
LPUNKNOWN pUnkOuter);
static HRESULT WINAPI hook_EnumDevices(
IDirectInput8W *self,
DWORD dwDevType,
LPDIENUMDEVICESCALLBACKW lpCallback,
LPVOID pvRef,
DWORD dwFlags);
static HRESULT WINAPI hook_SetDataFormat(
IDirectInputDevice8W *self,
LPCDIDATAFORMAT lpdf);
static HRESULT WINAPI hook_SetCooperativeLevel(
IDirectInputDevice8W *self,
HWND hwnd,
DWORD flags);
static HRESULT WINAPI hook_Acquire(IDirectInputDevice8W *self);
static HRESULT WINAPI hook_Unacquire(IDirectInputDevice8W *self);
static HRESULT WINAPI hook_GetDeviceState(
IDirectInputDevice8W *self,
DWORD cbData,
LPVOID lpvData);
static const IDirectInput8WVtbl api_vtbl = {
.AddRef = (void *) hook_AddRef,
.Release = (void *) hook_Release,
.CreateDevice = hook_CreateDevice,
.EnumDevices = hook_EnumDevices,
};
static const IDirectInput8W api = { (void *) &api_vtbl };
static const IDirectInputDevice8WVtbl dev_vtbl = {
.AddRef = (void *) hook_AddRef,
.Release = (void *) hook_Release,
.SetDataFormat = hook_SetDataFormat,
.SetCooperativeLevel= hook_SetCooperativeLevel,
.Acquire = hook_Acquire,
.Unacquire = hook_Unacquire,
.GetDeviceState = hook_GetDeviceState,
};
static const IDirectInputDevice8W dev = { (void *) &dev_vtbl };
static const struct hook_symbol zinput_hook_syms[] = {
{
.name = "DirectInput8Create",
.patch = hook_DirectInput8Create,
}
};
HRESULT zinput_hook_init(struct zinput_config *cfg)
{
assert(cfg != NULL);
if (!cfg->enable) {
return S_FALSE;
}
hook_table_apply(
NULL,
"dinput8.dll",
zinput_hook_syms,
_countof(zinput_hook_syms));
return S_OK;
}
HRESULT WINAPI hook_DirectInput8Create(
HINSTANCE hinst,
DWORD dwVersion,
REFIID riidltf,
LPVOID *ppvOut,
LPUNKNOWN punkOuter)
{
dprintf("ZInput: Blocking built-in DirectInput support\n");
*ppvOut = (void *) &api;
return S_OK;
}
static unsigned long WINAPI hook_AddRef(IUnknown *self)
{
return 1;
}
static unsigned long WINAPI hook_Release(IUnknown *self)
{
return 1;
}
static HRESULT WINAPI hook_CreateDevice(
IDirectInput8W *self,
REFGUID rguid,
LPDIRECTINPUTDEVICE8W *lplpDirectInputDevice,
LPUNKNOWN pUnkOuter)
{
dprintf("ZInput: %s\n", __func__);
*lplpDirectInputDevice = (void *) &dev;
return S_OK;
}
static HRESULT WINAPI hook_EnumDevices(
IDirectInput8W *self,
DWORD dwDevType,
LPDIENUMDEVICESCALLBACKW lpCallback,
LPVOID pvRef,
DWORD dwFlags)
{
dprintf("ZInput: %s\n", __func__);
return S_OK;
}
static HRESULT WINAPI hook_SetDataFormat(
IDirectInputDevice8W *self,
LPCDIDATAFORMAT lpdf)
{
dprintf("ZInput: %s\n", __func__);
return S_OK;
}
static HRESULT WINAPI hook_SetCooperativeLevel(
IDirectInputDevice8W *self,
HWND hwnd,
DWORD flags)
{
dprintf("ZInput: %s\n", __func__);
return S_OK;
}
static HRESULT WINAPI hook_Acquire(IDirectInputDevice8W *self)
{
return S_OK;
}
static HRESULT WINAPI hook_Unacquire(IDirectInputDevice8W *self)
{
return S_OK;
}
static HRESULT WINAPI hook_GetDeviceState(
IDirectInputDevice8W *self,
DWORD cbData,
LPVOID lpvData)
{
memset(lpvData, 0, cbData);
return S_OK;
}

View File

@ -1,11 +0,0 @@
#pragma once
#include <windows.h>
#include <stdbool.h>
struct zinput_config {
bool enable;
};
HRESULT zinput_hook_init(struct zinput_config *cfg);

View File

@ -1,11 +1,5 @@
#include <windows.h>
#include <dinput.h>
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <wchar.h>
#include "idacio/backend.h"
#include "idacio/config.h"
@ -88,10 +82,6 @@ HRESULT idac_di_init(
const struct idac_io_backend **backend)
{
HRESULT hr;
HMODULE dinput8;
HRESULT (WINAPI *api_entry)(HINSTANCE,DWORD,REFIID,LPVOID *,LPUNKNOWN);
wchar_t dll_path[MAX_PATH];
UINT path_pos;
assert(cfg != NULL);
assert(backend != NULL);
@ -110,47 +100,15 @@ HRESULT idac_di_init(
return hr;
}
/* Initial D THE ARCADE has some built-in DirectInput support that is not
particularly useful. idachook shorts this out by redirecting dinput8.dll
to a no-op implementation of DirectInput. However, idacio does need to
talk to the real operating system implementation of DirectInput without
the stub DLL interfering, so build a path to
C:\Windows\System32\dinput.dll here. */
dll_path[0] = L'\0';
path_pos = GetSystemDirectoryW(dll_path, _countof(dll_path));
wcscat_s(
dll_path + path_pos,
_countof(dll_path) - path_pos,
L"\\dinput8.dll");
dinput8 = LoadLibraryW(dll_path);
if (dinput8 == NULL) {
hr = HRESULT_FROM_WIN32(GetLastError());
dprintf("DirectInput: LoadLibrary failed: %08x\n", (int) hr);
return hr;
}
api_entry = (void *) GetProcAddress(dinput8, "DirectInput8Create");
if (api_entry == NULL) {
dprintf("DirectInput: GetProcAddress failed\n");
return E_FAIL;
}
hr = api_entry(
hr = DirectInput8Create(
inst,
DIRECTINPUT_VERSION,
&IID_IDirectInput8W,
(void **) &idac_di_api,
(void**)&idac_di_api,
NULL);
if (FAILED(hr)) {
dprintf("DirectInput: API create failed: %08x\n", (int) hr);
dprintf("DirectInput: DirectInput8Create failed: %08x\n", (int)hr);
return hr;
}

View File

@ -1,11 +1,5 @@
#include <windows.h>
#include <dinput.h>
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <wchar.h>
#include "swdcio/backend.h"
#include "swdcio/config.h"
@ -81,10 +75,6 @@ HRESULT swdc_di_init(
const struct swdc_io_backend **backend)
{
HRESULT hr;
HMODULE dinput8;
HRESULT (WINAPI *api_entry)(HINSTANCE,DWORD,REFIID,LPVOID *,LPUNKNOWN);
wchar_t dll_path[MAX_PATH];
UINT path_pos;
assert(cfg != NULL);
assert(backend != NULL);
@ -103,46 +93,15 @@ HRESULT swdc_di_init(
return hr;
}
/* SWDC has some built-in DirectInput support that is not
particularly useful. swdchook shorts this out by redirecting dinput8.dll
to a no-op implementation of DirectInput. However, swdcio does need to
talk to the real operating system implementation of DirectInput without
the stub DLL interfering, so build a path to
C:\Windows\System32\dinput.dll here. */
dll_path[0] = L'\0';
path_pos = GetSystemDirectoryW(dll_path, _countof(dll_path));
wcscat_s(
dll_path + path_pos,
_countof(dll_path) - path_pos,
L"\\dinput8.dll");
dinput8 = LoadLibraryW(dll_path);
if (dinput8 == NULL) {
hr = HRESULT_FROM_WIN32(GetLastError());
dprintf("DirectInput: LoadLibrary failed: %08x\n", (int) hr);
return hr;
}
api_entry = (void *) GetProcAddress(dinput8, "DirectInput8Create");
if (api_entry == NULL) {
dprintf("DirectInput: GetProcAddress failed\n");
return E_FAIL;
}
hr = api_entry(
hr = DirectInput8Create(
inst,
DIRECTINPUT_VERSION,
&IID_IDirectInput8W,
(void **) &swdc_di_api,
(void**)&swdc_di_api,
NULL);
if (FAILED(hr)) {
dprintf("DirectInput: API create failed: %08x\n", (int) hr);
dprintf("DirectInput: DirectInput8Create failed: %08x\n", (int) hr);
return hr;
}

View File

@ -179,7 +179,7 @@ static int16_t calculate_norm_steering(int16_t axis, uint16_t deadzone, bool lin
// optionally normalize the magnitude with respect to its expected range
// giving a magnitude value of 0.0 to 1.0
norm_magnitude = (int16_t)(magnitude / (max_stick_value - deadzone));
norm_magnitude = (magnitude / (max_stick_value - deadzone));
} else // if the controller is in the deadzone zero out the magnitude
{
magnitude = 0.0;