NSP : Add support for loading multiple programs

This commit is contained in:
KillzXGaming 2020-09-16 20:55:48 -04:00
parent e6f4f0562d
commit 5e035ff15e

View file

@ -64,12 +64,12 @@ namespace FirstPlugin
var CnmtNca = new Nca(Keys, Pfs.OpenFile(Pfs.Files.FirstOrDefault(s => s.Name.Contains(".cnmt.nca"))), false);
var CnmtPfs = new Pfs(CnmtNca.OpenSection(0, false, IntegrityCheckLevel.None, true));
var Cnmt = new Cnmt(CnmtPfs.OpenFile(CnmtPfs.Files[0]).AsStream());
var Program = Cnmt.ContentEntries.FirstOrDefault(c => c.Type == CnmtContentType.Program);
var CtrlEntry = Cnmt.ContentEntries.FirstOrDefault(c => c.Type == CnmtContentType.Control);
if (CtrlEntry != null)
Control = new Nca(Keys, Pfs.OpenFile($"{CtrlEntry.NcaId.ToHexString().ToLower()}.nca"), false);
Input = Pfs.OpenFile($"{Program.NcaId.ToHexString().ToLower()}.nca").AsStream();
foreach (var entry in Cnmt.ContentEntries)
{
if (entry.Type == CnmtContentType.Program) {
var Program = entry;
Input = Pfs.OpenFile($"{Program.NcaId.ToHexString().ToLower()}.nca").AsStream();
var Nca = new Nca(Keys, Input.AsStorage(), true);
Romfs romfs = new Romfs(
@ -83,11 +83,16 @@ namespace FirstPlugin
false, IntegrityCheckLevel.None, true));
foreach (var file in exefs.Files)
files.Add(new ExefsEntry(exefs,file));
files.Add(new ExefsEntry(exefs, file, Program.NcaId.ToHexString()));
}
for (int i = 0; i < romfs.Files.Count; i++)
files.Add(new FileEntry(romfs,romfs.Files[i]));
files.Add(new FileEntry(romfs, romfs.Files[i], Program.NcaId.ToHexString()));
}
}
var CtrlEntry = Cnmt.ContentEntries.FirstOrDefault(c => c.Type == CnmtContentType.Control);
if (CtrlEntry != null)
Control = new Nca(Keys, Pfs.OpenFile($"{CtrlEntry.NcaId.ToHexString().ToLower()}.nca"), false);
}
public void Unload()
@ -111,7 +116,18 @@ namespace FirstPlugin
return false;
}
public class ExefsEntry : FileEntry
public class ExefsEntry : PartEntry
{
public ExefsEntry(Pfs pfs, PfsFileEntry entry, string root = "") : base(pfs, entry)
{
if (root != string.Empty)
FileName = $"{root}/Exefs/{entry.Name}";
else
FileName = $"Exefs/{entry.Name}";
}
}
public class PartEntry : FileEntry
{
private Pfs ParentPfs;
private PfsFileEntry fileEntry;
@ -139,11 +155,11 @@ namespace FirstPlugin
}
}
public ExefsEntry(Pfs pfs, PfsFileEntry entry)
public PartEntry(Pfs pfs, PfsFileEntry entry)
{
ParentPfs = pfs;
fileEntry = entry;
FileName = $"Exefs/{fileEntry.Name}";
FileName = fileEntry.Name;
}
}
@ -185,10 +201,13 @@ namespace FirstPlugin
}
public FileEntry(Romfs romfs, RomfsFile romfsFile)
public FileEntry(Romfs romfs, RomfsFile romfsFile, string root = "")
{
ParentROMFS = romfs;
File = romfsFile;
if (root != string.Empty)
FileName = $"{root}/Romfs/{File.FullPath}";
else
FileName = $"Romfs/{File.FullPath}";
}
}