Harmony
Harmony copied to clipboard
x86 platform makes patch fail
trafficstars
Describe the bug The patch I wanna do works when built with x64/AnyCPU platform but it doesn't work with x86 platform
To Reproduce
public static void Patch()
{
Harmony harmony = new Harmony("TestPatch");
foreach (Type type in Assembly.GetAssembly(typeof(TimeZone)).GetTypes()
.Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(TimeZone))))
{
MethodInfo originalMethod1 = type.GetMethod("ToLocalTime");
var preFixMethodInfo1 = typeof(Program).GetMethod("PrefixTest", BindingFlags.Static | BindingFlags.NonPublic);
HarmonyMethod prefix1 = new HarmonyMethod(preFixMethodInfo1);
harmony.Patch(originalMethod1, prefix1, null, null, null);
}
}
static void Main(string[] args)
{
Patch();
DateTime date3 = TimeZone.CurrentTimeZone.ToLocalTime(DateTime.Now);
}
static bool PrefixTest(ref DateTime __result, DateTime __0)
{
__result = DateTime.UtcNow;
return false;
}
The result is quite random. AccessViolationException / System.ExecutionEngineException / random "date3" values returned
Expected behavior TimeZone.CurrentTimeZone.ToLocalTime with the current prefix code should return DateTime.UtcNow
Runtime environment (please complete the following information):
- OS: Windows 10, 64bit
- .NET version 3.5 (Other versions tested with same result)
- Harmony version v2.3.3
Additional context Add any other context about the problem here.