forked from alphazolam/RE_RSZ
-
Notifications
You must be signed in to change notification settings - Fork 4
/
RE_RSZ.bt
6805 lines (6214 loc) · 300 KB
/
RE_RSZ.bt
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
//------------------------------------------------
//--- 010 Editor v9.0.2 Binary Template
//
// File: RE_RSZ.bt
// Authors: alphaZomega
// Thanks To: Praydog, Darkness, Dtlnor
// Version: 0.8
// Purpose: Parsing RE Engine RSZ data
// Category: RE Engine
// File Mask: *.user.2;*.pfb.*;*.scn.*;*.rcol.*;*.bhvt.*;*.motfsm2.*;*.fsmv2.*;*.fchar.*
// ID Bytes:
// History: March 30, 2023
// Note: It is recommended to use this template with 010 Editor v9.0.2 or v10.0.2, to avoid crashes
//------------------------------------------------
// Option: //Effect:
local string RSZVersion <hidden=true> = "MHRise"; //change between RE2, RE3, RE8, DMC5 or MHRise
local int RTVersion <hidden=true> = FALSE; //Use Ray-Tracing Update file formats for RE7, RE2R and RE3R (subject to AutoDetectGame)
local int Nesting <hidden=true> = TRUE; //Attempt to nest class instances inside eachother
local int ShowAlignment <hidden=true> = FALSE; //Show metadata for each variable
local int ShowChildRSZs <hidden=true> = TRUE; //Show all RSZs one after another, non-nested. Disabling hides nested RSZHeaders
local int UseSpacers <hidden=true> = TRUE; //Show blank rows between some structs
local int AutoDetectGame <hidden=true> = TRUE; //Automatically detect RSZVersion based on the name + ext of the file being viewed
local int RedetectBHVT <hidden=true> = TRUE; //Will automatically redetect the next BHVT node if there is a problem
local int HideRawData <hidden=true> = FALSE; //Hides RawData struct
local int HideRawNodes <hidden=true> = TRUE; //Hides RawNodes struct
local int SortRequestSets <hidden=true> = TRUE; //Sorts RCOL RequestSets by their IDs
local int ExposeUserDatas <hidden=true> = TRUE; //Makes RSZFiles that contain embedded userDatas start after the Userdatas, for ctrl+J jump
local int SeekByGameObject <hidden=true> = FALSE; //Will automatically seek between detected GameObjects to fix reading errors
local int ReadNodeFullNames <hidden=true> = TRUE; //Reads FSM Node names with the names of all their parents (may be taxing)
local int ShowEnum <hidden=true> = TRUE; //Show enum to increase readibility
//Path to Noesis.exe
local wstring NoesisPath <hidden=true> = "C:\\Program Files\\noesis\\Noesis.exe";
//Game //Extracted Path
local wstring DMC5Path <hidden=true> = "F:\\modmanager\\REtool\\DMC_chunk_000\\natives\\x64\\";
local wstring RE2Path <hidden=true> = "F:\\modmanager\\REtool\\RE2_chunk_000\\natives\\x64\\";
local wstring RE3Path <hidden=true> = "F:\\modmanager\\REtool\\RE3_chunk_000\\natives\\stm\\";
local wstring RE4Path <hidden=true> = "H:\\modding\\REtool\\RE4demo_chunk_000\\natives\\stm\\";
local wstring RE7Path <hidden=true> = "F:\\modmanager\\REtool\\RE7_chunk_000\\natives\\x64\\";
local wstring RE8Path <hidden=true> = "F:\\modmanager\\REtool\\RE8_chunk_000\\natives\\stm\\";
local wstring MHRPath <hidden=true> = "F:\\modmanager\\REtool\\MHR_chunk_000\\natives\\stm\\";
local wstring RE2RTPath <hidden=true> = "F:\\modmanager\\REtool\\RE2RT_chunk_000\\natives\\stm\\";
local wstring RE3RTPath <hidden=true> = "F:\\modmanager\\REtool\\RE3RT_chunk_000\\natives\\stm\\";
local wstring RE7RTPath <hidden=true> = "F:\\modmanager\\REtool\\RE7RT_chunk_000\\natives\\stm\\";
local wstring SF6Path <hidden=true> = "F:\\modmanager\\REtool\\SF6Beta_chunk_000\\natives\\stm\\";
//RSZ Parser By Darkness:
#link "RSZParser.dll"
ubyte IsInitialized();
void ParseJson(string jsonPath);
string GetRSZClassName(uint32 classHash);
uint32 GetRSZClassCRC(uint32 classHash);
uint32 GetFieldCount(uint32 classHash);
uint32 GetFieldAlignment(uint32 classHash, uint32 fieldIndex);
ubyte GetFieldArrayState(uint32 classHash, uint32 fieldIndex);
string GetFieldName(uint32 classHash, uint32 fieldIndex);
string GetFieldTypeName(uint32 classHash, uint32 fieldIndex);
string GetFieldOrgTypeName(uint32 classHash, uint32 fieldIndex);
uint32 GetFieldSize(uint32 classHash, uint32 fieldIndex);
uint64 GetFieldType(uint32 classHash, uint32 fieldIndex);
ubyte IsFieldNative(uint32 classHash, uint32 fieldIndex);
#endlink
// #include "Enums.btx" //'btx' is a made up extension for extra template files, to not confuse them with main templates
#include "motfsmEnum.btx"
#include "TagsCollection.btx"
//Local variables:
local int i <hidden=true>, j <hidden=true>, k <hidden=true>, m <hidden=true>, n <hidden=true>, o <hidden=true>, h <hidden=true>, temp <hidden=true>,
matchSize <hidden=true>, lastGameObject <hidden=true>, uniqueHashes[5000] <hidden=true>, hashesLen <hidden=true>, noRetry <hidden=true>;
local uint RSZOffset <hidden=true> = FindFirst("RSZ",1,0,0,0.0,1,0,0,24);
local uint BHVTStart <hidden=true> = FindFirst("BHVT",1,0,0,0.0,1,0,0,24);
local int UVARStart <hidden=true> = BHVTStart;
local uint lastVarEnd <hidden=true>;
local uint realStart <hidden=true> = -1;
local int level <hidden=true>;
local int finished <hidden=true>;
local int broken <hidden=true>;
local ubyte silenceMessages <hidden=true>;
local string s <hidden=true>;
local wstring tempWString <hidden=true>;
local ubyte isAIFile <hidden=true>;
local char magic[4] <hidden=true>;
local ushort headerStringsCount <hidden=true>;
local uint headerStrings[1 + RSZOffset / 64] <hidden=true>;
local uint dummyArr[1] <hidden=true>;
local byte PasteBuffer[100000] <hidden=true>; //100KB buffer
if (detectedHash(4) && !detectedHash(0))
ReadBytes(magic, 4, 4);
else
ReadBytes(magic, 0, 4);
if (ShowAlignment) {
local int varLen <hidden=false>;
local uint maxVars <hidden=true> = ((FileSize()-RSZOffset)/6);
if (maxVars > 1000000) maxVars = 1000000;
local uint offs[maxVars] <hidden=false>, aligns[maxVars] <hidden=false>, sizes[maxVars] <hidden=false>; //synced
} else {
local int varLen <hidden=true>;
}
local string filename <hidden=true> = GetFileName();
local wstring extractedDir <hidden=true> = DMC5Path;
local wstring Local_Directory <hidden=true> = FileNameGetPath(filename, true);
local uint findValue <hidden=true> = find(Local_Directory, "natives");
Local_Directory = StrDel( Local_Directory, findValue, sizeof(Local_Directory) - findValue) + "natives\\";
local wstring dir <hidden=true> = Lower(Local_Directory);
local ushort maxLevels <hidden=true>;
local uint64 RSZAddresses[6000] <hidden=true>;
h = FindFirst(5919570,1,0,0,0.0,1,0,0,24)+4;
while (h != 3) {
RSZAddresses[maxLevels] = h-4;
maxLevels++;
h = FindFirst(5919570,1,0,0,0.0,1,h,0,24)+4;
}
local uint RSZFileMaxDivs <hidden=true> = maxLevels / 100 + 1;
local uint RSZFileWaypoints[RSZFileMaxDivs] <hidden=true>;
local uint RSZFileDivCounter <hidden=true>;
checkHashesForRT();
if (AutoDetectGame) {
if (RTVersion && (findS(filename, "scn\\.1[89]$")!=-1 || findS(filename, "pfb\\.16$")!=-1 || findS(filename, "motfsm2\\.30$")!=-1
|| findS(filename, "rcol\\.10$")!=-1 || findS(filename, "fsmv2\\.30$")!=-1 || findS(filename, "rcol\\.2$")!=-1)) {
Printf("Detected Pre-RayTracing file extension\n");
RTVersion = false;
}
o = 0;
local string xFmt <hidden=true> = "x64\\";
if (find(dir, "dmc5") != -1 || find(dir, "evil may") != -1 || find(dir, "dmc[ _]") != -1) {
RSZVersion = "DMC5"; o = 1;
extractedDir = DMC5Path;
Printf("Detected DMC in filepath\n");
} else if (find(dir, "sf6") != -1 || find(dir, "reet ?[Ff]ighter") != -1) {
RSZVersion = "SF6"; o = 1;
extractedDir = SF6Path;
xFmt = "stm\\";
Printf("Detected SF6 in filepath\n");
} else if (find(dir, "re2") != -1 || find(dir, "evil 2") != -1) {
RSZVersion = "RE2"; o = 1;
if (RTVersion) {
extractedDir = Lower(RE2RTPath);
xFmt = "stm\\";
} else {
extractedDir = Lower(RE2Path);
xFmt = "x64\\";
}
Printf("Detected RE2 in filepath\n");
} else if (find(dir, "re3") != -1 || find(dir, "evil 3") != -1) {
RSZVersion = "RE3"; o = 1;
if (RTVersion)
extractedDir = Lower(RE3RTPath);
else
extractedDir = Lower(RE3Path);
xFmt = "stm\\";
Printf("Detected RE3 in filepath\n");
} else if (find(dir, "re4") != -1 || find(dir, "evil 4") != -1) {
RSZVersion = "RE4"; o = 1;
extractedDir = Lower(RE4Path);
xFmt = "stm\\";
Printf("Detected RE4 in filepath\n");
} else if (find(dir, "re8") != -1 || find(dir, "evil 8") != -1 || find(dir, "illage") != -1) {
RSZVersion = "RE8"; o = 1;
extractedDir = Lower(RE8Path);
xFmt = "stm\\";
Printf("Detected RE8 in filepath\n");
} else if (find(dir, "re7") != -1 || find(dir, "evil 7") != -1) {
RSZVersion = "RE7"; o = 1;
if (RTVersion) {
extractedDir = Lower(RE7RTPath);
xFmt = "stm\\";
} else {
extractedDir = Lower(RE7Path);
xFmt = "x64\\";
}
Printf("Detected RE7 in filepath\n");
} else if (find(dir, "\\mhr") != -1 || find(dir, "nter R") != -1 || find(dir, "Rise") != -1) {
RSZVersion = "MHRise"; o = 1;
extractedDir = Lower(MHRPath);
xFmt = "stm\\";
Printf("Detected MHRise in filepath\n");
}
Local_Directory += xFmt;
} else if ((!RTVersion && (RSZVersion == "RE2" || RSZVersion == "RE7")) || RSZVersion == "DMC5") {
Local_Directory += "x64\\";
} else {
Local_Directory += "stm\\";
}
LittleEndian();
Local_Directory = Lower(Local_Directory);
local string JsonPath <hidden=true> = Lower(FileNameGetPath(GetTemplateFileName()) + "rsz" + RSZVersion);
if (RTVersion && (RSZVersion=="RE2" || RSZVersion=="RE7" || RSZVersion=="RE3"))
JsonPath = JsonPath + "rt";
JsonPath = JsonPath + ".json";
ParseJson(JsonPath);
if ( RSZOffset > -1 && AutoDetectGame && !(RSZVersion == "RE7" && !RTVersion))
AutoDetectVersion();
RTVersion = (RSZVersion=="RE2" || RSZVersion=="RE7" || RSZVersion=="RE3") * RTVersion;
local string GameVersion = RSZVersion;
if (RTVersion)
local int IsRayTracing = RTVersion;
if (RSZVersion=="SF6" && ReadUInt(4) == id_fchr)
#include "SF6_fchar.btx";
//============================
//Special functions & structs:
void checkHashesForRT() {
local int firstGameObj = FindFirst(3372393495, 1,0,0,0.0,1,0,0,24); //via.GameObject
local int firstFolder = FindFirst(2929908172, 1,0,0,0.0,1,0,0,24); //via.Folder
local int firstFSM = FindFirst(4193703126, 1,0,0,0.0,1,0,0,24); //via.motion.Fsm2ActionPlayMotion
local int firstRCOL = FindFirst(4150774079, 1,0,0,0.0,1,0,0,24); //via.physics.UserData
if (firstGameObj != -1) {
RTVersion = (ReadUInt(firstGameObj+4) == 216572408); //check if CRC version is new
} else if (firstFolder != -1) {
RTVersion = (ReadUInt(firstFolder+4) == 2121287109);
} else if (firstFSM != -1) {
RTVersion = (ReadUInt(firstFSM+4) == 1025596507 && findS(filename, "motfsm2\\.36$") == -1);
} else if (firstRCOL != -1) {
RTVersion = ((ReadUInt(firstRCOL+4) == 374943849) && findS(filename, "rcol\\.11$") == -1);
}
}
void AutoDetectVersion() {
local string hashName;
local uint checkedVersions, instanceCount, objectCount, hash, zz, varsChecked;
local int origRTVersion = RTVersion;
local int badCRCs;
local string origVersion = RSZVersion, origExtractedDir = (string)extractedDir, origXFmt = xFmt,
origLocal_Directory = Local_Directory, origJsonPath = JsonPath;
FSeek(RSZOffset);
if (FTell() + 12 < FileSize())
instanceCount = ReadUInt(FTell() + 12), objectCount = ReadUInt(FTell() + 8);
if (instanceCount) {
FSeek(ReadUInt(RSZOffset+24) + RSZOffset + 8);
//if (ReadUInt64() != 0) {
// if (RSZVersion != "RE7")
// Printf("RSZVersion auto detected to RE7\n");
// RSZVersion = "RE7"; extractedDir = RE7Path; xFmt = "x64\\";
// return;
//}
//if (RSZVersion == "RE3")
for (zz=1; zz<instanceCount; zz++) {
if (varsChecked > 100) break;
hash = ReadUInt();
hashName = ReadHashName(hash);
checkedVersions = 0;
if (hash != 0 && (hashName == "Unknown Class!") && hashName != "via.physics.UserData" && hashName != "via.physics.RequestSetColliderUserData") {
//Printf("%s %i %i\n", hashName, zz, FTell());
while (checkedVersions <= 6 && (hashName == "Unknown Class!")) { //|| (RSZVersion == "RE3" && (hashName == "via.physics.UserData" || hashName == "via.physics.RequestSetColliderUserData"))
switch (checkedVersions) {
case 0: RSZVersion = "DMC5"; extractedDir = DMC5Path; xFmt = "x64\\"; break;
case 1: RSZVersion = "RE2"; extractedDir = RTVersion ? RE2RTPath : RE2Path; xFmt = RTVersion ? "stm\\" : "x64\\"; break;
case 2: RSZVersion = "RE3"; extractedDir = RTVersion ? RE3RTPath : RE3Path; xFmt = "stm\\"; break;
case 3: RSZVersion = "RE8"; extractedDir = RE8Path; xFmt = "stm\\"; break;
case 4: RSZVersion = "MHRise"; extractedDir = MHRPath; xFmt = "stm\\"; break;
case 5: RSZVersion = "RE7"; extractedDir = RTVersion ? RE7RTPath : RE7Path; xFmt = RTVersion ? "stm\\" : "x64\\"; break;
case 6: RSZVersion = "SF6"; extractedDir = SF6Path; xFmt = "stm\\"; break;
default: break;
}
JsonPath = Lower(FileNameGetPath(GetTemplateFileName()) + "rsz" + RSZVersion);
if (RTVersion && (RSZVersion == "RE2" || RSZVersion == "RE3" || RSZVersion == "RE7"))
JsonPath = JsonPath + "rt";
JsonPath = JsonPath + ".json";
Local_Directory = dir + xFmt;
ParseJson(JsonPath);
hashName = ReadHashName(hash);
checkedVersions++;
}
if (hashName == "Unknown Class!") { //checkedVersions == 8 &&
RSZVersion = origVersion; extractedDir = origExtractedDir; xFmt = origXFmt;
Local_Directory = origLocal_Directory; JsonPath = origJsonPath; RTVersion = origRTVersion;
} else {
Printf("RSZVersion auto detected to %s\n", RSZVersion);
break;
}
} //else
// Printf("%s\n", hashName);
varsChecked++;
FSkip(8);
if (varsChecked > 15)
break;
}
}
FSeek(0);
}
void align(uint alignment) {
while (FTell() % alignment != 0 && FTell() <= FileSize())
FSkip(1);
}
int detectedColorVector(uint64 tell) {
if (tell+16<=FileSize()) {
local float R = ReadFloat(tell), G = ReadFloat(tell+4), B = ReadFloat(tell+8), A = ReadFloat(tell+12);
return ((R >= 0 && G >= 0 && B >= 0 && (A == 0 || A == 1)) && ((R+G+B+A <= 4) || (R+G+B+A) % 1.0 == 0));
} return 0;
}
float readColorFloat(uint64 tell) {
local float colorFlt = ReadFloat(tell);
if (colorFlt <= 1) {
colorFlt = (uint)(colorFlt * 255.0f + 0.5);
if (colorFlt > 255)
return 255;
}
return colorFlt ;
}
/*float colorFloatToByte(ubyte c) {
local float colorFlt = (uint)(colorFlt * 255.0f + 0.5);
if (colorFlt > 255) return 255;
if (colorFlt < 0) return 255;
return colorFlt ;
}
float colorByteToFloat(ubyte c) {
local float colorFlt = (uint)(colorFlt * 255.0f + 0.5);
if (colorFlt > 255) return 255;
if (colorFlt < 0) return 255;
return colorFlt ;
}*/
int detectedFloat(uint64 offset) {
if (offset+4 <= FileSize()) {
local float flt = ReadFloat(offset);
if (BHVTStart != -1)
return (ReadUByte(offset+3) < 255 && (Abs(flt) > 0.000001 && Abs(flt) < 100000) || ReadInt(offset) == 0);
else return (ReadUByte(offset+3) < 255 && (Abs(flt) > 0.0000001 && Abs(flt) < 10000000) || ReadInt(offset) == 0);
} return false;
}
int detectedStringSm(uint64 offset) {
if (offset+4 <= FileSize())
if (ReadUShort(offset-2) == 0)
if (ReadByte(offset) != 0 || ReadUShort(offset) == 0)
if (ReadByte(offset + 1) == 0 || sizeof(ReadWString(offset)) > 5)
//if (sizeof(ReadWString(offset)) >= 2)
return true;
return false;
}
int detectedString(uint64 offset) {
if (offset+6 <= FileSize())
if (ReadByte(offset) != 0 && ReadByte(offset + 1) == 0)
if (ReadByte(offset + 2) != 0 && ReadByte(offset + 3) == 0)
if (ReadByte(offset + 4) != 0) // && ReadByte(offset + 5) == 0
return true;
return false;
}
int detectedNode (uint tell) {
if (tell+12<FileSize())
if (ReadInt(tell-4) == 0)
if (ReadInt(tell) != -1)
if (detectedHash(tell))
if (ReadInt(tell+8) != 0)
if (detectedStringSm(startof(Header.BHVT.mNamePool) + 4 + (ReadUInt(tell+8)*2)))
return true;
return false;
}
int find(wstring str, wstring term) { return (RegExSearch(str, term, matchSize, 0)); }
int findS(string str, string term) { return (RegExSearch(str, term, matchSize, 0)); }
wstring Lower(wstring s1) { local string s = s1, s2 = s; for (k=0; k < sizeof(s); k++) s2[k] = ToLower(s[k]); return s2; }
wstring Upper(wstring s1) { local string s = s1, s2 = s; for (k=0; k < sizeof(s); k++) s2[k] = ToUpper(s[k]); return s2; }
int detectedBools(uint tell) {
local uint nonBoolTotal;
for (o=0; o<4; o++)
if (ReadUByte(tell + o) > 1)
nonBoolTotal++;
if (nonBoolTotal == 0)
return true;
return false;
}
int detectedHash(uint tell) {
local uint tst = ReadInt(tell);
if (tst == -1 || tst == 0)
return false;
local ubyte nonHashTotal;
for (o=0; o<4; o++)
if (ReadUByte(tell + o) == 0)
nonHashTotal++;
if (nonHashTotal <= 1)
return true;
return false;
}
void FileOpener(wstring path) {
local wstring tmpNm = GetTemplateFileNameW();
if (FileExists(NoesisPath) && (find(path, ".mesh.") != -1 || find(path, ".tex.") != -1)) {
Exec(NoesisPath, "\"" + path + "\"", 0);
FileOpen(path, TRUE, "hex", 0);
} else FileOpen(path, TRUE, "hex", 0);
FileSelect(FindOpenFileW(path));
if (GetTemplateFileNameW() == "")
RunTemplate(tmpNm, 0);
}
typedef byte BLANK <name=readBLANK, read=readBLANK>;
string readBLANK(BLANK &ref) { return " ";}
string ReadErrorNotice(BLANK &b) { return "[Read Error Adjustment]"; }
string ReadUserDataNotice(BLANK &b) { return "[Embedded UserDatas]"; }
string ReadMainDataNotice(BLANK &b) { return "[Main Data]"; }
void checkUseSpacers() { //this is used a lot to make things more readable and to make <open=true> work when at the end of a list
if (UseSpacers) {
FSkip(-1);
BLANK blank;
}
}
typedef enum {
id_All = -1,
id_Actions = 0,
id_Selectors = 1,
id_SelectorCallers = 2,
id_Conditions = 3,
id_TransitionEvents = 4,
id_ExpressionTreeConditions = 5,
id_StaticActions = 6,
id_StaticSelectorCallers = 7,
id_StaticConditions = 8,
id_StaticTransitionEvents = 9,
id_StaticExpressionTreeConditions = 10,
id_Transition = 11,
id_Paths = 12,
id_Tags = 13,
id_NameHash = 14
} BHVTlvl;
typedef enum <uint32> {
ukn_error = 0,
ukn_type,
not_init,
class_not_found,
out_of_range,
Undefined_tid,
Object_tid,
Action_tid,
Struct_tid,
NativeObject_tid,
Resource_tid,
UserData_tid,
Bool_tid,
C8_tid,
C16_tid,
S8_tid,
U8_tid,
S16_tid,
U16_tid,
S32_tid,
U32_tid,
S64_tid,
U64_tid,
F32_tid,
F64_tid,
String_tid,
MBString_tid,
Enum_tid,
Uint2_tid,
Uint3_tid,
Uint4_tid,
Int2_tid,
Int3_tid,
Int4_tid,
Float2_tid,
Float3_tid,
Float4_tid,
Float3x3_tid,
Float3x4_tid,
Float4x3_tid,
Float4x4_tid,
Half2_tid,
Half4_tid,
Mat3_tid,
Mat4_tid,
Vec2_tid,
Vec3_tid,
Vec4_tid,
VecU4_tid,
Quaternion_tid,
Guid_tid,
Color_tid,
DateTime_tid,
AABB_tid,
Capsule_tid,
TaperedCapsule_tid,
Cone_tid,
Line_tid,
LineSegment_tid,
OBB_tid,
Plane_tid,
PlaneXZ_tid,
Point_tid,
Range_tid,
RangeI_tid,
Ray_tid,
RayY_tid,
Segment_tid,
Size_tid,
Sphere_tid,
Triangle_tid,
Cylinder_tid,
Ellipsoid_tid,
Area_tid,
Torus_tid,
Rect_tid,
Rect3D_tid,
Frustum_tid,
KeyFrame_tid,
Uri_tid,
GameObjectRef_tid,
RuntimeType_tid,
Sfix_tid,
Sfix2_tid,
Sfix3_tid,
Sfix4_tid,
Position_tid,
F16_tid,
End_tid,
Data_tid
} TypeIDs;
uint getAlignedOffset(uint tell, uint alignment) {
local uint offset = tell;
switch (alignment) {
case 2: offset = tell + (tell % 2); break; //2-byte
case 4: offset = (tell + 3) & 0xFFFFFFFFFFFFFFFC; break; //4-byte
case 8: offset = (tell + 7) & 0xFFFFFFFFFFFFFFF8; break; //8-byte
case 16: offset = (tell + 15) & 0xFFFFFFFFFFFFFFF0; break; //16-byte
default: break;
}
return offset;
}
typedef struct(int listSize) {
local ubyte listSize <hidden=true> = listSize;
int Count;
} BHVTCount <read=ReadBHVTCount, write=WriteBHVTCount>;
string ReadBHVTCount(BHVTCount &c) { local string s; SPrintf(s, "%i", c.Count); return s; }
void WriteBHVTCount(BHVTCount &c, string s) {
local int newCount = Atoi(s);
if (newCount - c.Count > 0) {
local int k, j, padding;
local int addedSz = ((newCount - c.Count) * 4 * c.listSize);
if ( ((newCount - c.Count) * 4 * c.listSize) % 16 != 0)
while ((RSZOffset + addedSz + padding) % 16 != RSZOffset % 16)
padding++;
FixBHVTOffsets(addedSz + padding, RSZOffset);
local int extraStateBytes;
if (c.listSize == 6 && c.Count > 0) //states
extraStateBytes = ((startof(parentof(c)) + sizeof(parentof(c)) - (startof(c) + 4)) - (c.Count * 4 * c.listSize));
for (k=c.listSize; k>0; k--) {
InsertBytes(startof(c) + 4 + ((c.Count*4) * k) + (extraStateBytes), 4 * (newCount - c.Count), 0);
Printf("inserting %i bytes at %i for +%i new items\n", 4 * (newCount - c.Count), startof(c) + 4 + (c.Count*4) * k, newCount - c.Count);
}
if (padding)
InsertBytes(RSZOffset+addedSz, padding, 0);
ShowRefreshMessage("");
}
c.Count = newCount;
}
void FixBHVTOffsets(int addedSz, uint insertPoint) {
local int tt, vr, nd, nv;
if (exists(Header.treeDataSize))
Header.treeDataSize += addedSz;
if (BHVTStart > 0)
FixOffsets(0, BHVTStart, insertPoint, FileSize()+addedSz, addedSz, 0);
FixOffsets(BHVTStart, BHVTStart+sizeof(Header.BHVT), insertPoint - BHVTStart - 8, FileSize()+addedSz, addedSz, 0);
while(exists(RSZFile[tt])) {
if (!RSZFile[tt].isEmbeddedUserData)
FixOffsets(startof(RSZFile[tt]) + addedSz, startof(RSZFile[tt].RSZHeader)+48, insertPoint, FileSize()+addedSz, addedSz, 0);
tt++;
}
tt=0;
while (exists(Header.BHVT.Uvar[tt])) {
FixOffsets(startof(Header.BHVT.Uvar[tt]), startof(Header.BHVT.Uvar[tt])+40, insertPoint-BHVTStart, FileSize()+addedSz, addedSz, 0); //Header
if (exists(Header.BHVT.Uvar[tt].Data)) {
FixOffsets(startof(Header.BHVT.Uvar[tt].Data), startof(Header.BHVT.Uvar[tt].Data)+sizeof(Header.BHVT.Uvar[tt].Data), insertPoint-BHVTStart, FileSize()+addedSz, addedSz, 0); //Data
vr=0;
while(exists(Header.BHVT.Uvar[tt].Data.Var[vr])) {
if (exists(Header.BHVT.Uvar[tt].Data.Var[vr].VarData)) {
if (Header.BHVT.Uvar[tt].Data.Var[vr].VarData.nodesOffset > 0) Header.BHVT.Uvar[tt].Data.Var[vr].VarData.nodesOffset += addedSz;
if (Header.BHVT.Uvar[tt].Data.Var[vr].VarData.offset2 > 0) Header.BHVT.Uvar[tt].Data.Var[vr].VarData.offset2 += addedSz; //all this because [propCount, ukn00, ukn01] sometimes make false positives for FixOffsets
nd = 0;
while(exists(Header.BHVT.Uvar[tt].Data.Var[vr].VarData.Node[nd])) {
if (Header.BHVT.Uvar[tt].Data.Var[vr].VarData.Node[nd].name.strOffset > 0) Header.BHVT.Uvar[tt].Data.Var[vr].VarData.Node[nd].name.strOffset += addedSz;
if (Header.BHVT.Uvar[tt].Data.Var[vr].VarData.Node[nd].dataOffset > 0) Header.BHVT.Uvar[tt].Data.Var[vr].VarData.Node[nd].dataOffset += addedSz;
nv = 0;
while (exists(Header.BHVT.Uvar[tt].Data.Var[vr].VarData.Node[nd].Value[nv])) {
if (exists(Header.BHVT.Uvar[tt].Data.Var[vr].VarData.Node[nd].Value[nv].hashOffs)
&& Header.BHVT.Uvar[tt].Data.Var[vr].VarData.Node[nd].Value[nv].hashOffs > 0) {
Header.BHVT.Uvar[tt].Data.Var[vr].VarData.Node[nd].Value[nv].hashOffs += addedSz;
}
nv++;
}
nd++;
}
}
vr++;
}
}
if (exists(Header.BHVT.Uvar[tt].HashData))
FixOffsets(startof(Header.BHVT.Uvar[tt].HashData), startof(Header.BHVT.Uvar[tt].HashData)+sizeof(Header.BHVT.Uvar[tt].HashData)
, insertPoint-BHVTStart, FileSize()+addedSz, addedSz, 0); //Hashes
if (exists(Header.BHVT.Uvar[tt].EmbeddedUVARs))
FixOffsets(startof(Header.BHVT.Uvar[tt].EmbeddedUVARs)+4, 4+startof(Header.BHVT.Uvar[tt].EmbeddedUVARs)+sizeof(Header.BHVT.Uvar[tt].EmbeddedUVARs.embedOffsets)
, insertPoint-BHVTStart, FileSize()+addedSz, addedSz, 0); //embeds
if (exists(Header.BHVT.Uvar[tt].EndOffsets))
FixOffsets(startof(Header.BHVT.Uvar[tt].EndOffsets), startof(Header.BHVT.Uvar[tt].EndOffsets)+sizeof(Header.BHVT.Uvar[tt].EndOffsets)
, insertPoint-BHVTStart, FileSize()+addedSz, addedSz, 0); //End Offsets
tt++;
}
}
void FixRCOLOffsets(uint sizeToAdd, uint insertPt, int64 limitOffset) {
if (exists(RequestSets)) {
//if (sizeof(RSZFile[0]) != Header.userDataSize)
// Header.userDataSize = sizeof(RSZFile[0]);
FixOffsets(0, Groups.shapesEnd, insertPt, limitOffset, sizeToAdd, 0);
FixOffsets(startof(RequestSets), startof(RequestSets)+sizeof(RequestSets), insertPt, limitOffset, sizeToAdd, 0);
if (exists(IgnoreTags))
FixOffsets(startof(IgnoreTags), startof(IgnoreTags)+sizeof(IgnoreTags), insertPt, limitOffset, sizeToAdd, 0);
}
}
void WriteNewNode(ubyte &n, string s) {
local int addedSz = 78;
if (isAIFile)
addedSz = 52;
local int stringInsertPt = startof(Header.BHVT.mNamePool)+sizeof(Header.BHVT.mNamePool);
local int nodeInsertPt = startof(BehaviorTree.RawNodes)+sizeof(BehaviorTree.RawNodes);
local uint newHash = hash_wide(s);
local int existingPadding, stringPadding, nodePadding;
local int stringSz = sizeof(s)*2;
nodePadding = 16 - (addedSz % 16);
while(ReadUByte(stringInsertPt+existingPadding) == 0)
existingPadding++;
while((stringInsertPt + stringSz + stringPadding) % 16 != stringInsertPt % 16)
stringPadding++;
if (existingPadding + stringPadding > 16)
stringPadding -= 16;
FixBHVTOffsets(stringSz + stringPadding, stringInsertPt); // - stringPadding
FixBHVTOffsets(addedSz + nodePadding, RSZOffset); //-64
Header.BHVT.mNamePool.poolSize += sizeof(s);
SetCursorPos(stringInsertPt);
if (stringPadding > 0)
InsertBytes(stringInsertPt, stringPadding, 0);
if (stringPadding < 0)
DeleteBytes(stringInsertPt, -stringPadding);
InsertBytes(stringInsertPt, stringSz, 0);
WriteWString(stringInsertPt, s);
InsertBytes(RSZOffset, 16 - (addedSz % 16), 0);
InsertBytes(nodeInsertPt, addedSz, 0);
for (i=0;i<4;i++)
WriteUByte(nodeInsertPt+i, Random(255)); //Random hash
WriteUInt(nodeInsertPt+8, (stringInsertPt - startof(Header.BHVT.mNamePool)-4) / 2);
WriteInt(nodeInsertPt+24, -1);
WriteInt(nodeInsertPt+32, -1);
if (!isAIFile) {
WriteUInt(nodeInsertPt+44, 35);
WriteUInt(nodeInsertPt+48, newHash);
WriteUInt(nodeInsertPt+52, newHash);
}
BehaviorTree.NodeCount += 1;
ShowRefreshMessage("");
}
string readNodeWriterMessage(ubyte &n) { return " [Input a name here to add a Behavior Node]"; }
void ShowRefreshMessage(string extraMsg) {
if (!silenceMessages)
MessageBox( idOk, "Insert Data", "%sPress F5 to refresh the template and fix template results", extraMsg);
}
//General offset fixer
void FixOffsets(uint64 tell, uint64 tellLimit, uint64 insertPoint, int64 maxOffset, uint64 addedSz, int doInt32) {
if (tell > tellLimit) {
Printf("Cannot fix offsets: insert point %i is before start boundary %i\n", insertPoint, tell);
return;
}
Printf("Fixing Offsets greater than %i and less than %i from positions %i to %i:\n\n", insertPoint, maxOffset, tell, tellLimit);
local uint64 pos = FTell();
local int64 tmp;
local int varSize = 8 + -4 * (doInt32 > 0);
FSeek(tell);
while(FTell() + varSize <= tellLimit) {
if (FTell()+varSize > FileSize())
break;
if (doInt32)
tmp = ReadInt(FTell());
else
tmp = ReadInt64(FTell());
if (tmp >= insertPoint && tmp <= maxOffset) {
Printf("@ position %i: %Li >= %Li (limit %i) added +%i\n", FTell(), tmp, insertPoint, maxOffset, addedSz);
if (doInt32)
tmp = WriteUInt(FTell(), tmp + addedSz);
else
WriteUInt64(FTell(), tmp + addedSz);
}// else //if (tmp && tmp <= maxOffset)
// Printf("@ position %i: %Li >! %Li (limit %i) %i\n", FTell(), tmp, insertPoint, tellLimit, addedSz);
FSkip(varSize);
}
}
//Sorts array in ascending order, then sorts array2 by array (from Che)
void quicksort( int low, int high, uint array[], uint array2[] ) {
local int i = low;
local int j = high;
local int temp = 0;
local int z = array[(low + high) / 2]; // Choose a pivot value
local byte doArray2;
if (exists(array2[1]))
doArray2 = true;
while( i <= j ) { // Partition the data
while( array[i] < z ) // Find member above
i++;
while( array[j] > z ) // Find element below
j--;
if( i <= j ) {
// swap two elements
temp = array[i];
array[i] = array[j];
array[j] = temp;
if (doArray2) {
temp = array2[i];
array2[i] = array2[j];
array2[j] = temp;
}
i++;
j--;
}
}
// Recurse
if( low < j )
quicksort( low, j, array, array2 );
if( i < high )
quicksort( i, high, array, array2 );
}
int getLevel(uint offset) {
local int L = 0;
for (L=getRSZFileWaypointIndex(offset); L<level; L++) {
if (offset >= startof(RSZFile[L].Data) && offset < startof(RSZFile[L].Data) + sizeof(RSZFile[L].Data))
break;
}
return L;
}
int getLevelRSZ(uint offset) {
local int L;
for (L=getRSZFileWaypointIndex(offset); L<level; L++) {
if (offset >= startof(RSZFile[L].RSZHeader) - 16 && offset <= startof(RSZFile[L].RSZHeader) + 16)
break;
}
return L;
}
typedef struct {
uchar uuid[16] <open=suppress>;
local int firstFourBytes <hidden=true> = ReadInt(startof(uuid));
if (firstFourBytes != -1 && firstFourBytes != 0 ) {
if (FindFirst(firstFourBytes) != startof(uuid) || FindFirst(firstFourBytes,1,0,0,0.0,1,startof(uuid)+16,0,24) != -1) {
local string Guid <hidden=true> = TranslateGUID(uuid);
FSkip(-4);
struct SAMEGUIDS SameGUIDs(TranslateGUID(uuid)) <size=4>;
}
}
} rGUID <read=ReadrGUID, write=WriterGuid, comment=ReadrGUIDComment>;
string TranslateGUID (uchar uuid[]) {
local char s[37];
SPrintf(s,
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
uuid[3], uuid[2], uuid[1], uuid[0], uuid[5], uuid[4], uuid[7], uuid[6],
uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]
);
return s;
}
string ReadrGUID (rGUID &g) {
local string Guid = TranslateGUID(g.uuid);
return Guid;
}
string ReadrGUIDComment(rGUID &g) { if (exists(g.GameObjectRef)) return g.GameObjectRef; return ""; }
void WriterGuid (rGUID &g, string s) {
local string out;
local byte ii, offset;
local uchar uuid[16];
for (ii=0; ii<16; ii++) {
if (ii==4 || ii== 6 || ii==8 || ii==10)
offset++;
SScanf(SubStr(s, ii*2 + offset, 2), "%x", uuid[ii]);
}
local uchar uuid_le[16] = {
uuid[3], uuid[2], uuid[1], uuid[0], uuid[5], uuid[4], uuid[7], uuid[6],
uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]
};
WriteBytes(uuid_le, startof(g), 16);
}
//functions for opening files:
string getRE2ext(wstring ext) {
switch (ext) {
case ".jcns": return ".11";
case ".pfb": return ".16";
case ".mdf2": case ".tex": case ".rcol": case ".jmap": return ".10";
case ".efx": return ".1769669";
case ".wcc": case ".wss": case ".ies": case ".uvar": case ".wss": case ".fbxskel": return ".2";
case ".wel": return ".11";
case ".mesh": return ".1808312334";
case ".fsmv2": case ".bhvt": case ".motfsm2": return ".30";
case ".scn": return ".19";
case ".motbank": case ".mov": return ".1";
case ".chain": return ".21";
case ".lprb": return ".3";
case ".mmtr": return ".1808160001";
case ".tml": case ".clip": case ".rbs": return ".27";
case ".motlist": return ".85";
case ".mcol": return ".3017";
case ".cfil": case ".uvs": return ".7";
case ".mot": return ".65";
case ".gui": return ".270020";
case ".rmesh": return ".10008";
case ".rtex": return ".4";
case ".rbs": case ".rdd": return ".27019";
case ".mcamlist": case ".msg": return ".13";
default: return "";
}
}
string getRE3ext(wstring ext) {
switch (ext) {
case ".mcol": return ".9018";
case ".jcns": return ".12";
case ".pfb": return ".17";
case ".mdf2": return ".13";
case ".tex": return ".190820018";
case ".rcol": case ".jmap": return ".11";
case ".lprb": return ".4";
case ".efx": return ".2228526";
case ".wcc": case ".wss": case ".ies": case ".uvar": case ".wss": case ".user": return ".2";
case ".wel": return ".11";
case ".mesh": return ".1902042334";
case ".fsmv2": case ".bhvt": case ".tml": case ".clip": return ".34";
case ".motfsm2": return ".36";
case ".scn": return ".20";
case ".mov": return ".1";
case ".chain": return ".24";
case ".fbxskel": case ".motbank": return ".3";
case ".mmtr": return ".1905100741";
case ".rbs": return ".28";
case ".motlist": return ".99";
case ".cfil": case ".uvs": return ".7";
case ".mot": return ".78";
case ".gui": return ".340020";
case ".rmesh": return ".17008";
case ".rtex": return ".4";
case ".rdd": return ".28019";
case ".mcamlist": return ".14";
case ".msg": return ".15";
default: return "";
}
}
string getRE7ext(wstring ext) {
switch (ext) {
case ".uvar": case ".lprb": case ".rcol": case ".mcol": case ".wcc": case ".wss": case ".ies": return ".2";
case ".pfb": return ".16";
case ".mdf2": return ".6";
case ".efx": return ".1179750";
case ".tex": case ".jmap": case ".aimap": return ".8";
case ".wel": return ".10";
case ".mesh": return ".32";
case ".fsm": case ".motfsm": return ".17";
case ".scn": case ".tml": return ".18";
case ".motbank": return ".1";
case ".mov": return ".1.x64";
case ".chain": return ".5";
case ".mmtr": return ".69";
case ".motlist": return ".60";
case ".cfil": return ".3";
case ".uvs": return ".5";
case ".mot": return ".17";
case ".gui": return ".180014";
case ".rtex": return ".4";
case ".mcamlist": return ".7";
case ".msg": return ".12";
case ".clo": return ".2016100701";
case ".rbd": case ".rdl": return ".2016100700";
default: return "";
}
}
string getRE8ext(wstring ext) {
switch (ext) {
case ".mcol": return ".9018";
case ".jcns": return ".16";
case ".pfb": return ".17";
case ".mdf2": return ".19";
case ".tex": return ".30";
case ".rcol": return ".18";
case ".jmap": return ".17";
case ".lprb": return ".4";
case ".efx": return ".2228526";
case ".wcc": case ".wss": case ".ies": case ".uvar": case ".wss": case ".user": return ".2";
case ".wel": return ".11";
case ".mesh": return ".2101050001";
case ".bhvt": case ".tml": return ".34";
case ".fsmv2": case ".clip": return ".40";
case ".motfsm2": return ".42";
case ".scn": return ".20";
case ".mov": case ".finf": return ".1";
case ".chain": return ".39";
case ".fbxskel": case ".motbank": return ".3";
case ".mmtr": return ".1905100741";
case ".rbs": return ".28";
case ".motlist": return ".486";
case ".cfil": case ".uvs": return ".7";
case ".mot": return ".458";
case ".gui": return ".400023";
case ".rmesh": return ".17008";
case ".rtex": return ".5";
case ".rdd": return ".28019";
case ".mcamlist": return ".17";
case ".msg": return ".15";
case ".gpuc": return ".62";
default: return "";
}
}
string getSF6ext(wstring ext) {
switch (ext) {
case ".mesh": return ".220721329";
case ".mdf2": return ".31";
case ".scn": return ".20";
case ".user": return ".2";
case ".pfb": return ".17";
default: return "";
}
}
string getMHRext(wstring ext) {
switch (ext) {
case ".mcol": return ".10019";
case ".jcns": return ".14";
case ".pfb": return ".17";
case ".mdf2": return ".19";
case ".tex": return ".28";
case ".rcol": return ".18";
case ".jmap": return ".16";
case ".lprb": return ".4";
case ".efx": return ".2621987";
case ".wcc": case ".wss": case ".ies": case ".uvar": case ".wss": case ".user": return ".2";
case ".wel": return ".11";
case ".mesh": return ".2008058288";
case ".bhvt": case ".tml": return ".34";
case ".fsmv2": case ".clip": return ".40";
case ".motfsm2": return ".42";
case ".scn": return ".20";
case ".mov": case ".finf": return ".1";
case ".chain": return ".35";