Skip to content

Commit

Permalink
Add protocol support for Terraria 1.4.3.1
Browse files Browse the repository at this point in the history
Adds compatibility for servers running on 1.4.3.1. Support for 1.4.3.0 is also included in this patch.
  • Loading branch information
Moneylover3246 committed Nov 23, 2021
1 parent 4296704 commit c08eb0b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
44 changes: 27 additions & 17 deletions Crossplay/CrossplayPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public class CrossplayPlugin : TerrariaPlugin
public override string Name => "Crossplay";
public override string Author => "Moneylover3246";
public override string Description => "Enables crossplay for terraria";
public override Version Version => new Version("1.5.1");
public override Version Version => new Version("1.6.0");

private readonly List<int> AllowedVersions = new List<int>() { 230, 233, 234, 235, 236, 237, 238 };
private readonly List<int> AllowedVersions = new List<int>() { 230, 233, 234, 235, 236, 237, 238, 242 };

public static string ConfigPath => Path.Combine("tshock", "Crossplay.json");

Expand All @@ -40,6 +40,7 @@ public class CrossplayPlugin : TerrariaPlugin
{ 236, 664 },
{ 237, 666 },
{ 238, 667 },
{ 242, 669 },
};
public static readonly Dictionary<int, int> MaxTileType = new Dictionary<int, int>()
{
Expand All @@ -50,6 +51,7 @@ public class CrossplayPlugin : TerrariaPlugin
{ 236, 623 },
{ 237, 623 },
{ 238, 623 },
{ 242, 624 },
};
public static readonly Dictionary<int, int> MaxBuffType = new Dictionary<int, int>()
{
Expand All @@ -60,6 +62,7 @@ public class CrossplayPlugin : TerrariaPlugin
{ 236, 329 },
{ 237, 329 },
{ 238, 329 },
{ 242, 335 },
};
public static readonly Dictionary<int, int> MaxProjectileType = new Dictionary<int, int>()
{
Expand All @@ -69,7 +72,8 @@ public class CrossplayPlugin : TerrariaPlugin
{ 235, 955 },
{ 236, 955 },
{ 237, 955 },
{ 238, 955 }
{ 238, 955 },
{ 242, 970 },
};
public static readonly Dictionary<int, int> MaxItemType = new Dictionary<int, int>()
{
Expand All @@ -80,6 +84,7 @@ public class CrossplayPlugin : TerrariaPlugin
{ 236, 5087 },
{ 237, 5087 },
{ 238, 5087 },
{ 242, 5124 },
};

public CrossplayPlugin(Main game) : base(game)
Expand Down Expand Up @@ -149,21 +154,23 @@ private void GetData(GetDataEventArgs args)
if ((int)args.MsgID == 1)
{
string versionstring = reader.ReadString();
if (int.TryParse(versionstring.Substring(versionstring.Length - 3), out int version))
if (!int.TryParse(versionstring.Substring(versionstring.Length - 3), out int version))
{
if (AllowedVersions.Contains(version))
{
ClientVersions[index] = version;
NetMessage.SendData(9, args.Msg.whoAmI, -1, NetworkText.FromLiteral("Fixing Version..."), 1);
byte[] connectRequest = new PacketFactory()
.SetType(1)
.PackString($"Terraria{Main.curRelease}")
.GetByteData();
Log($"Changing version of index {args.Msg.whoAmI} from {Convert(version)} => {Convert(Main.curRelease)}", color: ConsoleColor.Green);

Buffer.BlockCopy(connectRequest, 0, args.Msg.readBuffer, args.Index - 3, connectRequest.Length);
}
return;
}
if (!AllowedVersions.Contains(version))
{
return;
}
ClientVersions[index] = version;
NetMessage.SendData(9, args.Msg.whoAmI, -1, NetworkText.FromLiteral("Fixing Version..."), 1);
byte[] connectRequest = new PacketFactory()
.SetType(1)
.PackString($"Terraria{Main.curRelease}")
.GetByteData();
Log($"Changing version of index {args.Msg.whoAmI} from {Convert(version)} => {Convert(Main.curRelease)}", color: ConsoleColor.Green);

Buffer.BlockCopy(connectRequest, 0, args.Msg.readBuffer, args.Index - 3, connectRequest.Length);
return;
}
if (ClientVersions[index] == 0)
Expand Down Expand Up @@ -606,22 +613,25 @@ private string Convert(int version)
return "v1.4.2.3";
case "Terraria242":
return "v1.4.3";
case "Terraria243":
return "v1.4.3.1";
}
return $"Unknown{version}";
}

public static void Log(string message, bool debug = false, ConsoleColor color = ConsoleColor.White)
{
Console.ForegroundColor = color;
if (debug)
{
if (Config.Settings.EnablePacketDebugging)
{
Console.ForegroundColor = color;
Console.WriteLine($"[Crossplay Debug] {message}");
Console.ResetColor();
}
return;
}
Console.ForegroundColor = color;
Console.WriteLine($"[Crossplay] {message}");
Console.ResetColor();
}
Expand Down
6 changes: 3 additions & 3 deletions Crossplay/obj/Release/net45/Crossplay.AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

[assembly: System.Reflection.AssemblyCompanyAttribute("Crossplay")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.5.1")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.5.1")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.6.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.6.0")]
[assembly: System.Reflection.AssemblyProductAttribute("Crossplay")]
[assembly: System.Reflection.AssemblyTitleAttribute("Crossplay")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.5.1")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.6.0")]

// Generated by the MSBuild WriteCodeFragment class.

Binary file modified References/OTAPI.dll
Binary file not shown.
Binary file modified References/TShockAPI.dll
Binary file not shown.
Binary file modified References/TerrariaServer.exe
Binary file not shown.

0 comments on commit c08eb0b

Please sign in to comment.