Skip to content

Commit 3af4910

Browse files
author
David Khristepher Santos
committed
Implement writing of BOOT.PNG
1 parent dc5ffbd commit 3af4910

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

Popstation/Pbp/PbpWriter.cs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -171,43 +171,44 @@ protected void WriteSTARTDAT(Stream outputStream)
171171
basePbp.Seek(x + 16, SeekOrigin.Begin);
172172
basePbp.Read(header, 2); // Read 2 ints into header
173173

174+
// header[0] - the size of the header (always 0x50)
175+
// header[1] - the size of boot.png
176+
177+
// Go back and copy 0x50 bytes starting from STARTDAT
174178
basePbp.Seek(x, SeekOrigin.Begin);
175179
basePbp.Read(buffer, 0, (int)header[0]);
176180

181+
if (convertInfo.Boot.Exists)
182+
{
183+
// Update boot size in header
184+
var temp_buffer = BitConverter.GetBytes(convertInfo.Boot.Size);
185+
for (var j = 0; j < sizeof(uint); j++)
186+
{
187+
buffer[16 + 4 + j] = temp_buffer[j];
188+
}
189+
}
190+
191+
// Write the header
192+
outputStream.Write(buffer, 0, (int)header[0]);
193+
177194

178195
if (!convertInfo.Boot.Exists)
179196
{
180-
outputStream.Write(buffer, 0, (int)header[0]);
197+
// Copy boot.png from basePbp
181198
basePbp.Read(buffer, 0, (int)header[1]);
182199
outputStream.Write(buffer, 0, (int)header[1]);
183200
}
184201
else
185202
{
186-
Console.WriteLine("Writing boot.png...\n");
187203
Notify?.Invoke(PopstationEventEnum.WriteBootPng, null);
188-
189204
convertInfo.Boot.Write(outputStream);
190205

191-
//ib[5] = boot_size;
192-
//var temp_buffer = BitConverter.GetBytes(boot_size);
193-
//for (var j = 0; j < sizeof(uint); j++)
194-
//{
195-
// buffer[5 + j] = temp_buffer[i];
196-
//}
197-
198-
//outputStream.Write(buffer, 0, (int)header[0]);
199-
200-
//using (var t = new FileStream(convertInfo.Boot, FileMode.Open, FileAccess.Read, FileShare.Read))
201-
//{
202-
// t.Read(buffer, 0, (int)boot_size);
203-
// outputStream.Write(buffer, 0, (int)boot_size);
204-
//}
205-
206-
//basePbp.Read(buffer, 0, (int)header[1]);
206+
// Skip boot.png in basePbp
207+
basePbp.Read(buffer, 0, (int)header[1]);
208+
//basePbp.Seek((int)header[1], SeekOrigin.Current);
207209
}
208210

209-
//_base.Seek(x, SeekOrigin.Begin);
210-
211+
// Copy the rest of the STARTDAT (encrypted PGD?)
211212
while ((x = (uint)basePbp.Read(buffer, 0, 1048576)) > 0)
212213
{
213214
outputStream.Write(buffer, 0, (int)x);

0 commit comments

Comments
 (0)