52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using BoneSync.Sync;
|
|
using BoneSync.Sync.Components;
|
|
using MelonLoader;
|
|
|
|
namespace BoneSync.Networking.Messages
|
|
{
|
|
public struct DiscardSyncableMessageData
|
|
{
|
|
public ushort syncId;
|
|
public bool despawn;
|
|
}
|
|
[PacketType(PacketType.DiscardSyncable), PacketReliability(PacketReliability.ReliableFast)]
|
|
internal class DiscardSyncableMessage : NetworkMessage
|
|
{
|
|
private DiscardSyncableMessageData _data;
|
|
|
|
public DiscardSyncableMessage(DiscardSyncableMessageData discardSyncableMessageData)
|
|
{
|
|
_data = discardSyncableMessageData;
|
|
byteEncoder.WriteUShort(_data.syncId);
|
|
byteEncoder.WriteBool(_data.despawn);
|
|
}
|
|
|
|
public DiscardSyncableMessage(Packet packet)
|
|
{
|
|
byteEncoder.WriteBytes(packet.Data);
|
|
_data.syncId = byteEncoder.ReadUShort();
|
|
_data.despawn = byteEncoder.ReadBool();
|
|
}
|
|
|
|
public override void Execute()
|
|
{
|
|
Syncable syncable = ObjectSyncCache.GetSyncable(_data.syncId);
|
|
|
|
if (syncable != null)
|
|
{
|
|
syncable.DiscardSyncable(true, _data.despawn);
|
|
} else
|
|
{
|
|
MelonLogger.Warning(senderId + " tried to discard a syncable that doesn't exist (syncId: " + _data.syncId + ")");
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|