-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataprocess.cpp
More file actions
1320 lines (1246 loc) · 34.3 KB
/
dataprocess.cpp
File metadata and controls
1320 lines (1246 loc) · 34.3 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
#include "StdAfx.h"
#include "dataprocess.h"
#include <fstream>
#include <conio.h>
#include <iostream>
#define TRYVECTOR(SENTENCE) try{SENTENCE}catch(std::out_of_range &exc){cout<<"Vector越界,字符串或TroopID等某种ID无法找到"<<endl;std::cerr << exc.what() << endl<<" Line:" << __LINE__ << endl<< " File:" << __FILE__ << endl<<"下标值:"<<value<<endl; _getch();}
using namespace std;
extern int iUnrecognized;
extern comment tempcomment;
extern vector<string> qStrs;
extern scriptsfile scripts;
extern triggerfile triggers;
extern missiontplfile missions;
extern menufile menus;
extern stringfile str_file;
extern troopfile trp_file;
extern int sel;
//声音解析用对象
extern map<int, string> opcodemap;
extern vector<string> gVars;
extern map<double, string> triggerinterval;
extern map<int, string> token2state;
extern vector<string> default_states;
std::string& trim(std::string &s)
{
if (s.empty())
{
return s;
}
for (size_t i=0;i<s.size();i++) {
if (s[i]=='\"') {
s.insert(i,string("\\"));
i+=2;
}
}
s.erase(0,s.find_first_not_of(" "));
s.erase(s.find_last_not_of(" ") + 1);
return s;
}
vector<string> globalVariable;
void split(std::string& s, std::string delim,std::vector< std::string >& ret)
{
size_t last = 0;
size_t index=s.find(delim,last);
string temp;
ret.clear();
while (index!=std::string::npos)
{
temp=s.substr(last,index-last);
if(!temp.empty())
ret.push_back(temp);
last=index+delim.length();
index=s.find(delim,last);
}
//送入最后一个分割项
if (index-last>0)
{
temp=s.substr(last,index-last);
if(!temp.empty())
ret.push_back(temp);
}
}
void scriptsfile::load(){
ifstream ifs;
script tempscript;
ifs.open("scripts.txt");
if (!ifs)
{
cout<<"错误:打开文件 "<< "scripts.txt" <<" 失败。"<<endl;
cout<<"请把程序放在mod目录下。"<<endl;
_getch();
exit(0);
}
cout<<"正在载入scripts.txt............";
string tempLine;
vector<string> words;
operation tempoperation;
if(getline(ifs,tempLine))
header.push_back(trim(tempLine));
else{
cout<<"scripts.txt格式不正确"<<endl;
exit(0);
}
if(getline(ifs,tempLine))
header.push_back(trim(tempLine));
else{
cout<<"scripts.txt格式不正确"<<endl;
exit(0);
}
int statementlen=0;
while(true){
//获取 储存identify
if(getline(ifs,tempLine)){
trim(tempLine);
if(tempLine.empty())
break;
split(tempLine," ",words);
tempscript.identify=words.front();
words.clear();
}else
break;
//获取 储存op block
if(getline(ifs,tempLine)){
trim(tempLine);
split(tempLine," ",words);
//使用operationlist的方法将数字常量储存到oplist
int i=tempscript.oplist.store(words);
scripts.push_back(tempscript);
words.clear();
tempscript.identify.clear();
tempscript.oplist.operations.clear();
}else
break;
}
cout<<"完成"<<endl;
}
void scriptsfile::analyze(){
for(int s_i=0;s_i<scripts.size();s_i++){
scripts[s_i].analyze();
}
}
void scriptsfile::output()
{
ofstream ofs("reversed\\module_scripts.py");
cout<<"正在反编译module_scripts.py............";
ofs<<"from header_common import *\n";
ofs<<"from header_operations import *\n";
ofs<<"from module_constants import *\n";
ofs<<"from module_constants import *\n";
ofs<<"from header_parties import *\n";
ofs<<"from header_skills import *\n";
ofs<<"from header_mission_templates import *\n";
ofs<<"from header_items import *\n";
ofs<<"from header_triggers import *\n";
ofs<<"from header_terrain_types import *\n";
ofs<<"from header_music import *\n";
ofs<<"from header_map_icons import *\n";
ofs<<"from ID_animations import *\n\n";
ofs<<"from txt2py_constant import *\n\n\n";
//scripts开始
ofs << "scripts = ["<<endl;
for(int s_i=0;s_i<scripts.size();s_i++){
ofs<<"#**************************************************"<<endl;
ofs<<"#* New Script Begin *"<<endl;
ofs<<"#**************************************************"<<endl;
if(scripts[s_i].identify=="game_receive_url_response")
cout<<"";
ofs<<" (\""<<scripts[s_i].identify<<"\",";
scripts[s_i].oplist.output(ofs);
ofs<<"),"<<endl;
}
//scripts结束
ofs<<"]"<<endl;
cout<<"完成"<<endl;
}
void triggerfile::load()
{
ifstream ifs;
ifs.open("triggers.txt");
if (!ifs)
{
cout<<"错误:打开文件 "<< "triggers.txt" <<" 失败。"<<endl;
cout<<"请把程序放在mod目录下。"<<endl;
_getch();
exit(0);
}
cout<<"正在载入triggers.txt............";
string tempLine;
vector<string> words;
if(getline(ifs,tempLine))
header.push_back(trim(tempLine));
else{
cout<<"triggers.txt格式不正确"<<endl;
exit(0);
}
if(getline(ifs,tempLine))
header.push_back(trim(tempLine));
else{
cout<<"triggers.txt格式不正确"<<endl;
exit(0);
}
while(getline(ifs,tempLine)){
trigger temptrigger;
trim(tempLine);
if(tempLine.empty())
continue;
split(tempLine," ",words);
temptrigger.store(words);
triggers.push_back(temptrigger);
}
cout<<"完成"<<endl;
}
void triggerfile::output()
{
ofstream ofs("reversed\\module_triggers.py");
cout<<"正在反编译module_triggers.py............";
ofs<<"from header_common import *\n";
ofs<<"from header_operations import *\n";
ofs<<"from header_parties import *\n";
ofs<<"from header_items import *\n";
ofs<<"from header_skills import *\n";
ofs<<"from header_triggers import *\n";
ofs<<"from header_troops import *\n";
ofs<<"from module_constants import *\n\n";
ofs<<"from txt2py_constant import *\n\n\n";
ofs<<"triggers = ["<<endl;
for(int t_i=0;t_i<triggers.size();t_i++){
ofs<<"#**************************************************"<<endl;
ofs<<"#* New Trigger Begin *"<<endl;
ofs<<"#**************************************************"<<endl;
triggers[t_i].output(ofs);
}
ofs<<"]";
cout<<"完成"<<endl;
}
void triggerfile::analyze()
{
for(int t_i=0;t_i<triggers.size();t_i++){
triggers[t_i].analyze();
}
}
int operationlist::store( vector<string> words)
{
int sentenceslen=0;
oplen=atoi(words.at(0).c_str());
int curop=0;
operation tempoperation;
int opcodeindex;
int nextoplistindex;
if(oplen==0){
operations.push_back(tempoperation);
return 1;
}
for(opcodeindex=1;opcodeindex<words.size();opcodeindex+=(sentenceslen+2)){
sentenceslen=atoi(words.at(opcodeindex+1).c_str());
tempoperation.sentences.push_back(words.at(opcodeindex));
for(int sentenceoffset=0;sentenceoffset<sentenceslen;sentenceoffset++){
tempoperation.sentences.push_back(words.at(opcodeindex+2+sentenceoffset));
}
operations.push_back(tempoperation);
curop++;
tempoperation.sentences.clear();
if(curop==oplen)
break;
}
nextoplistindex=(opcodeindex+sentenceslen+2);
return nextoplistindex;
}
//输出一个代码块
void operationlist::output(ofstream &ofs)
{
int curdepth=0;
int nextdepth=0;
//oplist开始
ofs<<endl<<"\t[";
if(oplen!=0){
ofs<<endl;
for(int op_i=0;op_i<operations.size();op_i++){
//sentences开始
if(operations[op_i].sentences[0]=="try_begin"||operations[op_i].sentences[0]=="try_for_range"||operations[op_i].sentences[0]=="try_for_range_backwards"||operations[op_i].sentences[0]=="try_for_parties"||operations[op_i].sentences[0]=="try_for_agents"){
nextdepth++;
}else if(operations[op_i].sentences[0]=="else_try"){
curdepth--;
}else if(operations[op_i].sentences[0]=="try_end"){
curdepth--;
nextdepth--;
}
for(int i=0;i<curdepth;i++)
ofs<<"\t";
ofs<<"\t\t(";
for(int sentence_i=0;sentence_i<operations[op_i].sentences.size();sentence_i++){
ofs<<operations[op_i].sentences[sentence_i];
if(sentence_i<operations[op_i].sentences.size()-1)
ofs<<",";
}
ofs<<"),";
ofs<<endl;
curdepth=nextdepth;
}
ofs<<"\t";
}
//oplist结束
ofs<<"]";
}
void operationlist::analyze()
{
for(int op_i=0;op_i<oplen;op_i++){
operations[op_i].analyze();
}
}
void missiontplfile::load()
{
ifstream ifs("mission_templates.txt");
group tempgroup;
if (!ifs)
{
cout<<"错误:打开文件 "<< "mission_templates.txt" <<" 失败。"<<endl;
cout<<"请把程序放在mod目录下。"<<endl;
_getch();
exit(0);
}
cout<<"正在载入mission_templates.txt............";
string tempLine;
if(getline(ifs,tempLine))
header.push_back(trim(tempLine));
else{
cout<<"mission_templates.txt格式不正确"<<endl;
exit(0);
}
if(getline(ifs,tempLine))
header.push_back(trim(tempLine));
else{
cout<<"mission_templates.txt格式不正确"<<endl;
exit(0);
}
vector<string> words;
int i=0;
while(true){
missiontpl tempmission;
if(!getline(ifs,tempLine))
break;
trim(tempLine);
if(tempLine.empty()||tempLine.find_first_of("mst_")!=0)
continue;
split(tempLine," ",words);
tempmission.id=words.at(0);
if(tempmission.id=="mst_camera_test")
cout<<"";
tempmission.name=words.at(1);
tempmission.flag=words.at(2);
tempmission.type=words.at(3);
words.clear();
if(!getline(ifs,tempLine)){
cout<<"error in loading mission_templates.txt unexpected ending, there should be a line."<<endl;
exit(0);
}
trim(tempLine);
split(tempLine," ",words);
tempmission.desc=words.at(0);
words.clear();
getline(ifs,tempLine);
if(!getline(ifs,tempLine)){
cout<<"error in loading mission_templates.txt unexpected ending, there should be a line."<<endl;
exit(0);
}
trim(tempLine);
split(tempLine," ",words);
tempmission.grouplen=words.at(0);
words.erase(words.begin());
//push group
for(int group_i=0;group_i<atoi(tempmission.grouplen.c_str());group_i++){
tempgroup.entryno=words.at(0);
tempgroup.spawnflag=words.at(1);
tempgroup.alterflag=words.at(2);
tempgroup.aiflag=words.at(3);
tempgroup.numspawn=words.at(4);
for(int item_i=6;item_i<words.size();item_i++){
tempgroup.items.push_back(words.at(item_i));
}
tempmission.groups.push_back(tempgroup);
tempgroup.items.clear();
words.clear();
if(!getline(ifs,tempLine)){
cout<<"error in loading mission_templates.txt unexpected ending, there should be a line."<<endl;
exit(0);
}
trim(tempLine);
if(group_i==atoi(tempmission.grouplen.c_str())-1)
break;
split(tempLine," ",words);
}
//push triggers
int trignum=atoi(tempLine.c_str());
if(tempmission.grouplen=="0")
trignum=atoi(words[0].c_str());
for(int t_i=0;t_i<trignum;t_i++){
trigger temptrigger;
if(!getline(ifs,tempLine)||(trim(tempLine)=="")){
cout << endl<< " ----txt修改错误:trigger number有误 已忽略" << endl;
break;
}
//cout << i++ << endl;
split(tempLine," ",words);
temptrigger.store(words);
tempmission.triggerlist.push_back(temptrigger);
words.clear();
}
missiontpls.push_back(tempmission);
}
cout<<"完成"<<endl;
}
void missiontplfile::output()
{
ofstream ofs("reversed\\module_mission_templates.py");
cout<<"正在反编译module_mission_templates.py............";
ofs<<"from header_common import *\n";
ofs<<"from header_operations import *\n";
ofs<<"from header_mission_templates import *\n";
ofs<<"from header_animations import *\n";
ofs<<"from header_sounds import *\n";
ofs<<"from header_music import *\n";
ofs<<"from header_items import *\n";
ofs<<"from module_constants import *\n\n";
ofs<<"from txt2py_constant import *\n\n\n";
ofs<<"mission_templates = ["<<endl;
for(int m_i=0;m_i<missiontpls.size();m_i++){
ofs<<"#**************************************************"<<endl;
ofs<<"#* New Mission Templates Begin *"<<endl;
ofs<<"#**************************************************"<<endl;
//一个任务模板开始
ofs<<"("<<endl;
ofs<<"\""<<missiontpls[m_i].name<<"\","<<missiontpls[m_i].flag<<","<<missiontpls[m_i].type<<","<<endl;
ofs<<"\""<<missiontpls[m_i].desc<<"\","<<endl<<" [";
//输出groups
for(int g_i=0;g_i<missiontpls[m_i].groups.size();g_i++){
ofs<<"("<<missiontpls[m_i].groups[g_i].entryno<<","<<missiontpls[m_i].groups[g_i].spawnflag<<","\
<<missiontpls[m_i].groups[g_i].alterflag<<","<<missiontpls[m_i].groups[g_i].aiflag<<","<<\
missiontpls[m_i].groups[g_i].numspawn<<",";
//输出list of equipments
ofs<<"[";
for(int e_i=0;e_i<missiontpls[m_i].groups[g_i].items.size();e_i++){
ofs<<missiontpls[m_i].groups[g_i].items[e_i]<<",";
}
ofs<<"]";
//输出group结尾
ofs<<"),"<<endl<<" ";
}
ofs<<"],"<<endl;
//输出triggerlist
ofs<<" ["<<endl;
for(int t_i=0;t_i<missiontpls[m_i].triggerlist.size();t_i++){
missiontpls[m_i].triggerlist[t_i].output(ofs);
}
ofs<<" ]"<<endl; //triggerlist结尾
ofs<<" ),"<<endl;//missionstpl结尾
}
ofs<<"]";
cout<<"完成"<<endl;
}
void missiontplfile::analyze()
{
for(int m_i=0;m_i<missiontpls.size();m_i++){
missiontpls[m_i].analyze();
}
}
void trigger::store( vector<string> words )
{
operationlist tempconditions;
operationlist tempconsequences;
int condtindex;
int consqindex;
checkinterval=words.at(0);
delayinterval=words.at(1);
rearminterval=words.at(2);
condtindex=3;
if(words.size()>condtindex){
vector<string> tpcondtwords;
vector<string> tpconsqwords;
tpcondtwords.insert(tpcondtwords.end(),words.begin()+condtindex,words.end());
consqindex=condtindex+conditionsblock.store(tpcondtwords);
if(words.size()>consqindex){
tpconsqwords.insert(tpconsqwords.end(),words.begin()+consqindex,words.end());
consequencesblock.store(tpconsqwords);
}
}
}
void trigger::output( ofstream& ofs )
{
ofs<<"("<<checkinterval<<","<<delayinterval<<","<<rearminterval<<",";
conditionsblock.output(ofs);
ofs<<",";
consequencesblock.output(ofs);
ofs<<"),"<<endl;
}
void trigger::analyze()
{
//interval的解析
string str;
str = triggerinterval[atof(checkinterval.c_str())];
if (!str.empty())
checkinterval = str;
str = triggerinterval[atof(delayinterval.c_str())];
if (!str.empty())
delayinterval = str;
str = triggerinterval[atof(rearminterval.c_str())];
if (!str.empty())
rearminterval = str;
//script块的解析
conditionsblock.analyze();
consequencesblock.analyze();
}
void operation::analyze()
{
string sopcode;
__int64 key;
__int64 orinkey;
char buffer[64];
string opcode;
for(int s_i=0;s_i<sentences.size();s_i++){
//处理opcode
if(s_i==0){
key=_atoi64(sentences[0].c_str());
if((key&0x80000000)==0x80000000){
sopcode="neg|";
}
if((key&0x40000000)==0x40000000){
sopcode=sopcode+"this_or_next|";
}
orinkey=key;
key=key&0x3FFFFFFF;
opcode=opcodemap[key&~0x40000000];
sopcode=sopcode+opcodemap[key&~0x40000000];
if(opcode.empty()){
cout<<"ERROR: 未定义的OPCODE! opcode:"<<orinkey;
sopcode=_i64toa(orinkey,buffer,10);
}
sentences[0]=sopcode;
}else{
__int64 i64sentence;
__int64 mask;
__int64 value;
string snewsentence;
i64sentence=_atoi64(sentences[s_i].c_str());
mask=i64sentence>>56;
if(i64sentence<0){
snewsentence=_i64toa(i64sentence,buffer,10);
continue;
//处理其他
}else{
value=i64sentence<<8;
value=value>>8;
#pragma region cases
switch(mask){
//no tag
case 0:
snewsentence=_i64toa(i64sentence,buffer,10);
break;
//register
case 1:
snewsentence=string("reg")+_i64toa(value,buffer,10);
break;
//global variable
case 2:
snewsentence=string("VAR+")+_i64toa(value,buffer,10);
break;
//string
case 3:
snewsentence=string("\"str_")+str_file.strs.at(value).id+"\"";
//snewsentence=string("STRING+")+_i64toa(value,buffer,10);
break;
//item
case 4:
snewsentence=string("ITEM+")+_i64toa(value,buffer,10);
break;
//troop
case 5:
if (sel == 1){
TRYVECTOR(snewsentence = string("\"trp_") + trp_file.troops.at(value).id + "\"";)
}
else{
snewsentence = string("TROOP+") + _i64toa(value, buffer, 10);
}
break;
//faction
case 6:
snewsentence=string("FACTION+")+_i64toa(value,buffer,10);
break;
//quest
case 7:
snewsentence=string("QUEST+")+_i64toa(value,buffer,10);
break;
//party_tpl
case 8:
snewsentence=string("PARTY_TPL+")+_i64toa(value,buffer,10);
break;
//party
case 9:
snewsentence=string("PARTY+")+_i64toa(value,buffer,10);
break;
//scene
case 10:
snewsentence=string("SCENE+")+_i64toa(value,buffer,10);
break;
//mission_tpl
case 11:
TRYVECTOR(snewsentence=string("\"mt_")+missions.missiontpls.at(value).name+"\"";)
break;
//menu
case 12:
TRYVECTOR(snewsentence="\"mnu_"+menus.menus.at(value).id+"\"";)
break;
//script
case 13:
TRYVECTOR(snewsentence=string("\"script_")+scripts.scripts.at(value).identify+"\"";)
break;
//particle_sys
case 14:
snewsentence=string("PARTICLE_SYS+")+_i64toa(value,buffer,10);
break;
//scene_prop
case 15:
snewsentence=string("SCENE_PROP+")+_i64toa(value,buffer,10);
break;
//sound
case 16:
snewsentence=string("SOUND+")+_i64toa(value,buffer,10);
break;
//local
case 17:
snewsentence=string("\":local_")+_i64toa(value,buffer,10)+"\"";
break;
//map_icon
case 18:
snewsentence=string("MICON+")+_i64toa(value,buffer,10);
break;
//skill
case 19:
snewsentence=string("SKILL+")+_i64toa(value,buffer,10);
break;
//mesh
case 20:
snewsentence=string("MESH+")+_i64toa(value,buffer,10);
break;
//presentation
case 21:
snewsentence=string("PRESENTATION+")+_i64toa(value,buffer,10);
break;
//quick_string
case 22:
snewsentence=string("QSTR+")+_i64toa(value,buffer,10);
break;
//track
case 23:
snewsentence=string("MUSIC+")+_i64toa(value,buffer,10);
break;
//table au
case 24:
snewsentence=string("TABLEAU+")+_i64toa(value,buffer,10);
break;
//animation
case 25:
snewsentence=string("ACTION+")+_i64toa(value,buffer,10);
break;
case 26:
snewsentence=string("END_UNRECOGNIZED+")+_i64toa(value,buffer,10);
break;
//如果无法解析
default:
snewsentence=_i64toa(i64sentence,buffer,10);
//tempsentence.append("(Unrecognized Tag");
//rawsentence="UNRECOGNIZED+"+string(_i64toa(value,mystring,10));
iUnrecognized++;
}
#pragma endregion 一堆的解析
}
sentences[s_i]=snewsentence;
}
}
}
void script::analyze()
{
oplist.analyze();
}
void comment::add( string str )
{
newcomment.append(str);
}
string comment::getstr()
{
if(newcomment=="\t\t#")
return "";
if(newcomment!=oldcomment){
oldcomment=newcomment;
string temp=newcomment;
newcomment="\t\t#";
return temp;
}
}
void comment::init()
{
newcomment="\t\t#";
}
void missiontpl::analyze()
{
for(int t_i=0;t_i<triggerlist.size();t_i++){
triggerlist[t_i].analyze();
}
}
int findstr(vector<string> vs, string s){
for each (string ts in vs)
{
if (ts == s){
return 1;
}
}
return 0;
}
void dialogfile::load()
{
ifstream ifs("conversation.txt");
string tempLine;
if (!ifs)
{
cout<<"错误:打开文件 "<< "conversation.txt" <<" 失败。"<<endl;
cout<<"请把程序放在mod目录下。"<<endl;
_getch();
exit(0);
}
cout<<"正在载入conversation.txt............";
if(getline(ifs,tempLine))
header.push_back(trim(tempLine));
else{
cout<<"conversation.txt格式不正确"<<endl;
exit(0);
}
if(getline(ifs,tempLine))
header.push_back(trim(tempLine));
else{
cout<<"conversation.txt格式不正确"<<endl;
exit(0);
}
//
vector<string> v_state;
while(getline(ifs,tempLine)){
trim(tempLine);
if(tempLine.empty())
continue;
dialog tempdialog;
vector<string> words;
split(tempLine," ",words);
//触发条件
tempdialog.partner=words[1];
//input token
tempdialog.i_token = words[2];
//条件块开始
int nextindex=3;
if(words.size()>nextindex){
vector<string> condtwords;
condtwords.insert(condtwords.end(),words.begin()+nextindex,words.end());
nextindex=nextindex+tempdialog.conditions.store(condtwords);
}
//对话文本
tempdialog.dlgtext=words[nextindex];
//output token
tempdialog.o_token = words[nextindex + 1];
//token读取完 将存入map 保持唯一性
vector<string> words2;
static int icount = 0;
string tempstr1="illegal_txt_defined_state";
string tempstr2 = "illegal_txt_defined_state";
char buffer1[16] = { 0 };
int ok;
ok = atoi(tempdialog.o_token.c_str());
char buffer2[16] = { 0 };
if (words[0].find_first_of(":") != string::npos){
if (words[0].find_first_of("dlga_") == 0)
words[0].erase(0, 5);
split(words[0], ":", words2);
if (token2state.count(atoi(tempdialog.i_token.c_str())) == 0){//key不存在,判断state是否已经存在
int suffix=1;
char buffer3[16];
string twords2;
twords2 = words2[0];
int i_conflicted = 0;
while (findstr(v_state, twords2)){
sprintf(buffer3, "_%d", suffix);
twords2=words2[0] + buffer3;
suffix++;
i_conflicted = 1;
}
if (i_conflicted){
cout << "发现重名的state:" << words2[0] << " 已经重命名state 注意汉化修正" << endl;
i_conflicted = 0;
}
words2[0] = twords2;
//token不存在则插入
token2state.insert(make_pair(atoi(tempdialog.i_token.c_str()), words2[0]));
v_state.push_back(words2[0]);//插入完记录插入的state
}
if (token2state.count(atoi(tempdialog.o_token.c_str())) == 0){//token不存在,判断state是否一样
int suffix = 1;
char buffer3[16];
string twords2;
twords2 = words2[1];
int i_conflicted = 0;
while (findstr(v_state, twords2)&&!findstr(default_states, twords2)){
sprintf(buffer3, "_%d", suffix);
twords2 = words2[1] + buffer3;
suffix++;
i_conflicted = 1;
}
if (i_conflicted){
cout << "发现重名的state:" << words2[1] << " 已经重命名state 注意汉化修正" << endl;
}
words2[1] = twords2;
//token不存在则插入
token2state.insert(make_pair(atoi(tempdialog.o_token.c_str()), words2[1]));
v_state.push_back(words2[1]);//插入完记录插入时的state
}
}
else{//autoid不标准,没办法分出inputstate和outputstate则自定义state,自定义state就不用判断重复问题了
_itoa(icount++, buffer1, 10);
tempstr1.append(buffer1);
token2state.insert(make_pair(atoi(tempdialog.i_token.c_str()), tempstr1));
_itoa(icount++, buffer2, 10);
tempstr2.append(buffer2);
token2state.insert(make_pair(atoi(tempdialog.o_token.c_str()), tempstr2));
}
//结果块开始
vector<string> consqwords;
consqwords.insert(consqwords.end(),words.begin()+nextindex+2,words.end());
nextindex=nextindex+2+tempdialog.consequences.store(consqwords);
tempdialog.voiceover=words[nextindex];
if(tempdialog.voiceover!="NO_VOICEOVER")
cout<<"(⊙o⊙)…"<<endl;
dialogs.push_back(tempdialog);
}
cout<<"完成"<<endl;
}
void dialogfile::output()
{
ofstream ofs("reversed\\module_dialogs.py");
cout<<"正在反编译module_dialogs.py............";
ofs<<"from header_common import *\n";
ofs<<"from header_dialogs import *\n";
ofs<<"from header_operations import *\n";
ofs<<"from header_parties import *\n";
ofs<<"from header_item_modifiers import *\n";
ofs<<"from header_skills import *\n";
ofs<<"from header_triggers import *\n";
ofs<<"from ID_troops import *\n";
ofs<<"from ID_party_templates import *\n\n";
ofs<<"from txt2py_constant import *\n\n\n";
ofs<<"dialogs = ["<<endl;
for(int d_i=0;d_i<dialogs.size();d_i++){
ofs<<"#**************************************************"<<endl;
ofs<<"#* New Dialog Begin *"<<endl;
ofs<<"#**************************************************"<<endl;
dialogs[d_i].output(ofs);
ofs<<","<<endl;
}
ofs<<"]"<<endl;
cout<<"完成"<<endl;
}
void dialogfile::analyze()
{
for(int d_i=0;d_i<dialogs.size();d_i++){
dialogs[d_i].analyze();
}
}
void dialog::output( ofstream& ofs )
{
ofs << "[" << partner << ",\"" << token2state[atoi(i_token.c_str())] << "\",";
conditions.output(ofs);
ofs<<","<<endl<<" \"";
ofs<<dlgtext<<"\",";
if (!token2state[atoi(o_token.c_str())].empty()){
ofs << "\"" << token2state[atoi(o_token.c_str())] << "\"";
ofs<<",";
}
else{
cout << "ERROR: 发现没有output token --"<<partner<<" "<<i_token << endl;
}
consequences.output(ofs);
if(voiceover!="NO_VOICEOVER")
ofs<<voiceover;
ofs<<"]";
}
void dialog::analyze()
{
__int64 ipartner=_atoi64(partner.c_str());
string snewparter="";
__int64 trpid;
__int64 othertrdid;
char buffer[64];
if((ipartner&0x00020000)==0x00020000)
snewparter+="party_tpl|";
if((trpid=(ipartner&0x00000fff))==0x00000fff)
snewparter+="anyone|";
else
snewparter+=string(_itoa(trpid,buffer,10))+"|";
if((ipartner&0x00001000)==0x00001000)
snewparter+="repeat_for_factions|";
if((ipartner&0x00002000)==0x00002000)
snewparter+="repeat_for_parties|";
if((ipartner&0x00003000)==0x00003000)
snewparter+="repeat_for_troops|";
if((ipartner&0x00004000)==0x00004000)
snewparter+="repeat_for_100|" ;
if((ipartner&0x00005000)==0x00005000)
snewparter+="repeat_for_1000|";
if((ipartner&0x00010000)==0x00010000)
snewparter+="plyr|";
if((ipartner&0x00040000)==0x00040000)
snewparter+="auto_proceed|";
if((ipartner&0x00080000)==0x00080000)
snewparter+="multi_line|";
if((othertrdid=ipartner&4293918720)!=0){
othertrdid=othertrdid>>20;
snewparter=snewparter+string("other(")+_i64toa(othertrdid,buffer,10)+")";
}
if(snewparter.find_last_of("|")==(snewparter.length()-1))
snewparter.erase(snewparter.length()-1);
partner=snewparter;
conditions.analyze();
consequences.analyze();
}
void menufile::load()
{
ifstream ifs("menus.txt");
string tempLine;
if (!ifs)
{
cout<<"错误:打开文件 "<< "conversation.txt" <<" 失败。"<<endl;
cout<<"请把程序放在mod目录下。"<<endl;
_getch();
exit(0);
}
cout<<"正在载入menus.txt............";
getline(ifs,tempLine);
trim(tempLine);
header.push_back(tempLine);
getline(ifs,tempLine);
trim(tempLine);
header.push_back(tempLine);
while(getline(ifs,tempLine)){
menu tempmenu;
vector<string> words;
trim(tempLine);
if (tempLine.empty()){ //父menu行不能为空
cout << "上级menu不存在,不可预料的空行" << endl;
break;
}
split(tempLine," ",words);
words[0].erase(0,5);
tempmenu.id=words[0];
tempmenu.flags=words[1];
tempmenu.text=words[2];
tempmenu.meshname=words[3];
vector<string> vsopblock;
int isublen=0;
vsopblock.insert(vsopblock.end(),words.begin()+4,words.end());
isublen=4+tempmenu.opblock.store(vsopblock);
tempmenu.optslen=words[isublen];
getline(ifs,tempLine);