2018-11-29 03:01:19 +01:00
|
|
|
using Ryujinx.HLE.Exceptions;
|
|
|
|
using System.IO;
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.Loaders.Npdm
|
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// https://github.com/SciresM/hactool/blob/master/npdm.c
|
|
|
|
// https://github.com/SciresM/hactool/blob/master/npdm.h
|
|
|
|
// http://switchbrew.org/index.php?title=NPDM
|
2019-11-29 05:32:51 +01:00
|
|
|
public class Npdm
|
2018-11-29 03:01:19 +01:00
|
|
|
{
|
|
|
|
private const int MetaMagic = 'M' << 0 | 'E' << 8 | 'T' << 16 | 'A' << 24;
|
|
|
|
|
2020-12-02 00:23:43 +01:00
|
|
|
public byte ProcessFlags { get; private set; }
|
2020-04-12 23:02:37 +02:00
|
|
|
public bool Is64Bit { get; private set; }
|
2018-12-05 01:52:39 +01:00
|
|
|
public byte MainThreadPriority { get; private set; }
|
|
|
|
public byte DefaultCpuId { get; private set; }
|
|
|
|
public int PersonalMmHeapSize { get; private set; }
|
2020-07-09 06:31:15 +02:00
|
|
|
public int Version { get; private set; }
|
2018-12-05 01:52:39 +01:00
|
|
|
public int MainThreadStackSize { get; private set; }
|
2019-09-02 18:03:57 +02:00
|
|
|
public string TitleName { get; set; }
|
2018-12-05 01:52:39 +01:00
|
|
|
public byte[] ProductCode { get; private set; }
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
public Aci0 Aci0 { get; private set; }
|
|
|
|
public Acid Acid { get; private set; }
|
2018-12-05 01:52:39 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
public Npdm(Stream stream)
|
2018-11-29 03:01:19 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
BinaryReader reader = new BinaryReader(stream);
|
2018-11-29 03:01:19 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (reader.ReadInt32() != MetaMagic)
|
2018-11-29 03:01:19 +01:00
|
|
|
{
|
|
|
|
throw new InvalidNpdmException("NPDM Stream doesn't contain NPDM file!");
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
reader.ReadInt64();
|
2018-11-29 03:01:19 +01:00
|
|
|
|
2020-12-02 00:23:43 +01:00
|
|
|
ProcessFlags = reader.ReadByte();
|
2018-11-29 03:01:19 +01:00
|
|
|
|
2020-12-02 00:23:43 +01:00
|
|
|
Is64Bit = (ProcessFlags & 1) != 0;
|
2018-11-29 03:01:19 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
reader.ReadByte();
|
2018-11-29 03:01:19 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
MainThreadPriority = reader.ReadByte();
|
|
|
|
DefaultCpuId = reader.ReadByte();
|
2018-11-29 03:01:19 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
reader.ReadInt32();
|
2018-11-29 03:01:19 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
PersonalMmHeapSize = reader.ReadInt32();
|
2018-11-29 03:01:19 +01:00
|
|
|
|
2020-07-09 06:31:15 +02:00
|
|
|
Version = reader.ReadInt32();
|
2018-11-29 03:01:19 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
MainThreadStackSize = reader.ReadInt32();
|
2018-11-29 03:01:19 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
byte[] tempTitleName = reader.ReadBytes(0x10);
|
2018-11-29 03:01:19 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
TitleName = Encoding.UTF8.GetString(tempTitleName, 0, tempTitleName.Length).Trim('\0');
|
2018-11-29 03:01:19 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
ProductCode = reader.ReadBytes(0x10);
|
2018-11-29 03:01:19 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
stream.Seek(0x30, SeekOrigin.Current);
|
2018-11-29 03:01:19 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
int aci0Offset = reader.ReadInt32();
|
|
|
|
int aci0Size = reader.ReadInt32();
|
|
|
|
int acidOffset = reader.ReadInt32();
|
|
|
|
int acidSize = reader.ReadInt32();
|
2018-11-29 03:01:19 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
Aci0 = new Aci0(stream, aci0Offset);
|
|
|
|
Acid = new Acid(stream, acidOffset);
|
2018-11-29 03:01:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|