This commit is contained in:
sinaioutlander
2020-11-05 17:33:04 +11:00
parent a46bc11e42
commit e175e9c438
47 changed files with 890 additions and 336 deletions

View File

@ -7,6 +7,7 @@ using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
#if CPP
using UnhollowerRuntimeLib;
using BepInEx.IL2CPP;
@ -14,57 +15,25 @@ using BepInEx.IL2CPP;
namespace UnityExplorer
{
#if MONO
[BepInPlugin(ExplorerCore.GUID, "UnityExplorer", ExplorerCore.VERSION)]
#if CPP
public class ExplorerBepInPlugin : BasePlugin
#else
public class ExplorerBepInPlugin : BaseUnityPlugin
#endif
{
public static ExplorerBepInPlugin Instance;
public static ManualLogSource Logging =>
#if CPP
Instance?.Log;
#else
Instance?.Logger;
#endif
public static ManualLogSource Logging => Instance?.Logger;
public static readonly Harmony HarmonyInstance = new Harmony(ExplorerCore.GUID);
#if CPP
// temporary for Il2Cpp until scene change delegate works
private static string lastSceneName;
#endif
// Init
#if CPP
public override void Load()
{
#else
internal void Awake()
{
#endif
Instance = this;
#if CPP
ClassInjector.RegisterTypeInIl2Cpp<ExplorerBehaviour>();
var obj = new GameObject(
"ExplorerBehaviour",
new Il2CppSystem.Type[]
{
Il2CppType.Of<ExplorerBehaviour>()
}
);
GameObject.DontDestroyOnLoad(obj);
#else
SceneManager.activeSceneChanged += DoSceneChange;
#endif
new ExplorerCore();
// HarmonyInstance.PatchAll();
HarmonyInstance.PatchAll();
}
internal static void DoSceneChange(Scene arg0, Scene arg1)
@ -72,7 +41,54 @@ namespace UnityExplorer
ExplorerCore.OnSceneChange();
}
#if CPP // BepInEx Il2Cpp mod class doesn't have monobehaviour methods yet, so wrap them in a dummy.
internal void Update()
{
ExplorerCore.Update();
}
}
#endif
#if CPP
[BepInPlugin(ExplorerCore.GUID, "UnityExplorer", ExplorerCore.VERSION)]
public class ExplorerBepInPlugin : BasePlugin
{
public static ExplorerBepInPlugin Instance;
public static ManualLogSource Logging => Instance?.Log;
public static readonly Harmony HarmonyInstance = new Harmony(ExplorerCore.GUID);
// temporary for Il2Cpp until scene change delegate works
private static string lastSceneName;
// Init
public override void Load()
{
Instance = this;
ClassInjector.RegisterTypeInIl2Cpp<ExplorerBehaviour>();
var obj = new GameObject(
"ExplorerBehaviour",
new Il2CppSystem.Type[]
{
Il2CppType.Of<ExplorerBehaviour>()
}
);
GameObject.DontDestroyOnLoad(obj);
new ExplorerCore();
HarmonyInstance.PatchAll();
}
internal static void DoSceneChange(Scene arg0, Scene arg1)
{
ExplorerCore.OnSceneChange();
}
// BepInEx Il2Cpp mod class doesn't have monobehaviour methods yet, so wrap them in a dummy.
public class ExplorerBehaviour : MonoBehaviour
{
public ExplorerBehaviour(IntPtr ptr) : base(ptr) { }
@ -82,23 +98,20 @@ namespace UnityExplorer
Logging.LogMessage("ExplorerBehaviour.Awake");
}
#endif
internal void Update()
{
ExplorerCore.Update();
#if CPP
var scene = SceneManager.GetActiveScene();
if (scene.name != lastSceneName)
{
lastSceneName = scene.name;
DoSceneChange(scene, scene);
}
#endif
}
#if CPP
}
#endif
}
#endif
}
#endif