[Ryujinx.HLE] Address dotnet-format issues (#5380)

* dotnet format style --severity info

Some changes were manually reverted.

* dotnet format analyzers --serverity info

Some changes have been minimally adapted.

* Restore a few unused methods and variables

* Silence dotnet format IDE0060 warnings

* Silence dotnet format IDE0052 warnings

* Address or silence dotnet format IDE1006 warnings

* Address dotnet format CA1816 warnings

* Address or silence dotnet format CA2208 warnings

* Address or silence dotnet format CA1806 and a few CA1854 warnings

* Address dotnet format CA2211 warnings

* Address dotnet format CA1822 warnings

* Address or silence dotnet format CA1069 warnings

* Make dotnet format succeed in style mode

* Address or silence dotnet format CA2211 warnings

* Address review comments

* Address dotnet format CA2208 warnings properly

* Make ProcessResult readonly

* Address most dotnet format whitespace warnings

* Apply dotnet format whitespace formatting

A few of them have been manually reverted and the corresponding warning was silenced

* Add previously silenced warnings back

I have no clue how these disappeared

* Revert formatting changes for while and for-loops

* Format if-blocks correctly

* Run dotnet format style after rebase

* Run dotnet format whitespace after rebase

* Run dotnet format style after rebase

* Run dotnet format analyzers after rebase

* Run dotnet format after rebase and remove unused usings

- analyzers
- style
- whitespace

* Disable 'prefer switch expression' rule

* Add comments to disabled warnings

* Fix a few disabled warnings

* Fix naming rule violation, Convert shader properties to auto-property and convert values to const

* Simplify properties and array initialization, Use const when possible, Remove trailing commas

* Start working on disabled warnings

* Fix and silence a few dotnet-format warnings again

* Run dotnet format after rebase

* Use using declaration instead of block syntax

* Address IDE0251 warnings

* Address a few disabled IDE0060 warnings

* Silence IDE0060 in .editorconfig

* Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas"

This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.

* dotnet format whitespace after rebase

* First dotnet format pass

* Fix naming rule violations

* Fix typo

* Add trailing commas, use targeted new and use array initializer

* Fix build issues

* Fix remaining build issues

* Remove SuppressMessage for CA1069 where possible

* Address dotnet format issues

* Address formatting issues

Co-authored-by: Ac_K <acoustik666@gmail.com>

* Add GetHashCode implementation for RenderingSurfaceInfo

* Explicitly silence CA1822 for every affected method in Syscall

* Address formatting issues in Demangler.cs

* Address review feedback

Co-authored-by: Ac_K <acoustik666@gmail.com>

* Revert marking service methods as static

* Next dotnet format pass

* Address review feedback

---------

Co-authored-by: Ac_K <acoustik666@gmail.com>
This commit is contained in:
TSRBerry 2023-07-16 19:31:14 +02:00 committed by GitHub
parent fec8291c17
commit 326749498b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1015 changed files with 8173 additions and 7615 deletions

View file

@ -8,8 +8,8 @@ namespace Ryujinx.HLE.Loaders.Elf
public ElfDynamic(ElfDynamicTag tag, long value)
{
Tag = tag;
Tag = tag;
Value = value;
}
}
}
}

View file

@ -3,73 +3,74 @@ using System.Diagnostics.CodeAnalysis;
namespace Ryujinx.HLE.Loaders.Elf
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("Design", "CA1069: Enums values should not be duplicated")]
enum ElfDynamicTag
{
DT_NULL = 0,
DT_NEEDED = 1,
DT_PLTRELSZ = 2,
DT_PLTGOT = 3,
DT_HASH = 4,
DT_STRTAB = 5,
DT_SYMTAB = 6,
DT_RELA = 7,
DT_RELASZ = 8,
DT_RELAENT = 9,
DT_STRSZ = 10,
DT_SYMENT = 11,
DT_INIT = 12,
DT_FINI = 13,
DT_SONAME = 14,
DT_RPATH = 15,
DT_SYMBOLIC = 16,
DT_REL = 17,
DT_RELSZ = 18,
DT_RELENT = 19,
DT_PLTREL = 20,
DT_DEBUG = 21,
DT_TEXTREL = 22,
DT_JMPREL = 23,
DT_BIND_NOW = 24,
DT_INIT_ARRAY = 25,
DT_FINI_ARRAY = 26,
DT_INIT_ARRAYSZ = 27,
DT_FINI_ARRAYSZ = 28,
DT_RUNPATH = 29,
DT_FLAGS = 30,
DT_ENCODING = 32,
DT_PREINIT_ARRAY = 32,
DT_NULL = 0,
DT_NEEDED = 1,
DT_PLTRELSZ = 2,
DT_PLTGOT = 3,
DT_HASH = 4,
DT_STRTAB = 5,
DT_SYMTAB = 6,
DT_RELA = 7,
DT_RELASZ = 8,
DT_RELAENT = 9,
DT_STRSZ = 10,
DT_SYMENT = 11,
DT_INIT = 12,
DT_FINI = 13,
DT_SONAME = 14,
DT_RPATH = 15,
DT_SYMBOLIC = 16,
DT_REL = 17,
DT_RELSZ = 18,
DT_RELENT = 19,
DT_PLTREL = 20,
DT_DEBUG = 21,
DT_TEXTREL = 22,
DT_JMPREL = 23,
DT_BIND_NOW = 24,
DT_INIT_ARRAY = 25,
DT_FINI_ARRAY = 26,
DT_INIT_ARRAYSZ = 27,
DT_FINI_ARRAYSZ = 28,
DT_RUNPATH = 29,
DT_FLAGS = 30,
DT_ENCODING = 32,
DT_PREINIT_ARRAY = 32,
DT_PREINIT_ARRAYSZ = 33,
DT_GNU_PRELINKED = 0x6ffffdf5,
DT_GNU_CONFLICTSZ = 0x6ffffdf6,
DT_GNU_LIBLISTSZ = 0x6ffffdf7,
DT_CHECKSUM = 0x6ffffdf8,
DT_PLTPADSZ = 0x6ffffdf9,
DT_MOVEENT = 0x6ffffdfa,
DT_MOVESZ = 0x6ffffdfb,
DT_FEATURE_1 = 0x6ffffdfc,
DT_POSFLAG_1 = 0x6ffffdfd,
DT_SYMINSZ = 0x6ffffdfe,
DT_SYMINENT = 0x6ffffdff,
DT_GNU_HASH = 0x6ffffef5,
DT_TLSDESC_PLT = 0x6ffffef6,
DT_TLSDESC_GOT = 0x6ffffef7,
DT_GNU_CONFLICT = 0x6ffffef8,
DT_GNU_LIBLIST = 0x6ffffef9,
DT_CONFIG = 0x6ffffefa,
DT_DEPAUDIT = 0x6ffffefb,
DT_AUDIT = 0x6ffffefc,
DT_PLTPAD = 0x6ffffefd,
DT_MOVETAB = 0x6ffffefe,
DT_SYMINFO = 0x6ffffeff,
DT_VERSYM = 0x6ffffff0,
DT_RELACOUNT = 0x6ffffff9,
DT_RELCOUNT = 0x6ffffffa,
DT_FLAGS_1 = 0x6ffffffb,
DT_VERDEF = 0x6ffffffc,
DT_VERDEFNUM = 0x6ffffffd,
DT_VERNEED = 0x6ffffffe,
DT_VERNEEDNUM = 0x6fffffff,
DT_AUXILIARY = 0x7ffffffd,
DT_FILTER = 0x7fffffff
DT_GNU_PRELINKED = 0x6ffffdf5,
DT_GNU_CONFLICTSZ = 0x6ffffdf6,
DT_GNU_LIBLISTSZ = 0x6ffffdf7,
DT_CHECKSUM = 0x6ffffdf8,
DT_PLTPADSZ = 0x6ffffdf9,
DT_MOVEENT = 0x6ffffdfa,
DT_MOVESZ = 0x6ffffdfb,
DT_FEATURE_1 = 0x6ffffdfc,
DT_POSFLAG_1 = 0x6ffffdfd,
DT_SYMINSZ = 0x6ffffdfe,
DT_SYMINENT = 0x6ffffdff,
DT_GNU_HASH = 0x6ffffef5,
DT_TLSDESC_PLT = 0x6ffffef6,
DT_TLSDESC_GOT = 0x6ffffef7,
DT_GNU_CONFLICT = 0x6ffffef8,
DT_GNU_LIBLIST = 0x6ffffef9,
DT_CONFIG = 0x6ffffefa,
DT_DEPAUDIT = 0x6ffffefb,
DT_AUDIT = 0x6ffffefc,
DT_PLTPAD = 0x6ffffefd,
DT_MOVETAB = 0x6ffffefe,
DT_SYMINFO = 0x6ffffeff,
DT_VERSYM = 0x6ffffff0,
DT_RELACOUNT = 0x6ffffff9,
DT_RELCOUNT = 0x6ffffffa,
DT_FLAGS_1 = 0x6ffffffb,
DT_VERDEF = 0x6ffffffc,
DT_VERDEFNUM = 0x6ffffffd,
DT_VERNEED = 0x6ffffffe,
DT_VERNEEDNUM = 0x6fffffff,
DT_AUXILIARY = 0x7ffffffd,
DT_FILTER = 0x7fffffff,
}
}
}

View file

@ -4,32 +4,32 @@ namespace Ryujinx.HLE.Loaders.Elf
{
public string Name { get; private set; }
public ElfSymbolType Type { get; private set; }
public ElfSymbolBinding Binding { get; private set; }
public ElfSymbolType Type { get; private set; }
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 readonly bool IsFuncOrObject => Type == ElfSymbolType.SttFunc || Type == ElfSymbolType.SttObject;
public readonly bool IsGlobalOrWeak => Binding == ElfSymbolBinding.StbGlobal || Binding == ElfSymbolBinding.StbWeak;
public int ShIdx { get; private set; }
public int ShIdx { get; private set; }
public ulong Value { get; private set; }
public ulong Size { get; private set; }
public ulong Size { get; private set; }
public ElfSymbol(
string name,
int info,
int other,
int shIdx,
ulong value,
ulong size)
int info,
int other,
int shIdx,
ulong value,
ulong size)
{
Name = name;
Type = (ElfSymbolType)(info & 0xf);
Binding = (ElfSymbolBinding)(info >> 4);
Name = name;
Type = (ElfSymbolType)(info & 0xf);
Binding = (ElfSymbolBinding)(info >> 4);
Visibility = (ElfSymbolVisibility)other;
ShIdx = shIdx;
Value = value;
Size = size;
ShIdx = shIdx;
Value = value;
Size = size;
}
}
}
}

View file

@ -2,13 +2,13 @@
{
struct ElfSymbol32
{
#pragma warning disable CS0649
public uint NameOffset;
public uint ValueAddress;
public uint Size;
public byte Info;
public byte Other;
#pragma warning disable CS0649 // Field is never assigned to
public uint NameOffset;
public uint ValueAddress;
public uint Size;
public byte Info;
public byte Other;
public ushort SectionIndex;
#pragma warning restore CS0649
}
}
}

View file

@ -2,13 +2,13 @@
{
struct ElfSymbol64
{
#pragma warning disable CS0649
public uint NameOffset;
public byte Info;
public byte Other;
#pragma warning disable CS0649 // Field is never assigned to
public uint NameOffset;
public byte Info;
public byte Other;
public ushort SectionIndex;
public ulong ValueAddress;
public ulong Size;
public ulong ValueAddress;
public ulong Size;
#pragma warning restore CS0649
}
}
}

View file

@ -2,8 +2,8 @@ namespace Ryujinx.HLE.Loaders.Elf
{
enum ElfSymbolBinding
{
StbLocal = 0,
StbLocal = 0,
StbGlobal = 1,
StbWeak = 2
StbWeak = 2,
}
}
}

View file

@ -2,12 +2,12 @@ namespace Ryujinx.HLE.Loaders.Elf
{
enum ElfSymbolType
{
SttNoType = 0,
SttObject = 1,
SttFunc = 2,
SttNoType = 0,
SttObject = 1,
SttFunc = 2,
SttSection = 3,
SttFile = 4,
SttCommon = 5,
SttTls = 6
SttFile = 4,
SttCommon = 5,
SttTls = 6,
}
}
}

View file

@ -2,9 +2,9 @@ namespace Ryujinx.HLE.Loaders.Elf
{
enum ElfSymbolVisibility
{
StvDefault = 0,
StvInternal = 1,
StvHidden = 2,
StvProtected = 3
StvDefault = 0,
StvInternal = 1,
StvHidden = 2,
StvProtected = 3,
}
}
}

View file

@ -6,13 +6,13 @@ namespace Ryujinx.HLE.Loaders.Executables
{
byte[] Program { get; }
Span<byte> Text { get; }
Span<byte> Ro { get; }
Span<byte> Ro { get; }
Span<byte> Data { get; }
uint TextOffset { get; }
uint RoOffset { get; }
uint RoOffset { get; }
uint DataOffset { get; }
uint BssOffset { get; }
uint BssSize { get; }
uint BssOffset { get; }
uint BssSize { get; }
}
}
}

View file

@ -9,53 +9,53 @@ namespace Ryujinx.HLE.Loaders.Executables
{
public byte[] Program { get; }
public Span<byte> Text => Program.AsSpan((int)TextOffset, (int)TextSize);
public Span<byte> Ro => Program.AsSpan((int)RoOffset, (int)RoSize);
public Span<byte> Ro => Program.AsSpan((int)RoOffset, (int)RoSize);
public Span<byte> Data => Program.AsSpan((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 uint[] Capabilities { get; }
public bool UsesSecureMemory { get; }
public uint[] 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(in SharedRef<IStorage> inStorage)
{
KipReader reader = new KipReader();
KipReader reader = new();
reader.Initialize(in 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 uint[32];
@ -68,7 +68,7 @@ namespace Ryujinx.HLE.Loaders.Executables
Program = new byte[DataOffset + uncompressedSize];
TextSize = DecompressSection(reader, KipReader.SegmentType.Text, TextOffset, Program);
RoSize = DecompressSection(reader, KipReader.SegmentType.Ro, RoOffset, Program);
RoSize = DecompressSection(reader, KipReader.SegmentType.Ro, RoOffset, Program);
DataSize = DecompressSection(reader, KipReader.SegmentType.Data, DataOffset, Program);
}
@ -83,4 +83,4 @@ namespace Ryujinx.HLE.Loaders.Executables
return (uint)uncompressedSize;
}
}
}
}

View file

@ -8,31 +8,31 @@ namespace Ryujinx.HLE.Loaders.Executables
{
public byte[] Program { get; }
public Span<byte> Text => Program.AsSpan((int)TextOffset, (int)Header.NroSegments[0].Size);
public Span<byte> Ro => Program.AsSpan((int)RoOffset, (int)Header.NroSegments[1].Size);
public Span<byte> Ro => Program.AsSpan((int)RoOffset, (int)Header.NroSegments[1].Size);
public Span<byte> Data => Program.AsSpan((int)DataOffset, (int)Header.NroSegments[2].Size);
public uint TextOffset => Header.NroSegments[0].FileOffset;
public uint RoOffset => Header.NroSegments[1].FileOffset;
public uint RoOffset => Header.NroSegments[1].FileOffset;
public uint DataOffset => Header.NroSegments[2].FileOffset;
public uint BssOffset => DataOffset + (uint)Data.Length;
public uint BssSize => Header.BssSize;
public uint BssOffset => DataOffset + (uint)Data.Length;
public uint BssSize => Header.BssSize;
public uint Mod0Offset => (uint)Start.Mod0Offset;
public uint FileSize => Header.Size;
public uint FileSize => Header.Size;
public ulong SourceAddress { get; private set; }
public ulong BssAddress { get; private set; }
public ulong BssAddress { get; private set; }
public NroExecutable(IStorage inStorage, ulong sourceAddress = 0, ulong bssAddress = 0) : base(inStorage)
{
Program = new byte[FileSize];
SourceAddress = sourceAddress;
BssAddress = bssAddress;
BssAddress = bssAddress;
OpenNroSegment(NroSegmentType.Text, false).Read(0, Text);
OpenNroSegment(NroSegmentType.Ro , false).Read(0, Ro);
OpenNroSegment(NroSegmentType.Ro, false).Read(0, Ro);
OpenNroSegment(NroSegmentType.Data, false).Read(0, Data);
}
}
}
}

View file

@ -13,20 +13,20 @@ namespace Ryujinx.HLE.Loaders.Executables
{
public byte[] Program { get; }
public Span<byte> Text => Program.AsSpan((int)TextOffset, (int)TextSize);
public Span<byte> Ro => Program.AsSpan((int)RoOffset, (int)RoSize);
public Span<byte> Ro => Program.AsSpan((int)RoOffset, (int)RoSize);
public Span<byte> Data => Program.AsSpan((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 string Name;
public Array32<byte> BuildId;
[GeneratedRegex(@"[a-z]:[\\/][ -~]{5,}\.nss", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)]
@ -38,24 +38,24 @@ namespace Ryujinx.HLE.Loaders.Executables
public NsoExecutable(IStorage inStorage, string name = null)
{
NsoReader reader = new NsoReader();
NsoReader reader = new();
reader.Initialize(inStorage.AsFile(OpenMode.Read)).ThrowIfFailure();
TextOffset = reader.Header.Segments[0].MemoryOffset;
RoOffset = reader.Header.Segments[1].MemoryOffset;
RoOffset = reader.Header.Segments[1].MemoryOffset;
DataOffset = reader.Header.Segments[2].MemoryOffset;
BssSize = reader.Header.BssSize;
BssSize = reader.Header.BssSize;
reader.GetSegmentSize(NsoReader.SegmentType.Data, out uint uncompressedSize).ThrowIfFailure();
Program = new byte[DataOffset + uncompressedSize];
TextSize = DecompressSection(reader, NsoReader.SegmentType.Text, TextOffset);
RoSize = DecompressSection(reader, NsoReader.SegmentType.Ro, RoOffset);
RoSize = DecompressSection(reader, NsoReader.SegmentType.Ro, RoOffset);
DataSize = DecompressSection(reader, NsoReader.SegmentType.Data, DataOffset);
Name = name;
Name = name;
BuildId = reader.Header.ModuleId;
PrintRoSectionInfo();
@ -74,12 +74,12 @@ namespace Ryujinx.HLE.Loaders.Executables
private void PrintRoSectionInfo()
{
string rawTextBuffer = Encoding.ASCII.GetString(Ro);
StringBuilder stringBuilder = new StringBuilder();
string rawTextBuffer = Encoding.ASCII.GetString(Ro);
StringBuilder stringBuilder = new();
string modulePath = null;
if (BitConverter.ToInt32(Ro.Slice(0, 4)) == 0)
if (BitConverter.ToInt32(Ro[..4]) == 0)
{
int length = BitConverter.ToInt32(Ro.Slice(4, 4));
if (length > 0)
@ -108,7 +108,7 @@ namespace Ryujinx.HLE.Loaders.Executables
MatchCollection sdkMwMatches = SdkMwRegex().Matches(rawTextBuffer);
if (sdkMwMatches.Count != 0)
{
string libHeader = " SDK Libraries: ";
string libHeader = " SDK Libraries: ";
string libContent = string.Join($"\n{new string(' ', libHeader.Length)}", sdkMwMatches);
stringBuilder.AppendLine($"{libHeader}{libContent}");
@ -120,4 +120,4 @@ namespace Ryujinx.HLE.Loaders.Executables
}
}
}
}
}

View file

@ -1,13 +1,12 @@
using Ryujinx.Common.Logging;
using System;
using System.IO;
using System.Text;
namespace Ryujinx.HLE.Loaders.Mods
{
class IpsPatcher
{
MemPatch _patches;
readonly MemPatch _patches;
public IpsPatcher(BinaryReader reader)
{
@ -20,15 +19,15 @@ namespace Ryujinx.HLE.Loaders.Mods
private static MemPatch ParseIps(BinaryReader reader)
{
ReadOnlySpan<byte> IpsHeaderMagic = "PATCH"u8;
ReadOnlySpan<byte> IpsTailMagic = "EOF"u8;
ReadOnlySpan<byte> Ips32HeaderMagic = "IPS32"u8;
ReadOnlySpan<byte> Ips32TailMagic = "EEOF"u8;
ReadOnlySpan<byte> ipsHeaderMagic = "PATCH"u8;
ReadOnlySpan<byte> ipsTailMagic = "EOF"u8;
ReadOnlySpan<byte> ips32HeaderMagic = "IPS32"u8;
ReadOnlySpan<byte> ips32TailMagic = "EEOF"u8;
MemPatch patches = new MemPatch();
var header = reader.ReadBytes(IpsHeaderMagic.Length).AsSpan();
MemPatch patches = new();
var header = reader.ReadBytes(ipsHeaderMagic.Length).AsSpan();
if (header.Length != IpsHeaderMagic.Length)
if (header.Length != ipsHeaderMagic.Length)
{
return null;
}
@ -36,15 +35,15 @@ namespace Ryujinx.HLE.Loaders.Mods
bool is32;
ReadOnlySpan<byte> tailSpan;
if (header.SequenceEqual(IpsHeaderMagic))
if (header.SequenceEqual(ipsHeaderMagic))
{
is32 = false;
tailSpan = IpsTailMagic;
tailSpan = ipsTailMagic;
}
else if (header.SequenceEqual(Ips32HeaderMagic))
else if (header.SequenceEqual(ips32HeaderMagic))
{
is32 = true;
tailSpan = Ips32TailMagic;
tailSpan = ips32TailMagic;
}
else
{
@ -114,4 +113,4 @@ namespace Ryujinx.HLE.Loaders.Mods
patches.AddFrom(_patches);
}
}
}
}

View file

@ -14,7 +14,7 @@ namespace Ryujinx.HLE.Loaders.Mods
Normal,
String,
EscapeChar,
Comment
Comment,
}
private readonly StreamReader _reader;
@ -31,13 +31,13 @@ namespace Ryujinx.HLE.Loaders.Mods
}
_reader = reader;
BuildId = header.Substring(BidHeader.Length).TrimEnd().TrimEnd('0');
BuildId = header[BidHeader.Length..].TrimEnd().TrimEnd('0');
}
// Uncomments line and unescapes C style strings within
private static string PreprocessLine(string line)
{
StringBuilder str = new StringBuilder();
StringBuilder str = new();
Token state = Token.Normal;
for (int i = 0; i < line.Length; ++i)
@ -56,29 +56,32 @@ 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;
}
if (state == Token.Comment) break;
if (state == Token.Comment)
{
break;
}
if (state < Token.EscapeChar)
{
@ -112,14 +115,17 @@ namespace Ryujinx.HLE.Loaders.Mods
// Big Endian
static byte[] Hex2ByteArrayBE(string hexstr)
{
if ((hexstr.Length & 1) == 1) return null;
if ((hexstr.Length & 1) == 1)
{
return null;
}
byte[] bytes = new byte[hexstr.Length >> 1];
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);
}
@ -147,11 +153,11 @@ namespace Ryujinx.HLE.Loaders.Mods
return null;
}
MemPatch patches = new MemPatch();
MemPatch patches = new();
bool enabled = false;
bool enabled = false;
bool printValues = false;
int offset_shift = 0;
int offsetShift = 0;
string line;
int lineNum = 0;
@ -205,7 +211,7 @@ namespace Ryujinx.HLE.Loaders.Mods
if (tokens[1] == "offset_shift")
{
if (tokens.Length != 3 || !ParseInt(tokens[2], out offset_shift))
if (tokens.Length != 3 || !ParseInt(tokens[2], out offsetShift))
{
ParseWarn();
@ -244,7 +250,7 @@ namespace Ryujinx.HLE.Loaders.Mods
continue;
}
offset += offset_shift;
offset += offsetShift;
if (printValues)
{
@ -272,4 +278,4 @@ namespace Ryujinx.HLE.Loaders.Mods
patches.AddFrom(Parse());
}
}
}
}

View file

@ -7,7 +7,7 @@ namespace Ryujinx.HLE.Loaders.Mods
{
public class MemPatch
{
readonly Dictionary<uint, byte[]> _patches = new Dictionary<uint, byte[]>();
readonly Dictionary<uint, byte[]> _patches = new();
/// <summary>
/// Adds a patch to specified offset. Overwrites if already present.
@ -69,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)
{
@ -93,4 +93,4 @@ namespace Ryujinx.HLE.Loaders.Mods
return count;
}
}
}
}

View file

@ -9,17 +9,17 @@ namespace Ryujinx.HLE.Loaders.Npdm
public ulong TitleId { get; set; }
public int FsVersion { get; private set; }
public int FsVersion { get; private set; }
public ulong FsPermissionsBitmask { get; private set; }
public ServiceAccessControl ServiceAccessControl { get; private set; }
public KernelAccessControl KernelAccessControl { get; private set; }
public KernelAccessControl KernelAccessControl { get; private set; }
public Aci0(Stream stream, int offset)
{
stream.Seek(offset, SeekOrigin.Begin);
BinaryReader reader = new BinaryReader(stream);
BinaryReader reader = new(stream);
if (reader.ReadInt32() != Aci0Magic)
{
@ -33,16 +33,16 @@ namespace Ryujinx.HLE.Loaders.Npdm
// Reserved.
stream.Seek(8, SeekOrigin.Current);
int fsAccessHeaderOffset = reader.ReadInt32();
int fsAccessHeaderSize = reader.ReadInt32();
int fsAccessHeaderOffset = reader.ReadInt32();
int fsAccessHeaderSize = reader.ReadInt32();
int serviceAccessControlOffset = reader.ReadInt32();
int serviceAccessControlSize = reader.ReadInt32();
int kernelAccessControlOffset = reader.ReadInt32();
int kernelAccessControlSize = reader.ReadInt32();
int serviceAccessControlSize = reader.ReadInt32();
int kernelAccessControlOffset = reader.ReadInt32();
int kernelAccessControlSize = reader.ReadInt32();
FsAccessHeader fsAccessHeader = new FsAccessHeader(stream, offset + fsAccessHeaderOffset, fsAccessHeaderSize);
FsAccessHeader fsAccessHeader = new(stream, offset + fsAccessHeaderOffset, fsAccessHeaderSize);
FsVersion = fsAccessHeader.Version;
FsVersion = fsAccessHeader.Version;
FsPermissionsBitmask = fsAccessHeader.PermissionsBitmask;
ServiceAccessControl = new ServiceAccessControl(stream, offset + serviceAccessControlOffset, serviceAccessControlSize);

View file

@ -8,25 +8,25 @@ namespace Ryujinx.HLE.Loaders.Npdm
private const int AcidMagic = 'A' << 0 | 'C' << 8 | 'I' << 16 | 'D' << 24;
public byte[] Rsa2048Signature { get; private set; }
public byte[] Rsa2048Modulus { get; private set; }
public int Unknown1 { get; private set; }
public int Flags { get; private set; }
public byte[] Rsa2048Modulus { get; private set; }
public int Unknown1 { get; private set; }
public int Flags { get; private set; }
public long TitleIdRangeMin { get; private set; }
public long TitleIdRangeMax { get; private set; }
public FsAccessControl FsAccessControl { get; private set; }
public FsAccessControl FsAccessControl { get; private set; }
public ServiceAccessControl ServiceAccessControl { get; private set; }
public KernelAccessControl KernelAccessControl { get; private set; }
public KernelAccessControl KernelAccessControl { get; private set; }
public Acid(Stream stream, int offset)
{
stream.Seek(offset, SeekOrigin.Begin);
BinaryReader reader = new BinaryReader(stream);
BinaryReader reader = new(stream);
Rsa2048Signature = reader.ReadBytes(0x100);
Rsa2048Modulus = reader.ReadBytes(0x100);
Rsa2048Modulus = reader.ReadBytes(0x100);
if (reader.ReadInt32() != AcidMagic)
{
@ -44,12 +44,12 @@ namespace Ryujinx.HLE.Loaders.Npdm
TitleIdRangeMin = reader.ReadInt64();
TitleIdRangeMax = reader.ReadInt64();
int fsAccessControlOffset = reader.ReadInt32();
int fsAccessControlSize = reader.ReadInt32();
int fsAccessControlOffset = reader.ReadInt32();
int fsAccessControlSize = reader.ReadInt32();
int serviceAccessControlOffset = reader.ReadInt32();
int serviceAccessControlSize = reader.ReadInt32();
int kernelAccessControlOffset = reader.ReadInt32();
int kernelAccessControlSize = reader.ReadInt32();
int serviceAccessControlSize = reader.ReadInt32();
int kernelAccessControlOffset = reader.ReadInt32();
int kernelAccessControlSize = reader.ReadInt32();
FsAccessControl = new FsAccessControl(stream, offset + fsAccessControlOffset, fsAccessControlSize);

View file

@ -4,25 +4,25 @@ namespace Ryujinx.HLE.Loaders.Npdm
{
public class FsAccessControl
{
public int Version { get; private set; }
public int Version { get; private set; }
public ulong PermissionsBitmask { get; private set; }
public int Unknown1 { get; private set; }
public int Unknown2 { get; private set; }
public int Unknown3 { get; private set; }
public int Unknown4 { get; private set; }
public int Unknown1 { get; private set; }
public int Unknown2 { get; private set; }
public int Unknown3 { get; private set; }
public int Unknown4 { get; private set; }
public FsAccessControl(Stream stream, int offset, int size)
{
stream.Seek(offset, SeekOrigin.Begin);
BinaryReader reader = new BinaryReader(stream);
BinaryReader reader = new(stream);
Version = reader.ReadInt32();
Version = reader.ReadInt32();
PermissionsBitmask = reader.ReadUInt64();
Unknown1 = reader.ReadInt32();
Unknown2 = reader.ReadInt32();
Unknown3 = reader.ReadInt32();
Unknown4 = reader.ReadInt32();
Unknown1 = reader.ReadInt32();
Unknown2 = reader.ReadInt32();
Unknown3 = reader.ReadInt32();
Unknown4 = reader.ReadInt32();
}
}
}

View file

@ -6,16 +6,16 @@ namespace Ryujinx.HLE.Loaders.Npdm
{
class FsAccessHeader
{
public int Version { get; private set; }
public int Version { get; private set; }
public ulong PermissionsBitmask { get; private set; }
public FsAccessHeader(Stream stream, int offset, int size)
{
stream.Seek(offset, SeekOrigin.Begin);
BinaryReader reader = new BinaryReader(stream);
BinaryReader reader = new(stream);
Version = reader.ReadInt32();
Version = reader.ReadInt32();
PermissionsBitmask = reader.ReadUInt64();
int dataSize = reader.ReadInt32();
@ -24,8 +24,9 @@ namespace Ryujinx.HLE.Loaders.Npdm
{
throw new InvalidNpdmException("FsAccessHeader is corrupted!");
}
int contentOwnerIdSize = reader.ReadInt32();
#pragma warning disable IDE0059 // Remove unnecessary value assignment
int contentOwnerIdSize = reader.ReadInt32();
#pragma warning restore IDE0059
int dataAndContentOwnerIdSize = reader.ReadInt32();
if (dataAndContentOwnerIdSize != 0x1c)

View file

@ -12,7 +12,7 @@ namespace Ryujinx.HLE.Loaders.Npdm
Capabilities = new int[size / 4];
BinaryReader reader = new BinaryReader(stream);
BinaryReader reader = new(stream);
for (int index = 0; index < Capabilities.Length; index++)
{

View file

@ -11,22 +11,22 @@ namespace Ryujinx.HLE.Loaders.Npdm
{
private const int MetaMagic = 'M' << 0 | 'E' << 8 | 'T' << 16 | 'A' << 24;
public byte ProcessFlags { get; private set; }
public bool Is64Bit { get; private set; }
public byte MainThreadPriority { get; private set; }
public byte DefaultCpuId { get; private set; }
public int PersonalMmHeapSize { get; private set; }
public int Version { get; private set; }
public int MainThreadStackSize { get; private set; }
public string TitleName { get; set; }
public byte[] ProductCode { get; private set; }
public byte ProcessFlags { get; private set; }
public bool Is64Bit { get; private set; }
public byte MainThreadPriority { get; private set; }
public byte DefaultCpuId { get; private set; }
public int PersonalMmHeapSize { get; private set; }
public int Version { get; private set; }
public int MainThreadStackSize { get; private set; }
public string TitleName { get; set; }
public byte[] ProductCode { get; private set; }
public Aci0 Aci0 { get; private set; }
public Acid Acid { get; private set; }
public Npdm(Stream stream)
{
BinaryReader reader = new BinaryReader(stream);
BinaryReader reader = new(stream);
if (reader.ReadInt32() != MetaMagic)
{
@ -42,7 +42,7 @@ namespace Ryujinx.HLE.Loaders.Npdm
reader.ReadByte();
MainThreadPriority = reader.ReadByte();
DefaultCpuId = reader.ReadByte();
DefaultCpuId = reader.ReadByte();
reader.ReadInt32();
@ -61,9 +61,11 @@ namespace Ryujinx.HLE.Loaders.Npdm
stream.Seek(0x30, SeekOrigin.Current);
int aci0Offset = reader.ReadInt32();
int aci0Size = reader.ReadInt32();
#pragma warning disable IDE0059 // Remove unnecessary value assignment
int aci0Size = reader.ReadInt32();
int acidOffset = reader.ReadInt32();
int acidSize = reader.ReadInt32();
int acidSize = reader.ReadInt32();
#pragma warning restore IDE0059
Aci0 = new Aci0(stream, aci0Offset);
Acid = new Acid(stream, acidOffset);

View file

@ -13,11 +13,11 @@ namespace Ryujinx.HLE.Loaders.Npdm
{
stream.Seek(offset, SeekOrigin.Begin);
BinaryReader reader = new BinaryReader(stream);
BinaryReader reader = new(stream);
int bytesRead = 0;
Dictionary<string, bool> services = new Dictionary<string, bool>();
Dictionary<string, bool> services = new();
while (bytesRead != size)
{
@ -28,7 +28,7 @@ namespace Ryujinx.HLE.Loaders.Npdm
break;
}
int length = (controlByte & 0x07) + 1;
int length = (controlByte & 0x07) + 1;
bool registerAllowed = (controlByte & 0x80) != 0;
services[Encoding.ASCII.GetString(reader.ReadBytes(length))] = registerAllowed;

View file

@ -86,7 +86,7 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions
bool enablePtc = device.System.EnablePtc && !modLoadResult.Modified;
if (!enablePtc)
{
Logger.Warning?.Print(LogClass.Ptc, $"Detected unsupported ExeFs modifications. PTC disabled.");
Logger.Warning?.Print(LogClass.Ptc, "Detected unsupported ExeFs modifications. PTC disabled.");
}
// We allow it for nx-hbloader because it can be used to launch homebrew.
@ -131,4 +131,4 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions
return processResult;
}
}
}
}

View file

@ -1,10 +1,10 @@
using LibHac.Common;
using LibHac.FsSystem;
using LibHac.Loader;
using LibHac.Ncm;
using LibHac.Ns;
using Ryujinx.HLE.HOS;
using Ryujinx.HLE.Loaders.Processes.Extensions;
using ApplicationId = LibHac.Ncm.ApplicationId;
namespace Ryujinx.HLE.Loaders.Processes
{
@ -13,8 +13,8 @@ namespace Ryujinx.HLE.Loaders.Processes
public static ProcessResult Load(this LocalFileSystem exeFs, Switch device, string romFsPath = "")
{
MetaLoader metaLoader = exeFs.GetNpdm();
var nacpData = new BlitStruct<ApplicationControlProperty>(1);
ulong programId = metaLoader.GetProgramId();
var nacpData = new BlitStruct<ApplicationControlProperty>(1);
ulong programId = metaLoader.GetProgramId();
device.Configuration.VirtualFileSystem.ModLoader.CollectMods(
new[] { programId },
@ -37,4 +37,4 @@ namespace Ryujinx.HLE.Loaders.Processes
return processResult;
}
}
}
}

View file

@ -58,4 +58,4 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions
metaLoader.Load(npdmBuffer).ThrowIfFailure();
}
}
}
}

View file

@ -20,7 +20,7 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions
public static ProcessResult Load(this Nca nca, Switch device, Nca patchNca, Nca controlNca)
{
// Extract RomFs and ExeFs from NCA.
IStorage romFs = nca.GetRomFs(device, patchNca);
IStorage romFs = nca.GetRomFs(device, patchNca);
IFileSystem exeFs = nca.GetExeFs(device, patchNca);
if (exeFs == null)
@ -173,4 +173,4 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions
return nacpData;
}
}
}
}

View file

@ -17,16 +17,16 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions
{
public static class PartitionFileSystemExtensions
{
private static readonly DownloadableContentJsonSerializerContext ContentSerializerContext = new(JsonHelper.GetDefaultSerializerOptions());
private static readonly TitleUpdateMetadataJsonSerializerContext TitleSerializerContext = new(JsonHelper.GetDefaultSerializerOptions());
private static readonly DownloadableContentJsonSerializerContext _contentSerializerContext = new(JsonHelper.GetDefaultSerializerOptions());
private static readonly TitleUpdateMetadataJsonSerializerContext _titleSerializerContext = new(JsonHelper.GetDefaultSerializerOptions());
internal static (bool, ProcessResult) TryLoad(this PartitionFileSystem partitionFileSystem, Switch device, string path, out string errorMessage)
{
errorMessage = null;
// Load required NCAs.
Nca mainNca = null;
Nca patchNca = null;
Nca mainNca = null;
Nca patchNca = null;
Nca controlNca = null;
try
@ -88,7 +88,7 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions
string titleUpdateMetadataPath = System.IO.Path.Combine(AppDataManager.GamesDirPath, titleIdBase.ToString("x16"), "updates.json");
if (File.Exists(titleUpdateMetadataPath))
{
string updatePath = JsonHelper.DeserializeFromFile(titleUpdateMetadataPath, TitleSerializerContext.TitleUpdateMetadata).Selected;
string updatePath = JsonHelper.DeserializeFromFile(titleUpdateMetadataPath, _titleSerializerContext.TitleUpdateMetadata).Selected;
if (File.Exists(updatePath))
{
PartitionFileSystem updatePartitionFileSystem = new(new FileStream(updatePath, FileMode.Open, FileAccess.Read).AsStorage());
@ -142,7 +142,7 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions
string addOnContentMetadataPath = System.IO.Path.Combine(AppDataManager.GamesDirPath, mainNca.Header.TitleId.ToString("x16"), "dlc.json");
if (File.Exists(addOnContentMetadataPath))
{
List<DownloadableContentContainer> dlcContainerList = JsonHelper.DeserializeFromFile(addOnContentMetadataPath, ContentSerializerContext.ListDownloadableContentContainer);
List<DownloadableContentContainer> dlcContainerList = JsonHelper.DeserializeFromFile(addOnContentMetadataPath, _contentSerializerContext.ListDownloadableContentContainer);
foreach (DownloadableContentContainer downloadableContentContainer in dlcContainerList)
{
@ -177,4 +177,4 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions
return new Nca(device.Configuration.VirtualFileSystem.KeySet, ncaFile.Release().AsStorage());
}
}
}
}

View file

@ -17,7 +17,7 @@
"subsdk7",
"subsdk8",
"subsdk9",
"sdk"
"sdk",
};
public static readonly string MainNpdmPath = "/main.npdm";
@ -27,7 +27,7 @@
public const bool AslrEnabled = true;
public const int NsoArgsHeaderSize = 8;
public const int NsoArgsDataSize = 0x9000;
public const int NsoArgsTotalSize = NsoArgsHeaderSize + NsoArgsDataSize;
public const int NsoArgsDataSize = 0x9000;
public const int NsoArgsTotalSize = NsoArgsHeaderSize + NsoArgsDataSize;
}
}
}

View file

@ -12,7 +12,6 @@ using Ryujinx.HLE.Loaders.Processes.Extensions;
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Linq;
using Path = System.IO.Path;
namespace Ryujinx.HLE.Loaders.Processes
@ -29,14 +28,14 @@ namespace Ryujinx.HLE.Loaders.Processes
public ProcessLoader(Switch device)
{
_device = device;
_device = device;
_processesByPid = new ConcurrentDictionary<ulong, ProcessResult>();
}
public bool LoadXci(string path)
{
FileStream stream = new(path, FileMode.Open, FileAccess.Read);
Xci xci = new(_device.Configuration.VirtualFileSystem.KeySet, stream.AsStorage());
Xci xci = new(_device.Configuration.VirtualFileSystem.KeySet, stream.AsStorage());
if (!xci.HasPartition(XciPartitionType.Secure))
{
@ -69,7 +68,7 @@ namespace Ryujinx.HLE.Loaders.Processes
public bool LoadNsp(string path)
{
FileStream file = new(path, FileMode.Open, FileAccess.Read);
FileStream file = new(path, FileMode.Open, FileAccess.Read);
PartitionFileSystem partitionFileSystem = new(file.AsStorage());
(bool success, ProcessResult processResult) = partitionFileSystem.TryLoad(_device, path, out string errorMessage);
@ -101,7 +100,7 @@ namespace Ryujinx.HLE.Loaders.Processes
public bool LoadNca(string path)
{
FileStream file = new(path, FileMode.Open, FileAccess.Read);
Nca nca = new(_device.Configuration.VirtualFileSystem.KeySet, file.AsStorage(false));
Nca nca = new(_device.Configuration.VirtualFileSystem.KeySet, file.AsStorage(false));
ProcessResult processResult = nca.Load(_device, null, null);
@ -141,20 +140,20 @@ namespace Ryujinx.HLE.Loaders.Processes
public bool LoadNxo(string path)
{
var nacpData = new BlitStruct<ApplicationControlProperty>(1);
IFileSystem dummyExeFs = null;
Stream romfsStream = null;
var nacpData = new BlitStruct<ApplicationControlProperty>(1);
IFileSystem dummyExeFs = null;
Stream romfsStream = null;
string programName = "";
ulong programId = 0000000000000000;
ulong programId = 0000000000000000;
// Load executable.
IExecutable executable;
if (Path.GetExtension(path).ToLower() == ".nro")
{
FileStream input = new(path, FileMode.Open);
NroExecutable nro = new(input.AsStorage());
FileStream input = new(path, FileMode.Open);
NroExecutable nro = new(input.AsStorage());
executable = nro;
@ -242,4 +241,4 @@ namespace Ryujinx.HLE.Loaders.Processes
return false;
}
}
}
}

View file

@ -31,7 +31,7 @@ namespace Ryujinx.HLE.Loaders.Processes
public static LibHac.Result RegisterProgramMapInfo(Switch device, PartitionFileSystem partitionFileSystem)
{
ulong applicationId = 0;
int programCount = 0;
int programCount = 0;
Span<bool> hasIndex = stackalloc bool[0x10];
@ -44,7 +44,7 @@ namespace Ryujinx.HLE.Loaders.Processes
continue;
}
ulong currentProgramId = nca.Header.TitleId;
ulong currentProgramId = nca.Header.TitleId;
ulong currentMainProgramId = currentProgramId & ~0xFFFul;
if (applicationId == 0 && currentMainProgramId != 0)
@ -82,9 +82,9 @@ namespace Ryujinx.HLE.Loaders.Processes
for (int i = 0; i < programCount; i++)
{
mapInfo[i].ProgramId = new ProgramId(applicationId + (uint)i);
mapInfo[i].ProgramId = new ProgramId(applicationId + (uint)i);
mapInfo[i].MainProgramId = new ApplicationId(applicationId);
mapInfo[i].ProgramIndex = (byte)i;
mapInfo[i].ProgramIndex = (byte)i;
}
return device.System.LibHacHorizonManager.NsClient.Fs.RegisterProgramIndexMapInfo(mapInfo[..programCount]);
@ -102,9 +102,9 @@ namespace Ryujinx.HLE.Loaders.Processes
control = ref new BlitStruct<ApplicationControlProperty>(1).Value;
// The set sizes don't actually matter as long as they're non-zero because we use directory savedata.
control.UserAccountSaveDataSize = 0x4000;
control.UserAccountSaveDataSize = 0x4000;
control.UserAccountSaveDataJournalSize = 0x4000;
control.SaveDataOwnerId = applicationId.Value;
control.SaveDataOwnerId = applicationId.Value;
Logger.Warning?.Print(LogClass.Application, "No control file was found for this game. Using a dummy one instead. This may cause inaccuracies in some games.");
}
@ -137,10 +137,10 @@ namespace Ryujinx.HLE.Loaders.Processes
endOffset = kip.BssOffset + kip.BssSize;
}
uint codeSize = BitUtils.AlignUp<uint>(kip.TextOffset + endOffset, KPageTableBase.PageSize);
int codePagesCount = (int)(codeSize / KPageTableBase.PageSize);
uint codeSize = BitUtils.AlignUp<uint>(kip.TextOffset + endOffset, KPageTableBase.PageSize);
int codePagesCount = (int)(codeSize / KPageTableBase.PageSize);
ulong codeBaseAddress = kip.Is64BitAddressSpace ? 0x8000000UL : 0x200000UL;
ulong codeAddress = codeBaseAddress + kip.TextOffset;
ulong codeAddress = codeBaseAddress + kip.TextOffset;
ProcessCreationFlags flags = 0;
@ -161,9 +161,9 @@ namespace Ryujinx.HLE.Loaders.Processes
flags |= ProcessCreationFlags.Is64Bit;
}
ProcessCreationInfo creationInfo = new(kip.Name, kip.Version, kip.ProgramId, codeAddress, codePagesCount, flags, 0, 0);
MemoryRegion memoryRegion = kip.UsesSecureMemory ? MemoryRegion.Service : MemoryRegion.Application;
KMemoryRegionManager region = context.MemoryManager.MemoryRegions[(int)memoryRegion];
ProcessCreationInfo creationInfo = new(kip.Name, kip.Version, kip.ProgramId, codeAddress, codePagesCount, flags, 0, 0);
MemoryRegion memoryRegion = kip.UsesSecureMemory ? MemoryRegion.Service : MemoryRegion.Application;
KMemoryRegionManager region = context.MemoryManager.MemoryRegions[(int)memoryRegion];
Result result = region.AllocatePages(out KPageList pageList, (ulong)codePagesCount);
if (result != Result.Success)
@ -241,15 +241,15 @@ namespace Ryujinx.HLE.Loaders.Processes
ref readonly var meta = ref npdm.Meta;
ulong argsStart = 0;
uint argsSize = 0;
uint argsSize = 0;
ulong codeStart = (meta.Flags & 1) != 0 ? 0x8000000UL : 0x200000UL;
uint codeSize = 0;
uint codeSize = 0;
var buildIds = executables.Select(e => (e switch
{
NsoExecutable nso => Convert.ToHexString(nso.BuildId.ItemsRo.ToArray()),
NroExecutable nro => Convert.ToHexString(nro.Header.BuildId),
_ => ""
_ => "",
}).ToUpper());
ulong[] nsoBase = new ulong[executables.Length];
@ -259,7 +259,7 @@ namespace Ryujinx.HLE.Loaders.Processes
IExecutable nso = executables[index];
uint textEnd = nso.TextOffset + (uint)nso.Text.Length;
uint roEnd = nso.RoOffset + (uint)nso.Ro.Length;
uint roEnd = nso.RoOffset + (uint)nso.Ro.Length;
uint dataEnd = nso.DataOffset + (uint)nso.Data.Length + nso.BssSize;
uint nsoSize = textEnd;
@ -290,7 +290,7 @@ namespace Ryujinx.HLE.Loaders.Processes
}
}
int codePagesCount = (int)(codeSize / KPageTableBase.PageSize);
int codePagesCount = (int)(codeSize / KPageTableBase.PageSize);
int personalMmHeapPagesCount = (int)(meta.SystemResourceSize / KPageTableBase.PageSize);
ProcessCreationInfo creationInfo = new(
@ -335,7 +335,7 @@ namespace Ryujinx.HLE.Loaders.Processes
if (result != Result.Success)
{
Logger.Error?.Print(LogClass.Loader, $"Process initialization failed setting resource limit values.");
Logger.Error?.Print(LogClass.Loader, "Process initialization failed setting resource limit values.");
return ProcessResult.Failed;
}
@ -346,7 +346,7 @@ namespace Ryujinx.HLE.Loaders.Processes
MemoryRegion memoryRegion = (MemoryRegion)(npdm.Acid.Flags >> 2 & 0xf);
if (memoryRegion > MemoryRegion.NvServices)
{
Logger.Error?.Print(LogClass.Loader, $"Process initialization failed due to invalid ACID flags.");
Logger.Error?.Print(LogClass.Loader, "Process initialization failed due to invalid ACID flags.");
return ProcessResult.Failed;
}
@ -420,9 +420,9 @@ namespace Ryujinx.HLE.Loaders.Processes
public static Result LoadIntoMemory(KProcess process, IExecutable image, ulong baseAddress)
{
ulong textStart = baseAddress + image.TextOffset;
ulong roStart = baseAddress + image.RoOffset;
ulong roStart = baseAddress + image.RoOffset;
ulong dataStart = baseAddress + image.DataOffset;
ulong bssStart = baseAddress + image.BssOffset;
ulong bssStart = baseAddress + image.BssOffset;
ulong end = dataStart + (ulong)image.Data.Length;
@ -432,7 +432,7 @@ namespace Ryujinx.HLE.Loaders.Processes
}
process.CpuMemory.Write(textStart, image.Text);
process.CpuMemory.Write(roStart, image.Ro);
process.CpuMemory.Write(roStart, image.Ro);
process.CpuMemory.Write(dataStart, image.Data);
process.CpuMemory.Fill(bssStart, image.BssSize, 0);
@ -464,4 +464,4 @@ namespace Ryujinx.HLE.Loaders.Processes
return SetProcessMemoryPermission(dataStart, end - dataStart, KMemoryPermission.ReadAndWrite);
}
}
}
}

View file

@ -7,7 +7,6 @@ using Ryujinx.HLE.HOS.SystemState;
using Ryujinx.HLE.Loaders.Processes.Extensions;
using Ryujinx.Horizon.Common;
using System;
using System.Linq;
namespace Ryujinx.HLE.Loaders.Processes
{
@ -20,36 +19,36 @@ namespace Ryujinx.HLE.Loaders.Processes
public readonly IDiskCacheLoadState DiskCacheLoadState;
public readonly MetaLoader MetaLoader;
public readonly MetaLoader MetaLoader;
public readonly ApplicationControlProperty ApplicationControlProperties;
public readonly ulong ProcessId;
public readonly ulong ProcessId;
public readonly string Name;
public readonly string DisplayVersion;
public readonly ulong ProgramId;
public readonly ulong ProgramId;
public readonly string ProgramIdText;
public readonly bool Is64Bit;
public readonly bool DiskCacheEnabled;
public readonly bool AllowCodeMemoryForJit;
public readonly bool Is64Bit;
public readonly bool DiskCacheEnabled;
public readonly bool AllowCodeMemoryForJit;
public ProcessResult(
MetaLoader metaLoader,
MetaLoader metaLoader,
BlitStruct<ApplicationControlProperty> applicationControlProperties,
bool diskCacheEnabled,
bool allowCodeMemoryForJit,
IDiskCacheLoadState diskCacheLoadState,
ulong pid,
byte mainThreadPriority,
uint mainThreadStackSize,
TitleLanguage titleLanguage)
bool diskCacheEnabled,
bool allowCodeMemoryForJit,
IDiskCacheLoadState diskCacheLoadState,
ulong pid,
byte mainThreadPriority,
uint mainThreadStackSize,
TitleLanguage titleLanguage)
{
_mainThreadPriority = mainThreadPriority;
_mainThreadPriority = mainThreadPriority;
_mainThreadStackSize = mainThreadStackSize;
DiskCacheLoadState = diskCacheLoadState;
ProcessId = pid;
ProcessId = pid;
MetaLoader = metaLoader;
MetaLoader = metaLoader;
ApplicationControlProperties = applicationControlProperties.Value;
if (metaLoader is not null)
@ -64,12 +63,12 @@ namespace Ryujinx.HLE.Loaders.Processes
}
DisplayVersion = ApplicationControlProperties.DisplayVersionString.ToString();
ProgramId = programId;
ProgramIdText = $"{programId:x16}";
Is64Bit = metaLoader.IsProgram64Bit();
ProgramId = programId;
ProgramIdText = $"{programId:x16}";
Is64Bit = metaLoader.IsProgram64Bit();
}
DiskCacheEnabled = diskCacheEnabled;
DiskCacheEnabled = diskCacheEnabled;
AllowCodeMemoryForJit = allowCodeMemoryForJit;
}