mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-23 13:45:34 +08:00
removed redundant ArcView.Reader instances.
This commit is contained in:
parent
375e162959
commit
84985d18f5
@ -82,18 +82,18 @@ namespace GameRes.Formats.Ffa
|
|||||||
if (!entry.Name.EndsWith (".so4", StringComparison.InvariantCultureIgnoreCase) &&
|
if (!entry.Name.EndsWith (".so4", StringComparison.InvariantCultureIgnoreCase) &&
|
||||||
!entry.Name.EndsWith (".so5", StringComparison.InvariantCultureIgnoreCase))
|
!entry.Name.EndsWith (".so5", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return input;
|
return input;
|
||||||
using (var header = new ArcView.Reader (input))
|
int packed = input.ReadInt32();
|
||||||
|
int unpacked = input.ReadInt32();
|
||||||
|
if (packed+8 != entry.Size || packed <= 0 || unpacked <= 0)
|
||||||
{
|
{
|
||||||
int packed = header.ReadInt32();
|
input.Position = 0;
|
||||||
int unpacked = header.ReadInt32();
|
return input;
|
||||||
if (packed+8 != entry.Size || packed <= 0 || unpacked <= 0)
|
}
|
||||||
return input;
|
using (input)
|
||||||
using (input)
|
using (var reader = new LzssReader (input, packed, unpacked))
|
||||||
using (var reader = new LzssReader (input, packed, unpacked))
|
{
|
||||||
{
|
reader.Unpack();
|
||||||
reader.Unpack();
|
return new BinMemoryStream (reader.Data, entry.Name);
|
||||||
return new BinMemoryStream (reader.Data, entry.Name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,13 +77,13 @@ namespace GameRes.Formats.Glib2
|
|||||||
stream.Position = 0x20;
|
stream.Position = 0x20;
|
||||||
if (0 != (meta.Flags & 0x1000))
|
if (0 != (meta.Flags & 0x1000))
|
||||||
{
|
{
|
||||||
ReadGms (stream.AsStream);
|
ReadGms (stream);
|
||||||
}
|
}
|
||||||
PixelFormat format = 32 == meta.BPP ? PixelFormats.Bgra32 : PixelFormats.Bgr32;
|
PixelFormat format = 32 == meta.BPP ? PixelFormats.Bgra32 : PixelFormats.Bgr32;
|
||||||
int stride = (int)meta.Width * 4;
|
int stride = (int)meta.Width * 4;
|
||||||
var pixels = new byte[stride * (int)meta.Height];
|
var pixels = new byte[stride * (int)meta.Height];
|
||||||
// stream.Seek (-meta.PackedSize, SeekOrigin.End);
|
// stream.Seek (-meta.PackedSize, SeekOrigin.End);
|
||||||
LzssUnpack (stream.AsStream, pixels);
|
LzssUnpack (stream, pixels);
|
||||||
var layer = InfoCache.GetInfo (info.FileName);
|
var layer = InfoCache.GetInfo (info.FileName);
|
||||||
if (null != layer && null != layer.Rect)
|
if (null != layer && null != layer.Rect)
|
||||||
{
|
{
|
||||||
@ -93,7 +93,7 @@ namespace GameRes.Formats.Glib2
|
|||||||
return ImageData.Create (info, format, null, pixels);
|
return ImageData.Create (info, format, null, pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadGms (Stream input)
|
void ReadGms (IBinaryStream input)
|
||||||
{
|
{
|
||||||
var header = new byte[0x10];
|
var header = new byte[0x10];
|
||||||
if (0x10 != input.Read (header, 0, 0x10))
|
if (0x10 != input.Read (header, 0, 0x10))
|
||||||
@ -123,42 +123,39 @@ namespace GameRes.Formats.Glib2
|
|||||||
throw new System.NotImplementedException ("PgxFormat.Write not implemented");
|
throw new System.NotImplementedException ("PgxFormat.Write not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LzssUnpack (Stream input, byte[] output)
|
static void LzssUnpack (IBinaryStream input, byte[] output)
|
||||||
{
|
{
|
||||||
var frame = new byte[0x1000];
|
var frame = new byte[0x1000];
|
||||||
int frame_pos = 0xFEE;
|
int frame_pos = 0xFEE;
|
||||||
using (var lz = new ArcView.Reader (input))
|
int dst = 0;
|
||||||
|
int bits = 1;
|
||||||
|
while (dst < output.Length)
|
||||||
{
|
{
|
||||||
int dst = 0;
|
if (1 == bits)
|
||||||
int bits = 1;
|
bits = input.ReadUInt8() | 0x100;
|
||||||
while (dst < output.Length)
|
|
||||||
{
|
|
||||||
if (1 == bits)
|
|
||||||
bits = lz.ReadByte() | 0x100;
|
|
||||||
|
|
||||||
if (0 != (bits & 1))
|
if (0 != (bits & 1))
|
||||||
|
{
|
||||||
|
byte b = input.ReadUInt8();
|
||||||
|
output[dst++] = b;
|
||||||
|
frame[frame_pos++] = b;
|
||||||
|
frame_pos &= 0xFFF;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
byte lo = input.ReadUInt8();
|
||||||
|
byte hi = input.ReadUInt8();
|
||||||
|
int offset = (hi & 0xF0) << 4 | lo;
|
||||||
|
int count = Math.Min ((~hi & 0xF) + 3, output.Length-dst);
|
||||||
|
for (int i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
byte b = lz.ReadByte();
|
byte b = frame[offset++ & 0xFFF];
|
||||||
output[dst++] = b;
|
output[dst++] = b;
|
||||||
frame[frame_pos++] = b;
|
frame[frame_pos++] = b;
|
||||||
frame_pos &= 0xFFF;
|
frame_pos &= 0xFFF;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
byte lo = lz.ReadByte();
|
|
||||||
byte hi = lz.ReadByte();
|
|
||||||
int offset = (hi & 0xF0) << 4 | lo;
|
|
||||||
int count = Math.Min ((~hi & 0xF) + 3, output.Length-dst);
|
|
||||||
for (int i = 0; i < count; ++i)
|
|
||||||
{
|
|
||||||
byte b = frame[offset++ & 0xFFF];
|
|
||||||
output[dst++] = b;
|
|
||||||
frame[frame_pos++] = b;
|
|
||||||
frame_pos &= 0xFFF;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bits >>= 1;
|
|
||||||
}
|
}
|
||||||
|
bits >>= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,18 +97,15 @@ namespace GameRes.Formats.Kaguya
|
|||||||
|
|
||||||
public byte[] Data { get { return m_output; } }
|
public byte[] Data { get { return m_output; } }
|
||||||
|
|
||||||
public BmrDecoder (Stream input)
|
public BmrDecoder (IBinaryStream input)
|
||||||
{
|
{
|
||||||
input.Position = 3;
|
input.Position = 3;
|
||||||
using (var header = new ArcView.Reader (input))
|
m_step = input.ReadUInt8();
|
||||||
{
|
m_final_size = input.ReadInt32();
|
||||||
m_step = header.ReadByte();
|
m_key = input.ReadInt32();
|
||||||
m_final_size = header.ReadInt32();
|
int unpacked_size = input.ReadInt32();
|
||||||
m_key = header.ReadInt32();
|
m_output = new byte[unpacked_size];
|
||||||
int unpacked_size = header.ReadInt32();
|
m_input = new MsbBitStream (input.AsStream, true);
|
||||||
m_output = new byte[unpacked_size];
|
|
||||||
m_input = new MsbBitStream (input, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Unpack ()
|
public void Unpack ()
|
||||||
|
@ -54,7 +54,6 @@ namespace GameRes.Formats.Kiss
|
|||||||
|
|
||||||
var dir = new List<Entry> (count);
|
var dir = new List<Entry> (count);
|
||||||
using (var input = file.CreateStream())
|
using (var input = file.CreateStream())
|
||||||
using (var reader = new ArcView.Reader (input))
|
|
||||||
{
|
{
|
||||||
long prev_offset = 4;
|
long prev_offset = 4;
|
||||||
input.Position = 4;
|
input.Position = 4;
|
||||||
@ -64,7 +63,7 @@ namespace GameRes.Formats.Kiss
|
|||||||
if (string.IsNullOrWhiteSpace (name))
|
if (string.IsNullOrWhiteSpace (name))
|
||||||
return null;
|
return null;
|
||||||
var entry = FormatCatalog.Instance.Create<Entry> (name);
|
var entry = FormatCatalog.Instance.Create<Entry> (name);
|
||||||
entry.Offset = reader.ReadInt64();
|
entry.Offset = input.ReadInt64();
|
||||||
if (entry.Offset < prev_offset || entry.Offset > file.MaxOffset)
|
if (entry.Offset < prev_offset || entry.Offset > file.MaxOffset)
|
||||||
return null;
|
return null;
|
||||||
dir.Add (entry);
|
dir.Add (entry);
|
||||||
|
@ -108,14 +108,13 @@ namespace GameRes.Formats.SuperNekoX
|
|||||||
void DetectFileTypes (ArcView file, List<Entry> dir)
|
void DetectFileTypes (ArcView file, List<Entry> dir)
|
||||||
{
|
{
|
||||||
using (var input = file.CreateStream())
|
using (var input = file.CreateStream())
|
||||||
using (var reader = new ArcView.Reader (input))
|
|
||||||
{
|
{
|
||||||
var buffer = new byte[0x10];
|
var buffer = new byte[0x10];
|
||||||
foreach (PackedEntry entry in dir)
|
foreach (PackedEntry entry in dir)
|
||||||
{
|
{
|
||||||
input.Position = entry.Offset;
|
input.Position = entry.Offset;
|
||||||
uint packed_size = reader.ReadUInt32();
|
uint packed_size = input.ReadUInt32();
|
||||||
entry.UnpackedSize = reader.ReadUInt32();
|
entry.UnpackedSize = input.ReadUInt32();
|
||||||
entry.Offset += 8;
|
entry.Offset += 8;
|
||||||
if (0 == packed_size)
|
if (0 == packed_size)
|
||||||
{
|
{
|
||||||
@ -135,7 +134,7 @@ namespace GameRes.Formats.SuperNekoX
|
|||||||
signature = LittleEndian.ToUInt32 (buffer, 0);
|
signature = LittleEndian.ToUInt32 (buffer, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
signature = reader.ReadUInt32();
|
signature = input.ReadUInt32();
|
||||||
IResource res;
|
IResource res;
|
||||||
if (0x020000 == signature || 0x0A0000 == signature)
|
if (0x020000 == signature || 0x0A0000 == signature)
|
||||||
res = ImageFormat.Tga;
|
res = ImageFormat.Tga;
|
||||||
|
Loading…
Reference in New Issue
Block a user