From 2c6087ce41e4c5b8a8f215274df97f7599cafce2 Mon Sep 17 00:00:00 2001 From: Darren Horrocks Date: Sat, 10 Aug 2024 21:40:09 +0100 Subject: [PATCH] fix for "Hard-coded MM/DD/YYYY date format in save menus is wrong for non-Americans" bug on the forums --- .../SaveLoadDateTimeFix.cs | 10 +++++ .../SaveLoadDateTimeFix_Patch.cs | 37 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/CommunityFixes/Fix/SaveLoadDateTimeFix/SaveLoadDateTimeFix.cs create mode 100644 src/CommunityFixes/Fix/SaveLoadDateTimeFix/SaveLoadDateTimeFix_Patch.cs diff --git a/src/CommunityFixes/Fix/SaveLoadDateTimeFix/SaveLoadDateTimeFix.cs b/src/CommunityFixes/Fix/SaveLoadDateTimeFix/SaveLoadDateTimeFix.cs new file mode 100644 index 0000000..53b2021 --- /dev/null +++ b/src/CommunityFixes/Fix/SaveLoadDateTimeFix/SaveLoadDateTimeFix.cs @@ -0,0 +1,10 @@ +namespace CommunityFixes.Fix.STFUFix; + +[Fix("Save/Load Date/Time Fix")] +public class SaveLoadDateTimeFix : BaseFix +{ + public override void OnInitialized() + { + HarmonyInstance.PatchAll(typeof(SaveLoadDateTimeFix_Patch)); + } +} diff --git a/src/CommunityFixes/Fix/SaveLoadDateTimeFix/SaveLoadDateTimeFix_Patch.cs b/src/CommunityFixes/Fix/SaveLoadDateTimeFix/SaveLoadDateTimeFix_Patch.cs new file mode 100644 index 0000000..41dba06 --- /dev/null +++ b/src/CommunityFixes/Fix/SaveLoadDateTimeFix/SaveLoadDateTimeFix_Patch.cs @@ -0,0 +1,37 @@ +using HarmonyLib; +using KSP.Game; +using System.Globalization; +using UnityEngine.UI; + +namespace CommunityFixes.Fix.STFUFix; + +internal class SaveLoadDateTimeFix_Patch +{ + [HarmonyPatch(typeof(SaveLoadDialogFileEntry), nameof(SaveLoadDialogFileEntry.Initialize), new Type[] { typeof(ExtendedSaveFileInfo), typeof(bool), typeof(bool) })] + [HarmonyPrefix] + public static void SaveLoadDialogFileEntry_Initialize(SaveLoadDialogFileEntry __instance, ExtendedSaveFileInfo fileInfo, bool loading, bool isLastPlayed) + { + CultureInfo.DefaultThreadCurrentCulture = Thread.CurrentThread.CurrentUICulture; + } + + [HarmonyPatch(typeof(SaveLoadDialog), nameof(SaveLoadDialog.UpdateLoadMenuGameInformation), new Type[] { typeof(ExtendedSaveFileInfo), typeof(Image) })] + [HarmonyPrefix] + public static void SaveLoadDialog_UpdateLoadMenuGameInformation(SaveLoadDialog __instance, ExtendedSaveFileInfo fileInfo, Image thumnailScreenshot) + { + CultureInfo.DefaultThreadCurrentCulture = Thread.CurrentThread.CurrentUICulture; + } + + [HarmonyPatch(typeof(CampaignLoadMenu), nameof(CampaignLoadMenu.UpdateLoadMenuGameInformation), new Type[] { typeof(ExtendedSaveFileInfo), typeof(Image) })] + [HarmonyPrefix] + public static void CampaignLoadMenu_UpdateLoadMenuGameInformation(CampaignLoadMenu __instance, ExtendedSaveFileInfo fileInfo, Image thumnailScreenshot) + { + CultureInfo.DefaultThreadCurrentCulture = Thread.CurrentThread.CurrentUICulture; + } + + [HarmonyPatch(typeof(CampaignTileEntry), nameof(CampaignTileEntry.Initialize), new Type[] { typeof(ExtendedSaveFileInfo), typeof(CampaignLoadMenu), typeof(CampaignMenu) })] + [HarmonyPrefix] + public static void CampaignTileEntry_UpdateLoadMenuGameInformation(CampaignTileEntry __instance, ExtendedSaveFileInfo fileInfo, CampaignLoadMenu loadMenu, CampaignMenu campaignMenu) + { + CultureInfo.DefaultThreadCurrentCulture = Thread.CurrentThread.CurrentUICulture; + } +} \ No newline at end of file