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