2024-04-23 21:00:10 -04:00
|
|
|
using System.IO;
|
2024-12-16 23:08:45 -05:00
|
|
|
using System.Text;
|
2024-04-23 21:00:10 -04:00
|
|
|
using SabreTools.IO.Extensions;
|
2026-03-24 19:17:25 -04:00
|
|
|
using SabreTools.Numerics.Extensions;
|
2025-09-26 13:06:18 -04:00
|
|
|
using static SabreTools.Data.Models.PlayStation3.Constants;
|
2024-04-23 21:00:10 -04:00
|
|
|
|
2026-01-27 12:03:01 -05:00
|
|
|
#pragma warning disable IDE0017 // Simplify object initialization
|
2025-09-26 14:57:20 -04:00
|
|
|
namespace SabreTools.Serialization.Readers
|
2024-04-23 21:00:10 -04:00
|
|
|
{
|
2025-09-26 15:02:43 -04:00
|
|
|
public class SFB : BaseBinaryReader<Data.Models.PlayStation3.SFB>
|
2024-04-23 21:00:10 -04:00
|
|
|
{
|
|
|
|
|
/// <inheritdoc/>
|
2025-09-26 13:06:18 -04:00
|
|
|
public override Data.Models.PlayStation3.SFB? Deserialize(Stream? data)
|
2024-04-23 21:00:10 -04:00
|
|
|
{
|
|
|
|
|
// If the data is invalid
|
2026-01-25 14:30:18 -05:00
|
|
|
if (data is null || !data.CanRead)
|
2024-04-23 21:00:10 -04:00
|
|
|
return null;
|
|
|
|
|
|
2024-11-28 22:57:12 -05:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Deserialize the SFB
|
2025-09-26 13:06:18 -04:00
|
|
|
var sfb = new Data.Models.PlayStation3.SFB();
|
2024-12-16 23:08:45 -05:00
|
|
|
|
|
|
|
|
sfb.Magic = data.ReadUInt32BigEndian();
|
|
|
|
|
if (sfb.Magic != SFBMagic)
|
2024-11-28 22:57:12 -05:00
|
|
|
return null;
|
2024-04-23 21:00:10 -04:00
|
|
|
|
2024-12-16 23:08:45 -05:00
|
|
|
sfb.FileVersion = data.ReadUInt32BigEndian();
|
|
|
|
|
sfb.Reserved1 = data.ReadBytes(0x18);
|
|
|
|
|
byte[] flagsType = data.ReadBytes(0x10);
|
|
|
|
|
sfb.FlagsType = Encoding.ASCII.GetString(flagsType).TrimEnd('\0');
|
|
|
|
|
sfb.DiscContentDataOffset = data.ReadUInt32BigEndian();
|
|
|
|
|
sfb.DiscContentDataLength = data.ReadUInt32BigEndian();
|
|
|
|
|
sfb.Reserved2 = data.ReadBytes(0x08);
|
|
|
|
|
byte[] discTitleName = data.ReadBytes(0x08);
|
|
|
|
|
sfb.DiscTitleName = Encoding.ASCII.GetString(discTitleName).TrimEnd('\0');
|
|
|
|
|
sfb.Reserved3 = data.ReadBytes(0x08);
|
|
|
|
|
sfb.DiscVersionDataOffset = data.ReadUInt32BigEndian();
|
|
|
|
|
sfb.DiscVersionDataLength = data.ReadUInt32BigEndian();
|
|
|
|
|
sfb.Reserved4 = data.ReadBytes(0x188);
|
|
|
|
|
byte[] discContent = data.ReadBytes(0x20);
|
|
|
|
|
sfb.DiscContent = Encoding.ASCII.GetString(discContent).TrimEnd('\0');
|
|
|
|
|
byte[] discTitle = data.ReadBytes(0x10);
|
|
|
|
|
sfb.DiscTitle = Encoding.ASCII.GetString(discTitle).TrimEnd('\0');
|
|
|
|
|
byte[] discVersion = data.ReadBytes(0x10);
|
|
|
|
|
sfb.DiscVersion = Encoding.ASCII.GetString(discVersion).TrimEnd('\0');
|
|
|
|
|
sfb.Reserved5 = data.ReadBytes(0x3C0);
|
|
|
|
|
|
2024-11-28 22:57:12 -05:00
|
|
|
return sfb;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// Ignore the actual error
|
2024-04-23 21:00:10 -04:00
|
|
|
return null;
|
2024-11-28 22:57:12 -05:00
|
|
|
}
|
2024-04-23 21:00:10 -04:00
|
|
|
}
|
|
|
|
|
}
|
2025-07-24 09:31:28 -04:00
|
|
|
}
|