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

Missing information on how to debug with dnSpy using Harmony #19

Open
Muchaszewski opened this issue Jan 27, 2021 · 2 comments
Open

Missing information on how to debug with dnSpy using Harmony #19

Muchaszewski opened this issue Jan 27, 2021 · 2 comments

Comments

@Muchaszewski
Copy link

I have been following information from this wiki site on how to debug with dnSpy with DumpAssemblies. However, this looks like it doesn't apply to Harmony as there is no mention and testing is confirms my worries.

I have created a simple Transpiler patch using Harmony and I want to debug it further.

        private Harmony _harmonyInstance;
        public void Awake()
        {
            HarmonyFileLog.Enabled = true;
            _harmonyInstance = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly());
        }

[HarmonyPatch(typeof(PlayerAction_Build), nameof(PlayerAction_Build.CreatePrebuilds))]
        private class Transpiler_PlayerAction_Build
        {
            static FieldInfo searchedVFInpudOnDown = AccessTools.Field(typeof(VFInput.InputValue), nameof(VFInput.InputValue.onDown));
            static FieldInfo requestedVFInpudOnDown = AccessTools.Field(typeof(VFInput.InputValue), nameof(VFInput.InputValue.pressing));

            private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
            {
                return new CodeMatcher(instructions).MatchForward(false,
                        new CodeMatch(OpCodes.Ldfld, searchedVFInpudOnDown))
                    .SetOperandAndAdvance(requestedVFInpudOnDown)
                    .InstructionEnumeration();
            }
        }

I have enabled as instructed

LoadDumpedAssemblies = true
BreakBeforeLoadAssemblies = true

and the results are not promising
image

The only dumped assembly is UnityEngine.CoreModule.dll and setting BreakBeforeLoadAssemblies to true, crashes the game while loading.

Assembly-CSharp is not reacting to my breakpoints anymore for the modified method!

Callstack from this method is marked as ??? in dnSpy
image

Is there any way to debug using HarmonyX or I need to go to pre-patch assembly route?

@ManlyMarco
Copy link
Member

Assuming you use bepinex, to debug harmony patched methods you have to change harmony backend to cecil in bepinex.cfg. You still can't easily set a breakpoint inside the method but you can step into it and see it in call stack.

For debugging preloader patched assemblies check https://bepinex.github.io/bepinex_docs/master/articles/advanced/debug/assemblies_dnSpy.html

@Muchaszewski
Copy link
Author

Thank you, I have found this option in the settings, I missed it for the first time.

I suggest then that you should add this information to the wiki for either HarmonyX or to the articles mentioned above, on how to debug those methods that were patched.

As for this point, and I think this should be mentioned in the wiki for how to debug this stuff for less informed users

You still can't easily set a breakpoint inside the method

You can set a breakpoint into the method, once you know which in the memory address of the assembly you are looking for (and there is many)
image
image

Another question:
Is it possible to name those assemblies, to have a somewhat human-readable name?

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