Example #1
0
        /// <summary>
        /// Opens the output log file.
        /// </summary>
        internal static void OpenOutputLog()
        {
            // Ugly but true!
            var    platform = Application.platform;
            string path     = "";

            switch (platform)
            {
            case RuntimePlatform.OSXPlayer:
            case RuntimePlatform.OSXEditor:
                // https://answers.unity.com/questions/1484445/how-do-i-find-the-player-log-file-from-code.html
                path = "~/Library/Logs/Unity/Player.log";
                break;

            case RuntimePlatform.LinuxEditor:
            case RuntimePlatform.LinuxPlayer:
                path = Path.Combine("~/.config/unity3d", Application.companyName, Application.
                                    productName, "Player.log");
                break;

            case RuntimePlatform.WindowsEditor:
            case RuntimePlatform.WindowsPlayer:
                path = Path.Combine(Environment.GetEnvironmentVariable("AppData"),
                                    "..", "LocalLow", Application.companyName, Application.productName,
                                    "Player.log");
                break;

            default:
                DebugLogger.LogWarning("Unable to open the output log on: {0}", platform);
                break;
            }
            if (!string.IsNullOrEmpty(path))
            {
                Application.OpenURL(Path.GetFullPath(path));
            }
        }
Example #2
0
 /// <summary>
 /// Applied after CreateSound runs.
 /// </summary>
 internal static void Postfix(string file_name, string anim_name, string sound_name)
 {
     // Add sound "GasPump_intake" to anim pumpgas_kanim.working_loop
     DebugLogger.LogDebug("Add sound \"{0}\" to anim {1}.{2}".F(sound_name,
                                                                file_name, anim_name));
 }
Example #3
0
 /// <summary>
 /// Applied after AddKAnimMod runs.
 /// </summary>
 internal static void Postfix(string name)
 {
     DebugLogger.LogDebug("Adding anim \"{0}\"", name);
 }
Example #4
0
 /// <summary>
 /// Applied before LogException runs.
 /// </summary>
 internal static bool Prefix(Exception e, string errorMessage)
 {
     DebugLogger.LogError(errorMessage);
     DebugLogger.LogException(e);
     return(false);
 }
Example #5
0
 /// <summary>
 /// A postfix method for instrumenting methods in the code base. Logs the total time
 /// taken in milliseconds.
 /// </summary>
 private static void ProfilerPostfix(MethodBase __originalMethod, Stopwatch __state)
 {
     DebugLogger.LogDebug("{1}.{2}:: {0:D} ms".F(__state.ElapsedMilliseconds,
                                                 __originalMethod.DeclaringType, __originalMethod.Name));
 }
Example #6
0
 public void LogException(Exception exception, UnityEngine.Object context)
 {
     DebugLogger.LogException(exception);
 }
            /// <summary>
            /// Transpiles RegisterBuilding to catch exceptions and log them.
            /// </summary>
            internal static IEnumerable <CodeInstruction> Transpiler(ILGenerator generator,
                                                                     IEnumerable <CodeInstruction> method)
            {
#if DEBUG
                DebugLogger.LogDebug("Transpiling BuildingConfigManager.RegisterBuilding()");
#endif
                var logger = typeof(DebugLogger).GetMethodSafe(nameof(DebugLogger.
                                                                      LogBuildingException), true, typeof(Exception), typeof(IBuildingConfig));
                var             ee = method.GetEnumerator();
                CodeInstruction last = null;
                bool            hasNext, isFirst = true;
                var             endMethod = generator.DefineLabel();
                // Emit all but the last instruction
                if (ee.MoveNext())
                {
                    do
                    {
                        last = ee.Current;
                        if (isFirst)
                        {
                            last.blocks.Add(new ExceptionBlock(ExceptionBlockType.
                                                               BeginExceptionBlock, null));
                        }
                        hasNext = ee.MoveNext();
                        isFirst = false;
                        if (hasNext)
                        {
                            yield return(last);
                        }
                    } while (hasNext);
                }
                if (last != null)
                {
                    // Preserves the labels "ret" might have had
                    last.opcode  = OpCodes.Nop;
                    last.operand = null;
                    yield return(last);

                    // Add a "leave"
                    yield return(new CodeInstruction(OpCodes.Leave, endMethod));

                    // The exception is already on the stack
                    var startHandler = new CodeInstruction(OpCodes.Ldarg_1);
                    startHandler.blocks.Add(new ExceptionBlock(ExceptionBlockType.
                                                               BeginCatchBlock, typeof(Exception)));
                    yield return(startHandler);

                    yield return(new CodeInstruction(OpCodes.Call, logger));

                    // End catch block, quash the exception
                    var endCatch = new CodeInstruction(OpCodes.Leave, endMethod);
                    endCatch.blocks.Add(new ExceptionBlock(ExceptionBlockType.
                                                           EndExceptionBlock, null));
                    yield return(endCatch);

                    // Actual new ret
                    var ret = new CodeInstruction(OpCodes.Ret);
                    ret.labels.Add(endMethod);
                    yield return(ret);
                }                 // Otherwise, there were no instructions to wrap
            }
Example #8
0
 /// <summary>
 /// Applied after OnSpawn runs.
 /// </summary>
 internal static void Postfix(ScheduleManager __instance)
 {
     DebugLogger.LogDebug("Sorting schedules");
     __instance.GetSchedules().Sort((a, b) => a.name.CompareTo(b.name));
 }
Example #9
0
 /// <summary>
 /// Applied after LogErrorArgs runs.
 /// </summary>
 internal static void Postfix()
 {
     DebugLogger.DumpStack();
 }