Skip to content

Commit

Permalink
CAM-38 Fix chart transmuting issue with invariant culture parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
AshtonMemer committed Jan 22, 2024
1 parent be43ed9 commit cfdbe4d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
13 changes: 7 additions & 6 deletions BmsLoader.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 },
Expand All @@ -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];

Expand All @@ -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);
}
Expand Down Expand Up @@ -545,7 +546,7 @@ private static void ProcessBossData(Bms bms)
private static void ProcessDelay(Bms bms)
{
var scene = bms.Info["GENRE"]?.GetValue<string>() ?? string.Empty;
var sceneIndex = int.Parse(scene.Split('_')[1]);
var sceneIndex = int.Parse(scene.Split('_')[1], CultureInfo.InvariantCulture);
var sceneInfo = Singleton<StageBattleComponent>.instance.sceneInfo;
var delayCache = new Dictionary<string, Decimal>();

Expand Down
2 changes: 1 addition & 1 deletion Data/Bms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>() ?? "1");
var speedAir = int.Parse(Info["PLAYER"]?.GetValue<string>() ?? "1", CultureInfo.InvariantCulture);
var speedGround = speedAir;

var objectId = 1;
Expand Down
5 changes: 3 additions & 2 deletions Managers/AlbumManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CustomAlbums.Data;
using System.Globalization;
using CustomAlbums.Data;
using Il2CppPeroTools2.Resources;
using UnityEngine;
using Logger = CustomAlbums.Utilities.Logger;
Expand Down Expand Up @@ -78,7 +79,7 @@ public static IEnumerable<string> 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)
Expand Down
2 changes: 1 addition & 1 deletion Patches/AssetPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions Patches/HiddenSupportPatch.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CustomAlbums.Managers;
using System.Globalization;
using CustomAlbums.Managers;
using CustomAlbums.Utilities;
using HarmonyLib;
using Il2Cpp;
Expand Down Expand Up @@ -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<bool>)delegate { return __instance.IsInvokeHideBms(albumUid); }
Expand Down

0 comments on commit cfdbe4d

Please sign in to comment.