RegisterInIl2CppAttribute

This commit is contained in:
js6pak committed 2021-01-14 18:17:47 +01:00
1 parent 12b7a5695c
commit c984c6324a
5 files changed
+58 -5

No files matched your search

+5 -2
View File
@@ -4,7 +4,7 @@ using BepInEx.IL2CPP;
using HarmonyLib;
using Reactor.Extensions;
using UnhollowerBaseLib;
using UnhollowerRuntimeLib;
using UnhollowerBaseLib.Attributes;
using UnityEngine;
namespace Reactor.Debugger
@@ -22,7 +22,7 @@ namespace Reactor.Debugger
public override void Load()
{
ClassInjector.RegisterTypeInIl2Cpp<DebuggerComponent>();
RegisterInIl2CppAttribute.Register();
var gameObject = new GameObject(nameof(DebuggerPlugin)).DontDestroy();
Component = gameObject.AddComponent<DebuggerComponent>();
@@ -35,10 +35,13 @@ namespace Reactor.Debugger
});
}
[RegisterInIl2Cpp]
public class DebuggerComponent : MonoBehaviour
{
[HideFromIl2Cpp]
public bool DisableGameEnd { get; set; }
[HideFromIl2Cpp]
public DragWindow TestWindow { get; }
public DebuggerComponent(IntPtr ptr) : base(ptr)
+7
View File
@@ -28,6 +28,13 @@ namespace Reactor.Extensions
return obj;
}
public static T DontUnload<T>(this T obj) where T : Object
{
obj.hideFlags |= HideFlags.DontUnloadUnusedAsset;
return obj;
}
/// <summary>
/// Adds a delegate to get one notification when a scene has loaded.
+4 -3
View File
@@ -6,7 +6,7 @@ using HarmonyLib;
using Reactor.Extensions;
using Reactor.Patches;
using Reactor.Unstrip;
using UnhollowerRuntimeLib;
using UnhollowerBaseLib.Attributes;
using UnityEngine;
namespace Reactor
@@ -23,8 +23,7 @@ namespace Reactor
public override void Load()
{
ClassInjector.RegisterTypeInIl2Cpp<ReactorComponent>();
ClassInjector.RegisterTypeInIl2Cpp<Unstrip.Patches.GUIWordWrapSizer>();
RegisterInIl2CppAttribute.Register();
var gameObject = new GameObject(nameof(ReactorPlugin)).DontDestroy();
gameObject.AddComponent<ReactorComponent>().Plugin = this;
@@ -41,8 +40,10 @@ namespace Reactor
return base.Unload();
}
[RegisterInIl2Cpp]
public class ReactorComponent : MonoBehaviour
{
[HideFromIl2Cpp]
public ReactorPlugin Plugin { get; internal set; }
public ReactorComponent(IntPtr ptr) : base(ptr)
+41
View File
@@ -0,0 +1,41 @@
using System;
using System.Reflection;
using HarmonyLib;
using UnhollowerRuntimeLib;
namespace Reactor
{
/// <summary>
/// Utility attribute for automatically calling <see cref="UnhollowerRuntimeLib.ClassInjector.RegisterTypeInIl2Cpp{T}"/>
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class RegisterInIl2CppAttribute : Attribute
{
public static void Register()
{
Register(Assembly.GetCallingAssembly());
}
public static void Register(Assembly assembly)
{
foreach (var type in assembly.GetTypes())
{
var attribute = type.GetCustomAttribute<RegisterInIl2CppAttribute>();
if (attribute != null)
{
try
{
typeof(ClassInjector).GetMethod(nameof(ClassInjector.RegisterTypeInIl2Cpp))!
.MakeGenericMethod(type)
.Invoke(null, new object[0]);
}
catch (Exception e)
{
PluginSingleton<ReactorPlugin>.Instance.Log.LogWarning($"Failed to register {type.FullDescription()}: {e}");
}
}
}
}
}
}
+1
View File
@@ -133,6 +133,7 @@ namespace Reactor.Unstrip
}
}
[RegisterInIl2Cpp]
internal sealed class GUIWordWrapSizer : GUILayoutEntry
{
private readonly GUIContent m_Content;