diff --git a/Directory.Build.props b/Directory.Build.props index 63ed50bd..9a68941f 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 1.4.0 + 1.4.1 netstandard2.0 11 true diff --git a/SpaceWarp/Patching/BootstrapPatch.cs b/SpaceWarp/Patching/BootstrapPatch.cs index ca7ea069..1b69cb7c 100644 --- a/SpaceWarp/Patching/BootstrapPatch.cs +++ b/SpaceWarp/Patching/BootstrapPatch.cs @@ -71,12 +71,11 @@ private static void PatchInitializationsIL(ILContext ilContext, ILLabel endLabel { flow.AddAction(new LoadAddressablesAction(plugin)); flow.AddAction(new LoadLocalizationAction(plugin)); - if (plugin.Plugin != null) + if (plugin.Plugin is BaseSpaceWarpPlugin baseSpaceWarpPlugin) { foreach (var action in Loading.LoadingActionGenerators) { - if (plugin.Plugin is BaseSpaceWarpPlugin baseSpaceWarpPlugin) - flow.AddAction(action(baseSpaceWarpPlugin)); + flow.AddAction(action(baseSpaceWarpPlugin)); } } else diff --git a/SpaceWarp/Patching/ColorsPatch.cs b/SpaceWarp/Patching/ColorsPatch.cs index 1ee57d2d..4acbb2c2 100644 --- a/SpaceWarp/Patching/ColorsPatch.cs +++ b/SpaceWarp/Patching/ColorsPatch.cs @@ -5,6 +5,8 @@ using KSP.Game; using KSP.Modules; using KSP.OAB; +using KSP.Sim; +using KSP.Sim.impl; using SpaceWarp.API.Assets; using UnityEngine; @@ -25,14 +27,26 @@ internal class ColorsPatch UNITY_STANDARD = "Standard"; [HarmonyPatch(typeof(ObjectAssemblyPartTracker), nameof(ObjectAssemblyPartTracker.OnPartPrefabLoaded))] - public static void Prefix(IObjectAssemblyAvailablePart obj, ref GameObject prefab) + internal static void Prefix(IObjectAssemblyAvailablePart obj, ref GameObject prefab) { - foreach(var renderer in prefab.GetComponentsInChildren()) + ReplaceShader(ref prefab, Shader.Find(KSP2_OPAQUE_PATH), "Parts Replace", "KSP2/Parts/Paintable"); + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(SimulationObjectView), nameof(SimulationObjectView.InitializeView))] + internal static void ApplyOnGameObjectFlight(GameObject instance, IUniverseView universe, SimulationObjectModel model) + { + ReplaceShader(ref instance, Shader.Find(KSP2_OPAQUE_PATH), "Parts Replace", "KSP2/Parts/Paintable"); + } + + internal static void ReplaceShader(ref GameObject target, Shader shaderToReplace,params string[] allowedShaders) + { + foreach (var renderer in target.GetComponentsInChildren(true)) { string shaderName = renderer.material.shader.name; - if (shaderName == "Parts Replace" || shaderName == "KSP2/Parts/Paintable") + if (allowedShaders.Contains(shaderName)) { - var mat = new Material(Shader.Find(KSP2_OPAQUE_PATH)); + var mat = new Material(shaderToReplace); mat.name = renderer.material.name; mat.CopyPropertiesFromMaterial(renderer.material); renderer.material = mat; diff --git a/SpaceWarpBuildTemplate/swinfo.json b/SpaceWarpBuildTemplate/swinfo.json index dade532c..609689f4 100644 --- a/SpaceWarpBuildTemplate/swinfo.json +++ b/SpaceWarpBuildTemplate/swinfo.json @@ -6,7 +6,7 @@ "description": "Space-Warp is an API for KSP2 mod developers.", "source": "https://github.com/SpaceWarpDev/SpaceWarp", "version_check": "https://raw.githubusercontent.com/SpaceWarpDev/SpaceWarp/main/SpaceWarpBuildTemplate/swinfo.json", - "version": "1.4.0", + "version": "1.4.1", "dependencies": [ { "id": "UitkForKsp2",