-
Notifications
You must be signed in to change notification settings - Fork 44
feat: FixLocaleIssues #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
beer-psi
wants to merge
8
commits into
MuNET-OSS:main
Choose a base branch
from
beerpsi-forks:patch-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+79
−0
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
da3640f
feat: FixLocaleIssues
beer-psi c4ccf67
fix: resolve ambiguity for DateTime.Parse
beer-psi 8e3a571
Update FixLocaleIssues.cs
beer-psi 75ae6c7
also sets culture for current thread
beer-psi 6e7cc56
fix: revert setting default thread locale
beer-psi 111881c
Add in locale overrides anyways, just in case
beer-psi 98a722d
fix: Patch straight at the root of this problem
beer-psi 0a5fddf
Update FixLocaleIssues.cs
beer-psi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| using System; | ||
| using System.Globalization; | ||
| using System.Threading; | ||
| using AquaMai.Config.Attributes; | ||
| using HarmonyLib; | ||
| using JetBrains.Annotations; | ||
| using Manager; | ||
| using MelonLoader; | ||
|
|
||
| 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("ja-JP"); | ||
| [CanBeNull] private static TimeZoneInfo _tokyoStandardTime; | ||
|
|
||
| public static void OnBeforePatch() | ||
| { | ||
| 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); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| MelonLogger.Warning($"Could not get JST timezone, DateTime.Now patch will not work: {e.StackTrace}"); | ||
| } | ||
| } | ||
|
|
||
| // This covers all calls to T.Parse(String) or T.Parse(String, NumberStyles) | ||
| // where T is a number. Sets the current thread's culture to Japan before calling | ||
| // the original getter, since that's what the original getter depends on. | ||
| // | ||
| // While we already set the thread's culture on the OnBeforePatch lifecycle hook, | ||
| // it seems to not apply to the game at all for some reason. | ||
| [HarmonyPrefix] | ||
| [HarmonyPatch(typeof(NumberFormatInfo), "get_CurrentInfo")] | ||
| public static bool NumberFormatInfo_get_CurrentInfo(ref NumberFormatInfo __result) | ||
| { | ||
| __result = JapanCultureInfo.NumberFormat; | ||
| return false; | ||
| } | ||
|
|
||
| // Same for datetimes. | ||
| [HarmonyPrefix] | ||
| [HarmonyPatch(typeof(DateTimeFormatInfo), "get_CurrentInfo")] | ||
| public static bool DateTimeFormatInfo_get_CurrentInfo(ref DateTimeFormatInfo __result) | ||
| { | ||
| __result = JapanCultureInfo.DateTimeFormat; | ||
| 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) | ||
beer-psi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| return true; | ||
| } | ||
|
|
||
| __result = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, _tokyoStandardTime!); | ||
| return false; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.