idk
I just don't know btw as of rn credits to EveryFileExplorer
This commit is contained in:
@@ -2,54 +2,43 @@
|
|||||||
|
|
||||||
namespace BMGEditor
|
namespace BMGEditor
|
||||||
{
|
{
|
||||||
public static class Yaz0 // ONLY WORKS WITH BIG ENDIAN - TO REWRITE !!
|
public static class Yaz0 // TODO: Finish rewriting this
|
||||||
{
|
{
|
||||||
// inspired from http://www.amnoid.de/gc/yaz0.txt
|
|
||||||
public static void Decompress(ref byte[] data)
|
public static void Decompress(ref byte[] data)
|
||||||
{
|
{
|
||||||
if (data[0] != 'Y' || data[1] != 'a' || data[2] != 'z' || data[3] != '0')
|
if (data[0] != 'Y' || data[1] != 'a' || data[2] != 'z' || data[3] != '0')
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int fullsize = (data[4] << 24) | (data[5] << 16) | (data[6] << 8) | data[7];
|
Int32 decompSize = (data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]);
|
||||||
byte[] output = new byte[fullsize];
|
byte[] output = new byte[decompSize];
|
||||||
|
int Offs = 16;
|
||||||
int inpos = 16, outpos = 0;
|
int dstoffs = 0;
|
||||||
while (outpos < fullsize)
|
while (true)
|
||||||
{
|
{
|
||||||
byte block = data[inpos++];
|
byte header = data[Offs++];
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++)
|
for (int i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
if ((block & 0x80) != 0)
|
if ((header & 0x80) != 0) output[dstoffs++] = data[Offs++];
|
||||||
{
|
|
||||||
// copy one plain byte
|
|
||||||
output[outpos++] = data[inpos++];
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// copy N compressed bytes
|
byte b = data[Offs++];
|
||||||
byte b1 = data[inpos++];
|
int offs = ((b & 0xF) << 8 | data[Offs++]) + 1;
|
||||||
byte b2 = data[inpos++];
|
int length = (b >> 4) + 2;
|
||||||
|
if (length == 2) length = data[Offs++] + 0x12;
|
||||||
int dist = ((b1 & 0xF) << 8) | b2;
|
for (int j = 0; j < length; j++)
|
||||||
int copysrc = outpos - (dist + 1);
|
{
|
||||||
|
output[dstoffs] = output[dstoffs - offs];
|
||||||
int nbytes = b1 >> 4;
|
dstoffs++;
|
||||||
if (nbytes == 0) nbytes = data[inpos++] + 0x12;
|
|
||||||
else nbytes += 2;
|
|
||||||
|
|
||||||
for (int j = 0; j < nbytes; j++)
|
|
||||||
output[outpos++] = output[copysrc++];
|
|
||||||
}
|
|
||||||
|
|
||||||
block <<= 1;
|
|
||||||
if (outpos >= fullsize || inpos >= data.Length)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (dstoffs >= decompSize)
|
||||||
Array.Resize(ref data, fullsize);
|
{
|
||||||
|
Array.Resize(ref data, decompSize);
|
||||||
output.CopyTo(data, 0);
|
output.CopyTo(data, 0);
|
||||||
}
|
}
|
||||||
|
header <<= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user