mirror of
https://github.com/crskycode/GARbro.git
synced 2026-06-06 13:48:57 +08:00
refactor: Rename & Format
This commit is contained in:
@@ -81,7 +81,7 @@ namespace GameRes.Formats.NeXAS
|
||||
Settings = new[] { PacEncoding };
|
||||
}
|
||||
|
||||
EncodingSetting PacEncoding = new EncodingSetting ("NexasEncodingCP", "DefaultEncoding");
|
||||
readonly EncodingSetting PacEncoding = new EncodingSetting ("NexasEncodingCP", "DefaultEncoding");
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
@@ -89,17 +89,17 @@ namespace GameRes.Formats.NeXAS
|
||||
return null;
|
||||
|
||||
List<Entry> dir = null;
|
||||
INexasIndexReader reader = new IndexReader (file, PacEncoding.Get<Encoding>());
|
||||
INexasIndexReader reader = new IndexReaderV1 (file, PacEncoding.Get<Encoding> ());
|
||||
try
|
||||
{
|
||||
dir = reader.Read();
|
||||
dir = reader.Read ();
|
||||
}
|
||||
catch {}
|
||||
|
||||
if (null == dir)
|
||||
{
|
||||
reader = new OldIndexReader (file);
|
||||
dir = reader.Read();
|
||||
reader = new IndexReaderV0 (file);
|
||||
dir = reader.Read ();
|
||||
|
||||
if (null == dir)
|
||||
return null;
|
||||
@@ -110,18 +110,18 @@ namespace GameRes.Formats.NeXAS
|
||||
return new PacArchive (file, this, dir, reader.PackType);
|
||||
}
|
||||
|
||||
internal sealed class IndexReader : INexasIndexReader
|
||||
internal sealed class IndexReaderV1 : INexasIndexReader
|
||||
{
|
||||
ArcView m_file;
|
||||
int m_count;
|
||||
int m_pack_type;
|
||||
Encoding m_encoding;
|
||||
readonly ArcView m_file;
|
||||
readonly int m_count;
|
||||
readonly int m_pack_type;
|
||||
readonly Encoding m_encoding;
|
||||
|
||||
const int MaxNameLength = 0x40;
|
||||
|
||||
public Compression PackType { get { return (Compression)m_pack_type; } }
|
||||
|
||||
public IndexReader (ArcView file, Encoding enc)
|
||||
public IndexReaderV1 (ArcView file, Encoding enc)
|
||||
{
|
||||
m_file = file;
|
||||
m_count = file.View.ReadInt32 (4);
|
||||
@@ -139,10 +139,10 @@ namespace GameRes.Formats.NeXAS
|
||||
bool success = false;
|
||||
try
|
||||
{
|
||||
success = ReadV0();
|
||||
success = ReadV0 ();
|
||||
}
|
||||
catch { /* ignore parse errors */ }
|
||||
if (!success && !ReadV1())
|
||||
if (!success && !ReadV1 ())
|
||||
return null;
|
||||
return m_dir;
|
||||
}
|
||||
@@ -165,7 +165,7 @@ namespace GameRes.Formats.NeXAS
|
||||
|
||||
bool ReadV0 ()
|
||||
{
|
||||
using (var input = m_file.CreateStream())
|
||||
using (var input = m_file.CreateStream ())
|
||||
{
|
||||
input.Position = 0xC;
|
||||
if (ReadFromStream (input, 0x20))
|
||||
@@ -177,16 +177,16 @@ namespace GameRes.Formats.NeXAS
|
||||
|
||||
bool ReadFromStream (IBinaryStream index, int name_length)
|
||||
{
|
||||
m_dir.Clear();
|
||||
m_dir.Clear ();
|
||||
for (int i = 0; i < m_count; ++i)
|
||||
{
|
||||
var name = index.ReadCString (name_length, m_encoding);
|
||||
if (string.IsNullOrWhiteSpace (name))
|
||||
return false;
|
||||
var entry = FormatCatalog.Instance.Create<PackedEntry> (name);
|
||||
entry.Offset = index.ReadUInt32();
|
||||
entry.UnpackedSize = index.ReadUInt32();
|
||||
entry.Size = index.ReadUInt32();
|
||||
entry.Offset = index.ReadUInt32 ();
|
||||
entry.UnpackedSize = index.ReadUInt32 ();
|
||||
entry.Size = index.ReadUInt32 ();
|
||||
if (!entry.CheckPlacement (m_file.MaxOffset))
|
||||
return false;
|
||||
switch (m_pack_type)
|
||||
@@ -212,14 +212,14 @@ namespace GameRes.Formats.NeXAS
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class OldIndexReader : INexasIndexReader
|
||||
internal sealed class IndexReaderV0 : INexasIndexReader
|
||||
{
|
||||
ArcView m_file;
|
||||
uint m_header_size;
|
||||
readonly ArcView m_file;
|
||||
readonly uint m_header_size;
|
||||
|
||||
public Compression PackType { get { return Compression.NeedDecryptionOnly; } }
|
||||
|
||||
public OldIndexReader (ArcView file)
|
||||
public IndexReaderV0 (ArcView file)
|
||||
{
|
||||
m_file = file;
|
||||
m_header_size = file.View.ReadUInt32 (3);
|
||||
@@ -230,25 +230,25 @@ namespace GameRes.Formats.NeXAS
|
||||
public List<Entry> Read ()
|
||||
{
|
||||
m_dir = new List<Entry> ();
|
||||
using (var input = m_file.CreateStream())
|
||||
using (var input = m_file.CreateStream ())
|
||||
{
|
||||
input.Position = 7;
|
||||
while (input.Position < m_header_size)
|
||||
{
|
||||
byte c;
|
||||
List<byte> name_buffer = new List<byte>();
|
||||
List<byte> name_buffer = new List<byte> ();
|
||||
while (true)
|
||||
{
|
||||
c = (byte)input.ReadByte();
|
||||
c = (byte)input.ReadByte ();
|
||||
if (c == 0) break;
|
||||
name_buffer.Add ((byte)~c);
|
||||
}
|
||||
var name = Binary.GetCString (name_buffer.ToArray(), 0);
|
||||
var name = Binary.GetCString (name_buffer.ToArray (), 0);
|
||||
if (string.IsNullOrWhiteSpace (name))
|
||||
return null;
|
||||
var entry = FormatCatalog.Instance.Create<Entry> (name);
|
||||
entry.Offset = input.ReadUInt32() + m_header_size;
|
||||
entry.Size = input.ReadUInt32();
|
||||
entry.Offset = input.ReadUInt32 () + m_header_size;
|
||||
entry.Size = input.ReadUInt32 ();
|
||||
if (!entry.CheckPlacement (m_file.MaxOffset))
|
||||
return null;
|
||||
m_dir.Add (entry);
|
||||
@@ -314,7 +314,7 @@ namespace GameRes.Formats.NeXAS
|
||||
{
|
||||
var dst = new byte[unpacked_size];
|
||||
var decoder = new HuffmanDecoder (packed, dst);
|
||||
return decoder.Unpack();
|
||||
return decoder.Unpack ();
|
||||
}
|
||||
|
||||
static private byte[] ZstdDecompress (Stream s, uint unpackedSize)
|
||||
|
||||
Reference in New Issue
Block a user