8000 MethodDelegate: allow for swapping value type with object, and allow ref for arg 0 on value type by Eddio0141 · Pull Request #633 · pardeike/Harmony · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

MethodDelegate: allow for swapping value type with object, and allow ref for arg 0 on value type #633

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

Merged
merged 2 commits into from
Dec 18, 2024

Conversation

Eddio0141
Copy link
Contributor

This changes AccessTools.MethodDelegate to let you use object where a value type exists

Also lets you use ref for the first argument with value types, since currently you can't mutate structs from dynamic methods generated when open instance without boxing, so this lets you use delegates such as void MyFunc(ref UnityEngine.Resolution res);

@pardeike
Copy link
Owner

That’s nice work!

@pardeike
Copy link
Owner

Maybe you can add some tests too?

@Eddio0141 Eddio0141 force-pushed the master branch 2 times, most recently from 921e1e7 to d6fb93f Compare November 16, 2024 16:15
repeat mutation to see effect

fixed bind error

restore missing test
@Eddio0141
Copy link
Contributor Author

Thanks! Also sorry for the messy commits, I've squashed them to two commits to try make it clean
I've added 2 tests which should test the exact code, it is all done now and should be passing

Also I just realised, this fix would only apply for virtualCall: false, since delegates is incompatible normally, and this fixes just the dmd to handle these things

@pardeike pardeike merged commit 899a3cd into pardeike:master Dec 18, 2024
1 check passed
@pardeike
Copy link
Owner
pardeike commented Mar 1, 2025

Looks like we broke backwards compatibility with this PR. A user posted the following problem today on the discord:

Hi, I'm having an issue with my mod that uses Harmony. My mod is compiled with Harmony 2.2.2 but the Unity Mod Manager that I'm using to inject my mod into the game has updated to using Harmony 2.3.5 which breaks compatibility.

If my mod compiled with Harmony 2.2.2 is run using Unity Mod Manager with Harmony 2.3.5 it can patch methods just fine but when the time comes to actually run the patched method I get the following error:

MissingMethodException: Method not found: !!0 HarmonyLib.AccessTools.MethodDelegate<!0>(System.Reflection.MethodInfo,object,bool)

I can fix the error by simply compiling with Harmony 2.3.5 but that'll make the mod incompatible for anyone trying to use an older version of Unity Mod Manager with Harmony 2.2.2. I haven't changed the code. The only thing that's changed is the Harmony .dll file. So I was hoping anyone had a more robust solution?

@Banane9
Copy link
Contributor
Banane9 commented Mar 1, 2025

Yup, adding a default parameter is source-, but not binary-compatible :C

@Eddio0141
Copy link
Contributor Author

Ah sorry about that, I didn't see this problem
I'm guessing #652 solves this issue

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.

3 participants
0