Skip to content

Commit

Permalink
fix: mocked material properties are no longer delayed if not neccessery
Browse files Browse the repository at this point in the history
  • Loading branch information
MSchmoecker committed Sep 21, 2022
1 parent 00d7d8e commit cdadc0e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## Version 2.7.9
* Added ZoneManager.OnVanillaClutterAvailable event
* Added CustomClutter to ModRegistry
* Fixed mocked material textures/shaders where not directly fixed after they were injected. Properties that are not available at this time are still delayed
* Fixed connection issues with the upcoming cross play update
* Fixed admin checks for the upcoming cross play update

Expand Down
41 changes: 29 additions & 12 deletions JotunnLib/Managers/MockSystem/MockManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private MockManager() {}
private Dictionary<string, GameObject> mockedPrefabs = new Dictionary<string, GameObject>();
private static HashSet<Material> fixedMaterials = new HashSet<Material>();
private static HashSet<Material> queuedToFixMaterials = new HashSet<Material>();
private static bool canFixMaterials;
private static bool allVanillaObjectsAvailable;

/// <summary>
/// Creates the container and registers all hooks
Expand Down Expand Up @@ -330,21 +330,14 @@ private static void TryFixMaterial(Material material)
return;
}

if (canFixMaterials)
{
FixMaterial(material);
}
else
{
queuedToFixMaterials.Add(material);
}
FixMaterial(material);
}

private static void FixQueuedMaterials()
{
// if the cache is already initialized, some later loaded textures are not found
PrefabManager.Cache.ClearCache<Texture>();
canFixMaterials = true;
allVanillaObjectsAvailable = true;

foreach (var material in new HashSet<Material>(queuedToFixMaterials))
{
Expand All @@ -360,7 +353,7 @@ private static void FixMaterial(Material material)
return;
}

fixedMaterials.Add(material);
bool everythingFixed = true;

foreach (int prop in material.GetTexturePropertyNameIDs())
{
Expand All @@ -379,7 +372,12 @@ private static void FixMaterial(Material material)
}
catch (MockResolveException ex)
{
Logger.LogWarning(ex.Message);
if (allVanillaObjectsAvailable)
{
Logger.LogWarning(ex.Message);
}

everythingFixed = false;
continue;
}

Expand All @@ -399,6 +397,25 @@ private static void FixMaterial(Material material)
{
material.shader = realShader;
}
else
{
if (allVanillaObjectsAvailable)
{
Logger.LogWarning($"Could not find shader {usedShader.name}");
}

everythingFixed = false;
}
}

if (everythingFixed && !fixedMaterials.Contains(material))
{
fixedMaterials.Add(material);
}

if (!everythingFixed && !queuedToFixMaterials.Contains(material))
{
queuedToFixMaterials.Add(material);
}
}
}
Expand Down

0 comments on commit cdadc0e

Please sign in to comment.