BepInEx / Il2CppInterop

A tool interoperate between CoreCLR and Il2Cpp at runtime
GNU Lesser General Public License v3.0
185 stars 59 forks source link

Fix GenericMethod_GetMethod_Hook on Unity 2020.3.41+ #89

Closed limoka closed 1 year ago

limoka commented 1 year ago

This PR fixes a crash after call to GenericMethod::GetMethod() hook. This issue appears on Unity version 2020.3.41+, and in some cases in 2021.3.12+, 2022.1.23+ because of this fix

In these versions Object::GetVirtualMethod() calls GenericMethod::GetGenericVirtualMethod() instead of GenericMethod::GetMethod() This also has an annoying interaction with shims added in 2021.2.0, where they get inlined together.

I also removed targetTargets.Length == 1 check because it seems to be always true, due to early return in GenericMethod::GetMethod() that I noticed. Unfortunately because of this, problems on debug builds could emerge. I don't know if these are important though.

Tested on a custom test game built using 2020.3.46. @decaprime also confirmed no issues on their beta version of the V Rising Unity 2020.3.46 Also tested on CoreKeeper 2021.3.14, no issues there.

For reference some relevant Unity libil2cpp versions are available here: link