Update BCCAD.cs

This commit is contained in:
Braedon 2022-02-10 17:34:15 -05:00
parent a9769d46a9
commit cbc2ecef72

View file

@ -10,24 +10,26 @@ namespace Bread2Unity
public BCCAD Read(byte[] bytes)
{
sheetW = (ushort)bytes[4];
sheetH = (ushort)bytes[6];
sheetW = BitConverter.ToUInt16(bytes, 4);
sheetH = BitConverter.ToUInt16(bytes, 6);
ISprite spriteParts_ = new ISprite();
int max = (bytes[8] * 2) + 12;
int loopTimes = 0;
// int max = (bytes[8] * 2) + 12;
int max = 64 * bytes[8] + 12;
// this is pretty bad spaghetti code, and I wrote this when I had the flu at 3 AM. so you're welcome --Starpelly
for (int i = 12; i < max; i+=2) // 16 bit bytes, skip every 2nd byte
// note this doesn't account for empty sprites, but I'll get there when i get there
for (int i = 12; i < max; i += 2) // 16 bit bytes, skip every 2nd byte
{
int ind = i + 4; // the first 4 contain the number of parts and an unknown number, I can skip these for now
ISprite spriteParts_ = new ISprite();
int compare = 0;
for (int j = 0; j < bytes[i]; j++)
{
int ind = i + 4 + (64 * j);
ISpritePart part = new ISpritePart();
part.regionX = BitConverter.ToUInt16(bytes, ind + 0);
part.regionY = BitConverter.ToUInt16(bytes, ind + 2);
part.regionW = BitConverter.ToUInt16(bytes,ind + 4);
part.regionW = BitConverter.ToUInt16(bytes, ind + 4);
part.regionH = BitConverter.ToUInt16(bytes, ind + 6);
part.posX = BitConverter.ToInt16(bytes, ind + 8);
part.posY = BitConverter.ToInt16(bytes, ind + 10);
@ -39,35 +41,19 @@ namespace Bread2Unity
// im sure the values between 20 and 28 are important so remind me to come back to these
part.opacity = bytes[ind + 28];
// Debug.Log(part.regionX);
Debug.Log("offset: " + ind + ", val: " + part.regionX);
spriteParts_.parts.Add(part);
int compare = 32;
if (loopTimes < 1)
{
compare = 32;
compare += 64;
}
else if (loopTimes >= 1)
{
if (loopTimes % 2 == 0)
{
compare = 32;
}
else
{
compare = 34;
}
}
max += compare * 2;
i += compare * 2;
loopTimes++;
Debug.Log("offset: " + (ind + (compare - loopTimes + 1) * 2) + ", val: " + BitConverter.ToUInt16(bytes, (ind + (compare - loopTimes + 1) * 2)));
}
sprites.Add(spriteParts_);
i += compare;
}
return new BCCAD()
{
};
@ -75,20 +61,5 @@ namespace Bread2Unity
/// sprites length bytes start = 12
/// 20 = 1
/// 84 = 2
/// 152 = 3
/// 216 = 4
/// 284 - 5
///
///
/// 64
/// 64
/// -- Loop
/// 68
/// 64
/// 68
/// 64
}
}