public override bool OnSave(BitStream stream) { long entityId = Component.Entity.EntityId; MySerializer.Write(stream, ref entityId); return(true); }
InventoryDeltaInformation WriteInventory(ref InventoryDeltaInformation packetInfo, BitStream stream, byte packetId, int maxBitPosition, out bool needsSplit) { var delta = PrepareSendData(ref packetInfo, stream, maxBitPosition, out needsSplit); delta.MessageId = packetInfo.MessageId; stream.WriteBool(delta.HasChanges); stream.WriteUInt32(delta.MessageId); if (!delta.HasChanges) { return(delta); } stream.WriteBool(delta.ChangedItems != null); if (delta.ChangedItems != null) { stream.WriteInt32(delta.ChangedItems.Count); foreach (var keyValuePair in delta.ChangedItems) { stream.WriteUInt32(keyValuePair.Key); stream.WriteInt64(keyValuePair.Value.RawValue); } } stream.WriteBool(delta.RemovedItems != null); if (delta.RemovedItems != null) { stream.WriteInt32(delta.RemovedItems.Count); foreach (var value in delta.RemovedItems) { stream.WriteUInt32(value); } } stream.WriteBool(delta.NewItems != null); if (delta.NewItems != null) { stream.WriteInt32(delta.NewItems.Count); foreach (var keyValuePair2 in delta.NewItems) { stream.WriteInt32(keyValuePair2.Key); var value2 = keyValuePair2.Value; MySerializer.Write(stream, ref value2, MyObjectBuilderSerializer.Dynamic); } } stream.WriteBool(delta.SwappedItems != null); if (delta.SwappedItems != null) { stream.WriteInt32(delta.SwappedItems.Count); foreach (var keyValuePair3 in delta.SwappedItems) { stream.WriteUInt32(keyValuePair3.Key); stream.WriteInt32(keyValuePair3.Value); } } return(delta); }
public override bool OnSave(BitStream stream) { stream.WriteInt64(Instance.Owner.Entity.EntityId); stream.WriteInt64(Instance.Id); var ob = Instance.GetObjectBuilder(); MySerializer.Write(stream, ref ob, serialInfo); return(true); }
public override bool Serialize(BitStream stream, bool validate) { if (stream.Reading) { T newValue; MySerializer.CreateAndRead(stream, out newValue, SerializeInfo); return(SetValue(ref newValue, validate)); } else { MySerializer.Write(stream, ref m_value, SerializeInfo); return(true); } }
public override bool OnSave(BitStream stream, Endpoint clientEndpoint) { var entityId = Instance.Owner.EntityId; MySerializer.Write(stream, ref entityId); var num = 0; for (var i = 0; i < Instance.Owner.InventoryCount; i++) { if (Instance == Instance.Owner.GetInventory(i)) { num = i; break; } } MySerializer.Write(stream, ref num); return(true); }
public override bool Serialize(BitStream stream, bool validate) { #if !XB1 // !XB1_SYNC_NOREFLECTION if (stream.Reading) { T newValue; MySerializer.CreateAndRead(stream, out newValue, SerializeInfo); return(SetValue(ref newValue, validate)); } else { MySerializer.Write(stream, ref m_value, SerializeInfo); return(true); } #else // XB1 System.Diagnostics.Debug.Assert(false); return(false); #endif // XB1 }
InventoryDeltaInformation PrepareSendData(ref InventoryDeltaInformation packetInfo, BitStream stream, int maxBitPosition, out bool needsSplit) { needsSplit = false; var bitPosition = stream.BitPosition; var delta = new InventoryDeltaInformation { HasChanges = false }; stream.WriteBool(false); stream.WriteUInt32(packetInfo.MessageId); stream.WriteBool(packetInfo.ChangedItems != null); if (packetInfo.ChangedItems != null) { stream.WriteInt32(packetInfo.ChangedItems.Count); if (stream.BitPosition > maxBitPosition) { needsSplit = true; } else { delta.ChangedItems = new Dictionary <uint, MyFixedPoint>(); foreach (var keyValuePair in packetInfo.ChangedItems) { stream.WriteUInt32(keyValuePair.Key); stream.WriteInt64(keyValuePair.Value.RawValue); if (stream.BitPosition <= maxBitPosition) { delta.ChangedItems[keyValuePair.Key] = keyValuePair.Value; delta.HasChanges = true; } else { needsSplit = true; } } } } stream.WriteBool(packetInfo.RemovedItems != null); if (packetInfo.RemovedItems != null) { stream.WriteInt32(packetInfo.RemovedItems.Count); if (stream.BitPosition > maxBitPosition) { needsSplit = true; } else { delta.RemovedItems = new List <uint>(); foreach (var num in packetInfo.RemovedItems) { stream.WriteUInt32(num); if (stream.BitPosition <= maxBitPosition) { delta.RemovedItems.Add(num); delta.HasChanges = true; } else { needsSplit = true; } } } } stream.WriteBool(packetInfo.NewItems != null); if (packetInfo.NewItems != null) { stream.WriteInt32(packetInfo.NewItems.Count); if (stream.BitPosition > maxBitPosition) { needsSplit = true; } else { delta.NewItems = new SortedDictionary <int, MyPhysicalInventoryItem>(); foreach (var keyValuePair2 in packetInfo.NewItems) { var value = keyValuePair2.Value; stream.WriteInt32(keyValuePair2.Key); MySerializer.Write(stream, ref value, MyObjectBuilderSerializer.Dynamic); if (stream.BitPosition <= maxBitPosition) { delta.NewItems[keyValuePair2.Key] = value; delta.HasChanges = true; } else { needsSplit = true; } } } } stream.WriteBool(packetInfo.SwappedItems != null); if (packetInfo.SwappedItems != null) { stream.WriteInt32(packetInfo.SwappedItems.Count); if (stream.BitPosition > maxBitPosition) { needsSplit = true; } else { delta.SwappedItems = new Dictionary <uint, int>(); foreach (var keyValuePair3 in packetInfo.SwappedItems) { stream.WriteUInt32(keyValuePair3.Key); stream.WriteInt32(keyValuePair3.Value); if (stream.BitPosition <= maxBitPosition) { delta.SwappedItems[keyValuePair3.Key] = keyValuePair3.Value; delta.HasChanges = true; } else { needsSplit = true; } } } } stream.SetBitPositionWrite(bitPosition); return(delta); }