public override void Process(int whoAmI, byte[] readBuffer, int length, int num) { int x = ReadInt16(readBuffer); int y = ReadInt16(readBuffer); var player = Main.player[whoAmI]; if (Math.Abs(player.position.X / 16 - x) >= 7 || Math.Abs(player.position.Y / 16 - y) >= 7) { return; } int chestIndex = Chest.FindChest(x, y); var ctx = new HookContext { Connection = player.Connection, Player = player, Sender = player, }; var args = new HookArgs.ChestOpenReceived { X = x, Y = y, ChestIndex = chestIndex, }; HookPoints.ChestOpenReceived.Invoke(ref ctx, ref args); if (ctx.CheckForKick()) { return; } if (ctx.Result == HookResult.IGNORE) { return; } if (ctx.Result == HookResult.DEFAULT && chestIndex > -1) { var user = Chest.UsingChest(chestIndex); if (user >= 0 && user != whoAmI) return; for (int i = 0; i < Chest.maxItems; i++) { NewNetMessage.SendData(32, whoAmI, -1, String.Empty, chestIndex, (float)i); } NewNetMessage.SendData(33, whoAmI, -1, String.Empty, chestIndex); Main.player[whoAmI].chest = chestIndex; return; } }
private static void ProcessChestOpen(int bufferId) { var buffer = NetMessage.buffer[bufferId]; var player = Main.player[bufferId]; if (Main.netMode != 2) { return; } int x = (int)buffer.reader.ReadInt16(); int y = (int)buffer.reader.ReadInt16(); if (Math.Abs(player.position.X / 16 - x) >= 7 || Math.Abs(player.position.Y / 16 - y) >= 7) { return; } int chestIndex = Chest.FindChest(x, y); if (chestIndex <= -1 || Chest.UsingChest(chestIndex) != -1) { return; } var ctx = new HookContext { Connection = player.Connection.Socket, Player = player, Sender = player }; var args = new HookArgs.ChestOpenReceived { X = x, Y = y, ChestIndex = chestIndex }; HookPoints.ChestOpenReceived.Invoke(ref ctx, ref args); if (ctx.CheckForKick()) { return; } if (ctx.Result == HookResult.IGNORE) { return; } if (ctx.Result == HookResult.DEFAULT && chestIndex > -1) { for (int num97 = 0; num97 < 40; num97++) { NetMessage.SendData(32, bufferId, -1, "", chestIndex, (float)num97, 0, 0, 0, 0, 0); } NetMessage.SendData(33, bufferId, -1, "", chestIndex, 0, 0, 0, 0, 0, 0); Main.player[bufferId].chest = chestIndex; if (Main.myPlayer == bufferId) { Main.recBigList = false; } Recipe.FindRecipes(); NetMessage.SendData(80, -1, bufferId, "", bufferId, (float)chestIndex, 0, 0, 0, 0, 0); if (Main.tile[x, y].frameX >= 36 && Main.tile[x, y].frameX < 72) { AchievementsHelper.HandleSpecialEvent(Main.player[bufferId], 16); } } }