Skip to content

Commit

Permalink
Merge pull request #46 from simonj0/fix-language
Browse files Browse the repository at this point in the history
 Use application region instead of date/time region for title descriptions (fixes #22)
  • Loading branch information
FailedShack committed Jun 14, 2019
2 parents 71dcf11 + 8ae8834 commit 7f6b2bd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions USBHelperInjector/Patches/LanguagePatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Harmony;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;

namespace USBHelperInjector.Patches
{
[Optional]
[HarmonyPatch]
class LanguagePatch
{
static MethodBase TargetMethod()
{
// v0.6.1.655: GClass32.Class43.method_0
return (from type in ReflectionHelper.Types
where type.GetProperty("Dlc", BindingFlags.Public | BindingFlags.Instance) != null
from nested in type.GetNestedTypes(BindingFlags.NonPublic | BindingFlags.Instance)
where nested.GetFields(BindingFlags.Public | BindingFlags.Instance).Any(p => p.FieldType == type)
from method in nested.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)
select method).FirstOrDefault();
}

static IEnumerable<CodeInstruction> Transpiler(MethodBase original, IEnumerable<CodeInstruction> instructions)
{
var codes = new List<CodeInstruction>(instructions);

var cultureGetter = typeof(CultureInfo).GetProperty("CurrentCulture").GetGetMethod();
var uiCultureGetter = typeof(CultureInfo).GetProperty("CurrentUICulture").GetGetMethod();

var index = codes.FindIndex(i => i.opcode == OpCodes.Call && ((MethodBase)i.operand) == cultureGetter);
if (index != -1)
{
codes[index].operand = uiCultureGetter;
}

return codes;
}
}
}
1 change: 1 addition & 0 deletions USBHelperInjector/USBHelperInjector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<Compile Include="Patches\KeySiteFormValidationPatch.cs" />
<Compile Include="Patches\KeySite3DSSettingsPatch.cs" />
<Compile Include="Patches\KeySiteErrorMessagePatch.cs" />
<Compile Include="Patches\LanguagePatch.cs" />
<Compile Include="Patches\MessageBoxPatch.cs" />
<Compile Include="Patches\SearchPatch.cs" />
<Compile Include="Patches\ServicePointPatch.cs" />
Expand Down

0 comments on commit 7f6b2bd

Please sign in to comment.