From cfdbe4def40d3f14ee4cc8c90faffc4cfdd7ee49 Mon Sep 17 00:00:00 2001 From: Ashton <53633401+AshtonMemer@users.noreply.github.com> Date: Sun, 21 Jan 2024 19:21:45 -0600 Subject: [PATCH] CAM-38 Fix chart transmuting issue with invariant culture parsing. --- BmsLoader.cs | 13 +++++++------ Data/Bms.cs | 2 +- Managers/AlbumManager.cs | 5 +++-- Patches/AssetPatch.cs | 2 +- Patches/HiddenSupportPatch.cs | 5 +++-- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/BmsLoader.cs b/BmsLoader.cs index 74d66b6..04d7fd8 100644 --- a/BmsLoader.cs +++ b/BmsLoader.cs @@ -1,4 +1,5 @@ -using System.Text.Json.Nodes; +using System.Globalization; +using System.Text.Json.Nodes; using CustomAlbums.Data; using CustomAlbums.Managers; using CustomAlbums.Utilities; @@ -63,11 +64,11 @@ internal static Bms Load(MemoryStream stream, string bmsName) if (!key.Contains("BPM")) continue; var bpmKey = string.IsNullOrEmpty(key[3..]) ? "00" : key[3..]; - bpmDict.Add(bpmKey, float.Parse(value)); + bpmDict.Add(bpmKey, float.Parse(value, CultureInfo.InvariantCulture)); if (bpmKey != "00") continue; - var freq = 60f / float.Parse(value) * 4f; + var freq = 60f / float.Parse(value, CultureInfo.InvariantCulture) * 4f; var obj = new JsonObject { { "tick", 0f }, @@ -82,7 +83,7 @@ internal static Bms Load(MemoryStream stream, string bmsName) var key = split[0]; var value = split[1]; - var beat = int.Parse(key[..3]); + var beat = int.Parse(key[..3], CultureInfo.InvariantCulture); var typeCode = key.Substring(3, 2); var type = Bms.Channels[typeCode]; @@ -91,7 +92,7 @@ internal static Bms Load(MemoryStream stream, string bmsName) var obj = new JsonObject { { "beat", beat }, - { "percent", float.Parse(value) } + { "percent", float.Parse(value, CultureInfo.InvariantCulture) } }; notePercents.Add(beat, obj); } @@ -545,7 +546,7 @@ private static void ProcessBossData(Bms bms) private static void ProcessDelay(Bms bms) { var scene = bms.Info["GENRE"]?.GetValue() ?? string.Empty; - var sceneIndex = int.Parse(scene.Split('_')[1]); + var sceneIndex = int.Parse(scene.Split('_')[1], CultureInfo.InvariantCulture); var sceneInfo = Singleton.instance.sceneInfo; var delayCache = new Dictionary(); diff --git a/Data/Bms.cs b/Data/Bms.cs index 625e1b3..f08bf49 100644 --- a/Data/Bms.cs +++ b/Data/Bms.cs @@ -400,7 +400,7 @@ public JsonArray GetNoteData() if (NoteData is null || NoteData.Count == 0) InitNoteData(); var processed = new JsonArray(); - var speedAir = int.Parse(Info["PLAYER"]?.GetValue() ?? "1"); + var speedAir = int.Parse(Info["PLAYER"]?.GetValue() ?? "1", CultureInfo.InvariantCulture); var speedGround = speedAir; var objectId = 1; diff --git a/Managers/AlbumManager.cs b/Managers/AlbumManager.cs index 80257ba..899d961 100644 --- a/Managers/AlbumManager.cs +++ b/Managers/AlbumManager.cs @@ -1,4 +1,5 @@ -using CustomAlbums.Data; +using System.Globalization; +using CustomAlbums.Data; using Il2CppPeroTools2.Resources; using UnityEngine; using Logger = CustomAlbums.Utilities.Logger; @@ -78,7 +79,7 @@ public static IEnumerable GetAllUid() public static Album GetByUid(string uid) { - return LoadedAlbums.FirstOrDefault(album => album.Value.Index == int.Parse(uid[4..])).Value; + return LoadedAlbums.FirstOrDefault(album => album.Value.Index == int.Parse(uid[4..], CultureInfo.InvariantCulture)).Value; } public static string GetAlbumName(this Album album) diff --git a/Patches/AssetPatch.cs b/Patches/AssetPatch.cs index e105ef4..a06c5fb 100644 --- a/Patches/AssetPatch.cs +++ b/Patches/AssetPatch.cs @@ -205,7 +205,7 @@ internal static void InitializeHandler() AlbumManager.LoadedAlbums.TryGetValue(albumKey, out var album); if (suffix.StartsWith("_map")) { - newAsset = album?.Sheets[int.Parse(suffix[^1].ToString())].GetStage(); + newAsset = album?.Sheets[int.Parse(suffix[^1].ToString(), CultureInfo.InvariantCulture)].GetStage(); // Do not cache the StageInfos, this should be loaded into memory only when we need it cache = false; } diff --git a/Patches/HiddenSupportPatch.cs b/Patches/HiddenSupportPatch.cs index 13af875..f5f60cf 100644 --- a/Patches/HiddenSupportPatch.cs +++ b/Patches/HiddenSupportPatch.cs @@ -1,4 +1,5 @@ -using CustomAlbums.Managers; +using System.Globalization; +using CustomAlbums.Managers; using CustomAlbums.Utilities; using HarmonyLib; using Il2Cpp; @@ -44,7 +45,7 @@ private static void Postfix(SpecialSongManager __instance) albumUid, value.Info.HideBmsDifficulty == "0" ? value.Sheets.ContainsKey(3) ? 3 : 2 - : int.Parse(value.Info.HideBmsDifficulty), + : int.Parse(value.Info.HideBmsDifficulty, CultureInfo.InvariantCulture), 4, $"{key}_map4", (Il2CppSystem.Func)delegate { return __instance.IsInvokeHideBms(albumUid); }