Exemplo n.º 1
0
        /// <summary>
        /// Logs all failed asserts to the error log.
        /// </summary>
        private static void LogAllFailedAsserts()
        {
            var handler = new HarmonyMethod(typeof(DebugLogger), nameof(DebugLogger.
                                                                        OnAssertFailed));
            var        inst = ModDebugRegistry.Instance.DebugInstance;
            MethodInfo assert;

            try {
                // Assert(bool)
                assert = typeof(Debug).GetMethodSafe("Assert", true, typeof(bool));
                if (assert != null)
                {
                    inst.Patch(assert, handler);
                }
                // Assert(bool, object)
                assert = typeof(Debug).GetMethodSafe("Assert", true, typeof(bool), typeof(
                                                         object));
                if (assert != null)
                {
                    inst.Patch(assert, handler);
                }
                // Assert(bool, object, UnityEngine.Object)
                assert = typeof(Debug).GetMethodSafe("Assert", true, typeof(bool), typeof(
                                                         object), typeof(UnityEngine.Object));
                if (assert != null)
                {
                    inst.Patch(assert, handler);
                }
                // Assert(bool, string)
                assert = typeof(KCrashReporter).GetMethodSafe("Assert", true, typeof(bool),
                                                              typeof(string));
                if (assert != null)
                {
                    inst.Patch(assert, handler);
                }
#if DEBUG
                DebugLogger.LogDebug("Logging all failed asserts");
#endif
            } catch (Exception e) {
                DebugLogger.BaseLogException(e, null);
            }
        }
Exemplo n.º 2
0
            /// <summary>
            /// Applied before OnPrefabInit runs.
            /// </summary>
            internal static MethodBase TargetMethod()
            {
                MethodBase target = null;

#if DEBUG
                DebugLogger.LogDebug("Transpiling LoadDLLs()");
#endif
                try {
                    target = typeof(Mod).Assembly.GetType("KMod.DLLLoader", false)?.
                             GetMethodSafe("LoadDLLs", true, PPatchTools.AnyArguments);
                    if (target == null)
                    {
                        DebugLogger.LogError("Unable to transpile LoadDLLs: Method not found");
                    }
                } catch (IOException e) {
                    // This should theoretically be impossible since the type is loaded
                    DebugLogger.BaseLogException(e, null);
                }
                return(target);
            }