mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-08 01:30:18 +08:00
Merge pull request #48 from YeLikesss/master
[Nexas]UTF-8 & Zstd Support
This commit is contained in:
@@ -14,6 +14,8 @@
|
|||||||
<TargetFrameworkProfile />
|
<TargetFrameworkProfile />
|
||||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||||
<RestorePackages>true</RestorePackages>
|
<RestorePackages>true</RestorePackages>
|
||||||
|
<NuGetPackageImportStamp>
|
||||||
|
</NuGetPackageImportStamp>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
@@ -102,6 +104,9 @@
|
|||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
<Reference Include="WindowsBase" />
|
<Reference Include="WindowsBase" />
|
||||||
|
<Reference Include="ZstdNet, Version=1.4.5.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\ZstdNet.1.4.5\lib\net45\ZstdNet.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Abel\ArcARC.cs" />
|
<Compile Include="Abel\ArcARC.cs" />
|
||||||
@@ -1322,6 +1327,7 @@ exit 0</PreBuildEvent>
|
|||||||
<PostBuildEvent>if not exist "$(TargetDir)\GameData" mkdir "$(TargetDir)\GameData"
|
<PostBuildEvent>if not exist "$(TargetDir)\GameData" mkdir "$(TargetDir)\GameData"
|
||||||
xcopy "$(ProjectDir)\Resources\Formats.dat" "$(TargetDir)\GameData\" /D /Y >NUL</PostBuildEvent>
|
xcopy "$(ProjectDir)\Resources\Formats.dat" "$(TargetDir)\GameData\" /D /Y >NUL</PostBuildEvent>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<Import Project="..\packages\ZstdNet.1.4.5\build\ZstdNet.targets" Condition="Exists('..\packages\ZstdNet.1.4.5\build\ZstdNet.targets')" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
<Target Name="BeforeBuild">
|
<Target Name="BeforeBuild">
|
||||||
@@ -1329,4 +1335,4 @@ xcopy "$(ProjectDir)\Resources\Formats.dat" "$(TargetDir)\GameData\" /D /Y >N
|
|||||||
<Target Name="AfterBuild">
|
<Target Name="AfterBuild">
|
||||||
</Target>
|
</Target>
|
||||||
-->
|
-->
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ namespace GameRes.Formats.NeXAS
|
|||||||
Huffman,
|
Huffman,
|
||||||
Deflate,
|
Deflate,
|
||||||
DeflateOrNone,
|
DeflateOrNone,
|
||||||
|
None2,
|
||||||
|
Zstd,
|
||||||
|
ZstdOrNone,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PacArchive : ArcFile
|
public class PacArchive : ArcFile
|
||||||
@@ -67,13 +70,16 @@ namespace GameRes.Formats.NeXAS
|
|||||||
public PacOpener ()
|
public PacOpener ()
|
||||||
{
|
{
|
||||||
Signatures = new uint[] { 0x00434150, 0 };
|
Signatures = new uint[] { 0x00434150, 0 };
|
||||||
|
Settings = new[] { PacEncoding };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
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;
|
||||||
@@ -88,16 +94,18 @@ namespace GameRes.Formats.NeXAS
|
|||||||
ArcView m_file;
|
ArcView m_file;
|
||||||
int m_count;
|
int m_count;
|
||||||
int m_pack_type;
|
int m_pack_type;
|
||||||
|
Encoding m_encoding;
|
||||||
|
|
||||||
const int MaxNameLength = 0x40;
|
const int MaxNameLength = 0x40;
|
||||||
|
|
||||||
public Compression PackType { get { return (Compression)m_pack_type; } }
|
public Compression PackType { get { return (Compression)m_pack_type; } }
|
||||||
|
|
||||||
public IndexReader (ArcView file)
|
public IndexReader (ArcView file, Encoding enc)
|
||||||
{
|
{
|
||||||
m_file = file;
|
m_file = file;
|
||||||
m_count = file.View.ReadInt32 (4);
|
m_count = file.View.ReadInt32 (4);
|
||||||
m_pack_type = file.View.ReadInt32 (8);
|
m_pack_type = file.View.ReadInt32 (8);
|
||||||
|
m_encoding = enc;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Entry> m_dir;
|
List<Entry> m_dir;
|
||||||
@@ -151,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);
|
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);
|
||||||
@@ -160,7 +168,23 @@ 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;
|
||||||
entry.IsPacked = m_pack_type != 0 && (m_pack_type != 4 || entry.Size != entry.UnpackedSize);
|
switch (m_pack_type)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
case 3:
|
||||||
|
case 6:
|
||||||
|
{
|
||||||
|
entry.IsPacked = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 4:
|
||||||
|
case 7:
|
||||||
|
{
|
||||||
|
entry.IsPacked = entry.Size != entry.UnpackedSize;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
m_dir.Add (entry);
|
m_dir.Add (entry);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -188,8 +212,16 @@ namespace GameRes.Formats.NeXAS
|
|||||||
return new BinMemoryStream (unpacked, 0, (int)pent.UnpackedSize, entry.Name);
|
return new BinMemoryStream (unpacked, 0, (int)pent.UnpackedSize, entry.Name);
|
||||||
}
|
}
|
||||||
case Compression.Deflate:
|
case Compression.Deflate:
|
||||||
default:
|
case Compression.DeflateOrNone:
|
||||||
return new ZLibStream (input, CompressionMode.Decompress);
|
return new ZLibStream (input, CompressionMode.Decompress);
|
||||||
|
case Compression.Zstd:
|
||||||
|
case Compression.ZstdOrNone:
|
||||||
|
{
|
||||||
|
var unpacked = ZstdDecompress (input, pent.UnpackedSize);
|
||||||
|
return new BinMemoryStream (unpacked, entry.Name);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return input;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,5 +231,15 @@ namespace GameRes.Formats.NeXAS
|
|||||||
var decoder = new HuffmanDecoder (packed, dst);
|
var decoder = new HuffmanDecoder (packed, dst);
|
||||||
return decoder.Unpack();
|
return decoder.Unpack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static private byte[] ZstdDecompress (Stream s, uint unpackedSize)
|
||||||
|
{
|
||||||
|
using (var ds = new ZstdNet.DecompressionStream (s))
|
||||||
|
{
|
||||||
|
var dst = new byte[unpackedSize];
|
||||||
|
ds.Read (dst, 0, dst.Length);
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
ArcFormats/Properties/Settings.Designer.cs
generated
12
ArcFormats/Properties/Settings.Designer.cs
generated
@@ -825,5 +825,17 @@ namespace GameRes.Formats.Properties {
|
|||||||
this["DXAPassword"] = value;
|
this["DXAPassword"] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
|
[global::System.Configuration.DefaultSettingValueAttribute("932")]
|
||||||
|
public int NexasEncodingCP {
|
||||||
|
get {
|
||||||
|
return ((int)(this["NexasEncodingCP"]));
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
this["NexasEncodingCP"] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -203,5 +203,8 @@
|
|||||||
<Setting Name="DXAPassword" Type="System.String" Scope="User">
|
<Setting Name="DXAPassword" Type="System.String" Scope="User">
|
||||||
<Value Profile="(Default)">DXARC</Value>
|
<Value Profile="(Default)">DXARC</Value>
|
||||||
</Setting>
|
</Setting>
|
||||||
|
<Setting Name="NexasEncodingCP" Type="System.Int32" Scope="User">
|
||||||
|
<Value Profile="(Default)">932</Value>
|
||||||
|
</Setting>
|
||||||
</Settings>
|
</Settings>
|
||||||
</SettingsFile>
|
</SettingsFile>
|
||||||
@@ -205,6 +205,9 @@
|
|||||||
<setting name="DXAPassword" serializeAs="String">
|
<setting name="DXAPassword" serializeAs="String">
|
||||||
<value>DXARC</value>
|
<value>DXARC</value>
|
||||||
</setting>
|
</setting>
|
||||||
|
<setting name="NexasEncodingCP" serializeAs="String">
|
||||||
|
<value>932</value>
|
||||||
|
</setting>
|
||||||
</GameRes.Formats.Properties.Settings>
|
</GameRes.Formats.Properties.Settings>
|
||||||
</userSettings>
|
</userSettings>
|
||||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /></startup>
|
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /></startup>
|
||||||
|
|||||||
@@ -6,8 +6,10 @@
|
|||||||
<package id="System.IO.FileSystem" version="4.3.0" targetFramework="net46" />
|
<package id="System.IO.FileSystem" version="4.3.0" targetFramework="net46" />
|
||||||
<package id="System.IO.FileSystem.Primitives" version="4.3.0" targetFramework="net46" />
|
<package id="System.IO.FileSystem.Primitives" version="4.3.0" targetFramework="net46" />
|
||||||
<package id="System.Memory" version="4.5.4" targetFramework="net46" />
|
<package id="System.Memory" version="4.5.4" targetFramework="net46" />
|
||||||
|
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net46" />
|
||||||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.6.0" targetFramework="net46" />
|
<package id="System.Runtime.CompilerServices.Unsafe" version="4.6.0" targetFramework="net46" />
|
||||||
<package id="System.Security.Cryptography.Algorithms" version="4.3.1" targetFramework="net46" />
|
<package id="System.Security.Cryptography.Algorithms" version="4.3.1" targetFramework="net46" />
|
||||||
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net46" />
|
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net46" />
|
||||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net46" />
|
<package id="System.ValueTuple" version="4.5.0" targetFramework="net46" />
|
||||||
</packages>
|
<package id="ZstdNet" version="1.4.5" targetFramework="net46" />
|
||||||
|
</packages>
|
||||||
|
|||||||
Reference in New Issue
Block a user