예제 #1
0
        public override void OnApplicationStart()
        {
            Instance       = this;
            _configHandler = new MelonLoaderConfigHandler();

            ExplorerCore.Init(this);
        }
예제 #2
0
        internal void Init()
        {
            Instance      = this;
            configHandler = new StandaloneConfigHandler();

            ExplorerCore.Init(this);
        }
 public static void Prefix(TextRenderer __instance)
 {
     if (__instance.gameObject.name == "ExplorerBehaviour")
     {
         ExplorerCore.Update();
     }
 }
예제 #4
0
 public void SetupPatches()
 {
     try
     {
         this.HarmonyInstance.PatchAll();
     }
     catch (Exception ex)
     {
         ExplorerCore.Log($"Exception setting up Harmony patches:\r\n{ex.ReflectionExToString()}");
     }
 }
예제 #5
0
 private void PrefixProperty(Type type, string property, HarmonyMethod prefix)
 {
     try
     {
         var prop = type.GetProperty(property);
         this.Harmony.Patch(prop.GetSetMethod(), prefix: prefix);
     }
     catch (Exception e)
     {
         ExplorerCore.Log($"Unable to patch {type.Name}.set_{property}: {e.Message}");
     }
 }
예제 #6
0
        internal override Type Internal_GetActualType(object obj)
        {
            if (obj == null)
            {
                return(null);
            }

            var type = obj.GetType();

            try
            {
                if (IsString(obj))
                {
                    return(typeof(string));
                }

                if (IsIl2CppPrimitive(type))
                {
                    return(il2cppPrimitivesToMono[type.FullName]);
                }

                if (obj is Il2CppSystem.Object cppObject)
                {
                    var cppType = cppObject.GetIl2CppType();

                    // check if type is injected
                    IntPtr classPtr = il2cpp_object_get_class(cppObject.Pointer);
                    if (RuntimeSpecificsStore.IsInjected(classPtr))
                    {
                        // Note: This will fail on injected subclasses.
                        // - {Namespace}.{Class}.{Subclass} would be {Namespace}.{Subclass} when injected.
                        // Not sure on solution yet.
                        return(GetTypeByName(cppType.FullName) ?? type);
                    }

                    if (AllTypes.TryGetValue(cppType.FullName, out Type primitive) && primitive.IsPrimitive)
                    {
                        return(primitive);
                    }

                    return(GetUnhollowedType(cppType) ?? type);
                }
            }
            catch (Exception ex)
            {
                ExplorerCore.LogWarning("Exception in IL2CPP GetActualType: " + ex);
            }

            return(type);
        }
예제 #7
0
        private void Init()
        {
            Instance       = this;
            _configHandler = new StandaloneConfigHandler();

#if CPP
            ClassInjector.RegisterTypeInIl2Cpp <ExplorerBehaviour>();
#endif
            var obj = new GameObject("ExplorerBehaviour");
            obj.AddComponent <ExplorerBehaviour>();

            GameObject.DontDestroyOnLoad(obj);
            obj.hideFlags = HideFlags.HideAndDontSave;

            ExplorerCore.Init(this);
        }
예제 #8
0
        private static void BuildDeobfuscationCache()
        {
            float start = UnityEngine.Time.realtimeSinceStartup;

            foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (var type in asm.TryGetTypes())
                {
                    TryCacheDeobfuscatedType(type);
                }
            }

            if (DeobfuscatedTypes.Count > 0)
            {
                ExplorerCore.Log($"Built deobfuscation cache in {UnityEngine.Time.realtimeSinceStartup - start} seconds, " +
                                 $"initial count: {DeobfuscatedTypes.Count} ");
            }
        }
예제 #9
0
        public static string ToStringForInput(object obj, Type type)
        {
            if (type == null || obj == null)
            {
                return(null);
            }

            if (type == typeof(string))
            {
                return(obj as string);
            }

            if (type.IsEnum)
            {
                return(Enum.IsDefined(type, obj)
                        ? Enum.GetName(type, obj)
                        : obj.ToString());
            }

            try
            {
                if (customTypes.ContainsKey(type.FullName))
                {
                    return(customTypesToString[type.FullName].Invoke(obj));
                }
                else if (formattedTypes.Contains(type))
                {
                    return(ReflectionUtility.GetMethodInfo(type, "ToString", new Type[] { typeof(string), typeof(IFormatProvider) })
                           .Invoke(obj, new object[] { NUMBER_FORMAT, en_US })
                           as string);
                }
                else
                {
                    return(obj.ToString());
                }
            }
            catch (Exception ex)
            {
                ExplorerCore.LogWarning($"Exception formatting object for input: {ex}");
                return(null);
            }
        }
예제 #10
0
        public void SetupCursorPatches()
        {
            try
            {
                PrefixProperty(typeof(Cursor),
                               "lockState",
                               new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_set_lockState))));

                PrefixProperty(typeof(Cursor),
                               "visible",
                               new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_set_visible))));

                PrefixProperty(typeof(EventSystem),
                               "current",
                               new HarmonyMethod(typeof(CursorUnlocker).GetMethod(nameof(CursorUnlocker.Prefix_EventSystem_set_current))));
            }
            catch (Exception ex)
            {
                ExplorerCore.Log($"Exception setting up Harmony patches:\r\n{ex.ReflectionExToString()}");
            }
        }
예제 #11
0
        private void Init()
        {
            Instance       = this;
            _configHandler = new StandaloneConfigHandler();

#if CPP
            ClassInjector.RegisterTypeInIl2Cpp <ExplorerBehaviour>();

            var obj = new GameObject(
                "ExplorerBehaviour",
                new Il2CppSystem.Type[] { Il2CppType.Of <ExplorerBehaviour>() }
                );
#else
            var obj = new GameObject(
                "ExplorerBehaviour",
                new Type[] { typeof(ExplorerBehaviour) }
                );
#endif

            GameObject.DontDestroyOnLoad(obj);
            obj.hideFlags = HideFlags.HideAndDontSave;

            ExplorerCore.Init(this);
        }
예제 #12
0
 public override void OnUpdate()
 {
     ExplorerCore.Update();
 }
예제 #13
0
 internal void Update()
 {
     ExplorerCore.Update();
 }
예제 #14
0
 internal static void OnPostRender(Camera _)
 {
     ExplorerCore.OnPostRender();
 }
예제 #15
0
 internal void FixedUpdate()
 {
     ExplorerCore.FixedUpdate();
 }