diff --git a/src/CachedObjects/Object/CacheDictionary.cs b/src/CachedObjects/Object/CacheDictionary.cs index 7623d89..4f13897 100644 --- a/src/CachedObjects/Object/CacheDictionary.cs +++ b/src/CachedObjects/Object/CacheDictionary.cs @@ -172,80 +172,22 @@ namespace Explorer { try { - //var ilTypes = new List(); - var monoTypes = new Type[] { TypeOfKeys, TypeOfValues }; + return Check(TypeOfKeys) && Check(TypeOfValues); - foreach (var type in monoTypes) + bool Check(Type type) { - var generic = typeof(Il2CppClassPointerStore<>).MakeGenericType(type); - if (generic == null) return false; + var ptr = (IntPtr)typeof(Il2CppClassPointerStore<>) + .MakeGenericType(type) + .GetField("NativeClassPtr") + .GetValue(null); - var genericPtr = (IntPtr)generic.GetField("NativeClassPtr").GetValue(null); - if (genericPtr == null) return false; - - var classPtr = IL2CPP.il2cpp_class_get_type(genericPtr); - if (classPtr == null) return false; - - var internalType = Il2CppSystem.Type.internal_from_handle(classPtr); - if (internalType == null) return false; - - //ilTypes.Add(internalType); + return Il2CppSystem.Type.internal_from_handle(IL2CPP.il2cpp_class_get_type(ptr)) is Il2CppSystem.Type; } } catch { return false; } - - // Should be fine if we got this far, but I'll leave the rest below commented out just in case. - return true; - - //MelonLogger.Log("Got both generic types, continuing..."); - - //var dictIlClass = IL2CPP.GetIl2CppClass("mscorlib.dll", "System.Collections.Generic", "Dictionary`2"); - //if (dictIlClass == null) return; - - //MelonLogger.Log("Got base dictionary Il2Cpp type"); - - //var ilClassFromType = IL2CPP.il2cpp_class_get_type(dictIlClass); - //if (ilClassFromType == null) return; - - //MelonLogger.Log("got IntPtr from base dictionary type"); - - //var internalHandle = Il2CppSystem.Type.internal_from_handle(ilClassFromType); - //if (internalHandle == null) return; - - //var generic = internalHandle.MakeGenericType(new Il2CppReferenceArray(new Il2CppSystem.Type[] - //{ - // ilTypes[0], ilTypes[1] - //})); - //if (generic == null) return; - - //MelonLogger.Log("Made generic handle for our entry types"); - - //var nativeClassPtr = generic.TypeHandle.value; - //if (nativeClassPtr == null) return; - - //MelonLogger.Log("Got the actual nativeClassPtr for the handle"); - - //var dictType = typeof(Il2CppSystem.Collections.Generic.Dictionary<,>).MakeGenericType(TypeOfKeys, TypeOfValues); - //if (dictType == null) return; - - //MelonLogger.Log("Made the generic type for the dictionary"); - - //var pointerStoreType = typeof(Il2CppClassPointerStore<>).MakeGenericType(dictType); - //if (pointerStoreType == null) return; - - //MelonLogger.Log("Made the generic PointerStoreType for our dict"); - - //var ptrToSet = IL2CPP.il2cpp_class_from_type(nativeClassPtr); - //if (ptrToSet == null) return; - - //MelonLogger.Log("Got class from nativeClassPtr, setting value..."); - - //pointerStoreType.GetField("NativeClassPtr").SetValue(null, ptrToSet); - - //MelonLogger.Log("Ok"); } // ============= GUI Draw ============= diff --git a/src/CppExplorer.cs b/src/CppExplorer.cs index 4b6adec..761b5cf 100644 --- a/src/CppExplorer.cs +++ b/src/CppExplorer.cs @@ -12,15 +12,10 @@ namespace Explorer { public class CppExplorer : MelonMod { - public const string GUID = "com.sinai.cppexplorer"; - public const string VERSION = "1.6.2"; - public const string AUTHOR = "Sinai"; - - public const string NAME = "CppExplorer" -#if Release_Unity2018 - + " (Unity 2018)" -#endif - ; + public const string NAME = "CppExplorer"; + public const string VERSION = "1.6.3"; + public const string AUTHOR = "Sinai"; + public const string GUID = "com.sinai.cppexplorer"; public static CppExplorer Instance { get; private set; } @@ -79,7 +74,7 @@ namespace Explorer public override void OnUpdate() { // Check main toggle key input - if (Input.GetKeyDown(KeyCode.F7)) + if (InputHelper.GetKeyDown(KeyCode.F7)) { ShowMenu = !ShowMenu; } @@ -87,7 +82,7 @@ namespace Explorer if (ShowMenu) { // Check Force-Unlock input - if (Input.GetKeyDown(KeyCode.LeftAlt)) + if (InputHelper.GetKeyDown(KeyCode.LeftAlt)) { ForceUnlockMouse = !ForceUnlockMouse; } diff --git a/src/CppExplorer.csproj b/src/CppExplorer.csproj index 5c9711d..5ae78f1 100644 --- a/src/CppExplorer.csproj +++ b/src/CppExplorer.csproj @@ -2,7 +2,7 @@ - Debug + Release AnyCPU {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D} Library @@ -11,32 +11,18 @@ v4.7.2 512 true - - - + CppExplorer false none false - ..\Release\2019\ - Release_2019 + ..\Release\ + prompt 4 x64 false - - - CppExplorer_Unity2018 - false - none - false - ..\Release\2018\ - Release_Unity2018 - prompt - 4 - x64 - false - + ..\..\..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\Il2Cppmscorlib.dll @@ -60,64 +46,31 @@ ..\..\..\..\..\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.InputLegacyModule.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 - - - ..\..\..\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.dll - False - - - ..\..\..\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.CoreModule.dll - False - - - ..\..\..\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.IMGUIModule.dll - False - - - ..\..\..\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.InputModule.dll - False - - - ..\..\..\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.PhysicsModule.dll - False - - - ..\..\..\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.TextRenderingModule.dll - False - - - ..\..\..\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.UI.dll - False - @@ -134,6 +87,7 @@ + diff --git a/src/CppExplorer.sln b/src/CppExplorer.sln index 191809c..fd5cdd3 100644 --- a/src/CppExplorer.sln +++ b/src/CppExplorer.sln @@ -7,14 +7,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CppExplorer", "CppExplorer. EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release_Unity2018|Any CPU = Release_Unity2018|Any CPU + Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release_Unity2018|Any CPU.ActiveCfg = Release_Unity2018|Any CPU - {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release_Unity2018|Any CPU.Build.0 = Release_Unity2018|Any CPU + {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Helpers/InputHelper.cs b/src/Helpers/InputHelper.cs new file mode 100644 index 0000000..e477a82 --- /dev/null +++ b/src/Helpers/InputHelper.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Reflection; +using UnityEngine; + +namespace Explorer +{ + /// + /// Version-agnostic UnityEngine.Input module using Reflection + /// + public class InputHelper + { + private static readonly Type input = ReflectionHelpers.GetTypeByName("UnityEngine.Input"); + + private static readonly PropertyInfo mousePositionInfo = input.GetProperty("mousePosition"); + + private static readonly MethodInfo getKey = input.GetMethod("GetKey", new Type[] { typeof(KeyCode) }); + private static readonly MethodInfo getKeyDown = input.GetMethod("GetKeyDown", new Type[] { typeof(KeyCode) }); + private static readonly MethodInfo getMouseButtonDown = input.GetMethod("GetMouseButtonDown", new Type[] { typeof(int) }); + private static readonly MethodInfo getMouseButton = input.GetMethod("GetMouseButton", new Type[] { typeof(int) }); + +#pragma warning disable IDE1006 // Camel-case property (Unity style) + public static Vector3 mousePosition => (Vector3)mousePositionInfo.GetValue(null); +#pragma warning restore IDE1006 + + public static bool GetKeyDown(KeyCode key) + { + return (bool)getKeyDown.Invoke(null, new object[] { key }); + } + + public static bool GetKey(KeyCode key) + { + return (bool)getKey.Invoke(null, new object[] { key }); + } + + /// 1 = left, 2 = middle, 3 = right, etc + public static bool GetMouseButtonDown(int btn) + { + return (bool)getMouseButtonDown.Invoke(null, new object[] { btn }); + } + + /// 1 = left, 2 = middle, 3 = right, etc + public static bool GetMouseButton(int btn) + { + return (bool)getMouseButton.Invoke(null, new object[] { btn }); + } + } +} diff --git a/src/Helpers/ReflectionHelpers.cs b/src/Helpers/ReflectionHelpers.cs index e1126ac..47c30bf 100644 --- a/src/Helpers/ReflectionHelpers.cs +++ b/src/Helpers/ReflectionHelpers.cs @@ -113,13 +113,13 @@ namespace Explorer } } - public static Type GetTypeByName(string typeName) + public static Type GetTypeByName(string fullName) { foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { foreach (var type in GetTypesSafe(asm)) { - if (type.FullName == typeName) + if (type.FullName == fullName) { return type; } diff --git a/src/Helpers/UnityHelpers.cs b/src/Helpers/UnityHelpers.cs index 5bccf64..727dea7 100644 --- a/src/Helpers/UnityHelpers.cs +++ b/src/Helpers/UnityHelpers.cs @@ -15,7 +15,7 @@ namespace Explorer { get { - if (m_mainCamera == null) + if (!m_mainCamera) { m_mainCamera = Camera.main; } diff --git a/src/MainMenu/InspectUnderMouse.cs b/src/MainMenu/InspectUnderMouse.cs index fd1ef65..5adc6cd 100644 --- a/src/MainMenu/InspectUnderMouse.cs +++ b/src/MainMenu/InspectUnderMouse.cs @@ -17,7 +17,7 @@ namespace Explorer { if (CppExplorer.ShowMenu) { - if (Input.GetKey(KeyCode.LeftShift) && Input.GetMouseButtonDown(1)) + if (InputHelper.GetKey(KeyCode.LeftShift) && InputHelper.GetMouseButtonDown(1)) { EnableInspect = !EnableInspect; } @@ -35,7 +35,10 @@ namespace Explorer public static void InspectRaycast() { - Ray ray = UnityHelpers.MainCamera.ScreenPointToRay(Input.mousePosition); + if (!UnityHelpers.MainCamera) + return; + + var ray = UnityHelpers.MainCamera.ScreenPointToRay(InputHelper.mousePosition); if (Physics.Raycast(ray, out RaycastHit hit, 1000f)) { @@ -43,7 +46,7 @@ namespace Explorer m_objUnderMouseName = obj.transform.GetGameObjectPath(); - if (Input.GetMouseButtonDown(0)) + if (InputHelper.GetMouseButtonDown(0)) { EnableInspect = false; m_objUnderMouseName = ""; @@ -63,7 +66,7 @@ namespace Explorer { if (m_objUnderMouseName != "") { - var pos = Input.mousePosition; + var pos = InputHelper.mousePosition; var rect = new Rect( pos.x - (Screen.width / 2), // x Screen.height - pos.y - 50, // y diff --git a/src/Windows/ResizeDrag.cs b/src/Windows/ResizeDrag.cs index a16554c..1ca0b38 100644 --- a/src/Windows/ResizeDrag.cs +++ b/src/Windows/ResizeDrag.cs @@ -34,15 +34,17 @@ namespace Explorer //var r = GUILayoutUtility.GetLastRect(); var r = GUIUnstrip.GetLastRect(); - Vector2 mouse = GUIUtility.ScreenToGUIPoint(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)); + var mousePos = InputHelper.mousePosition; - if (r.Contains(mouse) && Input.GetMouseButtonDown(0)) + Vector2 mouse = GUIUtility.ScreenToGUIPoint(new Vector2(mousePos.x, Screen.height - mousePos.y)); + + if (r.Contains(mouse) && InputHelper.GetMouseButtonDown(0)) { isResizing = true; m_currentWindow = ID; m_currentResize = new Rect(mouse.x, mouse.y, _rect.width, _rect.height); } - else if (!Input.GetMouseButton(0)) + else if (!InputHelper.GetMouseButton(0)) { isResizing = false; } diff --git a/src/Windows/WindowManager.cs b/src/Windows/WindowManager.cs index fd8f36a..dea61c3 100644 --- a/src/Windows/WindowManager.cs +++ b/src/Windows/WindowManager.cs @@ -90,7 +90,7 @@ namespace Explorer { createdNew = false; - if (Input.GetKey(KeyCode.LeftShift)) + if (InputHelper.GetKey(KeyCode.LeftShift)) { forceReflection = true; } @@ -192,7 +192,8 @@ namespace Explorer private static bool RectContainsMouse(Rect rect) { - return rect.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)); + var mousePos = InputHelper.mousePosition; + return rect.Contains(new Vector2(mousePos.x, Screen.height - mousePos.y)); } public static int NextWindowID()