internal static object DeserializeFromConfig(object input) { Type type = input.GetType(); MemberInfo[] infos = type.GetMembers(BindingFlags.Public | BindingFlags.Instance); foreach (MemberInfo info in infos) { if (info.MemberType == MemberTypes.Field) { FieldInfo finfo = (FieldInfo)info; string v = null; v = file.GetString("Kinect For Beat Saber", info.Name, null, false); if (v == null) { continue; } if (finfo.FieldType == typeof(Vector3)) { input.SetPrivateField(info.Name, ParseToVector3(v)); } else { input.SetPrivateField(info.Name, Convert.ChangeType(v, finfo.FieldType)); } } } return(input); }
private static ColorPickerViewController MakePicker(SubMenu subMenu, string id, string name, string description, string hex, bool setter = true) { Color col = Color.red; ColorUtility.TryParseHtmlString(config.GetString("Colors", id, hex, true), out col); colorMap[id] = col; ColorPickerViewController newPicker = subMenu.AddColorPicker(name, description, colorMap[id]); newPicker.GetValue += delegate { return(colorMap[id]); }; if (setter) { newPicker.SetValue += delegate(Color value) { string newHex = "#" + ColorUtility.ToHtmlStringRGB(value); hexMap[hex] = newHex; config.SetString("Colors", id, newHex); }; } return(newPicker); }
public IEnumerator LoadAudio() { Utilities.Logging.Log.Notice("Attempting to load Audio files"); var folderPath = Environment.CurrentDirectory + "/UserData/HitSoundChanger"; if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } var directories = Directory.GetDirectories(folderPath); hitSounds.Add(new HitSoundCollection { name = "Default", folderPath = "Default" }); foreach (var folder in directories) { HitSoundCollection newSounds = new HitSoundCollection(folder); yield return(newSounds.LoadSounds()); hitSounds.Add(newSounds); } string lastSound = Settings.GetString("HitSoundChanger", "Last Selected Sound", "Default", true); HitSoundCollection lastSounds = hitSounds.FirstOrDefault(x => x.folderPath == lastSound); if (lastSounds == null) { lastSounds = hitSounds[0]; } currentHitSound = lastSounds; }
public static void Read() { showInfo = config.GetBool("PP Helper", "showInfo", true, true); defaultAcc = config.GetFloat("PP Helper", "defaultAcc", 80f, true); ppTop = config.GetBool("PP Helper", "ppTop", false, true); accIncrement = config.GetFloat("PP Helper", "accIncrement", 0.1f, true); starRange = config.GetFloat("PP Helper", "starRange", 0.5f, true); starAccChoice = Enum.TryParse(config.GetString("PP Helper", "starAccChoice", "AverageOfTopN", true), out CalculationType starChoice) ? starChoice : CalculationType.AverageOfTopN; numberOfScores = config.GetInt("PP Helper", "numberOfScores", 3, true); accOverride = config.GetBool("PP Helper", "accOverride", true, true); autoUpdate = config.GetBool("PP Helper", "autoUpdate", true, true); playHistory = config.GetBool("PP Helper", "playHistory", true, true); sortMethod = Enum.TryParse(config.GetString("PP Helper", "sortMethod", "PPGain", true), out SortMethod sortChoice) ? sortChoice : SortMethod.PPGain; ignoreNoFail = config.GetBool("PP Helper", "ignoreNoFail", true, true); hideOnStart = config.GetBool("PP Helper", "hideOnStart", false, true); decimalPrecision = config.GetInt("PP Helper", "decimalPrecision", 2, true); }
public static void LoadIni() { if (config.HasKey("BeatSaverDownloader", "beatsaverURL")) { beatsaverURL = config.GetString("BeatSaverDownloader", "beatsaverURL", "https://beatsaver.com"); if (string.IsNullOrEmpty(beatsaverURL)) { config.SetString("BeatSaverDownloader", "beatsaverURL", "https://beatsaver.com"); beatsaverURL = "https://beatsaver.com"; } } else { LoadOldIni(); SaveConfig(); return; } apiAccessToken = config.GetString("BeatSaverDownloader", "apiAccessToken", apiTokenPlaceholder, true); disableDeleteButton = config.GetBool("BeatSaverDownloader", "disableDeleteButton", false, true); deleteToRecycleBin = config.GetBool("BeatSaverDownloader", "deleteToRecycleBin", true, true); enableSongIcons = config.GetBool("BeatSaverDownloader", "enableSongIcons", true, true); rememberLastPackAndSong = config.GetBool("BeatSaverDownloader", "rememberLastPackAndSong", false, true); lastSelectedSong = config.GetString("BeatSaverDownloader", "lastSelectedSong", "", true); lastSelectedPack = config.GetString("BeatSaverDownloader", "lastSelectedPack", "", true); lastSelectedSortMode = (SortMode)config.GetInt("BeatSaverDownloader", "lastSelectedSortMode", 0, true); maxSimultaneousDownloads = config.GetInt("BeatSaverDownloader", "maxSimultaneousDownloads", 3, true); fastScrollSpeed = config.GetInt("BeatSaverDownloader", "fastScrollSpeed", 5, true); }
public void OnApplicationStart() { BSEvents.menuSceneLoadedFresh += OnMenuSceneLoadedFresh; config = new BS_Utils.Utilities.Config("ScoreboardStylist"); hexMap = new Dictionary <string, string>(); hexMap.Add("#FFFFFF", config.GetString("Colors", "default", "#FFFFFF", true)); hexMap.Add("#F96854", config.GetString("Colors", "patron", "#F96854", true)); hexMap.Add("#1ABC9C", config.GetString("Colors", "rankingTeam", "#1ABC9C", true)); hexMap.Add("#FF03E3", config.GetString("Colors", "staff", "#FF03E3", true)); hexMap.Add("#FFD42A", config.GetString("Colors", "percent", "#FFD42A", true)); hexMap.Add("#6772E5", config.GetString("Colors", "pp", "#6772E5", true)); rankColor = config.GetString("Colors", "rank", "#FFFFFF", true); scoreColor = config.GetString("Colors", "score", "#FFFFFF", true); var harmony = HarmonyInstance.Create("com.rolo.BeatSaber.ScoreboardStylist"); harmony.PatchAll(Assembly.GetExecutingAssembly()); }
/// <summary> /// Automatically assigns fields of an input from the Config file, and attempts to assign defaults. /// If you want to use this code, it is recommended to copy this yourself. /// </summary> public static T DeserializeFromConfig <T>(T input, string DisplayName) { Type type = input.GetType(); MemberInfo[] infos = type.GetMembers(BindingFlags.Public | BindingFlags.Instance); foreach (MemberInfo info in infos) { if (info.MemberType != MemberTypes.Field || info.Name.ToLower().Contains("config")) { continue; } FieldInfo finfo = (FieldInfo)info; string value = config.GetString(DisplayName, info.Name, null); if (value == null) { Plugin.Log($"Failed to load variable {info.Name} in {type.Name}. Using defaults...", LogInfo.Info); continue; } if (finfo.FieldType == typeof(ICounterMode)) { input.SetPrivateField(info.Name, Enum.Parse(typeof(ICounterMode), value)); } else if (finfo.FieldType == typeof(ICounterPositions)) { input.SetPrivateField(info.Name, Enum.Parse(typeof(ICounterPositions), value)); } else { input.SetPrivateField(info.Name, Convert.ChangeType(value, finfo.FieldType)); } if (finfo.GetValue(input) == null) { throw new Exception(); } } return(input); }
/// <summary> /// Automatically assigns fields of an input from the Config file, and attempts to assign defaults if they do not exist. /// While this might work for objects outside of Counters+, it is recommended to yoink this code from GitHub and modify it yourself. /// </summary> public static object DeserializeFromConfig(object input, string DisplayName) { bool resetToDefaults = false; Type type = input.GetType(); MemberInfo[] infos = type.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic); foreach (MemberInfo info in infos) { if (info.MemberType != MemberTypes.Field || info.Name.ToLower().Contains("config")) { continue; } FieldInfo finfo = (FieldInfo)info; string value = config.GetString(DisplayName, info.Name, null); if (value == null) { if (type.Name.Contains("Main")) { value = finfo.GetValue(ConfigDefaults.MainDefaults).ToString(); } else if (!type.Name.Contains("Custom")) { value = finfo.GetValue(ConfigDefaults.Defaults[DisplayName]).ToString(); } if (value == null) { continue; } Plugin.Log($"Failed to load variable {info.Name} in {type.Name}. Resetting to defaults...", LogInfo.Info); resetToDefaults = true; } if (finfo.FieldType == typeof(ICounterMode)) { input.SetPrivateField(info.Name, Enum.Parse(typeof(ICounterMode), value)); } else if (finfo.FieldType == typeof(ICounterPositions)) { input.SetPrivateField(info.Name, Enum.Parse(typeof(ICounterPositions), value)); } else { input.SetPrivateField(info.Name, Convert.ChangeType(value, finfo.FieldType)); } if (finfo.GetValue(input) == null) { throw new Exception(); } } if (resetToDefaults) { if (type.Name.Contains("Main")) { (input as MainConfigModel).Save(); } else if (!type.Name.Contains("Custom")) { (input as ConfigModel).Save(); } } return(input); }
public static void Load() { beatsaverURL = config.GetString("BeatSaverDownloader", "beatsaverURL", "https://beatsaver.com", true); scoresaberURL = config.GetString("BeatSaverDownloader", "scoresaberURL", "https://scoresaber.com", true); maxSimultaneousDownloads = config.GetInt("BeatSaverDownloader", "maxSimultaneousDownloads", 3, true); }