/// <summary> /// Takes a state snapshot of the map. Only records it as a new state if the state has changed since the last snapshot. /// If the state has changed, all forward states are destroyed. So if you undo a few times then call this, you cannot redo those undos anymore. /// </summary> /// <returns>True if a new state snapshot was taken; false if the state has not changed.</returns> public bool Snapshot() { // Serilize the whole map as binary into memory byte[] serialized = BinaryValueWriter.CreateAndWrite(w => Map.Save(w, DynamicEntityFactory, MapBase.MapSaveFlags.DoNotSort)); // Check if the state changed since the last time if (_stateIndex >= 0 && ByteArrayEqualityComparer.AreEqual(_states[_stateIndex], serialized)) { return(false); } // Remove all forward (redo) states if (_states.Count > _stateIndex + 1) { _states.RemoveRange(_stateIndex + 1, _states.Count - _stateIndex - 1); } // Remove old states if (_states.Count > _maxStates) { _states.RemoveRange(0, _cropAmount); } // Push in new state _states.Add(serialized); _stateIndex = _states.Count - 1; return(true); }
public static void Write(BinaryValueWriter writer, System.StringComparer value) { // If System.StringComparer is not one of the 6 we recognize, comparerKey should be 0. byte comparerKey; StringComparerToByteMap.TryGetValue(value as System.Collections.Generic.IEqualityComparer <string> ?? System.Collections.Generic.EqualityComparer <string> .Default, out comparerKey); writer.Write(comparerKey); }
/// <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); }
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)); } }
public void Write(Stream stream, bool compress, Action <DwPackFileEntry> callback) { using var writer = new BinaryValueWriter(stream, StreamOwnership.Retain, Endianness.Little); DwPackHeader header; header.Signature = DwPackHeader.SIGNATURE; header.Field08 = Field08; header.FileCount = Entries.Count; header.Index = Index; writer.Write(header); var dataOffset = 0; for (int i = 0; i < Entries.Count; i++) { var e = Entries[i]; if (compress) { e.Compress(); } var entry = new DwPackEntry(); entry.Field00 = e.Field00; entry.Index = (short)i; entry.PackIndex = (short)header.Index; entry.Path = e.Path; entry.Field104 = e.Field104; entry.CompressedSize = e.CompressedSize; entry.UncompressedSize = e.UncompressedSize; entry.Flags = e.IsCompressed ? 1 : 0; entry.DataOffset = dataOffset; writer.Write(entry); dataOffset += entry.CompressedSize; } for (int i = 0; i < Entries.Count; i++) { callback?.Invoke(Entries[i]); Entries[i].CopyTo(writer.GetBaseStream(), decompress: false); } }
/// <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); }
// Write an object to a stream. internal void WriteObject (BinaryValueWriter.BinaryValueContext context, Object value) { // Handle the null case first. if (value == null) { context.writer.Write((byte)(BinaryElementType.NullValue)); return; } // Get the type of the object and see if we've // processed the type before. Type type = value.GetType(); long typeID = context.gen.GetIDForType(type); // Allocate an object identifier. bool firstTime; long objectID = context.gen.GetId(value, out firstTime); if (typeID == -1) { context.gen.RegisterType(type, objectID); } // Get a value writer for the type. BinaryValueWriter writer; writer = BinaryValueWriter.GetWriter(context, type); // Write the object header. writer.WriteObjectHeader (context, value, type, objectID, typeID); // Write the object internals. writer.WriteObject(context, value, type); }
static public void Write <K, V>(BinaryValueWriter writer, ScopeMap <K, V> v) { writer.Write(v); }
static public void Write <T>(BinaryValueWriter writer, ScopeArray <T> v) { writer.Write(v); }
/// <summary> /// When overridden in the derived class, gets the IValueWriter instance. This method is always called first. /// </summary> /// <returns>The IValueReader instance.</returns> public override IValueWriter GetWriter() { return(BinaryValueWriter.Create(_stream)); }
/// <summary> /// When overridden in the derived class, gets the IValueWriter instance. This method is always called first. /// </summary> /// <returns>The IValueReader instance.</returns> public override IValueWriter GetWriter() { return(BinaryValueWriter.Create(_filePath)); }