Adds models for the random bitsbyte data received in packet 13 - player update

This commit is contained in:
Chris 2020-05-18 14:42:29 +09:30
parent 51fadf406f
commit db84a9fc8f
7 changed files with 360 additions and 34 deletions

View file

@ -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;

View file

@ -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
/// <summary>
/// Control direction (BitFlags)
/// </summary>
public byte Control { get; set; }
public ControlSet Control { get; set; }
/// <summary>
/// Pulley update (BitFlags)
/// Misc Data Set 1
/// </summary>
public byte Pulley { get; set; }
public MiscDataSet1 MiscData1 { get; set; }
/// <summary>
/// Misc (BitFlags) Check tshock.readme.io
/// Misc Data Set 2
/// </summary>
public byte Misc { get; set; }
public MiscDataSet2 MiscData2 { get; set; }
/// <summary>
/// (BitFlags) Wether or not the player is sleeping.
/// Misc Data Set 3
/// </summary>
public byte Sleeping { get; set; }
public MiscDataSet3 MiscData3 { get; set; }
/// <summary>
/// The selected item in player's hand.
/// </summary>
@ -344,7 +346,19 @@ namespace TShockAPI
/// PlayerUpdate - When the player sends it's updated information to the server
/// </summary>
public static HandlerList<PlayerUpdateEventArgs> PlayerUpdate = new HandlerList<PlayerUpdateEventArgs>();
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;
}

View file

@ -0,0 +1,88 @@
using Terraria;
namespace TShockAPI.Models.PlayerUpdate
{
/// <summary>
/// Model for a control event sent with a player update packet
/// </summary>
public struct ControlSet
{
/// <summary>
/// Backing BitsByte field
/// </summary>
public BitsByte bitsbyte;
/// <summary>
/// Gets or Sets the Up flag on the backing field
/// </summary>
public bool MoveUp
{
get => bitsbyte[0];
set => bitsbyte[0] = value;
}
/// <summary>
/// Gets or Sets the Down flag on the backing field
/// </summary>
public bool MoveDown
{
get => bitsbyte[1];
set => bitsbyte[1] = value;
}
/// <summary>
/// Gets or Sets the Left flag on the backing field
/// </summary>
public bool MoveLeft
{
get => bitsbyte[2];
set => bitsbyte[2] = value;
}
/// <summary>
/// Gets or Sets the Right flag on the backing field
/// </summary>
public bool MoveRight
{
get => bitsbyte[3];
set => bitsbyte[3] = value;
}
/// <summary>
/// Gets or Sets the Jump flag on the backing field
/// </summary>
public bool Jump
{
get => bitsbyte[4];
set => bitsbyte[4] = value;
}
/// <summary>
/// Gets or Sets the ControlUseItem flag on the backing field
/// </summary>
public bool IsUsingItem
{
get => bitsbyte[5];
set => bitsbyte[5] = value;
}
/// <summary>
/// Gets or Sets the Direction flag on the backing field. True = 1, false = -1
/// </summary>
public bool FaceDirection
{
get => bitsbyte[6];
set => bitsbyte[6] = value;
}
/// <summary>
/// Constructs a new instance of ControlsModel with the given backing bitsbyte
/// </summary>
/// <param name="bitsbyte"></param>
public ControlSet(BitsByte bitsbyte)
{
this.bitsbyte = bitsbyte;
}
}
}

View file

@ -0,0 +1,87 @@
using Terraria;
namespace TShockAPI.Models.PlayerUpdate
{
/// <summary>
/// Model for the first set of misc data sent with a player update packet
/// </summary>
public struct MiscDataSet1
{
/// <summary>
/// Backing BitsByte field
/// </summary>
public BitsByte bitsbyte;
/// <summary>
/// Gets or Sets the Pulley flag on the backing field
/// </summary>
public bool IsUsingPulley
{
get => bitsbyte[0];
set => bitsbyte[0] = value;
}
/// <summary>
/// Gets or Sets the Pulley Direction flag on the backing field. True = 2, false = 1
/// </summary>
public bool PulleyDirection
{
get => bitsbyte[1];
set => bitsbyte[1] = value;
}
/// <summary>
/// Gets or Sets the Velocity > 0 flag on the backing field
/// </summary>
public bool HasVelocity
{
get => bitsbyte[2];
set => bitsbyte[2] = value;
}
/// <summary>
/// Gets or Sets the Vortex Stealth flag on the backing field
/// </summary>
public bool IsVortexStealthActive
{
get => bitsbyte[3];
set => bitsbyte[3] = value;
}
/// <summary>
/// Gets or Sets the Gravity Direction flag on the backing field. True = 1, False = -1
/// </summary>
public bool GravityDirection
{
get => bitsbyte[4];
set => bitsbyte[4] = value;
}
/// <summary>
/// Gets or Sets the Shield Raised flag on the backing field
/// </summary>
public bool IsShieldRaised
{
get => bitsbyte[5];
set => bitsbyte[5] = value;
}
/// <summary>
/// Gets or Sets the Ghost flag on the backing field
/// </summary>
public bool IsGhosted
{
get => bitsbyte[6];
set => bitsbyte[6] = value;
}
/// <summary>
/// Constructs a new instance of MiscDataSet1 with the given backing BitsByte
/// </summary>
/// <param name="bitsbyte"></param>
public MiscDataSet1(BitsByte bitsbyte)
{
this.bitsbyte = bitsbyte;
}
}
}

View file

@ -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
{
/// <summary>
/// Model for the second set of misc data sent with a player update packet
/// </summary>
public struct MiscDataSet2
{
/// <summary>
/// Backing BitsByte field
/// </summary>
public BitsByte bitsbyte;
/// <summary>
/// Gets or Sets the keepTryingHoverUp flag on the backing field
/// </summary>
public bool TryHoveringUp
{
get => bitsbyte[0];
set => bitsbyte[0] = value;
}
/// <summary>
/// Gets or Sets the Void Vault Enabled flag on the backing field
/// </summary>
public bool IsVoidVaultEnabled
{
get => bitsbyte[1];
set => bitsbyte[1] = value;
}
/// <summary>
/// Gets or Sets the Sitting flag on the backing field
/// </summary>
public bool IsSitting
{
get => bitsbyte[2];
set => bitsbyte[2] = value;
}
/// <summary>
/// Gets or Sets the Downed DD2 Event (any difficulty) flag on the backing field
/// </summary>
public bool HasDownedDd2Event
{
get => bitsbyte[3];
set => bitsbyte[3] = value;
}
/// <summary>
/// Gets or Sets the Petting Animal flag on the backing field
/// </summary>
public bool IsPettingAnimal
{
get => bitsbyte[4];
set => bitsbyte[4] = value;
}
/// <summary>
/// Gets or Sets the Is Petted Animal Small flag on the backing field
/// </summary>
public bool IsPettedAnimalSmall
{
get => bitsbyte[5];
set => bitsbyte[5] = value;
}
/// <summary>
/// Gets or Sets the Can Return with Potion of Return flag on the backing field
/// </summary>
public bool CanReturnWithPotionOfReturn
{
get => bitsbyte[6];
set => bitsbyte[6] = value;
}
/// <summary>
/// Gets or Sets the keepTryingHoverDown flag on the backing field
/// </summary>
public bool TryHoveringDown
{
get => bitsbyte[7];
set => bitsbyte[7] = value;
}
/// <summary>
/// Constructs a new instance of MiscDataSet2 with the given backing BitsByte
/// </summary>
/// <param name="bitsbyte"></param>
public MiscDataSet2(BitsByte bitsbyte)
{
this.bitsbyte = bitsbyte;
}
}
}

View file

@ -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
{
/// <summary>
/// Model for the third set of misc data sent with a player update packet
/// </summary>
public struct MiscDataSet3
{
public BitsByte bitsbyte;
public bool IsSleeping
{
get => bitsbyte[0];
set => bitsbyte[0] = value;
}
/// <summary>
/// Constructs a new instance of MiscDataSet3 with the given backing BitsByte
/// </summary>
/// <param name="bitsbyte"></param>
public MiscDataSet3(BitsByte bitsbyte)
{
this.bitsbyte = bitsbyte;
}
}
}

View file

@ -93,6 +93,10 @@
<Compile Include="Hooks\RegionHooks.cs" />
<Compile Include="ILog.cs" />
<Compile Include="Localization\EnglishLanguage.cs" />
<Compile Include="Models\PlayerUpdate\ControlSet.cs" />
<Compile Include="Models\PlayerUpdate\MiscDataSet1.cs" />
<Compile Include="Models\PlayerUpdate\MiscDataSet2.cs" />
<Compile Include="Models\PlayerUpdate\MiscDataSet3.cs" />
<Compile Include="NetItem.cs" />
<Compile Include="PlayerData.cs" />
<Compile Include="RegionHandler.cs" />
@ -205,7 +209,7 @@
</PropertyGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties BuildVersion_IncrementBeforeBuild="False" BuildVersion_StartDate="2011/6/17" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_BuildAction="Both" BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" />
<UserProperties BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" BuildVersion_BuildAction="Both" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_StartDate="2011/6/17" BuildVersion_IncrementBeforeBuild="False" />
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.