Further parse bunches till their channel receives them

This commit is contained in:
AeonLucid
2022-01-10 20:20:02 +01:00
parent f3b0a31761
commit 0a27bdd3c0
23 changed files with 1187 additions and 51 deletions
@@ -6,14 +6,46 @@ namespace Prospect.Unreal.Net.Packets.Bunch
{
public class FInBunch : FNetBitReader
{
public FInBunch(FInBunch inBunch, bool copyBuffer) : base(inBunch.PackageMap, null, 0)
{
PacketId = inBunch.PacketId;
Next = inBunch.Next;
Connection = inBunch.Connection;
ChIndex = inBunch.ChIndex;
ChType = inBunch.ChType;
ChName = inBunch.ChName;
ChSequence = inBunch.ChSequence;
bOpen = inBunch.bOpen;
bClose = inBunch.bClose;
bDormant = inBunch.bDormant;
bIsReplicationPaused = inBunch.bIsReplicationPaused;
bReliable = inBunch.bReliable;
bPartial = inBunch.bPartial;
bPartialInitial = inBunch.bPartialInitial;
bPartialFinal = inBunch.bPartialFinal;
bHasPackageMapExports = inBunch.bHasPackageMapExports;
bHasMustBeMappedGUIDs = inBunch.bHasMustBeMappedGUIDs;
bIgnoreRPCs = inBunch.bIgnoreRPCs;
CloseReason = inBunch.CloseReason;
// Copy network version info
SetEngineNetVer(inBunch.EngineNetVer());
SetGameNetVer(inBunch.GameNetVer());
if (copyBuffer)
{
throw new NotImplementedException();
}
}
public FInBunch(UNetConnection inConnection, byte[]? src = null, int countBits = 0) : base(inConnection.PackageMap, src, countBits)
{
PacketId = 0;
Next = null;
Connection = inConnection;
ChIndex = 0;
ChType = 0; // TODO: CHTYPE_None
ChName = UnrealNames.FNames[UnrealNameKey.None]; // TODO: NAME_None
ChType = EChannelType.CHTYPE_None;
ChName = UnrealNames.FNames[UnrealNameKey.None];
ChSequence = 0;
bOpen = false;
bClose = false;
@@ -41,7 +73,7 @@ namespace Prospect.Unreal.Net.Packets.Bunch
public int ChIndex { get; set; }
public int ChType { get; set; }
public EChannelType ChType { get; set; }
public FName ChName { get; set; }
@@ -71,7 +71,7 @@ public class FNetPacketNotify
var inSeqDelta = GetSequenceDelta(notificationData);
if (inSeqDelta > 0)
{
Logger.Verbose("FNetPacketNotify::Update - Seq {Seq}, InSeq {InSeq}", notificationData.Seq.Value, _inSeq.Value);
Logger.Verbose("Update - Seq {Seq}, InSeq {InSeq}", notificationData.Seq.Value, _inSeq.Value);
ProcessReceivedAcks(notificationData, func);
@@ -143,4 +143,34 @@ public class FNetPacketNotify
return new SequenceNumber((ushort)(ackedSeq.Value - MaxSequenceHistoryLength));
}
/// <summary>
/// Mark Seq as received and update current InSeq, missing sequence numbers will be marked as lost
/// </summary>
public void AckSeq(SequenceNumber seq)
{
AckSeq(seq, true);
}
/// <summary>
/// Explicitly mark Seq as not received and update current InSeq, additional missing sequence numbers will be marked as lost
/// </summary>
public void NakSeq(SequenceNumber seq)
{
AckSeq(seq, false);
}
private void AckSeq(SequenceNumber ackedSeq, bool isAck)
{
while (ackedSeq.Greater(_inAckSeq))
{
_inAckSeq.IncrementAndGet();
var bReportAcked = _inAckSeq.Equals(ackedSeq) ? isAck : false;
Logger.Verbose("AckSeq - AckedSeq: {Seq}, IsAck {IsAck}", _inAckSeq.Value, bReportAcked);
_inSeqHistory.AddDeliveryStatus(bReportAcked);
}
}
}
@@ -18,15 +18,6 @@ public readonly struct SequenceHistory
{
_storage = new uint[WordCount];
}
public void Read(FBitReader reader, uint numWords)
{
numWords = Math.Min(numWords, WordCount);
for (var i = 0; i < numWords; i++)
{
_storage[i] = reader.ReadUInt32();
}
}
public void Reset()
{
@@ -36,6 +27,20 @@ public readonly struct SequenceHistory
}
}
public void AddDeliveryStatus(bool delivered)
{
var carry = delivered ? 1u : 0u;
var valueMask = 1u << (int)(BitsPerWord - 1);
for (var i = 0; i < WordCount; i++)
{
var oldValue = carry;
carry = (_storage[i] & valueMask) >> (int)(BitsPerWord - 1);
_storage[i] = (_storage[i] << 1) | oldValue;
}
}
public bool IsDelivered(int index)
{
var wordIndex = (int)(index / BitsPerWord);
@@ -43,4 +48,13 @@ public readonly struct SequenceHistory
return (_storage[wordIndex] & wordMask) != 0;
}
public void Read(FBitReader reader, uint numWords)
{
numWords = Math.Min(numWords, WordCount);
for (var i = 0; i < numWords; i++)
{
_storage[i] = reader.ReadUInt32();
}
}
}