diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 511c5820..60dbecc8 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -98,7 +98,7 @@ namespace TShockAPI { byte plr = args.PlayerId; BitsByte control = args.Control; - BitsByte pulley = args.Pulley; + BitsByte pulley = args.MiscData1; byte item = args.SelectedItem ; var pos = args.Position; var vel = args.Velocity; diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index a1fc937d..bdc49a63 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -36,6 +36,8 @@ using Terraria.Localization; using Microsoft.Xna.Framework; using OTAPI.Tile; using TShockAPI.Localization; +using TShockAPI.Models; +using TShockAPI.Models.PlayerUpdate; namespace TShockAPI { @@ -305,19 +307,19 @@ namespace TShockAPI /// /// Control direction (BitFlags) /// - public byte Control { get; set; } + public ControlSet Control { get; set; } /// - /// Pulley update (BitFlags) + /// Misc Data Set 1 /// - public byte Pulley { get; set; } + public MiscDataSet1 MiscData1 { get; set; } /// - /// Misc (BitFlags) Check tshock.readme.io + /// Misc Data Set 2 /// - public byte Misc { get; set; } + public MiscDataSet2 MiscData2 { get; set; } /// - /// (BitFlags) Wether or not the player is sleeping. + /// Misc Data Set 3 /// - public byte Sleeping { get; set; } + public MiscDataSet3 MiscData3 { get; set; } /// /// The selected item in player's hand. /// @@ -344,7 +346,19 @@ namespace TShockAPI /// PlayerUpdate - When the player sends it's updated information to the server /// public static HandlerList PlayerUpdate = new HandlerList(); - private static bool OnPlayerUpdate(TSPlayer player, MemoryStream data, byte plr, byte control, byte pulley, byte misc, byte sleeping, byte selectedItem, Vector2 position, Vector2 velocity, Vector2? originalPos, Vector2? homePos) + private static bool OnPlayerUpdate( + TSPlayer player, + MemoryStream data, + byte plr, + ControlSet control, + MiscDataSet1 miscData1, + MiscDataSet2 miscData2, + MiscDataSet3 miscData3, + byte selectedItem, + Vector2 position, + Vector2 velocity, + Vector2? originalPos, + Vector2? homePos) { if (PlayerUpdate == null) return false; @@ -355,9 +369,9 @@ namespace TShockAPI Data = data, PlayerId = plr, Control = control, - Pulley = pulley, - Misc = misc, - Sleeping = sleeping, + MiscData1 = miscData1, + MiscData2 = miscData2, + MiscData3 = miscData3, SelectedItem = selectedItem, Position = position, Velocity = velocity, @@ -1956,7 +1970,7 @@ namespace TShockAPI private static bool HandleConnecting(GetDataHandlerArgs args) { - var account = TShock.UserAccounts.GetUserAccountByName(args.Player.Name); + var account = TShock.UserAccounts.GetUserAccountByName(args.Player.Name);// args.Player.DataWhenJoined = new PlayerData(args.Player); args.Player.DataWhenJoined.CopyCharacter(args.Player); args.Player.PlayerData = new PlayerData(args.Player); @@ -2080,29 +2094,29 @@ namespace TShockAPI } byte playerID = args.Data.ReadInt8(); - BitsByte control = (BitsByte)args.Data.ReadByte(); - BitsByte pulley = (BitsByte)args.Data.ReadByte(); - BitsByte misc = (BitsByte)args.Data.ReadByte(); - BitsByte sleeping = (BitsByte)args.Data.ReadByte(); + ControlSet controls = new ControlSet((BitsByte)args.Data.ReadByte()); + MiscDataSet1 miscData1 = new MiscDataSet1((BitsByte)args.Data.ReadByte()); + MiscDataSet2 miscData2 = new MiscDataSet2((BitsByte)args.Data.ReadByte()); + MiscDataSet3 miscData3 = new MiscDataSet3((BitsByte)args.Data.ReadByte()); byte selectedItem = args.Data.ReadInt8(); Vector2 position = args.Data.ReadVector2(); Vector2 velocity = Vector2.Zero; - if (pulley[2]) // if UpdateVelocity + if (miscData1.HasVelocity) velocity = args.Data.ReadVector2(); Vector2? originalPosition = new Vector2?(); Vector2? homePosition = Vector2.Zero; - if (misc[6]) // if UsedPotionofReturn + if (miscData2.CanReturnWithPotionOfReturn) { originalPosition = new Vector2?(args.Data.ReadVector2()); homePosition = new Vector2?(args.Data.ReadVector2()); } - if (OnPlayerUpdate(args.Player, args.Data, playerID, control, pulley, misc, sleeping, selectedItem, position, velocity, originalPosition, homePosition)) + if (OnPlayerUpdate(args.Player, args.Data, playerID, controls, miscData1, miscData2, miscData3, selectedItem, position, velocity, originalPosition, homePosition)) return true; - if (control[5]) + if (controls.IsUsingItem) { // Reimplementation of normal Terraria stuff? if (args.TPlayer.inventory[selectedItem].Name == "Mana Crystal" && args.Player.TPlayer.statManaMax <= 180) @@ -2137,45 +2151,45 @@ namespace TShockAPI args.TPlayer.controlRight = false; args.TPlayer.controlJump = false; args.TPlayer.controlUseItem = false; - args.TPlayer.pulley = pulley[0]; + args.TPlayer.pulley = miscData1.IsUsingPulley; - if (pulley[0]) - args.TPlayer.pulleyDir = (byte)(pulley[1] ? 2 : 1); + if (miscData1.IsUsingPulley) + args.TPlayer.pulleyDir = (byte)(miscData1.PulleyDirection ? 2 : 1); - if (pulley[3]) + if (miscData1.IsVortexStealthActive) args.TPlayer.vortexStealthActive = true; else args.TPlayer.vortexStealthActive = false; - args.TPlayer.gravDir = pulley[4] ? 1f : -1f; + args.TPlayer.gravDir = miscData1.GravityDirection ? 1f : -1f; args.TPlayer.direction = -1; - if (control[0]) + if (controls.MoveUp) { args.TPlayer.controlUp = true; } - if (control[1]) + if (controls.MoveDown) { args.TPlayer.controlDown = true; } - if (control[2]) + if (controls.MoveLeft) { args.TPlayer.controlLeft = true; } - if (control[3]) + if (controls.MoveRight) { args.TPlayer.controlRight = true; } - if (control[4]) + if (controls.Jump) { args.TPlayer.controlJump = true; } - if (control[5]) + if (controls.IsUsingItem) { args.TPlayer.controlUseItem = true; } - if (control[6]) + if (controls.FaceDirection) { args.TPlayer.direction = 1; } diff --git a/TShockAPI/Models/PlayerUpdate/ControlSet.cs b/TShockAPI/Models/PlayerUpdate/ControlSet.cs new file mode 100644 index 00000000..ac963217 --- /dev/null +++ b/TShockAPI/Models/PlayerUpdate/ControlSet.cs @@ -0,0 +1,88 @@ +using Terraria; + +namespace TShockAPI.Models.PlayerUpdate +{ + + /// + /// Model for a control event sent with a player update packet + /// + public struct ControlSet + { + /// + /// Backing BitsByte field + /// + public BitsByte bitsbyte; + + /// + /// Gets or Sets the Up flag on the backing field + /// + public bool MoveUp + { + get => bitsbyte[0]; + set => bitsbyte[0] = value; + } + + /// + /// Gets or Sets the Down flag on the backing field + /// + public bool MoveDown + { + get => bitsbyte[1]; + set => bitsbyte[1] = value; + } + + /// + /// Gets or Sets the Left flag on the backing field + /// + public bool MoveLeft + { + get => bitsbyte[2]; + set => bitsbyte[2] = value; + } + + /// + /// Gets or Sets the Right flag on the backing field + /// + public bool MoveRight + { + get => bitsbyte[3]; + set => bitsbyte[3] = value; + } + + /// + /// Gets or Sets the Jump flag on the backing field + /// + public bool Jump + { + get => bitsbyte[4]; + set => bitsbyte[4] = value; + } + + /// + /// Gets or Sets the ControlUseItem flag on the backing field + /// + public bool IsUsingItem + { + get => bitsbyte[5]; + set => bitsbyte[5] = value; + } + + /// + /// Gets or Sets the Direction flag on the backing field. True = 1, false = -1 + /// + public bool FaceDirection + { + get => bitsbyte[6]; + set => bitsbyte[6] = value; + } + + /// + /// Constructs a new instance of ControlsModel with the given backing bitsbyte + /// + /// + public ControlSet(BitsByte bitsbyte) + { + this.bitsbyte = bitsbyte; + } + } +} diff --git a/TShockAPI/Models/PlayerUpdate/MiscDataSet1.cs b/TShockAPI/Models/PlayerUpdate/MiscDataSet1.cs new file mode 100644 index 00000000..480353a1 --- /dev/null +++ b/TShockAPI/Models/PlayerUpdate/MiscDataSet1.cs @@ -0,0 +1,87 @@ +using Terraria; + +namespace TShockAPI.Models.PlayerUpdate +{ + /// + /// Model for the first set of misc data sent with a player update packet + /// + public struct MiscDataSet1 + { + /// + /// Backing BitsByte field + /// + public BitsByte bitsbyte; + + /// + /// Gets or Sets the Pulley flag on the backing field + /// + public bool IsUsingPulley + { + get => bitsbyte[0]; + set => bitsbyte[0] = value; + } + + /// + /// Gets or Sets the Pulley Direction flag on the backing field. True = 2, false = 1 + /// + public bool PulleyDirection + { + get => bitsbyte[1]; + set => bitsbyte[1] = value; + } + + /// + /// Gets or Sets the Velocity > 0 flag on the backing field + /// + public bool HasVelocity + { + get => bitsbyte[2]; + set => bitsbyte[2] = value; + } + + /// + /// Gets or Sets the Vortex Stealth flag on the backing field + /// + public bool IsVortexStealthActive + { + get => bitsbyte[3]; + set => bitsbyte[3] = value; + } + + /// + /// Gets or Sets the Gravity Direction flag on the backing field. True = 1, False = -1 + /// + public bool GravityDirection + { + get => bitsbyte[4]; + set => bitsbyte[4] = value; + } + + /// + /// Gets or Sets the Shield Raised flag on the backing field + /// + public bool IsShieldRaised + { + get => bitsbyte[5]; + set => bitsbyte[5] = value; + } + + /// + /// Gets or Sets the Ghost flag on the backing field + /// + public bool IsGhosted + { + get => bitsbyte[6]; + set => bitsbyte[6] = value; + } + + /// + /// Constructs a new instance of MiscDataSet1 with the given backing BitsByte + /// + /// + public MiscDataSet1(BitsByte bitsbyte) + { + this.bitsbyte = bitsbyte; + } + } +} diff --git a/TShockAPI/Models/PlayerUpdate/MiscDataSet2.cs b/TShockAPI/Models/PlayerUpdate/MiscDataSet2.cs new file mode 100644 index 00000000..9a5f3819 --- /dev/null +++ b/TShockAPI/Models/PlayerUpdate/MiscDataSet2.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Terraria; + +namespace TShockAPI.Models.PlayerUpdate +{ + /// + /// Model for the second set of misc data sent with a player update packet + /// + public struct MiscDataSet2 + { + /// + /// Backing BitsByte field + /// + public BitsByte bitsbyte; + + /// + /// Gets or Sets the keepTryingHoverUp flag on the backing field + /// + public bool TryHoveringUp + { + get => bitsbyte[0]; + set => bitsbyte[0] = value; + } + + /// + /// Gets or Sets the Void Vault Enabled flag on the backing field + /// + public bool IsVoidVaultEnabled + { + get => bitsbyte[1]; + set => bitsbyte[1] = value; + } + + /// + /// Gets or Sets the Sitting flag on the backing field + /// + public bool IsSitting + { + get => bitsbyte[2]; + set => bitsbyte[2] = value; + } + + /// + /// Gets or Sets the Downed DD2 Event (any difficulty) flag on the backing field + /// + public bool HasDownedDd2Event + { + get => bitsbyte[3]; + set => bitsbyte[3] = value; + } + + /// + /// Gets or Sets the Petting Animal flag on the backing field + /// + public bool IsPettingAnimal + { + get => bitsbyte[4]; + set => bitsbyte[4] = value; + } + + /// + /// Gets or Sets the Is Petted Animal Small flag on the backing field + /// + public bool IsPettedAnimalSmall + { + get => bitsbyte[5]; + set => bitsbyte[5] = value; + } + + /// + /// Gets or Sets the Can Return with Potion of Return flag on the backing field + /// + public bool CanReturnWithPotionOfReturn + { + get => bitsbyte[6]; + set => bitsbyte[6] = value; + } + + /// + /// Gets or Sets the keepTryingHoverDown flag on the backing field + /// + public bool TryHoveringDown + { + get => bitsbyte[7]; + set => bitsbyte[7] = value; + } + + /// + /// Constructs a new instance of MiscDataSet2 with the given backing BitsByte + /// + /// + public MiscDataSet2(BitsByte bitsbyte) + { + this.bitsbyte = bitsbyte; + } + } +} diff --git a/TShockAPI/Models/PlayerUpdate/MiscDataSet3.cs b/TShockAPI/Models/PlayerUpdate/MiscDataSet3.cs new file mode 100644 index 00000000..5b18a0fd --- /dev/null +++ b/TShockAPI/Models/PlayerUpdate/MiscDataSet3.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Terraria; + +namespace TShockAPI.Models.PlayerUpdate +{ + /// + /// Model for the third set of misc data sent with a player update packet + /// + public struct MiscDataSet3 + { + public BitsByte bitsbyte; + + public bool IsSleeping + { + get => bitsbyte[0]; + set => bitsbyte[0] = value; + } + + /// + /// Constructs a new instance of MiscDataSet3 with the given backing BitsByte + /// + /// + public MiscDataSet3(BitsByte bitsbyte) + { + this.bitsbyte = bitsbyte; + } + } +} diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index f38ef40c..97b54a0d 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -93,6 +93,10 @@ + + + + @@ -205,7 +209,7 @@ - +