Users browsing this thread: 3 Guest(s)
A Boy and His Blob Wii ANB files
#11
Okay, sure!

It's a modified version of something. It returns an int array (Why didn't I use a bytes?).

Code:
    public static int[] decompress(int[] instream, long inLength){

        int pointer = 0;

        byte type = (byte) instream[pointer++];
        int decompressedSize = (instream[pointer++])
                | (instream[pointer++] << 8) | (instream[pointer++] << 16);

        int[] outstream = new int[decompressedSize];
        int outpointer = 0;

        if (decompressedSize == 0) {
            decompressedSize = (instream[pointer++])
                    | (instream[pointer++] << 8) | (instream[pointer++] << 16)
                    | (instream[pointer++] << 24);
            ;
        }

        int bufferLength = 0x1000;
        int[] buffer = new int[bufferLength];
        int bufferOffset = 0;

        int currentOutSize = 0;
        int flags = 0, mask = 1;

        while (currentOutSize < decompressedSize) {
            if (mask == 1) {
                flags = instream[pointer++];
                mask = 0x80;
            } else {
                mask >>= 1;
            }

            if ((flags & mask) > 0) {
                int byte1 = instream[pointer++];

                int length = byte1 >> 4;
                int disp = -1;

                if (length == 0) {
                    int byte2 = instream[pointer++];
                    int byte3 = instream[pointer++];

                    length = (((byte1 & 0x0F) << 4) | (byte2 >> 4)) + 0x11;
                    disp = (((byte2 & 0x0F) << 8) | byte3) + 0x1;

                } else if (length == 1) {
                    int byte2 = instream[pointer++];
                    int byte3 = instream[pointer++];
                    int byte4 = instream[pointer++];

                    length = (((byte1 & 0x0F) << 12) | (byte2 << 4) | (byte3 >> 4)) + 0x111;
                    disp = (((byte3 & 0x0F) << 8) | byte4) + 0x1;

                } else {
                    int byte2 = instream[pointer++];

                    length = ((byte1 & 0xF0) >> 4) + 0x1;
                    disp = (((byte1 & 0x0F) << 8) | byte2) + 0x1;
                }

                int bufIdx = bufferOffset + bufferLength - disp;
                for (int i = 0; i < length; i++) {
                    int next = buffer[bufIdx % bufferLength];
                    bufIdx++;
                    outstream[outpointer++] = next;
                    buffer[bufferOffset] = next;
                    bufferOffset = (bufferOffset + 1) % bufferLength;
                }
                currentOutSize += length;
            } else {
                int next = instream[pointer++];

                outstream[outpointer++] = next;
                currentOutSize++;
                buffer[bufferOffset] = next;
                bufferOffset = (bufferOffset + 1) % bufferLength;
            }

        }
        return outstream;

    }

But maybe you're not getting the correct bytes because both of the decompression things work for me.
Could you output the compressed data and see?
Reply
Thanked by:


Messages In This Thread
A Boy and His Blob Wii ANB files - by Ploaj - 03-28-2015, 11:29 AM
RE: A Boy and His Blob Wii ANB files - by puggsoy - 03-28-2015, 09:17 PM
RE: A Boy and His Blob Wii ANB files - by Ploaj - 03-28-2015, 09:45 PM
RE: A Boy and His Blob Wii ANB files - by Daxar - 05-23-2015, 11:23 AM
RE: A Boy and His Blob Wii ANB files - by Ploaj - 05-23-2015, 11:46 AM
RE: A Boy and His Blob Wii ANB files - by Daxar - 05-23-2015, 03:58 PM
RE: A Boy and His Blob Wii ANB files - by Ploaj - 05-23-2015, 04:15 PM
RE: A Boy and His Blob Wii ANB files - by Daxar - 05-23-2015, 06:46 PM
RE: A Boy and His Blob Wii ANB files - by Ploaj - 05-23-2015, 07:03 PM
RE: A Boy and His Blob Wii ANB files - by Daxar - 05-23-2015, 09:01 PM
RE: A Boy and His Blob Wii ANB files - by Ploaj - 05-23-2015, 09:39 PM
RE: A Boy and His Blob Wii ANB files - by Daxar - 05-23-2015, 10:17 PM
RE: A Boy and His Blob Wii ANB files - by Ploaj - 05-23-2015, 10:55 PM
RE: A Boy and His Blob Wii ANB files - by Daxar - 05-24-2015, 05:54 AM
RE: A Boy and His Blob Wii ANB files - by Ploaj - 05-24-2015, 10:52 AM
RE: A Boy and His Blob Wii ANB files - by Daxar - 05-24-2015, 01:25 PM
RE: A Boy and His Blob Wii ANB files - by Ploaj - 05-24-2015, 02:03 PM
RE: A Boy and His Blob Wii ANB files - by Daxar - 05-24-2015, 02:21 PM
RE: A Boy and His Blob Wii ANB files - by Ploaj - 05-24-2015, 07:57 PM
RE: A Boy and His Blob Wii ANB files - by Daxar - 05-24-2015, 10:01 PM
RE: A Boy and His Blob Wii ANB files - by Ploaj - 05-24-2015, 10:04 PM
RE: A Boy and His Blob Wii ANB files - by Daxar - 05-24-2015, 10:18 PM
RE: A Boy and His Blob Wii ANB files - by Ploaj - 05-24-2015, 10:41 PM
RE: A Boy and His Blob Wii ANB files - by Daxar - 05-25-2015, 06:43 AM
RE: A Boy and His Blob Wii ANB files - by Ton - 05-26-2015, 02:38 PM
RE: A Boy and His Blob Wii ANB files - by Daxar - 05-31-2015, 01:16 PM
RE: A Boy and His Blob Wii ANB files - by Ploaj - 06-01-2015, 12:56 AM

Forum Jump: