From 5d08e9b495a2315e8a4758a8123466665085d044 Mon Sep 17 00:00:00 2001 From: Ac_K Date: Wed, 15 Sep 2021 01:24:49 +0200 Subject: hos: Cleanup the project (#2634) * hos: Cleanup the project Since a lot of changes has been done on the HOS project, there are some leftover here and there, or class just used in one service, things at wrong places, and more. This PR fixes that, additionnally to that, I've realigned some vars because I though it make the code more readable. * Address gdkchan feedback * addresses Thog feedback * Revert ElfSymbol --- Ryujinx.Common/Utilities/StreamUtils.cs | 17 ++ Ryujinx.HLE/Exceptions/InternalServiceException.cs | 2 +- .../Exceptions/InvalidFirmwarePackageException.cs | 2 +- Ryujinx.HLE/Exceptions/InvalidNpdmException.cs | 2 +- .../Exceptions/InvalidStructLayoutException.cs | 6 +- .../Exceptions/ServiceNotImplementedException.cs | 32 ++-- .../Exceptions/TamperCompilationException.cs | 2 +- Ryujinx.HLE/Exceptions/TamperExecutionException.cs | 2 +- Ryujinx.HLE/FileSystem/Content/ContentManager.cs | 2 +- Ryujinx.HLE/HLEConfiguration.cs | 82 +++++----- Ryujinx.HLE/HOS/Font/SharedFontManager.cs | 158 ------------------ Ryujinx.HLE/HOS/Font/SharedFontType.cs | 13 -- Ryujinx.HLE/HOS/Horizon.cs | 20 ++- Ryujinx.HLE/HOS/LibHacHorizonManager.cs | 38 ++--- Ryujinx.HLE/HOS/ServiceCtx.cs | 44 ++--- Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs | 3 +- .../HOS/Services/Sdb/Pl/ISharedFontManager.cs | 12 +- .../HOS/Services/Sdb/Pl/SharedFontManager.cs | 179 +++++++++++++++++++++ .../HOS/Services/Sdb/Pl/Types/SharedFontType.cs | 13 ++ Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs | 1 - .../HOS/Services/Sockets/Bsd/Types/LinuxError.cs | 155 ++++++++++++++++++ .../HOS/Services/Sockets/Bsd/Types/WSAError.cs | 134 +++++++++++++++ Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZone.cs | 1 + Ryujinx.HLE/Loaders/Elf/ElfSymbol.cs | 9 +- Ryujinx.HLE/Loaders/Elf/ElfSymbol32.cs | 2 +- Ryujinx.HLE/Loaders/Elf/ElfSymbol64.cs | 2 +- Ryujinx.HLE/Loaders/Executables/KipExecutable.cs | 44 ++--- Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs | 6 +- Ryujinx.HLE/Loaders/Mods/IPSPatcher.cs | 8 +- Ryujinx.HLE/Loaders/Mods/IPSwitchPatcher.cs | 53 +++--- Ryujinx.HLE/Loaders/Mods/MemPatch.cs | 8 +- Ryujinx.HLE/MemoryConfiguration.cs | 16 +- Ryujinx.HLE/PerformanceStatistics.cs | 34 ++-- Ryujinx.HLE/Utilities/FontUtils.cs | 37 ----- Ryujinx.HLE/Utilities/LinuxError.cs | 155 ------------------ Ryujinx.HLE/Utilities/StreamUtils.cs | 16 -- Ryujinx.HLE/Utilities/StringUtils.cs | 10 +- Ryujinx.HLE/Utilities/StructReader.cs | 38 ----- Ryujinx.HLE/Utilities/StructWriter.cs | 31 ---- Ryujinx.HLE/Utilities/WSAError.cs | 134 --------------- 40 files changed, 701 insertions(+), 822 deletions(-) create mode 100644 Ryujinx.Common/Utilities/StreamUtils.cs delete mode 100644 Ryujinx.HLE/HOS/Font/SharedFontManager.cs delete mode 100644 Ryujinx.HLE/HOS/Font/SharedFontType.cs create mode 100644 Ryujinx.HLE/HOS/Services/Sdb/Pl/SharedFontManager.cs create mode 100644 Ryujinx.HLE/HOS/Services/Sdb/Pl/Types/SharedFontType.cs create mode 100644 Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/LinuxError.cs create mode 100644 Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/WSAError.cs delete mode 100644 Ryujinx.HLE/Utilities/FontUtils.cs delete mode 100644 Ryujinx.HLE/Utilities/LinuxError.cs delete mode 100644 Ryujinx.HLE/Utilities/StreamUtils.cs delete mode 100644 Ryujinx.HLE/Utilities/StructReader.cs delete mode 100644 Ryujinx.HLE/Utilities/StructWriter.cs delete mode 100644 Ryujinx.HLE/Utilities/WSAError.cs diff --git a/Ryujinx.Common/Utilities/StreamUtils.cs b/Ryujinx.Common/Utilities/StreamUtils.cs new file mode 100644 index 00000000..9bd03ec9 --- /dev/null +++ b/Ryujinx.Common/Utilities/StreamUtils.cs @@ -0,0 +1,17 @@ +using System.IO; + +namespace Ryujinx.Common.Utilities +{ + public static class StreamUtils + { + public static byte[] StreamToBytes(Stream input) + { + using (MemoryStream stream = new MemoryStream()) + { + input.CopyTo(stream); + + return stream.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/Exceptions/InternalServiceException.cs b/Ryujinx.HLE/Exceptions/InternalServiceException.cs index b940c51c..85de63a6 100644 --- a/Ryujinx.HLE/Exceptions/InternalServiceException.cs +++ b/Ryujinx.HLE/Exceptions/InternalServiceException.cs @@ -6,4 +6,4 @@ namespace Ryujinx.HLE.Exceptions { public InternalServiceException(string message) : base(message) { } } -} +} \ No newline at end of file diff --git a/Ryujinx.HLE/Exceptions/InvalidFirmwarePackageException.cs b/Ryujinx.HLE/Exceptions/InvalidFirmwarePackageException.cs index bddd827a..d08de581 100644 --- a/Ryujinx.HLE/Exceptions/InvalidFirmwarePackageException.cs +++ b/Ryujinx.HLE/Exceptions/InvalidFirmwarePackageException.cs @@ -6,4 +6,4 @@ namespace Ryujinx.HLE.Exceptions { public InvalidFirmwarePackageException(string message) : base(message) { } } -} +} \ No newline at end of file diff --git a/Ryujinx.HLE/Exceptions/InvalidNpdmException.cs b/Ryujinx.HLE/Exceptions/InvalidNpdmException.cs index c4036ea0..98675e42 100644 --- a/Ryujinx.HLE/Exceptions/InvalidNpdmException.cs +++ b/Ryujinx.HLE/Exceptions/InvalidNpdmException.cs @@ -6,4 +6,4 @@ namespace Ryujinx.HLE.Exceptions { public InvalidNpdmException(string message) : base(message) { } } -} +} \ No newline at end of file diff --git a/Ryujinx.HLE/Exceptions/InvalidStructLayoutException.cs b/Ryujinx.HLE/Exceptions/InvalidStructLayoutException.cs index f4ccb7ba..2f03d13a 100644 --- a/Ryujinx.HLE/Exceptions/InvalidStructLayoutException.cs +++ b/Ryujinx.HLE/Exceptions/InvalidStructLayoutException.cs @@ -7,9 +7,9 @@ namespace Ryujinx.HLE.Exceptions { static readonly Type _structType = typeof(T); - public InvalidStructLayoutException(string message) : base(message) {} + public InvalidStructLayoutException(string message) : base(message) { } - public InvalidStructLayoutException(int expectedSize) : - base($"Type {_structType.Name} has the wrong size. Expected: {expectedSize} bytes, Got: {Unsafe.SizeOf()} bytes") {} + public InvalidStructLayoutException(int expectedSize) + : base($"Type {_structType.Name} has the wrong size. Expected: {expectedSize} bytes, got: {Unsafe.SizeOf()} bytes") { } } } \ No newline at end of file diff --git a/Ryujinx.HLE/Exceptions/ServiceNotImplementedException.cs b/Ryujinx.HLE/Exceptions/ServiceNotImplementedException.cs index c9247cc1..3dbf48d8 100644 --- a/Ryujinx.HLE/Exceptions/ServiceNotImplementedException.cs +++ b/Ryujinx.HLE/Exceptions/ServiceNotImplementedException.cs @@ -19,37 +19,29 @@ namespace Ryujinx.HLE.Exceptions public IpcMessage Request { get; } public ServiceNotImplementedException(IpcService service, ServiceCtx context) - : this(service, context, "The service call is not implemented.") - { } + : this(service, context, "The service call is not implemented.") { } - public ServiceNotImplementedException(IpcService service, ServiceCtx context, string message) - : base(message) + public ServiceNotImplementedException(IpcService service, ServiceCtx context, string message) : base(message) { Service = service; Context = context; Request = context.Request; } - public ServiceNotImplementedException(IpcService service, ServiceCtx context, string message, Exception inner) - : base(message, inner) + public ServiceNotImplementedException(IpcService service, ServiceCtx context, string message, Exception inner) : base(message, inner) { Service = service; Context = context; Request = context.Request; } - protected ServiceNotImplementedException(SerializationInfo info, StreamingContext context) - : base(info, context) - { } + protected ServiceNotImplementedException(SerializationInfo info, StreamingContext context) : base(info, context) { } public override string Message { get { - return base.Message + - Environment.NewLine + - Environment.NewLine + - BuildMessage(); + return base.Message + Environment.NewLine + Environment.NewLine + BuildMessage(); } } @@ -63,8 +55,7 @@ namespace Ryujinx.HLE.Exceptions if (callingType != null && callingMethod != null) { // If the type is past 0xF, we are using TIPC - var ipcCommands = Request.Type > IpcMessageType.TipcCloseSession ? - Service.TipcCommands : Service.HipcCommands; + var ipcCommands = Request.Type > IpcMessageType.TipcCloseSession ? Service.TipcCommands : Service.HipcCommands; // Find the handler for the method called var ipcHandler = ipcCommands.FirstOrDefault(x => x.Value == callingMethod); @@ -82,9 +73,9 @@ namespace Ryujinx.HLE.Exceptions sb.AppendLine(Context.Thread.GetGuestStackTrace()); // Print buffer information - if (Request.PtrBuff.Count > 0 || - Request.SendBuff.Count > 0 || - Request.ReceiveBuff.Count > 0 || + if (Request.PtrBuff.Count > 0 || + Request.SendBuff.Count > 0 || + Request.ReceiveBuff.Count > 0 || Request.ExchangeBuff.Count > 0 || Request.RecvListBuff.Count > 0) { @@ -149,11 +140,12 @@ namespace Ryujinx.HLE.Exceptions return sb.ToString(); } - private (Type, MethodBase) WalkStackTrace(StackTrace trace) + private static (Type, MethodBase) WalkStackTrace(StackTrace trace) { int i = 0; StackFrame frame; + // Find the IIpcService method that threw this exception while ((frame = trace.GetFrame(i++)) != null) { @@ -169,4 +161,4 @@ namespace Ryujinx.HLE.Exceptions return (null, null); } } -} +} \ No newline at end of file diff --git a/Ryujinx.HLE/Exceptions/TamperCompilationException.cs b/Ryujinx.HLE/Exceptions/TamperCompilationException.cs index 370df5d3..02d87163 100644 --- a/Ryujinx.HLE/Exceptions/TamperCompilationException.cs +++ b/Ryujinx.HLE/Exceptions/TamperCompilationException.cs @@ -6,4 +6,4 @@ namespace Ryujinx.HLE.Exceptions { public TamperCompilationException(string message) : base(message) { } } -} +} \ No newline at end of file diff --git a/Ryujinx.HLE/Exceptions/TamperExecutionException.cs b/Ryujinx.HLE/Exceptions/TamperExecutionException.cs index 1f132607..d62effe3 100644 --- a/Ryujinx.HLE/Exceptions/TamperExecutionException.cs +++ b/Ryujinx.HLE/Exceptions/TamperExecutionException.cs @@ -6,4 +6,4 @@ namespace Ryujinx.HLE.Exceptions { public TamperExecutionException(string message) : base(message) { } } -} +} \ No newline at end of file diff --git a/Ryujinx.HLE/FileSystem/Content/ContentManager.cs b/Ryujinx.HLE/FileSystem/Content/ContentManager.cs index 2bffb2a0..230b2dfd 100644 --- a/Ryujinx.HLE/FileSystem/Content/ContentManager.cs +++ b/Ryujinx.HLE/FileSystem/Content/ContentManager.cs @@ -191,7 +191,7 @@ namespace Ryujinx.HLE.FileSystem.Content if (device != null) { TimeManager.Instance.InitializeTimeZone(device); - device.System.Font.Initialize(this); + device.System.SharedFontManager.Initialize(); } } } diff --git a/Ryujinx.HLE/HLEConfiguration.cs b/Ryujinx.HLE/HLEConfiguration.cs index 0329ddb7..16c19ba4 100644 --- a/Ryujinx.HLE/HLEConfiguration.cs +++ b/Ryujinx.HLE/HLEConfiguration.cs @@ -143,49 +143,49 @@ namespace Ryujinx.HLE /// public Action RefreshInputConfig { internal get; set; } - public HLEConfiguration(VirtualFileSystem virtualFileSystem, - LibHacHorizonManager libHacHorizonManager, - ContentManager contentManager, - AccountManager accountManager, + public HLEConfiguration(VirtualFileSystem virtualFileSystem, + LibHacHorizonManager libHacHorizonManager, + ContentManager contentManager, + AccountManager accountManager, UserChannelPersistence userChannelPersistence, - IRenderer gpuRenderer, - IHardwareDeviceDriver audioDeviceDriver, - MemoryConfiguration memoryConfiguration, - IHostUiHandler hostUiHandler, - SystemLanguage systemLanguage, - RegionCode region, - bool enableVsync, - bool enableDockedMode, - bool enablePtc, - IntegrityCheckLevel fsIntegrityCheckLevel, - int fsGlobalAccessLogMode, - long systemTimeOffset, - string timeZone, - MemoryManagerMode memoryManagerMode, - bool ignoreMissingServices, - AspectRatio aspectRatio) + IRenderer gpuRenderer, + IHardwareDeviceDriver audioDeviceDriver, + MemoryConfiguration memoryConfiguration, + IHostUiHandler hostUiHandler, + SystemLanguage systemLanguage, + RegionCode region, + bool enableVsync, + bool enableDockedMode, + bool enablePtc, + IntegrityCheckLevel fsIntegrityCheckLevel, + int fsGlobalAccessLogMode, + long systemTimeOffset, + string timeZone, + MemoryManagerMode memoryManagerMode, + bool ignoreMissingServices, + AspectRatio aspectRatio) { - VirtualFileSystem = virtualFileSystem; - LibHacHorizonManager = libHacHorizonManager; - AccountManager = accountManager; - ContentManager = contentManager; + VirtualFileSystem = virtualFileSystem; + LibHacHorizonManager = libHacHorizonManager; + AccountManager = accountManager; + ContentManager = contentManager; UserChannelPersistence = userChannelPersistence; - GpuRenderer = gpuRenderer; - AudioDeviceDriver = audioDeviceDriver; - MemoryConfiguration = memoryConfiguration; - HostUiHandler = hostUiHandler; - SystemLanguage = systemLanguage; - Region = region; - EnableVsync = enableVsync; - EnableDockedMode = enableDockedMode; - EnablePtc = enablePtc; - FsIntegrityCheckLevel = fsIntegrityCheckLevel; - FsGlobalAccessLogMode = fsGlobalAccessLogMode; - SystemTimeOffset = systemTimeOffset; - TimeZone = timeZone; - MemoryManagerMode = memoryManagerMode; - IgnoreMissingServices = ignoreMissingServices; - AspectRatio = aspectRatio; + GpuRenderer = gpuRenderer; + AudioDeviceDriver = audioDeviceDriver; + MemoryConfiguration = memoryConfiguration; + HostUiHandler = hostUiHandler; + SystemLanguage = systemLanguage; + Region = region; + EnableVsync = enableVsync; + EnableDockedMode = enableDockedMode; + EnablePtc = enablePtc; + FsIntegrityCheckLevel = fsIntegrityCheckLevel; + FsGlobalAccessLogMode = fsGlobalAccessLogMode; + SystemTimeOffset = systemTimeOffset; + TimeZone = timeZone; + MemoryManagerMode = memoryManagerMode; + IgnoreMissingServices = ignoreMissingServices; + AspectRatio = aspectRatio; } } -} +} \ No newline at end of file diff --git a/Ryujinx.HLE/HOS/Font/SharedFontManager.cs b/Ryujinx.HLE/HOS/Font/SharedFontManager.cs deleted file mode 100644 index fda1633f..00000000 --- a/Ryujinx.HLE/HOS/Font/SharedFontManager.cs +++ /dev/null @@ -1,158 +0,0 @@ -using LibHac.Common; -using LibHac.Fs; -using LibHac.Fs.Fsa; -using LibHac.FsSystem; -using LibHac.FsSystem.NcaUtils; -using Ryujinx.HLE.Exceptions; -using Ryujinx.HLE.FileSystem; -using Ryujinx.HLE.FileSystem.Content; -using Ryujinx.HLE.HOS.Kernel.Memory; -using System; -using System.Buffers.Binary; -using System.Collections.Generic; -using System.IO; - -using static Ryujinx.HLE.Utilities.FontUtils; - -namespace Ryujinx.HLE.HOS.Font -{ - class SharedFontManager - { - private readonly Switch _device; - - private readonly SharedMemoryStorage _storage; - - private struct FontInfo - { - public int Offset; - public int Size; - - public FontInfo(int offset, int size) - { - Offset = offset; - Size = size; - } - } - - private Dictionary _fontData; - - public SharedFontManager(Switch device, SharedMemoryStorage storage) - { - _device = device; - _storage = storage; - } - - public void Initialize(ContentManager contentManager) - { - _fontData?.Clear(); - _fontData = null; - - } - - public void EnsureInitialized(ContentManager contentManager) - { - if (_fontData == null) - { - _storage.ZeroFill(); - - uint fontOffset = 0; - - FontInfo CreateFont(string name) - { - if (contentManager.TryGetFontTitle(name, out ulong fontTitle) && - contentManager.TryGetFontFilename(name, out string fontFilename)) - { - string contentPath = contentManager.GetInstalledContentPath(fontTitle, StorageId.NandSystem, NcaContentType.Data); - string fontPath = _device.FileSystem.SwitchPathToSystemPath(contentPath); - - if (!string.IsNullOrWhiteSpace(fontPath)) - { - byte[] data; - - using (IStorage ncaFileStream = new LocalStorage(fontPath, FileAccess.Read, FileMode.Open)) - { - Nca nca = new Nca(_device.System.KeySet, ncaFileStream); - IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _device.System.FsIntegrityCheckLevel); - - romfs.OpenFile(out IFile fontFile, ("/" + fontFilename).ToU8Span(), OpenMode.Read).ThrowIfFailure(); - - data = DecryptFont(fontFile.AsStream()); - } - - FontInfo info = new FontInfo((int)fontOffset, data.Length); - - WriteMagicAndSize(fontOffset, data.Length); - - fontOffset += 8; - - uint start = fontOffset; - - for (; fontOffset - start < data.Length; fontOffset++) - { - _storage.GetRef(fontOffset) = data[fontOffset - start]; - } - - return info; - } - else - { - if (!contentManager.TryGetSystemTitlesName(fontTitle, out string titleName)) - { - titleName = "Unknown"; - } - - throw new InvalidSystemResourceException($"{titleName} ({fontTitle:x8}) system title not found! This font will not work, provide the system archive to fix this error. (See https://github.com/Ryujinx/Ryujinx#requirements for more information)"); - } - } - else - { - throw new ArgumentException($"Unknown font \"{name}\"!"); - } - } - - _fontData = new Dictionary - { - { SharedFontType.JapanUsEurope, CreateFont("FontStandard") }, - { SharedFontType.SimplifiedChinese, CreateFont("FontChineseSimplified") }, - { SharedFontType.SimplifiedChineseEx, CreateFont("FontExtendedChineseSimplified") }, - { SharedFontType.TraditionalChinese, CreateFont("FontChineseTraditional") }, - { SharedFontType.Korean, CreateFont("FontKorean") }, - { SharedFontType.NintendoEx, CreateFont("FontNintendoExtended") } - }; - - if (fontOffset > Horizon.FontSize) - { - throw new InvalidSystemResourceException( - $"The sum of all fonts size exceed the shared memory size. " + - $"Please make sure that the fonts don't exceed {Horizon.FontSize} bytes in total. " + - $"(actual size: {fontOffset} bytes)."); - } - } - } - - private void WriteMagicAndSize(ulong offset, int size) - { - const int decMagic = 0x18029a7f; - const int key = 0x49621806; - - int encryptedSize = BinaryPrimitives.ReverseEndianness(size ^ key); - - _storage.GetRef(offset + 0) = decMagic; - _storage.GetRef(offset + 4) = encryptedSize; - } - - public int GetFontSize(SharedFontType fontType) - { - EnsureInitialized(_device.System.ContentManager); - - return _fontData[fontType].Size; - } - - public int GetSharedMemoryAddressOffset(SharedFontType fontType) - { - EnsureInitialized(_device.System.ContentManager); - - return _fontData[fontType].Offset + 8; - } - } -} diff --git a/Ryujinx.HLE/HOS/Font/SharedFontType.cs b/Ryujinx.HLE/HOS/Font/SharedFontType.cs deleted file mode 100644 index 53dca626..00000000 --- a/Ryujinx.HLE/HOS/Font/SharedFontType.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Ryujinx.HLE.HOS.Font -{ - public enum SharedFontType - { - JapanUsEurope = 0, - SimplifiedChinese = 1, - SimplifiedChineseEx = 2, - TraditionalChinese = 3, - Korean = 4, - NintendoEx = 5, - Count - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/HOS/Horizon.cs b/Ryujinx.HLE/HOS/Horizon.cs index 05ebdbb9..76ab1bc4 100644 --- a/Ryujinx.HLE/HOS/Horizon.cs +++ b/Ryujinx.HLE/HOS/Horizon.cs @@ -9,7 +9,6 @@ using Ryujinx.Audio.Output; using Ryujinx.Audio.Renderer.Device; using Ryujinx.Audio.Renderer.Server; using Ryujinx.HLE.FileSystem.Content; -using Ryujinx.HLE.HOS.Font; using Ryujinx.HLE.HOS.Kernel; using Ryujinx.HLE.HOS.Kernel.Memory; using Ryujinx.HLE.HOS.Kernel.Process; @@ -25,6 +24,7 @@ using Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager; using Ryujinx.HLE.HOS.Services.Nv; using Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl; using Ryujinx.HLE.HOS.Services.Pcv.Bpc; +using Ryujinx.HLE.HOS.Services.Sdb.Pl; using Ryujinx.HLE.HOS.Services.Settings; using Ryujinx.HLE.HOS.Services.Sm; using Ryujinx.HLE.HOS.Services.SurfaceFlinger; @@ -87,11 +87,10 @@ namespace Ryujinx.HLE.HOS internal KTransferMemory AppletCaptureBufferTransfer { get; private set; } - internal SharedFontManager Font { get; private set; } - - internal AccountManager AccountManager { get; private set; } - internal ContentManager ContentManager { get; private set; } - internal CaptureManager CaptureManager { get; private set; } + internal SharedFontManager SharedFontManager { get; private set; } + internal AccountManager AccountManager { get; private set; } + internal ContentManager ContentManager { get; private set; } + internal CaptureManager CaptureManager { get; private set; } internal KEvent VsyncEvent { get; private set; } @@ -175,15 +174,14 @@ namespace Ryujinx.HLE.HOS AppletState.SetFocus(true); - Font = new SharedFontManager(device, fontStorage); - VsyncEvent = new KEvent(KernelContext); DisplayResolutionChangeEvent = new KEvent(KernelContext); - AccountManager = device.Configuration.AccountManager; - ContentManager = device.Configuration.ContentManager; - CaptureManager = new CaptureManager(device); + SharedFontManager = new SharedFontManager(device, fontStorage); + AccountManager = device.Configuration.AccountManager; + ContentManager = device.Configuration.ContentManager; + CaptureManager = new CaptureManager(device); LibHacHorizonManager = device.Configuration.LibHacHorizonManager; diff --git a/Ryujinx.HLE/HOS/LibHacHorizonManager.cs b/Ryujinx.HLE/HOS/LibHacHorizonManager.cs index 61e0227f..f8975dd1 100644 --- a/Ryujinx.HLE/HOS/LibHacHorizonManager.cs +++ b/Ryujinx.HLE/HOS/LibHacHorizonManager.cs @@ -16,16 +16,15 @@ namespace Ryujinx.HLE.HOS public class LibHacHorizonManager { private LibHac.Horizon Server { get; set; } - public HorizonClient RyujinxClient { get; private set; } + public HorizonClient RyujinxClient { get; private set; } public HorizonClient ApplicationClient { get; private set; } - - public HorizonClient AccountClient { get; private set; } - public HorizonClient AmClient { get; private set; } - public HorizonClient BcatClient { get; private set; } - public HorizonClient FsClient { get; private set; } - public HorizonClient NsClient { get; private set; } - public HorizonClient SdbClient { get; private set; } + public HorizonClient AccountClient { get; private set; } + public HorizonClient AmClient { get; private set; } + public HorizonClient BcatClient { get; private set; } + public HorizonClient FsClient { get; private set; } + public HorizonClient NsClient { get; private set; } + public HorizonClient SdbClient { get; private set; } internal LibHacIReader ArpIReader { get; private set; } @@ -49,8 +48,7 @@ namespace Ryujinx.HLE.HOS public void InitializeBcatServer() { - BcatClient = Server.CreateHorizonClient(new ProgramLocation(SystemProgramId.Bcat, StorageId.BuiltInSystem), - BcatFsPermissions); + BcatClient = Server.CreateHorizonClient(new ProgramLocation(SystemProgramId.Bcat, StorageId.BuiltInSystem), BcatFsPermissions); _ = new BcatServer(BcatClient); } @@ -66,23 +64,15 @@ namespace Ryujinx.HLE.HOS public void InitializeSystemClients() { - AccountClient = Server.CreateHorizonClient(new ProgramLocation(SystemProgramId.Account, StorageId.BuiltInSystem), - AccountFsPermissions); - - AmClient = Server.CreateHorizonClient(new ProgramLocation(SystemProgramId.Am, StorageId.BuiltInSystem), - AmFsPermissions); - - NsClient = Server.CreateHorizonClient(new ProgramLocation(SystemProgramId.Ns, StorageId.BuiltInSystem), - NsFsPermissions); - - SdbClient = Server.CreateHorizonClient(new ProgramLocation(SystemProgramId.Sdb, StorageId.BuiltInSystem), - SdbFacData, SdbFacDescriptor); + AccountClient = Server.CreateHorizonClient(new ProgramLocation(SystemProgramId.Account, StorageId.BuiltInSystem), AccountFsPermissions); + AmClient = Server.CreateHorizonClient(new ProgramLocation(SystemProgramId.Am, StorageId.BuiltInSystem), AmFsPermissions); + NsClient = Server.CreateHorizonClient(new ProgramLocation(SystemProgramId.Ns, StorageId.BuiltInSystem), NsFsPermissions); + SdbClient = Server.CreateHorizonClient(new ProgramLocation(SystemProgramId.Sdb, StorageId.BuiltInSystem), SdbFacData, SdbFacDescriptor); } public void InitializeApplicationClient(ProgramId programId, in Npdm npdm) { - ApplicationClient = Server.CreateHorizonClient(new ProgramLocation(programId, StorageId.BuiltInUser), - npdm.FsAccessControlData, npdm.FsAccessControlDescriptor); + ApplicationClient = Server.CreateHorizonClient(new ProgramLocation(programId, StorageId.BuiltInUser), npdm.FsAccessControlData, npdm.FsAccessControlDescriptor); } // This function was added to avoid errors that come from a user's keys or SD encryption seed changing. @@ -147,4 +137,4 @@ namespace Ryujinx.HLE.HOS 0x01, 0x09, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; } -} +} \ No newline at end of file diff --git a/Ryujinx.HLE/HOS/ServiceCtx.cs b/Ryujinx.HLE/HOS/ServiceCtx.cs index 36d4163e..659b212a 100644 --- a/Ryujinx.HLE/HOS/ServiceCtx.cs +++ b/Ryujinx.HLE/HOS/ServiceCtx.cs @@ -8,32 +8,32 @@ namespace Ryujinx.HLE.HOS { class ServiceCtx { - public Switch Device { get; } - public KProcess Process { get; } - public IVirtualMemoryManager Memory { get; } - public KThread Thread { get; } - public IpcMessage Request { get; } - public IpcMessage Response { get; } - public BinaryReader RequestData { get; } - public BinaryWriter ResponseData { get; } + public Switch Device { get; } + public KProcess Process { get; } + public IVirtualMemoryManager Memory { get; } + public KThread Thread { get; } + public IpcMessage Request { get; } + public IpcMessage Response { get; } + public BinaryReader RequestData { get; } + public BinaryWriter ResponseData { get; } public ServiceCtx( - Switch device, - KProcess process, + Switch device, + KProcess process, IVirtualMemoryManager memory, - KThread thread, - IpcMessage request, - IpcMessage response, - BinaryReader requestData, - BinaryWriter responseData) + KThread thread, + IpcMessage request, + IpcMessage response, + BinaryReader requestData, + BinaryWriter responseData) { - Device = device; - Process = process; - Memory = memory; - Thread = thread; - Request = request; - Response = response; - RequestData = requestData; + Device = device; + Process = process; + Memory = memory; + Thread = thread; + Request = request; + Response = response; + RequestData = requestData; ResponseData = responseData; } } diff --git a/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs b/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs index aa17f6ac..4097eddf 100644 --- a/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs +++ b/Ryujinx.HLE/HOS/Services/Ro/IRoInterface.cs @@ -53,8 +53,7 @@ namespace Ryujinx.HLE.HOS.Services.Ro return ResultCode.InvalidAddress; } - StructReader reader = new StructReader(_owner.CpuMemory, nrrAddress); - NrrHeader header = reader.Read(); + NrrHeader header = _owner.CpuMemory.Read(nrrAddress); if (header.Magic != NrrMagic) { diff --git a/Ryujinx.HLE/HOS/Services/Sdb/Pl/ISharedFontManager.cs b/Ryujinx.HLE/HOS/Services/Sdb/Pl/ISharedFontManager.cs index 048e11da..82e246b7 100644 --- a/Ryujinx.HLE/HOS/Services/Sdb/Pl/ISharedFontManager.cs +++ b/Ryujinx.HLE/HOS/Services/Sdb/Pl/ISharedFontManager.cs @@ -1,6 +1,6 @@ -using Ryujinx.HLE.HOS.Font; using Ryujinx.HLE.HOS.Ipc; using Ryujinx.HLE.HOS.Kernel.Common; +using Ryujinx.HLE.HOS.Services.Sdb.Pl.Types; using System; namespace Ryujinx.HLE.HOS.Services.Sdb.Pl @@ -43,7 +43,7 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl { SharedFontType fontType = (SharedFontType)context.RequestData.ReadInt32(); - context.ResponseData.Write(context.Device.System.Font.GetFontSize(fontType)); + context.ResponseData.Write(context.Device.System.SharedFontManager.GetFontSize(fontType)); return ResultCode.Success; } @@ -54,7 +54,7 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl { SharedFontType fontType = (SharedFontType)context.RequestData.ReadInt32(); - context.ResponseData.Write(context.Device.System.Font.GetSharedMemoryAddressOffset(fontType)); + context.ResponseData.Write(context.Device.System.SharedFontManager.GetSharedMemoryAddressOffset(fontType)); return ResultCode.Success; } @@ -63,7 +63,7 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl // GetSharedMemoryNativeHandle() -> handle public ResultCode GetSharedMemoryNativeHandle(ServiceCtx context) { - context.Device.System.Font.EnsureInitialized(context.Device.System.ContentManager); + context.Device.System.SharedFontManager.EnsureInitialized(context.Device.System.ContentManager); if (_fontSharedMemHandle == 0) { @@ -131,8 +131,8 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl } context.Memory.Write(typesPosition + offset, (int)fontType); - context.Memory.Write(offsetsPosition + offset, context.Device.System.Font.GetSharedMemoryAddressOffset(fontType)); - context.Memory.Write(fontSizeBufferPosition + offset, context.Device.System.Font.GetFontSize(fontType)); + context.Memory.Write(offsetsPosition + offset, context.Device.System.SharedFontManager.GetSharedMemoryAddressOffset(fontType)); + context.Memory.Write(fontSizeBufferPosition + offset, context.Device.System.SharedFontManager.GetFontSize(fontType)); return true; } diff --git a/Ryujinx.HLE/HOS/Services/Sdb/Pl/SharedFontManager.cs b/Ryujinx.HLE/HOS/Services/Sdb/Pl/SharedFontManager.cs new file mode 100644 index 00000000..13bb9ff5 --- /dev/null +++ b/Ryujinx.HLE/HOS/Services/Sdb/Pl/SharedFontManager.cs @@ -0,0 +1,179 @@ +using LibHac.Common; +using LibHac.Fs; +using LibHac.Fs.Fsa; +using LibHac.FsSystem; +using LibHac.FsSystem.NcaUtils; +using Ryujinx.HLE.Exceptions; +using Ryujinx.HLE.FileSystem; +using Ryujinx.HLE.FileSystem.Content; +using Ryujinx.HLE.HOS.Kernel.Memory; +using Ryujinx.HLE.HOS.Services.Sdb.Pl.Types; +using System; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.IO; + +namespace Ryujinx.HLE.HOS.Services.Sdb.Pl +{ + class SharedFontManager + { + private static readonly uint FontKey = 0x06186249; + private static readonly uint BFTTFMagic = 0x18029a7f; + + private readonly Switch _device; + private readonly SharedMemoryStorage _storage; + + private struct FontInfo + { + public int Offset; + public int Size; + + public FontInfo(int offset, int size) + { + Offset = offset; + Size = size; + } + } + + private Dictionary _fontData; + + public SharedFontManager(Switch device, SharedMemoryStorage storage) + { + _device = device; + _storage = storage; + } + + public void Initialize() + { + _fontData?.Clear(); + _fontData = null; + + } + + public void EnsureInitialized(ContentManager contentManager) + { + if (_fontData == null) + { + _storage.ZeroFill(); + + uint fontOffset = 0; + + FontInfo CreateFont(string name) + { + if (contentManager.TryGetFontTitle(name, out ulong fontTitle) && contentManager.TryGetFontFilename(name, out string fontFilename)) + { + string contentPath = contentManager.GetInstalledContentPath(fontTitle, StorageId.NandSystem, NcaContentType.Data); + string fontPath = _device.FileSystem.SwitchPathToSystemPath(contentPath); + + if (!string.IsNullOrWhiteSpace(fontPath)) + { + byte[] data; + + using (IStorage ncaFileStream = new LocalStorage(fontPath, FileAccess.Read, FileMode.Open)) + { + Nca nca = new Nca(_device.System.KeySet, ncaFileStream); + IFileSystem romfs = nca.OpenFileSystem(NcaSectionType.Data, _device.System.FsIntegrityCheckLevel); + + romfs.OpenFile(out IFile fontFile, ("/" + fontFilename).ToU8Span(), OpenMode.Read).ThrowIfFailure(); + + data = DecryptFont(fontFile.AsStream()); + } + + FontInfo info = new FontInfo((int)fontOffset, data.Length); + + WriteMagicAndSize(fontOffset, data.Length); + + fontOffset += 8; + + uint start = fontOffset; + + for (; fontOffset - start < data.Length; fontOffset++) + { + _storage.GetRef(fontOffset) = data[fontOffset - start]; + } + + return info; + } + else + { + if (!contentManager.TryGetSystemTitlesName(fontTitle, out string titleName)) + { + titleName = "Unknown"; + } + + throw new InvalidSystemResourceException($"{titleName} ({fontTitle:x8}) system title not found! This font will not work, provide the system archive to fix this error. (See https://github.com/Ryujinx/Ryujinx#requirements for more information)"); + } + } + else + { + throw new ArgumentException($"Unknown font \"{name}\"!"); + } + } + + _fontData = new Dictionary + { + { SharedFontType.JapanUsEurope, CreateFont("FontStandard") }, + { SharedFontType.SimplifiedChinese, CreateFont("FontChineseSimplified") }, + { SharedFontType.SimplifiedChineseEx, CreateFont("FontExtendedChineseSimplified") }, + { SharedFontType.TraditionalChinese, CreateFont("FontChineseTraditional") }, + { SharedFontType.Korean, CreateFont("FontKorean") }, + { SharedFontType.NintendoEx, CreateFont("FontNintendoExtended") } + }; + + if (fontOffset > Horizon.FontSize) + { + throw new InvalidSystemResourceException("The sum of all fonts size exceed the shared memory size. " + + $"Please make sure that the fonts don't exceed {Horizon.FontSize} bytes in total. (actual size: {fontOffset} bytes)."); + } + } + } + + private void WriteMagicAndSize(ulong offset, int size) + { + const int key = 0x49621806; + + int encryptedSize = BinaryPrimitives.ReverseEndianness(size ^ key); + + _storage.GetRef(offset + 0) = (int)BFTTFMagic; + _storage.GetRef(offset + 4) = encryptedSize; + } + + public int GetFontSize(SharedFontType fontType) + { + EnsureInitialized(_device.System.ContentManager); + + return _fontData[fontType].Size; + } + + public int GetSharedMemoryAddressOffset(SharedFontType fontType) + { + EnsureInitialized(_device.System.ContentManager); + + return _fontData[fontType].Offset + 8; + } + + private static byte[] DecryptFont(Stream bfttfStream) + { + static uint KXor(uint data) => data ^ FontKey; + + using (BinaryReader reader = new BinaryReader(bfttfStream)) + using (MemoryStream ttfStream = new MemoryStream()) + using (BinaryWriter output = new BinaryWriter(ttfStream)) + { + if (KXor(reader.ReadUInt32()) != BFTTFMagic) + { + throw new InvalidDataException("Error: Input file is not in BFTTF format!"); + } + + bfttfStream.Position += 4; + + for (int i = 0; i < (bfttfStream.Length - 8) / 4; i++) + { + output.Write(KXor(reader.ReadUInt32())); + } + + return ttfStream.ToArray(); + } + } + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/HOS/Services/Sdb/Pl/Types/SharedFontType.cs b/Ryujinx.HLE/HOS/Services/Sdb/Pl/Types/SharedFontType.cs new file mode 100644 index 00000000..90ee4f03 --- /dev/null +++ b/Ryujinx.HLE/HOS/Services/Sdb/Pl/Types/SharedFontType.cs @@ -0,0 +1,13 @@ +namespace Ryujinx.HLE.HOS.Services.Sdb.Pl.Types +{ + public enum SharedFontType + { + JapanUsEurope = 0, + SimplifiedChinese = 1, + SimplifiedChineseEx = 2, + TraditionalChinese = 3, + Korean = 4, + NintendoEx = 5, + Count + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs b/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs index 63f639cb..355ef864 100644 --- a/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs +++ b/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs @@ -1,5 +1,4 @@ using Ryujinx.Common.Logging; -using Ryujinx.HLE.Utilities; using System; using System.Buffers.Binary; using System.Collections.Generic; diff --git a/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/LinuxError.cs b/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/LinuxError.cs new file mode 100644 index 00000000..b1326985 --- /dev/null +++ b/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/LinuxError.cs @@ -0,0 +1,155 @@ +using System.Diagnostics.CodeAnalysis; + +namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd +{ + [SuppressMessage("ReSharper", "InconsistentNaming")] + enum LinuxError + { + SUCCESS = 0, + EPERM = 1 /* Operation not permitted */, + ENOENT = 2 /* No such file or directory */, + ESRCH = 3 /* No such process */, + EINTR = 4 /* Interrupted system call */, + EIO = 5 /* I/O error */, + ENXIO = 6 /* No such device or address */, + E2BIG = 7 /* Argument list too long */, + ENOEXEC = 8 /* Exec format error */, + EBADF = 9 /* Bad file number */, + ECHILD = 10 /* No child processes */, + EAGAIN = 11 /* Try again */, + ENOMEM = 12 /* Out of memory */, + EACCES = 13 /* Permission denied */, + EFAULT = 14 /* Bad address */, + ENOTBLK = 15 /* Block device required */, + EBUSY = 16 /* Device or resource busy */, + EEXIST = 17 /* File exists */, + EXDEV = 18 /* Cross-device link */, + ENODEV = 19 /* No such device */, + ENOTDIR = 20 /* Not a directory */, + EISDIR = 21 /* Is a directory */, + EINVAL = 22 /* Invalid argument */, + ENFILE = 23 /* File table overflow */, + EMFILE = 24 /* Too many open files */, + ENOTTY = 25 /* Not a typewriter */, + ETXTBSY = 26 /* Text file busy */, + EFBIG = 27 /* File too large */, + ENOSPC = 28 /* No space left on device */, + ESPIPE = 29 /* Illegal seek */, + EROFS = 30 /* Read-only file system */, + EMLINK = 31 /* Too many links */, + EPIPE = 32 /* Broken pipe */, + EDOM = 33 /* Math argument out of domain of func */, + ERANGE = 34 /* Math result not representable */, + EDEADLK = 35 /* Resource deadlock would occur */, + ENAMETOOLONG = 36 /* File name too long */, + ENOLCK = 37 /* No record locks available */, + + /* + * This error code is special: arch syscall entry code will return + * -ENOSYS if users try to call a syscall that doesn't exist. To keep + * failures of syscalls that really do exist distinguishable from + * failures due to attempts to use a nonexistent syscall, syscall + * implementations should refrain from returning -ENOSYS. + */ + ENOSYS = 38 /* Invalid system call number */, + ENOTEMPTY = 39 /* Directory not empty */, + ELOOP = 40 /* Too many symbolic links encountered */, + EWOULDBLOCK = EAGAIN /* Operation would block */, + ENOMSG = 42 /* No message of desired type */, + EIDRM = 43 /* Identifier removed */, + ECHRNG = 44 /* Channel number out of range */, + EL2NSYNC = 45 /* Level 2 not synchronized */, + EL3HLT = 46 /* Level 3 halted */, + EL3RST = 47 /* Level 3 reset */, + ELNRNG = 48 /* Link number out of range */, + EUNATCH = 49 /* Protocol driver not attached */, + ENOCSI = 50 /* No CSI structure available */, + EL2HLT = 51 /* Level 2 halted */, + EBADE = 52 /* Invalid exchange */, + EBADR = 53 /* Invalid request descriptor */, + EXFULL = 54 /* Exchange full */, + ENOANO = 55 /* No anode */, + EBADRQC = 56 /* Invalid request code */, + EBADSLT = 57 /* Invalid slot */, + EDEADLOCK = EDEADLK, + EBFONT = 59 /* Bad font file format */, + ENOSTR = 60 /* Device not a stream */, + ENODATA = 61 /* No data available */, + ETIME = 62 /* Timer expired */, + ENOSR = 63 /* Out of streams resources */, + ENONET = 64 /* Machine is not on the network */, + ENOPKG = 65 /* Package not installed */, + EREMOTE = 66 /* Object is remote */, + ENOLINK = 67 /* Link has been severed */, + EADV = 68 /* Advertise error */, + ESRMNT = 69 /* Srmount error */, + ECOMM = 70 /* Communication error on send */, + EPROTO = 71 /* Protocol error */, + EMULTIHOP = 72 /* Multihop attempted */, + EDOTDOT = 73 /* RFS specific error */, + EBADMSG = 74 /* Not a data message */, + EOVERFLOW = 75 /* Value too large for defined data type */, + ENOTUNIQ = 76 /* Name not unique on network */, + EBADFD = 77 /* File descriptor in bad state */, + EREMCHG = 78 /* Remote address changed */, + ELIBACC = 79 /* Can not access a needed shared library */, + ELIBBAD = 80 /* Accessing a corrupted shared library */, + ELIBSCN = 81 /* .lib section in a.out corrupted */, + ELIBMAX = 82 /* Attempting to link in too many shared libraries */, + ELIBEXEC = 83 /* Cannot exec a shared library directly */, + EILSEQ = 84 /* Illegal byte sequence */, + ERESTART = 85 /* Interrupted system call should be restarted */, + ESTRPIPE = 86 /* Streams pipe error */, + EUSERS = 87 /* Too many users */, + ENOTSOCK = 88 /* Socket operation on non-socket */, + EDESTADDRREQ = 89 /* Destination address required */, + EMSGSIZE = 90 /* Message too long */, + EPROTOTYPE = 91 /* Protocol wrong type for socket */, + ENOPROTOOPT = 92 /* Protocol not available */, + EPROTONOSUPPORT = 93 /* Protocol not supported */, + ESOCKTNOSUPPORT = 94 /* Socket type not supported */, + EOPNOTSUPP = 95 /* Operation not supported on transport endpoint */, + EPFNOSUPPORT = 96 /* Protocol family not supported */, + EAFNOSUPPORT = 97 /* Address family not supported by protocol */, + EADDRINUSE = 98 /* Address already in use */, + EADDRNOTAVAIL = 99 /* Cannot assign requested address */, + ENETDOWN = 100 /* Network is down */, + ENETUNREACH = 101 /* Network is unreachable */, + ENETRESET = 102 /* Network dropped connection because of reset */, + ECONNABORTED = 103 /* Software caused connection abort */, + ECONNRESET = 104 /* Connection reset by peer */, + ENOBUFS = 105 /* No buffer space available */, + EISCONN = 106 /* Transport endpoint is already connected */, + ENOTCONN = 107 /* Transport endpoint is not connected */, + ESHUTDOWN = 108 /* Cannot send after transport endpoint shutdown */, + ETOOMANYREFS = 109 /* Too many references: cannot splice */, + ETIMEDOUT = 110 /* Connection timed out */, + ECONNREFUSED = 111 /* Connection refused */, + EHOSTDOWN = 112 /* Host is down */, + EHOSTUNREACH = 113 /* No route to host */, + EALREADY = 114 /* Operation already in progress */, + EINPROGRESS = 115 /* Operation now in progress */, + ESTALE = 116 /* Stale file handle */, + EUCLEAN = 117 /* Structure needs cleaning */, + ENOTNAM = 118 /* Not a XENIX named type file */, + ENAVAIL = 119 /* No XENIX semaphores available */, + EISNAM = 120 /* Is a named type file */, + EREMOTEIO = 121 /* Remote I/O error */, + EDQUOT = 122 /* Quota exceeded */, + ENOMEDIUM = 123 /* No medium found */, + EMEDIUMTYPE = 124 /* Wrong medium type */, + ECANCELED = 125 /* Operation Canceled */, + ENOKEY = 126 /* Required key not available */, + EKEYEXPIRED = 127 /* Key has expired */, + EKEYREVOKED = 128 /* Key has been revoked */, + EKEYREJECTED = 129 /* Key was rejected by service */, + + /* for robust mutexes */ + EOWNERDEAD = 130 /* Owner died */, + ENOTRECOVERABLE = 131 /* State not recoverable */, + + ERFKILL = 132 /* Operation not possible due to RF-kill */, + + EHWPOISON = 133 /* Memory page has hardware error */ + } +} \ No newline at end of file diff --git a/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/WSAError.cs b/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/WSAError.cs new file mode 100644 index 00000000..d87e72d8 --- /dev/null +++ b/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/WSAError.cs @@ -0,0 +1,134 @@ +using System.Diagnostics.CodeAnalysis; + +namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd +{ + [SuppressMessage("ReSharper", "InconsistentNaming")] + enum WsaError + { + /* + * All Windows Sockets error constants are biased by WSABASEERR from + * the "normal" + */ + WSABASEERR = 10000, + + /* + * Windows Sockets definitions of regular Microsoft C error constants + */ + WSAEINTR = (WSABASEERR + 4), + WSAEBADF = (WSABASEERR + 9), + WSAEACCES = (WSABASEERR + 13), + WSAEFAULT = (WSABASEERR + 14), + WSAEINVAL = (WSABASEERR + 22), + WSAEMFILE = (WSABASEERR + 24), + + /* + * Windows Sockets definitions of regular Berkeley error constants + */ + WSAEWOULDBLOCK = (WSABASEERR + 35), + WSAEINPROGRESS = (WSABASEERR + 36), + WSAEALREADY = (WSABASEERR + 37), + WSAENOTSOCK = (WSABASEERR + 38), + WSAEDESTADDRREQ = (WSABASEERR + 39), + WSAEMSGSIZE = (WSABASEERR + 40), + WSAEPROTOTYPE = (WSABASEERR + 41), + WSAENOPROTOOPT = (WSABASEERR + 42), + WSAEPROTONOSUPPORT = (WSABASEERR + 43), + WSAESOCKTNOSUPPORT = (WSABASEERR + 44), + WSAEOPNOTSUPP = (WSABASEERR + 45), + WSAEPFNOSUPPORT = (WSABASEERR + 46), + WSAEAFNOSUPPORT = (WSABASEERR + 47), + WSAEADDRINUSE = (WSABASEERR + 48), + WSAEADDRNOTAVAIL = (WSABASEERR + 49), + WSAENETDOWN = (WSABASEERR + 50), + WSAENETUNREACH = (WSABASEERR + 51), + WSAENETRESET = (WSABASEERR + 52), + WSAECONNABORTED = (WSABASEERR + 53), + WSAECONNRESET = (WSABASEERR + 54), + WSAENOBUFS = (WSABASEERR + 55), + WSAEISCONN = (WSABASEERR + 56), + WSAENOTCONN = (WSABASEERR + 57), + WSAESHUTDOWN = (WSABASEERR + 58), + WSAETOOMANYREFS = (WSABASEERR + 59), + WSAETIMEDOUT = (WSABASEERR + 60), + WSAECONNREFUSED = (WSABASEERR + 61), + WSAELOOP = (WSABASEERR + 62), + WSAENAMETOOLONG = (WSABASEERR + 63), + WSAEHOSTDOWN = (WSABASEERR + 64), + WSAEHOSTUNREACH = (WSABASEERR + 65), + WSAENOTEMPTY = (WSABASEERR + 66), + WSAEPROCLIM = (WSABASEERR + 67), + WSAEUSERS = (WSABASEERR + 68), + WSAEDQUOT = (WSABASEERR + 69), + WSAESTALE = (WSABASEERR + 70), + WSAEREMOTE = (WSABASEERR + 71), + + /* + * Extended Windows Sockets error constant definitions + */ + WSASYSNOTREADY = (WSABASEERR + 91), + WSAVERNOTSUPPORTED = (WSABASEERR + 92), + WSANOTINITIALISED = (WSABASEERR + 93), + WSAEDISCON = (WSABASEERR + 101), + WSAENOMORE = (WSABASEERR + 102), + WSAECANCELLED = (WSABASEERR + 103), + WSAEINVALIDPROCTABLE = (WSABASEERR + 104), + WSAEINVALIDPROVIDER = (WSABASEERR + 105), + WSAEPROVIDERFAILEDINIT = (WSABASEERR + 106), + WSASYSCALLFAILURE = (WSABASEERR + 107), + WSASERVICE_NOT_FOUND = (WSABASEERR + 108), + WSATYPE_NOT_FOUND = (WSABASEERR + 109), + WSA_E_NO_MORE = (WSABASEERR + 110), + WSA_E_CANCELLED = (WSABASEERR + 111), + WSAEREFUSED = (WSABASEERR + 112), + + /* + * Error return codes from gethostbyname() and gethostbyaddr() + * (when using the resolver). Note that these errors are + * retrieved via WSAGetLastError() and must therefore follow + * the rules for avoiding clashes with error numbers from + * specific implementations or language run-time systems. + * For this reason the codes are based at WSABASEERR+1001. + * Note also that [WSA]NO_ADDRESS is defined only for + * compatibility purposes. + */ + + /* Authoritative Answer: Host not found */ + WSAHOST_NOT_FOUND = (WSABASEERR + 1001), + + /* Non-Authoritative: Host not found, or SERVERFAIL */ + WSATRY_AGAIN = (WSABASEERR + 1002), + + /* Non-recoverable errors, FORMERR, REFUSED, NOTIMP */ + WSANO_RECOVERY = (WSABASEERR + 1003), + + /* Valid name, no data record of requested type */ + WSANO_DATA = (WSABASEERR + 1004), + + /* + * Define QOS related error return codes + * + */ + WSA_QOS_RECEIVERS = (WSABASEERR + 1005), + /* at least one Reserve has arrived */ + WSA_QOS_SENDERS = (WSABASEERR + 1006), + /* at least one Path has arrived */ + WSA_QOS_NO_SENDERS = (WSABASEERR + 1007), + /* there are no senders */ + WSA_QOS_NO_RECEIVERS = (WSABASEERR + 1008), + /* there are no receivers */ + WSA_QOS_REQUEST_CONFIRMED = (WSABASEERR + 1009), + /* Reserve has been confirmed */ + WSA_QOS_ADMISSION_FAILURE = (WSABASEERR + 1010), + /* error due to lack of resources */ + WSA_QOS_POLICY_FAILURE = (WSABASEERR + 1011), + /* rejected for administrative reasons - bad credentials */ + WSA_QOS_BAD_STYLE = (WSABASEERR + 1012), + /* unknown or conflicting style */ + WSA_QOS_BAD_OBJECT = (WSABASEERR + 1013), + /* problem with some part of the filterspec or providerspecific + * buffer in general */ + WSA_QOS_TRAFFIC_CTRL_ERROR = (WSABASEERR + 1014), + /* problem with some part of the flowspec */ + WSA_QOS_GENERIC_ERROR = (WSABASEERR + 1015) + } +} diff --git a/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZone.cs b/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZone.cs index c77c472e..95ea9d4d 100644 --- a/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZone.cs +++ b/Ryujinx.HLE/HOS/Services/Time/TimeZone/TimeZone.cs @@ -1,4 +1,5 @@ using Ryujinx.Common; +using Ryujinx.Common.Utilities; using Ryujinx.HLE.Utilities; using System; using System.IO; diff --git a/Ryujinx.HLE/Loaders/Elf/ElfSymbol.cs b/Ryujinx.HLE/Loaders/Elf/ElfSymbol.cs index 9961afe1..1cfc0bdc 100644 --- a/Ryujinx.HLE/Loaders/Elf/ElfSymbol.cs +++ b/Ryujinx.HLE/Loaders/Elf/ElfSymbol.cs @@ -8,13 +8,8 @@ namespace Ryujinx.HLE.Loaders.Elf public ElfSymbolBinding Binding { get; private set; } public ElfSymbolVisibility Visibility { get; private set; } - public bool IsFuncOrObject => - Type == ElfSymbolType.SttFunc || - Type == ElfSymbolType.SttObject; - - public bool IsGlobalOrWeak => - Binding == ElfSymbolBinding.StbGlobal || - Binding == ElfSymbolBinding.StbWeak; + public bool IsFuncOrObject => Type == ElfSymbolType.SttFunc || Type == ElfSymbolType.SttObject; + public bool IsGlobalOrWeak => Binding == ElfSymbolBinding.StbGlobal || Binding == ElfSymbolBinding.StbWeak; public int ShIdx { get; private set; } public ulong Value { get; private set; } diff --git a/Ryujinx.HLE/Loaders/Elf/ElfSymbol32.cs b/Ryujinx.HLE/Loaders/Elf/ElfSymbol32.cs index 2b25d044..2f84796b 100644 --- a/Ryujinx.HLE/Loaders/Elf/ElfSymbol32.cs +++ b/Ryujinx.HLE/Loaders/Elf/ElfSymbol32.cs @@ -11,4 +11,4 @@ public ushort SectionIndex; #pragma warning restore CS0649 } -} +} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Elf/ElfSymbol64.cs b/Ryujinx.HLE/Loaders/Elf/ElfSymbol64.cs index acbd2191..665e65b0 100644 --- a/Ryujinx.HLE/Loaders/Elf/ElfSymbol64.cs +++ b/Ryujinx.HLE/Loaders/Elf/ElfSymbol64.cs @@ -11,4 +11,4 @@ public ulong Size; #pragma warning restore CS0649 } -} +} \ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Executables/KipExecutable.cs b/Ryujinx.HLE/Loaders/Executables/KipExecutable.cs index 12730cd3..fe88f691 100644 --- a/Ryujinx.HLE/Loaders/Executables/KipExecutable.cs +++ b/Ryujinx.HLE/Loaders/Executables/KipExecutable.cs @@ -12,25 +12,25 @@ namespace Ryujinx.HLE.Loaders.Executables public Span Data => Program.AsSpan().Slice((int)DataOffset, (int)DataSize); public uint TextOffset { get; } - public uint RoOffset { get; } + public uint RoOffset { get; } public uint DataOffset { get; } - public uint BssOffset { get; } + public uint BssOffset { get; } public uint TextSize { get; } - public uint RoSize { get; } + public uint RoSize { get; } public uint DataSize { get; } - public uint BssSize { get; } + public uint BssSize { get; } - public int[] Capabilities { get; } - public bool UsesSecureMemory { get; } + public int[] Capabilities { get; } + public bool UsesSecureMemory { get; } public bool Is64BitAddressSpace { get; } - public bool Is64Bit { get; } - public ulong ProgramId { get; } - public byte Priority { get; } - public int StackSize { get; } - public byte IdealCoreId { get; } - public int Version { get; } - public string Name { get; } + public bool Is64Bit { get; } + public ulong ProgramId { get; } + public byte Priority { get; } + public int StackSize { get; } + public byte IdealCoreId { get; } + public int Version { get; } + public string Name { get; } public KipExecutable(IStorage inStorage) { @@ -39,22 +39,22 @@ namespace Ryujinx.HLE.Loaders.Executables reader.Initialize(inStorage).ThrowIfFailure(); TextOffset = (uint)reader.Segments[0].MemoryOffset; - RoOffset = (uint)reader.Segments[1].MemoryOffset; + RoOffset = (uint)reader.Segments[1].MemoryOffset; DataOffset = (uint)reader.Segments[2].MemoryOffset; - BssOffset = (uint)reader.Segments[3].MemoryOffset; - BssSize = (uint)reader.Segments[3].Size; + BssOffset = (uint)reader.Segments[3].MemoryOffset; + BssSize = (uint)reader.Segments[3].Size; StackSize = reader.StackSize; - UsesSecureMemory = reader.UsesSecureMemory; + UsesSecureMemory = reader.UsesSecureMemory; Is64BitAddressSpace = reader.Is64BitAddressSpace; - Is64Bit = reader.Is64Bit; + Is64Bit = reader.Is64Bit; - ProgramId = reader.ProgramId; - Priority = reader.Priority; + ProgramId = reader.ProgramId; + Priority = reader.Priority; IdealCoreId = reader.IdealCoreId; - Version = reader.Version; - Name = reader.Name.ToString(); + Version = reader.Version; + Name = reader.Name.ToString(); Capabilities = new int[32]; diff --git a/Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs b/Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs index 20502c11..285ce7e6 100644 --- a/Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs +++ b/Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs @@ -17,14 +17,14 @@ namespace Ryujinx.HLE.Loaders.Executables public Span Data => Program.AsSpan().Slice((int)DataOffset, (int)DataSize); public uint TextOffset { get; } - public uint RoOffset { get; } + public uint RoOffset { get; } public uint DataOffset { get; } public uint BssOffset => DataOffset + (uint)Data.Length; public uint TextSize { get; } - public uint RoSize { get; } + public uint RoSize { get; } public uint DataSize { get; } - public uint BssSize { get; } + public uint BssSize { get; } public string Name; public Buffer32 BuildId; diff --git a/Ryujinx.HLE/Loaders/Mods/IPSPatcher.cs b/Ryujinx.HLE/Loaders/Mods/IPSPatcher.cs index 11c7f04c..de50c6eb 100644 --- a/Ryujinx.HLE/Loaders/Mods/IPSPatcher.cs +++ b/Ryujinx.HLE/Loaders/Mods/IPSPatcher.cs @@ -20,10 +20,10 @@ namespace Ryujinx.HLE.Loaders.Mods private static MemPatch ParseIps(BinaryReader reader) { - Span IpsHeaderMagic = Encoding.ASCII.GetBytes("PATCH").AsSpan(); - Span IpsTailMagic = Encoding.ASCII.GetBytes("EOF").AsSpan(); + Span IpsHeaderMagic = Encoding.ASCII.GetBytes("PATCH").AsSpan(); + Span IpsTailMagic = Encoding.ASCII.GetBytes("EOF").AsSpan(); Span Ips32HeaderMagic = Encoding.ASCII.GetBytes("IPS32").AsSpan(); - Span Ips32TailMagic = Encoding.ASCII.GetBytes("EEOF").AsSpan(); + Span Ips32TailMagic = Encoding.ASCII.GetBytes("EEOF").AsSpan(); MemPatch patches = new MemPatch(); var header = reader.ReadBytes(IpsHeaderMagic.Length).AsSpan(); @@ -68,7 +68,7 @@ namespace Ryujinx.HLE.Loaders.Mods } int patchOffset = is32 ? buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3] - : buf[0] << 16 | buf[1] << 8 | buf[2]; + : buf[0] << 16 | buf[1] << 8 | buf[2]; if (ReadNext(2)) { diff --git a/Ryujinx.HLE/Loaders/Mods/IPSwitchPatcher.cs b/Ryujinx.HLE/Loaders/Mods/IPSwitchPatcher.cs index abe59dde..f0a32f86 100644 --- a/Ryujinx.HLE/Loaders/Mods/IPSwitchPatcher.cs +++ b/Ryujinx.HLE/Loaders/Mods/IPSwitchPatcher.cs @@ -7,11 +7,19 @@ namespace Ryujinx.HLE.Loaders.Mods { class IPSwitchPatcher { - readonly StreamReader _reader; - public string BuildId { get; } - const string BidHeader = "@nsobid-"; + private enum Token + { + Normal, + String, + EscapeChar, + Comment + } + + private readonly StreamReader _reader; + public string BuildId { get; } + public IPSwitchPatcher(StreamReader reader) { string header = reader.ReadLine(); @@ -26,14 +34,6 @@ namespace Ryujinx.HLE.Loaders.Mods BuildId = header.Substring(BidHeader.Length).TrimEnd().TrimEnd('0'); } - private enum Token - { - Normal, - String, - EscapeChar, - Comment - } - // Uncomments line and unescapes C style strings within private static string PreprocessLine(string line) { @@ -56,24 +56,24 @@ namespace Ryujinx.HLE.Loaders.Mods case Token.String: state = c switch { - '"' => Token.Normal, + '"' => Token.Normal, '\\' => Token.EscapeChar, - _ => Token.String + _ => Token.String }; break; case Token.EscapeChar: state = Token.String; c = c switch { - 'a' => '\a', - 'b' => '\b', - 'f' => '\f', - 'n' => '\n', - 'r' => '\r', - 't' => '\t', - 'v' => '\v', + 'a' => '\a', + 'b' => '\b', + 'f' => '\f', + 'n' => '\n', + 'r' => '\r', + 't' => '\t', + 'v' => '\v', '\\' => '\\', - _ => '?' + _ => '?' }; break; } @@ -119,7 +119,8 @@ namespace Ryujinx.HLE.Loaders.Mods for (int i = 0; i < hexstr.Length; i += 2) { int high = ParseHexByte((byte)hexstr[i]); - int low = ParseHexByte((byte)hexstr[i + 1]); + int low = ParseHexByte((byte)hexstr[i + 1]); + bytes[i >> 1] = (byte)((high << 4) | low); } @@ -131,11 +132,11 @@ namespace Ryujinx.HLE.Loaders.Mods { if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) { - return Int32.TryParse(str.Substring(2), System.Globalization.NumberStyles.HexNumber, null, out value); + return int.TryParse(str.Substring(2), System.Globalization.NumberStyles.HexNumber, null, out value); } else { - return Int32.TryParse(str, System.Globalization.NumberStyles.Integer, null, out value); + return int.TryParse(str, System.Globalization.NumberStyles.Integer, null, out value); } } @@ -148,7 +149,7 @@ namespace Ryujinx.HLE.Loaders.Mods MemPatch patches = new MemPatch(); - bool enabled = false; + bool enabled = false; bool printValues = false; int offset_shift = 0; @@ -236,7 +237,7 @@ namespace Ryujinx.HLE.Loaders.Mods continue; } - if (!Int32.TryParse(tokens[0], System.Globalization.NumberStyles.HexNumber, null, out int offset)) + if (!int.TryParse(tokens[0], System.Globalization.NumberStyles.HexNumber, null, out int offset)) { ParseWarn(); diff --git a/Ryujinx.HLE/Loaders/Mods/MemPatch.cs b/Ryujinx.HLE/Loaders/Mods/MemPatch.cs index 8b2dcb49..e224c3ef 100644 --- a/Ryujinx.HLE/Loaders/Mods/MemPatch.cs +++ b/Ryujinx.HLE/Loaders/Mods/MemPatch.cs @@ -1,10 +1,8 @@ -using Ryujinx.Cpu; +using Ryujinx.Common.Logging; using System; using System.Collections.Generic; using System.Linq; -using Ryujinx.Common.Logging; - namespace Ryujinx.HLE.Loaders.Mods { public class MemPatch @@ -71,7 +69,7 @@ namespace Ryujinx.HLE.Loaders.Mods foreach (var (offset, patch) in _patches.OrderBy(item => item.Key)) { int patchOffset = (int)offset; - int patchSize = patch.Length; + int patchSize = patch.Length; if (patchOffset < protectedOffset || patchOffset > memory.Length) { @@ -82,7 +80,7 @@ namespace Ryujinx.HLE.Loaders.Mods if (patchOffset + patchSize > memory.Length) { - patchSize = memory.Length - (int)patchOffset; // Add warning? + patchSize = memory.Length - patchOffset; // Add warning? } Logger.Info?.Print(LogClass.ModLoader, $"Patching address offset {patchOffset:x} <= {BitConverter.ToString(patch).Replace('-', ' ')} len={patchSize}"); diff --git a/Ryujinx.HLE/MemoryConfiguration.cs b/Ryujinx.HLE/MemoryConfiguration.cs index 2a59e04f..e56658f8 100644 --- a/Ryujinx.HLE/MemoryConfiguration.cs +++ b/Ryujinx.HLE/MemoryConfiguration.cs @@ -5,12 +5,12 @@ namespace Ryujinx.HLE { public enum MemoryConfiguration { - MemoryConfiguration4GB = 0, + MemoryConfiguration4GB = 0, MemoryConfiguration4GBAppletDev = 1, MemoryConfiguration4GBSystemDev = 2, - MemoryConfiguration6GB = 3, + MemoryConfiguration6GB = 3, MemoryConfiguration6GBAppletDev = 4, - MemoryConfiguration8GB = 5 + MemoryConfiguration8GB = 5 } static class MemoryConfigurationExtensions @@ -21,12 +21,12 @@ namespace Ryujinx.HLE { return configuration switch { - MemoryConfiguration.MemoryConfiguration4GB => MemoryArrange.MemoryArrange4GB, + MemoryConfiguration.MemoryConfiguration4GB => MemoryArrange.MemoryArrange4GB, MemoryConfiguration.MemoryConfiguration4GBAppletDev => MemoryArrange.MemoryArrange4GBAppletDev, MemoryConfiguration.MemoryConfiguration4GBSystemDev => MemoryArrange.MemoryArrange4GBSystemDev, - MemoryConfiguration.MemoryConfiguration6GB => MemoryArrange.MemoryArrange6GB, + MemoryConfiguration.MemoryConfiguration6GB => MemoryArrange.MemoryArrange6GB, MemoryConfiguration.MemoryConfiguration6GBAppletDev => MemoryArrange.MemoryArrange6GBAppletDev, - MemoryConfiguration.MemoryConfiguration8GB => MemoryArrange.MemoryArrange8GB, + MemoryConfiguration.MemoryConfiguration8GB => MemoryArrange.MemoryArrange8GB, _ => throw new AggregateException($"Invalid memory configuration \"{configuration}\".") }; } @@ -40,7 +40,7 @@ namespace Ryujinx.HLE MemoryConfiguration.MemoryConfiguration4GBSystemDev => MemorySize.MemorySize4GB, MemoryConfiguration.MemoryConfiguration6GB or MemoryConfiguration.MemoryConfiguration6GBAppletDev => MemorySize.MemorySize6GB, - MemoryConfiguration.MemoryConfiguration8GB => MemorySize.MemorySize8GB, + MemoryConfiguration.MemoryConfiguration8GB => MemorySize.MemorySize8GB, _ => throw new AggregateException($"Invalid memory configuration \"{configuration}\".") }; } @@ -54,7 +54,7 @@ namespace Ryujinx.HLE MemoryConfiguration.MemoryConfiguration4GBSystemDev => 4 * Gb, MemoryConfiguration.MemoryConfiguration6GB or MemoryConfiguration.MemoryConfiguration6GBAppletDev => 6 * Gb, - MemoryConfiguration.MemoryConfiguration8GB => 8 * Gb, + MemoryConfiguration.MemoryConfiguration8GB => 8 * Gb, _ => throw new AggregateException($"Invalid memory configuration \"{configuration}\".") }; } diff --git a/Ryujinx.HLE/PerformanceStatistics.cs b/Ryujinx.HLE/PerformanceStatistics.cs index fdc1e99f..b254356c 100644 --- a/Ryujinx.HLE/PerformanceStatistics.cs +++ b/Ryujinx.HLE/PerformanceStatistics.cs @@ -1,5 +1,4 @@ using Ryujinx.Common; -using System.Diagnostics; using System.Timers; namespace Ryujinx.HLE @@ -7,9 +6,8 @@ namespace Ryujinx.HLE public class PerformanceStatistics { private const double FrameRateWeight = 0.5; - - private const int FrameTypeGame = 0; - private const int PercentTypeFifo = 0; + private const int FrameTypeGame = 0; + private const int PercentTypeFifo = 0; private double[] _averageFrameRate; private double[] _accumulatedFrameTime; @@ -50,7 +48,6 @@ namespace Ryujinx.HLE _resetTimer = new Timer(1000); _resetTimer.Elapsed += ResetTimerElapsed; - _resetTimer.AutoReset = true; _resetTimer.Start(); @@ -75,10 +72,8 @@ namespace Ryujinx.HLE frameRate = _framesRendered[frameType] / _accumulatedFrameTime[frameType]; } - _averageFrameRate[frameType] = LinearInterpolate(_averageFrameRate[frameType], frameRate); - - _framesRendered[frameType] = 0; - + _averageFrameRate[frameType] = LinearInterpolate(_averageFrameRate[frameType], frameRate); + _framesRendered[frameType] = 0; _accumulatedFrameTime[frameType] = 0; } } @@ -96,15 +91,13 @@ namespace Ryujinx.HLE percent = (_accumulatedActiveTime[percentType] / _percentTime[percentType]) * 100; } - _averagePercent[percentType] = percent; - - _percentTime[percentType] = 0; - + _averagePercent[percentType] = percent; + _percentTime[percentType] = 0; _accumulatedActiveTime[percentType] = 0; } } - private double LinearInterpolate(double lhs, double rhs) + private static double LinearInterpolate(double lhs, double rhs) { return lhs * (1.0 - FrameRateWeight) + rhs * FrameRateWeight; } @@ -133,26 +126,23 @@ namespace Ryujinx.HLE private void EndPercentTime(int percentType) { - double currentTime = PerformanceCounter.ElapsedTicks * _ticksToSeconds; - - double elapsedTime = currentTime - _percentLastEndTime[percentType]; + double currentTime = PerformanceCounter.ElapsedTicks * _ticksToSeconds; + double elapsedTime = currentTime - _percentLastEndTime[percentType]; double elapsedActiveTime = currentTime - _percentStartTime[percentType]; lock (_percentLock[percentType]) { _accumulatedActiveTime[percentType] += elapsedActiveTime; - - _percentTime[percentType] += elapsedTime; + _percentTime[percentType] += elapsedTime; } _percentLastEndTime[percentType] = currentTime; - _percentStartTime[percentType] = 0; + _percentStartTime[percentType] = 0; } private void RecordFrameTime(int frameType) { double currentFrameTime = PerformanceCounter.ElapsedTicks * _ticksToSeconds; - double elapsedFrameTime = currentFrameTime - _previousFrameTime[frameType]; _previousFrameTime[frameType] = currentFrameTime; @@ -175,4 +165,4 @@ namespace Ryujinx.HLE return _averagePercent[PercentTypeFifo]; } } -} +} \ No newline at end of file diff --git a/Ryujinx.HLE/Utilities/FontUtils.cs b/Ryujinx.HLE/Utilities/FontUtils.cs deleted file mode 100644 index 91cbdee7..00000000 --- a/Ryujinx.HLE/Utilities/FontUtils.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.IO; - -namespace Ryujinx.HLE.Utilities -{ - public static class FontUtils - { - private static readonly uint FontKey = 0x06186249; - - public static byte[] DecryptFont(Stream bfttfStream) - { - uint KXor(uint In) => In ^ FontKey; - - using (BinaryReader reader = new BinaryReader(bfttfStream)) - { - using (MemoryStream ttfStream = new MemoryStream()) - { - using (BinaryWriter output = new BinaryWriter(ttfStream)) - { - if (KXor(reader.ReadUInt32()) != 0x18029a7f) - { - throw new InvalidDataException("Error: Input file is not in BFTTF format!"); - } - - bfttfStream.Position += 4; - - for (int i = 0; i < (bfttfStream.Length - 8) / 4; i++) - { - output.Write(KXor(reader.ReadUInt32())); - } - - return ttfStream.ToArray(); - } - } - } - } - } -} diff --git a/Ryujinx.HLE/Utilities/LinuxError.cs b/Ryujinx.HLE/Utilities/LinuxError.cs deleted file mode 100644 index 81a9d7be..00000000 --- a/Ryujinx.HLE/Utilities/LinuxError.cs +++ /dev/null @@ -1,155 +0,0 @@ -using System.Diagnostics.CodeAnalysis; - -namespace Ryujinx.HLE.Utilities -{ - [SuppressMessage("ReSharper", "InconsistentNaming")] - enum LinuxError - { - SUCCESS = 0, - EPERM = 1 /* Operation not permitted */, - ENOENT = 2 /* No such file or directory */, - ESRCH = 3 /* No such process */, - EINTR = 4 /* Interrupted system call */, - EIO = 5 /* I/O error */, - ENXIO = 6 /* No such device or address */, - E2BIG = 7 /* Argument list too long */, - ENOEXEC = 8 /* Exec format error */, - EBADF = 9 /* Bad file number */, - ECHILD = 10 /* No child processes */, - EAGAIN = 11 /* Try again */, - ENOMEM = 12 /* Out of memory */, - EACCES = 13 /* Permission denied */, - EFAULT = 14 /* Bad address */, - ENOTBLK = 15 /* Block device required */, - EBUSY = 16 /* Device or resource busy */, - EEXIST = 17 /* File exists */, - EXDEV = 18 /* Cross-device link */, - ENODEV = 19 /* No such device */, - ENOTDIR = 20 /* Not a directory */, - EISDIR = 21 /* Is a directory */, - EINVAL = 22 /* Invalid argument */, - ENFILE = 23 /* File table overflow */, - EMFILE = 24 /* Too many open files */, - ENOTTY = 25 /* Not a typewriter */, - ETXTBSY = 26 /* Text file busy */, - EFBIG = 27 /* File too large */, - ENOSPC = 28 /* No space left on device */, - ESPIPE = 29 /* Illegal seek */, - EROFS = 30 /* Read-only file system */, - EMLINK = 31 /* Too many links */, - EPIPE = 32 /* Broken pipe */, - EDOM = 33 /* Math argument out of domain of func */, - ERANGE = 34 /* Math result not representable */, - EDEADLK = 35 /* Resource deadlock would occur */, - ENAMETOOLONG = 36 /* File name too long */, - ENOLCK = 37 /* No record locks available */, - - /* - * This error code is special: arch syscall entry code will return - * -ENOSYS if users try to call a syscall that doesn't exist. To keep - * failures of syscalls that really do exist distinguishable from - * failures due to attempts to use a nonexistent syscall, syscall - * implementations should refrain from returning -ENOSYS. - */ - ENOSYS = 38 /* Invalid system call number */, - ENOTEMPTY = 39 /* Directory not empty */, - ELOOP = 40 /* Too many symbolic links encountered */, - EWOULDBLOCK = EAGAIN /* Operation would block */, - ENOMSG = 42 /* No message of desired type */, - EIDRM = 43 /* Identifier removed */, - ECHRNG = 44 /* Channel number out of range */, - EL2NSYNC = 45 /* Level 2 not synchronized */, - EL3HLT = 46 /* Level 3 halted */, - EL3RST = 47 /* Level 3 reset */, - ELNRNG = 48 /* Link number out of range */, - EUNATCH = 49 /* Protocol driver not attached */, - ENOCSI = 50 /* No CSI structure available */, - EL2HLT = 51 /* Level 2 halted */, - EBADE = 52 /* Invalid exchange */, - EBADR = 53 /* Invalid request descriptor */, - EXFULL = 54 /* Exchange full */, - ENOANO = 55 /* No anode */, - EBADRQC = 56 /* Invalid request code */, - EBADSLT = 57 /* Invalid slot */, - EDEADLOCK = EDEADLK, - EBFONT = 59 /* Bad font file format */, - ENOSTR = 60 /* Device not a stream */, - ENODATA = 61 /* No data available */, - ETIME = 62 /* Timer expired */, - ENOSR = 63 /* Out of streams resources */, - ENONET = 64 /* Machine is not on the network */, - ENOPKG = 65 /* Package not installed */, - EREMOTE = 66 /* Object is remote */, - ENOLINK = 67 /* Link has been severed */, - EADV = 68 /* Advertise error */, - ESRMNT = 69 /* Srmount error */, - ECOMM = 70 /* Communication error on send */, - EPROTO = 71 /* Protocol error */, - EMULTIHOP = 72 /* Multihop attempted */, - EDOTDOT = 73 /* RFS specific error */, - EBADMSG = 74 /* Not a data message */, - EOVERFLOW = 75 /* Value too large for defined data type */, - ENOTUNIQ = 76 /* Name not unique on network */, - EBADFD = 77 /* File descriptor in bad state */, - EREMCHG = 78 /* Remote address changed */, - ELIBACC = 79 /* Can not access a needed shared library */, - ELIBBAD = 80 /* Accessing a corrupted shared library */, - ELIBSCN = 81 /* .lib section in a.out corrupted */, - ELIBMAX = 82 /* Attempting to link in too many shared libraries */, - ELIBEXEC = 83 /* Cannot exec a shared library directly */, - EILSEQ = 84 /* Illegal byte sequence */, - ERESTART = 85 /* Interrupted system call should be restarted */, - ESTRPIPE = 86 /* Streams pipe error */, - EUSERS = 87 /* Too many users */, - ENOTSOCK = 88 /* Socket operation on non-socket */, - EDESTADDRREQ = 89 /* Destination address required */, - EMSGSIZE = 90 /* Message too long */, - EPROTOTYPE = 91 /* Protocol wrong type for socket */, - ENOPROTOOPT = 92 /* Protocol not available */, - EPROTONOSUPPORT = 93 /* Protocol not supported */, - ESOCKTNOSUPPORT = 94 /* Socket type not supported */, - EOPNOTSUPP = 95 /* Operation not supported on transport endpoint */, - EPFNOSUPPORT = 96 /* Protocol family not supported */, - EAFNOSUPPORT = 97 /* Address family not supported by protocol */, - EADDRINUSE = 98 /* Address already in use */, - EADDRNOTAVAIL = 99 /* Cannot assign requested address */, - ENETDOWN = 100 /* Network is down */, - ENETUNREACH = 101 /* Network is unreachable */, - ENETRESET = 102 /* Network dropped connection because of reset */, - ECONNABORTED = 103 /* Software caused connection abort */, - ECONNRESET = 104 /* Connection reset by peer */, - ENOBUFS = 105 /* No buffer space available */, - EISCONN = 106 /* Transport endpoint is already connected */, - ENOTCONN = 107 /* Transport endpoint is not connected */, - ESHUTDOWN = 108 /* Cannot send after transport endpoint shutdown */, - ETOOMANYREFS = 109 /* Too many references: cannot splice */, - ETIMEDOUT = 110 /* Connection timed out */, - ECONNREFUSED = 111 /* Connection refused */, - EHOSTDOWN = 112 /* Host is down */, - EHOSTUNREACH = 113 /* No route to host */, - EALREADY = 114 /* Operation already in progress */, - EINPROGRESS = 115 /* Operation now in progress */, - ESTALE = 116 /* Stale file handle */, - EUCLEAN = 117 /* Structure needs cleaning */, - ENOTNAM = 118 /* Not a XENIX named type file */, - ENAVAIL = 119 /* No XENIX semaphores available */, - EISNAM = 120 /* Is a named type file */, - EREMOTEIO = 121 /* Remote I/O error */, - EDQUOT = 122 /* Quota exceeded */, - ENOMEDIUM = 123 /* No medium found */, - EMEDIUMTYPE = 124 /* Wrong medium type */, - ECANCELED = 125 /* Operation Canceled */, - ENOKEY = 126 /* Required key not available */, - EKEYEXPIRED = 127 /* Key has expired */, - EKEYREVOKED = 128 /* Key has been revoked */, - EKEYREJECTED = 129 /* Key was rejected by service */, - - /* for robust mutexes */ - EOWNERDEAD = 130 /* Owner died */, - ENOTRECOVERABLE = 131 /* State not recoverable */, - - ERFKILL = 132 /* Operation not possible due to RF-kill */, - - EHWPOISON = 133 /* Memory page has hardware error */ - } -} \ No newline at end of file diff --git a/Ryujinx.HLE/Utilities/StreamUtils.cs b/Ryujinx.HLE/Utilities/StreamUtils.cs deleted file mode 100644 index 7b44bc17..00000000 --- a/Ryujinx.HLE/Utilities/StreamUtils.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.IO; - -namespace Ryujinx.HLE.Utilities -{ - static class StreamUtils - { - public static byte[] StreamToBytes(Stream input) - { - using (MemoryStream ms = new MemoryStream()) - { - input.CopyTo(ms); - return ms.ToArray(); - } - } - } -} diff --git a/Ryujinx.HLE/Utilities/StringUtils.cs b/Ryujinx.HLE/Utilities/StringUtils.cs index 0259a4fd..4142ab5b 100644 --- a/Ryujinx.HLE/Utilities/StringUtils.cs +++ b/Ryujinx.HLE/Utilities/StringUtils.cs @@ -12,7 +12,7 @@ namespace Ryujinx.HLE.Utilities { public static byte[] GetFixedLengthBytes(string inputString, int size, Encoding encoding) { - inputString = inputString + "\0"; + inputString += "\0"; int bytesCount = encoding.GetByteCount(inputString); @@ -76,8 +76,8 @@ namespace Ryujinx.HLE.Utilities public static U8Span ReadUtf8Span(ServiceCtx context, int index = 0) { - ulong position = (ulong)context.Request.PtrBuff[index].Position; - ulong size = (ulong)context.Request.PtrBuff[index].Size; + ulong position = context.Request.PtrBuff[index].Position; + ulong size = context.Request.PtrBuff[index].Size; ReadOnlySpan buffer = context.Memory.GetSpan(position, (int)size); @@ -93,7 +93,7 @@ namespace Ryujinx.HLE.Utilities { while (size-- > 0) { - byte value = context.Memory.Read((ulong)position++); + byte value = context.Memory.Read(position++); if (value == 0) { @@ -133,4 +133,4 @@ namespace Ryujinx.HLE.Utilities return i; } } -} +} \ No newline at end of file diff --git a/Ryujinx.HLE/Utilities/StructReader.cs b/Ryujinx.HLE/Utilities/StructReader.cs deleted file mode 100644 index 81e758a8..00000000 --- a/Ryujinx.HLE/Utilities/StructReader.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Ryujinx.Cpu; -using Ryujinx.Memory; -using System; -using System.Runtime.InteropServices; - -namespace Ryujinx.HLE.Utilities -{ - class StructReader - { - private IVirtualMemoryManager _memory; - - public ulong Position { get; private set; } - - public StructReader(IVirtualMemoryManager memory, ulong position) - { - _memory = memory; - Position = position; - } - - public T Read() where T : unmanaged - { - T value = MemoryHelper.Read(_memory, Position); - - Position += (uint)Marshal.SizeOf(); - - return value; - } - - public ReadOnlySpan Read(int size) where T : unmanaged - { - ReadOnlySpan data = _memory.GetSpan(Position, size); - - Position += (uint)size; - - return MemoryMarshal.Cast(data); - } - } -} diff --git a/Ryujinx.HLE/Utilities/StructWriter.cs b/Ryujinx.HLE/Utilities/StructWriter.cs deleted file mode 100644 index 39644db5..00000000 --- a/Ryujinx.HLE/Utilities/StructWriter.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Ryujinx.Cpu; -using Ryujinx.Memory; -using System.Runtime.InteropServices; - -namespace Ryujinx.HLE.Utilities -{ - class StructWriter - { - private IVirtualMemoryManager _memory; - - public ulong Position { get; private set; } - - public StructWriter(IVirtualMemoryManager memory, ulong position) - { - _memory = memory; - Position = position; - } - - public void Write(T value) where T : struct - { - MemoryHelper.Write(_memory, Position, value); - - Position += (ulong)Marshal.SizeOf(); - } - - public void SkipBytes(ulong count) - { - Position += count; - } - } -} diff --git a/Ryujinx.HLE/Utilities/WSAError.cs b/Ryujinx.HLE/Utilities/WSAError.cs deleted file mode 100644 index 81294b8b..00000000 --- a/Ryujinx.HLE/Utilities/WSAError.cs +++ /dev/null @@ -1,134 +0,0 @@ -using System.Diagnostics.CodeAnalysis; - -namespace Ryujinx.HLE.Utilities -{ - [SuppressMessage("ReSharper", "InconsistentNaming")] - enum WsaError - { - /* - * All Windows Sockets error constants are biased by WSABASEERR from - * the "normal" - */ - WSABASEERR = 10000, - - /* - * Windows Sockets definitions of regular Microsoft C error constants - */ - WSAEINTR = (WSABASEERR + 4), - WSAEBADF = (WSABASEERR + 9), - WSAEACCES = (WSABASEERR + 13), - WSAEFAULT = (WSABASEERR + 14), - WSAEINVAL = (WSABASEERR + 22), - WSAEMFILE = (WSABASEERR + 24), - - /* - * Windows Sockets definitions of regular Berkeley error constants - */ - WSAEWOULDBLOCK = (WSABASEERR + 35), - WSAEINPROGRESS = (WSABASEERR + 36), - WSAEALREADY = (WSABASEERR + 37), - WSAENOTSOCK = (WSABASEERR + 38), - WSAEDESTADDRREQ = (WSABASEERR + 39), - WSAEMSGSIZE = (WSABASEERR + 40), - WSAEPROTOTYPE = (WSABASEERR + 41), - WSAENOPROTOOPT = (WSABASEERR + 42), - WSAEPROTONOSUPPORT = (WSABASEERR + 43), - WSAESOCKTNOSUPPORT = (WSABASEERR + 44), - WSAEOPNOTSUPP = (WSABASEERR + 45), - WSAEPFNOSUPPORT = (WSABASEERR + 46), - WSAEAFNOSUPPORT = (WSABASEERR + 47), - WSAEADDRINUSE = (WSABASEERR + 48), - WSAEADDRNOTAVAIL = (WSABASEERR + 49), - WSAENETDOWN = (WSABASEERR + 50), - WSAENETUNREACH = (WSABASEERR + 51), - WSAENETRESET = (WSABASEERR + 52), - WSAECONNABORTED = (WSABASEERR + 53), - WSAECONNRESET = (WSABASEERR + 54), - WSAENOBUFS = (WSABASEERR + 55), - WSAEISCONN = (WSABASEERR + 56), - WSAENOTCONN = (WSABASEERR + 57), - WSAESHUTDOWN = (WSABASEERR + 58), - WSAETOOMANYREFS = (WSABASEERR + 59), - WSAETIMEDOUT = (WSABASEERR + 60), - WSAECONNREFUSED = (WSABASEERR + 61), - WSAELOOP = (WSABASEERR + 62), - WSAENAMETOOLONG = (WSABASEERR + 63), - WSAEHOSTDOWN = (WSABASEERR + 64), - WSAEHOSTUNREACH = (WSABASEERR + 65), - WSAENOTEMPTY = (WSABASEERR + 66), - WSAEPROCLIM = (WSABASEERR + 67), - WSAEUSERS = (WSABASEERR + 68), - WSAEDQUOT = (WSABASEERR + 69), - WSAESTALE = (WSABASEERR + 70), - WSAEREMOTE = (WSABASEERR + 71), - - /* - * Extended Windows Sockets error constant definitions - */ - WSASYSNOTREADY = (WSABASEERR + 91), - WSAVERNOTSUPPORTED = (WSABASEERR + 92), - WSANOTINITIALISED = (WSABASEERR + 93), - WSAEDISCON = (WSABASEERR + 101), - WSAENOMORE = (WSABASEERR + 102), - WSAECANCELLED = (WSABASEERR + 103), - WSAEINVALIDPROCTABLE = (WSABASEERR + 104), - WSAEINVALIDPROVIDER = (WSABASEERR + 105), - WSAEPROVIDERFAILEDINIT = (WSABASEERR + 106), - WSASYSCALLFAILURE = (WSABASEERR + 107), - WSASERVICE_NOT_FOUND = (WSABASEERR + 108), - WSATYPE_NOT_FOUND = (WSABASEERR + 109), - WSA_E_NO_MORE = (WSABASEERR + 110), - WSA_E_CANCELLED = (WSABASEERR + 111), - WSAEREFUSED = (WSABASEERR + 112), - - /* - * Error return codes from gethostbyname() and gethostbyaddr() - * (when using the resolver). Note that these errors are - * retrieved via WSAGetLastError() and must therefore follow - * the rules for avoiding clashes with error numbers from - * specific implementations or language run-time systems. - * For this reason the codes are based at WSABASEERR+1001. - * Note also that [WSA]NO_ADDRESS is defined only for - * compatibility purposes. - */ - - /* Authoritative Answer: Host not found */ - WSAHOST_NOT_FOUND = (WSABASEERR + 1001), - - /* Non-Authoritative: Host not found, or SERVERFAIL */ - WSATRY_AGAIN = (WSABASEERR + 1002), - - /* Non-recoverable errors, FORMERR, REFUSED, NOTIMP */ - WSANO_RECOVERY = (WSABASEERR + 1003), - - /* Valid name, no data record of requested type */ - WSANO_DATA = (WSABASEERR + 1004), - - /* - * Define QOS related error return codes - * - */ - WSA_QOS_RECEIVERS = (WSABASEERR + 1005), - /* at least one Reserve has arrived */ - WSA_QOS_SENDERS = (WSABASEERR + 1006), - /* at least one Path has arrived */ - WSA_QOS_NO_SENDERS = (WSABASEERR + 1007), - /* there are no senders */ - WSA_QOS_NO_RECEIVERS = (WSABASEERR + 1008), - /* there are no receivers */ - WSA_QOS_REQUEST_CONFIRMED = (WSABASEERR + 1009), - /* Reserve has been confirmed */ - WSA_QOS_ADMISSION_FAILURE = (WSABASEERR + 1010), - /* error due to lack of resources */ - WSA_QOS_POLICY_FAILURE = (WSABASEERR + 1011), - /* rejected for administrative reasons - bad credentials */ - WSA_QOS_BAD_STYLE = (WSABASEERR + 1012), - /* unknown or conflicting style */ - WSA_QOS_BAD_OBJECT = (WSABASEERR + 1013), - /* problem with some part of the filterspec or providerspecific - * buffer in general */ - WSA_QOS_TRAFFIC_CTRL_ERROR = (WSABASEERR + 1014), - /* problem with some part of the flowspec */ - WSA_QOS_GENERIC_ERROR = (WSABASEERR + 1015) - } -} -- cgit v1.2.3