55using System . Reflection . Emit ;
66using HarmonyLib ;
77using RimWorld ;
8+ using Steamworks ;
89using UnityEngine ;
910using Verse ;
1011using Verse . Steam ;
@@ -235,6 +236,7 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
235236 List < CodeInstruction > instructions = new List < CodeInstruction > ( instr ) ;
236237
237238 ConstructorInfo ciTarget = AccessTools . Constructor ( typeof ( WorkshopItem_Mod ) ) ;
239+ MethodInfo miAnchor = AccessTools . DeclaredMethod ( typeof ( SteamUGC ) , nameof ( SteamUGC . GetItemInstallInfo ) ) ;
238240
239241 int idxAnchor = instructions . FirstIndexOf ( ci => ci . opcode == OpCodes . Newobj && ci . operand == ciTarget ) ;
240242
@@ -243,18 +245,43 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
243245 return instructions ;
244246 }
245247
248+
249+
250+ int idxGetItemInstallInfo = instructions . FirstIndexOf ( ci => ci . opcode == OpCodes . Call && ci . operand == miAnchor ) ;
251+ if ( idxGetItemInstallInfo == - 1 ) {
252+ Util . Warning ( "Could not find SteamUGC.GetItemInstallInfo transpiler anchor - not injecting code" ) ;
253+ return instructions ;
254+ }
255+
256+ Log . Message ( $ "operand: { instructions [ idxGetItemInstallInfo - 1 ] . operand . GetType ( ) } ") ;
257+
258+ LocalBuilder lbTS = null ;
259+ var opcode = instructions [ idxGetItemInstallInfo - 1 ] . opcode ;
260+ if ( opcode == OpCodes . Ldloca || opcode == OpCodes . Ldloca_S ) {
261+ lbTS = ( LocalBuilder ) instructions [ idxGetItemInstallInfo - 1 ] . operand ;
262+ } else {
263+ Util . Warning ( "Could not find SteamUGC.GetItemInstallInfo TS local - not injecting code" ) ;
264+ return instructions ;
265+ }
266+
246267 /* Transform
268+ * ...
269+ * SteamUGC.GetItemInstallInfo(..., out [foo]);
270+ *
271+ * ...
247272 *
248273 * if (workshopItem == null)
249274 * {
250275 * workshopItem = new WorkshopItem_Mod();
251276 * }
252277 *
253278 * into
254- *
279+ * ...
280+ * SteamUGC.GetItemInstallInfo(..., out [foo]);
281+ * ....
255282 * if (workshopItem == null)
256283 * {
257- * ModsConfigUI.UpdateSteamTS(pfid, num2 );
284+ * ModsConfigUI.UpdateSteamTS(pfid, [foo] );
258285 * workshopItem = new WorkshopItem_Mod();
259286 * }
260287 *
@@ -264,7 +291,7 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
264291 idxAnchor ,
265292 new [ ] {
266293 new CodeInstruction ( OpCodes . Ldarg_0 ) ,
267- new CodeInstruction ( OpCodes . Ldloc_2 ) ,
294+ new CodeInstruction ( OpCodes . Ldloc , lbTS ) ,
268295 new CodeInstruction ( OpCodes . Call , AccessTools . Method ( typeof ( ModsConfigUI . Helpers ) , nameof ( ModsConfigUI . Helpers . UpdateSteamTS ) ) )
269296 }
270297 ) ;
0 commit comments