-
Notifications
You must be signed in to change notification settings - Fork 224
Expand file tree
/
Copy pathsettings_parser.cpp
More file actions
1914 lines (1627 loc) · 91.5 KB
/
settings_parser.cpp
File metadata and controls
1914 lines (1627 loc) · 91.5 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
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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (C) 2019 Mr Goldberg
This file is part of the Goldberg Emulator
The Goldberg Emulator is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
The Goldberg Emulator 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the Goldberg Emulator; if not, see
<http://www.gnu.org/licenses/>. */
#define SI_CONVERT_GENERIC
#define SI_SUPPORT_IOSTREAMS
#define SI_NO_MBCS
#include "simpleini/SimpleIni.h"
#include "dll/settings_parser.h"
#include "dll/settings_parser_ufs.h"
#include "dll/base64.h"
constexpr const static char config_ini_app[] = "configs.app.ini";
constexpr const static char config_ini_main[] = "configs.main.ini";
constexpr const static char config_ini_overlay[] = "configs.overlay.ini";
constexpr const static char config_ini_user[] = "configs.user.ini";
static CSimpleIniA ini{};
typedef struct IniValue {
enum class Type {
STR,
BOOL,
DOUBLE,
LONG,
};
explicit IniValue(const char *new_val): type(Type::STR), val_str(new_val) {}
explicit IniValue(bool new_val): type(Type::BOOL), val_bool(new_val) {}
explicit IniValue(double new_val): type(Type::DOUBLE), val_double(new_val) {}
explicit IniValue(long new_val): type(Type::LONG), val_long(new_val) {}
Type type;
union {
const char *val_str;
bool val_bool;
double val_double;
long val_long;
};
} IniValue;
static void save_global_ini_value(class Local_Storage *local_storage, const char *filename, const char *section, const char *key, IniValue val, const char *comment = nullptr) {
CSimpleIniA new_ini{};
new_ini.SetUnicode();
new_ini.SetSpaces(false);
auto sz = local_storage->data_settings_size(filename);
if (sz > 0) {
std::vector<char> ini_file_data(sz);
auto read = local_storage->get_data_settings(filename, &ini_file_data[0], static_cast<unsigned int>(ini_file_data.size()));
if (read == sz) {
new_ini.LoadData(&ini_file_data[0], ini_file_data.size());
}
}
std::string comment_str{};
if (comment && comment[0]) {
comment_str.append("# ").append(comment);
comment = comment_str.c_str();
}
switch (val.type)
{
case IniValue::Type::STR:
new_ini.SetValue(section, key, val.val_str, comment);
break;
case IniValue::Type::BOOL:
new_ini.SetBoolValue(section, key, val.val_bool, comment);
break;
case IniValue::Type::DOUBLE:
new_ini.SetDoubleValue(section, key, val.val_double, comment);
break;
case IniValue::Type::LONG:
new_ini.SetLongValue(section, key, val.val_long, comment);
break;
default: break;
}
std::string ini_buff{};
if (new_ini.Save(ini_buff, false) == SI_OK) {
local_storage->store_data_settings(filename, &ini_buff[0], static_cast<unsigned int>(ini_buff.size()));
}
}
static void merge_ini(const CSimpleIniA &new_ini, bool overwrite = false) {
std::list<CSimpleIniA::Entry> sections{};
new_ini.GetAllSections(sections);
for (auto const &sec : sections) {
std::list<CSimpleIniA::Entry> keys{};
new_ini.GetAllKeys(sec.pItem, keys);
for (auto const &key : keys) {
// only add the key if it didn't exist already
if (!ini.KeyExists(sec.pItem, key.pItem) || overwrite) {
std::list<CSimpleIniA::Entry> vals{};
new_ini.GetAllValues(sec.pItem, key.pItem, vals);
for (const auto &val : vals) {
ini.SetValue(sec.pItem, key.pItem, val.pItem);
}
}
}
}
}
Overlay_Appearance::NotificationPosition Overlay_Appearance::translate_notification_position(const std::string &str)
{
if (str == "top_left") return NotificationPosition::top_left;
else if (str == "top_center") return NotificationPosition::top_center;
else if (str == "top_right") return NotificationPosition::top_right;
else if (str == "bot_left") return NotificationPosition::bot_left;
else if (str == "bot_center") return NotificationPosition::bot_center;
else if (str == "bot_right") return NotificationPosition::bot_right;
PRINT_DEBUG("Invalid position '%s'", str.c_str());
return default_pos;
}
// custom_broadcasts.txt
static void load_custom_broadcasts(const std::string &base_path, std::set<IP_PORT> &custom_broadcasts)
{
const std::string broadcasts_filepath(base_path + "custom_broadcasts.txt");
std::ifstream broadcasts_file(std::filesystem::u8path(broadcasts_filepath));
if (broadcasts_file.is_open()) {
common_helpers::consume_bom(broadcasts_file);
PRINT_DEBUG("loading broadcasts file '%s'", broadcasts_filepath.c_str());
std::string line{};
while (std::getline(broadcasts_file, line)) {
if (line.length() <= 0) continue;
std::set<IP_PORT> ips = Networking::resolve_ip(line);
custom_broadcasts.insert(ips.begin(), ips.end());
PRINT_DEBUG("added ip/port to broadcast list '%s'", line.c_str());
}
}
}
// subscribed_groups_clans.txt
static void load_subscribed_groups_clans(const std::string &base_path, Settings *settings_client, Settings *settings_server)
{
const std::string clans_filepath(base_path + "subscribed_groups_clans.txt");
std::ifstream clans_file(std::filesystem::u8path(clans_filepath));
if (clans_file.is_open()) {
common_helpers::consume_bom(clans_file);
PRINT_DEBUG("loading group clans file '%s'", clans_filepath.c_str());
std::string line{};
while (std::getline(clans_file, line)) {
if (line.length() <= 0) continue;
std::size_t seperator1 = line.find("\t\t");
std::size_t seperator2 = line.rfind("\t\t");
std::string clan_id;
std::string clan_name;
std::string clan_tag;
if ((seperator1 != std::string::npos) && (seperator2 != std::string::npos)) {
clan_id = line.substr(0, seperator1);
clan_name = line.substr(seperator1+2, seperator2-2);
clan_tag = line.substr(seperator2+2);
// fix persistant tabbing problem for clan name
std::size_t seperator3 = clan_name.find("\t");
std::string clan_name_fix = clan_name.substr(0, seperator3);
clan_name = clan_name_fix;
}
Group_Clans nclan;
nclan.id = CSteamID( std::stoull(clan_id.c_str(), NULL, 0) );
nclan.name = clan_name;
nclan.tag = clan_tag;
try {
settings_client->subscribed_groups_clans.push_back(nclan);
settings_server->subscribed_groups_clans.push_back(nclan);
PRINT_DEBUG("Added clan %s", clan_name.c_str());
} catch (...) {}
}
}
}
// overlay::appearance
static void load_overlay_appearance(class Settings *settings_client, class Settings *settings_server, class Local_Storage *local_storage)
{
std::list<CSimpleIniA::Entry> names{};
if (!ini.GetAllKeys("overlay::appearance", names) || names.empty()) return;
for (const auto &name_ent : names) {
auto val_ptr = ini.GetValue("overlay::appearance", name_ent.pItem);
if (!val_ptr || !val_ptr[0]) continue;
std::string name(name_ent.pItem);
std::string value(val_ptr);
PRINT_DEBUG(" Overlay appearance line '%s'='%s'", name.c_str(), value.c_str());
try {
if (name.compare("Font_Override") == 0) {
value = common_helpers::string_strip(value);
// first try the local settings folder
std::string nfont_override(common_helpers::to_absolute(value, Local_Storage::get_game_settings_path() + "fonts"));
if (!common_helpers::file_exist(nfont_override)) {
nfont_override.clear();
}
// then try the global settings folder
if (nfont_override.empty()) {
nfont_override = common_helpers::to_absolute(value, local_storage->get_global_settings_path() + "fonts");
if (!common_helpers::file_exist(nfont_override)) {
nfont_override.clear();
}
}
if (nfont_override.size()) {
settings_client->overlay_appearance.font_override = nfont_override;
settings_server->overlay_appearance.font_override = nfont_override;
PRINT_DEBUG(" loaded font '%s'", nfont_override.c_str());
} else {
PRINT_DEBUG(" ERROR font file '%s' doesn't exist and will be ignored", value.c_str());
}
} else if (name.compare("Font_Size") == 0) {
float nfont_size = std::stof(value, NULL);
settings_client->overlay_appearance.font_size = nfont_size;
settings_server->overlay_appearance.font_size = nfont_size;
} else if (name.compare("Icon_Size") == 0) {
float nicon_size = std::stof(value, NULL);
settings_client->overlay_appearance.icon_size = nicon_size;
settings_server->overlay_appearance.icon_size = nicon_size;
} else if (name.compare("Font_Glyph_Extra_Spacing_x") == 0) {
float size = std::stof(value, NULL);
settings_client->overlay_appearance.font_glyph_extra_spacing_x = size;
settings_server->overlay_appearance.font_glyph_extra_spacing_x = size;
} else if (name.compare("Font_Glyph_Extra_Spacing_y") == 0) {
float size = std::stof(value, NULL);
settings_client->overlay_appearance.font_glyph_extra_spacing_y = size;
settings_server->overlay_appearance.font_glyph_extra_spacing_y = size;
} else if (name.compare("Notification_R") == 0) {
float nnotification_r = std::stof(value, NULL);
settings_client->overlay_appearance.notification_r = nnotification_r;
settings_server->overlay_appearance.notification_r = nnotification_r;
} else if (name.compare("Notification_G") == 0) {
float nnotification_g = std::stof(value, NULL);
settings_client->overlay_appearance.notification_g = nnotification_g;
settings_server->overlay_appearance.notification_g = nnotification_g;
} else if (name.compare("Notification_B") == 0) {
float nnotification_b = std::stof(value, NULL);
settings_client->overlay_appearance.notification_b = nnotification_b;
settings_server->overlay_appearance.notification_b = nnotification_b;
} else if (name.compare("Notification_A") == 0) {
float nnotification_a = std::stof(value, NULL);
settings_client->overlay_appearance.notification_a = nnotification_a;
settings_server->overlay_appearance.notification_a = nnotification_a;
} else if (name.compare("Notification_Rounding") == 0) {
float nnotification_rounding = std::stof(value, NULL);
settings_client->overlay_appearance.notification_rounding = nnotification_rounding;
settings_server->overlay_appearance.notification_rounding = nnotification_rounding;
} else if (name.compare("Notification_Margin_x") == 0) {
float val = std::stof(value, NULL);
settings_client->overlay_appearance.notification_margin_x = val;
settings_server->overlay_appearance.notification_margin_x = val;
} else if (name.compare("Notification_Margin_y") == 0) {
float val = std::stof(value, NULL);
settings_client->overlay_appearance.notification_margin_y = val;
settings_server->overlay_appearance.notification_margin_y = val;
} else if (name.compare("Notification_Animation") == 0) {
uint32 nnotification_animation = (uint32)(std::stof(value, NULL) * 1000.0f); // convert sec to milli
settings_client->overlay_appearance.notification_animation = nnotification_animation;
settings_server->overlay_appearance.notification_animation = nnotification_animation;
} else if (name.compare("Notification_Duration_Progress") == 0) {
uint32 time = (uint32)(std::stof(value, NULL) * 1000.0f); // convert sec to milli
settings_client->overlay_appearance.notification_duration_progress = time;
settings_server->overlay_appearance.notification_duration_progress = time;
} else if (name.compare("Notification_Duration_Achievement") == 0) {
uint32 time = (uint32)(std::stof(value, NULL) * 1000.0f); // convert sec to milli
settings_client->overlay_appearance.notification_duration_achievement = time;
settings_server->overlay_appearance.notification_duration_achievement = time;
} else if (name.compare("Notification_Duration_Invitation") == 0) {
uint32 time = (uint32)(std::stof(value, NULL) * 1000.0f); // convert sec to milli
settings_client->overlay_appearance.notification_duration_invitation = time;
settings_server->overlay_appearance.notification_duration_invitation = time;
} else if (name.compare("Notification_Duration_Chat") == 0) {
uint32 time = (uint32)(std::stof(value, NULL) * 1000.0f); // convert sec to milli
settings_client->overlay_appearance.notification_duration_chat = time;
settings_server->overlay_appearance.notification_duration_chat = time;
} else if (name.compare("Achievement_Unlock_Datetime_Format") == 0) {
settings_client->overlay_appearance.ach_unlock_datetime_format = value;
settings_server->overlay_appearance.ach_unlock_datetime_format = value;
} else if (name.compare("Background_R") == 0) {
float nbackground_r = std::stof(value, NULL);
settings_client->overlay_appearance.background_r = nbackground_r;
settings_server->overlay_appearance.background_r = nbackground_r;
} else if (name.compare("Background_G") == 0) {
float nbackground_g = std::stof(value, NULL);
settings_client->overlay_appearance.background_g = nbackground_g;
settings_server->overlay_appearance.background_g = nbackground_g;
} else if (name.compare("Background_B") == 0) {
float nbackground_b = std::stof(value, NULL);
settings_client->overlay_appearance.background_b = nbackground_b;
settings_server->overlay_appearance.background_b = nbackground_b;
} else if (name.compare("Background_A") == 0) {
float nbackground_a = std::stof(value, NULL);
settings_client->overlay_appearance.background_a = nbackground_a;
settings_server->overlay_appearance.background_a = nbackground_a;
} else if (name.compare("Element_R") == 0) {
float nelement_r = std::stof(value, NULL);
settings_client->overlay_appearance.element_r = nelement_r;
settings_server->overlay_appearance.element_r = nelement_r;
} else if (name.compare("Element_G") == 0) {
float nelement_g = std::stof(value, NULL);
settings_client->overlay_appearance.element_g = nelement_g;
settings_server->overlay_appearance.element_g = nelement_g;
} else if (name.compare("Element_B") == 0) {
float nelement_b = std::stof(value, NULL);
settings_client->overlay_appearance.element_b = nelement_b;
settings_server->overlay_appearance.element_b = nelement_b;
} else if (name.compare("Element_A") == 0) {
float nelement_a = std::stof(value, NULL);
settings_client->overlay_appearance.element_a = nelement_a;
settings_server->overlay_appearance.element_a = nelement_a;
} else if (name.compare("ElementHovered_R") == 0) {
float nelement_hovered_r = std::stof(value, NULL);
settings_client->overlay_appearance.element_hovered_r = nelement_hovered_r;
settings_server->overlay_appearance.element_hovered_r = nelement_hovered_r;
} else if (name.compare("ElementHovered_G") == 0) {
float nelement_hovered_g = std::stof(value, NULL);
settings_client->overlay_appearance.element_hovered_g = nelement_hovered_g;
settings_server->overlay_appearance.element_hovered_g = nelement_hovered_g;
} else if (name.compare("ElementHovered_B") == 0) {
float nelement_hovered_b = std::stof(value, NULL);
settings_client->overlay_appearance.element_hovered_b = nelement_hovered_b;
settings_server->overlay_appearance.element_hovered_b = nelement_hovered_b;
} else if (name.compare("ElementHovered_A") == 0) {
float nelement_hovered_a = std::stof(value, NULL);
settings_client->overlay_appearance.element_hovered_a = nelement_hovered_a;
settings_server->overlay_appearance.element_hovered_a = nelement_hovered_a;
} else if (name.compare("ElementActive_R") == 0) {
float nelement_active_r = std::stof(value, NULL);
settings_client->overlay_appearance.element_active_r = nelement_active_r;
settings_server->overlay_appearance.element_active_r = nelement_active_r;
} else if (name.compare("ElementActive_G") == 0) {
float nelement_active_g = std::stof(value, NULL);
settings_client->overlay_appearance.element_active_g = nelement_active_g;
settings_server->overlay_appearance.element_active_g = nelement_active_g;
} else if (name.compare("ElementActive_B") == 0) {
float nelement_active_b = std::stof(value, NULL);
settings_client->overlay_appearance.element_active_b = nelement_active_b;
settings_server->overlay_appearance.element_active_b = nelement_active_b;
} else if (name.compare("ElementActive_A") == 0) {
float nelement_active_a = std::stof(value, NULL);
settings_client->overlay_appearance.element_active_a = nelement_active_a;
settings_server->overlay_appearance.element_active_a = nelement_active_a;
} else if (name.compare("PosAchievement") == 0) {
auto pos = Overlay_Appearance::translate_notification_position(value);
settings_client->overlay_appearance.ach_earned_pos = pos;
settings_server->overlay_appearance.ach_earned_pos = pos;
} else if (name.compare("PosInvitation") == 0) {
auto pos = Overlay_Appearance::translate_notification_position(value);
settings_client->overlay_appearance.invite_pos = pos;
settings_server->overlay_appearance.invite_pos = pos;
} else if (name.compare("PosChatMsg") == 0) {
auto pos = Overlay_Appearance::translate_notification_position(value);
settings_client->overlay_appearance.chat_msg_pos = pos;
settings_server->overlay_appearance.chat_msg_pos = pos;
// >>> FPS background
} else if (name.compare("Stats_Background_R") == 0) {
float val = std::stof(value, NULL);
settings_client->overlay_appearance.stats_background_r = val;
settings_server->overlay_appearance.stats_background_r = val;
} else if (name.compare("Stats_Background_G") == 0) {
float val = std::stof(value, NULL);
settings_client->overlay_appearance.stats_background_g = val;
settings_server->overlay_appearance.stats_background_g = val;
} else if (name.compare("Stats_Background_B") == 0) {
float val = std::stof(value, NULL);
settings_client->overlay_appearance.stats_background_b = val;
settings_server->overlay_appearance.stats_background_b = val;
} else if (name.compare("Stats_Background_A") == 0) {
float val = std::stof(value, NULL);
settings_client->overlay_appearance.stats_background_a = val;
settings_server->overlay_appearance.stats_background_a = val;
// FPS background END <<<
// >>> FPS text color
} else if (name.compare("Stats_Text_R") == 0) {
float val = std::stof(value, NULL);
settings_client->overlay_appearance.stats_text_r = val;
settings_server->overlay_appearance.stats_text_r = val;
} else if (name.compare("Stats_Text_G") == 0) {
float val = std::stof(value, NULL);
settings_client->overlay_appearance.stats_text_g = val;
settings_server->overlay_appearance.stats_text_g = val;
} else if (name.compare("Stats_Text_B") == 0) {
float val = std::stof(value, NULL);
settings_client->overlay_appearance.stats_text_b = val;
settings_server->overlay_appearance.stats_text_b = val;
} else if (name.compare("Stats_Text_A") == 0) {
float val = std::stof(value, NULL);
settings_client->overlay_appearance.stats_text_a = val;
settings_server->overlay_appearance.stats_text_a = val;
// FPS text color END <<<
// >>> FPS position
} else if (name.compare("Stats_Pos_x") == 0) {
auto pos = std::stof(value);
if (pos < 0) {
pos = 0;
} else if (pos > 1.0f) {
pos = 1.0f;
}
settings_client->overlay_stats_pos_x = pos;
settings_server->overlay_stats_pos_x = pos;
} else if (name.compare("Stats_Pos_y") == 0) {
auto pos = std::stof(value);
if (pos < 0) {
pos = 0;
} else if (pos > 1.0f) {
pos = 1.0f;
}
settings_client->overlay_stats_pos_y = pos;
settings_server->overlay_stats_pos_y = pos;
// FPS position END <<<
} else {
PRINT_DEBUG("unknown overlay appearance setting");
}
} catch (...) { }
}
}
template<typename Out>
static void split_string(const std::string &s, char delim, Out result) {
std::stringstream ss(s);
std::string item{};
while (std::getline(ss, item, delim)) {
*(result++) = item;
}
}
// folder "controller"
static void load_gamecontroller_settings(Settings *settings)
{
std::string path = Local_Storage::get_game_settings_path() + "controller";
std::vector<std::string> paths = Local_Storage::get_filenames_path(path);
for (auto & p: paths) {
size_t length = p.length();
if (length < 4) continue;
if ( std::toupper(p.back()) != 'T') continue;
if ( std::toupper(p[length - 2]) != 'X') continue;
if ( std::toupper(p[length - 3]) != 'T') continue;
if (p[length - 4] != '.') continue;
PRINT_DEBUG("controller config %s", p.c_str());
std::string action_set_name = p.substr(0, length - 4);
std::transform(action_set_name.begin(), action_set_name.end(), action_set_name.begin(),[](unsigned char c){ return std::toupper(c); });
std::string controller_config_path = path + PATH_SEPARATOR + p;
std::ifstream input( std::filesystem::u8path(controller_config_path) );
if (input.is_open()) {
common_helpers::consume_bom(input);
std::map<std::string, std::pair<std::set<std::string>, std::string>> button_pairs;
for( std::string line; getline( input, line ); ) {
if (!line.empty() && line[line.length()-1] == '\n') {
line.pop_back();
}
if (!line.empty() && line[line.length()-1] == '\r') {
line.pop_back();
}
std::string action_name;
std::string button_name;
std::string source_mode;
std::size_t deliminator = line.find("=");
if (deliminator != 0 && deliminator != std::string::npos && deliminator != line.size()) {
action_name = line.substr(0, deliminator);
std::size_t deliminator2 = line.find("=", deliminator + 1);
if (deliminator2 != std::string::npos && deliminator2 != line.size()) {
button_name = line.substr(deliminator + 1, deliminator2 - (deliminator + 1));
source_mode = line.substr(deliminator2 + 1);
} else {
button_name = line.substr(deliminator + 1);
source_mode = "";
}
}
std::transform(action_name.begin(), action_name.end(), action_name.begin(),[](unsigned char c){ return std::toupper(c); });
std::transform(button_name.begin(), button_name.end(), button_name.begin(),[](unsigned char c){ return std::toupper(c); });
std::pair<std::set<std::string>, std::string> button_config = {{}, source_mode};
split_string(button_name, ',', std::inserter(button_config.first, button_config.first.begin()));
button_pairs[action_name] = button_config;
PRINT_DEBUG("Added %s %s %s", action_name.c_str(), button_name.c_str(), source_mode.c_str());
}
settings->controller_settings.action_sets[action_set_name] = button_pairs;
PRINT_DEBUG("Added %zu action names to %s", button_pairs.size(), action_set_name.c_str());
}
}
settings->glyphs_directory = path + (PATH_SEPARATOR "glyphs" PATH_SEPARATOR);
}
// steam_appid.txt
static uint32 parse_steam_app_id(const std::string &program_path)
{
uint32 appid = 0;
// try steam_settings folder
char array[10] = {};
array[0] = '0';
Local_Storage::get_file_data(Local_Storage::get_game_settings_path() + "steam_appid.txt", array, sizeof(array) - 1);
try {
appid = std::stoul(array);
} catch (...) {}
// try current dir
if (!appid) {
memset(array, 0, sizeof(array));
array[0] = '0';
Local_Storage::get_file_data("steam_appid.txt", array, sizeof(array) - 1);
try {
appid = std::stoul(array);
} catch (...) {}
}
// try exe dir
if (!appid) {
memset(array, 0, sizeof(array));
array[0] = '0';
Local_Storage::get_file_data(program_path + "steam_appid.txt", array, sizeof(array) - 1);
try {
appid = std::stoul(array);
} catch (...) {}
}
// try env vars
if (!appid) {
std::string str_appid = get_env_variable("SteamAppId");
std::string str_gameid = get_env_variable("SteamGameId");
std::string str_overlay_gameid = get_env_variable("SteamOverlayGameId");
PRINT_DEBUG("str_appid %s str_gameid: %s str_overlay_gameid: %s", str_appid.c_str(), str_gameid.c_str(), str_overlay_gameid.c_str());
uint32 appid_env = 0;
uint32 gameid_env = 0;
uint32 overlay_gameid = 0;
if (str_appid.size() > 0) {
try {
appid_env = std::stoul(str_appid);
} catch (...) {
appid_env = 0;
}
}
if (str_gameid.size() > 0) {
try {
gameid_env = std::stoul(str_gameid);
} catch (...) {
gameid_env = 0;
}
}
if (str_overlay_gameid.size() > 0) {
try {
overlay_gameid = std::stoul(str_overlay_gameid);
} catch (...) {
overlay_gameid = 0;
}
}
PRINT_DEBUG("appid_env %u gameid_env: %u overlay_gameid: %u", appid_env, gameid_env, overlay_gameid);
if (appid_env) {
appid = appid_env;
}
if (gameid_env) {
appid = gameid_env;
}
if (overlay_gameid) {
appid = overlay_gameid;
}
}
PRINT_DEBUG("final appid = %u", appid);
return appid;
}
// user::saves::local_save_path
static bool parse_local_save(std::string &save_path)
{
auto ptr = ini.GetValue("user::saves", "local_save_path");
if (!ptr || !ptr[0]) return false;
save_path = common_helpers::to_absolute(common_helpers::string_strip(ptr), Local_Storage::get_program_path());
if (save_path.size() && save_path.back() != *PATH_SEPARATOR) {
save_path.push_back(*PATH_SEPARATOR);
}
PRINT_DEBUG("using local save path '%s'", save_path.c_str());
return true;
}
// main::connectivity::listen_port
static uint16 parse_listen_port(class Local_Storage *local_storage)
{
uint16 port = static_cast<uint16>(ini.GetLongValue("main::connectivity", "listen_port"));
if (port == 0) {
port = DEFAULT_PORT;
}
return port;
}
// user::general::account_name
static std::string parse_account_name(class Local_Storage *local_storage)
{
auto name = ini.GetValue("user::general", "account_name");
if (!name || !name[0]) {
name = DEFAULT_NAME;
save_global_ini_value(
local_storage,
config_ini_user,
"user::general", "account_name", IniValue(name),
"user account name"
);
}
return std::string(name);
}
// user::general::account_steamid
static CSteamID parse_user_steam_id(class Local_Storage *local_storage)
{
char array_steam_id[32] = {};
CSteamID user_id((uint64)std::atoll(ini.GetValue("user::general", "account_steamid", "0")));
if (!user_id.IsValid()) {
user_id = generate_steam_id_user();
char temp_text[32]{};
snprintf(temp_text, sizeof(temp_text), "%llu", (uint64)user_id.ConvertToUint64());
save_global_ini_value(
local_storage,
config_ini_user,
"user::general", "account_steamid", IniValue(temp_text),
"Steam64 format"
);
}
return user_id;
}
// user::general::alt_steamid
static CSteamID parse_alt_steam_id(class Local_Storage* local_storage)
{
CSteamID alt_steam_id((uint64)std::atoll(ini.GetValue("user::general", "alt_steamid", "0")));
if (!alt_steam_id.IsValid()) {
return CSteamID();
}
PRINT_DEBUG("Alt Steam ID: %llu", alt_steam_id);
return alt_steam_id;
}
// user::general::alt_steamid_count
static uint32 parse_alt_steamid_count(class Local_Storage* local_storage)
{
uint32 count = static_cast<uint32>(ini.GetLongValue("user::general", "alt_steamid_count"));
PRINT_DEBUG("Alt Steam ID count: %u", (uint32)count);
return (uint32)count;
}
// user::general::ticket
static void parse_encrypted_app_ticket(class Settings *settings_client, class Settings *settings_server)
{
std::string ticketValue(common_helpers::string_strip(ini.GetValue("user::general", "ticket", "")));
if (ticketValue.size()) {
std::vector<uint8_t> ticket = base64_decode(ticketValue);
settings_client->customEncryptedAppTicket = ticket;
settings_server->customEncryptedAppTicket = ticket;
}
}
// user::general::language
// valid list: https://partner.steamgames.com/doc/store/localization/languages
static std::string parse_current_language(class Local_Storage *local_storage)
{
auto lang = ini.GetValue("user::general", "language");
if (!lang || !lang[0]) {
lang = DEFAULT_LANGUAGE;
save_global_ini_value(
local_storage,
config_ini_user,
"user::general", "language", IniValue(lang),
"the language reported to the game, default is 'english', check 'API language code' in https://partner.steamgames.com/doc/store/localization/languages"
);
}
return common_helpers::to_lower(std::string(lang));
}
// supported_languages.txt
// valid list: https://partner.steamgames.com/doc/store/localization/languages
static std::set<std::string> parse_supported_languages(class Local_Storage *local_storage, std::string &language)
{
std::set<std::string> supported_languages{};
std::string lang_config_path = Local_Storage::get_game_settings_path() + "supported_languages.txt";
std::ifstream input( std::filesystem::u8path(lang_config_path) );
std::string first_language{};
if (input.is_open()) {
common_helpers::consume_bom(input);
for( std::string line; getline( input, line ); ) {
if (!line.empty() && line.back() == '\n') {
line.pop_back();
}
if (!line.empty() && line.back() == '\r') {
line.pop_back();
}
try {
std::string lang = common_helpers::to_lower(line);
if (!first_language.size()) first_language = lang;
supported_languages.insert(lang);
PRINT_DEBUG("Added supported_language %s", lang.c_str());
} catch (...) {}
}
}
// if the current emu language is not in the supported languages list
if (!supported_languages.count(language)) {
if (first_language.size()) { // get the first supported language if the list wasn't empty
PRINT_DEBUG("[?] Your language '%s' isn't found in supported_languages.txt, using '%s' instead", language.c_str(), first_language.c_str());
language = first_language;
} else { // otherwise just lie and add it then!
supported_languages.insert(language);
PRINT_DEBUG("Forced current language '%s' into supported_languages", language.c_str());
}
}
return supported_languages;
}
// app::dlcs
static void parse_dlc(class Settings *settings_client, class Settings *settings_server)
{
constexpr static const char unlock_all_key[] = "unlock_all";
bool unlock_all = ini.GetBoolValue("app::dlcs", unlock_all_key, true);
if (unlock_all) {
PRINT_DEBUG("unlocking all DLCs");
settings_client->unlockAllDLC(true);
settings_server->unlockAllDLC(true);
} else {
PRINT_DEBUG("locking all DLCs");
settings_client->unlockAllDLC(false);
settings_server->unlockAllDLC(false);
}
std::list<CSimpleIniA::Entry> dlcs_keys{};
if (!ini.GetAllKeys("app::dlcs", dlcs_keys) || dlcs_keys.empty()) return;
// remove the unlock all key so we can iterate through the DLCs
dlcs_keys.remove_if([](const CSimpleIniA::Entry &item){
return common_helpers::str_cmp_insensitive(item.pItem, unlock_all_key);
});
for (const auto &dlc_key : dlcs_keys) {
AppId_t appid = (AppId_t)std::stoul(dlc_key.pItem);
if (!appid) continue;
auto name = ini.GetValue("app::dlcs", dlc_key.pItem, "unknown DLC");
PRINT_DEBUG("adding DLC: [%u] = '%s'", appid, name);
settings_client->addDLC(appid, name, true);
settings_server->addDLC(appid, name, true);
}
}
// app::paths
static void parse_app_paths(class Settings *settings_client, Settings *settings_server, const std::string &program_path)
{
std::list<CSimpleIniA::Entry> ids{};
if (!ini.GetAllKeys("app::paths", ids) || ids.empty()) return;
for (const auto &id : ids) {
auto val_ptr = ini.GetValue("app::paths", id.pItem);
// NOTE: empty path means we actively disable the path to the appid specified
if (!val_ptr) continue;
AppId_t appid = (AppId_t)std::stoul(id.pItem);
std::string rel_path(val_ptr);
std::string path{};
if (rel_path.size())
path = canonical_path(program_path + rel_path);
if (appid) {
if (!rel_path.size() || path.size()) {
PRINT_DEBUG("Adding app path: %u|%s|%s", appid, rel_path.c_str(), path.c_str());
settings_client->setAppInstallPath(appid, path);
settings_server->setAppInstallPath(appid, path);
} else {
PRINT_DEBUG("Error adding app path for: %u does this path exist? |%s|", appid, rel_path.c_str());
}
}
}
}
// leaderboards.txt
static void parse_leaderboards(class Settings *settings_client, class Settings *settings_server)
{
std::string dlc_config_path = Local_Storage::get_game_settings_path() + "leaderboards.txt";
std::ifstream input( std::filesystem::u8path(dlc_config_path) );
if (input.is_open()) {
common_helpers::consume_bom(input);
for( std::string line; getline( input, line ); ) {
if (!line.empty() && line[line.length()-1] == '\n') {
line.pop_back();
}
if (!line.empty() && line[line.length()-1] == '\r') {
line.pop_back();
}
std::string leaderboard{};
unsigned int sort_method = 0;
unsigned int display_type = 0;
std::size_t deliminator = line.find("=");
if (deliminator != 0 && deliminator != std::string::npos && deliminator != line.size()) {
leaderboard = line.substr(0, deliminator);
std::size_t deliminator2 = line.find("=", deliminator + 1);
if (deliminator2 != std::string::npos && deliminator2 != line.size()) {
sort_method = stol(line.substr(deliminator + 1, deliminator2 - (deliminator + 1)));
display_type = stol(line.substr(deliminator2 + 1));
}
}
if (leaderboard.size() && sort_method <= k_ELeaderboardSortMethodDescending && display_type <= k_ELeaderboardDisplayTypeTimeMilliSeconds) {
PRINT_DEBUG("Adding leaderboard: %s|%u|%u", leaderboard.c_str(), sort_method, display_type);
settings_client->setLeaderboard(leaderboard, (ELeaderboardSortMethod)sort_method, (ELeaderboardDisplayType)display_type);
settings_server->setLeaderboard(leaderboard, (ELeaderboardSortMethod)sort_method, (ELeaderboardDisplayType)display_type);
} else {
PRINT_DEBUG("Error adding leaderboard for: '%s', are sort method %u or display type %u valid?", leaderboard.c_str(), sort_method, display_type);
}
}
}
}
// stats.json
static void parse_stats(class Settings *settings_client, class Settings *settings_server, class Local_Storage *local_storage)
{
nlohmann::json stats_items;
std::string stats_json_path = Local_Storage::get_game_settings_path() + "stats.json";
if (local_storage->load_json(stats_json_path, stats_items)) {
for (const auto &stats : stats_items) {
std::string stat_name;
std::string stat_type;
std::string stat_default_value = "0";
std::string stat_global_value = "0";
try {
stat_name = stats.value("name", std::string(""));
stat_type = stats.value("type", std::string(""));
stat_default_value = stats.value("default", std::string("0"));
stat_global_value = stats.value("global", std::string("0"));
}
catch (const std::exception &e) {
PRINT_DEBUG("Error reading current stat item in stats.json, reason: %s", e.what());
continue;
}
std::transform(stat_type.begin(), stat_type.end(), stat_type.begin(),[](unsigned char c){ return std::tolower(c); });
struct Stat_config config = {};
try {
if (stat_type == "float") {
config.type = StatInfo::STAT_TYPE_FLOAT;
config.default_value_float = std::stof(stat_default_value);
config.global_value_double = std::stod(stat_global_value);
} else if (stat_type == "int") {
config.type = StatInfo::STAT_TYPE_INT;
config.default_value_int = std::stol(stat_default_value);
config.global_value_int64 = std::stoll(stat_global_value);
} else if (stat_type == "avgrate") {
config.type = StatInfo::STAT_TYPE_AVGRATE;
config.default_value_float = std::stof(stat_default_value);
config.global_value_double = std::stod(stat_global_value);
} else {
PRINT_DEBUG("Error adding stat %s, type %s isn't valid", stat_name.c_str(), stat_type.c_str());
continue;
}
} catch (...) {
PRINT_DEBUG("Error adding stat %s, default value %s or global value %s isn't valid", stat_name.c_str(), stat_default_value.c_str(), stat_global_value.c_str());
continue;
}
if (stat_name.size()) {
PRINT_DEBUG("Adding stat type: %s|%u|%f|%i", stat_name.c_str(), config.type, config.default_value_float, config.default_value_int);
settings_client->setStatDefiniton(stat_name, config);
settings_server->setStatDefiniton(stat_name, config);
} else {
PRINT_DEBUG("Error adding stat for: %s, empty name", stat_name.c_str());
}
}
}
}
// depots.txt
static void parse_depots(class Settings *settings_client, class Settings *settings_server)
{
std::string depots_config_path = Local_Storage::get_game_settings_path() + "depots.txt";
std::ifstream input( std::filesystem::u8path(depots_config_path) );
if (input.is_open()) {
common_helpers::consume_bom(input);
for( std::string line; getline( input, line ); ) {
if (!line.empty() && line[line.length()-1] == '\n') {
line.pop_back();
}
if (!line.empty() && line[line.length()-1] == '\r') {
line.pop_back();
}
try {
DepotId_t depot_id = std::stoul(line);
settings_client->depots.push_back(depot_id);
settings_server->depots.push_back(depot_id);
PRINT_DEBUG("Added depot %u", depot_id);
} catch (...) {}
}
}
}
// subscribed_groups.txt
static void parse_subscribed_groups(class Settings *settings_client, class Settings *settings_server)
{
std::string depots_config_path = Local_Storage::get_game_settings_path() + "subscribed_groups.txt";
std::ifstream input( std::filesystem::u8path(depots_config_path) );
if (input.is_open()) {
common_helpers::consume_bom(input);
for( std::string line; getline( input, line ); ) {
if (!line.empty() && line[line.length()-1] == '\n') {
line.pop_back();
}
if (!line.empty() && line[line.length()-1] == '\r') {
line.pop_back();
}
try {
uint64 source_id = std::stoull(line);
settings_client->subscribed_groups.insert(source_id);
settings_server->subscribed_groups.insert(source_id);
PRINT_DEBUG("Added source %llu", source_id);
} catch (...) {}
}
}
}
// installed_app_ids.txt
static void parse_installed_app_Ids(class Settings *settings_client, class Settings *settings_server)
{
std::string installed_apps_list_path = Local_Storage::get_game_settings_path() + "installed_app_ids.txt";
std::ifstream input( std::filesystem::u8path(installed_apps_list_path) );
if (input.is_open()) {
settings_client->assumeAnyAppInstalled(false);
settings_server->assumeAnyAppInstalled(false);
PRINT_DEBUG("Limiting/Locking installed apps");
common_helpers::consume_bom(input);
for( std::string line; getline( input, line ); ) {
if (!line.empty() && line[line.length()-1] == '\n') {
line.pop_back();
}
if (!line.empty() && line[line.length()-1] == '\r') {
line.pop_back();
}
try {