Esempio n. 1
0
        public static byte[] Decompress(ArraySlice <byte> data, int offset = 0)
        {
            switch (data[offset] & 0xFF)
            {
            case 0x10:
                return(Decompress10Lz(data, offset));

            case 0x11:
                return(Decompress11Lz(data, offset));

            default:
                return(null);
            }
        }
Esempio n. 2
0
        public static void ApplyPatch(ArraySlice <byte> rom, byte[] patch)
        {
            var patchlen = patch.Length;

            if (patchlen < 8 ||
                patch[0] != 'P' ||
                patch[1] != 'A' ||
                patch[2] != 'T' ||
                patch[3] != 'C' ||
                patch[4] != 'H')
            {
                throw new IOException("not a valid IPS file");
            }
            var offset = 5;

            while (offset + 2 < patchlen)
            {
                var writeOffset = ReadIpsOffset(patch, offset);
                if (writeOffset == 0x454f46)
                {
                    return;
                }
                offset += 3;
                if (offset + 1 >= patchlen)
                {
                    throw new IOException("abrupt ending to IPS file, entry cut off before size");
                }
                var size = ReadIpsSize(patch, offset);
                offset += 2;
                if (size == 0)
                {
                    if (offset + 1 >= patchlen)
                    {
                        throw new IOException("abrupt ending to IPS file, entry cut off before RLE size");
                    }
                    var rleSize = ReadIpsSize(patch, offset);
                    if (writeOffset + rleSize > rom.Length)
                    {
                        throw new IOException("trying to patch data past the end of the ROM file");
                    }
                    offset += 2;
                    if (offset >= patchlen)
                    {
                        throw new IOException("abrupt ending to IPS file, entry cut off before RLE byte");
                    }
                    var rleByte = patch[offset++];
                    for (var i = writeOffset; i < writeOffset + rleSize; i++)
                    {
                        rom[i] = rleByte;
                    }
                }
                else
                {
                    if (offset + size > patchlen)
                    {
                        throw new IOException("abrupt ending to IPS file, entry cut off before end of data block");
                    }
                    if (writeOffset + size > rom.Length)
                    {
                        throw new IOException("trying to patch data past the end of the ROM file");
                    }
                    ArraySlice.Copy(patch, offset, rom, writeOffset, size);
                    offset += size;
                }
            }
            throw new IOException("improperly terminated IPS file");
        }
Esempio n. 3
0
 public ArraySlice(ArraySlice <T> slice, int length, int offset = 0)
     : this(slice.Pointer, length, offset + slice.Offset)
 {
 }
Esempio n. 4
0
 public ArraySlice(ArraySlice <T> slice)
     : this(slice.Pointer)
 {
 }