This repository was archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathConfigLoader.cpp
167 lines (147 loc) · 4.87 KB
/
ConfigLoader.cpp
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
#pragma once
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include <sys/stat.h>
#include "Utils.cpp"
class ConfigLoader
{
private:
const std::string m_fileName = "myapex.ini";
std::vector<std::string> *lines = new std::vector<std::string>;
long m_lastTimeFileEdited = 0;
// features
bool m_featureAimbotOn = false;
bool m_featureNoRecoilOn = false;
bool m_featureSenseOn = false;
// aimbot
int m_aimbotTrigger = 0x0000;
int m_aimbotSmoothing = 999999;
int m_aimbotActivationFOV = 0;
int m_aimbotMaxRange = 0;
// norecoil
double m_norecoilPitchStrength = 0;
double m_norecoilYawStrength = 0;
bool loadFileIntoVector()
{
struct stat result;
if (stat(m_fileName.c_str(), &result) == 0)
{
long modTime = result.st_mtime;
bool fileNeedsReload = modTime > m_lastTimeFileEdited;
m_lastTimeFileEdited = modTime;
if (!fileNeedsReload)
return false;
}
lines->clear();
std::string str;
std::ifstream myFile(m_fileName);
while (getline(myFile, str))
{
utils::trim(str);
if (str.empty())
continue;
if (str.rfind("#", 0) == 0)
continue;
lines->push_back(str);
}
myFile.close();
return true;
}
void parseLines()
{
for (int i = 0; i < lines->size(); i++)
{
std::vector<std::string> lineParts = utils::split(lines->at(i));
// line key
std::string lineKey(lineParts.at(0));
utils::trim(lineKey);
if (lineKey.empty())
throw "Cannot parse the config";
// line value
std::string lineValue(lineParts.at(1));
utils::trim(lineValue);
if (lineValue.empty())
throw "Cannot parse the config";
// features
m_featureAimbotOn = (lineKey.compare("FEATURE_AIMBOT_ON") != 0) ? m_featureAimbotOn : utils::toBool(lineValue);
m_featureNoRecoilOn = (lineKey.compare("FEATURE_NORECOIL_ON") != 0) ? m_featureNoRecoilOn : utils::toBool(lineValue);
m_featureSenseOn = (lineKey.compare("FEATURE_SENSE_ON") != 0) ? m_featureSenseOn : utils::toBool(lineValue);
// aimbot
m_aimbotTrigger = (lineKey.compare("AIMBOT_TRIGGER") != 0) ? m_aimbotTrigger : stoi(lineValue, 0, 16);
m_aimbotSmoothing = (lineKey.compare("AIMBOT_SMOOTHING") != 0) ? m_aimbotSmoothing : stoi(lineValue);
m_aimbotActivationFOV = (lineKey.compare("AIMBOT_ACTIVATION_FOV") != 0) ? m_aimbotActivationFOV : stoi(lineValue);
m_aimbotMaxRange = (lineKey.compare("AIMBOT_MAX_RANGE") != 0) ? m_aimbotMaxRange : stoi(lineValue);
// norecoil
m_norecoilPitchStrength = (lineKey.compare("NORECOIL_PITCH_STRENGTH") != 0) ? m_norecoilPitchStrength : stod(lineValue);
m_norecoilYawStrength = (lineKey.compare("NORECOIL_YAW_STRENGTH") != 0) ? m_norecoilYawStrength : stod(lineValue);
}
}
void print()
{
printf("\n======================== SETTINGS LOADED ========================\n");
printf("FEATURE_AIMBOT_ON \t\t%s\n", m_featureAimbotOn ? "true" : "false");
printf("FEATURE_NORECOIL_ON \t\t%s\n", m_featureNoRecoilOn ? "true" : "false");
printf("FEATURE_SENSE_ON \t\t%s\n", m_featureSenseOn ? "true" : "false");
printf("AIMBOT_TRIGGER \t\t\t%d\n", m_aimbotTrigger);
printf("AIMBOT_SMOOTHING \t\t%d\n", m_aimbotSmoothing);
printf("AIMBOT_ACTIVATION_FOV \t\t%d\n", m_aimbotActivationFOV);
printf("AIMBOT_MAX_RANGE \t\t%d\n", m_aimbotMaxRange);
printf("NORECOIL_PITCH_STRENGTH \t%.6f\n", m_norecoilPitchStrength);
printf("NORECOIL_YAW_STRENGTH \t\t%.6f\n", m_norecoilYawStrength);
printf("=================================================================\n\n");
}
public:
ConfigLoader()
{
reloadFile();
}
void reloadFile()
{
if (loadFileIntoVector())
{
parseLines();
print();
}
}
// features
bool isAimbotOn()
{
return m_featureAimbotOn;
}
bool isNorecoilOn()
{
return m_featureNoRecoilOn;
}
bool isSenseOn()
{
return m_featureSenseOn;
}
// aimbot
int getAimbotTrigger()
{
return m_aimbotTrigger;
}
int getAimbotSmoothing()
{
return m_aimbotSmoothing;
}
int getAimbotActivationFOV()
{
return m_aimbotActivationFOV;
}
int getAimbotMaxRange()
{
return m_aimbotMaxRange;
}
// norecoil
double getNorecoilPitchStrength()
{
return m_norecoilPitchStrength;
}
double getNorecoilYawStrength()
{
return m_norecoilYawStrength;
}
};