public static void SetString(string section, string name, string value) { if (prefs.TryGetValue(section, out Dictionary <string, PrefDesc> prefsInSection) && prefsInSection.TryGetValue(name, out PrefDesc pref)) { pref.Value = pref.ValueEdited = value; ModPrefsController.SetString(section, name, value); } else { MelonModLogger.LogError("Trying to save unknown pref " + section + ":" + name); } }
public static void SaveConfig() { foreach (KeyValuePair <string, Dictionary <string, PrefDesc> > prefsInSection in prefs) { foreach (KeyValuePair <string, PrefDesc> pref in prefsInSection.Value) { pref.Value.Value = pref.Value.ValueEdited; ModPrefsController.SetString(prefsInSection.Key, pref.Key, pref.Value.Value); } } Main.OnModSettingsApplied(); MelonModLogger.Log("Config Saved!"); }
private static void RegisterPref(string section, string name, string defaultValue, string displayText, PrefType type, bool hideFromList) { if (prefs.TryGetValue(section, out Dictionary <string, PrefDesc> prefsInSection)) { if (prefsInSection.TryGetValue(name, out PrefDesc pref)) { MelonModLogger.LogError("Trying to registered Pref " + section + ":" + name + " more than one time"); } else { string toStoreValue = defaultValue; if (ModPrefsController.HasKey(section, name)) { toStoreValue = ModPrefsController.GetString(section, name, defaultValue); } else { ModPrefsController.SetString(section, name, defaultValue); } prefsInSection.Add(name, new PrefDesc(toStoreValue, type, hideFromList, (displayText ?? "") == "" ? name : displayText)); } } else { Dictionary <string, PrefDesc> dic = new Dictionary <string, PrefDesc>(); string toStoreValue = defaultValue; if (ModPrefsController.HasKey(section, name)) { toStoreValue = ModPrefsController.GetString(section, name, defaultValue); } else { ModPrefsController.SetString(section, name, defaultValue); } dic.Add(name, new PrefDesc(toStoreValue, type, hideFromList, (displayText ?? "") == "" ? name : displayText)); prefs.Add(section, dic); } }