-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathFixLocaleIssues.cs
More file actions
77 lines (69 loc) · 2.51 KB
/
FixLocaleIssues.cs
File metadata and controls
77 lines (69 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Globalization;
using AquaMai.Config.Attributes;
using HarmonyLib;
using JetBrains.Annotations;
using Manager;
namespace AquaMai.Mods.Fix;
// Fixes various locale issues that pop up if the game runs in a different locale than ja-JP.
[ConfigSection(exampleHidden: true, defaultOn: true)]
public class FixLocaleIssues
{
private static readonly CultureInfo JapanCultureInfo = new CultureInfo("ja-JP");
[CanBeNull] private static TimeZoneInfo _tokyoStandardTime;
[HarmonyPrefix]
[HarmonyPatch(typeof(int), "Parse", typeof(string))]
private static bool int_Parse(ref int __result, string s)
{
__result = int.Parse(s, JapanCultureInfo);
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(float), "Parse", typeof(string))]
private static bool float_Parse(ref float __result, string s)
{
__result = float.Parse(s, JapanCultureInfo);
return false;
}
// Forces local timezone to be UTC+9, since segatools didn't patch it properly until recent versions,
// which doesn't actually work well with maimai.
[HarmonyPrefix]
[HarmonyPatch(typeof(DateTime), "get_Now")]
private static bool DateTime_get_Now(ref DateTime __result)
{
if (_tokyoStandardTime == null)
{
try
{
_tokyoStandardTime = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");
}
catch (Exception e) when (e is TimeZoneNotFoundException or InvalidTimeZoneException)
{
_tokyoStandardTime = TimeZoneInfo.CreateCustomTimeZone(
"Tokyo Standard Time",
TimeManager.JpTime,
"(UTC+09:00) Osaka, Sapporo, Tokyo",
"Tokyo Standard Time",
"Tokyo Daylight Time",
null,
true);
}
}
__result = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, _tokyoStandardTime!);
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(DateTime), "Parse", typeof(string))]
private static bool DateTime_Parse(ref DateTime __result, string s)
{
__result = DateTime.Parse(s, JapanCultureInfo);
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(DateTime), "ToShortDateString")]
private static bool DateTime_ToShortDateString(DateTime __instance, ref string __result)
{
__result = __instance.ToString("d", JapanCultureInfo);
return false;
}
}