2015-10-19 13:08:56 +08:00
|
|
|
//! \file ArcHG3.cs
|
|
|
|
//! \date Mon Oct 12 22:34:11 2015
|
|
|
|
//! \brief CatSystem2 image resource.
|
|
|
|
//
|
|
|
|
// 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.Collections.Generic;
|
|
|
|
using System.ComponentModel.Composition;
|
|
|
|
using System.IO;
|
|
|
|
using GameRes.Utility;
|
|
|
|
|
|
|
|
namespace GameRes.Formats.CatSystem
|
|
|
|
{
|
|
|
|
[Export(typeof(ArchiveFormat))]
|
|
|
|
public class Hg3Opener : ArchiveFormat
|
|
|
|
{
|
|
|
|
public override string Tag { get { return "HG3"; } }
|
|
|
|
public override string Description { get { return "CatSystem2 engine multi-image"; } }
|
|
|
|
public override uint Signature { get { return 0x332d4748; } } // 'HG-3'
|
|
|
|
public override bool IsHierarchic { get { return false; } }
|
2016-10-11 04:05:22 +08:00
|
|
|
public override bool CanWrite { get { return false; } }
|
2015-10-19 13:08:56 +08:00
|
|
|
|
|
|
|
public override ArcFile TryOpen (ArcView file)
|
|
|
|
{
|
|
|
|
var base_name = Path.GetFileNameWithoutExtension (file.Name);
|
|
|
|
var dir = new List<Entry>();
|
|
|
|
long offset = 0xC;
|
|
|
|
int i = 0;
|
|
|
|
while (offset+0x14 < file.MaxOffset && file.View.AsciiEqual (offset+8, "stdinfo"))
|
|
|
|
{
|
|
|
|
uint section_size = file.View.ReadUInt32 (offset);
|
|
|
|
if (0 == section_size)
|
|
|
|
section_size = (uint)(file.MaxOffset - offset);
|
|
|
|
uint stdinfo_size = file.View.ReadUInt32 (offset+0x10);
|
2018-11-02 10:11:31 +08:00
|
|
|
if (file.View.AsciiEqual (offset+8+stdinfo_size, "img"))
|
2015-10-19 13:08:56 +08:00
|
|
|
{
|
|
|
|
var entry = new Entry
|
|
|
|
{
|
2016-10-26 09:10:30 +08:00
|
|
|
Name = string.Format ("{0}#{1:D4}", base_name, i),
|
2015-10-19 13:08:56 +08:00
|
|
|
Type = "image",
|
|
|
|
Offset = offset + 8,
|
|
|
|
Size = section_size - 8,
|
|
|
|
};
|
|
|
|
dir.Add (entry);
|
|
|
|
}
|
|
|
|
offset += section_size;
|
|
|
|
++i;
|
|
|
|
}
|
2015-11-30 07:50:03 +08:00
|
|
|
if (dir.Count < 1)
|
2015-10-19 13:08:56 +08:00
|
|
|
return null;
|
|
|
|
return new ArcFile (file, this, dir);
|
|
|
|
}
|
|
|
|
|
2016-10-26 09:10:30 +08:00
|
|
|
public override IImageDecoder OpenImage (ArcFile arc, Entry entry)
|
2015-10-19 13:08:56 +08:00
|
|
|
{
|
|
|
|
var offset = entry.Offset+8;
|
2015-11-29 16:27:49 +08:00
|
|
|
var info = new HgMetaData
|
2015-10-19 13:08:56 +08:00
|
|
|
{
|
|
|
|
HeaderSize = arc.File.View.ReadUInt32 (offset),
|
|
|
|
Width = arc.File.View.ReadUInt32 (offset+8),
|
|
|
|
Height = arc.File.View.ReadUInt32 (offset+0xC),
|
|
|
|
BPP = arc.File.View.ReadInt32 (offset+0x10),
|
|
|
|
OffsetX = arc.File.View.ReadInt32 (offset+0x14),
|
|
|
|
OffsetY = arc.File.View.ReadInt32 (offset+0x18),
|
|
|
|
CanvasWidth = arc.File.View.ReadUInt32 (offset+0x1C),
|
|
|
|
CanvasHeight = arc.File.View.ReadUInt32 (offset+0x20),
|
|
|
|
};
|
2016-10-26 09:10:30 +08:00
|
|
|
var input = arc.File.CreateStream (entry.Offset, entry.Size);
|
|
|
|
return new Hg3Reader (input, info);
|
2015-10-19 13:08:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|