Update ArcPAC.cs

This commit is contained in:
Crsky
2024-09-15 02:11:39 +08:00
committed by GitHub
parent afd4d5f7fa
commit ba065f76af

View File

@@ -32,7 +32,6 @@ using System.ComponentModel.Composition;
using GameRes.Compression; using GameRes.Compression;
using GameRes.Formats.Strings; using GameRes.Formats.Strings;
using GameRes.Utility; using GameRes.Utility;
using ZstdNet;
namespace GameRes.Formats.NeXAS namespace GameRes.Formats.NeXAS
{ {
@@ -43,7 +42,6 @@ namespace GameRes.Formats.NeXAS
Huffman, Huffman,
Deflate, Deflate,
DeflateOrNone, DeflateOrNone,
None2, None2,
Zstd, Zstd,
ZstdOrNone, ZstdOrNone,
@@ -75,13 +73,13 @@ namespace GameRes.Formats.NeXAS
Settings = new[] { PacEncoding }; Settings = new[] { PacEncoding };
} }
EncodingSetting PacEncoding = new EncodingSetting("NexasEncodingCP", "DefaultEncoding"); EncodingSetting PacEncoding = new EncodingSetting ("NexasEncodingCP", "DefaultEncoding");
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
{ {
if (!file.View.AsciiEqual (0, "PAC") || 'K' == file.View.ReadByte (3)) if (!file.View.AsciiEqual (0, "PAC") || 'K' == file.View.ReadByte (3))
return null; return null;
var reader = new IndexReader(file, PacEncoding.Get<Encoding>()); var reader = new IndexReader (file, PacEncoding.Get<Encoding>());
var dir = reader.Read(); var dir = reader.Read();
if (null == dir) if (null == dir)
return null; return null;
@@ -161,7 +159,7 @@ namespace GameRes.Formats.NeXAS
m_dir.Clear(); m_dir.Clear();
for (int i = 0; i < m_count; ++i) for (int i = 0; i < m_count; ++i)
{ {
var name = index.ReadCString(name_length, m_encoding); var name = index.ReadCString (name_length, m_encoding);
if (string.IsNullOrWhiteSpace (name)) if (string.IsNullOrWhiteSpace (name))
return false; return false;
var entry = FormatCatalog.Instance.Create<PackedEntry> (name); var entry = FormatCatalog.Instance.Create<PackedEntry> (name);
@@ -170,7 +168,6 @@ namespace GameRes.Formats.NeXAS
entry.Size = index.ReadUInt32(); entry.Size = index.ReadUInt32();
if (!entry.CheckPlacement (m_file.MaxOffset)) if (!entry.CheckPlacement (m_file.MaxOffset))
return false; return false;
bool isPacked = false; bool isPacked = false;
switch (m_pack_type) switch (m_pack_type)
{ {
@@ -219,17 +216,15 @@ namespace GameRes.Formats.NeXAS
} }
case Compression.Deflate: case Compression.Deflate:
case Compression.DeflateOrNone: case Compression.DeflateOrNone:
{ return new ZLibStream (input, CompressionMode.Decompress);
return new ZLibStream(input, CompressionMode.Decompress);
}
case Compression.Zstd: case Compression.Zstd:
case Compression.ZstdOrNone: case Compression.ZstdOrNone:
{ {
byte[] unpacked = ZstdDecompress(input, pent.UnpackedSize); var unpacked = ZstdDecompress (input, pent.UnpackedSize);
return new BinMemoryStream(unpacked, entry.Name); return new BinMemoryStream (unpacked, entry.Name);
} }
default: default:
throw new NotImplementedException(); return input;
} }
} }
@@ -240,13 +235,13 @@ namespace GameRes.Formats.NeXAS
return decoder.Unpack(); return decoder.Unpack();
} }
static private byte[] ZstdDecompress(Stream s, uint unpackedSize) static private byte[] ZstdDecompress (Stream s, uint unpackedSize)
{ {
using(DecompressionStream zstdDecStream = new DecompressionStream(s)) using (var ds = new ZstdNet.DecompressionStream (s))
{ {
byte[] dest = new byte[unpackedSize]; var dst = new byte[unpackedSize];
zstdDecStream.Read(dest, 0, dest.Length); ds.Read (dst, 0, dst.Length);
return dest; return dst;
} }
} }
} }