mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-23 00:52:31 +08:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
12cd718f12 | |||
995e2a3e93 | |||
2c95fec646 | |||
69912d7ea4 | |||
9c5596ace4 |
BIN
lib/0Harmony.dll
BIN
lib/0Harmony.dll
Binary file not shown.
BIN
lib/BepInEx.dll
BIN
lib/BepInEx.dll
Binary file not shown.
Binary file not shown.
@ -32,7 +32,7 @@ namespace UnityExplorer.CSConsole
|
||||
private Text inputHighlightText;
|
||||
|
||||
private readonly CSharpLexer highlightLexer;
|
||||
private readonly StringBuilder sbHighlight;
|
||||
//private readonly StringBuilder sbHighlight;
|
||||
|
||||
internal int m_lastCaretPos;
|
||||
internal int m_fixCaretPos;
|
||||
@ -68,7 +68,6 @@ The following helper methods are available:
|
||||
|
||||
public CodeEditor()
|
||||
{
|
||||
sbHighlight = new StringBuilder();
|
||||
highlightLexer = new CSharpLexer();
|
||||
|
||||
ConstructUI();
|
||||
@ -76,8 +75,24 @@ The following helper methods are available:
|
||||
InputField.onValueChanged.AddListener((string s) => { OnInputChanged(s); });
|
||||
}
|
||||
|
||||
internal static bool IsUserCopyPasting()
|
||||
{
|
||||
return (InputManager.GetKey(KeyCode.LeftControl) || InputManager.GetKey(KeyCode.RightControl))
|
||||
&& InputManager.GetKeyDown(KeyCode.V);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (s_copyPasteBuffer != null)
|
||||
{
|
||||
if (!IsUserCopyPasting())
|
||||
{
|
||||
OnInputChanged(s_copyPasteBuffer);
|
||||
|
||||
s_copyPasteBuffer = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (EnableCtrlRShortcut)
|
||||
{
|
||||
if ((InputManager.GetKey(KeyCode.LeftControl) || InputManager.GetKey(KeyCode.RightControl))
|
||||
@ -149,11 +164,18 @@ The following helper methods are available:
|
||||
AutoCompleter.ClearAutocompletes();
|
||||
}
|
||||
|
||||
public void OnInputChanged(string newInput, bool forceUpdate = false)
|
||||
{
|
||||
string newText = newInput;
|
||||
internal static string s_copyPasteBuffer;
|
||||
|
||||
UpdateIndent(newInput);
|
||||
public void OnInputChanged(string newText, bool forceUpdate = false)
|
||||
{
|
||||
if (IsUserCopyPasting())
|
||||
{
|
||||
//Console.WriteLine("Copy+Paste detected!");
|
||||
s_copyPasteBuffer = newText;
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateIndent(newText);
|
||||
|
||||
if (!forceUpdate && string.IsNullOrEmpty(newText))
|
||||
inputHighlightText.text = string.Empty;
|
||||
@ -203,35 +225,29 @@ The following helper methods are available:
|
||||
{
|
||||
int offset = 0;
|
||||
|
||||
sbHighlight.Length = 0;
|
||||
//Console.WriteLine("Highlighting input text:\r\n" + inputText);
|
||||
|
||||
string ret = "";
|
||||
|
||||
foreach (LexerMatchInfo match in highlightLexer.GetMatches(inputText))
|
||||
{
|
||||
for (int i = offset; i < match.startIndex; i++)
|
||||
{
|
||||
sbHighlight.Append(inputText[i]);
|
||||
}
|
||||
ret += inputText[i];
|
||||
|
||||
sbHighlight.Append($"{match.htmlColor}");
|
||||
ret += $"{match.htmlColor}";
|
||||
|
||||
for (int i = match.startIndex; i < match.endIndex; i++)
|
||||
{
|
||||
sbHighlight.Append(inputText[i]);
|
||||
}
|
||||
ret += inputText[i];
|
||||
|
||||
sbHighlight.Append(CLOSE_COLOR_TAG);
|
||||
ret += CLOSE_COLOR_TAG;
|
||||
|
||||
offset = match.endIndex;
|
||||
}
|
||||
|
||||
for (int i = offset; i < inputText.Length; i++)
|
||||
{
|
||||
sbHighlight.Append(inputText[i]);
|
||||
}
|
||||
ret += inputText[i];
|
||||
|
||||
inputText = sbHighlight.ToString();
|
||||
|
||||
return inputText;
|
||||
return ret;
|
||||
}
|
||||
|
||||
private void AutoIndentCaret()
|
||||
|
@ -24,7 +24,8 @@ namespace UnityExplorer.Config
|
||||
public int Default_Page_Limit = 25;
|
||||
public string Default_Output_Path = ExplorerCore.EXPLORER_FOLDER + @"\Output";
|
||||
public bool Log_Unity_Debug = false;
|
||||
public bool Save_Logs_To_Disk = true;
|
||||
public bool Hide_On_Startup = false;
|
||||
//public bool Save_Logs_To_Disk = true;
|
||||
|
||||
public static event Action OnConfigChanged;
|
||||
|
||||
@ -56,24 +57,27 @@ namespace UnityExplorer.Config
|
||||
{
|
||||
switch (config.KeyName)
|
||||
{
|
||||
case "Main_Menu_Toggle":
|
||||
case nameof(Main_Menu_Toggle):
|
||||
Instance.Main_Menu_Toggle = (KeyCode)Enum.Parse(typeof(KeyCode), config.Value);
|
||||
break;
|
||||
case "Force_Unlock_Mouse":
|
||||
case nameof(Force_Unlock_Mouse):
|
||||
Instance.Force_Unlock_Mouse = bool.Parse(config.Value);
|
||||
break;
|
||||
case "Default_Page_Limit":
|
||||
case nameof(Default_Page_Limit):
|
||||
Instance.Default_Page_Limit = int.Parse(config.Value);
|
||||
break;
|
||||
case "Log_Unity_Debug":
|
||||
case nameof(Log_Unity_Debug):
|
||||
Instance.Log_Unity_Debug = bool.Parse(config.Value);
|
||||
break;
|
||||
case "Save_Logs_To_Disk":
|
||||
Instance.Save_Logs_To_Disk = bool.Parse(config.Value);
|
||||
break;
|
||||
case "Default_Output_Path":
|
||||
case nameof(Default_Output_Path):
|
||||
Instance.Default_Output_Path = config.Value;
|
||||
break;
|
||||
case nameof(Hide_On_Startup):
|
||||
Instance.Hide_On_Startup = bool.Parse(config.Value);
|
||||
break;
|
||||
//case nameof(Save_Logs_To_Disk):
|
||||
// Instance.Save_Logs_To_Disk = bool.Parse(config.Value);
|
||||
// break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,12 +91,13 @@ namespace UnityExplorer.Config
|
||||
data.Sections.AddSection("Config");
|
||||
|
||||
var sec = data.Sections["Config"];
|
||||
sec.AddKey("Main_Menu_Toggle", Instance.Main_Menu_Toggle.ToString());
|
||||
sec.AddKey("Force_Unlock_Mouse", Instance.Force_Unlock_Mouse.ToString());
|
||||
sec.AddKey("Default_Page_Limit", Instance.Default_Page_Limit.ToString());
|
||||
sec.AddKey("Log_Unity_Debug", Instance.Log_Unity_Debug.ToString());
|
||||
sec.AddKey("Save_Logs_To_Disk", Instance.Save_Logs_To_Disk.ToString());
|
||||
sec.AddKey("Default_Output_Path", Instance.Default_Output_Path);
|
||||
sec.AddKey(nameof(Main_Menu_Toggle), Instance.Main_Menu_Toggle.ToString());
|
||||
sec.AddKey(nameof(Force_Unlock_Mouse), Instance.Force_Unlock_Mouse.ToString());
|
||||
sec.AddKey(nameof(Default_Page_Limit), Instance.Default_Page_Limit.ToString());
|
||||
sec.AddKey(nameof(Log_Unity_Debug), Instance.Log_Unity_Debug.ToString());
|
||||
sec.AddKey(nameof(Default_Output_Path), Instance.Default_Output_Path);
|
||||
sec.AddKey(nameof(Hide_On_Startup), Instance.Hide_On_Startup.ToString());
|
||||
//sec.AddKey("Save_Logs_To_Disk", Instance.Save_Logs_To_Disk.ToString());
|
||||
|
||||
File.WriteAllText(INI_PATH, data.ToString());
|
||||
}
|
||||
|
@ -4,27 +4,25 @@ using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityExplorer.Config;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Input;
|
||||
using UnityExplorer.Inspectors;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Modules;
|
||||
#if CPP
|
||||
using UnityExplorer.Helpers;
|
||||
#endif
|
||||
|
||||
namespace UnityExplorer
|
||||
{
|
||||
public class ExplorerCore
|
||||
{
|
||||
public const string NAME = "UnityExplorer";
|
||||
public const string VERSION = "3.1.8";
|
||||
public const string VERSION = "3.1.12";
|
||||
public const string AUTHOR = "Sinai";
|
||||
public const string GUID = "com.sinai.unityexplorer";
|
||||
|
||||
#if ML
|
||||
public const string EXPLORER_FOLDER = @"Mods\UnityExplorer";
|
||||
public static string EXPLORER_FOLDER = Path.Combine("Mods", NAME);
|
||||
#elif BIE
|
||||
public static string EXPLORER_FOLDER = Path.Combine(BepInEx.Paths.ConfigPath, "UnityExplorer");
|
||||
public static string EXPLORER_FOLDER = Path.Combine(BepInEx.Paths.ConfigPath, NAME);
|
||||
#elif STANDALONE
|
||||
public static string EXPLORER_FOLDER
|
||||
{
|
||||
@ -112,6 +110,10 @@ namespace UnityExplorer
|
||||
{
|
||||
UIManager.Init();
|
||||
Log("Initialized UnityExplorer UI.");
|
||||
|
||||
if (ModConfig.Instance.Hide_On_Startup)
|
||||
ShowMenu = false;
|
||||
|
||||
// InspectorManager.Instance.Inspect(Tests.TestClass.Instance);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -93,18 +93,18 @@ namespace UnityExplorer.Helpers
|
||||
}
|
||||
|
||||
#if CPP
|
||||
private static readonly Dictionary<CppType, Type> Il2CppToMonoType = new Dictionary<CppType, Type>();
|
||||
private static readonly Dictionary<string, Type> Il2CppToMonoType = new Dictionary<string, Type>();
|
||||
|
||||
public static Type GetMonoType(CppType cppType)
|
||||
{
|
||||
if (Il2CppToMonoType.ContainsKey(cppType))
|
||||
return Il2CppToMonoType[cppType];
|
||||
if (Il2CppToMonoType.ContainsKey(cppType.AssemblyQualifiedName))
|
||||
return Il2CppToMonoType[cppType.AssemblyQualifiedName];
|
||||
|
||||
var getType = Type.GetType(cppType.AssemblyQualifiedName);
|
||||
|
||||
if (getType != null)
|
||||
{
|
||||
Il2CppToMonoType.Add(cppType, getType);
|
||||
Il2CppToMonoType.Add(cppType.AssemblyQualifiedName, getType);
|
||||
return getType;
|
||||
}
|
||||
else
|
||||
@ -112,11 +112,17 @@ namespace UnityExplorer.Helpers
|
||||
string baseName = cppType.FullName;
|
||||
string baseAssembly = cppType.Assembly.GetName().name;
|
||||
|
||||
Type unhollowedType = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name == baseAssembly)?.GetTypes().FirstOrDefault(t =>
|
||||
t.CustomAttributes.Any(ca =>
|
||||
ca.AttributeType.Name == "ObfuscatedNameAttribute" && (string)ca.ConstructorArguments[0].Value == baseName));
|
||||
Type unhollowedType = AppDomain.CurrentDomain
|
||||
.GetAssemblies()
|
||||
.FirstOrDefault(a => a.GetName().Name == baseAssembly)?
|
||||
.TryGetTypes()
|
||||
.FirstOrDefault(t =>
|
||||
t.CustomAttributes.Any(ca
|
||||
=> ca.AttributeType.Name == "ObfuscatedNameAttribute"
|
||||
&& (string)ca.ConstructorArguments[0].Value == baseName));
|
||||
|
||||
Il2CppToMonoType.Add(cppType.AssemblyQualifiedName, unhollowedType);
|
||||
|
||||
Il2CppToMonoType.Add(cppType, unhollowedType);
|
||||
return unhollowedType;
|
||||
}
|
||||
}
|
||||
|
@ -55,16 +55,15 @@ namespace UnityExplorer.Inspectors
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!m_dontDestroyObject)
|
||||
if (!s_dontDestroyObject)
|
||||
{
|
||||
m_dontDestroyObject = new GameObject("DontDestroyMe");
|
||||
GameObject.DontDestroyOnLoad(m_dontDestroyObject);
|
||||
s_dontDestroyObject = new GameObject("DontDestroyMe");
|
||||
GameObject.DontDestroyOnLoad(s_dontDestroyObject);
|
||||
}
|
||||
return m_dontDestroyObject;
|
||||
return s_dontDestroyObject;
|
||||
}
|
||||
}
|
||||
|
||||
internal static GameObject m_dontDestroyObject;
|
||||
internal static GameObject s_dontDestroyObject;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
@ -97,22 +96,6 @@ namespace UnityExplorer.Inspectors
|
||||
}
|
||||
}
|
||||
|
||||
//#if CPP
|
||||
// public int GetSceneHandle(string sceneName)
|
||||
// {
|
||||
// if (sceneName == "DontDestroyOnLoad")
|
||||
// return DontDestroyScene;
|
||||
|
||||
// for (int i = 0; i < SceneManager.sceneCount; i++)
|
||||
// {
|
||||
// var scene = SceneManager.GetSceneAt(i);
|
||||
// if (scene.name == sceneName)
|
||||
// return scene.handle;
|
||||
// }
|
||||
// return -1;
|
||||
// }
|
||||
//#endif
|
||||
|
||||
internal void OnSceneChange()
|
||||
{
|
||||
m_sceneDropdown.OnCancel(null);
|
||||
@ -121,8 +104,13 @@ namespace UnityExplorer.Inspectors
|
||||
|
||||
private void RefreshSceneSelector()
|
||||
{
|
||||
var names = new List<string>();
|
||||
var scenes = new List<Scene>();
|
||||
var newNames = new List<string>();
|
||||
var newScenes = new List<Scene>();
|
||||
|
||||
if (m_currentScenes == null)
|
||||
m_currentScenes = new Scene[0];
|
||||
|
||||
bool anyChange = SceneManager.sceneCount != m_currentScenes.Length - 1;
|
||||
|
||||
for (int i = 0; i < SceneManager.sceneCount; i++)
|
||||
{
|
||||
@ -131,33 +119,32 @@ namespace UnityExplorer.Inspectors
|
||||
if (scene == default)
|
||||
continue;
|
||||
|
||||
scenes.Add(scene);
|
||||
names.Add(scene.name);
|
||||
if (!anyChange && !m_currentScenes.Any(it => it.GetHandle() == scene.GetHandle()))
|
||||
anyChange = true;
|
||||
|
||||
newScenes.Add(scene);
|
||||
newNames.Add(scene.name);
|
||||
}
|
||||
|
||||
names.Add("DontDestroyOnLoad");
|
||||
scenes.Add(DontDestroyScene);
|
||||
newNames.Add("DontDestroyOnLoad");
|
||||
newScenes.Add(DontDestroyScene);
|
||||
|
||||
m_sceneDropdown.options.Clear();
|
||||
|
||||
foreach (string scene in names)
|
||||
foreach (string scene in newNames)
|
||||
{
|
||||
m_sceneDropdown.options.Add(new Dropdown.OptionData { text = scene });
|
||||
}
|
||||
|
||||
if (!names.Contains(m_sceneDropdownText.text))
|
||||
if (anyChange)
|
||||
{
|
||||
m_sceneDropdownText.text = names[0];
|
||||
SetTargetScene(scenes[0]);
|
||||
m_sceneDropdownText.text = newNames[0];
|
||||
SetTargetScene(newScenes[0]);
|
||||
}
|
||||
|
||||
m_currentScenes = scenes.ToArray();
|
||||
m_currentScenes = newScenes.ToArray();
|
||||
}
|
||||
|
||||
//#if CPP
|
||||
// public void SetTargetScene(string name) => SetTargetScene(scene.handle);
|
||||
//#endif
|
||||
|
||||
public void SetTargetScene(Scene scene)
|
||||
{
|
||||
if (scene == default)
|
||||
@ -167,7 +154,7 @@ namespace UnityExplorer.Inspectors
|
||||
#if CPP
|
||||
GameObject[] rootObjs = SceneUnstrip.GetRootGameObjects(scene.handle);
|
||||
#else
|
||||
GameObject[] rootObjs = SceneUnstrip.GetRootGameObjects(scene);
|
||||
GameObject[] rootObjs = scene.GetRootGameObjects();
|
||||
#endif
|
||||
SetSceneObjectList(rootObjs);
|
||||
|
||||
|
@ -16,7 +16,7 @@ namespace UnityExplorer.UI.Modules
|
||||
public static DebugConsole Instance { get; private set; }
|
||||
|
||||
public static bool LogUnity { get; set; } = ModConfig.Instance.Log_Unity_Debug;
|
||||
public static bool SaveToDisk { get; set; } = ModConfig.Instance.Save_Logs_To_Disk;
|
||||
//public static bool SaveToDisk { get; set; } = ModConfig.Instance.Save_Logs_To_Disk;
|
||||
|
||||
internal static StreamWriter s_streamWriter;
|
||||
|
||||
@ -49,8 +49,8 @@ namespace UnityExplorer.UI.Modules
|
||||
|
||||
// set up IO
|
||||
|
||||
if (!SaveToDisk)
|
||||
return;
|
||||
//if (!SaveToDisk)
|
||||
// return;
|
||||
|
||||
var path = ExplorerCore.EXPLORER_FOLDER + @"\Logs";
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
//using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Config;
|
||||
@ -19,6 +18,7 @@ namespace UnityExplorer.UI.Modules
|
||||
private Toggle m_unlockMouseToggle;
|
||||
private InputField m_pageLimitInput;
|
||||
private InputField m_defaultOutputInput;
|
||||
private Toggle m_hideOnStartupToggle;
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
@ -27,26 +27,21 @@ namespace UnityExplorer.UI.Modules
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
// not needed?
|
||||
}
|
||||
|
||||
internal void OnApply()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(m_keycodeInput.text) && Enum.Parse(typeof(KeyCode), m_keycodeInput.text) is KeyCode keyCode)
|
||||
{
|
||||
ModConfig.Instance.Main_Menu_Toggle = keyCode;
|
||||
}
|
||||
|
||||
ModConfig.Instance.Force_Unlock_Mouse = m_unlockMouseToggle.isOn;
|
||||
|
||||
if (!string.IsNullOrEmpty(m_pageLimitInput.text) && int.TryParse(m_pageLimitInput.text, out int lim))
|
||||
{
|
||||
ModConfig.Instance.Default_Page_Limit = lim;
|
||||
}
|
||||
|
||||
ModConfig.Instance.Default_Output_Path = m_defaultOutputInput.text;
|
||||
|
||||
// todo default output path
|
||||
ModConfig.Instance.Hide_On_Startup = m_hideOnStartupToggle.isOn;
|
||||
|
||||
ModConfig.SaveSettings();
|
||||
ModConfig.InvokeConfigChanged();
|
||||
@ -98,6 +93,7 @@ namespace UnityExplorer.UI.Modules
|
||||
ConstructMouseUnlockOpt(optionsGroupObj);
|
||||
ConstructPageLimitOpt(optionsGroupObj);
|
||||
ConstructOutputPathOpt(optionsGroupObj);
|
||||
ConstructHideOnStartupOpt(optionsGroupObj);
|
||||
|
||||
var applyBtnObj = UIFactory.CreateButton(Content, new Color(0.2f, 0.2f, 0.2f));
|
||||
var applyText = applyBtnObj.GetComponentInChildren<Text>();
|
||||
@ -113,10 +109,34 @@ namespace UnityExplorer.UI.Modules
|
||||
applyBtn.onClick.AddListener(OnApply);
|
||||
}
|
||||
|
||||
private void ConstructHideOnStartupOpt(GameObject optionsGroupObj)
|
||||
{
|
||||
var rowObj = UIFactory.CreateHorizontalGroup(optionsGroupObj, new Color(1, 1, 1, 0));
|
||||
var rowGroup = rowObj.GetComponent<HorizontalLayoutGroup>();
|
||||
rowGroup.childControlWidth = true;
|
||||
rowGroup.childForceExpandWidth = false;
|
||||
rowGroup.childControlHeight = true;
|
||||
rowGroup.childForceExpandHeight = true;
|
||||
var groupLayout = rowObj.AddComponent<LayoutElement>();
|
||||
groupLayout.minHeight = 25;
|
||||
groupLayout.flexibleHeight = 0;
|
||||
groupLayout.minWidth = 200;
|
||||
groupLayout.flexibleWidth = 1000;
|
||||
|
||||
var labelObj = UIFactory.CreateLabel(rowObj, TextAnchor.MiddleLeft);
|
||||
var labelText = labelObj.GetComponent<Text>();
|
||||
labelText.text = "Hide UI on startup:";
|
||||
var labelLayout = labelObj.AddComponent<LayoutElement>();
|
||||
labelLayout.minWidth = 150;
|
||||
labelLayout.minHeight = 25;
|
||||
|
||||
UIFactory.CreateToggle(rowObj, out m_hideOnStartupToggle, out Text toggleText);
|
||||
m_hideOnStartupToggle.isOn = ModConfig.Instance.Hide_On_Startup;
|
||||
toggleText.text = "";
|
||||
}
|
||||
|
||||
internal void ConstructKeycodeOpt(GameObject parent)
|
||||
{
|
||||
//public KeyCode Main_Menu_Toggle = KeyCode.F7;
|
||||
|
||||
var rowObj = UIFactory.CreateHorizontalGroup(parent, new Color(1, 1, 1, 0));
|
||||
var rowGroup = rowObj.GetComponent<HorizontalLayoutGroup>();
|
||||
rowGroup.childControlWidth = true;
|
||||
@ -146,8 +166,6 @@ namespace UnityExplorer.UI.Modules
|
||||
|
||||
internal void ConstructMouseUnlockOpt(GameObject parent)
|
||||
{
|
||||
//public bool Force_Unlock_Mouse = true;
|
||||
|
||||
var rowObj = UIFactory.CreateHorizontalGroup(parent, new Color(1, 1, 1, 0));
|
||||
var rowGroup = rowObj.GetComponent<HorizontalLayoutGroup>();
|
||||
rowGroup.childControlWidth = true;
|
||||
|
@ -3,36 +3,25 @@ using UnityExplorer.Helpers;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityExplorer.Inspectors;
|
||||
using System.Reflection;
|
||||
|
||||
namespace UnityExplorer.Unstrip
|
||||
{
|
||||
public class SceneUnstrip
|
||||
public static class SceneUnstrip
|
||||
{
|
||||
#if MONO
|
||||
public static GameObject[] GetRootGameObjects(Scene scene) => scene.GetRootGameObjects();
|
||||
|
||||
//public static GameObject[] GetRootGameObjects(int handle)
|
||||
//{
|
||||
// Scene scene = default;
|
||||
// if (handle == SceneExplorer.DontDestroyHandle)
|
||||
// scene = SceneExplorer.DontDestroyObject.scene;
|
||||
// else
|
||||
// {
|
||||
// for (int i = 0; i < SceneManager.sceneCount; i++)
|
||||
// {
|
||||
// var iscene = SceneManager.GetSceneAt(i);
|
||||
// if (iscene.handle == handle)
|
||||
// scene = iscene;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (scene != default && scene.handle != -1)
|
||||
// return scene.GetRootGameObjects();
|
||||
|
||||
// return new GameObject[0];
|
||||
//}
|
||||
private static readonly FieldInfo fi_Scene_handle = typeof(Scene).GetField("m_Handle", ReflectionHelpers.CommonFlags);
|
||||
#endif
|
||||
|
||||
public static int GetHandle(this Scene scene)
|
||||
{
|
||||
#if CPP
|
||||
return scene.handle;
|
||||
#else
|
||||
return (int)fi_Scene_handle.GetValue(scene);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if CPP
|
||||
//Scene.GetRootGameObjects();
|
||||
|
||||
@ -43,13 +32,16 @@ namespace UnityExplorer.Unstrip
|
||||
public static GameObject[] GetRootGameObjects(int handle)
|
||||
{
|
||||
if (handle == -1)
|
||||
{
|
||||
return new GameObject[0];
|
||||
}
|
||||
|
||||
Il2CppSystem.Collections.Generic.List<GameObject> list = new Il2CppSystem.Collections.Generic.List<GameObject>(GetRootCount(handle));
|
||||
int count = GetRootCount(handle);
|
||||
|
||||
d_GetRootGameObjects iCall = ICallHelper.GetICall<d_GetRootGameObjects>("UnityEngine.SceneManagement.Scene::GetRootGameObjectsInternal");
|
||||
if (count < 1)
|
||||
return new GameObject[0];
|
||||
|
||||
var list = new Il2CppSystem.Collections.Generic.List<GameObject>(count);
|
||||
|
||||
var iCall = ICallHelper.GetICall<d_GetRootGameObjects>("UnityEngine.SceneManagement.Scene::GetRootGameObjectsInternal");
|
||||
|
||||
iCall.Invoke(handle, list.Pointer);
|
||||
|
||||
@ -58,14 +50,14 @@ namespace UnityExplorer.Unstrip
|
||||
|
||||
//Scene.rootCount;
|
||||
|
||||
internal delegate int GetRootCountInternal_delegate(int handle);
|
||||
internal delegate int d_GetRootCountInternal(int handle);
|
||||
|
||||
public static int GetRootCount(Scene scene) => GetRootCount(scene.handle);
|
||||
|
||||
public static int GetRootCount(int handle)
|
||||
{
|
||||
GetRootCountInternal_delegate iCall = ICallHelper.GetICall<GetRootCountInternal_delegate>("UnityEngine.SceneManagement.Scene::GetRootCountInternal");
|
||||
return iCall.Invoke(handle);
|
||||
return ICallHelper.GetICall<d_GetRootCountInternal>("UnityEngine.SceneManagement.Scene::GetRootCountInternal")
|
||||
.Invoke(handle);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user