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.HLE/HOS/Font/SharedFontManager.cs | 158 ------------------------------ Ryujinx.HLE/HOS/Font/SharedFontType.cs | 13 --- 2 files changed, 171 deletions(-) delete mode 100644 Ryujinx.HLE/HOS/Font/SharedFontManager.cs delete mode 100644 Ryujinx.HLE/HOS/Font/SharedFontType.cs (limited to 'Ryujinx.HLE/HOS/Font') 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 -- cgit v1.2.3