From fcccfc07e83f014e54756e5a138eff54509f3c92 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Mon, 19 Jul 2021 13:38:40 +0800
Subject: [PATCH 01/32] Fix invalid torch place style exploit
---
TShockAPI/Bouncer.cs | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 42cc6cd1..faea739c 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -308,8 +308,10 @@ namespace TShockAPI
return;
}
- if ((args.Player.TPlayer.BiomeTorchHoldStyle(style) != args.Player.TPlayer.BiomeTorchPlaceStyle(style))
- && (selectedItem.placeStyle != style))
+ var torchPlaceStyle = args.Player.TPlayer.UsingBiomeTorches
+ ? args.Player.TPlayer.BiomeTorchPlaceStyle(0) // using non-0 returns that number
+ : selectedItem.placeStyle;
+ if (torchPlaceStyle != style)
{
TShock.Log.ConsoleError("Bouncer / OnTileEdit rejected from (placestyle) {0} {1} {2} placeStyle: {3} expectedStyle: {4}",
args.Player.Name, action, editData, style, selectedItem.placeStyle);
From 9182b3b2be73e9ef2c8b7d0fc3e01df14b906b75 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Mon, 19 Jul 2021 13:48:06 +0800
Subject: [PATCH 02/32] Fix invalid place style exploit
---
TShockAPI/Bouncer.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index faea739c..2473a42e 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -386,8 +386,8 @@ namespace TShockAPI
else if (action == EditAction.PlaceTile || action == EditAction.ReplaceTile || action == EditAction.PlaceWall || action == EditAction.ReplaceWall)
{
if ((action == EditAction.PlaceTile && TShock.Config.Settings.PreventInvalidPlaceStyle) &&
- (MaxPlaceStyles.ContainsKey(editData) && style > MaxPlaceStyles[editData]) &&
- (ExtraneousPlaceStyles.ContainsKey(editData) && style > ExtraneousPlaceStyles[editData]))
+ ((MaxPlaceStyles.ContainsKey(editData) && style > MaxPlaceStyles[editData]) ||
+ (ExtraneousPlaceStyles.ContainsKey(editData) && style > ExtraneousPlaceStyles[editData])))
{
TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from (ms1) {0} {1} {2}", args.Player.Name, action, editData);
args.Player.SendTileSquare(tileX, tileY, 4);
From ea180347cb4073d1a5af397ebad22089fb5ea253 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Mon, 19 Jul 2021 13:57:02 +0800
Subject: [PATCH 03/32] Fix can't place `>>>` Booster Track
---
TShockAPI/Bouncer.cs | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 2473a42e..4dec9101 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -310,7 +310,9 @@ namespace TShockAPI
var torchPlaceStyle = args.Player.TPlayer.UsingBiomeTorches
? args.Player.TPlayer.BiomeTorchPlaceStyle(0) // using non-0 returns that number
- : selectedItem.placeStyle;
+ : editData == TileID.MinecartTrack && style == 2 && args.Player.TPlayer.direction == 1 // Booster Right Track
+ ? 3
+ : selectedItem.placeStyle;
if (torchPlaceStyle != style)
{
TShock.Log.ConsoleError("Bouncer / OnTileEdit rejected from (placestyle) {0} {1} {2} placeStyle: {3} expectedStyle: {4}",
@@ -385,9 +387,11 @@ namespace TShockAPI
}
else if (action == EditAction.PlaceTile || action == EditAction.ReplaceTile || action == EditAction.PlaceWall || action == EditAction.ReplaceWall)
{
+ var isInvalidPlaceStyle = ExtraneousPlaceStyles.ContainsKey(editData)
+ ? style > ExtraneousPlaceStyles[editData]
+ : MaxPlaceStyles.ContainsKey(editData) && style > MaxPlaceStyles[editData];
if ((action == EditAction.PlaceTile && TShock.Config.Settings.PreventInvalidPlaceStyle) &&
- ((MaxPlaceStyles.ContainsKey(editData) && style > MaxPlaceStyles[editData]) ||
- (ExtraneousPlaceStyles.ContainsKey(editData) && style > ExtraneousPlaceStyles[editData])))
+ isInvalidPlaceStyle)
{
TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from (ms1) {0} {1} {2}", args.Player.Name, action, editData);
args.Player.SendTileSquare(tileX, tileY, 4);
From b63b50bb3ee150ba267416c774275f21ebdb879c Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Mon, 19 Jul 2021 14:06:43 +0800
Subject: [PATCH 04/32] Rename `torchPlaceStyle` -> `correctedPlaceStyle`
---
TShockAPI/Bouncer.cs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 4dec9101..0384e783 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -308,15 +308,15 @@ namespace TShockAPI
return;
}
- var torchPlaceStyle = args.Player.TPlayer.UsingBiomeTorches
+ var correctedPlaceStyle = args.Player.TPlayer.UsingBiomeTorches
? args.Player.TPlayer.BiomeTorchPlaceStyle(0) // using non-0 returns that number
: editData == TileID.MinecartTrack && style == 2 && args.Player.TPlayer.direction == 1 // Booster Right Track
? 3
: selectedItem.placeStyle;
- if (torchPlaceStyle != style)
+ if (correctedPlaceStyle != style)
{
TShock.Log.ConsoleError("Bouncer / OnTileEdit rejected from (placestyle) {0} {1} {2} placeStyle: {3} expectedStyle: {4}",
- args.Player.Name, action, editData, style, selectedItem.placeStyle);
+ args.Player.Name, action, editData, style, correctedPlaceStyle);
args.Player.SendTileSquare(tileX, tileY, 1);
args.Handled = true;
return;
From 871f6babcc885edf450a0596e1e6021fda748c65 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Mon, 19 Jul 2021 15:01:49 +0800
Subject: [PATCH 05/32] Fix issues
---
TShockAPI/Bouncer.cs | 46 +++++++++++++++++++++++++++++++++-----------
1 file changed, 35 insertions(+), 11 deletions(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 0384e783..197490b1 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -308,18 +308,42 @@ namespace TShockAPI
return;
}
- var correctedPlaceStyle = args.Player.TPlayer.UsingBiomeTorches
- ? args.Player.TPlayer.BiomeTorchPlaceStyle(0) // using non-0 returns that number
- : editData == TileID.MinecartTrack && style == 2 && args.Player.TPlayer.direction == 1 // Booster Right Track
- ? 3
- : selectedItem.placeStyle;
- if (correctedPlaceStyle != style)
+ var createTile = selectedItem.createTile;
+ var placeStyle = selectedItem.placeStyle;
+ if (placeStyle != style)
{
- TShock.Log.ConsoleError("Bouncer / OnTileEdit rejected from (placestyle) {0} {1} {2} placeStyle: {3} expectedStyle: {4}",
- args.Player.Name, action, editData, style, correctedPlaceStyle);
- args.Player.SendTileSquare(tileX, tileY, 1);
- args.Handled = true;
- return;
+ var tplayer = args.Player.TPlayer;
+ if (createTile == TileID.Torches && placeStyle == TorchID.Torch && tplayer.unlockedBiomeTorches)
+ {
+ // BiomeTorchPlaceStyle checks if the player has biome torches activated
+ // but biome torches activation isn't broadcasted when it's toggled
+ var usingBiomeTorches = tplayer.UsingBiomeTorches;
+ if (!usingBiomeTorches)
+ {
+ tplayer.UsingBiomeTorches = true;
+ }
+ var biomeTorchStyle = tplayer.BiomeTorchPlaceStyle(placeStyle);
+ if (!usingBiomeTorches)
+ {
+ tplayer.UsingBiomeTorches = usingBiomeTorches;
+ }
+ if (style != biomeTorchStyle)
+ {
+ TShock.Log.ConsoleError("Bouncer / OnTileEdit rejected from (placestyle) {0} {1} {2} placeStyle: {3} expectedStyle: 0 or {4}",
+ args.Player.Name, action, editData, style, biomeTorchStyle);
+ args.Player.SendTileSquare(tileX, tileY, 1);
+ args.Handled = true;
+ return;
+ }
+ }
+ else if (createTile != TileID.MinecartTrack || placeStyle != 2 || args.Player.TPlayer.direction != 1 || style != 3)
+ {
+ TShock.Log.ConsoleError("Bouncer / OnTileEdit rejected from (placestyle) {0} {1} {2} placeStyle: {3} expectedStyle: {4}",
+ args.Player.Name, action, editData, style, placeStyle);
+ args.Player.SendTileSquare(tileX, tileY, 1);
+ args.Handled = true;
+ return;
+ }
}
}
From 38dcc16cd61dd6debf9da4e4c3ab7ff62d691970 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Mon, 19 Jul 2021 15:57:42 +0800
Subject: [PATCH 06/32] Add changelog entry
---
CHANGELOG.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e55df643..3c3f466a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
* Added `summonboss` permission check for Prismatic Lacewing. Players who do not have said permission will be unable to kill this critter, as it will summon the Empress of Light. Also added support for the `AnonymousBossInvasions` config option, if this is set to `false` it will now broadcast the name of the player who summoned her. (@moisterrific)
* Added `ForceTime` config setting check for Enchanted Sundial usage. If `ForceTime` is set to anything other than `normal`, Sundial use will be rejected as this would lead to very janky game behavior. Additionally, players with `cfgreload` permission will be advised to change it back to `normal` in order to use sundial. (@moisterrific, @bartico6)
* Added `%onlineplayers%` and `%serverslots%` placeholders for MOTD. The default MOTD message was also updated to use this. (@moisterrific, @bartico6)
+* Fixed a client crash exploit involving invalid tiles. (@Arthri)
## TShock 4.5.4
* Fixed ridiculous typo in `GetDataHandlers` which caused TShock to read the wrong field in the packet for `usingBiomeTorches`. (@hakusaro, @Arthri)
From c616d1caded8e24352176bec11f79bc1df9405d2 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Thu, 22 Jul 2021 10:39:19 +0800
Subject: [PATCH 07/32] Add comment describing biome torch correction code
---
TShockAPI/Bouncer.cs | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 197490b1..cb3229ff 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -315,8 +315,17 @@ namespace TShockAPI
var tplayer = args.Player.TPlayer;
if (createTile == TileID.Torches && placeStyle == TorchID.Torch && tplayer.unlockedBiomeTorches)
{
- // BiomeTorchPlaceStyle checks if the player has biome torches activated
- // but biome torches activation isn't broadcasted when it's toggled
+ // The torch is a default torch, so biome torches apply to it
+ // The player has also used Torch God's Favor, they can use biome torches
+
+ // The server isn't notified when the player turns on biome torches.
+ // So on the client it can be on, while on the server it's off.
+ // BiomeTorchPlaceStyle returns placeStyle as-is if biome torches is off.
+ // Because of the uncertainty, we:
+ // 1. Ensure that UsingBiomeTorches is on, so we can get the correct
+ // value from BiomeTorchPlaceStyle.
+ // 2. Check if the torch is either 0 or the biome torch since we aren't
+ // sure if the player has biome torches on
var usingBiomeTorches = tplayer.UsingBiomeTorches;
if (!usingBiomeTorches)
{
From 74197bd71b26ca6345ed6eadd51fbaa9591ae696 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Thu, 22 Jul 2021 10:43:23 +0800
Subject: [PATCH 08/32] Add comment describing right booster track check
---
TShockAPI/Bouncer.cs | 1 +
1 file changed, 1 insertion(+)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index cb3229ff..71a5e3d0 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -345,6 +345,7 @@ namespace TShockAPI
return;
}
}
+ // Checks if the player is trying to place a booster track facing right
else if (createTile != TileID.MinecartTrack || placeStyle != 2 || args.Player.TPlayer.direction != 1 || style != 3)
{
TShock.Log.ConsoleError("Bouncer / OnTileEdit rejected from (placestyle) {0} {1} {2} placeStyle: {3} expectedStyle: {4}",
From a1b7556d3a9d1325ed78e614573ae1142b346037 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Thu, 22 Jul 2021 10:44:17 +0800
Subject: [PATCH 09/32] Simplify booster track check
---
TShockAPI/Bouncer.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 71a5e3d0..6548e454 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -346,7 +346,7 @@ namespace TShockAPI
}
}
// Checks if the player is trying to place a booster track facing right
- else if (createTile != TileID.MinecartTrack || placeStyle != 2 || args.Player.TPlayer.direction != 1 || style != 3)
+ else if (createTile != ItemID.BoosterTrack || args.Player.TPlayer.direction != 1 || style != 3)
{
TShock.Log.ConsoleError("Bouncer / OnTileEdit rejected from (placestyle) {0} {1} {2} placeStyle: {3} expectedStyle: {4}",
args.Player.Name, action, editData, style, placeStyle);
From 8004b3f079f5c1757a66c7ca9c3ae76784510060 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Sun, 25 Jul 2021 13:55:56 +0800
Subject: [PATCH 10/32] Declare how biome torch works
---
TShockAPI/Bouncer.cs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 6548e454..303b5a5b 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -315,7 +315,8 @@ namespace TShockAPI
var tplayer = args.Player.TPlayer;
if (createTile == TileID.Torches && placeStyle == TorchID.Torch && tplayer.unlockedBiomeTorches)
{
- // The torch is a default torch, so biome torches apply to it
+ // Biome Torches only work on the default torch(placeStyle/TorchID: 0)
+ // This torch is the default one
// The player has also used Torch God's Favor, they can use biome torches
// The server isn't notified when the player turns on biome torches.
From de22400b3f65365ca00b3d78ad90a8cb856f5182 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Sun, 25 Jul 2021 14:06:47 +0800
Subject: [PATCH 11/32] Biome Torch check is suppose to check for 0
---
TShockAPI/Bouncer.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 303b5a5b..12772af5 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -337,7 +337,7 @@ namespace TShockAPI
{
tplayer.UsingBiomeTorches = usingBiomeTorches;
}
- if (style != biomeTorchStyle)
+ if (style != TorchID.Torch || style != biomeTorchStyle)
{
TShock.Log.ConsoleError("Bouncer / OnTileEdit rejected from (placestyle) {0} {1} {2} placeStyle: {3} expectedStyle: 0 or {4}",
args.Player.Name, action, editData, style, biomeTorchStyle);
From fd3e857f068bdf784859f0caf8c5bd59860d06d2 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Sun, 25 Jul 2021 14:07:38 +0800
Subject: [PATCH 12/32] Declare BiomeTorchPlaceStyle's purpose
---
TShockAPI/Bouncer.cs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 12772af5..663148cf 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -332,6 +332,8 @@ namespace TShockAPI
{
tplayer.UsingBiomeTorches = true;
}
+ // BiomeTorchPlaceStyle returns the place style of the player's
+ // current biome's biome torch
var biomeTorchStyle = tplayer.BiomeTorchPlaceStyle(placeStyle);
if (!usingBiomeTorches)
{
From ca31a15be9e2123b04589820ea095afaea84b84d Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Sun, 25 Jul 2021 16:29:05 +0800
Subject: [PATCH 13/32] Add helper method for getting max placeStyle
---
TShockAPI/Bouncer.cs | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 663148cf..384c7044 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -424,11 +424,8 @@ namespace TShockAPI
}
else if (action == EditAction.PlaceTile || action == EditAction.ReplaceTile || action == EditAction.PlaceWall || action == EditAction.ReplaceWall)
{
- var isInvalidPlaceStyle = ExtraneousPlaceStyles.ContainsKey(editData)
- ? style > ExtraneousPlaceStyles[editData]
- : MaxPlaceStyles.ContainsKey(editData) && style > MaxPlaceStyles[editData];
if ((action == EditAction.PlaceTile && TShock.Config.Settings.PreventInvalidPlaceStyle) &&
- isInvalidPlaceStyle)
+ style > GetMaxPlaceStyle(editData))
{
TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from (ms1) {0} {1} {2}", args.Player.Name, action, editData);
args.Player.SendTileSquare(tileX, tileY, 4);
@@ -2228,6 +2225,25 @@ namespace TShockAPI
});
}
+ ///
+ /// Returns the max associated with the given . Or -1 if there's no association
+ ///
+ /// Tile ID to query for
+ /// The max , otherwise -1 if there's no association
+ internal static int GetMaxPlaceStyle(int tileID)
+ {
+ int result;
+ if (ExtraneousPlaceStyles.TryGetValue(tileID, out result)
+ || MaxPlaceStyles.TryGetValue(tileID, out result))
+ {
+ return result;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+
// These time values are references from Projectile.cs, at npc.AddBuff() calls.
private static Dictionary NPCAddBuffTimeMax = new Dictionary()
{
From 8c31546f0437d1064a42887b2815767521152d43 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Sun, 25 Jul 2021 17:08:43 +0800
Subject: [PATCH 14/32] Detail exploits and fixes in changelog entry
---
CHANGELOG.md | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3c3f466a..b3051709 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,7 +32,9 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
* Added `summonboss` permission check for Prismatic Lacewing. Players who do not have said permission will be unable to kill this critter, as it will summon the Empress of Light. Also added support for the `AnonymousBossInvasions` config option, if this is set to `false` it will now broadcast the name of the player who summoned her. (@moisterrific)
* Added `ForceTime` config setting check for Enchanted Sundial usage. If `ForceTime` is set to anything other than `normal`, Sundial use will be rejected as this would lead to very janky game behavior. Additionally, players with `cfgreload` permission will be advised to change it back to `normal` in order to use sundial. (@moisterrific, @bartico6)
* Added `%onlineplayers%` and `%serverslots%` placeholders for MOTD. The default MOTD message was also updated to use this. (@moisterrific, @bartico6)
-* Fixed a client crash exploit involving invalid tiles. (@Arthri)
+* Fixed Bouncer exploits allowing for invalid tiles' placement. These tiles(specifically torches) caused clients to crash. The fixed exploits are listed below. (@Arthri)
+ - [Biome Torch Correction](https://github.com/Pryaxis/TShock/blob/3ba1e7419d63535eeb8b5634ec668448499f71df/TShockAPI/Bouncer.cs#L310). Previously, it used unrelated values to validate biome torches, and unintentionally passed on invalid tiles. It's now fixed to use the correct values and block invalid torches. As well as a new right booster track correction/check
+ - [Max Place Styles](https://github.com/Pryaxis/TShock/blob/3ba1e7419d63535eeb8b5634ec668448499f71df/TShockAPI/Bouncer.cs#L385). Previously, it fails only if both `MaxPlaceStyles` and `ExtraneousPlaceStyles` contains an entry for a tile, and unintentionally passed on invalid tiles. `ExtraneousPlaceStyles` only contains special max placeStyles, not all placeables unlike `MaxPlaceStyles`. It's now corrected to take from `ExtraneousPlaceStyles` first, then fallback to `MaxPlaceStyles` if there's no entry for that tile, and then finally -1 if there's no entry in either.
## TShock 4.5.4
* Fixed ridiculous typo in `GetDataHandlers` which caused TShock to read the wrong field in the packet for `usingBiomeTorches`. (@hakusaro, @Arthri)
From dcd10ad0b4da1f12f307d44b7f88af8682a303b4 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Sun, 25 Jul 2021 17:13:46 +0800
Subject: [PATCH 15/32] Expand on booster track check in changelog
---
CHANGELOG.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b3051709..a00c228b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -33,7 +33,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
* Added `ForceTime` config setting check for Enchanted Sundial usage. If `ForceTime` is set to anything other than `normal`, Sundial use will be rejected as this would lead to very janky game behavior. Additionally, players with `cfgreload` permission will be advised to change it back to `normal` in order to use sundial. (@moisterrific, @bartico6)
* Added `%onlineplayers%` and `%serverslots%` placeholders for MOTD. The default MOTD message was also updated to use this. (@moisterrific, @bartico6)
* Fixed Bouncer exploits allowing for invalid tiles' placement. These tiles(specifically torches) caused clients to crash. The fixed exploits are listed below. (@Arthri)
- - [Biome Torch Correction](https://github.com/Pryaxis/TShock/blob/3ba1e7419d63535eeb8b5634ec668448499f71df/TShockAPI/Bouncer.cs#L310). Previously, it used unrelated values to validate biome torches, and unintentionally passed on invalid tiles. It's now fixed to use the correct values and block invalid torches. As well as a new right booster track correction/check
+ - [Biome Torch Correction](https://github.com/Pryaxis/TShock/blob/3ba1e7419d63535eeb8b5634ec668448499f71df/TShockAPI/Bouncer.cs#L310). Previously, it used unrelated values to validate biome torches, and unintentionally passed on invalid tiles. It's now fixed to use the correct values and block invalid torches. As well as a new right booster track correction/check, to allow right booster tracks to be placed. Right booster track is an extraneous place style because it depends on the direction the player is facing. The new check takes that into consideration so that the place style isn't considered mismatched and rejected.
- [Max Place Styles](https://github.com/Pryaxis/TShock/blob/3ba1e7419d63535eeb8b5634ec668448499f71df/TShockAPI/Bouncer.cs#L385). Previously, it fails only if both `MaxPlaceStyles` and `ExtraneousPlaceStyles` contains an entry for a tile, and unintentionally passed on invalid tiles. `ExtraneousPlaceStyles` only contains special max placeStyles, not all placeables unlike `MaxPlaceStyles`. It's now corrected to take from `ExtraneousPlaceStyles` first, then fallback to `MaxPlaceStyles` if there's no entry for that tile, and then finally -1 if there's no entry in either.
## TShock 4.5.4
From fc2c6a64acbe859bf17955e9e7bce09a64fea27b Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Sun, 25 Jul 2021 17:14:10 +0800
Subject: [PATCH 16/32] Clarify as "reject" instead of fail
---
CHANGELOG.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a00c228b..fedc5a69 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -34,7 +34,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
* Added `%onlineplayers%` and `%serverslots%` placeholders for MOTD. The default MOTD message was also updated to use this. (@moisterrific, @bartico6)
* Fixed Bouncer exploits allowing for invalid tiles' placement. These tiles(specifically torches) caused clients to crash. The fixed exploits are listed below. (@Arthri)
- [Biome Torch Correction](https://github.com/Pryaxis/TShock/blob/3ba1e7419d63535eeb8b5634ec668448499f71df/TShockAPI/Bouncer.cs#L310). Previously, it used unrelated values to validate biome torches, and unintentionally passed on invalid tiles. It's now fixed to use the correct values and block invalid torches. As well as a new right booster track correction/check, to allow right booster tracks to be placed. Right booster track is an extraneous place style because it depends on the direction the player is facing. The new check takes that into consideration so that the place style isn't considered mismatched and rejected.
- - [Max Place Styles](https://github.com/Pryaxis/TShock/blob/3ba1e7419d63535eeb8b5634ec668448499f71df/TShockAPI/Bouncer.cs#L385). Previously, it fails only if both `MaxPlaceStyles` and `ExtraneousPlaceStyles` contains an entry for a tile, and unintentionally passed on invalid tiles. `ExtraneousPlaceStyles` only contains special max placeStyles, not all placeables unlike `MaxPlaceStyles`. It's now corrected to take from `ExtraneousPlaceStyles` first, then fallback to `MaxPlaceStyles` if there's no entry for that tile, and then finally -1 if there's no entry in either.
+ - [Max Place Styles](https://github.com/Pryaxis/TShock/blob/3ba1e7419d63535eeb8b5634ec668448499f71df/TShockAPI/Bouncer.cs#L385). Previously, it rejects only if both `MaxPlaceStyles` and `ExtraneousPlaceStyles` contains an entry for a tile, and unintentionally passed on invalid tiles. `ExtraneousPlaceStyles` only contains special max placeStyles, not all placeables unlike `MaxPlaceStyles`. It's now corrected to take from `ExtraneousPlaceStyles` first, then fallback to `MaxPlaceStyles` if there's no entry for that tile, and then finally -1 if there's no entry in either.
## TShock 4.5.4
* Fixed ridiculous typo in `GetDataHandlers` which caused TShock to read the wrong field in the packet for `usingBiomeTorches`. (@hakusaro, @Arthri)
From ab30f5da707536472de791c81eaedd6eed6f2364 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Thu, 29 Jul 2021 07:55:15 +0800
Subject: [PATCH 17/32] Explain conditions in booster track check
---
TShockAPI/Bouncer.cs | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 384c7044..d3e4b48e 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -348,7 +348,10 @@ namespace TShockAPI
return;
}
}
- // Checks if the player is trying to place a booster track facing right
+ // Only other extraneous tile is Right Booster Track with a placeStyle of 3
+ // The player can place it only if they're facing right
+ // or direction 1 for positive X <- -X(Left) Origin (Right)X+ ->
+ // If none of the conditions mentioned above check out, fail check
else if (createTile != ItemID.BoosterTrack || args.Player.TPlayer.direction != 1 || style != 3)
{
TShock.Log.ConsoleError("Bouncer / OnTileEdit rejected from (placestyle) {0} {1} {2} placeStyle: {3} expectedStyle: {4}",
From 288698ce42d5cb98b758e822c49deef8ee260fac Mon Sep 17 00:00:00 2001
From: Chris <2648373+QuiCM@users.noreply.github.com>
Date: Mon, 16 Aug 2021 22:14:02 +0930
Subject: [PATCH 18/32] Some refactoring for variable naming & code flow
---
TShockAPI/Bouncer.cs | 66 +++++++++++++++++++++++++-------------------
1 file changed, 37 insertions(+), 29 deletions(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index d3e4b48e..16b0a3fa 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -256,7 +256,10 @@ namespace TShockAPI
int tileY = args.Y;
short editData = args.EditData;
EditType type = args.editDetail;
- byte style = args.Style;
+
+ // 'placeStyle' is a term used in Terraria land to determine which frame of a sprite is displayed when the sprite is placed. The placeStyle
+ // determines the frameX and frameY offsets
+ byte requestedPlaceStyle = args.Style;
try
{
@@ -308,17 +311,27 @@ namespace TShockAPI
return;
}
- var createTile = selectedItem.createTile;
- var placeStyle = selectedItem.placeStyle;
- if (placeStyle != style)
+ // This is the actual tile ID we expect the selected item to create. If the tile ID from the packet and the tile ID from the item do not match
+ // we need to inspect further to determine if Terraria is sending funny information (which it does sometimes) or if someone is being malicious
+ var actualTileToBeCreated = selectedItem.createTile;
+ // This is the actual place style we expect the selected item to create. Same as above - if it differs from what the client tells us,
+ // we need to do some inspection to check if its valid
+ var actualItemPlaceStyle = selectedItem.placeStyle;
+
+ // The client has requested to place a style that does not match their held item's actual place style
+ if (requestedPlaceStyle != actualItemPlaceStyle)
{
var tplayer = args.Player.TPlayer;
- if (createTile == TileID.Torches && placeStyle == TorchID.Torch && tplayer.unlockedBiomeTorches)
- {
- // Biome Torches only work on the default torch(placeStyle/TorchID: 0)
- // This torch is the default one
- // The player has also used Torch God's Favor, they can use biome torches
+ // If the client is attempting to place a default torch, we need to check that the torch they are attempting to place is valid.
+ // The place styles may mismatch if the player is placing a biome torch.
+ // Biome torches can only be placed if the player has unlocked them (Torch God's Favor)
+ // Therefore, the following conditions need to be true:
+ // - The client's selected item will create a default torch
+ // - The client's selected item's place style will be that of a default torch
+ // - The client has unlocked biome torches
+ if (actualTileToBeCreated == TileID.Torches && actualItemPlaceStyle == TorchID.Torch && tplayer.unlockedBiomeTorches)
+ {
// The server isn't notified when the player turns on biome torches.
// So on the client it can be on, while on the server it's off.
// BiomeTorchPlaceStyle returns placeStyle as-is if biome torches is off.
@@ -328,34 +341,29 @@ namespace TShockAPI
// 2. Check if the torch is either 0 or the biome torch since we aren't
// sure if the player has biome torches on
var usingBiomeTorches = tplayer.UsingBiomeTorches;
- if (!usingBiomeTorches)
- {
- tplayer.UsingBiomeTorches = true;
- }
- // BiomeTorchPlaceStyle returns the place style of the player's
- // current biome's biome torch
- var biomeTorchStyle = tplayer.BiomeTorchPlaceStyle(placeStyle);
- if (!usingBiomeTorches)
- {
- tplayer.UsingBiomeTorches = usingBiomeTorches;
- }
- if (style != TorchID.Torch || style != biomeTorchStyle)
+ tplayer.UsingBiomeTorches = true;
+ // BiomeTorchPlaceStyle returns the place style of the player's current biome's biome torch
+ var biomeTorchPlaceStyle = tplayer.BiomeTorchPlaceStyle(actualItemPlaceStyle);
+ // Reset UsingBiomeTorches value
+ tplayer.UsingBiomeTorches = usingBiomeTorches;
+
+ // If the biome torch place style still doesn't match the expected place style then the client has sent an invalid place tile request
+ if (biomeTorchPlaceStyle != requestedPlaceStyle)
{
TShock.Log.ConsoleError("Bouncer / OnTileEdit rejected from (placestyle) {0} {1} {2} placeStyle: {3} expectedStyle: 0 or {4}",
- args.Player.Name, action, editData, style, biomeTorchStyle);
+ args.Player.Name, action, editData, requestedPlaceStyle, biomeTorchPlaceStyle);
args.Player.SendTileSquare(tileX, tileY, 1);
args.Handled = true;
return;
}
}
- // Only other extraneous tile is Right Booster Track with a placeStyle of 3
- // The player can place it only if they're facing right
- // or direction 1 for positive X <- -X(Left) Origin (Right)X+ ->
- // If none of the conditions mentioned above check out, fail check
- else if (createTile != ItemID.BoosterTrack || args.Player.TPlayer.direction != 1 || style != 3)
+ // Currently the only other extraneous tile is Right Booster Track with a placeStyle of 3
+ // The player can place it only if they're facing right (direction == 1).
+ // If this isn't the case, reject the packet
+ else if (actualTileToBeCreated != ItemID.BoosterTrack && requestedPlaceStyle != 3 && args.Player.TPlayer.direction != 1)
{
TShock.Log.ConsoleError("Bouncer / OnTileEdit rejected from (placestyle) {0} {1} {2} placeStyle: {3} expectedStyle: {4}",
- args.Player.Name, action, editData, style, placeStyle);
+ args.Player.Name, action, editData, requestedPlaceStyle, actualItemPlaceStyle);
args.Player.SendTileSquare(tileX, tileY, 1);
args.Handled = true;
return;
@@ -428,7 +436,7 @@ namespace TShockAPI
else if (action == EditAction.PlaceTile || action == EditAction.ReplaceTile || action == EditAction.PlaceWall || action == EditAction.ReplaceWall)
{
if ((action == EditAction.PlaceTile && TShock.Config.Settings.PreventInvalidPlaceStyle) &&
- style > GetMaxPlaceStyle(editData))
+ requestedPlaceStyle > GetMaxPlaceStyle(editData))
{
TShock.Log.ConsoleDebug("Bouncer / OnTileEdit rejected from (ms1) {0} {1} {2}", args.Player.Name, action, editData);
args.Player.SendTileSquare(tileX, tileY, 4);
From 16de180d5215755acc7ba0f9ba4eab1022f916a4 Mon Sep 17 00:00:00 2001
From: Lucas Nicodemus
Date: Mon, 16 Aug 2021 16:11:29 -0700
Subject: [PATCH 19/32] Move changelog entry to upcoming section
---
CHANGELOG.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fb6e525a..da9b8d57 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,9 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
* Added a new `/respawn` command that lets you respawn yourself or another player. Respawning yourself requires the `tshock.respawn` permission and respawning others requires the `tshock.respawn.other` permission. The full command syntax is `/respawn [player]`. (@moisterrific)
* Added a notification message and silent command support for permanently changing a target player's user group. Now players who received a group change will be notified of their new group if they are currently online. (@moisterrific, @QuiCM)
* Changed the TSPlayer IP method to return the loopback IP if RealPlayer is false. (@Rozen4334)
+* Fixed Bouncer exploits allowing for invalid tiles' placement. These tiles(specifically torches) caused clients to crash. The fixed exploits are listed below. (@Arthri, @QuiCM)
+ - [Biome Torch Correction](https://github.com/Pryaxis/TShock/blob/3ba1e7419d63535eeb8b5634ec668448499f71df/TShockAPI/Bouncer.cs#L310). Previously, it used unrelated values to validate biome torches, and unintentionally passed on invalid tiles. It's now fixed to use the correct values and block invalid torches. As well as a new right booster track correction/check, to allow right booster tracks to be placed. Right booster track is an extraneous place style because it depends on the direction the player is facing. The new check takes that into consideration so that the place style isn't considered mismatched and rejected.
+ - [Max Place Styles](https://github.com/Pryaxis/TShock/blob/3ba1e7419d63535eeb8b5634ec668448499f71df/TShockAPI/Bouncer.cs#L385). Previously, it rejects only if both `MaxPlaceStyles` and `ExtraneousPlaceStyles` contains an entry for a tile, and unintentionally passed on invalid tiles. `ExtraneousPlaceStyles` only contains special max placeStyles, not all placeables unlike `MaxPlaceStyles`. It's now corrected to take from `ExtraneousPlaceStyles` first, then fallback to `MaxPlaceStyles` if there's no entry for that tile, and then finally -1 if there's no entry in either.
## TShock 4.5.5
* Changed the world autosave message so that it no longer warns of a "potential lag spike." (@hakusaro)
@@ -44,9 +47,6 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
* Added `summonboss` permission check for Empress of Light. Players who do not have this permission will be unable to kill Prismatic Lacewings. Also added support for the `AnonymousBossInvasions` config option, if this is set to `false` it will now broadcast the name of the player who summoned her. (@moisterrific)
* Added `ForceTime` config setting check for Enchanted Sundial usage. If `ForceTime` is set to anything other than `normal`, Sundial use will be rejected as this would lead to very janky game behavior. Additionally, players with `cfgreload` permission will be advised to change it back to `normal` in order to use sundial. (@moisterrific, @bartico6)
* Added `%onlineplayers%` and `%serverslots%` placeholders for MOTD. The default MOTD message was also updated to use this. (@moisterrific, @bartico6)
-* Fixed Bouncer exploits allowing for invalid tiles' placement. These tiles(specifically torches) caused clients to crash. The fixed exploits are listed below. (@Arthri)
- - [Biome Torch Correction](https://github.com/Pryaxis/TShock/blob/3ba1e7419d63535eeb8b5634ec668448499f71df/TShockAPI/Bouncer.cs#L310). Previously, it used unrelated values to validate biome torches, and unintentionally passed on invalid tiles. It's now fixed to use the correct values and block invalid torches. As well as a new right booster track correction/check, to allow right booster tracks to be placed. Right booster track is an extraneous place style because it depends on the direction the player is facing. The new check takes that into consideration so that the place style isn't considered mismatched and rejected.
- - [Max Place Styles](https://github.com/Pryaxis/TShock/blob/3ba1e7419d63535eeb8b5634ec668448499f71df/TShockAPI/Bouncer.cs#L385). Previously, it rejects only if both `MaxPlaceStyles` and `ExtraneousPlaceStyles` contains an entry for a tile, and unintentionally passed on invalid tiles. `ExtraneousPlaceStyles` only contains special max placeStyles, not all placeables unlike `MaxPlaceStyles`. It's now corrected to take from `ExtraneousPlaceStyles` first, then fallback to `MaxPlaceStyles` if there's no entry for that tile, and then finally -1 if there's no entry in either.
* Fixed Bouncer inconsistently using `TilePlacementValid` when validating tile coordinates, which could cause a DoS attack due to unexpectedly large world framing. The list below shows the corrected methods within Bouncer. This was assigned [GHSA-jq4j-v8pr-jv7j](https://github.com/Pryaxis/TShock/security/advisories/GHSA-jq4j-v8pr-jv7j). (@drunderscore)
* `OnTileEdit`: The check was moved to be the first, and will no longer `SendTileSquare` upon failure.
* `OnPlaceObject`: The check was moved to be the first, and will no longer `SendTileSquare` upon failure.
From 265cd2012fa60c8488db6dde0c85011b65c70e1b Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Tue, 17 Aug 2021 22:37:49 +0800
Subject: [PATCH 20/32] Transfer checks to a dictionary
---
TShockAPI/Bouncer.cs | 122 +++++++++++++++++++++++++++++--------------
1 file changed, 82 insertions(+), 40 deletions(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 71621bf8..31f96d5c 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -45,6 +45,20 @@ namespace TShockAPI
internal Handlers.LandGolfBallInCupHandler LandGolfBallInCupHandler { get; private set; }
internal Handlers.SyncTilePickingHandler SyncTilePickingHandler { get; private set; }
+ ///
+ /// Represents a place style corrector.
+ ///
+ /// The player placing the tile.
+ /// The requested place style to be placed.
+ /// The actual place style that should be placed, based of the player's held item.
+ /// The correct place style in the current context.
+ internal delegate int PlaceStyleCorrector(Player player, int requestedPlaceStyle, int actualItemPlaceStyle);
+
+ ///
+ /// Represents a dictionary of s, the key is the tile ID and the value is the corrector.
+ ///
+ internal Dictionary PlaceStyleCorrectors = new Dictionary();
+
/// Constructor call initializes Bouncer and related functionality.
/// A new Bouncer.
internal Bouncer()
@@ -101,6 +115,70 @@ namespace TShockAPI
GetDataHandlers.KillMe += OnKillMe;
GetDataHandlers.FishOutNPC += OnFishOutNPC;
GetDataHandlers.FoodPlatterTryPlacing += OnFoodPlatterTryPlacing;
+
+ PlaceStyleCorrectors.Add(TileID.Torches,
+ (player, requestedPlaceStyle, actualItemPlaceStyle) =>
+ {
+ // If the client is attempting to place a default torch, we need to check that the torch they are attempting to place is valid.
+ // The place styles may mismatch if the player is placing a biome torch.
+ // Biome torches can only be placed if the player has unlocked them (Torch God's Favor)
+ // Therefore, the following conditions need to be true:
+ // - The client's selected item will create a default torch
+ // - The client's selected item's place style will be that of a default torch
+ // - The client has unlocked biome torches
+ if (actualItemPlaceStyle == TorchID.Torch && player.unlockedBiomeTorches)
+ {
+ // The server isn't notified when the player turns on biome torches.
+ // So on the client it can be on, while on the server it's off.
+ // BiomeTorchPlaceStyle returns placeStyle as-is if biome torches is off.
+ // Because of the uncertainty, we:
+ // 1. Ensure that UsingBiomeTorches is on, so we can get the correct
+ // value from BiomeTorchPlaceStyle.
+ // 2. Check if the torch is either 0 or the biome torch since we aren't
+ // sure if the player has biome torches on
+ var usingBiomeTorches = player.UsingBiomeTorches;
+ player.UsingBiomeTorches = true;
+ // BiomeTorchPlaceStyle returns the place style of the player's current biome's biome torch
+ var biomeTorchPlaceStyle = player.BiomeTorchPlaceStyle(actualItemPlaceStyle);
+ // Reset UsingBiomeTorches value
+ player.UsingBiomeTorches = usingBiomeTorches;
+
+ return biomeTorchPlaceStyle;
+ }
+ else
+ {
+ return requestedPlaceStyle;
+ }
+ });
+ PlaceStyleCorrectors.Add(TileID.MinecartTrack,
+ (player, requestedPlaceStyle, actualItemPlaceStyle) =>
+ {
+ // The player can place right booster tracks only if they're facing right (direction == 1).
+ // If this isn't the case, reject the packet
+ if (actualItemPlaceStyle == 2)
+ {
+ // 3 is for right-facing booster tracks
+ // 1 is right, because adding it to 0 points to the positive X axis -->
+ if (player.direction == 1)
+ {
+ return 3;
+ }
+ // 2 is for left-facing booster tracks
+ // -1 is left, because adding it to 0 points to the negative X axis <--
+ else if (player.direction == -1)
+ {
+ return 2;
+ }
+ else
+ {
+ throw new InvalidOperationException("Unrecognized player direction");
+ }
+ }
+ else
+ {
+ return actualItemPlaceStyle;
+ }
+ });
}
internal void OnGetSection(object sender, GetDataHandlers.GetSectionEventArgs args)
@@ -321,48 +399,12 @@ namespace TShockAPI
if (requestedPlaceStyle != actualItemPlaceStyle)
{
var tplayer = args.Player.TPlayer;
-
- // If the client is attempting to place a default torch, we need to check that the torch they are attempting to place is valid.
- // The place styles may mismatch if the player is placing a biome torch.
- // Biome torches can only be placed if the player has unlocked them (Torch God's Favor)
- // Therefore, the following conditions need to be true:
- // - The client's selected item will create a default torch
- // - The client's selected item's place style will be that of a default torch
- // - The client has unlocked biome torches
- if (actualTileToBeCreated == TileID.Torches && actualItemPlaceStyle == TorchID.Torch && tplayer.unlockedBiomeTorches)
- {
- // The server isn't notified when the player turns on biome torches.
- // So on the client it can be on, while on the server it's off.
- // BiomeTorchPlaceStyle returns placeStyle as-is if biome torches is off.
- // Because of the uncertainty, we:
- // 1. Ensure that UsingBiomeTorches is on, so we can get the correct
- // value from BiomeTorchPlaceStyle.
- // 2. Check if the torch is either 0 or the biome torch since we aren't
- // sure if the player has biome torches on
- var usingBiomeTorches = tplayer.UsingBiomeTorches;
- tplayer.UsingBiomeTorches = true;
- // BiomeTorchPlaceStyle returns the place style of the player's current biome's biome torch
- var biomeTorchPlaceStyle = tplayer.BiomeTorchPlaceStyle(actualItemPlaceStyle);
- // Reset UsingBiomeTorches value
- tplayer.UsingBiomeTorches = usingBiomeTorches;
-
- // If the biome torch place style still doesn't match the expected place style then the client has sent an invalid place tile request
- if (biomeTorchPlaceStyle != requestedPlaceStyle)
- {
- TShock.Log.ConsoleError("Bouncer / OnTileEdit rejected from (placestyle) {0} {1} {2} placeStyle: {3} expectedStyle: 0 or {4}",
- args.Player.Name, action, editData, requestedPlaceStyle, biomeTorchPlaceStyle);
- args.Player.SendTileSquare(tileX, tileY, 1);
- args.Handled = true;
- return;
- }
- }
- // Currently the only other extraneous tile is Right Booster Track with a placeStyle of 3
- // The player can place it only if they're facing right (direction == 1).
- // If this isn't the case, reject the packet
- else if (actualTileToBeCreated != ItemID.BoosterTrack && requestedPlaceStyle != 3 && args.Player.TPlayer.direction != 1)
+ var correctedPlaceStyle = actualItemPlaceStyle;
+ if (!PlaceStyleCorrectors.TryGetValue(actualTileToBeCreated, out PlaceStyleCorrector corrector)
+ || requestedPlaceStyle != (correctedPlaceStyle = corrector(tplayer, requestedPlaceStyle, actualItemPlaceStyle)))
{
TShock.Log.ConsoleError("Bouncer / OnTileEdit rejected from (placestyle) {0} {1} {2} placeStyle: {3} expectedStyle: {4}",
- args.Player.Name, action, editData, requestedPlaceStyle, actualItemPlaceStyle);
+ args.Player.Name, action, editData, requestedPlaceStyle, correctedPlaceStyle);
args.Player.SendTileSquare(tileX, tileY, 1);
args.Handled = true;
return;
From 96f26be50b44b0a54a8343daf4ed55772a4b5c88 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Tue, 17 Aug 2021 23:08:18 +0800
Subject: [PATCH 21/32] Complete correctors
---
TShockAPI/Bouncer.cs | 58 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 31f96d5c..5210f5f6 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -116,6 +116,8 @@ namespace TShockAPI
GetDataHandlers.FishOutNPC += OnFishOutNPC;
GetDataHandlers.FoodPlatterTryPlacing += OnFoodPlatterTryPlacing;
+
+ // The following section is based off and .
PlaceStyleCorrectors.Add(TileID.Torches,
(player, requestedPlaceStyle, actualItemPlaceStyle) =>
{
@@ -150,6 +152,50 @@ namespace TShockAPI
return requestedPlaceStyle;
}
});
+ PlaceStyleCorrectors.Add(TileID.Jackolanterns,
+ (player, requestedPlaceStyle, actualItemPlaceStyle) =>
+ {
+ if (actualItemPlaceStyle == 0)
+ {
+ return requestedPlaceStyle;
+ }
+ else
+ {
+ return 0;
+ }
+ });
+ PlaceStyleCorrectors.Add(TileID.SnowballLauncher,
+ (player, requestedPlaceStyle, actualItemPlaceStyle) =>
+ {
+ // 1 is right, because adding it to 0 points to the positive X axis -->
+ if (player.direction == 1)
+ {
+ // Right-facing snowball launcher
+ return 1;
+ }
+ // -1 is left, because adding it to 0 points to the negative X axis <--
+ else if (player.direction == -1)
+ {
+ // Left-facing snowball launcher
+ return 0;
+ }
+ else
+ {
+ throw new InvalidOperationException("Unrecognized player direction");
+ }
+ });
+ PlaceStyleCorrectors.Add(TileID.Painting4X3,
+ (player, requestedPlaceStyle, actualItemPlaceStyle) =>
+ {
+ if (actualItemPlaceStyle == 0)
+ {
+ return requestedPlaceStyle;
+ }
+ else
+ {
+ return 0;
+ }
+ });
PlaceStyleCorrectors.Add(TileID.MinecartTrack,
(player, requestedPlaceStyle, actualItemPlaceStyle) =>
{
@@ -179,6 +225,18 @@ namespace TShockAPI
return actualItemPlaceStyle;
}
});
+
+ // Return the input as-is. These tiles have a random placeStyle every time they're placed.
+ // Though they originate from the same tile.
+ // e.g. everytime Presents(36) are placed, a variation from the 8 is randomly chosen on the client.
+ // We just agree to it because there's nothing wrong.
+ // Although they can use hacks to place 10 variation 8s consecutively, we don't care about that.
+ PlaceStyleCorrector agreeAnyway =
+ (player, requestedPlaceStyle, actualItemPlaceStyle) => requestedPlaceStyle;
+
+ PlaceStyleCorrectors.Add(TileID.Presents, agreeAnyway);
+ PlaceStyleCorrectors.Add(TileID.Explosives, agreeAnyway);
+ PlaceStyleCorrectors.Add(TileID.Crystals, agreeAnyway);
}
internal void OnGetSection(object sender, GetDataHandlers.GetSectionEventArgs args)
From 16451ec0e943a50a66cfbd4d6b80b9bc8681eca4 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Tue, 17 Aug 2021 23:41:23 +0800
Subject: [PATCH 22/32] Complete docs and polish
---
TShockAPI/Bouncer.cs | 97 ++++++++++++++++++++++++++++++++------------
1 file changed, 71 insertions(+), 26 deletions(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 5210f5f6..9945d754 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -125,7 +125,7 @@ namespace TShockAPI
// The place styles may mismatch if the player is placing a biome torch.
// Biome torches can only be placed if the player has unlocked them (Torch God's Favor)
// Therefore, the following conditions need to be true:
- // - The client's selected item will create a default torch
+ // - The client's selected item will create a default torch(this should be true if this handler is running)
// - The client's selected item's place style will be that of a default torch
// - The client has unlocked biome torches
if (actualItemPlaceStyle == TorchID.Torch && player.unlockedBiomeTorches)
@@ -149,34 +149,86 @@ namespace TShockAPI
}
else
{
- return requestedPlaceStyle;
+ // If the player is not placing a default torch, then biome torches don't apply and return item place style.
+ // Or they haven't unlocked biome torches yet, then return default torch because they can't place biome torches.
+ return actualItemPlaceStyle;
}
});
PlaceStyleCorrectors.Add(TileID.Jackolanterns,
(player, requestedPlaceStyle, actualItemPlaceStyle) =>
{
- if (actualItemPlaceStyle == 0)
+ // Jack O' Lanterns is a tile with 9 variations, but only 1 item.
+ // The item uses the first style a.k.a. 0.
+ // RNG only generates placeStyles less than 9.
+ if (actualItemPlaceStyle == 0 && requestedPlaceStyle < 9)
{
return requestedPlaceStyle;
}
else
{
+ // Return 0 for now, but ideally 0-8 should be returned.
+ return 0;
+ }
+ });
+ PlaceStyleCorrectors.Add(TileID.Presents,
+ (player, requestedPlaceStyle, actualItemPlaceStyle) =>
+ {
+ // RNG only generates placeStyles less than 7.
+ // Do note there's a 8th present(blue, golden stripes) that's unplaceable.
+ // https://terraria.fandom.com/wiki/Presents, last present of the 8 displayed
+ if (requestedPlaceStyle < 7)
+ {
+ return requestedPlaceStyle;
+ }
+ else
+ {
+ // Return 0 for now, but ideally 0-7 should be returned.
+ return 0;
+ }
+ });
+ PlaceStyleCorrectors.Add(TileID.Explosives,
+ (player, requestedPlaceStyle, actualItemPlaceStyle) =>
+ {
+ // RNG only generates placeStyles less than 2.
+ if (requestedPlaceStyle < 2)
+ {
+ return requestedPlaceStyle;
+ }
+ else
+ {
+ // Return 0 for now, but ideally 0-1 should be returned.
+ return 0;
+ }
+ });
+ PlaceStyleCorrectors.Add(TileID.Crystals,
+ (player, requestedPlaceStyle, actualItemPlaceStyle) =>
+ {
+ // RNG only generates placeStyles less than 18.
+ // Do note that Gelatin Crystals(Queen Slime summon) share the same ID as Crystal Shards.
+ // <18 includes all shards except Gelatin Crystals.
+ if (requestedPlaceStyle < 18)
+ {
+ return requestedPlaceStyle;
+ }
+ else
+ {
+ // Return 0 for now, but ideally 0-17 should be returned.
return 0;
}
});
PlaceStyleCorrectors.Add(TileID.SnowballLauncher,
(player, requestedPlaceStyle, actualItemPlaceStyle) =>
{
- // 1 is right, because adding it to 0 points to the positive X axis -->
+ // Check the direction the player is facing.
+ // 1 is right and -1 is left, these are the only possible values.
if (player.direction == 1)
{
- // Right-facing snowball launcher
+ // Right-facing snowball launcher.
return 1;
}
- // -1 is left, because adding it to 0 points to the negative X axis <--
else if (player.direction == -1)
{
- // Left-facing snowball launcher
+ // Left-facing snowball launcher.
return 0;
}
else
@@ -187,32 +239,36 @@ namespace TShockAPI
PlaceStyleCorrectors.Add(TileID.Painting4X3,
(player, requestedPlaceStyle, actualItemPlaceStyle) =>
{
- if (actualItemPlaceStyle == 0)
+ // Painting4X3 or "Catacombs" is a painting with 9 variations, but only 1 item.
+ // The first item uses the first style a.k.a. 0.
+ // RNG only generates placeStyles less than 9.
+ if (actualItemPlaceStyle == 0 && requestedPlaceStyle < 9)
{
return requestedPlaceStyle;
}
else
{
+ // Return 0 for now, ideally 0-8 should be returned.
return 0;
}
});
PlaceStyleCorrectors.Add(TileID.MinecartTrack,
(player, requestedPlaceStyle, actualItemPlaceStyle) =>
{
- // The player can place right booster tracks only if they're facing right (direction == 1).
- // If this isn't the case, reject the packet
+ // Booster tracks have 2 variations, but only 1 item.
+ // The variation depends on the direction the player is facing.
if (actualItemPlaceStyle == 2)
{
- // 3 is for right-facing booster tracks
- // 1 is right, because adding it to 0 points to the positive X axis -->
+ // Check the direction the player is facing.
+ // 1 is right and -1 is left, these are the only possible values.
if (player.direction == 1)
{
+ // Right-facing booster tracks
return 3;
}
- // 2 is for left-facing booster tracks
- // -1 is left, because adding it to 0 points to the negative X axis <--
else if (player.direction == -1)
{
+ // Left-facing booster tracks
return 2;
}
else
@@ -222,21 +278,10 @@ namespace TShockAPI
}
else
{
+ // Not a booster track, return as-is.
return actualItemPlaceStyle;
}
});
-
- // Return the input as-is. These tiles have a random placeStyle every time they're placed.
- // Though they originate from the same tile.
- // e.g. everytime Presents(36) are placed, a variation from the 8 is randomly chosen on the client.
- // We just agree to it because there's nothing wrong.
- // Although they can use hacks to place 10 variation 8s consecutively, we don't care about that.
- PlaceStyleCorrector agreeAnyway =
- (player, requestedPlaceStyle, actualItemPlaceStyle) => requestedPlaceStyle;
-
- PlaceStyleCorrectors.Add(TileID.Presents, agreeAnyway);
- PlaceStyleCorrectors.Add(TileID.Explosives, agreeAnyway);
- PlaceStyleCorrectors.Add(TileID.Crystals, agreeAnyway);
}
internal void OnGetSection(object sender, GetDataHandlers.GetSectionEventArgs args)
From 307ff79170150b8f2e7bfe895f7fe80bfd5c3e82 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Tue, 17 Aug 2021 23:42:01 +0800
Subject: [PATCH 23/32] This isnt XML
---
TShockAPI/Bouncer.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 9945d754..464bbfff 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -117,7 +117,7 @@ namespace TShockAPI
GetDataHandlers.FoodPlatterTryPlacing += OnFoodPlatterTryPlacing;
- // The following section is based off and .
+ // The following section is based off Player.PlaceThing_Tiles_PlaceIt and Player.PlaceThing_Tiles_PlaceIt_GetLegacyTileStyle.
PlaceStyleCorrectors.Add(TileID.Torches,
(player, requestedPlaceStyle, actualItemPlaceStyle) =>
{
From 8c5e7b4d47fc83d0e96324eff8aacd156c9dae93 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Wed, 18 Aug 2021 17:09:58 +0800
Subject: [PATCH 24/32] Polish docs
---
TShockAPI/Bouncer.cs | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 464bbfff..182ce54b 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -149,8 +149,8 @@ namespace TShockAPI
}
else
{
- // If the player is not placing a default torch, then biome torches don't apply and return item place style.
- // Or they haven't unlocked biome torches yet, then return default torch because they can't place biome torches.
+ // If the player isn't holding the default torch, then biome torches don't apply and return item place style.
+ // Or, they are holding the default torch but haven't unlocked biome torches yet, so return item place style.
return actualItemPlaceStyle;
}
});
@@ -159,7 +159,7 @@ namespace TShockAPI
{
// Jack O' Lanterns is a tile with 9 variations, but only 1 item.
// The item uses the first style a.k.a. 0.
- // RNG only generates placeStyles less than 9.
+ // RNG only generates placeStyles less than 9, so permit only <9
if (actualItemPlaceStyle == 0 && requestedPlaceStyle < 9)
{
return requestedPlaceStyle;
@@ -173,8 +173,8 @@ namespace TShockAPI
PlaceStyleCorrectors.Add(TileID.Presents,
(player, requestedPlaceStyle, actualItemPlaceStyle) =>
{
- // RNG only generates placeStyles less than 7.
- // Do note there's a 8th present(blue, golden stripes) that's unplaceable.
+ // RNG only generates placeStyles less than 7, so permit only <7
+ // Note: there's an 8th present(blue, golden stripes) that's unplaceable.
// https://terraria.fandom.com/wiki/Presents, last present of the 8 displayed
if (requestedPlaceStyle < 7)
{
@@ -189,7 +189,7 @@ namespace TShockAPI
PlaceStyleCorrectors.Add(TileID.Explosives,
(player, requestedPlaceStyle, actualItemPlaceStyle) =>
{
- // RNG only generates placeStyles less than 2.
+ // RNG only generates placeStyles less than 2, so permit only <2
if (requestedPlaceStyle < 2)
{
return requestedPlaceStyle;
@@ -203,8 +203,8 @@ namespace TShockAPI
PlaceStyleCorrectors.Add(TileID.Crystals,
(player, requestedPlaceStyle, actualItemPlaceStyle) =>
{
- // RNG only generates placeStyles less than 18.
- // Do note that Gelatin Crystals(Queen Slime summon) share the same ID as Crystal Shards.
+ // RNG only generates placeStyles less than 18, so permit only <18.
+ // Note: Gelatin Crystals(Queen Slime summon) share the same ID as Crystal Shards.
// <18 includes all shards except Gelatin Crystals.
if (requestedPlaceStyle < 18)
{
@@ -241,14 +241,14 @@ namespace TShockAPI
{
// Painting4X3 or "Catacombs" is a painting with 9 variations, but only 1 item.
// The first item uses the first style a.k.a. 0.
- // RNG only generates placeStyles less than 9.
+ // RNG only generates placeStyles less than 9, so permit only <9.
if (actualItemPlaceStyle == 0 && requestedPlaceStyle < 9)
{
return requestedPlaceStyle;
}
else
{
- // Return 0 for now, ideally 0-8 should be returned.
+ // Return 0 for now, but ideally 0-8 should be returned.
return 0;
}
});
From a0cd2849eddb2f07052b8163679860ca31f8a912 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Wed, 18 Aug 2021 17:15:36 +0800
Subject: [PATCH 25/32] Add missing entries to ExtraneousPlaceStyles
---
TShockAPI/GetDataHandlers.cs | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs
index 3bed28b2..6983b4b3 100644
--- a/TShockAPI/GetDataHandlers.cs
+++ b/TShockAPI/GetDataHandlers.cs
@@ -4256,6 +4256,12 @@ namespace TShockAPI
///
internal static Dictionary ExtraneousPlaceStyles = new Dictionary
{
+ {TileID.Jackolanterns, 8},
+ {TileID.Presents, 6},
+ {TileID.Explosives, 1},
+ {TileID.Crystals, 17},
+ {TileID.SnowballLauncher, 1},
+ {TileID.Painting4X3, 8},
{TileID.MinecartTrack, 3}
};
From 638b7cc54f9a011e1169e68ce1ea167a2cca7ada Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Wed, 18 Aug 2021 17:39:28 +0800
Subject: [PATCH 26/32] Remove multiblock tiles
---
TShockAPI/Bouncer.cs | 52 ------------------------------------
TShockAPI/GetDataHandlers.cs | 3 ---
2 files changed, 55 deletions(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 182ce54b..45dfa76c 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -154,22 +154,6 @@ namespace TShockAPI
return actualItemPlaceStyle;
}
});
- PlaceStyleCorrectors.Add(TileID.Jackolanterns,
- (player, requestedPlaceStyle, actualItemPlaceStyle) =>
- {
- // Jack O' Lanterns is a tile with 9 variations, but only 1 item.
- // The item uses the first style a.k.a. 0.
- // RNG only generates placeStyles less than 9, so permit only <9
- if (actualItemPlaceStyle == 0 && requestedPlaceStyle < 9)
- {
- return requestedPlaceStyle;
- }
- else
- {
- // Return 0 for now, but ideally 0-8 should be returned.
- return 0;
- }
- });
PlaceStyleCorrectors.Add(TileID.Presents,
(player, requestedPlaceStyle, actualItemPlaceStyle) =>
{
@@ -216,42 +200,6 @@ namespace TShockAPI
return 0;
}
});
- PlaceStyleCorrectors.Add(TileID.SnowballLauncher,
- (player, requestedPlaceStyle, actualItemPlaceStyle) =>
- {
- // Check the direction the player is facing.
- // 1 is right and -1 is left, these are the only possible values.
- if (player.direction == 1)
- {
- // Right-facing snowball launcher.
- return 1;
- }
- else if (player.direction == -1)
- {
- // Left-facing snowball launcher.
- return 0;
- }
- else
- {
- throw new InvalidOperationException("Unrecognized player direction");
- }
- });
- PlaceStyleCorrectors.Add(TileID.Painting4X3,
- (player, requestedPlaceStyle, actualItemPlaceStyle) =>
- {
- // Painting4X3 or "Catacombs" is a painting with 9 variations, but only 1 item.
- // The first item uses the first style a.k.a. 0.
- // RNG only generates placeStyles less than 9, so permit only <9.
- if (actualItemPlaceStyle == 0 && requestedPlaceStyle < 9)
- {
- return requestedPlaceStyle;
- }
- else
- {
- // Return 0 for now, but ideally 0-8 should be returned.
- return 0;
- }
- });
PlaceStyleCorrectors.Add(TileID.MinecartTrack,
(player, requestedPlaceStyle, actualItemPlaceStyle) =>
{
diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs
index 6983b4b3..560ce976 100644
--- a/TShockAPI/GetDataHandlers.cs
+++ b/TShockAPI/GetDataHandlers.cs
@@ -4256,12 +4256,9 @@ namespace TShockAPI
///
internal static Dictionary ExtraneousPlaceStyles = new Dictionary
{
- {TileID.Jackolanterns, 8},
{TileID.Presents, 6},
{TileID.Explosives, 1},
{TileID.Crystals, 17},
- {TileID.SnowballLauncher, 1},
- {TileID.Painting4X3, 8},
{TileID.MinecartTrack, 3}
};
From 3eaf86ba04800c3c344162d92885585068e9b897 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Wed, 18 Aug 2021 18:39:41 +0800
Subject: [PATCH 27/32] Explicitly add placeStyle = 0
---
TShockAPI/Utils.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs
index 92d45299..97a38bdc 100644
--- a/TShockAPI/Utils.cs
+++ b/TShockAPI/Utils.cs
@@ -1226,7 +1226,7 @@ namespace TShockAPI
for (int i = 0; i < Main.maxItemTypes; i++)
{
item.netDefaults(i);
- if (item.placeStyle > 0)
+ if (item.placeStyle >= 0)
{
if (GetDataHandlers.MaxPlaceStyles.ContainsKey(item.createTile))
{
From 01d551aa30d7b56875c84dfcfa84557ea76cada2 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Wed, 18 Aug 2021 18:39:53 +0800
Subject: [PATCH 28/32] Clarify multi-block tiles
---
TShockAPI/Bouncer.cs | 1 +
1 file changed, 1 insertion(+)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 45dfa76c..b1aaa0ea 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -118,6 +118,7 @@ namespace TShockAPI
// The following section is based off Player.PlaceThing_Tiles_PlaceIt and Player.PlaceThing_Tiles_PlaceIt_GetLegacyTileStyle.
+ // Multi-block tiles are intentionally ignored because they don't pass through OnTileEdit.
PlaceStyleCorrectors.Add(TileID.Torches,
(player, requestedPlaceStyle, actualItemPlaceStyle) =>
{
From 335c1ddb50e03d1b85a741c32e610027f19189e6 Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Wed, 18 Aug 2021 18:40:04 +0800
Subject: [PATCH 29/32] Add entry for Ice Rod
---
TShockAPI/GetDataHandlers.cs | 1 +
1 file changed, 1 insertion(+)
diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs
index 560ce976..7c974e6d 100644
--- a/TShockAPI/GetDataHandlers.cs
+++ b/TShockAPI/GetDataHandlers.cs
@@ -4258,6 +4258,7 @@ namespace TShockAPI
{
{TileID.Presents, 6},
{TileID.Explosives, 1},
+ {TileID.MagicalIceBlock, 0},
{TileID.Crystals, 17},
{TileID.MinecartTrack, 3}
};
From d1459bb1ba9c6288783c35f5261b54ff824bfc8a Mon Sep 17 00:00:00 2001
From: Arthri <41360489+Arthri@users.noreply.github.com>
Date: Sat, 28 Aug 2021 10:42:19 +0800
Subject: [PATCH 30/32] Fix spaghetti one liner
---
TShockAPI/Bouncer.cs | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index b1aaa0ea..06a89f02 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -451,9 +451,20 @@ namespace TShockAPI
if (requestedPlaceStyle != actualItemPlaceStyle)
{
var tplayer = args.Player.TPlayer;
- var correctedPlaceStyle = actualItemPlaceStyle;
- if (!PlaceStyleCorrectors.TryGetValue(actualTileToBeCreated, out PlaceStyleCorrector corrector)
- || requestedPlaceStyle != (correctedPlaceStyle = corrector(tplayer, requestedPlaceStyle, actualItemPlaceStyle)))
+ // Search for an extraneous tile corrector
+ // If none found then it can't be a false positive so deny the action
+ if (!PlaceStyleCorrectors.TryGetValue(actualTileToBeCreated, out PlaceStyleCorrector corrector))
+ {
+ TShock.Log.ConsoleError("Bouncer / OnTileEdit rejected from (placestyle) {0} {1} {2} placeStyle: {3} expectedStyle: {4}",
+ args.Player.Name, action, editData, requestedPlaceStyle, actualItemPlaceStyle);
+ args.Player.SendTileSquare(tileX, tileY, 1);
+ args.Handled = true;
+ return;
+ }
+
+ // See if the corrector's expected style matches
+ var correctedPlaceStyle = corrector(tplayer, requestedPlaceStyle, actualItemPlaceStyle);
+ if (requestedPlaceStyle != correctedPlaceStyle)
{
TShock.Log.ConsoleError("Bouncer / OnTileEdit rejected from (placestyle) {0} {1} {2} placeStyle: {3} expectedStyle: {4}",
args.Player.Name, action, editData, requestedPlaceStyle, correctedPlaceStyle);
From 50821e7e89d4ba06502d9371cccae1f55e1566c2 Mon Sep 17 00:00:00 2001
From: Lucas Nicodemus
Date: Tue, 23 Nov 2021 18:29:57 -0800
Subject: [PATCH 31/32] Fix changelog location for GHSA-6w5v-hxr3-m2wx
---
CHANGELOG.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 68921924..c581a343 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,9 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
* Removed `TShockAPI/DB/DBTools.cs`. This appears to have been dead code and not used by anything. (@hakusaro, @DeathCradle)
* Fixed the `/firework` command not sending fireworks when specified without a firework color. The firework command now correctly sends red fireworks to a target if a color is not specified. (@hakusaro, @Kojirremer)
* Fixed bad XML of TShock code documentation. (@Arthri)
+* Fixed Bouncer exploits allowing for invalid tiles' placement. These tiles(specifically torches) caused clients to crash. The fixed exploits are listed below. (@Arthri, @QuiCM)
+ - [Biome Torch Correction](https://github.com/Pryaxis/TShock/blob/3ba1e7419d63535eeb8b5634ec668448499f71df/TShockAPI/Bouncer.cs#L310). Previously, it used unrelated values to validate biome torches, and unintentionally passed on invalid tiles. It's now fixed to use the correct values and block invalid torches. As well as a new right booster track correction/check, to allow right booster tracks to be placed. Right booster track is an extraneous place style because it depends on the direction the player is facing. The new check takes that into consideration so that the place style isn't considered mismatched and rejected.
+ - [Max Place Styles](https://github.com/Pryaxis/TShock/blob/3ba1e7419d63535eeb8b5634ec668448499f71df/TShockAPI/Bouncer.cs#L385). Previously, it rejects only if both `MaxPlaceStyles` and `ExtraneousPlaceStyles` contains an entry for a tile, and unintentionally passed on invalid tiles. `ExtraneousPlaceStyles` only contains special max placeStyles, not all placeables unlike `MaxPlaceStyles`. It's now corrected to take from `ExtraneousPlaceStyles` first, then fallback to `MaxPlaceStyles` if there's no entry for that tile, and then finally -1 if there's no entry in either.
## TShock 4.5.7
* Fixed the `/respawn` command to permit respawning players from the console. (@hakusaro, @Kojirremer)
@@ -35,9 +38,6 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
* Added a new `/respawn` command that lets you respawn yourself or another player. Respawning yourself requires the `tshock.respawn` permission and respawning others requires the `tshock.respawn.other` permission. The full command syntax is `/respawn [player]`. (@moisterrific)
* Added a notification message and silent command support for permanently changing a target player's user group. Now players who received a group change will be notified of their new group if they are currently online. (@moisterrific, @QuiCM)
* Changed the TSPlayer IP method to return the loopback IP if RealPlayer is false. (@Rozen4334)
-* Fixed Bouncer exploits allowing for invalid tiles' placement. These tiles(specifically torches) caused clients to crash. The fixed exploits are listed below. (@Arthri, @QuiCM)
- - [Biome Torch Correction](https://github.com/Pryaxis/TShock/blob/3ba1e7419d63535eeb8b5634ec668448499f71df/TShockAPI/Bouncer.cs#L310). Previously, it used unrelated values to validate biome torches, and unintentionally passed on invalid tiles. It's now fixed to use the correct values and block invalid torches. As well as a new right booster track correction/check, to allow right booster tracks to be placed. Right booster track is an extraneous place style because it depends on the direction the player is facing. The new check takes that into consideration so that the place style isn't considered mismatched and rejected.
- - [Max Place Styles](https://github.com/Pryaxis/TShock/blob/3ba1e7419d63535eeb8b5634ec668448499f71df/TShockAPI/Bouncer.cs#L385). Previously, it rejects only if both `MaxPlaceStyles` and `ExtraneousPlaceStyles` contains an entry for a tile, and unintentionally passed on invalid tiles. `ExtraneousPlaceStyles` only contains special max placeStyles, not all placeables unlike `MaxPlaceStyles`. It's now corrected to take from `ExtraneousPlaceStyles` first, then fallback to `MaxPlaceStyles` if there's no entry for that tile, and then finally -1 if there's no entry in either.
* Fixed a bug that caused sundials to be ignored all the time, instead of only when the player has no permission or time is frozen. (@Rozen4334)
* Added colours and usage examples (similiar to how the new ban system looks) for many more commands. (@moisterrific)
* Changed `RespawnSeconds` and `RespawnBossSeconds` from `10` to `0` to respect the game's default respawn timers. (@moisterrific)
From e714f8ea589a684cbd1ffd0738382041d5c5e1e6 Mon Sep 17 00:00:00 2001
From: Lucas Nicodemus
Date: Tue, 23 Nov 2021 18:31:55 -0800
Subject: [PATCH 32/32] Verison tick: 4.5.8
---
CHANGELOG.md | 3 +++
TShockAPI/Properties/AssemblyInfo.cs | 4 ++--
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c581a343..083bacc1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,9 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
* 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
+* Hopefully TShock on .NET 5?
+
+## TShock 4.5.8
* Removed `TShockAPI/DB/DBTools.cs`. This appears to have been dead code and not used by anything. (@hakusaro, @DeathCradle)
* Fixed the `/firework` command not sending fireworks when specified without a firework color. The firework command now correctly sends red fireworks to a target if a color is not specified. (@hakusaro, @Kojirremer)
* Fixed bad XML of TShock code documentation. (@Arthri)
diff --git a/TShockAPI/Properties/AssemblyInfo.cs b/TShockAPI/Properties/AssemblyInfo.cs
index fc81908d..9fe73c13 100644
--- a/TShockAPI/Properties/AssemblyInfo.cs
+++ b/TShockAPI/Properties/AssemblyInfo.cs
@@ -53,5 +53,5 @@ using System.Runtime.InteropServices;
// Also, be sure to release on github with the exact assembly version tag as below
// so that the update manager works correctly (via the Github releases api and mimic)
-[assembly: AssemblyVersion("4.5.7")]
-[assembly: AssemblyFileVersion("4.5.7")]
+[assembly: AssemblyVersion("4.5.8")]
+[assembly: AssemblyFileVersion("4.5.8")]