Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GetDataHandlers.cs #2

Merged
merged 9 commits into from
Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 69 additions & 26 deletions TShockAPI/GetDataHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,14 @@ public class SpawnEventArgs : GetDataHandledEventArgs
/// </summary>
public int RespawnTimer { get; set; }
/// <summary>
/// Number Of Deaths PVE
/// </summary>
public int NumberOfDeathsPVE { get; set; }
/// <summary>
/// Number Of Deaths PVP
/// </summary>
public int NumberOfDeathsPVP { get; set; }
/// <summary>
/// Context of where the player is spawning from.
/// </summary>
public PlayerSpawnContext SpawnContext { get; set; }
Expand All @@ -864,7 +872,7 @@ public class SpawnEventArgs : GetDataHandledEventArgs
/// PlayerSpawn - When a player spawns
/// </summary>
public static HandlerList<SpawnEventArgs> PlayerSpawn = new HandlerList<SpawnEventArgs>();
private static bool OnPlayerSpawn(TSPlayer player, MemoryStream data, byte pid, int spawnX, int spawnY, int respawnTimer, PlayerSpawnContext spawnContext)
private static bool OnPlayerSpawn(TSPlayer player, MemoryStream data, byte pid, int spawnX, int spawnY, int respawnTimer, int numberOfDeathsPVE, int numberOfDeathsPVP, PlayerSpawnContext spawnContext)
{
if (PlayerSpawn == null)
return false;
Expand All @@ -877,6 +885,8 @@ private static bool OnPlayerSpawn(TSPlayer player, MemoryStream data, byte pid,
SpawnX = spawnX,
SpawnY = spawnY,
RespawnTimer = respawnTimer,
NumberOfDeathsPVE = numberOfDeathsPVE,
NumberOfDeathsPVP = numberOfDeathsPVP,
SpawnContext = spawnContext
};
PlayerSpawn.Invoke(null, args);
Expand Down Expand Up @@ -1033,12 +1043,16 @@ public class PlayerZoneEventArgs : GetDataHandledEventArgs
/// 0 = Old One's Army, 1 = Granite, 2 = Marble, 3 = Hive, 4 = Gem Cave, 5 = Lihzhard Temple, 6 = Graveyard
/// </summary>
public BitsByte Zone4 { get; set; }
/// <summary>
/// 0 = The Aether
/// </summary>
public BitsByte Zone5 { get; set; }
}
/// <summary>
/// PlayerZone - When the player sends it's zone/biome information to the server
/// </summary>
public static HandlerList<PlayerZoneEventArgs> PlayerZone = new HandlerList<PlayerZoneEventArgs>();
private static bool OnPlayerZone(TSPlayer player, MemoryStream data, byte plr, BitsByte zone1, BitsByte zone2, BitsByte zone3, BitsByte zone4)
private static bool OnPlayerZone(TSPlayer player, MemoryStream data, byte plr, BitsByte zone1, BitsByte zone2, BitsByte zone3, BitsByte zone4, BitsByte zone5)
{
if (PlayerZone == null)
return false;
Expand All @@ -1051,7 +1065,8 @@ private static bool OnPlayerZone(TSPlayer player, MemoryStream data, byte plr, B
Zone1 = zone1,
Zone2 = zone2,
Zone3 = zone3,
Zone4 = zone4
Zone4 = zone4,
Zone5 = zone5
};
PlayerZone.Invoke(null, args);
return args.Handled;
Expand Down Expand Up @@ -1519,12 +1534,16 @@ public class PaintTileEventArgs : GetDataHandledEventArgs
/// Type
/// </summary>
public byte type { get; set; }
/// <summary>
/// Paint Coat Tile
/// </summary>
public byte coatTile { get; set; }
}
/// <summary>
/// NPCStrike - Called when an NPC is attacked
/// </summary>
public static HandlerList<PaintTileEventArgs> PaintTile = new HandlerList<PaintTileEventArgs>();
private static bool OnPaintTile(TSPlayer player, MemoryStream data, Int32 x, Int32 y, byte t)
private static bool OnPaintTile(TSPlayer player, MemoryStream data, Int32 x, Int32 y, byte t, byte ct)
{
if (PaintTile == null)
return false;
Expand All @@ -1535,7 +1554,8 @@ private static bool OnPaintTile(TSPlayer player, MemoryStream data, Int32 x, Int
Data = data,
X = x,
Y = y,
type = t
type = t,
coatTile = ct
};
PaintTile.Invoke(null, args);
return args.Handled;
Expand All @@ -1558,12 +1578,16 @@ public class PaintWallEventArgs : GetDataHandledEventArgs
/// Type
/// </summary>
public byte type { get; set; }
/// <summary>
/// Paint Coat Wall
/// </summary>
public byte coatWall { get; set; }
}
/// <summary>
/// Called When a wall is painted
/// </summary>
public static HandlerList<PaintWallEventArgs> PaintWall = new HandlerList<PaintWallEventArgs>();
private static bool OnPaintWall(TSPlayer player, MemoryStream data, Int32 x, Int32 y, byte t)
private static bool OnPaintWall(TSPlayer player, MemoryStream data, Int32 x, Int32 y, byte t, byte cw)
{
if (PaintWall == null)
return false;
Expand All @@ -1574,7 +1598,8 @@ private static bool OnPaintWall(TSPlayer player, MemoryStream data, Int32 x, Int
Data = data,
X = x,
Y = y,
type = t
type = t,
coatWall = cw
};
PaintWall.Invoke(null, args);
return args.Handled;
Expand Down Expand Up @@ -1734,12 +1759,15 @@ public class PlaceObjectEventArgs : GetDataHandledEventArgs
/// <summary>Alternate variation of the object placed.</summary>
public byte Alternate { get; set; }

/// <summary>Related to Rubblemaker.</summary>
public sbyte Random { get; set; }

/// <summary>The direction the object was placed.</summary>
public bool Direction { get; set; }
}
/// <summary>Fired when an object is placed in the world.</summary>
public static HandlerList<PlaceObjectEventArgs> PlaceObject = new HandlerList<PlaceObjectEventArgs>();
private static bool OnPlaceObject(TSPlayer player, MemoryStream data, 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, sbyte random, bool direction)
{
if (PlaceObject == null)
return false;
Expand All @@ -1753,6 +1781,7 @@ private static bool OnPlaceObject(TSPlayer player, MemoryStream data, short x, s
Type = type,
Style = style,
Alternate = alternate,
Random = random,
Direction = direction
};

Expand Down Expand Up @@ -1980,14 +2009,18 @@ public class PlayerDamageEventArgs : GetDataHandledEventArgs
/// Is the damage critical?
/// </summary>
public bool Critical { get; set; }
/// <summary>
/// Cooldown Counter
/// </summary>
public sbyte CooldownCounter { get; set; }
/// <summary>The reason the player took damage and/or died.</summary>
public PlayerDeathReason PlayerDeathReason { get; set; }
}
/// <summary>
/// PlayerDamage - Called when a player is damaged
/// </summary>
public static HandlerList<PlayerDamageEventArgs> PlayerDamage = new HandlerList<PlayerDamageEventArgs>();
private static bool OnPlayerDamage(TSPlayer player, MemoryStream data, 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, sbyte cooldownCounter, PlayerDeathReason playerDeathReason)
{
if (PlayerDamage == null)
return false;
Expand All @@ -2001,6 +2034,7 @@ private static bool OnPlayerDamage(TSPlayer player, MemoryStream data, byte id,
Damage = dmg,
PVP = pvp,
Critical = crit,
CooldownCounter = cooldownCounter,
PlayerDeathReason = playerDeathReason,
};
PlayerDamage.Invoke(null, args);
Expand Down Expand Up @@ -2687,9 +2721,11 @@ private static bool HandleSpawn(GetDataHandlerArgs args)
short spawnx = args.Data.ReadInt16();
short spawny = args.Data.ReadInt16();
int respawnTimer = args.Data.ReadInt32();
short numberOfDeathsPVE = args.Data.ReadInt16();
short numberOfDeathsPVP = args.Data.ReadInt16();
PlayerSpawnContext context = (PlayerSpawnContext)args.Data.ReadByte();

if (OnPlayerSpawn(args.Player, args.Data, player, spawnx, spawny, respawnTimer, context))
if (OnPlayerSpawn(args.Player, args.Data, player, spawnx, spawny, respawnTimer, numberOfDeathsPVE, numberOfDeathsPVP, context))
return true;

if ((Main.ServerSideCharacter) && (spawnx == -1 && spawny == -1)) //this means they want to spawn to vanilla spawn
Expand Down Expand Up @@ -2912,17 +2948,19 @@ private static bool HandleProjectileNew(GetDataHandlerArgs args)
Vector2 vel = args.Data.ReadVector2();
byte owner = args.Data.ReadInt8();
short type = args.Data.ReadInt16();
NewProjectileData bits = new NewProjectileData((BitsByte)args.Data.ReadByte());
BitsByte bitsByte = (BitsByte)args.Data.ReadByte();
BitsByte bitsByte2 = (BitsByte)(bitsByte[2] ? args.Data.ReadByte() : 0);
float[] ai = new float[Projectile.maxAI];
for (int i = 0; i < Projectile.maxAI; ++i)
ai[i] = !bits.AI[i] ? 0.0f : args.Data.ReadSingle();
ushort bannerId = bits.HasBannerIdToRespondTo ? args.Data.ReadUInt16() : (ushort)0;
short dmg = bits.HasDamage ? args.Data.ReadInt16() : (short)0;
float knockback = bits.HasKnockback ? args.Data.ReadSingle() : 0.0f;
short origDmg = bits.HasOriginalDamage ? args.Data.ReadInt16() : (short)0;
short projUUID = bits.HasUUUID ? args.Data.ReadInt16() : (short)-1;
if (projUUID >= 1000)
projUUID = -1;
for (int i = 0; i < Projectile.maxAI; ++i) ai[i] = 0f;
ai[0] = bitsByte[0] ? args.Data.ReadSingle() : 0f;
ai[1] = bitsByte[1] ? args.Data.ReadSingle() : 0f;
ushort bannerId = (ushort)(bitsByte[3] ? args.Data.ReadUInt16() : 0);
short dmg = (short)(bitsByte[4] ? args.Data.ReadInt16() : 0);
float knockback = bitsByte[5] ? args.Data.ReadSingle() : 0f;
short origDmg = (short)(bitsByte[6] ? args.Data.ReadInt16() : 0);
short projUUID = (short)(bitsByte[7] ? args.Data.ReadInt16() : -1);
if (projUUID >= 1000) projUUID = -1;
ai[2] = (bitsByte2[0] ? args.Data.ReadSingle() : 0f);

var index = TShock.Utils.SearchProjectile(ident, owner);

Expand Down Expand Up @@ -3150,8 +3188,9 @@ private static bool HandlePlayerZone(GetDataHandlerArgs args)
BitsByte zone2 = args.Data.ReadInt8();
BitsByte zone3 = args.Data.ReadInt8();
BitsByte zone4 = args.Data.ReadInt8();
BitsByte zone5 = args.Data.ReadInt8();

if (OnPlayerZone(args.Player, args.Data, plr, zone1, zone2, zone3, zone4))
if (OnPlayerZone(args.Player, args.Data, plr, zone1, zone2, zone3, zone4, zone5))
return true;

return false;
Expand Down Expand Up @@ -3616,13 +3655,14 @@ private static bool HandlePaintTile(GetDataHandlerArgs args)
var x = args.Data.ReadInt16();
var y = args.Data.ReadInt16();
var t = args.Data.ReadInt8();
var ct = args.Data.ReadInt8();//PaintCoatTile

if (x < 0 || y < 0 || x >= Main.maxTilesX || y >= Main.maxTilesY || t > Main.numTileColors)
{
TShock.Log.ConsoleDebug(GetString("GetDataHandlers / HandlePaintTile rejected range check {0}", args.Player.Name));
return true;
}
if (OnPaintTile(args.Player, args.Data, x, y, t))
if (OnPaintTile(args.Player, args.Data, x, y, t, ct))
{
return true;
}
Expand Down Expand Up @@ -3663,13 +3703,14 @@ private static bool HandlePaintWall(GetDataHandlerArgs args)
var x = args.Data.ReadInt16();
var y = args.Data.ReadInt16();
var t = args.Data.ReadInt8();
var cw = args.Data.ReadInt8();//PaintCoatWall

if (x < 0 || y < 0 || x >= Main.maxTilesX || y >= Main.maxTilesY || t > Main.numTileColors)
{
TShock.Log.ConsoleDebug(GetString("GetDataHandlers / HandlePaintWall rejected range check {0}", args.Player.Name));
return true;
}
if (OnPaintWall(args.Player, args.Data, x, y, t))
if (OnPaintWall(args.Player, args.Data, x, y, t, cw))
{
return true;
}
Expand Down Expand Up @@ -3928,9 +3969,10 @@ private static bool HandlePlaceObject(GetDataHandlerArgs args)
short type = args.Data.ReadInt16();
short style = args.Data.ReadInt16();
byte alternate = args.Data.ReadInt8();
sbyte random = (sbyte)args.Data.ReadInt8();
bool direction = args.Data.ReadBoolean();

if (OnPlaceObject(args.Player, args.Data, x, y, type, style, alternate, direction))
if (OnPlaceObject(args.Player, args.Data, x, y, type, style, alternate, random, direction))
return true;

return false;
Expand Down Expand Up @@ -4068,7 +4110,7 @@ private static bool HandlePlayerPortalTeleport(GetDataHandlerArgs args)

private static bool HandleNpcTeleportPortal(GetDataHandlerArgs args)
{
var npcIndex = args.Data.ReadByte();
var npcIndex = args.Data.ReadUInt16();
var portalColorIndex = args.Data.ReadInt16();
var newPosition = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle());
var velocity = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle());
Expand Down Expand Up @@ -4162,8 +4204,9 @@ private static bool HandlePlayerDamageV2(GetDataHandlerArgs args)
var bits = (BitsByte)(args.Data.ReadByte());
var crit = bits[0];
var pvp = bits[1];
var cooldownCounter = (sbyte)args.Data.ReadInt8();

if (OnPlayerDamage(args.Player, args.Data, id, direction, dmg, pvp, crit, playerDeathReason))
if (OnPlayerDamage(args.Player, args.Data, id, direction, dmg, pvp, crit, cooldownCounter, playerDeathReason))
return true;

return false;
Expand Down
4 changes: 4 additions & 0 deletions TShockAPI/Net/SpawnMsg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public override PacketTypes ID
public short TileX { get; set; }
public short TileY { get; set; }
public int RespawnTimer { get; set; }
public short numberOfDeathsPVE { get; set; }
public short numberOfDeathsPVP { get; set; }
public PlayerSpawnContext PlayerSpawnContext { get; set; }

public override void Pack(Stream stream)
Expand All @@ -41,6 +43,8 @@ public override void Pack(Stream stream)
stream.WriteInt16(TileX);
stream.WriteInt16(TileY);
stream.WriteInt32(RespawnTimer);
stream.WriteInt16(numberOfDeathsPVE);
stream.WriteInt16(numberOfDeathsPVP);
stream.WriteByte((byte) PlayerSpawnContext);
}
}
Expand Down
6 changes: 5 additions & 1 deletion TShockAPI/TSPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,9 @@ public void Spawn(PlayerSpawnContext context, int? respawnTimer = null)
/// <param name="tiley">The Y coordinate.</param>
/// <param name="context">The PlayerSpawnContext.</param>
/// <param name="respawnTimer">The respawn timer, will be Player.respawnTimer if parameter is null.</param>
public void Spawn(int tilex, int tiley, PlayerSpawnContext context, int? respawnTimer = null)
/// <param name="numberOfDeathsPVE">The number of deaths PVE, will be TPlayer.numberOfDeathsPVE if parameter is null.</param>
/// <param name="numberOfDeathsPVP">The number of deaths PVP, will be TPlayer.numberOfDeathsPVP if parameter is null.</param>
public void Spawn(int tilex, int tiley, PlayerSpawnContext context, int? respawnTimer = null, short? numberOfDeathsPVE = null, short? numberOfDeathsPVP = null)
{
using (var ms = new MemoryStream())
{
Expand All @@ -1404,6 +1406,8 @@ public void Spawn(int tilex, int tiley, PlayerSpawnContext context, int? respawn
TileX = (short)tilex,
TileY = (short)tiley,
RespawnTimer = respawnTimer ?? TShock.Players[Index].RespawnTimer * 60,
numberOfDeathsPVE = numberOfDeathsPVE ?? (short)TPlayer.numberOfDeathsPVE,
numberOfDeathsPVP = numberOfDeathsPVP ?? (short)TPlayer.numberOfDeathsPVP,
PlayerSpawnContext = context,
};
msg.PackFull(ms);
Expand Down
14 changes: 14 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,22 @@ Use past tense when adding new entries; sign your name off when you add or chang
* If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. -->

## Upcoming changes

* Your changes could be here!
* Fixed wrong MaxProjDamage trigger.(@ATFGK, #2804)
* Fixed incorrect Spawn information.(@ATFGK, #2804)
* New argument `AI[2]` has been added to hook `GetDataHandlers.HandleProjectileNew`.(@ATFGK)
* New argument `Zone5` has been added to hook `GetDataHandlers.OnPlayerZone`.(@ATFGK)
* New argument `coatTile` has been added to hook `GetDataHandlers.OnPaintTile`.(@ATFGK)
* New argument `coatWall` has been added to hook `GetDataHandlers.OnPaintWall`.(@ATFGK)
* New argument `CooldownCounter` has been added to hook `GetDataHandlers.OnPlayerDamage`.(@ATFGK)
* New argument `Random` has been added to hook `GetDataHandlers.OnPlaceObject`.(@ATFGK)
* New argument `numberOfDeathsPVE` and `numberOfDeathsPVP` have been added to hook `GetDataHandlers.OnPlayerSpawn`.(@ATFGK)
* New argument `numberOfDeathsPVE` and `numberOfDeathsPVP` have been added to `TSPlayer.Spawn`.(@ATFGK)
* An argument `npcIndex` in `GetDataHandlers.HandleNpcTeleportPortal` has been updated to `ushort`.(@ATFGK)
* Fixed Super Sponge unable to absorb shimmer. (@sgkoishi, #2833)


## TShock 5.1.3
* Added support for Terraria 1.4.4.9 via OTAPI 3.1.20. (@SignatureBeef)

Expand Down