static IEnumerable <CodeInstruction> Transpiler1(IEnumerable <CodeInstruction> instructions) { var custominstruc = new CodeMatcher(instructions) .MatchForward(false, new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(l => l.opcode == OpCodes.Call && l.Calls(AccessTools.Method(typeof(SceneEdit), "InitMenuNative")))) .SetAndAdvance(OpCodes.Nop, null) .SetAndAdvance(OpCodes.Nop, null) .SetAndAdvance(OpCodes.Nop, null) .SetAndAdvance(OpCodes.Nop, null) .SetAndAdvance(OpCodes.Nop, null) //.SetAndAdvance(OpCodes.Nop, null) .Insert( new CodeInstruction(OpCodes.Ldarg_0), Transpilers.EmitDelegate <Action>(() => { Debug.Log("Calling your test coroutine."); //InitMenuNativeRe(); //@this2.StartCoroutine(test2()); //Task.Factory.StartNew(new Action(() => InitialBackgroundWorker())); @this2.StartCoroutine(InitialBackgroundWorker()); //@this2.StartCoroutine(MenuLoaderWorker()); //test2(); }), new CodeInstruction(OpCodes.Pop) ) //.Insert(new CodeInstruction (OpCodes.Call, AccessTools.Method(typeof(Main), "InitMenuNativeRe"))) .InstructionEnumeration(); return(custominstruc); }
static IEnumerable <CodeInstruction> CheckConditions(IEnumerable <CodeInstruction> instructions) { CodeMatcher matcher = new CodeMatcher(instructions) .MatchForward(false, new CodeMatch(OpCodes.Ldloc_S), new CodeMatch(i => i.opcode == OpCodes.Ldfld && ((FieldInfo)i.operand).Name == "desc"), new CodeMatch(i => i.opcode == OpCodes.Ldfld && ((FieldInfo)i.operand).Name == "hasBuildCollider"), new CodeMatch(OpCodes.Brfalse), new CodeMatch(OpCodes.Ldloc_S) ).Advance(1) .SetAndAdvance(OpCodes.Ldarg_0, null) .SetInstructionAndAdvance( Transpilers.EmitDelegate <Func <BuildPreview, BuildTool_Click, bool> >( (preview, _this) => { if (preview.item.ID == 2212) { if (_this.handPrefabDesc != null && _this.handPrefabDesc.modelIndex == GroundSubstation.firstSubstationId + 2) { return(false); } } return(preview.desc.hasBuildCollider); })); return(matcher.InstructionEnumeration()); }
public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { CodeMatcher matcher = new CodeMatcher(instructions) .End() .MatchBack(false, new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldflda, AccessTools.Field(typeof(BuildTool_BlueprintPaste), nameof(BuildTool_BlueprintPaste.cursorTarget)))); CodeMatcher matcher2 = matcher.Clone().MatchForward(false, new CodeMatch(OpCodes.Ldloc_S), new CodeMatch(OpCodes.Ldc_I4_S) , new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(BuildPreview), nameof(BuildPreview.condition)))); object previewVariable = matcher2.Operand; matcher.Advance(1); while (matcher.Opcode != OpCodes.Stloc_S) { matcher.RemoveInstruction(); } matcher.InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, previewVariable)) .InsertAndAdvance(Transpilers.EmitDelegate <Func <BuildTool_BlueprintPaste, BuildPreview, Vector3> >((tool, preview) => preview.lpos.normalized * Mathf.Min(tool.planet.realRadius * 0.025f, 20f))); return(matcher.InstructionEnumeration()); }
public static IEnumerable <CodeInstruction> MultiplyUnlockText(IEnumerable <CodeInstruction> instructions) { CodeMatcher matcher = new CodeMatcher(instructions) .MatchForward(false, new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(TechProto), nameof(TechProto.UnlockFunctions)))) .MatchForward(false, new CodeMatch(instr => instr.IsStloc())); OpCode typeStlocOpcode = matcher.Opcode.ToLoad(); object typeStlocOperand = matcher.Operand; matcher.MatchForward(false, new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(TechProto), nameof(TechProto.UnlockValues)))) .MatchForward(false, new CodeMatch(OpCodes.Stloc_S)); object arg = matcher.Operand; matcher.Advance(1) .InsertAndAdvance(new CodeInstruction(typeStlocOpcode, typeStlocOperand)) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloca_S, arg)) .InsertAndAdvance(Transpilers.EmitDelegate <RefAction <int, int> >((int type, ref int value) => { if (type == 18) { value *= GigaStationsPlugin.droneCapacityMultiplier; } else if (type == 19) { value *= GigaStationsPlugin.vesselCapacityMultiplier; } })); return(matcher.InstructionEnumeration()); }
static IEnumerable <CodeInstruction> CodeTranspiler(IEnumerable <CodeInstruction> instructions) { var custominstruc = new CodeMatcher(instructions) .MatchForward(true, new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldfld), new CodeMatch(OpCodes.Ldc_I4_0), new CodeMatch(OpCodes.Ceq), new CodeMatch(OpCodes.Stfld), new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldfld), new CodeMatch(OpCodes.Ldc_I4_0), new CodeMatch(OpCodes.Ceq), new CodeMatch(OpCodes.Stfld), new CodeMatch(OpCodes.Br) ) .Insert( new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(PropMyItem), "_isVisible")), Transpilers.EmitDelegate <Action <bool> >((vis) => { Main.PMIUIStatus = vis; }) ) .InstructionEnumeration(); return(custominstruc); }
private static IEnumerable <CodeInstruction> FilterDrops(IEnumerable <CodeInstruction> instructions) { return(new CodeMatcher(instructions) .MatchForward(false, new CodeMatch(OpCodes.Ldfld, AccessTools.DeclaredField(typeof(CharacterDrop), nameof(CharacterDrop.m_drops)))) .SetInstructionAndAdvance(Transpilers.EmitDelegate(ConditionChecker.FilterOnDeath)) .InstructionEnumeration()); }
private static IEnumerable <CodeInstruction> Transpiler1(IEnumerable <CodeInstruction> instructions) { IEnumerable <CodeInstruction> custominstruc = new CodeMatcher(instructions) .MatchForward(false, new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(l => l.opcode == OpCodes.Call && l.Calls(AccessTools.Method(typeof(SceneEdit), "InitMenuNative")))) .SetAndAdvance(OpCodes.Nop, null) .SetAndAdvance(OpCodes.Nop, null) .SetAndAdvance(OpCodes.Nop, null) .SetAndAdvance(OpCodes.Nop, null) .SetAndAdvance(OpCodes.Nop, null) .Insert( new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldarg_0), Transpilers.EmitDelegate <Action <SceneEdit> >((lthis) => { @this = lthis; Main.logger.LogDebug("Calling your modified CoRoutine"); @this.StartCoroutine(InitMenuNative()); }), new CodeInstruction(OpCodes.Pop) ) .InstructionEnumeration(); return(custominstruc); }
public static IEnumerable <CodeInstruction> ChangeFunction(IEnumerable <CodeInstruction> instructions) { CodeMatcher matcher = new CodeMatcher(instructions) .End() .MatchBack(false, new CodeMatch(OpCodes.Ldloc_S), new CodeMatch(OpCodes.Ldc_I4_1), new CodeMatch(OpCodes.Add) ) .Advance(1) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0)) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(FactoryStorage), nameof(FactoryStorage.tankPool)))) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, 4)) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldelema, typeof(TankComponent))) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_0)) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, 5)) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldelema, typeof(AnimData))) .InsertAndAdvance(Transpilers.EmitDelegate <RefAction <TankComponent, AnimData> >((ref TankComponent tank, ref AnimData anim) => { if (tank.fluidCapacity > 11000) { anim.time = InverseFunction(anim.time); } })); return(matcher.InstructionEnumeration()); }
static IEnumerable <CodeInstruction> Transpiler1(IEnumerable <CodeInstruction> instructions) { var custominstruc = new CodeMatcher(instructions) .MatchForward(false, new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(l => l.opcode == OpCodes.Call && l.Calls(AccessTools.Method(typeof(SceneEdit), "InitMenuNative")))) .SetAndAdvance(OpCodes.Nop, null) .SetAndAdvance(OpCodes.Nop, null) .SetAndAdvance(OpCodes.Nop, null) .SetAndAdvance(OpCodes.Nop, null) .SetAndAdvance(OpCodes.Nop, null) .Insert( new CodeInstruction(OpCodes.Ldarg_0), Transpilers.EmitDelegate <Action>(() => { Debug.Log("Calling your control test coroutine."); @this2.StartCoroutine(InitMenuNative()); }), new CodeInstruction(OpCodes.Pop) ) .InstructionEnumeration(); return(custominstruc); }
public static IEnumerable <CodeInstruction> CargoContainer_Expand2x_Patch(IEnumerable <CodeInstruction> instructions) { CodeMatcher matcher = new CodeMatcher(instructions) .MatchForward(true, new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldloc_0), new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(CargoContainer), nameof(CargoContainer.poolCapacity))) ) .Advance(1) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0)) .InsertAndAdvance(Transpilers.EmitDelegate <Action <CargoContainer> >((CargoContainer __instance) => { if (executeNow) { UpdateCargoBuffer(__instance); } else { expandedCargos.Add(__instance); } })) .InsertAndAdvance(new CodeInstruction(OpCodes.Ret)); return(matcher.InstructionEnumeration()); }
private static IEnumerable <CodeInstruction> Transpile_Player_AddKnownRecipe(IEnumerable <CodeInstruction> instructions) { // Insert our own callback after: // this.m_knownRecipes.Add(recipe.m_item.m_itemData.m_shared.m_name); return(new CodeMatcher(instructions) // IL_0022: ldarg.0 // IL_0023: ldfld class [System.Core] System.Collections.Generic.HashSet`1<string> Player::m_knownRecipes // IL_0028: ldarg.1 // IL_0029: ldfld class ItemDrop Recipe::m_item // IL_002E: ldfld class ItemDrop/ItemData ItemDrop::m_itemData // IL_0033: ldfld class ItemDrop/ItemData/SharedData ItemDrop/ItemData::m_shared // IL_0038: ldfld string ItemDrop/ItemData/SharedData::m_name // IL_003D: callvirt instance bool class [System.Core] System.Collections.Generic.HashSet`1<string>::Add(!0) // IL_0042: pop .MatchForward(true, new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(Player), nameof(Player.m_knownRecipes))), new CodeMatch(OpCodes.Ldarg_1), new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(Recipe), nameof(Recipe.m_item))), new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(ItemDrop), nameof(ItemDrop.m_itemData))), new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(ItemDrop.ItemData), nameof(ItemDrop.ItemData.m_shared))), new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(ItemDrop.ItemData.SharedData), nameof(ItemDrop.ItemData.SharedData.m_name))), new CodeMatch(OpCodes.Callvirt, AccessTools.Method(typeof(HashSet <string>), nameof(HashSet <string> .Add))), new CodeMatch(OpCodes.Pop) ) .Insert( new CodeInstruction(OpCodes.Ldarg_1), Transpilers.EmitDelegate <Action <Recipe> >( recipe => PlayerKnownManager.OnPlayerAddKnownRecipe(recipe.m_item.m_itemData.m_shared.m_name) ) ) .InstructionEnumeration()); }
static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { CodeMatcher matcher = new CodeMatcher(instructions) .MatchForward(false, new CodeMatch(OpCodes.Ldc_R4), new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldfld), new CodeMatch(i => i.opcode == OpCodes.Callvirt && ((MethodInfo)i.operand).Name == "GetVeinsInAreaNonAlloc")) .SetInstructionAndAdvance(new CodeInstruction(OpCodes.Ldloc_3)) .InsertAndAdvance( Transpilers.EmitDelegate <Func <BuildPreview, float> >(preview => DSPAdvancedMiner.getMinerRadius(preview.desc) + 4) ).MatchForward(true, new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(Vector3), nameof(Vector3.Dot))), new CodeMatch(OpCodes.Stloc_S), new CodeMatch(OpCodes.Ldloc_S), new CodeMatch(OpCodes.Ldc_R4)) .SetInstructionAndAdvance(new CodeInstruction(OpCodes.Ldloc_3)) .InsertAndAdvance( Transpilers.EmitDelegate <Func <BuildPreview, float> >(preview => { float radius = DSPAdvancedMiner.getMinerRadius(preview.desc); return(radius * radius); }) ); return(matcher.InstructionEnumeration()); }
static IEnumerable <CodeInstruction> DysonSphereSegmentRenderer_DrawModels_Patch(IEnumerable <CodeInstruction> instructions) { CodeMatcher matcher = new CodeMatcher(instructions) .MatchForward(true, new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(DysonSphereSegmentRenderer), nameof(DysonSphereSegmentRenderer.dysonSphere))), new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(DysonSphere), nameof(DysonSphere.layersIdBased))) ) .MatchForward(false, new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(DysonSphereSegmentRenderer), nameof(DysonSphereSegmentRenderer.dysonSphere))), new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(DysonSphere), nameof(DysonSphere.layersIdBased))) ) .SetOpcodeAndAdvance(OpCodes.Nop) .SetInstructionAndAdvance(new CodeInstruction(OpCodes.Nop)) .SetInstructionAndAdvance(new CodeInstruction(OpCodes.Nop)) .Advance(1) .SetInstructionAndAdvance(new CodeInstruction(OpCodes.Ldarg_0)) .SetInstructionAndAdvance(Transpilers.EmitDelegate <Func <uint, DysonSphereSegmentRenderer, DysonSphereLayer> >((uint index, DysonSphereSegmentRenderer renderer) => { if (hideDysonSphereMesh.Value && DysonSphere.renderPlace == ERenderPlace.Universe) { return(null); } return(renderer.dysonSphere.layersIdBased[(int)((UIntPtr)index)]); })); return(matcher.InstructionEnumeration()); }
public static IEnumerable <CodeInstruction> ClickReform(IEnumerable <CodeInstruction> instructions) { CodeMatcher matcher = new CodeMatcher(instructions) .MatchForward(true, new CodeMatch(x => x.IsLdloc()), new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(BuildTool_Reform), nameof(BuildTool_Click.castGroundPos))) ) .Advance(1) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0)) .InsertAndAdvance(Transpilers.EmitDelegate <Action <BuildTool_Reform> >(tool => { currentGridData.snapGrid = new Vector2(tool.brushSize, tool.brushSize); float longitude = 0; float latitude = 0; BlueprintUtils.GetLongitudeLatitudeRad(tool.castGroundPos.normalized, ref longitude, ref latitude); if (isLockedLongitude) { longitude = lockLongitude; } if (isLockedLatitude) { latitude = lockLatitude; } tool.castGroundPos = BlueprintUtils.GetDir(longitude, latitude) * tool.castGroundPos.magnitude; })); return(matcher.InstructionEnumeration()); }
public void EmitDelegateTest() { var instruction = Transpilers.EmitDelegate <Action>(TranspliersClasses.TestStaticMethod); Assert.AreEqual(OpCodes.Call, instruction.opcode); Assert.IsTrue(instruction.operand is MethodInfo); instruction = Transpilers.EmitDelegate <Action>(() => TranspliersClasses.TestStaticField = 5); Assert.AreEqual(OpCodes.Call, instruction.opcode); Assert.IsTrue(instruction.operand is MethodInfo); CompileInstruction(instruction)(null); Assert.AreEqual(5, TranspliersClasses.TestStaticField); int dummy = 0; instruction = Transpilers.EmitDelegate <Action>(() => dummy = 15); Assert.AreEqual(OpCodes.Call, instruction.opcode); Assert.IsTrue(instruction.operand is MethodInfo); CompileInstruction(instruction)(null); Assert.AreEqual(15, dummy); }
private static IEnumerable <CodeInstruction> Transpile_Player_AddKnownItem(IEnumerable <CodeInstruction> instructions) { // Insert our own callback after: // this.m_knownMaterial.Add(item.m_shared.m_name); return(new CodeMatcher(instructions) .MatchForward(true, // IL_0032: ldfld class [System.Core] System.Collections.Generic.HashSet`1<string> Player::m_knownMaterial // IL_0037: ldarg.1 // IL_0038: ldfld class ItemDrop/ItemData/SharedData ItemDrop/ItemData::m_shared // IL_003D: ldfld string ItemDrop/ItemData/SharedData::m_name // IL_0042: callvirt instance bool class [System.Core] System.Collections.Generic.HashSet`1<string>::Add(!0) // IL_0047: pop new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(Player), nameof(Player.m_knownMaterial))), new CodeMatch(OpCodes.Ldarg_1), new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(ItemDrop.ItemData), nameof(ItemDrop.ItemData.m_shared))), new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(ItemDrop.ItemData.SharedData), nameof(ItemDrop.ItemData.SharedData.m_name))), new CodeMatch(OpCodes.Callvirt, AccessTools.Method(typeof(HashSet <string>), nameof(HashSet <string> .Add))), new CodeMatch(OpCodes.Pop) ) .Insert( new CodeInstruction(OpCodes.Ldarg_1), Transpilers.EmitDelegate <Action <ItemDrop.ItemData> >( item => PlayerKnownManager.OnPlayerAddKnownItem(item.m_shared.m_name) ) ) .InstructionEnumeration()); }
public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { CodeMatcher matcher = new CodeMatcher(instructions) .End().MatchBack(false, new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Call, AccessTools.PropertyGetter(typeof(BuildTool), nameof(BuildTool.buildPreviews))), new CodeMatch(OpCodes.Callvirt)) .Advance(1) .InsertAndAdvance(Transpilers.EmitDelegate <Action <BuildTool_Inserter> >(tool => { if (UndoManager.IgnoreAllEvents.Value) { return; } if (NebulaModAPI.IsMultiplayerActive) { if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsClient) { return; } } IEnumerable <int> objectIds = tool.buildPreviews.Select(preview => preview.objId); PlayerUndo data = UndoManager.GetCurrentPlayerData(); data.AddUndoItem(new UndoBuild(data, objectIds)); })) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0)); return(matcher.InstructionEnumeration()); }
public static IEnumerable <CodeInstruction> IsEnabledInject(IEnumerable <CodeInstruction> instructions) { return(new CodeMatcher(instructions) .MatchForward(false, new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(SpawnSystem.SpawnData), "m_enabled"))) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_3)) .InsertAndAdvance(Transpilers.EmitDelegate(LogIsEnabled)) .InstructionEnumeration()); }
public static IEnumerable <CodeInstruction> HaveBiomeInject(IEnumerable <CodeInstruction> instructions) { return(new CodeMatcher(instructions) .MatchForward(true, new CodeMatch(OpCodes.Callvirt, AccessTools.Method(typeof(Heightmap), "HaveBiome"))) .Advance(1) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_3)) .InsertAndAdvance(Transpilers.EmitDelegate(LogHaveBiome)) .InstructionEnumeration()); }
private static IEnumerable <CodeInstruction> ModifySpawn(IEnumerable <CodeInstruction> instructions) { return(new CodeMatcher(instructions) .MatchForward(false, new CodeMatch(OpCodes.Stloc_3)) .Advance(1) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0)) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_3)) .InsertAndAdvance(Transpilers.EmitDelegate(LocalSpawnSessionManager.ModifySpawn)) .InstructionEnumeration()); }
private static IEnumerable <CodeInstruction> GetRoomObject(IEnumerable <CodeInstruction> instructions) { return(new CodeMatcher(instructions) .MatchForward(true, new CodeMatch(OpCodes.Callvirt, AccessTools.Method(typeof(GameObject), nameof(GameObject.GetComponent), generics: new[] { typeof(Room) }))) .Advance(1) .GetInstruction(out var storeInstruction) .Advance(1) .InsertAndAdvance(storeInstruction.GetLdlocFromStLoc()) .InsertAndAdvance(Transpilers.EmitDelegate(CacheRoom)) .InstructionEnumeration()); }
public static IEnumerable <CodeInstruction> ChangeCastDistance(IEnumerable <CodeInstruction> instructions) { CodeMatcher matcher = new CodeMatcher(instructions) .MatchForward(false, new CodeMatch(OpCodes.Ldc_R4, 800f) ) .SetInstruction(Transpilers.EmitDelegate <Func <float> >(() => GameCamera.instance.blueprintPoser.planetRadius * 2.4f)); return(matcher.InstructionEnumeration()); }
public static IEnumerable <CodeInstruction> CargoPathPatch(IEnumerable <CodeInstruction> instructions) { CodeMatcher matcher = new CodeMatcher(instructions) .MatchForward(false, new CodeMatch(OpCodes.Ldarg_0), new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(CargoPath), nameof(CargoPath.chunks))), new CodeMatch(OpCodes.Ldloc_S) ); matcher.MatchForward(false, new CodeMatch(OpCodes.Stloc_S)); object beginArg = matcher.Operand; matcher.Advance(1).MatchForward(false, new CodeMatch(OpCodes.Stloc_S)); object speedArg = matcher.Operand; matcher.MatchForward(false, new CodeMatch(OpCodes.Ldc_I4_0), new CodeMatch(OpCodes.Stloc_S)); matcher.Advance(2) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0)) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloca_S, beginArg)) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloca_S, speedArg)) .InsertAndAdvance(Transpilers.EmitDelegate <RefAction <CargoPath, int, int> >((CargoPath path, ref int begin, ref int speed) => { // The change if (speed > 10) // If the speed is greater than 10, the length judgment process is performed to prevent crossing the boundary { for (int i = 10; i <= speed; i++) { if (begin + i + 10 >= path.bufferLength) // About to leave the end of the conveyor belt { speed = i; break; } if (path.buffer[begin + i] != 0) // Not empty within the speed range { speed = i; break; } } if (speed < 10) { speed = 10; // If the speed slows down to within a safe speed, set it to a safe speed } } })); return(matcher.InstructionEnumeration()); }
public static IEnumerable <CodeInstruction> ToSpawnInject(IEnumerable <CodeInstruction> instructions) { return(new CodeMatcher(instructions) .MatchForward(true, new CodeMatch(OpCodes.Call, AccessTools.Property(typeof(TimeSpan), nameof(TimeSpan.TotalSeconds)))) .Advance(1) .InsertAndAdvance(new CodeInstruction(OpCodes.Dup)) .MatchForward(true, new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(UnityEngine.Mathf), "Min", new[] { typeof(int), typeof(int) }))) .Advance(1) .InsertAndAdvance(new CodeInstruction(OpCodes.Dup)) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_3)) .InsertAndAdvance(Transpilers.EmitDelegate(ToSpawnLog)) .InstructionEnumeration()); }
static IEnumerable <CodeInstruction> FixMovement(IEnumerable <CodeInstruction> instructions) { CodeMatcher matcher = new CodeMatcher(instructions) .MatchForward(true, new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(PlayerController), nameof(PlayerController.actionBuild))), new CodeMatch(OpCodes.Callvirt, AccessTools.Method(typeof(PlayerAction_Build), "get_blueprintMode")), new CodeMatch(OpCodes.Ldc_I4_0), new CodeMatch(OpCodes.Cgt_Un) ).Advance(1) .InsertAndAdvance(Transpilers.EmitDelegate <Func <bool, bool> >(isBp => isBp && mode)); return(matcher.InstructionEnumeration()); }
public static IEnumerable <CodeInstruction> AddColors(IEnumerable <CodeInstruction> instructions) { CodeMatcher matcher = new CodeMatcher(instructions) .MatchForward(false, new CodeMatch(OpCodes.Ldloc_1), new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(BeltComponent), nameof(BeltComponent.speed))), new CodeMatch(OpCodes.Ldc_I4_1) ); CodeMatcher matcher2 = matcher.Clone(); matcher2.MatchForward(true, new CodeMatch(OpCodes.Ldloc_S), new CodeMatch(OpCodes.Stloc_S)); object arg = matcher2.Operand; matcher2.Advance(1); object label = matcher2.Operand; matcher.Advance(2) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, arg)) .SetInstruction(Transpilers.EmitDelegate <Func <int, int, int> >((speed, other) => { if (speed <= 1) { return(other); } if (speed <= 2) { other += 4; } else if (speed <= 5) { other += 8; } else if (speed <= 12) { other += 12; } return(other); })) .Advance(1) .InsertAndAdvance(new CodeInstruction(OpCodes.Stloc_S, arg)) .SetInstruction(new CodeInstruction(OpCodes.Br, label)); return(matcher.InstructionEnumeration()); }
public static IEnumerable <CodeInstruction> DontClearOpenPath(IEnumerable <CodeInstruction> instructions) { CodeMatcher matcher = new CodeMatcher(instructions) .MatchForward(false, new CodeMatch(OpCodes.Ldstr)) .SetInstruction(Transpilers.EmitDelegate <Func <string> >(() => { string currentPath = UIRoot.instance.uiGame.blueprintBrowser.openPath; return(BlueprintData.GenerateNewFileName(currentPath)); })); return(matcher.InstructionEnumeration()); }
public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { CodeMatcher matcher = new CodeMatcher(instructions) .MatchForward(false, new CodeMatch(OpCodes.Ldc_I4_S, (sbyte)122), new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(Input), nameof(Input.GetKeyDown), new [] { typeof(KeyCode) }))) .RemoveInstruction() .SetInstruction(Transpilers.EmitDelegate <Func <bool> >(() => { return(CustomKeyBindSystem.GetKeyBind("DSPTrashButton").keyValue); })); return(matcher.InstructionEnumeration()); }
static IEnumerable <CodeInstruction> RemoveBrokenConnections(IEnumerable <CodeInstruction> instructions) { CodeMatcher matcher = new CodeMatcher(instructions) .MatchForward(true, new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(BuildPreview), nameof(BuildPreview.bpgpuiModelId))), new CodeMatch(OpCodes.Ldc_I4_0) ).Advance(1); Label label = (Label)matcher.Instruction.operand; matcher.Advance(-2) .InsertAndAdvance(Transpilers.EmitDelegate <Func <BuildPreview, bool> >(bp => { if (!isEnabled && !NebulaModAPI.NebulaIsInstalled) { return(true); } if (bp.desc.multiLevel) { BuildPreview current = bp; while (current.input != null) { if (!current.input.IsGood()) { return(false); } current = current.input; } } if (bp.desc.isInserter) { if (bp.input != null && !bp.input.IsGood()) { return(bp.input.desc.isBelt); } if (bp.output != null && !bp.output.IsGood()) { return(bp.output.desc.isBelt); } } return(true); })) .InsertAndAdvance(new CodeInstruction(OpCodes.Brfalse, label)) .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_3)); return(matcher.InstructionEnumeration()); }
static IEnumerable <CodeInstruction> CodeTranspiler(IEnumerable <CodeInstruction> instructions) { var custominstruc = new CodeMatcher(instructions) .MatchForward(false, new CodeMatch(OpCodes.Ldloc_S), new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(UTY), "FileNameEscape")), new CodeMatch(OpCodes.Stloc_S)) .Insert( new CodeInstruction(OpCodes.Ldloc_S, 5), new CodeInstruction(OpCodes.Ldarg_0), Transpilers.EmitDelegate <Func <String, CharacterMgr, String> >((str, lthis) => { //Debug.Log("Provided Dir is " + lthis.PresetDirectory); SavePrompt.textBox1.Text = str; string result = null; do { SavePrompt.ShowDialog(); if (SavePrompt.Result != null) { if (File.Exists(lthis.PresetDirectory + "//" + SavePrompt.Result + ".preset")) { DialogResult res = MessageBox.Show("We have found that a preset by this name already exists. Pressing OK will overwrite the file.", "A file by this name exists!", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (res == DialogResult.Cancel) { continue; } } result = SavePrompt.Result; } else { result = str; } } while (result == null || result == ""); return(result); }), new CodeInstruction(OpCodes.Stloc_S, 5) ) .InstructionEnumeration(); return(custominstruc); }