mirror of
https://github.com/crskycode/GARbro.git
synced 2026-06-06 05:38:48 +08:00
feat: add DAT/TIMELEAP format
Incompatible with trial edition, because that the archive in it is not encrypted. The encryption was added in test edition.
This commit is contained in:
@@ -284,6 +284,7 @@
|
||||
<Compile Include="FC01\ImageTIL.cs" />
|
||||
<Compile Include="FC01\ImageWM2.cs" />
|
||||
<Compile Include="FC01\ImageWMK.cs" />
|
||||
<Compile Include="FrontWing\ArcDAT.cs" />
|
||||
<Compile Include="FrontWing\ArcFG.cs" />
|
||||
<Compile Include="FrontWing\ArcFLT.cs" />
|
||||
<Compile Include="FrontWing\ArcVAV.cs" />
|
||||
|
||||
104
ArcFormats/FrontWing/ArcDAT.cs
Normal file
104
ArcFormats/FrontWing/ArcDAT.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
//! \file ArcDAT.cs
|
||||
//! \date 2025-12-13
|
||||
//! \brief FrontWing resource archive.
|
||||
//
|
||||
// Copyright (C) 2018 by morkt
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using GameRes.Utility;
|
||||
|
||||
namespace GameRes.Formats.FrontWing
|
||||
{
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class DatOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "DAT/TIMELEAP"; } }
|
||||
public override string Description { get { return "'Time Leap' resource archive"; } }
|
||||
public override uint Signature { get { return 0; } }
|
||||
public override bool IsHierarchic { get { return false; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
if (file.MaxOffset < 4)
|
||||
return null;
|
||||
int count = file.View.ReadInt32 (file.MaxOffset - 4);
|
||||
if (!IsSaneCount (count))
|
||||
return null;
|
||||
|
||||
int index_size = 0x50 * count;
|
||||
if (file.MaxOffset < index_size + 4)
|
||||
return null;
|
||||
var index = file.View.ReadBytes (file.MaxOffset - 4 - index_size, (uint)index_size);
|
||||
NibbleSwap (index);
|
||||
|
||||
int index_offset = 0;
|
||||
var dir = new List<Entry> (count);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var name = Binary.GetCString (index, index_offset, 0x40);
|
||||
var entry = Create<Entry> (name);
|
||||
entry.Offset = LittleEndian.ToUInt32 (index, index_offset + 0x40);
|
||||
entry.Size = LittleEndian.ToUInt32 (index, index_offset + 0x48);
|
||||
if (!entry.CheckPlacement (file.MaxOffset))
|
||||
return null;
|
||||
index_offset += 0x50;
|
||||
dir.Add (entry);
|
||||
}
|
||||
return new ArcFile (file, this, dir);
|
||||
}
|
||||
|
||||
static readonly byte[] keyTable = {
|
||||
0xff, 0xff, 0xff, 0x01,
|
||||
0x9c, 0xaa, 0xa5, 0x00,
|
||||
0x30, 0xff, 0x77, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
public override Stream OpenEntry (ArcFile arc, Entry entry)
|
||||
{
|
||||
var data = arc.File.View.ReadBytes (entry.Offset, entry.Size);
|
||||
for (int i = 1; i < data.Length; i += 4)
|
||||
{
|
||||
data[i] = (byte)(-data[i] & 0xff);
|
||||
}
|
||||
for (int i = 0; i < data.Length; i += 3)
|
||||
{
|
||||
data[i] ^= keyTable[i / 5 % 5 + i % 6];
|
||||
}
|
||||
NibbleSwap(data, 2, 6);
|
||||
return new BinMemoryStream (data);
|
||||
}
|
||||
|
||||
void NibbleSwap (byte[] buffer, int start = 0, int step = 1)
|
||||
{
|
||||
for (int i = start; i < buffer.Length; i += step)
|
||||
{
|
||||
buffer[i] = (byte)(((buffer[i] & 0xf0) >> 4) + ((buffer[i] & 0xf) << 4));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user