Skip to content

Commit

Permalink
Merge pull request #253 from SpaceWarpDev/1.4.1_hotfix
Browse files Browse the repository at this point in the history
1.4.1 hotfix
  • Loading branch information
cheese3660 authored Aug 24, 2023
2 parents 60c9956 + 4c69110 commit cf60e69
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<SpaceWarpVersion>1.4.0</SpaceWarpVersion>
<SpaceWarpVersion>1.4.1</SpaceWarpVersion>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>11</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
5 changes: 2 additions & 3 deletions SpaceWarp/Patching/BootstrapPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 18 additions & 4 deletions SpaceWarp/Patching/ColorsPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Renderer>())
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<Renderer>(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;
Expand Down
2 changes: 1 addition & 1 deletion SpaceWarpBuildTemplate/swinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit cf60e69

Please sign in to comment.