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
Auto inject Il2Cpp-Types #334
base: master
Are you sure you want to change the base?
Conversation
Due to how interfaces are implemented, the set of interfaces that the class inherits from need to be specified manually, and I think that this may cause issues regarding this. |
Greetings! Thanks for the contribution! Here are some of my points regarding this:
Overall I think that the points I mentioned above should be addressed before this PR can be merged. |
Greeting, |
This also doesn't respect bepinex's caching for finding types with mono.cecil |
I hope it's ok how I made it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some of my notes.
I think that it's fine if you don't have the time to finish it up right away, there is no hurry finishing this right this instant. When it comes to our plugin cache, this should not conflict with this as-is, but it would be preferable to use it as it prevents some early type resolving issues and helps with performance.
As for the interface attribute, I think it might be worth moving it to Unhollower side. If you don't have time to do it, I can probably look at it this week myself.
[AttributeUsage(AttributeTargets.Class)] | ||
public class Il2CppInterfaces : Attribute | ||
{ | ||
|
||
public Type[] Interfaces { get; protected set; } | ||
|
||
public Il2CppInterfaces(params Type[] interfaces) | ||
{ | ||
Interfaces = interfaces; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest Il2CppImplementsAttribute
as the name.
Also, I agree with @js6pak that maybe this can be moved to Unhollower's ClassInjector
class. This would make manual injector much, much easier (and it makes sense to keep this attribute on Unhollower's side).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I'll move it to Unhollower
I adjusted the OP since this is potentially a breaking feature for older BE builds. Since now registering is opt-out instead of opt-in, there could be cases where undesired types get injected automatically. Doesn't affect the PR itself (as it only potentially breaks previous BE builds), but marking this correctly is important for future reference. |
This is fine, but I've got an idea how it wouldn't break older builds. |
The overload is of course a good idea. That said, the reason this is a potentially breaking PR is because before BepInEx did not automatically inject types into Il2Cpp. In other words, the injection was "opt-in", as you had to specifically write code to inject your type. Now with automatic injection, you have to instead specify which types you don't want to inject (or if you don't want to inject anything in your assembly automatically). As such, the injection becomes "opt-out", as you have to add an attribute to get back to current BepInEx behaviour. This is likely not a major issue since in most cases you will always want to inject Il2Cpp types into Il2Cpp. However, those plugins that currently assume they can skip injection just by not injecting can break. As I mentioned, it is not a major issue IMO as this only affects Bleeding Edge build which are expected to be unstable and not compatible with each other. |
Unhollower version |
Description
With this change the LoadPlugin method will automatically search every Type which inherits Il2CppObjectBase in the plugin assembly and registers it
Motivation and Context
It makes creating new types easier, because you don't have to create a bunch of ClassInjector.RegisterTypeInIl2Cpp
How Has This Been Tested?
I tested it be creating a plugin which has multiple MonoBehaviour without ClassInjector.RegisterTypeInIl2Cpp and then adding them to a GameObject
Screenshots (if appropriate):
Types of changes
Checklist: