mirror of
https://github.com/crskycode/GARbro.git
synced 2026-06-06 13:48:57 +08:00
Add support for SAS5 .gar archive
This commit is contained in:
@@ -776,6 +776,7 @@
|
||||
<Compile Include="Qlie\WidgetQLIE.xaml.cs">
|
||||
<DependentUpon>WidgetQLIE.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Sas5\ArcGAR.cs" />
|
||||
<Compile Include="Sas5\ArcIAR.cs" />
|
||||
<Compile Include="Sas5\ArcSec5.cs" />
|
||||
<Compile Include="Sas5\ArcWAR.cs" />
|
||||
|
||||
112
ArcFormats/Sas5/ArcGAR.cs
Normal file
112
ArcFormats/Sas5/ArcGAR.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
//! \file ArcGAR.cs
|
||||
//! \date 2025 Nov 24
|
||||
//! \brief Sas5 engine video archive.
|
||||
//
|
||||
// Copyright (C) 2015 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.Sas5
|
||||
{
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class GarOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "GAR/SAS5"; } }
|
||||
public override string Description { get { return "SAS5 engine video archive"; } }
|
||||
public override uint Signature { get { return 0x20524147; } } // 'GAR '
|
||||
public override bool IsHierarchic { get { return false; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
public GarOpener ()
|
||||
{
|
||||
Extensions = new string[] { "gar" };
|
||||
}
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
int version = file.View.ReadInt32 (4);
|
||||
if (version != 1)
|
||||
return null;
|
||||
|
||||
uint index_offset = file.View.ReadUInt32 (8);
|
||||
int block_start = file.View.ReadInt32 (0x14);
|
||||
int count = file.View.ReadInt32 (index_offset) - 1;
|
||||
if (!IsSaneCount (count))
|
||||
return null;
|
||||
var GetEntryName = CreateEntryNameDelegate (file.Name);
|
||||
|
||||
index_offset += 0x20;
|
||||
int real_count = 0;
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
int block = file.View.ReadInt32 (index_offset + i * 0x14);
|
||||
real_count += Convert.ToInt32 (block != block_start);
|
||||
}
|
||||
|
||||
var dir = new List<Entry> (real_count);
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
int block = file.View.ReadInt32 (index_offset);
|
||||
if (block == block_start)
|
||||
continue;
|
||||
var entry = new Entry {
|
||||
Name = GetEntryName (i),
|
||||
Offset = file.View.ReadUInt32 (index_offset + 4),
|
||||
Size = file.View.ReadUInt32 (index_offset + 12),
|
||||
};
|
||||
if (!entry.CheckPlacement (file.MaxOffset))
|
||||
return null;
|
||||
if (block > block_start)
|
||||
{
|
||||
entry.Type = "video";
|
||||
}
|
||||
dir.Add (entry);
|
||||
index_offset += 0x14;
|
||||
}
|
||||
return new ArcFile (file, this, dir);
|
||||
}
|
||||
|
||||
internal Func<int, string> CreateEntryNameDelegate (string arc_name)
|
||||
{
|
||||
var index = Sec5Opener.LookupIndex (arc_name);
|
||||
string base_name = Path.GetFileNameWithoutExtension (arc_name);
|
||||
if (null == index)
|
||||
return n => GetDefaultName (base_name, n);
|
||||
else
|
||||
return (n) => {
|
||||
Entry entry;
|
||||
if (index.TryGetValue (n, out entry))
|
||||
return entry.Name;
|
||||
return GetDefaultName (base_name, n);
|
||||
};
|
||||
}
|
||||
|
||||
internal static string GetDefaultName (string base_name, int n)
|
||||
{
|
||||
return string.Format ("{0}#{1:D5}", base_name, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -548,6 +548,9 @@
|
||||
<data name="Type_audio" xml:space="preserve">
|
||||
<value>音频</value>
|
||||
</data>
|
||||
<data name="Type_video" xml:space="preserve">
|
||||
<value>视频</value>
|
||||
</data>
|
||||
<data name="Type_image" xml:space="preserve">
|
||||
<value>图像</value>
|
||||
</data>
|
||||
|
||||
Reference in New Issue
Block a user