-
Notifications
You must be signed in to change notification settings - Fork 17
/
mainwindow.cpp
1489 lines (1359 loc) · 59.8 KB
/
mainwindow.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
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
#include <iostream>
#include <set>
#include <map>
#include <algorithm>
#include <cctype>
#include <string>
#include <sstream>
#include <windows.h>
#include <regex>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string/replace.hpp>
#include "genie/dat/DatFile.h"
#include "genie/lang/LangFile.h"
#include "paths.h"
#include "conversions.h"
#include "wololo/datPatch.h"
#include "wololo/Drs.h"
#include "fixes/berbersutfix.h"
#include "fixes/vietfix.h"
#include "fixes/demoshipfix.h"
#include "fixes/portuguesefix.h"
#include "fixes/malayfix.h"
#include "fixes/ethiopiansfreepikeupgradefix.h"
#include "fixes/maliansfreeminingupgradefix.h"
#include "fixes/ai900unitidfix.h"
#include "fixes/hotkeysfix.h"
#include "fixes/disablenonworkingunits.h"
#include "fixes/feitoriafix.h"
#include "fixes/burmesefix.h"
#include "fixes/incafix.h"
#include "fixes/siegetowerfix.h"
#include "fixes/smallfixes.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "dialog.h"
#include <QWhatsThis>
#include <QPoint>
#include <QProgressBar>
#include "sdk/public/steam/steam_api.h"
#include "JlCompress.h"
namespace fs = boost::filesystem;
fs::path HDPath;
fs::path outPath;
std::map<int, fs::path> slpFiles;
std::map<int, fs::path> wavFiles;
std::map<std::string,fs::path> newTerrainFiles;
std::vector<fs::path> existingMapNames;
std::vector<std::pair<int,std::string>> rmsCodeStrings;
std::string const version = "2.1";
std::string language;
std::map<std::string, std::string> translation;
bool secondAttempt = false;
QProgressBar* bar = NULL;
fs::path nfzUpOutPath;
fs::path nfzOutPath;
fs::path modHkiOutPath;
fs::path modHki2OutPath;
fs::path upHkiOutPath;
fs::path upHki2OutPath;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
language = "en";
ui->setupUi(this);
std::string steamPath = getSteamPath();
HDPath = getHDPath(steamPath);
outPath = getOutPath(HDPath);
changeLanguage(language);
nfzUpOutPath = outPath / "Games/WololoKingdoms/Player.nfz";
nfzOutPath = outPath / "Voobly Mods/AOC/Data Mods/WololoKingdoms/Player.nfz";
modHkiOutPath = outPath / "Voobly Mods/AOC/Data Mods/WololoKingdoms/player1.hki";
modHki2OutPath = outPath / "Voobly Mods/AOC/Data Mods/WololoKingdoms/player2.hki";
upHkiOutPath = outPath / "Games/WololoKingdoms/player1.hki";
upHki2OutPath = outPath / "Games/WololoKingdoms/player2.hki";
QObject::connect( this->ui->languageChoice, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged), this, [this]() {
switch(this->ui->languageChoice->currentIndex()) {
case 0: language = "br"; break;
case 1: language = "de"; break;
case 2: language = "en"; break;
case 3: language = "es"; break;
case 4: language = "fr"; break;
case 5: language = "it"; break;
case 6: language = "jp"; break;
case 7: language = "ko"; break;
case 8: language = "nl"; break;
case 9: language = "ru"; break;
case 10: language = "zh"; break;
default: language = "en";
}
changeLanguage(language);
} );
//TODO do this in a loop
this->ui->hotkeyTip->setIcon(QIcon("resources/question.png"));
this->ui->hotkeyTip->setIconSize(QSize(16,16));
this->ui->hotkeyTip->setWhatsThis(translation["hotkeyTip"].c_str());
QObject::connect( this->ui->hotkeyTip, &QPushButton::clicked, this, [this]() {
QWhatsThis::showText(this->ui->hotkeyTip->mapToGlobal(QPoint(0,0)),this->ui->hotkeyTip->whatsThis());
} );
if(fs::exists("player1.hki")) {
this->ui->hotkeyChoice->setDisabled(true);
this->ui->hotkeyChoice->setItemText(0,translation["customHotkeys"].c_str());
this->ui->hotkeyTip->setDisabled(true);
}
this->ui->tooltipTip->setIcon(QIcon("resources/question.png"));
this->ui->tooltipTip->setIconSize(QSize(16,16));
this->ui->tooltipTip->setWhatsThis(translation["tooltipTip"].c_str());
QObject::connect( this->ui->tooltipTip, &QPushButton::clicked, this, [this]() {
QWhatsThis::showText(this->ui->tooltipTip->mapToGlobal(QPoint(0,0)),this->ui->tooltipTip->whatsThis());
} );
this->ui->exeTip->setIcon(QIcon("resources/question.png"));
this->ui->exeTip->setIconSize(QSize(16,16));
std::string line = translation["exeTip"];
boost::replace_all(line, "<folder>", outPath.string()+"\\age2_x1");
this->ui->exeTip->setWhatsThis(line.c_str());
QObject::connect( this->ui->exeTip, &QPushButton::clicked, this, [this]() {
QWhatsThis::showText(this->ui->exeTip->mapToGlobal(QPoint(0,0)),this->ui->exeTip->whatsThis());
} );
this->ui->modsTip->setIcon(QIcon("resources/question.png"));
this->ui->modsTip->setIconSize(QSize(16,16));
this->ui->modsTip->setWhatsThis(translation["modsTip"].c_str());
QObject::connect( this->ui->modsTip, &QPushButton::clicked, this, [this]() {
QWhatsThis::showText(this->ui->modsTip->mapToGlobal(QPoint(0,0)),this->ui->modsTip->whatsThis());
} );
this->ui->mapsTip->setIcon(QIcon("resources/question.png"));
this->ui->mapsTip->setIconSize(QSize(16,16));
this->ui->mapsTip->setWhatsThis(translation["mapsTip"].c_str());
QObject::connect( this->ui->mapsTip, &QPushButton::clicked, this, [this]() {
QWhatsThis::showText(this->ui->mapsTip->mapToGlobal(QPoint(0,0)),this->ui->mapsTip->whatsThis());
} );
QObject::connect( this->ui->runButton, &QPushButton::clicked, this, &MainWindow::run);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changeLanguage(std::string language) {
std::string line;
std::ifstream translationFile("resources/"+language+".txt");
while (std::getline(translationFile, line)) {
boost::replace_all(line, "\\n", "\n");
int index = line.find('=');
translation[line.substr(0, index)] = line.substr(index+1, std::string::npos);
}
this->ui->runButton->setText(translation["runButton"].c_str());
this->ui->replaceTooltips->setText(translation["replaceTooltips"].c_str());
this->ui->createExe->setText(translation["createExe"].c_str());
this->ui->useGrid->setText(translation["useGrid"].c_str());
this->ui->usePw->setText(translation["usePw"].c_str());
this->ui->useWalls->setText(translation["useWalls"].c_str());
this->ui->hotkeyChoice->setItemText(1,translation["hotkeys1"].c_str());
this->ui->hotkeyChoice->setItemText(2,translation["hotkeys2"].c_str());
this->ui->hotkeyChoice->setItemText(3,translation["hotkeys3"].c_str());
fs::path vooblyDir = outPath / "Voobly Mods/AOC/Data Mods/WololoKingdoms/";
fs::path nfzOutPath = vooblyDir / "Player.nfz";
if(fs::exists(nfzOutPath)) {
this->ui->hotkeyChoice->setItemText(0,translation["hotkeys0"].c_str());
} else {
this->ui->hotkeyChoice->setItemText(0,translation["hotkeyChoice"].c_str());
this->ui->runButton->setDisabled(true);
QObject::connect( this->ui->hotkeyChoice, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged), this, [this]{
if (this->ui->hotkeyChoice->currentIndex() != 0)
this->ui->runButton->setDisabled(false);
else
this->ui->runButton->setDisabled(true);
} );
}
if(!fs::exists("resources/"+language+".ini")) {
this->ui->replaceTooltips->setEnabled(false);
this->ui->replaceTooltips->setChecked(false);
} else {
this->ui->replaceTooltips->setEnabled(true);
}
qApp->processEvents();
}
void MainWindow::recCopy(fs::path const &src, fs::path const &dst, bool skip, bool force) {
// recursive copy
//fs::path currentPath(current->path());
if (fs::is_directory(src)) {
if(!fs::exists(dst)) {
fs::create_directories(dst);
}
for (fs::directory_iterator current(src), end;current != end; ++current) {
fs::path currentPath(current->path());
recCopy(currentPath, dst / currentPath.filename(), skip, force);
}
}
else {
if (skip) {
boost::system::error_code ec;
fs::copy_file(src, dst, ec);
} else if (force)
fs::copy_file(src,dst,fs::copy_option::overwrite_if_exists);
else
fs::copy_file(src, dst);
}
}
void MainWindow::indexDrsFiles(fs::path const &src) {
// Index files to be written to the drs
if (fs::is_directory(src)) {
for (fs::directory_iterator current(src), end;current != end; ++current) {
fs::path currentPath(current->path());
indexDrsFiles(currentPath);
}
}
else {
std::string extension = src.extension().string();
if (extension == ".slp") {
int id = atoi(src.stem().string().c_str());
slpFiles[id] = src;
}
else if (extension == ".wav") {
int id = atoi(src.stem().string().c_str());
wavFiles[id] = src;
}
}
}
void MainWindow::indexTerrainFiles(fs::path const &src) {
// Index files to be written to the drs
if (fs::is_directory(src)) {
for (fs::directory_iterator current(src), end;current != end; ++current) {
fs::path currentPath(current->path());
indexTerrainFiles(currentPath);
}
}
else {
if (src.extension().string() == ".slp") {
newTerrainFiles[src.filename().string()] = src;
}
}
}
void MainWindow::convertLanguageFile(std::ifstream *in, std::ofstream *iniOut, genie::LangFile *dllOut, bool generateLangDll, std::map<int, std::string> *langReplacement) {
std::string line;
while (std::getline(*in, line)) {
int spaceIdx = line.find(' ');
std::string number = line.substr(0, spaceIdx);
int nb;
try {
nb = stoi(number);
if (nb == 0xFFFF) {
/*
* this one seems to be used by AOC for dynamically-generated strings
* (like market tributes), maybe it's the maximum the game can read ?
*/
continue;
}
if (nb <= 1000) {
// skip changes to fonts
continue;
}
if (nb >= 20150 && nb <= 20167) {
// skip the old civ descriptions
continue;
}
/*
* Conquerors AI names start at 5800 (5800 = 4660+1140, so offset 1140 in the xml file)
* However, there's only space for 10 civ AI names. We'll shift AI names to 11500+ instead (offset 6840 or 1140+5700)
*/
if (nb >= 5800 && nb < 6000) {
nb += 5700;
number = std::to_string(nb);
}
if (nb >= 106000 && nb < 106160) { //AK&AoR AI names have 10xxxx id, get rid of the 10, then shift
nb -= 100000;
nb += 5700;
number = std::to_string(nb);
}
if (nb >= 120150 && nb <= 120180) { // descriptions of the civs in the expansion
//These civ descriptions can be too long for the tech tree, we'll take out some newlines
if (nb == 120156 || nb == 120155) {
boost::replace_all(line, "civilization \\n\\n", "civilization \\n");
}
if (nb == 120167) {
boost::replace_all(line, "civilization \\n\\n", "civilization \\n");
boost::replace_all(line, "\\n\\n<b>Unique Tech", "\\n<b>Unique Tech");
}
// replace the old descriptions of the civs in the base game
nb -= 100000;
number = std::to_string(nb);
}
}
catch (std::invalid_argument const & e){
continue;
}
if (langReplacement->count(nb)) {
// this string has been changed by one of our patches (modified attributes etc.)
line = (*langReplacement)[nb];
langReplacement->erase(nb);
}
else {
// load the string from the HD edition file
int firstQuoteIdx = spaceIdx;
do {
firstQuoteIdx++;
} while (line[firstQuoteIdx] != '"');
int secondQuoteIdx = firstQuoteIdx;
do {
secondQuoteIdx++;
} while (line[secondQuoteIdx] != '"');
line = line.substr(firstQuoteIdx + 1, secondQuoteIdx - firstQuoteIdx - 1);
}
//convert UTF-8 into ANSI
std::wstring wideLine = strtowstr(line);
std::string outputLine;
//if(language!="zh")
ConvertUnicode2CP(wideLine.c_str(), outputLine, CP_ACP);
//else
// ConvertUnicode2CP(wideLine.c_str(), outputLine, 1386);
*iniOut << number << '=' << outputLine << std::endl;
if (generateLangDll) {
boost::replace_all(outputLine, "·", "\xb7"); // Dll can't handle that character.
boost::replace_all(outputLine, "\\n", "\n"); // the dll file requires actual line feed, not escape sequences
try {
dllOut->setString(nb, outputLine);
}
catch (std::string const & e) {
boost::replace_all(outputLine, "\xb7", "-"); // non-english dll files don't seem to like that character
boost::replace_all(outputLine, "\xae", "R");
dllOut->setString(nb, outputLine);
}
}
}
/*
* Stuff that's in lang replacement but not in the HD files (in this case extended language height box)
*/
for(std::map<int,std::string>::iterator it = langReplacement->begin(); it != langReplacement->end(); it++) {
//convert UTF-8 into ANSI
std::wstring wideLine = strtowstr(it->second);
std::string outputLine;
//if(language!="zh")
ConvertUnicode2CP(wideLine.c_str(), outputLine, CP_ACP);
//else
// ConvertUnicode2CP(wideLine.c_str(), outputLine, 1386);
*iniOut << std::to_string(it->first) << '=' << outputLine << std::endl;
if (generateLangDll) {
boost::replace_all(outputLine, "·", "\xb7"); // Dll can't handle that character.
boost::replace_all(outputLine, "\\n", "\n"); // the dll file requires actual line feed, not escape sequences
try {
dllOut->setString(it->first, outputLine);
}
catch (std::string const & e) {
boost::replace_all(outputLine, "\xb7", "-"); // non-english dll files don't seem to like that character
boost::replace_all(outputLine, "\xae", "R");
dllOut->setString(it->first, outputLine);
}
}
}
/*
* Strings needed for code generation that are not in the regular hd text file
* Only needed offline since regular aoc has this in the normal language dlls.
*/
if (generateLangDll) {
for(std::vector<std::pair<int,std::string>>::iterator it = rmsCodeStrings.begin(); it != rmsCodeStrings.end(); it++) {
dllOut->setString(it->first, it->second);
}
}
}
void MainWindow::makeDrs(std::ofstream *out) {
this->ui->label->setText((translation["working"]+"\n"+translation["workingDrs"]).c_str());
this->ui->label->repaint();
// Exclude Forgotten Empires leftovers
slpFiles.erase(50163); // Forgotten Empires loading screen
slpFiles.erase(50189); // Forgotten Empires main menu
slpFiles.erase(53207); // Forgotten Empires in-game logo
slpFiles.erase(53208); // Forgotten Empires objective window
slpFiles.erase(53209); // ???
const int numberOfTables = 2; // slp and wav
int numberOfSlpFiles = slpFiles.size();
int numberOfWavFiles = wavFiles.size();
int offsetOfFirstFile = sizeof (wololo::DrsHeader) +
sizeof (wololo::DrsTableInfo) * numberOfTables +
sizeof (wololo::DrsFileInfo) * (numberOfSlpFiles + numberOfWavFiles);
int offset = offsetOfFirstFile;
// file infos
std::vector<wololo::DrsFileInfo> slpFileInfos;
std::vector<wololo::DrsFileInfo> wavFileInfos;
for (std::map<int,fs::path>::iterator it = slpFiles.begin(); it != slpFiles.end(); it++) {
wololo::DrsFileInfo slp;
size_t size;
size = fs::file_size(it->second);
slp.file_id = it->first;
slp.file_data_offset = offset;
slp.file_size = size;
offset += size;
slpFileInfos.push_back(slp);
}
bar->setValue(bar->value()+1);bar->repaint(); //60
for (std::map<int,fs::path>::iterator it = wavFiles.begin(); it != wavFiles.end(); it++) {
wololo::DrsFileInfo wav;
size_t size;
size = fs::file_size(it->second);
wav.file_id = it->first;
wav.file_data_offset = offset;
wav.file_size = size;
offset += size;
wavFileInfos.push_back(wav);
}
bar->setValue(bar->value()+1);bar->repaint(); //61
// header infos
wololo::DrsHeader const header = {
{ 'C', 'o', 'p', 'y', 'r',
'i', 'g', 'h', 't', ' ',
'(', 'c', ')', ' ', '1',
'9', '9', '7', ' ', 'E',
'n', 's', 'e', 'm', 'b',
'l', 'e', ' ', 'S', 't',
'u', 'd', 'i', 'o', 's',
'.', '\x1a' }, // copyright
{ '1', '.', '0', '0' }, // version
{ 't', 'r', 'i', 'b', 'e' }, // ftype
numberOfTables, // table_count
offsetOfFirstFile // file_offset
};
// table infos
wololo::DrsTableInfo const slpTableInfo = {
0x20, // file_type, MAGIC
{ 'p', 'l', 's' }, // file_extension, "slp" in reverse
sizeof (wololo::DrsHeader) + sizeof (wololo::DrsFileInfo) * numberOfTables, // file_info_offset
(int) slpFileInfos.size() // num_files
};
wololo::DrsTableInfo const wavTableInfo = {
0x20, // file_type, MAGIC
{ 'v', 'a', 'w' }, // file_extension, "wav" in reverse
(int) (sizeof (wololo::DrsHeader) + sizeof (wololo::DrsFileInfo) * numberOfTables + sizeof (wololo::DrsFileInfo) * slpFileInfos.size()), // file_info_offset
(int) wavFileInfos.size() // num_files
};
bar->setValue(bar->value()+1);bar->repaint(); //62
this->ui->label->setText((translation["working"]+"\n"+translation["workingDrs2"]).c_str());
this->ui->label->repaint();
// now write the actual drs file
// header
out->write(header.copyright, sizeof (wololo::DrsHeader::copyright));
out->write(header.version, sizeof (wololo::DrsHeader::version));
out->write(header.ftype, sizeof (wololo::DrsHeader::ftype));
out->write(reinterpret_cast<const char *>(&header.table_count), sizeof (wololo::DrsHeader::table_count));
out->write(reinterpret_cast<const char *>(&header.file_offset), sizeof (wololo::DrsHeader::file_offset));
// table infos
out->write(reinterpret_cast<const char *>(&slpTableInfo.file_type), sizeof (wololo::DrsTableInfo::file_type));
out->write(slpTableInfo.file_extension, sizeof (wololo::DrsTableInfo::file_extension));
out->write(reinterpret_cast<const char *>(&slpTableInfo.file_info_offset), sizeof (wololo::DrsTableInfo::file_info_offset));
out->write(reinterpret_cast<const char *>(&slpTableInfo.num_files), sizeof (wololo::DrsTableInfo::num_files));
out->write(reinterpret_cast<const char *>(&wavTableInfo.file_type), sizeof (wololo::DrsTableInfo::file_type));
out->write(wavTableInfo.file_extension, sizeof (wololo::DrsTableInfo::file_extension));
out->write(reinterpret_cast<const char *>(&wavTableInfo.file_info_offset), sizeof (wololo::DrsTableInfo::file_info_offset));
out->write(reinterpret_cast<const char *>(&wavTableInfo.num_files), sizeof (wololo::DrsTableInfo::num_files));
bar->setValue(bar->value()+1);bar->repaint(); //63
// file infos
for (std::vector<wololo::DrsFileInfo>::iterator it = slpFileInfos.begin(); it != slpFileInfos.end(); it++) {
out->write(reinterpret_cast<const char *>(&it->file_id), sizeof (wololo::DrsFileInfo::file_id));
out->write(reinterpret_cast<const char *>(&it->file_data_offset), sizeof (wololo::DrsFileInfo::file_data_offset));
out->write(reinterpret_cast<const char *>(&it->file_size), sizeof (wololo::DrsFileInfo::file_size));
}
bar->setValue(bar->value()+1);bar->repaint(); //64
for (std::vector<wololo::DrsFileInfo>::iterator it = wavFileInfos.begin(); it != wavFileInfos.end(); it++) {
out->write(reinterpret_cast<const char *>(&it->file_id), sizeof (wololo::DrsFileInfo::file_id));
out->write(reinterpret_cast<const char *>(&it->file_data_offset), sizeof (wololo::DrsFileInfo::file_data_offset));
out->write(reinterpret_cast<const char *>(&it->file_size), sizeof (wololo::DrsFileInfo::file_size));
}
bar->setValue(bar->value()+1);bar->repaint(); //65
this->ui->label->setText((translation["working"]+"\n"+translation["workingDrs3"]).c_str());
this->ui->label->repaint();
// now write the actual files
for (std::map<int,fs::path>::iterator it = slpFiles.begin(); it != slpFiles.end();it++) {
std::ifstream srcStream = std::ifstream(it->second.string(), std::ios::binary);
*out << srcStream.rdbuf();
}
bar->setValue(bar->value()+1);bar->repaint(); //66
for (std::map<int,fs::path>::iterator it = wavFiles.begin(); it != wavFiles.end(); it++) {
std::ifstream srcStream = std::ifstream(it->second.string(), std::ios::binary);
*out << srcStream.rdbuf();
}
bar->setValue(bar->value()+1);bar->repaint(); //67
}
void MainWindow::copyCivIntroSounds(fs::path inputDir, fs::path outputDir) {
std::string const civs[] = {"italians", "indians", "incas", "magyars", "slavs",
"portuguese", "ethiopians", "malians", "berbers", "burmese", "malay", "vietnamese", "khmer"};
for (size_t i = 0; i < sizeof civs / sizeof (std::string); i++) {
boost::system::error_code ec;
fs::copy_file(inputDir / (civs[i] + ".mp3"), outputDir / (civs[i] + ".mp3"), ec);
}
}
void MainWindow::uglyHudHack(fs::path assetsPath) {
/*
* Shifts the offset between interface files by 10 so there's space for the new civs
*/
int const hudFiles[] = {51130, 51160};
for (size_t baseIndex = 0; baseIndex < sizeof hudFiles / sizeof (int); baseIndex++) {
for (size_t i = 1; i <= 23; i++) {
slpFiles[hudFiles[baseIndex]+i+(baseIndex+1)*10] = assetsPath / (std::to_string(hudFiles[baseIndex]+i) + ".slp");
}
}
/*
* copies the Slav hud files for AK civs, the good way of doing this would be to extract
* the actual AK civs hud files from
* Age2HD\resources\_common\slp\game_b[24-27].slp correctly, but I haven't found a way yet
*/
int const slavHudFiles[] = {51123, 51153, 51183};
for (size_t baseIndex = 0; baseIndex < sizeof slavHudFiles / sizeof (int); baseIndex++) {
for (size_t i = 1; i <= 8; i++) {
slpFiles[slavHudFiles[baseIndex]+i+baseIndex*10] = assetsPath / (std::to_string(slavHudFiles[baseIndex]) + ".slp");
}
}
}
void MainWindow::copyWallFiles(fs::path inputDir) {
/*
* Base IDS 2098 Stone 2110 Fortified 4169 Damaged 4173 Damaged Fortified
* Central European +0, Asian +1, Middle Eastern +2, West European +3
* +8 per damage increase
*
* New Types:
* 5000 American, 7000 Mediterranean, 15000 Eastern European, 16000 Indian, 17000 African, 18000 South East Asian
* Base IDs 124 Stone 126 Fortified 145 Damaged 147 Damaged Fortified
* +4 per damage increase
*/
indexDrsFiles(inputDir);
int conversionTable[] = {3,-15,2,0,3,-18,-5,1,0,1,2,3,0,1,2};
int newBaseSLP = 24000;
for(size_t i = 0; i < sizeof(conversionTable)/sizeof(int); i++) {
int archID = conversionTable[i];
if (archID < 0) {
archID = -archID;
int digits = archID == 5 || archID == 7?124:324;
slpFiles[newBaseSLP+i*1000+digits+200] = inputDir/(std::to_string(archID*1000+digits)+".slp");
slpFiles[newBaseSLP+i*1000+digits+202] = inputDir/(std::to_string(archID*1000+digits+2)+".slp");
for (int j = 0; j <= 10; j+=2)
slpFiles[newBaseSLP+i*1000+digits+221+j] = inputDir/(std::to_string(archID*1000+digits+21+j)+".slp");
} else {
slpFiles[newBaseSLP+i*1000+324] = inputDir/(std::to_string(2098+archID)+".slp");
slpFiles[newBaseSLP+i*1000+326] = inputDir/(std::to_string(2110+archID)+".slp");
for (int j = 0; j <= 20; j+=4)
slpFiles[newBaseSLP+i*1000+345+j] = inputDir/(std::to_string(4169+archID+j)+".slp");
}
}
}
std::string MainWindow::tolower(std::string line) {
std::transform(line.begin(), line.end(), line.begin(), static_cast<int(*)(int)>(std::tolower));
return line;
}
void MainWindow::createMusicPlaylist(std::string inputDir, std::string const outputDir) {
boost::replace_all(inputDir, "/", "\\");
std::ofstream outputFile(outputDir);
for (int i = 1; i <= 23; i++ ) {
outputFile << inputDir << "xmusic" << std::to_string(i) << ".mp3" << std::endl;
}
}
void MainWindow::copyHDMaps(fs::path inputDir, fs::path outputDir, bool replace) {
std::vector<fs::path> mapNames;
for (fs::directory_iterator end, it(inputDir); it != end; it++) {
std::string extension = it->path().extension().string();
if (extension == ".rms") {
mapNames.push_back(it->path());
}
}
bar->setValue(bar->value()+1);bar->repaint(); //13+17
bar->setValue(bar->value()+1);bar->repaint(); //14+18
std::map<std::string,fs::path> terrainOverrides;
std::vector<std::tuple<std::string,std::string,std::string,std::string,std::string,std::string,bool,std::string,std::string>> replacements = {
//<Name,Regex Pattern if needed,replace name,terrain ID, replace terrain ID,slp to replace,upgrade trees?,tree to replace,new tree>
std::make_tuple("DRAGONFOREST","DRAGONFORES(T?)","DRAGONFORES$1","48","21","15029.slp",true,"SNOWPINETREE","DRAGONTREE"),
//std::make_tuple("ACACIA_FOREST","AC(C?)ACIA(_?)FORES(T?)","AC$1ACIA$2FORES$3","50","13","15010.slp",true,"PALMTREE","ACACIA_TREEE"),
std::make_tuple("ACACIA_FOREST","AC(C?)ACIA(_?)FORES(T?)","AC$1ACIA$2FORES$3","50","41","",false,"",""),
std::make_tuple("DLC_RAINFOREST","","DLC_RAINFOREST","56","10","15011.slp",true,"FOREST_TREE","DLC_RAINTREE"),
std::make_tuple("BAOBAB","","BAOBAB","49","16","",false,"",""),
std::make_tuple("DLC_MANGROVESHALLOW","","DLC_MANGROVESHALLOW","54","4","15014.slp",false,"",""),
std::make_tuple("DLC_MANGROVEFOREST","","DLC_MANGROVEFOREST","55","16","",false,"",""),
std::make_tuple("DLC_NEWSHALLOW","","DLC_NEWSHALLOW","59","26","15024.slp",false,"",""),
std::make_tuple("SAVANNAH","","SAVANNAH","41","14","15010.slp",false,"",""),
std::make_tuple("DIRT4","((DLC_)?)DIRT4","$1DIRT4","42","3","15007.slp",false,"",""),
std::make_tuple("MOORLAND","","MOORLAND","44","9","15009.slp",false,"",""),
std::make_tuple("CRACKEDIT","","CRACKEDIT","45","6","15000.slp",false,"",""),
std::make_tuple("QUICKSAND","","QUICKSAND","46","40","15018.slp",false,"",""),
std::make_tuple("BLACK","","BLACK","47","40","15018.slp",false,"",""),
std::make_tuple("DLC_ROCK","","DLC_ROCK","40","40","15018.slp",false,"",""),
std::make_tuple("DLC_BEACH2","","DLC_BEACH2","51","2","15017.slp",false,"",""),
std::make_tuple("DLC_BEACH3","","DLC_BEACH3","52","2","15017.slp",false,"",""),
std::make_tuple("DLC_BEACH4","","DLC_BEACH4","53","2","15017.slp",false,"",""),
std::make_tuple("DLC_DRYROAD","","DLC_DRYROAD","43","25","15019.slp",false,"",""),
std::make_tuple("DLC_WATER4","","DLC_WATER4","57","22","",false,"",""),
std::make_tuple("DLC_WATER5","","DLC_WATER5","58","1","",false,"",""),
std::make_tuple("DLC_DRYROAD","","DLC_DRYROAD","43","25","15019.slp",false,"",""),
std::make_tuple("DLC_JUNGLELEAVES","","DLC_JUNGLELEAVES","62","11","15006.slp",false,"",""),
std::make_tuple("DLC_JUNGLEROAD","","DLC_JUNGLEROAD","62","39","15031.slp",false,"",""),
std::make_tuple("DLC_JUNGLEGRASS","","DLC_JUNGLEGRASS","61","12","15008.slp",false,"","")
};
for (std::vector<fs::path>::iterator it = mapNames.begin(); it != mapNames.end(); it++) {
std::string mapName = it->stem().string()+".rms";
if (mapName.substr(0,3) == "ZR@") {
fs::copy_file(*it,outputDir/mapName,fs::copy_option::overwrite_if_exists);
continue;
}
if(fs::exists(outputDir/it->filename())) {
if(replace)
fs::remove(outputDir/it->filename());
else
continue;
}
if(fs::exists(outputDir/("ZR@"+it->filename().string()))) {
fs::remove(outputDir/("ZR@"+it->filename().string()));
}
std::ifstream input(inputDir.string()+it->filename().string());
std::string str(static_cast<std::stringstream const&>(std::stringstream() << input.rdbuf()).str());
if(str.find("DLC_MANGROVESHALLOW")!=std::string::npos) {
if(str.find("<PLAYER_SETUP>")!=std::string::npos)
str = std::regex_replace(str, std::regex("<PLAYER_SETUP>\\s*(\\r*)\\n"),
"<PLAYER_SETUP>$1\n terrain_state 0 0 0 1$1\n");
else
str = std::regex_replace(str, std::regex("#include_drs\\s+random_map\\.def\\s*(\\r*)\\n"),
"#include_drs random_map.def$1\n<PLAYER_SETUP>$1\n terrain_state 0 0 0 1$1\n");
}
for (std::vector<std::tuple<std::string,std::string,std::string,std::string,std::string,std::string,bool,std::string,std::string>>::iterator repIt = replacements.begin(); repIt != replacements.end(); repIt++) {
std::regex terrainConstDef;
std::regex terrainName;
if(std::get<1>(*repIt)=="") {
terrainConstDef = std::regex("#const\\s+" +std::get<0>(*repIt)+ "\\s+" +std::get<3>(*repIt));
terrainName = std::regex(std::get<0>(*repIt));
} else {
terrainConstDef = std::regex("#const\\s+" +std::get<1>(*repIt)+ "\\s+" +std::get<3>(*repIt));
terrainName = std::regex(std::get<1>(*repIt));
}
if(std::regex_search(str,terrainName)) {
str = std::regex_replace(str,terrainConstDef, "#const "+std::get<2>(*repIt)+" "+std::get<4>(*repIt));
if(std::get<5>(*repIt) != "") {
terrainOverrides[std::get<5>(*repIt)] = newTerrainFiles[std::get<0>(*repIt)+".slp"];
if(std::get<6>(*repIt)) {
if(str.find("<PLAYER_SETUP>")!=std::string::npos)
str = std::regex_replace(str, std::regex("<PLAYER_SETUP>\\s*(\\r*)\\n"),
"<PLAYER_SETUP>$1\n effect_amount GAIA_UPGRADE_UNIT "+std::get<7>(*repIt)+" "+std::get<8>(*repIt)+" 0$1\n");
else
str = std::regex_replace(str, std::regex("#include_drs\\s+random_map\\.def\\s*(\\r*)\\n"),
"#include_drs random_map.def$1\n<PLAYER_SETUP>$1\n effect_amount GAIA_UPGRADE_UNIT "+std::get<7>(*repIt)+" "+std::get<8>(*repIt)+" 0$1\n");
}
}
}
}
if(str.find("DLC_MANGROVESHALLOW")!=std::string::npos) {
terrainOverrides["15004.slp"] = newTerrainFiles["15004.slp"];
terrainOverrides["15005.slp"] = newTerrainFiles["15005.slp"];
terrainOverrides["15021.slp"] = newTerrainFiles["15021.slp"];
terrainOverrides["15022.slp"] = newTerrainFiles["15022.slp"];
terrainOverrides["15023.slp"] = newTerrainFiles["15023.slp"];
}
//str = regex_replace(str, std::regex("#const\\s+BAOBAB\\s+49"), "#const BAOBAB 16");
std::ofstream out(outputDir.string()+"/"+mapName);
out << str;
out.close();
if (mapName.substr(0,3) == "rw_" || mapName.substr(0,3) == "sm_") {
std::string scenarioFile = it->stem().string()+".scx";
terrainOverrides[scenarioFile] = fs::path(inputDir.string()+"/"+scenarioFile);
}
if (terrainOverrides.size() != 0) {
QuaZip zip(QString((outputDir.string()+"/ZR@"+mapName).c_str()));
zip.open(QuaZip::mdAdd, NULL);
terrainOverrides[mapName] = fs::path(outputDir.string()+"/"+mapName);
for(std::map<std::string,fs::path>::iterator files = terrainOverrides.begin(); files != terrainOverrides.end(); files++) {
QuaZipFile outFile(&zip);
QuaZipNewInfo fileInfo(QString(files->first.c_str()));;
fileInfo.uncompressedSize = fs::file_size(files->second);
outFile.open(QIODevice::WriteOnly,fileInfo,NULL,0,0,0,false);
QFile inFile;
inFile.setFileName(files->second.string().c_str());
inFile.open(QIODevice::ReadOnly);
copyData(inFile, outFile);
outFile.close();
inFile.close();
}
zip.close();
fs::remove(fs::path(outputDir.string()+"/"+mapName));
}
terrainOverrides.clear();
}
bar->setValue(bar->value()+1);bar->repaint(); //15+19
}
void MainWindow::transferHdDatElements(genie::DatFile *hdDat, genie::DatFile *aocDat) {
aocDat->Sounds = hdDat->Sounds;
aocDat->GraphicPointers = hdDat->GraphicPointers;
aocDat->Graphics = hdDat->Graphics;
aocDat->Techages = hdDat->Techages;
aocDat->UnitHeaders = hdDat->UnitHeaders;
aocDat->Civs = hdDat->Civs;
aocDat->Researchs = hdDat->Researchs;
aocDat->UnitLines = hdDat->UnitLines;
aocDat->TechTree = hdDat->TechTree;
//Copy Terrains
aocDat->TerrainBlock.TerrainsUsed2 = 42;
aocDat->TerrainsUsed1 = 42;
//terrainSwap(hdDat, aocDat, 41,54,15030); //mangrove terrain
terrainSwap(hdDat, aocDat, 15,55,15012); //mangrove forest
terrainSwap(hdDat, aocDat, 16,49,15025); //baobab forest
terrainSwap(hdDat, aocDat, 41,50,15013); //acacia forest
slpFiles[15012] = newTerrainFiles["DLC_MANGROVEFOREST.slp"];
slpFiles[15013] = newTerrainFiles["ACACIA_FOREST.slp"];
slpFiles[15025] = newTerrainFiles["BAOBAB.slp"];
aocDat->TerrainBlock.Terrains[35].TerrainToDraw = -1;
aocDat->TerrainBlock.Terrains[35].SLP = 15024;
aocDat->TerrainBlock.Terrains[35].Name2 = "g_ice";
//terrainSwap(hdDat, aocDat, 15,45,15000); //cracked sand
}
void MainWindow::patchArchitectures(genie::DatFile *aocDat) {
short buildingIDs[] = {10, 14, 18, 19, 20, 30, 31, 32, 47, 49, 51, 63, 64, 67, 71, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88,
90, 91, 92, 95, 101, 103, 104, 105, 110, 116, 117, 129, 130, 131, 132, 133, 137, 141, 142, 150, 153,
155, 179, 190, 209, 210, 234, 235, 236, 276, 463, 464, 465, 481, 482, 483, 484, 487, 488, 490, 491, 498,
562, 563, 564, 565, 566, 584, 585, 586, 587, 597, 611, 612, 613, 614, 615, 616, 617, 659, 660, 661,
662, 663, 664, 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 806, 807, 808, 1102, 1189};
short unitIDs[] = {17, 21, 420, 442, 527, 528, 529, 532, 539, 545, 691, 1103, 1104};
short civIDs[] = {13,23,7,17,14,31,21,6,11,12,27,1,4,18,9};
short burmese = 30; //These are used for ID reference
for(unsigned int c = 0; c < sizeof(civIDs)/sizeof(short); c++) {
std::map<short,short> replacedGraphics;
//buildings
for(unsigned int b = 0; b < sizeof(buildingIDs)/sizeof(short); b++) {
replaceGraphic(aocDat, &aocDat->Civs[civIDs[c]].Units[buildingIDs[b]].StandingGraphic.first,
aocDat->Civs[burmese].Units[buildingIDs[b]].StandingGraphic.first, c, replacedGraphics);
short oldGraphicID = aocDat->Civs[civIDs[c]].Units[buildingIDs[b]].Building.ConstructionGraphicID;
if(oldGraphicID > 130 && oldGraphicID != 4248) { //exclude standard construction graphics for all civs
replaceGraphic(aocDat, &aocDat->Civs[civIDs[c]].Units[buildingIDs[b]].Building.ConstructionGraphicID,
aocDat->Civs[burmese].Units[buildingIDs[b]].Building.ConstructionGraphicID, c, replacedGraphics);
}
std::vector<genie::unit::DamageGraphic>::iterator compIt = aocDat->Civs[burmese].Units[buildingIDs[b]].DamageGraphics.begin();
for(std::vector<genie::unit::DamageGraphic>::iterator it = aocDat->Civs[civIDs[c]].Units[buildingIDs[b]].DamageGraphics.begin();
it != aocDat->Civs[civIDs[c]].Units[buildingIDs[b]].DamageGraphics.end(); it++) {
replaceGraphic(aocDat, &(it->GraphicID), compIt->GraphicID, c, replacedGraphics);
compIt++;
}
}
//units like ships
for(unsigned int u = 0; u < sizeof(unitIDs)/sizeof(short); u++) {
replaceGraphic(aocDat, &aocDat->Civs[civIDs[c]].Units[unitIDs[u]].StandingGraphic.first, aocDat->Civs[burmese].Units[unitIDs[u]].StandingGraphic.first, c, replacedGraphics);
replaceGraphic(aocDat, &aocDat->Civs[civIDs[c]].Units[unitIDs[u]].DeadFish.WalkingGraphic.first, aocDat->Civs[burmese].Units[unitIDs[u]].DeadFish.WalkingGraphic.first, c, replacedGraphics);
replaceGraphic(aocDat, &aocDat->Civs[civIDs[c]].Units[unitIDs[u]].Type50.AttackGraphic, aocDat->Civs[burmese].Units[unitIDs[u]].Type50.AttackGraphic, c, replacedGraphics);
}
bar->setValue(bar->value()+1);bar->repaint(); //37-52
}
//Let the Berber Mill have 40 frames instead of 8/10, which is close to the african mill with 38 frames
aocDat->Graphics[aocDat->Civs[27].Units[129].StandingGraphic.first].FrameCount = 40;
aocDat->Graphics[aocDat->Civs[27].Units[130].StandingGraphic.first].FrameCount = 40;
aocDat->Graphics[aocDat->Graphics[aocDat->Civs[27].Units[129].StandingGraphic.first].Deltas[0].GraphicID].FrameCount = 40;
aocDat->Graphics[aocDat->Graphics[aocDat->Civs[27].Units[130].StandingGraphic.first].Deltas[1].GraphicID].FrameCount = 40;
//Fix the missionary converting frames while we're at it
aocDat->Graphics[6616].FrameCount = 14;
//Separate Monks and DA buildings into 4 major regions (Europe, Asian, Southern, American)
std::vector<std::vector<short>> civGroups = { {5,6,12,18,28,29,30,31},
{7,8,9,10,20,25,26,27},
{15,16,21}};
std::map<int,int> slps = {{2683,0},{376,2},{4518,1},{2223,3},{3482,4},{3483,5},{4172,6},{4330,7},{889,10},{4612,16},{891,17},{4611,15},{3596,12},
{4610,14},{3594,11},{3595,13},{774,131},{779,134},{433,10},{768,130},{433,10},{771,132},{775,133},{3831,138},{3827,137}};
short cgBuildingIDs[] = {12, 68, 70, 109, 598, 618, 619, 620};
short cgUnitIDs[] = {125,134,286};
for(int i = 0; i < 3; i++) {
short monkHealingGraphic;
if (i != 2) {
int newSLP = 60000+10000*i+135;
genie::Graphic newGraphic = aocDat->Graphics[1597];
monkHealingGraphic = aocDat->Graphics.size();
newGraphic.ID = monkHealingGraphic;
newGraphic.SLP = newSLP;
aocDat->Graphics.push_back(newGraphic);
aocDat->GraphicPointers.push_back(1);
slpFiles[newSLP] = HDPath/("resources/_common/drs/graphics/776.slp");
}
for(unsigned int cg = 0; cg < civGroups[i].size(); cg++) {
std::map<short,short> replacedGraphics;
for(unsigned int b = 0; b < sizeof(cgBuildingIDs)/sizeof(short); b++) {
replaceGraphic(aocDat, &aocDat->Civs[civGroups[i][cg]].Units[cgBuildingIDs[b]].StandingGraphic.first, -1, i, replacedGraphics, slps);
for(std::vector<genie::unit::DamageGraphic>::iterator it = aocDat->Civs[civGroups[i][cg]].Units[cgBuildingIDs[b]].DamageGraphics.begin();
it != aocDat->Civs[civGroups[i][cg]].Units[cgBuildingIDs[b]].DamageGraphics.end(); it++) {
replaceGraphic(aocDat, &(it->GraphicID), -1, i, replacedGraphics, slps);
}
}
//units like ships
for(unsigned int u = 0; u < sizeof(cgUnitIDs)/sizeof(short); u++) {
replaceGraphic(aocDat, &aocDat->Civs[civGroups[i][cg]].Units[cgUnitIDs[u]].StandingGraphic.first, -1, i, replacedGraphics, slps);
if (aocDat->Civs[civGroups[i][cg]].Units[cgUnitIDs[u]].DeadFish.WalkingGraphic.first != -1)
replaceGraphic(aocDat, &aocDat->Civs[civGroups[i][cg]].Units[cgUnitIDs[u]].DeadFish.WalkingGraphic.first, -1, i, replacedGraphics, slps);
if (aocDat->Civs[civGroups[i][cg]].Units[cgUnitIDs[u]].Type50.AttackGraphic != -1)
replaceGraphic(aocDat, &aocDat->Civs[civGroups[i][cg]].Units[cgUnitIDs[u]].Type50.AttackGraphic, -1, i, replacedGraphics, slps);
}
//special UP healing slp workaround
if (i != 2) {
for(unsigned int cg = 0; cg < civGroups[i].size(); cg++) {
size_t code = 0x811E0000+monkHealingGraphic;
int ccode = (int) code;
aocDat->Civs[civGroups[i][cg]].Units[125].LanguageDLLHelp = ccode;
if (i == 0) {
aocDat->Civs[civGroups[i][cg]].Units[125].IconID = 218;
aocDat->Civs[civGroups[i][cg]].Units[286].IconID = 218;
} else {
aocDat->Civs[civGroups[i][cg]].Units[125].IconID = 169;
aocDat->Civs[civGroups[i][cg]].Units[286].IconID = 169;
}
}
}
}
bar->setValue(bar->value()+1);bar->repaint(); //52-55
}
}
void MainWindow::replaceGraphic(genie::DatFile *aocDat, short* graphicID, short compareID, short c, std::map<short,short>& replacedGraphics, std::map<int,int> slps) {
if(replacedGraphics[*graphicID] != 0)
*graphicID = replacedGraphics[*graphicID];
else {
std::vector<int> duplicatedGraphics;
short newGraphicID;
if (compareID != -1)
newGraphicID = duplicateGraphic(aocDat, duplicatedGraphics, *graphicID, compareID, c);
else
newGraphicID = duplicateGraphic(aocDat, duplicatedGraphics, *graphicID, compareID, c, slps);
replacedGraphics[*graphicID] = newGraphicID;
*graphicID = newGraphicID;
}
}
bool MainWindow::checkGraphics(genie::DatFile *aocDat, short graphicID, std::vector<int> checkedGraphics) {
//Tests if any of the referenced graphic SLPs are in the right range, AKA civ-dependant
checkedGraphics.push_back(graphicID);
genie::Graphic newGraphic = aocDat->Graphics[graphicID];
if (aocDat->Graphics[graphicID].SLP < 18000 || aocDat->Graphics[graphicID].SLP >= 19000) {
for(std::vector<genie::GraphicDelta>::iterator it = newGraphic.Deltas.begin(); it != newGraphic.Deltas.end(); it++) {
if(it->GraphicID != -1 && std::find(checkedGraphics.begin(), checkedGraphics.end(), it->GraphicID) == checkedGraphics.end()
&& checkGraphics(aocDat, it->GraphicID, checkedGraphics))
return true;
}
return false;
} else
return true;
}
short MainWindow::duplicateGraphic(genie::DatFile *aocDat, std::vector<int> duplicatedGraphics, short graphicID, short compareID, short offset, std::map<int,int> slps) {
if (compareID != -1 && (aocDat->Graphics[compareID].SLP < 18000 || aocDat->Graphics[compareID].SLP >= 19000)) {
std::vector<int> checkedGraphics;
if(!checkGraphics(aocDat, compareID, checkedGraphics))
return graphicID;
}
genie::Graphic newGraphic = aocDat->Graphics[graphicID];
int newBaseSLP = compareID==-1?60000:24000;
short newGraphicID = aocDat->Graphics.size();
int newSLP;
if(compareID==-1) {
if (slps[aocDat->Graphics[graphicID].SLP] == 0 && aocDat->Graphics[graphicID].SLP != 2683)
newSLP = aocDat->Graphics[graphicID].SLP;
else
newSLP = newBaseSLP+10000*offset+slps[aocDat->Graphics[graphicID].SLP];
} else
newSLP = aocDat->Graphics[compareID].SLP - 18000 + newBaseSLP + 1000*offset;
if(newSLP != aocDat->Graphics[graphicID].SLP) {
fs::path src = HDPath/("resources/_common/drs/gamedata_x2/"+std::to_string(newGraphic.SLP)+".slp");
if(fs::exists(src))
slpFiles[newSLP] = src;
else {
src = HDPath/("resources/_common/drs/graphics/"+std::to_string(newGraphic.SLP)+".slp");
if(fs::exists(src))
slpFiles[newSLP] = src;
}
}
duplicatedGraphics.push_back(newGraphic.ID);
newGraphic.ID = newGraphicID;
newGraphic.SLP = newSLP;
aocDat->Graphics.push_back(newGraphic);
aocDat->GraphicPointers.push_back(1);
if (compareID == -1) {
for(std::vector<genie::GraphicDelta>::iterator it = newGraphic.Deltas.begin(); it != newGraphic.Deltas.end(); it++) {
if(it->GraphicID != -1 && std::find(duplicatedGraphics.begin(), duplicatedGraphics.end(), it->GraphicID) == duplicatedGraphics.end())
it->GraphicID = duplicateGraphic(aocDat, duplicatedGraphics, it->GraphicID, -1, offset, slps);
}
aocDat->Graphics.at(newGraphicID) = newGraphic;
} else if(aocDat->Graphics[compareID].Deltas.size() == newGraphic.Deltas.size()) {
/* don't copy graphics files if the amount of deltas is different to the comparison,
* this is usually with damage graphics and different amount of Flames.
*/
std::vector<genie::GraphicDelta>::iterator compIt = aocDat->Graphics[compareID].Deltas.begin();
for(std::vector<genie::GraphicDelta>::iterator it = newGraphic.Deltas.begin(); it != newGraphic.Deltas.end(); it++) {
if(it->GraphicID != -1 && std::find(duplicatedGraphics.begin(), duplicatedGraphics.end(), it->GraphicID) == duplicatedGraphics.end())
it->GraphicID = duplicateGraphic(aocDat, duplicatedGraphics, it->GraphicID, compIt->GraphicID, offset);
compIt++;
}
aocDat->Graphics.at(newGraphicID) = newGraphic;
}
return newGraphicID;
}
void MainWindow::terrainSwap(genie::DatFile *hdDat, genie::DatFile *aocDat, int tNew, int tOld, int slpID) {
aocDat->TerrainBlock.Terrains[tNew] = hdDat->TerrainBlock.Terrains[tOld];
aocDat->TerrainBlock.Terrains[tNew].SLP = slpID;
if (tNew == 41) {
for(size_t j = 0; j < aocDat->TerrainRestrictions.size(); j++) {
aocDat->TerrainRestrictions[j].PassableBuildableDmgMultiplier.push_back(hdDat->TerrainRestrictions[j].PassableBuildableDmgMultiplier[tOld]);
aocDat->TerrainRestrictions[j].TerrainPassGraphics.push_back(hdDat->TerrainRestrictions[j].TerrainPassGraphics[tOld]);
if (j == 4)
aocDat->TerrainRestrictions[j].PassableBuildableDmgMultiplier[tNew] = 1.2;
}
} else {
for(size_t j = 0; j < aocDat->TerrainRestrictions.size(); j++) {
aocDat->TerrainRestrictions[j].PassableBuildableDmgMultiplier[tNew] = hdDat->TerrainRestrictions[j].PassableBuildableDmgMultiplier[tOld];
aocDat->TerrainRestrictions[j].TerrainPassGraphics[tNew] = hdDat->TerrainRestrictions[j].TerrainPassGraphics[tOld];
}
}
}
void MainWindow::hotkeySetup() {
fs::path nfz1Path("resources/Player1.nfz");
fs::path nfzPath = outPath / "player.nfz";
fs::path aocHkiPath("resources/player1.hki");
fs::path customHkiPath("player1.hki");
fs::path hkiPath = HDPath / ("Profiles/player0.hki");
fs::path hkiOutPath = outPath / "player1.hki";
fs::path hki2OutPath = outPath / "player2.hki";
fs::path nfzOutPath = outPath / "Voobly Mods/AOC/Data Mods/WololoKingdoms/Player.nfz";
fs::remove(nfzOutPath);
fs::remove(nfzUpOutPath);
if(fs::exists(nfzPath)) //Copy the Aoc Profile
fs::copy_file(nfzPath, nfzOutPath);
else //otherwise copy the default profile included
fs::copy_file(nfz1Path, nfzOutPath);
if(this->ui->createExe->isChecked()) { //Profiles for UP
if(fs::exists(nfzPath)) //Copy the Aoc Profile