mirror of
https://github.com/NuclearPowered/Reactor.git
synced 2026-10-19 15:51:54 +00:00
RegisterInIl2CppAttribute
This commit is contained in:
5 files changed
+58
-5
No files matched your search
@@ -4,7 +4,7 @@ using BepInEx.IL2CPP;
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using Reactor.Extensions;
|
using Reactor.Extensions;
|
||||||
using UnhollowerBaseLib;
|
using UnhollowerBaseLib;
|
||||||
using UnhollowerRuntimeLib;
|
using UnhollowerBaseLib.Attributes;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Reactor.Debugger
|
namespace Reactor.Debugger
|
||||||
@@ -22,7 +22,7 @@ namespace Reactor.Debugger
|
|||||||
|
|
||||||
public override void Load()
|
public override void Load()
|
||||||
{
|
{
|
||||||
ClassInjector.RegisterTypeInIl2Cpp<DebuggerComponent>();
|
RegisterInIl2CppAttribute.Register();
|
||||||
|
|
||||||
var gameObject = new GameObject(nameof(DebuggerPlugin)).DontDestroy();
|
var gameObject = new GameObject(nameof(DebuggerPlugin)).DontDestroy();
|
||||||
Component = gameObject.AddComponent<DebuggerComponent>();
|
Component = gameObject.AddComponent<DebuggerComponent>();
|
||||||
@@ -35,10 +35,13 @@ namespace Reactor.Debugger
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[RegisterInIl2Cpp]
|
||||||
public class DebuggerComponent : MonoBehaviour
|
public class DebuggerComponent : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
[HideFromIl2Cpp]
|
||||||
public bool DisableGameEnd { get; set; }
|
public bool DisableGameEnd { get; set; }
|
||||||
|
|
||||||
|
[HideFromIl2Cpp]
|
||||||
public DragWindow TestWindow { get; }
|
public DragWindow TestWindow { get; }
|
||||||
|
|
||||||
public DebuggerComponent(IntPtr ptr) : base(ptr)
|
public DebuggerComponent(IntPtr ptr) : base(ptr)
|
||||||
|
|||||||
@@ -28,6 +28,13 @@ namespace Reactor.Extensions
|
|||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static T DontUnload<T>(this T obj) where T : Object
|
||||||
|
{
|
||||||
|
obj.hideFlags |= HideFlags.DontUnloadUnusedAsset;
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a delegate to get one notification when a scene has loaded.
|
/// Adds a delegate to get one notification when a scene has loaded.
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using HarmonyLib;
|
|||||||
using Reactor.Extensions;
|
using Reactor.Extensions;
|
||||||
using Reactor.Patches;
|
using Reactor.Patches;
|
||||||
using Reactor.Unstrip;
|
using Reactor.Unstrip;
|
||||||
using UnhollowerRuntimeLib;
|
using UnhollowerBaseLib.Attributes;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Reactor
|
namespace Reactor
|
||||||
@@ -23,8 +23,7 @@ namespace Reactor
|
|||||||
|
|
||||||
public override void Load()
|
public override void Load()
|
||||||
{
|
{
|
||||||
ClassInjector.RegisterTypeInIl2Cpp<ReactorComponent>();
|
RegisterInIl2CppAttribute.Register();
|
||||||
ClassInjector.RegisterTypeInIl2Cpp<Unstrip.Patches.GUIWordWrapSizer>();
|
|
||||||
|
|
||||||
var gameObject = new GameObject(nameof(ReactorPlugin)).DontDestroy();
|
var gameObject = new GameObject(nameof(ReactorPlugin)).DontDestroy();
|
||||||
gameObject.AddComponent<ReactorComponent>().Plugin = this;
|
gameObject.AddComponent<ReactorComponent>().Plugin = this;
|
||||||
@@ -41,8 +40,10 @@ namespace Reactor
|
|||||||
return base.Unload();
|
return base.Unload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[RegisterInIl2Cpp]
|
||||||
public class ReactorComponent : MonoBehaviour
|
public class ReactorComponent : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
[HideFromIl2Cpp]
|
||||||
public ReactorPlugin Plugin { get; internal set; }
|
public ReactorPlugin Plugin { get; internal set; }
|
||||||
|
|
||||||
public ReactorComponent(IntPtr ptr) : base(ptr)
|
public ReactorComponent(IntPtr ptr) : base(ptr)
|
||||||
|
|||||||
@@ -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}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -133,6 +133,7 @@ namespace Reactor.Unstrip
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[RegisterInIl2Cpp]
|
||||||
internal sealed class GUIWordWrapSizer : GUILayoutEntry
|
internal sealed class GUIWordWrapSizer : GUILayoutEntry
|
||||||
{
|
{
|
||||||
private readonly GUIContent m_Content;
|
private readonly GUIContent m_Content;
|
||||||
|
|||||||
Reference in new issue
Block a user