Пример #1
0
            public Z64File ToFile(Z64Game game)
            {
                if (!Valid())
                {
                    return(new Z64File(null, -1, -1, -1, false));
                }

                if (!Exist())
                {
                    return(Z64File.DeletedFile(VRomStart, RomStart, VRomEnd - VRomStart));
                }

                int len = GetSize();

                byte[] data = new byte[len];
                Buffer.BlockCopy(game.Rom.RawRom, RomStart, data, 0, len);

                int romEnd = RomStart + data.Length;

                if (Compressed())
                {
                    data = Yaz0.Decompress(data);
                }

                return(new Z64File(data, VRomStart, RomStart, romEnd, Compressed()));
            }
Пример #2
0
        public void InjectFile(int vrom, byte[] data)
        {
            var file = GetFile(vrom);

            if (file == null)
            {
                throw new Z64GameException("Invalid VROM");
            }

            int oldSize = file.Compressed ? file.RomEnd - file.RomStart : file.Data.Length;

            var restStart = file.RomEnd != 0
                ? file.RomEnd
                : file.RomStart + file.Data.Length;

            //find rom end
            Z64File last = null;

            for (int i = 0; i < GetFileCount(); i++)
            {
                var iter = GetFileFromIndex(i);

                if (iter.Valid() && !iter.Deleted && (last == null || iter.RomStart > last.RomStart))
                {
                    last = iter;
                }
            }
            if (last == null)
            {
                throw new Exception("?");
            }

            var restEnd = last.RomEnd;

            //save rest
            byte[] rest = new byte[restEnd - restStart];
            Buffer.BlockCopy(Rom.RawRom, restStart, rest, 0, rest.Length);

            var encData = file.Compressed ? Yaz0.Compress(data) : data;
            int off     = encData.Length - oldSize;

            //copy new file in rom
            Buffer.BlockCopy(encData, 0, Rom.RawRom, file.RomStart, encData.Length);

            file.Data    = data;
            file.VRomEnd = (file.VRomStart + data.Length) + 0xF & ~0xF;
            if (file.Compressed)
            {
                file.RomEnd = (file.RomStart + encData.Length) + 0xF & ~0xF;
            }

            //copy rest
            Buffer.BlockCopy(rest, 0, Rom.RawRom, file.RomEnd, rest.Length);

            //offset each file rom addresses
            for (int i = _files.IndexOf(file) + 1; i < _files.Count; i++)
            {
                _files[i].RomStart = (_files[i].RomStart + off) + 0xF & ~0xF;
                _files[i].RomEnd   = (_files[i].RomEnd + off) + 0xF & ~0xF;
            }

            file.Data    = data;
            file.Deleted = false;
        }