DEV9: Move and fix GetDelta Function

This commit is contained in:
TheLastRar 2024-04-06 19:16:32 +01:00 committed by lightningterror
parent 569b93da51
commit 8a14552e56
3 changed files with 21 additions and 12 deletions

View File

@ -68,6 +68,24 @@ namespace Sessions
{
}
s32 TCP_Session::GetDelta(u32 a, u32 b)
{
s64 delta = static_cast<s64>(a) - static_cast<s64>(b);
if (delta > 0.5 * UINT_MAX)
{
delta = -static_cast<s64>(UINT_MAX) + a - b - 1;
Console.Error("DEV9: TCP: [PS2] SequenceNumber Overflow Detected");
Console.Error("DEV9: TCP: [PS2] New Data Offset: %d bytes", delta);
}
if (delta < -0.5 * UINT_MAX)
{
delta = UINT_MAX - b + a + 1;
Console.Error("DEV9: TCP: [PS2] SequenceNumber Overflow Detected");
Console.Error("DEV9: TCP: [PS2] New Data Offset: %d bytes", delta);
}
return delta;
}
TCP_Packet* TCP_Session::CreateBasePacket(PayloadData* data)
{
//DevCon.WriteLn("Creating Base Packet");

View File

@ -95,7 +95,7 @@ namespace Sessions
NumCheckResult CheckRepeatSYNNumbers(PacketReader::IP::TCP::TCP_Packet* tcp);
NumCheckResult CheckNumbers(PacketReader::IP::TCP::TCP_Packet* tcp);
u32 GetDelta(u32 parExpectedSeq, u32 parGotSeq);
s32 GetDelta(u32 a, u32 b); //Returns a - b
//Returns true if errored
bool ErrorOnNonEmptyPacket(PacketReader::IP::TCP::TCP_Packet* tcp);

View File

@ -308,7 +308,9 @@ namespace Sessions
windowSize.store(tcp->windowSize << windowScale);
const NumCheckResult Result = CheckNumbers(tcp);
//Check if we already have some of the data sent
const uint delta = GetDelta(expectedSeqNumber, tcp->sequenceNumber);
pxAssert(delta >= 0);
//if (Result == NumCheckResult::GotOldData)
//{
// DevCon.WriteLn("[PS2] New Data Offset: %d bytes", delta);
@ -464,17 +466,6 @@ namespace Sessions
return NumCheckResult::OK;
}
u32 TCP_Session::GetDelta(u32 parExpectedSeq, u32 parGotSeq)
{
u32 delta = parExpectedSeq - parGotSeq;
if (delta > 0.5 * UINT_MAX)
{
delta = UINT_MAX - parExpectedSeq + parGotSeq;
Console.Error("DEV9: TCP: [PS2] SequenceNumber Overflow Detected");
Console.Error("DEV9: TCP: [PS2] New Data Offset: %d bytes", delta);
}
return delta;
}
bool TCP_Session::ErrorOnNonEmptyPacket(TCP_Packet* tcp)
{
NumCheckResult ResultFIN = CheckNumbers(tcp);