Skip to content

Commit

Permalink
Possible colors patch fix?
Browse files Browse the repository at this point in the history
  • Loading branch information
cheese3660 committed Oct 31, 2023
1 parent 9b27c29 commit b48db52
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions SpaceWarp.Core/Patching/ColorsPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using KSP.Game;
using KSP.Modules;
using KSP.OAB;
using KSP.Sim.impl;
using SpaceWarp.API.Assets;
using UnityEngine;

Expand Down Expand Up @@ -42,6 +43,24 @@ public static void Prefix(IObjectAssemblyAvailablePart obj, ref GameObject prefa
}
}

[HarmonyPrefix]
[HarmonyPatch(typeof(SimulationObjectView), nameof(SimulationObjectView.InitializeView))]
public static void UpdateColorsInFlight(GameObject instance)
{
foreach (var renderer in instance.GetComponentsInChildren<Renderer>())
{
var shaderName = renderer.material.shader.name;
if (shaderName is not ("Parts Replace" or "KSP2/Parts/Paintable")) continue;
Material material;
var mat = new Material(Shader.Find(Ksp2OpaquePath))
{
name = (material = renderer.material).name
};
mat.CopyPropertiesFromMaterial(material);
renderer.material = mat;
}
}

//Everything below this point will be removed in the next patch
private const int Diffuse = 0;
private const int Metallic = 1;
Expand Down

0 comments on commit b48db52

Please sign in to comment.