From 09121368e402b4cd0f1f92b7f91945e5bbd259d3 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Thu, 21 Dec 2017 20:32:07 -0700 Subject: [PATCH 01/45] Move TShock.CheckRangePermission to TSPlayer TShock.CheckRangePermission is now TSPlayer.IsInRange, but the most important thing is that this method returns the opposite of what the original did, so all of the calls that would go to it are now inverted. --- CHANGELOG.md | 1 + TShockAPI/Bouncer.cs | 30 +++++++++++++++--------------- TShockAPI/GetDataHandlers.cs | 8 ++++---- TShockAPI/TSPlayer.cs | 14 ++++++++++++++ TShockAPI/TShock.cs | 20 +------------------- 5 files changed, 35 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7286ea27..88ba267a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Added `TSPlayer.CheckIgnores()` and removed `TShock.CheckIgnores(TSPlayer)`. (@hakusaro) * Hooks inside TShock can now be registered with their `Register` method and can be prioritized according to the TShock HandlerList system. (@hakusaro) * Fix message requiring login not using the command specifier set in the config file. (@hakusaro) +* Move `TShock.CheckRangePermission()` to `TSPlayer.IsInRange` which **returns the opposite** of what the previous method did (see updated docs). (@hakusaro) ## TShock 4.3.25 * Fixed a critical exploit in the Terraria protocol that could cause massive unpreventable world corruption as well as a number of other problems. Thanks to @bartico6 for reporting. Fixed by the efforts of @QuiCM, @hakusaro, and tips in the right directioon from @bartico6. diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 8e81d802..d4727962 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -83,7 +83,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, args.X, args.Y)) + if (!args.Player.IsInRange(args.X, args.Y)) { NetMessage.SendData((int)PacketTypes.UpdateTileEntity, -1, -1, NetworkText.Empty, args.ItemFrame.ID, 0, 1); args.Handled = true; @@ -138,7 +138,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, args.X, args.Y)) + if (!args.Player.IsInRange(args.X, args.Y)) { args.Handled = true; return; @@ -253,7 +253,7 @@ namespace TShockAPI } if (TShock.Config.RangeChecks && - TShock.CheckRangePermission(args.Player, (int)(Main.npc[id].position.X / 16f), (int)(Main.npc[id].position.Y / 16f), 128)) + !args.Player.IsInRange((int)(Main.npc[id].position.X / 16f), (int)(Main.npc[id].position.Y / 16f), 128)) { args.Player.SendData(PacketTypes.NpcUpdate, "", id); args.Handled = true; @@ -319,7 +319,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, TShock.Players[id].TileX, TShock.Players[id].TileY, 100)) + if (!args.Player.IsInRange(TShock.Players[id].TileX, TShock.Players[id].TileY, 100)) { args.Player.SendData(PacketTypes.PlayerHp, "", id); args.Player.SendData(PacketTypes.PlayerUpdate, "", id); @@ -373,7 +373,7 @@ namespace TShockAPI // client side (but only if it passed the range check) (i.e., return false) if (type == 0) { - if (TShock.CheckRangePermission(args.Player, (int)(Main.item[id].position.X / 16f), (int)(Main.item[id].position.Y / 16f))) + if (!args.Player.IsInRange((int)(Main.item[id].position.X / 16f), (int)(Main.item[id].position.Y / 16f))) { // Causes item duplications. Will be re added if necessary //args.Player.SendData(PacketTypes.ItemDrop, "", id); @@ -385,7 +385,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, (int)(pos.X / 16f), (int)(pos.Y / 16f))) + if (!args.Player.IsInRange((int)(pos.X / 16f), (int)(pos.Y / 16f))) { args.Player.SendData(PacketTypes.ItemDrop, "", id); args.Handled = true; @@ -465,7 +465,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, TShock.Players[id].TileX, TShock.Players[id].TileY, 50)) + if (!args.Player.IsInRange(TShock.Players[id].TileX, TShock.Players[id].TileY, 50)) { args.Player.SendData(PacketTypes.PlayerAddBuff, "", id); args.Handled = true; @@ -516,7 +516,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, Main.chest[id].x, Main.chest[id].y)) + if (!args.Player.IsInRange(Main.chest[id].x, Main.chest[id].y)) { args.Handled = true; return; @@ -544,7 +544,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, x, y)) + if (!args.Player.IsInRange(x, y)) { args.Player.SendData(PacketTypes.UpdateNPCHome, "", id, Main.npc[id].homeTileX, Main.npc[id].homeTileY, Convert.ToByte(Main.npc[id].homeless)); @@ -564,7 +564,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, args.X, args.Y)) + if (!args.Player.IsInRange(args.X, args.Y)) { args.Handled = true; return; @@ -632,7 +632,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, tileX, tileY)) + if (!args.Player.IsInRange(tileX, tileY)) { args.Player.SendTileSquare(tileX, tileY, 3); args.Handled = true; @@ -765,7 +765,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, tileX, tileY, 16)) + if (!args.Player.IsInRange(tileX, tileY, 16)) { args.Player.SendTileSquare(tileX, tileY, 1); args.Handled = true; @@ -1160,7 +1160,7 @@ namespace TShockAPI || type != TileID.SilkRope || type != TileID.VineRope || type != TileID.WebRope) - && TShock.CheckRangePermission(args.Player, x, y)) + && !args.Player.IsInRange(x, y)) { args.Player.SendTileSquare(x, y, 4); args.Handled = true; @@ -1484,7 +1484,7 @@ namespace TShockAPI return; } - if (TShock.CheckRangePermission(args.Player, tileX, tileY)) + if (!args.Player.IsInRange(tileX, tileY)) { if (action == EditAction.PlaceTile && (editData == TileID.Rope || editData == TileID.SilkRope || editData == TileID.VineRope || editData == TileID.WebRope)) { @@ -1661,7 +1661,7 @@ namespace TShockAPI var tile = Main.tile[realx, realy]; var newtile = tiles[x, y]; if (TShock.CheckTilePermission(args.Player, realx, realy) || - TShock.CheckRangePermission(args.Player, realx, realy)) + !args.Player.IsInRange(realx, realy)) { continue; } diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index a8524597..310a3b64 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2578,7 +2578,7 @@ namespace TShockAPI return true; } - if (TShock.CheckRangePermission(args.Player, x, y)) + if (!args.Player.IsInRange(x, y)) { args.Player.SendData(PacketTypes.SignNew, "", id); return true; @@ -2898,7 +2898,7 @@ namespace TShockAPI if (args.Player.IsBouncerThrottled() || TShock.CheckTilePermission(args.Player, x, y, true) || - TShock.CheckRangePermission(args.Player, x, y)) + !args.Player.IsInRange(x, y)) { args.Player.SendData(PacketTypes.PaintTile, "", x, y, Main.tile[x, y].color()); return true; @@ -2942,7 +2942,7 @@ namespace TShockAPI if (args.Player.IsBouncerThrottled() || TShock.CheckTilePermission(args.Player, x, y, true) || - TShock.CheckRangePermission(args.Player, x, y)) + !args.Player.IsInRange(x, y)) { args.Player.SendData(PacketTypes.PaintWall, "", x, y, Main.tile[x, y].wallColor()); return true; @@ -3293,7 +3293,7 @@ namespace TShockAPI return true; } - if (TShock.CheckRangePermission(args.Player, (int)position.X, (int)position.Y)) + if (!args.Player.IsInRange((int)position.X, (int)position.Y)) { return true; } diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 69181389..8071ea37 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -321,6 +321,20 @@ namespace TShockAPI public bool SilentJoinInProgress; + /// Checks if a player has permission to modify a tile dependent on range checks. + /// The x coordinate of the tile. + /// The y coordinate of the tile. + /// The range to check for. + /// True if the player is in range of a tile or if range checks are off. False if not. + public bool IsInRange(int x, int y, int range = 32) + { + if (TShock.Config.RangeChecks && ((Math.Abs(TileX - x) > range) || (Math.Abs(TileY - y) > range))) + { + return false; + } + return true; + } + /// /// A list of points where ice tiles have been placed. /// diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 44c6b9f1..8e2ea548 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -585,7 +585,7 @@ namespace TShockAPI return; } - if (CheckRangePermission(tsplr, args.Chest.x, args.Chest.y)) + if (!tsplr.IsInRange(args.Chest.x, args.Chest.y)) { args.Handled = true; return; @@ -1757,24 +1757,6 @@ namespace TShockAPI e.Handled = true; } - - - - /// CheckRangePermission - Checks if a player has permission to modify a tile dependent on range checks. - /// player - The TSPlayer object. - /// x - The x coordinate of the tile. - /// y - The y coordinate of the tile. - /// range - The range to check for. - /// bool - True if the player should not be able to place the tile. False if they can, or if range checks are off. - public static bool CheckRangePermission(TSPlayer player, int x, int y, int range = 32) - { - if (Config.RangeChecks && ((Math.Abs(player.TileX - x) > range) || (Math.Abs(player.TileY - y) > range))) - { - return true; - } - return false; - } - /// CheckTilePermission - Checks to see if a player has permission to modify a tile in general. /// player - The TSPlayer object. /// tileX - The x coordinate of the tile. From 195a23a7e5fbd48e2eb9027fee82ad0447534f5f Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Fri, 22 Dec 2017 00:31:02 -0700 Subject: [PATCH 02/45] Migrate most of CheckTilePermission to TSPlayer TShock.CheckTilePermission(ply, x, y, paint) has been replaced with TSPlayer.HasPaintPermission and TSPlayer.HasBuildPermission respectively. These two methods dramatically simplify the logic required to process build permissions. Still todo after this commit: 1. Implement warnings for when a player fails a permission check on build. This is probably going to be accomplished by a default argument to the HasBuildPermission signature. 2. Create a variant that checks for ice tile permission and use like HasPaintPermission() so as to remove the other TShock.CheckTilePermission method. Annoyingly, all of the existing methods that start with Check seem to "check" if they player _doesn't_ have permission (true = no permission), which makes nearly every call negative. --- TShockAPI/Bouncer.cs | 20 +++++------ TShockAPI/GetDataHandlers.cs | 8 ++--- TShockAPI/TSPlayer.cs | 50 ++++++++++++++++++++++++++ TShockAPI/TShock.cs | 69 ------------------------------------ 4 files changed, 64 insertions(+), 83 deletions(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index d4727962..0bbf77e5 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -76,7 +76,7 @@ namespace TShockAPI return; } - if (TShock.CheckTilePermission(args.Player, args.X, args.Y)) + if (!args.Player.HasBuildPermission(args.X, args.Y)) { NetMessage.SendData((int)PacketTypes.UpdateTileEntity, -1, -1, NetworkText.Empty, args.ItemFrame.ID, 0, 1); args.Handled = true; @@ -114,7 +114,7 @@ namespace TShockAPI return; } - if (TShock.CheckTilePermission(args.Player, args.X, args.Y)) + if (!args.Player.HasBuildPermission(args.X, args.Y)) { args.Handled = true; return; @@ -132,7 +132,7 @@ namespace TShockAPI return; } - if (TShock.CheckTilePermission(args.Player, args.X, args.Y)) + if (!args.Player.HasBuildPermission(args.X, args.Y)) { args.Handled = true; return; @@ -183,7 +183,7 @@ namespace TShockAPI return; } - if (TShock.CheckTilePermission(args.Player, x, y)) + if (!args.Player.HasBuildPermission(x, y)) { args.Handled = true; return; @@ -510,7 +510,7 @@ namespace TShockAPI return; } - if (TShock.CheckTilePermission(args.Player, Main.chest[id].x, Main.chest[id].y) && TShock.Config.RegionProtectChests) + if (!args.Player.HasBuildPermission(Main.chest[id].x, Main.chest[id].y) && TShock.Config.RegionProtectChests) { args.Handled = true; return; @@ -535,7 +535,7 @@ namespace TShockAPI // Calls to TShock.CheckTilePermission need to be broken up into different subsystems // In particular, this handles both regions and other things. Ouch. - if (TShock.CheckTilePermission(args.Player, x, y)) + if (!args.Player.HasBuildPermission(x, y)) { args.Player.SendErrorMessage("You do not have access to modify this area."); args.Player.SendData(PacketTypes.UpdateNPCHome, "", id, Main.npc[id].homeTileX, Main.npc[id].homeTileY, @@ -570,7 +570,7 @@ namespace TShockAPI return; } - if (TShock.CheckTilePermission(args.Player, args.X, args.Y) && TShock.Config.RegionProtectChests) + if (!args.Player.HasBuildPermission(args.X, args.Y) && TShock.Config.RegionProtectChests) { args.Handled = true; return; @@ -625,7 +625,7 @@ namespace TShockAPI } } - if (TShock.CheckTilePermission(args.Player, tileX, tileY)) + if (!args.Player.HasBuildPermission(tileX, tileY)) { args.Player.SendTileSquare(tileX, tileY, 3); args.Handled = true; @@ -758,7 +758,7 @@ namespace TShockAPI } } - if (TShock.CheckTilePermission(args.Player, tileX, tileY)) + if (!args.Player.HasBuildPermission(tileX, tileY)) { args.Player.SendTileSquare(tileX, tileY, 1); args.Handled = true; @@ -1660,7 +1660,7 @@ namespace TShockAPI var tile = Main.tile[realx, realy]; var newtile = tiles[x, y]; - if (TShock.CheckTilePermission(args.Player, realx, realy) || + if (!args.Player.HasBuildPermission(realx, realy) || !args.Player.IsInRange(realx, realy)) { continue; diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 310a3b64..6d7000a1 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2532,7 +2532,7 @@ namespace TShockAPI args.Player.ActiveChest = id; - if (TShock.CheckTilePermission(args.Player, x, y) && TShock.Config.RegionProtectChests) + if (!args.Player.HasBuildPermission(x, y) && TShock.Config.RegionProtectChests) { args.Player.SendData(PacketTypes.ChestOpen, "", -1); return true; @@ -2572,7 +2572,7 @@ namespace TShockAPI if (OnSignEvent(id, x, y)) return true; - if (TShock.CheckTilePermission(args.Player, x, y)) + if (!args.Player.HasBuildPermission(x, y)) { args.Player.SendData(PacketTypes.SignNew, "", id); return true; @@ -2897,7 +2897,7 @@ namespace TShockAPI } if (args.Player.IsBouncerThrottled() || - TShock.CheckTilePermission(args.Player, x, y, true) || + !args.Player.HasPaintPermission(x, y) || !args.Player.IsInRange(x, y)) { args.Player.SendData(PacketTypes.PaintTile, "", x, y, Main.tile[x, y].color()); @@ -2941,7 +2941,7 @@ namespace TShockAPI } if (args.Player.IsBouncerThrottled() || - TShock.CheckTilePermission(args.Player, x, y, true) || + !args.Player.HasPaintPermission(x, y) || !args.Player.IsInRange(x, y)) { args.Player.SendData(PacketTypes.PaintWall, "", x, y, Main.tile[x, y].wallColor()); diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 8071ea37..05d9844c 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -335,6 +335,56 @@ namespace TShockAPI return true; } + private enum BuildPermissionFailPoint + { + GeneralBuild, + SpawnProtect, + Regions + } + + /// Determines if the player can build on a given point. + /// The x coordinate they want to build at. + /// The y coordinate they want to paint at. + /// True if the player can build at the given point from build, spawn, and region protection. + public bool HasBuildPermission(int x, int y) + { + BuildPermissionFailPoint failure = BuildPermissionFailPoint.GeneralBuild; + // The goal is to short circuit on easy stuff as much as possible. + // Don't compute permissions unless needed, and don't compute taxing stuff unless needed. + + // If the player has bypass on build protection or building is enabled; continue + // (General build protection takes precedence over spawn protection) + if (!TShock.Config.DisableBuild || HasPermission(Permissions.antibuild)) + { + // If they have spawn protect bypass, or it isn't spawn, or it isn't in spawn; continue + // (If they have spawn protect bypass, we don't care if it's spawn or not) + if (!TShock.Config.SpawnProtection || HasPermission(Permissions.editspawn) || !Utils.IsInSpawn(x, y)) + { + // If they have build permission in this region, then they're allowed to continue + if (TShock.Regions.CanBuild(x, y, this)) + { + return true; + } + } + } + + // TODO: Implement warning system. + + // If they lack build permission, they end up here. + // If they have build permission but lack the ability to edit spawn and it's spawn, they end up here. + // If they have build, it isn't spawn, or they can edit spawn, but they fail the region check, they end up here. + return false; + } + + /// Determines if the player can paint on a given point. Checks general build permissions, then paint. + /// The x coordinate they want to paint at. + /// The y coordinate they want to paint at. + /// True if they can paint. + public bool HasPaintPermission(int x, int y) + { + return HasBuildPermission(x, y) || HasPermission(Permissions.canpaint); + } + /// /// A list of points where ice tiles have been placed. /// diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 1cc17e37..f35efda8 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -1842,75 +1842,6 @@ namespace TShockAPI return false; } - /// CheckTilePermission - Checks to see if a player has the ability to modify a tile at a given position. - /// player - The TSPlayer object. - /// tileX - The x coordinate of the tile. - /// tileY - The y coordinate of the tile. - /// paint - Whether or not the tile is paint. - /// bool - True if the player should not be able to modify the tile. - public static bool CheckTilePermission(TSPlayer player, int tileX, int tileY, bool paint = false) - { - if ((!paint && !player.HasPermission(Permissions.canbuild)) || - (paint && !player.HasPermission(Permissions.canpaint))) - { - if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.BPm) > 2000) - { - if (paint) - { - player.SendErrorMessage("You do not have permission to paint!"); - } - else - { - player.SendErrorMessage("You do not have permission to build!"); - } - player.BPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; - } - return true; - } - - if (!Regions.CanBuild(tileX, tileY, player)) - { - if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.RPm) > 2000) - { - player.SendErrorMessage("This region is protected from changes."); - player.RPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; - } - return true; - } - - if (Config.DisableBuild) - { - if (!player.HasPermission(Permissions.antibuild)) - { - if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.WPm) > 2000) - { - player.SendErrorMessage("The world is protected from changes."); - player.WPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; - } - return true; - } - } - - if (Config.SpawnProtection) - { - if (!player.HasPermission(Permissions.editspawn)) - { - if (Utils.IsInSpawn(tileX, tileY)) - { - if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.SPm) > 1000) - { - player.SendErrorMessage("Spawn is protected from changes."); - player.SPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; - } - return true; - } - } - } - return false; - } - - - /// Distance - Determines the distance between two vectors. /// value1 - The first vector location. /// value2 - The second vector location. From 7b2a4494b547cfd81f006bb79df28f43a1cf3819 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Fri, 22 Dec 2017 01:16:18 -0700 Subject: [PATCH 03/45] Move ice tile processing to TSPlayer. This moves ice tile placement and processing from TShock.CheckTilePermissions to TSPlayer in the form of the new boolean 'HasModifiedIceSuccessfully.' This is such a stupid thing we have to track, but we have to track it. Previously, we duplicated all of the check permission code and inserted special ice code paths. This duplicated a ton of code for little gain. The result of moving everything is that the control flow is easier to follow. In Terraria ice tiles are placed and melt on a timer so it's necessary to track them being placed and removed to permit tile events that would otherwise be blocked due to region checks and stuff. They're usually fairly harmless blocks, and without this code, ice wouldn't work properly. It's not ideal for this to be in TShock at all. --- TShockAPI/Bouncer.cs | 6 ++- TShockAPI/TSPlayer.cs | 40 ++++++++++++++++++++ TShockAPI/TShock.cs | 85 ------------------------------------------- 3 files changed, 44 insertions(+), 87 deletions(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 0bbf77e5..77d602a7 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -1146,7 +1146,8 @@ namespace TShockAPI { for (int j = y; j < y + tileData.Height; j++) { - if (TShock.CheckTilePermission(args.Player, i, j, type, EditAction.PlaceTile)) + if (!args.Player.HasModifiedIceSuccessfully(i, j, type, EditAction.PlaceTile) + && !args.Player.HasBuildPermission(i, j)) { args.Player.SendTileSquare(i, j, 4); args.Handled = true; @@ -1477,7 +1478,8 @@ namespace TShockAPI return; } - if (TShock.CheckTilePermission(args.Player, tileX, tileY, editData, action)) + if (!args.Player.HasModifiedIceSuccessfully(tileX, tileY, editData, action) + && !args.Player.HasBuildPermission(tileX, tileY)) { args.Player.SendTileSquare(tileX, tileY, 4); args.Handled = true; diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 05d9844c..a5aa17f2 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -385,6 +385,46 @@ namespace TShockAPI return HasBuildPermission(x, y) || HasPermission(Permissions.canpaint); } + /// Checks if a player can place ice, and if they can, tracks ice placements and removals. + /// The x coordinate of the suspected ice block. + /// The y coordinate of the suspected ice block. + /// The tile type of the suspected ice block. + /// The EditAction on the suspected ice block. + /// True if a player successfully places an ice tile or removes one of their past ice tiles. + public bool HasModifiedIceSuccessfully(int x, int y, short tileType, GetDataHandlers.EditAction editAction) + { + // The goal is to short circuit ASAP. + // A subsequent call to HasBuildPermission can figure this out if not explicitly ice. + if (!TShock.Config.AllowIce) + { + return false; + } + + // They've placed some ice. Horrible! + if (editAction == GetDataHandlers.EditAction.PlaceTile && tileType == TileID.MagicalIceBlock) + { + IceTiles.Add(new Point(x, y)); + return true; + } + + // The edit wasn't an add, so we check to see if the position matches any of the known ice tiles + if (editAction == GetDataHandlers.EditAction.KillTile) + { + foreach (Point p in IceTiles) + { + // If they're trying to kill ice or dirt, and the tile was in the list, we allow it. + if (p.X == x && p.Y == y && (Main.tile[p.X, p.Y].type == TileID.Dirt || Main.tile[p.X, p.Y].type == TileID.MagicalIceBlock)) + { + IceTiles.Remove(p); + return true; + } + } + } + + // Only a small number of cases let this happen. + return false; + } + /// /// A list of points where ice tiles have been placed. /// diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index f35efda8..5c03f7ee 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -1757,91 +1757,6 @@ namespace TShockAPI e.Handled = true; } - /// CheckTilePermission - Checks to see if a player has permission to modify a tile in general. - /// player - The TSPlayer object. - /// tileX - The x coordinate of the tile. - /// tileY - The y coordinate of the tile. - /// tileType - The tile type. - /// actionType - The type of edit that took place. - /// bool - True if the player should not be able to modify a tile. - public static bool CheckTilePermission(TSPlayer player, int tileX, int tileY, short tileType, GetDataHandlers.EditAction actionType) - { - if (!player.HasPermission(Permissions.canbuild)) - { - if (TShock.Config.AllowIce && actionType != GetDataHandlers.EditAction.PlaceTile) - { - foreach (Point p in player.IceTiles) - { - if (p.X == tileX && p.Y == tileY && (Main.tile[p.X, p.Y].type == 0 || Main.tile[p.X, p.Y].type == 127)) - { - player.IceTiles.Remove(p); - return false; - } - } - - if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.BPm) > 2000) - { - player.SendErrorMessage("You do not have permission to build!"); - player.BPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; - } - return true; - } - - if (TShock.Config.AllowIce && actionType == GetDataHandlers.EditAction.PlaceTile && tileType == 127) - { - player.IceTiles.Add(new Point(tileX, tileY)); - return false; - } - - if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.BPm) > 2000) - { - player.SendErrorMessage("You do not have permission to build!"); - player.BPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; - } - return true; - } - - if (!Regions.CanBuild(tileX, tileY, player)) - { - if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.RPm) > 2000) - { - player.SendErrorMessage("This region is protected from changes."); - player.RPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; - } - return true; - } - - if (Config.DisableBuild) - { - if (!player.HasPermission(Permissions.antibuild)) - { - if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.WPm) > 2000) - { - player.SendErrorMessage("The world is protected from changes."); - player.WPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; - } - return true; - } - } - - if (Config.SpawnProtection) - { - if (!player.HasPermission(Permissions.editspawn)) - { - if (Utils.IsInSpawn(tileX, tileY)) - { - if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - player.SPm) > 2000) - { - player.SendErrorMessage("Spawn is protected from changes."); - player.SPm = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; - } - return true; - } - } - } - return false; - } - /// Distance - Determines the distance between two vectors. /// value1 - The first vector location. /// value2 - The second vector location. From e370873fff5a3d511c0a7a05da5f1d70f95aa973 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Fri, 22 Dec 2017 01:27:14 -0700 Subject: [PATCH 04/45] Warn players if they can't modify the world This reimplements warnings that CheckTilePermissions previously had. It defaults to on because every single call currently in TShock expects it to be on. --- CHANGELOG.md | 1 + TShockAPI/Bouncer.cs | 3 --- TShockAPI/TSPlayer.cs | 26 ++++++++++++++++++++++---- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e081c0b6..db04f777 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Fix message requiring login not using the command specifier set in the config file. (@hakusaro) * Move `TShock.CheckRangePermission()` to `TSPlayer.IsInRange` which **returns the opposite** of what the previous method did (see updated docs). (@hakusaro) * Move `TShock.CheckSpawn` to `Utils.IsInSpawn`. (@hakusaro) +* Replace `TShock.CheckTilePermission` with `TSPlayer.HasBuildPermission`, `TSPlayer.HasPaintPermission`, and `TSPlayer.HasModifiedIceSuccessfully` respectively. (@hakusaro) ## TShock 4.3.25 * Fixed a critical exploit in the Terraria protocol that could cause massive unpreventable world corruption as well as a number of other problems. Thanks to @bartico6 for reporting. Fixed by the efforts of @QuiCM, @hakusaro, and tips in the right directioon from @bartico6. diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 77d602a7..d17c5266 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -533,11 +533,8 @@ namespace TShockAPI short y = args.Y; byte homeless = args.Homeless; - // Calls to TShock.CheckTilePermission need to be broken up into different subsystems - // In particular, this handles both regions and other things. Ouch. if (!args.Player.HasBuildPermission(x, y)) { - args.Player.SendErrorMessage("You do not have access to modify this area."); args.Player.SendData(PacketTypes.UpdateNPCHome, "", id, Main.npc[id].homeTileX, Main.npc[id].homeTileY, Convert.ToByte(Main.npc[id].homeless)); args.Handled = true; diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index a5aa17f2..dad3ca4e 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -346,7 +346,7 @@ namespace TShockAPI /// The x coordinate they want to build at. /// The y coordinate they want to paint at. /// True if the player can build at the given point from build, spawn, and region protection. - public bool HasBuildPermission(int x, int y) + public bool HasBuildPermission(int x, int y, bool shouldWarnPlayer = true) { BuildPermissionFailPoint failure = BuildPermissionFailPoint.GeneralBuild; // The goal is to short circuit on easy stuff as much as possible. @@ -356,10 +356,12 @@ namespace TShockAPI // (General build protection takes precedence over spawn protection) if (!TShock.Config.DisableBuild || HasPermission(Permissions.antibuild)) { + failure = BuildPermissionFailPoint.SpawnProtect; // If they have spawn protect bypass, or it isn't spawn, or it isn't in spawn; continue // (If they have spawn protect bypass, we don't care if it's spawn or not) if (!TShock.Config.SpawnProtection || HasPermission(Permissions.editspawn) || !Utils.IsInSpawn(x, y)) { + failure = BuildPermissionFailPoint.Regions; // If they have build permission in this region, then they're allowed to continue if (TShock.Regions.CanBuild(x, y, this)) { @@ -367,12 +369,28 @@ namespace TShockAPI } } } - - // TODO: Implement warning system. - // If they lack build permission, they end up here. // If they have build permission but lack the ability to edit spawn and it's spawn, they end up here. // If they have build, it isn't spawn, or they can edit spawn, but they fail the region check, they end up here. + + // If they shouldn't be warned, exit early. + if (!shouldWarnPlayer) + return false; + + // If they should be warned, warn them. + switch (failure) + { + case BuildPermissionFailPoint.GeneralBuild: + SendErrorMessage("You lack permission to build on this server."); + break; + case BuildPermissionFailPoint.SpawnProtect: + SendErrorMessage("You lack permission to build in the spawn point."); + break; + case BuildPermissionFailPoint.Regions: + SendErrorMessage("You lack permission to build in this region."); + break; + } + return false; } From bfbe58e9edd321a479cac347e4c28a6d984add12 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Fri, 22 Dec 2017 10:03:59 -0700 Subject: [PATCH 05/45] Implement cooldown warnings on build permissions --- TShockAPI/TSPlayer.cs | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index dad3ca4e..a4402849 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -377,6 +377,12 @@ namespace TShockAPI if (!shouldWarnPlayer) return false; + // Space out warnings by 2 seconds so that they don't get spammed. + if (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - lastPermissionWarning) < 2000) + { + return false; + } + // If they should be warned, warn them. switch (failure) { @@ -391,6 +397,9 @@ namespace TShockAPI break; } + // Set the last warning time to now. + lastPermissionWarning = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; + return false; } @@ -449,24 +458,10 @@ namespace TShockAPI public List IceTiles; /// - /// Unused, can be removed. + /// The last time the player was warned for build permissions. + /// In MS, defaults to 1 (so it will warn on the first attempt). /// - public long RPm = 1; - - /// - /// World protection message cool down. - /// - public long WPm = 1; - - /// - /// Spawn protection message cool down. - /// - public long SPm = 1; - - /// - /// Permission to build message cool down. - /// - public long BPm = 1; + public long lastPermissionWarning = 1; /// /// The time in ms when the player has logged in. From c501a128ff2dc62b1939db132382ef4222e04fbf Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Fri, 22 Dec 2017 21:02:53 -0700 Subject: [PATCH 06/45] Clarify summary of TSPlayer.IsInRange --- TShockAPI/TSPlayer.cs | 218 ++---------------------------------------- 1 file changed, 8 insertions(+), 210 deletions(-) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index d526e851..d0d1bb3c 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -307,215 +307,6 @@ namespace TShockAPI || !IsLoggedIn && TShock.Config.RequireLogin; } - /// Checks to see if a player has hacked item stacks in their inventory, and messages them as it checks. - /// If the check should send a message to the player with the results of the check. - /// True if any stacks don't conform. - public bool HasHackedItemStacks(bool shouldWarnPlayer = false) - { - // Iterates through each inventory location a player has. - // This section is sub divided into number ranges for what each range of slots corresponds to. - bool check = false; - - Item[] inventory = TPlayer.inventory; - Item[] armor = TPlayer.armor; - Item[] dye = TPlayer.dye; - Item[] miscEquips = TPlayer.miscEquips; - Item[] miscDyes = TPlayer.miscDyes; - Item[] piggy = TPlayer.bank.item; - Item[] safe = TPlayer.bank2.item; - Item[] forge = TPlayer.bank3.item; - Item trash = TPlayer.trashItem; - for (int i = 0; i < NetItem.MaxInventory; i++) - { - if (i < NetItem.InventoryIndex.Item2) - { - // From above: this is slots 0-58 in the inventory. - // 0-58 - Item item = new Item(); - if (inventory[i] != null && inventory[i].netID != 0) - { - item.netDefaults(inventory[i].netID); - item.Prefix(inventory[i].prefix); - item.AffixName(); - if (inventory[i].stack > item.maxStack || inventory[i].stack < 0) - { - check = true; - if (shouldWarnPlayer) - { - SendErrorMessage("Stack cheat detected. Remove item {0} ({1}) and then rejoin.", item.Name, inventory[i].stack); - } - } - } - } - else if (i < NetItem.ArmorIndex.Item2) - { - // 59-78 - var index = i - NetItem.ArmorIndex.Item1; - Item item = new Item(); - if (armor[index] != null && armor[index].netID != 0) - { - item.netDefaults(armor[index].netID); - item.Prefix(armor[index].prefix); - item.AffixName(); - if (armor[index].stack > item.maxStack || armor[index].stack < 0) - { - check = true; - if (shouldWarnPlayer) - { - SendErrorMessage("Stack cheat detected. Remove armor {0} ({1}) and then rejoin.", item.Name, armor[index].stack); - } - } - } - } - else if (i < NetItem.DyeIndex.Item2) - { - // 79-88 - var index = i - NetItem.DyeIndex.Item1; - Item item = new Item(); - if (dye[index] != null && dye[index].netID != 0) - { - item.netDefaults(dye[index].netID); - item.Prefix(dye[index].prefix); - item.AffixName(); - if (dye[index].stack > item.maxStack || dye[index].stack < 0) - { - check = true; - if (shouldWarnPlayer) - { - SendErrorMessage("Stack cheat detected. Remove dye {0} ({1}) and then rejoin.", item.Name, dye[index].stack); - } - } - } - } - else if (i < NetItem.MiscEquipIndex.Item2) - { - // 89-93 - var index = i - NetItem.MiscEquipIndex.Item1; - Item item = new Item(); - if (miscEquips[index] != null && miscEquips[index].netID != 0) - { - item.netDefaults(miscEquips[index].netID); - item.Prefix(miscEquips[index].prefix); - item.AffixName(); - if (miscEquips[index].stack > item.maxStack || miscEquips[index].stack < 0) - { - check = true; - if (shouldWarnPlayer) - { - SendErrorMessage("Stack cheat detected. Remove item {0} ({1}) and then rejoin.", item.Name, miscEquips[index].stack); - } - } - } - } - else if (i < NetItem.MiscDyeIndex.Item2) - { - // 93-98 - var index = i - NetItem.MiscDyeIndex.Item1; - Item item = new Item(); - if (miscDyes[index] != null && miscDyes[index].netID != 0) - { - item.netDefaults(miscDyes[index].netID); - item.Prefix(miscDyes[index].prefix); - item.AffixName(); - if (miscDyes[index].stack > item.maxStack || miscDyes[index].stack < 0) - { - check = true; - if (shouldWarnPlayer) - { - SendErrorMessage("Stack cheat detected. Remove item dye {0} ({1}) and then rejoin.", item.Name, miscDyes[index].stack); - } - } - } - } - else if (i < NetItem.PiggyIndex.Item2) - { - // 98-138 - var index = i - NetItem.PiggyIndex.Item1; - Item item = new Item(); - if (piggy[index] != null && piggy[index].netID != 0) - { - item.netDefaults(piggy[index].netID); - item.Prefix(piggy[index].prefix); - item.AffixName(); - - if (piggy[index].stack > item.maxStack || piggy[index].stack < 0) - { - check = true; - if (shouldWarnPlayer) - { - SendErrorMessage("Stack cheat detected. Remove piggy-bank item {0} ({1}) and then rejoin.", item.Name, piggy[index].stack); - } - } - } - } - else if (i < NetItem.SafeIndex.Item2) - { - // 138-178 - var index = i - NetItem.SafeIndex.Item1; - Item item = new Item(); - if (safe[index] != null && safe[index].netID != 0) - { - item.netDefaults(safe[index].netID); - item.Prefix(safe[index].prefix); - item.AffixName(); - - if (safe[index].stack > item.maxStack || safe[index].stack < 0) - { - check = true; - if (shouldWarnPlayer) - { - SendErrorMessage("Stack cheat detected. Remove safe item {0} ({1}) and then rejoin.", item.Name, safe[index].stack); - } - } - } - } - else if (i < NetItem.TrashIndex.Item2) - { - // 179-219 - Item item = new Item(); - if (trash != null && trash.netID != 0) - { - item.netDefaults(trash.netID); - item.Prefix(trash.prefix); - item.AffixName(); - - if (trash.stack > item.maxStack) - { - check = true; - if (shouldWarnPlayer) - { - SendErrorMessage("Stack cheat detected. Remove trash item {0} ({1}) and then rejoin.", item.Name, trash.stack); - } - } - } - } - else - { - // 220 - var index = i - NetItem.ForgeIndex.Item1; - Item item = new Item(); - if (forge[index] != null && forge[index].netID != 0) - { - item.netDefaults(forge[index].netID); - item.Prefix(forge[index].prefix); - item.AffixName(); - - if (forge[index].stack > item.maxStack || forge[index].stack < 0) - { - check = true; - if (shouldWarnPlayer) - { - SendErrorMessage("Stack cheat detected. Remove Defender's Forge item {0} ({1}) and then rejoin.", item.Name, forge[index].stack); - } - } - } - - } - } - - return check; - } - /// /// The player's server side inventory data. /// @@ -530,7 +321,7 @@ namespace TShockAPI public bool SilentJoinInProgress; - /// Checks if a player has permission to modify a tile dependent on range checks. + /// Checks if a player is in range of a given tile if range checks are enabled. /// The x coordinate of the tile. /// The y coordinate of the tile. /// The range to check for. @@ -1549,7 +1340,14 @@ namespace TShockAPI StackFrame frame = null; frame = trace.GetFrame(1); if (frame != null && frame.GetMethod().DeclaringType != null) + { TShock.Log.Debug(frame.GetMethod().DeclaringType.Name + " called Disable()."); + TShock.Log.Debug("SSC: " + IsDisabledForSSC); + TShock.Log.Debug("Stacks: " + IsDisabledForStackDetection); + TShock.Log.Debug("Wearables: " + IsDisabledForBannedWearable); + TShock.Log.Debug("Trash: " + IsDisabledPendingTrashRemoval); + TShock.Log.Debug("Logged in?" + IsLoggedIn); + } } /// From 604b386cbaca45e6f392bccac9f0ce07aed25489 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Fri, 22 Dec 2017 21:12:56 -0700 Subject: [PATCH 07/45] Rescue lost work --- TShockAPI/TSPlayer.cs | 218 ++---------------------------------------- 1 file changed, 8 insertions(+), 210 deletions(-) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index d526e851..d0d1bb3c 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -307,215 +307,6 @@ namespace TShockAPI || !IsLoggedIn && TShock.Config.RequireLogin; } - /// Checks to see if a player has hacked item stacks in their inventory, and messages them as it checks. - /// If the check should send a message to the player with the results of the check. - /// True if any stacks don't conform. - public bool HasHackedItemStacks(bool shouldWarnPlayer = false) - { - // Iterates through each inventory location a player has. - // This section is sub divided into number ranges for what each range of slots corresponds to. - bool check = false; - - Item[] inventory = TPlayer.inventory; - Item[] armor = TPlayer.armor; - Item[] dye = TPlayer.dye; - Item[] miscEquips = TPlayer.miscEquips; - Item[] miscDyes = TPlayer.miscDyes; - Item[] piggy = TPlayer.bank.item; - Item[] safe = TPlayer.bank2.item; - Item[] forge = TPlayer.bank3.item; - Item trash = TPlayer.trashItem; - for (int i = 0; i < NetItem.MaxInventory; i++) - { - if (i < NetItem.InventoryIndex.Item2) - { - // From above: this is slots 0-58 in the inventory. - // 0-58 - Item item = new Item(); - if (inventory[i] != null && inventory[i].netID != 0) - { - item.netDefaults(inventory[i].netID); - item.Prefix(inventory[i].prefix); - item.AffixName(); - if (inventory[i].stack > item.maxStack || inventory[i].stack < 0) - { - check = true; - if (shouldWarnPlayer) - { - SendErrorMessage("Stack cheat detected. Remove item {0} ({1}) and then rejoin.", item.Name, inventory[i].stack); - } - } - } - } - else if (i < NetItem.ArmorIndex.Item2) - { - // 59-78 - var index = i - NetItem.ArmorIndex.Item1; - Item item = new Item(); - if (armor[index] != null && armor[index].netID != 0) - { - item.netDefaults(armor[index].netID); - item.Prefix(armor[index].prefix); - item.AffixName(); - if (armor[index].stack > item.maxStack || armor[index].stack < 0) - { - check = true; - if (shouldWarnPlayer) - { - SendErrorMessage("Stack cheat detected. Remove armor {0} ({1}) and then rejoin.", item.Name, armor[index].stack); - } - } - } - } - else if (i < NetItem.DyeIndex.Item2) - { - // 79-88 - var index = i - NetItem.DyeIndex.Item1; - Item item = new Item(); - if (dye[index] != null && dye[index].netID != 0) - { - item.netDefaults(dye[index].netID); - item.Prefix(dye[index].prefix); - item.AffixName(); - if (dye[index].stack > item.maxStack || dye[index].stack < 0) - { - check = true; - if (shouldWarnPlayer) - { - SendErrorMessage("Stack cheat detected. Remove dye {0} ({1}) and then rejoin.", item.Name, dye[index].stack); - } - } - } - } - else if (i < NetItem.MiscEquipIndex.Item2) - { - // 89-93 - var index = i - NetItem.MiscEquipIndex.Item1; - Item item = new Item(); - if (miscEquips[index] != null && miscEquips[index].netID != 0) - { - item.netDefaults(miscEquips[index].netID); - item.Prefix(miscEquips[index].prefix); - item.AffixName(); - if (miscEquips[index].stack > item.maxStack || miscEquips[index].stack < 0) - { - check = true; - if (shouldWarnPlayer) - { - SendErrorMessage("Stack cheat detected. Remove item {0} ({1}) and then rejoin.", item.Name, miscEquips[index].stack); - } - } - } - } - else if (i < NetItem.MiscDyeIndex.Item2) - { - // 93-98 - var index = i - NetItem.MiscDyeIndex.Item1; - Item item = new Item(); - if (miscDyes[index] != null && miscDyes[index].netID != 0) - { - item.netDefaults(miscDyes[index].netID); - item.Prefix(miscDyes[index].prefix); - item.AffixName(); - if (miscDyes[index].stack > item.maxStack || miscDyes[index].stack < 0) - { - check = true; - if (shouldWarnPlayer) - { - SendErrorMessage("Stack cheat detected. Remove item dye {0} ({1}) and then rejoin.", item.Name, miscDyes[index].stack); - } - } - } - } - else if (i < NetItem.PiggyIndex.Item2) - { - // 98-138 - var index = i - NetItem.PiggyIndex.Item1; - Item item = new Item(); - if (piggy[index] != null && piggy[index].netID != 0) - { - item.netDefaults(piggy[index].netID); - item.Prefix(piggy[index].prefix); - item.AffixName(); - - if (piggy[index].stack > item.maxStack || piggy[index].stack < 0) - { - check = true; - if (shouldWarnPlayer) - { - SendErrorMessage("Stack cheat detected. Remove piggy-bank item {0} ({1}) and then rejoin.", item.Name, piggy[index].stack); - } - } - } - } - else if (i < NetItem.SafeIndex.Item2) - { - // 138-178 - var index = i - NetItem.SafeIndex.Item1; - Item item = new Item(); - if (safe[index] != null && safe[index].netID != 0) - { - item.netDefaults(safe[index].netID); - item.Prefix(safe[index].prefix); - item.AffixName(); - - if (safe[index].stack > item.maxStack || safe[index].stack < 0) - { - check = true; - if (shouldWarnPlayer) - { - SendErrorMessage("Stack cheat detected. Remove safe item {0} ({1}) and then rejoin.", item.Name, safe[index].stack); - } - } - } - } - else if (i < NetItem.TrashIndex.Item2) - { - // 179-219 - Item item = new Item(); - if (trash != null && trash.netID != 0) - { - item.netDefaults(trash.netID); - item.Prefix(trash.prefix); - item.AffixName(); - - if (trash.stack > item.maxStack) - { - check = true; - if (shouldWarnPlayer) - { - SendErrorMessage("Stack cheat detected. Remove trash item {0} ({1}) and then rejoin.", item.Name, trash.stack); - } - } - } - } - else - { - // 220 - var index = i - NetItem.ForgeIndex.Item1; - Item item = new Item(); - if (forge[index] != null && forge[index].netID != 0) - { - item.netDefaults(forge[index].netID); - item.Prefix(forge[index].prefix); - item.AffixName(); - - if (forge[index].stack > item.maxStack || forge[index].stack < 0) - { - check = true; - if (shouldWarnPlayer) - { - SendErrorMessage("Stack cheat detected. Remove Defender's Forge item {0} ({1}) and then rejoin.", item.Name, forge[index].stack); - } - } - } - - } - } - - return check; - } - /// /// The player's server side inventory data. /// @@ -530,7 +321,7 @@ namespace TShockAPI public bool SilentJoinInProgress; - /// Checks if a player has permission to modify a tile dependent on range checks. + /// Checks if a player is in range of a given tile if range checks are enabled. /// The x coordinate of the tile. /// The y coordinate of the tile. /// The range to check for. @@ -1549,7 +1340,14 @@ namespace TShockAPI StackFrame frame = null; frame = trace.GetFrame(1); if (frame != null && frame.GetMethod().DeclaringType != null) + { TShock.Log.Debug(frame.GetMethod().DeclaringType.Name + " called Disable()."); + TShock.Log.Debug("SSC: " + IsDisabledForSSC); + TShock.Log.Debug("Stacks: " + IsDisabledForStackDetection); + TShock.Log.Debug("Wearables: " + IsDisabledForBannedWearable); + TShock.Log.Debug("Trash: " + IsDisabledPendingTrashRemoval); + TShock.Log.Debug("Logged in?" + IsLoggedIn); + } } /// From 5991802dce1c5d29606dce97b67ff0014bf8f44d Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Fri, 22 Dec 2017 21:15:26 -0700 Subject: [PATCH 08/45] Revert "Clarify summary of TSPlayer.IsInRange" This reverts commit c501a128ff2dc62b1939db132382ef4222e04fbf. --- TShockAPI/TSPlayer.cs | 218 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 210 insertions(+), 8 deletions(-) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index d0d1bb3c..d526e851 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -307,6 +307,215 @@ namespace TShockAPI || !IsLoggedIn && TShock.Config.RequireLogin; } + /// Checks to see if a player has hacked item stacks in their inventory, and messages them as it checks. + /// If the check should send a message to the player with the results of the check. + /// True if any stacks don't conform. + public bool HasHackedItemStacks(bool shouldWarnPlayer = false) + { + // Iterates through each inventory location a player has. + // This section is sub divided into number ranges for what each range of slots corresponds to. + bool check = false; + + Item[] inventory = TPlayer.inventory; + Item[] armor = TPlayer.armor; + Item[] dye = TPlayer.dye; + Item[] miscEquips = TPlayer.miscEquips; + Item[] miscDyes = TPlayer.miscDyes; + Item[] piggy = TPlayer.bank.item; + Item[] safe = TPlayer.bank2.item; + Item[] forge = TPlayer.bank3.item; + Item trash = TPlayer.trashItem; + for (int i = 0; i < NetItem.MaxInventory; i++) + { + if (i < NetItem.InventoryIndex.Item2) + { + // From above: this is slots 0-58 in the inventory. + // 0-58 + Item item = new Item(); + if (inventory[i] != null && inventory[i].netID != 0) + { + item.netDefaults(inventory[i].netID); + item.Prefix(inventory[i].prefix); + item.AffixName(); + if (inventory[i].stack > item.maxStack || inventory[i].stack < 0) + { + check = true; + if (shouldWarnPlayer) + { + SendErrorMessage("Stack cheat detected. Remove item {0} ({1}) and then rejoin.", item.Name, inventory[i].stack); + } + } + } + } + else if (i < NetItem.ArmorIndex.Item2) + { + // 59-78 + var index = i - NetItem.ArmorIndex.Item1; + Item item = new Item(); + if (armor[index] != null && armor[index].netID != 0) + { + item.netDefaults(armor[index].netID); + item.Prefix(armor[index].prefix); + item.AffixName(); + if (armor[index].stack > item.maxStack || armor[index].stack < 0) + { + check = true; + if (shouldWarnPlayer) + { + SendErrorMessage("Stack cheat detected. Remove armor {0} ({1}) and then rejoin.", item.Name, armor[index].stack); + } + } + } + } + else if (i < NetItem.DyeIndex.Item2) + { + // 79-88 + var index = i - NetItem.DyeIndex.Item1; + Item item = new Item(); + if (dye[index] != null && dye[index].netID != 0) + { + item.netDefaults(dye[index].netID); + item.Prefix(dye[index].prefix); + item.AffixName(); + if (dye[index].stack > item.maxStack || dye[index].stack < 0) + { + check = true; + if (shouldWarnPlayer) + { + SendErrorMessage("Stack cheat detected. Remove dye {0} ({1}) and then rejoin.", item.Name, dye[index].stack); + } + } + } + } + else if (i < NetItem.MiscEquipIndex.Item2) + { + // 89-93 + var index = i - NetItem.MiscEquipIndex.Item1; + Item item = new Item(); + if (miscEquips[index] != null && miscEquips[index].netID != 0) + { + item.netDefaults(miscEquips[index].netID); + item.Prefix(miscEquips[index].prefix); + item.AffixName(); + if (miscEquips[index].stack > item.maxStack || miscEquips[index].stack < 0) + { + check = true; + if (shouldWarnPlayer) + { + SendErrorMessage("Stack cheat detected. Remove item {0} ({1}) and then rejoin.", item.Name, miscEquips[index].stack); + } + } + } + } + else if (i < NetItem.MiscDyeIndex.Item2) + { + // 93-98 + var index = i - NetItem.MiscDyeIndex.Item1; + Item item = new Item(); + if (miscDyes[index] != null && miscDyes[index].netID != 0) + { + item.netDefaults(miscDyes[index].netID); + item.Prefix(miscDyes[index].prefix); + item.AffixName(); + if (miscDyes[index].stack > item.maxStack || miscDyes[index].stack < 0) + { + check = true; + if (shouldWarnPlayer) + { + SendErrorMessage("Stack cheat detected. Remove item dye {0} ({1}) and then rejoin.", item.Name, miscDyes[index].stack); + } + } + } + } + else if (i < NetItem.PiggyIndex.Item2) + { + // 98-138 + var index = i - NetItem.PiggyIndex.Item1; + Item item = new Item(); + if (piggy[index] != null && piggy[index].netID != 0) + { + item.netDefaults(piggy[index].netID); + item.Prefix(piggy[index].prefix); + item.AffixName(); + + if (piggy[index].stack > item.maxStack || piggy[index].stack < 0) + { + check = true; + if (shouldWarnPlayer) + { + SendErrorMessage("Stack cheat detected. Remove piggy-bank item {0} ({1}) and then rejoin.", item.Name, piggy[index].stack); + } + } + } + } + else if (i < NetItem.SafeIndex.Item2) + { + // 138-178 + var index = i - NetItem.SafeIndex.Item1; + Item item = new Item(); + if (safe[index] != null && safe[index].netID != 0) + { + item.netDefaults(safe[index].netID); + item.Prefix(safe[index].prefix); + item.AffixName(); + + if (safe[index].stack > item.maxStack || safe[index].stack < 0) + { + check = true; + if (shouldWarnPlayer) + { + SendErrorMessage("Stack cheat detected. Remove safe item {0} ({1}) and then rejoin.", item.Name, safe[index].stack); + } + } + } + } + else if (i < NetItem.TrashIndex.Item2) + { + // 179-219 + Item item = new Item(); + if (trash != null && trash.netID != 0) + { + item.netDefaults(trash.netID); + item.Prefix(trash.prefix); + item.AffixName(); + + if (trash.stack > item.maxStack) + { + check = true; + if (shouldWarnPlayer) + { + SendErrorMessage("Stack cheat detected. Remove trash item {0} ({1}) and then rejoin.", item.Name, trash.stack); + } + } + } + } + else + { + // 220 + var index = i - NetItem.ForgeIndex.Item1; + Item item = new Item(); + if (forge[index] != null && forge[index].netID != 0) + { + item.netDefaults(forge[index].netID); + item.Prefix(forge[index].prefix); + item.AffixName(); + + if (forge[index].stack > item.maxStack || forge[index].stack < 0) + { + check = true; + if (shouldWarnPlayer) + { + SendErrorMessage("Stack cheat detected. Remove Defender's Forge item {0} ({1}) and then rejoin.", item.Name, forge[index].stack); + } + } + } + + } + } + + return check; + } + /// /// The player's server side inventory data. /// @@ -321,7 +530,7 @@ namespace TShockAPI public bool SilentJoinInProgress; - /// Checks if a player is in range of a given tile if range checks are enabled. + /// Checks if a player has permission to modify a tile dependent on range checks. /// The x coordinate of the tile. /// The y coordinate of the tile. /// The range to check for. @@ -1340,14 +1549,7 @@ namespace TShockAPI StackFrame frame = null; frame = trace.GetFrame(1); if (frame != null && frame.GetMethod().DeclaringType != null) - { TShock.Log.Debug(frame.GetMethod().DeclaringType.Name + " called Disable()."); - TShock.Log.Debug("SSC: " + IsDisabledForSSC); - TShock.Log.Debug("Stacks: " + IsDisabledForStackDetection); - TShock.Log.Debug("Wearables: " + IsDisabledForBannedWearable); - TShock.Log.Debug("Trash: " + IsDisabledPendingTrashRemoval); - TShock.Log.Debug("Logged in?" + IsLoggedIn); - } } /// From 5e7cb92de05dcd89bc6fb881aa597363e7a0b92c Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Fri, 22 Dec 2017 21:18:47 -0700 Subject: [PATCH 09/45] Re-apply some changes --- TShockAPI/TSPlayer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index d526e851..3c747b9d 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -530,7 +530,7 @@ namespace TShockAPI public bool SilentJoinInProgress; - /// Checks if a player has permission to modify a tile dependent on range checks. + /// Checks if a player is in range of a given tile if range checks are enabled. /// The x coordinate of the tile. /// The y coordinate of the tile. /// The range to check for. From 301125b2d81bf3a917fb4f740aaea297c68ad1c5 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 14:11:47 -0700 Subject: [PATCH 10/45] OnTileEdit is now a GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 83bcb26d..cf49df1d 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -80,13 +80,8 @@ namespace TShockAPI /// /// Used when a TileEdit event is called. /// - public class TileEditEventArgs : HandledEventArgs + public class TileEditEventArgs : GetDataHandledEventArgs { - /// - /// The TSPlayer who made the tile edit - /// - public TSPlayer Player { get; set; } - /// /// The tile coordinate on the X plane /// @@ -122,7 +117,7 @@ namespace TShockAPI /// TileEdit - called when a tile is placed or destroyed /// public static HandlerList TileEdit = new HandlerList(); - private static bool OnTileEdit(TSPlayer ply, int x, int y, EditAction action, EditType editDetail, short editData, byte style) + private static bool OnTileEdit(TSPlayer ply, MemoryStream data, int x, int y, EditAction action, EditType editDetail, short editData, byte style) { if (TileEdit == null) return false; @@ -130,6 +125,7 @@ namespace TShockAPI var args = new TileEditEventArgs { Player = ply, + Data = data, X = x, Y = y, Action = action, @@ -2077,7 +2073,7 @@ namespace TShockAPI var style = args.Data.ReadInt8(); - if (OnTileEdit(args.Player, tileX, tileY, action, type, editData, style)) + if (OnTileEdit(args.Player, args.Data, tileX, tileY, action, type, editData, style)) return true; return false; From 62013c75948158cb6bc4f5fe497d4743a89a91b9 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 14:12:41 -0700 Subject: [PATCH 11/45] OnPvpToggled now uses GetDataHandledEventArgs --- TShockAPI/GetDataHandlers.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index cf49df1d..80398dc5 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -139,7 +139,7 @@ namespace TShockAPI /// /// For use in a TogglePvp event /// - public class TogglePvpEventArgs : HandledEventArgs + public class TogglePvpEventArgs : GetDataHandledEventArgs { /// /// The Terraria player ID of the player @@ -154,13 +154,15 @@ namespace TShockAPI /// TogglePvp - called when a player toggles pvp /// public static HandlerList TogglePvp = new HandlerList(); - private static bool OnPvpToggled(byte _id, bool _pvp) + private static bool OnPvpToggled(TSPlayer player, MemoryStream data, byte _id, bool _pvp) { if (TogglePvp == null) return false; var args = new TogglePvpEventArgs { + Player = player, + Data = data, PlayerId = _id, Pvp = _pvp, }; @@ -2178,7 +2180,7 @@ namespace TShockAPI { byte id = args.Data.ReadInt8(); bool pvp = args.Data.ReadBoolean(); - if (OnPvpToggled(id, pvp)) + if (OnPvpToggled(args.Player, args.Data, id, pvp)) return true; if (id != args.Player.Index) From 3f9c0ebbfee80d04c729a0eb34e70fb132c6fa6c Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 14:13:51 -0700 Subject: [PATCH 12/45] OnPlayerTeam now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 80398dc5..c37566e7 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -173,7 +173,7 @@ namespace TShockAPI /// /// For use in a PlayerTeam event /// - public class PlayerTeamEventArgs : HandledEventArgs + public class PlayerTeamEventArgs : GetDataHandledEventArgs { /// /// The Terraria player ID of the player @@ -188,13 +188,15 @@ namespace TShockAPI /// TogglePvp - called when a player toggles pvp /// public static HandlerList PlayerTeam = new HandlerList(); - private static bool OnPlayerTeam(byte _id, byte _team) + private static bool OnPlayerTeam(TSPlayer player, MemoryStream data, byte _id, byte _team) { if (PlayerTeam == null) return false; var args = new PlayerTeamEventArgs { + Player = player, + Data = data, PlayerId = _id, Team = _team, }; @@ -2201,7 +2203,7 @@ namespace TShockAPI { byte id = args.Data.ReadInt8(); byte team = args.Data.ReadInt8(); - if (OnPlayerTeam(id, team)) + if (OnPlayerTeam(args.Player, args.Data, id, team)) return true; if (id != args.Player.Index) From d54af26916bd13b8effa1793145294d36235a1f1 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 14:14:58 -0700 Subject: [PATCH 13/45] OnPlayerSlot now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index c37566e7..e20be739 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -207,7 +207,7 @@ namespace TShockAPI /// /// For use in a PlayerSlot event /// - public class PlayerSlotEventArgs : HandledEventArgs + public class PlayerSlotEventArgs : GetDataHandledEventArgs { /// /// The Terraria playerID @@ -234,13 +234,15 @@ namespace TShockAPI /// PlayerSlot - called at a PlayerSlot event /// public static HandlerList PlayerSlot = new HandlerList(); - private static bool OnPlayerSlot(byte _plr, byte _slot, short _stack, byte _prefix, short _type) + private static bool OnPlayerSlot(TSPlayer player, MemoryStream data, byte _plr, byte _slot, short _stack, byte _prefix, short _type) { if (PlayerSlot == null) return false; var args = new PlayerSlotEventArgs { + Player = player, + Data = data, PlayerId = _plr, Slot = _slot, Stack = _stack, @@ -1603,7 +1605,7 @@ namespace TShockAPI bypassTrashCanCheck = true; } - if (OnPlayerSlot(plr, slot, stack, prefix, type) || plr != args.Player.Index || slot < 0 || + if (OnPlayerSlot(args.Player, args.Data, plr, slot, stack, prefix, type) || plr != args.Player.Index || slot < 0 || slot > NetItem.MaxInventory) return true; if (args.Player.IgnoreSSCPackets) From dbadcc6db0cfed51baa9c2ea639427708199a5c0 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 14:16:43 -0700 Subject: [PATCH 14/45] OnPlayerHP now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index e20be739..09337bc2 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -256,7 +256,7 @@ namespace TShockAPI /// /// For use in a PlayerHP event /// - public class PlayerHPEventArgs : HandledEventArgs + public class PlayerHPEventArgs : GetDataHandledEventArgs { /// /// The Terraria playerID of the player @@ -276,13 +276,15 @@ namespace TShockAPI /// public static HandlerList PlayerHP = new HandlerList(); - private static bool OnPlayerHP(byte _plr, short _cur, short _max) + private static bool OnPlayerHP(TSPlayer player, MemoryStream data, byte _plr, short _cur, short _max) { if (PlayerHP == null) return false; var args = new PlayerHPEventArgs { + Player = player, + Data = data, PlayerId = _plr, Current = _cur, Max = _max, @@ -1645,7 +1647,7 @@ namespace TShockAPI var cur = args.Data.ReadInt16(); var max = args.Data.ReadInt16(); - if (OnPlayerHP(plr, cur, max) || cur <= 0 || max <= 0 || args.Player.IgnoreSSCPackets) + if (OnPlayerHP(args.Player, args.Data, plr, cur, max) || cur <= 0 || max <= 0 || args.Player.IgnoreSSCPackets) return true; if (max > TShock.Config.MaxHP && !args.Player.HasPermission(Permissions.ignorehp)) From c6a5de4398fcd4e9746d38e83722e468dba58243 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 14:17:51 -0700 Subject: [PATCH 15/45] OnPaintTile now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 09337bc2..86ff009b 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2108,7 +2108,7 @@ namespace TShockAPI /// /// For use with a PaintTile event /// - public class PaintTileEventArgs : HandledEventArgs + public class PaintTileEventArgs : GetDataHandledEventArgs { /// /// X Location @@ -2128,13 +2128,15 @@ namespace TShockAPI /// public static HandlerList PaintTile = new HandlerList(); - private static bool OnPaintTile(Int32 x, Int32 y, byte t) + private static bool OnPaintTile(TSPlayer player, MemoryStream data, Int32 x, Int32 y, byte t) { if (PaintTile == null) return false; var args = new PaintTileEventArgs { + Player = player, + Data = data, X = x, Y = y, type = t @@ -2919,7 +2921,7 @@ namespace TShockAPI { return true; } - if (OnPaintTile(x, y, t)) + if (OnPaintTile(args.Player, args.Data, x, y, t)) { return true; } From 8bb3b88ab058c745e971a649019893281ee0f072 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 14:19:44 -0700 Subject: [PATCH 16/45] OnPlaceItemFrame now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 86ff009b..75d70a9c 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -3120,11 +3120,8 @@ namespace TShockAPI } /// The arguments to the PlaceItemFrame event. - public class PlaceItemFrameEventArgs : HandledEventArgs + public class PlaceItemFrameEventArgs : GetDataHandledEventArgs { - /// The TSPlayer that triggered the event. - public TSPlayer Player { get; set; } - /// The X coordinate of the item frame. public short X { get; set; } @@ -3147,7 +3144,7 @@ namespace TShockAPI /// Fired when an ItemFrame is placed. public static HandlerList PlaceItemFrame = new HandlerList(); - private static bool OnPlaceItemFrame(TSPlayer player, short x, short y, short itemID, byte prefix, short stack, TEItemFrame itemFrame) + private static bool OnPlaceItemFrame(TSPlayer player, MemoryStream data, short x, short y, short itemID, byte prefix, short stack, TEItemFrame itemFrame) { if (PlaceItemFrame == null) return false; @@ -3155,6 +3152,7 @@ namespace TShockAPI var args = new PlaceItemFrameEventArgs { Player = player, + Data = data, X = x, Y = y, ItemID = itemID, @@ -3313,7 +3311,7 @@ namespace TShockAPI var stack = args.Data.ReadInt16(); var itemFrame = (TEItemFrame)TileEntity.ByID[TEItemFrame.Find(x, y)]; - if (OnPlaceItemFrame(args.Player, x, y, itemID, prefix, stack, itemFrame)) + if (OnPlaceItemFrame(args.Player, args.Data, x, y, itemID, prefix, stack, itemFrame)) { return true; } From 0efa2fd6487db796f0cd7a9f78ad9bcb62963502 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 14:21:31 -0700 Subject: [PATCH 17/45] OnPlayerMana now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 75d70a9c..7e7324b5 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -296,7 +296,7 @@ namespace TShockAPI /// /// For use in a PlayerMana event /// - public class PlayerManaEventArgs : HandledEventArgs + public class PlayerManaEventArgs : GetDataHandledEventArgs { public byte PlayerId { get; set; } public short Current { get; set; } @@ -307,13 +307,15 @@ namespace TShockAPI /// public static HandlerList PlayerMana = new HandlerList(); - private static bool OnPlayerMana(byte _plr, short _cur, short _max) + private static bool OnPlayerMana(TSPlayer player, MemoryStream data, byte _plr, short _cur, short _max) { if (PlayerMana == null) return false; var args = new PlayerManaEventArgs { + Player = player, + Data = data, PlayerId = _plr, Current = _cur, Max = _max, @@ -1676,7 +1678,7 @@ namespace TShockAPI var cur = args.Data.ReadInt16(); var max = args.Data.ReadInt16(); - if (OnPlayerMana(plr, cur, max) || cur < 0 || max < 0 || args.Player.IgnoreSSCPackets) + if (OnPlayerMana(args.Player, args.Data, plr, cur, max) || cur < 0 || max < 0 || args.Player.IgnoreSSCPackets) return true; if (max > TShock.Config.MaxMP && !args.Player.HasPermission(Permissions.ignoremp)) From e9931e8740d660bccac08e8e1659074d87277dfb Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 14:22:45 -0700 Subject: [PATCH 18/45] OnPlayerInfo now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 7e7324b5..f38de154 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -324,7 +324,7 @@ namespace TShockAPI return args.Handled; } - public class PlayerInfoEventArgs : HandledEventArgs + public class PlayerInfoEventArgs : GetDataHandledEventArgs { /// /// The Terraria playerID of the player @@ -353,13 +353,15 @@ namespace TShockAPI /// public static HandlerList PlayerInfo = new HandlerList(); - private static bool OnPlayerInfo(byte _plrid, byte _hair, int _style, byte _difficulty, string _name) + private static bool OnPlayerInfo(TSPlayer player, MemoryStream data, byte _plrid, byte _hair, int _style, byte _difficulty, string _name) { if (PlayerInfo == null) return false; var args = new PlayerInfoEventArgs { + Player = player, + Data = data, PlayerId = _plrid, Hair = _hair, Style = _style, @@ -1730,7 +1732,7 @@ namespace TShockAPI bool extraSlot = extra[2]; - if (OnPlayerInfo(playerid, hair, skinVariant, difficulty, name)) + if (OnPlayerInfo(args.Player, args.Data, playerid, hair, skinVariant, difficulty, name)) { TShock.Utils.ForceKick(args.Player, "A plugin cancelled the event.", true); return true; From fd7b9858dfee7ffd70f48fa0cb2faab6edb7089f Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 14:24:12 -0700 Subject: [PATCH 19/45] OnPlaceChest now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index f38de154..f2ae168d 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -375,10 +375,8 @@ namespace TShockAPI /// /// For use in a PlaceChest event /// - public class PlaceChestEventArgs : HandledEventArgs + public class PlaceChestEventArgs : GetDataHandledEventArgs { - /// The TSPlayer that triggered the event - public TSPlayer Player { get; set; } /// What the packet is doing (see MP packet docs). public int Flag { get; set; } /// @@ -395,7 +393,7 @@ namespace TShockAPI /// public static HandlerList PlaceChest = new HandlerList(); - private static bool OnPlaceChest(TSPlayer player, int flag, int tilex, int tiley) + private static bool OnPlaceChest(TSPlayer player, MemoryStream data, int flag, int tilex, int tiley) { if (PlaceChest == null) return false; @@ -403,6 +401,7 @@ namespace TShockAPI var args = new PlaceChestEventArgs { Player = player, + Data = data, Flag = flag, TileX = tilex, TileY = tiley, @@ -2496,7 +2495,7 @@ namespace TShockAPI int tileY = args.Data.ReadInt16(); args.Data.ReadInt16(); // Ignore style - if (OnPlaceChest(args.Player, flag, tileX, tileY)) + if (OnPlaceChest(args.Player, args.Data, flag, tileX, tileY)) return true; return false; From 551762f10e1890427e9489199891a7fa6245da19 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 14:25:30 -0700 Subject: [PATCH 20/45] OnProjectileKill now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index f2ae168d..dfa26294 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -411,10 +411,8 @@ namespace TShockAPI } /// The arguments to the ProjectileKill packet. - public class ProjectileKillEventArgs : HandledEventArgs + public class ProjectileKillEventArgs : GetDataHandledEventArgs { - /// The TSPlayer that fired the event. - public TSPlayer Player; /// The projectile's identity...? public int ProjectileIdentity; /// The the player index of the projectile's owner (Main.players). @@ -432,7 +430,7 @@ namespace TShockAPI /// The projectile's owner (from the packet). /// The projectile's index (from Main.projectiles). /// bool - private static bool OnProjectileKill(TSPlayer player, int identity, byte owner, int index) + private static bool OnProjectileKill(TSPlayer player, MemoryStream data, int identity, byte owner, int index) { if (ProjectileKill == null) return false; @@ -440,6 +438,7 @@ namespace TShockAPI var args = new ProjectileKillEventArgs { Player = player, + Data = data, ProjectileIdentity = identity, ProjectileOwner = owner, ProjectileIndex = index, @@ -2405,7 +2404,7 @@ namespace TShockAPI owner = (byte)args.Player.Index; var index = TShock.Utils.SearchProjectile(ident, owner); - if (OnProjectileKill(args.Player, ident, owner, index)) + if (OnProjectileKill(args.Player, args.Data, ident, owner, index)) { return true; } From 0543e0b18fb7262bbb809784256fe9f3b00651db Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 14:27:01 -0700 Subject: [PATCH 21/45] OnGemLockToggle now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index dfa26294..41334bcc 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -3170,10 +3170,8 @@ namespace TShockAPI /// /// For use with a ToggleGemLock event /// - public class GemLockToggleEventArgs : HandledEventArgs + public class GemLockToggleEventArgs : GetDataHandledEventArgs { - /// The TSPlayer that triggered the event. - public TSPlayer Player { get; set; } /// /// X Location /// @@ -3193,13 +3191,15 @@ namespace TShockAPI /// public static HandlerList GemLockToggle = new HandlerList(); - private static bool OnGemLockToggle(short x, short y, bool on) + private static bool OnGemLockToggle(TSPlayer player, MemoryStream data, short x, short y, bool on) { if (GemLockToggle == null) return false; var args = new GemLockToggleEventArgs { + Player = player, + Data = data, X = x, Y = y, On = on @@ -3214,7 +3214,7 @@ namespace TShockAPI var y = args.Data.ReadInt16(); var on = args.Data.ReadBoolean(); - if (OnGemLockToggle(x, y, on)) + if (OnGemLockToggle(args.Player, args.Data, x, y, on)) { return true; } From 649cd453d787202a670542134b4bd8db6660c1ea Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 14:28:09 -0700 Subject: [PATCH 22/45] OnKillMe now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 41334bcc..00a3f02d 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -451,10 +451,8 @@ namespace TShockAPI /// /// For use in a KillMe event /// - public class KillMeEventArgs : HandledEventArgs + public class KillMeEventArgs : GetDataHandledEventArgs { - /// The TSPlayer that triggered the event. - public TSPlayer Player { get; set; } /// /// The Terraria playerID of the player /// @@ -479,7 +477,7 @@ namespace TShockAPI /// public static HandlerList KillMe = new HandlerList(); - private static bool OnKillMe(TSPlayer player, byte plr, byte direction, short damage, bool pvp, PlayerDeathReason playerDeathReason) + private static bool OnKillMe(TSPlayer player, MemoryStream data, byte plr, byte direction, short damage, bool pvp, PlayerDeathReason playerDeathReason) { if (KillMe == null) return false; @@ -487,6 +485,7 @@ namespace TShockAPI var args = new KillMeEventArgs { Player = player, + Data = data, PlayerId = plr, Direction = direction, Damage = damage, @@ -2433,7 +2432,7 @@ namespace TShockAPI BitsByte bits = (BitsByte)args.Data.ReadByte(); bool pvp = bits[0]; - if (OnKillMe(args.Player, id, direction, dmg, pvp, playerDeathReason)) + if (OnKillMe(args.Player, args.Data, id, direction, dmg, pvp, playerDeathReason)) return true; args.Player.Dead = true; From c6c4446021c869ccd52a0c8838cfac04db8c98d8 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 14:29:16 -0700 Subject: [PATCH 23/45] OnPlayerUpdate now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 00a3f02d..b2f08e89 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -499,10 +499,8 @@ namespace TShockAPI /// /// For use in a PlayerUpdate event /// - public class PlayerUpdateEventArgs : HandledEventArgs + public class PlayerUpdateEventArgs : GetDataHandledEventArgs { - /// The TSPlayer object that triggered the event - public TSPlayer Player { get; set; } /// /// The Terraria playerID of the player /// @@ -531,7 +529,7 @@ namespace TShockAPI /// public static HandlerList PlayerUpdate = new HandlerList(); - private static bool OnPlayerUpdate(TSPlayer player, byte plr, byte control, byte item, Vector2 position, Vector2 velocity, byte pulley) + private static bool OnPlayerUpdate(TSPlayer player, MemoryStream data, byte plr, byte control, byte item, Vector2 position, Vector2 velocity, byte pulley) { if (PlayerUpdate == null) return false; @@ -539,6 +537,7 @@ namespace TShockAPI var args = new PlayerUpdateEventArgs { Player = player, + Data = data, PlayerId = plr, Control = control, Item = item, @@ -549,6 +548,7 @@ namespace TShockAPI PlayerUpdate.Invoke(null, args); return args.Handled; } + public static bool TSCheckNoclip(Vector2 Position, int Width, int Height) { int num = (int)(Position.X / 16f); @@ -2242,7 +2242,7 @@ namespace TShockAPI if (pulley[2]) vel = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle()); - if (OnPlayerUpdate(args.Player, plr, control, item, pos, vel, pulley)) + if (OnPlayerUpdate(args.Player, args.Data, plr, control, item, pos, vel, pulley)) return true; if (control[5]) From f0a6ad54a2e643837a21e5d95ea330000b834403 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 14:31:39 -0700 Subject: [PATCH 24/45] OnHealOtherPlayer now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index b2f08e89..560442ed 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -605,11 +605,8 @@ namespace TShockAPI } /// The event args object for the HealOtherPlayer event - public class HealOtherPlayerEventArgs : HandledEventArgs + public class HealOtherPlayerEventArgs : GetDataHandledEventArgs { - /// The TSPlayer object that caused the event - public TSPlayer Player { get; set; } - /// The Terraria player index of the target player public byte TargetPlayerIndex { get; set; } @@ -621,11 +618,10 @@ namespace TShockAPI public static HandlerList HealOtherPlayer = new HandlerList(); /// Fires the HealOtherPlayer event - /// The TSPlayer that started the event /// The Terraria player index that the event targets /// The amount to heal /// bool - private static bool OnHealOtherPlayer(TSPlayer player, byte targetPlayerIndex, short amount) + private static bool OnHealOtherPlayer(TSPlayer player, MemoryStream data, byte targetPlayerIndex, short amount) { if (HealOtherPlayer == null) return false; @@ -633,6 +629,7 @@ namespace TShockAPI var args = new HealOtherPlayerEventArgs { Player = player, + Data = data, TargetPlayerIndex = targetPlayerIndex, Amount = amount, }; @@ -1586,7 +1583,7 @@ namespace TShockAPI byte plr = args.Data.ReadInt8(); short amount = args.Data.ReadInt16(); - if (OnHealOtherPlayer(args.Player, plr, amount)) + if (OnHealOtherPlayer(args.Player, args.Data, plr, amount)) return true; return false; From a3ca7f3d0e8a3e3b89ce6d82156cccef6334a6c2 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 14:32:32 -0700 Subject: [PATCH 25/45] OnSendTileSquare now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 560442ed..90de1c68 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -641,14 +641,8 @@ namespace TShockAPI /// /// For use in a SendTileSquare event /// - public class SendTileSquareEventArgs : HandledEventArgs + public class SendTileSquareEventArgs : GetDataHandledEventArgs { - /// The TSPlayer that triggered the event. - public TSPlayer Player { get; set; } - - /// The raw memory stream from the original event - public MemoryStream Data { get; set; } - /// /// Size of the area /// From 40755192b3058af4db1ec364969429f29b1f27a0 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 14:33:12 -0700 Subject: [PATCH 26/45] OnPlaceObject now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 90de1c68..a7b0e0a0 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -682,7 +682,7 @@ namespace TShockAPI } /// The arguments to the PlaceObject hook. - public class PlaceObjectEventArgs : HandledEventArgs + public class PlaceObjectEventArgs : GetDataHandledEventArgs { /// The calling Player. public TSPlayer Player { get; set; } @@ -718,7 +718,7 @@ namespace TShockAPI /// The object's alternate data. /// The direction of the object. /// bool - private static bool OnPlaceObject(TSPlayer player, short x, short y, short type, short style, byte alternate, bool direction) + private static bool OnPlaceObject(TSPlayer player, MemoryStream data, short x, short y, short type, short style, byte alternate, bool direction) { if (PlaceObject == null) return false; @@ -726,6 +726,7 @@ namespace TShockAPI var args = new PlaceObjectEventArgs { Player = player, + Data = data, X = x, Y = y, Type = type, @@ -2091,7 +2092,7 @@ namespace TShockAPI byte alternate = args.Data.ReadInt8(); bool direction = args.Data.ReadBoolean(); - if (OnPlaceObject(args.Player, x, y, type, style, alternate, direction)) + if (OnPlaceObject(args.Player, args.Data, x, y, type, style, alternate, direction)) return true; return false; From 50104612cf0b90f90b7ed3493299beb12bca3990 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 14:35:32 -0700 Subject: [PATCH 27/45] OnNewProjectile now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index a7b0e0a0..854e2b70 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -743,10 +743,8 @@ namespace TShockAPI /// /// For use in a NewProjectile event /// - public class NewProjectileEventArgs : HandledEventArgs + public class NewProjectileEventArgs : GetDataHandledEventArgs { - /// The TSPlayer that triggered the new projectile. - public TSPlayer Player { get; set; } /// /// ??? /// @@ -785,13 +783,14 @@ namespace TShockAPI /// public static HandlerList NewProjectile = new HandlerList(); - private static bool OnNewProjectile(short ident, Vector2 pos, Vector2 vel, float knockback, short dmg, byte owner, short type, int index, TSPlayer player) + private static bool OnNewProjectile(MemoryStream data, short ident, Vector2 pos, Vector2 vel, float knockback, short dmg, byte owner, short type, int index, TSPlayer player) { if (NewProjectile == null) return false; var args = new NewProjectileEventArgs { + Data = data, Identity = ident, Position = pos, Velocity = vel, @@ -2382,7 +2381,7 @@ namespace TShockAPI var index = TShock.Utils.SearchProjectile(ident, owner); - if (OnNewProjectile(ident, pos, vel, knockback, dmg, owner, type, index, args.Player)) + if (OnNewProjectile(args.Data, ident, pos, vel, knockback, dmg, owner, type, index, args.Player)) return true; return false; From 4c3600f58d1c165e6e70a24ce0818274ed558b5e Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 14:36:28 -0700 Subject: [PATCH 28/45] OnLiquidSet now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 854e2b70..8406e778 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -808,10 +808,8 @@ namespace TShockAPI /// /// For use in a LiquidSet event /// - public class LiquidSetEventArgs : HandledEventArgs + public class LiquidSetEventArgs : GetDataHandledEventArgs { - /// The TSPlayer that triggered the event. - public TSPlayer Player { get; set; } /// /// X location of the tile /// @@ -834,7 +832,7 @@ namespace TShockAPI /// public static HandlerList LiquidSet = new HandlerList(); - private static bool OnLiquidSet(TSPlayer player, int tilex, int tiley, byte amount, byte type) + private static bool OnLiquidSet(TSPlayer player, MemoryStream data, int tilex, int tiley, byte amount, byte type) { if (LiquidSet == null) return false; @@ -842,6 +840,7 @@ namespace TShockAPI var args = new LiquidSetEventArgs { Player = player, + Data = data, TileX = tilex, TileY = tiley, Amount = amount, @@ -2471,7 +2470,7 @@ namespace TShockAPI byte amount = args.Data.ReadInt8(); byte type = args.Data.ReadInt8(); - if (OnLiquidSet(args.Player, tileX, tileY, amount, type)) + if (OnLiquidSet(args.Player, args.Data, tileX, tileY, amount, type)) return true; return false; From df9920564a032096fd062c05e14751c7fe01b040 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 15:06:01 -0700 Subject: [PATCH 29/45] OnPlayerSpawn now uses GetDataHandledEventArgs. OnPlayerSpawn's player ID field is now PlayerID. --- TShockAPI/GetDataHandlers.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 8406e778..a3ac79ae 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -852,12 +852,12 @@ namespace TShockAPI /// /// For use in a PlayerSpawn event /// - public class SpawnEventArgs : HandledEventArgs + public class SpawnEventArgs : GetDataHandledEventArgs { /// /// The Terraria playerID of the player /// - public byte Player { get; set; } + public byte PlayerID { get; set; } /// /// X location of the player's spawn /// @@ -872,7 +872,7 @@ namespace TShockAPI /// public static HandlerList PlayerSpawn = new HandlerList(); - private static bool OnPlayerSpawn(byte player, int spawnX, int spawnY) + private static bool OnPlayerSpawn(TSPlayer player, MemoryStream data, byte pid, int spawnX, int spawnY) { if (PlayerSpawn == null) return false; @@ -880,6 +880,8 @@ namespace TShockAPI var args = new SpawnEventArgs { Player = player, + Data = data, + PlayerID = pid, SpawnX = spawnX, SpawnY = spawnY, }; @@ -2495,7 +2497,7 @@ namespace TShockAPI var spawnx = args.Data.ReadInt16(); var spawny = args.Data.ReadInt16(); - if (OnPlayerSpawn(player, spawnx, spawny)) + if (OnPlayerSpawn(args.Player, args.Data, player, spawnx, spawny)) return true; if (args.Player.InitSpawn && args.TPlayer.inventory[args.TPlayer.selectedItem].type != 50) From 1d0d4750e227c0094bc67d6ff988272c6b283f11 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 15:09:43 -0700 Subject: [PATCH 30/45] OnChestOpen now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index a3ac79ae..ad079ebe 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -891,7 +891,7 @@ namespace TShockAPI /// /// For use with a ChestOpen event /// - public class ChestOpenEventArgs : HandledEventArgs + public class ChestOpenEventArgs : GetDataHandledEventArgs { /// /// X location of said chest @@ -901,24 +901,20 @@ namespace TShockAPI /// Y location of said chest /// public int Y { get; set; } - - /// - /// The player opening the chest - /// - public TSPlayer Player { get; set; } } /// /// ChestOpen - Called when any chest is opened /// public static HandlerList ChestOpen = new HandlerList(); - private static bool OnChestOpen(int x, int y, TSPlayer player) + private static bool OnChestOpen(MemoryStream data, int x, int y, TSPlayer player) { if (ChestOpen == null) return false; var args = new ChestOpenEventArgs { + Data = data, X = x, Y = y, Player = player, @@ -2547,7 +2543,7 @@ namespace TShockAPI var x = args.Data.ReadInt16(); var y = args.Data.ReadInt16(); - if (OnChestOpen(x, y, args.Player)) + if (OnChestOpen(args.Data, x, y, args.Player)) return true; return false; From 3b25043d117b7a9c62d52873ff010eb8370badf2 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 15:10:32 -0700 Subject: [PATCH 31/45] OnChestItem now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index ad079ebe..3f3c5470 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -926,10 +926,8 @@ namespace TShockAPI /// /// For use in a ChestItemChange event /// - public class ChestItemEventArgs : HandledEventArgs + public class ChestItemEventArgs : GetDataHandledEventArgs { - /// The TSPlayer that triggered the event. - public TSPlayer Player { get; set; } /// /// ChestID /// @@ -956,7 +954,7 @@ namespace TShockAPI /// public static HandlerList ChestItemChange = new HandlerList(); - private static bool OnChestItemChange(TSPlayer player, short id, byte slot, short stacks, byte prefix, short type) + private static bool OnChestItemChange(TSPlayer player, MemoryStream data, short id, byte slot, short stacks, byte prefix, short type) { if (ChestItemChange == null) return false; @@ -964,6 +962,7 @@ namespace TShockAPI var args = new ChestItemEventArgs { Player = player, + Data = data, ID = id, Slot = slot, Stacks = stacks, @@ -2582,7 +2581,7 @@ namespace TShockAPI var prefix = args.Data.ReadInt8(); var type = args.Data.ReadInt16(); - if (OnChestItemChange(args.Player, id, slot, stacks, prefix, type)) + if (OnChestItemChange(args.Player, args.Data, id, slot, stacks, prefix, type)) return true; Item item = new Item(); From 82a749c24d3b664b3526682edfa39a154ce8ab8e Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 15:17:29 -0700 Subject: [PATCH 32/45] OnSignEvent now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 3f3c5470..8864c966 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -976,7 +976,7 @@ namespace TShockAPI /// /// For use in a Sign event /// - public class SignEventArgs : HandledEventArgs + public class SignEventArgs : GetDataHandledEventArgs { /// /// The Terraria playerID of the player @@ -996,13 +996,15 @@ namespace TShockAPI /// public static HandlerList Sign = new HandlerList(); - private static bool OnSignEvent(short id, int x, int y) + private static bool OnSignEvent(TSPlayer player, MemoryStream data, short id, int x, int y) { if (Sign == null) return false; var args = new SignEventArgs { + Player = player, + Data = data, ID = id, X = x, Y = y, @@ -2601,7 +2603,7 @@ namespace TShockAPI var y = args.Data.ReadInt16(); args.Data.ReadString(); // Ignore sign text - if (OnSignEvent(id, x, y)) + if (OnSignEvent(args.Player, args.Data, id, x, y)) return true; if (TShock.CheckTilePermission(args.Player, x, y)) From ed1a04b38b412003727ae0501d2752d08b713bae Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 15:20:35 -0700 Subject: [PATCH 33/45] OnUpdateNPCHome now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 8864c966..628fa4e4 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -1016,10 +1016,8 @@ namespace TShockAPI /// /// For use in a NPCHome event /// - public class NPCHomeChangeEventArgs : HandledEventArgs + public class NPCHomeChangeEventArgs : GetDataHandledEventArgs { - /// The TSPlayer that caused the event. - public TSPlayer Player { get; set; } /// /// The Terraria playerID of the player /// @@ -1042,7 +1040,7 @@ namespace TShockAPI /// public static HandlerList NPCHome = new HandlerList(); - private static bool OnUpdateNPCHome(TSPlayer player, short id, short x, short y, byte homeless) + private static bool OnUpdateNPCHome(TSPlayer player, MemoryStream data, short id, short x, short y, byte homeless) { if (NPCHome == null) return false; @@ -1050,6 +1048,7 @@ namespace TShockAPI var args = new NPCHomeChangeEventArgs { Player = player, + Data = data, ID = id, X = x, Y = y, @@ -2627,7 +2626,7 @@ namespace TShockAPI var y = args.Data.ReadInt16(); var homeless = args.Data.ReadInt8(); - if (OnUpdateNPCHome(args.Player, id, x, y, homeless)) + if (OnUpdateNPCHome(args.Player, args.Data, id, x, y, homeless)) return true; if (!args.Player.HasPermission(Permissions.movenpc)) From 5d4a4f706782950e3f3dab4dfb503a46f38be9b6 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 15:21:36 -0700 Subject: [PATCH 34/45] OnPlayerBuff now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 628fa4e4..0ab947fd 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -1061,9 +1061,8 @@ namespace TShockAPI /// /// For use in a PlayerBuff event /// - public class PlayerBuffEventArgs : HandledEventArgs + public class PlayerBuffEventArgs : GetDataHandledEventArgs { - public TSPlayer Player { get; set; } /// /// The Terraria playerID of the player /// @@ -1082,7 +1081,7 @@ namespace TShockAPI /// public static HandlerList PlayerBuff = new HandlerList(); - private static bool OnPlayerBuff(TSPlayer player, byte id, byte type, int time) + private static bool OnPlayerBuff(TSPlayer player, MemoryStream data, byte id, byte type, int time) { if (PlayerBuff == null) return false; @@ -1090,6 +1089,7 @@ namespace TShockAPI var args = new PlayerBuffEventArgs { Player = player, + Data = data, ID = id, Type = type, Time = time @@ -2645,7 +2645,7 @@ namespace TShockAPI var type = args.Data.ReadInt8(); var time = args.Data.ReadInt32(); - if (OnPlayerBuff(args.Player, id, type, time)) + if (OnPlayerBuff(args.Player, args.Data, id, type, time)) return true; args.Player.SendData(PacketTypes.PlayerAddBuff, "", id); From d0efdc393984f1fc3766bbdbcd404486aadeedb1 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 15:22:29 -0700 Subject: [PATCH 35/45] OnItemDrop now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 0ab947fd..54715e9b 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -1101,12 +1101,8 @@ namespace TShockAPI /// /// For use in an ItemDrop event /// - public class ItemDropEventArgs : HandledEventArgs + public class ItemDropEventArgs : GetDataHandledEventArgs { - /// - /// The player who sent message - /// - public TSPlayer Player { get; set; } /// /// ID of the item. /// If below 400 and NetID(Type) is 0 Then Set Null. If ItemID is 400 Then New Item @@ -1142,7 +1138,7 @@ namespace TShockAPI /// public static HandlerList ItemDrop = new HandlerList(); - private static bool OnItemDrop(TSPlayer player, short id, Vector2 pos, Vector2 vel, short stacks, byte prefix, bool noDelay, short type) + private static bool OnItemDrop(TSPlayer player, MemoryStream data, short id, Vector2 pos, Vector2 vel, short stacks, byte prefix, bool noDelay, short type) { if (ItemDrop == null) return false; @@ -1150,6 +1146,7 @@ namespace TShockAPI var args = new ItemDropEventArgs { Player = player, + Data = data, ID = id, Position = pos, Velocity = vel, @@ -2662,7 +2659,7 @@ namespace TShockAPI var noDelay = args.Data.ReadInt8() == 1; var type = args.Data.ReadInt16(); - if (OnItemDrop(args.Player, id, pos, vel, stacks, prefix, noDelay, type)) + if (OnItemDrop(args.Player, args.Data, id, pos, vel, stacks, prefix, noDelay, type)) return true; return false; From 45c81e960aca9b853114a59568baf8251318c9b0 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 15:23:26 -0700 Subject: [PATCH 36/45] OnPlayerDamage now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 54715e9b..8a0081b2 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -1162,9 +1162,8 @@ namespace TShockAPI /// /// For use in a PlayerDamage event /// - public class PlayerDamageEventArgs : HandledEventArgs + public class PlayerDamageEventArgs : GetDataHandledEventArgs { - public TSPlayer Player { get; set; } /// /// The Terraria playerID of the player /// @@ -1193,7 +1192,7 @@ namespace TShockAPI /// public static HandlerList PlayerDamage = new HandlerList(); - private static bool OnPlayerDamage(TSPlayer player, byte id, byte dir, short dmg, bool pvp, bool crit, PlayerDeathReason playerDeathReason) + private static bool OnPlayerDamage(TSPlayer player, MemoryStream data, byte id, byte dir, short dmg, bool pvp, bool crit, PlayerDeathReason playerDeathReason) { if (PlayerDamage == null) return false; @@ -1201,6 +1200,7 @@ namespace TShockAPI var args = new PlayerDamageEventArgs { Player = player, + Data = data, ID = id, Direction = dir, Damage = dmg, @@ -2692,7 +2692,7 @@ namespace TShockAPI var crit = bits[0]; var pvp = bits[1]; - if (OnPlayerDamage(args.Player, id, direction, dmg, pvp, crit, playerDeathReason)) + if (OnPlayerDamage(args.Player, args.Data, id, direction, dmg, pvp, crit, playerDeathReason)) return true; if (TShock.Players[id].GodMode) From 61d1bcf93f619864543d3c91d0f4d2a56aea41cc Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 15:24:56 -0700 Subject: [PATCH 37/45] OnNPCStrike now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 8a0081b2..f457af5d 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -1215,10 +1215,8 @@ namespace TShockAPI /// /// For use with a NPCStrike event /// - public class NPCStrikeEventArgs : HandledEventArgs + public class NPCStrikeEventArgs : GetDataHandledEventArgs { - /// The TSPlayer that triggered the event. - public TSPlayer Player { get; set; } /// /// ??? /// @@ -1245,7 +1243,7 @@ namespace TShockAPI /// public static HandlerList NPCStrike = new HandlerList(); - private static bool OnNPCStrike(TSPlayer player, short id, byte dir, short dmg, float knockback, byte crit) + private static bool OnNPCStrike(TSPlayer player, MemoryStream data, short id, byte dir, short dmg, float knockback, byte crit) { if (NPCStrike == null) return false; @@ -1253,6 +1251,7 @@ namespace TShockAPI var args = new NPCStrikeEventArgs { Player = player, + Data = data, ID = id, Direction = dir, Damage = dmg, @@ -2711,7 +2710,7 @@ namespace TShockAPI var direction = (byte)(args.Data.ReadInt8() - 1); var crit = args.Data.ReadInt8(); - if (OnNPCStrike(args.Player, id, direction, dmg, knockback, crit)) + if (OnNPCStrike(args.Player, args.Data, id, direction, dmg, knockback, crit)) return true; if (Main.npc[id].townNPC && !args.Player.HasPermission(Permissions.hurttownnpc)) From 16654cafc42dc05deeec2fa31765c3580e30d1ec Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 15:27:00 -0700 Subject: [PATCH 38/45] OnMassWireOperation now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index f457af5d..7c1c64d5 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -1263,11 +1263,8 @@ namespace TShockAPI } /// The arguments to the MassWireOperation event. - public class MassWireOperationEventArgs : HandledEventArgs + public class MassWireOperationEventArgs : GetDataHandledEventArgs { - /// The TSPlayer that triggered the event. - public TSPlayer Player { get; set; } - /// The start X point in the operation. public short StartX { get; set; } @@ -1287,7 +1284,7 @@ namespace TShockAPI /// Fired on a mass wire edit operation. public static HandlerList MassWireOperation = new HandlerList(); - private static bool OnMassWireOperation(TSPlayer player, short startX, short startY, short endX, short endY, byte toolMode) + private static bool OnMassWireOperation(TSPlayer player, MemoryStream data, short startX, short startY, short endX, short endY, byte toolMode) { if (MassWireOperation == null) return false; @@ -1295,6 +1292,7 @@ namespace TShockAPI var args = new MassWireOperationEventArgs { Player = player, + Data = data, StartX = startX, StartY = startY, EndX = endX, @@ -3098,7 +3096,7 @@ namespace TShockAPI short endY = args.Data.ReadInt16(); byte toolMode = (byte) args.Data.ReadByte(); - if (OnMassWireOperation(args.Player, startX, startY, endX, endY, toolMode)) + if (OnMassWireOperation(args.Player, args.Data, startX, startY, endX, endY, toolMode)) return true; return false; From 8413343cbdb0a3a9d3a49bfb112363a0f2559993 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 15:28:27 -0700 Subject: [PATCH 39/45] OnPlaceTileEntity now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 7c1c64d5..1d00fa89 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -1305,11 +1305,8 @@ namespace TShockAPI } /// For use in a PlaceTileEntity event. - public class PlaceTileEntityEventArgs : HandledEventArgs + public class PlaceTileEntityEventArgs : GetDataHandledEventArgs { - /// The TSPlayer that triggered the event. - public TSPlayer Player { get; set; } - /// The X coordinate of the event. public short X { get; set; } @@ -1323,7 +1320,7 @@ namespace TShockAPI /// Fired when a PlaceTileEntity event occurs. public static HandlerList PlaceTileEntity = new HandlerList(); - private static bool OnPlaceTileEntity(TSPlayer player, short x, short y, byte type) + private static bool OnPlaceTileEntity(TSPlayer player, MemoryStream data, short x, short y, byte type) { if (PlaceTileEntity == null) return false; @@ -1331,6 +1328,7 @@ namespace TShockAPI var args = new PlaceTileEntityEventArgs { Player = player, + Data = data, X = x, Y = y, Type = type @@ -3268,7 +3266,7 @@ namespace TShockAPI var y = args.Data.ReadInt16(); var type = (byte) args.Data.ReadByte(); - if (OnPlaceTileEntity(args.Player, x, y, type)) + if (OnPlaceTileEntity(args.Player, args.Data, x, y, type)) { return true; } From c607ecfe27cdd4d8f726becc3275e77fda917649 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 15:31:20 -0700 Subject: [PATCH 40/45] OnNPCSpecial now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 1d00fa89..e14573d7 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -1341,7 +1341,7 @@ namespace TShockAPI /// /// For use with a NPCSpecial event /// - public class NPCSpecialEventArgs : HandledEventArgs + public class NPCSpecialEventArgs : GetDataHandledEventArgs { /// /// ??? @@ -1357,13 +1357,15 @@ namespace TShockAPI /// public static HandlerList NPCSpecial = new HandlerList(); - private static bool OnNPCSpecial(byte id, byte type) + private static bool OnNPCSpecial(TSPlayer player, MemoryStream data, byte id, byte type) { if (NPCSpecial == null) return false; var args = new NPCSpecialEventArgs { + Player = player, + Data = data, ID = id, Type = type, }; @@ -2724,7 +2726,7 @@ namespace TShockAPI var id = args.Data.ReadInt8(); var type = args.Data.ReadInt8(); - if (OnNPCSpecial(id, type)) + if (OnNPCSpecial(args.Player, args.Data, id, type)) return true; if (type == 1 && TShock.Config.DisableDungeonGuardian) From cd07aaf62c58ad2a47e80291c309c9b20575b1e1 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 15:32:57 -0700 Subject: [PATCH 41/45] OnPlayerAnimation now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index e14573d7..807ce0dd 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -1376,18 +1376,14 @@ namespace TShockAPI /// /// For use with a PlayerAnimation event /// - public class PlayerAnimationEventArgs : HandledEventArgs - { - /// The TSPlayer that triggered the event. - public TSPlayer Player { get; set; } - } + public class PlayerAnimationEventArgs : GetDataHandledEventArgs { } /// /// PlayerAnimation - Called when a player animates /// public static HandlerList PlayerAnimation = new HandlerList(); - private static bool OnPlayerAnimation(TSPlayer player) + private static bool OnPlayerAnimation(TSPlayer player, MemoryStream data) { if (PlayerAnimation == null) return false; @@ -1395,6 +1391,7 @@ namespace TShockAPI var args = new PlayerAnimationEventArgs { Player = player, + Data = data, }; PlayerAnimation.Invoke(null, args); return args.Handled; @@ -2747,7 +2744,7 @@ namespace TShockAPI private static bool HandlePlayerAnimation(GetDataHandlerArgs args) { - if (OnPlayerAnimation(args.Player)) + if (OnPlayerAnimation(args.Player, args.Data)) return true; return false; From 1ff2d6566b4b08e13a52118e12fa04cf0932efcf Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 15:34:28 -0700 Subject: [PATCH 42/45] OnPlayerBuffUpdate now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 807ce0dd..87438810 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -1400,7 +1400,7 @@ namespace TShockAPI /// /// For use in a PlayerBuffUpdate event /// - public class PlayerBuffUpdateEventArgs : HandledEventArgs + public class PlayerBuffUpdateEventArgs : GetDataHandledEventArgs { /// /// The Terraria playerID of the player @@ -1412,13 +1412,15 @@ namespace TShockAPI /// public static HandlerList PlayerBuffUpdate = new HandlerList(); - private static bool OnPlayerBuffUpdate(byte id) + private static bool OnPlayerBuffUpdate(TSPlayer player, MemoryStream data, byte id) { if (PlayerBuffUpdate == null) return false; var args = new PlayerBuffUpdateEventArgs { + Player = player, + Data = data, ID = id, }; PlayerBuffUpdate.Invoke(null, args); @@ -2754,7 +2756,7 @@ namespace TShockAPI { var id = args.Data.ReadInt8(); - if (OnPlayerBuffUpdate(id)) + if (OnPlayerBuffUpdate(args.Player, args.Data, id)) return true; for (int i = 0; i < Terraria.Player.maxBuffs; i++) From 6814aabf6e8ca20f032cefa9c980a6ffd7186799 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 15:35:38 -0700 Subject: [PATCH 43/45] OnTeleport now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 87438810..f1155b13 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -1430,7 +1430,7 @@ namespace TShockAPI /// /// For use with a NPCStrike event /// - public class TeleportEventArgs : HandledEventArgs + public class TeleportEventArgs : GetDataHandledEventArgs { /// /// ??? @@ -1458,13 +1458,15 @@ namespace TShockAPI /// public static HandlerList Teleport = new HandlerList(); - private static bool OnTeleport(Int16 id, byte f, float x, float y) + private static bool OnTeleport(TSPlayer player, MemoryStream data, Int16 id, byte f, float x, float y) { if (Teleport == null) return false; var args = new TeleportEventArgs { + Player = player, + Data = data, ID = id, Flag = f, X = x, @@ -2988,7 +2990,7 @@ namespace TShockAPI var x = args.Data.ReadSingle(); var y = args.Data.ReadSingle(); - if (OnTeleport(id, flag, x, y)) + if (OnTeleport(args.Player, args.Data, id, flag, x, y)) return true; int type = 0; From ad83c393002892ed864604c43a6a625e60d78765 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 15:40:14 -0700 Subject: [PATCH 44/45] OnPaintWall now uses GetDataHandledEventArgs. --- TShockAPI/GetDataHandlers.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index f1155b13..86076fad 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2133,7 +2133,7 @@ namespace TShockAPI /// /// For use with a PaintWall event /// - public class PaintWallEventArgs : HandledEventArgs + public class PaintWallEventArgs : GetDataHandledEventArgs { /// /// X Location @@ -2153,13 +2153,15 @@ namespace TShockAPI /// public static HandlerList PaintWall = new HandlerList(); - private static bool OnPaintWall(Int32 x, Int32 y, byte t) + private static bool OnPaintWall(TSPlayer player, MemoryStream data, Int32 x, Int32 y, byte t) { if (PaintWall == null) return false; var args = new PaintWallEventArgs { + Player = player, + Data = data, X = x, Y = y, type = t @@ -2949,7 +2951,7 @@ namespace TShockAPI { return true; } - if (OnPaintWall(x, y, t)) + if (OnPaintWall(args.Player, args.Data, x, y, t)) { return true; } From 6b6cce3640539a3e6e7e35c5cf64ef6ad020b786 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 15:49:51 -0700 Subject: [PATCH 45/45] Patch docs, fix warnings, update changelog --- CHANGELOG.md | 1 + TShockAPI/GetDataHandlers.cs | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebac456e..5a4e2b5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Fix message requiring login not using the command specifier set in the config file. (@hakusaro) * Move `TShock.CheckSpawn` to `Utils.IsInSpawn`. (@hakusaro) * Fix stack hack detection being inconsistent between two different check points. Moved `TShock.HackedInventory` to `TSPlayer.HasHackedItemStacks`. Added `GetDataHandlers.GetDataHandledEventArgs` which is where most hooks will inherit from in the future. (@hakusaro) +* All `GetDataHandlers` hooks now inherit from `GetDataHandledEventArgs` which includes a `TSPlayer` and a `MemoryStream` of raw data. (@hakusaro) ## TShock 4.3.25 * Fixed a critical exploit in the Terraria protocol that could cause massive unpreventable world corruption as well as a number of other problems. Thanks to @bartico6 for reporting. Fixed by the efforts of @QuiCM, @hakusaro, and tips in the right directioon from @bartico6. diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 86076fad..627c0e49 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -426,6 +426,7 @@ namespace TShockAPI /// Fires the ProjectileKill event. /// The TSPlayer that caused the event. + /// The MemoryStream containing the raw event data. /// The projectile identity (from the packet). /// The projectile's owner (from the packet). /// The projectile's index (from Main.projectiles). @@ -618,6 +619,8 @@ namespace TShockAPI public static HandlerList HealOtherPlayer = new HandlerList(); /// Fires the HealOtherPlayer event + /// The TSPlayer that caused the event. + /// The MemoryStream containing the raw event data. /// The Terraria player index that the event targets /// The amount to heal /// bool @@ -684,9 +687,6 @@ namespace TShockAPI /// The arguments to the PlaceObject hook. public class PlaceObjectEventArgs : GetDataHandledEventArgs { - /// The calling Player. - public TSPlayer Player { get; set; } - /// The X location where the object was placed. public short X { get; set ; } @@ -710,7 +710,8 @@ namespace TShockAPI public static HandlerList PlaceObject = new HandlerList(); /// Fires the PlaceObject hook. To be called when an object is placed in the world. - /// The originating player. + /// The TSPlayer that caused the event. + /// The MemoryStream containing the raw event data. /// The x position where the object is placed. /// The y position where the object is placed. /// The type of object.