public static void RegisterAllEnums(Module module)
        {
            SRMod.ForceModContext(SRModLoader.GetModForAssembly(module.Assembly));
            foreach (var type in module.GetTypes())
            {
                if (type.GetCustomAttributes(true).Any((x) => x is EnumHolderAttribute))
                {
                    foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.Public |
                                                         BindingFlags.NonPublic))
                    {
                        if (!field.FieldType.IsEnum)
                        {
                            continue;
                        }

                        if ((int)field.GetValue(null) == 0)
                        {
                            var newVal = EnumPatcher.GetFirstFreeValue(field.FieldType);
                            EnumPatcher.AddEnumValueWithAlternatives(field.FieldType, newVal, field.Name);
                            field.SetValue(null, newVal);
                        }
                        else
                        {
                            EnumPatcher.AddEnumValueWithAlternatives(field.FieldType, field.GetValue(null), field.Name);
                        }
                    }
                }
            }
            SRMod.ClearModContext();
        }
Exemple #2
0
        public static void PopulateConfigs(SRMod mod)
        {
            SRMod.ForceModContext(mod);

            foreach (var file in GetConfigs(mod.EntryType.Module))
            {
                mod.Configs.Add(file);
                file.TryLoadFromFile();
            }

            SRMod.ClearModContext();
        }
Exemple #3
0
        public override bool Execute(string[] args)
        {
            var mod     = SRModLoader.GetMod(args[0]);
            var config  = mod.Configs.First(x => x.FileName.ToLower() == args[1].ToLower());
            var section = config.Sections.First(x => x.Name.ToLower() == args[2].ToLower());
            var element = section.Elements.First(x => x.Options.Name.ToLower() == args[3].ToLower());

            if (args.Length >= 5)
            {
                element.SetValue(element.Options.Parser.ParseObject(args[4]));
                //Debug.Log(element.GetValue<object>()+" "+element.GetType()+"!");
            }
            else
            {
                Console.Log("Current Value: " + element.Options.Parser.EncodeObject(element.GetValue <object>()));
            }
            SRMod.ForceModContext(mod);
            config.SaveToFile();
            SRMod.ClearModContext();
            return(true);
        }
Exemple #4
0
        // PROCESSES THE TEXT FROM THE CONSOLE INPUT
        internal static void ProcessInput(string command, bool forced = false)
        {
            if (command.Equals(string.Empty))
            {
                return;
            }

            if (!forced)
            {
                if (history.Count == HISTORY)
                {
                    history.RemoveAt(0);
                }

                history.Add(command);
            }

            try
            {
                Log("<color=cyan>Command: </color>" + command);

                bool   spaces = command.Contains(" ");
                string cmd    = spaces ? command.Substring(0, command.IndexOf(' ')) : command;

                if (commands.ContainsKey(cmd))
                {
                    bool     executed      = false;
                    bool     keepExecution = true;
                    string[] args          = spaces ? StripArgs(command) : null;

                    foreach (CommandCatcher catcher in catchers)
                    {
                        keepExecution = catcher.Invoke(cmd, args);

                        if (!keepExecution)
                        {
                            break;
                        }
                    }

                    if (keepExecution)
                    {
                        SRMod.ForceModContext(commands[cmd].belongingMod);
                        try
                        {
                            executed = commands[cmd].Execute(args);
                        }
                        finally
                        {
                            SRMod.ClearModContext();
                        }
                    }

                    if (!executed && keepExecution)
                    {
                        Console.Log($"<color=cyan>Usage:</color> <color=#77DDFF>{ColorUsage(commands[cmd].Usage)}</color>");
                    }
                }
                else
                {
                    LogError("Unknown command. Please use '<color=white>help</color>' for available commands or check the menu on the right");
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }