Two files for this is too much

This commit is contained in:
Denis
2022-01-16 16:15:34 +01:00
parent de72057ee1
commit 7b709d7702
2 changed files with 41 additions and 48 deletions

View File

@@ -1,45 +0,0 @@
using System;
namespace BMGEditor
{
public static class Yaz0 // TODO: Finish rewriting this
{
public static void Decompress(ref byte[] data)
{
if (data[0] != 'Y' || data[1] != 'a' || data[2] != 'z' || data[3] != '0')
return;
Int32 decompSize = (data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]);
byte[] output = new byte[decompSize];
int Offs = 16;
int dstoffs = 0;
while (true)
{
byte header = data[Offs++];
for (int i = 0; i < 8; i++)
{
if ((header & 0x80) != 0) output[dstoffs++] = data[Offs++];
else
{
byte b = data[Offs++];
int offs = ((b & 0xF) << 8 | data[Offs++]) + 1;
int length = (b >> 4) + 2;
if (length == 2) length = data[Offs++] + 0x12;
for (int j = 0; j < length; j++)
{
output[dstoffs] = output[dstoffs - offs];
dstoffs++;
}
}
if (dstoffs >= decompSize)
{
Array.Resize(ref data, decompSize);
output.CopyTo(data, 0);
return;
}
header <<= 1;
}
}
}
}
}

View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace BMGEditor
@@ -27,4 +24,45 @@ namespace BMGEditor
private Stream m_Backend;
}
public static class Yaz0 // TODO: Finish rewriting this
{
public static void Decompress(ref byte[] data)
{
if (data[0] != 'Y' || data[1] != 'a' || data[2] != 'z' || data[3] != '0')
return;
Int32 decompSize = (data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]);
byte[] output = new byte[decompSize];
int Offs = 16;
int dstoffs = 0;
while (true)
{
byte header = data[Offs++];
for (int i = 0; i < 8; i++)
{
if ((header & 0x80) != 0) output[dstoffs++] = data[Offs++];
else
{
byte b = data[Offs++];
int offs = ((b & 0xF) << 8 | data[Offs++]) + 1;
int length = (b >> 4) + 2;
if (length == 2) length = data[Offs++] + 0x12;
for (int j = 0; j < length; j++)
{
output[dstoffs] = output[dstoffs - offs];
dstoffs++;
}
}
if (dstoffs >= decompSize)
{
Array.Resize(ref data, decompSize);
output.CopyTo(data, 0);
return;
}
header <<= 1;
}
}
}
}
}