-
Notifications
You must be signed in to change notification settings - Fork 681
Auto inject Il2Cpp-Types #334
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,57 @@ | ||||
using System; | ||||
using System.Reflection; | ||||
using UnhollowerBaseLib; | ||||
using UnhollowerRuntimeLib; | ||||
|
||||
namespace BepInEx.IL2CPP | ||||
{ | ||||
|
||||
[AttributeUsage(AttributeTargets.Class)] | ||||
public class Il2CppInterfaces : Attribute | ||||
{ | ||||
|
||||
public Type[] Interfaces { get; protected set; } | ||||
|
||||
public Il2CppInterfaces(params Type[] interfaces) | ||||
{ | ||||
Interfaces = interfaces; | ||||
} | ||||
|
||||
} | ||||
Comment on lines
+9
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest Also, I agree with @js6pak that maybe this can be moved to Unhollower's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I'll move it to Unhollower |
||||
|
||||
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class)] | ||||
public class DontAutoRegisterInIl2Cpp : Attribute { } | ||||
|
||||
internal class PluginClassInjector | ||||
{ | ||||
|
||||
public static void RegisterAssemblyInIl2Cpp(Assembly pluginAssembly) | ||||
{ | ||||
if (pluginAssembly.GetCustomAttribute<DontAutoRegisterInIl2Cpp>() != null) return; | ||||
|
||||
foreach (var type in pluginAssembly.DefinedTypes) | ||||
if (typeof(Il2CppObjectBase).IsAssignableFrom(type) && !ClassInjector.IsTypeRegisteredInIl2Cpp(type)) | ||||
RegisterTypeInIl2Cpp(type); | ||||
} | ||||
|
||||
public static bool RegisterTypeInIl2Cpp(Type type) | ||||
ghorsington marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
{ | ||||
if(type.Assembly.GetCustomAttribute<DontAutoRegisterInIl2Cpp>() != null) return false; | ||||
PHPCore1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
if (type.GetCustomAttribute<DontAutoRegisterInIl2Cpp>() != null) return false; | ||||
|
||||
if (!ClassInjector.IsTypeRegisteredInIl2Cpp(type.BaseType)) | ||||
if (!RegisterTypeInIl2Cpp(type.BaseType)) | ||||
return false; | ||||
|
||||
var interfaces = type.GetCustomAttribute<Il2CppInterfaces>(); | ||||
|
||||
if (interfaces != null) | ||||
ClassInjector.RegisterTypeInIl2CppWithInterfaces(type, true, interfaces.Interfaces); | ||||
else | ||||
ClassInjector.RegisterTypeInIl2Cpp(type); | ||||
|
||||
return true; | ||||
} | ||||
|
||||
} | ||||
} |
Uh oh!
There was an error while loading. Please reload this page.