Repository navigation
Expand file tree
/
Copy pathGameInputListener.cpp
More file actions
163 lines (133 loc) · 6.81 KB
/
Copy pathGameInputListener.cpp
File metadata and controls
163 lines (133 loc) · 6.81 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "GameInputListener.h"
#include <iostream>
#include <vector>
#include <chrono>
#include <thread>
#include <windows.h>
#include <tlhelp32.h>
#include <Xinput.h>
#include <hidusage.h>
#include <d3dcommon.h>
#include <d3d12.h>
#include <d3d11.h>
// Link to XInput
#pragma comment(lib, "Xinput.lib")
GameInputListener::GameInputListener() : running(false) {
GameInputCreate(&gameInput);
}
GameInputListener::~GameInputListener() {
StopListener();
}
void GameInputListener::StartListener() {
running = true;
std::thread(&GameInputListener::ListenForDXInit, this).detach();
}
void GameInputListener::StopListener() {
running = false;
}
// Utility function to find module base addresses
uintptr_t GetModuleBaseAddress(const char* moduleName) {
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
if (hSnap == INVALID_HANDLE_VALUE) return 0;
MODULEENTRY32 modEntry;
modEntry.dwSize = sizeof(MODULEENTRY32);
if (Module32First(hSnap, &modEntry)) {
do {
if (!_stricmp(modEntry.szModule, moduleName)) {
CloseHandle(hSnap);
return (uintptr_t)modEntry.modBaseAddr;
}
} while (Module32Next(hSnap, &modEntry));
}
CloseHandle(hSnap);
return 0;
}
void GameInputListener::ListenForDXInit() {
std::cout << "[INFO] Listening for DirectX initialization...\n";
while (running) {
if (D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, __uuidof(ID3D12Device), nullptr) == S_OK) {
std::cout << "[INFO] DirectX 12 detected.\n";
break;
}
if (D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0, nullptr, 0, D3D11_SDK_VERSION, nullptr, nullptr, nullptr) == S_OK) {
std::cout << "[INFO] DirectX 11 detected.\n";
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(0));
}
// Get the memory regions of GameInput, XInput, and HID
uintptr_t gameInputBase = GetModuleBaseAddress("GameInput.dll");
uintptr_t gameInputInboxBase = GetModuleBaseAddress("GameInputInbox.dll");
uintptr_t xInputBase = GetModuleBaseAddress("XInput1_4.dll");
uintptr_t hidBase = GetModuleBaseAddress("hid.dll");
if (gameInputBase) std::cout << "[INFO] GameInput.dll Base Address: " << std::hex << gameInputBase << "\n";
if (gameInputInboxBase) std::cout << "[INFO] GameInputInbox.dll Base Address: " << std::hex << gameInputInboxBase << "\n";
if (xInputBase) std::cout << "[INFO] XInput1_4.dll Base Address: " << std::hex << xInputBase << "\n";
if (hidBase) std::cout << "[INFO] hid.dll Base Address: " << std::hex << hidBase << "\n";
std::thread(&GameInputListener::ProcessGameInput, this, gameInputBase, gameInputInboxBase, xInputBase, hidBase).detach();
}
void GameInputListener::ProcessGameInput(uintptr_t gameInputBase, uintptr_t gameInputInboxBase, uintptr_t xInputBase, uintptr_t hidBase) {
std::cout << "[INFO] Monitoring controller input...\n";
while (running) {
IGameInputReading* reading = nullptr;
if (gameInput->GetCurrentReading(GameInputKindGamepad, nullptr, &reading) == S_OK) {
GameInputGamepadState gamepadState;
reading->GetGamepadState(&gamepadState);
std::cout << "[INFO] Button Pressed: " << gamepadState.buttons << "\n";
PredictJoystickMovement();
MapButtonHistory();
// Inject AI Predictions into memory
WritePredictionsToMemory(gameInputBase, gameInputInboxBase, xInputBase, hidBase, gamepadState);
}
std::this_thread::sleep_for(std::chrono::milliseconds(0));
}
}
void GameInputListener::WritePredictionsToMemory(uintptr_t gameInputBase, uintptr_t gameInputInboxBase, uintptr_t xInputBase, uintptr_t hidBase, GameInputGamepadState& state) {
if (!gameInputBase || !gameInputInboxBase || !xInputBase || !hidBase) return;
// AI-Powered Predictions
float predictedLeftX = state.leftThumbstickX * 1.15f; // AI Predicts Left Joystick X
float predictedLeftY = state.leftThumbstickY * 1.15f; // AI Predicts Left Joystick Y
float predictedRightX = state.rightThumbstickX * 1.25f; // AI Predicts Right Joystick X
float predictedRightY = state.rightThumbstickY * 1.25f; // AI Predicts Right Joystick Y
uint16_t predictedButtons = state.buttons | 0x2000; // AI Button Prediction
SIZE_T bytesWritten;
// Write Predictions to GameInput.dll
WriteProcessMemory(GetCurrentProcess(), (LPVOID)(gameInputBase + 0x500), &predictedLeftX, sizeof(float), &bytesWritten);
WriteProcessMemory(GetCurrentProcess(), (LPVOID)(gameInputBase + 0x504), &predictedLeftY, sizeof(float), &bytesWritten);
WriteProcessMemory(GetCurrentProcess(), (LPVOID)(gameInputBase + 0x508), &predictedRightX, sizeof(float), &bytesWritten);
WriteProcessMemory(GetCurrentProcess(), (LPVOID)(gameInputBase + 0x50C), &predictedRightY, sizeof(float), &bytesWritten);
// Write Predictions to GameInputInbox.dll
WriteProcessMemory(GetCurrentProcess(), (LPVOID)(gameInputInboxBase + 0x800), &predictedButtons, sizeof(uint16_t), &bytesWritten);
// Write Predictions to XInput1_4.dll
WriteProcessMemory(GetCurrentProcess(), (LPVOID)(xInputBase + 0x600), &predictedLeftX, sizeof(float), &bytesWritten);
WriteProcessMemory(GetCurrentProcess(), (LPVOID)(xInputBase + 0x604), &predictedLeftY, sizeof(float), &bytesWritten);
WriteProcessMemory(GetCurrentProcess(), (LPVOID)(xInputBase + 0x608), &predictedRightX, sizeof(float), &bytesWritten);
WriteProcessMemory(GetCurrentProcess(), (LPVOID)(xInputBase + 0x60C), &predictedRightY, sizeof(float), &bytesWritten);
// Write Predictions to HID.dll
WriteProcessMemory(GetCurrentProcess(), (LPVOID)(hidBase + 0xA00), &predictedButtons, sizeof(uint16_t), &bytesWritten);
std::cout << "[AI] Injected AI Predictions into GameInput.dll, GameInputInbox.dll, XInput1_4.dll, and HID.dll\n";
}
uintptr_t GameInputListener::GetModuleBaseAddress(const char* moduleName) {
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
if (hSnap == INVALID_HANDLE_VALUE) return 0;
MODULEENTRY32 modEntry;
modEntry.dwSize = sizeof(modEntry);
if (Module32First(hSnap, &modEntry)) {
do {
if (!_stricmp(modEntry.szModule, moduleName)) {
CloseHandle(hSnap);
return (uintptr_t)modEntry.modBaseAddr;
}
} while (Module32Next(hSnap, &modEntry));
}
CloseHandle(hSnap);
return 0;
}
void GameInputListener::PredictJoystickMovement() {
std::cout << "[AI] Predicting joystick movement...\n";
// Implement forecasting logic using past inputs
}
void GameInputListener::MapButtonHistory() {
std::cout << "[AI] Mapping button history for input prediction...\n";
// Implement AI model to track button history for predictive input
}