private static void Player_GetItem(ILContext il) { ILCursor cursor = new ILCursor(il); ILLabel label = cursor.DefineLabel(); if (cursor.TryGotoNext(MoveType.AfterLabel, i => i.MatchLdloc(3), i => i.MatchStloc(4))) { cursor.Emit(OpCodes.Ldarg, 0); cursor.Emit(OpCodes.Ldarg, 2); cursor.EmitDelegate <Func <Player, Item, Item> >((player, item) => { if (ItemUtility.BlockGetItem) { return(item); } if (item.bait > 0 || Utility.FishingWhitelist.Contains(item.type)) { FishingBelt belt = player.inventory.OfType <FishingBelt>().FirstOrDefault(bag => bag.Handler.HasSpace(item)); if (belt != null) { Main.PlaySound(SoundID.Grab); Item temp = item.Clone(); belt.Handler.InsertItem(ref item); BagItemText(belt.item, temp, temp.stack - item.stack, false, false); if (item.IsAir || !item.active) { return(item); } } } if (item.stack <= 0) { item.active = false; } return(item); }); cursor.Emit(OpCodes.Starg, 2); cursor.Emit(OpCodes.Ldarg, 2); cursor.EmitDelegate <Func <Item, bool> >(item => item.IsAir); cursor.Emit(OpCodes.Brfalse, label); cursor.Emit(OpCodes.Ldarg, 2); cursor.Emit(OpCodes.Ret); cursor.MarkLabel(label); } }
public FishingBeltItemStorage(int slots, FishingBelt bag) : base(slots) { this.bag = bag; }
private static void Player_GetItem(ILContext il) { ILCursor cursor = new ILCursor(il); ILLabel myCode = cursor.DefineLabel(); ILLabel label = cursor.DefineLabel(); ILLabel l = null; while (cursor.TryGotoNext(i => i.MatchBneUn(out l))) { if (l.Target.Offset == 187) { cursor.Remove(); cursor.Emit(OpCodes.Bne_Un, myCode); } } while (cursor.TryGotoNext(i => i.MatchBrtrue(out l))) { if (l.Target.Offset == 187) { cursor.Remove(); cursor.Emit(OpCodes.Brtrue, myCode); } } if (cursor.TryGotoPrev(i => i.MatchLdloc(3), i => i.MatchStloc(4))) { cursor.MarkLabel(myCode); cursor.Emit(OpCodes.Ldarg, 0); cursor.Emit(OpCodes.Ldarg, 2); cursor.EmitDelegate <Func <Player, Item, Item> >((player, item) => { if (item.bait > 0 || Utility.FishingWhitelist.Contains(item.type)) { FishingBelt belt = player.inventory.OfType <FishingBelt>().FirstOrDefault(bag => bag.Handler.HasSpace(item)); if (belt != null) { Main.PlaySound(SoundID.Grab); belt.Handler.InsertItem(ref item); if (item.IsAir || !item.active) { return(item); } } } return(item); }); cursor.Emit(OpCodes.Starg, 2); cursor.Emit(OpCodes.Ldarg, 2); cursor.Emit(OpCodes.Callvirt, typeof(Item).GetProperty("IsAir", BaseLibrary.Utility.defaultFlags).GetGetMethod()); cursor.Emit(OpCodes.Brfalse, label); cursor.Emit(OpCodes.Ldarg, 2); cursor.Emit(OpCodes.Ret); cursor.MarkLabel(label); } }