-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBundleManager.cs
More file actions
1428 lines (1301 loc) · 77 KB
/
BundleManager.cs
File metadata and controls
1428 lines (1301 loc) · 77 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 AtlasTexturePlugin;
using Frosty.Controls;
using Frosty.Core;
using Frosty.Core.Viewport;
using Frosty.Core.Windows;
using Frosty.Hash;
using FrostySdk;
using FrostySdk.Ebx;
using FrostySdk.IO;
using FrostySdk.Managers;
using FrostySdk.Resources;
using MeshSetPlugin;
using MeshSetPlugin.Resources;
using RootInstanceEntiresPlugin;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing.Drawing2D;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Markup;
using DuplicationPlugin;
using System.Windows.Documents;
using static DuplicationPlugin.DuplicationTool;
using System.Runtime.CompilerServices;
namespace BundleManager
{
internal class BundleManager
{
#region Base Classes and public voids
private FrostyTaskWindow task;
private AssetManager AM
{
get { return App.AssetManager; }
}
private Random rnd = new Random();
private Stopwatch stopWatch = new Stopwatch();
private StringBuilder LogList = new StringBuilder(); //Logs changes so that they can be exported to a csv
private long lastTimestamp = 0;
private List<int> BundleOrder = new List<int>(); //The order of bundles that the Bundle Manager completes in (very important to get right)
private Dictionary<int, BundleParentArrays> BundleParents = new Dictionary<int, BundleParentArrays>();
private Dictionary<int, BM_BundleData> BundleDataDict = new Dictionary<int, BM_BundleData>();
private Dictionary<EbxAssetEntry, List<EbxAssetEntry>> assetsToBM = new Dictionary<EbxAssetEntry, List<EbxAssetEntry>>();
private Dictionary<EbxAssetEntry, List<ChunkAssetEntry>> soundwaveSpecialCase = new Dictionary<EbxAssetEntry, List<ChunkAssetEntry>>();
private Dictionary<EbxAssetEntry, MeshVariData> meshassetSpecialCase = new Dictionary<EbxAssetEntry, MeshVariData>();
private Dictionary<EbxAssetEntry, List<ResAssetEntry>> textureMappingSpecialCase = new Dictionary<EbxAssetEntry, List<ResAssetEntry>>();
Dictionary<EbxAssetEntry, Dictionary<EbxAssetEntry, MeshVariData>> ModifiedObjectVariations = new Dictionary<EbxAssetEntry, Dictionary<EbxAssetEntry, MeshVariData>>();
private bool hasMissedTextureResCache = false;
private Dictionary<ResAssetEntry, EbxAssetEntry> uncachedTextureResMappings = new Dictionary<ResAssetEntry, EbxAssetEntry>();
private Dictionary<EbxAssetEntry, Dictionary<int, EbxAssetEntry>> mvdbsToUpdate = new Dictionary<EbxAssetEntry, Dictionary<int, EbxAssetEntry>>();
private Dictionary<string, AssetLogger> loggerExtensions = new Dictionary<string, AssetLogger>();
private Dictionary<EbxAssetEntry, AssetData> LoggedData = new Dictionary<EbxAssetEntry, AssetData>();
private BundleManagerPrerequisites prerequisites = new BundleManagerPrerequisites();
private bool BlockNetworkRegistries;
public BundleManager(FrostyTaskWindow Task, bool blockNetworkRegistries = false) //Constructor which just loads the cache if it can
{
task = Task;
loggerExtensions.Add("null", new AssetLogger());
foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
{
if (type.IsSubclassOf(typeof(AssetLogger)))
{
var extension = (AssetLogger)Activator.CreateInstance(type);
loggerExtensions.Add(extension.AssetType, extension);
}
}
BundleParents = BmCache.BundleParents.ToDictionary(o => o.Key, o => new BundleParentArrays(o.Value, new List<int>()));
BlockNetworkRegistries = blockNetworkRegistries;
}
public void CompleteBundleManage(List<int> levelBundles = null)
{
stopWatch.Start();
ClearBundleEdits();
if (EstablishBundleLoadOrder())
{
List<int> AllowedBundles = GetAllowedBundles(levelBundles);
FindNewDependencies(AllowedBundles);
BundleEnumeration(AllowedBundles);
ExportLog();
}
stopWatch.Stop();
App.Logger.Log(string.Format("Bundle Manager Completed in {0} seconds.", stopWatch.Elapsed));
CompletionMessage();
}
#endregion
#region Stage 1 - Preparing Bundle Manager (Clearing existing edits, checking there are no bundle infinite loops and finding swbf2 bpb parent bundles)
public void ClearBundleEdits() //Removes any existing bundle edits, reverts net reg and mvdb edits, and sets chunk firstmips to -1
{
App.WhitelistedBundles.Clear();
//Make sure any added bundles have the correct .Blueprint assigned.
foreach (BundleEntry newBunEntry in AM.EnumerateBundles().Where(blueEntry => blueEntry != null && blueEntry.Added && blueEntry.Type != BundleType.SharedBundle && blueEntry.Blueprint == null))
newBunEntry.Blueprint = AM.GetEbxEntry(newBunEntry.Name.Replace("win32/", ""));
List<EbxAssetEntry> bundleBlueprints = AM.EnumerateBundles().Select(bEntry => bEntry.Blueprint).Where(blueEntry => blueEntry != null && blueEntry.IsAdded).ToList();
List<EbxAssetEntry> ebxEntries = AM.EnumerateEbx(modifiedOnly: true).ToList();
foreach (EbxAssetEntry refEntry in ebxEntries)
{
if (bundleBlueprints.Contains(refEntry))
continue;
if (refEntry.Type == null || refEntry.Type == "NetworkRegistryAsset" || refEntry.Type == "MeshVariationDatabase")
AM.RevertAsset(refEntry);
else if (refEntry.Type == "LevelDescriptionAsset")
{
refEntry.AddedBundles.Clear();
Guid refGuid = AM.GetEbx(refEntry).RootInstanceGuid;
EbxAssetEntry levEntry = AM.GetEbxEntry("LevelListReport");
if (((dynamic)AM.GetEbx(levEntry).RootObject).BuiltLevels.Contains(refGuid))
{
foreach (int bunId in levEntry.EnumerateBundles())
refEntry.AddToBundle(bunId);
}
else
App.Logger.LogError($"ERROR: {refEntry.Name} root instance GUID not contained within LevelListReport");
}
else
{
refEntry.AddedBundles.Clear();
if (!refEntry.HasModifiedData || !refEntry.ModifiedEntry.IsDirty)
refEntry.IsDirty = false;
}
}
foreach (ChunkAssetEntry chkEntry in AM.EnumerateChunks(modifiedOnly: true))
{
chkEntry.AddedBundles.Clear();
if (!chkEntry.IsAdded)
chkEntry.FirstMip = -1;
if (!chkEntry.HasModifiedData || !chkEntry.ModifiedEntry.IsDirty)
chkEntry.IsDirty = false;
}
foreach (ResAssetEntry resEntry in AM.EnumerateRes(modifiedOnly: true))
{
resEntry.AddedBundles.Clear();
if (!resEntry.HasModifiedData || !resEntry.ModifiedEntry.IsDirty)
resEntry.IsDirty = false;
}
}
private void AddModdedParent(int bunId, int moddedParentBunId)
{
if (BundleParents.ContainsKey(bunId))
{
if (!BundleParents[bunId].moddedParents.Contains(moddedParentBunId) && !BundleParents[bunId].baseParents.Contains(moddedParentBunId))
BundleParents[bunId].moddedParents.Add(moddedParentBunId);
}
else
BundleParents.Add(bunId, new BundleParentArrays(new List<int>(), new List<int>() { moddedParentBunId }));
}
private bool EstablishBundleLoadOrder(bool loadPrerequisites = true) //Verifies integrity of cached bundle hierarchy and checks if modder has modified the bundle load order (e.g. adding new bpb parent references in swbf2 vurs)
{
bool LoopFound = false;
if (ProfilesLibrary.IsLoaded(ProfileVersion.StarWarsBattlefrontII))
{
foreach (EbxAssetEntry refEntry in App.AssetManager.EnumerateEbx(type: "VisualUnlockRootAsset"))
{
if (refEntry.HasModifiedData)
{
dynamic refRoot = App.AssetManager.GetEbx(refEntry).RootObject;
foreach (dynamic BlueprintBundleReference in refRoot.ThirdPersonBundles)
CheckSwbf2VurBundle(BlueprintBundleReference, refEntry.Name);
foreach (dynamic BlueprintBundleReference in refRoot.FirstPersonBundles)
CheckSwbf2VurBundle(BlueprintBundleReference, refEntry.Name);
foreach (dynamic SkinInfo in refRoot.SkinInfos)
{
CheckSwbf2VurBundle(SkinInfo.ThirdPersonBundle, refEntry.Name);
CheckSwbf2VurBundle(SkinInfo.FirstPersonBundle, refEntry.Name);
}
}
}
foreach (EbxAssetEntry refEntry in App.AssetManager.EnumerateEbx(type: "SubWorldData"))
{
if (refEntry.HasModifiedData)
{
dynamic refRoot = App.AssetManager.GetEbx(refEntry).RootObject;
foreach (dynamic pr in refRoot.Objects)
{
if (pr.Type == PointerRefType.Internal && pr.Internal.GetType().Name == "SubWorldReferenceObjectData")
{
string bunName = "win32/" + pr.Internal.BundleName;
int bunId = AM.GetBundleId(bunName);
if (bunId == -1)
continue;
AddModdedParent(bunId, refEntry.EnumerateBundles().ToList()[0]);
}
}
}
}
}
if (loadPrerequisites)
LoadPrerequisites();
foreach (BundleEntry bunEntry in AM.EnumerateBundles())
{
int bunID = AM.GetBundleId(bunEntry);
if (!BundleDataDict.ContainsKey(bunID))
{
if (SeekBundleParents(bunID, new List<int> { }) == false)
{
LoopFound = true;
break;
}
}
}
return !LoopFound;
}
private void CheckSwbf2VurBundle(dynamic BlueprintBundleReference, string vurName) //Checks swbf2 vur for new bpb parent references
{
foreach (dynamic Par in BlueprintBundleReference.Parents)
{
if (Par.Name != "")
{
if (CheckSwbf2VurBundleName(Par.Name, vurName) == true & CheckSwbf2VurBundleName(BlueprintBundleReference.Name, vurName) == true)
AddModdedParent(AM.GetBundleId("win32/" + BlueprintBundleReference.Name), AM.GetBundleId("win32/" + Par.Name));
}
}
}
private bool CheckSwbf2VurBundleName(string bunName, string vurName) //I can't be bothered to explain this
{
if (AM.GetBundleId("win32/" + bunName) != -1)
return true;
App.Logger.Log(string.Format("Warning: Bundle parent {0} in {1} does not exist", "win32/" + bunName, vurName));
return false;
}
private bool SeekBundleParents(int bunID, List<int> prevBunIDs) //Verifies there are no bundle loops which could cause the bundle manager to never finish
{
if (!prevBunIDs.Contains(bunID))
{
prevBunIDs.Add(bunID);
if (!BundleParents.ContainsKey(bunID))
{
BundleOrder.Add(bunID);
BundleDataDict.Add(bunID, new BM_BundleData { Parents = new List<int>(), ModifiedAssets = new List<EbxAssetEntry>() });
if (Config.Get<bool>("BMO_EnableBundleLogExport", false))
LogString("Bundle", "Logging Parents", string.Format("{0} ({1})", AM.GetBundleEntry(bunID).Name, bunID), "0 parents (No cache data found)");
return true;
}
else
{
List<int> ParentsList = new List<int>();
foreach (int bunParID in BundleParents[bunID].allParents)
{
if (bunID != bunParID)
{
if (!BundleDataDict.ContainsKey(bunParID))
{
if (SeekBundleParents(bunParID, prevBunIDs) == false)
return false;
}
if (!ParentsList.Contains(bunParID))
ParentsList.Add(bunParID);
foreach (int bunGranParID in BundleDataDict[bunParID].Parents)
{
if (!ParentsList.Contains(bunGranParID))
ParentsList.Add(bunGranParID);
}
}
}
if (ProfilesLibrary.IsLoaded(ProfileVersion.StarWarsBattlefrontII)) //Extreme case for swbf2. Not sure if this code is necessary anymore and I can't be bothered to check
{
if (AM.GetBundleEntry(bunID).Name == @"win32/S9_3/COOP_NT_FOSD/COOP_NT_FOSD" || AM.GetBundleEntry(bunID).Name == @"win32/S9_3/COOP_NT_MC85/COOP_NT_MC85")
{
foreach (int badBunId in new List<string> { "win32/gameplay/bundles/sharedbundles/common/animation/sharedbundleanimation_common",
"win32/gameplay/bundles/sharedbundles/frontend+mp/abilities/sharedbundleabilities_frontend+mp"}.Select(o => AM.GetBundleId(o)).ToList())
{
if (ParentsList.Contains(badBunId))
ParentsList.Remove(badBunId);
}
}
}
BundleOrder.Add(bunID);
BundleDataDict.Add(bunID, new BM_BundleData { Parents = ParentsList, ModifiedAssets = new List<EbxAssetEntry>() });
if (Config.Get<bool>("BMO_EnableBundleLogExport", false))
LogString("Bundle", "Logging Parents", string.Format("{0} ({1})", AM.GetBundleEntry(bunID).Name, bunID), String.Join(";", BundleDataDict[bunID].Parents.Select(o => AM.GetBundleEntry(o).Name).ToList()));
return true;
}
}
else
{
App.Logger.Log("ERROR: BUNDLE LOOP DETECTED. BUNDLE MANAGER CANCELLED");
foreach (int prevBunId in prevBunIDs)
{
App.Logger.Log(AM.GetBundleEntry(prevBunId).Name);
}
App.Logger.Log(AM.GetBundleEntry(bunID).Name);
return false;
}
}
private void LoadPrerequisites()
{
string dirName = Path.GetDirectoryName(App.FileSystem.CacheName) + @"/BundleManagerPrerequisites";
if (!Directory.Exists(dirName) || !Config.Get<bool>("BMO_EnablePrerequisites", true))
return;
List<string> prereqFiles = Directory.EnumerateFiles(dirName).Where(file => file.EndsWith(".bmpre")).ToList();
if (prereqFiles.Count == 0)
return;
App.Logger.Log($"Bundle Manager: Using Prerequisites files: {string.Join(", ", prereqFiles.ToList().Select(o => "\"" + Path.GetFileNameWithoutExtension(o) + "\""))}");
foreach (string prereqFile in prereqFiles)
prerequisites.ReadFile(prereqFile, ref BundleParents);
}
public void ExportPrerequistis(string FileName)
{
BundleManagerPrerequisites prerequistes = new BundleManagerPrerequisites();
prerequistes.FindBundleEdits();
EstablishBundleLoadOrder(false);
prerequistes.WriteToFile(FileName, ref BundleParents);
}
#endregion
#region Stage 2 - Finding dependencies of modified base game assets and creating mvdbs for modified/added meshes & objectvariations
private void FindNewDependencies(List<int> AllowedBundles)
{
List<BundleEntry> newBundles = AM.EnumerateBundles().Where(bEntry => bEntry.Added && bEntry.Blueprint != null).ToList();
foreach (BundleEntry bEntry in newBundles)
{
int newBunId = AM.GetBundleId(bEntry);
EbxAssetEntry blueEntry = bEntry.Blueprint;
if (!blueEntry.IsInBundle(AM.GetBundleId(bEntry)))
blueEntry.AddedBundles.Add(AM.GetBundleId(bEntry));
DependencyDetector(blueEntry);
if (!AllowedBundles.Contains(newBunId))
continue;
//Copies over bundle contents of sublevel if the bundles are linked
if (Config.Get<bool>("BMO_CopyLinkedBundles", true))
{
foreach (EbxAssetEntry linkedEntry in blueEntry.LinkedAssets)
{
foreach (int oldBunId in linkedEntry.Bundles)
{
if (AM.GetBundleEntry(oldBunId) != null && AM.GetBundleEntry(oldBunId).Blueprint == linkedEntry)
{
List<AssetEntry> assetsToAdd = new List<AssetEntry>(AM.EnumerateEbx().Where(o => o.IsInBundle(oldBunId)));
assetsToAdd.AddRange(AM.EnumerateRes().Where(o => o.IsInBundle(oldBunId)));
foreach (AssetEntry refEntry in assetsToAdd)
{
if (refEntry != linkedEntry)
{
switch (refEntry.Type)
{
case "NetworkRegistryAsset":
if (!BlockNetworkRegistries)
{
EbxAssetEntry netEntry = new DuplicateAssetExtension().DuplicateAsset((EbxAssetEntry)refEntry, bEntry.Name.ToLower().Substring(6) + "_networkregistry_Win32", false, null);
netEntry.AddedBundles.Clear();
netEntry.AddToBundle(newBunId);
LogString(netEntry.AssetType, "Duplicating original network registry", netEntry.Name, AM.GetBundleEntry(newBunId).Name);
}
break;
case "MeshVariationDatabase":
EbxAssetEntry mvEntry = new DuplicateAssetExtension().DuplicateAsset((EbxAssetEntry)refEntry, bEntry.Name.Replace("win32/", "") + "/MeshVariationDb_Win32", false, null);
mvEntry.AddedBundles.Clear();
mvEntry.AddToBundle(newBunId);
LogString(mvEntry.AssetType, "Duplicating original meshvariationdb", mvEntry.Name, AM.GetBundleEntry(newBunId).Name);
break;
default:
if (refEntry != linkedEntry)
{
refEntry.AddToBundle(newBunId);
LogString(refEntry.AssetType, "Copying from duplicated bundle", refEntry.Name, AM.GetBundleEntry(newBunId).Name);
}
break;
}
}
}
foreach (ChunkAssetEntry chunkEntry in AM.EnumerateChunks().Where(o => o.IsInBundle(oldBunId)))
{
if (BmH32Cache.IsLoaded)
{
chunkEntry.FirstMip = BmH32Cache.chunkCachedData[chunkEntry].Item1;
chunkEntry.H32 = BmH32Cache.chunkCachedData[chunkEntry].Item2;
LogString(chunkEntry.AssetType, "Setting H32&Firstmip (h32 cache)", BmH32Cache.chunkCachedData[chunkEntry].Item1.ToString(), BmH32Cache.chunkCachedData[chunkEntry].Item2.ToString());
}
chunkEntry.AddToBundle(newBunId);
LogString(chunkEntry.AssetType, "Copying from duplicated bundle", chunkEntry.Name, AM.GetBundleEntry(newBunId).Name);
}
}
}
}
}
}
foreach (EbxAssetEntry parEntry in AM.EnumerateEbx())
{
if (parEntry.HasModifiedData)
{
if (!parEntry.IsAdded)
DependencyDetector(parEntry);
string type = "null";
foreach (string uniqueTypes in new List<string> { "SoundWaveAsset", "MeshAsset", "ObjectVariation", "SpatialPrefabBlueprint", "UITextureMappingAsset" })
{
if (TypeLibrary.IsSubClassOf(parEntry.Type, uniqueTypes))
type = uniqueTypes;
}
switch (type)
{
case "SoundWaveAsset": SoundWaveNewChunksDetector(parEntry); break;
case "MeshAsset": MeshAssetDatabaseDetector(parEntry); break;
case "ObjectVariation": ObjectVariationDatabaseDetector(parEntry); break;
case "SpatialPrefabBlueprint": FullDependencyDetector(parEntry); break;
case "UITextureMappingAsset": TextureMappingAssetDetector(parEntry); break;
}
}
}
}
private void DependencyDetector(EbxAssetEntry parEntry) //Finds new ebx references in modified files and orders them to be checked over during the bundle enumeration
{
List<EbxAssetEntry> refEntries = new List<EbxAssetEntry>();
foreach (Guid refGuid in parEntry.EnumerateDependencies())
{
if (!parEntry.DependentAssets.Contains(refGuid))
{
EbxAssetEntry refEntry = AM.GetEbxEntry(refGuid);
if (refEntry != null)
{
LogString("Ebx", "Dependency found", parEntry.Name, refEntry.Name);
refEntries.Add(refEntry);
}
else
LogString("Ebx", "Dependency found", parEntry.Name, "Null Reference");
}
}
if (refEntries.Count != 0)
{
assetsToBM.Add(parEntry, refEntries);
void AddToBundleEnumeration(int bunId)
{
if (BundleDataDict[bunId].ModifiedAssets.Count == 0)
LogString("Bundle", "Preparing to enumerate over bundle", App.AssetManager.GetBundleEntry(bunId).Name, "");
BundleDataDict[bunId].ModifiedAssets.Add(parEntry);
}
foreach (int bunId in parEntry.EnumerateBundles())
AddToBundleEnumeration(bunId);
if (prerequisites.assetsAddedToBundles.ContainsKey(parEntry))
{
foreach (int bunId in prerequisites.assetsAddedToBundles[parEntry].Select(o => App.AssetManager.GetBundleId(o)))
AddToBundleEnumeration(bunId);
}
}
}
private void FullDependencyDetector(EbxAssetEntry parEntry)
{
if (parEntry.IsAdded)
return;
EbxAsset parAsset = AM.GetEbx(parEntry);
dynamic parRoot = parAsset.RootObject;
GetModifiedLoggedData(parEntry, parAsset);
if (assetsToBM.ContainsKey(parEntry))
assetsToBM[parEntry] = LoggedData[parEntry].EbxReferences;
else
assetsToBM.Add(parEntry, LoggedData[parEntry].EbxReferences);
}
private void SoundWaveNewChunksDetector(EbxAssetEntry parEntry) //Finds cases where modified sound wave assets have new chunks added to them
{
if (parEntry.IsAdded)
return;
dynamic parRootOrig = AM.GetEbx(parEntry, true).RootObject;
dynamic parRoot = AM.GetEbx(parEntry).RootObject;
List<Guid> origChunkGuids = new List<Guid>();
List<ChunkAssetEntry> newChunkEntries = new List<ChunkAssetEntry>();
foreach (dynamic chunkData in parRootOrig.Chunks)
origChunkGuids.Add(chunkData.ChunkId);
foreach (dynamic chunkData in parRoot.Chunks)
{
if (!origChunkGuids.Contains(chunkData.ChunkId))
{
ChunkAssetEntry chkEntry = App.AssetManager.GetChunkEntry(chunkData.ChunkId);
if (chkEntry != null)
{
LogString("Ebx-Chunk", "Dependency found", parEntry.Name, chkEntry.Name);
newChunkEntries.Add(chkEntry);
}
else
LogString("Ebx-Chunk", "Dependency found", parEntry.Name, "Null Reference");
}
}
if (newChunkEntries.Count != 0)
soundwaveSpecialCase.Add(parEntry, newChunkEntries);
}
private void MeshAssetDatabaseDetector(EbxAssetEntry parEntry) //Creates a MeshVariationDatabase entry for new meshes and detects if modified meshes require a newMeshVariationDatabase
{
EbxAsset parAsset = AM.GetEbx(parEntry);
dynamic parRoot = parAsset.RootObject;
GetModifiedLoggedData(parEntry, parAsset);
bool needsNewEntry = parEntry.IsAdded || CheckMeshNeedsNewDatabase(parEntry, parAsset, parRoot);
if (needsNewEntry)
{
BM_MeshVariationDatabaseEntry bm_mvEntry = new BM_MeshVariationDatabaseEntry(parEntry, parAsset, parRoot);
LoggedData[parEntry].meshVari = new MeshVariData() { BM_MeshVariationDatabaseEntry = bm_mvEntry, refGuids = bm_mvEntry.GetReferenceGuids() };
if (!parEntry.IsAdded && BmCache.MeshVariationEntries.ContainsKey(parEntry) && BmCache.MeshVariationEntries[parEntry].ContainsKey(0) && BmCache.MeshVariationEntries[parEntry][0].BM_MeshVariationDatabaseEntry != null)
{
MeshVariOriginalData unmodifiedData = BmCache.MeshVariationEntries[parEntry][0];
foreach (KeyValuePair<EbxAssetEntry, int> pair in unmodifiedData.dbLocations)
{
if (!mvdbsToUpdate.ContainsKey(pair.Key))
mvdbsToUpdate.Add(pair.Key, new Dictionary<int, EbxAssetEntry>());
mvdbsToUpdate[pair.Key].Add(pair.Value, parEntry);
}
}
}
else
LoggedData[parEntry].meshVari = new MeshVariData() { BM_MeshVariationDatabaseEntry = BmCache.MeshVariationEntries[parEntry][0].BM_MeshVariationDatabaseEntry, refGuids = BmCache.MeshVariationEntries[parEntry][0].refGuids };
}
private bool CheckMeshNeedsNewDatabase(EbxAssetEntry parEntry, EbxAsset parAsset, dynamic parRoot)
{
if (!BmCache.MeshVariationEntries.ContainsKey(parEntry) || !BmCache.MeshVariationEntries[parEntry].ContainsKey(0) || BmCache.MeshVariationEntries[parEntry][0].BM_MeshVariationDatabaseEntry == null)
return true;
BM_MeshVariationDatabaseEntry bm_mvEntry = BmCache.MeshVariationEntries[parEntry][0].BM_MeshVariationDatabaseEntry;
return bm_mvEntry.CheckMeshNeedsUpdating(parAsset, parRoot);
}
private void ObjectVariationDatabaseDetector(EbxAssetEntry parEntry)
{
EbxAsset parAsset = AM.GetEbx(parEntry);
dynamic parRoot = parAsset.RootObject;
uint varHash = parRoot.NameHash;
GetModifiedLoggedData(parEntry, parAsset);
if (!parEntry.IsAdded)
App.Logger.LogWarning($"{parEntry.Name}\n The bundle manager does not update existing MeshVariationDatabase entries for none-duplicated ObjectVariations because the gameplay merger cannot properly handle those edits.\n It is recommended to use the duplication plugin to create a new ObjectVariation with the changes you want");
Dictionary<string, EbxAssetEntry> meshNamesToEntry = new Dictionary<string, EbxAssetEntry>();
foreach (EbxAssetEntry refEntry in App.AssetManager.EnumerateEbx())
{
if (TypeLibrary.IsSubClassOf(refEntry.Type, "MeshAsset"))
meshNamesToEntry.Add($"{refEntry.Filename}_{(uint)Utils.HashString(refEntry.Name)}", refEntry);
}
//Find the mesh(es) which this variation is attached to
foreach (ResAssetEntry resEntry in App.AssetManager.EnumerateRes())
{
if (resEntry.Name.ToLower().StartsWith(parEntry.Name.ToLower()))
{
string meshName = resEntry.Name.ToLower().Substring(parEntry.Name.Length + 1);
meshName = meshName.Substring(0, meshName.IndexOf("/"));
if (!meshNamesToEntry.ContainsKey(meshName))
{
App.Logger.LogWarning($"Bundle Manager: Could not find mesh {meshName.Substring(0, meshName.LastIndexOf("_"))} when trying to create mvdb entry of {parEntry.Name}");
continue;
}
EbxAssetEntry meshEntry = meshNamesToEntry[meshName];
EbxAsset meshAsset = App.AssetManager.GetEbx(meshEntry);
dynamic meshRoot = meshAsset.RootObject;
MeshSet meshSet = App.AssetManager.GetResAs<MeshSet>(App.AssetManager.GetResEntry(meshRoot.MeshSetResource));
Dictionary<string, dynamic> meshMaterialsNameToMaterial = new Dictionary<string, dynamic>();
foreach (dynamic classObject in parAsset.Objects)
{
if (classObject.GetType().Name == "MeshMaterialVariation")
{
//App.Logger.Log(classObject.__Id);
if (classObject.__Id == "MeshMaterialVariation" || meshMaterialsNameToMaterial.ContainsKey(classObject.__Id))
{
App.Logger.LogError($"{parEntry.Name} section \"{classObject.__Id}\"\nYou need to rename your MeshMaterialVariations to match the mesh section names of the original mesh in the materials section and they should each be unique");
return;
}
meshMaterialsNameToMaterial.Add(classObject.__Id, classObject);
}
}
Dictionary<Guid, dynamic> meshSectionToVariationSection = new Dictionary<Guid, dynamic>();
foreach (MeshSetLod lod in meshSet.Lods)
{
foreach (MeshSetSection section in lod.Sections)
{
if (lod.IsSectionRenderable(section) && section.PrimitiveCount > 0)
{
dynamic material = meshRoot.Materials[section.MaterialId].Internal;
if (!meshSectionToVariationSection.ContainsKey(material.__InstanceGuid.ExportedGuid))
{
if (!meshMaterialsNameToMaterial.ContainsKey(section.Name))
{
App.Logger.LogError($"{parEntry.Name} missing mesh material variation \"{section.Name}\"\nYou need to rename your MeshMaterialVariations to match the mesh section names of the original mesh in the materials section and they should each be unique");
return;
}
meshSectionToVariationSection.Add(material.__InstanceGuid.ExportedGuid, meshMaterialsNameToMaterial[section.Name]);
}
}
}
}
BM_MeshVariationDatabaseEntry bm_mvEntry = new BM_MeshVariationDatabaseEntry(meshEntry, meshAsset, meshRoot, parEntry, parRoot, meshSectionToVariationSection);
if (!ModifiedObjectVariations.ContainsKey(parEntry))
ModifiedObjectVariations.Add(parEntry, new Dictionary<EbxAssetEntry, MeshVariData>());
ModifiedObjectVariations[parEntry].Add(meshEntry, new MeshVariData() { BM_MeshVariationDatabaseEntry = bm_mvEntry, refGuids = bm_mvEntry.GetReferenceGuids() });
//LoggedData[parEntry].meshVari = new MeshVariData() { BM_MeshVariationDatabaseEntry = bm_mvEntry, refGuids = bm_mvEntry.GetReferenceGuids() };
}
}
//if (!parEntry.IsAdded && BmCache.ObjectVariationPairs.ContainsKey(parEntry))
//{
// foreach (KeyValuePair<EbxAssetEntry, ResAssetEntry> pair in BmCache.ObjectVariationPairs[parEntry])
// {
// EbxAsset meshAsset = AM.GetEbx(parEntry);
// if (CheckObjectVariationNeedsNewDatabase(parAsset, parRoot, pair.Key, meshAsset, varHash))
// {
// }
// }
//}
}
private bool CheckObjectVariationNeedsNewDatabase(EbxAsset parAsset, dynamic parRoot, EbxAssetEntry meshEntry, EbxAsset meshAsest, uint varHash)
{
if (!BmCache.MeshVariationEntries.ContainsKey(meshEntry) || !BmCache.MeshVariationEntries[meshEntry].ContainsKey(varHash) || BmCache.MeshVariationEntries[meshEntry][varHash].BM_MeshVariationDatabaseEntry == null)
return true;
BM_MeshVariationDatabaseEntry bm_mvEntry = BmCache.MeshVariationEntries[meshEntry][varHash].BM_MeshVariationDatabaseEntry;
return bm_mvEntry.CheckVariationNeedsUpdating(parAsset, parRoot, meshAsest);
}
private void TextureMappingAssetDetector(EbxAssetEntry parEntry)
{
if (parEntry.IsAdded)
return;
EbxAsset parAsset = AM.GetEbx(parEntry);
dynamic parRoot = parAsset.RootObject;
dynamic parRootOrig = AM.GetEbx(parEntry, true).RootObject;
List<ResourceRef> origTextureRefs = new List<ResourceRef>();
List<ResAssetEntry> newTextureEntries = new List<ResAssetEntry>();
foreach (dynamic mappingEntry in parRootOrig.Output)
origTextureRefs.Add(mappingEntry.TextureRef);
foreach (dynamic mappingEntry in parRoot.Output) {
if (!origTextureRefs.Contains(mappingEntry.TextureRef))
{
ResourceRef texRef = mappingEntry.TextureRef;
ResAssetEntry resEntry = AM.GetResEntry(texRef);
if (resEntry != null)
{
LogString("Ebx-Res", "Dependency found", parEntry.Name, resEntry.Name);
newTextureEntries.Add(resEntry);
}
else
{
App.Logger.LogWarning($"Res entry {texRef} could not be found in this project. Make sure to bundle this asset properly if referencing an external resource.");
App.Logger.LogWarning($"Referenced in {parEntry.Name} Output[{parRoot.Output.IndexOf(mappingEntry)}]");
LogString("Ebx-Res", "Dependency found", parEntry.Name, "Null Reference");
}
}
}
if (newTextureEntries.Count != 0)
{
textureMappingSpecialCase.Add(parEntry, newTextureEntries);
}
}
#endregion
#region Stage 3 - Bundle Enumeration
private void BundleEnumeration(List<int> AllowedBundles)
{
LoadSwbf2FrontendAnimations(AllowedBundles);
int taskIdx = 0;
int taskCount = BundleOrder.Where(bunID => BundleDataDict[bunID].ModifiedAssets.Count > 0 && AllowedBundles.Contains(bunID)).ToList().Count;
LogString("BUNDLE MANAGER", "Enumerating Over", string.Format("{0}/{1} bundles", taskCount, BundleOrder.Count), "");
//task.Update(status: "Enumerating Bundles");
foreach (int bunID in BundleOrder) //DO NOT USE PARALLEL FOREACH
{
if (AllowedBundles.Contains(bunID))
{
if (BundleDataDict[bunID].ModifiedAssets.Count > 0)
task.Update(status: String.Format("Completing: {0}", AM.GetBundleEntry(bunID).Name), progress: ((double)taskIdx++ / (double)taskCount) * 100.0d);
BundleCompleter(bunID);
}
}
//Make sure all of the new bundles have some asset in them else Frosty will crash if the bundle is empty
foreach (BundleEntry bEntry in App.AssetManager.EnumerateBundles().Where(bEntry => bEntry.Added).ToList())
GetEmptyChunk().AddToBundle(App.AssetManager.GetBundleId(bEntry));
}
private void BundleCompleter(int bunID)
{
string bunName = AM.GetBundleEntry(bunID).Name;
List<int> parIDs = BundleDataDict[bunID].Parents;
List<MeshVariData> NewMeshVariationDbEntries = new List<MeshVariData>();
List<EbxImportReference> NewNetworkRegistryReferences = new List<EbxImportReference>();
List<EbxAssetEntry> AddedObjectVariations = new List<EbxAssetEntry>();
EbxAssetEntry mvdbEntry = AM.GetEbxEntry(AM.GetBundleEntry(bunID).Name.ToLower().Substring(6) + "/MeshVariationDb_Win32");
bool prereqBundle = AM.GetBundleEntry(bunID).Added && AM.GetBundleEntry(bunID).Type == BundleType.SubLevel && AM.GetEbxEntry(AM.GetBundleEntry(bunID).Name) == null;
List<EbxAssetEntry> ignoreDependencies = !prereqBundle ? new List<EbxAssetEntry>() : prerequisites.assetsAddedToBundles.Where(bunList => bunList.Value.Contains(AM.GetBundleEntry(bunID))).Select(ebxEntry => ebxEntry.Key).ToList();
//Adding dependencies to bundle
if (BundleDataDict[bunID].ModifiedAssets.Count > 0)
{
LogString("Bundle", "Completing Bundle", AM.GetBundleEntry(bunID).Name, BundleDataDict[bunID].ModifiedAssets.Count + " assets enumerating over");
parIDs = BundleDataDict[bunID].Parents;
foreach (EbxAssetEntry parEntry in BundleDataDict[bunID].ModifiedAssets)
{
LogString("Ebx", "Completing Dependencies", parEntry.Name, assetsToBM[parEntry].Count + " assets");
foreach (EbxAssetEntry refEntry in assetsToBM[parEntry])
CheckAddEbxToBundle(refEntry);
}
foreach (EbxAssetEntry varEntry in AddedObjectVariations)
{
if (ModifiedObjectVariations.ContainsKey(varEntry))
{
foreach (KeyValuePair<EbxAssetEntry, MeshVariData> pair in ModifiedObjectVariations[varEntry])
{
if (IsLoaded(pair.Key))
{
NewMeshVariationDbEntries.Add(pair.Value);
EbxAssetEntry meshEntry = AM.GetEbxEntry(pair.Value.BM_MeshVariationDatabaseEntry.Mesh.External.FileGuid);
ResAssetEntry variationBlocks = AM.GetResEntry($"{varEntry.Name.ToLower()}/{meshEntry.Filename}_{(uint)Utils.HashString(meshEntry.Name)}/shaderblocks_variation/blocks");
CheckAddResToBundle(variationBlocks);
}
}
}
else
{
if (varEntry.IsAdded)
continue;
foreach (KeyValuePair<EbxAssetEntry, ResAssetEntry> pair in BmCache.ObjectVariationPairs[varEntry])
{
if (IsLoaded(pair.Key) && (mvdbEntry == null || !(mvdbEntry.ContainsDependency(varEntry.Guid) && mvdbEntry.ContainsDependency(pair.Key.Guid))))
{
MeshVariOriginalData variation = BmCache.MeshVariationEntries[pair.Key][(uint)Utils.HashString(varEntry.Name, true)];
CheckAddResToBundle(pair.Value);
List<Guid> refGuids = new List<Guid>(variation.refGuids);
refGuids.Add(varEntry.Guid);
NewMeshVariationDbEntries.Add(new MeshVariData() { BM_MeshVariationDatabaseEntry = variation.BM_MeshVariationDatabaseEntry, refGuids = refGuids });
using (NativeReader reader = new NativeReader(AM.GetRes(pair.Value)))
{
for (int idx = 72; idx < Convert.ToInt32(reader.BaseStream.Length - 12); idx = idx + 4)
{
reader.BaseStream.Position = idx;
EbxAssetEntry readEntry = RootInstanceEbxEntryDb.GetEbxEntryByRootInstanceGuid(reader.ReadGuid());
if (readEntry != null && readEntry != varEntry && (!BmCache.UnmodifiedAssetData.ContainsKey(varEntry) || !BmCache.UnmodifiedAssetData[varEntry].EbxReferences.Contains(readEntry)) && !IsLoaded(readEntry))
{
CheckAddEbxToBundle(readEntry);
//App.Logger.Log(readEntry.Name);
}
}
}
}
}
}
}
}
//MeshVariationDB
if (Config.Get<bool>("BMO_CompleteMeshVariationDBs", true))
{
if (NewMeshVariationDbEntries.Count != 0 || (mvdbEntry != null && mvdbsToUpdate.ContainsKey(mvdbEntry)))
{
int count = NewMeshVariationDbEntries.Count;
if (mvdbEntry != null && mvdbsToUpdate.ContainsKey(mvdbEntry))
count = count + mvdbsToUpdate[mvdbEntry].Count;
LogString("Bundle", "Completing MeshVariationDatabase", AM.GetBundleEntry(bunID).Name, count + " entries enumerating over");
if (mvdbEntry != null)
{
EbxAsset meshvariAsset = AM.GetEbx(mvdbEntry);
dynamic meshvariRoot = meshvariAsset.RootObject;
if (mvdbsToUpdate.ContainsKey(mvdbEntry))
{
foreach (KeyValuePair<int, EbxAssetEntry> pair in mvdbsToUpdate[mvdbEntry])
{
meshvariRoot.Entries[pair.Key] = LoggedData[pair.Value].meshVari.BM_MeshVariationDatabaseEntry.WriteToGameEntry();
foreach (Guid texGuid in LoggedData[pair.Value].meshVari.refGuids)
{
if (!mvdbEntry.ContainsDependency(texGuid))
meshvariAsset.AddDependency(texGuid);
}
}
LogString("Bundle", "Updated MeshVariationDB Modified Entries", mvdbEntry.Name, mvdbsToUpdate[mvdbEntry].Count.ToString() + " entries edited");
mvdbsToUpdate.Remove(mvdbEntry);
}
foreach (MeshVariData mvEntry in NewMeshVariationDbEntries)
{
meshvariRoot.Entries.Add(mvEntry.BM_MeshVariationDatabaseEntry.WriteToGameEntry());
foreach (Guid refGuid in mvEntry.refGuids)
meshvariAsset.AddDependency(refGuid);
}
if (NewMeshVariationDbEntries.Count > 0)
LogString("Bundle", "Added MeshVariationDB New Entries", mvdbEntry.Name, NewMeshVariationDbEntries.Count.ToString() + " entries added");
AM.ModifyEbx(mvdbEntry.Name, meshvariAsset);
}
else
{
CreateMeshVariationDatabase(AM.GetBundleEntry(bunID).Name.Replace("win32/", "") + "/MeshVariationDb_Win32");
}
}
}
//Network Registry
if (NewNetworkRegistryReferences.Count > 0 & Config.Get<bool>("BMO_CompleteNetworkRegistries", true) == true && !BlockNetworkRegistries)
{
EbxAssetEntry netregEntry = AM.GetEbxEntry(AM.GetBundleEntry(bunID).Name.ToLower().Substring(6) + "_networkregistry_Win32");
if (netregEntry != null)
{
if (!netregEntry.IsAdded)
netregEntry.ClearModifications();
if (Config.Get<bool>("BMO_CreateNetworkRegistries", false) && !netregEntry.IsAdded)
CreateNetworkRegistry(netregEntry.Name.Replace("_networkregistry_Win32", "") + "Modded_" + rnd.Next(0, Int32.MaxValue).ToString() + rnd.Next(0, Int32.MaxValue).ToString() + "_networkregistry_Win32");
else
AddNetRegEntries(netregEntry, true);
}
else if (AM.GetBundleEntry(bunID).Type == BundleType.SubLevel)
CreateNetworkRegistry(AM.GetBundleEntry(bunID).Name.ToLower().Substring(6) + "_networkregistry_Win32");
//Config.Get<bool>("BMO_CreateNetworkRegistries", false);
}
//Loading Sound Wave Chunks
foreach (EbxAssetEntry refEntry in soundwaveSpecialCase.Keys)
{
if (refEntry.IsInBundle(bunID) || (prerequisites.assetsAddedToBundles.ContainsKey(refEntry) && prerequisites.assetsAddedToBundles[refEntry].Select(o => App.AssetManager.GetBundleId(o)).Contains(bunID)))
{
foreach (ChunkAssetEntry chkEntry in soundwaveSpecialCase[refEntry])
CheckAddChkToBundle(chkEntry);
}
}
//Loading mapped textures
foreach (EbxAssetEntry refEntry in textureMappingSpecialCase.Keys)
{
//App.Logger.Log("Checking texture mappings for " + refEntry.Name);
if (refEntry.IsInBundle(bunID) || (prerequisites.assetsAddedToBundles.ContainsKey(refEntry) && prerequisites.assetsAddedToBundles[refEntry].Select(o => App.AssetManager.GetBundleId(o)).Contains(bunID)))
{
foreach (ResAssetEntry resEntry in textureMappingSpecialCase[refEntry])
{
EbxAssetEntry theTextureEntry = FindTextureEbxForRes(resEntry);
CheckAddEbxToBundle(theTextureEntry);
CheckAddResToBundle(resEntry);
}
} else
{
//App.Logger.Log("Skipping");
}
}
// reset after run
if (hasMissedTextureResCache)
{
//App.Logger.Log("Resetting ad hoc texture/res cache");
hasMissedTextureResCache = false;
uncachedTextureResMappings.Clear();
}
//Methods
bool IsLoaded(AssetEntry refEntry)
{
if (refEntry == null)
return true;
if (refEntry.IsInBundle(bunID))
return true;
foreach (int parId in parIDs)
{
if (refEntry.IsInBundle(parId))
return true;
}
if (ignoreDependencies.Contains(refEntry))
return true;
return false;
}
void CheckAddEbxToBundle(EbxAssetEntry refEntry)
{
if (!IsLoaded(refEntry))
AddEbxToBundle(refEntry);
}
void AddEbxToBundle(EbxAssetEntry parEntry)
{
if (!LoggedData.ContainsKey(parEntry))
GetLoggedData(parEntry);
LogString(parEntry.AssetType, "Adding to bundle", parEntry.Name, AM.GetBundleEntry(bunID).Name);
parEntry.AddToBundle(bunID);
AssetData parData = LoggedData[parEntry];
foreach (ResAssetEntry resEntry in parData.Res)
CheckAddResToBundle(resEntry);
foreach ((ChunkAssetEntry, int, string) chkData in parData.Chunks)
{
//App.Logger.Log((!chkData.Item1.IsAdded && !chkData.Item1.HasModifiedData).ToString());
if (!chkData.Item1.IsAdded && !chkData.Item1.HasModifiedData)
{
if (BmH32Cache.IsLoaded)
{
chkData.Item1.FirstMip = BmH32Cache.chunkCachedData[chkData.Item1].Item1;
chkData.Item1.H32 = BmH32Cache.chunkCachedData[chkData.Item1].Item2;
LogString(chkData.Item1.AssetType, "Setting H32&Firstmip (h32 cache)", BmH32Cache.chunkCachedData[chkData.Item1].Item1.ToString(), BmH32Cache.chunkCachedData[chkData.Item1].Item2.ToString());
}
else
{
chkData.Item1.FirstMip = chkData.Item2;
chkData.Item1.H32 = Utils.HashString(chkData.Item3 != null ? chkData.Item3 : parEntry.Name, true);
LogString(chkData.Item1.AssetType, "Setting H32&Firstmip (cache)", chkData.Item2.ToString(), chkData.Item1.H32.ToString());
}
}
CheckAddChkToBundle(chkData.Item1);
}
if (parData.Objects != null)
{
foreach (EbxImportReference InstanceObj in parData.Objects)
NewNetworkRegistryReferences.Add(InstanceObj);
}
if (parData.meshVari != null)
NewMeshVariationDbEntries.Add(parData.meshVari);
if (parEntry.Type == "ObjectVariation")
AddedObjectVariations.Add(parEntry);
foreach (EbxAssetEntry refEntry in parData.EbxReferences)
CheckAddEbxToBundle(refEntry);
}
void CheckAddResToBundle(ResAssetEntry refEntry)
{
if (!IsLoaded(refEntry))
AddResToBundle(refEntry);
}
void AddResToBundle(ResAssetEntry refEntry)
{
LogString(refEntry.AssetType, "Adding to bundle", refEntry.Name, bunName);
refEntry.AddToBundle(bunID);
}
void CheckAddChkToBundle(ChunkAssetEntry refEntry)
{
if (!IsLoaded(refEntry))
AddChkToBundle(refEntry);
}
void AddChkToBundle(ChunkAssetEntry refEntry)
{
LogString(refEntry.AssetType, "Adding to bundle", refEntry.Name, bunName);
refEntry.AddToBundle(bunID);
//if (refEntry.FirstMip == -1 && BmCache.ChunkFirstMips.ContainsKey(refEntry))
// refEntry.FirstMip = BmCache.ChunkFirstMips[refEntry];
}
void GetLoggedData(EbxAssetEntry parEntry)
{
if (!parEntry.HasModifiedData)
{
if (BmCache.UnmodifiedAssetData.ContainsKey(parEntry))
{
LogString("Ebx", "Reading Cached Data", parEntry.Name, parEntry.Type.ToString());
LoggedData.Add(parEntry, BmCache.UnmodifiedAssetData[parEntry]);
if (TypeLibrary.IsSubClassOf(parEntry.Type, "MeshAsset"))
LoggedData[parEntry].meshVari = new MeshVariData() { BM_MeshVariationDatabaseEntry = BmCache.MeshVariationEntries[parEntry][0].BM_MeshVariationDatabaseEntry, refGuids = BmCache.MeshVariationEntries[parEntry][0].refGuids };
}
else
LoggedData.Add(parEntry, new AssetData() { EbxReferences = parEntry.EnumerateDependencies().Select(o => App.AssetManager.GetEbxEntry(o)).ToList(), Chunks = new List<(ChunkAssetEntry, int, string)>(), Res = new List<ResAssetEntry>() });
}