Repository navigation
Expand file tree
/
Copy pathXInput9_1_0Proxy.cpp
More file actions
116 lines (96 loc) · 3.18 KB
/
Copy pathXInput9_1_0Proxy.cpp
File metadata and controls
116 lines (96 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// FF8R-Analog360 - Restores 360° analog movement in FINAL FANTASY VIII Remastered
// Copyright (C) 2026 Quentin MOREL
// SPDX-License-Identifier: GPL-3.0-or-later
#include "logger.h"
#include "squall360.h"
#include <windows.h>
#include <xinput.h>
// The Windows SDK declares the XInput functions noexcept (WIN_NOEXCEPT), MinGW headers don't.
// Our definitions must match the header declarations exactly.
#ifndef WIN_NOEXCEPT
#define WIN_NOEXCEPT
#endif
static HMODULE g_realDll = nullptr;
constexpr auto CONSOLE_NAME = "FF8R-Analog360 - debug";
constexpr auto CONSOLE_PREFIX_MESSAGE = "[squall360]";
constexpr auto REAL_DLL_NAME = "\\XInput9_1_0.dll";
static FARPROC getRealFunction(const char* name)
{
if (g_realDll == nullptr)
{
char path[MAX_PATH];
GetSystemDirectoryA(path, MAX_PATH);
lstrcatA(path, REAL_DLL_NAME);
g_realDll = LoadLibraryA(path);
}
return (g_realDll != nullptr) ? GetProcAddress(g_realDll, name) : nullptr;
}
extern "C"
{
DWORD WINAPI XInputGetState(DWORD userIndex, XINPUT_STATE* state) WIN_NOEXCEPT
{
using Fn = DWORD(WINAPI*)(DWORD, XINPUT_STATE*);
const auto fn = reinterpret_cast<Fn>(getRealFunction("XInputGetState"));
return fn ? fn(userIndex, state) : ERROR_DEVICE_NOT_CONNECTED;
}
DWORD WINAPI XInputSetState(DWORD userIndex, XINPUT_VIBRATION* vibration) WIN_NOEXCEPT
{
using Fn = DWORD(WINAPI*)(DWORD, XINPUT_VIBRATION*);
const auto fn = reinterpret_cast<Fn>(getRealFunction("XInputSetState"));
return fn ? fn(userIndex, vibration) : ERROR_DEVICE_NOT_CONNECTED;
}
DWORD WINAPI XInputGetCapabilities(DWORD userIndex, DWORD flags, XINPUT_CAPABILITIES* capabilities) WIN_NOEXCEPT
{
using Fn = DWORD(WINAPI*)(DWORD, DWORD, XINPUT_CAPABILITIES*);
const auto fn = reinterpret_cast<Fn>(getRealFunction("XInputGetCapabilities"));
return fn ? fn(userIndex, flags, capabilities) : ERROR_DEVICE_NOT_CONNECTED;
}
DWORD WINAPI XInputGetDSoundAudioDeviceGuids(DWORD userIndex, GUID* renderGuid, GUID* captureGuid)
{
using Fn = DWORD(WINAPI*)(DWORD, GUID*, GUID*);
const auto fn = reinterpret_cast<Fn>(getRealFunction("XInputGetDSoundAudioDeviceGuids"));
return fn ? fn(userIndex, renderGuid, captureGuid) : ERROR_DEVICE_NOT_CONNECTED;
}
}
static DWORD WINAPI threadInitialisationMod(LPVOID /*param*/)
{
logInit(CONSOLE_NAME, CONSOLE_PREFIX_MESSAGE);
logPrint("FFVIII-Analog360 - Started");
if (tryInstallSquall360Patch())
{
logPrint("Success patching");
}
else
{
logPrint("Failure patching");
}
return 0;
}
BOOL WINAPI DllMain(HINSTANCE /*inst*/, DWORD reason, LPVOID /*reserved*/)
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
{
if (!isSupportedGameModuleLoaded())
{
break; // launcher or another process: do nothing
}
if (HANDLE thread = CreateThread(nullptr, 0, threadInitialisationMod, nullptr, 0, nullptr))
{
CloseHandle(thread);
}
break;
}
case DLL_PROCESS_DETACH:
{
logStop();
break;
}
default:
{
break;
}
}
return TRUE;
}