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); }
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); }
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; }
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(); } }
public static void WriteResourceKeyIGT(this Stream stream, ResourceKey key) { stream.WriteValueU64(key.InstanceId); stream.WriteValueU32(key.GroupId); stream.WriteValueU32(key.TypeId); }
public Stream GetResourceStream(ResourceKey key) { return(new MemoryStream(this.GetResource(key))); }