示例#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
        private ResourceKey[] ReadResourceKeys(Stream input, int count)
        {
            // this may need to be checked for compatability with big-endian scenegraph files.
            ResourceKey[] keys = new ResourceKey[count];
            for (int i = 0; i < count; i++)
            {
                ResourceKey key;
                if (this.LittleEndian == true)
                {
                    key.InstanceId = input.ReadValueU64();
                }
                else
                {
                    key.InstanceId  = 0;
                    key.InstanceId |= input.ReadValueU32();
                    key.InstanceId |= (UInt64)(input.ReadValueU32()) << 32;
                }
                key.TypeId  = input.ReadValueU32();
                key.GroupId = input.ReadValueU32();
                keys[i]     = key;
            }

            return(keys);
        }
        public override void Deserialize(Stream input)
        {
            uint version = input.ReadValueU32();

            if (version < 17)
            {
                throw new FormatException("unsupported version < 17");
            }
            else if (version > 21)
            {
                throw new FormatException("unsupported version > 21");
            }

            KeyTable keyTable = input.ReadKeyTable(4);

            this.DesignModePresets = new List <PresetReference>();
            if (version >= 17)
            {
                uint count = input.ReadValueU32();
                for (uint i = 0; i < count; i++)
                {
                    PresetReference reference = new PresetReference();
                    reference.Internal = version >= 21 ? input.ReadValueBoolean() : false;

                    if (reference.Internal == true)
                    {
                        reference.Stream = input.ReadToMemoryStream(input.ReadValueU32());
                    }
                    else
                    {
                        reference.Name = input.ReadStringUTF16(input.ReadValueU32());
                    }

                    reference.Unknown = input.ReadValueU32();
                    this.DesignModePresets.Add(reference);
                }
            }

            base.Deserialize(input);

            this.Unknown90 = keyTable.Keys[input.ReadValueS32()];

            this.UnknownA0 = input.ReadValueU32();
            this.UnknownA8 = input.ReadValueU32();
            this.UnknownAC = input.ReadValueU32();

            this.UnknownDC = input.ReadValueU32();
            this.UnknownE0 = input.ReadValueU32();

            this.Presets = new List <Preset>();
            {
                byte count = input.ReadValueU8();
                for (byte i = 0; i < count; i++)
                {
                    this.Presets.Add(new Preset(input, keyTable));
                }
            }

            this.UnknownF8 = input.ReadValueBoolean();

            this.Unknown100 = keyTable.Keys[input.ReadValueS32()];

            this.UnknownE4 = input.ReadValueU32();

            if (version >= 20)
            {
                this.RoomTypeFlags           = input.ReadValueU32();
                this.BuyCategoryFlags        = input.ReadValueU32();
                this.BuySubCategoryFlags     = input.ReadValueU64();
                this.BuyRoomSubCategoryFlags = input.ReadValueU64();
                this.BuildCategoryFlags      = input.ReadValueU32();
            }
            else
            {
                this.RoomTypeFlags       = input.ReadValueU32();
                this.BuyCategoryFlags    = input.ReadValueU32();
                this.BuySubCategoryFlags = input.ReadValueU64();
                this.BuildCategoryFlags  = input.ReadValueU32();
            }

            if (this.RoomTypeFlags == 0)
            {
                this.RoomTypeFlags = 0x80000000;
            }

            if (this.BuyCategoryFlags == 0)
            {
                this.BuyCategoryFlags = 0x80000000;
            }

            if (this.BuySubCategoryFlags == 0)
            {
                this.BuySubCategoryFlags = 0x8000000000000000;
            }

            if (this.BuyRoomSubCategoryFlags == 0)
            {
                this.BuyRoomSubCategoryFlags = 0x8000000000000000;
            }

            if (this.BuildCategoryFlags == 0)
            {
                this.BuildCategoryFlags = 0x80000000;
            }

            this.FixBuildCategoryFlags();

            this.Unknown110 = keyTable.Keys[input.ReadValueS32()];

            this.UnknownA4 = input.ReadValueU32();

            this.UnknownString1 = input.ReadStringUTF16(input.ReadValueU8(), false);
            this.UnknownString2 = input.ReadStringUTF16(input.ReadValueU8(), false);

            if (version >= 19)
            {
                this.Unknown150 = input.ReadValueU32();
                this.Unknown154 = input.ReadValueU32();
                this.Unknown158 = new List <UnknownClass2>();
                uint count = input.ReadValueU32();
                for (uint i = 0; i < count; i++)
                {
                    this.Unknown158.Add(new UnknownClass2(input));
                }
            }

            if (version >= 18)
            {
                this.Unknown120 = keyTable.Keys[input.ReadValueS32()];
            }
        }
示例#7
0
 public Stream GetResourceStream(ResourceKey key)
 {
     return(new MemoryStream(this.GetResource(key)));
 }
示例#8
0
        public virtual void Deserialize(Stream input)
        {
            uint version = input.ReadValueU32();

            if (version >= 10)
            {
                this.CatalogName = input.ReadValueU64();
                this.Description = input.ReadValueU64();
            }

            this.Unknown40 = input.ReadStringUTF16(input.ReadValueU8(), false);
            this.Unknown50 = input.ReadStringUTF16(input.ReadValueU8(), false);

            this.Unknown60  = input.ReadValueU32();
            this.Unknown64  = input.ReadValueU32();
            this.Unknown68  = input.ReadValueU32();
            this.StatusFlag = input.ReadValueU8();

            if (version < 5)
            {
                if ((this.StatusFlag & 2) == 2)
                {
                    this.StatusFlag |= 0x10;
                }
                else
                {
                    this.StatusFlag |= 0x20;
                }
            }

            if (version < 6)
            {
                this.SubSort = input.ReadStringUTF16(input.ReadValueU8(), false);
            }

            if (version >= 9)
            {
                this.Unknown70 = input.ReadValueU64();
            }
            else
            {
                ResourceKey key = input.ReadResourceKeyIGT();
                this.Unknown70 = key.InstanceId;
            }

            this.UnknownByte = input.ReadValueU8();

            if (version >= 3)
            {
                this.EnvironmentScore = input.ReadValueF32();
            }

            if (version >= 7)
            {
                this.FireType = input.ReadValueU32();
            }

            if (version >= 8)
            {
                this.IsStealable = input.ReadValueBoolean();
            }

            if (version >= 11)
            {
                this.IsReposesable = input.ReadValueBoolean();
            }

            if (version >= 12)
            {
                this.Unknown84 = input.ReadValueU32();
            }

            if (version < 10)
            {
                this.CatalogName = input.ReadValueU64();
                this.Description = input.ReadValueU64();
            }
        }
示例#9
0
 public static void WriteResourceKeyIGT(this Stream stream, ResourceKey key)
 {
     stream.WriteValueU64(key.InstanceId);
     stream.WriteValueU32(key.GroupId);
     stream.WriteValueU32(key.TypeId);
 }