@@ -10,19 +10,12 @@ public class MaterialColorUpdaterPatch
1010{
1111 internal static readonly Dictionary < MaterialColorUpdater , Props > temperatureColorProps = [ ] ;
1212
13- [ HarmonyPostfix ]
14- [ HarmonyPatch ( MethodType . Constructor , typeof ( Transform ) , typeof ( int ) , typeof ( Part ) ) ]
15- private static void MaterialColorUpdater_Ctor_Postfix ( MaterialColorUpdater __instance )
16- {
17- temperatureColorProps [ __instance ] = new Props ( int . MinValue + 1 ) ;
18- }
19-
2013 [ HarmonyPostfix ]
2114 [ HarmonyPatch ( "CreateRendererList" ) ]
2215 private static void MaterialColorUpdater_CreateRendererList_Postfix (
2316 MaterialColorUpdater __instance )
2417 {
25- var props = temperatureColorProps [ __instance ] ;
18+ var props = temperatureColorProps [ __instance ] = new Props ( int . MinValue + 1 ) ;
2619 foreach ( var renderer in __instance . renderers ) {
2720 MaterialPropertyManager . Instance ? . Set ( renderer , props ) ;
2821 }
@@ -46,6 +39,7 @@ private static IEnumerable<CodeInstruction> Update_Transpiler(
4639 foreach ( var insn in insns ) {
4740 yield return insn ;
4841
42+ // this.mpb.SetColor(this.propertyID, this.setColor);
4943 // IL_0022: ldarg.0 // this
5044 // IL_0023: ldfld class UnityEngine.MaterialPropertyBlock MaterialColorUpdater::mpb
5145 // IL_0028: ldarg.0 // this
@@ -54,14 +48,17 @@ private static IEnumerable<CodeInstruction> Update_Transpiler(
5448 // IL_002f: ldfld valuetype UnityEngine.Color MaterialColorUpdater::setColor
5549 // IL_0034: callvirt instance void UnityEngine.MaterialPropertyBlock::SetColor(int32, valuetype UnityEngine.Color)
5650 if ( insn . Calls ( MPB_SetColor ) ) break ;
51+ // Remaining code applies MPB to renderers.
5752 }
5853
59- CodeInstruction [ ] replace = [
54+ // MaterialColorUpdaterPatch.Update_SetProperty(this);
55+ // return;
56+ CodeInstruction [ ] updateProp = [
6057 new ( OpCodes . Ldarg_0 ) , // this
6158 CodeInstruction . Call ( ( ) => Update_SetProperty ( default ) ) ,
6259 new ( OpCodes . Ret )
6360 ] ;
64- foreach ( var insn in replace ) yield return insn ;
61+ foreach ( var insn in updateProp ) yield return insn ;
6562 }
6663
6764 private static void DisposeIfExists ( MaterialColorUpdater mcu )
@@ -84,6 +81,39 @@ private static void Part_OnDestroy_Postfix(Part __instance)
8481 DisposeIfExists ( __instance . temperatureRenderer ) ;
8582 }
8683
84+ [ HarmonyTranspiler ]
85+ [ HarmonyPatch ( typeof ( ModuleJettison ) , nameof ( ModuleJettison . Jettison ) ) ]
86+ private static IEnumerable < CodeInstruction > ModuleJettison_Jettison_Transpiler (
87+ IEnumerable < CodeInstruction > insns )
88+ {
89+ var ModuleJettison_jettisonTemperatureRenderer = AccessTools . Field (
90+ typeof ( ModuleJettison ) , nameof ( ModuleJettison . jettisonTemperatureRenderer ) ) ;
91+
92+ // this.jettisonTemperatureRenderer = null;
93+ // IL_0327: ldarg.0 // this
94+ // IL_0328: ldnull
95+ // IL_0329: stfld class MaterialColorUpdater ModuleJettison::jettisonTemperatureRenderer
96+ CodeMatch [ ] matchSetTempRendererNull = [
97+ new ( OpCodes . Ldarg_0 ) ,
98+ new ( OpCodes . Ldnull ) ,
99+ new ( OpCodes . Stfld , ModuleJettison_jettisonTemperatureRenderer )
100+ ] ;
101+
102+ var matcher = new CodeMatcher ( insns ) ;
103+
104+ matcher
105+ . MatchStartForward ( matchSetTempRendererNull )
106+ . ThrowIfNotMatch ( "failed to find set temp renderer null" )
107+ . Insert (
108+ // MaterialColorUpdaterPatch.DisposeIfExists(this.jettisonTemperatureRenderer);
109+ new CodeInstruction ( OpCodes . Ldarg_0 ) , // this
110+ new CodeInstruction ( OpCodes . Ldfld , ModuleJettison_jettisonTemperatureRenderer ) ,
111+ CodeInstruction . Call ( ( ) => DisposeIfExists ( default ) )
112+ ) ;
113+
114+ return matcher . InstructionEnumeration ( ) ;
115+ }
116+
87117 // FIXME: write a transpiler for ModuleJettison.Jettison.
88118
89119 [ HarmonyPostfix ]
0 commit comments