From 2e8057aa54f4adc46ba23d3d52398b9a638d25b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20=C5=9Apiewak?= Date: Mon, 15 Jul 2024 14:15:14 +0200 Subject: [PATCH] Update ArcDX8.cs Add anything that can be done without user input. --- ArcFormats/DxLib/ArcDX8.cs | 49 +++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/ArcFormats/DxLib/ArcDX8.cs b/ArcFormats/DxLib/ArcDX8.cs index edc05b80..1a009819 100644 --- a/ArcFormats/DxLib/ArcDX8.cs +++ b/ArcFormats/DxLib/ArcDX8.cs @@ -41,27 +41,64 @@ namespace GameRes.Formats.DxLib public Dx8Opener () { - Extensions = new[] { "bin" }; + Extensions = new string[] { "dxa", "hud", "usi", "med", "dat", "bin", "bcx", "wolf" }; Signatures = new[] { 0x00085844u }; } static readonly byte[] DefaultKey = new byte[] { 0xBE, 0xC8, 0x8A, 0xF5, 0x28, 0x50, 0xC9 }; + + DxScheme DefaultScheme = new DxScheme { KnownKeys = new List() }; + + + internal struct DxHeaderV8 + { + public long BaseOffset; + public long IndexOffset; + public uint IndexSize; + public long FileTable; + public long DirTable; + public int CodePage; + public DXA8Flags Flags; + public byte HuffmanKB; + //15 bytes of padding. + } + + internal enum DXA8Flags : UInt32 + { + DXA_FLAG_NO_KEY=1, //file is not encrypted + DXA_FLAG_NO_HEAD_PRESS=1<<1, //do not compress headers + } + public override ArcFile TryOpen (ArcView file) { - var dx = new DxHeader { + var dx = new DxHeaderV8 { IndexSize = file.View.ReadUInt32 (4), BaseOffset = file.View.ReadInt64 (8), IndexOffset = file.View.ReadInt64 (0x10), - FileTable = (uint)file.View.ReadInt64 (0x18), - DirTable = (uint)file.View.ReadInt64 (0x20), + FileTable = file.View.ReadInt64 (0x18), + DirTable = file.View.ReadInt64 (0x20), CodePage = file.View.ReadInt32 (0x28), + Flags = (DXA8Flags)file.View.ReadUInt32(0x2C), + HuffmanKB = file.View.ReadByte(0x30) }; if (dx.DirTable >= dx.IndexSize || dx.FileTable >= dx.IndexSize) return null; + //at this point we cannot proceed without user input. If NO_HEAD_PRESS is set we could maybe restore the 7-byte key + //Otherwise (assuming the archive is encrypted) we have no way to continue without user input. + + //TODO: Ask for key here. + var key = DefaultKey; - var index = file.View.ReadBytes (dx.IndexOffset, dx.IndexSize); - Decrypt (index, 0, index.Length, 0, key); + if ((dx.Flags & DXA8Flags.DXA_FLAG_NO_HEAD_PRESS) != 0) + { + var index = file.View.ReadBytes(dx.IndexOffset, dx.IndexSize); + Decrypt(index, 0, index.Length, 0, key); + } else + { + //input is compressed. First by huffman then by LZ. if it's also encrypted then we're stuck. + throw new NotImplementedException(); + } // decrypt-2 // decompress return null;