Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x86 platform makes patch fail #614

Open
snamds opened this issue Jun 18, 2024 · 0 comments
Open

x86 platform makes patch fail #614

snamds opened this issue Jun 18, 2024 · 0 comments
Assignees

Comments

@snamds
Copy link

snamds commented Jun 18, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants