mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-23 19:34:15 +08:00
[Nexas]UTF-8 & Zstd Support
This commit is contained in:
parent
d4f7fa2eed
commit
08e5a28058
@ -14,6 +14,8 @@
|
||||
<TargetFrameworkProfile />
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||
<RestorePackages>true</RestorePackages>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@ -102,6 +104,9 @@
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<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>
|
||||
<Compile Include="Abel\ArcARC.cs" />
|
||||
@ -1322,6 +1327,13 @@ exit 0</PreBuildEvent>
|
||||
<PostBuildEvent>if not exist "$(TargetDir)\GameData" mkdir "$(TargetDir)\GameData"
|
||||
xcopy "$(ProjectDir)\Resources\Formats.dat" "$(TargetDir)\GameData\" /D /Y >NUL</PostBuildEvent>
|
||||
</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.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
|
@ -32,6 +32,7 @@ using System.ComponentModel.Composition;
|
||||
using GameRes.Compression;
|
||||
using GameRes.Formats.Strings;
|
||||
using GameRes.Utility;
|
||||
using ZstdNet;
|
||||
|
||||
namespace GameRes.Formats.NeXAS
|
||||
{
|
||||
@ -42,6 +43,10 @@ namespace GameRes.Formats.NeXAS
|
||||
Huffman,
|
||||
Deflate,
|
||||
DeflateOrNone,
|
||||
|
||||
None2,
|
||||
Zstd,
|
||||
ZstdOrNone,
|
||||
}
|
||||
|
||||
public class PacArchive : ArcFile
|
||||
@ -67,13 +72,16 @@ namespace GameRes.Formats.NeXAS
|
||||
public PacOpener ()
|
||||
{
|
||||
Signatures = new uint[] { 0x00434150, 0 };
|
||||
Settings = new[] { PacEncoding };
|
||||
}
|
||||
|
||||
EncodingSetting PacEncoding = new EncodingSetting("NexasEncodingCP", "DefaultEncoding");
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
if (!file.View.AsciiEqual (0, "PAC") || 'K' == file.View.ReadByte (3))
|
||||
return null;
|
||||
var reader = new IndexReader (file);
|
||||
var reader = new IndexReader(file, PacEncoding.Get<Encoding>());
|
||||
var dir = reader.Read();
|
||||
if (null == dir)
|
||||
return null;
|
||||
@ -88,16 +96,18 @@ namespace GameRes.Formats.NeXAS
|
||||
ArcView m_file;
|
||||
int m_count;
|
||||
int m_pack_type;
|
||||
Encoding m_encoding;
|
||||
|
||||
const int MaxNameLength = 0x40;
|
||||
|
||||
public Compression PackType { get { return (Compression)m_pack_type; } }
|
||||
|
||||
public IndexReader (ArcView file)
|
||||
public IndexReader (ArcView file, Encoding enc)
|
||||
{
|
||||
m_file = file;
|
||||
m_count = file.View.ReadInt32 (4);
|
||||
m_pack_type = file.View.ReadInt32 (8);
|
||||
m_encoding = enc;
|
||||
}
|
||||
|
||||
List<Entry> m_dir;
|
||||
@ -151,7 +161,7 @@ namespace GameRes.Formats.NeXAS
|
||||
m_dir.Clear();
|
||||
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))
|
||||
return false;
|
||||
var entry = FormatCatalog.Instance.Create<PackedEntry> (name);
|
||||
@ -160,7 +170,27 @@ namespace GameRes.Formats.NeXAS
|
||||
entry.Size = index.ReadUInt32();
|
||||
if (!entry.CheckPlacement (m_file.MaxOffset))
|
||||
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);
|
||||
}
|
||||
return true;
|
||||
@ -188,8 +218,18 @@ namespace GameRes.Formats.NeXAS
|
||||
return new BinMemoryStream (unpacked, 0, (int)pent.UnpackedSize, entry.Name);
|
||||
}
|
||||
case Compression.Deflate:
|
||||
case Compression.DeflateOrNone:
|
||||
{
|
||||
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:
|
||||
return new ZLibStream (input, CompressionMode.Decompress);
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,5 +239,15 @@ namespace GameRes.Formats.NeXAS
|
||||
var decoder = new HuffmanDecoder (packed, dst);
|
||||
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>
|
||||
// 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>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@ -12,7 +12,7 @@ namespace GameRes.Formats.Properties {
|
||||
|
||||
|
||||
[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 {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
@ -825,5 +825,17 @@ namespace GameRes.Formats.Properties {
|
||||
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">
|
||||
<Value Profile="(Default)">DXARC</Value>
|
||||
</Setting>
|
||||
<Setting Name="NexasEncodingCP" Type="System.Int32" Scope="User">
|
||||
<Value Profile="(Default)">932</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
@ -205,6 +205,9 @@
|
||||
<setting name="DXAPassword" serializeAs="String">
|
||||
<value>DXARC</value>
|
||||
</setting>
|
||||
<setting name="NexasEncodingCP" serializeAs="String">
|
||||
<value>932</value>
|
||||
</setting>
|
||||
</GameRes.Formats.Properties.Settings>
|
||||
</userSettings>
|
||||
<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.Primitives" version="4.3.0" 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.Security.Cryptography.Algorithms" version="4.3.1" 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="ZstdNet" version="1.4.5" targetFramework="net461" />
|
||||
</packages>
|
Loading…
x
Reference in New Issue
Block a user