private static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { List <CodeInstruction> TargetSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Ldc_R4, (float)0.9), new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(UnityEngine.Time), "get_time")) }; List <CodeInstruction> InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Global), "get_Intensity")), new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(UnityEngine.Time), "get_time")) }; return(HarmonyHelpers.PatchBySequence(instructions, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.REPLACE)); }
private static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { List <CodeInstruction> TargetSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Ldc_R4, -10f), new CodeInstruction(OpCodes.Mul), }; List <CodeInstruction> InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Global), "zoom")), new CodeInstruction(OpCodes.Mul), }; return(HarmonyHelpers.PatchBySequence(instructions, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.REPLACE, HarmonyHelpers.CheckMode.NONNULL)); }
private static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { List <CodeInstruction> TargetSequence = new List <CodeInstruction>() //changes the alarm siren threshold for shields { new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldc_I4_3), new CodeInstruction(OpCodes.Stfld, AccessTools.Field(typeof(PLPawnItem_Scanner), "MaxZoomLevel")), }; List <CodeInstruction> InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldc_I4_5), new CodeInstruction(OpCodes.Stfld, AccessTools.Field(typeof(PLPawnItem_Scanner), "MaxZoomLevel")), }; return(HarmonyHelpers.PatchBySequence(instructions, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.REPLACE)); }
private static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions, ILGenerator generator) { // Label ifmelty = generator.DefineLabel(); List <CodeInstruction> TargetSequence = new List <CodeInstruction>() //changes the alarm siren threshold for shields { new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(PLShipStats), "get_ShieldsMax")), new CodeInstruction(OpCodes.Ldc_R4, .3f), new CodeInstruction(OpCodes.Mul), }; List <CodeInstruction> InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(PLShipStats), "get_ShieldsMax")), new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Global), "shield")), new CodeInstruction(OpCodes.Mul), }; return(HarmonyHelpers.PatchBySequence(instructions, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.REPLACE, HarmonyHelpers.CheckMode.NONNULL)); }
private static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions, ILGenerator generator) { List <CodeInstruction> targetSequence = new List <CodeInstruction>() { //new CodeInstruction(OpCodes.Ldloc_3), new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(PLPlayer), "GetClassName")), new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(System.String), "ToUpper")), }; List <CodeInstruction> injectedSequence = new List <CodeInstruction>() { //new CodeInstruction(OpCodes.Ldloc_S, 3), new CodeInstruction(OpCodes.Ldc_I4_0), new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(PLPlayer), "GetPlayerName")), }; return(HarmonyHelpers.PatchBySequence(instructions, targetSequence, injectedSequence, PatchMode.REPLACE)); }
private static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions, ILGenerator generator) { List <CodeInstruction> targetSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldc_I4_0), new CodeInstruction(OpCodes.Stfld, AccessTools.Field(typeof(PLNetworkManager), "IsTyping")), new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(PLInGameUI), "Instance")), new CodeInstruction(OpCodes.Ldc_I4_1), new CodeInstruction(OpCodes.Stfld, AccessTools.Field(typeof(PLInGameUI), "ForceChatTextAsDirty")), }; Label afterIf = generator.DefineLabel(); List <CodeInstruction> injectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(ChatCommandRouter), "get_Instance")), new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(PLNetworkManager), "CurrentChatText")), new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(ChatCommandRouter), "FindAndExecute", null, null)), new CodeInstruction(OpCodes.Brtrue, afterIf), new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(String), "Empty")), new CodeInstruction(OpCodes.Stfld, AccessTools.Field(typeof(PLNetworkManager), "CurrentChatText")), new CodeInstruction(OpCodes.Nop), }; injectedSequence[injectedSequence.Count - 1].labels.Add(afterIf); instructions = HarmonyHelpers.PatchBySequence(instructions, targetSequence, injectedSequence); int index = -1; List <CodeInstruction> instructionList = instructions.ToList(); for (int i = 0; i < instructionList.Count; i++) { if ("TeamMessage".Equals(instructionList[i].operand)) { index = i; break; } } if (index != -1) { Label afterMessage = generator.DefineLabel(); instructionList[index + 17].labels.Add(afterMessage); instructionList[index - 2].opcode = OpCodes.Ldarg_0; instructionList[index - 2].operand = null; List <CodeInstruction> toInsert = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(PLNetworkManager), "CurrentChatText")), new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(ChatInputPatch), "MessageIsCommand")), new CodeInstruction(OpCodes.Brtrue, afterMessage), new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(PLServer), "Instance")) }; instructionList.InsertRange(index - 1, toInsert); } else { Logger.Info("Warning: \"TeamMessage\" not found. All commands will be displayed in chat."); } return(instructionList); }
private static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { List <CodeInstruction> TargetSequence = new List <CodeInstruction>() //changes the color key on the scanner for all but the { new CodeInstruction(OpCodes.Stloc_0), new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(PLNetworkManager), "Instance")), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(PLNetworkManager), "ViewedPawn")) }; List <CodeInstruction> InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Global), "Walter")), new CodeInstruction(OpCodes.Stloc_0), }; IEnumerable <CodeInstruction> itemkeycolor = HarmonyHelpers.PatchBySequence(instructions, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.AFTER); TargetSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Ldstr, "\n[FFFF00](*) PICKUPS[-]") }; InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Global), "ItemKey")), }; IEnumerable <CodeInstruction> researchkeycolor = HarmonyHelpers.PatchBySequence(itemkeycolor, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.REPLACE); TargetSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Ldstr, "\n[44FFFF](*) RESEARCH MATS[-]") }; InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Global), "ResearchKey")), }; IEnumerable <CodeInstruction> teleporterblip = HarmonyHelpers.PatchBySequence(researchkeycolor, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.REPLACE); TargetSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Ldc_R4, 1f), new CodeInstruction(OpCodes.Ldc_R4, 0f), new CodeInstruction(OpCodes.Ldc_R4, 1f), new CodeInstruction(OpCodes.Newobj) }; InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Global), "teleporterrgb")), }; IEnumerable <CodeInstruction> crewblip = HarmonyHelpers.PatchBySequence(teleporterblip, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.REPLACE, HarmonyHelpers.CheckMode.NONNULL); TargetSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Color), "get_green")), }; InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Global), "crewrgb")), }; IEnumerable <CodeInstruction> hostileblip1 = HarmonyHelpers.PatchBySequence(crewblip, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.REPLACE); TargetSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Color), "get_red")), }; InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Global), "hostilergb")), }; IEnumerable <CodeInstruction> hostileblip2 = HarmonyHelpers.PatchBySequence(hostileblip1, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.REPLACE); TargetSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Color), "get_red")), }; InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Global), "hostilergb")), }; IEnumerable <CodeInstruction> itemblip1 = HarmonyHelpers.PatchBySequence(hostileblip2, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.REPLACE); TargetSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Color), "get_yellow")), }; InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Global), "itemrgb")), }; IEnumerable <CodeInstruction> itemblip2 = HarmonyHelpers.PatchBySequence(itemblip1, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.REPLACE); TargetSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Color), "get_yellow")), }; InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Global), "itemrgb")), }; IEnumerable <CodeInstruction> itemblip3 = HarmonyHelpers.PatchBySequence(itemblip2, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.REPLACE); TargetSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Color), "get_yellow")), }; InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Global), "itemrgb")), }; IEnumerable <CodeInstruction> researchblip = HarmonyHelpers.PatchBySequence(itemblip3, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.REPLACE); TargetSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Ldc_R4, .2f), new CodeInstruction(OpCodes.Ldc_R4, 1f), new CodeInstruction(OpCodes.Ldc_R4, 1f), new CodeInstruction(OpCodes.Newobj) }; InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Global), "researchrgb")), }; IEnumerable <CodeInstruction> doorblip = HarmonyHelpers.PatchBySequence(researchblip, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.REPLACE, HarmonyHelpers.CheckMode.NONNULL); TargetSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Color), "get_blue")), }; InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Global), "doorrgb")), }; IEnumerable <CodeInstruction> npcblip = HarmonyHelpers.PatchBySequence(doorblip, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.REPLACE); TargetSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Color), "get_white")), }; InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Global), "npcrgb")), }; return(HarmonyHelpers.PatchBySequence(npcblip, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.REPLACE, HarmonyHelpers.CheckMode.NONNULL)); }
private static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions) { /*List<CodeInstruction> instructionlist = instructions.ToList(); * instructionlist[3234].opcode = OpCodes.Ldc_R4; * instructionlist[3234].operand = .5f; * return instructionlist.AsEnumerable(); use for simple transpiling!, use below for better and more future-proof transpiling!*/ List <CodeInstruction> TargetSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(PLShipStats), "get_HullMax")), new CodeInstruction(OpCodes.Ldc_R4, .2f), new CodeInstruction(OpCodes.Mul), }; List <CodeInstruction> InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(PLShipStats), "get_HullMax")), new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Global), "hull")), //default value is .4f new CodeInstruction(OpCodes.Mul), }; IEnumerable <CodeInstruction> shieldlights = HarmonyHelpers.PatchBySequence(instructions, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.REPLACE); TargetSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(PLShipStats), "get_ShieldsMax")), new CodeInstruction(OpCodes.Ldc_R4, .3f), new CodeInstruction(OpCodes.Mul), }; InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(PLShipStats), "get_ShieldsMax")), new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Global), "shield")), //default value is .98f new CodeInstruction(OpCodes.Mul), }; IEnumerable <CodeInstruction> meltdownlights = HarmonyHelpers.PatchBySequence(shieldlights, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.REPLACE); TargetSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Ldfld, AccessTools.Method(typeof(PLShipInfoBase), "InWarp")), // use AcessTools.Field(typeof(class), "Method)) to call bools in IL, also this isn't futureproof at all lmao new CodeInstruction(OpCodes.Ldc_I4_0), new CodeInstruction(OpCodes.Ceq), new CodeInstruction(OpCodes.Br_S), new CodeInstruction(OpCodes.Ldc_I4_0), new CodeInstruction(OpCodes.Or), new CodeInstruction(OpCodes.Stloc_S) }; PulsarPluginLoader.Utilities.Logger.Info("temp critical patch done"); InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Ldloc_S, 79), //use the number after the V_ for flags (like flag9) new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(PLShipInfoBase), "IsReactorTempCritical")), new CodeInstruction(OpCodes.Or), new CodeInstruction(OpCodes.Stloc_S, 79) }; IEnumerable <CodeInstruction> sectorlights = HarmonyHelpers.PatchBySequence(meltdownlights, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.AFTER, HarmonyHelpers.CheckMode.NONNULL); //adds sectors that trigger alarm lights TargetSequence = new List <CodeInstruction>() { /* new CodeInstruction(OpCodes.Ldarg_0), * new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(PLShipInfoBase), "InWarp")), * new CodeInstruction(OpCodes.Ldc_I4_0), * new CodeInstruction(OpCodes.Ceq), * new CodeInstruction(OpCodes.Br_S), * new CodeInstruction(OpCodes.Ldc_I4_0), * new CodeInstruction(OpCodes.Or), * new CodeInstruction(OpCodes.Stloc_S) */ new CodeInstruction(OpCodes.Ldloc_S, 79), //use the number after the V_ for flags (like flag9) new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(PLShipInfoBase), "IsReactorTempCritical")), new CodeInstruction(OpCodes.Or), new CodeInstruction(OpCodes.Stloc_S, 79) }; InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Ldloc_S, 79), //start blackhole new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(PLServer), "GetCurrentSector")), new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(PLSectorInfo), "get_VisualIndication")), new CodeInstruction(OpCodes.Ldc_I4_S, 0x1F), new CodeInstruction(OpCodes.Ceq), new CodeInstruction(OpCodes.Or), new CodeInstruction(OpCodes.Stloc_S, 79), //end blackhole new CodeInstruction(OpCodes.Ldloc_S, 79), //start CU asteroid encounter new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(PLServer), "GetCurrentSector")), new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(PLSectorInfo), "get_VisualIndication")), new CodeInstruction(OpCodes.Ldc_I4_S, 0x70), new CodeInstruction(OpCodes.Ceq), new CodeInstruction(OpCodes.Or), new CodeInstruction(OpCodes.Stloc_S, 79), //end CU asteroid encounter new CodeInstruction(OpCodes.Ldloc_S, 79), // start warp guardian new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(PLServer), "GetCurrentSector")), new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(PLSectorInfo), "get_VisualIndication")), new CodeInstruction(OpCodes.Ldc_I4, 0x86), new CodeInstruction(OpCodes.Ceq), new CodeInstruction(OpCodes.Or), new CodeInstruction(OpCodes.Stloc_S, 79), // end warp guardian /* new CodeInstruction(OpCodes.Ldloc_S, 79), // start unseen threat * new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(PLServer),"GetCurrentSector")), * new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(PLSectorInfo),"get_VisualIndication")), * new CodeInstruction(OpCodes.Ldc_I4, 0x8C), * new CodeInstruction(OpCodes.Ceq), * new CodeInstruction(OpCodes.Or), * new CodeInstruction(OpCodes.Stloc_S, 79), // end unseen threat */ new CodeInstruction(OpCodes.Ldloc_S, 79), //start fire yes new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(PLShipInfo), "CountNonNullFires")), new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Global), "firecount")), //default value is 17 new CodeInstruction(OpCodes.Cgt), new CodeInstruction(OpCodes.Or), new CodeInstruction(OpCodes.Stloc_S, 79), //end fire yes new CodeInstruction(OpCodes.Ldloc_S, 79), //start o2 new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(PLShipInfoBase), "MyStats")), new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(typeof(PLShipStats), "get_OxygenLevel")), new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Global), "o2")), //o2 is .18f by default new CodeInstruction(OpCodes.Clt), new CodeInstruction(OpCodes.Or), new CodeInstruction(OpCodes.Stloc_S, 79), //end o2 }; PulsarPluginLoader.Utilities.Logger.Info("sector patch done"); IEnumerable <CodeInstruction> alertflashes = HarmonyHelpers.PatchBySequence(sectorlights, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.AFTER, HarmonyHelpers.CheckMode.NONNULL); TargetSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(PLShipInfo), "timesPlayedFlash")), new CodeInstruction(OpCodes.Ldc_I4_S), }; InjectedSequence = new List <CodeInstruction>() { new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(PLShipInfo), "timesPlayedFlash")), new CodeInstruction(OpCodes.Ldsfld, AccessTools.Field(typeof(Global), "flashcount")), }; return(HarmonyHelpers.PatchBySequence(alertflashes, TargetSequence, InjectedSequence, HarmonyHelpers.PatchMode.REPLACE, HarmonyHelpers.CheckMode.NONNULL)); }