mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-27 21:34:14 +08:00
(Legacy): Tigerman Project resource formats.
This commit is contained in:
parent
8f4dd8a38d
commit
ed9dd06c4c
79
Legacy/Tigerman/ArcCHR.cs
Normal file
79
Legacy/Tigerman/ArcCHR.cs
Normal file
@ -0,0 +1,79 @@
|
||||
//! \file ArcCHR.cs
|
||||
//! \date 2018 Apr 10
|
||||
//! \brief Tigerman Project compound image.
|
||||
//
|
||||
// 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;
|
||||
|
||||
namespace GameRes.Formats.Tigerman
|
||||
{
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class ChrOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "CHR/TIGERMAN"; } }
|
||||
public override string Description { get { return "Tigerman Project compound image"; } }
|
||||
public override uint Signature { get { return 0; } }
|
||||
public override bool IsHierarchic { get { return false; } }
|
||||
public override bool CanWrite { get { return false; } }
|
||||
|
||||
public ChrOpener ()
|
||||
{
|
||||
Extensions = new string[] { "chr", "cls", "ev" };
|
||||
Signatures = new uint[] { 0x01B1, 0 };
|
||||
}
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
uint base_offset = file.View.ReadUInt32 (0);
|
||||
if (base_offset >= file.MaxOffset || !file.View.AsciiEqual (base_offset, "ZT"))
|
||||
return null;
|
||||
var base_name = Path.GetFileNameWithoutExtension (file.Name);
|
||||
var dir = new List<Entry>();
|
||||
Func<int, uint, uint, Entry> create_entry = (i, offset, size) => new Entry {
|
||||
Name = string.Format ("{0}#{1}.ZIT", base_name, i),
|
||||
Type = "image",
|
||||
Offset = offset,
|
||||
Size = size,
|
||||
};
|
||||
dir.Add (create_entry (0, base_offset, file.View.ReadUInt32 (4)));
|
||||
uint index_offset = 12;
|
||||
while (index_offset + 0x24 <= base_offset)
|
||||
{
|
||||
uint offset = file.View.ReadUInt32 (index_offset);
|
||||
if (offset != 0)
|
||||
{
|
||||
uint size = file.View.ReadUInt32 (index_offset+4);
|
||||
var entry = create_entry (dir.Count, offset, size);
|
||||
if (!entry.CheckPlacement (file.MaxOffset))
|
||||
return null;
|
||||
dir.Add (entry);
|
||||
}
|
||||
index_offset += 0x24;
|
||||
}
|
||||
return new ArcFile (file, this, dir);
|
||||
}
|
||||
}
|
||||
}
|
69
Legacy/Tigerman/ArcPAC.cs
Normal file
69
Legacy/Tigerman/ArcPAC.cs
Normal file
@ -0,0 +1,69 @@
|
||||
//! \file ArcPAC.cs
|
||||
//! \date 2018 Apr 10
|
||||
//! \brief Tigerman Project 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;
|
||||
|
||||
// [020927][Tigerman Project] Hotaruko
|
||||
|
||||
namespace GameRes.Formats.Tigerman
|
||||
{
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class PacOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "PAC/TIGERMAN"; } }
|
||||
public override string Description { get { return "Tigerman Project 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.View.ReadInt32 (0) != 0)
|
||||
return null;
|
||||
int count = file.View.ReadInt32 (4);
|
||||
if (!IsSaneCount (count))
|
||||
return null;
|
||||
|
||||
uint index_offset = 0x14;
|
||||
long base_offset = index_offset + count * 0x18;
|
||||
var dir = new List<Entry> (count);
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
var name = file.View.ReadString (index_offset, 0x10);
|
||||
var entry = FormatCatalog.Instance.Create<Entry> (name);
|
||||
entry.Offset = file.View.ReadUInt32 (index_offset+0x10) + base_offset;
|
||||
entry.Size = file.View.ReadUInt32 (index_offset+0x14);
|
||||
if (!entry.CheckPlacement (file.MaxOffset))
|
||||
return null;
|
||||
dir.Add (entry);
|
||||
index_offset += 0x18;
|
||||
}
|
||||
return new ArcFile (file, this, dir);
|
||||
}
|
||||
}
|
||||
}
|
100
Legacy/Tigerman/ImageCHR.cs
Normal file
100
Legacy/Tigerman/ImageCHR.cs
Normal file
@ -0,0 +1,100 @@
|
||||
//! \file ImageCHR.cs
|
||||
//! \date 2018 Apr 10
|
||||
//! \brief Tigerman Project compound image.
|
||||
//
|
||||
// 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.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace GameRes.Formats.Tigerman
|
||||
{
|
||||
internal class ChrMetaData : ImageMetaData
|
||||
{
|
||||
public uint Offset;
|
||||
public uint Length;
|
||||
public ImageMetaData ZitInfo;
|
||||
}
|
||||
|
||||
[Export(typeof(ImageFormat))]
|
||||
public class ChrFormat : ImageFormat
|
||||
{
|
||||
public override string Tag { get { return "CHR/TIGERMAN"; } }
|
||||
public override string Description { get { return "Tigerman Project compound image"; } }
|
||||
public override uint Signature { get { return 0; } }
|
||||
|
||||
public ChrFormat ()
|
||||
{
|
||||
Extensions = new string[] { "chr", "cls", "ev" };
|
||||
Signatures = new uint[] { 0x01B1, 0 };
|
||||
}
|
||||
|
||||
static readonly ResourceInstance<ImageFormat> s_zit_format = new ResourceInstance<ImageFormat> ("ZIT");
|
||||
|
||||
public override ImageMetaData ReadMetaData (IBinaryStream file)
|
||||
{
|
||||
uint base_offset = file.ReadUInt32();
|
||||
if (base_offset >= file.Length)
|
||||
return null;
|
||||
uint base_length = file.ReadUInt32();
|
||||
if (base_offset + base_length > file.Length)
|
||||
return null;
|
||||
file.Position = base_offset;
|
||||
uint signature = file.ReadUInt32();
|
||||
if (!s_zit_format.Value.Signatures.Contains (signature))
|
||||
return null;
|
||||
using (var zit = OpenZitStream (file, base_offset, base_length))
|
||||
{
|
||||
var info = s_zit_format.Value.ReadMetaData (zit);
|
||||
if (null == info)
|
||||
return null;
|
||||
return new ChrMetaData {
|
||||
Width = info.Width,
|
||||
Height = info.Height,
|
||||
BPP = info.BPP,
|
||||
Offset = base_offset,
|
||||
Length = base_length,
|
||||
ZitInfo = info,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override ImageData Read (IBinaryStream file, ImageMetaData info)
|
||||
{
|
||||
var meta = (ChrMetaData)info;
|
||||
using (var zit = OpenZitStream (file, meta.Offset, meta.Length))
|
||||
return s_zit_format.Value.Read (zit, meta.ZitInfo);
|
||||
}
|
||||
|
||||
IBinaryStream OpenZitStream (IBinaryStream file, uint offset, uint size)
|
||||
{
|
||||
var input = new StreamRegion (file.AsStream, offset, size, true);
|
||||
return new BinaryStream (input, file.Name);
|
||||
}
|
||||
|
||||
public override void Write (Stream file, ImageData image)
|
||||
{
|
||||
throw new System.NotImplementedException ("ChrFormat.Write not implemented");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user