-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXimEngine.cpp
More file actions
214 lines (184 loc) · 8.96 KB
/
Copy pathXimEngine.cpp
File metadata and controls
214 lines (184 loc) · 8.96 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include "XimEngine.h"
#include <iostream>
#include <fstream>
#include <cmath>
#include <thread>
#include <algorithm>
constexpr double TARGET_TICK_MS = 1.0;
constexpr double PI = 3.14159265358979323846;
// Central memory address point definitions
XimPcEngine g_Engine;
double g_AccumulatedRawX = 0.0;
double g_AccumulatedRawY = 0.0;
int g_SaveIndicatorTicks = 0;
int g_CurrentScrollPage = 0;
XimPcEngine::XimPcEngine() {
smoothX = 0.0; smoothY = 0.0; smoothingFactor = 0.35;
isEngineEnabled = false; isFiring = false; isAiming = false;
activeScopeMultiplier = 1.0; currentScopeName = "1x / Iron Sight";
attachmentVerticalMultiplier = 1.0; attachmentHorizontalMultiplier = 1.0;
currentAttachmentName = "None (Bare Weapon)";
autoLeanEnabled = true; autoBreathEnabled = true; crouchJumpEnabled = true;
leanLeftHeld = false; leanRightHeld = false; breathHeld = false;
LoadWeaponProfile("smgsmgs");
}
void XimPcEngine::SendKey(WORD vkCode, DWORD flags) {
INPUT input = { 0 }; input.type = INPUT_KEYBOARD; input.ki.wVk = vkCode; input.ki.dwFlags = flags;
SendInput(1, &input, sizeof(INPUT));
}
void XimPcEngine::ToggleEngine() {
isEngineEnabled = !isEngineEnabled;
isFiring = false; isAiming = false;
ResetTacticalStates();
}
void XimPcEngine::ToggleAutoLean() { autoLeanEnabled = !autoLeanEnabled; ResetTacticalStates(); }
void XimPcEngine::ToggleAutoBreath() { autoBreathEnabled = !autoBreathEnabled; ResetTacticalStates(); }
void XimPcEngine::ToggleCrouchJump() { crouchJumpEnabled = !crouchJumpEnabled; }
bool XimPcEngine::IsEnabled() const { return isEngineEnabled; }
bool XimPcEngine::IsAutoLeanEnabled() const { return autoLeanEnabled; }
bool XimPcEngine::IsAutoBreathEnabled() const { return autoBreathEnabled; }
bool XimPcEngine::IsCrouchJumpEnabled() const { return crouchJumpEnabled; }
void XimPcEngine::SetFiringState(bool firing) {
if (!isEngineEnabled) { isFiring = false; return; }
if (firing && !isFiring) fireStartTime = std::chrono::steady_clock::now();
isFiring = firing;
}
void XimPcEngine::SetAimingState(bool aiming) {
if (!isEngineEnabled) { isAiming = false; ResetTacticalStates(); return; }
if (!aiming && isAiming) ResetTacticalStates();
isAiming = aiming;
}
void XimPcEngine::ResetTacticalStates() {
if (leanLeftHeld) { SendKey('Q', KEYEVENTF_KEYUP); leanLeftHeld = false; }
if (leanRightHeld) { SendKey('E', KEYEVENTF_KEYUP); leanRightHeld = false; }
if (breathHeld) { SendKey(VK_SHIFT, KEYEVENTF_KEYUP); breathHeld = false; }
}
void XimPcEngine::SaveProfileToFile() {
std::ofstream outFile(activeWeapon.name + "_config.txt");
if (outFile.is_open()) {
outFile << activeWeapon.stabilizationFrequency << " " << activeWeapon.stabilizationAmplitude;
for (const auto& node : activeWeapon.pattern) {
outFile << " " << node.pullDownPerMs;
}
outFile << "\n"; outFile.close();
}
}
void XimPcEngine::LoadProfileFromFile() {
std::ifstream inFile(activeWeapon.name + "_config.txt");
if (inFile.is_open()) {
double savedFreq, savedAmp;
if (inFile >> savedFreq >> savedAmp) {
activeWeapon.stabilizationFrequency = savedFreq;
activeWeapon.stabilizationAmplitude = savedAmp;
for (auto& node : activeWeapon.pattern) {
double val; if (inFile >> val) node.pullDownPerMs = val;
}
}
inFile.close();
}
}
bool XimPcEngine::LoadWeaponProfile(const std::string& profileName) {
if (profileName == "smgsmgs") {
activeWeapon.name = "smgsmgs";
activeWeapon.pattern = { {0, 150, 0.22, 0.01}, {150, 20000, 0.18, 0.00} };
activeWeapon.stabilizationFrequency = 9.8; activeWeapon.stabilizationAmplitude = 0.09;
LoadProfileFromFile(); return true;
}
else if (profileName == "dmrdmr") {
activeWeapon.name = "dmrdmr";
activeWeapon.pattern = { {0, 150, 0.65, 0.00}, {150, 20000, 0.42, 0.00} };
activeWeapon.stabilizationFrequency = 4.5; activeWeapon.stabilizationAmplitude = 0.05;
LoadProfileFromFile(); return true;
}
else if (profileName == "berrylite") {
activeWeapon.name = "berrylite";
activeWeapon.pattern = { {0, 150, 0.45, 0.02}, {150, 20000, 0.32, 0.00} };
activeWeapon.stabilizationFrequency = 8.5; activeWeapon.stabilizationAmplitude = 0.18;
LoadProfileFromFile(); return true;
}
else if (profileName == "august") {
activeWeapon.name = "august";
activeWeapon.pattern = { {0, 150, 0.28, -0.03}, {150, 20000, 0.22, 0.00} };
activeWeapon.stabilizationFrequency = 6.2; activeWeapon.stabilizationAmplitude = 0.11;
LoadProfileFromFile(); return true;
}
return false;
}
void XimPcEngine::AdjustRecoilPower(double verticalDelta, double horizontalDelta) {
if (activeWeapon.pattern.size() > 1) {
activeWeapon.pattern[1].pullDownPerMs = (std::max)(0.0, activeWeapon.pattern[1].pullDownPerMs + verticalDelta);
}
activeWeapon.stabilizationAmplitude = (std::max)(0.0, activeWeapon.stabilizationAmplitude + horizontalDelta);
SaveProfileToFile();
}
void XimPcEngine::SetScopeProfile(const std::string& scopeType) {
if (scopeType == "1x") activeScopeMultiplier = 1.0;
else if (scopeType == "3x") activeScopeMultiplier = 2.1;
else if (scopeType == "4x") activeScopeMultiplier = 2.8;
}
void XimPcEngine::SetAttachmentProfile(const std::string& attachType) {
if (attachType == "none") { attachmentVerticalMultiplier = 1.0; attachmentHorizontalMultiplier = 1.0; }
else if (attachType == "vert") { attachmentVerticalMultiplier = 0.85; attachmentHorizontalMultiplier = 1.0; }
else if (attachType == "comp") { attachmentVerticalMultiplier = 0.90; attachmentHorizontalMultiplier = 0.85; }
}
void XimPcEngine::ExecuteCrouchJump() {
if (!isEngineEnabled || !crouchJumpEnabled) return;
INPUT inputs[2] = {};
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = VK_SPACE;
inputs[1].type = INPUT_KEYBOARD;
inputs[1].ki.wVk = 'C';
SendInput(2, inputs, sizeof(INPUT));
std::this_thread::sleep_for(std::chrono::milliseconds(50));
inputs[0].ki.dwFlags = KEYEVENTF_KEYUP;
inputs[1].ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(2, inputs, sizeof(INPUT));
}
void XimPcEngine::UpdateStabilization(double freq, double amp) {
activeWeapon.stabilizationFrequency = freq; activeWeapon.stabilizationAmplitude = amp; SaveProfileToFile();
}
std::string XimPcEngine::GetActiveName() const { return activeWeapon.name; }
double XimPcEngine::GetCurrentFreq() const { return activeWeapon.stabilizationFrequency; }
double XimPcEngine::GetCurrentAmp() const { return activeWeapon.stabilizationAmplitude; }
double XimPcEngine::GetNodeVerticalValue(size_t index) const {
if (index < activeWeapon.pattern.size()) return activeWeapon.pattern[index].pullDownPerMs;
return 0.0;
}
void XimPcEngine::ProcessFrame(double rawX, double rawY, double& outX, double& outY) {
smoothX = (smoothingFactor * rawX) + ((1.0 - smoothingFactor) * smoothX);
smoothY = (smoothingFactor * rawY) + ((1.0 - smoothingFactor) * smoothY);
outX = smoothX; outY = smoothY;
if (isEngineEnabled && isFiring) {
auto currentTime = std::chrono::steady_clock::now();
auto elapsedMs = std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - fireStartTime).count();
for (const auto& node : activeWeapon.pattern) {
if (elapsedMs >= node.startMs && elapsedMs < node.endMs) {
outX += (node.pullRightPerMs * activeScopeMultiplier * attachmentHorizontalMultiplier) * TARGET_TICK_MS;
outY += (node.pullDownPerMs * activeScopeMultiplier * attachmentVerticalMultiplier) * TARGET_TICK_MS;
break;
}
}
double timeInSeconds = elapsedMs / 1000.0;
outX += (activeWeapon.stabilizationAmplitude * activeScopeMultiplier * attachmentHorizontalMultiplier) *
std::sin(2.0 * PI * activeWeapon.stabilizationFrequency * timeInSeconds);
}
if (!isEngineEnabled) return;
if (autoBreathEnabled && isAiming && !breathHeld) { SendKey(VK_SHIFT, 0); breathHeld = true; }
if (autoLeanEnabled && isAiming) {
bool aKeyPressed = (GetAsyncKeyState('A') & 0x8000) != 0;
bool dKeyPressed = (GetAsyncKeyState('D') & 0x8000) != 0;
if (aKeyPressed && !dKeyPressed) {
if (leanRightHeld) { SendKey('E', KEYEVENTF_KEYUP); leanRightHeld = false; }
if (!leanLeftHeld) { SendKey('Q', 0); leanLeftHeld = true; }
}
// FIXED: Cleared erroneous key up constraints targeting the 'E' virtual register channel
else if (dKeyPressed && !aKeyPressed) {
if (leanLeftHeld) { SendKey('Q', KEYEVENTF_KEYUP); leanLeftHeld = false; }
if (!leanRightHeld) { SendKey('E', 0); leanRightHeld = true; }
}
else {
if (leanLeftHeld) { SendKey('Q', KEYEVENTF_KEYUP); leanLeftHeld = false; }
if (leanRightHeld) { SendKey('E', KEYEVENTF_KEYUP); leanRightHeld = false; }
}
}
}