예제 #1
0
    public static void Read(BinaryValueReader reader, out System.StringComparer value)
    {
        byte comparerKey;

        reader.Read(out comparerKey);
        value = ByteToStringComparerMap[comparerKey] as System.StringComparer;
    }
예제 #2
0
파일: UndoManager.cs 프로젝트: wtfcolt/game
        /// <summary>
        /// Redos to the next state (undos an undo).
        /// </summary>
        /// <returns>True if moved to the next state; false if there was no state to redo to.</returns>
        public bool Redo()
        {
            if (_stateIndex >= _states.Count - 1)
            {
                return(false);
            }

            _stateIndex++;
            Map.Load(BinaryValueReader.Create(_states[_stateIndex]), true, DynamicEntityFactory);

            return(true);
        }
예제 #3
0
파일: UndoManager.cs 프로젝트: wtfcolt/game
        /// <summary>
        /// Undos to the previous snapshot if there are any states to undo to.
        /// </summary>
        /// <returns>True if moved to the previous state; false if there are no previous states to move to.</returns>
        public bool Undo()
        {
            if (_stateIndex <= 0)
            {
                return(false);
            }

            _stateIndex--;
            Map.Load(BinaryValueReader.Create(_states[_stateIndex]), true, DynamicEntityFactory);

            return(true);
        }
예제 #4
0
        public static EncodedWavInfo EncodeWavToAdpcm(Stream stream, AdpcmFormat format)
        {
            var result = new EncodedWavInfo();

            result.Format = format;

            using (var waveReader = new WaveFileReader(stream))
            {
                result.SampleRate  = waveReader.WaveFormat.SampleRate;
                result.SampleCount = ( int )waveReader.SampleCount;

                // Try to find the smpl chunk containing loop info
                var smplChunk = waveReader.ExtraChunks.FirstOrDefault(x => x.IdentifierAsString == "smpl");
                if (smplChunk != null)
                {
                    using (var reader = new BinaryValueReader(waveReader, Amicitia.IO.Streams.StreamOwnership.Retain, Endianness.Big))
                    {
                        reader.Seek(smplChunk.StreamPosition + 0x24, SeekOrigin.Begin);
                        var sampleLoopCount = reader.ReadInt32();
                        if (sampleLoopCount > 0)
                        {
                            reader.Seek(0x04 + 0x08, SeekOrigin.Current);
                            result.HasLoop   = true;
                            result.LoopStart = reader.ReadInt32();
                            result.LoopEnd   = reader.ReadInt32();
                        }
                    }
                }

                // Get samples
                var sampleProvider = waveReader.ToSampleProvider();
                sampleProvider = sampleProvider.ToMono();

                var samples = new float[result.SampleCount];
                sampleProvider.Read(samples, 0, samples.Length);

                // Encode
                var pcm16 = Waveform.Pcm32ToPcm16(samples);
                result.History = new AdpcmHistory[Waveform.GetAdpcmFrameCount(pcm16.Length)];

                if (format == AdpcmFormat.Adpcm4)
                {
                    result.Data = Waveform.Pcm16ToAdpcm4(pcm16, result.History);
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            return(result);
        }
        /// <summary>
        /// Copies the values of this NPCChatConditionalCollectionBase to another NPCChatConditionalCollectionBase.
        /// </summary>
        /// <param name="dest">The NPCChatConditionalCollectionBase to copy the values into.</param>
        public void CopyValuesTo(NPCChatConditionalCollectionBase dest)
        {
            var stream = new BitStream(256);

            using (var writer = BinaryValueWriter.Create(stream))
            {
                Write(writer);
            }

            stream.PositionBits = 0;

            var reader = BinaryValueReader.Create(stream);

            dest.Read(reader);
        }
예제 #6
0
        public ParticleModifier DeepCopy()
        {
            // Create the deep copy by serializing to/from an IValueWriter
            using (var bs = new BitStream())
            {
                // Write
                using (var writer = BinaryValueWriter.Create(bs, false))
                {
                    Write(writer);
                }

                bs.Position = 0;

                // Read
                var reader = BinaryValueReader.Create(bs, false);
                return(Read(reader));
            }
        }
예제 #7
0
        public void Read(Stream stream)
        {
            Entries.Clear();

            using var reader = new BinaryValueReader(stream, StreamOwnership.Retain, Endianness.Little);
            var header = reader.Read <DwPackHeader>();

            Field08 = header.Field08;
            Index   = header.Index;

            var dataStartOffset = DwPackHeader.SIZE + (header.FileCount * DwPackEntry.SIZE);

            for (int i = 0; i < header.FileCount; i++)
            {
                var entry = reader.Read <DwPackEntry>();
                Entries.Add(new DwPackFileEntry(stream, dataStartOffset, ref entry));
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="EditorNPCChatConditionalCollection"/> class.
        /// </summary>
        /// <param name="source">The source <see cref="NPCChatConditionalCollectionBase"/> to copy the values from. If null,
        /// no values are copied.</param>
        public EditorNPCChatConditionalCollection(NPCChatConditionalCollectionBase source)
        {
            if (source == null)
            {
                return;
            }

            var stream = new BitStream(256);

            using (var writer = BinaryValueWriter.Create(stream))
            {
                source.Write(writer);
            }

            stream.PositionBits = 0;

            IValueReader reader = BinaryValueReader.Create(stream);

            Read(reader);
        }
예제 #9
0
 static public void Read <K, V>(BinaryValueReader reader, out ScopeMap <K, V> v)
 {
     reader.Read(out v);
 }
예제 #10
0
 static public void Read <T>(BinaryValueReader reader, out ScopeArray <T> v)
 {
     reader.Read(out v);
 }
 /// <summary>
 /// When overridden in the derived class, gets the IValueReader instance used to read the values
 /// written by the IValueWriter created with GetWriter().
 /// </summary>
 /// <returns>The IValueWriter instance.</returns>
 public override IValueReader GetReader()
 {
     _stream.PositionBits = 0;
     return(BinaryValueReader.Create(_stream));
 }
 /// <summary>
 /// When overridden in the derived class, gets the IValueReader instance used to read the values
 /// written by the IValueWriter created with GetWriter().
 /// </summary>
 /// <returns>The IValueWriter instance.</returns>
 public override IValueReader GetReader()
 {
     return(BinaryValueReader.CreateFromFile(_filePath));
 }
예제 #13
0
 void LoadMapFromState(int stateIndex)
 {
     Map.Load(BinaryValueReader.Create(_states[stateIndex], useEnumNames: false), true, DynamicEntityFactory);
 }