internal EcoNativeCommand(MethodInfo method, ILogger logger) { this.logger = logger; if (ecoChatManager == null) { ecoChatManager = (ChatManager)typeof(ChatServer).GetField("netChatManager", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(ChatServer.Obj) ?? throw new Exception("A critical part of the Eco codebase has been changed; please uninstall Rocket until it is updated to support these changes."); } if (execute == null) { execute = typeof(ChatManager).GetMethod("InvokeCommand", BindingFlags.Instance | BindingFlags.NonPublic) ?? throw new Exception("A critical part of the Eco codebase has been changed; please uninstall Rocket until it is updated to support these changes."); } command = (ChatCommandAttribute)method.GetCustomAttributes().FirstOrDefault(x => x is ChatCommandAttribute); if (command != null) { commandMethod = method; logger.LogInformation($"The vanilla command \"{Name}\" has been registered."); } else { logger.LogError($"An attempt was made to register a vanilla command (method: {method.DeclaringType?.FullName ?? "UnknownType"}.{method.Name}) with inproper attributes!"); } }
public static ChatCommandId FromType <T>() where T : IChatCommand { ChatCommandAttribute cacheableAttribute = (ChatCommandAttribute)AttributeUtilities.GetCacheableAttribute <T, ChatCommandAttribute>(); if (cacheableAttribute != null) { return(new ChatCommandId(cacheableAttribute.Name)); } return(new ChatCommandId((string)null)); }
public ChatCommandProcessor AddCommand <T>() where T : IChatCommand, new() { ChatCommandAttribute cacheableAttribute = AttributeUtilities.GetCacheableAttribute <T, ChatCommandAttribute>(); string commandKey = "ChatCommand." + cacheableAttribute.Name; ChatCommandId chatCommandId = ChatCommandId.FromType <T>(); _commands[chatCommandId] = new T(); if (Language.Exists(commandKey)) { _localizedCommands.Add(Language.GetText(commandKey), chatCommandId); } else { commandKey += "_"; LocalizedText[] array = Language.FindAll((string key, LocalizedText text) => key.StartsWith(commandKey)); foreach (LocalizedText key2 in array) { _localizedCommands.Add(key2, chatCommandId); } } return(this); }
static ChatHandler() { ChatCommands = new List <IChatCommand>(); List <Type> allCommandTypes = ChatCommandAttribute.GetAllUsingTypes( Assembly.GetAssembly(typeof(ChatHandler))); foreach (Type t in allCommandTypes) { IChatCommand cmd = Activator.CreateInstance(t) as IChatCommand; if (cmd != null) { ChatCommands.Add(cmd); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("[ERROR]: Chat command type does not inherit from IChatCommand: " + t.Name); } } }
// Token: 0x06001347 RID: 4935 RVA: 0x0041B370 File Offset: 0x00419570 public ChatCommandProcessor AddCommand <T>() where T : IChatCommand, new() { ChatCommandAttribute cacheableAttribute = AttributeUtilities.GetCacheableAttribute <T, ChatCommandAttribute>(); string commandKey = "ChatCommand." + cacheableAttribute.Name; ChatCommandId chatCommandId = ChatCommandId.FromType <T>(); this._commands[chatCommandId] = Activator.CreateInstance <T>(); if (Language.Exists(commandKey)) { this._localizedCommands.Add(Language.GetText(commandKey), chatCommandId); } else { commandKey += "_"; LocalizedText[] array = Language.FindAll((string key, LocalizedText text) => key.StartsWith(commandKey)); for (int i = 0; i < array.Length; i++) { LocalizedText key2 = array[i]; this._localizedCommands.Add(key2, chatCommandId); } } return(this); }