From 72b9f8f0a0a3d3e946f5438237b4e6ca9478125b Mon Sep 17 00:00:00 2001 From: LDj3SNuD <35856442+LDj3SNuD@users.noreply.github.com> Date: Fri, 20 Sep 2019 01:59:48 +0200 Subject: [PATCH] Misc fixes (#772) * Update Logger.cs * Update MainWindow.cs * Update SvcTable.cs * Update SvcTable.cs * Update SvcTable.cs --- Ryujinx.Common/Logging/Logger.cs | 7 +- .../HOS/Kernel/SupervisorCall/SvcTable.cs | 73 +++++++++++-------- Ryujinx/Ui/MainWindow.cs | 11 +-- 3 files changed, 56 insertions(+), 35 deletions(-) diff --git a/Ryujinx.Common/Logging/Logger.cs b/Ryujinx.Common/Logging/Logger.cs index 95b67c8ed..10b1d9703 100644 --- a/Ryujinx.Common/Logging/Logger.cs +++ b/Ryujinx.Common/Logging/Logger.cs @@ -39,6 +39,11 @@ namespace Ryujinx.Common.Logging m_Time = Stopwatch.StartNew(); } + public static void RestartTime() + { + m_Time.Restart(); + } + public static void AddTarget(ILogTarget target) { m_LogTargets.Add(target); @@ -134,4 +139,4 @@ namespace Ryujinx.Common.Logging return $"{Class} {Caller}: {Message}"; } } -} \ No newline at end of file +} diff --git a/Ryujinx.HLE/HOS/Kernel/SupervisorCall/SvcTable.cs b/Ryujinx.HLE/HOS/Kernel/SupervisorCall/SvcTable.cs index c1a31da9b..70b6db0c4 100644 --- a/Ryujinx.HLE/HOS/Kernel/SupervisorCall/SvcTable.cs +++ b/Ryujinx.HLE/HOS/Kernel/SupervisorCall/SvcTable.cs @@ -165,40 +165,48 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall } } + BindingFlags staticNonPublic = BindingFlags.NonPublic | BindingFlags.Static; + // Print all the arguments for debugging purposes. int inputArgsCount = methodArgs.Length - byRefArgsCount; - generator.Emit(OpCodes.Ldc_I4_S, inputArgsCount); - - generator.Emit(OpCodes.Newarr, typeof(object)); - - string argsFormat = svcName; - - for (int index = 0; index < inputArgsCount; index++) + if (inputArgsCount != 0) { - argsFormat += $" {methodArgs[index].Name}: 0x{{{index}:X8}},"; + generator.Emit(OpCodes.Ldc_I4, inputArgsCount); - generator.Emit(OpCodes.Dup); - generator.Emit(OpCodes.Ldc_I4_S, index); - generator.Emit(OpCodes.Conv_I); + generator.Emit(OpCodes.Newarr, typeof(object)); - generator.Emit(OpCodes.Ldarg_1); - generator.Emit(OpCodes.Ldc_I4, byRefArgsCount + index); + string argsFormat = svcName; - MethodInfo info = typeof(IExecutionContext).GetMethod(nameof(IExecutionContext.GetX)); + for (int index = 0; index < inputArgsCount; index++) + { + argsFormat += $" {methodArgs[index].Name}: 0x{{{index}:X8}},"; - generator.Emit(OpCodes.Call, info); + generator.Emit(OpCodes.Dup); + generator.Emit(OpCodes.Ldc_I4, index); - generator.Emit(OpCodes.Box, typeof(ulong)); + generator.Emit(OpCodes.Ldarg_1); + generator.Emit(OpCodes.Ldc_I4, byRefArgsCount + index); - generator.Emit(OpCodes.Stelem_Ref); + MethodInfo info = typeof(IExecutionContext).GetMethod(nameof(IExecutionContext.GetX)); + + generator.Emit(OpCodes.Call, info); + + generator.Emit(OpCodes.Box, typeof(ulong)); + + generator.Emit(OpCodes.Stelem_Ref); + } + + argsFormat = argsFormat.Substring(0, argsFormat.Length - 1); + + generator.Emit(OpCodes.Ldstr, argsFormat); } + else + { + generator.Emit(OpCodes.Ldnull); - argsFormat = argsFormat.Substring(0, argsFormat.Length - 1); - - generator.Emit(OpCodes.Ldstr, argsFormat); - - BindingFlags staticNonPublic = BindingFlags.NonPublic | BindingFlags.Static; + generator.Emit(OpCodes.Ldstr, svcName); + } MethodInfo printArgsMethod = typeof(SvcTable).GetMethod(nameof(PrintArguments), staticNonPublic); @@ -226,7 +234,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall throw new InvalidOperationException($"Method \"{svcName}\" has a invalid ref type \"{argType.Name}\"."); } - generator.Emit(OpCodes.Ldloca_S, (byte)local.LocalIndex); + generator.Emit(OpCodes.Ldloca, local); } else { @@ -325,6 +333,18 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall throw new InvalidSvcException($"Method \"{svcName}\" has a invalid ref type \"{type.Name}\"."); } + private static void PrintArguments(object[] argValues, string formatOrSvcName) + { + if (argValues != null) + { + Logger.PrintDebug(LogClass.KernelSvc, string.Format(formatOrSvcName, argValues)); + } + else + { + Logger.PrintDebug(LogClass.KernelSvc, formatOrSvcName); + } + } + private static void PrintResult(KernelResult result, string svcName) { if (result != KernelResult.Success && @@ -339,10 +359,5 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall Logger.PrintDebug(LogClass.KernelSvc, $"{svcName} returned result {result}."); } } - - private static void PrintArguments(object[] argValues, string format) - { - Logger.PrintDebug(LogClass.KernelSvc, string.Format(format, argValues)); - } } -} \ No newline at end of file +} diff --git a/Ryujinx/Ui/MainWindow.cs b/Ryujinx/Ui/MainWindow.cs index 59ce50923..28c6ac586 100644 --- a/Ryujinx/Ui/MainWindow.cs +++ b/Ryujinx/Ui/MainWindow.cs @@ -1,4 +1,4 @@ -using DiscordRPC; +using DiscordRPC; using Gtk; using GUI = Gtk.Builder.ObjectAttribute; using Ryujinx.Audio; @@ -208,6 +208,8 @@ namespace Ryujinx.UI } else { + Logger.RestartTime(); + if (Directory.Exists(path)) { string[] romFsFiles = Directory.GetFiles(path, "*.istorage"); @@ -228,7 +230,6 @@ namespace Ryujinx.UI _device.LoadCart(path); } } - else if (File.Exists(path)) { switch (System.IO.Path.GetExtension(path).ToLowerInvariant()) @@ -254,14 +255,14 @@ namespace Ryujinx.UI } catch (ArgumentOutOfRangeException) { - Logger.PrintError(LogClass.Application, $"The file which you have specified is unsupported by Ryujinx"); + Logger.PrintError(LogClass.Application, "The file which you have specified is unsupported by Ryujinx."); } break; } } else { - Logger.PrintWarning(LogClass.Application, "Please specify a valid XCI/NCA/NSP/PFS0/NRO file"); + Logger.PrintWarning(LogClass.Application, "Please specify a valid XCI/NCA/NSP/PFS0/NRO file."); End(); } @@ -396,7 +397,7 @@ namespace Ryujinx.UI Profile.FinishProfiling(); _device.Dispose(); _audioOut.Dispose(); - DiscordClient.Dispose(); + DiscordClient?.Dispose(); Logger.Shutdown(); Environment.Exit(0); }