Skip to content

Inherit patcher types - #39

Open
Nytra wants to merge 3 commits into
ResoniteModding:masterfrom
Nytra:inheritPatcherTypes
Open

Inherit patcher types#39
Nytra wants to merge 3 commits into
ResoniteModding:masterfrom
Nytra:inheritPatcherTypes

Conversation

@Nytra

@Nytra Nytra commented Jul 25, 2026

Copy link
Copy Markdown

This makes pre-patcher types be inherited which matches the behavior of plugin types.

Description

There is some difference between the way plugin types and patcher types are found in assemblies.

The plugin types will search with inheritance whereas the patcher types will not.

This PR makes the plugins and patchers use the same searching code essentially.

Current plugin searching code which this PR is based off:

if (!ReferencesThisAssembly(ass))

if (ass.MainModule.GetTypeReferences().Any(r => MetadataHelper.TypeInheretsFrom(r, typeof(BepInPlugin))))

Plugin attribute code which passes the third parameter to make it use inheritance:

var attr = MetadataHelper.GetCustomAttributes<BepInPlugin>(td, false, true).FirstOrDefault();

Motivation and Context

I need this for my UniModFramework

How Has This Been Tested?

Tested by loading some pre-patchers and they seem to work.

Screenshots (if appropriate):

N/a

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@hazre

hazre commented Jul 27, 2026

Copy link
Copy Markdown
Member

I'm cool with this change as long as it doesn't break existing or future pre-patchers. Meaning it would require some extensive testing.

@Nytra

Nytra commented Jul 27, 2026

Copy link
Copy Markdown
Author

I've tested it with Arti's FourLeafClover mod and it works, I'm not sure what else there is to test.

@EIA485

EIA485 commented Jul 27, 2026

Copy link
Copy Markdown

as relevant context heres why my upstream pr was denied for now
another prepatcher mod you can test against is DeleagateRefEditing

@github-actions

Copy link
Copy Markdown

Download the artifacts for this pull request:

@art0007i

Copy link
Copy Markdown

Well I've decided to do some testing, and I tried this setup:

PatcherA.dll defines class which inherits BasePatcher
PatcherB.dll inherits the class defined in PatcherA.dll

This works, but if I rename PatcherA.dll to zzPatcherA.dll it stops working. There's no error message or anything in the log either.

Here's a zip with the source code to both PatcherA and PatcherB and the compiled dlls that I used for this test:
Patcher.zip

@Nytra

Nytra commented Aug 13, 2026

Copy link
Copy Markdown
Author

I mean isn't this just because PatcherB.dll references PatcherA.dll which now doesn't exist because you renamed it?

@art0007i

Copy link
Copy Markdown

oh maybe

@art0007i

Copy link
Copy Markdown

still no warning or error on that is not the best I Think

@Nytra

Nytra commented Aug 13, 2026

Copy link
Copy Markdown
Author

Nothing in bepinex log? I'd think this would be a .NET thing not something I need to handle explicitly

@art0007i

Copy link
Copy Markdown

bepinex might be swallowing it somewhere, but nope, nothing at all in the log when the referenced assembly is missing.

only thing relevant to patcher b when it's dependancy has been renamed is this:

[Debug  :   BepInEx] Examining '/home/arti/.local/share/com.kesomannen.gale/resonite/profiles/Default/BepInEx/patchers/PatcherB.dll'

interestingly enough the patcher A still runs successfully even though it's been renamed. I haven't looked fully at the prepatcher stuff but do they put each dll in a separate load context? otherwise I think c#'s type resolution shuld find the types if they're already loaded in memory beforehand

@Nytra

Nytra commented Aug 13, 2026

Copy link
Copy Markdown
Author

I don't think the load context would matter because it uses Cecil to get the DLL references I think

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

Successfully merging this pull request may close these issues.

4 participants