2023-09-08 21:12:19 -04:00
|
|
|
using System.IO;
|
2024-04-03 20:55:02 -04:00
|
|
|
using System.Text;
|
2025-09-26 13:06:18 -04:00
|
|
|
using SabreTools.Data.Models.BDPlus;
|
2024-04-17 11:52:22 -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.BDPlus.Constants;
|
2023-09-08 21:12:19 -04:00
|
|
|
|
2025-09-26 14:57:20 -04:00
|
|
|
namespace SabreTools.Serialization.Readers
|
2023-09-08 21:12:19 -04:00
|
|
|
{
|
2025-09-26 15:02:43 -04:00
|
|
|
public class BDPlus : BaseBinaryReader<SVM>
|
2023-09-08 21:12:19 -04:00
|
|
|
{
|
2024-04-03 20:55:02 -04:00
|
|
|
/// <inheritdoc/>
|
2024-04-04 01:55:05 -04:00
|
|
|
public override SVM? Deserialize(Stream? data)
|
2024-04-03 20:55:02 -04:00
|
|
|
{
|
|
|
|
|
// If the data is invalid
|
2026-01-25 14:30:18 -05:00
|
|
|
if (data is null || !data.CanRead)
|
2024-04-03 20:55:02 -04:00
|
|
|
return null;
|
|
|
|
|
|
2024-11-28 22:57:12 -05:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Try to parse the SVM
|
|
|
|
|
var svm = new SVM();
|
|
|
|
|
|
|
|
|
|
byte[] signature = data.ReadBytes(8);
|
|
|
|
|
svm.Signature = Encoding.ASCII.GetString(signature);
|
|
|
|
|
if (svm.Signature != SignatureString)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
svm.Unknown1 = data.ReadBytes(5);
|
|
|
|
|
svm.Year = data.ReadUInt16BigEndian();
|
|
|
|
|
svm.Month = data.ReadByteValue();
|
|
|
|
|
if (svm.Month < 1 || svm.Month > 12)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
svm.Day = data.ReadByteValue();
|
|
|
|
|
if (svm.Day < 1 || svm.Day > 31)
|
|
|
|
|
return null;
|
|
|
|
|
|
2024-12-16 23:08:45 -05:00
|
|
|
svm.Unknown2 = data.ReadUInt32LittleEndian();
|
|
|
|
|
svm.Length = data.ReadUInt32LittleEndian();
|
2024-11-28 22:57:12 -05:00
|
|
|
if (svm.Length > 0)
|
|
|
|
|
svm.Data = data.ReadBytes((int)svm.Length);
|
|
|
|
|
|
|
|
|
|
return svm;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// Ignore the actual error
|
2024-04-03 20:55:02 -04:00
|
|
|
return null;
|
2024-11-28 22:57:12 -05:00
|
|
|
}
|
2024-04-03 17:27:08 -04:00
|
|
|
}
|
2023-09-08 21:12:19 -04:00
|
|
|
}
|
2025-07-24 09:31:28 -04:00
|
|
|
}
|