I forgot to do an end write-up of this, and there doesn't seem to be too much interest in this. But I guess I should just give you the unfinished work I did.
So this is what I made back then to decode the images
Code: Select all
//decode the custom RLE CONTAINS ERRORS ATM
std::vector<char> MisakaArchive::decodeRLE(std::vector<char> buffer)
{
const char BACK_FLAG = 0x80;
const char REPEAT_FLAG = 0x40;
const char LHDR_FLAG = 0x20;
std::vector<char> result;
int cur_src = 0;
int cur_dst = 0;
int cur_bck = 0;
while (cur_src < buffer.size()){
char src = buffer[cur_src++];
int amt = 0;
if (src & BACK_FLAG){
amt = (src & 0x60) >> 5;
amt += 4;
cur_bck = (src & 0x1F) << 8 | reinterpret_cast<unsigned char &>(buffer[cur_src++]);
assert(cur_bck>0);
cur_bck = cur_dst - cur_bck;
int subcopy = amt;
while (cur_dst - cur_bck < subcopy){
int subcopy_amt = (cur_dst - cur_bck);
copy_data(result, result, cur_dst, cur_bck, subcopy_amt);
subcopy -= subcopy_amt;
cur_bck += subcopy_amt;
cur_dst += subcopy_amt;
}
copy_data(result, result, cur_dst, cur_bck, subcopy);
cur_bck += subcopy;
cur_dst += subcopy;
}
else if ((src & 0xE0) == 0x60)
{
amt = src & 0x1F;
amt += 4;
assert(cur_dst > cur_bck);
int subcopy = amt;
while (cur_dst - cur_bck < subcopy){
int subcopy_amt = (cur_dst - cur_bck);
copy_data(result, result, cur_dst, cur_bck, subcopy_amt);
subcopy -= subcopy_amt;
cur_bck += subcopy_amt;
cur_dst += subcopy_amt;
}
copy_data(result, result, cur_dst, cur_bck, subcopy);
cur_bck += subcopy;
cur_dst += subcopy;
}
else if (src & REPEAT_FLAG){
amt = (src & 0x10) ? (src & 0x0F) << 8 | reinterpret_cast<unsigned char &>(buffer[cur_src++]) : src & 0x1F;
amt += 4;
result.insert(result.begin() + cur_dst, amt, buffer[cur_src++]);
cur_dst += amt;
}
else if (src & LHDR_FLAG){
amt = ((src & 0x1F) << 8) | reinterpret_cast<unsigned char &>(buffer[cur_src++]);
copy_data(result, buffer, cur_dst, cur_src, amt);
cur_src += amt;
cur_dst += amt;
}
else if (src == 0x00){
break;
}
else
{
amt = src & 0x1F;
copy_data(result, buffer, cur_dst, cur_src, amt);
cur_src += amt;
cur_dst += amt;
}
}
return result;
}
This has still some bugs in it but you can find this and the actually working hackishly direct MIPS ASM to C++ translation here:
https://github.com/Bigpet/KatagawaBinParser