Skip to content

Commit

Permalink
Reach material conversion improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Vegetal-Pole committed Apr 28, 2024
1 parent c5d7123 commit 1202cf1
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions TagTool/Commands/Porting/PortTagCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public void ProcessDeferredActions()
}
}

private void PreConvertReachDefinition(object definition)
private void PreConvertReachDefinition(object definition, Stream blamCacheStream)
{
if(definition is ScenarioStructureBsp sbsp)
{
Expand Down Expand Up @@ -556,11 +556,23 @@ private void PreConvertReachDefinition(object definition)
var newMaterials = new List<Projectile.ProjectileMaterialResponseBlock>();
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<Globals>(BlamCache, blamCacheStream, BlamCache.TagCache.FindFirstInGroup<Globals>());
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());

Expand Down Expand Up @@ -792,7 +804,7 @@ public CachedTag ConvertTagInternal(Stream cacheStream, Stream blamCacheStream,

if(BlamCache.Version >= CacheVersion.HaloReach)
{
PreConvertReachDefinition(blamDefinition);
PreConvertReachDefinition(blamDefinition, blamCacheStream);
}

switch (blamDefinition)
Expand Down Expand Up @@ -1981,6 +1993,17 @@ short FindMatchingMaterial(string name)
if (name.StartsWith("wet_"))
name = name.Substring(4);

// other reach fixups
Dictionary<string, string> substitutions = new Dictionary<string, string>
{
{"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)
Expand Down

0 comments on commit 1202cf1

Please sign in to comment.