mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-09-22 14:55:11 +00:00
Reduce unncessary methods in deserialization
This commit is contained in:
@@ -19,9 +19,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
if (data.Position < 0 || data.Position >= data.Length)
|
||||
return null;
|
||||
|
||||
// Cache the current offset
|
||||
int initialOffset = (int)data.Position;
|
||||
|
||||
// Try to parse the SVM
|
||||
return ParseSVMData(data);
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Header
|
||||
|
||||
// Try to parse the header
|
||||
var header = ParseHeader(data);
|
||||
if (header == null)
|
||||
var header = data.ReadType<Header>();
|
||||
if (header?.Magic != SignatureString)
|
||||
return null;
|
||||
|
||||
// Set the archive header
|
||||
@@ -60,21 +60,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return archive;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled header on success, null on error</returns>
|
||||
private static Header? ParseHeader(Stream data)
|
||||
{
|
||||
var header = data.ReadType<Header>();
|
||||
|
||||
if (header?.Magic != SignatureString)
|
||||
return null;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a file entry
|
||||
/// </summary>
|
||||
|
||||
@@ -27,9 +27,11 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Header
|
||||
|
||||
// Try to parse the header
|
||||
var header = ParseHeader(data);
|
||||
var header = data.ReadType<BspHeader>();
|
||||
if (header?.Lumps == null)
|
||||
return null;
|
||||
if (header.Version < 29 || header.Version > 30)
|
||||
return null;
|
||||
|
||||
// Set the level header
|
||||
file.Header = header;
|
||||
@@ -109,24 +111,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return file;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Level header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Level header on success, null on error</returns>
|
||||
/// <remarks>Only recognized versions are 29 and 30</remarks>
|
||||
private static BspHeader? ParseHeader(Stream data)
|
||||
{
|
||||
var header = data.ReadType<BspHeader>();
|
||||
|
||||
if (header == null)
|
||||
return null;
|
||||
if (header.Version < 29 || header.Version > 30)
|
||||
return null;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into LUMP_ENTITIES
|
||||
/// </summary>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Models.CFB;
|
||||
using static SabreTools.Models.CFB.Constants;
|
||||
|
||||
@@ -20,9 +20,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
if (data.Position < 0 || data.Position >= data.Length)
|
||||
return null;
|
||||
|
||||
// Cache the current offset
|
||||
int initialOffset = (int)data.Position;
|
||||
|
||||
// Determine the header version
|
||||
uint version = GetVersion(data);
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.IO.Extensions;
|
||||
@@ -25,9 +24,19 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region CIA Header
|
||||
|
||||
// Try to parse the header
|
||||
var header = ParseCIAHeader(data);
|
||||
var header = data.ReadType<CIAHeader>();
|
||||
if (header == null)
|
||||
return null;
|
||||
if (header.CertificateChainSize > data.Length)
|
||||
return null;
|
||||
if (header.TicketSize > data.Length)
|
||||
return null;
|
||||
if (header.TMDFileSize > data.Length)
|
||||
return null;
|
||||
if (header.MetaSize > data.Length)
|
||||
return null;
|
||||
if ((long)header.ContentSize > data.Length)
|
||||
return null;
|
||||
|
||||
// Set the CIA archive header
|
||||
cia.Header = header;
|
||||
@@ -124,7 +133,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
if (header.MetaSize > 0)
|
||||
{
|
||||
// Try to parse the meta
|
||||
var meta = ParseMetaData(data);
|
||||
var meta = data.ReadType<MetaData>();
|
||||
if (meta == null)
|
||||
return null;
|
||||
|
||||
@@ -137,31 +146,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return cia;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a CIA header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled CIA header on success, null on error</returns>
|
||||
public static CIAHeader? ParseCIAHeader(Stream data)
|
||||
{
|
||||
var header = data.ReadType<CIAHeader>();
|
||||
|
||||
if (header == null)
|
||||
return null;
|
||||
if (header.CertificateChainSize > data.Length)
|
||||
return null;
|
||||
if (header.TicketSize > data.Length)
|
||||
return null;
|
||||
if (header.TMDFileSize > data.Length)
|
||||
return null;
|
||||
if (header.MetaSize > data.Length)
|
||||
return null;
|
||||
if ((long)header.ContentSize > data.Length)
|
||||
return null;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a certificate
|
||||
/// </summary>
|
||||
@@ -399,20 +383,20 @@ namespace SabreTools.Serialization.Deserializers
|
||||
titleMetadata.ContentInfoRecords = new ContentInfoRecord[64];
|
||||
for (int i = 0; i < 64; i++)
|
||||
{
|
||||
var contentInfoRecord = ParseContentInfoRecord(data);
|
||||
var contentInfoRecord = data.ReadType<ContentInfoRecord>();
|
||||
if (contentInfoRecord == null)
|
||||
return null;
|
||||
|
||||
titleMetadata.ContentInfoRecords[i] = ParseContentInfoRecord(data);
|
||||
titleMetadata.ContentInfoRecords[i] = contentInfoRecord;
|
||||
}
|
||||
titleMetadata.ContentChunkRecords = new ContentChunkRecord[titleMetadata.ContentCount];
|
||||
for (int i = 0; i < titleMetadata.ContentCount; i++)
|
||||
{
|
||||
var contentChunkRecord = ParseContentChunkRecord(data);
|
||||
var contentChunkRecord = data.ReadType<ContentChunkRecord>();
|
||||
if (contentChunkRecord == null)
|
||||
return null;
|
||||
|
||||
titleMetadata.ContentChunkRecords[i] = ParseContentChunkRecord(data);
|
||||
titleMetadata.ContentChunkRecords[i] = contentChunkRecord;
|
||||
}
|
||||
|
||||
// Certificates only exist in standalone TMD files
|
||||
@@ -431,35 +415,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return titleMetadata;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a content info record
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled content info record on success, null on error</returns>
|
||||
public static ContentInfoRecord? ParseContentInfoRecord(Stream data)
|
||||
{
|
||||
return data.ReadType<ContentInfoRecord>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a content chunk record
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled content chunk record on success, null on error</returns>
|
||||
public static ContentChunkRecord? ParseContentChunkRecord(Stream data)
|
||||
{
|
||||
return data.ReadType<ContentChunkRecord>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a meta data
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled meta data on success, null on error</returns>
|
||||
public static MetaData? ParseMetaData(Stream data)
|
||||
{
|
||||
return data.ReadType<MetaData>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,8 +27,12 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Header
|
||||
|
||||
// Try to parse the header
|
||||
var header = ParseHeader(data);
|
||||
if (header == null)
|
||||
var header = data.ReadType<Header>();
|
||||
if (header?.Dummy0 != 0x00000001)
|
||||
return null;
|
||||
if (header?.MajorVersion != 0x00000001)
|
||||
return null;
|
||||
if (header.MinorVersion != 3 && header.MinorVersion != 5 && header.MinorVersion != 6)
|
||||
return null;
|
||||
|
||||
// Set the game cache header
|
||||
@@ -39,7 +43,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Block Entry Header
|
||||
|
||||
// Try to parse the block entry header
|
||||
var blockEntryHeader = ParseBlockEntryHeader(data);
|
||||
var blockEntryHeader = data.ReadType<BlockEntryHeader>();
|
||||
if (blockEntryHeader == null)
|
||||
return null;
|
||||
|
||||
@@ -56,7 +60,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the block entries
|
||||
for (int i = 0; i < blockEntryHeader.BlockCount; i++)
|
||||
{
|
||||
var blockEntry = ParseBlockEntry(data);
|
||||
var blockEntry = data.ReadType<BlockEntry>();
|
||||
if (blockEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -68,7 +72,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Fragmentation Map Header
|
||||
|
||||
// Try to parse the fragmentation map header
|
||||
var fragmentationMapHeader = ParseFragmentationMapHeader(data);
|
||||
var fragmentationMapHeader = data.ReadType<FragmentationMapHeader>();
|
||||
if (fragmentationMapHeader == null)
|
||||
return null;
|
||||
|
||||
@@ -85,7 +89,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the fragmentation maps
|
||||
for (int i = 0; i < fragmentationMapHeader.BlockCount; i++)
|
||||
{
|
||||
var fragmentationMap = ParseFragmentationMap(data);
|
||||
var fragmentationMap = data.ReadType<FragmentationMap>();
|
||||
if (fragmentationMap == null)
|
||||
return null;
|
||||
|
||||
@@ -99,7 +103,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
if (header.MinorVersion < 6)
|
||||
{
|
||||
// Try to parse the block entry map header
|
||||
var blockEntryMapHeader = ParseBlockEntryMapHeader(data);
|
||||
var blockEntryMapHeader = data.ReadType<BlockEntryMapHeader>();
|
||||
if (blockEntryMapHeader == null)
|
||||
return null;
|
||||
|
||||
@@ -119,7 +123,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the block entry maps
|
||||
for (int i = 0; i < file.BlockEntryMapHeader.BlockCount; i++)
|
||||
{
|
||||
var blockEntryMap = ParseBlockEntryMap(data);
|
||||
var blockEntryMap = data.ReadType<BlockEntryMap>();
|
||||
if (blockEntryMap == null)
|
||||
return null;
|
||||
|
||||
@@ -135,7 +139,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Directory Header
|
||||
|
||||
// Try to parse the directory header
|
||||
var directoryHeader = ParseDirectoryHeader(data);
|
||||
var directoryHeader = data.ReadType<DirectoryHeader>();
|
||||
if (directoryHeader == null)
|
||||
return null;
|
||||
|
||||
@@ -152,7 +156,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the directory entries
|
||||
for (int i = 0; i < directoryHeader.ItemCount; i++)
|
||||
{
|
||||
var directoryEntry = ParseDirectoryEntry(data);
|
||||
var directoryEntry = data.ReadType<DirectoryEntry>();
|
||||
if (directoryEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -200,7 +204,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the directory info 1 entries
|
||||
for (int i = 0; i < directoryHeader.Info1Count; i++)
|
||||
{
|
||||
var directoryInfo1Entry = ParseDirectoryInfo1Entry(data);
|
||||
var directoryInfo1Entry = data.ReadType<DirectoryInfo1Entry>();
|
||||
if (directoryInfo1Entry == null)
|
||||
return null;
|
||||
|
||||
@@ -217,7 +221,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the directory info 2 entries
|
||||
for (int i = 0; i < directoryHeader.ItemCount; i++)
|
||||
{
|
||||
var directoryInfo2Entry = ParseDirectoryInfo2Entry(data);
|
||||
var directoryInfo2Entry = data.ReadType<DirectoryInfo2Entry>();
|
||||
if (directoryInfo2Entry == null)
|
||||
return null;
|
||||
|
||||
@@ -234,7 +238,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the directory copy entries
|
||||
for (int i = 0; i < directoryHeader.CopyCount; i++)
|
||||
{
|
||||
var directoryCopyEntry = ParseDirectoryCopyEntry(data);
|
||||
var directoryCopyEntry = data.ReadType<DirectoryCopyEntry>();
|
||||
if (directoryCopyEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -251,7 +255,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the directory local entries
|
||||
for (int i = 0; i < directoryHeader.LocalCount; i++)
|
||||
{
|
||||
var directoryLocalEntry = ParseDirectoryLocalEntry(data);
|
||||
var directoryLocalEntry = data.ReadType<DirectoryLocalEntry>();
|
||||
if (directoryLocalEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -268,9 +272,11 @@ namespace SabreTools.Serialization.Deserializers
|
||||
if (header.MinorVersion >= 5)
|
||||
{
|
||||
// Try to parse the directory map header
|
||||
var directoryMapHeader = ParseDirectoryMapHeader(data);
|
||||
if (directoryMapHeader == null)
|
||||
return null;
|
||||
var directoryMapHeader = data.ReadType<DirectoryMapHeader>();
|
||||
if (directoryMapHeader?.Dummy0 != 0x00000001)
|
||||
return null;
|
||||
if (directoryMapHeader?.Dummy1 != 0x00000000)
|
||||
return null;
|
||||
|
||||
// Set the game cache directory map header
|
||||
file.DirectoryMapHeader = directoryMapHeader;
|
||||
@@ -286,7 +292,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the directory map entries
|
||||
for (int i = 0; i < directoryHeader.ItemCount; i++)
|
||||
{
|
||||
var directoryMapEntry = ParseDirectoryMapEntry(data);
|
||||
var directoryMapEntry = data.ReadType<DirectoryMapEntry>();
|
||||
if (directoryMapEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -298,8 +304,8 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Checksum Header
|
||||
|
||||
// Try to parse the checksum header
|
||||
var checksumHeader = ParseChecksumHeader(data);
|
||||
if (checksumHeader == null)
|
||||
var checksumHeader = data.ReadType<ChecksumHeader>();
|
||||
if (checksumHeader?.Dummy0 != 0x00000001)
|
||||
return null;
|
||||
|
||||
// Set the game cache checksum header
|
||||
@@ -313,8 +319,10 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Checksum Map Header
|
||||
|
||||
// Try to parse the checksum map header
|
||||
var checksumMapHeader = ParseChecksumMapHeader(data);
|
||||
if (checksumMapHeader == null)
|
||||
var checksumMapHeader = data.ReadType<ChecksumMapHeader>();
|
||||
if (checksumMapHeader?.Dummy0 != 0x14893721)
|
||||
return null;
|
||||
if (checksumMapHeader?.Dummy1 != 0x00000001)
|
||||
return null;
|
||||
|
||||
// Set the game cache checksum map header
|
||||
@@ -330,7 +338,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the checksum map entries
|
||||
for (int i = 0; i < checksumMapHeader.ItemCount; i++)
|
||||
{
|
||||
var checksumMapEntry = ParseChecksumMapEntry(data);
|
||||
var checksumMapEntry = data.ReadType<ChecksumMapEntry>();
|
||||
if (checksumMapEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -347,7 +355,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the checksum entries
|
||||
for (int i = 0; i < checksumMapHeader.ChecksumCount; i++)
|
||||
{
|
||||
var checksumEntry = ParseChecksumEntry(data);
|
||||
var checksumEntry = data.ReadType<ChecksumEntry>();
|
||||
if (checksumEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -374,232 +382,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return file;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Game Cache header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Game Cache on success, null on error</returns>
|
||||
private static Header? ParseHeader(Stream data)
|
||||
{
|
||||
var header = data.ReadType<Header>();
|
||||
|
||||
if (header == null)
|
||||
return null;
|
||||
if (header.Dummy0 != 0x00000001)
|
||||
return null;
|
||||
if (header.MajorVersion != 0x00000001)
|
||||
return null;
|
||||
if (header.MinorVersion != 3 && header.MinorVersion != 5 && header.MinorVersion != 6)
|
||||
return null;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Game Cache block entry header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Game Cache block entry header on success, null on error</returns>
|
||||
private static BlockEntryHeader? ParseBlockEntryHeader(Stream data)
|
||||
{
|
||||
return data.ReadType<BlockEntryHeader>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Game Cache block entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Game Cache block entry on success, null on error</returns>
|
||||
private static BlockEntry? ParseBlockEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<BlockEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Game Cache fragmentation map header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Game Cache fragmentation map header on success, null on error</returns>
|
||||
private static FragmentationMapHeader? ParseFragmentationMapHeader(Stream data)
|
||||
{
|
||||
return data.ReadType<FragmentationMapHeader>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Game Cache fragmentation map
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Game Cache fragmentation map on success, null on error</returns>
|
||||
private static FragmentationMap? ParseFragmentationMap(Stream data)
|
||||
{
|
||||
return data.ReadType<FragmentationMap>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Game Cache block entry map header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Game Cache block entry map header on success, null on error</returns>
|
||||
private static BlockEntryMapHeader? ParseBlockEntryMapHeader(Stream data)
|
||||
{
|
||||
return data.ReadType<BlockEntryMapHeader>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Game Cache block entry map
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Game Cache block entry map on success, null on error</returns>
|
||||
private static BlockEntryMap? ParseBlockEntryMap(Stream data)
|
||||
{
|
||||
return data.ReadType<BlockEntryMap>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Game Cache directory header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Game Cache directory header on success, null on error</returns>
|
||||
private static DirectoryHeader? ParseDirectoryHeader(Stream data)
|
||||
{
|
||||
return data.ReadType<DirectoryHeader>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Game Cache directory entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Game Cache directory entry on success, null on error</returns>
|
||||
private static DirectoryEntry? ParseDirectoryEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<DirectoryEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Game Cache directory info 1 entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Game Cache directory info 1 entry on success, null on error</returns>
|
||||
private static DirectoryInfo1Entry? ParseDirectoryInfo1Entry(Stream data)
|
||||
{
|
||||
return data.ReadType<DirectoryInfo1Entry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Game Cache directory info 2 entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Game Cache directory info 2 entry on success, null on error</returns>
|
||||
private static DirectoryInfo2Entry? ParseDirectoryInfo2Entry(Stream data)
|
||||
{
|
||||
return data.ReadType<DirectoryInfo2Entry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Game Cache directory copy entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Game Cache directory copy entry on success, null on error</returns>
|
||||
private static DirectoryCopyEntry? ParseDirectoryCopyEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<DirectoryCopyEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Game Cache directory local entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Game Cache directory local entry on success, null on error</returns>
|
||||
private static DirectoryLocalEntry? ParseDirectoryLocalEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<DirectoryLocalEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Game Cache directory map header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Game Cache directory map header on success, null on error</returns>
|
||||
private static DirectoryMapHeader? ParseDirectoryMapHeader(Stream data)
|
||||
{
|
||||
var directoryMapHeader = data.ReadType<DirectoryMapHeader>();
|
||||
|
||||
if (directoryMapHeader == null)
|
||||
return null;
|
||||
if (directoryMapHeader.Dummy0 != 0x00000001)
|
||||
return null;
|
||||
if (directoryMapHeader.Dummy1 != 0x00000000)
|
||||
return null;
|
||||
|
||||
return directoryMapHeader;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Game Cache directory map entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Game Cache directory map entry on success, null on error</returns>
|
||||
private static DirectoryMapEntry? ParseDirectoryMapEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<DirectoryMapEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Game Cache checksum header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Game Cache checksum header on success, null on error</returns>
|
||||
private static ChecksumHeader? ParseChecksumHeader(Stream data)
|
||||
{
|
||||
var checksumHeader = data.ReadType<ChecksumHeader>();
|
||||
|
||||
if (checksumHeader == null)
|
||||
return null;
|
||||
if (checksumHeader.Dummy0 != 0x00000001)
|
||||
return null;
|
||||
|
||||
return checksumHeader;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Game Cache checksum map header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Game Cache checksum map header on success, null on error</returns>
|
||||
private static ChecksumMapHeader? ParseChecksumMapHeader(Stream data)
|
||||
{
|
||||
var checksumMapHeader = data.ReadType<ChecksumMapHeader>();
|
||||
|
||||
if (checksumMapHeader == null)
|
||||
return null;
|
||||
if (checksumMapHeader.Dummy0 != 0x14893721)
|
||||
return null;
|
||||
if (checksumMapHeader.Dummy1 != 0x00000001)
|
||||
return null;
|
||||
|
||||
return checksumMapHeader;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Game Cache checksum map entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Game Cache checksum map entry on success, null on error</returns>
|
||||
private static ChecksumMapEntry? ParseChecksumMapEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<ChecksumMapEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Game Cache checksum entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Game Cache checksum entry on success, null on error</returns>
|
||||
private static ChecksumEntry? ParseChecksumEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<ChecksumEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Game Cache data block header
|
||||
/// </summary>
|
||||
|
||||
@@ -24,8 +24,10 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Header
|
||||
|
||||
// Try to parse the header
|
||||
var header = ParseHeader(data);
|
||||
if (header == null)
|
||||
var header = data.ReadType<Header>();
|
||||
if (header?.Signature1 != Constants.HeaderSignature)
|
||||
return null;
|
||||
if (header.TocAddress >= data.Length)
|
||||
return null;
|
||||
|
||||
// Set the archive header
|
||||
@@ -69,7 +71,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
var directory = archive.Directories[i];
|
||||
for (int j = 0; j < directory.FileCount; j++)
|
||||
{
|
||||
var file = ParseFile(data);
|
||||
var file = data.ReadType<Models.InstallShieldArchiveV3.File>();
|
||||
if (file?.Name == null)
|
||||
return null;
|
||||
|
||||
@@ -86,25 +88,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return archive;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled header on success, null on error</returns>
|
||||
public static Header? ParseHeader(Stream data)
|
||||
{
|
||||
var header = data.ReadType<Header>();
|
||||
|
||||
if (header == null)
|
||||
return null;
|
||||
if (header?.Signature1 != Constants.HeaderSignature)
|
||||
return null;
|
||||
if (header.TocAddress >= data.Length)
|
||||
return null;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a directory
|
||||
/// </summary>
|
||||
@@ -123,15 +106,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return directory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a file
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled file on success, null on error</returns>
|
||||
public static Models.InstallShieldArchiveV3.File? ParseFile(Stream data)
|
||||
{
|
||||
return data.ReadType<Models.InstallShieldArchiveV3.File>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Common Header
|
||||
|
||||
// Try to parse the cabinet header
|
||||
var commonHeader = ParseCommonHeader(data);
|
||||
if (commonHeader == null)
|
||||
var commonHeader = data.ReadType<CommonHeader>();
|
||||
if (commonHeader?.Signature != SignatureString)
|
||||
return null;
|
||||
|
||||
// Set the cabinet header
|
||||
@@ -59,7 +59,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
data.Seek(descriptorOffset, SeekOrigin.Begin);
|
||||
|
||||
// Try to parse the descriptor
|
||||
var descriptor = ParseDescriptor(data);
|
||||
var descriptor = data.ReadType<Descriptor>();
|
||||
if (descriptor == null)
|
||||
return null;
|
||||
|
||||
@@ -325,21 +325,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return cabinet;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a common header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled common header on success, null on error</returns>
|
||||
public static CommonHeader? ParseCommonHeader(Stream data)
|
||||
{
|
||||
var commonHeader = data.ReadType<CommonHeader>();
|
||||
|
||||
if (commonHeader?.Signature != SignatureString)
|
||||
return null;
|
||||
|
||||
return commonHeader;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a volume header
|
||||
/// </summary>
|
||||
@@ -387,16 +372,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return volumeHeader;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a descriptor
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled descriptor on success, null on error</returns>
|
||||
public static Descriptor? ParseDescriptor(Stream data)
|
||||
{
|
||||
return data.ReadType<Descriptor>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into an offset list
|
||||
/// </summary>
|
||||
|
||||
@@ -42,8 +42,8 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
// Try to parse the executable header
|
||||
data.Seek(initialOffset + stub.Header.NewExeHeaderAddr, SeekOrigin.Begin);
|
||||
var informationBlock = ParseInformationBlock(data);
|
||||
if (informationBlock == null)
|
||||
var informationBlock = data.ReadType<InformationBlock>();
|
||||
if (informationBlock?.Signature != LESignatureString && informationBlock?.Signature != LXSignatureString)
|
||||
return null;
|
||||
|
||||
// Set the executable header
|
||||
@@ -66,7 +66,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the object table
|
||||
for (int i = 0; i < executable.ObjectTable.Length; i++)
|
||||
{
|
||||
var entry = ParseObjectTableEntry(data);
|
||||
var entry = data.ReadType<ObjectTableEntry>();
|
||||
if (entry == null)
|
||||
return null;
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the object page map
|
||||
for (int i = 0; i < executable.ObjectPageMap.Length; i++)
|
||||
{
|
||||
var entry = ParseObjectPageMapEntry(data);
|
||||
var entry = data.ReadType<ObjectPageMapEntry>();
|
||||
if (entry == null)
|
||||
return null;
|
||||
|
||||
@@ -131,7 +131,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the resource table
|
||||
for (int i = 0; i < executable.ResourceTable.Length; i++)
|
||||
{
|
||||
var entry = ParseResourceTableEntry(data);
|
||||
var entry = data.ReadType<ResourceTableEntry>();
|
||||
if (entry == null)
|
||||
return null;
|
||||
|
||||
@@ -215,7 +215,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the module format directives table
|
||||
for (int i = 0; i < executable.ModuleFormatDirectivesTable.Length; i++)
|
||||
{
|
||||
var entry = ParseModuleFormatDirectivesTableEntry(data);
|
||||
var entry = data.ReadType<ModuleFormatDirectivesTableEntry>();
|
||||
if (entry == null)
|
||||
return null;
|
||||
|
||||
@@ -248,7 +248,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the fix-up page table
|
||||
for (int i = 0; i < executable.FixupPageTable.Length; i++)
|
||||
{
|
||||
var entry = ParseFixupPageTableEntry(data);
|
||||
var entry = data.ReadType<FixupPageTableEntry>();
|
||||
if (entry == null)
|
||||
return null;
|
||||
|
||||
@@ -356,7 +356,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the per-page checksum name table
|
||||
for (int i = 0; i < executable.PerPageChecksumTable.Length; i++)
|
||||
{
|
||||
var entry = ParsePerPageChecksumTableEntry(data);
|
||||
var entry = data.ReadType<PerPageChecksumTableEntry>();
|
||||
if (entry == null)
|
||||
return null;
|
||||
|
||||
@@ -418,51 +418,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return executable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into an information block
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled information block on success, null on error</returns>
|
||||
public static InformationBlock? ParseInformationBlock(Stream data)
|
||||
{
|
||||
var informationBlock = data.ReadType<InformationBlock>();
|
||||
|
||||
if (informationBlock?.Signature != LESignatureString && informationBlock?.Signature != LXSignatureString)
|
||||
return null;
|
||||
|
||||
return informationBlock;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into an object table entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled object table entry on success, null on error</returns>
|
||||
public static ObjectTableEntry? ParseObjectTableEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<ObjectTableEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into an object page map entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled object page map entry on success, null on error</returns>
|
||||
public static ObjectPageMapEntry? ParseObjectPageMapEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<ObjectPageMapEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a resource table entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled resource table entry on success, null on error</returns>
|
||||
public static ResourceTableEntry? ParseResourceTableEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<ResourceTableEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a resident names table entry
|
||||
/// </summary>
|
||||
@@ -545,36 +500,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return bundle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a module format directives table entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled module format directives table entry on success, null on error</returns>
|
||||
public static ModuleFormatDirectivesTableEntry? ParseModuleFormatDirectivesTableEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<ModuleFormatDirectivesTableEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a verify record directive table entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled verify record directive table entry on success, null on error</returns>
|
||||
public static VerifyRecordDirectiveTableEntry? ParseVerifyRecordDirectiveTableEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<VerifyRecordDirectiveTableEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a fix-up page table entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled fix-up page table entry on success, null on error</returns>
|
||||
public static FixupPageTableEntry? ParseFixupPageTableEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<FixupPageTableEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a fix-up record table entry
|
||||
/// </summary>
|
||||
@@ -831,16 +756,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return entry;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a per-page checksum table entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled per-page checksum table entry on success, null on error</returns>
|
||||
public static PerPageChecksumTableEntry? ParsePerPageChecksumTableEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<PerPageChecksumTableEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a non-resident names table entry
|
||||
/// </summary>
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var entry = ParseRelocationEntry(data);
|
||||
var entry = data.ReadType<RelocationEntry>();
|
||||
if (entry == null)
|
||||
return null;
|
||||
|
||||
@@ -137,15 +137,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return relocationTable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a relocation table entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled relocation table entry on success, null on error</returns>
|
||||
public static RelocationEntry? ParseRelocationEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<RelocationEntry>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,8 +35,8 @@ namespace SabreTools.Serialization.Deserializers
|
||||
long basePtr = data.Position;
|
||||
|
||||
// Deserialize the user data, returning null if invalid
|
||||
var userData = ParseUserData(data);
|
||||
if (userData == null)
|
||||
var userData = data.ReadType<UserData>();
|
||||
if (userData?.Signature != UserDataSignatureString)
|
||||
return null;
|
||||
|
||||
// Set the user data
|
||||
@@ -92,7 +92,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
while (data.Position < hashTableEnd)
|
||||
{
|
||||
var hashEntry = ParseHashEntry(data);
|
||||
var hashEntry = data.ReadType<HashEntry>();
|
||||
if (hashEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
while (data.Position < hashTableEnd)
|
||||
{
|
||||
var hashEntry = ParseHashEntry(data);
|
||||
var hashEntry = data.ReadType<HashEntry>();
|
||||
if (hashEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
while (data.Position < hashTableEnd)
|
||||
{
|
||||
var hashEntry = ParseHashEntry(data);
|
||||
var hashEntry = data.ReadType<HashEntry>();
|
||||
if (hashEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -183,7 +183,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
while (data.Position < blockTableEnd)
|
||||
{
|
||||
var blockEntry = ParseBlockEntry(data);
|
||||
var blockEntry = data.ReadType<BlockEntry>();
|
||||
if (blockEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -212,7 +212,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
while (data.Position < blockTableEnd)
|
||||
{
|
||||
var blockEntry = ParseBlockEntry(data);
|
||||
var blockEntry = data.ReadType<BlockEntry>();
|
||||
if (blockEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -241,7 +241,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
while (data.Position < blockTableEnd)
|
||||
{
|
||||
var blockEntry = ParseBlockEntry(data);
|
||||
var blockEntry = data.ReadType<BlockEntry>();
|
||||
if (blockEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -391,21 +391,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return archiveHeader;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a user data object
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled user data on success, null on error</returns>
|
||||
private static UserData? ParseUserData(Stream data)
|
||||
{
|
||||
var userData = data.ReadType<UserData>();
|
||||
|
||||
if (userData?.Signature != UserDataSignatureString)
|
||||
return null;
|
||||
|
||||
return userData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a HET table
|
||||
/// </summary>
|
||||
@@ -492,36 +477,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return betTable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a hash entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled hash entry on success, null on error</returns>
|
||||
private static HashEntry? ParseHashEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<HashEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a block entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled block entry on success, null on error</returns>
|
||||
private static BlockEntry? ParseBlockEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<BlockEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a patch info
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled patch info on success, null on error</returns>
|
||||
private static PatchInfo? ParsePatchInfo(Stream data)
|
||||
{
|
||||
return data.ReadType<PatchInfo>();
|
||||
}
|
||||
|
||||
#region Helpers
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Development Card Info Header
|
||||
|
||||
// Try to parse the development card info header
|
||||
var developmentCardInfoHeader = ParseDevelopmentCardInfoHeader(data);
|
||||
var developmentCardInfoHeader = data.ReadType<DevelopmentCardInfoHeader>();
|
||||
if (developmentCardInfoHeader == null)
|
||||
return null;
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Handle the extended header, if it exists
|
||||
if (partition.ExtendedHeaderSizeInBytes > 0)
|
||||
{
|
||||
var extendedHeader = ParseNCCHExtendedHeader(data);
|
||||
var extendedHeader = data.ReadType<NCCHExtendedHeader>();
|
||||
if (extendedHeader != null)
|
||||
cart.ExtendedHeaders[i] = extendedHeader;
|
||||
}
|
||||
@@ -119,10 +119,10 @@ namespace SabreTools.Serialization.Deserializers
|
||||
long offset = partition.RomFSOffsetInMediaUnits * mediaUnitSize;
|
||||
data.Seek(partitionOffset + offset, SeekOrigin.Begin);
|
||||
|
||||
var romFsHeader = ParseRomFSHeader(data);
|
||||
if (romFsHeader == null)
|
||||
var romFsHeader = data.ReadType<RomFSHeader>();
|
||||
if (romFsHeader?.MagicString != RomFSMagicNumber)
|
||||
continue;
|
||||
else if (romFsHeader.MagicString != RomFSMagicNumber || romFsHeader.MagicNumber != RomFSSecondMagicNumber)
|
||||
if (romFsHeader?.MagicNumber != RomFSSecondMagicNumber)
|
||||
continue;
|
||||
|
||||
cart.RomFSHeaders[i] = romFsHeader;
|
||||
@@ -157,7 +157,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
header.PartitionsTable = new PartitionTableEntry[8];
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
var partitionTableEntry = ParsePartitionTableEntry(data);
|
||||
var partitionTableEntry = data.ReadType<PartitionTableEntry>();
|
||||
if (partitionTableEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -191,16 +191,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return header;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a partition table entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled partition table entry on success, null on error</returns>
|
||||
public static PartitionTableEntry? ParsePartitionTableEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<PartitionTableEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a card info header
|
||||
/// </summary>
|
||||
@@ -245,16 +235,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return id;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a development card info header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled development card info header on success, null on error</returns>
|
||||
public static DevelopmentCardInfoHeader? ParseDevelopmentCardInfoHeader(Stream data)
|
||||
{
|
||||
return data.ReadType<DevelopmentCardInfoHeader>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into an NCCH header
|
||||
/// </summary>
|
||||
@@ -283,7 +263,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
header.ExtendedHeaderHash = data.ReadBytes(0x20);
|
||||
header.ExtendedHeaderSizeInBytes = data.ReadUInt32();
|
||||
header.Reserved2 = data.ReadUInt32();
|
||||
header.Flags = ParseNCCHHeaderFlags(data);
|
||||
header.Flags = data.ReadType<NCCHHeaderFlags>();
|
||||
header.PlainRegionOffsetInMediaUnits = data.ReadUInt32();
|
||||
header.PlainRegionSizeInMediaUnits = data.ReadUInt32();
|
||||
header.LogoRegionOffsetInMediaUnits = data.ReadUInt32();
|
||||
@@ -302,26 +282,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return header;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into an NCCH header flags
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled NCCH header flags on success, null on error</returns>
|
||||
public static NCCHHeaderFlags? ParseNCCHHeaderFlags(Stream data)
|
||||
{
|
||||
return data.ReadType<NCCHHeaderFlags>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into an NCCH extended header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled NCCH extended header on success, null on error</returns>
|
||||
public static NCCHExtendedHeader? ParseNCCHExtendedHeader(Stream data)
|
||||
{
|
||||
return data.ReadType<NCCHExtendedHeader>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into an ExeFS header
|
||||
/// </summary>
|
||||
@@ -366,24 +326,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return exeFSFileHeader;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into an RomFS header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled RomFS header on success, null on error</returns>
|
||||
public static RomFSHeader? ParseRomFSHeader(Stream data)
|
||||
{
|
||||
var romFSHeader = data.ReadType<RomFSHeader>();
|
||||
|
||||
if (romFSHeader == null)
|
||||
return null;
|
||||
if (romFSHeader.MagicString != RomFSMagicNumber)
|
||||
return null;
|
||||
if (romFSHeader.MagicNumber != RomFSSecondMagicNumber)
|
||||
return null;
|
||||
|
||||
return romFSHeader;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,17 +19,18 @@ namespace SabreTools.Serialization.Deserializers
|
||||
if (data.Position < 0 || data.Position >= data.Length)
|
||||
return null;
|
||||
|
||||
// Cache the current offset
|
||||
long initialOffset = data.Position;
|
||||
|
||||
// Create a new Half-Life No Cache to fill
|
||||
var file = new Models.NCF.File();
|
||||
|
||||
#region Header
|
||||
|
||||
// Try to parse the header
|
||||
var header = ParseHeader(data);
|
||||
if (header == null)
|
||||
var header = data.ReadType<Header>();
|
||||
if (header?.Dummy0 != 0x00000001)
|
||||
return null;
|
||||
if (header?.MajorVersion != 0x00000002)
|
||||
return null;
|
||||
if (header?.MinorVersion != 1)
|
||||
return null;
|
||||
|
||||
// Set the no cache header
|
||||
@@ -38,13 +39,13 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#endregion
|
||||
|
||||
// Cache the current offset
|
||||
initialOffset = data.Position;
|
||||
long initialOffset = data.Position;
|
||||
|
||||
#region Directory Header
|
||||
|
||||
// Try to parse the directory header
|
||||
var directoryHeader = ParseDirectoryHeader(data);
|
||||
if (directoryHeader == null)
|
||||
var directoryHeader = data.ReadType<DirectoryHeader>();
|
||||
if (directoryHeader?.Dummy0 != 0x00000004)
|
||||
return null;
|
||||
|
||||
// Set the game cache directory header
|
||||
@@ -60,7 +61,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the directory entries
|
||||
for (int i = 0; i < directoryHeader.ItemCount; i++)
|
||||
{
|
||||
var directoryEntry = ParseDirectoryEntry(data);
|
||||
var directoryEntry = data.ReadType<DirectoryEntry>();
|
||||
if (directoryEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -108,7 +109,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the directory info 1 entries
|
||||
for (int i = 0; i < directoryHeader.Info1Count; i++)
|
||||
{
|
||||
var directoryInfo1Entry = ParseDirectoryInfo1Entry(data);
|
||||
var directoryInfo1Entry = data.ReadType<DirectoryInfo1Entry>();
|
||||
if (directoryInfo1Entry == null)
|
||||
return null;
|
||||
|
||||
@@ -125,7 +126,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the directory info 2 entries
|
||||
for (int i = 0; i < directoryHeader.ItemCount; i++)
|
||||
{
|
||||
var directoryInfo2Entry = ParseDirectoryInfo2Entry(data);
|
||||
var directoryInfo2Entry = data.ReadType<DirectoryInfo2Entry>();
|
||||
if (directoryInfo2Entry == null)
|
||||
return null;
|
||||
|
||||
@@ -142,7 +143,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the directory copy entries
|
||||
for (int i = 0; i < directoryHeader.CopyCount; i++)
|
||||
{
|
||||
var directoryCopyEntry = ParseDirectoryCopyEntry(data);
|
||||
var directoryCopyEntry = data.ReadType<DirectoryCopyEntry>();
|
||||
if (directoryCopyEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -159,7 +160,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the directory local entries
|
||||
for (int i = 0; i < directoryHeader.LocalCount; i++)
|
||||
{
|
||||
var directoryLocalEntry = ParseDirectoryLocalEntry(data);
|
||||
var directoryLocalEntry = data.ReadType<DirectoryLocalEntry>();
|
||||
if (directoryLocalEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -174,8 +175,10 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Unknown Header
|
||||
|
||||
// Try to parse the unknown header
|
||||
var unknownHeader = ParseUnknownHeader(data);
|
||||
if (unknownHeader == null)
|
||||
var unknownHeader = data.ReadType<UnknownHeader>();
|
||||
if (unknownHeader?.Dummy0 != 0x00000001)
|
||||
return null;
|
||||
if (unknownHeader?.Dummy1 != 0x00000000)
|
||||
return null;
|
||||
|
||||
// Set the game cache unknown header
|
||||
@@ -191,7 +194,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the unknown entries
|
||||
for (int i = 0; i < directoryHeader.ItemCount; i++)
|
||||
{
|
||||
var unknownEntry = ParseUnknownEntry(data);
|
||||
var unknownEntry = data.ReadType<UnknownEntry>();
|
||||
if (unknownEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -203,8 +206,8 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Checksum Header
|
||||
|
||||
// Try to parse the checksum header
|
||||
var checksumHeader = ParseChecksumHeader(data);
|
||||
if (checksumHeader == null)
|
||||
var checksumHeader = data.ReadType<ChecksumHeader>();
|
||||
if (checksumHeader?.Dummy0 != 0x00000001)
|
||||
return null;
|
||||
|
||||
// Set the game cache checksum header
|
||||
@@ -218,8 +221,10 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Checksum Map Header
|
||||
|
||||
// Try to parse the checksum map header
|
||||
var checksumMapHeader = ParseChecksumMapHeader(data);
|
||||
if (checksumMapHeader == null)
|
||||
var checksumMapHeader = data.ReadType<ChecksumMapHeader>();
|
||||
if (checksumMapHeader?.Dummy0 != 0x14893721)
|
||||
return null;
|
||||
if (checksumMapHeader?.Dummy1 != 0x00000001)
|
||||
return null;
|
||||
|
||||
// Set the game cache checksum map header
|
||||
@@ -235,7 +240,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the checksum map entries
|
||||
for (int i = 0; i < checksumMapHeader.ItemCount; i++)
|
||||
{
|
||||
var checksumMapEntry = ParseChecksumMapEntry(data);
|
||||
var checksumMapEntry = data.ReadType<ChecksumMapEntry>();
|
||||
if (checksumMapEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -252,7 +257,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the checksum entries
|
||||
for (int i = 0; i < checksumMapHeader.ChecksumCount; i++)
|
||||
{
|
||||
var checksumEntry = ParseChecksumEntry(data);
|
||||
var checksumEntry = data.ReadType<ChecksumEntry>();
|
||||
if (checksumEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -266,178 +271,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life No Cache header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life No Cache header on success, null on error</returns>
|
||||
private static Header? ParseHeader(Stream data)
|
||||
{
|
||||
var header = data.ReadType<Header>();
|
||||
|
||||
if (header == null)
|
||||
return null;
|
||||
if (header.Dummy0 != 0x00000001)
|
||||
return null;
|
||||
if (header.MajorVersion != 0x00000002)
|
||||
return null;
|
||||
if (header.MinorVersion != 1)
|
||||
return null;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life No Cache directory header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life No Cache directory header on success, null on error</returns>
|
||||
private static DirectoryHeader? ParseDirectoryHeader(Stream data)
|
||||
{
|
||||
var directoryHeader = data.ReadType<DirectoryHeader>();
|
||||
|
||||
if (directoryHeader == null)
|
||||
return null;
|
||||
if (directoryHeader.Dummy0 != 0x00000004)
|
||||
return null;
|
||||
|
||||
return directoryHeader;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life No Cache directory entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life No Cache directory entry on success, null on error</returns>
|
||||
private static DirectoryEntry? ParseDirectoryEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<DirectoryEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life No Cache directory info 1 entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life No Cache directory info 1 entry on success, null on error</returns>
|
||||
private static DirectoryInfo1Entry? ParseDirectoryInfo1Entry(Stream data)
|
||||
{
|
||||
return data.ReadType<DirectoryInfo1Entry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life No Cache directory info 2 entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life No Cache directory info 2 entry on success, null on error</returns>
|
||||
private static DirectoryInfo2Entry? ParseDirectoryInfo2Entry(Stream data)
|
||||
{
|
||||
return data.ReadType<DirectoryInfo2Entry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life No Cache directory copy entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life No Cache directory copy entry on success, null on error</returns>
|
||||
private static DirectoryCopyEntry? ParseDirectoryCopyEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<DirectoryCopyEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life No Cache directory local entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life No Cache directory local entry on success, null on error</returns>
|
||||
private static DirectoryLocalEntry? ParseDirectoryLocalEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<DirectoryLocalEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life No Cache unknown header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life No Cache unknown header on success, null on error</returns>
|
||||
private static UnknownHeader? ParseUnknownHeader(Stream data)
|
||||
{
|
||||
var unknownHeader = data.ReadType<UnknownHeader>();
|
||||
|
||||
if (unknownHeader == null)
|
||||
return null;
|
||||
if (unknownHeader.Dummy0 != 0x00000001)
|
||||
return null;
|
||||
if (unknownHeader.Dummy1 != 0x00000000)
|
||||
return null;
|
||||
|
||||
return unknownHeader;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life No Cache unknown entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life No Cacheunknown entry on success, null on error</returns>
|
||||
private static UnknownEntry? ParseUnknownEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<UnknownEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life No Cache checksum header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life No Cache checksum header on success, null on error</returns>
|
||||
private static ChecksumHeader? ParseChecksumHeader(Stream data)
|
||||
{
|
||||
var checksumHeader = data.ReadType<ChecksumHeader>();
|
||||
|
||||
if (checksumHeader == null)
|
||||
return null;
|
||||
if (checksumHeader.Dummy0 != 0x00000001)
|
||||
return null;
|
||||
|
||||
return checksumHeader;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life No Cache checksum map header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life No Cache checksum map header on success, null on error</returns>
|
||||
private static ChecksumMapHeader? ParseChecksumMapHeader(Stream data)
|
||||
{
|
||||
var checksumMapHeader = data.ReadType<ChecksumMapHeader>();
|
||||
|
||||
if (checksumMapHeader == null)
|
||||
return null;
|
||||
if (checksumMapHeader.Dummy0 != 0x14893721)
|
||||
return null;
|
||||
if (checksumMapHeader.Dummy1 != 0x00000001)
|
||||
return null;
|
||||
|
||||
return checksumMapHeader;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life No Cache checksum map entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life No Cache checksum map entry on success, null on error</returns>
|
||||
private static ChecksumMapEntry? ParseChecksumMapEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<ChecksumMapEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life No Cache checksum entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life No Cache checksum entry on success, null on error</returns>
|
||||
private static ChecksumEntry? ParseChecksumEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<ChecksumEntry>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,12 +41,12 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
// Try to parse the executable header
|
||||
data.Seek(initialOffset + stub.Header.NewExeHeaderAddr, SeekOrigin.Begin);
|
||||
var executableHeader = ParseExecutableHeader(data);
|
||||
if (executableHeader == null)
|
||||
var header = data.ReadType<ExecutableHeader>();
|
||||
if (header?.Magic != SignatureString)
|
||||
return null;
|
||||
|
||||
// Set the executable header
|
||||
executable.Header = executableHeader;
|
||||
executable.Header = header;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -55,13 +55,13 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// If the offset for the segment table doesn't exist
|
||||
int tableAddress = initialOffset
|
||||
+ (int)stub.Header.NewExeHeaderAddr
|
||||
+ executableHeader.SegmentTableOffset;
|
||||
+ header.SegmentTableOffset;
|
||||
if (tableAddress >= data.Length)
|
||||
return executable;
|
||||
|
||||
// Try to parse the segment table
|
||||
data.Seek(tableAddress, SeekOrigin.Begin);
|
||||
var segmentTable = ParseSegmentTable(data, executableHeader.FileSegmentCount);
|
||||
var segmentTable = ParseSegmentTable(data, header.FileSegmentCount);
|
||||
if (segmentTable == null)
|
||||
return null;
|
||||
|
||||
@@ -75,13 +75,13 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// If the offset for the segment table doesn't exist
|
||||
tableAddress = initialOffset
|
||||
+ (int)stub.Header.NewExeHeaderAddr
|
||||
+ executableHeader.ResourceTableOffset;
|
||||
+ header.ResourceTableOffset;
|
||||
if (tableAddress >= data.Length)
|
||||
return executable;
|
||||
|
||||
// Try to parse the resource table
|
||||
data.Seek(tableAddress, SeekOrigin.Begin);
|
||||
var resourceTable = ParseResourceTable(data, executableHeader.ResourceEntriesCount);
|
||||
var resourceTable = ParseResourceTable(data, header.ResourceEntriesCount);
|
||||
if (resourceTable == null)
|
||||
return null;
|
||||
|
||||
@@ -95,10 +95,10 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// If the offset for the resident-name table doesn't exist
|
||||
tableAddress = initialOffset
|
||||
+ (int)stub.Header.NewExeHeaderAddr
|
||||
+ executableHeader.ResidentNameTableOffset;
|
||||
+ header.ResidentNameTableOffset;
|
||||
int endOffset = initialOffset
|
||||
+ (int)stub.Header.NewExeHeaderAddr
|
||||
+ executableHeader.ModuleReferenceTableOffset;
|
||||
+ header.ModuleReferenceTableOffset;
|
||||
if (tableAddress >= data.Length)
|
||||
return executable;
|
||||
|
||||
@@ -118,13 +118,13 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// If the offset for the module-reference table doesn't exist
|
||||
tableAddress = initialOffset
|
||||
+ (int)stub.Header.NewExeHeaderAddr
|
||||
+ executableHeader.ModuleReferenceTableOffset;
|
||||
+ header.ModuleReferenceTableOffset;
|
||||
if (tableAddress >= data.Length)
|
||||
return executable;
|
||||
|
||||
// Try to parse the module-reference table
|
||||
data.Seek(tableAddress, SeekOrigin.Begin);
|
||||
var moduleReferenceTable = ParseModuleReferenceTable(data, executableHeader.ModuleReferenceTableSize);
|
||||
var moduleReferenceTable = ParseModuleReferenceTable(data, header.ModuleReferenceTableSize);
|
||||
if (moduleReferenceTable == null)
|
||||
return null;
|
||||
|
||||
@@ -138,10 +138,10 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// If the offset for the imported-name table doesn't exist
|
||||
tableAddress = initialOffset
|
||||
+ (int)stub.Header.NewExeHeaderAddr
|
||||
+ executableHeader.ImportedNamesTableOffset;
|
||||
+ header.ImportedNamesTableOffset;
|
||||
endOffset = initialOffset
|
||||
+ (int)stub.Header.NewExeHeaderAddr
|
||||
+ executableHeader.EntryTableOffset;
|
||||
+ header.EntryTableOffset;
|
||||
if (tableAddress >= data.Length)
|
||||
return executable;
|
||||
|
||||
@@ -161,11 +161,11 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// If the offset for the imported-name table doesn't exist
|
||||
tableAddress = initialOffset
|
||||
+ (int)stub.Header.NewExeHeaderAddr
|
||||
+ executableHeader.EntryTableOffset;
|
||||
+ header.EntryTableOffset;
|
||||
endOffset = initialOffset
|
||||
+ (int)stub.Header.NewExeHeaderAddr
|
||||
+ executableHeader.EntryTableOffset
|
||||
+ executableHeader.EntryTableSize;
|
||||
+ header.EntryTableOffset
|
||||
+ header.EntryTableSize;
|
||||
if (tableAddress >= data.Length)
|
||||
return executable;
|
||||
|
||||
@@ -184,10 +184,10 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
// If the offset for the nonresident-name table doesn't exist
|
||||
tableAddress = initialOffset
|
||||
+ (int)executableHeader.NonResidentNamesTableOffset;
|
||||
+ (int)header.NonResidentNamesTableOffset;
|
||||
endOffset = initialOffset
|
||||
+ (int)executableHeader.NonResidentNamesTableOffset
|
||||
+ executableHeader.NonResidentNameTableSize;
|
||||
+ (int)header.NonResidentNamesTableOffset
|
||||
+ header.NonResidentNameTableSize;
|
||||
if (tableAddress >= data.Length)
|
||||
return executable;
|
||||
|
||||
@@ -205,21 +205,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return executable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a New Executable header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled executable header on success, null on error</returns>
|
||||
public static ExecutableHeader? ParseExecutableHeader(Stream data)
|
||||
{
|
||||
var header = data.ReadType<ExecutableHeader>();
|
||||
|
||||
if (header?.Magic != SignatureString)
|
||||
return null;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a segment table
|
||||
/// </summary>
|
||||
@@ -232,7 +217,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var entry = ParseSegmentTableEntry(data);
|
||||
var entry = data.ReadType<SegmentTableEntry>();
|
||||
if (entry == null)
|
||||
return null;
|
||||
|
||||
@@ -242,16 +227,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return segmentTable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a segment table entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled segment table entry on success, null on error</returns>
|
||||
public static SegmentTableEntry? ParseSegmentTableEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<SegmentTableEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a resource table
|
||||
/// </summary>
|
||||
@@ -286,7 +261,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
for (int j = 0; j < entry.ResourceCount; j++)
|
||||
{
|
||||
// TODO: Should we read and store the resource data?
|
||||
var resource = ParseResourceTypeResourceEntry(data);
|
||||
var resource = data.ReadType<ResourceTypeResourceEntry>();
|
||||
if (resource == null)
|
||||
return null;
|
||||
|
||||
@@ -344,17 +319,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return resourceTable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a resource entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled resource entry on success, null on error</returns>
|
||||
public static ResourceTypeResourceEntry? ParseResourceTypeResourceEntry(Stream data)
|
||||
{
|
||||
// TODO: Should we read and store the resource data?
|
||||
return data.ReadType<ResourceTypeResourceEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a resource type and name string
|
||||
/// </summary>
|
||||
@@ -420,7 +384,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var entry = ParseModuleReferenceTableEntry(data);
|
||||
var entry = data.ReadType<ModuleReferenceTableEntry>();
|
||||
if (entry == null)
|
||||
return null;
|
||||
|
||||
@@ -430,16 +394,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return moduleReferenceTable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a module-reference table entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled module-reference table entry on success, null on error</returns>
|
||||
public static ModuleReferenceTableEntry? ParseModuleReferenceTableEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<ModuleReferenceTableEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into an imported-name table
|
||||
/// </summary>
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Header
|
||||
|
||||
// Try to parse the header
|
||||
var header = ParseCommonHeader(data);
|
||||
var header = data.ReadType<CommonHeader>();
|
||||
if (header == null)
|
||||
return null;
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// If we have a DSi-compatible cartridge
|
||||
if (header.UnitCode == Unitcode.NDSPlusDSi || header.UnitCode == Unitcode.DSi)
|
||||
{
|
||||
var extendedDSiHeader = ParseExtendedDSiHeader(data);
|
||||
var extendedDSiHeader = data.ReadType<ExtendedDSiHeader>();
|
||||
if (extendedDSiHeader == null)
|
||||
return null;
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the file allocation table
|
||||
while (data.Position - fileAllocationTableOffset < header.FileAllocationTableLength)
|
||||
{
|
||||
var entry = ParseFileAllocationTableEntry(data);
|
||||
var entry = data.ReadType<FileAllocationTableEntry>();
|
||||
if (entry == null)
|
||||
return null;
|
||||
|
||||
@@ -117,26 +117,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return cart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a common header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled common header on success, null on error</returns>
|
||||
private static CommonHeader? ParseCommonHeader(Stream data)
|
||||
{
|
||||
return data.ReadType<CommonHeader>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into an extended DSi header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled extended DSi header on success, null on error</returns>
|
||||
private static ExtendedDSiHeader? ParseExtendedDSiHeader(Stream data)
|
||||
{
|
||||
return data.ReadType<ExtendedDSiHeader>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a name table
|
||||
/// </summary>
|
||||
@@ -151,7 +131,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
int entryCount = int.MaxValue;
|
||||
while (entryCount > 0)
|
||||
{
|
||||
var entry = ParseFolderAllocationTableEntry(data);
|
||||
var entry = data.ReadType<FolderAllocationTableEntry>();
|
||||
if (entry == null)
|
||||
return null;
|
||||
|
||||
@@ -185,16 +165,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return nameTable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a folder allocation table entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled folder allocation table entry on success, null on error</returns>
|
||||
private static FolderAllocationTableEntry? ParseFolderAllocationTableEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<FolderAllocationTableEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a name list entry
|
||||
/// </summary>
|
||||
@@ -222,15 +192,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a name list entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled name list entry on success, null on error</returns>
|
||||
private static FileAllocationTableEntry? ParseFileAllocationTableEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<FileAllocationTableEntry>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,8 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Header
|
||||
|
||||
// Try to parse the header
|
||||
var header = ParseHeader(data);
|
||||
if (header == null)
|
||||
var header = data.ReadType<Header>();
|
||||
if (header?.Signature != SignatureString)
|
||||
return null;
|
||||
|
||||
// Set the package header
|
||||
@@ -49,7 +49,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the directory items
|
||||
for (int i = 0; i < file.DirectoryItems.Length; i++)
|
||||
{
|
||||
var directoryItem = ParseDirectoryItem(data);
|
||||
var directoryItem = data.ReadType<DirectoryItem>();
|
||||
if (directoryItem == null)
|
||||
return null;
|
||||
|
||||
@@ -60,30 +60,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Package header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Package header on success, null on error</returns>
|
||||
private static Header? ParseHeader(Stream data)
|
||||
{
|
||||
var header = data.ReadType<Header>();
|
||||
|
||||
if (header?.Signature != SignatureString)
|
||||
return null;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Package directory item
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Package directory item on success, null on error</returns>
|
||||
private static DirectoryItem? ParseDirectoryItem(Stream data)
|
||||
{
|
||||
return data.ReadType<DirectoryItem>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
data.Seek(offset, SeekOrigin.Begin);
|
||||
|
||||
// Try to parse the footer
|
||||
var footer = ParseFooter(data);
|
||||
var footer = data.ReadType<Footer>();
|
||||
if (footer == null)
|
||||
return null;
|
||||
|
||||
@@ -90,10 +90,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
private static Header? ParseHeader(Stream data)
|
||||
{
|
||||
var header = data.ReadType<Header>();
|
||||
if (header == null)
|
||||
return null;
|
||||
|
||||
return header.Signature switch
|
||||
return header?.Signature switch
|
||||
{
|
||||
Version0SignatureString when header.FileSegmentSize != Version0HSegmentSize => null,
|
||||
Version0SignatureString => header,
|
||||
@@ -112,16 +109,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a footer
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled footer on success, null on error</returns>
|
||||
private static Footer? ParseFooter(Stream data)
|
||||
{
|
||||
return data.ReadType<Footer>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a file entry
|
||||
/// </summary>
|
||||
|
||||
@@ -61,9 +61,9 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
#region Header
|
||||
|
||||
// Try to parse the header
|
||||
var header = ParseDiscInformationUnitHeader(data);
|
||||
if (header == null)
|
||||
// We only accept Disc Information units, not Emergency Brake or other
|
||||
var header = data.ReadType<DiscInformationUnitHeader>();
|
||||
if (header?.DiscInformationIdentifier != "DI")
|
||||
return null;
|
||||
|
||||
// Set the information unit header
|
||||
@@ -88,7 +88,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
if (unit.Body.DiscTypeIdentifier == DiscTypeIdentifierReWritable || unit.Body.DiscTypeIdentifier == DiscTypeIdentifierRecordable)
|
||||
{
|
||||
// Try to parse the trailer
|
||||
var trailer = ParseDiscInformationUnitTrailer(data);
|
||||
var trailer = data.ReadType<DiscInformationUnitTrailer>();
|
||||
if (trailer == null)
|
||||
return null;
|
||||
|
||||
@@ -101,22 +101,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return unit;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a disc information unit header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled disc information unit header on success, null on error</returns>
|
||||
private static DiscInformationUnitHeader? ParseDiscInformationUnitHeader(Stream data)
|
||||
{
|
||||
var header = data.ReadType<DiscInformationUnitHeader>();
|
||||
|
||||
// We only accept Disc Information units, not Emergency Brake or other
|
||||
if (header?.DiscInformationIdentifier != "DI")
|
||||
return null;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a disc information unit body
|
||||
/// </summary>
|
||||
@@ -145,16 +129,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return body;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a disc information unit trailer
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled disc information unit trailer on success, null on error</returns>
|
||||
private static DiscInformationUnitTrailer? ParseDiscInformationUnitTrailer(Stream data)
|
||||
{
|
||||
return data.ReadType<DiscInformationUnitTrailer>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
data.Seek(eocdlOffset, SeekOrigin.Begin);
|
||||
|
||||
// Read the ZIP64 end of central directory locator
|
||||
var eocdl64 = ParseEndOfCentralDirectoryLocator64(data);
|
||||
var eocdl64 = data.ReadType<EndOfCentralDirectoryLocator64>();
|
||||
if (eocdl64 == null)
|
||||
return null;
|
||||
|
||||
@@ -428,16 +428,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a ZIP64 end of central directory locator
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled ZIP64 end of central directory locator on success, null on error</returns>
|
||||
public static EndOfCentralDirectoryLocator64? ParseEndOfCentralDirectoryLocator64(Stream data)
|
||||
{
|
||||
return data.ReadType<EndOfCentralDirectoryLocator64>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a ZIP64 end of central directory record
|
||||
/// </summary>
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region COFF File Header
|
||||
|
||||
// Try to parse the COFF file header
|
||||
var coffFileHeader = ParseCOFFFileHeader(data);
|
||||
var coffFileHeader = data.ReadType<COFFFileHeader>();
|
||||
if (coffFileHeader == null)
|
||||
return null;
|
||||
|
||||
@@ -154,7 +154,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
// Try to parse the delay-load directory table
|
||||
data.Seek(delayLoadDirectoryTableAddress, SeekOrigin.Begin);
|
||||
var delayLoadDirectoryTable = ParseDelayLoadDirectoryTable(data);
|
||||
var delayLoadDirectoryTable = data.ReadType<DelayLoadDirectoryTable>();
|
||||
if (delayLoadDirectoryTable == null)
|
||||
return null;
|
||||
|
||||
@@ -285,16 +285,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return executable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Portable Executable COFF file header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled executable header on success, null on error</returns>
|
||||
public static COFFFileHeader? ParseCOFFFileHeader(Stream data)
|
||||
{
|
||||
return data.ReadType<COFFFileHeader>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into an optional header
|
||||
/// </summary>
|
||||
@@ -676,16 +666,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return [.. attributeCertificateTable];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a byte array into a delay-load directory table
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled delay-load directory table on success, null on error</returns>
|
||||
public static DelayLoadDirectoryTable? ParseDelayLoadDirectoryTable(Stream data)
|
||||
{
|
||||
return data.ReadType<DelayLoadDirectoryTable>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a base relocation table
|
||||
/// </summary>
|
||||
@@ -1110,7 +1090,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
int hintNameTableEntryAddress = hintNameTableEntryAddresses[i];
|
||||
data.Seek(hintNameTableEntryAddress, SeekOrigin.Begin);
|
||||
|
||||
var hintNameTableEntry = ParseHintNameTableEntry(data);
|
||||
var hintNameTableEntry = data.ReadType<HintNameTableEntry>();
|
||||
if (hintNameTableEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -1124,16 +1104,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return importTable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a hint name table entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled hint name table entry on success, null on error</returns>
|
||||
public static HintNameTableEntry? ParseHintNameTableEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<HintNameTableEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a resource directory table
|
||||
/// </summary>
|
||||
|
||||
@@ -25,8 +25,8 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Header
|
||||
|
||||
// Try to parse the header
|
||||
var header = ParseHeader(data);
|
||||
if (header == null)
|
||||
var header = data.ReadType<Header>();
|
||||
if (header?.Signature != SignatureString)
|
||||
return null;
|
||||
|
||||
// Set the archive header
|
||||
@@ -60,21 +60,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return archive;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled header on success, null on error</returns>
|
||||
private static Header? ParseHeader(Stream data)
|
||||
{
|
||||
var header = data.ReadType<Header>();
|
||||
|
||||
if (header?.Signature != SignatureString)
|
||||
return null;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a file descriptor
|
||||
/// </summary>
|
||||
|
||||
@@ -19,10 +19,10 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
// Deserialize the SFB
|
||||
var sfb = data.ReadType<Models.PlayStation3.SFB>();
|
||||
if (sfb == null)
|
||||
if (sfb?.Magic == null)
|
||||
return null;
|
||||
|
||||
string magic = Encoding.ASCII.GetString(sfb!.Magic!);
|
||||
string magic = Encoding.ASCII.GetString(sfb.Magic);
|
||||
if (magic != ".SFB")
|
||||
return null;
|
||||
|
||||
|
||||
@@ -27,8 +27,12 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Header
|
||||
|
||||
// Try to parse the header
|
||||
var header = ParseHeader(data);
|
||||
if (header?.Lumps == null)
|
||||
var header = data.ReadType<VbspHeader>();
|
||||
if (header?.Signature != SignatureString)
|
||||
return null;
|
||||
if (Array.IndexOf([17, 18, 19, 20, 21, 22, 23, 25, 27, 29, 0x00040014], header.Version) > -1)
|
||||
return null;
|
||||
if (header.Lumps == null)
|
||||
return null;
|
||||
|
||||
// Set the package header
|
||||
@@ -257,23 +261,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return file;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life 2 Level header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life 2 Level header on success, null on error</returns>
|
||||
private static VbspHeader? ParseHeader(Stream data)
|
||||
{
|
||||
var header = data.ReadType<VbspHeader>();
|
||||
|
||||
if (header?.Signature != SignatureString)
|
||||
return null;
|
||||
if (Array.IndexOf([17, 18, 19, 20, 21, 22, 23, 25, 27, 29, 0x00040014], header.Version) > -1)
|
||||
return null;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into LUMP_ENTITIES
|
||||
/// </summary>
|
||||
|
||||
@@ -19,9 +19,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
if (data.Position < 0 || data.Position >= data.Length)
|
||||
return null;
|
||||
|
||||
// Cache the current offset
|
||||
long initialOffset = data.Position;
|
||||
|
||||
// Create a new Valve Package to fill
|
||||
var file = new Models.VPK.File();
|
||||
|
||||
@@ -29,8 +26,10 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
// Try to parse the header
|
||||
// The original version had no signature.
|
||||
var header = ParseHeader(data);
|
||||
if (header == null)
|
||||
var header = data.ReadType<Header>();
|
||||
if (header?.Signature != SignatureUInt32)
|
||||
return null;
|
||||
if (header.Version > 2)
|
||||
return null;
|
||||
|
||||
// Set the package header
|
||||
@@ -43,7 +42,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
if (header.Version == 2)
|
||||
{
|
||||
// Try to parse the extended header
|
||||
var extendedHeader = ParseExtendedHeader(data);
|
||||
var extendedHeader = data.ReadType<ExtendedHeader>();
|
||||
if (extendedHeader == null)
|
||||
return null;
|
||||
|
||||
@@ -76,12 +75,12 @@ namespace SabreTools.Serialization.Deserializers
|
||||
var archiveHashes = new List<ArchiveHash>();
|
||||
|
||||
// Cache the current offset
|
||||
initialOffset = data.Position;
|
||||
long initialOffset = data.Position;
|
||||
|
||||
// Try to parse the directory items
|
||||
while (data.Position < initialOffset + file.ExtendedHeader.ArchiveMD5SectionSize)
|
||||
{
|
||||
var archiveHash = ParseArchiveHash(data);
|
||||
var archiveHash = data.ReadType<ArchiveHash>();
|
||||
if (archiveHash == null)
|
||||
return null;
|
||||
|
||||
@@ -96,45 +95,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return file;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Valve Package header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Valve Package header on success, null on error</returns>
|
||||
private static Header? ParseHeader(Stream data)
|
||||
{
|
||||
var header = data.ReadType<Header>();
|
||||
|
||||
if (header == null)
|
||||
return null;
|
||||
if (header.Signature != SignatureUInt32)
|
||||
return null;
|
||||
if (header.Version > 2)
|
||||
return null;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Valve Package extended header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Valve Package extended header on success, null on error</returns>
|
||||
private static ExtendedHeader? ParseExtendedHeader(Stream data)
|
||||
{
|
||||
return data.ReadType<ExtendedHeader>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Valve Package archive hash
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Valve Package archive hash on success, null on error</returns>
|
||||
private static ArchiveHash? ParseArchiveHash(Stream data)
|
||||
{
|
||||
return data.ReadType<ArchiveHash>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Valve Package directory item tree
|
||||
/// </summary>
|
||||
@@ -212,7 +172,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
directoryItem.Name = name;
|
||||
|
||||
// Get the directory entry
|
||||
var directoryEntry = ParseDirectoryEntry(data);
|
||||
var directoryEntry = data.ReadType<DirectoryEntry>();
|
||||
if (directoryEntry == null)
|
||||
return null;
|
||||
|
||||
@@ -258,15 +218,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return directoryItem;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Valve Package directory entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Valve Package directory entry on success, null on error</returns>
|
||||
private static DirectoryEntry? ParseDirectoryEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<DirectoryEntry>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,8 +25,8 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Header
|
||||
|
||||
// Try to parse the header
|
||||
var header = ParseHeader(data);
|
||||
if (header == null)
|
||||
var header = data.ReadType<Header>();
|
||||
if (header?.Signature != SignatureString)
|
||||
return null;
|
||||
|
||||
// Set the package header
|
||||
@@ -48,7 +48,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
file.DirEntries = new DirEntry[header.NumDirs];
|
||||
for (int i = 0; i < header.NumDirs; i++)
|
||||
{
|
||||
var lump = ParseDirEntry(data);
|
||||
var lump = data.ReadType<DirEntry>();
|
||||
if (lump == null)
|
||||
return null;
|
||||
|
||||
@@ -90,33 +90,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return file;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Texture Package header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Texture Package header on success, null on error</returns>
|
||||
private static Header? ParseHeader(Stream data)
|
||||
{
|
||||
var header = data.ReadType<Header>();
|
||||
|
||||
if (header == null)
|
||||
return null;
|
||||
if (header.Signature != SignatureString)
|
||||
return null;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Texture Package directory entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Texture Package directory entry on success, null on error</returns>
|
||||
private static DirEntry? ParseDirEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<DirEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Texture Package file entry
|
||||
/// </summary>
|
||||
@@ -228,7 +201,9 @@ namespace SabreTools.Serialization.Deserializers
|
||||
font.FontInfo = new CharInfo[256];
|
||||
for (int i = 0; i < font.FontInfo.Length; i++)
|
||||
{
|
||||
font.FontInfo[i] = ParseCharInfo(data);
|
||||
var fontInfo = data.ReadType<CharInfo>();
|
||||
if (fontInfo != null)
|
||||
font.FontInfo[i] = fontInfo;
|
||||
}
|
||||
font.Data = new byte[font.Height][];
|
||||
for (int i = 0; i < font.Height; i++)
|
||||
@@ -244,20 +219,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a Half-Life Texture Package CharInfo
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled Half-Life Texture Package CharInfo on success, null on error</returns>
|
||||
private static CharInfo ParseCharInfo(Stream data)
|
||||
{
|
||||
var charinfo = new CharInfo();
|
||||
|
||||
charinfo.StartOffset = data.ReadUInt16();
|
||||
charinfo.CharWidth = data.ReadUInt16();
|
||||
|
||||
return charinfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,7 @@ using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public partial class XMID :
|
||||
IStringDeserializer<Models.Xbox.XMID>
|
||||
public partial class XMID : IStringDeserializer<Models.Xbox.XMID>
|
||||
{
|
||||
#region IStringDeserializer
|
||||
|
||||
|
||||
@@ -24,8 +24,10 @@ namespace SabreTools.Serialization.Deserializers
|
||||
#region Header
|
||||
|
||||
// Try to parse the header
|
||||
var header = ParseHeader(data);
|
||||
if (header == null)
|
||||
var header = data.ReadType<Header>();
|
||||
if (header?.Signature != HeaderSignatureString)
|
||||
return null;
|
||||
if (header.Version != 6)
|
||||
return null;
|
||||
|
||||
// Set the package header
|
||||
@@ -41,7 +43,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the directory entries
|
||||
for (int i = 0; i < file.DirectoryEntries.Length; i++)
|
||||
{
|
||||
var directoryEntry = ParseDirectoryEntry(data);
|
||||
var directoryEntry = data.ReadType<DirectoryEntry>();
|
||||
if (directoryEntry == null)
|
||||
continue;
|
||||
|
||||
@@ -60,7 +62,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the preload directory entries
|
||||
for (int i = 0; i < file.PreloadDirectoryEntries.Length; i++)
|
||||
{
|
||||
var directoryEntry = ParseDirectoryEntry(data);
|
||||
var directoryEntry = data.ReadType<DirectoryEntry>();
|
||||
if (directoryEntry == null)
|
||||
continue;
|
||||
|
||||
@@ -80,7 +82,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// Try to parse the preload directory mappings
|
||||
for (int i = 0; i < file.PreloadDirectoryMappings.Length; i++)
|
||||
{
|
||||
var directoryMapping = ParseDirectoryMapping(data);
|
||||
var directoryMapping = data.ReadType<DirectoryMapping>();
|
||||
if (directoryMapping == null)
|
||||
continue;
|
||||
|
||||
@@ -121,8 +123,8 @@ namespace SabreTools.Serialization.Deserializers
|
||||
data.Seek(-8, SeekOrigin.End);
|
||||
|
||||
// Try to parse the footer
|
||||
var footer = ParseFooter(data);
|
||||
if (footer == null)
|
||||
var footer = data.ReadType<Footer>();
|
||||
if (footer?.Signature != FooterSignatureString)
|
||||
return null;
|
||||
|
||||
// Set the package footer
|
||||
@@ -133,43 +135,6 @@ namespace SabreTools.Serialization.Deserializers
|
||||
return file;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a XBox Package File header
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled XBox Package File header on success, null on error</returns>
|
||||
private static Header? ParseHeader(Stream data)
|
||||
{
|
||||
var header = data.ReadType<Header>();
|
||||
|
||||
if (header?.Signature != HeaderSignatureString)
|
||||
return null;
|
||||
if (header.Version != 6)
|
||||
return null;
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a XBox Package File directory entry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled XBox Package File directory entry on success, null on error</returns>
|
||||
private static DirectoryEntry? ParseDirectoryEntry(Stream data)
|
||||
{
|
||||
return data.ReadType<DirectoryEntry>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a XBox Package File directory mapping
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled XBox Package File directory mapping on success, null on error</returns>
|
||||
private static DirectoryMapping? ParseDirectoryMapping(Stream data)
|
||||
{
|
||||
return data.ReadType<DirectoryMapping>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a XBox Package File directory item
|
||||
/// </summary>
|
||||
@@ -197,20 +162,5 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
return directoryItem;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a Stream into a XBox Package File footer
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled XBox Package File footer on success, null on error</returns>
|
||||
private static Footer? ParseFooter(Stream data)
|
||||
{
|
||||
var footer = data.ReadType<Footer>();
|
||||
|
||||
if (footer?.Signature != FooterSignatureString)
|
||||
return null;
|
||||
|
||||
return footer;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,7 @@ using SabreTools.Serialization.Interfaces;
|
||||
|
||||
namespace SabreTools.Serialization.Deserializers
|
||||
{
|
||||
public partial class XeMID :
|
||||
IStringDeserializer<Models.Xbox.XeMID>
|
||||
public partial class XeMID : IStringDeserializer<Models.Xbox.XeMID>
|
||||
{
|
||||
#region IStringDeserializer
|
||||
|
||||
|
||||
Reference in New Issue
Block a user