Esempio n. 1
0
        public int AddData(EffectStorageType type, byte[] data)
        {
            switch (type)
            {
            case EffectStorageType.Effect:
            {
                if (data.Length != _effeEntrySize)
                {
                    return(-1);
                }
                _effe.Add(data);
                _effeChanged = true;
                return(_effe.Count - 1);
            }

            case EffectStorageType.Beam:
            {
                if (data.Length != _beamEntrySize)
                {
                    return(-1);
                }
                _beam.Add(data);
                _beamChanged = true;
                return(_beam.Count - 1);
            }

            case EffectStorageType.Contrail:
            {
                if (data.Length != _cntlEntrySize)
                {
                    return(-1);
                }
                _cntl.Add(data);
                _cntlChanged = true;
                return(_cntl.Count - 1);
            }

            case EffectStorageType.LightVolume:
            {
                if (data.Length != _ltvlEntrySize)
                {
                    return(-1);
                }
                _ltvl.Add(data);
                _ltvlChanged = true;
                return(_ltvl.Count - 1);
            }

            default:
                throw new ArgumentOutOfRangeException("Invalid EffectStorgeType value.");
            }
        }
Esempio n. 2
0
        private void ReadCompiledEffect(DataBlock block, uint offset, EffectStorageType type)
        {
            if (_cacheFile.CompiledEffects == null)
            {
                return;
            }

            // Read the index
            SeekToOffset(block, offset);
            int index = _reader.ReadInt32();

            //get the data
            byte[] data = _cacheFile.CompiledEffects.GetData(type, index);

            // Now create a fixup
            var fixup = new DataBlockEffectFixup((int)type, index, (int)offset, data);

            block.EffectFixups.Add(fixup);
        }
Esempio n. 3
0
        public byte[] GetData(EffectStorageType type, int index)
        {
            switch (type)
            {
            case EffectStorageType.Effect:
                return(_effe[index]);

            case EffectStorageType.Beam:
                return(_beam[index]);

            case EffectStorageType.Contrail:
                return(_cntl[index]);

            case EffectStorageType.LightVolume:
                return(_ltvl[index]);

            default:
                return(null);
            }
        }
Esempio n. 4
0
        private void LoadData(IReader reader, EffectStorageType type, long pointer, StructureLayout pointerLayout, string dataLayout)
        {
            reader.SeekTo(_metaArea.PointerToOffset(pointer));
            var layout = _buildInfo.Layouts.GetLayout(dataLayout);

            var pointerData = StructureReader.ReadStructure(reader, pointerLayout);

            var size    = (int)pointerData.GetInteger("size");
            var address = (uint)pointerData.GetInteger("pointer");

            long expand = _expander.Expand(address);

            reader.SeekTo(_metaArea.PointerToOffset(expand));

            int entryCount = size / layout.Size;

            switch (type)
            {
            case EffectStorageType.Effect:
            {
                _effeEntrySize = layout.Size;
                _effePointer   = pointer;
                for (int i = 0; i < entryCount; i++)
                {
                    _effe.Add(reader.ReadBlock(layout.Size));
                }

                break;
            }

            case EffectStorageType.Beam:
            {
                _beamEntrySize = layout.Size;
                _beamPointer   = pointer;

                for (int i = 0; i < entryCount; i++)
                {
                    _beam.Add(reader.ReadBlock(layout.Size));
                }

                break;
            }

            case EffectStorageType.Contrail:
            {
                _cntlEntrySize = layout.Size;
                _cntlPointer   = pointer;

                for (int i = 0; i < entryCount; i++)
                {
                    _cntl.Add(reader.ReadBlock(layout.Size));
                }

                break;
            }

            case EffectStorageType.LightVolume:
            {
                _ltvlEntrySize = layout.Size;
                _ltvlPointer   = pointer;

                for (int i = 0; i < entryCount; i++)
                {
                    _ltvl.Add(reader.ReadBlock(layout.Size));
                }

                break;
            }
            }
        }
Esempio n. 5
0
        private void SaveData(IStream stream, EffectStorageType type)
        {
            long pointer;

            byte[] data;
            switch (type)
            {
            case EffectStorageType.Effect:
                pointer = _effePointer;
                data    = _effe.SelectMany(a => a).ToArray();
                break;

            case EffectStorageType.Beam:
                pointer = _beamPointer;
                data    = _beam.SelectMany(a => a).ToArray();
                break;

            case EffectStorageType.Contrail:
                pointer = _cntlPointer;
                data    = _cntl.SelectMany(a => a).ToArray();
                break;

            case EffectStorageType.LightVolume:
                pointer = _ltvlPointer;
                data    = _ltvl.SelectMany(a => a).ToArray();
                break;

            default:
                return;
            }

            var pointerLayout = _buildInfo.Layouts.GetLayout("compiled effect pointer");

            stream.SeekTo(_metaArea.PointerToOffset(pointer));
            var pointerData = StructureReader.ReadStructure(stream, pointerLayout);

            var oldSize    = (int)pointerData.GetInteger("size");
            var oldAddress = (uint)pointerData.GetInteger("pointer");

            var oldExpand = _expander.Expand(oldAddress);

            if (oldExpand >= 0 && oldSize > 0)
            {
                _allocator.Free(oldExpand, oldSize);
            }

            long newAddress = 0;

            if (data.Length > 0)
            {
                newAddress = _allocator.Allocate(data.Length, 0x10, stream);
                stream.SeekTo(_metaArea.PointerToOffset(newAddress));
                stream.WriteBlock(data);
            }

            uint cont = _expander.Contract(newAddress);

            pointerData.SetInteger("size", (ulong)data.Length);
            pointerData.SetInteger("pointer", cont);

            stream.SeekTo(_metaArea.PointerToOffset(pointer));
            StructureWriter.WriteStructure(pointerData, pointerLayout, stream);
        }