mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-27 07:34:00 +08:00
[Nexas]UTF-8 & Zstd Support
This commit is contained in:
parent
d4f7fa2eed
commit
08e5a28058
@ -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,13 @@ 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')" />
|
||||||
|
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||||
|
<PropertyGroup>
|
||||||
|
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Error Condition="!Exists('..\packages\ZstdNet.1.4.5\build\ZstdNet.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\ZstdNet.1.4.5\build\ZstdNet.targets'))" />
|
||||||
|
</Target>
|
||||||
<!-- 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">
|
||||||
|
@ -32,6 +32,7 @@ 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
|
||||||
{
|
{
|
||||||
@ -42,6 +43,10 @@ namespace GameRes.Formats.NeXAS
|
|||||||
Huffman,
|
Huffman,
|
||||||
Deflate,
|
Deflate,
|
||||||
DeflateOrNone,
|
DeflateOrNone,
|
||||||
|
|
||||||
|
None2,
|
||||||
|
Zstd,
|
||||||
|
ZstdOrNone,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PacArchive : ArcFile
|
public class PacArchive : ArcFile
|
||||||
@ -67,13 +72,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 +96,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 +161,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 +170,27 @@ 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);
|
|
||||||
|
bool isPacked = false;
|
||||||
|
switch (m_pack_type)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
case 3:
|
||||||
|
case 6:
|
||||||
|
{
|
||||||
|
isPacked = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 4:
|
||||||
|
case 7:
|
||||||
|
{
|
||||||
|
isPacked = entry.Size != entry.UnpackedSize;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
entry.IsPacked = isPacked;
|
||||||
|
|
||||||
m_dir.Add (entry);
|
m_dir.Add (entry);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -188,9 +218,19 @@ 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:
|
||||||
|
{
|
||||||
|
byte[] unpacked = ZstdDecompress(input, pent.UnpackedSize);
|
||||||
|
return new BinMemoryStream(unpacked, entry.Name);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static private byte[] HuffmanDecode (byte[] packed, int unpacked_size)
|
static private byte[] HuffmanDecode (byte[] packed, int unpacked_size)
|
||||||
@ -199,5 +239,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(DecompressionStream zstdDecStream = new DecompressionStream(s))
|
||||||
|
{
|
||||||
|
byte[] dest = new byte[unpackedSize];
|
||||||
|
zstdDecStream.Read(dest, 0, dest.Length);
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
22
ArcFormats/Properties/Settings.Designer.cs
generated
22
ArcFormats/Properties/Settings.Designer.cs
generated
@ -1,10 +1,10 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
// This code was generated by a tool.
|
// 此代码由工具生成。
|
||||||
// Runtime Version:4.0.30319.42000
|
// 运行时版本:4.0.30319.42000
|
||||||
//
|
//
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||||
// the code is regenerated.
|
// 重新生成代码,这些更改将会丢失。
|
||||||
// </auto-generated>
|
// </auto-generated>
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ namespace GameRes.Formats.Properties {
|
|||||||
|
|
||||||
|
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.10.0.0")]
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.6.0.0")]
|
||||||
public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||||
|
|
||||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||||
@ -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="net461" />
|
||||||
<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" />
|
||||||
|
<package id="ZstdNet" version="1.4.5" targetFramework="net461" />
|
||||||
</packages>
|
</packages>
|
Loading…
Reference in New Issue
Block a user