forked from ryantpayton/MapleStory-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfiguration.cpp
402 lines (331 loc) · 8.09 KB
/
Configuration.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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
//////////////////////////////////////////////////////////////////////////////////
// This file is part of the continued Journey MMORPG client //
// Copyright (C) 2015-2019 Daniel Allendorf, Ryan Payton //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//////////////////////////////////////////////////////////////////////////////////
#include "Configuration.h"
#include "Util/Misc.h"
#include <fstream>
namespace ms
{
Configuration::Configuration()
{
settings.emplace<ServerIP>();
settings.emplace<ServerPort>();
settings.emplace<Fullscreen>();
settings.emplace<Width>();
settings.emplace<Height>();
settings.emplace<VSync>();
settings.emplace<FontPathNormal>();
settings.emplace<FontPathBold>();
settings.emplace<BGMVolume>();
settings.emplace<SFXVolume>();
settings.emplace<SaveLogin>();
settings.emplace<DefaultAccount>();
settings.emplace<DefaultWorld>();
settings.emplace<DefaultChannel>();
settings.emplace<DefaultRegion>();
settings.emplace<DefaultCharacter>();
settings.emplace<ChatViewMax>();
settings.emplace<ChatViewX>();
settings.emplace<ChatViewY>();
settings.emplace<PosSTATS>();
settings.emplace<PosEQINV>();
settings.emplace<PosINV>();
settings.emplace<PosSKILL>();
settings.emplace<PosQUEST>();
settings.emplace<PosMAP>();
settings.emplace<PosUSERLIST>();
settings.emplace<PosCHAT>();
settings.emplace<PosMINIMAP>();
settings.emplace<PosSHOP>();
settings.emplace<PosNOTICE>();
settings.emplace<PosMAPLECHAT>();
settings.emplace<PosCHANNEL>();
settings.emplace<PosJOYPAD>();
settings.emplace<PosEVENT>();
settings.emplace<PosKEYCONFIG>();
settings.emplace<PosOPTIONMENU>();
settings.emplace<PosCHARINFO>();
settings.emplace<MiniMapType>();
settings.emplace<MiniMapSimpleMode>();
settings.emplace<MiniMapDefaultHelpers>();
load();
}
Configuration::~Configuration()
{
#ifndef _DEBUG
save();
#endif
}
void Configuration::load()
{
std::unordered_map<std::string, std::string> rawsettings;
std::ifstream file(FILENAME);
if (file.is_open())
{
// Go through the file line by line
std::string line;
while (getline(file, line))
{
// If the setting is not empty, load the value.
size_t split = line.find('=');
if (split != std::string::npos && split + 2 < line.size())
{
rawsettings.emplace(
line.substr(0, split - 1),
line.substr(split + 2)
);
}
}
}
// Replace default values with loaded values
for (auto& setting : settings)
{
auto rsiter = rawsettings.find(setting.second->name);
if (rsiter != rawsettings.end())
setting.second->value = rsiter->second;
}
}
void Configuration::save() const
{
// Open the settings file
std::ofstream config(FILENAME);
if (config.is_open())
{
// Save settings line by line
for (auto& setting : settings)
config << setting.second->to_string() << std::endl;
}
}
void Configuration::BoolEntry::save(bool b)
{
value = b ? "true" : "false";
}
bool Configuration::BoolEntry::load() const
{
return value == "true";
}
void Configuration::StringEntry::save(std::string str)
{
value = str;
}
std::string Configuration::StringEntry::load() const
{
return value;
}
void Configuration::PointEntry::save(Point<int16_t> vec)
{
value = vec.to_string();
}
Point<int16_t> Configuration::PointEntry::load() const
{
std::string xstr = value.substr(1, value.find(",") - 1);
std::string ystr = value.substr(value.find(",") + 1, value.find(")") - value.find(",") - 1);
auto x = string_conversion::or_zero<int16_t>(xstr);
auto y = string_conversion::or_zero<int16_t>(ystr);
return { x, y };
}
bool Configuration::get_show_fps() const
{
return SHOW_FPS;
}
bool Configuration::get_show_packets() const
{
return SHOW_PACKETS;
}
bool Configuration::get_auto_login() const
{
#ifdef NDEBUG
return false;
#endif
return AUTO_LOGIN;
}
uint8_t Configuration::get_auto_world()
{
return auto_world;
}
uint8_t Configuration::get_auto_channel()
{
return auto_channel;
}
std::string Configuration::get_auto_acc()
{
return auto_acc;
}
std::string Configuration::get_auto_pass()
{
return auto_pass;
}
std::string Configuration::get_auto_pic()
{
return auto_pic;
}
int32_t Configuration::get_auto_cid()
{
return auto_cid;
}
std::string Configuration::get_title() const
{
return TITLE;
}
std::string Configuration::get_version() const
{
return VERSION;
}
std::string Configuration::get_login_music() const
{
return LoginMusic;
}
std::string Configuration::get_login_music_sea() const
{
return LoginMusicSEA;
}
std::string Configuration::get_login_music_newtro() const
{
return LoginMusicNewtro;
}
std::string Configuration::get_joinlink() const
{
return JOINLINK;
}
std::string Configuration::get_website() const
{
return WEBSITE;
}
std::string Configuration::get_findid() const
{
return FINDID;
}
std::string Configuration::get_findpass() const
{
return FINDPASS;
}
std::string Configuration::get_resetpic() const
{
return RESETPIC;
}
std::string Configuration::get_chargenx() const
{
return CHARGENX;
}
void Configuration::set_macs(char* macs)
{
MACS = macs;
}
void Configuration::set_hwid(char* hwid, char* volumeSerialNumber)
{
VolumeSerialNumber = volumeSerialNumber;
std::string newHWID;
newHWID.append(hwid);
newHWID.append("_");
std::string part1 = VolumeSerialNumber.substr(0, 2);
std::string part2 = VolumeSerialNumber.substr(2, 2);
std::string part3 = VolumeSerialNumber.substr(4, 2);
std::string part4 = VolumeSerialNumber.substr(6, 2);
// TODO: VolumeSerialNumber was not eight characters long, added fix for last part.
// TODO: Need to look into why the VolumeSerialNumber was seven characters long
part4 = string_format::pad_string(part4, 2);
newHWID.append(part4);
newHWID.append(part3);
newHWID.append(part2);
newHWID.append(part1);
HWID = newHWID;
}
void Configuration::set_max_width(int16_t max_width)
{
MAXWIDTH = max_width;
}
void Configuration::set_max_height(int16_t max_height)
{
MAXHEIGHT = max_height;
}
std::string Configuration::get_macs()
{
return MACS;
}
std::string Configuration::get_hwid()
{
return HWID;
}
std::string Configuration::get_vol_serial_num()
{
return VolumeSerialNumber;
}
int16_t Configuration::get_max_width()
{
return MAXWIDTH;
}
int16_t Configuration::get_max_height()
{
return MAXHEIGHT;
}
bool Configuration::get_rightclicksell()
{
return rightclicksell;
}
void Configuration::set_rightclicksell(bool value)
{
rightclicksell = value;
}
bool Configuration::get_show_weekly()
{
return show_weekly;
}
void Configuration::set_show_weekly(bool value)
{
show_weekly = value;
}
bool Configuration::get_start_shown()
{
return start_shown;
}
void Configuration::set_start_shown(bool value)
{
start_shown = value;
}
uint8_t Configuration::get_worldid()
{
return worldid;
}
void Configuration::set_worldid(uint8_t id)
{
worldid = id;
}
uint8_t Configuration::get_channelid()
{
return channelid;
}
void Configuration::set_channelid(uint8_t id)
{
channelid = id;
}
bool Configuration::get_admin()
{
return admin;
}
void Configuration::set_admin(bool value)
{
admin = value;
}
bool Configuration::get_caps_lock_enabled()
{
return caps_lock_enabled;
}
void Configuration::set_caps_lock_enabled(int value)
{
caps_lock_enabled = value;
}
}