示例#1
0
        public static string GetExampleInput(Type type)
        {
            if (!typeInputExamples.ContainsKey(type.AssemblyQualifiedName))
            {
                try
                {
                    if (type.IsEnum)
                    {
                        typeInputExamples.Add(type.AssemblyQualifiedName, Enum.GetNames(type).First());
                    }
                    else
                    {
                        var instance = Activator.CreateInstance(type);
                        typeInputExamples.Add(type.AssemblyQualifiedName, ToStringForInput(instance, type));
                    }
                }
                catch (Exception ex)
                {
                    ExplorerCore.LogWarning("Exception generating default instance for example input for '" + type.FullName + "'");
                    ExplorerCore.Log(ex);
                    return("");
                }
            }

            return(typeInputExamples[type.AssemblyQualifiedName]);
        }
示例#2
0
 public void SetupPatches()
 {
     try
     {
         this.HarmonyInstance.PatchAll();
     }
     catch (Exception ex)
     {
         ExplorerCore.Log($"Exception setting up Harmony patches:\r\n{ex.ReflectionExToString()}");
     }
 }
示例#3
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}");
     }
 }
        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} ");
            }
        }
        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()}");
            }
        }