Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using AuroraLib.Archives; | ||
using AuroraLib.Common; | ||
|
||
namespace AuroraLip.Archives.Formats | ||
{ | ||
public class PAK_TM2 : Archive, IFileAccess | ||
{ | ||
public bool CanRead => true; | ||
|
||
public bool CanWrite => false; | ||
|
||
public const string Extension = ".pak"; | ||
|
||
public bool IsMatch(Stream stream, in string extension = "") | ||
=> Matcher(stream, extension); | ||
|
||
public static bool Matcher(Stream stream, in string extension = "") | ||
{ | ||
if (extension == Extension && stream.Length > 0x20) | ||
{ | ||
uint entryCount = stream.ReadUInt32(Endian.Big); | ||
if (entryCount != 0 && entryCount < 1024 && stream.Position + entryCount * 8 < stream.Length) | ||
{ | ||
stream.Seek((entryCount - 1) * 8, SeekOrigin.Current); | ||
Entry lastEntry = stream.Read<Entry>(Endian.Big); | ||
return lastEntry.Offset + lastEntry.Size == stream.Length; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
protected override void Read(Stream stream) | ||
{ | ||
uint entryCount = stream.ReadUInt32(Endian.Big); | ||
Entry[] entrys = stream.For((int)entryCount, s => s.Read<Entry>(Endian.Big)); | ||
|
||
|
||
Root = new ArchiveDirectory() { OwnerArchive = this }; | ||
for (int i = 0; i < entrys.Length; i++) | ||
{ | ||
Root.AddArchiveFile(stream, entrys[i].Size, entrys[i].Offset, $"Entry_{i}"); | ||
} | ||
} | ||
|
||
protected override void Write(Stream stream) => throw new NotImplementedException(); | ||
|
||
private struct Entry | ||
{ | ||
public uint Offset; | ||
public uint Size; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters