예제 #1
0
        public static void Patch(ModuleDefinition module, List <string> log)
        {
            var player    = IL.GetTypeDefinition(module, "Player");
            var itemCheck = IL.GetMethodDefinition(player, "ItemCheck");
            var checkMana = IL.GetMethodDefinition(player, "CheckMana");

            int spot = IL.ScanForOpcodePattern(itemCheck, (i, instruction) =>
            {
                var in1 = itemCheck.Body.Instructions[i - 1].OpCode;
                return(in1.Name.ToLower().Contains("ldloc") && itemCheck.Body.Instructions[i + 1].Operand as sbyte? == 127);
            },
                                               OpCodes.Ldfld,
                                               OpCodes.Ldc_I4_S,
                                               OpCodes.Bne_Un_S);

            for (int i = -1; i < 5; i++)
            {
                itemCheck.Body.Instructions[spot + i].OpCode = OpCodes.Nop;
            }
            itemCheck.Body.Instructions[spot + 5].OpCode = OpCodes.Br;

            checkMana.Body.ExceptionHandlers.Clear();
            checkMana.Body.Instructions.Clear();
            checkMana.Body.Instructions.Add(Instruction.Create(OpCodes.Ldc_I4_1));
            checkMana.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
        }
예제 #2
0
        public static void PathOnUpdateControlInput(ModuleDefinition module, List <string> log)
        {
            var fn = IL.GetMethodDefinition(module, "Game1", "UpdateControlInput");

            if (fn == null)
            {
                log.Add("Can't find target method!");
                return;
            }

            int spot = IL.ScanForOpcodePattern(fn,
                                               (i, instruction) =>
            {
                var reference = fn.Body.Instructions[i + 2].Operand as MethodReference;
                return(reference != null && reference.Name == "checkForRunButton");
            },
                                               OpCodes.Ldloc_0,
                                               OpCodes.Ldc_I4_0,
                                               OpCodes.Call
                                               );

            if (spot == -1)
            {
                log.Add("Can't find patch location!");
                return;
            }

            spot += 3;
            var callType   = module.ImportReference(typeof(dotNetMT.EventRouter)).Resolve();
            var callMethod = module.ImportReference(IL.GetMethodDefinition(callType, "OnUpdateControlInput"));

            IL.MethodAppend(fn, spot, 0, new[] {
                Instruction.Create(OpCodes.Call, callMethod),
            });
        }
예제 #3
0
        public static void Patch(ModuleDefinition module, List <string> log)
        {
            var npc       = IL.GetTypeDefinition(module, "NPC");
            var strikeNPC = IL.GetMethodDefinition(npc, "StrikeNPC");

            int spot = IL.ScanForOpcodePattern(strikeNPC,
                                               OpCodes.Ldarg_1,
                                               OpCodes.Conv_R8,
                                               OpCodes.Stloc_1);

            var life = IL.GetFieldDefinition(npc, "life");

            strikeNPC.Body.Instructions[spot].OpCode = OpCodes.Ldarg_0;
            strikeNPC.Body.Instructions.Insert(spot + 1, Instruction.Create(OpCodes.Ldfld, life));

            int spot2 = IL.ScanForOpcodePattern(strikeNPC,
                                                (i, instruction) =>
            {
                var i0 = strikeNPC.Body.Instructions[i].Operand as ParameterReference;
                return(i0 != null && i0.Name == "crit");
            },
                                                spot,
                                                OpCodes.Ldarg_S,
                                                OpCodes.Brfalse_S);

            for (int i = spot + 4; i < spot2; i++)
            {
                strikeNPC.Body.Instructions[i].OpCode = OpCodes.Nop;
            }
        }
예제 #4
0
        public static void PatchEnableChat(ModuleDefinition module, List <string> log)
        {   // patch chat to allow on singleplayer // Main.clrInput();
            var main   = IL.GetTypeDefinition(module, "Main");
            var update = IL.GetMethodDefinition(main, "DoUpdate");

            int spot = IL.ScanForOpcodePattern(update, (i, instruction) =>
            {
                var f0       = instruction.Operand as FieldReference;
                var result0  = f0 != null && f0.Name == "netMode";
                var f33      = update.Body.Instructions[i + 3].Operand as FieldReference;
                var result33 = f33 != null && f33.Name == "keyState";
                return(result0 && result33);
            },
                                               OpCodes.Ldsfld,
                                               OpCodes.Ldc_I4_1,
                                               OpCodes.Bne_Un
                                               );

            if (spot == -1)
            {
                log.Add("[ERROR] Can't apply path, pattern not found!");
                return;
            }

            update.Body.Instructions[spot + 0].OpCode = OpCodes.Nop;
            update.Body.Instructions[spot + 1].OpCode = OpCodes.Nop;
            update.Body.Instructions[spot + 2].OpCode = OpCodes.Nop;
        }
예제 #5
0
        public static void Patch(ModuleDefinition module, List <string> log)
        {
            var fn   = IL.GetMethodDefinition(IL.GetTypeDefinition(module, "GameLocation"), "checkAction");
            int spot = IL.ScanForOpcodePattern(fn,
                                               (i, instruction) =>
            {
                var reference = fn.Body.Instructions[i + 3].Operand as FieldReference;
                return(reference != null && reference.Name == "haltAfterCheck");
            },
                                               OpCodes.Ldarg_3,
                                               OpCodes.Callvirt,
                                               OpCodes.Ldc_I4_0,
                                               OpCodes.Stsfld
                                               );

            if (spot == -1)
            {
                log.Add("Can't find patch location!");
                return;
            }

            spot += 4;
            var callType   = module.ImportReference(typeof(dotNetMT.EasyPlant)).Resolve();
            var callMethod = module.ImportReference(IL.GetMethodDefinition(callType, "ProcessPlant"));

            IL.MethodAppend(fn, spot, 0, new[]
            {
                Instruction.Create(OpCodes.Ldarg_0),
                Instruction.Create(OpCodes.Ldarg_S, fn.Parameters.FirstOrDefault(def => def.Name == "tileLocation")),
                Instruction.Create(OpCodes.Ldarg_S, fn.Parameters.FirstOrDefault(def => def.Name == "who")),
                Instruction.Create(OpCodes.Call, callMethod),
            });
        }
        public static void Patch(ModuleDefinition module, List <string> log)
        {
            double chance = DNMT.Config.Get <double>("Tweak-SoilDecay", "chance", 0.001d, true);

            var fn   = IL.GetMethodDefinition(IL.GetTypeDefinition(module, "Farm"), "DayUpdate");
            int spot = IL.ScanForOpcodePattern(fn,
                                               (i, instruction) =>
            {
                var fieldReference = fn.Body.Instructions[i].Operand as FieldReference;
                return(fieldReference != null && fieldReference.Name == "random");
            },
                                               OpCodes.Ldsfld,
                                               OpCodes.Callvirt,
                                               OpCodes.Ldc_R8,
                                               OpCodes.Bgt_Un_S
                                               );

            if (spot == -1)
            {
                log.Add("Can't find patch location!");
                return;
            }

            //log.Add("spot: " + spot.ToString());
            fn.Body.Instructions[spot + 2].Operand = chance;
        }
예제 #7
0
        public static void PatchBuffUpdate(ModuleDefinition module, List <string> log)
        {
            var target = IL.GetMethodDefinition(module, "Buff", "update");

            if (target == null)
            {
                log.Add("Can't find target method!");
                return;
            }

            int spot = IL.ScanForOpcodePattern(target, (i, instruction) =>
            {
                var reference = target.Body.Instructions[i + 0].Operand as FieldReference;
                return(reference != null && reference.Name == "millisecondsDuration");
            },
                                               OpCodes.Ldfld,
                                               OpCodes.Ldc_I4_0,
                                               OpCodes.Bgt_S,
                                               OpCodes.Ldc_I4_1,
                                               OpCodes.Ret
                                               );

            if (spot == -1)
            {
                log.Add("Can't find patch location!");
                return;
            }

            var type   = module.ImportReference(MethodBase.GetCurrentMethod().DeclaringType).Resolve(); // typeof(dotNetMT.EasyPlant)
            var method = module.ImportReference(IL.GetMethodDefinition(type, "PlayNotifySound"));

            IL.MethodAppend(target, spot + 3, 0, new[] { Instruction.Create(OpCodes.Call, method) });
        }
예제 #8
0
        public static void PatchFishingRodDoneFishing(ModuleDefinition module, List <string> log)
        {
            var target = IL.GetMethodDefinition(module, "FishingRod", "doneFishing");

            if (target == null)
            {
                log.Add("Can't find target method!");
                return;
            }

            var type   = module.ImportReference(MethodBase.GetCurrentMethod().DeclaringType).Resolve(); // typeof(dotNetMT.EasyPlant)
            var method = module.ImportReference(IL.GetMethodDefinition(type, "PlayNotifySound"));


            int spot;

            spot = IL.ScanForOpcodePattern(target, (i, instruction) =>
            {
                var reference = target.Body.Instructions[i + 1].Operand as FieldReference;
                return(reference != null && reference.Name == "attachments");
            },
                                           OpCodes.Ldarg_0,
                                           OpCodes.Ldfld,
                                           OpCodes.Ldc_I4_0,
                                           OpCodes.Ldnull
                                           );
            if (spot == -1)
            {
                log.Add("Can't find patch location!");
                return;
            }

            IL.MethodAppend(target, spot + 0, 0, new[] { Instruction.Create(OpCodes.Call, method) });

            spot = IL.ScanForOpcodePattern(target, (i, instruction) =>
            {
                var reference = target.Body.Instructions[i + 1].Operand as FieldReference;
                return(reference != null && reference.Name == "attachments");
            },
                                           OpCodes.Ldarg_0,
                                           OpCodes.Ldfld,
                                           OpCodes.Ldc_I4_1,
                                           OpCodes.Ldnull
                                           );
            if (spot == -1)
            {
                log.Add("Can't find patch location!");
                return;
            }

            IL.MethodAppend(target, spot + 0, 0, new[] { Instruction.Create(OpCodes.Call, method) });
        }
예제 #9
0
        public static void Patch(ModuleDefinition module, List <string> log)
        {
            var player   = IL.GetTypeDefinition(module, "Player");
            var adjTiles = IL.GetMethodDefinition(player, "AdjTiles");

            int spot = IL.ScanForOpcodePattern(adjTiles, OpCodes.Ldc_I4_4,
                                               OpCodes.Stloc_0,
                                               OpCodes.Ldc_I4_3,
                                               OpCodes.Stloc_1
                                               );

            adjTiles.Body.Instructions[spot].OpCode      = OpCodes.Ldc_I4;
            adjTiles.Body.Instructions[spot].Operand     = 30;
            adjTiles.Body.Instructions[spot + 2].OpCode  = OpCodes.Ldc_I4;
            adjTiles.Body.Instructions[spot + 2].Operand = 30;
        }
예제 #10
0
        public static void Patch(ModuleDefinition module, List <string> log)
        {
            var main         = IL.GetTypeDefinition(module, "Main");
            var drawInfoAccs = IL.GetMethodDefinition(main, "DrawInfoAccs");

            int spot = IL.ScanForOpcodePattern(drawInfoAccs, (i, instruction) =>
            {
                var fieldReference = instruction.Operand as FieldReference;
                return(fieldReference != null && fieldReference.Name == "accWatch");
            },
                                               OpCodes.Ldfld,
                                               OpCodes.Ldc_I4_0,
                                               OpCodes.Ble
                                               );

            drawInfoAccs.Body.Instructions[spot + 2].OpCode = OpCodes.Blt;
        }
예제 #11
0
        public static void Patch(ModuleDefinition module, List <string> log)
        {
            var player   = IL.GetTypeDefinition(module, "Player");
            var pickAmmo = IL.GetMethodDefinition(player, "PickAmmo");

            int spot = IL.ScanForOpcodePattern(pickAmmo,
                                               (i, instruction) =>
            {
                var i1 = instruction.Operand as FieldReference;
                return(i1 != null && i1.Name == "stack");
            },
                                               OpCodes.Ldfld,
                                               OpCodes.Ldc_I4_1,
                                               OpCodes.Sub,
                                               OpCodes.Stfld);

            pickAmmo.Body.Instructions[spot + 1].OpCode = OpCodes.Ldc_I4_0;
        }
        public static void Patch(ModuleDefinition module, List <string> log)
        {
            var target = IL.GetMethodDefinition(module, "GeodeMenu", "receiveLeftClick");

            if (target == null)
            {
                log.Add("Can't find target method!");
                return;
            }

            // ---

            int spot = IL.ScanForOpcodePattern(target, (i, instruction) =>
            {
                var reference = target.Body.Instructions[i + 3].Operand as FieldReference;
                return(reference != null && reference.Name == "clint");
            },
                                               OpCodes.Callvirt,
                                               OpCodes.Callvirt,
                                               OpCodes.Ldarg_0,
                                               OpCodes.Ldfld
                                               );

            if (spot == -1)
            {
                log.Add("Can't find patch location!");
                return;
            }

            // ---

            var type   = module.ImportReference(MethodBase.GetCurrentMethod().DeclaringType).Resolve(); // typeof(dotNetMT.EasyPlant)
            var method = module.ImportReference(IL.GetMethodDefinition(type, "Adjust"));

            IL.MethodAppend(target, spot + 1, 0, new[] {
                Instruction.Create(OpCodes.Ldarg_0),
                Instruction.Create(OpCodes.Call, method),
            });
        }
예제 #13
0
        public static void Patch(ModuleDefinition module, List <string> log)
        {
            var main             = IL.GetTypeDefinition(module, "Main");
            var guiChatDrawInner = IL.GetMethodDefinition(main, "GUIChatDrawInner");
            var questSwap        = IL.GetMethodDefinition(main, "AnglerQuestSwap");

            int spot = IL.ScanForOpcodePattern(guiChatDrawInner,
                                               (i, instruction) =>
            {
                var i3 = guiChatDrawInner.Body.Instructions[i + 3].Operand as FieldReference;
                return(i3 != null && i3.Name == "anglerQuestFinished");
            },
                                               OpCodes.Ldloc_S,
                                               OpCodes.Brfalse,
                                               OpCodes.Ldc_I4_1);

            guiChatDrawInner.Body.Instructions[spot + 2] = Instruction.Create(OpCodes.Call, questSwap);
            for (int i = spot + 3; guiChatDrawInner.Body.Instructions[i].OpCode != OpCodes.Ret; i++)
            {
                guiChatDrawInner.Body.Instructions[i].OpCode = OpCodes.Nop;
            }
        }
예제 #14
0
        public static void Patch(ModuleDefinition module, List <string> log)
        {
            var player     = IL.GetTypeDefinition(module, "Player");
            var update     = IL.GetMethodDefinition(player, "Update");
            var jumpAgain1 = IL.GetFieldDefinition(player, "jumpAgainBlizzard");
            var jumpAgain2 = IL.GetFieldDefinition(player, "jumpAgainCloud");
            var jumpAgain3 = IL.GetFieldDefinition(player, "jumpAgainFart");
            var jumpAgain4 = IL.GetFieldDefinition(player, "jumpAgainSail");
            var jumpAgain5 = IL.GetFieldDefinition(player, "jumpAgainSandstorm");
            var jumpAgain6 = IL.GetFieldDefinition(player, "jumpAgainUnicorn");

            int spot = IL.ScanForOpcodePattern(update,
                                               (i, instruction) =>
            {
                var i0 = update.Body.Instructions[i + 1].Operand as FieldReference;
                return(i0 != null && i0.Name == "doubleJumpCloud");
            },
                                               OpCodes.Ldc_I4_0,
                                               OpCodes.Stfld);

            update.Body.Instructions.Insert(spot + 2, Instruction.Create(OpCodes.Ldarg_0));
            update.Body.Instructions.Insert(spot + 3, Instruction.Create(OpCodes.Ldc_I4_1));
            update.Body.Instructions.Insert(spot + 4, Instruction.Create(OpCodes.Stfld, jumpAgain1));
            update.Body.Instructions.Insert(spot + 2, Instruction.Create(OpCodes.Ldarg_0));
            update.Body.Instructions.Insert(spot + 3, Instruction.Create(OpCodes.Ldc_I4_1));
            update.Body.Instructions.Insert(spot + 4, Instruction.Create(OpCodes.Stfld, jumpAgain2));
            update.Body.Instructions.Insert(spot + 2, Instruction.Create(OpCodes.Ldarg_0));
            update.Body.Instructions.Insert(spot + 3, Instruction.Create(OpCodes.Ldc_I4_1));
            update.Body.Instructions.Insert(spot + 4, Instruction.Create(OpCodes.Stfld, jumpAgain3));
            update.Body.Instructions.Insert(spot + 2, Instruction.Create(OpCodes.Ldarg_0));
            update.Body.Instructions.Insert(spot + 3, Instruction.Create(OpCodes.Ldc_I4_1));
            update.Body.Instructions.Insert(spot + 4, Instruction.Create(OpCodes.Stfld, jumpAgain4));
            update.Body.Instructions.Insert(spot + 2, Instruction.Create(OpCodes.Ldarg_0));
            update.Body.Instructions.Insert(spot + 3, Instruction.Create(OpCodes.Ldc_I4_1));
            update.Body.Instructions.Insert(spot + 4, Instruction.Create(OpCodes.Stfld, jumpAgain5));
            update.Body.Instructions.Insert(spot + 2, Instruction.Create(OpCodes.Ldarg_0));
            update.Body.Instructions.Insert(spot + 3, Instruction.Create(OpCodes.Ldc_I4_1));
            update.Body.Instructions.Insert(spot + 4, Instruction.Create(OpCodes.Stfld, jumpAgain6));
        }
예제 #15
0
        public static void Patch(ModuleDefinition module, List <string> log)
        {
            var player    = IL.GetTypeDefinition(module, "Player");
            var itemCheck = IL.GetMethodDefinition(player, "ItemCheck");

            int spot = IL.ScanForOpcodePattern(itemCheck, (i, instruction) =>
            {
                var fieldReference = instruction.Operand as FieldReference;
                return(fieldReference != null && fieldReference.Name == "chaosState");
            },
                                               OpCodes.Ldfld,
                                               OpCodes.Brfalse);

            var  target = itemCheck.Body.Instructions[spot + 1].Operand as Instruction;
            bool done   = false;

            for (; !done; target = target.Next)
            {
                if (target.OpCode == OpCodes.Call)
                {
                    done = true;
                }

                target.OpCode  = OpCodes.Nop;
                target.Operand = null;
            }

            int spot2 = IL.ScanForOpcodePattern(itemCheck, (i, instruction) =>
            {
                var methodReference = instruction.Operand as MethodReference;
                return(methodReference != null && methodReference.Name == "SolidCollision");
            },
                                                OpCodes.Call,
                                                OpCodes.Brtrue);

            itemCheck.Body.Instructions[spot2 + 1].OpCode = OpCodes.Pop;
        }
        public static void Patch(ModuleDefinition module, List <string> log)
        {
            float multiplier = DNMT.Config.Get <float>("Tweak-MovementSpeed", "multiplier", 0.099f, true);

            var fn   = IL.GetMethodDefinition(IL.GetTypeDefinition(module, "Farmer"), "getMovementSpeed");
            int spot = IL.ScanForOpcodePattern(fn,
                                               (i, instruction) =>
            {
                var fieldReference = fn.Body.Instructions[i + 2].Operand as FieldReference;
                return(fieldReference != null && fieldReference.Name == "movementMultiplier");
            },
                                               OpCodes.Ldarg_0,
                                               OpCodes.Ldc_R4,
                                               OpCodes.Stfld
                                               );

            if (spot == -1)
            {
                log.Add("Can't find patch location!");
                return;
            }

            fn.Body.Instructions[spot + 1].Operand = multiplier;
        }
예제 #17
0
        public static void Patch(ModuleDefinition module, List <string> log)
        {
            float multiplier = DNMT.Config.Get <float>("Tweak-DayLength", "multiplier", 2f, true);

            var fn   = IL.GetMethodDefinition(IL.GetTypeDefinition(module, "Game1"), "UpdateGameClock");
            int spot = IL.ScanForOpcodePattern(fn,
                                               (i, instruction) =>
            {
                var fieldReference = fn.Body.Instructions[i].Operand as FieldReference;
                return(fieldReference != null && fieldReference.Name == "gameTimeInterval");
            },
                                               OpCodes.Ldsfld,
                                               OpCodes.Ldc_I4,
                                               OpCodes.Ldsfld
                                               );

            if (spot == -1)
            {
                log.Add("Can't find patch location!");
                return;
            }

            fn.Body.Instructions[spot + 1].Operand = (int)(7000 * multiplier);
        }
예제 #18
0
        public static void Patch(ModuleDefinition module, List <string> log)
        {
            var fn   = IL.GetMethodDefinition(IL.GetTypeDefinition(module, "Crop"), ".ctor", 3);
            int spot = IL.ScanForOpcodePattern(fn,
                                               (i, instruction) =>
            {
                var fieldReference = fn.Body.Instructions[i + 2].Operand as FieldReference;
                return(fieldReference != null && fieldReference.Name == "harvestMethod");
            },
                                               OpCodes.Ldelem_Ref,
                                               OpCodes.Call,
                                               OpCodes.Stfld
                                               );

            if (spot == -1)
            {
                log.Add("Can't find patch location!");
                return;
            }

            //spot -= 2;
            //fn.Body.Instructions[spot + 0].OpCode = OpCodes.Nop;
            //fn.Body.Instructions[spot + 1].OpCode = OpCodes.Ldc_I4_1;
            //fn.Body.Instructions[spot + 2].OpCode = OpCodes.Nop;
            //fn.Body.Instructions[spot + 3].OpCode = OpCodes.Nop;

            spot += 2;
            var callType   = module.ImportReference(typeof(dotNetMT.ScytheHarvest)).Resolve();
            var callMethod = module.ImportReference(IL.GetMethodDefinition(callType, "AdjustHarvestMethod"));

            IL.MethodAppend(fn, spot, 0, new[]
            {
                Instruction.Create(OpCodes.Ldarg_1),
                Instruction.Create(OpCodes.Call, callMethod),
            });

            // ---

            fn   = IL.GetMethodDefinition(IL.GetTypeDefinition(module, "Crop"), "harvest");
            spot = IL.ScanForOpcodePattern(fn,
                                           (i, instruction) =>
            {
                var fieldReference = fn.Body.Instructions[i + 1].Operand as FieldReference;
                return(fieldReference != null && fieldReference.Name == "harvestMethod");
            },
                                           OpCodes.Ldarg_0,
                                           OpCodes.Ldfld,
                                           OpCodes.Ldc_I4_1,
                                           OpCodes.Bne_Un
                                           );
            if (spot == -1)
            {
                log.Add("Can't find patch location!");
                return;
            }

            spot      += 4;
            callMethod = module.ImportReference(IL.GetMethodDefinition(callType, "ProcessScytheHarvest"));
            IL.MethodAppend(fn, spot, 0, new[]
            {
                Instruction.Create(OpCodes.Ldarg_0),
                Instruction.Create(OpCodes.Ldarg_S, fn.Parameters.FirstOrDefault(def => def.Name == "xTile")),
                Instruction.Create(OpCodes.Ldarg_S, fn.Parameters.FirstOrDefault(def => def.Name == "yTile")),
                //Instruction.Create(OpCodes.Ldloc_S, fn.Body.Variables[4]),
                Instruction.Create(OpCodes.Ldarg_S, fn.Parameters.FirstOrDefault(def => def.Name == "soil")),
                Instruction.Create(OpCodes.Ldarg_S, fn.Parameters.FirstOrDefault(def => def.Name == "junimoHarvester")),
                Instruction.Create(OpCodes.Call, callMethod),
                //Instruction.Create(OpCodes.Stloc_S, fn.Body.Variables[4]),
            });

            // ---
        }
예제 #19
0
        public static void Patch(ModuleDefinition module, List <string> log)
        {
            float minZoom = DNMT.Config.Get <float>("Tweak-ZoomOut", "minZoom", 0.5f, true);

            var type = IL.GetTypeDefinition(module, "DayTimeMoneyBox");

            var fn   = IL.GetMethodDefinition(type, "draw");
            int spot = IL.ScanForOpcodePattern(fn,
                                               (i, instruction) =>
            {
                var fieldReference = fn.Body.Instructions[i].Operand as FieldReference;
                return(fieldReference != null && fieldReference.Name == "zoomLevel");
            },
                                               OpCodes.Ldfld,
                                               OpCodes.Ldc_R4,
                                               OpCodes.Ble_S
                                               );

            if (spot == -1)
            {
                log.Add("Can't find patch location!");
                return;
            }

            fn.Body.Instructions[spot + 1].Operand = minZoom;

            fn   = IL.GetMethodDefinition(type, "receiveLeftClick");
            spot = IL.ScanForOpcodePattern(fn,
                                           (i, instruction) =>
            {
                var fieldReference = fn.Body.Instructions[i].Operand as FieldReference;
                return(fieldReference != null && fieldReference.Name == "zoomLevel");
            },
                                           OpCodes.Ldfld,
                                           OpCodes.Ldc_R4,
                                           OpCodes.Ble_Un_S
                                           );

            if (spot == -1)
            {
                log.Add("Can't find patch location!");
                return;
            }

            fn.Body.Instructions[spot + 1].Operand = minZoom;

            spot = IL.ScanForOpcodePattern(fn,
                                           (i, instruction) =>
            {
                var fieldReference = fn.Body.Instructions[i].Operand as FieldReference;
                return(fieldReference != null && fieldReference.Name == "options");
            },
                                           OpCodes.Ldsfld,
                                           OpCodes.Ldc_R4,
                                           OpCodes.Ldloc_1
                                           );

            if (spot == -1)
            {
                log.Add("Can't find patch location!");
                return;
            }

            fn.Body.Instructions[spot + 1].Operand = minZoom;
        }
예제 #20
0
        public static void Patch(ModuleDefinition module, List <string> log)
        {
            var player    = IL.GetTypeDefinition(module, "Player");
            var quickHeal = IL.GetMethodDefinition(player, "QuickHeal");
            var quickMana = IL.GetMethodDefinition(player, "QuickMana");
            var itemCheck = IL.GetMethodDefinition(player, "ItemCheck"); // regular potion usage

            // quick heal
            int spot1 = IL.ScanForOpcodePattern(quickHeal,
                                                (i, instruction) =>
            {
                var i1 = quickHeal.Body.Instructions[i + 1].Operand as FieldReference;
                return(i1 != null && i1.Name == "potion");
            },
                                                OpCodes.Ldloc_0,
                                                OpCodes.Ldfld,
                                                OpCodes.Brfalse_S);

            for (int i = 0; i < 2; i++)
            {
                quickHeal.Body.Instructions[spot1 + i].OpCode = OpCodes.Nop;
            }
            quickHeal.Body.Instructions[spot1 + 2].OpCode = OpCodes.Br_S;

            // quick mana
            int spot2 = IL.ScanForOpcodePattern(quickMana,
                                                (i, instruction) =>
            {
                var i4 = quickMana.Body.Instructions[i + 4].Operand as FieldReference;
                return(i4 != null && i4.Name == "potion");
            },
                                                OpCodes.Ldarg_0,
                                                OpCodes.Ldfld,
                                                OpCodes.Ldloc_0,
                                                OpCodes.Ldelem_Ref,
                                                OpCodes.Ldfld,
                                                OpCodes.Brfalse_S);

            for (int i = 0; i < 5; i++)
            {
                quickMana.Body.Instructions[spot2 + i].OpCode = OpCodes.Nop;
            }
            quickMana.Body.Instructions[spot2 + 5].OpCode = OpCodes.Br_S;

            // health/mana
            int spot3 = IL.ScanForOpcodePattern(itemCheck,
                                                (i, instruction) =>
            {
                var i2 = itemCheck.Body.Instructions[i + 2].Operand as FieldReference;
                return(i2 != null && i2.Name == "potionDelayTime");
            },
                                                OpCodes.Ldarg_0,
                                                OpCodes.Ldarg_0,
                                                OpCodes.Ldfld,
                                                OpCodes.Stfld);

            for (int i = 0; i < 10; i++)
            {
                itemCheck.Body.Instructions[spot3 + i].OpCode = OpCodes.Nop;
            }

            // rejuv
            int spot4 = IL.ScanForOpcodePattern(itemCheck,
                                                (i, instruction) =>
            {
                var i2 = itemCheck.Body.Instructions[i + 2].Operand as FieldReference;
                return(i2 != null && i2.Name == "restorationDelayTime");
            },
                                                OpCodes.Ldarg_0,
                                                OpCodes.Ldarg_0,
                                                OpCodes.Ldfld,
                                                OpCodes.Stfld);

            for (int i = 0; i < 10; i++)
            {
                itemCheck.Body.Instructions[spot4 + i].OpCode = OpCodes.Nop;
            }
        }