Exemplo n.º 1
0
        public static byte[] LZ77_Compress(byte[] data, bool header = false)
        {
            ByteArrayOutputStream res = new ByteArrayOutputStream();

            if (header)
            {
                res.writeUInt(0x37375A4C); //LZ77
            }

            res.writeInt((data.Length << 8) | 0x10);

            byte[] tempBuffer = new byte[16];

            //Current byte to compress.
            int current = 0;

            while (current < data.Length)
            {
                int  tempBufferCursor = 0;
                byte blockFlags       = 0;
                for (int i = 0; i < 8; i++)

                {
                    //Not sure if this is needed. The DS probably ignores this data.
                    if (current >= data.Length)
                    {
                        tempBuffer[tempBufferCursor++] = 0;
                        continue;
                    }

                    int searchPos = 0;
                    int searchLen = 0;
                    LZ77_Compress_Search(data, current, out searchPos, out searchLen);
                    int searchDisp = current - searchPos - 1;
                    if (searchLen > 2) //We found a big match, let's write a compressed block.
                    {
                        blockFlags |= (byte)(1 << (7 - i));
                        tempBuffer[tempBufferCursor++] = (byte)((((searchLen - 3) & 0xF) << 4) + ((searchDisp >> 8) & 0xF));
                        tempBuffer[tempBufferCursor++] = (byte)(searchDisp & 0xFF);
                        current += searchLen;
                    }
                    else
                    {
                        tempBuffer[tempBufferCursor++] = data[current++];
                    }
                }

                res.writeByte(blockFlags);
                for (int i = 0; i < tempBufferCursor; i++)
                {
                    res.writeByte(tempBuffer[i]);
                }
            }

            return(res.getArray());
        }
Exemplo n.º 2
0
        public void write(ByteArrayOutputStream outp, ByteArrayOutputStream cam, int camID)
        {
            outp.writeUShort((ushort)X);
            outp.writeUShort((ushort)Y);
            outp.writeUShort((ushort)Width);
            outp.writeUShort((ushort)Height);
            outp.writeByte((byte)Number);
            outp.writeByte((byte)camID);
            outp.writeByte((byte)Music);
            outp.writeByte((byte)Unknown1);
            outp.writeByte((byte)Unknown2);
            outp.writeByte((byte)Unknown3);
            outp.writeByte((byte)Lighting);
            outp.writeByte((byte)FlagpoleID);

            cam.writeInt(CameraTop);
            cam.writeInt(CameraBottom);
            cam.writeInt(CameraTopSpin);
            cam.writeInt(CameraBottomSpin);
            cam.writeUShort((ushort)camID);
            cam.writeUShort((ushort)CameraBottomStick);
            cam.writeUInt(0); //This seems just padding.
        }