diff --git a/SMAPI.Mods.CustomLocalization.csproj b/CustomLocalization.csproj
similarity index 57%
rename from SMAPI.Mods.CustomLocalization.csproj
rename to CustomLocalization.csproj
index b421036..4a88e39 100644
--- a/SMAPI.Mods.CustomLocalization.csproj
+++ b/CustomLocalization.csproj
@@ -12,19 +12,7 @@
- ..\libs\0Harmony.dll
-
-
- ..\libs\Mono.Android.dll
-
-
- ..\libs\\MonoGame.Framework.dll
-
-
- ..\libs\StardewModdingAPI.dll
-
-
- ..\libs\\StardewValley.dll
+ ..\..\libs\0Harmony.dll
@@ -33,4 +21,7 @@
PreserveNewest
+
+
+
diff --git a/ModEntry.cs b/ModEntry.cs
index 8e93c71..2756a7b 100644
--- a/ModEntry.cs
+++ b/ModEntry.cs
@@ -1,13 +1,13 @@
+using System;
using System.Collections.Generic;
-using System.Reflection;
-using Android.OS;
using Harmony;
+using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
+using StardewModdingAPI.Mods.CustomLocalization.Rewrites;
using StardewValley;
using StardewValley.BellsAndWhistles;
using StardewValley.Menus;
-using StardewValley.Mobile;
using StardewValley.Objects;
using StardewValley.Projectiles;
@@ -21,6 +21,8 @@ namespace StardewModdingAPI.Mods.CustomLocalization
public static string ModPath;
+ public static IReflectionHelper Reflection;
+
private static ModEntry Instance;
public static void SaveConfig()
@@ -30,14 +32,12 @@ namespace StardewModdingAPI.Mods.CustomLocalization
public override void Entry(IModHelper helper)
{
- if (Build.VERSION.SdkInt < BuildVersionCodes.M)
- return;
Instance = this;
ModConfig = helper.ReadConfig();
ModPath = helper.DirectoryPath;
monitor = this.Monitor;
- HarmonyInstance harmony = HarmonyInstance.Create("zaneyork.CustomLocalization");
- harmony.PatchAll(Assembly.GetExecutingAssembly());
+ Reflection = helper.Reflection;
+ DoPatch();
Dictionary dictionary = this.Helper.Reflection.GetField>(Game1.content, "_localizedAsset").GetValue();
Dictionary dictionaryAssets = this.Helper.Reflection.GetField>(Game1.content, "loadedAssets").GetValue();
@@ -58,6 +58,66 @@ namespace StardewModdingAPI.Mods.CustomLocalization
}
}
+ private static void DoPatch()
+ {
+ HarmonyInstance harmony = HarmonyInstance.Create("zaneyork.CustomLocalization");
+ harmony.Patch(
+ original: AccessTools.DeclaredMethod(typeof(TitleContainer), "OpenStream"),
+ prefix: new HarmonyMethod(typeof(TitleContainerRewrites.OpenStreamRewrite), nameof(TitleContainerRewrites.OpenStreamRewrite.Prefix))
+ );
+ harmony.Patch(
+ original: AccessTools.DeclaredMethod(typeof(StartupPreferences), "readSettings"),
+ postfix: new HarmonyMethod(typeof(StartupPreferencesRewrites.ReadSettingsRewrite), nameof(StartupPreferencesRewrites.ReadSettingsRewrite.Postfix))
+ );
+ harmony.Patch(
+ original: AccessTools.DeclaredMethod(typeof(StartupPreferences), "writeSettings"),
+ prefix: new HarmonyMethod(typeof(StartupPreferencesRewrites.WriteSettingsRewrite), nameof(StartupPreferencesRewrites.WriteSettingsRewrite.Prefix)),
+ postfix: new HarmonyMethod(typeof(StartupPreferencesRewrites.WriteSettingsRewrite), nameof(StartupPreferencesRewrites.WriteSettingsRewrite.Postfix))
+ );
+ harmony.Patch(
+ original: AccessTools.DeclaredMethod(typeof(StartupPreferences), "writeSettings"),
+ prefix: new HarmonyMethod(typeof(StartupPreferencesRewrites.WriteSettingsRewrite), nameof(StartupPreferencesRewrites.WriteSettingsRewrite.Prefix)),
+ postfix: new HarmonyMethod(typeof(StartupPreferencesRewrites.WriteSettingsRewrite), nameof(StartupPreferencesRewrites.WriteSettingsRewrite.Postfix))
+ );
+ harmony.Patch(
+ original: AccessTools.DeclaredMethod(typeof(SpriteText), "OnLanguageChange"),
+ prefix: new HarmonyMethod(typeof(SpriteTextRewrites.OnLanguageChangeRewrite), nameof(SpriteTextRewrites.OnLanguageChangeRewrite.Prefix))
+ );
+ harmony.Patch(
+ original: AccessTools.DeclaredMethod(typeof(SpriteText), "setUpCharacterMap"),
+ prefix: new HarmonyMethod(typeof(SpriteTextRewrites.SetUpCharacterMapRewrite), nameof(SpriteTextRewrites.SetUpCharacterMapRewrite.Prefix))
+ );
+ harmony.Patch(
+ original: AccessTools.DeclaredMethod(typeof(LocalizedContentManager), "LanguageCodeString"),
+ prefix: new HarmonyMethod(typeof(LocalizedContentManagerRewrites.LanguageCodeStringRewrite), nameof(LocalizedContentManagerRewrites.LanguageCodeStringRewrite.Prefix))
+ );
+ harmony.Patch(
+ original: AccessTools.DeclaredProperty(typeof(LocalizedContentManager), "CurrentLanguageLatin").GetMethod,
+ prefix: new HarmonyMethod(typeof(LocalizedContentManagerRewrites.GetCurrentLanguageLatinRewrite), nameof(LocalizedContentManagerRewrites.GetCurrentLanguageLatinRewrite.Prefix))
+ );
+
+ Type mobileMenuType = AccessTools.TypeByName("StardewValley.Menus.LanguageSelectionMobile");
+ if (mobileMenuType != null)
+ {
+ harmony.Patch(
+ original: AccessTools.DeclaredMethod(mobileMenuType, "draw", new Type[] { typeof(SpriteBatch) }),
+ prefix: new HarmonyMethod(typeof(LanguageSelectionMobileRewrites.DrawRewrite), nameof(LanguageSelectionMobileRewrites.DrawRewrite.Prefix))
+ );
+ harmony.Patch(
+ original: AccessTools.DeclaredMethod(mobileMenuType, "releaseLeftClick"),
+ prefix: new HarmonyMethod(typeof(LanguageSelectionMobileRewrites.ReleaseLeftClickRewrite), nameof(LanguageSelectionMobileRewrites.ReleaseLeftClickRewrite.Prefix))
+ );
+ harmony.Patch(
+ original: AccessTools.DeclaredMethod(mobileMenuType, "setCurrentItemIndex"),
+ prefix: new HarmonyMethod(typeof(LanguageSelectionMobileRewrites.SetCurrentItemIndexRewrite), nameof(LanguageSelectionMobileRewrites.SetCurrentItemIndexRewrite.Prefix))
+ );
+ harmony.Patch(
+ original: AccessTools.DeclaredMethod(mobileMenuType, "SetupButtons"),
+ transpiler: new HarmonyMethod(typeof(LanguageSelectionMobileRewrites.SetupButtonsRewrite), nameof(LanguageSelectionMobileRewrites.SetupButtonsRewrite.Transpiler))
+ );
+ }
+ }
+
private void LoadContent()
{
Game1.concessionsSpriteSheet = ((ContentManager)Game1.content).Load("LooseSprites\\Concessions");
@@ -77,17 +137,26 @@ namespace StardewModdingAPI.Mods.CustomLocalization
Game1.giftboxTexture = ((ContentManager)Game1.content).Load("LooseSprites\\Giftbox");
Game1.controllerMaps = ((ContentManager)Game1.content).Load("LooseSprites\\ControllerMaps");
Game1.animations = ((ContentManager)Game1.content).Load("TileSheets\\animations");
- Game1.mobileSpriteSheet = ((ContentManager)Game1.content).Load("LooseSprites\\MobileAtlas_manually_made");
+ Reflection.GetField(typeof(Game1), "mobileSpriteSheet", false)?.SetValue(((ContentManager)Game1.content).Load("LooseSprites\\MobileAtlas_manually_made"));
Game1.achievements = (Dictionary)((ContentManager)Game1.content).Load>("Data\\Achievements");
Game1.NPCGiftTastes = (IDictionary)((ContentManager)Game1.content).Load>("Data\\NPCGiftTastes");
Game1.onScreenMenus.Clear();
- this.Helper.Reflection.GetMethod(Game1.game1, "TranslateFields").Invoke();
+ Reflection.GetMethod(Game1.game1, "TranslateFields").Invoke();
Game1.dayTimeMoneyBox = new DayTimeMoneyBox();
- Game1.dayTimeMoneyBox.game1 = Game1.game1;
+ Reflection.GetField(Game1.dayTimeMoneyBox, "game1", false)?.SetValue(Game1.game1);
Game1.onScreenMenus.Add((IClickableMenu)Game1.dayTimeMoneyBox);
- Game1.toolbar = new Toolbar();
- Game1.virtualJoypad = new VirtualJoypad();
- Game1.onScreenMenus.Add((IClickableMenu)Game1.toolbar);
+ IReflectedField fieldToolBar = Helper.Reflection.GetField(typeof(Game1), "toolbar", false);
+ fieldToolBar?.SetValue(new Toolbar());
+ Type typeVirtualJoypad = AccessTools.TypeByName("StardewValley.Mobile.VirtualJoypad");
+ if(typeVirtualJoypad != null)
+ {
+ object virtualJoypad = AccessTools.CreateInstance(typeVirtualJoypad);
+ Reflection.GetField