Terraria 1.3.5.3 Source Code

This commit is contained in:
MikeyIsBaeYT 2021-10-27 18:03:19 -04:00
commit 4b21dac4b6
503 changed files with 409032 additions and 0 deletions

32
Chat/ChatCommandId.cs Normal file
View file

@ -0,0 +1,32 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Chat.ChatCommandId
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using ReLogic.Utilities;
using System.IO;
using System.Text;
using Terraria.Chat.Commands;
namespace Terraria.Chat
{
public struct ChatCommandId
{
private readonly string _name;
private ChatCommandId(string name) => this._name = name;
public static ChatCommandId FromType<T>() where T : IChatCommand
{
ChatCommandAttribute cacheableAttribute = AttributeUtilities.GetCacheableAttribute<T, ChatCommandAttribute>();
return cacheableAttribute != null ? new ChatCommandId(cacheableAttribute.Name) : new ChatCommandId((string) null);
}
public void Serialize(BinaryWriter writer) => writer.Write(this._name ?? "");
public static ChatCommandId Deserialize(BinaryReader reader) => new ChatCommandId(reader.ReadString());
public int GetMaxSerializedSize() => 4 + Encoding.UTF8.GetByteCount(this._name ?? "");
}
}

View file

@ -0,0 +1,87 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Chat.ChatCommandProcessor
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using ReLogic.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria.Chat.Commands;
using Terraria.Localization;
namespace Terraria.Chat
{
public class ChatCommandProcessor : IChatProcessor
{
private Dictionary<LocalizedText, ChatCommandId> _localizedCommands = new Dictionary<LocalizedText, ChatCommandId>();
private Dictionary<ChatCommandId, IChatCommand> _commands = new Dictionary<ChatCommandId, IChatCommand>();
private IChatCommand _defaultCommand;
public ChatCommandProcessor AddCommand<T>() where T : IChatCommand, new()
{
string commandKey = "ChatCommand." + AttributeUtilities.GetCacheableAttribute<T, ChatCommandAttribute>().Name;
ChatCommandId key1 = ChatCommandId.FromType<T>();
this._commands[key1] = (IChatCommand) new T();
if (Language.Exists(commandKey))
{
this._localizedCommands.Add(Language.GetText(commandKey), key1);
}
else
{
commandKey += "_";
foreach (LocalizedText key2 in Language.FindAll((LanguageSearchFilter) ((key, text) => key.StartsWith(commandKey))))
this._localizedCommands.Add(key2, key1);
}
return this;
}
public ChatCommandProcessor AddDefaultCommand<T>() where T : IChatCommand, new()
{
this.AddCommand<T>();
this._defaultCommand = this._commands[ChatCommandId.FromType<T>()];
return this;
}
private static bool HasLocalizedCommand(ChatMessage message, LocalizedText command)
{
string lower = message.Text.ToLower();
string str = command.Value;
if (!lower.StartsWith(str))
return false;
return lower.Length == str.Length || lower[str.Length] == ' ';
}
private static string RemoveCommandPrefix(string messageText, LocalizedText command)
{
string str = command.Value;
return !messageText.StartsWith(str) || messageText.Length == str.Length || messageText[str.Length] != ' ' ? "" : messageText.Substring(str.Length + 1);
}
public bool ProcessOutgoingMessage(ChatMessage message)
{
KeyValuePair<LocalizedText, ChatCommandId> keyValuePair = this._localizedCommands.FirstOrDefault<KeyValuePair<LocalizedText, ChatCommandId>>((Func<KeyValuePair<LocalizedText, ChatCommandId>, bool>) (pair => ChatCommandProcessor.HasLocalizedCommand(message, pair.Key)));
ChatCommandId commandId = keyValuePair.Value;
if (keyValuePair.Key == null)
return false;
message.SetCommand(commandId);
message.Text = ChatCommandProcessor.RemoveCommandPrefix(message.Text, keyValuePair.Key);
return true;
}
public bool ProcessReceivedMessage(ChatMessage message, int clientId)
{
IChatCommand chatCommand;
if (this._commands.TryGetValue(message.CommandId, out chatCommand))
{
chatCommand.ProcessMessage(message.Text, (byte) clientId);
return true;
}
if (this._defaultCommand == null)
return false;
this._defaultCommand.ProcessMessage(message.Text, (byte) clientId);
return true;
}
}
}

49
Chat/ChatMessage.cs Normal file
View file

@ -0,0 +1,49 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Chat.ChatMessage
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using System.IO;
using System.Text;
using Terraria.Chat.Commands;
namespace Terraria.Chat
{
public class ChatMessage
{
public ChatCommandId CommandId { get; private set; }
public string Text { get; set; }
public ChatMessage(string message)
{
this.CommandId = ChatCommandId.FromType<SayChatCommand>();
this.Text = message;
}
private ChatMessage(string message, ChatCommandId commandId)
{
this.CommandId = commandId;
this.Text = message;
}
public void Serialize(BinaryWriter writer)
{
this.CommandId.Serialize(writer);
writer.Write(this.Text);
}
public int GetMaxSerializedSize() => 0 + this.CommandId.GetMaxSerializedSize() + (4 + Encoding.UTF8.GetByteCount(this.Text));
public static ChatMessage Deserialize(BinaryReader reader)
{
ChatCommandId commandId = ChatCommandId.Deserialize(reader);
return new ChatMessage(reader.ReadString(), commandId);
}
public void SetCommand(ChatCommandId commandId) => this.CommandId = commandId;
public void SetCommand<T>() where T : IChatCommand => this.CommandId = ChatCommandId.FromType<T>();
}
}

View file

@ -0,0 +1,18 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Chat.Commands.ChatCommandAttribute
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using System;
namespace Terraria.Chat.Commands
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = false, Inherited = false)]
public sealed class ChatCommandAttribute : Attribute
{
public readonly string Name;
public ChatCommandAttribute(string name) => this.Name = name;
}
}

View file

@ -0,0 +1,25 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Chat.Commands.EmoteCommand
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using Terraria.Localization;
namespace Terraria.Chat.Commands
{
[ChatCommand("Emote")]
public class EmoteCommand : IChatCommand
{
private static readonly Color RESPONSE_COLOR = new Color(200, 100, 0);
public void ProcessMessage(string text, byte clientId)
{
if (!(text != ""))
return;
text = string.Format("*{0} {1}", (object) Main.player[(int) clientId].name, (object) text);
NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(text), EmoteCommand.RESPONSE_COLOR);
}
}
}

View file

@ -0,0 +1,13 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Chat.Commands.IChatCommand
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
namespace Terraria.Chat.Commands
{
public interface IChatCommand
{
void ProcessMessage(string text, byte clientId);
}
}

View file

@ -0,0 +1,22 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Chat.Commands.ListPlayersCommand
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria.Localization;
namespace Terraria.Chat.Commands
{
[ChatCommand("Playing")]
public class ListPlayersCommand : IChatCommand
{
private static readonly Color RESPONSE_COLOR = new Color((int) byte.MaxValue, 240, 20);
public void ProcessMessage(string text, byte clientId) => NetMessage.SendChatMessageToClient(NetworkText.FromLiteral(string.Join(", ", ((IEnumerable<Player>) Main.player).Where<Player>((Func<Player, bool>) (player => player.active)).Select<Player, string>((Func<Player, string>) (player => player.name)))), ListPlayersCommand.RESPONSE_COLOR, (int) clientId);
}
}

View file

@ -0,0 +1,48 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Chat.Commands.PartyChatCommand
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using Terraria.GameContent.NetModules;
using Terraria.Localization;
using Terraria.Net;
namespace Terraria.Chat.Commands
{
[ChatCommand("Party")]
public class PartyChatCommand : IChatCommand
{
private static readonly Color ERROR_COLOR = new Color((int) byte.MaxValue, 240, 20);
public void ProcessMessage(string text, byte clientId)
{
int team = Main.player[(int) clientId].team;
Color color = Main.teamColor[team];
if (team == 0)
{
this.SendNoTeamError(clientId);
}
else
{
if (text == "")
return;
for (int playerId = 0; playerId < (int) byte.MaxValue; ++playerId)
{
if (Main.player[playerId].team == team)
{
NetPacket packet = NetTextModule.SerializeServerMessage(NetworkText.FromLiteral(text), color, clientId);
NetManager.Instance.SendToClient(packet, playerId);
}
}
}
}
private void SendNoTeamError(byte clientId)
{
NetPacket packet = NetTextModule.SerializeServerMessage(Lang.mp[10].ToNetworkText(), PartyChatCommand.ERROR_COLOR);
NetManager.Instance.SendToClient(packet, (int) clientId);
}
}
}

View file

@ -0,0 +1,25 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Chat.Commands.RollCommand
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using Terraria.Localization;
namespace Terraria.Chat.Commands
{
[ChatCommand("Roll")]
public class RollCommand : IChatCommand
{
private static readonly Color RESPONSE_COLOR = new Color((int) byte.MaxValue, 240, 20);
public string InternalName => "roll";
public void ProcessMessage(string text, byte clientId)
{
int num = Main.rand.Next(1, 101);
NetMessage.BroadcastChatMessage(NetworkText.FromFormattable("*{0} {1} {2}", (object) Main.player[(int) clientId].name, (object) Lang.mp[9].ToNetworkText(), (object) num), RollCommand.RESPONSE_COLOR);
}
}
}

View file

@ -0,0 +1,24 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Chat.Commands.SayChatCommand
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using System;
using Terraria.GameContent.NetModules;
using Terraria.Localization;
using Terraria.Net;
namespace Terraria.Chat.Commands
{
[ChatCommand("Say")]
public class SayChatCommand : IChatCommand
{
public void ProcessMessage(string text, byte clientId)
{
NetPacket packet = NetTextModule.SerializeServerMessage(NetworkText.FromLiteral(text), Main.player[(int) clientId].ChatColor(), clientId);
NetManager.Instance.Broadcast(packet);
Console.WriteLine("<{0}> {1}", (object) Main.player[(int) clientId].name, (object) text);
}
}
}

15
Chat/IChatProcessor.cs Normal file
View file

@ -0,0 +1,15 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.Chat.IChatProcessor
// Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null
// MVID: 68659D26-2BE6-448F-8663-74FA559E6F08
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
namespace Terraria.Chat
{
public interface IChatProcessor
{
bool ProcessReceivedMessage(ChatMessage message, int clientId);
bool ProcessOutgoingMessage(ChatMessage message);
}
}