-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from simonj0/fix-language
Use application region instead of date/time region for title descriptions (fixes #22)
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters