forked from alphazolam/RE-Engine-010-Templates
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRE_Engine_GUI.bt
More file actions
1379 lines (1260 loc) · 46.3 KB
/
RE_Engine_GUI.bt
File metadata and controls
1379 lines (1260 loc) · 46.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
//------------------------------------------------
//--- 010 Editor v9.0.2 Binary Template
//
// File: RE_Engine_GUI.bt
// Authors: alphaZomega
// Version: 1.32
// Purpose: Editing RE Engine gui.* files
// Category: RE Engine
// File Mask: *.gui.*
// ID Bytes: [+4] 47 55 49 52
// History: January 26, 2021
//------------------------------------------------
LittleEndian();
#include "common.bt";
//global vars
local uint64 R <hidden=true>, G <hidden=true>, B <hidden=true>, A <hidden=true>;
local int version <hidden=true>, i <hidden=true>, j <hidden=true>, k <hidden=true>, colorType <hidden=true>,
pos <hidden=true>, pos2 <hidden=true>, offsets[10000] <hidden=true>, offsetCounter <hidden=true> = 0;
local string fName <hidden=true> = GetFileName();
local int strSz <hidden=true> = Strlen(fName);
local uint64 Type <hidden=true>;
//motlist template versions, whatever
local uint Version <hidden=true> = 85; //RE2 + DMC5; other versions set up in the File Header
local ubyte DisplayCLIP = true; //Set this to false if the template is crashing
//typedef structs
typedef byte BLANK <name=readBLANK,read=readBLANK, write=null>;
string readBLANK(BLANK &ref) { return " ";}
//Special Make-Unique write function:
void MakeUnique(BLANK &b, string s) {
uint i, j, k, m, exit, ctr;
uchar bytes[1000];
for (i=0; i<HEADER.numOffs; i++) {
for (j=0; j<Elements.Element[i].ElementInfo.subElementCount; j++) {
for (k=0; k<Elements.Element[i].SubElement[j].itemCount; k++) {
if (exists(Elements.Element[i].SubElement[j].Attributes.Attribute[k].Value_Offset) && exists(Elements.Element[i].SubElement[j].Attributes.Attribute[k].bytes)
&& Elements.Element[i].SubElement[j].Attributes.Attribute[k].isPointer) {
ctr = 0;
for (m=0; m<10000; m++) {
if (offsets[m] == Elements.Element[i].SubElement[j].Attributes.Attribute[k].Value_Offset)
ctr++;
if (offsets[m] == 0 || ctr > 1) { //exists(Elements.Element[i].SubElement[j].Attributes.Attribute[k].valueOffset) &&
Elements.Element[i].SubElement[j].Attributes.Attribute[k].Value_Offset = FileSize();
ConvertDataToBytes(Elements.Element[i].SubElement[j].Attributes.Attribute[k].bytes, bytes );
WriteBytes(bytes, FileSize(), sizeof(Elements.Element[i].SubElement[j].Attributes.Attribute[k].bytes));
if (Elements.Element[i].SubElement[j].Attributes.Attribute[k].AttributeInfo.Name == "ColorOffset") {
WriteFloat(FileSize()-16, 1); WriteFloat(FileSize()-12, 1); WriteFloat(FileSize()-8, 1); WriteFloat(FileSize()-4, 1);
}
break;
}
}
}
}
}
}
MessageBox( idOk, "Insert Data", "Press F5 to refresh the template and fix template results");
}
string ReadUniqueWriterName (BLANK &u) { return "[MakeUnique Script]"; }
string ReadUniqueWriter (BLANK &u) { return "--> [Input Here to make all values unique] <--"; }
typedef struct {
wstring str;
} USTRING <read=ReadUSTRING>;
wstring ReadUSTRING(USTRING &input) { return input.str; }
typedef struct { string str; } STRING <read=ReadSTRING>;
string ReadSTRING (STRING &input) { return input.str; }
typedef ubyte COLORBYTE <read=ReadCOLORBYTE, write=WriteCOLORBYTE>;
string ReadCOLORBYTE (COLORBYTE input) { string s; SPrintf( s, "%g", input / 255.0f ) ; return s ; }
void WriteCOLORBYTE (COLORBYTE &f, string s ) { local float ff = Atof(s); f = (COLORBYTE)((ubyte)(ff * 255.0f));}
typedef struct {
uint32 type;
uint32 uknInt;
uint64 nameOffset;
FSeek(nameOffset);
string Name;
FSeek(startof(nameOffset)+8);
} ATTRIBUTEINFO <read=ReadATTRIBUTEINFO>;
string ReadATTRIBUTEINFO(ATTRIBUTEINFO &input) { return (parentof(input).type); }
typedef struct {
ATTRIBUTEINFO AttributeInfo;
local wstring Name <hidden=true> = AttributeInfo.Name;
//local uint64 valueOffset <hidden=true> = ReadUInt64(FTell());
uint64 Value_Offset;
if (version > 430027)
uint64 nameHash;
local string type <hidden=true> = "";
//record if value is unique or not:
local ubyte uniqueOffset <hidden=true> = false;
local uint offsetIdx <hidden=true> = 0;
if (Value_Offset > FTell() && Value_Offset < FileSize() && AttributeInfo.type > 10) {
for (k=0; k<10000; k++) {
if (Value_Offset == offsets[k] || offsets[k] == 0) {
if (offsets[k] == 0)
uniqueOffset = true;
break;
}
}
if (uniqueOffset == true) {
offsets[offsetCounter] = Value_Offset;
offsetIdx = offsetCounter;
offsetCounter += 1;
}
FSeek(Value_Offset);
} else
FSeek(startof(Value_Offset));
uniqueOffset = false; //(so that the writer can change it to true after adding a unique one)
local ubyte isPointer;
switch (AttributeInfo.type) {
case 1:
type = "bool";
uint32 Value;
break;
case 3:
case 5:
case 6: //RE3
case 7:
case 4: //UV
type = "int";
uint32 Value;
break;
case 10:
type = "float"; FSkip(4);
float Value;
break;
case 14:
case 43: //(RE3)
type = "string";
string Value <open=suppress>;
isPointer = true;
break;
case 13:
case 32: //filepath
// case 34: //string (RE3)
type = "wstring";
wstring Value <open=suppress>;
isPointer = true;
break;
case 34: // guid
type = "guid";
GUID value;
isPointer = true;
break;
case 22:
case 26:
type = "vector4";
struct {
float Red <name="X">, Green <name="Y">, Blue <name="Z">;
if (Name != "Position" && Name != "Scale")
float Alpha <name="W">;
else local float Value_W <hidden=true>;
} Value;
isPointer = true;
break;
case 21: //RE3
case 31: //vector3
type = "vector3";
struct {
float Red <name="X">, Green <name="Y">, Blue <name="Z">;
} Value;
isPointer = true;
break;
case 24: //color (bytes)
type = "color";
colorType = 1;
readColor();
isPointer = true;
break;
case 27:
case 28: //color (floats)
type = "color";
colorType = 0;
readColor();
isPointer = true;
break;
case 35:
type = "rangeI";
struct {
int s, r;
} Value;
isPointer = true;
break;
default:
break;
}
if (exists(Value)) {
local uint valueSz <hidden=true> = FTell() - startof(Value);
FSeek(startof(Value));
uchar bytes[valueSz] <hidden=true>;
} else
local uint valueSz <hidden=true> = 0;
FSeek(startof(this)+24 + 8 * (version > 430027));
//if (!exists(Value))
// Printf(assertFailed);
} ATTRIBUTE <name=ReadATTRIBUTENAME, read=ReadATTRIBUTE, write=WriteATTRIBUTE, optimize=false>; //
string ReadATTRIBUTENAME (ATTRIBUTE &input) {
if (!exists(input.Value)) {
return ("*" + input.Name);
} return input.Name;
}
string ReadATTRIBUTE (ATTRIBUTE &input) {
string value = "";
if (exists(input.Value)) {
if (input.type == "float") {
SPrintf(value, "%f", input.Value);
} else if (input.type == "bool") {
input.Value == false ? value = "False" : value = "True";
} else if (input.type == "int") {
SPrintf(value, "%g", input.Value);
} else if (input.type == "color") {
SPrintf(value, "[%g, %g, %g, %g]", input.Value.Red, input.Value.Green, input.Value.Blue, input.Value.Alpha);
} else if (exists(input.Value.Blue) && !exists(input.Value.Alpha)) {
SPrintf(value, "[%g, %g, %g]", input.Value.Red, input.Value.Green, input.Value.Blue);
} else if (exists(input.Value.Blue) && exists(input.Value.Alpha)) {
SPrintf(value, "[%g, %g, %g, %g]", input.Value.Red, input.Value.Green, input.Value.Blue, input.Value.Alpha);
} else if (input.type == "wstring" || input.type == "string") {
value = input.Value;
}
}
return (value);
}
void WriteATTRIBUTE(ATTRIBUTE &input, string s) {
if (exists(input.Value)) {
local ubyte doWrite = false;
/*if ((exists(input.Value_Offset) && input.uniqueOffset == false) ||
(doesExist(input.type,"string") && sizeof(s) > sizeof((string)input.Value))) {
for (j=0; j<10000; j++)
if (offsets[j] == input.Value_Offset) {
if (input.offsetIdx == j)
break;
doWrite = true;
input.uniqueOffset = false;
local uint64 writePos = FileSize();
input.Value_Offset = writePos;
break;
} else if (offsets[j] == 0)
break;
}*/
if (input.type == "string") {
if (exists(writePos)) {
InsertBytes(writePos, sizeof(s), 0);
WriteString(writePos, s);
} else input.Value = s;
} else if (input.type == "wstring") {
if (exists(writePos)) {
InsertBytes(writePos, sizeof((wstring)s), 0);
WriteWString(writePos, (wstring)s);
} else input.Value = (wstring)s;
} else {
if (doWrite)
InsertBytes(writePos, 4, 0);
if (input.type == "float") {
if (doWrite)
WriteFloat(writePos, Atof(s));
else input.Value = Atof(s);
} else if (input.type == "bool") {
if (Lower(s) == "true") s = "1";
else if (Lower(s) == "false") s = "0";
if (doWrite)
WriteUInt(writePos, Atoi(s));
else input.Value = Atoi(s);
} else if (input.type == "int") {
if (doWrite)
WriteUInt(writePos, Atoi(s));
else input.Value = Atoi(s);
} else if ((input.type == "color" || input.type == "vector3" || input.type == "vector4")) {
if (doWrite) {
if (sizeof(input.Value) > 4) {
if (input.type == "vector3" || input.Name == "Position" || input.Name == "Scale")
InsertBytes(writePos, 8, 0);
else
InsertBytes(writePos, 12, 0);
local float x, y, z, w;
SScanf( s, "%g %g %g %g", x, y, z, w);
if (w == 0) w = 1;
WriteFloat(writePos, x);
WriteFloat(writePos+4, y);
WriteFloat(writePos+8, z);
if (input.type == "vector4" || input.type == "color")
WriteFloat(writePos+12, w);
} else {
WriteUByte(writePos, Atoi(s));
WriteUByte(writePos+1, Atoi(s));
WriteUByte(writePos+2, Atoi(s));
WriteUByte(writePos+3, 255);
}
} else {
if (exists(input.Value.Alpha)) {
if (doesExist(s, ",")) {
SScanf( s, "%g,%g,%g,%g", input.Value.Red, input.Value.Green, input.Value.Blue, input.Value.Alpha);
} else { SScanf( s, "%g %g %g %g", input.Value.Red, input.Value.Green, input.Value.Blue, input.Value.Alpha); }
} else if (doesExist(s, ",")) {
SScanf( s, "%g,%g,%g", input.Value.Red, input.Value.Green, input.Value.Blue);
} else { SScanf( s, "%g %g %g", input.Value.Red, input.Value.Green, input.Value.Blue); }
}
}
}
if (doWrite)
MessageBox( idOk, "Insert Data", "New Unique value added at End of File\nRefresh the template with F5 to edit it");
}
}
typedef struct {
if (HEADER.guiVersion < 900043) {
GUID guid;
} else {
uint64 hash;
}
} GuiNodeID <optimize=true, read=(exists(guid) ? GUIDToString(guid) : hash)>;
typedef struct {
GuiNodeID ID, ContainerID;
if (HEADER.guiVersion >= 400022) {
GUID Guid3;
}
struct StringRead Name(-1,0,0,0,0);
struct StringRead className(-1,0,0,1,0);
uint64 subStructOffs;
if (HEADER.guiVersion >= 540034) uint64 reorderIndicesOffset;
uint64 extraAttributesOffset;
// if (HEADER.guiVersion == 430027 || HEADER.guiVersion >= 620035) uint64 nullOffset;
if (HEADER.guiVersion >= 430027) uint64 uknOffset;
uint64 elementDataOffset;
if (HEADER.guiVersion >= 430027) uint64 uknNum;
} SUBELEMENTINFO <read=ReadSUBELEMENTINFO>;
string ReadSUBELEMENTINFO (SUBELEMENTINFO &input) { return input.className.String; }
typedef struct {
SUBELEMENTINFO SubElementInfo;
FSeek(SubElementInfo.subStructOffs);
uint64 itemCount;
if (itemCount)
struct {
ATTRIBUTE Attribute[itemCount];
} Attributes <open=true>;
if (exists(SubElementInfo.reorderIndicesOffset)) {
FSeek(SubElementInfo.reorderIndicesOffset);
if (HEADER.guiVersion >= 54000)
{
uint16 orderIndices[itemCount];
}
}
FSeek(SubElementInfo.extraAttributesOffset);
uint64 extraAttributeCount;
if (extraAttributeCount > 0) {
struct {
ATTRIBUTE Attribute[extraAttributeCount];
} ExtraAttributes <open=true>;
}
if (exists(SubElementInfo.uknOffset) && SubElementInfo.uknOffset) {
FSeek(SubElementInfo.uknOffset);
uint64 uknCount;
struct {
GuiNodeID StateId;
// uint64 asciiNameOffset;
// typedef struct(int64 atAddress, int64 addOffset, ubyte isAbsolute, ubyte isUTF8, ubyte isUint32)
struct StringRead AsciiName(-1, 0, 0, 1, 0);
uint64 offs3;
struct StringRead UnicodeName(-1, 0, 0, 0, 0);
} ExtraStateReference[uknCount] <optimize=true>;
}
BLANK blank; FSkip(-1);
} SUBELEMENT <name="Element", read=ReadSUBELEMENT>;
string ReadSUBELEMENT (SUBELEMENT &input) { return input.SubElementInfo.Name.String; }
typedef struct {
GuiNodeID Id;
uint64 nameOffs, viaOffs, elementsOffset, clipsOffset;
if (HEADER.guiVersion >= 900043) {
uint64 offsPrag1;
uint64 attributesOffset2;
}
pos = FTell();
if (elementsOffset > 0) {
FSeek(elementsOffset);
uint64 subElementCount;
if (subElementCount && HEADER.guiVersion < 900043)
uint64 offs[subElementCount];
} else {
local uint64 subElementCount = 0;
}
FSeek(clipsOffset);
uint32 totalClipCount, clipCount;
if (totalClipCount)
uint64 offset[totalClipCount];
if (exists(offsPrag1) && offsPrag1 > 0) {
FSeek(offsPrag1);
uint64 count1;
struct {
GuiNodeID id;
struct StringRead Name(-1,0,0,0,0);
struct StringRead Tag(-1,0,0,1,0);
struct StringRead State(-1,0,0,0,0);
uint32 nameUtf16Hash;
ubyte propertyType;
ubyte uknByte;
uint16 padding;
uint64 dataOffset;
} ContainerExtraData1[count1] <optimize=false, read=ReadStringRead(Name)>;
}
if (exists(attributesOffset2) && attributesOffset2 > 0) {
FSeek(attributesOffset2);
uint64 count2;
struct {
GuiNodeID id;
uint64 listOffset;
uint32 propertyType;
int32 uknInt;
struct StringRead ClassName(-1,0,0,1,0);
struct StringRead Name(-1,0,0,1,0);
local uint64 p = FTell();
FSeek(listOffset);
uint64 itemCount;
uint64 IDs[itemCount];
FSeek(p);
} ContainerExtraData2[count2] <optimize=false, read=ReadStringRead(Name)>;
}
FSeek(nameOffs);
wstring Name;
FSeek(viaOffs);
string className;
FSeek(pos);
} ELEMENTINFO <name="ElementInfo", read=ReadELEMENTINFO>;
string ReadELEMENTINFO (ELEMENTINFO &input) { return input.className; }
typedef struct {
ELEMENTINFO ElementInfo;
if (HEADER.guiVersion < 900043) {
for (j=0; j<ElementInfo.subElementCount ; j++){
FSeek(ElementInfo.offs[j]);
SUBELEMENT SubElement;
}
} else {
FSeek(ElementInfo.elementsOffset + 8);
for (j=0; j<ElementInfo.subElementCount ; j++){
SUBELEMENT SubElement;
FSeek(startof(SubElement.SubElementInfo.uknNum) + 8);
}
}
if (DisplayCLIP && ElementInfo.totalClipCount) {
FSeek(ElementInfo.offset[0]);
struct CLIP {
local int z <hidden=true>;
for (z=0; z<ElementInfo.totalClipCount; z++) {
FSeek(ElementInfo.offset[z]);
struct CLIP_ENTRY Clip;
}
if (FTell()<=startof(this))
FSeek(startof(Clip[0])+sizeof(Clip[0]));
} Clip <name="CLIP Data", read=ReadCLIP>;
}
FSeek(startof(ElementInfo)+sizeof(ElementInfo));
} ELEMENT <name="Container", read=ReadELEMENT>;
string ReadELEMENT (ELEMENT &input) { return input.ElementInfo.Name; }
string ReadCLIP (CLIP &input) { return ReadCLIP_ENTRY(input.Clip[0]); }
//functions
int doesExist(string str, string term) {
local int matchSize;
return (RegExSearch(str, term, matchSize, 0) != -1);
}
int detectedFloat(uint64 offset) {
if (offset+4 <= FileSize())
if (ReadUByte(offset+3) < 255)
if (Abs(ReadFloat(offset)) > 0.0000001)
if (Abs(ReadFloat(offset)) < 1000000)
return true;
return false;
}
string Lower(string stringIn) {
local string s2 = stringIn;
for (k=0; k < sizeof(stringIn); k++) {
s2[k] = ToLower(stringIn[k]);
}
return s2;
}
void readColor() {
if (colorType == 1) { //for reader
COLORBYTE Value <hidden=true>, Blue <hidden=true>, Green <hidden=true>, Alpha <hidden=true>;
} else {
float Value <hidden=true>, Blue <hidden=true>, Green <hidden=true>, Alpha <hidden=true>;
}
FSeek(startof(Value));
if (colorType) {
R = ReadUByte(FTell());
G = ReadUByte(FTell()+1);
B = ReadUByte(FTell()+2);
A = ReadUByte(FTell()+3);
} else {
R = ReadFloat(FTell()) * 255.0f + 0.5;
G = ReadFloat(FTell()+4) * 255.0f + 0.5;
B = ReadFloat(FTell()+8) * 255.0f + 0.5;
A = ReadFloat(FTell()+12) * 255.0f + 0.5;
}
SetBackColor((B<<16) | (G<<8) | (R));
struct { //in a struct for easy copy+paste
SetForeColor(R);
if (colorType) COLORBYTE Red; else float Red;
SetForeColor(G<<8);
if (colorType) COLORBYTE Green; else float Green;
SetForeColor(B<<16);
if (colorType) COLORBYTE Blue; else float Blue;
SetForeColor((A<<16) + (A<<8) + A);
if (colorType) COLORBYTE Alpha; else float Alpha;
SetForeColor(cGreen);
SetBackColor(cNone);
} Value <name="Color", open=true>;
FSkip(-1); BLANK blank;
}
//generic string reader
typedef struct(int64 atAddress, int64 addOffset, ubyte isAbsolute, ubyte isUTF8, ubyte isUint32)
{
if (!isAbsolute) {
if (atAddress != -1)
FSeek(atAddress);
if (isUint32)
uint32 strOffset;
else
uint64 strOffset;
FSeek(strOffset + addOffset);
} else
FSeek(atAddress + addOffset);
if (!exists(strOffset) || strOffset > 0)
if (isUTF8)
string String;
else
wstring String;
if (exists(strOffset)) {
if (atAddress == -1 || startof(this) == atAddress)
FSeek(startof(strOffset) + 8 - isUint32 * 4);
else
FSeek(startof(this)+1);
}
} StringRead <read=ReadStringRead, write=WriteStringRead>;
wstring ReadStringRead(StringRead &st) {
if (exists(st.String))
return st.String;
local string s;
if (exists(st.strOffset))
SPrintf(s, "%i", st.strOffset);
return s;
}
void WriteStringRead(StringRead &st, string s) {
if (exists(st.String))
st.String = s;
else if (exists(st.strOffset))
st.strOffset = Atoi(s);
}
typedef struct {
uchar uuid[16];
} rGUID <read=ReadrGUID>;
string ReadrGUID (rGUID &g) {
local char s[37];
SPrintf(s,
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
g.uuid[0], g.uuid[1], g.uuid[2], g.uuid[3], g.uuid[4], g.uuid[5], g.uuid[6], g.uuid[7],
g.uuid[8], g.uuid[9], g.uuid[10], g.uuid[11], g.uuid[12], g.uuid[13], g.uuid[14], g.uuid[15]
);
return s;
}
typedef struct OptimizedKey {
float frame;
uint32 interpolationType : 8;
uint32 flags : 8;
uint32 value : 16;
};
typedef struct KEY {
float frame;
float rate;
enum {
InterpolationType_Unknown = 0x0,
InterpolationType_Discrete = 0x1,
InterpolationType_Linear = 0x2,
InterpolationType_Event = 0x3,
InterpolationType_Slerp = 0x4,
InterpolationType_Hermite = 0x5,
InterpolationType_AutoHermite = 0x6,
InterpolationType_Bezier = 0x7,
InterpolationType_AutoBezier = 0x8,
InterpolationType_OffsetFrame = 0x9,
InterpolationType_OffsetSec = 0xA,
InterpolationType_PassEvent = 0xB,
InterpolationType_Bezier3D = 0xC,
InterpolationType_Range = 0xD,
InterpolationType_DiscreteToEnd = 0xE,
} interpolationType : 8;
uint32 instanceValue : 1;
uint32 reserved : 23 <hidden=true>;
uint32 reserved2 <hidden=true>;
if (exists(parentof(this).PropInfo.DataType)) {
switch (parentof(this).PropInfo.DataType) {
//PropertyType_Unknown:
case PropertyType_Bool:
case PropertyType_S8:
byte value; break;
case PropertyType_U8:
ubyte value; break;
case PropertyType_S16:
int16 value; break;
case PropertyType_U16:
uint16 value; break;
case PropertyType_S32:
int32 value; break;
case PropertyType_U32:
uint32 value; break;
case PropertyType_S64:
int64 value; break;
case PropertyType_U64:
uint64 value; break;
case PropertyType_F32:
double value; break;
case PropertyType_F64:
double value; break;
case PropertyType_Str8:
case PropertyType_Enum:
uint64 value;
FSeek(clipHeader.namesOffsExtra[1] + start + value);
string String;
break;
case PropertyType_Guid:
case PropertyType_Str16:
case PropertyType_Asset:
uint64 value;
FSeek(clipHeader.unicodeNamesOffs + start + value*2);
wstring String;
break;
default:
int64 value;
break;
}
} else {
int64 value;
FSkip(-8);
double value;
}
FSeek(startof(this)+keySize - 8);
uint64 hermiteKeyIndex;
};
typedef KEY clipKey <name=ReadKeyName, read=ReadClipKey, write=WriteClipKey>;
string ReadKeyName (clipKey &k) { string s; SPrintf(s, "Key@%g ", k.frame); return s; }
string ReadClipKey (clipKey &k) {
local string s;
if (exists(k.String)) {
s += (wstring)k.String;
} else if (ReadInt64(startof(k.value)) != 0 && (detectedFloat(startof(k.value)) || detectedFloat(startof(k.value)+4)))
SPrintf(s, "%lf", ReadDouble(startof(k.value)));
else
SPrintf(s, "%i", ReadInt(startof(k.value)));
if (exists(k.interpolationHermiteValue))
SPrintf(s, "%s (%lf)", s, k.interpolationHermiteValue);
return s;
}
void WriteClipKey(clipKey &k, string s) {
if (exists(parentof(k).PropInfo.DataType) && parentof(k).PropInfo.DataType == PropertyType_F32)
WriteDouble(startof(k.value), Atof(s));
else
WriteInt64(startof(k.value), Atoi(s));
}
enum <ubyte> PropertyType
{
PropertyType_Unknown = 0x0,
PropertyType_Bool = 0x1,
PropertyType_S8 = 0x2,
PropertyType_U8 = 0x3,
PropertyType_S16 = 0x4,
PropertyType_U16 = 0x5,
PropertyType_S32 = 0x6,
PropertyType_U32 = 0x7,
PropertyType_S64 = 0x8,
PropertyType_U64 = 0x9,
PropertyType_F32 = 0xA,
PropertyType_F64 = 0xB,
PropertyType_Str8 = 0xC,
PropertyType_Str16 = 0xD,
PropertyType_Enum = 0xE,
PropertyType_Quaternion = 0xF,
PropertyType_Array = 0x10,
PropertyType_NativeArray = 0x11,
PropertyType_Class = 0x12,
PropertyType_NativeClass = 0x13,
PropertyType_Struct = 0x14,
PropertyType_Vec2 = 0x15,
PropertyType_Vec3 = 0x16,
PropertyType_Vec4 = 0x17,
PropertyType_Color = 0x18,
PropertyType_Range = 0x19,
PropertyType_Float2 = 0x1A,
PropertyType_Float3 = 0x1B,
PropertyType_Float4 = 0x1C,
PropertyType_RangeI = 0x1D,
PropertyType_Point = 0x1E,
PropertyType_Size = 0x1F,
PropertyType_Asset = 0x20,
PropertyType_Action = 0x21,
PropertyType_Guid = 0x22,
PropertyType_Uint2 = 0x23,
PropertyType_Uint3 = 0x24,
PropertyType_Uint4 = 0x25,
PropertyType_Int2 = 0x26,
PropertyType_Int3 = 0x27,
PropertyType_Int4 = 0x28,
PropertyType_OBB = 0x29,
PropertyType_Mat4 = 0x2A,
PropertyType_Rect = 0x2B,
PropertyType_PathPoint3D = 0x2C,
PropertyType_Plane = 0x2D,
PropertyType_Sphere = 0x2E,
PropertyType_Capsule = 0x2F,
PropertyType_AABB = 0x30,
PropertyType_Nullable = 0x31,
PropertyType_Sfix = 0x32,
PropertyType_Sfix2 = 0x33,
PropertyType_Sfix3 = 0x34,
PropertyType_Sfix4 = 0x35,
PropertyType_AnimationCurve = 0x36,
PropertyType_KeyFrame = 0x37,
PropertyType_GameObjectRef = 0x38,
};
typedef struct {
struct PROPINFO {
if (Version < 486)
uint32 pad <hidden=true>;
if (Version == 60)
int32 uknRE7;
float ValueA <name="Value A (Start)">;
float ValueB <name="Value B (End)">;
if (Version==60) {
uint32 U32_1;
//uint32 U32_2;
} else {
uint32 U32_1;
uint32 U32_2;
}
if (Version >= 993) {
uint64 nameOffset;
uint64 dataOffset;
uint64 ChildStartIndex;
ushort ChildMembershipCount;
short arrayIndex;
ubyte speedPointNum;
PropertyType DataType;
ubyte uknByte2;
ubyte uknByte3;
uint64 lastKeyOffset;
} else if (Version == 486) { //RE8
uint64 nameOffset;
uint64 dataOffset;
uint64 ChildStartIndex;
ushort ChildMembershipCount;
short arrayIndex;
short speedPointNum;
PropertyType DataType;
ubyte uknByte;
uint64 lastKeyOffset;
uint64 speedPointOffset;
uint64 clipPropertyOffset;
} else {
PropertyType DataType;
ubyte uknCount <hidden=true>;
FSkip(2);
if (Version == 99)
uint64 RE3hash;
else
FSkip(8);
if (Version == 60) {
FSkip(8);
uint64 uknRE7;
}
uint64 nameOffset, nameOffset;
if (Version == 60) {
uint64 uknRE7;
FSkip(8);
}
FSkip(8);
if (Version != 60)
FSkip(16);
uint64 ChildStartIndex, ChildMembershipCount <write=InsertClipKey>;
if (Version == 60) {
FSkip(8);
uint64 uknRE7;
}
}
FSeek(clipHeader.namesOffsExtra[1] + start + PropInfo.nameOffset[0]);
string FunctionName <hidden=false>;
if (Version < 486 && PropInfo.nameOffset[1] > 0) {
FSeek(clipHeader.unicodeNamesOffs + start + PropInfo.nameOffset[1]*2);
wstring wFunctionName <hidden=false>;
}
FSeek(startof(this)+propSize);
} PropInfo <read=ReadPROPINFO, name="[PropInfo]">;
switch (PropInfo.DataType) {
case PropertyType_NativeArray:
case PropertyType_Nullable:
case PropertyType_NativeClass:
case PropertyType_Range:
case PropertyType_RangeI:
case PropertyType_Vec4:
case PropertyType_Vec3:
case PropertyType_Vec2:
case PropertyType_Float4:
case PropertyType_Quaternion:
case PropertyType_OBB:
case PropertyType_Mat4:
case PropertyType_Class:
case PropertyType_Array:
case PropertyType_Struct:
case PropertyType_Color:
case PropertyType_Float2:
case PropertyType_Float3:
case PropertyType_Point:
FSeek(clipHeader.propertiesOffs + start + (propSize*PropInfo.ChildStartIndex));
if (PropInfo.ChildMembershipCount)
struct PROPERTY ChildProp[PropInfo.ChildMembershipCount] <optimize=false>;
break;
default:
FSeek(clipHeader.keysOffs + start + (keySize*PropInfo.ChildStartIndex));
if (PropInfo.ChildMembershipCount){
Type = PropInfo.DataType;
struct clipKey Keys[PropInfo.ChildMembershipCount] <optimize=false>;
}
break;
}
FSeek(startof(this)+propSize);
} PROPERTY <name=ReadPROPERTYNAME, read=ReadPROPERTY, write=WritePROPERTY>;
string ReadPROPERTY (PROPERTY &input) {
string s = "";
SPrintf(s, "[%i, %i]", input.PropInfo.ValueA, input.PropInfo.ValueB );
return s;
}
string ReadPROPERTYNAME (PROPERTY &input) {
local string fnName;
if (exists(input.PropInfo.FunctionName)) {
fnName = input.PropInfo.FunctionName;
if (exists(input.PropInfo.wFunctionName))
fnName = input.PropInfo.wFunctionName;
if (exists(input.ChildProp)) {
local string s;
SPrintf(s, "*[%ix] %s", input.PropInfo.ChildMembershipCount, fnName );
return s;
} else if (exists(input.Keys))
return "* " + fnName;
else
return fnName;
}
return "";
}
void WritePROPERTY (PROPERTY &f, string s ) { SScanf(s, "%g %g", f.PropInfo.ValueA, f.PropInfo.ValueB); }
string ReadPROPINFO(PROPINFO &p) { return EnumToString(p.DataType); }
//General offset fixer
void FixOffsets(uint64 tell, uint64 limitPoint, uint64 relStart, uint64 relEnd, uint64 insertPoint, uint64 addedSz, int doInt32) {
if (tell > limitPoint)
return;
local uint64 pos = FTell();
local int64 tmp;
local int varSize = 8 + -4 * doInt32;
local int64 startBound = insertPoint - relStart - keySize;
local int64 endBound = relEnd - relStart;
FSeek(tell);
while(FTell() + varSize <= limitPoint) {
if (FTell()+varSize > FileSize())
break;
if (doInt32==1)
tmp = ReadInt(FTell());
else
tmp = ReadInt64(FTell());
if (tmp >= startBound && tmp < endBound) {
if (doInt32==true)
tmp = WriteUInt(FTell(), tmp+addedSz);
else
WriteUInt64(FTell(), tmp + addedSz);
}
FSkip(varSize);
}
}
//Inserts a new clip Key when increasing ChildMembershipCount in [PropInfo]:
void InsertClipKey(uint64 &ch, string s) {
local int newKeys = Atoi(s) - ch;
local int insertPt, clipStart, clipEnd;
local int z;
if (newKeys > 0 && !exists(parentof(parentof(ch)).ChildProp)) {
local int ii, jj, kk;
while(exists(Elements.Element[ii])) {
jj=0;
while(exists(Elements.Element[ii].Clip.Clip[jj])) {
if (startof(Elements.Element[ii].Clip.Clip[jj]) < startof(ch) &&
startof(Elements.Element[ii].Clip.Clip[jj]) + sizeof(Elements.Element[ii].Clip.Clip[jj]) > startof(ch)) {
clipStart = startof(Elements.Element[ii].Clip.Clip[jj]);
clipEnd = startof(Elements.Element[ii].Clip.Clip[jj]) + sizeof(Elements.Element[ii].Clip.Clip[jj]);
if (exists(Elements.Element[ii].Clip.Clip[jj].Keys)) {
if (ch) {
insertPt = startof(Elements.Element[ii].Clip.Clip[jj].Keys[parentof(ch).ChildStartIndex]) + keySize * ch;
} else {
insertPt = startof(Elements.Element[ii].Clip.Clip[jj].Names);
parentof(ch).ChildStartIndex = Elements.Element[ii].Clip.Clip[jj].clipHeader.numKeys;
}
} else
insertPt = startof(Elements.Element[ii].Clip.Clip[jj].Names);
for (z=0; z<newKeys; z++) {
FixOffsets(0, FileSize(), 0, FileSize(), insertPt, keySize, false);
FixOffsets(clipStart, clipEnd, clipStart, clipEnd, insertPt, keySize, false);
InsertBytes(insertPt, keySize, 0);
insertPt += keySize;
Elements.Element[ii].Clip.Clip[jj].clipHeader.numKeys++;
ch++;
}
MessageBox( idOk, "Insert Data", "Press F5 to refresh the template and fix template results");
return;
}
jj++;
}
ii++;
}
} else
ch = Atoi(s);
}
typedef struct {
if (Version < 486) {
uint32 nodeCount, propCount;
float Start_Frame, End_Frame;
GUID guid1, guid2;
FSkip(8);
} else {
ushort nodeCount;
ushort propCount;
uint nodeType : 8;
uint padding : 24 <hidden=true>;
}
uint64 hash;
uint64 nameOffset, nameOffset, firstPropIdx;
if (Version == 85)
uint64 firstPropIdx;
pos = FTell();
if (Version == 99) {
FSeek(clipHeader.unicodeNamesOffs + start + nameOffset[0] * 2);
wstring name;
} else if (Version >= 486) {
FSeek(clipHeader.unicodeNamesOffs + start + nameOffset[0] * 2);
wstring name;
} else {
FSeek(clipHeader.namesOffsExtra[1] + start + nameOffset[0]);