Exemplo n.º 1
0
 public AssetFile()
 {
     Header      = new AssetPackHeader(0x52584541, 1, 0);
     EntryTable  = new AssetPackEntryTable();
     DataOffset  = 20 + (EntryTable.Entries.Length * 64);
     DataOffset += 2048 - (DataOffset % 2048);
 }
Exemplo n.º 2
0
            public AssetFile(byte[] data)
            {
                if (data == null)
                {
                    Header      = new AssetPackHeader(0x52584541, 1, 0);
                    EntryTable  = new AssetPackEntryTable();
                    DataOffset  = 20 + (EntryTable.Entries.Length * 64);
                    DataOffset += 2048 - (DataOffset % 2048);
                    return;
                }
                if (data.Length < 2048)
                {
                    throw new Exception("Invalid asset file size!");
                }
                var magic = Swap(BitConverter.ToUInt32(data, 0));

                if (magic != 0x52584541)
                {
                    throw new Exception("Invalid asset file magic!");
                }
                var version = Swap(BitConverter.ToUInt32(data, 4));

                if (version != 1)
                {
                    throw new NotSupportedException("Unsupported asset file version!");
                }
                var datasize = Swap(BitConverter.ToUInt32(data, 8));

                Header      = new AssetPackHeader(magic, version, datasize);
                EntryTable  = new AssetPackEntryTable(data, 12);
                DataOffset  = 20 + (EntryTable.Entries.Length * 64);
                DataOffset += 2048 - (DataOffset % 2048);
                var offset = DataOffset;

                for (var i = 0; i < EntryTable.Entries.Length; i++)
                {
                    if (EntryTable.Entries[i].Size <= 0)
                    {
                        continue;
                    }
                    var tmp = new byte[EntryTable.Entries[i].Size];
                    Buffer.BlockCopy(data, offset, tmp, 0, tmp.Length);
                    SetImage(tmp, i);
                    offset += tmp.Length;
                }
            }