From 9910725258a8fd874bbded58ed7b06ea9eb7eaaf Mon Sep 17 00:00:00 2001
From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com>
Date: Tue, 30 Nov 2021 20:45:56 +0700
Subject: [PATCH 1/5] Update CHANGELOG.md
---
CHANGELOG.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 62a73f8c..ef058577 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
## TShock 4.5.12
* Fixed the ability to spawn Zenith projectile with non-original items. (@AgaSpace)
+* Fixed the ability to create custom messages with your death (or the death of another player) (@AgaSpace)
## TShock 4.5.11
* Add the new allowed buff TentacleSpike to NPC buff cheat detection bouncer. (@sgkoishi)
From 8f69c6e767c85caa2a7803eb7a01481a8d364468 Mon Sep 17 00:00:00 2001
From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com>
Date: Tue, 30 Nov 2021 20:50:51 +0700
Subject: [PATCH 2/5] Created a new field in config.
---
TShockAPI/Configuration/TShockConfig.cs | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/TShockAPI/Configuration/TShockConfig.cs b/TShockAPI/Configuration/TShockConfig.cs
index 2c643fab..d87dfa22 100644
--- a/TShockAPI/Configuration/TShockConfig.cs
+++ b/TShockAPI/Configuration/TShockConfig.cs
@@ -460,6 +460,10 @@ namespace TShockAPI.Configuration
/// Prohibit the use of Zenith projectile with different objects instead of weapons.
[Description("Prohibit the use of Zenith projectile with different objects instead of weapons.")]
public bool DisableModifiedZenith = false;
+
+ /// Allows you to disable or enable protection against creating custom messages with death. Created for developers who came up with a more original solution to this problem.
+ [Description("Allows you to disable or enable protection against creating custom messages with death. Created for developers who came up with a more original solution to this problem.")]
+ public bool DisableCustomDeathMessages = true;
#endregion
From cdeec8aa040079c6e9890bc1ed22d90979a6978e Mon Sep 17 00:00:00 2001
From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com>
Date: Tue, 30 Nov 2021 20:53:19 +0700
Subject: [PATCH 3/5] Added protection in OnKillMe
---
TShockAPI/Bouncer.cs | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 2145b373..3216d769 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -2279,6 +2279,12 @@ namespace TShockAPI
args.Handled = true;
return;
}
+ if (TShock.Config.Settings.DisableCustomDeathMessages && playerDeathReason._sourceCustomReason != null)
+ {
+ TShock.Log.ConsoleDebug("Bouncer / OnKillMe rejected custom death message from {0}", args.Player.Name);
+ args.Handled = true;
+ return;
+ }
}
}
From a00512fcf45d32750930371637694e6da71bdcd9 Mon Sep 17 00:00:00 2001
From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com>
Date: Tue, 30 Nov 2021 21:14:53 +0700
Subject: [PATCH 4/5] Added protection to OnPlayerDamage
---
TShockAPI/Bouncer.cs | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 3216d769..deca614e 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -2178,6 +2178,7 @@ namespace TShockAPI
bool pvp = args.PVP;
bool crit = args.Critical;
byte direction = args.Direction;
+ PlayerDeathReason reason = args.PlayerDeathReason;
if (id >= Main.maxPlayers || TShock.Players[id] == null)
{
@@ -2242,6 +2243,17 @@ namespace TShockAPI
return;
}
+ /*
+ * A player must take damage from another player in any case
+ * I didn't add sourceProjectile because the player can't always die from a projectile.
+ */
+ if (TShock.Config.Settings.DisableCustomDeathMessages &&
+ (reason._sourcePlayerIndex == -1 || reason._sourceNPCIndex != -1 || reason._sourceOtherIndex != -1 || reason._sourceCustomReason != null))
+ {
+ TShock.Log.ConsoleDebug("Bouncer / OnPlayerDamage rejected custom death message from {0}", args.Player.Name);
+ args.Handled = true;
+ return;
+ }
}
/// Bouncer's KillMe hook stops crash exploits from out of bounds values.
From 823293ed4399e42fe27c4f22c41f449a00ec1a0d Mon Sep 17 00:00:00 2001
From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com>
Date: Thu, 2 Dec 2021 10:03:36 +0700
Subject: [PATCH 5/5] Updated code comments
---
TShockAPI/Bouncer.cs | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index deca614e..1d1ccf26 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -2244,8 +2244,11 @@ namespace TShockAPI
}
/*
- * A player must take damage from another player in any case
- * I didn't add sourceProjectile because the player can't always die from a projectile.
+ * PlayerDeathReason does not initially contain any information, so all fields have values -1 or null.
+ * We can use this to determine the real cause of death.
+ *
+ * If the player was not specified, that is, the player index is -1, then it is definitely a custom cause, as you can only deal damage with a projectile or another player.
+ * This is how everything else works. If an NPC is specified, its value is not -1, which is a custom cause.
*/
if (TShock.Config.Settings.DisableCustomDeathMessages &&
(reason._sourcePlayerIndex == -1 || reason._sourceNPCIndex != -1 || reason._sourceOtherIndex != -1 || reason._sourceCustomReason != null))