0
0
Fork 0
mirror of https://github.com/GreemDev/Ryujinx.git synced 2024-12-23 18:35:47 +00:00
Ryujinx/Ryujinx.HLE/Loaders/Npdm/Npdm.cs

73 lines
2.2 KiB
C#
Raw Normal View History

2018-11-29 02:01:19 +00:00
using Ryujinx.HLE.Exceptions;
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
{
private const int MetaMagic = 'M' << 0 | 'E' << 8 | 'T' << 16 | 'A' << 24;
public byte MmuFlags { get; }
public bool Is64Bits { get; }
public byte MainThreadPriority { get; }
public byte DefaultCpuId { get; }
public int PersonalMmHeapSize { get; }
public int ProcessCategory { get; }
public int MainThreadStackSize { get; }
public string TitleName { get; }
public byte[] ProductCode { get; }
public Aci0 Aci0 { get; }
public Acid Acid { get; }
public Npdm(Stream stream)
2018-11-29 02:01:19 +00:00
{
BinaryReader reader = new BinaryReader(stream);
2018-11-29 02:01:19 +00:00
if (reader.ReadInt32() != MetaMagic)
2018-11-29 02:01:19 +00:00
{
throw new InvalidNpdmException("NPDM Stream doesn't contain NPDM file!");
}
reader.ReadInt64();
2018-11-29 02:01:19 +00:00
MmuFlags = reader.ReadByte();
2018-11-29 02:01:19 +00:00
Is64Bits = (MmuFlags & 1) != 0;
reader.ReadByte();
2018-11-29 02:01:19 +00:00
MainThreadPriority = reader.ReadByte();
DefaultCpuId = reader.ReadByte();
2018-11-29 02:01:19 +00:00
reader.ReadInt32();
2018-11-29 02:01:19 +00:00
PersonalMmHeapSize = reader.ReadInt32();
2018-11-29 02:01:19 +00:00
ProcessCategory = reader.ReadInt32();
2018-11-29 02:01:19 +00:00
MainThreadStackSize = reader.ReadInt32();
2018-11-29 02:01:19 +00:00
byte[] tempTitleName = reader.ReadBytes(0x10);
2018-11-29 02:01:19 +00:00
TitleName = Encoding.UTF8.GetString(tempTitleName, 0, tempTitleName.Length).Trim('\0');
2018-11-29 02:01:19 +00:00
ProductCode = reader.ReadBytes(0x10);
2018-11-29 02:01:19 +00:00
stream.Seek(0x30, SeekOrigin.Current);
2018-11-29 02:01:19 +00:00
int aci0Offset = reader.ReadInt32();
int aci0Size = reader.ReadInt32();
int acidOffset = reader.ReadInt32();
int acidSize = reader.ReadInt32();
2018-11-29 02:01:19 +00:00
Aci0 = new Aci0(stream, aci0Offset);
Acid = new Acid(stream, acidOffset);
2018-11-29 02:01:19 +00:00
}
}
}