forked from igroglaz/a2mgr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.cpp
266 lines (230 loc) · 6.2 KB
/
config.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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#include "config.h"
#include "utils.h"
std::string current_directory = "";
unsigned long v_screentype = SCREENTYPE_PNG;
unsigned long g_scrollintv = 25;
bool r_fps = false;
bool r_time = false;
bool r_stopwatch = false;
bool r_grid = false;
bool g_altchat = false;
unsigned long r_width = 640;
unsigned long r_height = 480;
bool z_screendir = true;
bool z_logsdir = true;
unsigned long z_resolution = 0;
bool z_russian = true;
bool z_lang_override = false;
bool show_stopwatch = false;
unsigned long show_stopwatch_frozen = 0;
unsigned long net_key = 0;
unsigned long net_maxplayers = 16;
unsigned long r_grid_color = 0x3800;
unsigned long z_handle = 0;
unsigned long crc32_allods2_exe = 0;
unsigned long crc32_a2mgr_dll = 0;
unsigned long crc32_patch_res = 0;//ccrc.CalcCRC(patchr.c_str());
unsigned long crc32_world_res = 0;//ccrc.CalcCRC(worldr.c_str());
unsigned long crc32_graphics_res = 0;//ccrc.CalcCRC(graphr.c_str());
unsigned char sha1_allods2_exe[20];
unsigned char sha1_a2mgr_dll[20];
unsigned char sha1_patch_res[20];
unsigned char sha1_world_res[20];
unsigned char sha1_graphics_res[20];
unsigned char sha1_uuid[20];
int z_softcore = 0;
using namespace std;
void ParseConfig2x(ifstream& f_temp)
{
unsigned long r_widtho = r_width;
unsigned long r_heighto = r_height;
bool invalidwh = false;
string wh;
while(getline(f_temp, wh))
{
wh = Trim(wh);
if(!wh.length()) continue;
size_t cw = wh.find_first_of("#;");
if(cw != string::npos) wh.erase(cw);
if(!wh.length()) continue;
cw = wh.find("//");
if(cw != string::npos) wh.erase(cw);
if(!wh.length()) continue;
vector<string> cmd = ParseCommandLine(wh);
if(!cmd.size() || cmd.size() > 2) continue;
if(cmd[0] == "v_screentype" && cmd.size() == 2)
{
bool invalid = false;
if(CheckInteger(cmd[1]))
{
unsigned long stype = StrToInt(cmd[1]);
if(stype > SCREENTYPE_GIF)
{
stype = v_screentype;
invalid = true;
}
v_screentype = stype;
}
else
{
string ph = ToLower(cmd[1]);
if(ph == "png") v_screentype = SCREENTYPE_PNG;
else if(ph == "jpg") v_screentype = SCREENTYPE_JPG;
else if(ph == "bmp") v_screentype = SCREENTYPE_BMP;
else if(ph == "gif") v_screentype = SCREENTYPE_GIF;
else invalid = true;
}
}
else if(cmd[0] == "g_scrollspeed" && cmd.size() == 2)
{
bool invalid = false;
if(CheckInteger(cmd[1]))
g_scrollintv = StrToInt(cmd[1]);
else invalid = true;
if(!invalid)
{
if(g_scrollintv > 100) g_scrollintv = 100;
unsigned long interval = 1000;
unsigned long scrollintv = 100 - g_scrollintv;
g_scrollintv = (interval / 100) * scrollintv;
}
}
else if(cmd[0] == "r_fps")
{
if(cmd.size() == 2) r_fps = StrToBoolean(cmd[1]);
else r_fps = true;
}
else if(cmd[0] == "r_time")
{
if(cmd.size() == 2) r_time = StrToBoolean(cmd[1]);
else r_time = true;
}
else if(cmd[0] == "r_stopwatch")
{
if(cmd.size() == 2) r_stopwatch = StrToBoolean(cmd[1]);
else r_stopwatch = true;
}
else if(cmd[0] == "g_altchat")
{
if(cmd.size() == 2) g_altchat = StrToBoolean(cmd[1]);
else g_altchat = true;
}
else if(cmd[0] == "r_width" && cmd.size() == 2)
{
bool invalid = false;
if(CheckInteger(cmd[1]))
r_width = StrToInt(cmd[1]);
else invalid = true;
if(!invalidwh) invalidwh = invalid;
if(!invalidwh) z_resolution++;
}
else if(cmd[0] == "r_height" && cmd.size() == 2)
{
bool invalid = false;
if(CheckInteger(cmd[1]))
r_height = StrToInt(cmd[1]);
else invalid = true;
if(!invalidwh) invalidwh = invalid;
if(!invalidwh) z_resolution++;
}
else if(cmd[0] == "z_logsdir")
{
if(cmd.size() == 2) z_logsdir = StrToBoolean(cmd[1]);
else z_logsdir = true;
}
else if(cmd[0] == "z_screendir")
{
if(cmd.size() == 2) z_screendir = StrToBoolean(cmd[1]);
else z_screendir = true;
}
else if(cmd[0] == "z_language" && cmd.size() == 2)
{
string lng = ToLower(cmd[1]);
if(lng == "rus" || lng == "russian")
{
z_russian = true;
z_lang_override = true;
}
else if(lng == "eng" || lng == "english")
{
z_russian = false;
z_lang_override = true;
}
else z_lang_override = false;
}
else if(cmd[0] == "r_grid")
{
if(cmd.size() == 2) r_grid = StrToBoolean(cmd[1]);
else r_grid = true;
}
else if(cmd[0] == "r_grid_color")
{
if(cmd.size() != 2) continue;
vector<string> parmc = Explode(cmd[1], ":");
if(parmc.size() != 3) continue;
unsigned long c_r = 0, c_b = 0, c_g = 0;
if(CheckInteger(parmc[0])) c_r = StrToInt(parmc[0]);
else continue;
if(CheckInteger(parmc[1])) c_g = StrToInt(parmc[1]);
else continue;
if(CheckInteger(parmc[2])) c_b = StrToInt(parmc[2]);
else continue;
c_r = (unsigned long)((float)c_r / 255.0 * 31.0);
c_g = (unsigned long)((float)c_g / 255.0 * 63.0);
c_b = (unsigned long)((float)c_b / 255.0 * 31.0);
unsigned long val = 0;
val |= (c_r & 0x1F);
val <<= 5;
val |= (c_g & 0x3F);
val <<= 6;
val |= (c_b & 0x1F);
r_grid_color = val;
}
}
if(!z_resolution || z_resolution != 2) invalidwh = true;
if(invalidwh)
{
r_width = r_widtho;
r_height = r_heighto;
z_resolution = 0;
}
}
void ParseConfig1x(ifstream& f_temp)
{
string wh;
while(getline(f_temp, wh))
{
wh = Trim(wh);
size_t cw = wh.find_first_of("=");
if(cw == string::npos) continue;
string prm = wh;
string val = wh;
prm.erase(cw);
val.erase(0, cw+1);
prm = Trim(prm);
val = Trim(val);
if(prm == "scroll_inverval")
g_scrollintv = StrToInt(val);
else if(prm == "show_fps")
r_fps = StrToBoolean(val);
else if(prm == "show_watches")
r_time = StrToBoolean(val);
else if(prm == "alt_chat")
g_altchat = StrToBoolean(val);
}
}
void ParseConfig()
{
ifstream f_temp;
bool oldfmt = false;
f_temp.open("allods2.cfg", ios::in);
if(!f_temp.is_open())
{
f_temp.open("allods2.conf", ios::in);
if(!f_temp.is_open()) return;
else oldfmt = true;
}
if(oldfmt) ParseConfig1x(f_temp);
else ParseConfig2x(f_temp);
f_temp.close();
}