Terraria 1.4.0.5 Source Code

This commit is contained in:
MikeyIsBaeYT 2021-10-26 12:45:26 -04:00
commit 05205f009e
1059 changed files with 563450 additions and 0 deletions

15
Net/AddressType.cs Normal file
View file

@ -0,0 +1,15 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Net.AddressType
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
namespace Terraria.Net
{
public enum AddressType
{
Tcp,
Steam,
WeGame,
}
}

106
Net/LegacyNetBufferPool.cs Normal file
View file

@ -0,0 +1,106 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Net.LegacyNetBufferPool
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using System;
using System.Collections.Generic;
namespace Terraria.Net
{
public class LegacyNetBufferPool
{
private const int SMALL_BUFFER_SIZE = 256;
private const int MEDIUM_BUFFER_SIZE = 1024;
private const int LARGE_BUFFER_SIZE = 16384;
private static object bufferLock = new object();
private static Queue<byte[]> _smallBufferQueue = new Queue<byte[]>();
private static Queue<byte[]> _mediumBufferQueue = new Queue<byte[]>();
private static Queue<byte[]> _largeBufferQueue = new Queue<byte[]>();
private static int _smallBufferCount;
private static int _mediumBufferCount;
private static int _largeBufferCount;
private static int _customBufferCount;
public static byte[] RequestBuffer(int size)
{
lock (LegacyNetBufferPool.bufferLock)
{
if (size <= 256)
{
if (LegacyNetBufferPool._smallBufferQueue.Count != 0)
return LegacyNetBufferPool._smallBufferQueue.Dequeue();
++LegacyNetBufferPool._smallBufferCount;
return new byte[256];
}
if (size <= 1024)
{
if (LegacyNetBufferPool._mediumBufferQueue.Count != 0)
return LegacyNetBufferPool._mediumBufferQueue.Dequeue();
++LegacyNetBufferPool._mediumBufferCount;
return new byte[1024];
}
if (size <= 16384)
{
if (LegacyNetBufferPool._largeBufferQueue.Count != 0)
return LegacyNetBufferPool._largeBufferQueue.Dequeue();
++LegacyNetBufferPool._largeBufferCount;
return new byte[16384];
}
++LegacyNetBufferPool._customBufferCount;
return new byte[size];
}
}
public static byte[] RequestBuffer(byte[] data, int offset, int size)
{
byte[] numArray = LegacyNetBufferPool.RequestBuffer(size);
Buffer.BlockCopy((Array) data, offset, (Array) numArray, 0, size);
return numArray;
}
public static void ReturnBuffer(byte[] buffer)
{
int length = buffer.Length;
lock (LegacyNetBufferPool.bufferLock)
{
if (length <= 256)
LegacyNetBufferPool._smallBufferQueue.Enqueue(buffer);
else if (length <= 1024)
{
LegacyNetBufferPool._mediumBufferQueue.Enqueue(buffer);
}
else
{
if (length > 16384)
return;
LegacyNetBufferPool._largeBufferQueue.Enqueue(buffer);
}
}
}
public static void DisplayBufferSizes()
{
lock (LegacyNetBufferPool.bufferLock)
{
Main.NewText("Small Buffers: " + (object) LegacyNetBufferPool._smallBufferQueue.Count + " queued of " + (object) LegacyNetBufferPool._smallBufferCount);
Main.NewText("Medium Buffers: " + (object) LegacyNetBufferPool._mediumBufferQueue.Count + " queued of " + (object) LegacyNetBufferPool._mediumBufferCount);
Main.NewText("Large Buffers: " + (object) LegacyNetBufferPool._largeBufferQueue.Count + " queued of " + (object) LegacyNetBufferPool._largeBufferCount);
Main.NewText("Custom Buffers: 0 queued of " + (object) LegacyNetBufferPool._customBufferCount);
}
}
public static void PrintBufferSizes()
{
lock (LegacyNetBufferPool.bufferLock)
{
Console.WriteLine("Small Buffers: " + (object) LegacyNetBufferPool._smallBufferQueue.Count + " queued of " + (object) LegacyNetBufferPool._smallBufferCount);
Console.WriteLine("Medium Buffers: " + (object) LegacyNetBufferPool._mediumBufferQueue.Count + " queued of " + (object) LegacyNetBufferPool._mediumBufferCount);
Console.WriteLine("Large Buffers: " + (object) LegacyNetBufferPool._largeBufferQueue.Count + " queued of " + (object) LegacyNetBufferPool._largeBufferCount);
Console.WriteLine("Custom Buffers: 0 queued of " + (object) LegacyNetBufferPool._customBufferCount);
Console.WriteLine("");
}
}
}
}

96
Net/NetGroupInfo.cs Normal file
View file

@ -0,0 +1,96 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Net.NetGroupInfo
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using System;
using System.Collections.Generic;
namespace Terraria.Net
{
public class NetGroupInfo
{
private readonly string[] _separatorBetweenInfos = new string[1]
{
", "
};
private readonly string[] _separatorBetweenIdAndInfo = new string[1]
{
":"
};
private List<NetGroupInfo.INetGroupInfoProvider> _infoProviders;
public NetGroupInfo()
{
this._infoProviders = new List<NetGroupInfo.INetGroupInfoProvider>();
this._infoProviders.Add((NetGroupInfo.INetGroupInfoProvider) new NetGroupInfo.IPAddressInfoProvider());
this._infoProviders.Add((NetGroupInfo.INetGroupInfoProvider) new NetGroupInfo.SteamLobbyInfoProvider());
}
public string ComposeInfo()
{
List<string> stringList = new List<string>();
foreach (NetGroupInfo.INetGroupInfoProvider infoProvider in this._infoProviders)
{
if (infoProvider.HasValidInfo)
{
string safeInfo = this.ConvertToSafeInfo(((int) infoProvider.Id).ToString() + this._separatorBetweenIdAndInfo[0] + infoProvider.ProvideInfoNeededToJoin());
stringList.Add(safeInfo);
}
}
return string.Join(this._separatorBetweenInfos[0], stringList.ToArray());
}
public Dictionary<NetGroupInfo.InfoProviderId, string> DecomposeInfo(
string info)
{
Dictionary<NetGroupInfo.InfoProviderId, string> dictionary = new Dictionary<NetGroupInfo.InfoProviderId, string>();
foreach (string text in info.Split(this._separatorBetweenInfos, StringSplitOptions.RemoveEmptyEntries))
{
string[] strArray = this.ConvertFromSafeInfo(text).Split(this._separatorBetweenIdAndInfo, StringSplitOptions.RemoveEmptyEntries);
int result;
if (strArray.Length == 2 && int.TryParse(strArray[0], out result))
dictionary[(NetGroupInfo.InfoProviderId) result] = strArray[1];
}
return dictionary;
}
private string ConvertToSafeInfo(string text) => Uri.EscapeDataString(text);
private string ConvertFromSafeInfo(string text) => Uri.UnescapeDataString(text);
public enum InfoProviderId
{
IPAddress,
Steam,
}
private interface INetGroupInfoProvider
{
NetGroupInfo.InfoProviderId Id { get; }
bool HasValidInfo { get; }
string ProvideInfoNeededToJoin();
}
private class IPAddressInfoProvider : NetGroupInfo.INetGroupInfoProvider
{
public NetGroupInfo.InfoProviderId Id => NetGroupInfo.InfoProviderId.IPAddress;
public bool HasValidInfo => false;
public string ProvideInfoNeededToJoin() => "";
}
private class SteamLobbyInfoProvider : NetGroupInfo.INetGroupInfoProvider
{
public NetGroupInfo.InfoProviderId Id => NetGroupInfo.InfoProviderId.Steam;
public bool HasValidInfo => Main.LobbyId > 0UL;
public string ProvideInfoNeededToJoin() => Main.LobbyId.ToString();
}
}
}

130
Net/NetManager.cs Normal file
View file

@ -0,0 +1,130 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Net.NetManager
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using System.Collections.Generic;
using System.IO;
using Terraria.Net.Sockets;
namespace Terraria.Net
{
public class NetManager
{
public static readonly NetManager Instance = new NetManager();
private Dictionary<ushort, NetModule> _modules = new Dictionary<ushort, NetModule>();
private ushort _moduleCount;
private NetManager()
{
}
public void Register<T>() where T : NetModule, new()
{
T obj = new T();
NetManager.PacketTypeStorage<T>.Id = this._moduleCount;
NetManager.PacketTypeStorage<T>.Module = obj;
this._modules[this._moduleCount] = (NetModule) obj;
++this._moduleCount;
}
public NetModule GetModule<T>() where T : NetModule => (NetModule) NetManager.PacketTypeStorage<T>.Module;
public ushort GetId<T>() where T : NetModule => NetManager.PacketTypeStorage<T>.Id;
public void Read(BinaryReader reader, int userId, int readLength)
{
ushort key = reader.ReadUInt16();
if (this._modules.ContainsKey(key))
this._modules[key].Deserialize(reader, userId);
Main.ActiveNetDiagnosticsUI.CountReadModuleMessage((int) key, readLength);
}
public void Broadcast(NetPacket packet, int ignoreClient = -1)
{
for (int index = 0; index < 256; ++index)
{
if (index != ignoreClient && Netplay.Clients[index].IsConnected())
this.SendData(Netplay.Clients[index].Socket, packet);
}
}
public void Broadcast(
NetPacket packet,
NetManager.BroadcastCondition conditionToBroadcast,
int ignoreClient = -1)
{
for (int clientIndex = 0; clientIndex < 256; ++clientIndex)
{
if (clientIndex != ignoreClient && Netplay.Clients[clientIndex].IsConnected() && conditionToBroadcast(clientIndex))
this.SendData(Netplay.Clients[clientIndex].Socket, packet);
}
}
public void SendToSelf(NetPacket packet)
{
packet.Reader.BaseStream.Position = 3L;
this.Read(packet.Reader, Main.myPlayer, packet.Length);
NetManager.SendCallback((object) packet);
Main.ActiveNetDiagnosticsUI.CountSentModuleMessage((int) packet.Id, packet.Length);
}
public void BroadcastOrLoopback(NetPacket packet)
{
if (Main.netMode == 2)
{
this.Broadcast(packet);
}
else
{
if (Main.netMode != 0)
return;
this.SendToSelf(packet);
}
}
public void SendToServerOrLoopback(NetPacket packet)
{
if (Main.netMode == 1)
{
this.SendToServer(packet);
}
else
{
if (Main.netMode != 0)
return;
this.SendToSelf(packet);
}
}
public void SendToServer(NetPacket packet) => this.SendData(Netplay.Connection.Socket, packet);
public void SendToClient(NetPacket packet, int playerId) => this.SendData(Netplay.Clients[playerId].Socket, packet);
private void SendData(ISocket socket, NetPacket packet)
{
if (Main.netMode == 0)
return;
packet.ShrinkToFit();
try
{
socket.AsyncSend(packet.Buffer.Data, 0, packet.Length, new SocketSendCallback(NetManager.SendCallback), (object) packet);
}
catch
{
}
Main.ActiveNetDiagnosticsUI.CountSentModuleMessage((int) packet.Id, packet.Length);
}
public static void SendCallback(object state) => ((NetPacket) state).Recycle();
private class PacketTypeStorage<T> where T : NetModule
{
public static ushort Id;
public static T Module;
}
public delegate bool BroadcastCondition(int clientIndex);
}
}

17
Net/NetModule.cs Normal file
View file

@ -0,0 +1,17 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Net.NetModule
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using System.IO;
namespace Terraria.Net
{
public abstract class NetModule
{
public abstract bool Deserialize(BinaryReader reader, int userId);
protected static NetPacket CreatePacket<T>(int maxSize) where T : NetModule => new NetPacket(NetManager.Instance.GetId<T>(), maxSize);
}
}

47
Net/NetPacket.cs Normal file
View file

@ -0,0 +1,47 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Net.NetPacket
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using System.IO;
using Terraria.DataStructures;
namespace Terraria.Net
{
public struct NetPacket
{
private const int HEADER_SIZE = 5;
public readonly ushort Id;
public readonly CachedBuffer Buffer;
public int Length { get; private set; }
public BinaryWriter Writer => this.Buffer.Writer;
public BinaryReader Reader => this.Buffer.Reader;
public NetPacket(ushort id, int size)
: this()
{
this.Id = id;
this.Buffer = BufferPool.Request(size + 5);
this.Length = size + 5;
this.Writer.Write((ushort) (size + 5));
this.Writer.Write((byte) 82);
this.Writer.Write(id);
}
public void Recycle() => this.Buffer.Recycle();
public void ShrinkToFit()
{
if (this.Length == (int) this.Writer.BaseStream.Position)
return;
this.Length = (int) this.Writer.BaseStream.Position;
this.Writer.Seek(0, SeekOrigin.Begin);
this.Writer.Write((ushort) this.Length);
this.Writer.Seek(this.Length, SeekOrigin.Begin);
}
}
}

19
Net/RemoteAddress.cs Normal file
View file

@ -0,0 +1,19 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Net.RemoteAddress
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
namespace Terraria.Net
{
public abstract class RemoteAddress
{
public AddressType Type;
public abstract string GetIdentifier();
public abstract string GetFriendlyName();
public abstract bool IsLocalHost();
}
}

19
Net/ServerMode.cs Normal file
View file

@ -0,0 +1,19 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Net.ServerMode
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using System;
namespace Terraria.Net
{
[Flags]
public enum ServerMode : byte
{
None = 0,
Lobby = 1,
FriendsCanJoin = 2,
FriendsOfFriends = 4,
}
}

36
Net/Sockets/ISocket.cs Normal file
View file

@ -0,0 +1,36 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Net.Sockets.ISocket
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
namespace Terraria.Net.Sockets
{
public interface ISocket
{
void Close();
bool IsConnected();
void Connect(RemoteAddress address);
void AsyncSend(byte[] data, int offset, int size, SocketSendCallback callback, object state = null);
void AsyncReceive(
byte[] data,
int offset,
int size,
SocketReceiveCallback callback,
object state = null);
bool IsDataAvailable();
void SendQueuedPackets();
bool StartListening(SocketConnectionAccepted callback);
void StopListening();
RemoteAddress GetRemoteAddress();
}
}

View file

@ -0,0 +1,92 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Net.Sockets.SocialSocket
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using System;
using System.Threading;
using Terraria.Social;
namespace Terraria.Net.Sockets
{
public class SocialSocket : ISocket
{
private RemoteAddress _remoteAddress;
public SocialSocket()
{
}
public SocialSocket(RemoteAddress remoteAddress) => this._remoteAddress = remoteAddress;
void ISocket.Close()
{
if (this._remoteAddress == null)
return;
SocialAPI.Network.Close(this._remoteAddress);
this._remoteAddress = (RemoteAddress) null;
}
bool ISocket.IsConnected() => SocialAPI.Network.IsConnected(this._remoteAddress);
void ISocket.Connect(RemoteAddress address)
{
this._remoteAddress = address;
SocialAPI.Network.Connect(address);
}
void ISocket.AsyncSend(
byte[] data,
int offset,
int size,
SocketSendCallback callback,
object state)
{
SocialAPI.Network.Send(this._remoteAddress, data, size);
callback.BeginInvoke(state, (AsyncCallback) null, (object) null);
}
private void ReadCallback(
byte[] data,
int offset,
int size,
SocketReceiveCallback callback,
object state)
{
int size1;
while ((size1 = SocialAPI.Network.Receive(this._remoteAddress, data, offset, size)) == 0)
Thread.Sleep(1);
callback(state, size1);
}
void ISocket.AsyncReceive(
byte[] data,
int offset,
int size,
SocketReceiveCallback callback,
object state)
{
new SocialSocket.InternalReadCallback(this.ReadCallback).BeginInvoke(data, offset, size, callback, state, (AsyncCallback) null, (object) null);
}
void ISocket.SendQueuedPackets()
{
}
bool ISocket.IsDataAvailable() => SocialAPI.Network.IsDataAvailable(this._remoteAddress);
RemoteAddress ISocket.GetRemoteAddress() => this._remoteAddress;
bool ISocket.StartListening(SocketConnectionAccepted callback) => SocialAPI.Network.StartListening(callback);
void ISocket.StopListening() => SocialAPI.Network.StopListening();
private delegate void InternalReadCallback(
byte[] data,
int offset,
int size,
SocketReceiveCallback callback,
object state);
}
}

View file

@ -0,0 +1,10 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Net.Sockets.SocketConnectionAccepted
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
namespace Terraria.Net.Sockets
{
public delegate void SocketConnectionAccepted(ISocket client);
}

View file

@ -0,0 +1,10 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Net.Sockets.SocketReceiveCallback
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
namespace Terraria.Net.Sockets
{
public delegate void SocketReceiveCallback(object state, int size);
}

View file

@ -0,0 +1,10 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Net.Sockets.SocketSendCallback
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
namespace Terraria.Net.Sockets
{
public delegate void SocketSendCallback(object state);
}

155
Net/Sockets/TcpSocket.cs Normal file
View file

@ -0,0 +1,155 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Net.Sockets.TcpSocket
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Terraria.Localization;
namespace Terraria.Net.Sockets
{
public class TcpSocket : ISocket
{
private byte[] _packetBuffer = new byte[1024];
private List<object> _callbackBuffer = new List<object>();
private int _messagesInQueue;
private TcpClient _connection;
private TcpListener _listener;
private SocketConnectionAccepted _listenerCallback;
private RemoteAddress _remoteAddress;
private bool _isListening;
public int MessagesInQueue => this._messagesInQueue;
public TcpSocket() => this._connection = new TcpClient()
{
NoDelay = true
};
public TcpSocket(TcpClient tcpClient)
{
this._connection = tcpClient;
this._connection.NoDelay = true;
IPEndPoint remoteEndPoint = (IPEndPoint) tcpClient.Client.RemoteEndPoint;
this._remoteAddress = (RemoteAddress) new TcpAddress(remoteEndPoint.Address, remoteEndPoint.Port);
}
void ISocket.Close()
{
this._remoteAddress = (RemoteAddress) null;
this._connection.Close();
}
bool ISocket.IsConnected() => this._connection != null && this._connection.Client != null && this._connection.Connected;
void ISocket.Connect(RemoteAddress address)
{
TcpAddress tcpAddress = (TcpAddress) address;
this._connection.Connect(tcpAddress.Address, tcpAddress.Port);
this._remoteAddress = address;
}
private void ReadCallback(IAsyncResult result)
{
Tuple<SocketReceiveCallback, object> asyncState = (Tuple<SocketReceiveCallback, object>) result.AsyncState;
asyncState.Item1(asyncState.Item2, this._connection.GetStream().EndRead(result));
}
private void SendCallback(IAsyncResult result)
{
Tuple<SocketSendCallback, object> asyncState = (Tuple<SocketSendCallback, object>) result.AsyncState;
try
{
this._connection.GetStream().EndWrite(result);
asyncState.Item1(asyncState.Item2);
}
catch (Exception ex)
{
((ISocket) this).Close();
}
}
void ISocket.SendQueuedPackets()
{
}
void ISocket.AsyncSend(
byte[] data,
int offset,
int size,
SocketSendCallback callback,
object state)
{
this._connection.GetStream().BeginWrite(data, 0, size, new AsyncCallback(this.SendCallback), (object) new Tuple<SocketSendCallback, object>(callback, state));
}
void ISocket.AsyncReceive(
byte[] data,
int offset,
int size,
SocketReceiveCallback callback,
object state)
{
this._connection.GetStream().BeginRead(data, offset, size, new AsyncCallback(this.ReadCallback), (object) new Tuple<SocketReceiveCallback, object>(callback, state));
}
bool ISocket.IsDataAvailable() => this._connection.Connected && this._connection.GetStream().DataAvailable;
RemoteAddress ISocket.GetRemoteAddress() => this._remoteAddress;
bool ISocket.StartListening(SocketConnectionAccepted callback)
{
IPAddress address = IPAddress.Any;
string ipString;
if (Program.LaunchParameters.TryGetValue("-ip", out ipString) && !IPAddress.TryParse(ipString, out address))
address = IPAddress.Any;
this._isListening = true;
this._listenerCallback = callback;
if (this._listener == null)
this._listener = new TcpListener(address, Netplay.ListenPort);
try
{
this._listener.Start();
}
catch (Exception ex)
{
return false;
}
new Thread(new ThreadStart(this.ListenLoop))
{
IsBackground = true,
Name = "TCP Listen Thread"
}.Start();
return true;
}
void ISocket.StopListening() => this._isListening = false;
private void ListenLoop()
{
while (this._isListening)
{
if (!Netplay.Disconnect)
{
try
{
ISocket client = (ISocket) new TcpSocket(this._listener.AcceptTcpClient());
Console.WriteLine(Language.GetTextValue("Net.ClientConnecting", (object) client.GetRemoteAddress()));
this._listenerCallback(client);
}
catch (Exception ex)
{
}
}
else
break;
}
this._listener.Stop();
}
}
}

35
Net/SteamAddress.cs Normal file
View file

@ -0,0 +1,35 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Net.SteamAddress
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Steamworks;
namespace Terraria.Net
{
public class SteamAddress : RemoteAddress
{
public readonly CSteamID SteamId;
private string _friendlyName;
public SteamAddress(CSteamID steamId)
{
this.Type = AddressType.Steam;
this.SteamId = steamId;
}
public override string ToString() => "STEAM_0:" + ((ulong) this.SteamId.m_SteamID % 2UL).ToString() + ":" + ((ulong) (this.SteamId.m_SteamID - (76561197960265728L + this.SteamId.m_SteamID % 2L)) / 2UL).ToString();
public override string GetIdentifier() => this.ToString();
public override bool IsLocalHost() => Program.LaunchParameters.ContainsKey("-localsteamid") && Program.LaunchParameters["-localsteamid"].Equals(__nonvirtual (this.SteamId.m_SteamID.ToString()));
public override string GetFriendlyName()
{
if (this._friendlyName == null)
this._friendlyName = SteamFriends.GetFriendPersonaName(this.SteamId);
return this._friendlyName;
}
}
}

31
Net/TcpAddress.cs Normal file
View file

@ -0,0 +1,31 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Net.TcpAddress
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using System.Net;
namespace Terraria.Net
{
public class TcpAddress : RemoteAddress
{
public IPAddress Address;
public int Port;
public TcpAddress(IPAddress address, int port)
{
this.Type = AddressType.Tcp;
this.Address = address;
this.Port = port;
}
public override string GetIdentifier() => this.Address.ToString();
public override bool IsLocalHost() => this.Address.Equals((object) IPAddress.Loopback);
public override string ToString() => new IPEndPoint(this.Address, this.Port).ToString();
public override string GetFriendlyName() => this.ToString();
}
}

31
Net/WeGameAddress.cs Normal file
View file

@ -0,0 +1,31 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Net.WeGameAddress
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using rail;
namespace Terraria.Net
{
public class WeGameAddress : RemoteAddress
{
public readonly RailID rail_id;
private string nickname;
public WeGameAddress(RailID id, string name)
{
this.Type = AddressType.WeGame;
this.rail_id = id;
this.nickname = name;
}
public override string ToString() => "WEGAME_0:" + __nonvirtual (((RailComparableID) this.rail_id).id_.ToString());
public override string GetIdentifier() => this.ToString();
public override bool IsLocalHost() => Program.LaunchParameters.ContainsKey("-localwegameid") && Program.LaunchParameters["-localwegameid"].Equals(__nonvirtual (((RailComparableID) this.rail_id).id_.ToString()));
public override string GetFriendlyName() => this.nickname;
}
}