From 1202cf1869f25e08ed3b26e1b2703d19016c392f Mon Sep 17 00:00:00 2001 From: Vegetal-Pole Date: Sat, 27 Apr 2024 23:03:48 -0500 Subject: [PATCH] Reach material conversion improvements --- TagTool/Commands/Porting/PortTagCommand.cs | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/TagTool/Commands/Porting/PortTagCommand.cs b/TagTool/Commands/Porting/PortTagCommand.cs index 849fcfb5..8947c7c8 100644 --- a/TagTool/Commands/Porting/PortTagCommand.cs +++ b/TagTool/Commands/Porting/PortTagCommand.cs @@ -337,7 +337,7 @@ public void ProcessDeferredActions() } } - private void PreConvertReachDefinition(object definition) + private void PreConvertReachDefinition(object definition, Stream blamCacheStream) { if(definition is ScenarioStructureBsp sbsp) { @@ -556,11 +556,23 @@ private void PreConvertReachDefinition(object definition) var newMaterials = new List(); var converter = new StructureAutoConverter(BlamCache, CacheContext); converter.TranslateList(proj.MaterialResponsesNew, newMaterials); + if (proj.MaterialResponses != null && proj.MaterialResponses.Count > 0) proj.MaterialResponses.AddRange(newMaterials); else proj.MaterialResponses = newMaterials; + // some reach old materials have mismatched names and indices + var reachGlobals = DeserializeTagCached(BlamCache, blamCacheStream, BlamCache.TagCache.FindFirstInGroup()); + var reachMaterials = reachGlobals.AlternateMaterials; + foreach (var response in proj.MaterialResponses) + { + if (response.RuntimeMaterialIndex < 0 || response.RuntimeMaterialIndex >= reachMaterials.Count) + response.RuntimeMaterialIndex = -1; + else if (reachMaterials[response.RuntimeMaterialIndex].Name != response.MaterialName) + response.RuntimeMaterialIndex = (short)reachMaterials.FindIndex(m => m.Name == response.MaterialName); + } + // preconvert projectile flags converter.TranslateEnum(proj.FlagsReach, out proj.Flags, proj.Flags.GetType()); @@ -792,7 +804,7 @@ public CachedTag ConvertTagInternal(Stream cacheStream, Stream blamCacheStream, if(BlamCache.Version >= CacheVersion.HaloReach) { - PreConvertReachDefinition(blamDefinition); + PreConvertReachDefinition(blamDefinition, blamCacheStream); } switch (blamDefinition) @@ -1981,6 +1993,17 @@ short FindMatchingMaterial(string name) if (name.StartsWith("wet_")) name = name.Substring(4); + // other reach fixups + Dictionary substitutions = new Dictionary + { + {"hard_metal_thin_hum_spartan", "hard_metal_thin_hum_masterchief"}, + {"energy_shield_thin_hum_spartan", "energy_shield_thin_hum_masterchief"}, + {"energy_shield_invulnerable", "energy_shield_invincible"}, + {"energy_hologram", "energy_holo"}, + }; + if (substitutions.TryGetValue(name, out var sub)) + name = sub; + // search for the name in the destination materials var matchIndex = (short)materials.FindIndex(x => CacheContext.StringTable.GetString(x.Name) == name); if (matchIndex != -1)