コード例 #1
0
        public byte[] GetRawResource(ResourceKey key)
        {
            if (this._Entries.ContainsKey(key) == false || !(this._Entries[key] is StreamEntry))
            {
                throw new KeyNotFoundException();
            }

            StreamEntry entry = (StreamEntry)this._Entries[key];

            this.Stream.Seek(this.BaseOffset + entry.Offset, SeekOrigin.Begin);

            byte[] data = new byte[entry.CompressedSize];
            this.Stream.Read(data, 0, data.Length);
            return(data);
        }
コード例 #2
0
        public void DeleteResource(ResourceKey key)
        {
            if (this.Stream.CanWrite == false)
            {
                throw new NotSupportedException();
            }

            if (this._Entries.ContainsKey(key) == false)
            {
                throw new KeyNotFoundException();
            }

            if (this._Entries[key] is StreamEntry)
            {
                this.OriginalEntries[key] = (StreamEntry)this._Entries[key];
            }

            this._Entries.Remove(key);
        }
コード例 #3
0
        public void SetResource(ResourceKey key, byte[] data)
        {
            if (this.Stream.CanWrite == false)
            {
                throw new NotSupportedException();
            }

            if (this._Entries.ContainsKey(key) && this._Entries[key] is StreamEntry)
            {
                this.OriginalEntries[key] = (StreamEntry)this._Entries[key];
            }

            MemoryEntry entry = new MemoryEntry();

            entry.Compressed     = false;
            entry.CompressedSize = entry.DecompressedSize = (uint)data.Length;
            entry.Data           = (byte[])(data.Clone());

            this._Entries[key] = entry;
        }
コード例 #4
0
        public byte[] GetResource(ResourceKey key)
        {
            if (this._Entries.ContainsKey(key) == false)
            {
                throw new KeyNotFoundException();
            }

            if (this._Entries[key] is StreamEntry)
            {
                StreamEntry entry = (StreamEntry)this._Entries[key];

                this.Stream.Seek(this.BaseOffset + entry.Offset, SeekOrigin.Begin);

                byte[] data;
                if (entry.Compressed == true)
                {
                    data = this.Stream.RefPackDecompress();

                    if (data.Length != entry.DecompressedSize)
                    {
                        throw new InvalidOperationException("decompressed data not same length as specified in index");
                    }
                }
                else
                {
                    data = new byte[entry.DecompressedSize];
                    this.Stream.Read(data, 0, data.Length);
                }

                return(data);
            }
            else if (this._Entries[key] is MemoryEntry)
            {
                return((byte[])(((MemoryEntry)this._Entries[key]).Data.Clone()));
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
コード例 #5
0
 public static void WriteResourceKeyIGT(this Stream stream, ResourceKey key)
 {
     stream.WriteValueU64(key.InstanceId);
     stream.WriteValueU32(key.GroupId);
     stream.WriteValueU32(key.TypeId);
 }
コード例 #6
0
 public Stream GetResourceStream(ResourceKey key)
 {
     return(new MemoryStream(this.GetResource(key)));
 }