private static IEnumerable <CodeInstruction> CreateInitialMap_Transpiler_QuestCount(IEnumerable <CodeInstruction> instructionsEnumerable, ILGenerator generator) { List <CodeInstruction> instructions = instructionsEnumerable.ToList(); FieldInfo loadLevel_squareMap = AccessTools.Field(typeof(LoadLevel), nameof(LoadLevel.squareMap)); MethodInfo levelGenTools_SetQuestTriesTotal = AccessTools.Method(typeof(C_LevelGen), nameof(C_LevelGen.SetQuestTriesTotal)); CodeReplacementPatch patch = new CodeReplacementPatch( expectedMatches: 1, prefixInstructionSequence: new List <CodeInstruction> { // Line 391 new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, loadLevel_squareMap), new CodeInstruction(OpCodes.Brfalse), new CodeInstruction(OpCodes.Ldarg_0), }, insertInstructionSequence: new List <CodeInstruction> { // LevelGenTools.SetQuestTriesTotal(); new CodeInstruction(OpCodes.Call, levelGenTools_SetQuestTriesTotal), // Clear }); patch.ApplySafe(instructions, logger); return(instructions); }
private static IEnumerable <CodeInstruction> GetTraitsRemoveTrait_Transpiler(IEnumerable <CodeInstruction> instructionsEnumerable) { // Removed gate that prevents traits with less than -5 value being removed. FieldInfo unlock_cost3 = AccessTools.Field(typeof(Unlock), nameof(Unlock.cost3)); FieldInfo scrollingMenu_gc = AccessTools.Field(typeof(ScrollingMenu), nameof(ScrollingMenu.gc)); FieldInfo gameController_challenges = AccessTools.Field(typeof(GameController), nameof(GameController.challenges)); // TODO change to marker-method // since we want to remove the `(unlock.cost3 > -5 || this.gc.challenges.Contains("NoLimits"))` condition, we'll look for exactly that CodeReplacementPatch patch = new CodeReplacementPatch( expectedMatches: 1, targetInstructionSequence: new List <CodeInstruction> { new CodeInstruction(OpCodes.Ldloc_3), // get the `Unlock` local variable new CodeInstruction(OpCodes.Ldfld, unlock_cost3), // access the cost3 field on that variable new CodeInstruction(OpCodes.Ldc_I4_S, -5), // prepare int value -5 new CodeInstruction(OpCodes.Bgt_S), // if cost3 > -5 move on. new CodeInstruction(OpCodes.Ldarg_0), // get `this` new CodeInstruction(OpCodes.Ldfld, scrollingMenu_gc), // get this.gc new CodeInstruction(OpCodes.Ldfld, gameController_challenges), // get this.gc.challenges new CodeInstruction(OpCodes.Ldstr, "NoLimits"), // prepare string "NoLimits" new CodeInstruction(OpCodes.Callvirt), // call this.gc.challenges.Contains("NoLimits") new CodeInstruction(OpCodes.Brfalse_S) // go somewhere else if it does not contain "NoLimits" }); List <CodeInstruction> instructions = instructionsEnumerable.ToList(); patch.ApplySafe(instructions, logger); return(instructions); }
private static IEnumerable <CodeInstruction> BecomeHidden_Transpiler(IEnumerable <CodeInstruction> instructionsEnumerable, ILGenerator generator) { List <CodeInstruction> instructions = instructionsEnumerable.ToList(); FieldInfo statusEffetcs_gc = AccessTools.Field(typeof(StatusEffects), "gc"); FieldInfo gameController_audiHandler = AccessTools.Field(typeof(GameController), nameof(GameController.audioHandler)); FieldInfo statusEffects_agent = AccessTools.Field(typeof(StatusEffects), nameof(StatusEffects.agent)); MethodInfo audioHandler_Play = AccessTools.Method(typeof(AudioHandler), nameof(AudioHandler.Play), new[] { typeof(PlayfieldObject), typeof(string) }); MethodInfo patches_GetClipName = AccessTools.Method(typeof(P_StatusEffects), nameof(BecomeHidden_GetClipName), new[] { typeof(PlayfieldObject) }); /* * Replace: * this.gc.audioHandler.Play(this.agent, "Hide"); * With: * this.gc.audioHandler.Play(this.agent, StatusEffectsPatches.BecomeHidden_GetClipName(hiddenInObject)) */ CodeReplacementPatch agentPositionPatch = new CodeReplacementPatch( expectedMatches: 1, prefixInstructionSequence: new List <CodeInstruction> { new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, statusEffetcs_gc), new CodeInstruction(OpCodes.Ldfld, gameController_audiHandler), // this.gc.audioHandler new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, statusEffects_agent) // this.agent }, targetInstructionSequence: new List <CodeInstruction> { new CodeInstruction(OpCodes.Ldstr, "Hide") // string: "Hide" }, insertInstructionSequence: new List <CodeInstruction> { new CodeInstruction(OpCodes.Ldarg_1), new CodeInstruction(OpCodes.Call, patches_GetClipName) // StatusEffectsPatches.BecomeHidden_GetClipName(hiddenInObject) }, postfixInstructionSequence: new List <CodeInstruction> { new CodeInstruction(OpCodes.Callvirt, audioHandler_Play) // this.gc.audioHandler.Play(this.agent, "Hide") } ); agentPositionPatch.ApplySafe(instructions, logger); return(instructions); }