-
Notifications
You must be signed in to change notification settings - Fork 45
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.
Open
Changes from 2 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,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] | ||
beer-psi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [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) | ||
beer-psi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| 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); | ||
beer-psi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| __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; | ||
| } | ||
| } | ||
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.