forked from Xideta/WryeBashTagGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWryeBashTagGenerator.pas
2344 lines (1841 loc) · 72.5 KB
/
WryeBashTagGenerator.pas
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
{
Generates bash tags for a selected plugin automatically
Games: FO3/FNV/FO4/TES4/TES5/SSE/Enderal/EnderalSE
Author: fireundubh <fireundubh@gmail.com>
Hotkey: F12
}
Unit WryeBashTagGenerator;
Const
ScriptName = 'WryeBashTagGenerator';
ScriptVersion = '1.6.4.10';
ScriptAuthor = 'fireundubh';
ScriptEmail = 'fireundubh@gmail.com';
ScaleFactor = Screen.PixelsPerInch / 96;
Var
slBadTags : TStringList;
slDifferentTags : TStringList;
slExistingTags : TStringList;
slLog : TStringList;
slSuggestedTags : TStringList;
slDeprecatedTags : TStringList;
slOutToFileTags : TStringList;
g_FileName : string;
g_Tag : string;
g_AddTags : boolean;
g_AddFile : boolean;
g_LogTests : boolean;
Function wbIsOblivion: boolean;
Begin
Result := wbGameMode = 1;
End;
Function wbIsSkyrim: boolean;
Begin
Result := (wbGameMode = 4) Or (wbGameMode = 5) Or (wbGameMode = 7) Or (wbGameMode = 8) Or (wbGameMode = 9);
End;
Function wbIsSkyrimSE: boolean;
Begin
Result := (wbGameMode = 7) Or (wbGameMode = 9);
End;
Function wbIsFallout3: boolean;
Begin
Result := wbGameMode = 2;
End;
Function wbIsFalloutNV: boolean;
Begin
Result := wbGameMode = 3;
End;
Function wbIsFallout4: boolean;
Begin
Result := (wbGameMode = 6) Or (wbGameMode = 10);
End;
Function wbIsFallout76: boolean;
Begin
Result := wbGameMode = 11;
End;
Function wbIsEnderal: boolean;
Begin
Result := wbGameMode = 5;
End;
Function wbIsEnderalSE: boolean;
Begin
Result := wbGameMode = 9;
End;
Procedure LogInfo(AText: String);
Begin
AddMessage('[INFO] ' + AText);
End;
Procedure LogWarn(AText: String);
Begin
AddMessage('[WARN] ' + AText);
End;
Procedure LogError(AText: String);
Begin
AddMessage('[ERRO] ' + AText);
End;
Function Initialize: integer;
Begin
ClearMessages();
LogInfo('--------------------------------------------------------------------------------');
LogInfo(ScriptName + ' v' + ScriptVersion + ' by ' + ScriptAuthor + ' <' + ScriptEmail + '>');
LogInfo('--------------------------------------------------------------------------------');
LogInfo(DataPath);
g_AddTags := True;
g_AddFile := False;
g_LogTests := True;
slLog := TStringList.Create;
slLog.Sorted := False;
slLog.Duplicates := dupAccept;
slSuggestedTags := TStringList.Create;
slSuggestedTags.Sorted := True;
slSuggestedTags.Duplicates := dupIgnore;
slSuggestedTags.Delimiter := ',';
slExistingTags := TStringList.Create;
slDifferentTags := TStringList.Create;
slDifferentTags.Sorted := True;
slDifferentTags.Duplicates := dupIgnore;
slBadTags := TStringList.Create;
slDeprecatedTags := TStringList.Create;
slDeprecatedTags.CommaText := 'Body-F,Body-M,Body-Size-F,Body-Size-M,C.GridFlags,Derel,Eyes,Eyes-D,Eyes-E,Eyes-R,Hair,Invent,InventOnly,Merge,Npc.EyesOnly,Npc.HairOnly,NpcFaces,R.Relations,Relations,ScriptContents';
// Wish I didn't have to make a new list for this, but script errors on AssignFile
slOutToFileTags := TStringList.Create;
If ShowPrompt(ScriptName + ' v' + ScriptVersion) = mrAbort Then
Begin
LogError('Cannot proceed because user aborted execution');
Result := 1;
Exit;
End;
If wbIsFallout76 Then
Begin
LogError('Cannot proceed because CBash does not support Fallout 76');
Result := 2;
Exit;
End;
If wbIsFallout3 Then
LogInfo('Using game mode: Fallout 3')
Else If wbIsFalloutNV Then
LogInfo('Using game mode: Fallout: New Vegas')
Else If wbIsFallout4 Then
LogInfo('Using game mode: Fallout 4')
Else If wbIsOblivion Then
LogInfo('Using game mode: Oblivion')
Else If wbIsEnderal Then
LogInfo('Using game mode: Enderal')
Else If wbIsEnderalSE Then
LogInfo('Using game mode: Enderal Special Edition')
Else If wbIsSkyrimSE Then
LogInfo('Using game mode: Skyrim Special Edition')
Else If wbIsSkyrim Then
LogInfo('Using game mode: Skyrim')
Else
Begin
LogError('Cannot proceed because script does not support game mode');
Result := 3;
Exit;
End;
ScriptProcessElements := [etFile];
End;
Function Process(input: IInterface): integer;
Var
kDescription : IwbElement;
kHeader : IwbElement;
sDescription : string;
sTags : string;
sMasterName : string;
r : IwbMainRecord;
i : integer;
f : IwbFile;
outFile : TextFile;
Begin
If (ElementType(input) = etMainRecord) Then
exit;
f := GetFile(input);
g_FileName := GetFileName(f);
AddMessage(#10);
LogInfo('Processing... Please wait. This could take a while.');
For i := 0 To Pred(RecordCount(f)) Do
ProcessRecord(RecordByIndex(f, i));
LogInfo('--------------------------------------------------------------------------------');
LogInfo(g_FileName);
LogInfo('-------------------------------------------------------------------------- TESTS');
If g_LogTests Then
For i := 0 To Pred(slLog.Count) Do
LogInfo(slLog[i]);
LogInfo('------------------------------------------------------------------------ RESULTS');
If slSuggestedTags.Count > 0 Then
Begin
kHeader := ElementBySignature(f, 'TES4');
kDescription := ElementBySignature(kHeader, 'SNAM');
sDescription := GetEditValue(kDescription);
slExistingTags.CommaText := RegExMatchGroup('{{BASH:(.*?)}}', sDescription, 1);
StringListIntersection(slExistingTags, slDeprecatedTags, slBadTags);
LogInfo(FormatTags(slBadTags, 'deprecated tag found:', 'deprecated tags found:', 'No deprecated tags found.'));
slBadTags.Clear;
StringListDifference(slSuggestedTags, slExistingTags, slDifferentTags);
StringListDifference(slExistingTags, slSuggestedTags, slBadTags);
slSuggestedTags.AddStrings(slDifferentTags);
If (SameText(slExistingTags.CommaText, slSuggestedTags.CommaText) And Not g_AddFile) Then
Begin
LogInfo(FormatTags(slExistingTags, 'existing tag found:', 'existing tags found:', 'No existing tags found.'));
LogInfo(FormatTags(slSuggestedTags, 'suggested tag:', 'suggested tags:', 'No suggested tags.'));
LogWarn('No tags to add.' + #13#10);
Exit;
End;
If g_AddTags Then
Begin
// if the description element doesn't exist, add the element
kDescription := ElementBySignature(kHeader, 'SNAM');
If Not Assigned(kDescription) Then
kDescription := Add(kHeader, 'SNAM', True);
sDescription := GetEditValue(kDescription);
sTags := Format('{{BASH:%s}}', [slSuggestedTags.DelimitedText]);
If (Length(sDescription) = 0) And (slSuggestedTags.Count > 0) Then
sDescription := sTags
Else If Not SameText(slExistingTags.CommaText, slSuggestedTags.CommaText) Then
Begin
If slExistingTags.Count = 0 Then
sDescription := sDescription + #10#10 +sTags
Else
sDescription := RegExReplace('{{BASH:.*?}}', sTags, sDescription);
End;
SetEditValue(kDescription, sDescription);
LogInfo(FormatTags(slBadTags, 'bad tag removed:', 'bad tags removed:', 'No bad tags found.'));
LogInfo(FormatTags(slDifferentTags, 'tag added to file header:', 'tags added to file header:', 'No tags added.'));
End
Else
Begin
LogInfo(FormatTags(slBadTags, 'bad tag found:', 'bad tags found:', 'No bad tags found.'));
LogInfo(FormatTags(slDifferentTags, 'suggested tag to add:', 'suggested tags to add:', 'No suggested tags to add.'));
End;
LogInfo(FormatTags(slExistingTags, 'existing tag found:', 'existing tags found:', 'No existing tags found.'));
LogInfo(FormatTags(slSuggestedTags, 'suggested tag overall:', 'suggested tags overall:', 'No suggested tags overall.'));
If g_AddFile Then // Write tags to text file
Begin
slOutToFileTags.Add (slSuggestedTags.DelimitedText);
slOutToFileTags.SaveToFile (DataPath + 'BashTags\' + ChangeFileExt(g_FileName, '.txt'));
slOutToFileTags.Clear;
LogInfo('Finished writing auggested bash tags to file');
End
End
Else
LogInfo('No tags are suggested for this plugin.');
slLog.Clear;
slSuggestedTags.Clear;
slExistingTags.Clear;
slDifferentTags.Clear;
slBadTags.Clear;
AddMessage(#10);
End;
Function ProcessRecord(e: IwbMainRecord): integer;
Var
o : IwbMainRecord;
sSignature : string;
ConflictState : TConflictThis;
iFormID : integer;
Begin
ConflictState := ConflictAllForMainRecord(e);
If (ConflictState = caUnknown)
Or (ConflictState = caOnlyOne)
Or (ConflictState = caNoConflict) Then
Exit;
// exit if the record should not be processed
If SameText(g_FileName, 'Dawnguard.esm') Then
Begin
iFormID := GetLoadOrderFormID(e) And $00FFFFFF;
If (iFormID = $00016BCF)
Or (iFormID = $0001EE6D)
Or (iFormID = $0001FA4C)
Or (iFormID = $00039F67)
Or (iFormID = $0006C3B6) Then
Exit;
End;
// get master record if record is an override
o := Master(e);
If Not Assigned(o) Then
Exit;
// if record overrides several masters, then get the last one
o := HighestOverrideOrSelf(o, OverrideCount(o));
If Equals(e, o) Then
Exit;
// stop processing deleted records to avoid errors
If GetIsDeleted(e)
Or GetIsDeleted(o) Then
Exit;
sSignature := Signature(e);
// -------------------------------------------------------------------------------
// GROUP: Supported tags exclusive to FNV
// -------------------------------------------------------------------------------
If wbIsFalloutNV Then
If sSignature = 'WEAP' Then
ProcessTag('WeaponMods', e, o);
// -------------------------------------------------------------------------------
// GROUP: Supported tags exclusive to TES4
// -------------------------------------------------------------------------------
If wbIsOblivion Then
Begin
If ContainsStr('CREA NPC_', sSignature) Then
Begin
ProcessTag('Actors.Spells', e, o);
If sSignature = 'CREA' Then
ProcessTag('Creatures.Blood', e, o);
End
Else If sSignature = 'RACE' Then
Begin
ProcessTag('R.ChangeSpells', e, o);
ProcessTag('R.Attributes-F', e, o);
ProcessTag('R.Attributes-M', e, o);
End
Else If sSignature = 'ROAD' Then
ProcessTag('Roads', e, o)
Else If sSignature = 'SPEL' Then
ProcessTag('SpellStats', e, o);
End;
// -------------------------------------------------------------------------------
// GROUP: Supported tags exclusive to TES5, SSE
// -------------------------------------------------------------------------------
If wbIsSkyrim Then
Begin
If sSignature = 'CELL' Then
Begin
ProcessTag('C.Location', e, o);
ProcessTag('C.LockList', e, o);
ProcessTag('C.Regions', e, o);
ProcessTag('C.SkyLighting', e, o);
End
Else If ContainsStr('ACTI ALCH AMMO ARMO BOOK FLOR FURN INGR KEYM LCTN MGEF MISC NPC_ SCRL SLGM SPEL TACT WEAP', sSignature) Then
ProcessTag('Keywords', e, o)
Else If sSignature = 'FACT' Then
Begin
ProcessTag('Relations.Add', e, o);
ProcessTag('Relations.Change', e, o);
ProcessTag('Relations.Remove', e, o);
End
Else If sSignature = 'NPC_' Then
Begin
ProcessTag('Actors.Perks.Add', e, o);
ProcessTag('Actors.Perks.Change', e, o);
ProcessTag('Actors.Perks.Remove', e, o);
ProcessTag('Factions', e, o);
g_Tag := 'NPC.AIPackageOverrides';
If Not CompareFlags(e, o, 'ACBS\Template Flags', 'Use AI Packages', False, False) Then
ProcessTag('NPC.AIPackageOverrides', e, o);
ProcessTag('NPC.AttackRace', e, o);
ProcessTag('NPC.CrimeFaction', e, o);
ProcessTag('NPC.DefaultOutfit', e, o);
End
Else If sSignature = 'OTFT' Then
Begin
ProcessTag('Outfits.Add', e, o);
ProcessTag('Outfits.Remove', e, o);
End;
End;
// -------------------------------------------------------------------------------
// GROUP: Supported tags exclusive to FO3, FNV
// -------------------------------------------------------------------------------
If wbIsFallout3 Or wbIsFalloutNV Then
Begin
If sSignature = 'FLST' Then
ProcessTag('Deflst', e, o);
g_Tag := 'Destructible';
If ContainsStr('ACTI ALCH AMMO BOOK CONT DOOR FURN IMOD KEYM MISC MSTT PROJ TACT TERM WEAP', sSignature) Then
ProcessTag('Destructible', e, o)
// special handling for CREA and NPC_ record types
Else If ContainsStr('CREA NPC_', sSignature) Then
If Not CompareFlags(e, o, 'ACBS\Template Flags', 'Use Model/Animation', False, False) Then
ProcessTag('Destructible', e, o)
// added in Wrye Bash 307 Beta 6
Else If sSignature = 'FACT' Then
Begin
ProcessTag('Relations.Add', e, o);
ProcessTag('Relations.Change', e, o);
ProcessTag('Relations.Remove', e, o);
End;
End;
// -------------------------------------------------------------------------------
// GROUP: Supported tags exclusive to FO3, FNV, TES4
// -------------------------------------------------------------------------------
If wbIsFallout3 Or wbIsFalloutNV Or wbIsOblivion Then
Begin
If ContainsStr('CREA NPC_', sSignature) Then
Begin
If sSignature = 'CREA' Then
ProcessTag('Creatures.Type', e, o);
g_Tag := 'Factions';
If wbIsOblivion Or Not CompareFlags(e, o, 'ACBS\Template Flags', 'Use Factions', False, False) Then
ProcessTag('Factions', e, o);
If sSignature = 'NPC_' Then
Begin
ProcessTag('NPC.Eyes', e, o);
ProcessTag('NPC.FaceGen', e, o);
ProcessTag('NPC.Hair', e, o);
End;
End
Else If sSignature = 'RACE' Then
Begin
ProcessTag('R.Body-F', e, o);
ProcessTag('R.Body-M', e, o);
ProcessTag('R.Body-Size-F', e, o);
ProcessTag('R.Body-Size-M', e, o);
ProcessTag('R.Eyes', e, o);
ProcessTag('R.Hair', e, o);
ProcessTag('R.Relations.Add', e, o);
ProcessTag('R.Relations.Change', e, o);
ProcessTag('R.Relations.Remove', e, o);
End;
End;
// -------------------------------------------------------------------------------
// GROUP: Supported tags exclusive to FO3, FNV, TES5, SSE
// -------------------------------------------------------------------------------
If wbIsFallout3 Or wbIsFalloutNV Or wbIsSkyrim Then
Begin
If ContainsStr('CREA NPC_', sSignature) Then
Begin
g_Tag := 'Actors.ACBS';
If Not CompareFlags(e, o, 'ACBS\Template Flags', 'Use Stats', False, False) Then
ProcessTag('Actors.ACBS', e, o);
g_Tag := 'Actors.AIData';
If Not CompareFlags(e, o, 'ACBS\Template Flags', 'Use AI Data', False, False) Then
ProcessTag('Actors.AIData', e, o);
g_Tag := 'Actors.AIPackages';
If Not CompareFlags(e, o, 'ACBS\Template Flags', 'Use AI Packages', False, False) Then
ProcessTag('Actors.AIPackages', e, o);
If sSignature = 'CREA' Then
If Not CompareFlags(e, o, 'ACBS\Template Flags', 'Use Model/Animation', False, False) Then
ProcessTag('Actors.Anims', e, o);
If Not CompareFlags(e, o, 'ACBS\Template Flags', 'Use Traits', False, False) Then
Begin
ProcessTag('Actors.CombatStyle', e, o);
ProcessTag('Actors.DeathItem', e, o);
End;
g_Tag := 'Actors.Skeleton';
If Not CompareFlags(e, o, 'ACBS\Template Flags', 'Use Model/Animation', False, False) Then
ProcessTag('Actors.Skeleton', e, o);
g_Tag := 'Actors.Stats';
If Not CompareFlags(e, o, 'ACBS\Template Flags', 'Use Stats', False, False) Then
ProcessTag('Actors.Stats', e, o);
If wbIsFallout3 Or wbIsFalloutNV Or (sSignature = 'NPC_') Then
ProcessTag('Actors.Voice', e, o);
If sSignature = 'NPC_' Then
Begin
g_Tag := 'NPC.Class';
If Not CompareFlags(e, o, 'ACBS\Template Flags', 'Use Traits', False, False) Then
ProcessTag('NPC.Class', e, o);
g_Tag := 'NPC.Race';
If Not CompareFlags(e, o, 'ACBS\Template Flags', 'Use Traits', False, False) Then
ProcessTag('NPC.Race', e, o);
End;
g_Tag := 'Scripts';
If Not CompareFlags(e, o, 'ACBS\Template Flags', 'Use Script', False, False) Then
ProcessTag(g_Tag, e, o);
End;
If sSignature = 'CELL' Then
Begin
ProcessTag('C.Acoustic', e, o);
ProcessTag('C.Encounter', e, o);
ProcessTag('C.ForceHideLand', e, o);
ProcessTag('C.ImageSpace', e, o);
End;
If sSignature = 'RACE' Then
Begin
ProcessTag('R.Ears', e, o);
ProcessTag('R.Head', e, o);
ProcessTag('R.Mouth', e, o);
ProcessTag('R.Teeth', e, o);
ProcessTag('R.Skills', e, o);
ProcessTag('R.Description', e, o);
ProcessTag('Voice-F', e, o);
ProcessTag('Voice-M', e, o);
End;
If ContainsStr('ACTI ALCH ARMO CONT DOOR FLOR FURN INGR KEYM LIGH LVLC MISC QUST WEAP', sSignature) Then
ProcessTag('Scripts', e, o);
End;
// -------------------------------------------------------------------------------
// GROUP: Supported tags exclusive to FO3, FNV, TES4, TES5, SSE
// -------------------------------------------------------------------------------
If wbIsFallout3 Or wbIsFalloutNV Or wbIsOblivion Or wbIsSkyrim Then
Begin
If sSignature = 'CELL' Then
Begin
ProcessTag('C.Climate', e, o);
ProcessTag('C.Light', e, o);
ProcessTag('C.MiscFlags', e, o);
ProcessTag('C.Music', e, o);
ProcessTag('C.Name', e, o);
ProcessTag('C.Owner', e, o);
ProcessTag('C.RecordFlags', e, o);
ProcessTag('C.Water', e, o);
End;
// TAG: Delev, Relev
If ContainsStr('LVLC LVLI LVLN LVSP', sSignature) Then
ProcessDelevRelevTags(e, o);
If ContainsStr('ACTI ALCH AMMO APPA ARMO BOOK BSGN CLAS CLOT DOOR FLOR FURN INGR KEYM LIGH MGEF MISC SGST SLGM WEAP', sSignature) Then
Begin
ProcessTag('Graphics', e, o);
ProcessTag('Names', e, o);
ProcessTag('Stats', e, o);
If ContainsStr('ACTI DOOR LIGH MGEF', sSignature) Then
Begin
ProcessTag('Sound', e, o);
If sSignature = 'MGEF' Then
ProcessTag('EffectStats', e, o);
End;
End;
If ContainsStr('CREA EFSH GRAS LSCR LTEX REGN STAT TREE', sSignature) Then
ProcessTag('Graphics', e, o);
If sSignature = 'CONT' Then
Begin
ProcessTag('Invent.Add', e, o);
ProcessTag('Invent.Change', e, o);
ProcessTag('Invent.Remove', e, o);
ProcessTag('Names', e, o);
ProcessTag('Sound', e, o);
End;
If ContainsStr('DIAL ENCH EYES FACT HAIR QUST RACE SPEL WRLD', sSignature) Then
Begin
ProcessTag('Names', e, o);
If sSignature = 'ENCH' Then
ProcessTag('EnchantmentStats', e, o);
If sSignature = 'SPEL' Then
ProcessTag('SpellStats', e, o);
End;
If sSignature = 'FACT' Then
Begin
ProcessTag('Relations.Add', e, o);
ProcessTag('Relations.Change', e, o);
ProcessTag('Relations.Remove', e, o);
End;
If (sSignature = 'WTHR') Then
ProcessTag('Sound', e, o);
// special handling for CREA and NPC_
If ContainsStr('CREA NPC_', sSignature) Then
Begin
If wbIsOblivion Or wbIsFallout3 Or wbIsFalloutNV Or (sSignature = 'NPC_') Then
ProcessTag('Actors.RecordFlags', e, o);
If wbIsOblivion Then
Begin
ProcessTag('Invent.Add', e, o);
ProcessTag('Invent.Change', e, o);
ProcessTag('Invent.Remove', e, o);
ProcessTag('Names', e, o);
If sSignature = 'CREA' Then
ProcessTag('Sound', e, o);
End;
If Not wbIsOblivion Then
Begin
g_Tag := 'Invent.Add';
If Not CompareFlags(e, o, 'ACBS\Template Flags', 'Use Inventory', False, False) Then
ProcessTag(g_Tag, e, o);
g_Tag := 'Invent.Change';
If Not CompareFlags(e, o, 'ACBS\Template Flags', 'Use Inventory', False, False) Then
ProcessTag(g_Tag, e, o);
g_Tag := 'Invent.Remove';
If Not CompareFlags(e, o, 'ACBS\Template Flags', 'Use Inventory', False, False) Then
ProcessTag(g_Tag, e, o);
// special handling for CREA and NPC_ record types
g_Tag := 'Names';
If Not CompareFlags(e, o, 'ACBS\Template Flags', 'Use Base Data', False, False) Then
ProcessTag(g_Tag, e, o);
// special handling for CREA record type
g_Tag := 'Sound';
If sSignature = 'CREA' Then
If Not CompareFlags(e, o, 'ACBS\Template Flags', 'Use Model/Animation', False, False) Then
ProcessTag(g_Tag, e, o);
End;
End;
End;
// ObjectBounds
g_Tag := 'ObjectBounds';
If wbIsFallout3 And ContainsStr('ACTI ADDN ALCH AMMO ARMA ARMO ASPC BOOK COBJ CONT CREA DOOR EXPL FURN GRAS IDLM INGR KEYM LIGH LVLC LVLI LVLN MISC MSTT NOTE NPC_ PROJ PWAT SCOL SOUN STAT TACT TERM TREE TXST WEAP', sSignature) Then
ProcessTag(g_Tag, e, o);
If wbIsFalloutNV And ContainsStr('ACTI ADDN ALCH AMMO ARMA ARMO ASPC BOOK CCRD CHIP CMNY COBJ CONT CREA DOOR EXPL FURN GRAS IDLM IMOD INGR KEYM LIGH LVLC LVLI LVLN MISC MSTT NOTE NPC_ PROJ PWAT SCOL SOUN STAT TACT TERM TREE TXST WEAP', sSignature) Then
ProcessTag(g_Tag, e, o);
If wbIsSkyrim And ContainsStr('ACTI ADDN ALCH AMMO APPA ARMO ARTO ASPC BOOK CONT DOOR DUAL ENCH EXPL FLOR FURN GRAS HAZD IDLM INGR KEYM LIGH LVLI LVLN LVSP MISC MSTT NPC_ PROJ SCRL SLGM SOUN SPEL STAT TACT TREE TXST WEAP', sSignature) Then
ProcessTag(g_Tag, e, o);
If wbIsFallout4 And ContainsStr('LVLI LVLN', sSignature) Then
ProcessTag(g_Tag, e, o);
// Text
If Not wbIsFallout4 Then
Begin
g_Tag := 'Text';
If wbIsOblivion And ContainsStr('BOOK BSGN CLAS LSCR MGEF SKIL', sSignature) Then
ProcessTag(g_Tag, e, o);
If wbIsFallout3 And ContainsStr('AVIF BOOK CLAS LSCR MESG MGEF NOTE PERK TERM', sSignature) Then
ProcessTag(g_Tag, e, o);
If wbIsFalloutNV And ContainsStr('AVIF BOOK CHAL CLAS IMOD LSCR MESG MGEF NOTE PERK TERM', sSignature) Then
ProcessTag(g_Tag, e, o);
If wbIsSkyrim And ContainsStr('ALCH AMMO APPA ARMO AVIF BOOK CLAS LSCR MESG MGEF SCRL SHOU SPEL WEAP', sSignature) Then
ProcessTag(g_Tag, e, o);
End;
End;
Function Finalize: integer;
Begin
slLog.Free;
slSuggestedTags.Free;
slExistingTags.Free;
slDifferentTags.Free;
slBadTags.Free;
slDeprecatedTags.Free;
slOutToFileTags.Free;
End;
Function StrToBool(AValue: String): boolean;
Begin
If (AValue <> '0') And (AValue <> '1') Then
Result := Nil
Else
Result := (AValue = '1');
End;
Function RegExMatchGroup(AExpr: String; ASubj: String; AGroup: integer): string;
Var
re : TPerlRegEx;
Begin
Result := '';
re := TPerlRegEx.Create;
Try
re.RegEx := AExpr;
re.Options := [];
re.Subject := ASubj;
If re.Match Then
Result := re.Groups[AGroup];
Finally
re.Free;
End;
End;
Function RegExReplace(Const AExpr: String; ARepl: String; ASubj: String): string;
Var
re : TPerlRegEx;
sResult : string;
Begin
Result := '';
re := TPerlRegEx.Create;
Try
re.RegEx := AExpr;
re.Options := [];
re.Subject := ASubj;
re.Replacement := ARepl;
re.ReplaceAll;
sResult := re.Subject;
Finally
re.Free;
Result := sResult;
End;
End;
Function EditValues(Const AElement: IwbElement): string;
Var
kElement : IInterface;
sName : string;
i : integer;
Begin
Result := GetEditValue(AElement);
For i := 0 To Pred(ElementCount(AElement)) Do
Begin
kElement := ElementByIndex(AElement, i);
sName := Name(kElement);
If SameText(sName, 'unknown') Or SameText(sName, 'unused') Then
Continue;
If Result <> '' Then
Result := Result + ' ' + EditValues(kElement)
Else
Result := EditValues(kElement);
End;
End;
Function CompareAssignment(AElement: IwbElement; AMaster: IwbElement): boolean;
Begin
Result := False;
If TagExists(g_Tag) Then
Exit;
If Not Assigned(AElement) And Not Assigned(AMaster) Then
Exit;
If Assigned(AElement) And Assigned(AMaster) Then
Exit;
AddLogEntry('Assigned', AElement, AMaster);
slSuggestedTags.Add(g_Tag);
Result := True;
End;
Function CompareElementCount(AElement: IwbElement; AMaster: IwbElement): boolean;
Begin
Result := False;
If TagExists(g_Tag) Then
Exit;
If ElementCount(AElement) = ElementCount(AMaster) Then
Exit;
AddLogEntry('ElementCount', AElement, AMaster);
slSuggestedTags.Add(g_Tag);
Result := True;
End;
Function CompareElementCountAdd(AElement: IwbElement; AMaster: IwbElement): boolean;
Begin
Result := False;
If TagExists(g_Tag) Then
Exit;
If ElementCount(AElement) <= ElementCount(AMaster) Then
Exit;
AddLogEntry('ElementCountAdd', AElement, AMaster);
slSuggestedTags.Add(g_Tag);
Result := True;
End;
Function CompareElementCountRemove(AElement: IwbElement; AMaster: IwbElement): boolean;
Begin
Result := False;
If TagExists(g_Tag) Then
Exit;
If ElementCount(AElement) >= ElementCount(AMaster) Then
Exit;
AddLogEntry('ElementCountRemove', AElement, AMaster);
slSuggestedTags.Add(g_Tag);
Result := True;
End;
Function CompareEditValue(AElement: IwbElement; AMaster: IwbElement): boolean;
Begin
Result := False;
If TagExists(g_Tag) Then
Exit;
If SameText(GetEditValue(AElement), GetEditValue(AMaster)) Then
Exit;
AddLogEntry('GetEditValue', AElement, AMaster);
slSuggestedTags.Add(g_Tag);
Result := True;
End;
Function CompareFlags(AElement: IwbElement; AMaster: IwbElement; APath: String; AFlagName: String; ASuggest: boolean; ANotOperator: boolean): boolean;
Var
x : IwbElement;
y : IwbElement;
a : IwbElement;
b : IwbElement;
sa : string;
sb : string;
sTestName : string;
bResult : boolean;
Begin
Result := False;
If TagExists(g_Tag) Then
Exit;
// flags arrays
x := ElementByPath(AElement, APath);
y := ElementByPath(AMaster, APath);
// individual flags
a := ElementByName(x, AFlagName);
b := ElementByName(y, AFlagName);
// individual flag edit values
sa := GetEditValue(a);
sb := GetEditValue(b);
If ANotOperator Then
Result := Not SameText(sa, sb) // only used for Behave Like Exterior, Use Sky Lighting, and Has Water
Else
Result := StrToBool(sa) Or StrToBool(sb);
If ASuggest And Result Then
Begin
sTestName := IfThen(ANotOperator, 'CompareFlags:NOT', 'CompareFlags:OR');
AddLogEntry(sTestName, x, y);
slSuggestedTags.Add(g_Tag);
End;
End;
Function CompareKeys(AElement: IwbElement; AMaster: IwbElement): boolean;
Var
sElementEditValues : string;
sMasterEditValues : string;
ConflictState : TConflictThis;
Begin
Result := False;
If TagExists(g_Tag) Then
Exit;
ConflictState := ConflictAllForMainRecord(ContainingMainRecord(AElement));
If (ConflictState = caUnknown)
Or (ConflictState = caOnlyOne)
Or (ConflictState = caNoConflict) Then
Exit;
sElementEditValues := EditValues(AElement);
sMasterEditValues := EditValues(AMaster);
If IsEmptyKey(sElementEditValues) And IsEmptyKey(sMasterEditValues) Then
Exit;
If SameText(sElementEditValues, sMasterEditValues) Then
Exit;
AddLogEntry('CompareKeys', AElement, AMaster);
slSuggestedTags.Add(g_Tag);
Result := True;
End;
Function CompareNativeValues(AElement: IwbElement; AMaster: IwbElement; APath: String): boolean;
Var
x : IwbElement;
y : IwbElement;
Begin
Result := False;
If TagExists(g_Tag) Then
Exit;
x := ElementByPath(AElement, APath);
y := ElementByPath(AMaster, APath);
If GetNativeValue(x) = GetNativeValue(y) Then
Exit;
AddLogEntry('CompareNativeValues', AElement, AMaster);
slSuggestedTags.Add(g_Tag);
Result := True;
End;
Function SortedArrayElementByValue(AElement: IwbElement; APath: String; AValue: String): IwbElement;
Var
i : integer;