forked from TES5Edit/TES5Edit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxDump.dpr
1676 lines (1517 loc) · 55.9 KB
/
xDump.dpr
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
{******************************************************************************
This Source Code Form is subject to the terms of the Mozilla Public License,
v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain
one at https://mozilla.org/MPL/2.0/.
*******************************************************************************}
{$I xdDefines.inc}
{$IFDEF EXCEPTION_LOGGING_ENABLED}
// JCL_DEBUG_EXPERT_GENERATEJDBG OFF
// JCL_DEBUG_EXPERT_INSERTJDBG ON
// JCL_DEBUG_EXPERT_DELETEMAPFILE ON
{$ENDIF}
program xDump;
{$APPTYPE CONSOLE}
uses
{$IFDEF EXCEPTION_LOGGING_ENABLED}
nxExceptionHook,
{$ENDIF}
TypInfo,
Classes,
SysUtils,
Windows,
Registry,
IniFiles,
ZlibEx,
lz4,
wbBSA in 'Core\wbBSA.pas',
wbCommandLine in 'Core\wbCommandLine.pas',
wbSort in 'Core\wbSort.pas',
wbInterface in 'Core\wbInterface.pas',
wbSaveInterface in 'Core\wbSaveInterface.pas',
wbImplementation in 'Core\wbImplementation.pas',
wbLocalization in 'Core\wbLocalization.pas',
wbHelpers in 'Core\wbHelpers.pas',
wbLoadOrder in 'Core\wbLoadOrder.pas',
wbHardcoded in 'Core\wbHardcoded.pas',
wbDefinitionsCommon in 'Core\wbDefinitionsCommon.pas',
wbDefinitionsFNV in 'Core\wbDefinitionsFNV.pas',
wbDefinitionsFNVSaves in 'Core\wbDefinitionsFNVSaves.pas',
wbDefinitionsFO3 in 'Core\wbDefinitionsFO3.pas',
wbDefinitionsFO3Saves in 'Core\wbDefinitionsFO3Saves.pas',
wbDefinitionsFO4 in 'Core\wbDefinitionsFO4.pas',
wbDefinitionsFO4Saves in 'Core\wbDefinitionsFO4Saves.pas',
wbDefinitionsFO76 in 'Core\wbDefinitionsFO76.pas',
wbDefinitionsTES3 in 'Core\wbDefinitionsTES3.pas',
wbDefinitionsTES4 in 'Core\wbDefinitionsTES4.pas',
wbDefinitionsTES4Saves in 'Core\wbDefinitionsTES4Saves.pas',
wbDefinitionsTES5 in 'Core\wbDefinitionsTES5.pas',
wbDefinitionsTES5Saves in 'Core\wbDefinitionsTES5Saves.pas';
{$R *.res}
{$MAXSTACKSIZE 2097152}
const
IMAGE_FILE_LARGE_ADDRESS_AWARE = $0020;
{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}
var
StartTime : TDateTime;
DumpGroups : TStringList;
SkipChildGroups : TStringList;
DumpChapters : TStringList;
DumpForms : TStringList;
DumpCount : Integer;
DumpMax : Integer;
DumpCheckReport : Boolean = False;
DumpSize : Boolean = False;
DumpHidden : Boolean = False;
procedure ReportProgress(const aStatus: string);
begin
WriteLn(ErrOutput, FormatDateTime('<hh:nn:ss.zzz>', Now - StartTime), ' ', aStatus);
end;
type
TExportFormat = (efUESPWiki, efRaw);
TwbDefProfile = string;
TwbExportPass = ( epRead, epSimple, epShared, epChapters, epRemaining, epNothing);
var
wbDefProfiles : TStringList = nil;
function StrToTExportFormat(aFormat: string): TExportFormat;
begin
Result := efRaw;
if Uppercase(aFormat)='RAW' then
Result := efRaw
else if Uppercase(aFormat)='UESPWIKI' then
Result := efUESPWiki;
end;
function UESPName(aName: String): String;
begin
while Pos(' ', aName)>0 do
aName[Pos(' ', aName)] := '_';
Result := aName;
end;
function UESPType(aType: String): String;
function UESParrayType(aType: String): String; forward;
function UESPsingleType(aType, aStandard, aResult: String): String;
var
i: Integer;
l: Integer;
begin
i := Pos(UpperCase(aStandard), Uppercase(aType));
if i>0 then begin
Result := '';
l := Length(aStandard);
if i>1 then begin
Result := Copy(aType, 1, i-1);
Delete(aType, 1, i+l-1);
end else
Delete(aType, 1, l);
Result := Result + aResult + aType;
end else
Result := aType;
end;
function UESParrayCount(aType: String): String;
var
i: Integer;
c: String;
begin
i := Pos('_', aType);
if i>1 then begin
c := Copy(aType, 1, i-1);
Delete(aType, 1, i);
end else
c := '';
Result := '_'+aType+'['+c+']';
end;
function UESParrayType(aType: String): String;
const
cArray = '_ARRAY';
cof = '_OF_';
var
i: Integer;
j : Integer;
l: Integer;
t: String;
begin
i := Pos(cArray, UpperCase(aType));
l := Length(cArray);
if (i>0) and ((i+l-1) = Length(aType)) then begin
Delete(aType, i, l);
j := Pos(cOf, UpperCase(aType));
if j>1 then begin
Result := Copy(aType, 1, j-1);
Delete(aType, 1, j+Length(cOf)-1);
t := UESParrayCount(aType);
Result := Result + t;
end;
end else
Result := aType;
end;
begin
Result := UESPName(aType);
Result := UESParrayType(Result);
Result := UESPsingleType(Result, 'Unsigned_Bytes', 'uint8');
Result := UESPsingleType(Result, 'Signed_Bytes', 'int8');
Result := UESPsingleType(Result, 'Bytes', 'int8');
Result := UESPsingleType(Result, 'Unsigned_Byte', 'uint8');
Result := UESPsingleType(Result, 'Signed_Byte', 'int8');
Result := UESPsingleType(Result, 'Byte', 'int8');
Result := UESPsingleType(Result, 'Unsigned_DWord', 'uint32');
Result := UESPsingleType(Result, 'Signed_DWord', 'int32');
Result := UESPsingleType(Result, 'DWord', 'int32');
Result := UESPsingleType(Result, 'Unsigned_Word', 'uint16');
Result := UESPsingleType(Result, 'Signed_Word', 'int16');
Result := UESPsingleType(Result, 'Word', 'int16');
Result := UESPsingleType(Result, 'Float', 'float32');
Result := UESPsingleType(Result, 'FormID', 'formid');
end;
const
UESPWikiTable = '{| class="wikitable" border="1" width="100%"'+#13+#10+
'! width="3%" | [[Tes5Mod:File Format Conventions|C]]'+#13+#10+
'! width="10%" | SubRecord'+#13+#10+
'! width="15%" | Name'+#13+#10+
'! width="15%" | [[Tes5Mod:File Format Conventions|Type/Size]]'+#13+#10+
'! width="57%" | Info';
UESPWikiClose ='|}'+#13+#10;
function AnchorProfile(aFormat: TExportFormat; aIndent, aProfile: String; useProfile: Boolean; aName, aType: String): String;
begin
case aFormat of
efUESPWiki: begin
if aIndent='' then
Result := '=== [[Tes5Mod:Save File Format/'+aProfile+'|'+UESPName(aName)+']] ==='+#13+#10+UESPWikiTable
else begin
Result := '|-'+#13+#10+'|'+UESPName(aName)+#13+#10+'|';
if useProfile then
Result := Result+'[[Tes5Mod:Save File Format/'+aProfile+'|'+UESPType(aType)+']]'
else
Result := Result+UESPType(aType);
Result := Result+#13+#10+'|';
end;
end;
efRaw: begin
Result := aIndent+aName+' as '+aType;
if useProfile then Result := Result+' ['+aProfile+']';
end;
end;
end;
procedure AddProfile(aProfile: String);
var
i : Integer;
begin
i := wbDefProfiles.IndexOf(aProfile);
if i >= 0 then begin
wbDefProfiles.Objects[i] := Pointer(Integer(wbDefProfiles.Objects[i])+1);
end else begin
wbDefProfiles.AddObject(aProfile, Pointer(1));
end;
end;
function FindProfile(aProfile: String): Integer;
var
i : Integer;
begin
i := wbDefProfiles.IndexOf(aProfile);
if i >= 0 then begin
Result := Integer(wbDefProfiles.Objects[i]);
end else
Result := 0;
end;
procedure MarkProfile(aProfile: String);
var
i : Integer;
begin
i := wbDefProfiles.IndexOf(aProfile);
if i >= 0 then
wbDefProfiles.Objects[i] := Pointer(-1);
end;
procedure LockProfile(aProfile: String);
var
i : Integer;
begin
i := wbDefProfiles.IndexOf(aProfile);
if i >= 0 then
wbDefProfiles.Objects[i] := Pointer(-2);
end;
procedure ProfileContainer(aFormat: TExportFormat; aElement: IwbNamedDef; var aProfile: String;
Pass: TwbExportPass; aIndent: String); forward;
procedure ExportElement(aFormat: TExportFormat; aElement: IwbNamedDef; var aProfile: String;
Pass: TwbExportPass; aIndent: string = ''); forward;
procedure ExportContainer(aFormat: TExportFormat; aElement: IwbNamedDef; var aProfile: String;
Pass: TwbExportPass; aIndent: String; skipFirst: Boolean);
var
i : Integer;
j : Integer;
Profile : String;
begin
case aElement.DefType of
dtSubRecordStruct,
dtSubRecordUnion,
dtRecord :
with aElement as IwbRecordDef do
for i := 0 to Pred(MemberCount) do begin
Profile := '';
ExportElement(aFormat, Members[i], Profile, Pass, aIndent);
aProfile := aProfile + Profile;
end;
dtSubRecord :
with aElement as IwbSubRecordDef do begin
Profile := '';
ExportElement(aFormat, Value, Profile, Pass, aIndent);
aProfile := aProfile + Profile;
end;
dtString,
dtLString,
dtLenString,
dtByteArray,
dtInteger,
dtIntegerFormater,
dtFloat : ;
dtSubRecordArray :
with aElement as IwbSubRecordArrayDef do begin
Profile := '';
ExportElement(aFormat, Element, Profile, Pass, aIndent);
aProfile := aProfile + Profile;
end;
dtArray :
with aElement as IwbArrayDef do begin
Profile := '';
ExportElement(aFormat, Element, Profile, Pass, aIndent);
aProfile := aProfile + Profile;
end;
dtStruct,
dtStructChapter :
with aElement as IwbStructDef do
for i := 0 to Pred(MemberCount) do begin
Profile := '';
ExportElement(aFormat, Members[i], Profile, Pass, aIndent);
aProfile := aProfile + Profile;
end;
dtUnion :
with aElement as IwbUnionDef do begin
if skipFirst then j := 1 else j := 0;
for i := j to Pred(MemberCount) do begin
Profile := '';
ExportElement(aFormat, Members[i], Profile, Pass, aIndent);
aProfile := aProfile + Profile;
end;
end;
dtEmpty: ;
end;
end;
procedure ExportElement(aFormat: TExportFormat; aElement: IwbNamedDef; var aProfile: String;
Pass: TwbExportPass; aIndent: string = '');
var
doIt : Boolean;
skipFirst : Boolean;
theElement : IwbNamedDef;
theIndent : String;
Profile : String;
begin
doIt := False;
skipFirst := False;
theElement := aElement;
if aElement.defType in dtArrays then begin
case aElement.DefType of
dtArray: with aElement as IwbArrayDef do begin
doIt := Element.DefType in dtNonValues;
theElement := Element;
end;
dtSubRecordArray: with aElement as IwbSubRecordArrayDef do begin
doIt := Element.DefType in dtNonValues;
end;
end;
end else if aElement.defType in [dtSubrecord] then begin
with aElement as IwbSubRecordDef do begin
doIt := Value.DefType in dtNonValues;
theElement := Value;
end;
end else if aElement.defType in [dtUnion] then begin
with aElement as IwbUnionDef do if MemberCount>0 then begin
doIt := True;
skipFirst := Members[0].DefTypeName = 'Null';
end;
end else if (aElement.defType in dtNonValues) then
doIt := True;
Profile := ':' + wbDefToName(aElement)+'='+aElement.DefTypeName;
aProfile := aProfile + Profile;
if doIt then begin
Profile := '';
ProfileContainer(aFormat, theElement, Profile, Pass, aIndent);
aProfile := aProfile + Profile;
end;
Write(AnchorProfile(aFormat, aIndent, aProfile, doIt, wbDefToName(aElement), aElement.DefTypeName));
if skipFirst then Write(' Present only if ...');
WriteLn;
theIndent := aIndent + ' ';
if ((aIndent='') or (FindProfile(aProfile)<>-1)) and doIt then begin
Profile := '';
ExportContainer(aFormat, theElement, Profile, Pass, theIndent, skipFirst);
end;
if aIndent = '' then begin
case aFormat of
efUESPWiki: Write(UESPWikiClose);
end;
WriteLN;
end;
end;
procedure ProfileElement(aFormat: TExportFormat; aElement: IwbNamedDef; var aProfile: String;
Pass: TwbExportPass; aIndent: String); forward;
procedure ProfileContainer(aFormat: TExportFormat; aElement: IwbNamedDef; var aProfile: String;
Pass: TwbExportPass; aIndent: String);
var
i : Integer;
Profile : string;
begin
Profile := '';
case aElement.DefType of
dtSubRecordStruct,
dtSubRecordUnion,
dtRecord :
with aElement as IwbRecordDef do
for i := 0 to Pred(MemberCount) do begin
Profile := '';
ProfileElement(aFormat, Members[i], Profile, Pass, aIndent);
aProfile := aProfile + Profile;
end;
dtSubRecord :
with aElement as IwbSubRecordDef do begin
Profile := '';
ProfileElement(aFormat, Value, profile, Pass, aIndent);
aProfile := aProfile + Profile;
end;
dtString,
dtLString,
dtLenString,
dtByteArray,
dtInteger,
dtIntegerFormater,
dtFloat : ;
dtSubRecordArray :
with aElement as IwbSubRecordArrayDef do begin
Profile := '';
ProfileElement(aFormat, Element, Profile, Pass, aIndent);
aProfile := aProfile + Profile;
end;
dtArray :
with aElement as IwbArrayDef do begin
Profile := '';
ProfileElement(aFormat, Element, Profile, Pass, aIndent);
aProfile := aProfile + Profile;
end;
dtStruct,
dtStructChapter :
with aElement as IwbStructDef do
for i := 0 to Pred(MemberCount) do begin
Profile := '';
ProfileElement(aFormat, Members[i], Profile, Pass, aIndent);
aProfile := aProfile + Profile;
end;
dtUnion :
with aElement as IwbUnionDef do
for i := 0 to Pred(MemberCount) do begin
Profile := '';
ProfileElement(aFormat, Members[i], Profile, Pass, aIndent);
aProfile := aProfile + Profile;
end;
dtEmpty: ;
end;
end;
procedure ProfileElement(aFormat: TExportFormat; aElement: IwbNamedDef; var aProfile: String; Pass: TwbExportPass;
aIndent: String);
var
Profile : String;
doIt : Boolean;
doubleIt : Boolean;
theElement : IwbNamedDef;
n : Integer;
procedure doFindSimpleProfile(aProfile: String);
begin
n := FindProfile(aProfile);
if not (aElement.DefType in dtNonValues) and (n>1) then begin
LockProfile(aProfile);
end;
end;
procedure doFindSharedProfile(aProfile: String);
begin
if (aElement.DefType in [dtStruct, dtSubRecordStruct]) and (FindProfile(aProfile)>0) then begin
MarkProfile(aProfile);
ExportElement(aFormat, aElement, Profile, Pass, aIndent);
end;
if (aElement.DefType in [dtUnion, dtSubRecordUnion]) and (FindProfile(aProfile)>1) then begin
MarkProfile(aProfile);
ExportElement(aFormat, aElement, Profile, Pass, aIndent);
end;
end;
procedure doFindChaptersProfile(aProfile: String);
begin
if (aElement.DefType in [dtRecord, dtStructChapter]) then begin
MarkProfile(aProfile);
ExportElement(aFormat, aElement, Profile, Pass, aIndent);
end;
end;
procedure doFindProfile(aProfile: String);
begin
if FindProfile(aProfile)>0 then begin
MarkProfile(aProfile);
end;
end;
procedure CheckPass(Pass: TwbExportPass; aProfile: String);
begin
Profile := '';
case Pass of
epRead: AddProfile(aProfile);
epSimple: doFindSimpleProfile(aProfile);
epShared: doFindSharedProfile(aProfile);
epChapters: doFindChaptersProfile(aProfile);
epRemaining: doFindProfile(aProfile);
end;
end;
begin
if not Assigned(wbDefProfiles) then begin
wbDefProfiles := TStringList.Create;
wbDefProfiles.Sorted := True;
wbDefProfiles.Duplicates := dupIgnore;
end;
Profile := ':' + wbDefToName(aElement)+'='+aElement.DefTypeName;
aProfile := aProfile + Profile;
doIt := False;
doubleIt := False;
theElement := aElement;
if aElement.defType in dtArrays then begin
case aElement.DefType of
dtArray: with aElement as IwbArrayDef do begin
doIt := Element.DefType in dtNonValues;
doubleIt := doIt;
theElement := Element;
end;
dtSubRecordArray: with aElement as IwbSubRecordArrayDef do begin
doIt := Element.DefType in dtNonValues;
doubleIt := doIt;
end;
end;
end else if aElement.defType in [dtSubrecord] then begin
with aElement as IwbSubRecordDef do begin
doIt := Value.DefType in dtNonValues;
theElement := Value;
end;
end else if (aElement.defType in dtNonValues) then
doIt := True;
if doIt then begin
Profile := '';
ProfileContainer(aFormat, theElement, Profile, Pass, aIndent);
aProfile := aProfile + Profile;
if doubleIt then begin
Profile := '';
ProfileContainer(aFormat, theElement, Profile, Pass, aIndent);
aProfile := aProfile + Profile;
end;
end;
CheckPass(Pass, aProfile);
end;
procedure ProfileHeader(aFormat: TExportFormat; Pass: TwbExportPass);
var
RecordDef : PwbMainRecordDef;
Profile : String;
begin
Profile := '';
case wbToolSource of
tsPlugins: begin
if wbFindRecordDef(wbHeaderSignature, RecordDef) then
ProfileElement(aFormat, RecordDef^, Profile, Pass, '');
end;
tsSaves: begin
ProfileElement(aFormat, wbFileHeader, Profile, Pass, '');
end;
end;
end;
procedure ProfileArray(aFormat: TExportFormat; Pass: TwbExportPass);
var
i : Integer;
RecordDef : PwbMainRecordDef;
Profile : String;
begin
case wbToolSource of
tsPlugins: for i := 0 to Pred(wbGroupOrder.Count) do
if wbGroupOrder[i]<>wbHeaderSignature then begin
Profile := '';
if wbFindRecordDef(AnsiString(wbGroupOrder[i]), RecordDef) then
ProfileElement(aFormat, RecordDef^, Profile, Pass, '');
end;
end;
end;
procedure ProfileChapters(aFormat: TExportFormat; Pass: TwbExportPass);
var
i : Integer;
Profile : String;
begin
Profile := '';
case wbToolSource of
tsSaves: for i := 0 to Pred(wbFileChapters.MemberCount) do begin
ProfileElement(aFormat, wbFileChapters.Members[i], Profile, Pass, '');
end;
end;
end;
procedure WriteElement(aElement: IwbElement; aIndent: string = ''); forward;
procedure WriteContainer(aContainer: IwbContainer; aIndent: string = '');
var
i : Integer;
GroupRecord : IwbGroupRecord;
ContainerRef : IwbContainerElementRef;
Chapter : IwbChapter;
begin
if (wbToolSource in [tsPlugins]) then if (aContainer.ElementType = etGroupRecord) then
if Supports(aContainer, IwbGroupRecord, GroupRecord) then
if GroupRecord.GroupType = 0 then begin
if Assigned(DumpGroups) and not DumpGroups.Find(String(TwbSignature(GroupRecord.GroupLabel)), i) then
Exit;
ReportProgress('Dumping: ' + GroupRecord.Name);
end
else
if Assigned(SkipChildGroups) and Assigned(GroupRecord.ChildrenOf) and
SkipChildGroups.Find(String(TwbSignature(GroupRecord.ChildrenOf.Signature)), i)
then
Exit;
if (wbToolSource in [tsSaves]) and Assigned(DumpChapters) and Supports(aContainer, IwbChapter, Chapter) then begin
if not DumpChapters.Find(IntToStr(Chapter.ChapterType), i) then
Exit;
ReportProgress('Dumping: ' + aContainer.Name);
end;
if (wbToolSource in [tsSaves]) and Assigned(ChaptersToSkip) and Supports(aContainer, IwbChapter, Chapter) then
if ChaptersToSkip.Find(IntToStr(Chapter.ChapterType), i) then begin
ReportProgress('Skiping: ' + Chapter.ChapterTypeName);
Exit;
end;
if aContainer.Skipped then begin
if ((not wbReportMode) or DumpCheckReport) then WriteLn(aIndent, '<contents skipped>');
end else begin
Supports(aContainer, IwbContainerElementRef, ContainerRef);
for i := 0 to Pred(aContainer.ElementCount) do
WriteElement(aContainer.Elements[i], aIndent);
end;
end;
procedure WriteElement(aElement: IwbElement; aIndent: string = '');
var
Container : IwbContainer;
Name : string;
Value : string;
Error : string;
i : Integer;
GroupRecord : IwbGroupRecord;
begin
if Assigned(DumpGroups) and (aElement.ElementType = etGroupRecord) then
if Supports(aElement, IwbGroupRecord, GroupRecord) then
if GroupRecord.GroupType = 0 then begin
if not DumpGroups.Find(String(TwbSignature(GroupRecord.GroupLabel)), i) then
Exit;
end
else
if Assigned(SkipChildGroups) and Assigned(GroupRecord.ChildrenOf) and
SkipChildGroups.Find(String(TwbSignature(GroupRecord.ChildrenOf.Signature)), i)
then
Exit;
if aElement.ElementType = etMainRecord then
Inc(DumpCount);
if (DumpMax > 0) and (DumpCount > DumpMax) then
Exit;
if DumpCheckReport then
Error := aElement.Check;
if wbToolMode in [tmDump] then begin
Name := aElement.DisplayName[True];
Value := aElement.Value;
if DumpHidden or ((aElement.Name <> 'Unused') and (Name <> 'Unused')) then begin
if (Name <> '') and ((not wbReportMode) or DumpCheckReport) then
Write(aIndent, Name);
if (Name <> '') or (Value <> '') then begin
aIndent := aIndent + ' ';
if DumpSize then
if (not wbReportMode) or DumpCheckReport then begin
if Name <> '' then
Write(' ');
Write('[', aElement.DataSize, ']');
end;
end;
if (Value <> '') and (DumpHidden or (Pos('Hidden: ', Name)<>1)) then begin
if ((not wbReportMode) or DumpCheckReport) then
WriteLn(': ', Value);
end else begin
if (Name <> '') and ((not wbReportMode) or DumpCheckReport) then
WriteLn;
end;
end;
end;
if DumpCheckReport and (Error <> '') then
WriteLn(aIndent, '[ERROR: ', Error ,']');
if Supports(aElement, IwbContainer, Container) and (DumpHidden or (Pos('Hidden: ', Name)<>1)) then
WriteContainer(Container, aIndent);
end;
{==============================================================================}
function CheckForErrors(const aIndent: Integer; const aElement: IwbElement): Boolean;
var
Error : string;
Container : IwbContainerElementRef;
i : Integer;
GroupRecord : IwbGroupRecord;
begin
Error := aElement.Check;
Result := Error <> '';
if Result then
WriteLn(StringOfChar(' ', aIndent * 2) + aElement.Name, ' -> ', Error);
if Supports(aElement, IwbContainerElementRef, Container) then begin
if (wbToolSource in [tsPlugins]) then if (Container.ElementType = etGroupRecord) then
if Supports(Container, IwbGroupRecord, GroupRecord) then
if GroupRecord.GroupType = 0 then begin
if Assigned(DumpGroups) and not DumpGroups.Find(String(TwbSignature(GroupRecord.GroupLabel)), i) then
Exit;
ReportProgress('Checking: ' + GroupRecord.Name);
end
else
if Assigned(SkipChildGroups) and Assigned(GroupRecord.ChildrenOf) and
SkipChildGroups.Find(String(TwbSignature(GroupRecord.ChildrenOf.Signature)), i)
then
Exit;
for i := Pred(Container.ElementCount) downto 0 do
Result := CheckForErrors(aIndent + 1, Container.Elements[i]) or Result;
end;
if Result and (Error = '') then
WriteLn(StringOfChar(' ', aIndent * 2), 'Above errors were found in: ', aElement.Name);
end;
{==============================================================================}
const
DataName : array[Boolean] of string = (
'Data',
'Data Files' // gmTES3
);
function CheckAppPath: string;
function CheckPath(const aStartFrom: string): string;
var
s: string;
begin
Result := '';
s := aStartFrom;
while Length(s) > 3 do begin
if FileExists(s + wbGameExeName) and DirectoryExists(s + DataName[wbGameMode = gmTES3]) then begin
Result := s;
Exit;
end;
s := ExtractFilePath(ExcludeTrailingPathDelimiter(s));
end;
end;
var
CurrentDir, ExeDir: string;
begin
CurrentDir := IncludeTrailingPathDelimiter(GetCurrentDir);
Result := CheckPath(CurrentDir);
if (Result = '') then begin
ExeDir := ExtractFilePath(ParamStr(0));
if not SameText(CurrentDir, ExeDir) then
Result := CheckPath(ExeDir);
end;
end;
function CheckParamPath: string; // for Dump, do we have bsa in the same directory
var
s: string;
F : TSearchRec;
begin
Result := '';
s := ParamStr(ParamCount);
s := ChangeFileExt(s, '*' + wbArchiveExtension);
if FindFirst(s, faAnyfile, F)=0 then begin
Result := ExtractFilePath(ParamStr(ParamCount));
SysUtils.FindClose(F);
end;
end;
procedure DoInitPath;
const
sBethRegKey = '\SOFTWARE\Bethesda Softworks\';
sUninstallRegKey = '\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\';
sSureAIRegKey = '\Software\SureAI\';
var
regPath, regKey, client: string;
ProgramPath : String;
DataPath : String;
begin
ProgramPath := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)));
if not wbFindCmdLineParam('D', DataPath) then begin
DataPath := CheckAppPath;
if (DataPath = '') then with TRegistry.Create do try
Access := KEY_READ or KEY_WOW64_32KEY;
RootKey := HKEY_LOCAL_MACHINE;
client := 'Steam';
case wbGameMode of
gmTES3, gmTES4, gmFO3, gmFNV, gmTES5, gmFO4, gmSSE, gmTES5VR, gmFO4VR: begin
regPath := sBethRegKey + wbGameNameReg + '\';
end;
gmEnderal, gmEnderalSE: begin
RootKey := HKEY_CURRENT_USER;
regPath := sSureAIRegKey + wbGameNameReg + '\';
end;
gmFO76: begin
regPath := sUninstallRegKey + wbGameNameReg + '\';
client := 'Bethesda.net Launcher';
end;
end;
if not OpenKey(regPath, False) then begin
Access := KEY_READ or KEY_WOW64_64KEY;
if not OpenKey(regPath, False) then begin
ReportProgress('Warning: Could not open registry key: ' + regPath);
Exit;
end;
end;
case wbGameMode of
gmTES3, gmTES4, gmFO3, gmFNV, gmTES5, gmFO4, gmSSE, gmTES5VR, gmFO4VR:
regKey := 'Installed Path';
gmEnderal, gmEnderalSE: regKey := 'Install_Path';
gmFO76: regKey := 'Path';
end;
DataPath := ReadString(regKey);
DataPath := StringReplace(DataPath, '"', '', [rfReplaceAll]);
if DataPath = '' then begin
ReportProgress(Format('Warning: Could not determine %s installation path, no "%s" registry key', [wbGameName2, regKey]));
end;
finally
Free;
end;
if (DataPath <> '') then
DataPath := IncludeTrailingPathDelimiter(DataPath) + 'Data\';
end else
DataPath := IncludeTrailingPathDelimiter(DataPath);
wbDataPath := DataPath;
end;
function isMode(aMode: String): Boolean;
begin
Result := FindCmdLineSwitch(aMode) or (Pos(Uppercase(aMode), UpperCase(ExtractFileName(ParamStr(0))))<>0);
end;
function isFormatValid(aFormatName: String): Boolean;
begin
if Uppercase(aFormatName) = 'RAW' then
Result := True
else if Uppercase(aFormatName) = 'UESPWIKI' then
Result := True
else
Result := False;
end;
procedure SwitchToCoSave;
begin
case wbGameMode of
gmFNV: SwitchToFNVCoSave;
gmFO3: SwitchToFO3CoSave;
gmFO4, gmFO4vr: SwitchToFO4CoSave;
gmTES4: SwitchToTES4CoSave;
gmTES5,
gmTES5vr,
gmEnderal,
gmEnderalSE,
gmSSE: SwitchToTES5CoSave;
end;
end;
var
NeedsSyntaxInfo : Boolean;
s, t : string;
i,j : integer;
c : Integer;
bsaCount : Integer;
_File : IwbFile;
Masters : TStringList;
IsLocalized : Boolean;
// F : TSearchRec;
n,m : TStringList;
Pass : TwbExportPass;
ts : TwbToolSource;
tm : TwbToolMode;
gm : TwbGameMode;
tss : TwbSetOfSource;
tms : TwbSetOfMode;
Found : Boolean;
b : TBytes;
begin
{$IF CompilerVersion >= 24}
FormatSettings.DecimalSeparator := '.';
{$ELSE}
SysUtils.DecimalSeparator := '.';
{$IFEND}
_wbProgressCallback := ReportProgress;
wbDontSave := True;
wbAllowInternalEdit := False;
wbMoreInfoForUnknown := False;
wbSimpleRecords := False;
wbHideUnused := False;
StartTime := Now;
try
try
t := ExtractFileName(ParamStr(0)).ToLowerInvariant;
Found := False;
for ts := Low(TwbToolSource) to High(TwbToolSource) do begin
s := GetEnumName(TypeInfo(TwbToolSource), Ord(ts) );
Delete(s, 1, 2);
if FindCmdLineSwitch(s) then begin
wbToolSource := ts;
Found := True;
Break;
end;
end;
if not Found then
for ts := Low(TwbToolSource) to High(TwbToolSource) do begin
s := GetEnumName(TypeInfo(TwbToolSource), Ord(ts) ).ToLowerInvariant;
Delete(s, 1, 2);
if t.Contains(s) then begin
wbToolSource := ts;
Found := True;
Break;
end;
end;
if not Found then
wbToolSource := tsPlugins;
Found := False;
for tm := Low(TwbToolMode) to High(TwbToolMode) do begin
s := GetEnumName(TypeInfo(TwbToolMode), Ord(tm) );
Delete(s, 1, 2);
if FindCmdLineSwitch(s) then begin
wbToolMode := tm;
Found := True;
Break;
end;
end;
if not Found then
for tm := Low(TwbToolMode) to High(TwbToolMode) do begin
s := GetEnumName(TypeInfo(TwbToolMode), Ord(tm) ).ToLowerInvariant;
Delete(s, 1, 2);
if t.Contains(s) then begin
wbToolMode := tm;
Found := True;
Break;
end;
end;
if not Found then begin
WriteLn(ErrOutput, 'Can''t determine ToolMode.');
Exit;
end;
Found := False;
for gm := Low(TwbGameMode) to High(TwbGameMode) do begin
s := GetEnumName(TypeInfo(TwbGameMode), Ord(gm) );
Delete(s, 1, 2);
if FindCmdLineSwitch(s) then begin
wbGameMode := gm;
Found := True;
Break;
end;
end;
if not Found then
for gm := Low(TwbGameMode) to High(TwbGameMode) do begin
s := GetEnumName(TypeInfo(TwbGameMode), Ord(gm) ).ToLowerInvariant;
Delete(s, 1, 2);
if t.Contains(s) then begin
wbGameMode := gm;
Found := True;
Break;
end;
end;
if not Found then begin
WriteLn(ErrOutput, 'Can''t determine GameMode.');
Exit;
end;
wbToolName := GetEnumName(TypeInfo(TwbToolMode), Ord(wbToolMode) );
Delete(wbToolName, 1 ,2);
wbSourceName := GetEnumName(TypeInfo(TwbToolSource), Ord(wbToolSource) );