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()); }
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)}"); } } }
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); }
public static void LoadConfig() { Config = MinimapSettings.ReadFile(ConfigPath); }