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/Loaders/Mods/IPSPatcher.cs | 8 ++--- Ryujinx.HLE/Loaders/Mods/IPSwitchPatcher.cs | 53 +++++++++++++++-------------- Ryujinx.HLE/Loaders/Mods/MemPatch.cs | 8 ++--- 3 files changed, 34 insertions(+), 35 deletions(-) (limited to 'Ryujinx.HLE/Loaders/Mods') 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}"); -- cgit v1.2.3