Ejemplo n.º 1
0
 public static void Init()
 {
     Directory.CreateDirectory(ConfigDir);
     if (!File.Exists(ConfigPath))
     {
         Console.instance.Print("[Minimap+] Config not found. Creating...");
         MinimapSettings.SaveDefault(ConfigPath);
     }
     Console.instance.Print("[Minimap+] Loading config...");
     LoadConfig();
     Console.instance.Print("[Minimap+] Loaded!");
     new Harmony(nameof(MinimapPlus)).PatchAll(Assembly.GetExecutingAssembly());
 }
Ejemplo n.º 2
0
        public static void SaveDefault(string path)
        {
            var settings = new MinimapSettings();

            File.Create(path).Dispose();
            using (var sw = new StreamWriter(path))
            {
                foreach (var prop in settings.GetType().GetProperties())
                {
                    sw.WriteLine($"{prop.Name}={prop.GetValue(settings)}");
                }
            }
        }
Ejemplo n.º 3
0
        public static MinimapSettings ReadFile(string path)
        {
            var settings = new MinimapSettings();

            using (var sr = new StreamReader(path))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    var keyvalue = line.Split('=');
                    if (keyvalue.Length != 2)
                    {
                        continue;
                    }
                    foreach (var prop in settings.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
                    {
                        if (prop.Name != keyvalue[0])
                        {
                            continue;
                        }
                        if (prop.PropertyType == typeof(float))
                        {
                            prop.SetValue(settings, float.Parse(keyvalue[1]));
                            continue;
                        }

                        if (prop.PropertyType == typeof(bool))
                        {
                            prop.SetValue(settings, bool.Parse(keyvalue[1]));
                            continue;
                        }

                        if (prop.PropertyType == typeof(int))
                        {
                            prop.SetValue(settings, int.Parse(keyvalue[1]));
                        }
                    }
                }
            }

            return(settings);
        }
Ejemplo n.º 4
0
 public static void LoadConfig()
 {
     Config = MinimapSettings.ReadFile(ConfigPath);
 }