mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-02 11:20:29 +08:00
reorganized project directory structure.
This commit is contained in:
74
ArcFormats/WildBug/ArcWBP.cs
Normal file
74
ArcFormats/WildBug/ArcWBP.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
//! \file ArcWBP.cs
|
||||
//! \date Thu Jul 09 17:02:03 2015
|
||||
//! \brief Wild Bug's resource archive format.
|
||||
//
|
||||
// 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;
|
||||
|
||||
namespace GameRes.Formats.WildBug
|
||||
{
|
||||
[Export(typeof(ArchiveFormat))]
|
||||
public class WbpOpener : ArchiveFormat
|
||||
{
|
||||
public override string Tag { get { return "WBP"; } }
|
||||
public override string Description { get { return "Wild Bug's engine resource archive"; } }
|
||||
public override uint Signature { get { return 0x46435241; } } // 'ARCF'
|
||||
public override bool IsHierarchic { get { return false; } }
|
||||
public override bool CanCreate { get { return false; } }
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
if (!file.View.AsciiEqual (0, "ARCFORM3 WBUG "))
|
||||
return null;
|
||||
int count = file.View.ReadInt32 (0x10);
|
||||
if (!IsSaneCount (count))
|
||||
return null;
|
||||
uint index_offset = file.View.ReadUInt32 (0x14);
|
||||
uint index_size = file.View.ReadUInt32 (0x18);
|
||||
uint data_offset = file.View.ReadUInt32 (0x1C);
|
||||
if (data_offset < index_offset || data_offset > file.MaxOffset)
|
||||
return null;
|
||||
if (index_size > file.View.Reserve (index_offset, index_size))
|
||||
return null;
|
||||
|
||||
var dir = new List<Entry> (count);
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
uint name_length = file.View.ReadByte (index_offset+9);
|
||||
string name = file.View.ReadString (index_offset+0x14, name_length);
|
||||
if (0 == name.Length)
|
||||
return null;
|
||||
var entry = FormatCatalog.Instance.CreateEntry (name);
|
||||
entry.Offset = file.View.ReadUInt32 (index_offset);
|
||||
entry.Size = file.View.ReadUInt32 (index_offset+4);
|
||||
if (!entry.CheckPlacement (file.MaxOffset))
|
||||
return null;
|
||||
dir.Add (entry);
|
||||
index_offset += name_length + 0x14;
|
||||
}
|
||||
return new ArcFile (file, this, dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
79
ArcFormats/WildBug/AudioWPN.cs
Normal file
79
ArcFormats/WildBug/AudioWPN.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
//! \file AudioWPN.cs
|
||||
//! \date Mon Aug 10 09:22:18 2015
|
||||
//! \brief Wild Bug audio format.
|
||||
//
|
||||
// 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.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using GameRes.Utility;
|
||||
|
||||
namespace GameRes.Formats.WildBug
|
||||
{
|
||||
[Export(typeof(AudioFormat))]
|
||||
public class WpnAudio : AudioFormat
|
||||
{
|
||||
public override string Tag { get { return "WPN"; } }
|
||||
public override string Description { get { return "Wild Bug's audio format"; } }
|
||||
public override uint Signature { get { return 0x1A444257; } } // 'WBD'
|
||||
|
||||
public override SoundInput TryOpen (Stream file)
|
||||
{
|
||||
var header = new byte[0x24];
|
||||
if (header.Length != file.Read (header, 0, header.Length))
|
||||
return null;
|
||||
if (!Binary.AsciiEqual (header, 4, "WAV"))
|
||||
return null;
|
||||
if (LittleEndian.ToInt32 (header, 8) < 2)
|
||||
return null;
|
||||
int fmt_offset = LittleEndian.ToInt32 (header, 0x10);
|
||||
int fmt_size = LittleEndian.ToInt32 (header, 0x14);
|
||||
int data_offset = LittleEndian.ToInt32 (header, 0x1C);
|
||||
int data_size = LittleEndian.ToInt32 (header, 0x20);
|
||||
var wav_header = new byte[8+12+fmt_size+8];
|
||||
Buffer.BlockCopy (WavHeader, 0, wav_header, 0, WavHeader.Length);
|
||||
LittleEndian.Pack (wav_header.Length-8+data_size, wav_header, 4);
|
||||
LittleEndian.Pack (fmt_size, wav_header, 0x10);
|
||||
file.Position = fmt_offset;
|
||||
file.Read (wav_header, 0x14, fmt_size);
|
||||
int d = wav_header.Length-8;
|
||||
wav_header[d++]= (byte)'d';
|
||||
wav_header[d++]= (byte)'a';
|
||||
wav_header[d++]= (byte)'t';
|
||||
wav_header[d++]= (byte)'a';
|
||||
LittleEndian.Pack (data_size, wav_header, d);
|
||||
var wav_data = new StreamRegion (file, data_offset, data_size);
|
||||
return new WaveInput (new PrefixStream (wav_header, wav_data));
|
||||
}
|
||||
|
||||
static readonly byte[] WavHeader = new byte[] {
|
||||
(byte)'R', (byte)'I', (byte)'F', (byte)'F', 0, 0, 0, 0,
|
||||
(byte)'W', (byte)'A', (byte)'V', (byte)'E', (byte)'f', (byte)'m', (byte)'t', 0x20,
|
||||
};
|
||||
|
||||
public override void Write (SoundInput source, Stream output)
|
||||
{
|
||||
throw new System.NotImplementedException ("WpnFormat.Write not implemenented");
|
||||
}
|
||||
}
|
||||
}
|
||||
213
ArcFormats/WildBug/AudioWWA.cs
Normal file
213
ArcFormats/WildBug/AudioWWA.cs
Normal file
@@ -0,0 +1,213 @@
|
||||
//! \file AudioWWA.cs
|
||||
//! \date Mon Aug 10 11:48:29 2015
|
||||
//! \brief Wild Bug compressed audio format.
|
||||
//
|
||||
// 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.ComponentModel.Composition;
|
||||
using System.IO;
|
||||
using GameRes.Utility;
|
||||
|
||||
namespace GameRes.Formats.WildBug
|
||||
{
|
||||
[Export(typeof(AudioFormat))]
|
||||
public class WwaAudio : AudioFormat
|
||||
{
|
||||
public override string Tag { get { return "WWA"; } }
|
||||
public override string Description { get { return "Wild Bug's compressed audio format"; } }
|
||||
public override uint Signature { get { return 0x1A585057; } } // 'WPX'
|
||||
|
||||
public override SoundInput TryOpen (Stream file)
|
||||
{
|
||||
var header = new byte[0x10];
|
||||
if (header.Length != file.Read (header, 0, header.Length))
|
||||
return null;
|
||||
if (!Binary.AsciiEqual (header, 4, "WAV"))
|
||||
return null;
|
||||
int count = header[0xE];
|
||||
int dir_size = header[0xF];
|
||||
if (1 != header[0xC] || 0 == count || 0 == dir_size)
|
||||
return null;
|
||||
|
||||
return new WwaInput (file, count, dir_size);
|
||||
}
|
||||
|
||||
public override void Write (SoundInput source, Stream output)
|
||||
{
|
||||
throw new System.NotImplementedException ("WwaFormat.Write not implemenented");
|
||||
}
|
||||
}
|
||||
|
||||
internal class WwaInput : SoundInput
|
||||
{
|
||||
public override string SourceFormat { get { return "raw"; } }
|
||||
|
||||
public override int SourceBitrate
|
||||
{
|
||||
get { return (int)Format.AverageBytesPerSecond * 8; }
|
||||
}
|
||||
|
||||
public WwaInput (Stream file, int count, int dir_size) : base (null)
|
||||
{
|
||||
file.Position = 0x10;
|
||||
var header = new byte[count * dir_size];
|
||||
if (header.Length != file.Read (header, 0, header.Length))
|
||||
throw new InvalidFormatException();
|
||||
|
||||
var section = WpxSection.Find (header, 0x20, count, dir_size);
|
||||
if (null == section || section.UnpackedSize < 0x10 || section.DataFormat != 0x80)
|
||||
throw new InvalidFormatException();
|
||||
file.Position = section.Offset;
|
||||
Format = ReadFormat (file);
|
||||
|
||||
section = WpxSection.Find (header, 0x21, count, dir_size);
|
||||
if (null == section)
|
||||
throw new InvalidFormatException();
|
||||
|
||||
var reader = new WwaReader (file, section);
|
||||
var data = reader.Unpack (section.DataFormat);
|
||||
if (null == data)
|
||||
throw new InvalidFormatException();
|
||||
Source = new MemoryStream (data);
|
||||
file.Dispose();
|
||||
}
|
||||
|
||||
static WaveFormat ReadFormat (Stream file)
|
||||
{
|
||||
var format = new WaveFormat();
|
||||
using (var input = new ArcView.Reader (file))
|
||||
{
|
||||
format.FormatTag = input.ReadUInt16 ();
|
||||
format.Channels = input.ReadUInt16 ();
|
||||
format.SamplesPerSecond = input.ReadUInt32 ();
|
||||
format.AverageBytesPerSecond = input.ReadUInt32 ();
|
||||
format.BlockAlign = input.ReadUInt16 ();
|
||||
format.BitsPerSample = input.ReadUInt16 ();
|
||||
}
|
||||
return format;
|
||||
}
|
||||
|
||||
#region IO.Stream methods
|
||||
public override long Position
|
||||
{
|
||||
get { return Source.Position; }
|
||||
set { Source.Position = value; }
|
||||
}
|
||||
|
||||
public override bool CanSeek { get { return Source.CanSeek; } }
|
||||
|
||||
public override long Seek (long offset, SeekOrigin origin)
|
||||
{
|
||||
return Source.Seek (offset, origin);
|
||||
}
|
||||
|
||||
public override int Read (byte[] buffer, int offset, int count)
|
||||
{
|
||||
return Source.Read (buffer, offset, count);
|
||||
}
|
||||
|
||||
public override int ReadByte ()
|
||||
{
|
||||
return Source.ReadByte();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
internal class WwaReader : WpxDecoder
|
||||
{
|
||||
public WwaReader (Stream input, WpxSection section) : base (input, section)
|
||||
{
|
||||
ResetInput();
|
||||
}
|
||||
|
||||
public byte[] Unpack (int flags) // sub_46B16C
|
||||
{
|
||||
if (0 == (flags & 0x80) && 0 != PackedSize)
|
||||
{
|
||||
if (0 != (flags & 8))
|
||||
{
|
||||
if (0 != (flags & 4))
|
||||
throw new NotImplementedException ();
|
||||
else if (0 != (flags & 2))
|
||||
return UnpackVB(); // sub_461B34
|
||||
}
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
else
|
||||
return ReadUncompressed();
|
||||
}
|
||||
|
||||
byte[] UnpackVB ()
|
||||
{
|
||||
m_available = FillBuffer();
|
||||
if (0 == m_available)
|
||||
return null;
|
||||
var ref_table = new byte[0x10000];
|
||||
int v6 = -1 & 3;
|
||||
m_output[0] = m_buffer[0];
|
||||
int dst = 1;
|
||||
int remaining = m_output.Length - 1;
|
||||
m_current = 1 + v6 + 128;
|
||||
|
||||
if (!FillRefTable (ref_table, 1 + v6))
|
||||
return null;
|
||||
while (remaining > 0)
|
||||
{
|
||||
while (0 != GetNextBit())
|
||||
{
|
||||
int v23 = 0;
|
||||
int v24 = 0;
|
||||
int v25 = 16384;
|
||||
for (;;)
|
||||
{
|
||||
++v23;
|
||||
if (0 != GetNextBit())
|
||||
v24 |= v25;
|
||||
if (ref_table[2 * v24] == v23)
|
||||
break;
|
||||
v25 >>= 1;
|
||||
if (0 == v25)
|
||||
return null;
|
||||
}
|
||||
m_output[dst++] = ref_table[2 * v24 + 1];
|
||||
--remaining;
|
||||
if (0 == remaining)
|
||||
return m_output;
|
||||
}
|
||||
int v26 = ReadNext();
|
||||
int src_offset = dst - v26 - 1;
|
||||
int count = 2;
|
||||
if (0 == GetNextBit())
|
||||
{
|
||||
count += ReadCount();
|
||||
}
|
||||
if (remaining < count)
|
||||
return null;
|
||||
Binary.CopyOverlapped (m_output, src_offset, dst, count);
|
||||
dst += count;
|
||||
remaining -= count;
|
||||
}
|
||||
return m_output;
|
||||
}
|
||||
}
|
||||
}
|
||||
1011
ArcFormats/WildBug/ImageWBM.cs
Normal file
1011
ArcFormats/WildBug/ImageWBM.cs
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user