2018-08-17 00:47:36 +01:00
|
|
|
using Ryujinx.HLE.Exceptions;
|
2018-06-18 03:28:11 +01:00
|
|
|
using System.IO;
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.Loaders.Npdm
|
|
|
|
{
|
|
|
|
//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
|
|
|
|
class Npdm
|
|
|
|
{
|
2018-08-17 00:47:36 +01:00
|
|
|
private const int MetaMagic = 'M' << 0 | 'E' << 8 | 'T' << 16 | 'A' << 24;
|
|
|
|
|
2018-11-28 22:18:09 +00:00
|
|
|
public byte MmuFlags { get; private set; }
|
|
|
|
public bool Is64Bits { get; private set; }
|
|
|
|
public byte MainThreadPriority { get; private set; }
|
|
|
|
public byte DefaultCpuId { get; private set; }
|
|
|
|
public int PersonalMmHeapSize { get; private set; }
|
|
|
|
public int ProcessCategory { get; private set; }
|
|
|
|
public int MainThreadStackSize { get; private set; }
|
|
|
|
public string TitleName { get; private set; }
|
|
|
|
public byte[] ProductCode { get; private set; }
|
2018-08-17 00:47:36 +01:00
|
|
|
|
|
|
|
public ACI0 ACI0 { get; private set; }
|
|
|
|
public ACID ACID { get; private set; }
|
|
|
|
|
|
|
|
public Npdm(Stream Stream)
|
2018-06-18 03:28:11 +01:00
|
|
|
{
|
2018-08-17 00:47:36 +01:00
|
|
|
BinaryReader Reader = new BinaryReader(Stream);
|
2018-06-18 03:28:11 +01:00
|
|
|
|
2018-08-17 00:47:36 +01:00
|
|
|
if (Reader.ReadInt32() != MetaMagic)
|
2018-06-18 03:28:11 +01:00
|
|
|
{
|
|
|
|
throw new InvalidNpdmException("NPDM Stream doesn't contain NPDM file!");
|
|
|
|
}
|
|
|
|
|
2018-08-17 00:47:36 +01:00
|
|
|
Reader.ReadInt64();
|
|
|
|
|
2018-11-28 22:18:09 +00:00
|
|
|
MmuFlags = Reader.ReadByte();
|
2018-06-18 03:28:11 +01:00
|
|
|
|
2018-11-28 22:18:09 +00:00
|
|
|
Is64Bits = (MmuFlags & 1) != 0;
|
2018-06-18 03:28:11 +01:00
|
|
|
|
2018-08-17 00:47:36 +01:00
|
|
|
Reader.ReadByte();
|
2018-06-18 03:28:11 +01:00
|
|
|
|
2018-11-28 22:18:09 +00:00
|
|
|
MainThreadPriority = Reader.ReadByte();
|
2018-06-18 03:28:11 +01:00
|
|
|
DefaultCpuId = Reader.ReadByte();
|
|
|
|
|
2018-08-17 00:47:36 +01:00
|
|
|
Reader.ReadInt32();
|
2018-06-18 03:28:11 +01:00
|
|
|
|
2018-11-28 22:18:09 +00:00
|
|
|
PersonalMmHeapSize = Reader.ReadInt32();
|
2018-06-18 03:28:11 +01:00
|
|
|
|
2018-11-28 22:18:09 +00:00
|
|
|
ProcessCategory = Reader.ReadInt32();
|
2018-06-18 03:28:11 +01:00
|
|
|
|
2018-11-28 22:18:09 +00:00
|
|
|
MainThreadStackSize = Reader.ReadInt32();
|
2018-06-18 03:28:11 +01:00
|
|
|
|
|
|
|
byte[] TempTitleName = Reader.ReadBytes(0x10);
|
|
|
|
|
2018-08-17 00:47:36 +01:00
|
|
|
TitleName = Encoding.UTF8.GetString(TempTitleName, 0, TempTitleName.Length).Trim('\0');
|
2018-06-18 03:28:11 +01:00
|
|
|
|
2018-08-17 00:47:36 +01:00
|
|
|
ProductCode = Reader.ReadBytes(0x10);
|
2018-06-18 03:28:11 +01:00
|
|
|
|
2018-08-17 00:47:36 +01:00
|
|
|
Stream.Seek(0x30, SeekOrigin.Current);
|
2018-06-18 03:28:11 +01:00
|
|
|
|
2018-08-17 00:47:36 +01:00
|
|
|
int ACI0Offset = Reader.ReadInt32();
|
|
|
|
int ACI0Size = Reader.ReadInt32();
|
|
|
|
int ACIDOffset = Reader.ReadInt32();
|
|
|
|
int ACIDSize = Reader.ReadInt32();
|
2018-06-18 03:28:11 +01:00
|
|
|
|
2018-08-17 00:47:36 +01:00
|
|
|
ACI0 = new ACI0(Stream, ACI0Offset);
|
|
|
|
ACID = new ACID(Stream, ACIDOffset);
|
2018-06-18 03:28:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|