Change patch mode to make it available for other platform
This commit is contained in:
parent
02aabe7a45
commit
2446150121
|
@ -12,19 +12,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="0Harmony">
|
<Reference Include="0Harmony">
|
||||||
<HintPath>..\libs\0Harmony.dll</HintPath>
|
<HintPath>..\..\libs\0Harmony.dll</HintPath>
|
||||||
</Reference>
|
|
||||||
<Reference Include="Mono.Android">
|
|
||||||
<HintPath>..\libs\Mono.Android.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="MonoGame.Framework">
|
|
||||||
<HintPath>..\libs\\MonoGame.Framework.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="StardewModdingAPI">
|
|
||||||
<HintPath>..\libs\StardewModdingAPI.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="StardewValley">
|
|
||||||
<HintPath>..\libs\\StardewValley.dll</HintPath>
|
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -33,4 +21,7 @@
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="3.0.0-beta.7" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
95
ModEntry.cs
95
ModEntry.cs
|
@ -1,13 +1,13 @@
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
|
||||||
using Android.OS;
|
|
||||||
using Harmony;
|
using Harmony;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Content;
|
using Microsoft.Xna.Framework.Content;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using StardewModdingAPI.Mods.CustomLocalization.Rewrites;
|
||||||
using StardewValley;
|
using StardewValley;
|
||||||
using StardewValley.BellsAndWhistles;
|
using StardewValley.BellsAndWhistles;
|
||||||
using StardewValley.Menus;
|
using StardewValley.Menus;
|
||||||
using StardewValley.Mobile;
|
|
||||||
using StardewValley.Objects;
|
using StardewValley.Objects;
|
||||||
using StardewValley.Projectiles;
|
using StardewValley.Projectiles;
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@ namespace StardewModdingAPI.Mods.CustomLocalization
|
||||||
|
|
||||||
public static string ModPath;
|
public static string ModPath;
|
||||||
|
|
||||||
|
public static IReflectionHelper Reflection;
|
||||||
|
|
||||||
private static ModEntry Instance;
|
private static ModEntry Instance;
|
||||||
|
|
||||||
public static void SaveConfig()
|
public static void SaveConfig()
|
||||||
|
@ -30,14 +32,12 @@ namespace StardewModdingAPI.Mods.CustomLocalization
|
||||||
|
|
||||||
public override void Entry(IModHelper helper)
|
public override void Entry(IModHelper helper)
|
||||||
{
|
{
|
||||||
if (Build.VERSION.SdkInt < BuildVersionCodes.M)
|
|
||||||
return;
|
|
||||||
Instance = this;
|
Instance = this;
|
||||||
ModConfig = helper.ReadConfig<ModConfig>();
|
ModConfig = helper.ReadConfig<ModConfig>();
|
||||||
ModPath = helper.DirectoryPath;
|
ModPath = helper.DirectoryPath;
|
||||||
monitor = this.Monitor;
|
monitor = this.Monitor;
|
||||||
HarmonyInstance harmony = HarmonyInstance.Create("zaneyork.CustomLocalization");
|
Reflection = helper.Reflection;
|
||||||
harmony.PatchAll(Assembly.GetExecutingAssembly());
|
DoPatch();
|
||||||
|
|
||||||
Dictionary<string, bool> dictionary = this.Helper.Reflection.GetField<Dictionary<string, bool>>(Game1.content, "_localizedAsset").GetValue();
|
Dictionary<string, bool> dictionary = this.Helper.Reflection.GetField<Dictionary<string, bool>>(Game1.content, "_localizedAsset").GetValue();
|
||||||
Dictionary<string, object> dictionaryAssets = this.Helper.Reflection.GetField<Dictionary<string, object>>(Game1.content, "loadedAssets").GetValue();
|
Dictionary<string, object> dictionaryAssets = this.Helper.Reflection.GetField<Dictionary<string, object>>(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()
|
private void LoadContent()
|
||||||
{
|
{
|
||||||
Game1.concessionsSpriteSheet = ((ContentManager)Game1.content).Load<Texture2D>("LooseSprites\\Concessions");
|
Game1.concessionsSpriteSheet = ((ContentManager)Game1.content).Load<Texture2D>("LooseSprites\\Concessions");
|
||||||
|
@ -77,17 +137,26 @@ namespace StardewModdingAPI.Mods.CustomLocalization
|
||||||
Game1.giftboxTexture = ((ContentManager)Game1.content).Load<Texture2D>("LooseSprites\\Giftbox");
|
Game1.giftboxTexture = ((ContentManager)Game1.content).Load<Texture2D>("LooseSprites\\Giftbox");
|
||||||
Game1.controllerMaps = ((ContentManager)Game1.content).Load<Texture2D>("LooseSprites\\ControllerMaps");
|
Game1.controllerMaps = ((ContentManager)Game1.content).Load<Texture2D>("LooseSprites\\ControllerMaps");
|
||||||
Game1.animations = ((ContentManager)Game1.content).Load<Texture2D>("TileSheets\\animations");
|
Game1.animations = ((ContentManager)Game1.content).Load<Texture2D>("TileSheets\\animations");
|
||||||
Game1.mobileSpriteSheet = ((ContentManager)Game1.content).Load<Texture2D>("LooseSprites\\MobileAtlas_manually_made");
|
Reflection.GetField<Texture2D>(typeof(Game1), "mobileSpriteSheet", false)?.SetValue(((ContentManager)Game1.content).Load<Texture2D>("LooseSprites\\MobileAtlas_manually_made"));
|
||||||
Game1.achievements = (Dictionary<int, string>)((ContentManager)Game1.content).Load<Dictionary<int, string>>("Data\\Achievements");
|
Game1.achievements = (Dictionary<int, string>)((ContentManager)Game1.content).Load<Dictionary<int, string>>("Data\\Achievements");
|
||||||
Game1.NPCGiftTastes = (IDictionary<string, string>)((ContentManager)Game1.content).Load<Dictionary<string, string>>("Data\\NPCGiftTastes");
|
Game1.NPCGiftTastes = (IDictionary<string, string>)((ContentManager)Game1.content).Load<Dictionary<string, string>>("Data\\NPCGiftTastes");
|
||||||
Game1.onScreenMenus.Clear();
|
Game1.onScreenMenus.Clear();
|
||||||
this.Helper.Reflection.GetMethod(Game1.game1, "TranslateFields").Invoke();
|
Reflection.GetMethod(Game1.game1, "TranslateFields").Invoke();
|
||||||
Game1.dayTimeMoneyBox = new DayTimeMoneyBox();
|
Game1.dayTimeMoneyBox = new DayTimeMoneyBox();
|
||||||
Game1.dayTimeMoneyBox.game1 = Game1.game1;
|
Reflection.GetField<Game1>(Game1.dayTimeMoneyBox, "game1", false)?.SetValue(Game1.game1);
|
||||||
Game1.onScreenMenus.Add((IClickableMenu)Game1.dayTimeMoneyBox);
|
Game1.onScreenMenus.Add((IClickableMenu)Game1.dayTimeMoneyBox);
|
||||||
Game1.toolbar = new Toolbar();
|
IReflectedField<Toolbar> fieldToolBar = Helper.Reflection.GetField<Toolbar>(typeof(Game1), "toolbar", false);
|
||||||
Game1.virtualJoypad = new VirtualJoypad();
|
fieldToolBar?.SetValue(new Toolbar());
|
||||||
Game1.onScreenMenus.Add((IClickableMenu)Game1.toolbar);
|
Type typeVirtualJoypad = AccessTools.TypeByName("StardewValley.Mobile.VirtualJoypad");
|
||||||
|
if(typeVirtualJoypad != null)
|
||||||
|
{
|
||||||
|
object virtualJoypad = AccessTools.CreateInstance(typeVirtualJoypad);
|
||||||
|
Reflection.GetField<object>(typeof(Game1), "virtualJoypad", false)?.SetValue(virtualJoypad);
|
||||||
|
}
|
||||||
|
if (fieldToolBar != null)
|
||||||
|
{
|
||||||
|
Game1.onScreenMenus.Add(fieldToolBar.GetValue());
|
||||||
|
}
|
||||||
Game1.buffsDisplay = new BuffsDisplay();
|
Game1.buffsDisplay = new BuffsDisplay();
|
||||||
Game1.onScreenMenus.Add((IClickableMenu)Game1.buffsDisplay);
|
Game1.onScreenMenus.Add((IClickableMenu)Game1.buffsDisplay);
|
||||||
Game1.dialogueFont = (SpriteFont)((ContentManager)Game1.content).Load<SpriteFont>("Fonts\\SpriteFont1");
|
Game1.dialogueFont = (SpriteFont)((ContentManager)Game1.content).Load<SpriteFont>("Fonts\\SpriteFont1");
|
||||||
|
|
|
@ -14,11 +14,8 @@ namespace StardewModdingAPI.Mods.CustomLocalization.Rewrites
|
||||||
{
|
{
|
||||||
public class LanguageSelectionMobileRewrites
|
public class LanguageSelectionMobileRewrites
|
||||||
{
|
{
|
||||||
[HarmonyPatch(typeof(LanguageSelectionMobile))]
|
|
||||||
[HarmonyPatch("SetupButtons")]
|
|
||||||
public class SetupButtonsRewrite
|
public class SetupButtonsRewrite
|
||||||
{
|
{
|
||||||
[HarmonyTranspiler]
|
|
||||||
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
|
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
|
||||||
{
|
{
|
||||||
var codes = new List<CodeInstruction>(instructions);
|
var codes = new List<CodeInstruction>(instructions);
|
||||||
|
@ -39,43 +36,40 @@ namespace StardewModdingAPI.Mods.CustomLocalization.Rewrites
|
||||||
return codes.AsEnumerable();
|
return codes.AsEnumerable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[HarmonyPatch(typeof(LanguageSelectionMobile))]
|
|
||||||
[HarmonyPatch("setCurrentItemIndex")]
|
|
||||||
public class SetCurrentItemIndexRewrite
|
public class SetCurrentItemIndexRewrite
|
||||||
{
|
{
|
||||||
[HarmonyPrefix]
|
public static void Prefix(object __instance)
|
||||||
public static void Prefix(LanguageSelectionMobile __instance)
|
|
||||||
{
|
{
|
||||||
Rectangle mainBox = (Rectangle)__instance.GetType().GetField("mainBox", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
|
Rectangle mainBox = ModEntry.Reflection.GetField<Rectangle>(__instance, "mainBox").GetValue();
|
||||||
int buttonHeight = (int)__instance.GetType().GetField("buttonHeight", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
|
int buttonHeight = ModEntry.Reflection.GetField<int>(__instance, "buttonHeight").GetValue();
|
||||||
|
int buttonWidth = ModEntry.Reflection.GetField<int>(__instance, "buttonWidth").GetValue();
|
||||||
for (short i = 0; i < ModEntry.ModConfig.locales.Length; i++)
|
for (short i = 0; i < ModEntry.ModConfig.locales.Length; i++)
|
||||||
{
|
{
|
||||||
ModConfig.Locale locale = ModEntry.ModConfig.locales[i];
|
ModConfig.Locale locale = ModEntry.ModConfig.locales[i];
|
||||||
__instance.languages.Add(new ClickableComponent(
|
List<ClickableComponent> languages = ModEntry.Reflection.GetField<List<ClickableComponent>>(__instance, "languages").GetValue();
|
||||||
new Rectangle(mainBox.X + 0x10, (mainBox.Y + 0x10) + (buttonHeight * ModEntry.ModConfig.OriginLocaleCount + i), __instance.buttonWidth, buttonHeight),
|
languages.Add(new ClickableComponent(
|
||||||
|
new Rectangle(mainBox.X + 0x10, (mainBox.Y + 0x10) + (buttonHeight * ModEntry.ModConfig.OriginLocaleCount + i), buttonWidth, buttonHeight),
|
||||||
locale.Name, null));
|
locale.Name, null));
|
||||||
if ((int)(CurrentLanguageCode) == locale.CodeEnum)
|
if ((int)(CurrentLanguageCode) == locale.CodeEnum)
|
||||||
{
|
{
|
||||||
__instance.GetType().GetField("languageCodeName", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).SetValue(__instance, locale.Name);
|
ModEntry.Reflection.GetField<string>(__instance, "languageCodeName").SetValue(locale.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[HarmonyPatch(typeof(LanguageSelectionMobile))]
|
|
||||||
[HarmonyPatch("releaseLeftClick")]
|
|
||||||
public class ReleaseLeftClickRewrite
|
public class ReleaseLeftClickRewrite
|
||||||
{
|
{
|
||||||
[HarmonyPrefix]
|
public static bool Prefix(object __instance, int x, int y)
|
||||||
public static bool Prefix(LanguageSelectionMobile __instance, int x, int y)
|
|
||||||
{
|
{
|
||||||
MobileScrollbox scrollArea = (MobileScrollbox)__instance.GetType().GetField("scrollArea", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
|
object scrollArea = ModEntry.Reflection.GetField<object>(__instance, "scrollArea").GetValue();
|
||||||
if (scrollArea == null || !scrollArea.havePanelScrolled)
|
if (scrollArea == null || !ModEntry.Reflection.GetField<bool>(scrollArea, "havePanelScrolled").GetValue())
|
||||||
{
|
{
|
||||||
foreach (ClickableComponent language in __instance.languages)
|
List<ClickableComponent> languages = ModEntry.Reflection.GetField<List<ClickableComponent>>(__instance, "languages").GetValue();
|
||||||
|
foreach (ClickableComponent language in languages)
|
||||||
{
|
{
|
||||||
if (language.containsPoint(x, y))
|
if (language.containsPoint(x, y))
|
||||||
{
|
{
|
||||||
__instance.GetType().GetField("languageChosen", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).SetValue(__instance, true);
|
ModEntry.Reflection.GetField<bool>(__instance, "languageChosen").SetValue(true);
|
||||||
Game1.playSound("select");
|
Game1.playSound("select");
|
||||||
switch (language.name)
|
switch (language.name)
|
||||||
{
|
{
|
||||||
|
@ -125,25 +119,23 @@ namespace StardewModdingAPI.Mods.CustomLocalization.Rewrites
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
__instance.exitThisMenu(true);
|
ModEntry.Reflection.GetMethod(__instance, "exitThisMenu").Invoke(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (scrollArea == null)
|
if (scrollArea == null)
|
||||||
return false;
|
return false;
|
||||||
scrollArea.releaseLeftClick(x, y);
|
ModEntry.Reflection.GetMethod(scrollArea, "releaseLeftClick").Invoke(x, y);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[HarmonyPatch(typeof(LanguageSelectionMobile))]
|
|
||||||
[HarmonyPatch("draw")]
|
|
||||||
[HarmonyPatch(new Type[] { typeof(SpriteBatch) })]
|
|
||||||
public class DrawRewrite
|
public class DrawRewrite
|
||||||
{
|
{
|
||||||
[HarmonyPrefix]
|
public static bool Prefix(object __instance, SpriteBatch b)
|
||||||
public static bool Prefix(LanguageSelectionMobile __instance, SpriteBatch b)
|
|
||||||
{
|
{
|
||||||
Utility.getTopLeftPositionForCenteringOnScreen(__instance.width, __instance.height - 100, 0, 0);
|
int width = ModEntry.Reflection.GetField<int>(__instance, "width").GetValue();
|
||||||
|
int height = ModEntry.Reflection.GetField<int>(__instance, "height").GetValue();
|
||||||
|
Utility.getTopLeftPositionForCenteringOnScreen(width, height - 100, 0, 0);
|
||||||
SpriteBatch spriteBatch = b;
|
SpriteBatch spriteBatch = b;
|
||||||
Texture2D fadeToBlackRect = Game1.fadeToBlackRect;
|
Texture2D fadeToBlackRect = Game1.fadeToBlackRect;
|
||||||
Viewport viewport = Game1.graphics.GraphicsDevice.Viewport;
|
Viewport viewport = Game1.graphics.GraphicsDevice.Viewport;
|
||||||
|
@ -152,14 +144,15 @@ namespace StardewModdingAPI.Mods.CustomLocalization.Rewrites
|
||||||
spriteBatch.Draw(fadeToBlackRect, bounds, color);
|
spriteBatch.Draw(fadeToBlackRect, bounds, color);
|
||||||
Rectangle mainBox = (Rectangle)__instance.GetType().GetField("mainBox", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
|
Rectangle mainBox = (Rectangle)__instance.GetType().GetField("mainBox", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
|
||||||
IClickableMenu.drawTextureBox(b, (int)mainBox.X, (int)mainBox.Y, (int)mainBox.Width, (int)mainBox.Height, Color.White);
|
IClickableMenu.drawTextureBox(b, (int)mainBox.X, (int)mainBox.Y, (int)mainBox.Width, (int)mainBox.Height, Color.White);
|
||||||
MobileScrollbox scrollArea = (MobileScrollbox)__instance.GetType().GetField("scrollArea", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
|
object scrollArea = ModEntry.Reflection.GetField<object>(__instance, "scrollArea").GetValue();
|
||||||
if (scrollArea != null)
|
if (scrollArea != null)
|
||||||
{
|
{
|
||||||
MobileScrollbar newScrollbar = (MobileScrollbar)__instance.GetType().GetField("newScrollbar", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
|
object newScrollbar = ModEntry.Reflection.GetField<object>(__instance, "newScrollbar").GetValue();
|
||||||
newScrollbar.draw(b);
|
ModEntry.Reflection.GetMethod(newScrollbar, "draw").Invoke(b);
|
||||||
scrollArea.setUpForScrollBoxDrawing(b, 1f);
|
ModEntry.Reflection.GetMethod(scrollArea, "setUpForScrollBoxDrawing").Invoke(b, 1f);
|
||||||
}
|
}
|
||||||
foreach (ClickableComponent language in __instance.languages)
|
List<ClickableComponent> languages = ModEntry.Reflection.GetField<List<ClickableComponent>>(__instance, "languages").GetValue();
|
||||||
|
foreach (ClickableComponent language in languages)
|
||||||
{
|
{
|
||||||
int num1 = -1;
|
int num1 = -1;
|
||||||
switch (language.name)
|
switch (language.name)
|
||||||
|
@ -221,10 +214,11 @@ namespace StardewModdingAPI.Mods.CustomLocalization.Rewrites
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (scrollArea != null)
|
if (scrollArea != null)
|
||||||
scrollArea.finishScrollBoxDrawing(b, 1f);
|
ModEntry.Reflection.GetMethod(scrollArea, "finishScrollBoxDrawing").Invoke(b, 1f);
|
||||||
if ((__instance.upperRightCloseButton != null) && __instance.shouldDrawCloseButton())
|
ClickableTextureComponent upperRightCloseButton = ModEntry.Reflection.GetField<ClickableTextureComponent>(__instance, "upperRightCloseButton").GetValue();
|
||||||
|
if (upperRightCloseButton != null && ModEntry.Reflection.GetMethod(__instance, "shouldDrawCloseButton").Invoke<bool>())
|
||||||
{
|
{
|
||||||
__instance.upperRightCloseButton.draw(b);
|
upperRightCloseButton.draw(b);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,8 @@ namespace StardewModdingAPI.Mods.CustomLocalization.Rewrites
|
||||||
{
|
{
|
||||||
public class LocalizedContentManagerRewrites
|
public class LocalizedContentManagerRewrites
|
||||||
{
|
{
|
||||||
[HarmonyPatch(typeof(LocalizedContentManager))]
|
|
||||||
[HarmonyPatch("LanguageCodeString")]
|
|
||||||
public class LanguageCodeStringRewrite
|
public class LanguageCodeStringRewrite
|
||||||
{
|
{
|
||||||
[HarmonyPrefix]
|
|
||||||
public static bool Prefix(LanguageCode code, ref string __result)
|
public static bool Prefix(LanguageCode code, ref string __result)
|
||||||
{
|
{
|
||||||
switch (code)
|
switch (code)
|
||||||
|
@ -44,11 +41,8 @@ namespace StardewModdingAPI.Mods.CustomLocalization.Rewrites
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[HarmonyPatch(typeof(LocalizedContentManager))]
|
|
||||||
[HarmonyPatch("get_CurrentLanguageLatin")]
|
|
||||||
public class GetCurrentLanguageLatinRewrite
|
public class GetCurrentLanguageLatinRewrite
|
||||||
{
|
{
|
||||||
[HarmonyPrefix]
|
|
||||||
public static bool Prefix(ref bool __result)
|
public static bool Prefix(ref bool __result)
|
||||||
{
|
{
|
||||||
ModConfig.Locale locale = ModEntry.ModConfig.GetByCode((int)LocalizedContentManager.CurrentLanguageCode);
|
ModConfig.Locale locale = ModEntry.ModConfig.GetByCode((int)LocalizedContentManager.CurrentLanguageCode);
|
||||||
|
|
|
@ -32,11 +32,8 @@ namespace StardewModdingAPI.Mods.CustomLocalization.Rewrites
|
||||||
SpriteText.fontPixelZoom = locale.FontPixelZoom;
|
SpriteText.fontPixelZoom = locale.FontPixelZoom;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[HarmonyPatch(typeof(SpriteText))]
|
|
||||||
[HarmonyPatch("setUpCharacterMap")]
|
|
||||||
public class SetUpCharacterMapRewrite
|
public class SetUpCharacterMapRewrite
|
||||||
{
|
{
|
||||||
[HarmonyPrefix]
|
|
||||||
public static void Prefix()
|
public static void Prefix()
|
||||||
{
|
{
|
||||||
if (!LocalizedContentManager.CurrentLanguageLatin)
|
if (!LocalizedContentManager.CurrentLanguageLatin)
|
||||||
|
@ -50,11 +47,8 @@ namespace StardewModdingAPI.Mods.CustomLocalization.Rewrites
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
[HarmonyPatch(typeof(SpriteText))]
|
|
||||||
[HarmonyPatch("OnLanguageChange")]
|
|
||||||
public class OnLanguageChangeRewrite
|
public class OnLanguageChangeRewrite
|
||||||
{
|
{
|
||||||
[HarmonyPrefix]
|
|
||||||
public static void Prefix()
|
public static void Prefix()
|
||||||
{
|
{
|
||||||
LoadFont();
|
LoadFont();
|
||||||
|
|
|
@ -1,17 +1,12 @@
|
||||||
using System.IO;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Harmony;
|
|
||||||
using StardewValley;
|
using StardewValley;
|
||||||
|
|
||||||
namespace StardewModdingAPI.Mods.CustomLocalization.Rewrites
|
namespace StardewModdingAPI.Mods.CustomLocalization.Rewrites
|
||||||
{
|
{
|
||||||
public class StartupPreferencesRewrites
|
public class StartupPreferencesRewrites
|
||||||
{
|
{
|
||||||
[HarmonyPatch(typeof(StartupPreferences))]
|
|
||||||
[HarmonyPatch("writeSettings")]
|
|
||||||
public class WriteSettingsRewrite
|
public class WriteSettingsRewrite
|
||||||
{
|
{
|
||||||
[HarmonyPrefix]
|
|
||||||
public static void Prefix(StartupPreferences __instance)
|
public static void Prefix(StartupPreferences __instance)
|
||||||
{
|
{
|
||||||
ModEntry.ModConfig.CurrentLanguageCode = (int)LocalizedContentManager.CurrentLanguageCode;
|
ModEntry.ModConfig.CurrentLanguageCode = (int)LocalizedContentManager.CurrentLanguageCode;
|
||||||
|
@ -21,7 +16,6 @@ namespace StardewModdingAPI.Mods.CustomLocalization.Rewrites
|
||||||
typeof(StartupPreferences).GetField("languageCode", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).SetValue(__instance, LocalizedContentManager.LanguageCode.en);
|
typeof(StartupPreferences).GetField("languageCode", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).SetValue(__instance, LocalizedContentManager.LanguageCode.en);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[HarmonyPostfix]
|
|
||||||
public static void Postfix(StartupPreferences __instance)
|
public static void Postfix(StartupPreferences __instance)
|
||||||
{
|
{
|
||||||
if (ModEntry.ModConfig.CurrentLanguageCode > ModEntry.ModConfig.OriginLocaleCount)
|
if (ModEntry.ModConfig.CurrentLanguageCode > ModEntry.ModConfig.OriginLocaleCount)
|
||||||
|
@ -30,11 +24,8 @@ namespace StardewModdingAPI.Mods.CustomLocalization.Rewrites
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[HarmonyPatch(typeof(StartupPreferences))]
|
|
||||||
[HarmonyPatch("readSettings")]
|
|
||||||
public class ReadSettingsRewrite
|
public class ReadSettingsRewrite
|
||||||
{
|
{
|
||||||
[HarmonyPostfix]
|
|
||||||
public static void Postfix(StartupPreferences __instance)
|
public static void Postfix(StartupPreferences __instance)
|
||||||
{
|
{
|
||||||
if (ModEntry.ModConfig.CurrentLanguageCode > ModEntry.ModConfig.OriginLocaleCount)
|
if (ModEntry.ModConfig.CurrentLanguageCode > ModEntry.ModConfig.OriginLocaleCount)
|
||||||
|
|
|
@ -8,11 +8,8 @@ namespace StardewModdingAPI.Mods.CustomLocalization.Rewrites
|
||||||
{
|
{
|
||||||
public class TitleContainerRewrites
|
public class TitleContainerRewrites
|
||||||
{
|
{
|
||||||
[HarmonyPatch(typeof(TitleContainer))]
|
|
||||||
[HarmonyPatch("OpenStream")]
|
|
||||||
public class OpenStreamRewrite
|
public class OpenStreamRewrite
|
||||||
{
|
{
|
||||||
[HarmonyPrefix]
|
|
||||||
public static bool Prefix(string name, ref Stream __result)
|
public static bool Prefix(string name, ref Stream __result)
|
||||||
{
|
{
|
||||||
Stream stream = null;
|
Stream stream = null;
|
||||||
|
@ -21,7 +18,6 @@ namespace StardewModdingAPI.Mods.CustomLocalization.Rewrites
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
string newPath = Path.Combine(ModEntry.ModPath, name);
|
string newPath = Path.Combine(ModEntry.ModPath, name);
|
||||||
string safeName = (string)typeof(TitleContainer).GetMethod("NormalizeRelativePath", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, new object[] { name });
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
stream = new FileStream(newPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
stream = new FileStream(newPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
|
@ -35,9 +31,15 @@ namespace StardewModdingAPI.Mods.CustomLocalization.Rewrites
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MethodInfo PlatformOpenStream = typeof(TitleContainer).GetMethod("PlatformOpenStream", BindingFlags.Static | BindingFlags.NonPublic);
|
string safeName = ModEntry.Reflection.GetMethod(typeof(TitleContainer), "NormalizeRelativePath", false)?.Invoke<string>(name);
|
||||||
stream = (Stream)PlatformOpenStream.Invoke(null, new object[] { safeName });
|
if(safeName != null)
|
||||||
__result = stream;
|
__result = ModEntry.Reflection.GetMethod(typeof(TitleContainer), "PlatformOpenStream", false)?.Invoke<Stream>(safeName);
|
||||||
|
else
|
||||||
|
__result = ModEntry.Reflection.GetMethod(typeof(TitleContainer), "PlatformOpenStream", false)?.Invoke<Stream>(name);
|
||||||
|
if(__result == null)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 16
|
# Visual Studio Version 16
|
||||||
VisualStudioVersion = 16.0.29728.190
|
VisualStudioVersion = 16.0.29728.190
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SMAPI.Mods.CustomLocalization", "SMAPI.Mods.CustomLocalization.csproj", "{4E035E78-8288-415F-81D2-B4B3C489A005}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomLocalization", "CustomLocalization.csproj", "{4E035E78-8288-415F-81D2-B4B3C489A005}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
@ -11,10 +11,8 @@ Global
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{4E035E78-8288-415F-81D2-B4B3C489A005}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{4E035E78-8288-415F-81D2-B4B3C489A005}.Debug|Any CPU.ActiveCfg = Debug|x86
|
||||||
{4E035E78-8288-415F-81D2-B4B3C489A005}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{4E035E78-8288-415F-81D2-B4B3C489A005}.Release|Any CPU.ActiveCfg = Release|x86
|
||||||
{4E035E78-8288-415F-81D2-B4B3C489A005}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{4E035E78-8288-415F-81D2-B4B3C489A005}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"Name": "Custom Localization",
|
"Name": "Custom Localization",
|
||||||
"Author": "ZaneYork",
|
"Author": "ZaneYork",
|
||||||
"Version": "1.0.3",
|
"Version": "1.1.0",
|
||||||
"Description": "Localization for not exist locale.",
|
"Description": "Localization for not exist locale.",
|
||||||
"UniqueID": "ZaneYork.CustomLocalization",
|
"UniqueID": "ZaneYork.CustomLocalization",
|
||||||
"EntryDll": "CustomLocalization.dll",
|
"EntryDll": "CustomLocalization.dll",
|
||||||
|
|
Loading…
Reference in New Issue