From 301125b2d81bf3a917fb4f740aaea297c68ad1c5 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 23 Dec 2017 14:11:47 -0700 Subject: [PATCH 01/36] 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 02/36] 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 03/36] 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 04/36] 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 05/36] 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 06/36] 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 07/36] 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 08/36] 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 09/36] 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 10/36] 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 11/36] 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 12/36] 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 13/36] 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 14/36] 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 15/36] 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 16/36] 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 17/36] 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 18/36] 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 19/36] 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 20/36] 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 21/36] 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 22/36] 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 23/36] 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 24/36] 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 25/36] 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 26/36] 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 27/36] 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 28/36] 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 29/36] 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 30/36] 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 31/36] 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 32/36] 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 33/36] 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 34/36] 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 35/36] 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 36/36] 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.