-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMake Sorting Patches.pas
951 lines (802 loc) · 29.5 KB
/
Make Sorting Patches.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
{
Generates multiple sorting patches for the items it is run on.
Which patches exactly to generate can be selected in the dialog.
The patches will be named BaseName-SortingMod.esp, for example MyMod-FIS.esp, MyMod-VIS.esp, etc
}
unit MakeSortingPatches;
//uses VisOverrides;
uses praFunctions;
uses praTagifier;
const
taggingConfigDataFileName = ScriptsPath + 'SortingPatchData.json';
typeConfigFileName = ScriptsPath + 'sorting-patches-type-map.txt';
configFileName = ScriptsPath + 'multipatcher.json';
tagExtractionRegexNoBrackets = '^[\[\]\(\)\{\}|]([^\[\]\(\)\{\}|]+)[\[\]\(\)\{\}|].*';
tagStripRegex = '^[\[\]\(\)\{\}|].+[\[\]\(\)\{\}|] (.+)$';
var
ToFile: IInterface;
taggingConfigData: TJsonObject;
fileMap, typeConfigKeys, typeConfigValues: TStringList;
patcherConfig: TJsonObject;
keepTheseTags: TStringList;
foundItemTypes: TJsonObject;
procedure loadConfig();
begin
patcherConfig := TJsonObject.create;
if(FileExists(configFileName)) then begin
patcherConfig.loadFromFile(configFileName);
end;
end;
procedure saveConfig();
begin
patcherConfig.saveToFile(configFileName, false);
end;
function showConfigDialog(): boolean;
var
i, createdIndex: integer;
frm: TForm;
btnOk, btnCancel: TButton;
resultCode: integer;
typeSelect: TComboBox;
entries: TStringList;
baseNameInput: TEdit;
name, baseName: string;
clbAssets : TCheckListBox;
hasAtLeastOne: boolean;
keepTagsCb, dryRunCb, dumpTypesCb: TCheckBox;
begin
Result := false;
frm := CreateDialog('Multipatch', 400, 300);
CreateLabel(frm, 8, 10, 'Generate for these mods:');
clbAssets := TCheckListBox.Create(frm);
clbAssets.Parent := frm;
clbAssets.Top := 30;
clbAssets.Left := 8;
clbAssets.Width := 200;
clbAssets.Height := 170;
//clbAssets.Items.AddStrings(slAssetsType);
//clbAssets.CheckAll(cbChecked, False, False);
for i:=0 to taggingConfigData.count-1 do begin
name := taggingConfigData.names[i];
createdIndex := clbAssets.Items.add(name);
if(patcherConfig.O['enabledTaggers'].B[name]) then begin
clbAssets.Checked[createdIndex] := True;
end;
end;
CreateLabel(frm, 230, 10, 'Patch filename base:');
baseNameInput := CreateInput(frm, 230, 30, patcherConfig.S['baseName']);
baseNameInput.Width := 150;
keepTagsCb := CreateCheckbox(frm, 230, 70, 'Keep Valid Tags');
keepTagsCb.checked := patcherConfig.B['keepValidTags'];
dryRunCb := CreateCheckbox(frm, 230, 90, 'Dry-Run Mode');
dryRunCb.checked := patcherConfig.B['dryRunMode'];
dumpTypesCb := CreateCheckbox(frm, 230, 110, 'Dump Types');
dumpTypesCb.checked := patcherConfig.B['dumpTypes'];
btnOk := CreateButton(frm, 100, 240, ' OK ');
btnCancel := CreateButton(frm, 200, 240, 'Cancel');
btnCancel.ModalResult := mrCancel;
btnOk.ModalResult := mrYes;
btnOk.Default := true;
resultCode := frm.showModal();
if(resultCode = mrYes) then begin
patcherConfig.B['keepValidTags'] := keepTagsCb.checked;
patcherConfig.B['dryRunMode'] := dryRunCb.checked;
patcherConfig.B['dumpTypes'] := dumpTypesCb.checked;
hasAtLeastOne := false;
for i:=0 to clbAssets.Items.count-1 do begin
name := clbAssets.Items[i];
if(clbAssets.Checked[i]) then begin
hasAtLeastOne := true;
end;
patcherConfig.O['enabledTaggers'].B[name] := clbAssets.Checked[i];
end;
baseName := trim(baseNameInput.text);
patcherConfig.S['baseName'] := baseName;
if(hasAtLeastOne) and (baseName <> '') then begin
Result := true;
end;
end;
frm.free();
end;
function extractBareTag(text: string): string;
begin
Result := regexExtract(text, tagExtractionRegexNoBrackets, 1);
end;
procedure loadTaggingConfigData();
var
i, j: integer;
name, tagName, tagValue: string;
curEntry, entryTags: TJsonObject;
curTagArray: TJsonArray;
begin
taggingConfigData := TJsonObject.create();
taggingConfigData.LoadFromFile(taggingConfigDataFileName);
for i:=0 to taggingConfigData.count-1 do begin
name := taggingConfigData.names[i];
curEntry := taggingConfigData.O[name];
curTagArray := curEntry.A['extraValidTags'];
entryTags := curEntry.O['tags'];
for j:= 0 to entryTags.count-1 do begin
tagName := entryTags.Names[j];
tagValue := extractBareTag(entryTags.S[tagName]);
curTagArray.add(tagValue);
end;
end;
end;
function getTypeFromConfig(edid: string): String;
var
index: integer;
begin
Result := '';
index := typeConfigKeys.indexOf(edid);
if(index < 0) then exit;
Result := typeConfigValues[index];
end;
procedure loadTypeConfig();
var
tmpList: TStringList;
i, j, curIndex: integer;
curLine, curKey, curVal: string;
breakPos: integer;
begin
typeConfigKeys := TStringList.create;
typeConfigValues := TStringList.create;
if(not FileExists(typeConfigFileName)) then begin
exit;
end;
tmpList := TStringList.create;
tmpList.loadFromFile(typeConfigFileName);
for i:=0 to tmpList.count-1 do begin
curLine := tmpList[i];
breakPos := -1;
for j:=1 to length(curLine) do begin
if(curLine[j] = '=') then begin
breakPos := j;
break;
end;
end;
if breakPos <> -1 then begin
curKey := trim(copy(curLine, 0, breakPos-1));
curVal := trim(copy(curLine, breakPos+1, length(curLine)));
curIndex := typeConfigKeys.indexOf(curKey);
if(curIndex >= 0) then begin
typeConfigValues[curIndex] := curVal;
end else begin
curIndex := typeConfigKeys.add(curKey);
typeConfigValues.insert(curIndex, curVal);
end;
end;
end;
tmpList.free();
end;
procedure prepareFiles(baseName: string);
var
i: integer;
taggingName, curFileName: string;
curFile: IInterface;
begin
fileMap := TStringList.create;
for i:=0 to taggingConfigData.count-1 do begin
taggingName := taggingConfigData.names[i];
if(patcherConfig.O['enabledTaggers'].B[taggingName]) then begin
curFileName := baseName + '-' + taggingName + '.esp';
curFile := FindFile(curFileName);
if(not assigned(curFile)) then begin
curFile := AddNewFileName(curFileName, true);
end;
fileMap.addObject(taggingName, curFile);
end;
end;
end;
function Initialize: integer;
var
outFileBase: string;
begin
Result := 1;
initTagifier();
//initTags();
loadTaggingConfigData();
loadTypeConfig();
loadConfig();
if(not showConfigDialog()) then begin
exit;
end;
saveConfig();
prepareFiles(patcherConfig.S['baseName']);
Result := 0;
keepTheseTags := TStringList.create;
keepTheseTags.add('[PRA]');
foundItemTypes := TJsonObject.create;
end;
function getArmoType(e: IInterface): string;
var
armorRating: integer;
armorRatingStr: String;
armoInrd: IInterface;
bod2tags: String;
bod2flags: cardinal;
begin
Result := '';
armoInrd := LinksTo(ElementBySignature(e, 'INRD'));
if(checkInnr(armoInrd)) then begin
// nothing to do
exit;
end;
bod2flags := 0;
// check pipboy
bod2tags := GetElementEditValues(e, 'BOD2\First Person Flags');
if(bod2tags <> '') then begin
// it seems that these flags are in the wrong order...
// TODO fix this, at some point with proper flag handling
bod2tags := StringReverse(bod2tags);
bod2flags := BinToInt(bod2tags);
//AddMessage('Flags: '+bod2tags+' '+IntToStr(bod2tags));
if(bod2flags = $40000000) then begin
// only the pip-boy flag is set
// 0001110000000000000000000000001 -> first 3 are BODY, LHand, RHand
Result := 'PipBoy';
exit;
end;
end;
if(hasNonPlayableFlag(e)) then begin
exit;
end;
if(hasKeywordBySignature(e, 'VaultSuitKeyword', 'KWDA')) then begin
Result := 'VaultSuit';
end else if(hasKeywordBySignature(e, 'ArmorTypePower', 'KWDA')) then begin
Result := 'PowerArmor';
end else begin
armorRating := 0;
armorRatingStr := GetElementEditValues(e, 'FNAM\Armor Rating');
if armorRatingStr <> '' then begin
armorRating := StrToInt(armorRatingStr);
end;
if armorRating = 0 then begin
Result := 'Clothing';
end else begin
Result := 'Armor';
end;
end;
end;
function getNoteType(e: IInterface): String;
var
curName, curModel: String;
begin
curName := DisplayName(e);
if (hasScript(e, 'SimSettlements:Newspaper')) then begin
Result := 'News';
exit;
end;
if (hasScript(e, 'SimSettlementsV2:Books:NewsArticle')) then begin
Result := 'News';
exit;
end;
curModel := getModel(e);
if(curModel = 'Props\NewspaperPublickOccurencesLowPoly.nif') then begin
Result := 'News';
exit;
end;
// script: CA_SkillMagazineScript
if (hasKWDA(e, 'PerkMagKeyword') or hasScript(e, 'CA_SkillMagazineScript')) then begin
Result := 'Perkmag';
exit;
end;
Result := 'Note';
end;
function getWeapType(e: IInterface): String;
var
curName: String;
ammo: IInterface;
weapInrd: IInterface;
newOverride: IInterface;
flags: IInterface;
begin
Result := '';
if(hasNonPlayableFlag(e)) then begin
exit;
end;
// now only process explosives
if hasKWDA(e, 'WeaponTypeExplosive') then begin
// check if this has ammo
ammo := getUsedAmmo(e);
if (not assigned(ammo)) then begin
// some explosive
if hasKWDA(e, 'AnimsMine') then begin
Result := 'Mine';
end else begin
Result := 'Grenade';
end;
end;
exit;
end;
if(hasKWDA(e, 'WeaponTypeGrenade')) then begin
Result := 'Grenade';
exit;
end;
if(hasKWDA(e, 'WeaponTypeMine')) then begin
Result := 'Mine';
exit;
end;
// otherwise, this is a normal weapon
weapInrd := LinksTo(ElementBySignature(e, 'INRD'));
if(checkInnr(weapInrd)) then begin
// nothing to do
exit;
end;
newOverride := getOrCreateElementOverride(e, ToFile);
AddMessage('Adding INNR to '+DisplayName(e));
if(hasAnyKeyword(e, weaponTypesMelee, 'KWDA')) then begin
// melee
Result := 'Melee';
end else begin
// gun
Result := 'Gun';
end;
end;
function getAlchType(e: IInterface): String;
var
alchType: integer;
tag: String;
curName: String;
begin
alchType := getAlchemyType(e);
tag := tagGoodChem;
case (alchType) of
1: Result := 'GoodChem';
2: Result := 'BadChem';
10: Result := 'Food'; // generic food, cooked
11: Result := 'FoodRaw'; // raw
12: Result := 'FoodPrewar'; // prewar
13: Result := 'FoodCrop'; // crop
20: Result := 'Drink';
21: Result := 'Liquor';
22: Result := 'Nukacola';
30: Result := 'Syringe';
40: Result := 'Device';
41: Result := 'Tool'; //tools
end;
end;
function getHolotapeType(e: IInterface): string;
var
holotapeType, curName, tagToUse, programName, edid: string;
begin
curName := DisplayName(e);
holotapeType := getElementEditValues(e, 'DNAM');
if(holotapeType = 'Sound') or (holotapeType = 'Voice') then begin
Result := 'Holotape';
exit;
end;
if (holotapeType = 'Program') then begin
programName := getElementEditValues(e, 'PNAM');
if(programName <> '') then begin
programName := LowerCase(programName);
if(gameProgramList.indexOf(programName) >= 0) then begin
Result := 'HolotapeGame';
exit;
end;
end;
end;
// Result := strStartsWithCI(fullString, list[index-1]);
// special
if(strStartsWith(curName, '- ')) then begin
Result := 'HolotapeSettings';
exit;
end;
if (pos('setting', curName) > 0 or pos('config', curName) > 0) then begin
Result := 'HolotapeSettings';
exit;
end;
edid := LowerCase(EditorID(e));
if (pos('setting', edid) > 0 or pos('config', edid) > 0 or pos('cheat', edid) > 0) then begin
Result := 'HolotapeSettings';
exit;
end;
Result := 'Holotape';
end;
function getMiscType(e: IInterface): String;
var
value: integer;
weight: float;
numComponents: integer;
i: integer;
entry: IInterface;
componentcontainer: IInterface;
curName: String;
components: String;
begin
// AddMessage('Processing misc');
Result := '';
curName := DisplayName(e);
// test pipboy
if(hasScript(e, 'DLC06:PipboyMiscItemScript')) or (hasScript(e, 'CreationsByCOOTS:PipboyMiscItemScript')) then begin
Result := 'PipBoy';
exit;
end;
if(hasScript(e, 'praVRF:SimulationData')) then begin
Result := 'Holotape';
exit;
end;
// it can be {Scrap}
weight := StrToFloat( GetElementEditValues(e, 'DATA\Weight') );
value := StrToInt( GetElementEditValues(e, 'DATA\Value') );
components := getComponents(e);
if components <> '' then begin
// hack for gears, mostly
if (curName = components) or (curName = components+'s') then begin
// resource
Result := 'Resource';
exit;
end;
// scrap
// exception for shipments
// ShipmentScript
if hasScript(e, 'ShipmentScript') then begin
Result := 'Shipment';
exit;
end;
Result := 'Scrap';
exit;
end;
if isLooseMod(e) then begin
Result := 'LooseMod';
exit;
end;
if hasKWDA(e, 'FeaturedItem') then begin
Result := 'Collectible';
exit;
end;
if hasKWDA(e, 'VendorItemNoSale') or hasKWDA(e, 'UnscrappableObject') then begin
Result := 'Quest';
exit;
end;
if(LowerCase(getModel(e)) = 'props\pipboymiscitem\pipboymisc01.nif') then begin
Result := 'PipBoy';
exit;
end;
// START
if ((weight = 0) and (value > 0)) then begin
// weightless but valuable -> currency
Result := 'Currency';
end else if (value > 0) and (value >= weight) then begin
// has weight and valuable -> valuable
Result := 'Valuable';
end else begin
// otherwise trash
Result := 'OtherMisc';
end;
// END
end;
function getItemTypeString(e: IInterface): string;
var
sig: string;
begin
Result := getTypeFromConfig(EditorID(e));
if(Result <> '') then exit;
sig := Signature(e);
Result := '';
if sig = 'KEYM' then begin
Result := 'Key';
exit;
end else if sig = 'AMMO' then begin
if(not hasNonPlayableFlag(e)) then begin
Result := 'Ammo';
exit;
end;
end else if sig = 'ARMO' then begin
Result := getArmoType(e);
exit;
end else if sig = 'BOOK' then begin
Result := getNoteType(e);
exit;
end else if sig = 'WEAP' then begin
Result := getWeapType(e);
exit;
end else if sig = 'ALCH' then begin
Result := getAlchType(e);
exit;
end else if sig = 'NOTE' then begin
Result := getHolotapeType(e);
exit;
end else if(sig = 'MISC') then begin
Result := getMiscType(e);
exit;
end;
end;
function jsonArrayContains(needle: String; haystack: TJsonArray): boolean;
var
i: integer;
begin
//AddMessage('searching in array for '+needle);
for i:=0 to haystack.count-1 do begin
//AddMessage(' checking '+haystack.S[i]);
if(needle = haystack.S[i]) then begin
//AddMessage(' found');
Result := true;
exit;
end;
end;
Result := false;
end;
function getTagFromName(text: string): string;
begin
Result := '';
len := length(text);
if(len = 0) then begin
exit;
end;
// regex := '^([\[\]\(\)\{\}|][^\[\]\(\)\{\}|]+[\[\]\(\)\{\}|]).+';
tag := regexExtract(text, tagExtractionRegex, 1);
// AddMessage('checkItemTagForCfg got tag '+tag);
if(tag = '') then begin
exit;
end;
// for where the entire name is in brackets
if(tag = text) then begin
exit;
end;
Result := extractBareTag(text);
end;
function isTagValid(tag: String; extraValidTags: TJsonArray): boolean;
begin
Result := (jsonArrayContains(tag, extraValidTags));
end;
function checkItemTagForCfg(text: String; extraValidTags: TJsonArray): boolean;
var
tagBare: string;
begin
// AddMessage('checkItemTagForCfg for '+text);
Result := false;
tagBare := getTagFromName(text);
if(tagBare = '') then begin
exit;
end;
//AddMessage('checkItemTagForCfg got bare tag '+tagBare);
Result := isTagValid(tagBare, extraValidTags);
end;
function stripTagExtra(text: String): string;
var
c, tag, tagBare, tagNoBrackets: string;
i, len: integer;
begin
// AddMessage('checkItemTagForCfg for '+text);
Result := text;
len := length(text);
if(len = 0) then begin
exit;
end;
// regex := '^([\[\]\(\)\{\}|][^\[\]\(\)\{\}|]+[\[\]\(\)\{\}|]).+';
tag := regexExtract(text, tagExtractionRegex, 1);
// AddMessage('tag='+tag);
if(tag = '') then begin
exit;
end;
if(keepTheseTags.indexOf(tag) >= 0) then begin
exit;
end;
// for where the entire name is in brackets
if(tag = text) then begin
exit;
end;
//tagBare := extractBareTag(text);
//AddMessage('tagBare='+tagBare);
//if (not jsonArrayContains(tagBare, extraValidTags)) then begin
// yes strip
Result := stripTag(text);
//end;
// Result := (jsonArrayContains(tagBare, extraValidTags));
end;
function stripTag(inName: string): string;
begin
Result := trim(regexExtract(inName, tagStripRegex, 1));
if(Result = '') then begin
Result := inName;
end;
end;
procedure processForTaggingCfg(e: IInterface; targetFile: IInterface; typeStr, confName: string);
var
curData, curTagData: TJsonObject;
extraValidTags: TJsonArray;
prevName, curName, sig, cmpString, tag, newName, newNameBase, prevTag: string;
existingOverride, newOverride, checkElem: IInterface;
newInrd, newInnr: IInterface;
dryRunMode: boolean;
begin
dryRunMode := patcherConfig.B['dryRunMode'];
AddMessage('Processing '+DisplayName(e)+' for '+confName+' into '+GetFileName(targetFile)+'; type='+typeStr);
existingOverride := getExistingElementOverride(e, targetFile);
// OR createElementOverride
checkElem := e;
if(assigned(existingOverride)) then begin
// checkElem := existingOverride;
newOverride := existingOverride;
end;
curData := taggingConfigData.O[confName];
//extraValidTags := curData.A['extraValidTags'];
curTagData := curData.O['tags'];
tag := curTagData.S[typeStr];
curName := DisplayName(checkElem);
if(curName = '') then begin
AddMessage('elem has no name?');
exit;
end;
if(patcherConfig.B['keepValidTags']) then begin
if(checkItemTagForCfg(curName, curData.A['extraValidTags'])) then begin
exit;
end;
end;// else begin
newName := stripTagExtra(curName);
if(not assigned(newOverride)) then begin
if(not dryRunMode) then begin
newOverride := createElementOverride(e, targetFile);
end;
end else begin
if(patcherConfig.B['keepValidTags']) then begin
prevName := DisplayName(newOverride);
prevTag := getTagFromName(prevName);
if(isTagValid(prevTag, curData.A['extraValidTags'])) then begin
tag := prevTag; // old tag gets used
end;
end;
// now kill it and make a new one
if(not dryRunMode) then begin
Remove(newOverride);
newOverride := createElementOverride(e, targetFile);
end;
end;
sig := Signature(e);
if (sig = 'MISC') or (sig = 'OMOD') then begin
if(tag = '') then exit;
newNameBase := removeComponentString(newName);
cmpString := getComponents(checkElem);
if (curData.O['settings'].B['addComponentString']) and (cmpString <> '') then begin
newName := prefixNameWithTag(tag, newNameBase+'{{{'+cmpString+'}}}');
end else begin
newName := prefixNameWithTag(tag, newNameBase);
end;
if(not dryRunMode) then begin
SetElementEditValues(newOverride, 'FULL', newName);
end else begin
AddMessage('Would be setting newName: '+newName);
end;
exit;
end else if(sig = 'ARMO') then begin
if(tag = '') then begin
// otherwise special ARMO stuff
if(typeStr = 'Armor') then begin
newInnr := innrCommonArmor;
end else if(typeStr = 'PowerArmor') then begin
newInnr := innrPowerArmor;
end else begin
newInnr := innrClothes;
end;
if(not dryRunMode) then begin
AddMessage('Adding INNR to '+DisplayName(newOverride));
setPathLinksTo(newOverride, 'INRD', newInnr);
ensureDefaultObjectTemplate(newOverride);
end else begin
AddMessage('Would be Adding INNR '+DisplayName(newInnr)+' to '+DisplayName(newOverride));
end;
exit;
end;
end else if(sig = 'WEAP') then begin
if(tag = '') then begin
newInnr := innrCommonGun;
if(typeStr = 'Melee') then begin
newInnr := innrCommonMelee;
end;
if(not dryRunMode) then begin
AddMessage('Adding INNR to '+DisplayName(newOverride));
setPathLinksTo(newOverride, 'INRD', newInnr);
ensureDefaultObjectTemplate(newOverride);
end else begin
AddMessage('Would be Adding INNR '+DisplayName(newInnr)+' to '+DisplayName(newOverride));
end;
exit;
end;
end;
newName := prefixNameWithTag(tag, newName);
if(not dryRunMode) then begin
SetElementEditValues(newOverride, 'FULL', newName);
end else begin
AddMessage('Would be setting new name: '+newName);
end;
exit;
end;
procedure multiTagifyElement(e: IInterface);
var
curSig, newName, curName, curFileName: String;
scrapComponentsString: String;
newElem, curOverride, existingOverride, winOverride, masterElem, curFile: IInterface;
curEdid, typeStr, taggingName: String;
i, numOverrides: integer;
begin
curSig := Signature(e);
if (sigsToProcess.indexOf(curSig) < 0) then begin
// AddMessage('Skipping, signature');
exit;
end;
curEdid := GetElementEditValues(e, 'EDID');
if(isEdidIgnored(curEdid)) then begin
// AddMessage('Skipping '+curName+', EDID');
exit;
end;
if (
hasAnyScript(e, scriptBlackList) or
hasAnyScriptInPrefixList(e, scriptBlackListPrefix)
) then begin
// AddMessage('Skipping '+curName+', Script');
exit;
end;
// AddMessage('Script ok');
curName := DisplayName(e);
if(curName = '') then begin
exit;
end;
// fish out winning override, unless in any of the patches
masterElem := MasterOrSelf(e);
numOverrides := OverrideCount(masterElem);
for i:= 0 to numOverrides-1 do begin
curOverride := OverrideByIndex(masterElem, i);
curFileName := GetFileName(GetFile(curOverride));
if(fileMap.indexOf(curFileName) < 0) then begin
winOverride := curOverride;
end;
end;
if(not assigned(winOverride)) then begin
winOverride := e;
end;
curName := DisplayName(winOverride);
if(curName = '') then begin
exit;
end;
// find type
typeStr := getItemTypeString(e);
if(typeStr = '') then exit;
// AddMessage('Item Type: '+EditorID(e)+'='+typeStr);
if(patcherConfig.B['dumpTypes']) then begin
foundItemTypes.S[EditorID(e)] := typeStr;
end;
// now apply it for each file
for i:=0 to fileMap.count-1 do begin
taggingName := fileMap[i];
curFile := ObjectToElement(fileMap.Objects[i]);
processForTaggingCfg(e, curFile, typeStr, taggingName);
end;
end;
function Process(e: IInterface): integer;
var
newElem: IInterface;
begin
if Signature(e) = 'TES4' then exit;
multiTagifyElement(e);
end;
function Finalize: integer;
var
i: integer;
taggingName, curEdid, curType: string;
curFile: IInterface;
begin
for i:=0 to fileMap.count-1 do begin
taggingName := fileMap[i];
curFile := ObjectToElement(fileMap.Objects[i]);
CleanMasters(curFile);
end;
if(patcherConfig.B['dumpTypes']) then begin
AddMessage('=== DUMPING TYPES ===');
for i:=0 to foundItemTypes.count-1 do begin
curEdid := foundItemTypes.Names[i];
curType := foundItemTypes.S[curEdid];
AddMessage(curEdid+'='+curType);
end;
end
foundItemTypes.free();
Result := 0;
cleanupTagifier();
taggingConfigData.free();
fileMap.free();
typeConfigKeys.free();
typeConfigValues.free();
patcherConfig.free();
keepTheseTags.free();
end;
end.