-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathCombo.cs
More file actions
1298 lines (1087 loc) · 61.1 KB
/
Copy pathCombo.cs
File metadata and controls
1298 lines (1087 loc) · 61.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using DataTool.ConvertLogic.WEM;
using DataTool.Helper;
using TankLib;
using TankLib.Chunks;
using TankLib.Helpers;
using TankLib.STU;
using TankLib.STU.Types;
using static DataTool.Helper.STUHelper;
using static DataTool.Helper.IO;
namespace DataTool.FindLogic;
public static class Combo {
private static readonly ConcurrentBag<ushort> s_unhandledTypes = new ConcurrentBag<ushort>();
public class ComboInfo {
// keep everything at top level, stops us from doing the same things again.
// everything here is unsorted, but we can use GUIDs as references.
public Dictionary<ulong, EntityAsset> m_entities;
public Dictionary<ulong, HashSet<ulong>> m_entitiesByIdentifier;
public Dictionary<ulong, ModelAsset> m_models;
public Dictionary<ulong, MaterialAsset> m_materials;
public Dictionary<ulong, MaterialDataAsset> m_materialData;
public Dictionary<ulong, ModelLookAsset> m_modelLooks;
public Dictionary<ulong, AnimationAsset> m_animations;
public Dictionary<ulong, TextureAsset> m_textures;
public Dictionary<ulong, EffectInfoCombo> m_effects;
public Dictionary<ulong, EffectInfoCombo> m_animationEffects;
public Dictionary<ulong, SoundInfoNew> m_sounds;
public Dictionary<ulong, WWiseBankInfo> m_soundBanks;
public Dictionary<ulong, SoundFileAsset> m_voiceSoundFiles;
public Dictionary<ulong, SoundFileAsset> m_soundFiles;
public Dictionary<ulong, VoiceSetAsset> m_voiceSets;
public Dictionary<ulong, DisplayTextAsset> m_displayText;
public Dictionary<ulong, SubtitleAsset> m_subtitles;
public HashSet<ulong> m_doneScripts;
public bool m_processExistingEntities = false;
public bool m_fullLog = false;
public ComboInfo() {
m_entities = new Dictionary<ulong, EntityAsset>();
m_entitiesByIdentifier = new Dictionary<ulong, HashSet<ulong>>();
m_models = new Dictionary<ulong, ModelAsset>();
m_materials = new Dictionary<ulong, MaterialAsset>();
m_materialData = new Dictionary<ulong, MaterialDataAsset>();
m_modelLooks = new Dictionary<ulong, ModelLookAsset>();
m_animations = new Dictionary<ulong, AnimationAsset>();
m_textures = new Dictionary<ulong, TextureAsset>();
m_effects = new Dictionary<ulong, EffectInfoCombo>();
m_animationEffects = new Dictionary<ulong, EffectInfoCombo>();
m_sounds = new Dictionary<ulong, SoundInfoNew>();
m_soundBanks = new Dictionary<ulong, WWiseBankInfo>();
m_voiceSoundFiles = new Dictionary<ulong, SoundFileAsset>();
m_soundFiles = new Dictionary<ulong, SoundFileAsset>();
m_voiceSets = new Dictionary<ulong, VoiceSetAsset>();
m_displayText = new Dictionary<ulong, DisplayTextAsset>();
m_subtitles = new Dictionary<ulong, SubtitleAsset>();
m_doneScripts = new HashSet<ulong>();
}
public void RemoveByKey(ulong key) {
m_entities.Remove(key);
m_entitiesByIdentifier.Remove(key);
m_models.Remove(key);
m_materials.Remove(key);
m_materialData.Remove(key);
m_modelLooks.Remove(key);
m_animations.Remove(key);
m_textures.Remove(key);
m_effects.Remove(key);
m_animationEffects.Remove(key);
m_sounds.Remove(key);
m_soundBanks.Remove(key);
m_voiceSoundFiles.Remove(key);
m_soundFiles.Remove(key);
m_voiceSets.Remove(key);
m_displayText.Remove(key);
m_subtitles.Remove(key);
}
public void RemoveByKey(ulong[] keys) {
foreach (var @ulong in keys) {
RemoveByKey(@ulong);
}
}
private static void SetAssetName<T>(ulong guid, string name, Dictionary<ulong, T> map, Dictionary<ulong, ulong> replacements = null) where T : ComboAsset {
if (name == null) return;
if (replacements != null) guid = GetReplacement(guid, replacements);
if (!map.TryGetValue(guid, out var asset)) return;
asset.m_name = name.TrimEnd(' ');
}
public void SetEntityName(ulong entity, string name, Dictionary<ulong, ulong> replacements = null) => SetAssetName(entity, name, m_entities, replacements);
public void SetTextureName(ulong texture, string name, Dictionary<ulong, ulong> replacements = null) => SetAssetName(texture, name, m_textures, replacements);
public void SetTextureProcessIcon(ulong texture) {
if (!m_textures.TryGetValue(texture, out var asset)) return;
asset.m_processIcon = true;
}
/// <summary>
/// Sets save texture options for a texture, these will be used when saving the texture.
/// </summary>
/// <remarks>NOTE: If using replacements, these wont work as the guids will be different, in order for these to work, you need to set the options on the replaced guid</remarks>
public void SetTextureOptions(ulong texture, SaveLogic.Combo.SaveTextureOptions options) {
if (!m_textures.TryGetValue(texture, out var asset)) return;
asset.m_split = options.Split;
asset.m_fileType = options.FileTypeOverride;
asset.m_processIcon = options.ProcessIcon;
asset.m_name = options.FileNameOverride;
}
public void SetTextureSplit(ulong texture) {
if (!m_textures.TryGetValue(texture, out var asset)) return;
asset.m_split = true;
}
/// <summary>
/// Overrides the file type the texture is saved as
/// </summary>
/// <param name="texture"></param>
/// <param name="fileType">tif, png, dds</param>
public void SetTextureFileType(ulong texture, string fileType) {
if (!m_textures.TryGetValue(texture, out var asset)) return;
asset.m_fileType = fileType;
}
public void SetEffectName(ulong effect, string name, Dictionary<ulong, ulong> replacements = null) {
SetAssetName(effect, name, m_effects, replacements);
SetAssetName(effect, name, m_animationEffects, replacements);
}
public void SetModelName(ulong look, string name, Dictionary<ulong, ulong> replacements = null) => SetAssetName(look, name, m_models, replacements);
public void SetModelLookName(ulong look, string name, Dictionary<ulong, ulong> replacements = null) => SetAssetName(look, name, m_modelLooks, replacements);
public void SetEffectVoiceSet(ulong effectGUID, ulong voiceSet) {
if (m_animationEffects.TryGetValue(effectGUID, out var animationEffect)) SetEffectVoiceSet(animationEffect, voiceSet);
if (m_effects.TryGetValue(effectGUID, out var effect)) SetEffectVoiceSet(effect, voiceSet);
}
private static void SetEffectVoiceSet(EffectInfoCombo effect, ulong voiceSet) {
effect.Effect.VoiceSet = voiceSet;
}
}
public class ComboAsset {
public ulong m_GUID;
public string m_name;
protected ComboAsset(ulong guid) {
m_name = null;
m_GUID = guid;
m_name = GetNullableGUIDName(guid);
}
public string GetName() {
if (m_name != null && !Program.Flags.NoNames) {
return GetValidFilename(m_name);
}
return GetFileName(m_GUID);
}
public string GetNameIndex() {
if (m_name != null && !Program.Flags.NoNames) {
return GetValidFilename(m_name);
}
var type = teResourceGUID.Type(m_GUID);
if (type == 0xF1) return GetName(); // localized texture
if (type == 0x118) return GetName(); // new model
if (type == 0x119) return GetName(); // new look
if (type == 0x127) return GetName(); // other material thing...
// other effect types
if (type == 0x4A) return GetName();
if (type == 0x8E) return GetName();
if (type == 0x12B) return GetName();
return $"{m_GUID & 0xFFFFFFFFFFFF:X12}";
}
}
public class DisplayTextAsset : ComboAsset {
public string m_text;
public DisplayTextAsset(ulong guid, string text) : base(guid) {
m_text = text;
}
}
public class VoiceSetAsset : ComboAsset {
public VoiceSetAsset(ulong guid) : base(guid) { }
public Dictionary<ulong, HashSet<VoiceLineInstanceInfo>> VoiceLineInstances;
// key = 078 voice stimulus
}
public class VoiceLineInstanceInfo {
public ulong GUIDx06F;
public ulong GUIDx09B;
public ulong VoiceLineSet;
public ulong ExternalSound;
public ulong VoiceStimulus;
public ulong[] Conversations;
public ulong Subtitle;
public HashSet<ulong> SoundFiles;
public STUCriteriaContainer? m_criteria;
public float? m_weight;
}
public class SoundFileAsset : ComboAsset {
public SoundFileAsset(ulong guid) : base(guid) { }
}
public class SoundInfoNew : ComboAsset {
public Dictionary<uint, ulong> SoundFiles;
public Dictionary<uint, ulong> SoundStreams;
public ulong SoundBank;
public SoundInfoNew(ulong guid) : base(guid) { }
}
public class WWiseBankEvent {
public BankObjectEventAction.EventActionType Type;
public uint StartDelay; // milliseconds
public uint SoundID;
}
public class WWiseBankInfo : ComboAsset {
public List<WWiseBankEvent> Events;
public WWiseBankInfo(ulong guid) : base(guid) { }
}
public class EffectInfoCombo : ComboAsset {
// wrap
public EffectParser.EffectInfo Effect;
public EffectInfoCombo(ulong guid) : base(guid) { }
}
public class EntityAsset : ComboAsset {
public ulong m_modelGUID;
public ulong m_modelLookGUID;
public ulong m_effectGUID; // todo: STUEffectComponent defined instead of model is like a model in behaviour?
public ulong m_voiceSet;
public HashSet<ulong> m_animations;
public HashSet<ulong> m_effects;
//public HashSet<ulong> m_animationEffects;
public List<ChildEntityReference> Children;
public EntityAsset(ulong guid) : base(guid) {
m_animations = new HashSet<ulong>();
m_effects = new HashSet<ulong>();
// m_animationEffects = new HashSet<ulong>();
}
}
public class ChildEntityReference {
public ulong m_hardpointGUID;
public ulong m_identifier;
public ulong m_defGUID;
public ChildEntityReference(STUChildEntityDefinition childEntityDefinition, Dictionary<ulong, ulong> replacements) {
m_defGUID = GetReplacement((ulong) childEntityDefinition.m_child, replacements);
m_hardpointGUID = childEntityDefinition.m_hardPoint;
m_identifier = childEntityDefinition.m_49F782CE;
}
}
public class ModelMaterial {
public readonly ulong m_guid;
public readonly ulong m_key;
public ModelMaterial(ulong guid, ulong key) {
m_guid = guid;
m_key = key;
}
}
public class ModelLookAsset : ComboAsset {
public List<ModelMaterial> m_materials = new List<ModelMaterial>(); // id, guid
public ModelLookAsset(ulong guid) : base(guid) { }
}
public class MaterialAsset : ComboAsset {
public ulong m_materialDataGUID;
public ulong m_shaderSourceGUID;
public ulong m_shaderGroupGUID;
public List<(ulong instance, ulong code, byte[] shaderData)> m_shaders;
// shader info;
// main shader = 44, used to be A5
// golden = 50
public HashSet<ulong> m_materialIDs;
public MaterialAsset(ulong guid) : base(guid) {
m_materialIDs = new HashSet<ulong>();
m_shaders = new List<(ulong instance, ulong code, byte[] shaderData)>();
}
}
public class MaterialDataAsset : ComboAsset {
public Dictionary<uint, ulong> m_textureMap;
public Dictionary<uint, byte[]> m_staticInputMap;
public MaterialDataAsset(ulong guid) : base(guid) { }
}
public class TextureAsset : ComboAsset {
public bool m_loose;
public bool? m_processIcon;
public bool? m_split;
public string m_fileType;
public TextureAsset(ulong guid) : base(guid) { }
}
public class ModelAsset : ComboAsset {
public HashSet<ulong> m_animations;
public HashSet<ulong> m_modelLooks;
public HashSet<ulong> m_looseMaterials;
public ModelAsset(ulong guid) : base(guid) {
m_animations = new HashSet<ulong>();
m_modelLooks = new HashSet<ulong>();
m_looseMaterials = new HashSet<ulong>();
}
}
public class SubtitleAsset : ComboAsset {
public HashSet<string> m_text;
public SubtitleAsset(ulong guid) : base(guid) {
m_text = new HashSet<string>();
}
public void AddText(string text) {
if (text == null) return;
m_text.Add(text);
}
}
public class AnimationAsset : ComboAsset {
public float m_fps;
public uint m_priority;
public uint m_group;
public ulong m_effect;
public AnimationAsset(ulong guid) : base(guid) { }
}
public class ComboContext {
// Models + Effects + Entities
public ulong Model;
public ulong ModelLook;
public ulong Effect;
public ulong Entity;
// Animation Effects
public ulong Animation;
// Model Looks
public ulong Material;
public ulong MaterialID;
public ulong MaterialData;
// Child entities
public ulong ChildEntityIdentifier;
public ComboContext Clone() {
return new ComboContext {
Model = Model, ModelLook = ModelLook, Entity = Entity, Effect = Effect,
Animation = Animation, Material = Material, MaterialID = MaterialID, MaterialData = MaterialData
};
}
}
public static ulong GetReplacement(ulong guid, Dictionary<ulong, ulong> replacements) {
if (replacements == null) return guid;
if (replacements.TryGetValue(guid, out var replacement)) return replacement;
return guid;
}
public static bool RemoveDuplicateVoiceSetEntries(ComboInfo @base, ref ComboInfo target, ulong voiceSet, ulong targetVoiceSet) {
if (!@base.m_voiceSets.ContainsKey(voiceSet) || !target.m_voiceSets.ContainsKey(targetVoiceSet)) {
return false;
}
HashSet<ulong> keys = new HashSet<ulong>();
foreach (KeyValuePair<ulong, HashSet<VoiceLineInstanceInfo>> pair in @base.m_voiceSets[voiceSet].VoiceLineInstances) {
foreach (VoiceLineInstanceInfo voice in pair.Value) {
foreach (ulong guid in voice.SoundFiles) {
keys.Add(guid);
}
}
}
bool hasData = false;
// we have to call toarray here to "freeze" the GC stack and allow us to modify the "original" without C# bitching.
foreach (KeyValuePair<ulong, HashSet<VoiceLineInstanceInfo>> pair in target.m_voiceSets[targetVoiceSet].VoiceLineInstances.ToArray()) {
HashSet<VoiceLineInstanceInfo> newSet = new HashSet<VoiceLineInstanceInfo>();
foreach (VoiceLineInstanceInfo voice in pair.Value) {
foreach (ulong guid in voice.SoundFiles.ToArray()) { // and here
if (!keys.Add(guid)) {
voice.SoundFiles.Remove(guid);
}
}
if (voice.SoundFiles.Count > 0) {
newSet.Add(voice);
hasData = true;
}
}
target.m_voiceSets[targetVoiceSet].VoiceLineInstances[pair.Key] = newSet;
}
return hasData;
}
public static ComboInfo Find(ComboInfo info, ulong guid, Dictionary<ulong, ulong> replacements = null, ComboContext context = null) {
if (info == null) info = new ComboInfo();
if (context == null) context = new ComboContext();
// it's time to redesign our FindLogic architecture
// changes:
// All findlogics in one.
// ComboContext tells the function what to do.
// this allows for:
// Entities that do not have a model
// Model effects
if (guid == 0) return info;
guid = GetReplacement(guid, replacements);
if (info.m_fullLog) {
Logger.Debug("Combo", $"Searching in {GetFileName(guid)}");
}
// Debugger break area:
// if (GetFileName(guid) == "000000000F6D.00C") Debugger.Break(); // TIME VORTEX MANIPULATOR / TARDIS
// in 216172782113785973 / 000000000875.00D
// in 216172782113784100 / 000000000124.00D
// if (GetFileName(guid) == "00000000302E.00C") Debugger.Break(); // albino TARDIS (NO COLOUR)
// in 216172782113785973 / 000000000875.00D
// in 216172782113784100 / 000000000124.00D
// 000000000124.00D - Playable ent, hardpoint = x11
// 000000000875.00D - Main ent, hardpoint = null
// if (GetFileName(guid) == "0000000050F2.00C") Debugger.Break(); // renhardt OWL
// if (GetFileName(guid) == "000000005100.00C") Debugger.Break(); // zen OWL
// if (GetFileName(guid) == "000000000AA9.008") Debugger.Break();
// 508906757892874256 / 000000002010.08F = ANCR_badass_POTG effect
// 288230376151718579 / 000000001AB3.003 = shield entity
//if (GetFileName(guid) == "0000000014EF.003") Debugger.Break(); // ilios windmill
//if (GetFileName(guid) == "0000000014F4.003") Debugger.Break(); // ilios bigboat
//if (GetFileName(guid) == "000000001AF7.003") Debugger.Break(); // black forest (winter) windmill
//if (GetFileName(guid) == "000000001A2E.003") Debugger.Break(); // black forest (winter) spawndoor
//if (GetFileName(guid) == "000000001B4E.003") Debugger.Break(); // black forest (winter) middle cog
//if (GetFileName(guid) == "000000001BDB.003") Debugger.Break(); // black forest (winter) capture point
ushort guidType = teResourceGUID.Type(guid);
if (guidType == 0 || guidType == 1) return info;
switch (guidType) {
case 0x3: {
if (!info.m_processExistingEntities && info.m_entities.ContainsKey(guid)) break;
STUEntityDefinition entityDefinition = GetInstance<STUEntityDefinition>(guid);
if (entityDefinition == null) break;
ComboContext entityContext = context.Clone();
entityContext.Entity = guid;
if (context.ChildEntityIdentifier != 0) {
if (!info.m_entitiesByIdentifier.ContainsKey(context.ChildEntityIdentifier)) {
info.m_entitiesByIdentifier[context.ChildEntityIdentifier] = new HashSet<ulong>();
}
info.m_entitiesByIdentifier[context.ChildEntityIdentifier].Add(guid);
}
info.m_entities.TryGetValue(guid, out var entityInfo);
if (entityInfo == null) {
entityInfo = new EntityAsset(guid);
info.m_entities[guid] = entityInfo;
}
if (entityDefinition.m_childEntityData != null) {
entityInfo.Children = new List<ChildEntityReference>();
foreach (STUChildEntityDefinition childEntityDefinition in entityDefinition.m_childEntityData) {
if (childEntityDefinition == null) continue;
ComboContext childContext = new ComboContext {
ChildEntityIdentifier = childEntityDefinition.m_49F782CE
};
Find(info, (ulong) childEntityDefinition.m_child, replacements, childContext);
if (info.m_entities.ContainsKey(GetReplacement((ulong) childEntityDefinition.m_child, replacements))) {
// sometimes the entity can't be loaded
entityInfo.Children.Add(new ChildEntityReference(childEntityDefinition, replacements));
}
}
}
if (entityDefinition.m_componentMap != null) {
STUEntityComponent[] components = entityDefinition.m_componentMap.Values
.OrderBy(x => x?.GetType() != typeof(STUModelComponent) &&
x?.GetType() != typeof(STUEffectComponent)).ToArray();
// STUModelComponent first because we need model for context
// STUEffectComponent second(ish) because we need effect for context
foreach (STUEntityComponent component in components) {
if (component == null) continue;
if (component is STUModelComponent modelComponent) {
if (modelComponent.m_F5ADE169 != 0) {
entityContext.Model = GetReplacement(modelComponent.m_F5ADE169, replacements);
entityContext.ModelLook = GetReplacement(modelComponent.m_EE77FFF9, replacements);
} else {
entityContext.Model = GetReplacement(modelComponent.m_model, replacements);
entityContext.ModelLook = GetReplacement(modelComponent.m_look, replacements);
}
Find(info, modelComponent.m_model, replacements, entityContext);
Find(info, modelComponent.m_F5ADE169, replacements, entityContext); // new model
Find(info, modelComponent.m_look, replacements, entityContext);
Find(info, modelComponent.m_EE77FFF9, replacements, entityContext); // new look
Find(info, modelComponent.m_animBlendTreeSet, replacements, entityContext);
Find(info, modelComponent.m_36F54327, replacements, entityContext);
} else if (component is STUEffectComponent effectComponent) {
entityContext.Effect = GetReplacement(effectComponent.m_effect, replacements);
Find(info, effectComponent.m_effect, replacements, entityContext);
} else if (component is STUStatescriptComponent statescriptComponent) {
if (statescriptComponent.m_B634821A != null) {
foreach (STUStatescriptGraphWithOverrides graphWithOverrides in statescriptComponent.m_B634821A) {
Find(info, graphWithOverrides, replacements, entityContext);
}
}
} else if (component is STUWeaponComponent weaponComponent) {
Find(info, weaponComponent.m_managerScript, replacements, entityContext);
if (weaponComponent.m_weapons != null) {
foreach (STUWeaponDefinition weaponDefinition in weaponComponent.m_weapons) {
Find(info, weaponDefinition.m_script, replacements, entityContext);
Find(info, weaponDefinition.m_graph, replacements, entityContext);
}
}
} else if (component is STUVoiceSetComponent voiceSetComponent) {
entityInfo.m_voiceSet = GetReplacement(voiceSetComponent.m_voiceDefinition, replacements);
Find(info, voiceSetComponent.m_voiceDefinition, replacements, entityContext);
} else if (component is STUFirstPersonComponent firstPersonComponent) {
Find(info, firstPersonComponent.m_entity, replacements, entityContext);
} else if (component is STUHealthComponent healthComponent) {
Find(info, healthComponent.m_63FBB2D3, replacements, entityContext);
} else if (component is STULocalIdleAnimComponent localIdleAnimComponent) {
Find(info, localIdleAnimComponent.m_idleAnimation, replacements, entityContext);
} else if (component is STUMirroredIdleAnimComponent mirroredIdleAnimComponent) {
Find(info, mirroredIdleAnimComponent.m_idleAnimation, replacements, entityContext);
} else if (component is STU_05DE82F2 unkComponent1) {
Find(info, unkComponent1.m_4A83FA61, replacements, entityContext);
} else if (component is STU_3CFA8C4A unkComponent2) {
if (unkComponent2.m_entries == null) continue;
foreach (STU_FB16F341 unkComponent2Entry in unkComponent2.m_entries) {
Find(info, unkComponent2Entry.m_animation, replacements, entityContext);
}
}
}
}
// assign voice master to effects
if (entityInfo.m_voiceSet != 0) {
foreach (ulong entityAnimation in entityInfo.m_animations) {
AnimationAsset entityAnimationInfo = info.m_animations[entityAnimation];
if (entityAnimationInfo.m_effect == 0) continue;
info.SetEffectVoiceSet(entityAnimationInfo.m_effect, entityInfo.m_voiceSet);
}
}
entityInfo.m_modelGUID = entityContext.Model;
entityInfo.m_modelLookGUID = entityContext.ModelLook;
entityInfo.m_effectGUID = entityContext.Effect;
break;
}
case 0x4:
case 0xF1: {
if (info.m_textures.ContainsKey(guid)) break;
TextureAsset textureInfo = new TextureAsset(guid);
info.m_textures[guid] = textureInfo;
if (context.Material == 0) {
textureInfo.m_loose = true;
}
break;
}
case 0x6: {
if (context.Model != 0) {
info.m_models[context.Model].m_animations.Add(guid);
}
if (context.Entity != 0) {
info.m_entities[context.Entity].m_animations.Add(guid);
}
if (context.Model == 0 && context.Entity == 0) {
TankLib.Helpers.Logger.Debug("Combo", "Animation with no model or entity. will be lost (unless saving all)");
}
if (info.m_animations.ContainsKey(guid)) break;
AnimationAsset animationInfo = new AnimationAsset(guid);
ComboContext animationContext = context.Clone();
animationContext.Animation = guid;
info.m_animations[guid] = animationInfo;
using Stream animationStream = OpenFile(guid);
if (animationStream == null) break;
using BinaryReader animationReader = new BinaryReader(animationStream);
var header = animationReader.Read<teAnimation.AnimHeader>();
animationInfo.m_fps = header.FPS;
animationInfo.m_priority = header.Priority;
animationInfo.m_group = header.Group;
animationInfo.m_effect = GetReplacement(header.Effect, replacements);
Find(info, header.Effect, replacements, animationContext);
break;
}
case 0x8:
case 0x127: {
// if (info.m_materials.ContainsKey(guid) &&
// (info.m_materials[guid].m_materialIDs.Contains(context.MaterialID) || context.MaterialID == 0)) break;
// // ^ break if material exists and has id, or id is 0
teMaterial material = null;
try {
material = new teMaterial(OpenFile(guid));
} catch {
break;
}
MaterialAsset materialInfo;
if (!info.m_materials.ContainsKey(guid)) {
materialInfo = new MaterialAsset(guid) {
m_materialDataGUID = GetReplacement(material.Header.MaterialData, replacements)
};
info.m_materials[guid] = materialInfo;
} else {
materialInfo = info.m_materials[guid];
}
materialInfo.m_materialIDs.Add(context.MaterialID);
materialInfo.m_shaderSourceGUID = GetReplacement(material.Header.ShaderSource, replacements);
materialInfo.m_shaderGroupGUID = GetReplacement(material.Header.ShaderGroup, replacements);
if (Program.Flags.ExtractShaders) {
// Local function to prevent nesting on error handling, could be hoisted into a static function
void ExtractShaders() {
using Stream shaderGroupStream = OpenFile(materialInfo.m_shaderGroupGUID);
if (shaderGroupStream == null) {
Logger.Error("Combo", $"ExtractShaders: can't open shader group {materialInfo.m_shaderGroupGUID:X16}");
return;
}
teShaderGroup shaderGroup = new teShaderGroup(shaderGroupStream);
if (shaderGroup.Shaders == null || shaderGroup.Instances == null) {
Logger.Error("Combo", $"ExtractShaders: group {materialInfo.m_shaderGroupGUID:X16} has no shader/instance arrays");
return;
}
for (int i = 0; i < shaderGroup.Shaders.Length; i++) {
ulong shaderCodeGuid = GetReplacement(shaderGroup.Shaders[i], replacements);
using Stream shaderCodeStream = OpenFile(shaderCodeGuid);
if (shaderCodeStream == null) {
Logger.Error("Combo", $"ExtractShaders: can't open shader code {shaderCodeGuid:X16}");
continue;
}
teShaderCode shaderCode = new teShaderCode(shaderCodeStream);
materialInfo.m_shaders.Add((GetReplacement(shaderGroup.Instances[i], replacements), shaderCodeGuid, shaderCode.ByteCode));
}
}
ExtractShaders();
}
if (context.ModelLook == 0 && context.Model != 0) {
info.m_models[context.Model].m_looseMaterials.Add(guid);
}
ComboContext materialContext = context.Clone();
materialContext.Material = guid;
Find(info, material.Header.MaterialData, replacements, materialContext);
break;
}
case 0x118: // something model...
case 0xC: {
if (info.m_models.ContainsKey(guid)) break;
ModelAsset modelInfo = new ModelAsset(guid);
info.m_models[guid] = modelInfo;
/*teModelChunk_STU stu = chunkedData.GetChunk<teModelChunk_STU>();
if (stu != null) {
Find(info, stu.StructuredData.m_37ED05D0, replacements, context);
Find(info, stu.StructuredData.m_AD47190C, replacements, context);
}*/
break;
}
case 0xD:
case 0x4A:
case 0x8F:
case 0x8E:
case 0xD4: // sequence
case 0x12B: {
if (info.m_effects.ContainsKey(guid)) break;
if (info.m_animationEffects.ContainsKey(guid)) break;
EffectParser.EffectInfo effectInfo = new EffectParser.EffectInfo {
GUID = guid
};
effectInfo.SetupEffect();
var effectComboInfo = new EffectInfoCombo(guid) { Effect = effectInfo };
if (guidType == 0x8F) {
info.m_animationEffects[guid] = effectComboInfo;
//if (context.Entity != 0) {
// info.Entities[context.Entity].m_animationEffects.Add(guid);
//}
} else {
info.m_effects[guid] = effectComboInfo;
if (context.Entity != 0) {
info.m_entities[context.Entity].m_effects.Add(guid);
}
}
using (Stream effectStream = OpenFile(guid)) {
teChunkedData chunkedData = new teChunkedData(effectStream);
EffectParser parser = new EffectParser(chunkedData, guid);
ulong lastParticleModel = 0;
foreach (KeyValuePair<EffectParser.ChunkPlaybackInfo, IChunk> chunk in parser.GetChunks()) {
parser.Process(effectInfo, chunk, replacements);
if (chunk.Value is teEffectComponentModel model) {
ComboContext dmceContext = new ComboContext {
Model = GetReplacement(model.Header.Model, replacements)
};
Find(info, model.Header.Model, replacements, dmceContext);
Find(info, model.Header.ModelLook, replacements, dmceContext);
Find(info, model.Header.Animation, replacements, dmceContext);
} else if (chunk.Value is teEffectComponentEffect effect) {
Find(info, effect.Header.Effect, replacements); // clean context
} else if (chunk.Value is teEffectComponentEntity entity) {
ComboContext neceContext =
new ComboContext { ChildEntityIdentifier = entity.Header.Identifier };
Find(info, entity.Header.Entity, replacements, neceContext);
} else if (chunk.Value is teEffectComponentEntityControl entityControl) {
if (entityControl.Header.Animation == 0) continue;
Find(info, entityControl.Header.Animation, replacements);
if (!info.m_entitiesByIdentifier.ContainsKey(entityControl.Header.Identifier)) continue;
foreach (ulong ceceEntity in info.m_entitiesByIdentifier[entityControl.Header.Identifier]) {
EntityAsset ceceEntityInfo = info.m_entities[ceceEntity];
ceceEntityInfo.m_animations.Add(GetReplacement(entityControl.Header.Animation, replacements));
if (ceceEntityInfo.m_modelGUID != 0) {
info.m_models[ceceEntityInfo.m_modelGUID].m_animations.Add(GetReplacement(entityControl.Header.Animation, replacements));
}
}
} else if (chunk.Value is teEffectComponentSound soundComponent) {
Find(info, soundComponent.Header.Sound, replacements);
} else if (chunk.Value is teEffectChunkShaderSetup shaders) {
if (lastParticleModel == 0) TankLib.Helpers.Logger.Debug("Combo", "ShaderSetup with no model. textures will get lost");
ComboContext ssceContext = new ComboContext { Model = lastParticleModel };
Find(info, shaders.Header.Material, replacements, ssceContext);
Find(info, shaders.Header.MaterialData, replacements, ssceContext);
}
if (chunk.Value is teEffectComponentParticle particle) {
Find(info, particle.Header.Model, replacements);
lastParticleModel = GetReplacement(particle.Header.Model, replacements);
} else if (chunk.Value is teEffectComponentRibbonRenderer ribbonRenderer) {
Find(info, ribbonRenderer.Header.ModelGUID, replacements);
lastParticleModel = GetReplacement(ribbonRenderer.Header.ModelGUID, replacements);
} else {
lastParticleModel = 0;
}
}
}
break;
}
case 0x1A:
case 0x119: {
if (info.m_modelLooks.ContainsKey(guid)) {
if (context.Model != 0) {
info.m_models[context.Model].m_modelLooks.Add(guid);
}
break;
}
STUModelLook modelLook = GetInstance<STUModelLook>(guid);
if (modelLook == null) break;
ModelLookAsset modelLookInfo = new ModelLookAsset(guid);
info.m_modelLooks[guid] = modelLookInfo;
ComboContext modelLookContext = context.Clone();
modelLookContext.ModelLook = guid;
if (modelLook.m_materials != null) {
foreach (STUModelMaterial modelLookMaterial in modelLook.m_materials) {
FindModelMaterial(info, modelLookMaterial, modelLookInfo, modelLookContext, replacements);
}
}
if (modelLook.m_materialEffects != null) {
var matEffectContext = new ComboContext {
Model = context.Model
// this will be a loose material
};
foreach (STU_D75EA2E1 materialEffect in modelLook.m_materialEffects) {
Find(info, materialEffect.m_materialEffect, replacements, matEffectContext);
Find(info, materialEffect.m_82F3DCE0, replacements, matEffectContext);
if (materialEffect.m_materials != null) {
foreach (var material in materialEffect.m_materials) {
Find(info, material.m_material, replacements, matEffectContext);
Find(info, material.m_5753874F, replacements, matEffectContext);
}
}
}
}
if (modelLook.m_5ED21CE1 != null) {
foreach (var modelRef in modelLook.m_5ED21CE1) {
Find(info, modelRef, replacements);
}
}
if (modelLook.m_05692DC5 != null) {
foreach (var anim in modelLook.m_05692DC5) {
Find(info, anim.m_animation, replacements, context);
}
}
if (modelLook.m_844B23C0 != null) {
foreach (var idk in modelLook.m_844B23C0) {
Find(info, idk.m_8A557E94, replacements, context);
}
}
if (context.Model != 0) {
info.m_models[context.Model].m_modelLooks.Add(guid);
}
break;
}
case 0x1B: {
if (!info.m_doneScripts.Add(guid)) break;
var statescriptGraph = GetInstance<STUStatescriptGraph>(guid);
if (statescriptGraph == null) break;
Find(info, statescriptGraph.m_publicSchema, replacements, context);
STUConfigVar[] configVars = GetInstances<STUConfigVar>(guid);
if (configVars == null) break;
foreach (STUConfigVar configVar in configVars) {
Find(info, configVar, replacements, context);
}
break;
}
case 0x20: {
STUAnimBlendTree blendTree = GetInstance<STUAnimBlendTree>(guid);
if (blendTree == null || blendTree.m_animNodes == null) break;
foreach (STUAnimNode_Base animNode in blendTree.m_animNodes) {
if (animNode is STUAnimNode_Animation animNodeAnimation) {
Find(info, animNodeAnimation?.m_animation?.m_value, replacements, context);
} else if (animNode is STUAnimNode_AnimationPose2d animNodePose2D) {
Find(info, animNodePose2D?.m_animation?.m_value, replacements, context);
}
}
break;
}
case 0x21: {
STUAnimBlendTreeSet blendTreeSet = GetInstance<STUAnimBlendTreeSet>(guid);
if (blendTreeSet == null) break;
foreach (ulong externalRef in blendTreeSet.m_externalRefs) {
Find(info, externalRef, replacements, context);
}
foreach (STUAnimBlendTreeSet_BlendTreeItem blendTreeItem in blendTreeSet.m_blendTreeItems) {
Find(info, blendTreeItem.m_C0214513, replacements, context);
if (blendTreeItem.m_F6E6D4B1?.m_5AD927D3 != null) {
foreach (var anim in blendTreeItem.m_F6E6D4B1.m_5AD927D3) {
Find(info, anim, replacements, context);
}
}
if (blendTreeItem.m_gameData is STU_7D00A73D animGameDataUnk1) {
if (animGameDataUnk1.m_animDatas != null) {
foreach (STUAnimGameData_AnimationData animData in animGameDataUnk1.m_animDatas) {
if (animData.m_ED5A243E == 0) continue;
var animIdentifierId = new teResourceGUID(animData.m_ED5A243E).WithType(0x1C);
Find(info, animIdentifierId, replacements, context);
}
}
}
if (blendTreeItem?.m_onFinished?.m_slotAnims != null) {
foreach (STUAnimBlendTree_SlotAnimation blendTreeSlotAnimation in blendTreeItem.m_onFinished.m_slotAnims) {
Find(info, blendTreeSlotAnimation?.m_animation, replacements, context);
}
}
}
break;
}
case 0x2C: {
if (info.m_sounds.ContainsKey(guid)) break;
STUSound sound = GetInstance<STUSound>(guid);
if (sound == null) break;
SoundInfoNew soundInfo = new SoundInfoNew(guid);
info.m_sounds[guid] = soundInfo;
if (sound.m_C32C2195 != null) {
if (sound.m_C32C2195.m_soundWEMFiles != null) {
soundInfo.SoundFiles = new Dictionary<uint, ulong>();
int i = 0;
foreach (teStructuredDataAssetRef<STU_FBCC5EB2> soundWemFile in sound.m_C32C2195.m_soundWEMFiles) {
Find(info, soundWemFile, replacements, context);
soundInfo.SoundFiles[sound.m_C32C2195.m_wwiseWEMFileIDs[i]] = GetReplacement(soundWemFile, replacements);
i++;
}
}
if (sound.m_C32C2195.m_soundWEMStreams != null) {
soundInfo.SoundStreams = new Dictionary<uint, ulong>();
int i = 0;
foreach (teStructuredDataAssetRef<STU_FBCC5EB2> soundWemStream in sound.m_C32C2195.m_soundWEMStreams) {
Find(info, soundWemStream, replacements, context);
soundInfo.SoundStreams[sound.m_C32C2195.m_wwiseWEMStreamIDs[i]] = GetReplacement(soundWemStream, replacements);
i++;
}
}
if (sound.m_C32C2195.m_09D4067B != null) {
foreach (teStructuredDataAssetRef<STU_C77C3128> soundUnk1 in sound.m_C32C2195.m_09D4067B) {
Find(info, soundUnk1, replacements, context);
}
}
if (sound.m_C32C2195.m_4587972B != null) {
foreach (teStructuredDataAssetRef<STU_221B83D5> soundUnk2 in sound.m_C32C2195.m_4587972B) {
Find(info, soundUnk2, replacements, context);
}
}
Find(info, sound.m_C32C2195.m_soundBank);
}
break;
}
case 0x3F:
case 0xBB: {
if (info.m_soundFiles.ContainsKey(guid)) break;