-
Notifications
You must be signed in to change notification settings - Fork 2
/
Find Unused Assets.pas
1538 lines (1257 loc) · 48.8 KB
/
Find Unused Assets.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
{
This should, in theory, scan the given file's BA2s, and report any files which are in there, but aren't used by the plugin itself.
Run on a whole file.
}
unit FindUnusedAssets;
uses PraUtil;//, PexParser;
var
archivesList: TStringList;
unusedAssets: TStringList;
notFoundAssets: TStringList;
// these are ALL resources, to prevent double processing
scriptNames: TStringList; // raw script names!
nifNames: TStringList; // includes meshes\
matNames: TStringList; // includes materials\
texNames: TStringList; // includes textures\
sndNames: TStringList; // includes sound\
resourceNames: TStringList; // all resources which are used
resourceBlackList: TStringList;
// Config Stuff
addSource: boolean;
//deleteDirectoryAfterwards: boolean;
addFacemesh: boolean;
addScolMesh: boolean;
// parseScripts: boolean;
// useResourceBlacklist: boolean;
addAnimFolder: boolean;
currentFilename: string;
outputDir: string;
archive2path: string;
hasTextureOutput: boolean;
hasMainOutput: boolean;
needsCleanup: boolean;
mainba2, texba2: string;
function ExtractFileBasename(filename: string): string;
var
curExt: string;
begin
curExt := ExtractFileExt(filename);
Result := copy(filename, 0, length(filename)-length(curExt));
end;
function processResource(resName: string): boolean;
begin
if(resName = '') then begin
Result := false;
exit;
end;
// if ((not fileExists(DataPath+resName)) or (resourceNames.indexOf(resName) >= 0)) then begin
if (resourceNames.indexOf(resName) >= 0) then begin
Result := false;
exit;
end;
{
if (useResourceBlacklist) then begin
if(resourceBlackList.indexOf(resName) >= 0) then begin
AddMessage('Resource blacklisted: '+resName);
exit;
end;
end;
}
// AddMessage('Found resource '+resName);
resourceNames.add(resName);
// does this exist?
if(not ResourceExists(resName)) then begin
// AddMessage('Failed to find '+resName);
notFoundAssets.add(resName);
end;
Result := true;
end;
function processResourceDirectoryRecursive(dir: string): boolean;
var
curFullPath: string;
searchResult : TSearchRec;
curFile: string;
begin
curFullPath := DataPath + stripSlash(dir);
Result := false;
if(not DirectoryExists(curFullPath)) then begin
exit;
end;
if FindFirst(curFullPath+'\*', faAnyFile, searchResult) = 0 then begin
repeat
// ignore . and ..
if(searchResult.Name <> '.') and (searchResult.Name <> '..') then begin
curFile := stripSlash(dir)+'\'+searchResult.Name;
if((searchResult.attr and faDirectory) = faDirectory) then begin
// dir
if(processResourceDirectoryRecursive(curFile)) then begin
Result := true;
end;
end else begin
// file
if(processResource(curFile)) then begin
Result := true;
end;
end;
end;
until FindNext(searchResult) <> 0;
// Must free up resources used by these successful finds
FindClose(searchResult);
end;
end;
/////////////// SCRIPTS BEGIN ////////////////
{
converts a script name to the path of the corresponding PSC file
}
function scriptNameToSourcePath(name: string): string;
begin
Result := StringReplace(name, ':', '\', [rfReplaceAll]);
// Result := LowerCase(StringReplace(name, ':', '\', [rfReplaceAll]));
Result := 'scripts\source\user\' + Result + '.psc';
end;
{
converts a script name to the path of the corresponding PEX file
}
function scriptNameToPexPath(name: string): string;
begin
// Result := LowerCase(StringReplace(name, ':', '\', [rfReplaceAll]));
Result := StringReplace(name, ':', '\', [rfReplaceAll]);
Result := 'scripts\' + Result + '.pex';
end;
procedure processScriptBase(pexPath: string);
var
curName: string;
i:integer;
begin
{
if(not pexReadFile(pexPath)) then begin
pexCleanUp();
AddMessage('Failed to parse '+pexPath);
exit;
end;
for i:=0 to pexExtendedObjects.count-1 do begin
curName := pexExtendedObjects[i];
if(curName <> '') then begin
// AddMessage('Parent name: '+pexExtendedObjects[i]);
processScriptName(pexExtendedObjects[i]);
end;
end;
pexCleanUp();
}
end;
procedure processScriptName(scriptName: string);
var
sourcePath: string;
destDir: string;
pscPath, pexPath: string;
begin
if(scriptNames.indexOf(scriptName) < 0) then begin
scriptNames.add(scriptName);
if(addSource) then begin
processResource(scriptNameToSourcePath(scriptName));
end;
pexPath := scriptNameToPexPath(scriptName);
if(processResource(pexPath)) then begin
{if(parseScripts) then begin
processScriptBase(pexPath);
end;}
end;
end;
end;
procedure processScriptElem(script: IInterface);
var
curScriptName: string;
begin
curScriptName := GetElementEditValues(script, 'scriptName');
if(curScriptName <> '') then begin
processScriptName(curScriptName);
end;
end;
procedure processScripts(e: IInterface);
var
vmad, scriptList, frags, aliases: IInterface;
curScript, curAlias: IInterface;
i, j: integer;
begin
vmad := ElementByName(e, 'VMAD - Virtual Machine Adapter');
if(not assigned(vmad)) then begin
exit;
end;
// scripts
scriptList := ElementByName(vmad, 'Scripts');
if(assigned(scriptList)) then begin
for i := 0 to ElementCount(scriptList)-1 do begin
curScript := ElementByIndex(scriptList, i);
processScriptElem(curScript);
end;
end;
// fragments
frags := ElementByName(vmad, 'Script Fragments');
if(assigned(frags)) then begin
curScript := ElementByName(frags, 'Script');
if(assigned(curScript)) then begin
processScriptElem(curScript);
end;
// sometimes frags itself has a script
processScriptElem(frags);
end;
// quest aliases
aliases := ElementByName(vmad, 'Aliases');
if(assigned(aliases)) then begin
for i := 0 to ElementCount(aliases)-1 do begin
curAlias := ElementByIndex(aliases, i);
scriptList := ElementByName(curAlias, 'Alias Scripts');
for j := 0 to ElementCount(scriptList)-1 do begin
curScript := ElementByIndex(scriptList, j);
processScriptElem(curScript);
end;
end;
end;
end;
//////////////// SCRIPTS END /////////////////
/////////////// TEXTURES BEGIN ///////////////
procedure processTexture(textureName: String);
begin
if(textureName = '') then begin
exit;
end;
if(texNames.indexOf(textureName) >= 0) then begin
exit;
end;
texNames.add(textureName);
// AddMessage('Found texture '+textureName);
processResource(textureName);
end;
function loadTdfStructFromArchive(struct: TdfStruct; materialName: string): boolean;
var
i: integer;
containers: TStringList;
lastContainer: string;
begin
containers := TStringList.create;
// AddMessage('Looking for '+materialName);
ResourceCount(materialName, containers);
for i:=0 to containers.count-1 do begin
lastContainer := containers[i];
// AddMessage(containers[i]);
end;
containers.free;
if(lastContainer = '') then begin
Result := false;
exit;
end;
struct.LoadFromResource(containers, materialName);
Result := true;
end;
procedure GetTexturesFromTextureSet(aSet: TwbNifBlock);
var
i: integer;
el: TdfElement;
begin
if not Assigned(aSet) then
Exit;
el := aSet.Elements['Textures'];
for i := 0 to Pred(el.Count) do begin
processTexture(wbNormalizeResourceName(el[i].EditValue, resTexture));
end;
end;
procedure processMaterial(materialName: string);
var
matFile: TdfStruct;
// TwbBGSMFile, TwbBGEMFile
i: integer;
el: TdfElement;
begin
if(materialName = '') then begin
exit;
end;
if(matNames.indexOf(materialName) >= 0) then begin
exit;
end;
{
if(not FileExists(DataPath+materialName)) then begin
exit;
end;
}
if SameText(ExtractFileExt(materialName), '.bgsm') then begin
matFile := TwbBGSMFile.Create;
end else if SameText(ExtractFileExt(materialName), '.bgem') then begin
matFile := TwbBGEMFile.Create;
end;
// matFile.LoadFromResource(materialName);
// matFile.LoadFromResource('SS2 - Main.ba2', materialName);
// matFile.LoadFromResource('F:\SteamSSD\steamapps\common\Fallout 4\Data\Fallout4 - Materials.ba2', materialName);
matNames.add(materialName);
processResource(materialName);
if(not loadTdfStructFromArchive(matFile, materialName)) then begin
matFile.Free;
// AddMessage('Failed to find '+materialName);
exit;
end;
el := matFile.Elements['Textures'];
if Assigned(el) then begin
for i := 0 to Pred(el.Count) do begin
processTexture(wbNormalizeResourceName(el[i].EditValue, resTexture));
end;
end;
matFile.Free;
end;
//////////////// TEXTURES END ////////////////
//////////////// MODELS BEGIN ////////////////
function getModelNameByPath(e: IInterface; path: string): string;
var
tempElem: IInterface;
begin
Result := '';
tempElem := ElementByPath(e, path);
if(assigned(tempElem)) then begin
Result := GetEditValue(tempElem);
end;
end;
function getModelName(e: IInterface): string;
var
tempElem: IInterface;
begin
Result := getModelNameByPath(e, 'Model\MODL');
end;
function getMaterialSwap(e: IInterface): IInterface;
var
tempElem: IInterface;
begin
Result := nil;
tempElem := ElementByName(e, 'Model');
if(assigned(tempElem)) then begin
// ALSO MATERIAL SWAP
tempElem := ElementBySignature(tempElem, 'MODS');
if(assigned(tempElem)) then begin
Result := LinksTo(tempElem);
end;
end;
end;
function loadNifFromArchive(struct: TwbNifFile; nifPath: string): boolean;
var
i: integer;
containers: TStringList;
lastContainer: string;
begin
containers := TStringList.create;
// AddMessage('Looking for '+materialName);
ResourceCount(nifPath, containers);
for i:=0 to containers.count-1 do begin
lastContainer := containers[i];
// AddMessage(containers[i]);
end;
containers.free;
if(lastContainer = '') then begin
Result := false;
exit;
end;
struct.LoadFromResource(containers, nifPath);
Result := true;
end;
procedure processNif(nifPath: string);
var
i: integer;
nif: TwbNifFile;
Block: TwbNifBlock;
curBlockName: string;
hasMaterial: boolean;
begin
nif := TwbNifFile.Create;
// mostly stolen from kinggath...
if(not loadNifFromArchive(nif, nifPath)) then begin
nif.free();
exit;
end;
try
//nif.LoadFromResource(nifPath);
for i := 0 to Pred(Nif.BlocksCount) do begin
Block := Nif.Blocks[i];
// AddMessage('foo? '+Block.BlockType);
if Block.BlockType = 'BSLightingShaderProperty' then begin
// check for material file in the Name field of FO4 meshes
hasMaterial := False;
if nif.NifVersion = nfFO4 then begin
// if shader material is used, get textures from it
// at this point, s is the material name
curBlockName := Block.EditValues['Name'];
if (SameText(ExtractFileExt(curBlockName), '.bgsm') or SameText(ExtractFileExt(curBlockName), '.bgem')) then begin
curBlockName := wbNormalizeResourceName(curBlockName, resMaterial);
processMaterial(curBlockName);
hasMaterial := True;
end;
end;
// no material used, get textures from texture set
if not hasMaterial then begin
GetTexturesFromTextureSet(Block.Elements['Texture Set'].LinksTo);
end;
end else if(Block.BlockType = 'BSBehaviorGraphExtraData') then begin
curBlockName := Block.EditValues['Behavior Graph File'];
if(curBlockName <> '') then begin
//processResource
// ProcessResource('Meshes\'+curBlockName);
ProcessResource(wbNormalizeResourceName(curBlockName, resMesh));
end;
end else if(Block.BlockType = 'BSEffectShaderProperty') then begin
processTexture(Block.EditValues['Source Texture']);
processTexture(Block.EditValues['Grayscale Texture']);
processTexture(Block.EditValues['Env Map Texture']);
processTexture(Block.EditValues['Normal Texture']);
processTexture(Block.EditValues['Env Mask Texture']);
end else if(Block.BlockType = 'BSShaderPPLightingProperty') then begin
if(assigned(Block.Elements['Texture Set'])) then begin
GetTexturesFromTextureSet(Block.Elements['Texture Set'].LinksTo);
end;
end else if(Block.BlockType = 'BSShaderNoLightingProperty') or
(Block.BlockType = 'TallGrassShaderProperty') or
(Block.BlockType = 'TileShaderProperty') or
Block.IsNiObject('NiTexture', True) then begin
curBlockName := Block.EditValues['File Name'];
if(curBlockName <> '') then begin
ProcessResource(wbNormalizeResourceName(curBlockName, resTexture));
end;
end else if(Block.BlockType = 'BSSkyShaderProperty') then begin
curBlockName := Block.EditValues['Source Name'];
if(curBlockName <> '') then begin
ProcessResource(wbNormalizeResourceName(curBlockName, resTexture));
end;
end else if(Block.BlockType = 'BSSubIndexTriShape') then begin
curBlockName := Block.EditValues['Segment Data\SSF File'];
if(curBlockName <> '') then begin
ProcessResource(wbNormalizeResourceName(curBlockName, resMesh));
end;
end;
end;
finally
nif.free();
end;
end;
function normalizeSlashes(name: string): string;
begin
Result := StringReplace(name, '/', '\', [rfReplaceAll]);
end;
procedure processModel(modelName: string);
var
modelNameFull: string;
begin
//modelName := 'meshes\' + LowerCase(modelName);
//processTexture();
modelName := wbNormalizeResourceName(modelName, resMesh);
if(nifNames.indexOf(modelName) >= 0) then begin
// done that already
exit;
end;
modelNameFull := DataPath+modelName;
{
if(not fileExists(modelNameFull)) then begin
exit;
end;
}
nifNames.add(modelName);
processResource(modelName);
processNif(modelName);
end;
procedure processMatSwap(e: IInterface);
var
subs, curSub: IInterface;
i, numElems: integer;
replacementMat: string;
begin
subs := ElementByName(e, 'Material Substitutions');
if(not assigned(subs)) then begin
exit;
end;
numElems := ElementCount(subs);
for i := 0 to numElems-1 do begin
curSub := ElementByIndex(subs, i);
//dumpElement(curSub, '');
// bnam : original
// snam : replacement
replacementMat := GetElementEditValues(curSub, 'SNAM - Replacement Material');
// addMessage('Found mat: '+replacementMat);
processMaterial(wbNormalizeResourceName(replacementMat, resMaterial));
end;
end;
procedure processModelByPath(e: IInterface; path: string);
var
modelName: string;
matSwap: IInterface;
begin
modelName := getModelNameByPath(e, path);
if(modelName <> '') then begin
processModel(modelName);
matSwap := getMaterialSwap(e);
if(assigned(matSwap)) then begin
processMatSwap(matSwap);
end;
end;
end;
procedure processModels(e: IInterface);
var
modelName: string;
matSwap: IInterface;
begin
if(Signature(e) = 'SCOL') and (not addScolMesh) then begin
exit;
end;
processModelByPath(e, 'Model\MODL');
processModelByPath(e, '1st Person Model\MOD4');
// for ARMO
processModelByPath(e, 'Male world model\MOD2');
processModelByPath(e, 'Female world model\MOD3');
processModelByPath(e, 'Male 1st Person\MOD4');
processModelByPath(e, 'Female 1st Person\MOD5');
end;
procedure processPrevisParent(e: IInterface);
var
masterName, formIdHex, previsFileName: string;
begin
if(not assigned(e)) then begin
exit;
end;
formIdHex := IntToHex(FixedFormID(e) and $00FFFFFF, 8);
masterName := GetFileName(GetFile(MasterOrSelf(e)));
previsFileName := 'Vis\'+masterName+'\'+formIdHex+'.uvd';
// AddMessage('Vis filename: '+previsFileName);
processResource(previsFileName);
end;
procedure processPhysicsMesh(e: IInterface);
var
meshName, formIdHex, masterName: string;
begin
masterName := GetFileName(GetFile(MasterOrSelf(e)));
formIdHex := IntToHex(FixedFormID(e) and $00FFFFFF, 8);
// if masterName is Fallout4.esm, then we don't have the masterName part??
if(LowerCase(masterName) = 'fallout4.esm') then begin
meshName := 'Meshes\PreCombined\'+formIdHex+'_Physics.NIF';
end else begin
meshName := 'Meshes\PreCombined\'+masterName+'\'+formIdHex+'_Physics.NIF';
end;
//AddMessage('PHYSICS '+meshName);
processResource(meshName);
end;
procedure processPrecombines(e: IInterface);
var
xcri, rvis, rvisTarget, meshes: IInterface;
meshName: string;
i: integer;
begin
xcri := ElementBySignature(e, 'XCRI');
if(assigned(xcri)) then begin
meshes := ElementByName(xcri, 'Meshes');
for i:=0 to ElementCount(meshes)-1 do begin
meshName := GetEditValue(ElementByIndex(meshes, i));
processModel(meshName);
end;
end;
// now previs
rvis := ElementBySignature(e, 'RVIS');
if(assigned(rvis)) then begin
rvisTarget := LinksTo(rvis);
processPrevisParent(rvisTarget);
//dumpElem(rvisTarget);
end else begin
// maybe this file exists anyway
processPrevisParent(e);
end;
// now physics.
processPhysicsMesh(e);
end;
procedure processNpcModels(e: IInterface);
var
modelName, modelNameFull, curNameBase, curNameExt: string;
formId: LongWord;
templateElem: IInterface;
begin
// so apparently, the face meshes are used if Traits are NOT enabled
templateElem := ElementBySignature(e, 'ACBS');
if(assigned(templateElem)) then begin
templateElem := ElementByName(templateElem, 'Use Template Actors');
if(assigned(templateElem)) then begin
// check if "Traits" is set
if(GetElementEditValues(templateElem, 'Traits') = '1') then begin
// we have the trait. so nothing to do.
exit;
end;
end;
end;
formId := GetLoadOrderFormID(e);
modelName := IntToHex(formId and 16777215, 8) + '.nif';
curNameBase := ExtractFileBasename(currentFilename);
curNameExt := ExtractFileExt(currentFilename);
processModel('Actors\Character\FaceGenData\FaceGeom\'+curNameBase+curNameExt+'\' + modelName);
if(SameText(curNameExt, '.esl')) then begin
// try this too
processModel('Actors\Character\FaceGenData\FaceGeom\'+curNameBase+'.esp\' + modelName);
end;
end;
///////////////// MODELS END /////////////////
//////////////// SOUNDS BEGIN ////////////////
procedure processSound(sndName: string);
var
xwmName: string;
begin
if(sndNames.indexOf(sndName) >= 0) then begin
exit;
end;
sndNames.add(sndName);
if(SameText(ExtractFileExt(sndName), '.wav')) then begin
xwmName := ExtractFileBasename(sndName) + '.xwm';
if(processResource(xwmName)) then begin
// done
exit;
end;
end;
processResource(sndName);
//AddMessage('Sound '+sndName);
end;
procedure processSounds(e: IInterface);
var
soundList, curSnd: IInterface;
i: Integer;
curSndFilename: string;
begin
soundList := ElementByName(e, 'Sounds');
//dumpElement(soundList, '');
if(assigned(soundList)) then begin
for i := 0 to ElementCount(soundList)-1 do begin
curSnd := ElementByIndex(soundList, i);
curSndFilename := GetEditValue( ElementBySignature(curSnd, 'ANAM'));
// AddMessage('== curSndFilename 1: '+curSndFilename);
// dumpElement(curSnd, '');
processSound(wbNormalizeResourceName(curSndFilename, resSound));
end;
end;
{
// it could also have ANAM right away
soundList := ElementBySignature(e, 'ANAM');
if(assigned(soundList)) then begin
// soundList either linksTo, or is something else
curSnd := LinksTo(soundList);
if(assigned(soundList)) then begin
AddMessage('== NOW ==');
dumpElem(curSnd);
if(Signature(curSnd) <> 'SOUN') then begin
exit;
end;
end;
AddMessage('== NOW2 ==');
dumpElem(e);
1bla
curSndFilename := GetEditValue(soundList);
AddMessage('== curSndFilename 2: '+curSndFilename);
processSound(wbNormalizeResourceName(curSndFilename, resSound));
end;
}
end;
function stripSlash(path: string): string;
begin
Result := path;
if(SameText(copy(path, length(path), 1), '\')) then begin
Result := copy(path, 0, length(path)-1);
end;
end;
procedure processRace(e: IInterface);
var
subGraph, animPaths, curData: IInterface;
i, j: integer;
curHkx: string;
begin
subGraph := ElementByPath(e, 'Subgraph Data');
if(not assigned(subGraph)) then exit;
for i:=0 to ElementCount(subGraph)-1 do begin
curData := ElementByIndex(subGraph, i);
curHkx := GetElementEditValues(curData, 'SGNM');
// AddMessage('MAIN HKX '+curHkx);
if(curHkx <> '') then begin
//processResource('meshes\'+LowerCase(curHkx));
processResource(wbNormalizeResourceName(curHkx, resMesh));
//processResource('Meshes\'+curHkx);
end;
animPaths := ElementByPath(curData, 'Animation Paths');
for j:=0 to ElementCount(animPaths)-j do begin
curHkx := GetEditValue(ElementByIndex(animPaths, j));
if(curHkx <> '') then begin
//processResourceDirectoryRecursive('meshes\'+LowerCase(curHkx));
processResourceDirectoryRecursive('Meshes\'+curHkx);
// AddMessage('SUB HKX '+curHkx);
end;
end;
end;
end;
procedure processVoiceType(e: IInterface);
var
dialFormId: cardinal;
formIdStr, basePath, curFormId, curExt: string;
responses, curRsp, curFile, curDial: IInterface;
i: integer;
searchResult : TSearchRec;
begin
// nope for now
exit;
basePath := 'Sound\Voice\'+GetFileName(GetFile(e)) + '\' +EditorID(e);
if(not DirectoryExists(DataPath + basePath)) then begin
// AddMessage('nope');
exit;
end;
curFile := GetFile(e);
if FindFirst(DataPath+basePath+'\*', faAnyFile, searchResult) = 0 then begin
repeat
// ignore . and ..
if(searchResult.Name <> '.') and (searchResult.Name <> '..') then begin
try
curExt := ExtractFileExt(searchResult.Name); // must be .fuz (or .wav or .xwm ???)
curFormId := copy(searchResult.Name, 0, 8);
dialFormId := StrToInt('$' + curFormId);
curDial := getFormByFileAndFormID(curFile, dialFormId);
if assigned(curDial) then begin
processSound(wbNormalizeResourceName(basePath+'\'+searchResult.Name, resSound));
//AddMessage('yes '+IntToHex(dialFormId, 8));
end;
except
AddMessage('File '+searchResult.Name+' seems to be invalid');
end;
end;
until FindNext(searchResult) <> 0;
// Must free up resources used by these successful finds
FindClose(searchResult);
end;
end;
{
procedure processVoiceTypeNew(e: IInterface);
var
basePath: string;
begin
basePath := 'Sound\Voice\'+GetFileName(GetFile(e)) + '\' +EditorID(e);
// what follows are editor ID (or that one override name) of relevant INFOs
// how to find relevant INFOs?
// - find all INFOs which reference the voicetype
// - - find all QUSTs which reference the voicetype
// - - - find corresponding aliases within the quest, if any
// - find the relevant NPC(s)
// - - find all INFOs which reference the NPC
// - - find all QUSTs whcih reference the NPC
// - - - find the corresponding aliases in the quest, if any
// for relevant quest aliases:
// - Iterate the quest's SCENs
// - Iterate the SCEN's actions
// - if ALID is the aliases ID, then... ooof
end;
}
///////////////// SOUNDS END /////////////////
////////////////// GUI BEGIN /////////////////
function showConfigGui(): boolean;
var
frm: TForm;
btnOkay, btnCancel: TButton;
windowHeightBase: Integer;
windowWidthBase: Integer;
topOffset: Integer;
cbIncludeSource: TCheckBox;
//cbIgnoreNamespaceless: TCheckBox;
includeFaceMeshes: TCheckBox;
includeScol: TCheckBox;
cbAutoXwm: TCheckBox;
processingGroup: TGroupBox;
outputGroup: TGroupBox;
unpackExisting: TCheckBox;
repackOutput: TCheckBox;
deleteDirectory: TCheckBox;
// parseScriptsCb: TCheckBox;
blacklistScriptsCb: TCheckBox;
compressMainBa2: TCheckBox;
addAnimFolderCb: TCheckBox;
resultCode: Integer;
begin
scriptNames := TStringList.create;
nifNames := TStringList.create;
matNames := TStringList.create;
texNames := TStringList.create;
sndNames := TStringList.create;
resourceNames := TStringList.create;
notFoundAssets := TStringList.create;
needsCleanup := true;
scriptNames.CaseSensitive := false;
nifNames.CaseSensitive := false;
matNames.CaseSensitive := false;
texNames.CaseSensitive := false;
sndNames.CaseSensitive := false;
resourceNames.CaseSensitive := false;
Result := true;
windowHeightBase := 280;
windowWidthBase := 360;
topOffset := 0;
frm := CreateDialog('Asset Collector', windowWidthBase, windowHeightBase+60);
btnOkay := CreateButton(frm, 10, windowHeightBase, 'OK');
btnOkay.ModalResult := mrYes;
btnOkay.width := 75;
btnCancel := CreateButton(frm, 90, windowHeightBase, 'Cancel');
btnCancel.ModalResult := mrCancel;
btnCancel.width := 75;
topOffset := 10;
processingGroup := CreateGroup(frm, 10, topOffset, 345, 150, 'Processing');
cbIncludeSource := CreateCheckbox(processingGroup, 10, 15,'Include Script Sources');
cbIncludeSource.state := cbChecked;
includeFaceMeshes := CreateCheckbox(processingGroup, 10, 35,'Include Face Meshes');
includeFaceMeshes.state := cbChecked;
includeScol := CreateCheckbox(processingGroup, 10, 55, 'Include SCOL Meshes');
//cbAutoXwm := CreateCheckbox(processingGroup, 10, 75,'Use XWM sound files, if possible');
//cbAutoXwm.State := cbChecked;
//parseScriptsCb := CreateCheckbox(processingGroup, 10, 95,'Parse Scripts and include extended scripts');
// parseScriptsCb.State := cbChecked;
// blacklistScriptsCb := CreateCheckbox(processingGroup, 10, 115,'Use Blacklist');
{
if (resourceBlackList <> nil) then begin
blacklistScriptsCb.State := cbChecked;
end else begin
blacklistScriptsCb.Enabled := false;
end;
}
addAnimFolderCb := CreateCheckbox(processingGroup, 10, 135, 'Include Meshes\AnimTextData, if it exists');
addAnimFolderCb.State := cbChecked;
topOffset := topOffset + 160;
//cbIgnoreNamespaceless
// cbIncludeSource
resultCode := frm.ShowModal;
if(resultCode <> mrYes) then begin
Result := false;
exit;
end;
{
if(assigned(resourceBlackList)) then begin
useResourceBlacklist := (blacklistScriptsCb.state = cbChecked);
end else begin
useResourceBlacklist := false;
end;
}
//deleteDirectoryAfterwards := (deleteDirectory.state = cbChecked);