Fix multidisc

This commit is contained in:
Li 2023-04-17 10:14:13 +12:00
parent 9e00f65cb9
commit 8000c946bd
8 changed files with 41 additions and 20 deletions

View File

@ -2,6 +2,7 @@
using GameBuilder.Progress;
using GameBuilder.Psp;
using GameBuilder.VersionKey;
using PspCrypto;
namespace ChovySign_CLI
{
@ -178,14 +179,17 @@ namespace ChovySign_CLI
if(res != 0) return res;
if (drmInfo is null) return Error("no versionkey was found, exiting", 6);
if (pbpMode is null) return Error("no pbp mode was set, exiting", 7);
Console.WriteLine("Version Key: " + BitConverter.ToString(drmInfo.VersionKey).Replace("-", ""));
if (pbpMode is null) return Error("no pbp mode was set, exiting", 7);
if (pbpMode == PbpMode.PSP && drmInfo.KeyIndex != 2)
return Error("KeyType is "+drmInfo.KeyIndex+", but PBP mode is PSP, you cant do that .. please use a type 1 versionkey.", 8);
if (pbpMode == PbpMode.POPS && drmInfo.KeyIndex != 1)
return Error("KeyType is " + drmInfo.KeyIndex + ", but PBP mode is POPS, you cant do that .. please use a type 1 versionkey.", 8);
if (pbpMode == PbpMode.POPS && (popsDiscName is null || popsIcon0File is null)) return Error("pbp mode is POPS, but you have not specified a disc title or icon file using --pops-info.", 9);
if (pbpMode == PbpMode.POPS)
@ -223,14 +227,18 @@ namespace ChovySign_CLI
psIsoImg,
"EBOOT.PBP",
0);
byte[] ebootsig = new byte[0x200];
SceNpDrm.KsceNpDrmEbootSigGenPs1("EBOOT.PBP", ebootsig, 0x3600000);
File.WriteAllBytes("__sce_ebootpbp", ebootsig.ToArray());
}
}
else
{
using (PsTitleImg psIsoImg = new PsTitleImg(drmInfo, discInfs))
using (PsTitleImg psTitleImg = new PsTitleImg(drmInfo, discInfs))
{
psIsoImg.RegisterCallback(onProgress);
psIsoImg.CreatePsar();
psTitleImg.RegisterCallback(onProgress);
psTitleImg.CreatePsar();
PbpBuilder.CreatePbp(psfo.WriteSfo(),
File.ReadAllBytes(popsIcon0File),
@ -238,9 +246,13 @@ namespace ChovySign_CLI
(popsPic0File is not null) ? File.ReadAllBytes(popsPic0File) : null,
Resources.PIC1,
null,
psIsoImg,
psTitleImg,
"EBOOT.PBP",
0);
byte[] ebootsig = new byte[0x200];
SceNpDrm.KsceNpDrmEbootSigGenPs1("EBOOT.PBP", ebootsig, 0x3600000);
File.WriteAllBytes("__sce_ebootpbp", ebootsig.ToArray());
}
}
}
@ -263,6 +275,10 @@ namespace ChovySign_CLI
"EBOOT.PBP",
1);
byte[] ebootsig = new byte[0x200];
SceNpDrm.KsceNpDrmEbootSigGenPsp("EBOOT.PBP", ebootsig, 0x3600000);
File.WriteAllBytes("__sce_ebootpbp", ebootsig.ToArray());
}
}
}

View File

@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<History>True|2023-04-16T20:27:16.5281469Z;True|2023-04-17T08:22:02.0531219+12:00;</History>
<History>True|2023-04-16T21:56:35.5065135Z;True|2023-04-17T09:22:54.8607008+12:00;True|2023-04-17T08:27:16.5281469+12:00;True|2023-04-17T08:22:02.0531219+12:00;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>

View File

@ -57,8 +57,8 @@ namespace GameBuilder.Pops
createIsoMap();
psarUtil.WriteStr("PSTITLEIMG000000");
psarUtil.WriteInt64(PSISO_ALIGN+isoPart.Length); // location of STARTDAT
psarUtil.WriteInt64(PSISO_ALIGN + isoPart.Length); // location of STARTDAT
psarUtil.WriteBytes(Rng.RandomBytes(0x10)); // dunno what this is
psarUtil.WritePadding(0x00, 0x1D8);
@ -70,7 +70,6 @@ namespace GameBuilder.Pops
isoPart.CopyTo(Psar);
psarUtil.WriteBytes(StartDat);
psarUtil.WriteBytes(SimplePgd);
}
@ -115,7 +114,7 @@ namespace GameBuilder.Pops
discNumber++;
if (compressors[i] is null) { isoMapUtil.WriteInt32(0); continue; };
int padLen = Convert.ToInt32(PSISO_ALIGN - (isoPart.Position % PSISO_ALIGN));
int padLen = MathUtil.CalculatePaddingAmount(Convert.ToInt32(isoPart.Position), PSISO_ALIGN);
isoPartUtil.WritePadding(0x00, padLen);
using (PsIsoImg psIsoImg = new PsIsoImg(this.DrmInfo, compressors[i]))
@ -144,7 +143,7 @@ namespace GameBuilder.Pops
isoMapUtil.WriteStrWithPadding(discs.First().DiscIdHdr, 0x00, 0x20);
isoMapUtil.WriteInt64(Convert.ToInt64(PSISO_ALIGN + isoPart.Length + StartDat.Length));
psarUtil.WriteBytes(Rng.RandomBytes(0x80));
isoMapUtil.WriteBytes(Rng.RandomBytes(0x80));
isoMapUtil.WriteStrWithPadding(discs.First().DiscName, 0x00, 0x80);
isoMapUtil.WriteInt32(MAX_DISCS);
isoMapUtil.WritePadding(0x00, 0x70);

View File

@ -19,8 +19,8 @@ namespace GameBuilder.Psp
byte[] dataPsp = dataPsar.GenerateDataPsp();
int padLen = MathUtil.CalculatePaddingAmount(dataPsp.Length, 0x100);
Array.Resize(ref dataPsp, dataPsp.Length + padLen);
if(version == 1)
Array.Resize(ref dataPsp, dataPsp.Length + padLen);
StreamUtil pbpUtil = new StreamUtil(pbpStream);
pbpUtil.WriteByte(0x00);

View File

@ -25,7 +25,7 @@ namespace GameBuilder.Psp
{
this.IsoFile = isoFile;
this.IsoStream = File.OpenRead(isoFile);
using (CDReader cdReader = new CDReader(this.IsoStream, true, true))
using (CDReader cdReader = new CDReader(this.IsoStream, true, true, 2048))
{
foreach (string file in filesList)
{

View File

@ -14,6 +14,10 @@ namespace GameBuilder
{
this.s = s;
}
public string ReadStrLen(int len)
{
return Encoding.UTF8.GetString(ReadBytes(len));
}
public string ReadCStr()
{
using (MemoryStream ms = new MemoryStream())

View File

@ -16,8 +16,10 @@ namespace GameBuilder.VersionKey
byte[] versionKey = new byte[0x10];
SceNpDrm.SetPSID(consoleId);
SceNpDrm.sceNpDrmGetVersionKey(versionKey, actDat, licenseDat, keyType);
string contentId = Encoding.UTF8.GetString(licenseDat, 0x10, 0x24);
SceNpDrm.Aid = BitConverter.ToUInt64(licenseDat, 0x8);
string contentId = Encoding.UTF8.GetString(licenseDat, 0x10, 0x24);
return new NpDrmInfo(versionKey, contentId, keyType);
}
}

View File

@ -33,7 +33,7 @@ namespace GameBuilder.VersionKey
int dataPsarLocation = ebootUtil.ReadInt32At(0x24);
ebootStream.Seek(dataPsarLocation, SeekOrigin.Begin);
string magic = ebootUtil.ReadCStr();
string magic = ebootUtil.ReadStrLen(8);
switch (magic)
{
@ -47,7 +47,7 @@ namespace GameBuilder.VersionKey
byte[] versionkey = getKey(npUmdHdr, npUmdBody);
return new NpDrmInfo(versionkey, contentId, keyType);
case "PSISOIMG0000":
case "PSISOIMG":
using (DNASStream dnas = new DNASStream(ebootStream, dataPsarLocation + 0x400))
{
contentId = ebootUtil.ReadStringAt(dataPspLocation + 0x560);
@ -56,7 +56,7 @@ namespace GameBuilder.VersionKey
return new NpDrmInfo(versionkey, contentId, keyType);
}
case "PSTITLEIMG000000":
case "PSTITLEI":
using (DNASStream dnas = new DNASStream(ebootStream, dataPsarLocation + 0x200))
{
contentId = ebootUtil.ReadStringAt(dataPspLocation + 0x560);
@ -66,7 +66,7 @@ namespace GameBuilder.VersionKey
return new NpDrmInfo(versionkey, contentId, keyType);
}
default:
throw new Exception("Cannot obtain versionkey from this EBOOT.PBP");
throw new Exception("Cannot obtain versionkey from this EBOOT.PBP (magic:" + magic + ")");
}
}