using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using AtlyssCommandLib.API;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CodeTalker;
using CodeTalker.Networking;
using CodeTalker.Packets;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Nessie.ATLYSS.EasySettings;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Soggy_Pancake")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.0.6.0")]
[assembly: AssemblyInformationalVersion("0.0.6+51c2fbd14307f06259845b80f8680f25bcb88812")]
[assembly: AssemblyProduct("AtlyssCommandLib")]
[assembly: AssemblyTitle("AtlyssCommandLib")]
[assembly: AssemblyVersion("0.0.6.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace AtlyssCommandLib
{
internal static class BuiltInCmds
{
internal static bool Help(Caller caller, string[] args)
{
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_0332: Unknown result type (might be due to invalid IL or missing references)
//IL_0338: Unknown result type (might be due to invalid IL or missing references)
string[] array = args;
foreach (string text in array)
{
ManualLogSource? logger = Plugin.logger;
if (logger != null)
{
logger.LogDebug((object)("Arg: \"" + text + "\""));
}
}
CommandProvider provider = CommandManager.root;
string currentArg = "";
int num = 0;
while (true)
{
ManualLogSource? logger2 = Plugin.logger;
if (logger2 != null)
{
logger2.LogDebug((object)$"help loop {num + 1} len {args.Length}: {string.Concat(args)}");
}
if (num == args.Length || args[num] == "")
{
string text2 = Utils.buildHelpMessage(caller, provider);
string[] array2 = Array.Empty<string>();
try
{
array2 = (from a in provider.aliases
where a.Value.isProvider && a.Value.provider == provider.childProviders[currentArg]
select a.Key).ToArray();
}
catch
{
}
if (array2.Length != 0)
{
text2 = text2 + "\nAliases: " + string.Join(", ", array2);
}
Utils.NotifyCaller(caller, text2);
break;
}
currentArg = args[num].ToLower();
if (provider.childProviders.ContainsKey(currentArg))
{
provider = provider.childProviders[currentArg];
ManualLogSource? logger3 = Plugin.logger;
if (logger3 != null)
{
logger3.LogDebug((object)("found provider " + currentArg));
}
if (args.Length > 1)
{
args = args[1..];
}
else
{
args[0] = "";
}
continue;
}
if (provider.commands.ContainsKey(currentArg) || (provider.aliases.ContainsKey(currentArg) && !provider.aliases[currentArg].isProvider))
{
ModCommand modCommand = ((!provider.aliases.ContainsKey(currentArg)) ? provider.commands[currentArg] : provider.aliases[currentArg].command);
string text2 = "\n" + modCommand.getHelpMessage();
text2 = text2 + "\n" + modCommand.getDetailedHelpMessage();
text2 = text2.Trim();
string[] array3 = Array.Empty<string>();
try
{
array3 = (from a in provider.aliases
where !a.Value.isProvider && a.Value.command == provider.commands[currentArg]
select a.Key).ToArray();
}
catch
{
}
if (array3.Length != 0)
{
text2 = text2 + "\nAliases: " + string.Join(", ", array3);
}
Utils.NotifyCaller(caller, text2.Trim());
}
else
{
provider.PrintHelp(caller, currentArg);
}
break;
}
return false;
}
internal static bool ChatColorProtector(Caller caller, string[] args)
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
if ((caller.isHost || (Object)(object)caller.player != (Object)(object)Player._mainPlayer) && !Plugin.chatColorsInstalled)
{
Utils.NotifyCaller(caller, "Chat Colors mod is not installed on the server. Cannot set chat color.", Color.red);
return false;
}
if (args.Length != 1)
{
throw new ArgumentException("No arguments given!");
}
if (args[0].ToLower() == "clear")
{
return true;
}
string pattern = "^#([0-9A-Fa-f]{6})$";
Regex regex = new Regex(pattern);
if (!regex.IsMatch(args[0]))
{
throw new ArgumentException("Invalid color format! Use hex format like #RRGGBB or use /chatcolor clear to reset.");
}
return true;
}
internal static bool listMods(Caller caller, string[] args)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
ConfigEntry<bool>? enableListingMods = ModConfig.enableListingMods;
if (enableListingMods == null || enableListingMods.Value)
{
Utils.NotifyCaller(caller, "Listing mods is disabled on this server.", Color.red);
return true;
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Loaded mods:");
foreach (KeyValuePair<string, PluginInfo> pluginInfo in Chainloader.PluginInfos)
{
stringBuilder.AppendLine($"{pluginInfo.Value.Metadata.Name} - {pluginInfo.Value.Metadata.Version}");
}
string message = stringBuilder.ToString().TrimEnd();
Utils.NotifyCaller(caller, message);
return true;
}
}
internal class CommandManager
{
internal static readonly CommandProvider root = new CommandProvider("/", "");
internal static Dictionary<string, string> serverCommands = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
internal static void updateServerCommands()
{
Player? obj = Player._mainPlayer.NC<Player>();
if (obj != null && obj.Network_isHostPlayer)
{
return;
}
serverCommands.Clear();
foreach (ModCommand value in root.commands.Values)
{
if (value.options.serverSide && (value.Command != "chatcolor" || (value.Command == "chatcolor" && Plugin.chatColorsInstalled)))
{
serverCommands[value.Command] = value.getHelpMessage();
}
}
foreach (CommandProvider value2 in root.childProviders.Values)
{
if (value2.hasServerCommands)
{
serverCommands[value2.prefix] = value2.getHelpMessage();
}
}
}
internal static void updateServerCommands(PacketHeader header, BinaryPacketBase pkt)
{
Player? obj = Player._mainPlayer.NC<Player>();
if (obj == null || obj.Network_isHostPlayer || !(pkt is ServerCommandPkt serverCommandPkt))
{
return;
}
serverCommands.Clear();
foreach (ServerCommandPkt.Entry entry in serverCommandPkt.entries)
{
serverCommands[entry.prefix] = entry.helpMessage;
}
}
internal static bool execCommand(ModCommand cmd, Caller caller, string[] args)
{
bool isHost = caller.isHost;
CommandOptions options = cmd.options;
ManualLogSource? logger = Plugin.logger;
if (logger != null)
{
logger.LogDebug((object)("Command being called: " + caller.cmdPrefix));
}
ManualLogSource? logger2 = Plugin.logger;
if (logger2 != null)
{
logger2.LogDebug((object)("Am server?: " + isHost));
}
ManualLogSource? logger3 = Plugin.logger;
if (logger3 != null)
{
logger3.LogDebug((object)$"cmd: server/client/console {cmd.options.serverSide} {cmd.options.clientSide} {cmd.options.consoleCmd}");
}
if (options.consoleCmd)
{
if (caller.isConsole)
{
cmd.Callback(caller, args);
}
else
{
ManualLogSource? logger4 = Plugin.logger;
if (logger4 != null)
{
logger4.LogError((object)$"Command '{caller.cmdPrefix}' is console only. Caller is console: {caller.isConsole}");
}
}
return true;
}
if (options.hostOnly)
{
if (caller.isHost)
{
cmd.Callback(caller, args);
}
else
{
ManualLogSource? logger5 = Plugin.logger;
if (logger5 != null)
{
logger5.LogError((object)$"Command '{caller.cmdPrefix}' is host only. Caller is host: {caller.isHost}");
}
}
return true;
}
if (!options.clientSide && options.serverSide && isHost)
{
ManualLogSource? logger6 = Plugin.logger;
if (logger6 != null)
{
logger6.LogDebug((object)"Server side only command!");
}
if (!cmd.Callback(caller, args))
{
cmd.printHelp(caller);
}
return true;
}
if (options.clientSide && !options.serverSide)
{
ManualLogSource? logger7 = Plugin.logger;
if (logger7 != null)
{
logger7.LogDebug((object)"Client side only command!");
}
if (!cmd.Callback(caller, args))
{
cmd.printHelp(caller);
}
return true;
}
if (options.serverSide && options.clientSide)
{
ManualLogSource? logger8 = Plugin.logger;
if (logger8 != null)
{
logger8.LogDebug((object)"Client and server side command!");
}
bool flag = cmd.Callback(caller, args);
if (!flag && (Delegate?)cmd.Callback != (Delegate?)new CommandCallback(BuiltInCmds.Help))
{
cmd.printHelp(caller);
}
if (!isHost)
{
return !flag;
}
return true;
}
return true;
}
}
internal class ModConfig
{
public static ConfigEntry<bool>? enableListingMods;
public static ConfigEntry<bool>? sendFailedCommands;
public static void init(ConfigFile config)
{
enableListingMods = config.Bind<bool>("General", "EnableModListing", true, "Enable the /mods command to list server mods.");
sendFailedCommands = config.Bind<bool>("General", "SendFailedCommandsToServer", false, "If a command fails to parse on the client side, still send it to the server. Useful for commands that only run server side. CommandLib will no longer print the error help message! The server will still block commands from properly entering chat, but if the server is vanilla it will enter chat!");
if (Chainloader.PluginInfos.ContainsKey("EasySettings"))
{
try
{
easySettings();
}
catch
{
}
}
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void easySettings()
{
SettingsTab modTab = Settings.ModTab;
modTab.AddHeader("Atlyss Command Lib Settings");
modTab.AddToggle(enableListingMods);
modTab.AddToggle(sendFailedCommands);
}
}
internal class ServerCommandPkt : BinaryPacketBase
{
internal struct Entry
{
public string prefix;
public string helpMessage;
}
public List<Entry> entries = new List<Entry>();
public override string PacketSignature => "ACL_ServerCmds";
public override byte[] Serialize()
{
CommandManager.updateServerCommands();
MemoryStream memoryStream = new MemoryStream();
BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
binaryWriter.Write((byte)CommandManager.serverCommands.Count);
foreach (KeyValuePair<string, string> serverCommand in CommandManager.serverCommands)
{
binaryWriter.Write(Encoding.UTF8.GetBytes(serverCommand.Key + "\0"));
binaryWriter.Write(Encoding.UTF8.GetBytes(serverCommand.Value + "\0"));
}
ManualLogSource? logger = Plugin.logger;
if (logger != null)
{
logger.LogMessage((object)("Full servercmd hex: " + BitConverter.ToString(memoryStream.ToArray()).Replace("-", "")));
}
return memoryStream.ToArray();
}
public override void Deserialize(byte[] data)
{
MemoryStream memoryStream = new MemoryStream(data);
BinaryReader binaryReader = new BinaryReader(memoryStream);
byte b = binaryReader.ReadByte();
short num = 1;
short num2 = 0;
short num3 = 0;
while (memoryStream.Position < memoryStream.Length)
{
if (binaryReader.Read() == 0)
{
if (num2 == 0)
{
num2 = (short)memoryStream.Position;
}
else if (num3 == 0)
{
num3 = (short)memoryStream.Position;
string @string = Encoding.UTF8.GetString(data, num, num2 - num - 1);
string string2 = Encoding.UTF8.GetString(data, num2, num3 - num2 - 1);
entries.Add(new Entry
{
prefix = @string,
helpMessage = string2
});
num2 = 0;
num3 = 0;
num = (short)memoryStream.Position;
}
}
}
if (entries.Count != b)
{
ManualLogSource? logger = Plugin.logger;
if (logger != null)
{
logger.LogWarning((object)$"Expected {b} server commands but got {entries.Count}!");
}
}
}
}
internal static class Patches
{
private static ScriptableEmoteList? emoteList;
private static InputField? consoleInputField;
private static bool blockMsg = false;
public static string blockReason = "";
public static string[] commandSplit(string message)
{
return (from Match m in Regex.Matches(message, "[\\\"].+?[\\\"]|[^ ]+")
select m.Value.Trim('"') into m
where !string.IsNullOrWhiteSpace(m)
select m).ToArray();
}
[HarmonyPrefix]
[HarmonyPriority(int.MaxValue)]
[HarmonyPatch(typeof(ChatBehaviour), "Cmd_SendChatMessage")]
internal static bool Client_SendChatMessage(ref ChatBehaviour __instance, ref bool __runOriginal, ref string _message)
{
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Expected O, but got Unknown
if (!_message.StartsWith('/') || _message.StartsWith("//") || _message.Length == 0)
{
return true;
}
if ((Object)(object)emoteList == (Object)null)
{
FieldInfo field = ((object)__instance).GetType().GetField("_scriptableEmoteList", BindingFlags.Instance | BindingFlags.NonPublic);
emoteList = (ScriptableEmoteList)field.GetValue(__instance);
}
if (_message == "/afk" || isEmote(_message))
{
return true;
}
if (_message.StartsWith("/"))
{
string[] array = commandSplit(_message);
Caller caller = default(Caller);
caller.player = Player._mainPlayer;
Caller caller2 = caller;
blockMsg = CommandManager.root.recieveCommand(caller2, array[0], (array.Length > 1) ? array[1..] : Array.Empty<string>());
}
return true;
static bool isEmote(string _message)
{
if ((Object)(object)emoteList == (Object)null)
{
return false;
}
EmoteCommand[] emoteCommandList = emoteList._emoteCommandList;
foreach (EmoteCommand val in emoteCommandList)
{
if (_message == val._emoteChatCommand)
{
return true;
}
}
return false;
}
}
[HarmonyPrefix]
[HarmonyPriority(int.MinValue)]
[HarmonyPatch(typeof(ChatBehaviour), "Cmd_SendChatMessage")]
internal static bool Client_BlockChatMessage(ref ChatBehaviour __instance, ref string _message, ref bool __runOriginal)
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
if (blockMsg)
{
ConfigEntry<bool>? sendFailedCommands = ModConfig.sendFailedCommands;
if (sendFailedCommands == null || !sendFailedCommands.Value)
{
blockMsg = false;
if ((blockReason != "") & __runOriginal)
{
Caller caller = default(Caller);
caller.player = ((Component)__instance).GetComponent<Player>();
Utils.NotifyCaller(caller, blockReason);
blockReason = "";
}
__runOriginal = false;
return false;
}
}
return true;
}
[HarmonyPrefix]
[HarmonyPriority(int.MinValue)]
[HarmonyPatch(typeof(ChatBehaviour), "Rpc_RecieveChatMessage")]
internal static void Server_RecieveChatMessage(ref ChatBehaviour __instance, ref bool __runOriginal, ref string message)
{
if (message.StartsWith('/') && !message.StartsWith("//") && message.Length != 0 && !((Object)(object)__instance == (Object)null))
{
string text = message.Split()[0];
string prefix = text.Substring(1, text.Length - 1);
string[] array = commandSplit(message);
Caller caller = new Caller(prefix, ((Component)__instance).gameObject.GetComponent<Player>());
__runOriginal = !CommandManager.root.recieveCommand(caller, array[0], (array.Length > 1) ? array[1..] : Array.Empty<string>());
}
}
[HarmonyPrefix]
[HarmonyPriority(int.MinValue)]
[HarmonyPatch(typeof(HostConsole), "Send_ServerMessage")]
internal static void Console_RecieveCommand(ref HostConsole __instance, ref string _message, ref bool __runOriginal)
{
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Expected O, but got Unknown
if (_message.StartsWith('/') && _message.Length != 0)
{
string text = _message.Split()[0];
string prefix = text.Substring(1, text.Length - 1);
string[] array = commandSplit(_message);
Caller caller = new Caller(prefix, null, console: true);
__runOriginal = !CommandManager.root.recieveCommand(caller, array[0], (array.Length > 1) ? array[1..] : Array.Empty<string>());
if ((Object)(object)consoleInputField == (Object)null)
{
FieldInfo field = typeof(HostConsole).GetField("_consoleInputField", BindingFlags.Instance | BindingFlags.NonPublic);
consoleInputField = (InputField)field.GetValue(__instance);
}
consoleInputField.text = string.Empty;
}
}
[HarmonyPatch(typeof(PlayerMove), "Start")]
[HarmonyPostfix]
internal static void SendCommandList(PlayerMove __instance)
{
Player? obj = Player._mainPlayer.NC<Player>();
if (obj == null || !obj._isHostPlayer)
{
return;
}
Player component = ((Component)__instance).GetComponent<Player>();
if ((Object)(object)component != (Object)null && (Object)(object)component != (Object)(object)Player._mainPlayer)
{
ManualLogSource? logger = Plugin.logger;
if (logger != null)
{
logger.LogDebug((object)"sending server command list!");
}
CodeTalkerNetwork.SendNetworkPacket(component, (BinaryPacketBase)(object)new ServerCommandPkt(), (CompressionType)1, CompressionLevel.Fastest);
}
}
[HarmonyPatch(typeof(AtlyssNetworkManager), "OnStartServer")]
[HarmonyPostfix]
internal static void StartHosting()
{
CommandManager.updateServerCommands();
}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("Soggy_Pancake.CommandLib", "AtlyssCommandLib", "0.0.6")]
internal class Plugin : BaseUnityPlugin
{
[CompilerGenerated]
private static class <>O
{
public static BinaryPacketListener <0>__updateServerCommands;
public static CommandCallback <1>__Help;
public static CommandCallback <2>__listMods;
public static CommandCallback <3>__ChatColorProtector;
}
internal static ManualLogSource? logger;
internal static Harmony? harmony;
internal static HostConsole? hostConsole;
internal static ConsoleCommandManager? consoleCommandManager;
internal static CommandProvider? serverCmds;
internal static CommandProvider? clientCmds;
internal static bool chatColorsInstalled;
private void Awake()
{
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Expected O, but got Unknown
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Expected O, but got Unknown
logger = ((BaseUnityPlugin)this).Logger;
logger.LogInfo((object)"Plugin AtlyssCommandLib is loaded!");
if (Application.version != "12026.a2")
{
logger.LogWarning((object)("[VERSION MISMATCH] This version of AtlyssCommandLib is made for 12026.a2, you are running " + Application.version + "."));
}
harmony = new Harmony("Soggy_Pancake.CommandLib");
harmony.PatchAll(typeof(Patches));
ModConfig.init(((BaseUnityPlugin)this).Config);
chatColorsInstalled = Chainloader.PluginInfos.ContainsKey("StuntedRaccoon.CustomChatColors");
logger.LogInfo((object)("Chatcolors " + (chatColorsInstalled ? "is" : "isn't") + " installed!"));
object obj = <>O.<0>__updateServerCommands;
if (obj == null)
{
BinaryPacketListener val = CommandManager.updateServerCommands;
<>O.<0>__updateServerCommands = val;
obj = (object)val;
}
CodeTalkerNetwork.RegisterBinaryListener<ServerCommandPkt>((BinaryPacketListener)obj);
CommandOptions value = new CommandOptions(clientSide: true, serverSide: true);
Utils.RegisterCommand("help", "Shows this help message", BuiltInCmds.Help, value);
ConfigEntry<bool>? enableListingMods = ModConfig.enableListingMods;
if (enableListingMods != null && enableListingMods.Value)
{
value.clientSide = false;
Utils.RegisterCommand("mods", "List server's installed mods!", BuiltInCmds.listMods, value);
}
registerVanillaCommands();
addCommandCompatibility();
}
internal static void getHostConsole()
{
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Expected O, but got Unknown
if ((Object)(object)hostConsole != (Object)null)
{
return;
}
hostConsole = Object.FindFirstObjectByType<HostConsole>();
if ((Object)(object)hostConsole == (Object)null)
{
ManualLogSource? obj = logger;
if (obj != null)
{
obj.LogError((object)"Failed to find HostConsole instance!");
}
}
else
{
FieldInfo field = typeof(HostConsole).GetField("_cmdManager", BindingFlags.Instance | BindingFlags.NonPublic);
consoleCommandManager = (ConsoleCommandManager)field.GetValue(hostConsole);
}
}
private void registerVanillaCommands()
{
CommandOptions value = new CommandOptions(clientSide: true, serverSide: true);
Utils.RegisterCommand("emotes", "Lists all available emotes", compaitibilityCommand, value);
Utils.RegisterCommand("afk", "Go afk", compaitibilityCommand, value);
CommandOptions value2 = new CommandOptions(clientSide: false, serverSide: false, consoleCmd: true);
Utils.RegisterCommand("shutdown", "Shuts down the server with optional countdown.", vanillaServerCommand, value2);
Utils.RegisterCommand("cancelsd", "Cancel shutting down the server.", vanillaServerCommand, value2);
Utils.RegisterCommand("starthost", "initalizes the server. Server instance must be shut down to initalize.", vanillaServerCommand, value2);
Utils.RegisterCommand("kick", "kicks a connected client. Must have a output of the connection ID number. (ex: /kick 2)", vanillaServerCommand, value2);
Utils.RegisterCommand("ban", "same as kick, but also bans the client's address from connecting to the server. (ex: /ban 2)", vanillaServerCommand, value2);
Utils.RegisterCommand("clearbanlist", "clears the list of bans saved in your host settings profile.", vanillaServerCommand, value2);
Utils.RegisterCommand("clients", "displays all clients that are connected to the server with Connnection IDs.", vanillaServerCommand, value2);
Utils.RegisterCommand("maplist", "displays all loaded map instances on the server.", vanillaServerCommand, value2);
Utils.RegisterCommand("savelog", "clears console log.", vanillaServerCommand, value2);
Utils.RegisterCommand("clear", "clears console log.", vanillaServerCommand, value2);
}
private void addCommandCompatibility()
{
Utils.RegisterCommand(options: new CommandOptions(clientSide: true, serverSide: true), command: "chatcolor", helpMessage: "Set your chat color using a hex code! /chatcolor #[color]. HASHTAG REQUIRED", callback: BuiltInCmds.ChatColorProtector);
}
private bool vanillaServerCommand(Caller caller, string[] args)
{
if (!caller.isConsole)
{
return true;
}
ManualLogSource? obj = logger;
if (obj != null)
{
obj.LogInfo((object)("Vanilla server command '" + caller.cmdPrefix + "' called"));
}
return false;
}
private bool compaitibilityCommand(Caller caller, string[] args)
{
return false;
}
private bool testCmd(Caller caller, string[] args)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
Utils.NotifyCaller(caller, "Test command executed!");
foreach (string text in args)
{
ManualLogSource? obj = logger;
if (obj != null)
{
obj.LogInfo((object)("Arg: \"" + text + "\""));
}
}
return true;
}
private bool testTopLevel(Caller caller, string[] args)
{
ManualLogSource? obj = logger;
if (obj != null)
{
obj.LogInfo((object)"Yo?");
}
foreach (string text in args)
{
ManualLogSource? obj2 = logger;
if (obj2 != null)
{
obj2.LogInfo((object)("Arg: \"" + text + "\""));
}
}
return true;
}
}
internal static class PluginInfo
{
internal const string GUID = "Soggy_Pancake.CommandLib";
internal const string NAME = "AtlyssCommandLib";
internal const string GAMEVER = "12026.a2";
internal const string VERSION = "0.0.6";
}
internal static class UnityNullFix
{
public static T? NC<T>(this T? obj) where T : Object
{
if (!Object.op_Implicit((Object)(object)obj))
{
return default(T);
}
return obj;
}
}
}
namespace AtlyssCommandLib.API
{
public struct Caller
{
public Player? player;
public readonly bool isConsole;
internal string cmdPrefix;
public bool isHost
{
get
{
Player mainPlayer = Player._mainPlayer;
if (mainPlayer == null)
{
return false;
}
return mainPlayer.Network_isHostPlayer;
}
}
public readonly bool IsRemote => (Object)(object)player != (Object)(object)Player._mainPlayer;
internal Caller(string prefix, Player? _player, bool console = false)
{
cmdPrefix = prefix;
player = _player;
isConsole = console;
}
internal Caller(string prefix, ChatBehaviour chatBehaviour)
{
isConsole = false;
cmdPrefix = prefix;
player = ((Component)chatBehaviour).GetComponent<Player>();
}
}
public struct CommandOptions
{
public bool clientSide;
public bool serverSide;
public bool consoleCmd;
public bool hostOnly;
public CommandOptions()
{
clientSide = true;
serverSide = false;
consoleCmd = false;
hostOnly = false;
}
public CommandOptions(bool clientSide = false, bool serverSide = false, bool consoleCmd = false, bool hostOnly = false)
{
this.clientSide = clientSide;
this.serverSide = serverSide;
this.consoleCmd = consoleCmd;
this.hostOnly = hostOnly;
}
}
public delegate bool CommandCallback(Caller caller, string[] args);
public class CommandProvider
{
internal struct Alias
{
public bool isProvider;
public ModCommand command;
public CommandProvider provider;
}
internal string prefix;
internal string helpHeader;
internal bool hasClientCommands;
internal bool hasServerCommands;
internal bool hasConsoleCommands;
internal bool hasHostOnlyCommands;
internal CommandProvider? _parentProvider;
internal Dictionary<string, Alias> aliases = new Dictionary<string, Alias>(StringComparer.OrdinalIgnoreCase);
internal Dictionary<string, ModCommand> commands = new Dictionary<string, ModCommand>(StringComparer.OrdinalIgnoreCase);
internal Dictionary<string, CommandProvider> childProviders = new Dictionary<string, CommandProvider>(StringComparer.OrdinalIgnoreCase);
public static CommandProvider Root => CommandManager.root;
public CommandProvider? ParentProvider => _parentProvider;
public CommandProvider(string prefix, string header)
{
this.prefix = prefix;
helpHeader = header;
_parentProvider = null;
}
public CommandProvider(string prefix, string header, CommandProvider? parentProvider = null)
{
this.prefix = prefix;
helpHeader = header;
_parentProvider = parentProvider ?? CommandManager.root;
ParentProvider?.RegisterProvider(this);
}
public ModCommand? RegisterCommand(string command, string helpMessage, CommandCallback callback, CommandOptions? options = null)
{
if (command.StartsWith('/'))
{
string text = command;
command = text.Substring(1, text.Length - 1);
}
if (command.Contains(' '))
{
ManualLogSource? logger = Plugin.logger;
if (logger != null)
{
logger.LogError((object)("Command '" + command + "' contains spaces! Not registering Command!"));
}
return null;
}
ModCommand modCommand = new ModCommand(command, helpMessage, callback, options ?? new CommandOptions());
RegisterCommand(modCommand);
return modCommand;
}
public ModCommand? RegisterCommand(string command, string helpMessage, string detailedHelpMessage, CommandCallback callback, CommandOptions? options = null)
{
if (command.StartsWith('/'))
{
string text = command;
command = text.Substring(1, text.Length - 1);
}
if (command.Contains(' '))
{
ManualLogSource? logger = Plugin.logger;
if (logger != null)
{
logger.LogError((object)("Command '" + command + "' contains spaces! Not registering Command!"));
}
return null;
}
ModCommand modCommand = new ModCommand(command, helpMessage, detailedHelpMessage, callback, options ?? new CommandOptions());
RegisterCommand(modCommand);
return modCommand;
}
public void RegisterCommand(ModCommand cmd)
{
CommandOptions options = cmd.options;
if (commands.ContainsKey(cmd.Command) || aliases.ContainsKey(cmd.Command))
{
ManualLogSource? logger = Plugin.logger;
if (logger != null)
{
logger.LogError((object)("Failed to register Command '" + cmd.Command + "'! Command or alias with that name already exists!"));
}
return;
}
if (!options.clientSide && !options.serverSide && !options.consoleCmd && !options.hostOnly)
{
ManualLogSource? logger2 = Plugin.logger;
if (logger2 != null)
{
logger2.LogError((object)("Failed to register Command '" + cmd.Command + "'! Command has to either be a client, server, or console Command!"));
}
return;
}
commands.Add(cmd.Command, cmd);
CommandProvider commandProvider = this;
CommandOptions options2 = cmd.options;
while (commandProvider != null)
{
commandProvider.hasClientCommands = commandProvider.hasClientCommands || options2.clientSide;
commandProvider.hasServerCommands = commandProvider.hasServerCommands || options2.serverSide;
commandProvider.hasConsoleCommands = commandProvider.hasConsoleCommands || options2.consoleCmd;
commandProvider.hasHostOnlyCommands = commandProvider.hasHostOnlyCommands || options2.hostOnly;
commandProvider = commandProvider.ParentProvider;
}
}
public void RegisterProvider(CommandProvider provider)
{
if (!childProviders.ContainsKey(provider.prefix) && !aliases.ContainsKey(provider.prefix))
{
childProviders.Add(provider.prefix, provider);
provider._parentProvider = this;
ManualLogSource? logger = Plugin.logger;
if (logger != null)
{
logger.LogInfo((object)("Registered Command command '" + provider.prefix + "' under '" + prefix + "'"));
}
}
}
public void RegisterAlias(string alias, ModCommand? command)
{
if (command != null && !commands.ContainsKey(alias) && !aliases.ContainsKey(alias))
{
aliases.Add(alias, new Alias
{
isProvider = false,
command = command
});
}
}
public void RegisterAlias(string[] aliases, ModCommand? command)
{
if (command == null)
{
return;
}
foreach (string text in aliases)
{
if (commands.ContainsKey(text) || this.aliases.ContainsKey(text))
{
break;
}
RegisterAlias(text, command);
}
}
public void RegisterAlias(string alias, CommandProvider? provider)
{
if (provider != null && !commands.ContainsKey(alias) && !aliases.ContainsKey(alias))
{
aliases.Add(alias, new Alias
{
isProvider = true,
provider = provider
});
}
}
public void RegisterAlias(string[] aliases, CommandProvider? provider)
{
if (provider == null)
{
return;
}
foreach (string text in aliases)
{
if (commands.ContainsKey(text) || this.aliases.ContainsKey(text))
{
break;
}
RegisterAlias(text, provider);
}
}
internal bool recieveCommand(Caller caller, string command, string[] args)
{
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
if (command.StartsWith('/'))
{
string text = command;
command = text.Substring(1, text.Length - 1);
}
caller.cmdPrefix = command;
Player? obj = Player._mainPlayer.NC<Player>();
bool flag = obj != null && obj.Network_isHostPlayer;
if (commands.ContainsKey(command) || (aliases.ContainsKey(command) && !aliases[command].isProvider))
{
try
{
ModCommand cmd = ((!commands.ContainsKey(command)) ? aliases[command].command : commands[command]);
return CommandManager.execCommand(cmd, caller, args);
}
catch (ArgumentException ex)
{
if (!string.IsNullOrEmpty(ex.Message) && string.IsNullOrEmpty(ex.ParamName))
{
Utils.NotifyCaller(caller, "Recieved invalid arguments for command '" + command + " " + string.Join(" ", args) + "' Reason: " + ex.Message, Color.yellow);
}
else if (!string.IsNullOrEmpty(ex.ParamName) && !string.IsNullOrEmpty(ex.Message))
{
Utils.NotifyCaller(caller, "'" + ex.ParamName + "' is invalid! Reason: " + ex.Message);
}
else
{
ManualLogSource? logger = Plugin.logger;
if (logger != null)
{
logger.LogError((object)("Recieved invalid arguments for command '" + command + " " + string.Join(" ", args) + "' Error: " + ex));
}
}
commands[command].printHelp(caller);
return true;
}
catch (Exception ex2)
{
ManualLogSource? logger2 = Plugin.logger;
if (logger2 != null)
{
logger2.LogError((object)("Error executing command '" + command + " " + string.Join(" ", args) + "' Error: " + ex2));
}
commands[command].printHelp(caller);
return true;
}
}
if (childProviders.ContainsKey(command) || (aliases.ContainsKey(command) && aliases[command].isProvider))
{
CommandProvider commandProvider = ((!aliases.ContainsKey(command)) ? childProviders[command] : aliases[command].provider);
string command2 = ((args.Length != 0) ? args[0] : "");
return commandProvider.recieveCommand(caller, command2, (args.Length > 1) ? args[1..] : Array.Empty<string>());
}
if (this == Root)
{
Player? obj2 = Player._mainPlayer.NC<Player>();
if (obj2 != null && obj2.Network_isHostPlayer && CommandManager.serverCommands.ContainsKey(command))
{
return false;
}
}
List<string> list = new List<string>();
CommandProvider commandProvider2 = this;
while (commandProvider2?.ParentProvider != null)
{
list.Add(commandProvider2.prefix);
commandProvider2 = commandProvider2.ParentProvider;
}
string text2 = "";
if (list.Count > 0)
{
list.Reverse();
text2 = string.Join(' ', list);
text2 += " ";
}
Patches.blockReason = "\nCommand '" + command + "' not found! Use /help " + text2 + "to list available comands";
return true;
}
public string getHelpMessage()
{
return helpHeader;
}
public virtual void PrintHelp(Caller caller, string cmd)
{
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
string text = "";
if (helpHeader != "")
{
text = text + "\n" + helpHeader + "\n\n";
}
text += Utils.buildHelpMessage(caller, this);
List<string> list = new List<string>();
CommandProvider commandProvider = this;
while (commandProvider?.ParentProvider != null)
{
list.Add(commandProvider.prefix);
commandProvider = commandProvider.ParentProvider;
}
string text2 = "";
if (list.Count > 0)
{
list.Reverse();
text2 = string.Join(' ', list);
text2 += " ";
}
text = text + "\nCommand '" + cmd + "' not found! Use /help " + text2 + "to list available comands";
Utils.NotifyCaller(caller, text);
}
}
public class ModCommand
{
internal string Command;
private string HelpMessage = "";
private string DetailedHelpMessage = "";
internal CommandCallback Callback;
internal CommandOptions options;
public ModCommand(string command, string helpMessage, CommandCallback callback, CommandOptions options)
{
Command = command;
HelpMessage = helpMessage.Trim();
Callback = callback;
this.options = options;
}
public ModCommand(string command, string helpMessage, string detailedHelp, CommandCallback callback, CommandOptions options)
{
Command = command;
HelpMessage = helpMessage.Trim();
DetailedHelpMessage = detailedHelp.Trim();
Callback = callback;
this.options = options;
}
public void printHelp(Caller caller)
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
string message = "/" + Command + " - " + HelpMessage + " " + DetailedHelpMessage;
Utils.NotifyCaller(caller, message);
}
public string getHelpMessage()
{
return HelpMessage;
}
public string getDetailedHelpMessage()
{
return DetailedHelpMessage;
}
}
public class Utils
{
public static ModCommand? RegisterCommand(string command, string helpMessage, CommandCallback callback, CommandOptions? options = null)
{
return CommandManager.root.RegisterCommand(command, helpMessage, callback, options ?? new CommandOptions());
}
public static ModCommand? RegisterCommand(string command, string helpMessage, string detailedHelpMessage, CommandCallback callback, CommandOptions? options = null)
{
return CommandManager.root.RegisterCommand(command, helpMessage, detailedHelpMessage, callback, options ?? new CommandOptions());
}
public static void RegisterCommand(ModCommand command)
{
CommandManager.root.RegisterCommand(command);
}
public static void RegisterProvider(CommandProvider provider)
{
CommandManager.root.RegisterProvider(provider);
}
public static void RegisterAlias(string alias, ModCommand? command)
{
CommandManager.root.RegisterAlias(alias, command);
}
public static void RegisterAlias(string[] aliases, ModCommand? command)
{
CommandManager.root.RegisterAlias(aliases, command);
}
public static void RegisterAlias(string alias, CommandProvider? provider)
{
CommandManager.root.RegisterAlias(alias, provider);
}
public static void RegisterAlias(string[] aliases, CommandProvider? provider)
{
CommandManager.root.RegisterAlias(aliases, provider);
}
public static void NotifyCaller(Caller caller, string message, Color color = default(Color))
{
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
if (caller.isConsole)
{
Plugin.getHostConsole();
HostConsole? obj = Plugin.hostConsole.NC<HostConsole>();
if (obj != null)
{
obj.New_LogMessage(message);
}
return;
}
if ((Object)(object)caller.player == (Object)(object)Player._mainPlayer)
{
if (color == default(Color))
{
color = Color.white;
}
Player._mainPlayer._chatBehaviour.New_ChatMessage("<color=#" + ColorUtility.ToHtmlStringRGB(color) + ">" + message + "</color>");
return;
}
if (color == default(Color))
{
color = Color.white;
}
Player? player = caller.player;
if (player != null)
{
player._chatBehaviour.Target_RecieveMessage("<color=#" + ColorUtility.ToHtmlStringRGB(color) + ">" + message + "</color>");
}
}
public static string buildHelpMessage(Caller caller, CommandProvider provider)
{
string[] array = getCommands(provider);
if (provider == CommandProvider.Root)
{
array = array.Concat(CommandManager.serverCommands.Keys).Distinct().ToArray();
}
int num = array.Max((string c) => c.Length);
num = ((num - 1) / 4 + 1) * 4;
string text = "Available commands: \n";
string[] array2 = array;
foreach (string text2 in array2)
{
text = text + "/" + text2.PadRight(num) + " - " + ((provider.commands.ContainsKey(text2) ? provider.commands[text2].getHelpMessage() : null) ?? (provider.childProviders.ContainsKey(text2) ? provider.childProviders[text2]?.getHelpMessage() : "ERROR")) + "\n";
}
return text.TrimEnd();
string[] getCommands(CommandProvider provider)
{
bool remotePlayer = caller.IsRemote;
return (from cmd in provider.commands.Where<KeyValuePair<string, ModCommand>>(delegate(KeyValuePair<string, ModCommand> cmd)
{
CommandOptions options = cmd.Value.options;
return (caller.isConsole && (options.consoleCmd || options.serverSide)) || (caller.isHost && (options.serverSide || options.hostOnly)) || (!remotePlayer && options.clientSide);
})
select cmd.Key).Concat(from s in provider.childProviders.Where<KeyValuePair<string, CommandProvider>>(delegate(KeyValuePair<string, CommandProvider> pbj)
{
CommandProvider value = pbj.Value;
return (caller.isConsole && (value.hasConsoleCommands || value.hasServerCommands)) || (caller.isHost && (value.hasServerCommands || value.hasHostOnlyCommands)) || (!remotePlayer && value.hasClientCommands);
})
select s.Key).Distinct().ToArray();
}
}
}
}