mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-11-18 14:36:39 +00:00
189c0c9c72
* Implement Modding Support * Executables: Rewrite to use contiguous mem and Spans * Reorder ExeFs, Npdm, ControlData and SaveData calls After discussion with gdkchan, it was decided it's best to call LoadExeFs after all other loads are done as it starts the guest process. * Build RomFs manually instead of Layering FS Layered FS approach has considerable latency when building the final romfs. So, we manually replace files in a single romfs instance. * Add RomFs modding via storage file * Fix and cleanup MemPatch * Add dynamically loaded NRO patching * Support exefs file replacement * Rewrite ModLoader to use mods-search architecture * Disable PPTC when exefs patches are detected Disable PPTC on exefs replacements too * Rewrite ModLoader, again * Increased maintainability and matches Atmosphere closely * Creates base mods structure if it doesn't exist * Add Exefs partition replacement * IPSwitch: Fix nsobid parsing * Move mod logs to new LogClass * Allow custom suffixes to title dirs again * Address nits * Add a per-App "Open Mods Directory" context menu item Creates the path if not present. * Normalize tooltips verbiage * Use LocalStorage and remove unused namespaces
84 lines
No EOL
3 KiB
C#
84 lines
No EOL
3 KiB
C#
using LibHac.Fs;
|
|
using LibHac.Loader;
|
|
using System;
|
|
|
|
namespace Ryujinx.HLE.Loaders.Executables
|
|
{
|
|
class KipExecutable : IExecutable
|
|
{
|
|
public byte[] Program { get; }
|
|
public Span<byte> Text => Program.AsSpan().Slice(TextOffset, TextSize);
|
|
public Span<byte> Ro => Program.AsSpan().Slice(RoOffset, RoSize);
|
|
public Span<byte> Data => Program.AsSpan().Slice(DataOffset, DataSize);
|
|
|
|
public int TextOffset { get; }
|
|
public int RoOffset { get; }
|
|
public int DataOffset { get; }
|
|
public int BssOffset { get; }
|
|
|
|
public int TextSize { get; }
|
|
public int RoSize { get; }
|
|
public int DataSize { get; }
|
|
public int BssSize { 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 KipExecutable(IStorage inStorage)
|
|
{
|
|
KipReader reader = new KipReader();
|
|
|
|
reader.Initialize(inStorage).ThrowIfFailure();
|
|
|
|
TextOffset = reader.Segments[0].MemoryOffset;
|
|
RoOffset = reader.Segments[1].MemoryOffset;
|
|
DataOffset = reader.Segments[2].MemoryOffset;
|
|
BssOffset = reader.Segments[3].MemoryOffset;
|
|
BssSize = reader.Segments[3].Size;
|
|
|
|
StackSize = reader.StackSize;
|
|
|
|
UsesSecureMemory = reader.UsesSecureMemory;
|
|
Is64BitAddressSpace = reader.Is64BitAddressSpace;
|
|
Is64Bit = reader.Is64Bit;
|
|
|
|
ProgramId = reader.ProgramId;
|
|
Priority = reader.Priority;
|
|
IdealCoreId = reader.IdealCoreId;
|
|
Version = reader.Version;
|
|
Name = reader.Name.ToString();
|
|
|
|
Capabilities = new int[32];
|
|
|
|
for (int index = 0; index < Capabilities.Length; index++)
|
|
{
|
|
Capabilities[index] = (int)reader.Capabilities[index];
|
|
}
|
|
|
|
reader.GetSegmentSize(KipReader.SegmentType.Data, out int uncompressedSize).ThrowIfFailure();
|
|
Program = new byte[DataOffset + uncompressedSize];
|
|
|
|
TextSize = DecompressSection(reader, KipReader.SegmentType.Text, TextOffset, Program);
|
|
RoSize = DecompressSection(reader, KipReader.SegmentType.Ro, RoOffset, Program);
|
|
DataSize = DecompressSection(reader, KipReader.SegmentType.Data, DataOffset, Program);
|
|
}
|
|
|
|
private static int DecompressSection(KipReader reader, KipReader.SegmentType segmentType, int offset, byte[] Program)
|
|
{
|
|
reader.GetSegmentSize(segmentType, out int uncompressedSize).ThrowIfFailure();
|
|
|
|
var span = Program.AsSpan().Slice(offset, uncompressedSize);
|
|
|
|
reader.ReadSegment(segmentType, span).ThrowIfFailure();
|
|
|
|
return uncompressedSize;
|
|
}
|
|
}
|
|
} |