diff --git a/README.md b/README.md index e7d639bf..b02b6ebe 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,20 @@ -# CppExplorer [![Version](https://img.shields.io/badge/MelonLoader-0.2.7.1-green.svg)](https://github.com/HerpDerpinstine/MelonLoader) +# Explorer [![Version](https://img.shields.io/badge/MelonLoader-0.2.7.1-green.svg)](https://github.com/HerpDerpinstine/MelonLoader) [![Version](https://img.shields.io/badge/BepInEx-5.3.0.svg)](https://github.com/BepInEx/BepInEx)

- An in-game explorer and a suite of debugging tools for IL2CPP Unity games, using MelonLoader.

+ An in-game explorer and a suite of debugging tools for IL2CPP and Mono Unity games, using MelonLoader and BepInEx.

- + - -

-

- Looking for a Mono version? +

-- [Known issues](#known-issues) +- [Current status](#current-status) - [How to install](#how-to-install) - [How to use](#how-to-use) - [Mod Config](#mod-config) @@ -26,21 +23,34 @@ - [Building](#building) - [Credits](#credits) -## Known issues -As of version 1.7+, CppExplorer has reached a fairly stable state for most Il2Cpp games. +## Current status + +| Mod Loader | Il2Cpp | Mono | +| ----------- | ------ | ---- | +| MelonLoader | ✔ | ✔ | +| BepInEx | ? (WIP) | ✔ | +IL2CPP Issues: * .NET 3.5 is not currently supported (Unity 5.6.1 and older), this might change in the future. * Some methods may still fail with a `MissingMethodException`, please let me know if you experience this (with full MelonLoader log please). * Reflection may fail with certain types, see [here](https://github.com/knah/Il2CppAssemblyUnhollower#known-issues) for more details. -* Scrolling with mouse wheel in the CppExplorer menu may not work on all games at the moment. +* Scrolling with mouse wheel in the Explorer menu may not work on all games at the moment. ## How to install +### MelonLoader Requires [MelonLoader](https://github.com/HerpDerpinstine/MelonLoader) to be installed for your game. -1. Download CppExplorer.zip from [Releases](https://github.com/sinai-dev/CppExplorer/releases). +1. Download the relevant Explorer_MelonLoader_.zip from [Releases](https://github.com/sinai-dev/Explorer/releases). 2. Unzip the file into the `Mods` folder in your game's installation directory, created by MelonLoader. -3. Make sure it's not in a sub-folder, `CppExplorer.dll` and `mcs.dll` should be directly in the `Mods\` folder. +3. Make sure it's not in a sub-folder, `Explorer.dll` and `mcs.dll` should be directly in the `Mods\` folder. + +### BepInEx +Requires [BepInEx](https://github.com/BepInEx/BepInEx) to be installed for your game. + +1. Download the relevant Explorer_BepInEx_.zip from [Releases](https://github.com/sinai-dev/Explorer/releases). +2. Unzip the file into the `BepInEx\plugins\` folder in your game's installation directory, created by MelonLoader. +3. Make sure it's not in a sub-folder, `Explorer.dll` and `mcs.dll` should be directly in the `plugins\` folder. ## How to use @@ -50,24 +60,24 @@ Requires [MelonLoader](https://github.com/HerpDerpinstine/MelonLoader) to be ins ### Mod Config -There is a simple Mod Config for the CppExplorer, which is generated the first time you run it. +There is a simple Mod Config for the Explorer, which is generated the first time you run it. -This config is generated to `Mods\CppExplorer\config.xml`. Edit the config while the game is closed if you wish to change it. +This config is generated to `[Game_Directory]\Mods\Explorer\config.xml`. Edit the config while the game is closed if you wish to change it. `Main_Menu_Toggle` (KeyCode) -* Sets the keybinding for the Main Menu toggle (show/hide all CppExplorer windows) +* Sets the keybinding for the Main Menu toggle (show/hide all Explorer windows) * See [this article](https://docs.unity3d.com/ScriptReference/KeyCode.html) for a full list of all accepted KeyCodes. * Default: `F7` `Default_Window_Size` (Vector2) -* Sets the default width and height for all CppExplorer windows when created. +* Sets the default width and height for all Explorer windows when created. * `x` is width, `y` is height. * Default: `550 700` ## Features -[![](overview.png)](https://raw.githubusercontent.com/sinai-dev/CppExplorer/master/overview.png) +[![](overview.png)](https://raw.githubusercontent.com/sinai-dev/Explorer/master/overview.png) -An overview of the different CppExplorer menus. +An overview of the different Explorer menus. ### Scene Explorer @@ -76,7 +86,7 @@ This config is generated to `Mods\CppExplorer\config.xml`. Edit the config while ### Inspectors -CppExplorer has two main inspector modes: GameObject Inspector, and Reflection Inspector. +Explorer has two main inspector modes: GameObject Inspector, and Reflection Inspector. Tips: * When in Tab View, GameObjects are denoted by a [G] prefix, and Reflection objects are denoted by a [R] prefix. @@ -105,13 +115,13 @@ CppExplorer has two main inspector modes: GameObject Inspector, and Re ### Inspect-under-mouse -* Press Shift+RMB (Right Mouse Button) while the CppExplorer menu is open to begin Inspect-Under-Mouse. +* Press Shift+RMB (Right Mouse Button) while the Explorer menu is open to begin Inspect-Under-Mouse. * Hover over your desired object, if you see the name appear then you can click on it to inspect it. * Only objects with Colliders are supported. ### Mouse Control -CppExplorer can force the mouse to be visible and unlocked when the menu is open, if you have enabled "Force Unlock Mouse" (Left-Alt toggle). However, you may also want to prevent the mouse clicking-through onto the game behind CppExplorer, this is possible but it requires specific patches for that game. +Explorer can force the mouse to be visible and unlocked when the menu is open, if you have enabled "Force Unlock Mouse" (Left-Alt toggle). However, you may also want to prevent the mouse clicking-through onto the game behind Explorer, this is possible but it requires specific patches for that game. * For VRChat, use [VRCExplorerMouseControl](https://github.com/sinai-dev/VRCExplorerMouseControl) * For Hellpoint, use [HPExplorerMouseControl](https://github.com/sinai-dev/Hellpoint-Mods/tree/master/HPExplorerMouseControl/HPExplorerMouseControl) @@ -125,12 +135,12 @@ using Harmony; [HarmonyPatch(typeof(MyGame.MenuClass), nameof(MyGame.MenuClass.CursorUpdate)] public class MenuClass_CursorUpdate { - [HarmonyPrefix] - public static bool Prefix() - { - // prevent method running if menu open, let it run if not. - return !CppExplorer.ShowMenu; - } + [HarmonyPrefix] + public static bool Prefix() + { + // prevent method running if menu open, let it run if not. + return !ExplorerCore.ShowMenu; + } } ``` @@ -139,11 +149,11 @@ public class MenuClass_CursorUpdate If you'd like to build this yourself, everything you need (other than MelonLoader) is included with this repository, there is no need for recursive cloning etc. 1. Install MelonLoader for your game. -2. Open the `src\CppExplorer.csproj` file in a text editor. -3. Scroll down until you see the `` containing the References. -4. Fix all of the paths in the `..\Steam\` directory for your game (use the full path if you need to). -5. Open the `src\CppExplorer.sln` project and build it. -6. The dll is built to the `Release\` folder in the root of the repository. +2. Open the `src\Explorer.csproj` file in a text editor. +3. Set the relevant `GameFolder` value(s) for the version(s) you want to build, eg. set `MLCppGameFolder` if you want to build for a MelonLoader Il2Cpp game. +4. Open the `src\Explorer.sln` project. +5. Select `Solution 'Explorer' (1 of 1 project)` in the Solution Explorer panel, and set the Active config to the version you want to build, then build it. +5. The DLLs are built to the `Release\` folder in the root of the repository. ## Credits diff --git a/icon.png b/icon.png index 14c82ad3..ae791aa8 100644 Binary files a/icon.png and b/icon.png differ diff --git a/lib/UnityEngine.dll b/lib/UnityEngine.dll new file mode 100644 index 00000000..ce772f8d Binary files /dev/null and b/lib/UnityEngine.dll differ diff --git a/overview.png b/overview.png index 97cadcf3..758ebe5a 100644 Binary files a/overview.png and b/overview.png differ diff --git a/src/CachedObjects/CacheObjectBase.cs b/src/CachedObjects/CacheObjectBase.cs index 9646e37a..c5fbe21e 100644 --- a/src/CachedObjects/CacheObjectBase.cs +++ b/src/CachedObjects/CacheObjectBase.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using MelonLoader; using UnityEngine; namespace Explorer @@ -272,13 +271,13 @@ public object[] ParseArguments() } catch { - MelonLogger.Log($"Argument #{i} '{m_arguments[i].Name}' ({type.Name}), could not parse input '{input}'."); + ExplorerCore.Log($"Argument #{i} '{m_arguments[i].Name}' ({type.Name}), could not parse input '{input}'."); } } } // Didn't use input, see if there is a default value. - if (m_arguments[i].HasDefaultValue) + if (HasDefaultValue(m_arguments[i])) { parsedArgs.Add(m_arguments[i].DefaultValue); continue; @@ -291,6 +290,16 @@ public object[] ParseArguments() return parsedArgs.ToArray(); } + public static bool HasDefaultValue(ParameterInfo arg) + { + return +#if NET35 + arg.DefaultValue != null; // rip null default args in NET35 +#else + arg.HasDefaultValue; +#endif + } + public virtual void UpdateValue() { if (MemInfo == null) @@ -348,13 +357,13 @@ public void SetValue() } else { - pi.SetValue(pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance, Value); + pi.SetValue(pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance, Value, null); } } } catch (Exception e) { - MelonLogger.LogWarning($"Error setting value: {e.GetType()}, {e.Message}"); + ExplorerCore.LogWarning($"Error setting value: {e.GetType()}, {e.Message}"); } } @@ -391,13 +400,13 @@ public void Draw(Rect window, float labelWidth = 215f) if (HasParameters) { - GUILayout.BeginVertical(null); + GUILayout.BeginVertical(new GUILayoutOption[0]); if (m_isEvaluating) { if (cm != null && cm.GenericArgs.Length > 0) { - GUILayout.Label($"Generic Arguments:", null); + GUILayout.Label($"Generic Arguments:", new GUILayoutOption[0]); for (int i = 0; i < cm.GenericArgs.Length; i++) { @@ -424,13 +433,13 @@ public void Draw(Rect window, float labelWidth = 215f) } var input = cm.GenericArgInput[i]; - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUILayout.Label($"{cm.GenericArgs[i].Name}", new GUILayoutOption[] { GUILayout.Width(15) }); cm.GenericArgInput[i] = GUILayout.TextField(input, new GUILayoutOption[] { GUILayout.Width(150) }); GUI.skin.label.alignment = TextAnchor.MiddleLeft; - GUILayout.Label(types, null); + GUILayout.Label(types, new GUILayoutOption[0]); GUILayout.EndHorizontal(); } @@ -438,7 +447,7 @@ public void Draw(Rect window, float labelWidth = 215f) if (m_arguments.Length > 0) { - GUILayout.Label($"Arguments:", null); + GUILayout.Label($"Arguments:", new GUILayoutOption[0]); for (int i = 0; i < m_arguments.Length; i++) { var name = m_arguments[i].Name; @@ -447,24 +456,24 @@ public void Draw(Rect window, float labelWidth = 215f) var label = $"{type} "; label += $"{name}"; - if (m_arguments[i].HasDefaultValue) + if (HasDefaultValue(m_arguments[i])) { label = $"[{label} = {m_arguments[i].DefaultValue ?? "null"}]"; } - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUILayout.Label(i.ToString(), new GUILayoutOption[] { GUILayout.Width(15) }); m_argumentInput[i] = GUILayout.TextField(input, new GUILayoutOption[] { GUILayout.Width(150) }); GUI.skin.label.alignment = TextAnchor.MiddleLeft; - GUILayout.Label(label, null); + GUILayout.Label(label, new GUILayoutOption[0]); GUILayout.EndHorizontal(); } } - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); if (GUILayout.Button(EVALUATE_LABEL, new GUILayoutOption[] { GUILayout.Width(70) })) { if (cm != null) @@ -499,7 +508,7 @@ public void Draw(Rect window, float labelWidth = 215f) // new line and space GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(labelWidth); } else if (cm != null) @@ -513,7 +522,7 @@ public void Draw(Rect window, float labelWidth = 215f) // new line and space GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(labelWidth); } @@ -521,15 +530,15 @@ public void Draw(Rect window, float labelWidth = 215f) if (!string.IsNullOrEmpty(ReflectionException)) { - GUILayout.Label("Reflection failed! (" + ReflectionException + ")", null); + GUILayout.Label("Reflection failed! (" + ReflectionException + ")", new GUILayoutOption[0]); } else if ((HasParameters || this is CacheMethod) && !m_evaluated) { - GUILayout.Label($"Not yet evaluated ({typeName})", null); + GUILayout.Label($"Not yet evaluated ({typeName})", new GUILayoutOption[0]); } else if (Value == null && !(this is CacheMethod)) { - GUILayout.Label($"null ({typeName})", null); + GUILayout.Label($"null ({typeName})", new GUILayoutOption[0]); } else { diff --git a/src/CachedObjects/Object/CacheDictionary.cs b/src/CachedObjects/Object/CacheDictionary.cs index c31519b6..b0de5688 100644 --- a/src/CachedObjects/Object/CacheDictionary.cs +++ b/src/CachedObjects/Object/CacheDictionary.cs @@ -1,8 +1,10 @@ using System; using System.Collections; using System.Collections.Generic; -using UnhollowerBaseLib; using UnityEngine; +#if CPP +using UnhollowerBaseLib; +#endif namespace Explorer { @@ -51,8 +53,8 @@ private IDictionary Il2CppDictionaryToMono() // note: "ValueType" is the Dictionary itself, TypeOfValues is the 'Dictionary.Values' type. // get keys and values - var keys = ValueType.GetProperty("Keys") .GetValue(Value); - var values = ValueType.GetProperty("Values").GetValue(Value); + var keys = ValueType.GetProperty("Keys") .GetValue(Value, null); + var values = ValueType.GetProperty("Values").GetValue(Value, null); // create lists to hold them var keyList = new List(); @@ -87,7 +89,7 @@ private void EnumerateWithReflection(object collection, List list) // iterate while ((bool)moveNext.Invoke(enumerator, null)) { - list.Add(current.GetValue(enumerator)); + list.Add(current.GetValue(enumerator, null)); } } @@ -152,6 +154,7 @@ private bool EnsureDictionaryIsSupported() return true; } +#if CPP try { return Check(TypeOfKeys) && Check(TypeOfValues); @@ -170,6 +173,9 @@ bool Check(Type type) { return false; } +#else + return false; +#endif } // ============= GUI Draw ============= @@ -178,7 +184,7 @@ public override void DrawValue(Rect window, float width) { if (m_cachedKeys == null || m_cachedValues == null) { - GUILayout.Label("Cached keys or values is null!", null); + GUILayout.Label("Cached keys or values is null!", new GUILayoutOption[0]); return; } @@ -220,7 +226,7 @@ public override void DrawValue(Rect window, float width) if (count > Pages.ItemsPerPage) { GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); @@ -250,13 +256,13 @@ public override void DrawValue(Rect window, float width) //collapsing the BeginHorizontal called from ReflectionWindow.WindowFunction or previous array entry GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); //GUIUnstrip.Space(whitespace); if (key == null || val == null) { - GUILayout.Label($"[{i}] (null)", null); + GUILayout.Label($"[{i}] (null)", new GUILayoutOption[0]); } else { diff --git a/src/CachedObjects/Object/CacheList.cs b/src/CachedObjects/Object/CacheList.cs index b17683c4..807d37c6 100644 --- a/src/CachedObjects/Object/CacheList.cs +++ b/src/CachedObjects/Object/CacheList.cs @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Generic; using System.Reflection; -using MelonLoader; using UnityEngine; namespace Explorer @@ -103,6 +102,7 @@ private IEnumerable EnumerateWithReflection() { if (Value == null) return null; +#if CPP if (GenericTypeDef == typeof(Il2CppSystem.Collections.Generic.List<>)) { return (IEnumerable)CppListToArrayMethod?.Invoke(Value, new object[0]); @@ -115,8 +115,12 @@ private IEnumerable EnumerateWithReflection() { return CppIListToMono(); } +#else + return Value as IEnumerable; +#endif } +#if CPP private IEnumerable CppHashSetToMono() { var set = new HashSet(); @@ -158,10 +162,11 @@ private IList CppIListToMono() } catch (Exception e) { - MelonLogger.Log("Exception converting Il2Cpp IList to Mono IList: " + e.GetType() + ", " + e.Message); + ExplorerCore.Log("Exception converting Il2Cpp IList to Mono IList: " + e.GetType() + ", " + e.Message); return null; } } +#endif private Type GetEntryType() { @@ -226,6 +231,7 @@ public override void UpdateValue() if (obj != null && ReflectionHelpers.GetActualType(obj) is Type t) { +#if CPP if (obj is Il2CppSystem.Object iObj) { try @@ -238,6 +244,7 @@ public override void UpdateValue() } catch { } } +#endif if (GetCacheObject(obj, t) is CacheObjectBase cached) { @@ -263,7 +270,7 @@ public override void DrawValue(Rect window, float width) { if (m_cachedEntries == null) { - GUILayout.Label("m_cachedEntries is null!", null); + GUILayout.Label("m_cachedEntries is null!", new GUILayoutOption[0]); return; } @@ -290,7 +297,7 @@ public override void DrawValue(Rect window, float width) GUI.skin.button.alignment = TextAnchor.MiddleLeft; string btnLabel = $"[{count}] {EntryType.FullName}"; - if (GUILayout.Button(btnLabel, new GUILayoutOption[] { GUILayout.MaxWidth(negativeWhitespace) })) + if (GUILayout.Button(btnLabel, new GUILayoutOption[] { GUILayout.Width(negativeWhitespace) })) { WindowManager.InspectObject(Value, out bool _); } @@ -305,7 +312,7 @@ public override void DrawValue(Rect window, float width) if (count > Pages.ItemsPerPage) { GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); @@ -334,13 +341,13 @@ public override void DrawValue(Rect window, float width) //collapsing the BeginHorizontal called from ReflectionWindow.WindowFunction or previous array entry GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); if (entry == null || entry.Value == null) { - GUILayout.Label($"[{i}] (null)", null); + GUILayout.Label($"[{i}] (null)", new GUILayoutOption[0]); } else { diff --git a/src/CachedObjects/Other/CacheMethod.cs b/src/CachedObjects/Other/CacheMethod.cs index ae6fb627..1eac4935 100644 --- a/src/CachedObjects/Other/CacheMethod.cs +++ b/src/CachedObjects/Other/CacheMethod.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using MelonLoader; using UnityEngine; namespace Explorer @@ -59,7 +58,7 @@ public void Evaluate() } catch (Exception e) { - MelonLogger.LogWarning($"Exception evaluating: {e.GetType()}, {e.Message}"); + ExplorerCore.LogWarning($"Exception evaluating: {e.GetType()}, {e.Message}"); ReflectionException = ReflectionHelpers.ExceptionToString(e); } @@ -94,7 +93,7 @@ private MethodInfo MakeGenericMethodFromInput() { if (!constraint.IsAssignableFrom(t)) { - MelonLogger.LogWarning($"Generic argument #{i}, '{input}' is not assignable from the constraint '{constraint}'!"); + ExplorerCore.LogWarning($"Generic argument #{i}, '{input}' is not assignable from the constraint '{constraint}'!"); return null; } } @@ -104,7 +103,7 @@ private MethodInfo MakeGenericMethodFromInput() } else { - MelonLogger.LogWarning($"Generic argument #{i}, could not get any type by the name of '{input}'!" + + ExplorerCore.LogWarning($"Generic argument #{i}, could not get any type by the name of '{input}'!" + $" Make sure you use the full name, including the NameSpace."); return null; } @@ -130,12 +129,12 @@ public override void DrawValue(Rect window, float width) } else { - GUILayout.Label($"null ({typeLabel})", null); + GUILayout.Label($"null ({typeLabel})", new GUILayoutOption[0]); } } else { - GUILayout.Label($"Not yet evaluated ({typeLabel})", null); + GUILayout.Label($"Not yet evaluated ({typeLabel})", new GUILayoutOption[0]); } } } diff --git a/src/CachedObjects/Struct/CacheColor.cs b/src/CachedObjects/Struct/CacheColor.cs index fd19836c..b8726ef4 100644 --- a/src/CachedObjects/Struct/CacheColor.cs +++ b/src/CachedObjects/Struct/CacheColor.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; using UnityEngine; namespace Explorer @@ -53,7 +52,7 @@ public override void DrawValue(Rect window, float width) //var c = (Color)Value; //GUI.color = c; - GUILayout.Label($"Color: {((Color)Value).ToString()}", null); + GUILayout.Label($"Color: {((Color)Value).ToString()}", new GUILayoutOption[0]); //GUI.color = Color.white; if (CanWrite && IsExpanded) @@ -62,32 +61,32 @@ public override void DrawValue(Rect window, float width) var whitespace = CalcWhitespace(window); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); GUILayout.Label("R:", new GUILayoutOption[] { GUILayout.Width(30) }); r = GUILayout.TextField(r, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); GUILayout.Label("G:", new GUILayoutOption[] { GUILayout.Width(30) }); g = GUILayout.TextField(g, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); GUILayout.Label("B:", new GUILayoutOption[] { GUILayout.Width(30) }); b = GUILayout.TextField(b, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); GUILayout.Label("A:", new GUILayoutOption[] { GUILayout.Width(30) }); a = GUILayout.TextField(a, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); // draw set value button - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); if (GUILayout.Button("Apply", new GUILayoutOption[] { GUILayout.Width(155) })) { @@ -95,7 +94,7 @@ public override void DrawValue(Rect window, float width) } GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); } } diff --git a/src/CachedObjects/Struct/CacheEnum.cs b/src/CachedObjects/Struct/CacheEnum.cs index 0036a770..716f55c3 100644 --- a/src/CachedObjects/Struct/CacheEnum.cs +++ b/src/CachedObjects/Struct/CacheEnum.cs @@ -2,9 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; using System.Reflection; -using MelonLoader; using UnityEngine; namespace Explorer @@ -58,7 +56,7 @@ public override void DrawValue(Rect window, float width) } } - GUILayout.Label(Value.ToString() + " (" + ValueType + ")", null); + GUILayout.Label(Value.ToString() + " (" + ValueType + ")", new GUILayoutOption[0]); } public void SetEnum(int change) diff --git a/src/CachedObjects/Struct/CacheEnumFlags.cs b/src/CachedObjects/Struct/CacheEnumFlags.cs index c9e7fe25..fdd107e4 100644 --- a/src/CachedObjects/Struct/CacheEnumFlags.cs +++ b/src/CachedObjects/Struct/CacheEnumFlags.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; -using MelonLoader; using UnityEngine; namespace Explorer @@ -69,7 +67,7 @@ public override void UpdateValue() } catch (Exception e) { - MelonLogger.Log(e.ToString()); + ExplorerCore.Log(e.ToString()); } } @@ -94,7 +92,7 @@ public override void DrawValue(Rect window, float width) } } - GUILayout.Label(Value.ToString() + " (" + ValueType + ")", null); + GUILayout.Label(Value.ToString() + " (" + ValueType + ")", new GUILayoutOption[0]); if (IsExpanded) { @@ -104,15 +102,15 @@ public override void DrawValue(Rect window, float width) for (int i = 0; i < EnumNames.Length; i++) { - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); - m_enabledFlags[i] = GUILayout.Toggle(m_enabledFlags[i], EnumNames[i], null); + m_enabledFlags[i] = GUILayout.Toggle(m_enabledFlags[i], EnumNames[i], new GUILayoutOption[0]); GUILayout.EndHorizontal(); } - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); if (GUILayout.Button("Apply", new GUILayoutOption[] { GUILayout.Width(155) })) { @@ -120,7 +118,7 @@ public override void DrawValue(Rect window, float width) } GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); } } } diff --git a/src/CachedObjects/Struct/CachePrimitive.cs b/src/CachedObjects/Struct/CachePrimitive.cs index ded5257f..898226b8 100644 --- a/src/CachedObjects/Struct/CachePrimitive.cs +++ b/src/CachedObjects/Struct/CachePrimitive.cs @@ -2,8 +2,9 @@ using System.Collections; using System.Collections.Generic; using System.Reflection; -using MelonLoader; +#if CPP using UnhollowerRuntimeLib; +#endif using UnityEngine; namespace Explorer @@ -77,7 +78,7 @@ public override void DrawValue(Rect window, float width) if (CanWrite) { - b = GUILayout.Toggle(b, label, null); + b = GUILayout.Toggle(b, label, new GUILayoutOption[0]); if (b != (bool)Value) { SetValueFromInput(b.ToString()); @@ -85,7 +86,7 @@ public override void DrawValue(Rect window, float width) } else { - GUILayout.Label(label, null); + GUILayout.Label(label, new GUILayoutOption[0]); } return; @@ -93,9 +94,9 @@ public override void DrawValue(Rect window, float width) // all other non-bool values use TextField - GUILayout.BeginVertical(null); + GUILayout.BeginVertical(new GUILayoutOption[0]); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); // using ValueType.Name instead of ValueTypeName, because we only want the short name. GUILayout.Label("" + ValueType.Name + "", new GUILayoutOption[] { GUILayout.Width(50) }); @@ -106,11 +107,11 @@ public override void DrawValue(Rect window, float width) if (dynSize > maxwidth) { - m_valueToString = GUILayout.TextArea(m_valueToString, new GUILayoutOption[] { GUILayout.MaxWidth(maxwidth) }); + m_valueToString = GUIUnstrip.TextArea(m_valueToString, new GUILayoutOption[] { GUILayout.Width(maxwidth) }); } else { - m_valueToString = GUILayout.TextField(m_valueToString, new GUILayoutOption[] { GUILayout.MaxWidth(dynSize) }); + m_valueToString = GUILayout.TextField(m_valueToString, new GUILayoutOption[] { GUILayout.Width(dynSize) }); } if (CanWrite) @@ -125,7 +126,7 @@ public override void DrawValue(Rect window, float width) if (m_canBitwiseOperate) { bool orig = m_inBitwiseMode; - m_inBitwiseMode = GUILayout.Toggle(m_inBitwiseMode, "Bitwise?", null); + m_inBitwiseMode = GUILayout.Toggle(m_inBitwiseMode, "Bitwise?", new GUILayoutOption[0]); if (orig != m_inBitwiseMode) { RefreshToString(); @@ -140,7 +141,7 @@ public override void DrawValue(Rect window, float width) { if (CanWrite) { - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUI.skin.label.alignment = TextAnchor.MiddleRight; GUILayout.Label("RHS:", new GUILayoutOption[] { GUILayout.Width(35) }); @@ -201,9 +202,9 @@ public override void DrawValue(Rect window, float width) GUILayout.EndHorizontal(); } - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label($"Binary:", new GUILayoutOption[] { GUILayout.Width(60) }); - GUILayout.TextField(m_bitwiseToString, null); + GUILayout.TextField(m_bitwiseToString, new GUILayoutOption[0]); GUILayout.EndHorizontal(); } @@ -214,7 +215,7 @@ public void SetValueFromInput(string valueString) { if (MemInfo == null) { - MelonLogger.Log("Trying to SetValue but the MemberInfo is null!"); + ExplorerCore.Log("Trying to SetValue but the MemberInfo is null!"); return; } @@ -240,7 +241,7 @@ public void SetValueFromInput(string valueString) } catch (Exception e) { - MelonLogger.Log("Exception parsing value: " + e.GetType() + ", " + e.Message); + ExplorerCore.Log("Exception parsing value: " + e.GetType() + ", " + e.Message); } } diff --git a/src/CachedObjects/Struct/CacheQuaternion.cs b/src/CachedObjects/Struct/CacheQuaternion.cs index 59057871..0a132bd3 100644 --- a/src/CachedObjects/Struct/CacheQuaternion.cs +++ b/src/CachedObjects/Struct/CacheQuaternion.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; using UnityEngine; namespace Explorer @@ -49,7 +48,7 @@ public override void DrawValue(Rect window, float width) } } - GUILayout.Label($"Quaternion: {((Quaternion)Value).eulerAngles.ToString()}", null); + GUILayout.Label($"Quaternion: {((Quaternion)Value).eulerAngles.ToString()}", new GUILayoutOption[0]); if (CanWrite && IsExpanded) { @@ -57,26 +56,26 @@ public override void DrawValue(Rect window, float width) var whitespace = CalcWhitespace(window); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); GUILayout.Label("X:", new GUILayoutOption[] { GUILayout.Width(30) }); x = GUILayout.TextField(x, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); GUILayout.Label("Y:", new GUILayoutOption[] { GUILayout.Width(30) }); y = GUILayout.TextField(y, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); GUILayout.Label("Z:", new GUILayoutOption[] { GUILayout.Width(30) }); z = GUILayout.TextField(z, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); // draw set value button - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); if (GUILayout.Button("Apply", new GUILayoutOption[] { GUILayout.Width(155) })) { @@ -84,7 +83,7 @@ public override void DrawValue(Rect window, float width) } GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); } } diff --git a/src/CachedObjects/Struct/CacheRect.cs b/src/CachedObjects/Struct/CacheRect.cs index 857ffef2..0df036ec 100644 --- a/src/CachedObjects/Struct/CacheRect.cs +++ b/src/CachedObjects/Struct/CacheRect.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; using UnityEngine; namespace Explorer @@ -51,7 +50,7 @@ public override void DrawValue(Rect window, float width) } } - GUILayout.Label($"Rect: {((Rect)Value).ToString()}", null); + GUILayout.Label($"Rect: {((Rect)Value).ToString()}", new GUILayoutOption[0]); if (CanWrite && IsExpanded) { @@ -59,32 +58,32 @@ public override void DrawValue(Rect window, float width) var whitespace = CalcWhitespace(window); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); GUILayout.Label("X:", new GUILayoutOption[] { GUILayout.Width(30) }); x = GUILayout.TextField(x, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); GUILayout.Label("Y:", new GUILayoutOption[] { GUILayout.Width(30) }); y = GUILayout.TextField(y, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); GUILayout.Label("W:", new GUILayoutOption[] { GUILayout.Width(30) }); w = GUILayout.TextField(w, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); GUILayout.Label("H:", new GUILayoutOption[] { GUILayout.Width(30) }); h = GUILayout.TextField(h, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); // draw set value button - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); if (GUILayout.Button("Apply", new GUILayoutOption[] { GUILayout.Width(155) })) { @@ -92,7 +91,7 @@ public override void DrawValue(Rect window, float width) } GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); } } diff --git a/src/CachedObjects/Struct/CacheVector.cs b/src/CachedObjects/Struct/CacheVector.cs index 6bf01a6f..8056ec87 100644 --- a/src/CachedObjects/Struct/CacheVector.cs +++ b/src/CachedObjects/Struct/CacheVector.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; using System.Reflection; using UnityEngine; @@ -90,7 +89,7 @@ public override void DrawValue(Rect window, float width) } } - GUILayout.Label($"Vector{VectorSize}: {(string)m_toStringMethod.Invoke(Value, new object[0])}", null); + GUILayout.Label($"Vector{VectorSize}: {(string)m_toStringMethod.Invoke(Value, new object[0])}", new GUILayoutOption[0]); if (CanWrite && IsExpanded) { @@ -99,13 +98,13 @@ public override void DrawValue(Rect window, float width) var whitespace = CalcWhitespace(window); // always draw x and y - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); GUILayout.Label("X:", new GUILayoutOption[] { GUILayout.Width(30) }); x = GUILayout.TextField(x, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); GUILayout.Label("Y:", new GUILayoutOption[] { GUILayout.Width(30) }); y = GUILayout.TextField(y, new GUILayoutOption[] { GUILayout.Width(120) }); @@ -114,7 +113,7 @@ public override void DrawValue(Rect window, float width) if (VectorSize > 2) { // draw z - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); GUILayout.Label("Z:", new GUILayoutOption[] { GUILayout.Width(30) }); z = GUILayout.TextField(z, new GUILayoutOption[] { GUILayout.Width(120) }); @@ -123,7 +122,7 @@ public override void DrawValue(Rect window, float width) if (VectorSize > 3) { // draw w - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); GUILayout.Label("W:", new GUILayoutOption[] { GUILayout.Width(30) }); w = GUILayout.TextField(w, new GUILayoutOption[] { GUILayout.Width(120) }); @@ -131,7 +130,7 @@ public override void DrawValue(Rect window, float width) } // draw set value button - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUIUnstrip.Space(whitespace); if (GUILayout.Button("Apply", new GUILayoutOption[] { GUILayout.Width(155) })) { @@ -139,7 +138,7 @@ public override void DrawValue(Rect window, float width) } GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); } } diff --git a/src/Config/ModConfig.cs b/src/Config/ModConfig.cs index 3ac29b72..21332478 100644 --- a/src/Config/ModConfig.cs +++ b/src/Config/ModConfig.cs @@ -8,7 +8,7 @@ public class ModConfig { [XmlIgnore] public static readonly XmlSerializer Serializer = new XmlSerializer(typeof(ModConfig)); - [XmlIgnore] private const string EXPLORER_FOLDER = @"Mods\CppExplorer"; + [XmlIgnore] private const string EXPLORER_FOLDER = @"Mods\Explorer"; [XmlIgnore] private const string SETTINGS_PATH = EXPLORER_FOLDER + @"\config.xml"; [XmlIgnore] public static ModConfig Instance; diff --git a/src/CppExplorer.csproj b/src/CppExplorer.csproj deleted file mode 100644 index 892c8e2d..00000000 --- a/src/CppExplorer.csproj +++ /dev/null @@ -1,128 +0,0 @@ - - - - - Debug - AnyCPU - {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D} - Library - Properties - Explorer - v4.7.2 - 512 - true - - CppExplorer - false - none - false - ..\Release\ - - prompt - 4 - x64 - false - - - - - ..\..\..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\Il2Cppmscorlib.dll - False - - - ..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\Il2CppSystem.Core.dll - False - - - ..\lib\mcs.dll - True - - - ..\..\..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\MelonLoader.ModHandler.dll - False - - - - - - - - - ..\..\..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnhollowerBaseLib.dll - False - - - ..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnityEngine.dll - False - - - ..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnityEngine.CoreModule.dll - False - - - ..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnityEngine.IMGUIModule.dll - False - - - ..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnityEngine.PhysicsModule.dll - False - - - ..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnityEngine.TextRenderingModule.dll - False - - - ..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnityEngine.UI.dll - False - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/CppExplorer.sln b/src/CppExplorer.sln deleted file mode 100644 index 67f89eff..00000000 --- a/src/CppExplorer.sln +++ /dev/null @@ -1,22 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30128.74 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CppExplorer", "CppExplorer.csproj", "{B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release|Any CPU.ActiveCfg = Debug|Any CPU - {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release|Any CPU.Build.0 = Debug|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {DD5C0A5D-03F1-4CC3-8B4D-E10834908C5A} - EndGlobalSection -EndGlobal diff --git a/src/Explorer.csproj b/src/Explorer.csproj new file mode 100644 index 00000000..294d43bf --- /dev/null +++ b/src/Explorer.csproj @@ -0,0 +1,301 @@ + + + + + Debug + AnyCPU + {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D} + Library + v4.7.2 + Properties + Explorer + 512 + true + + Explorer + true + true + false + + D:\Steam\steamapps\common\Hellpoint + + + D:\Steam\steamapps\common\Outward + + + D:\Steam\steamapps\common\Outward - Il2Cpp + + + D:\Steam\steamapps\common\Outward + + + + v4.7.2 + false + none + false + ..\Release\ML_Cpp\ + CPP,ML + prompt + 4 + x64 + false + true + true + false + + + v4.7.2 + false + none + false + ..\Release\ML_Mono\ + MONO,ML + prompt + 4 + x64 + false + false + true + false + + + v3.5 + false + none + false + ..\Release\ML_Mono_NET35\ + MONO,ML,NET35 + prompt + 4 + x64 + false + false + true + true + + + v4.7.2 + false + none + false + ..\Release\BIE_Cpp\ + CPP,BIE + prompt + 4 + x64 + false + true + false + false + + + v4.7.2 + false + none + false + ..\Release\BIE_Mono\ + MONO,BIE + prompt + 4 + x64 + false + false + false + false + + + v3.5 + false + none + false + ..\Release\BIE_Mono_NET35\ + MONO,BIE,NET35 + prompt + 4 + x64 + false + false + false + true + + + + + + + + + + + ..\lib\mcs.dll + True + + + ..\lib\mcs.NET35.dll + True + + + + $(MLCppGameFolder)\MelonLoader\MelonLoader.ModHandler.dll + False + + + + $(MLMonoGameFolder)\MelonLoader\MelonLoader.ModHandler.dll + False + + + + $(BIEMonoGameFolder)\BepInEx\core\BepInEx.dll + False + + + $(BIEMonoGameFolder)\BepInEx\core\0Harmony.dll + False + + + + $(BIECppGameFolder)\BepInEx\core\BepInEx.Core.dll + False + + + $(BIECppGameFolder)\BepInEx\core\0Harmony.dll + False + + + $(BIECppGameFolder)\BepInEx\core\BepInEx.IL2CPP.dll + False + + + + ..\lib\UnityEngine.dll + False + + + + $(MLCppGameFolder)\MelonLoader\Managed\UnhollowerBaseLib.dll + False + + + $(MLCppGameFolder)\MelonLoader\Managed\Il2Cppmscorlib.dll + False + + + $(MLCppGameFolder)\MelonLoader\Managed\Il2CppSystem.Core.dll + False + + + $(MLCppGameFolder)\MelonLoader\Managed\UnityEngine.dll + False + + + $(MLCppGameFolder)\MelonLoader\Managed\UnityEngine.CoreModule.dll + False + + + $(MLCppGameFolder)\MelonLoader\Managed\UnityEngine.IMGUIModule.dll + False + + + $(MLCppGameFolder)\MelonLoader\Managed\UnityEngine.PhysicsModule.dll + False + + + $(MLCppGameFolder)\MelonLoader\Managed\UnityEngine.TextRenderingModule.dll + False + + + $(MLCppGameFolder)\MelonLoader\Managed\UnityEngine.UI.dll + False + + + + $(BIECppGameFolder)\BepInEx\core\UnhollowerBaseLib.dll + False + + + $(BIECppGameFolder)\BepInEx\unhollowed\Il2Cppmscorlib.dll + False + + + $(BIECppGameFolder)\BepInEx\unhollowed\Il2CppSystem.Core.dll + False + + + $(BIECppGameFolder)\BepInEx\unhollowed\UnityEngine.dll + False + + + $(BIECppGameFolder)\BepInEx\unhollowed\UnityEngine.CoreModule.dll + False + + + $(BIECppGameFolder)\BepInEx\unhollowed\UnityEngine.IMGUIModule.dll + False + + + $(BIECppGameFolder)\BepInEx\unhollowed\UnityEngine.PhysicsModule.dll + False + + + $(BIECppGameFolder)\BepInEx\unhollowed\UnityEngine.TextRenderingModule.dll + False + + + $(BIECppGameFolder)\BepInEx\unhollowed\UnityEngine.UI.dll + False + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Explorer.sln b/src/Explorer.sln new file mode 100644 index 00000000..a5c30cc7 --- /dev/null +++ b/src/Explorer.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30128.74 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Explorer", "Explorer.csproj", "{B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Release_BIE_Cpp|Any CPU = Release_BIE_Cpp|Any CPU + Release_BIE_Mono_NET35|Any CPU = Release_BIE_Mono_NET35|Any CPU + Release_BIE_Mono|Any CPU = Release_BIE_Mono|Any CPU + Release_ML_Cpp|Any CPU = Release_ML_Cpp|Any CPU + Release_ML_Mono_NET35|Any CPU = Release_ML_Mono_NET35|Any CPU + Release_ML_Mono|Any CPU = Release_ML_Mono|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release_BIE_Cpp|Any CPU.ActiveCfg = Release_BIE_Cpp|Any CPU + {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release_BIE_Cpp|Any CPU.Build.0 = Release_BIE_Cpp|Any CPU + {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release_BIE_Mono_NET35|Any CPU.ActiveCfg = Release_BIE_Mono_NET35|Any CPU + {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release_BIE_Mono_NET35|Any CPU.Build.0 = Release_BIE_Mono_NET35|Any CPU + {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release_BIE_Mono|Any CPU.ActiveCfg = Release_BIE_Mono|Any CPU + {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release_BIE_Mono|Any CPU.Build.0 = Release_BIE_Mono|Any CPU + {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release_ML_Cpp|Any CPU.ActiveCfg = Release_ML_Cpp|Any CPU + {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release_ML_Cpp|Any CPU.Build.0 = Release_ML_Cpp|Any CPU + {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release_ML_Mono_NET35|Any CPU.ActiveCfg = Release_ML_Mono_NET35|Any CPU + {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release_ML_Mono_NET35|Any CPU.Build.0 = Release_ML_Mono_NET35|Any CPU + {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release_ML_Mono|Any CPU.ActiveCfg = Release_ML_Mono|Any CPU + {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release_ML_Mono|Any CPU.Build.0 = Release_ML_Mono|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DD5C0A5D-03F1-4CC3-8B4D-E10834908C5A} + EndGlobalSection +EndGlobal diff --git a/src/CppExplorer.cs b/src/ExplorerCore.cs similarity index 50% rename from src/CppExplorer.cs rename to src/ExplorerCore.cs index 19b90e9b..b6ab8d8b 100644 --- a/src/CppExplorer.cs +++ b/src/ExplorerCore.cs @@ -1,31 +1,30 @@ -using MelonLoader; -using UnityEngine; +using UnityEngine; namespace Explorer { - public class CppExplorer : MelonMod + public class ExplorerCore { - public const string NAME = "CppExplorer"; - public const string VERSION = "1.7.5"; + public const string NAME = +#if ML +#if CPP + "Explorer (Il2Cpp, MelonLoader)"; +#else + "Explorer (Mono, MelonLoader)"; +#endif +#else +#if CPP + "Explorer (Il2Cpp, BepInEx)"; +#else + "Explorer (Mono, BepInEx)"; +#endif +#endif + public const string VERSION = "1.8.0"; public const string AUTHOR = "Sinai"; - public const string GUID = "com.sinai.cppexplorer"; + public const string GUID = "com.sinai.explorer"; - public static CppExplorer Instance { get; private set; } + public static ExplorerCore Instance { get; private set; } - public static bool ShowMenu - { - get => m_showMenu; - set => SetShowMenu(value); - } - public static bool m_showMenu; - - private static void SetShowMenu(bool show) - { - m_showMenu = show; - CursorControl.UpdateCursorControl(); - } - - public override void OnApplicationStart() + public ExplorerCore() { Instance = this; @@ -38,16 +37,23 @@ public override void OnApplicationStart() CursorControl.Init(); - MelonLogger.Log($"CppExplorer {VERSION} initialized."); + Log($"{NAME} {VERSION} initialized."); } - public override void OnLevelWasLoaded(int level) + public static bool ShowMenu { - ScenePage.Instance?.OnSceneChange(); - SearchPage.Instance?.OnSceneChange(); + get => m_showMenu; + set => SetShowMenu(value); } + public static bool m_showMenu; - public override void OnUpdate() + private static void SetShowMenu(bool show) + { + m_showMenu = show; + CursorControl.UpdateCursorControl(); + } + + public static void Update() { if (InputHelper.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle)) { @@ -64,7 +70,7 @@ public override void OnUpdate() } } - public override void OnGUI() + public static void OnGUI() { if (!ShowMenu) return; @@ -77,5 +83,38 @@ public override void OnGUI() GUI.skin = origSkin; } + + public static void OnSceneChange() + { + ScenePage.Instance?.OnSceneChange(); + SearchPage.Instance?.OnSceneChange(); + } + + public static void Log(string message) + { +#if ML + MelonLoader.MelonLogger.Log(message); +#else + Explorer_BepInPlugin.Logging?.LogMessage(message); +#endif + } + + public static void LogWarning(string message) + { +#if ML + MelonLoader.MelonLogger.LogWarning(message); +#else + Explorer_BepInPlugin.Logging?.LogWarning(message); +#endif + } + + public static void LogError(string message) + { +#if ML + MelonLoader.MelonLogger.LogError(message); +#else + Explorer_BepInPlugin.Logging?.LogError(message); +#endif + } } } diff --git a/src/Explorer_BepInPlugin.cs b/src/Explorer_BepInPlugin.cs new file mode 100644 index 00000000..0d417c5c --- /dev/null +++ b/src/Explorer_BepInPlugin.cs @@ -0,0 +1,141 @@ +#if BIE +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Reflection; +using System.IO; +using BepInEx; +using BepInEx.Logging; +using HarmonyLib; +using Mono.CSharp; +using UnityEngine.SceneManagement; +using UnityEngine.Events; +using UnityEngine; +#if CPP +using UnhollowerRuntimeLib; +using BepInEx.IL2CPP; +#endif + +namespace Explorer +{ + [BepInPlugin(ExplorerCore.GUID, ExplorerCore.NAME, ExplorerCore.VERSION)] +#if CPP + public class Explorer_BepInPlugin : BasePlugin +#else + public class Explorer_BepInPlugin : BaseUnityPlugin +#endif + { + public static Explorer_BepInPlugin Instance; + public static ManualLogSource Logging => +#if CPP + Instance.Log; +#else + Instance?.Logger; +#endif + + public static readonly Harmony HarmonyInstance = new Harmony(ExplorerCore.GUID); + +#if CPP + // temporary for BIE Il2Cpp + private static bool tempSceneChangeCheck; + private static string lastSceneName; +#endif + + // Init +#if CPP + public override void Load() + { +#else + internal void Awake() + { +#endif + Instance = this; + +#if CPP + tempSceneChangeCheck = true; + ClassInjector.RegisterTypeInIl2Cpp(); + + GameObject.DontDestroyOnLoad( + new GameObject( + "Explorer_Dummy", + new Il2CppSystem.Type[] + { + Il2CppType.Of() + }) + ); +#else + SceneManager.activeSceneChanged += DoSceneChange; +#endif + + LoadMCS(); + + new ExplorerCore(); + + HarmonyInstance.PatchAll(); + } + + void LoadMCS() + { +#if NET35 + var path = @"BepInEx\plugins\mcs.NET35.dll"; +#else + var path = @"BepInEx\plugins\mcs.dll"; +#endif + Assembly.Load(File.ReadAllBytes(path)); + ExplorerCore.Log("Loaded mcs!"); + } + + internal static void DoSceneChange(Scene arg0, Scene arg1) + { + ExplorerCore.OnSceneChange(); + } + + internal static void DoUpdate() + { + ExplorerCore.Update(); + +#if CPP + if (tempSceneChangeCheck) + { + var scene = SceneManager.GetActiveScene(); + if (scene.name != lastSceneName) + { + lastSceneName = scene.name; + DoSceneChange(scene, scene); + } + } +#endif + } + + internal static void DoOnGUI() + { + ExplorerCore.OnGUI(); + } + +#if CPP + public class DummyMB : MonoBehaviour + { + public DummyMB(IntPtr ptr) : base(ptr) { } + + internal void Awake() + { + Logging.LogMessage("DummyMB Awake"); + } + +#endif + internal void Update() + { + DoUpdate(); + } + + internal void OnGUI() + { + DoOnGUI(); + } +#if CPP + } +#endif + } +} +#endif diff --git a/src/Explorer_MelonMod.cs b/src/Explorer_MelonMod.cs new file mode 100644 index 00000000..d3ba4464 --- /dev/null +++ b/src/Explorer_MelonMod.cs @@ -0,0 +1,37 @@ +#if ML +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using MelonLoader; + +namespace Explorer +{ + public class Explorer_MelonMod : MelonMod + { + public static Explorer_MelonMod Instance; + + public override void OnApplicationStart() + { + Instance = this; + + new ExplorerCore(); + } + + public override void OnLevelWasLoaded(int level) + { + ExplorerCore.OnSceneChange(); + } + + public override void OnUpdate() + { + ExplorerCore.Update(); + } + + public override void OnGUI() + { + ExplorerCore.OnGUI(); + } + } +} +#endif \ No newline at end of file diff --git a/src/Extensions/ReflectionExtensions.cs b/src/Extensions/ReflectionExtensions.cs index 9eb43e54..09d98551 100644 --- a/src/Extensions/ReflectionExtensions.cs +++ b/src/Extensions/ReflectionExtensions.cs @@ -7,6 +7,7 @@ namespace Explorer { public static class ReflectionExtensions { +#if CPP /// /// Extension to allow for easy, non-generic Il2Cpp casting. /// The extension is on System.Object, but only Il2Cpp objects would be a valid target. @@ -15,6 +16,7 @@ public static object Il2CppCast(this object obj, Type castTo) { return ReflectionHelpers.Il2CppCast(obj, castTo); } +#endif /// /// Extension to safely try to get all Types from an Assembly, with a fallback for ReflectionTypeLoadException. diff --git a/src/Helpers/InputHelper.cs b/src/Helpers/InputHelper.cs index e1e16913..28389d5b 100644 --- a/src/Helpers/InputHelper.cs +++ b/src/Helpers/InputHelper.cs @@ -1,6 +1,5 @@ using System; using System.Reflection; -using MelonLoader; using UnityEngine; namespace Explorer @@ -48,7 +47,7 @@ public static Vector3 mousePosition get { if (NO_INPUT) return Vector3.zero; - return (Vector3)_mousePosition.GetValue(null); + return (Vector3)_mousePosition.GetValue(null, null); } } #pragma warning restore IDE1006 @@ -81,17 +80,17 @@ public static bool GetMouseButton(int btn) private static bool TryManuallyLoadInput() { - MelonLogger.Log("UnityEngine.Input is null, trying to load manually...."); + ExplorerCore.Log("UnityEngine.Input is null, trying to load manually...."); if ((ReflectionHelpers.LoadModule("UnityEngine.InputLegacyModule.dll") || ReflectionHelpers.LoadModule("UnityEngine.CoreModule.dll")) && Input != null) { - MelonLogger.Log("Ok!"); + ExplorerCore.Log("Ok!"); return true; } else { - MelonLogger.Log("Could not load Input module!"); + ExplorerCore.Log("Could not load Input module!"); return false; } } diff --git a/src/Helpers/ReflectionHelpers.cs b/src/Helpers/ReflectionHelpers.cs index 403ed0ca..65a70d0e 100644 --- a/src/Helpers/ReflectionHelpers.cs +++ b/src/Helpers/ReflectionHelpers.cs @@ -3,12 +3,14 @@ using System.Collections.Generic; using System.IO; using System.Reflection; -using MelonLoader; -using UnhollowerBaseLib; -using UnhollowerRuntimeLib; using UnityEngine; using BF = System.Reflection.BindingFlags; + +#if CPP using ILType = Il2CppSystem.Type; +using UnhollowerBaseLib; +using UnhollowerRuntimeLib; +#endif namespace Explorer { @@ -16,11 +18,12 @@ public class ReflectionHelpers { public static BF CommonFlags = BF.Public | BF.Instance | BF.NonPublic | BF.Static; - public static ILType GameObjectType => Il2CppType.Of(); - public static ILType TransformType => Il2CppType.Of(); - public static ILType ObjectType => Il2CppType.Of(); - public static ILType ComponentType => Il2CppType.Of(); - public static ILType BehaviourType => Il2CppType.Of(); +#if CPP + public static ILType GameObjectType => Il2CppType.Of(); + public static ILType TransformType => Il2CppType.Of(); + public static ILType ObjectType => Il2CppType.Of(); + public static ILType ComponentType => Il2CppType.Of(); + public static ILType BehaviourType => Il2CppType.Of(); private static readonly MethodInfo tryCastMethodInfo = typeof(Il2CppObjectBase).GetMethod("TryCast"); private static readonly Dictionary cachedTryCastMethods = new Dictionary(); @@ -36,15 +39,22 @@ public static object Il2CppCast(object obj, Type castTo) return cachedTryCastMethods[castTo].Invoke(obj, null); } +#else + public static Type GameObjectType => typeof(GameObject); + public static Type TransformType => typeof(Transform); + public static Type ObjectType => typeof(UnityEngine.Object); + public static Type ComponentType => typeof(Component); + public static Type BehaviourType => typeof(Behaviour); +#endif public static bool IsEnumerable(Type t) { - return typeof(IEnumerable).IsAssignableFrom(t) || IsCppEnumerable(t); - } + if (typeof(IEnumerable).IsAssignableFrom(t)) + { + return true; + } - // Checks for Il2Cpp List or HashSet. - public static bool IsCppEnumerable(Type t) - { +#if CPP if (t.IsGenericType && t.GetGenericTypeDefinition() is Type g) { return typeof(Il2CppSystem.Collections.Generic.List<>).IsAssignableFrom(g) @@ -55,6 +65,9 @@ public static bool IsCppEnumerable(Type t) { return typeof(Il2CppSystem.Collections.IList).IsAssignableFrom(t); } +#else + return false; +#endif } public static bool IsDictionary(Type t) @@ -64,6 +77,7 @@ public static bool IsDictionary(Type t) return true; } +#if CPP if (t.IsGenericType && t.GetGenericTypeDefinition() is Type g) { return typeof(Il2CppSystem.Collections.Generic.Dictionary<,>).IsAssignableFrom(g) @@ -74,6 +88,9 @@ public static bool IsDictionary(Type t) return typeof(Il2CppSystem.Collections.IDictionary).IsAssignableFrom(t) || typeof(Il2CppSystem.Collections.Hashtable).IsAssignableFrom(t); } +#else + return false; +#endif } public static Type GetTypeByName(string fullName) @@ -96,6 +113,7 @@ public static Type GetActualType(object obj) { if (obj == null) return null; +#if CPP // Need to use GetIl2CppType for Il2CppSystem Objects if (obj is Il2CppSystem.Object ilObject) { @@ -107,6 +125,7 @@ public static Type GetActualType(object obj) return Type.GetType(ilObject.GetIl2CppType().AssemblyQualifiedName) ?? obj.GetType(); } +#endif // It's a normal object, this is fine return obj.GetType(); @@ -139,13 +158,14 @@ public static bool LoadModule(string module) } catch (Exception e) { - MelonLogger.Log(e.GetType() + ", " + e.Message); + ExplorerCore.Log(e.GetType() + ", " + e.Message); return false; } } public static string ExceptionToString(Exception e) { +#if CPP if (IsFailedGeneric(e)) { return "Unable to initialize this type."; @@ -154,10 +174,12 @@ public static string ExceptionToString(Exception e) { return "Garbage collected in Il2Cpp."; } +#endif return e.GetType() + ", " + e.Message; } +#if CPP public static bool IsFailedGeneric(Exception e) { return IsExceptionOfType(e, typeof(TargetInvocationException)) && IsExceptionOfType(e, typeof(TypeLoadException)); @@ -184,5 +206,6 @@ public static bool IsExceptionOfType(Exception e, Type t, bool strict = true, bo else return false; } +#endif } } diff --git a/src/Menu/CursorControl.cs b/src/Menu/CursorControl.cs index 4a663ceb..9cbc1af7 100644 --- a/src/Menu/CursorControl.cs +++ b/src/Menu/CursorControl.cs @@ -1,7 +1,10 @@ using System; -using Harmony; -using MelonLoader; using UnityEngine; +#if ML +using Harmony; +#else +using HarmonyLib; +#endif namespace Explorer { @@ -17,7 +20,7 @@ public static bool ForceUnlockMouse private static bool m_lastVisibleState; private static bool m_currentlySettingCursor = false; - public static bool ShouldForceMouse => CppExplorer.ShowMenu && ForceUnlockMouse; + public static bool ShouldForceMouse => ExplorerCore.ShowMenu && ForceUnlockMouse; private static Type CursorType => m_cursorType ?? (m_cursorType = ReflectionHelpers.GetTypeByName("UnityEngine.Cursor")); private static Type m_cursorType; @@ -29,11 +32,11 @@ public static void Init() // Check if Cursor class is loaded if (CursorType == null) { - MelonLogger.Log("Trying to manually load Cursor module..."); + ExplorerCore.Log("Trying to manually load Cursor module..."); if (ReflectionHelpers.LoadModule("UnityEngine.CoreModule") && CursorType != null) { - MelonLogger.Log("Ok!"); + ExplorerCore.Log("Ok!"); } else { @@ -54,12 +57,12 @@ public static void Init() } catch (Exception e) { - MelonLogger.Log($"Exception on CursorControl.Init! {e.GetType()}, {e.Message}"); + ExplorerCore.Log($"Exception on CursorControl.Init! {e.GetType()}, {e.Message}"); } // Enable ShowMenu and ForceUnlockMouse // (set m_showMenu directly to not call UpdateCursorState twice) - CppExplorer.m_showMenu = true; + ExplorerCore.m_showMenu = true; ForceUnlockMouse = true; } @@ -67,7 +70,16 @@ private static void TryPatch(string property, HarmonyMethod patch, bool setter) { try { - var harmony = CppExplorer.Instance.harmonyInstance; + // var harmony = ExplorerCore.Instance.harmonyInstance; + + var harmony = +#if ML + Explorer_MelonMod.Instance.harmonyInstance; +#else + Explorer_BepInPlugin.HarmonyInstance; +#endif + ; + var prop = typeof(Cursor).GetProperty(property); if (setter) @@ -83,7 +95,7 @@ private static void TryPatch(string property, HarmonyMethod patch, bool setter) } catch (Exception e) { - MelonLogger.Log($"[NON-FATAL] Couldn't patch a method: {e.Message}"); + ExplorerCore.Log($"[NON-FATAL] Couldn't patch a method: {e.Message}"); } } @@ -121,7 +133,7 @@ public static void UpdateCursorControl() } catch (Exception e) { - MelonLogger.Log($"Exception setting Cursor state: {e.GetType()}, {e.Message}"); + ExplorerCore.Log($"Exception setting Cursor state: {e.GetType()}, {e.Message}"); } } diff --git a/src/Menu/InspectUnderMouse.cs b/src/Menu/InspectUnderMouse.cs index dcf22cb9..777b1bb6 100644 --- a/src/Menu/InspectUnderMouse.cs +++ b/src/Menu/InspectUnderMouse.cs @@ -10,7 +10,7 @@ public class InspectUnderMouse public static void Update() { - if (CppExplorer.ShowMenu) + if (ExplorerCore.ShowMenu) { if (InputHelper.GetKey(KeyCode.LeftShift) && InputHelper.GetMouseButtonDown(1)) { diff --git a/src/Menu/MainMenu/MainMenu.cs b/src/Menu/MainMenu/MainMenu.cs index f57865e9..93e3c941 100644 --- a/src/Menu/MainMenu/MainMenu.cs +++ b/src/Menu/MainMenu/MainMenu.cs @@ -3,7 +3,6 @@ using System.Linq; using System.Text; using UnityEngine; -using MelonLoader; namespace Explorer { @@ -36,11 +35,11 @@ public static void SetCurrentPage(int index) { if (index < 0 || Pages.Count <= index) { - MelonLogger.Log("cannot set page " + index); + ExplorerCore.Log("cannot set page " + index); return; } m_currentPage = index; - GUI.BringWindowToFront(MainWindowID); + GUIUnstrip.BringWindowToFront(MainWindowID); GUI.FocusWindow(MainWindowID); } @@ -51,16 +50,16 @@ public void Update() public void OnGUI() { - MainRect = GUI.Window(MainWindowID, MainRect, (GUI.WindowFunction)MainWindow, CppExplorer.NAME); + MainRect = GUIUnstrip.Window(MainWindowID, MainRect, (GUI.WindowFunction)MainWindow, ExplorerCore.NAME); } private void MainWindow(int id) { GUI.DragWindow(new Rect(0, 0, MainRect.width - 90, 20)); - if (GUI.Button(new Rect(MainRect.width - 90, 2, 80, 20), $"Hide ({ModConfig.Instance.Main_Menu_Toggle})")) + if (GUIUnstrip.Button(new Rect(MainRect.width - 90, 2, 80, 20), $"Hide ({ModConfig.Instance.Main_Menu_Toggle})")) { - CppExplorer.ShowMenu = false; + ExplorerCore.ShowMenu = false; return; } @@ -83,7 +82,7 @@ private void MainWindow(int id) private void MainHeader() { - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); for (int i = 0; i < Pages.Count; i++) { if (m_currentPage == i) @@ -91,22 +90,22 @@ private void MainHeader() else GUI.color = Color.white; - if (GUILayout.Button(Pages[i].Name, null)) + if (GUILayout.Button(Pages[i].Name, new GUILayoutOption[0])) { m_currentPage = i; } } GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUI.color = Color.white; - InspectUnderMouse.EnableInspect = GUILayout.Toggle(InspectUnderMouse.EnableInspect, "Inspect Under Mouse (Shift + RMB)", null); + InspectUnderMouse.EnableInspect = GUILayout.Toggle(InspectUnderMouse.EnableInspect, "Inspect Under Mouse (Shift + RMB)", new GUILayoutOption[0]); bool mouseState = CursorControl.ForceUnlockMouse; - bool setMouse = GUILayout.Toggle(mouseState, "Force Unlock Mouse (Left Alt)", null); + bool setMouse = GUILayout.Toggle(mouseState, "Force Unlock Mouse (Left Alt)", new GUILayoutOption[0]); if (setMouse != mouseState) CursorControl.ForceUnlockMouse = setMouse; - WindowManager.TabView = GUILayout.Toggle(WindowManager.TabView, "Tab View", null); + WindowManager.TabView = GUILayout.Toggle(WindowManager.TabView, "Tab View", new GUILayoutOption[0]); GUILayout.EndHorizontal(); //GUIUnstrip.Space(10); diff --git a/src/Menu/MainMenu/Pages/Console/REPLHelper.cs b/src/Menu/MainMenu/Pages/Console/REPLHelper.cs index b5058409..eb95555c 100644 --- a/src/Menu/MainMenu/Pages/Console/REPLHelper.cs +++ b/src/Menu/MainMenu/Pages/Console/REPLHelper.cs @@ -6,7 +6,9 @@ namespace Explorer { public class ReplHelper : MonoBehaviour { +#if CPP public ReplHelper(IntPtr intPtr) : base(intPtr) { } +#endif public T Find() where T : Object { diff --git a/src/Menu/MainMenu/Pages/ConsolePage.cs b/src/Menu/MainMenu/Pages/ConsolePage.cs index 4a0ab321..8ab52d00 100644 --- a/src/Menu/MainMenu/Pages/ConsolePage.cs +++ b/src/Menu/MainMenu/Pages/ConsolePage.cs @@ -3,7 +3,6 @@ using System.IO; using System.Reflection; using System.Text; -using MelonLoader; using Mono.CSharp; using UnityEngine; @@ -36,15 +35,16 @@ public class ConsolePage : WindowPage public override void Init() { +#if CPP UnhollowerRuntimeLib.ClassInjector.RegisterTypeInIl2Cpp(); - +#endif try { MethodInput = @"// This is a basic C# console. // Some common using directives are added by default, you can add more below. -// If you want to return some output, MelonLogger.Log() it. +// If you want to return some output, Debug.Log() it. -MelonLogger.Log(""hello world"");"; +Debug.Log(""hello world"");"; ResetConsole(); @@ -55,7 +55,7 @@ public override void Init() } catch (Exception e) { - MelonLogger.Log($"Error setting up console!\r\nMessage: {e.Message}"); + ExplorerCore.Log($"Error setting up console!\r\nMessage: {e.Message}"); MainMenu.SetCurrentPage(0); MainMenu.Pages.Remove(this); } @@ -110,7 +110,7 @@ public object Evaluate(string str, bool suppressWarning = false) { if (!suppressWarning) { - MelonLogger.LogWarning(e.GetType() + ", " + e.Message); + ExplorerCore.LogWarning(e.GetType() + ", " + e.Message); } } @@ -120,19 +120,19 @@ public object Evaluate(string str, bool suppressWarning = false) public override void DrawWindow() { - GUILayout.Label("C# Console", null); + GUILayout.Label("C# Console", new GUILayoutOption[0]); GUI.skin.label.alignment = TextAnchor.UpperLeft; - GUILayout.Label("Enter code here as though it is a method body:", null); + GUILayout.Label("Enter code here as though it is a method body:", new GUILayoutOption[0]); inputAreaScroll = GUIUnstrip.BeginScrollView(inputAreaScroll, new GUILayoutOption[] { GUILayout.Height(250) }); - MethodInput = GUILayout.TextArea(MethodInput, new GUILayoutOption[] { GUILayout.ExpandHeight(true) }); + MethodInput = GUIUnstrip.TextArea(MethodInput, new GUILayoutOption[] { GUILayout.ExpandHeight(true) }); GUIUnstrip.EndScrollView(); - if (GUILayout.Button("Execute", null)) + if (GUILayout.Button("Execute", new GUILayoutOption[0])) { try { @@ -144,19 +144,19 @@ public override void DrawWindow() if (result != null && !Equals(result, VoidType.Value)) { - MelonLogger.Log("[Console Output]\r\n" + result.ToString()); + ExplorerCore.Log("[Console Output]\r\n" + result.ToString()); } } } catch (Exception e) { - MelonLogger.LogError("Exception compiling!\r\nMessage: " + e.Message + "\r\nStack: " + e.StackTrace); + ExplorerCore.LogError("Exception compiling!\r\nMessage: " + e.Message + "\r\nStack: " + e.StackTrace); } } - GUILayout.Label("Using directives:", null); + GUILayout.Label("Using directives:", new GUILayoutOption[0]); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Add namespace:", new GUILayoutOption[] { GUILayout.Width(105) }); UsingInput = GUILayout.TextField(UsingInput, new GUILayoutOption[] { GUILayout.Width(150) }); if (GUILayout.Button("Add", new GUILayoutOption[] { GUILayout.Width(120) })) @@ -171,7 +171,7 @@ public override void DrawWindow() foreach (var asm in UsingDirectives) { - GUILayout.Label(AsmToUsing(asm, true), null); + GUILayout.Label(AsmToUsing(asm, true), new GUILayoutOption[0]); } } diff --git a/src/Menu/MainMenu/Pages/ScenePage.cs b/src/Menu/MainMenu/Pages/ScenePage.cs index 3817ccad..4fdeeea5 100644 --- a/src/Menu/MainMenu/Pages/ScenePage.cs +++ b/src/Menu/MainMenu/Pages/ScenePage.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using MelonLoader; using UnityEngine; using UnityEngine.SceneManagement; @@ -87,7 +86,11 @@ public List SearchSceneObjects(string _search) foreach (var obj in Resources.FindObjectsOfTypeAll(ReflectionHelpers.GameObjectType)) { +#if CPP var go = obj.TryCast(); +#else + var go = obj as GameObject; +#endif if (go.name.ToLower().Contains(_search.ToLower()) && go.scene.name == m_currentScene) { matches.Add(new GameObjectCache(go)); @@ -125,14 +128,22 @@ private void Update_Impl(bool manual = false) { try { - var scene = SceneManager.GetSceneByName(m_currentScene); + for (int i = 0; i < SceneManager.sceneCount; i++) + { + var scene = SceneManager.GetSceneAt(i); + + if (scene.name == m_currentScene) + { + allTransforms.AddRange(scene.GetRootGameObjects() + .Select(it => it.transform)); - allTransforms.AddRange(scene.GetRootGameObjects() - .Select(it => it.transform)); + break; + } + } } catch { - MelonLogger.Log("Exception getting root scene objects, falling back to backup method..."); + ExplorerCore.Log("Exception getting root scene objects, falling back to backup method..."); m_getRootObjectsFailed = true; allTransforms.AddRange(GetRootObjectsManual_Impl()); @@ -174,7 +185,11 @@ private IEnumerable GetRootObjectsManual_Impl() var list = new List(); foreach (var obj in array) { +#if CPP var transform = obj.TryCast(); +#else + var transform = obj as Transform; +#endif if (transform.parent == null && transform.gameObject.scene.name == m_currentScene) { list.Add(transform); @@ -184,7 +199,7 @@ private IEnumerable GetRootObjectsManual_Impl() } catch (Exception e) { - MelonLogger.Log("Exception getting root scene objects (manual): " + ExplorerCore.Log("Exception getting root scene objects (manual): " + e.GetType() + ", " + e.Message + "\r\n" + e.StackTrace); return new Transform[0]; @@ -199,7 +214,7 @@ public override void DrawWindow() { DrawHeaderArea(); - GUILayout.BeginVertical(GUI.skin.box, null); + GUILayout.BeginVertical(GUIContent.none, GUI.skin.box, null); DrawPageButtons(); @@ -222,20 +237,20 @@ public override void DrawWindow() private void DrawHeaderArea() { - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); // Current Scene label GUILayout.Label("Current Scene:", new GUILayoutOption[] { GUILayout.Width(120) }); SceneChangeButtons(); - GUILayout.Label("" + m_currentScene + "", null); //new GUILayoutOption[] { GUILayout.Width(250) }); + GUILayout.Label("" + m_currentScene + "", new GUILayoutOption[0]); GUILayout.EndHorizontal(); // ----- GameObject Search ----- - GUILayout.BeginHorizontal(GUI.skin.box, null); + GUILayout.BeginHorizontal(GUIContent.none, GUI.skin.box, null); GUILayout.Label("Search Scene:", new GUILayoutOption[] { GUILayout.Width(100) }); - m_searchInput = GUILayout.TextField(m_searchInput, null); + m_searchInput = GUILayout.TextField(m_searchInput, new GUILayoutOption[0]); if (GUILayout.Button("Search", new GUILayoutOption[] { GUILayout.Width(80) })) { @@ -248,8 +263,14 @@ private void DrawHeaderArea() private void SceneChangeButtons() { - // Need to do 'ToList()' so the object isn't cleaned up by Il2Cpp GC. - var scenes = SceneManager.GetAllScenes().ToList(); + var scenes = new List(); + var names = new List(); + for (int i = 0; i < SceneManager.sceneCount; i++) + { + var scene = SceneManager.GetSceneAt(i); + names.Add(scene.name); + scenes.Add(scene); + } if (scenes.Count > 1) { @@ -264,7 +285,7 @@ private void SceneChangeButtons() } if (changeWanted != 0) { - int index = scenes.IndexOf(SceneManager.GetSceneByName(m_currentScene)); + int index = names.IndexOf(m_currentScene); index += changeWanted; if (index > scenes.Count - 1) { @@ -281,7 +302,7 @@ private void SceneChangeButtons() private void DrawPageButtons() { - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); Pages.DrawLimitInputArea(); @@ -312,7 +333,7 @@ private void DrawGameObjectList() { if (m_currentTransform != null) { - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); if (GUILayout.Button("<-", new GUILayoutOption[] { GUILayout.Width(35) })) { TraverseUp(); @@ -329,11 +350,11 @@ private void DrawGameObjectList() } else { - GUILayout.Label("Scene Root GameObjects:", null); + GUILayout.Label("Scene Root GameObjects:", new GUILayoutOption[0]); if (m_getRootObjectsFailed) { - if (GUILayout.Button("Update Root Object List (auto-update failed!)", null)) + if (GUILayout.Button("Update Root Object List (auto-update failed!)", new GUILayoutOption[0])) { Update_Impl(true); } @@ -358,7 +379,7 @@ private void DrawGameObjectList() } label += ""; - GUILayout.Label(label, null); + GUILayout.Label(label, new GUILayoutOption[0]); } else { @@ -381,7 +402,7 @@ private void DrawSearchResultsList() CancelSearch(); } - GUILayout.Label("Search Results:", null); + GUILayout.Label("Search Results:", new GUILayoutOption[0]); if (m_searchResults.Count > 0) { @@ -403,13 +424,13 @@ private void DrawSearchResultsList() } else { - GUILayout.Label("Null or destroyed!", null); + GUILayout.Label("Null or destroyed!", new GUILayoutOption[0]); } } } else { - GUILayout.Label("No results found!", null); + GUILayout.Label("No results found!", new GUILayoutOption[0]); } } diff --git a/src/Menu/MainMenu/Pages/SearchPage.cs b/src/Menu/MainMenu/Pages/SearchPage.cs index 7d864c75..164afd71 100644 --- a/src/Menu/MainMenu/Pages/SearchPage.cs +++ b/src/Menu/MainMenu/Pages/SearchPage.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using MelonLoader; using UnityEngine; namespace Explorer @@ -65,10 +64,17 @@ private void CacheResults(IEnumerable results) { var toCache = obj; +#if CPP if (toCache is Il2CppSystem.Object ilObject) { toCache = ilObject.TryCast() ?? ilObject.TryCast()?.gameObject ?? ilObject; } +#else + if (toCache is GameObject || toCache is Transform) + { + toCache = toCache as GameObject ?? (toCache as Transform).gameObject; + } +#endif var cache = CacheObjectBase.GetCacheObject(toCache); m_searchResults.Add(cache); @@ -83,7 +89,7 @@ public override void DrawWindow() try { // helpers - GUILayout.BeginHorizontal(GUI.skin.box, null); + GUILayout.BeginHorizontal(GUIContent.none, GUI.skin.box, null); GUILayout.Label("Helpers", new GUILayoutOption[] { GUILayout.Width(70) }); if (GUILayout.Button("Find Static Instances", new GUILayoutOption[] { GUILayout.Width(180) })) { @@ -96,15 +102,15 @@ public override void DrawWindow() SearchBox(); // results - GUILayout.BeginVertical(GUI.skin.box, null); + GUILayout.BeginVertical(GUIContent.none, GUI.skin.box, null); GUI.skin.label.alignment = TextAnchor.MiddleCenter; - GUILayout.Label("Results " + " (" + m_searchResults.Count + ")", null); + GUILayout.Label("Results " + " (" + m_searchResults.Count + ")", new GUILayoutOption[0]); GUI.skin.label.alignment = TextAnchor.UpperLeft; int count = m_searchResults.Count; - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); Pages.DrawLimitInputArea(); @@ -145,7 +151,7 @@ public override void DrawWindow() } else { - GUILayout.Label("No results found!", null); + GUILayout.Label("No results found!", new GUILayoutOption[0]); } GUIUnstrip.EndScrollView(); @@ -159,21 +165,21 @@ public override void DrawWindow() private void SearchBox() { - GUILayout.BeginVertical(GUI.skin.box, null); + GUILayout.BeginVertical(GUIContent.none, GUI.skin.box, null); // ----- GameObject Search ----- GUI.skin.label.alignment = TextAnchor.MiddleCenter; - GUILayout.Label("Search", null); + GUILayout.Label("Search", new GUILayoutOption[0]); GUI.skin.label.alignment = TextAnchor.UpperLeft; - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Name Contains:", new GUILayoutOption[] { GUILayout.Width(100) }); m_searchInput = GUILayout.TextField(m_searchInput, new GUILayoutOption[] { GUILayout.Width(200) }); GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Class Filter:", new GUILayoutOption[] { GUILayout.Width(100) }); ClassFilterToggle(TypeFilter.Object, "Object"); @@ -183,7 +189,7 @@ private void SearchBox() GUILayout.EndHorizontal(); if (TypeMode == TypeFilter.Custom) { - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUI.skin.label.alignment = TextAnchor.MiddleRight; GUILayout.Label("Custom Class:", new GUILayoutOption[] { GUILayout.Width(250) }); GUI.skin.label.alignment = TextAnchor.UpperLeft; @@ -191,7 +197,7 @@ private void SearchBox() GUILayout.EndHorizontal(); } - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Scene Filter:", new GUILayoutOption[] { GUILayout.Width(100) }); SceneFilterToggle(SceneFilter.Any, "Any", 60); SceneFilterToggle(SceneFilter.This, "This Scene", 100); @@ -199,7 +205,7 @@ private void SearchBox() SceneFilterToggle(SceneFilter.None, "No Scene", 80); GUILayout.EndHorizontal(); - if (GUILayout.Button("Search", null)) + if (GUILayout.Button("Search", new GUILayoutOption[0])) { Search(); } @@ -254,15 +260,23 @@ private void Search() private List FindAllObjectsOfType(string searchQuery, string typeName) { +#if CPP Il2CppSystem.Type searchType = null; +#else + Type searchType = null; +#endif if (TypeMode == TypeFilter.Custom) { try { if (ReflectionHelpers.GetTypeByName(typeName) is Type t) { +#if CPP searchType = Il2CppSystem.Type.GetType(t.AssemblyQualifiedName); +#else + searchType = t; +#endif } else { @@ -271,7 +285,7 @@ private List FindAllObjectsOfType(string searchQuery, string typeName) } catch (Exception e) { - MelonLogger.Log("Exception getting Search Type: " + e.GetType() + ", " + e.Message); + ExplorerCore.Log("Exception getting Search Type: " + e.GetType() + ", " + e.Message); } } else if (TypeMode == TypeFilter.Object) @@ -291,7 +305,7 @@ private List FindAllObjectsOfType(string searchQuery, string typeName) { if (searchType != null) { - MelonLogger.LogWarning("Your Custom Class Type must inherit from UnityEngine.Object!"); + ExplorerCore.LogWarning("Your Custom Class Type must inherit from UnityEngine.Object!"); } return new List(); } @@ -300,7 +314,7 @@ private List FindAllObjectsOfType(string searchQuery, string typeName) var allObjectsOfType = Resources.FindObjectsOfTypeAll(searchType); - //MelonLogger.Log("Found count: " + allObjectsOfType.Length); + //ExplorerCore.Log("Found count: " + allObjectsOfType.Length); int i = 0; foreach (var obj in allObjectsOfType) @@ -313,7 +327,11 @@ private List FindAllObjectsOfType(string searchQuery, string typeName) } if (searchType.FullName == ReflectionHelpers.ComponentType.FullName +#if CPP && ReflectionHelpers.TransformType.IsAssignableFrom(obj.GetIl2CppType())) +#else + && ReflectionHelpers.TransformType.IsAssignableFrom(obj.GetType())) +#endif { // Transforms shouldn't really be counted as Components, skip them. // They're more akin to GameObjects. @@ -338,15 +356,18 @@ private List FindAllObjectsOfType(string searchQuery, string typeName) public static bool FilterScene(object obj, SceneFilter filter) { - GameObject go; + GameObject go = null; +#if CPP if (obj is Il2CppSystem.Object ilObject) { go = ilObject.TryCast() ?? ilObject.TryCast().gameObject; } - else +#else + if (obj is GameObject || obj is Component) { go = (obj as GameObject) ?? (obj as Component).gameObject; } +#endif if (!go) { @@ -404,7 +425,7 @@ public static IEnumerable GetInstanceClassScanner() if (pi != null) { - obj = pi.GetValue(null); + obj = pi.GetValue(null, null); } else { diff --git a/src/Menu/ResizeDrag.cs b/src/Menu/ResizeDrag.cs index fa78b609..9c824da6 100644 --- a/src/Menu/ResizeDrag.cs +++ b/src/Menu/ResizeDrag.cs @@ -1,6 +1,7 @@ using System; -using MelonLoader; +#if CPP using UnhollowerBaseLib; +#endif using UnityEngine; namespace Explorer @@ -22,10 +23,18 @@ public static Rect ResizeWindow(Rect _rect, int ID) try { - GUILayout.BeginHorizontal(GUI.skin.box, null); + GUILayout.BeginHorizontal(GUIContent.none, GUI.skin.box, null); GUI.skin.label.alignment = TextAnchor.MiddleCenter; +#if CPP +#if ML GUILayout.Button(gcDrag, GUI.skin.label, new GUILayoutOption[] { GUILayout.Height(15) }); +#else + GUILayout.Button(gcDrag.ToString(), new GUILayoutOption[] { GUILayout.Height(15) }); +#endif +#else + GUILayout.Button(gcDrag, GUI.skin.label, new GUILayoutOption[] { GUILayout.Height(15) }); +#endif //var r = GUILayoutUtility.GetLastRect(); var r = LayoutUtilityUnstrip.GetLastRect(); @@ -34,7 +43,7 @@ public static Rect ResizeWindow(Rect _rect, int ID) try { - var mouse = GUIUtility.ScreenToGUIPoint(new Vector2(mousePos.x, Screen.height - mousePos.y)); + var mouse = GUIUnstrip.ScreenToGUIPoint(new Vector2(mousePos.x, Screen.height - mousePos.y)); if (r.Contains(mouse) && InputHelper.GetMouseButtonDown(0)) { isResizing = true; @@ -62,7 +71,7 @@ public static Rect ResizeWindow(Rect _rect, int ID) GUILayout.EndHorizontal(); } - catch (Il2CppException e) when (e.Message.StartsWith("System.ArgumentException")) + catch (Exception e) when (e.Message.StartsWith("System.ArgumentException")) { // suppress return origRect; @@ -70,8 +79,8 @@ public static Rect ResizeWindow(Rect _rect, int ID) catch (Exception e) { RESIZE_FAILED = true; - MelonLogger.Log("Exception on GuiResize: " + e.GetType() + ", " + e.Message); - //MelonLogger.Log(e.StackTrace); + ExplorerCore.Log("Exception on GuiResize: " + e.GetType() + ", " + e.Message); + //ExplorerCore.Log(e.StackTrace); return origRect; } @@ -79,7 +88,7 @@ public static Rect ResizeWindow(Rect _rect, int ID) } else { - GUILayout.BeginHorizontal(GUI.skin.box, null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Resize window:", new GUILayoutOption[] { GUILayout.Width(100) }); diff --git a/src/Menu/UIHelpers.cs b/src/Menu/UIHelpers.cs index 0797cf82..a41790f9 100644 --- a/src/Menu/UIHelpers.cs +++ b/src/Menu/UIHelpers.cs @@ -56,13 +56,13 @@ public static void GOButton_Impl(object _obj, Color activeColor, string label, b if (!obj) { - GUILayout.Label("null", null); + GUILayout.Label("null", new GUILayoutOption[0]); return; } // ------ toggle active button ------ - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUI.skin.button.alignment = TextAnchor.UpperLeft; GUI.color = activeColor; @@ -102,7 +102,7 @@ public static void GOButton_Impl(object _obj, Color activeColor, string label, b public static void SmallInspectButton(object obj) { - if (GUILayout.Button("Inspect", null)) + if (GUILayout.Button("Inspect", new GUILayoutOption[0])) { WindowManager.InspectObject(obj, out bool _); } diff --git a/src/Menu/Windows/GameObjectWindow.cs b/src/Menu/Windows/GameObjectWindow.cs index 8d07c889..46649c33 100644 --- a/src/Menu/Windows/GameObjectWindow.cs +++ b/src/Menu/Windows/GameObjectWindow.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; -using MelonLoader; -using UnhollowerRuntimeLib; using UnityEngine; +#if CPP +using UnhollowerRuntimeLib; +#endif + namespace Explorer { public class GameObjectWindow : UIWindow @@ -60,7 +62,7 @@ public bool GetObjectAsGameObject() return true; } - MelonLogger.Log("Error: Target is null or not a GameObject/Transform!"); + ExplorerCore.Log("Error: Target is null or not a GameObject/Transform!"); DestroyWindow(); return false; } @@ -103,7 +105,7 @@ public override void Update() { if (Target == null) { - MelonLogger.Log("Target is null!"); + ExplorerCore.Log("Target is null!"); DestroyWindow(); return; } @@ -111,7 +113,7 @@ public override void Update() { if (!uObj) { - MelonLogger.Log("Target was destroyed!"); + ExplorerCore.Log("Target was destroyed!"); DestroyWindow(); return; } @@ -149,10 +151,13 @@ public override void Update() ChildPages.ItemCount = m_children.Length; // update components +#if CPP var compList = new Il2CppSystem.Collections.Generic.List(); TargetGO.GetComponentsInternal(ReflectionHelpers.ComponentType, true, false, true, false, compList); - m_components = compList.ToArray(); +#else + m_components = TargetGO.GetComponents(); +#endif CompPages.ItemCount = m_components.Length; } @@ -164,7 +169,7 @@ public override void Update() private void DestroyOnException(Exception e) { - MelonLogger.Log($"Exception drawing GameObject Window: {e.GetType()}, {e.Message}"); + ExplorerCore.Log($"Exception drawing GameObject Window: {e.GetType()}, {e.Message}"); DestroyWindow(); } @@ -179,8 +184,12 @@ private void InspectGameObject(Transform obj) } } +#if CPP private void ReflectObject(Il2CppSystem.Object obj) - { +#else + private void ReflectObject(object obj) +#endif + { var window = WindowManager.InspectObject(obj, out bool created, true); if (created) @@ -214,8 +223,8 @@ public override void WindowFunction(int windowID) scroll = GUIUnstrip.BeginScrollView(scroll); - GUILayout.BeginHorizontal(null); - GUILayout.Label("Scene: " + (m_scene == "" ? "n/a" : m_scene) + "", null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); + GUILayout.Label("Scene: " + (m_scene == "" ? "n/a" : m_scene) + "", new GUILayoutOption[0]); if (m_scene == UnityHelpers.ActiveSceneName) { if (GUILayout.Button("Send to Scene View", new GUILayoutOption[] { GUILayout.Width(150) })) @@ -230,7 +239,7 @@ public override void WindowFunction(int windowID) } GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Path:", new GUILayoutOption[] { GUILayout.Width(50) }); string pathlabel = TargetGO.transform.GetGameObjectPath(); if (TargetGO.transform.parent != null) @@ -240,16 +249,16 @@ public override void WindowFunction(int windowID) InspectGameObject(TargetGO.transform.parent); } } - GUILayout.TextArea(pathlabel, null); + GUIUnstrip.TextArea(pathlabel, new GUILayoutOption[0]); GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Name:", new GUILayoutOption[] { GUILayout.Width(50) }); - GUILayout.TextArea(m_name, null); + GUIUnstrip.TextArea(m_name, new GUILayoutOption[0]); GUILayout.EndHorizontal(); // --- Horizontal Columns section --- - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.BeginVertical(new GUILayoutOption[] { GUILayout.Width(rect.width / 2 - 17) }); TransformList(rect); @@ -280,12 +289,12 @@ public override void WindowFunction(int windowID) private void TransformList(Rect m_rect) { - GUILayout.BeginVertical(GUI.skin.box, null); + GUILayout.BeginVertical(GUIContent.none, GUI.skin.box, null); m_transformScroll = GUIUnstrip.BeginScrollView(m_transformScroll); - GUILayout.Label("Children", null); + GUILayout.Label("Children", new GUILayoutOption[0]); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); ChildPages.DrawLimitInputArea(); if (ChildPages.ItemCount > ChildPages.ItemsPerPage) @@ -293,7 +302,7 @@ private void TransformList(Rect m_rect) ChildPages.CurrentPageLabel(); GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(80) })) { @@ -316,7 +325,7 @@ private void TransformList(Rect m_rect) if (!obj) { - GUILayout.Label("null", null); + GUILayout.Label("null", new GUILayoutOption[0]); continue; } @@ -325,7 +334,7 @@ private void TransformList(Rect m_rect) } else { - GUILayout.Label("None", null); + GUILayout.Label("None", new GUILayoutOption[0]); } GUIUnstrip.EndScrollView(); @@ -334,11 +343,11 @@ private void TransformList(Rect m_rect) private void ComponentList(Rect m_rect) { - GUILayout.BeginVertical(GUI.skin.box, null); + GUILayout.BeginVertical(GUIContent.none, GUI.skin.box, null); m_compScroll = GUIUnstrip.BeginScrollView(m_compScroll); - GUILayout.Label("Components", null); + GUILayout.Label("Components", new GUILayoutOption[0]); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); CompPages.DrawLimitInputArea(); if (CompPages.ItemCount > CompPages.ItemsPerPage) @@ -346,7 +355,7 @@ private void ComponentList(Rect m_rect) CompPages.CurrentPageLabel(); GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(80) })) { @@ -359,25 +368,29 @@ private void ComponentList(Rect m_rect) } GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); var width = m_rect.width / 2 - 115f; m_addComponentInput = GUILayout.TextField(m_addComponentInput, new GUILayoutOption[] { GUILayout.Width(width) }); - if (GUILayout.Button("Add Comp", null)) + if (GUILayout.Button("Add Comp", new GUILayoutOption[0])) { if (ReflectionHelpers.GetTypeByName(m_addComponentInput) is Type compType) { if (typeof(Component).IsAssignableFrom(compType)) { +#if CPP TargetGO.AddComponent(Il2CppType.From(compType)); +#else + TargetGO.AddComponent(compType); +#endif } else { - MelonLogger.LogWarning($"Type '{compType.Name}' is not assignable from Component!"); + ExplorerCore.LogWarning($"Type '{compType.Name}' is not assignable from Component!"); } } else { - MelonLogger.LogWarning($"Could not find a type by the name of '{m_addComponentInput}'!"); + ExplorerCore.LogWarning($"Could not find a type by the name of '{m_addComponentInput}'!"); } } GUILayout.EndHorizontal(); @@ -398,18 +411,26 @@ private void ComponentList(Rect m_rect) if (!component) continue; - var ilType = component.GetIl2CppType(); - - GUILayout.BeginHorizontal(null); - if (ReflectionHelpers.BehaviourType.IsAssignableFrom(ilType)) + var type = +#if CPP + component.GetIl2CppType(); +#else + component.GetType(); +#endif + GUILayout.BeginHorizontal(new GUILayoutOption[0]); + if (ReflectionHelpers.BehaviourType.IsAssignableFrom(type)) { +#if CPP BehaviourEnabledBtn(component.TryCast()); +#else + BehaviourEnabledBtn(component as Behaviour); +#endif } else { GUIUnstrip.Space(26); } - if (GUILayout.Button("" + ilType.Name + "", new GUILayoutOption[] { GUILayout.Width(m_rect.width / 2 - 100) })) + if (GUILayout.Button("" + type.Name + "", new GUILayoutOption[] { GUILayout.Width(m_rect.width / 2 - 100) })) { ReflectObject(component); } @@ -463,7 +484,7 @@ private void GameObjectControls() { if (m_hideControls) { - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("GameObject Controls", new GUILayoutOption[] { GUILayout.Width(200) }); if (GUILayout.Button("^ Show ^", new GUILayoutOption[] { GUILayout.Width(75) })) { @@ -474,9 +495,9 @@ private void GameObjectControls() return; } - GUILayout.BeginVertical(GUI.skin.box, new GUILayoutOption[] { GUILayout.Width(520) }); + GUILayout.BeginVertical(GUIContent.none, GUI.skin.box, new GUILayoutOption[] { GUILayout.Width(520) }); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("GameObject Controls", new GUILayoutOption[] { GUILayout.Width(200) }); if (GUILayout.Button("v Hide v", new GUILayoutOption[] { GUILayout.Width(75) })) { @@ -484,7 +505,7 @@ private void GameObjectControls() } GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); bool m_active = TargetGO.activeSelf; m_active = GUILayout.Toggle(m_active, (m_active ? "Enabled " : "Disabled") + "", new GUILayoutOption[] { GUILayout.Width(80) }); @@ -509,9 +530,9 @@ private void GameObjectControls() } GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); - m_setParentInput = GUILayout.TextField(m_setParentInput, null); + m_setParentInput = GUILayout.TextField(m_setParentInput, new GUILayoutOption[0]); if (GUILayout.Button("Set Parent", new GUILayoutOption[] { GUILayout.Width(80) })) { if (GameObject.Find(m_setParentInput) is GameObject newparent) @@ -520,7 +541,7 @@ private void GameObjectControls() } else { - MelonLogger.LogWarning($"Could not find gameobject '{m_setParentInput}'"); + ExplorerCore.LogWarning($"Could not find gameobject '{m_setParentInput}'"); } } @@ -530,14 +551,14 @@ private void GameObjectControls() } GUILayout.EndHorizontal(); - GUILayout.BeginVertical(GUI.skin.box, null); + GUILayout.BeginVertical(GUIContent.none, GUI.skin.box, null); m_cachedInput[0] = TranslateControl(TranslateType.Position, ref m_translateAmount, false); m_cachedInput[1] = TranslateControl(TranslateType.Rotation, ref m_rotateAmount, true); m_cachedInput[2] = TranslateControl(TranslateType.Scale, ref m_scaleAmount, false); - GUILayout.BeginHorizontal(null); - if (GUILayout.Button("Apply to Transform", null) || m_autoApplyTransform) + GUILayout.BeginHorizontal(new GUILayoutOption[0]); + if (GUILayout.Button("Apply to Transform", new GUILayoutOption[0]) || m_autoApplyTransform) { if (m_localContext) { @@ -556,19 +577,19 @@ private void GameObjectControls() UpdateFreeze(); } } - if (GUILayout.Button("Update from Transform", null) || m_autoUpdateTransform) + if (GUILayout.Button("Update from Transform", new GUILayoutOption[0]) || m_autoUpdateTransform) { CacheTransformValues(); } GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); BoolToggle(ref m_autoApplyTransform, "Auto-apply to Transform?"); BoolToggle(ref m_autoUpdateTransform, "Auto-update from transform?"); GUILayout.EndHorizontal(); bool b = m_localContext; - b = GUILayout.Toggle(b, "Use local transform values?", null); + b = GUILayout.Toggle(b, "Use local transform values?", new GUILayoutOption[0]); if (b != m_localContext) { m_localContext = b; @@ -612,7 +633,7 @@ private void BoolToggle(ref bool value, string message) lbl += value ? "lime" : "orange"; lbl += $">{message}"; - value = GUILayout.Toggle(value, lbl, null); + value = GUILayout.Toggle(value, lbl, new GUILayoutOption[0]); } public enum TranslateType @@ -624,7 +645,7 @@ public enum TranslateType private Vector3 TranslateControl(TranslateType mode, ref float amount, bool multByTime) { - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label($"{(m_localContext ? "Local " : "")}{mode}:", new GUILayoutOption[] { GUILayout.Width(m_localContext ? 110 : 65) }); @@ -647,7 +668,7 @@ private Vector3 TranslateControl(TranslateType mode, ref float amount, bool mult Vector3 input = m_cachedInput[(int)mode]; - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUI.skin.label.alignment = TextAnchor.MiddleRight; GUILayout.Label("X:", new GUILayoutOption[] { GUILayout.Width(20) }); diff --git a/src/Menu/Windows/ReflectionWindow.cs b/src/Menu/Windows/ReflectionWindow.cs index d2b385e1..7da2444b 100644 --- a/src/Menu/Windows/ReflectionWindow.cs +++ b/src/Menu/Windows/ReflectionWindow.cs @@ -2,9 +2,10 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using MelonLoader; -using UnhollowerBaseLib; using UnityEngine; +#if CPP +using UnhollowerBaseLib; +#endif namespace Explorer { @@ -52,6 +53,7 @@ public override void Init() CacheMembers(ReflectionHelpers.GetAllBaseTypes(Target)); // cache the extra cast-caching +#if CPP if (Target is Il2CppSystem.Object ilObject) { var unityObj = ilObject.TryCast(); @@ -66,6 +68,10 @@ public override void Init() } } } +#else + m_uObj = Target as UnityEngine.Object; + m_component = Target as Component; +#endif } public override void Update() @@ -134,13 +140,14 @@ private void CacheMembers(Type[] types) } catch { - MelonLogger.Log($"Exception getting members for type: {declaringType.FullName}"); + ExplorerCore.Log($"Exception getting members for type: {declaringType.FullName}"); continue; } object target = Target; string exception = null; +#if CPP if (target is Il2CppSystem.Object ilObject) { try @@ -152,6 +159,7 @@ private void CacheMembers(Type[] types) exception = ReflectionHelpers.ExceptionToString(e); } } +#endif foreach (var member in infos) { @@ -192,7 +200,7 @@ void AppendParams(ParameterInfo[] _args) continue; } - // MelonLogger.Log($"Trying to cache member {signature}..."); + // ExplorerCore.Log($"Trying to cache member {signature}..."); try { @@ -206,8 +214,8 @@ void AppendParams(ParameterInfo[] _args) } catch (Exception e) { - MelonLogger.LogWarning($"Exception caching member {sig}!"); - MelonLogger.Log(e.ToString()); + ExplorerCore.LogWarning($"Exception caching member {sig}!"); + ExplorerCore.Log(e.ToString()); } } } @@ -231,17 +239,17 @@ public override void WindowFunction(int windowID) GUIUnstrip.BeginArea(new Rect(5, 25, rect.width - 10, rect.height - 35), GUI.skin.box); } - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Type: " + TargetType.FullName + "", new GUILayoutOption[] { GUILayout.Width(245f) }); if (m_uObj) { - GUILayout.Label("Name: " + m_uObj.name, null); + GUILayout.Label("Name: " + m_uObj.name, new GUILayoutOption[0]); } GUILayout.EndHorizontal(); if (m_uObj) { - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Tools:", new GUILayoutOption[] { GUILayout.Width(80) }); UIHelpers.InstantiateButton(m_uObj); if (m_component && m_component.gameObject is GameObject obj) @@ -262,12 +270,12 @@ public override void WindowFunction(int windowID) UIStyles.HorizontalLine(Color.grey); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Search:", new GUILayoutOption[] { GUILayout.Width(75) }); - m_search = GUILayout.TextField(m_search, null); + m_search = GUILayout.TextField(m_search, new GUILayoutOption[0]); GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Filter:", new GUILayoutOption[] { GUILayout.Width(75) }); FilterToggle(MemberTypes.All, "All"); FilterToggle(MemberTypes.Property, "Properties"); @@ -275,7 +283,7 @@ public override void WindowFunction(int windowID) FilterToggle(MemberTypes.Method, "Methods"); GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Values:", new GUILayoutOption[] { GUILayout.Width(75) }); if (GUILayout.Button("Update", new GUILayoutOption[] { GUILayout.Width(100) })) { @@ -293,7 +301,7 @@ public override void WindowFunction(int windowID) Pages.ItemCount = m_cachedMembersFiltered.Length; // prev/next page buttons - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); Pages.DrawLimitInputArea(); @@ -321,7 +329,7 @@ public override void WindowFunction(int windowID) UIStyles.HorizontalLine(Color.grey); - GUILayout.BeginVertical(GUI.skin.box, null); + GUILayout.BeginVertical(GUIContent.none, GUI.skin.box, null); var members = this.m_cachedMembersFiltered; int start = Pages.CalculateOffsetIndex(); @@ -357,16 +365,13 @@ public override void WindowFunction(int windowID) GUIUnstrip.EndArea(); } } - catch (Il2CppException e) + catch (Exception e) when (e.Message.Contains("in a group with only")) { - if (!e.Message.Contains("in a group with only")) - { - throw; - } + // suppress } catch (Exception e) { - MelonLogger.LogWarning("Exception drawing ReflectionWindow: " + e.GetType() + ", " + e.Message); + ExplorerCore.LogWarning("Exception drawing ReflectionWindow: " + e.GetType() + ", " + e.Message); DestroyWindow(); return; } diff --git a/src/Menu/Windows/TabViewWindow.cs b/src/Menu/Windows/TabViewWindow.cs index 0b349fb1..95a61d42 100644 --- a/src/Menu/Windows/TabViewWindow.cs +++ b/src/Menu/Windows/TabViewWindow.cs @@ -50,7 +50,7 @@ public override void WindowFunction(int windowID) try { GUI.DragWindow(new Rect(0, 0, m_rect.width - 90, 20)); - if (GUI.Button(new Rect(m_rect.width - 90, 2, 80, 20), "Close All")) + if (GUIUnstrip.Button(new Rect(m_rect.width - 90, 2, 80, 20), "Close All")) { foreach (var window in WindowManager.Windows) { @@ -61,8 +61,8 @@ public override void WindowFunction(int windowID) GUIUnstrip.BeginArea(new Rect(5, 25, m_rect.width - 10, m_rect.height - 35), GUI.skin.box); - GUILayout.BeginVertical(GUI.skin.box, null); - GUILayout.BeginHorizontal(null); + GUILayout.BeginVertical(GUIContent.none, GUI.skin.box, null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUI.skin.button.alignment = TextAnchor.MiddleLeft; int tabPerRow = Mathf.FloorToInt((float)((decimal)m_rect.width / 238)); int rowCount = 0; @@ -72,7 +72,7 @@ public override void WindowFunction(int windowID) { rowCount = 0; GUILayout.EndHorizontal(); - GUILayout.BeginHorizontal(null); + GUILayout.BeginHorizontal(new GUILayoutOption[0]); } rowCount++; diff --git a/src/Menu/Windows/UIWindow.cs b/src/Menu/Windows/UIWindow.cs index 475bab04..d387e83f 100644 --- a/src/Menu/Windows/UIWindow.cs +++ b/src/Menu/Windows/UIWindow.cs @@ -42,7 +42,11 @@ public void DestroyWindow() public void OnGUI() { - m_rect = GUI.Window(windowID, m_rect, (GUI.WindowFunction)WindowFunction, Title); +#if CPP + m_rect = GUI.Window(windowID, m_rect, (GUI.WindowFunction)WindowFunction, GUIContent.Temp(Title), GUI.skin.window); +#else + m_rect = GUI.Window(windowID, m_rect, WindowFunction, Title); +#endif } public void Header() @@ -50,8 +54,12 @@ public void Header() if (!WindowManager.TabView) { GUI.DragWindow(new Rect(0, 0, m_rect.width - 90, 20)); - - if (GUI.Button(new Rect(m_rect.width - 90, 2, 80, 20), "X")) + +#if CPP + if (GUI.Button(new Rect(m_rect.width - 90, 2, 80, 20), GUIContent.Temp("X"), GUI.skin.button)) +#else + if (GUI.Button(new Rect(m_rect.width - 90, 2, 80, 20), "X", GUI.skin.button)) +#endif { DestroyWindow(); return; diff --git a/src/Menu/Windows/WindowManager.cs b/src/Menu/Windows/WindowManager.cs index 465b4f03..ab26bb6d 100644 --- a/src/Menu/Windows/WindowManager.cs +++ b/src/Menu/Windows/WindowManager.cs @@ -85,12 +85,16 @@ public static UIWindow InspectObject(object obj, out bool createdNew, bool force { forceReflection = true; } - + +#if CPP Il2CppSystem.Object iObj = null; if (obj is Il2CppSystem.Object isObj) { iObj = isObj; } +#else + var iObj = obj; +#endif if (!forceReflection) { @@ -98,6 +102,7 @@ public static UIWindow InspectObject(object obj, out bool createdNew, bool force { bool equals = ReferenceEquals(obj, window.Target); +#if CPP if (!equals && iObj is Il2CppSystem.Object iCurrent && window.Target is Il2CppSystem.Object iTarget) { if (iCurrent.GetIl2CppType().FullName != iTarget.GetIl2CppType().FullName) @@ -110,6 +115,7 @@ public static UIWindow InspectObject(object obj, out bool createdNew, bool force equals = iCurrent.Pointer == iTarget.Pointer; } +#endif if (equals) { @@ -134,7 +140,7 @@ private static void FocusWindow(UIWindow window) { if (!TabView) { - GUI.BringWindowToFront(window.windowID); + GUIUnstrip.BringWindowToFront(window.windowID); GUI.FocusWindow(window.windowID); } else @@ -165,7 +171,7 @@ public static bool IsMouseInWindow { get { - if (!CppExplorer.ShowMenu) + if (!ExplorerCore.ShowMenu) { return false; } diff --git a/src/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs index 38d40b36..3cb5bd9e 100644 --- a/src/Properties/AssemblyInfo.cs +++ b/src/Properties/AssemblyInfo.cs @@ -2,19 +2,22 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Explorer; + +#if ML using MelonLoader; -[assembly: MelonInfo(typeof(CppExplorer), CppExplorer.NAME, CppExplorer.VERSION, CppExplorer.AUTHOR)] +[assembly: MelonInfo(typeof(Explorer_MelonMod), ExplorerCore.NAME, ExplorerCore.VERSION, ExplorerCore.AUTHOR)] [assembly: MelonGame(null, null)] +#endif // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle(CppExplorer.NAME)] +[assembly: AssemblyTitle(ExplorerCore.NAME)] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany(CppExplorer.AUTHOR)] -[assembly: AssemblyProduct(CppExplorer.NAME)] +[assembly: AssemblyCompany(ExplorerCore.AUTHOR)] +[assembly: AssemblyProduct(ExplorerCore.NAME)] [assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/src/Tests/TestClass.cs b/src/Tests/TestClass.cs index 92cccb2d..512cec2e 100644 --- a/src/Tests/TestClass.cs +++ b/src/Tests/TestClass.cs @@ -4,7 +4,6 @@ using UnityEngine; using System.Reflection; using System.Collections.Specialized; -using MelonLoader; // used to test multiple generic constraints public class TestGeneric : IComparable @@ -44,12 +43,18 @@ public class TestClass public static TestClass Instance => m_instance ?? (m_instance = new TestClass()); private static TestClass m_instance; +#if CPP + public static Il2CppSystem.Collections.Generic.HashSet ILHashSetTest; +#endif + public TestClass() { +#if CPP ILHashSetTest = new Il2CppSystem.Collections.Generic.HashSet(); ILHashSetTest.Add("1"); ILHashSetTest.Add("2"); ILHashSetTest.Add("3"); +#endif testBitmask = 1 | 2; } @@ -109,7 +114,6 @@ public Hashtable TestNonGenericDict() "Three" }; - public static Il2CppSystem.Collections.Generic.HashSet ILHashSetTest; // Test indexed parameter diff --git a/src/UnstripFixes/GUIUnstrip.cs b/src/UnstripFixes/GUIUnstrip.cs index 82703cae..673bfbfb 100644 --- a/src/UnstripFixes/GUIUnstrip.cs +++ b/src/UnstripFixes/GUIUnstrip.cs @@ -1,14 +1,16 @@ using System; using System.Reflection; -using MelonLoader; -using UnhollowerRuntimeLib; using UnityEngine; +#if CPP using UnityEngineInternal; +using UnhollowerRuntimeLib; +#endif namespace Explorer { public class GUIUnstrip { +#if CPP public static int s_ScrollControlId; public static bool ScrollFailed = false; @@ -19,6 +21,12 @@ public class GUIUnstrip private static GenericStack m_scrollStack; public static DateTime nextScrollStepTime; + + private static MethodInfo ScreenToGuiPointMethod; + private static bool m_screenToGuiAttemped; + + private static MethodInfo m_bringWindowToFrontMethod; + private static bool m_bringWindowFrontAttempted; private static GenericStack GetScrollStack() { @@ -45,11 +53,75 @@ private static GenericStack GetScrollStack() return m_scrollStack; } +#endif - public static void Space(float pixels) + public static Rect Window(int id, Rect rect, GUI.WindowFunction windowFunc, string title) { - GUIUtility.CheckOnGUI(); +#if CPP + return GUI.Window(id, rect, windowFunc, GUIContent.Temp(title), GUI.skin.window); +#else + return GUI.Window(id, rect, windowFunc, title); +#endif + } + + public static bool Button(Rect rect, string title) + { +#if CPP + return GUI.Button(rect, GUIContent.Temp(title), GUI.skin.button); +#else + return GUI.Button(rect, title); +#endif + } + + public static string TextArea(string text, params GUILayoutOption[] options) + { +#if CPP + return GUILayout.DoTextField(text, -1, true, GUI.skin.textArea, options); +#else + return GUILayout.TextArea(text, options); +#endif + } + + public static void BringWindowToFront(int id) + { +#if CPP + if (!m_bringWindowFrontAttempted) + { + m_bringWindowFrontAttempted = true; + m_bringWindowToFrontMethod = typeof(GUI).GetMethod("BringWindowToFront"); + } + if (m_bringWindowToFrontMethod == null) + { + throw new Exception("Couldn't get method 'GUIUtility.BringWindowToFront'!"); + } + m_bringWindowToFrontMethod.Invoke(null, new object[] { id }); +#else + GUI.BringWindowToFront(id); +#endif + } + + public static Vector2 ScreenToGUIPoint(Vector2 screenPoint) + { +#if CPP + if (!m_screenToGuiAttemped) + { + m_screenToGuiAttemped = true; + ScreenToGuiPointMethod = typeof(GUIUtility).GetMethod("ScreenToGUIPoint"); + } + if (ScreenToGuiPointMethod == null) + { + throw new Exception("Couldn't get method 'GUIUtility.ScreenToGUIPoint'!"); + } + return (Vector2)ScreenToGuiPointMethod.Invoke(null, new object[] { screenPoint }); +#else + return GUIUtility.ScreenToGUIPoint(screenPoint); +#endif + } + + public static void Space(float pixels) + { +#if CPP if (GUILayoutUtility.current.topLevel.isVertical) LayoutUtilityUnstrip.GetRect(0, pixels, GUILayoutUtility.spaceStyle, new GUILayoutOption[] { GUILayout.Height(pixels) }); else @@ -59,31 +131,47 @@ public static void Space(float pixels) { GUILayoutUtility.current.topLevel.entries[GUILayoutUtility.current.topLevel.entries.Count - 1].consideredForMargin = false; } +#else + GUILayout.Space(pixels); +#endif } // fix for repeatbutton +#if CPP +#if ML static public bool RepeatButton(Texture image, params GUILayoutOption[] options) { return DoRepeatButton(GUIContent.Temp(image), GUI.skin.button, options); } - static public bool RepeatButton(string text, params GUILayoutOption[] options) { return DoRepeatButton(GUIContent.Temp(text), GUI.skin.button, options); } static public bool RepeatButton(GUIContent content, params GUILayoutOption[] options) { return DoRepeatButton(content, GUI.skin.button, options); } static public bool RepeatButton(Texture image, GUIStyle style, params GUILayoutOption[] options) { return DoRepeatButton(GUIContent.Temp(image), style, options); } - static public bool RepeatButton(string text, GUIStyle style, params GUILayoutOption[] options) { return DoRepeatButton(GUIContent.Temp(text), style, options); } // Make a repeating button. The button returns true as long as the user holds down the mouse +#endif + static public bool RepeatButton(string text, params GUILayoutOption[] options) { return DoRepeatButton(GUIContent.Temp(text), GUI.skin.button, options); } static public bool RepeatButton(GUIContent content, GUIStyle style, params GUILayoutOption[] options) { return DoRepeatButton(content, style, options); } static bool DoRepeatButton(GUIContent content, GUIStyle style, GUILayoutOption[] options) - { return GUI.RepeatButton(LayoutUtilityUnstrip.GetRect(content, style, options), content, style); } + { + return GUI.DoRepeatButton(LayoutUtilityUnstrip.GetRect(content, style, options), content, style, FocusType.Passive); + } +#else // mono + public static bool RepeatButton(string text, params GUILayoutOption[] args) + { + return GUILayout.RepeatButton(text, args); + } +#endif // Fix for BeginArea +#if CPP +#if ML static public void BeginArea(Rect screenRect) { BeginArea(screenRect, GUIContent.none, GUIStyle.none); } static public void BeginArea(Rect screenRect, string text) { BeginArea(screenRect, GUIContent.Temp(text), GUIStyle.none); } static public void BeginArea(Rect screenRect, Texture image) { BeginArea(screenRect, GUIContent.Temp(image), GUIStyle.none); } static public void BeginArea(Rect screenRect, GUIContent content) { BeginArea(screenRect, content, GUIStyle.none); } - static public void BeginArea(Rect screenRect, GUIStyle style) { BeginArea(screenRect, GUIContent.none, style); } static public void BeginArea(Rect screenRect, string text, GUIStyle style) { BeginArea(screenRect, GUIContent.Temp(text), style); } static public void BeginArea(Rect screenRect, Texture image, GUIStyle style) { BeginArea(screenRect, GUIContent.Temp(image), style); } +#endif + + static public void BeginArea(Rect screenRect, GUIStyle style) { BeginArea(screenRect, GUIContent.none, style); } - // Begin a GUILayout block of GUI controls in a fixed screen area. static public void BeginArea(Rect screenRect, GUIContent content, GUIStyle style) { GUILayoutGroup g = GUILayoutUtility.BeginLayoutArea(style, Il2CppType.Of()); @@ -97,8 +185,15 @@ static public void BeginArea(Rect screenRect, GUIContent content, GUIStyle style GUI.BeginGroup(g.rect, content, style); } +#else + public static void BeginArea(Rect rect, GUIStyle skin) + { + GUILayout.BeginArea(rect, skin); + } +#endif // Close a GUILayout block started with BeginArea +#if CPP static public void EndArea() { if (Event.current.type == EventType.Used) @@ -107,9 +202,17 @@ static public void EndArea() GUILayoutUtility.current.topLevel = GUILayoutUtility.current.layoutGroups.Peek().TryCast(); GUI.EndGroup(); } +#else + public static void EndArea() + { + GUILayout.EndArea(); + } +#endif // Fix for BeginGroup +#if CPP +#if ML public static void BeginGroup(Rect position) { BeginGroup(position, GUIContent.none, GUIStyle.none); } public static void BeginGroup(Rect position, string text) { BeginGroup(position, GUIContent.Temp(text), GUIStyle.none); } public static void BeginGroup(Rect position, Texture image) { BeginGroup(position, GUIContent.Temp(image), GUIStyle.none); } @@ -117,7 +220,8 @@ static public void EndArea() public static void BeginGroup(Rect position, GUIStyle style) { BeginGroup(position, GUIContent.none, style); } public static void BeginGroup(Rect position, string text, GUIStyle style) { BeginGroup(position, GUIContent.Temp(text), style); } public static void BeginGroup(Rect position, Texture image, GUIStyle style) { BeginGroup(position, GUIContent.Temp(image), style); } - + +#endif public static void BeginGroup(Rect position, GUIContent content, GUIStyle style) { BeginGroup(position, content, style, Vector2.zero); } internal static void BeginGroup(Rect position, GUIContent content, GUIStyle style, Vector2 scrollOffset) @@ -139,14 +243,28 @@ internal static void BeginGroup(Rect position, GUIContent content, GUIStyle styl } GUIClip.Push(position, scrollOffset, Vector2.zero, false); } +#else + public static void BeginGroup(Rect rect, GUIStyle style) + { + GUI.BeginGroup(rect, style); + } +#endif +#if CPP public static void EndGroup() { GUIClip.Internal_Pop(); } +#else + public static void EndGroup() + { + GUI.EndGroup(); + } +#endif // Fix for BeginScrollView. +#if CPP public static Vector2 BeginScrollView(Vector2 scroll, params GUILayoutOption[] options) { // First, just try normal way, may not have been stripped or was unstripped successfully. @@ -171,7 +289,7 @@ public static Vector2 BeginScrollView(Vector2 scroll, params GUILayoutOption[] o } catch (Exception e) { - MelonLogger.Log("Exception on manual BeginScrollView: " + e.GetType() + ", " + e.Message + "\r\n" + e.StackTrace); + ExplorerCore.Log("Exception on manual BeginScrollView: " + e.GetType() + ", " + e.Message + "\r\n" + e.StackTrace); ManualUnstripFailed = true; } } @@ -196,7 +314,7 @@ public static void EndScrollView(bool handleScrollWheel = true) } } - private static Vector2 BeginScrollView_ImplLayout(Vector2 scrollPosition, bool alwaysShowHorizontal, bool alwaysShowVertical, + private static Vector2 BeginScrollView_ImplLayout(Vector2 scrollPosition, bool alwaysShowHorizontal, bool alwaysShowVertical, GUIStyle horizontalScrollbar, GUIStyle verticalScrollbar, GUIStyle background, params GUILayoutOption[] options) { var guiscrollGroup = GUILayoutUtility.BeginLayoutGroup(background, null, Il2CppType.Of()) @@ -227,7 +345,7 @@ private static Vector2 BeginScrollView_ImplLayout(Vector2 scrollPosition, bool a ); } - private static Vector2 BeginScrollView_Impl(Rect position, Vector2 scrollPosition, Rect viewRect, bool alwaysShowHorizontal, + private static Vector2 BeginScrollView_Impl(Rect position, Vector2 scrollPosition, Rect viewRect, bool alwaysShowHorizontal, bool alwaysShowVertical, GUIStyle horizontalScrollbar, GUIStyle verticalScrollbar, GUIStyle background) { // GUIUtility.CheckOnGUI(); @@ -487,5 +605,16 @@ private static bool ScrollerRepeatButton_Impl(int scrollerID, Rect rect, GUIStyl } return result; } +#else + public static Vector2 BeginScrollView(Vector2 scroll, params GUILayoutOption[] options) + { + return GUILayout.BeginScrollView(scroll, options); + } + + public static void EndScrollView() + { + GUILayout.EndScrollView(); + } +#endif } -} +} \ No newline at end of file diff --git a/src/UnstripFixes/LayoutUtilityUnstrip.cs b/src/UnstripFixes/LayoutUtilityUnstrip.cs index e75e3ad7..466c8f1c 100644 --- a/src/UnstripFixes/LayoutUtilityUnstrip.cs +++ b/src/UnstripFixes/LayoutUtilityUnstrip.cs @@ -4,6 +4,7 @@ namespace Explorer { public class LayoutUtilityUnstrip { +#if CPP public static Rect GetRect(float width, float height) { return DoGetRect(width, width, height, height, GUIStyle.none, null); } public static Rect GetRect(float width, float height, GUIStyle style) { return DoGetRect(width, width, height, height, style, null); } public static Rect GetRect(float width, float height, params GUILayoutOption[] options) { return DoGetRect(width, width, height, height, GUIStyle.none, options); } @@ -102,6 +103,12 @@ public static Rect GetLastRect() last = GUILayoutUtility.kDummyRect; } return last; + } +#else + public static Rect GetLastRect() + { + return GUILayoutUtility.GetLastRect(); } +#endif } -} +} \ No newline at end of file diff --git a/src/UnstripFixes/ScrollViewStateUnstrip.cs b/src/UnstripFixes/ScrollViewStateUnstrip.cs index c7d27f04..2e735b33 100644 --- a/src/UnstripFixes/ScrollViewStateUnstrip.cs +++ b/src/UnstripFixes/ScrollViewStateUnstrip.cs @@ -1,4 +1,5 @@ -using System; +#if CPP +using System; using System.Collections.Generic; using UnityEngine; @@ -25,3 +26,5 @@ public static ScrollViewStateUnstrip FromPointer(IntPtr ptr) } } } + +#endif \ No newline at end of file diff --git a/src/UnstripFixes/SliderHandlerUnstrip.cs b/src/UnstripFixes/SliderHandlerUnstrip.cs index e61d0e0e..c00087dd 100644 --- a/src/UnstripFixes/SliderHandlerUnstrip.cs +++ b/src/UnstripFixes/SliderHandlerUnstrip.cs @@ -1,4 +1,5 @@ -using System; +#if CPP +using System; using UnhollowerRuntimeLib; using UnityEngine; @@ -365,3 +366,4 @@ private float MinValue() } } +#endif \ No newline at end of file diff --git a/src/UnstripFixes/UnstripExtensions.cs b/src/UnstripFixes/UnstripExtensions.cs index 7a0e1741..c94e597c 100644 --- a/src/UnstripFixes/UnstripExtensions.cs +++ b/src/UnstripFixes/UnstripExtensions.cs @@ -1,4 +1,5 @@ -using UnityEngine; +#if CPP +using UnityEngine; namespace Explorer { @@ -20,3 +21,4 @@ public static Rect GetLastUnstripped(this GUILayoutGroup group) } } } +#endif \ No newline at end of file