diff --git a/Core/GameEngine/Source/GameNetwork/NetCommandList.cpp b/Core/GameEngine/Source/GameNetwork/NetCommandList.cpp index 579b8578c72..ed890033cc4 100644 --- a/Core/GameEngine/Source/GameNetwork/NetCommandList.cpp +++ b/Core/GameEngine/Source/GameNetwork/NetCommandList.cpp @@ -122,6 +122,18 @@ void NetCommandList::reset() { m_lastMessageInserted = nullptr; } +static bool isCommandIdNewer(UnsignedShort newVal, UnsignedShort oldVal) +{ +#if RETAIL_COMPATIBLE_NETWORKING + return newVal > oldVal; +#else + // TheSuperHackers @info Caball009 14/06/2026 Ensure messages are sorted + // chronologically by including a command id overflow check. + const UnsignedShort diff = newVal - oldVal; + return diff != 0 && diff < 0x8000; +#endif +} + /** * Insert sorts msg. Assumes that all the previous message inserts were done using this function. * The message is sorted in based first on command type, then player id, and then command id. @@ -157,10 +169,10 @@ NetCommandRef * NetCommandList::addMessage(NetCommandRef *&msg) { NetCommandRef *theNext = m_lastMessageInserted->getNext(); if ((m_lastMessageInserted->getCommand()->getNetCommandType() == msg->getCommand()->getNetCommandType()) && (m_lastMessageInserted->getCommand()->getPlayerID() == msg->getCommand()->getPlayerID()) && - (m_lastMessageInserted->getCommand()->getID() < msg->getCommand()->getID()) && + isCommandIdNewer(msg->getCommand()->getID(), m_lastMessageInserted->getCommand()->getID()) && ((theNext == nullptr) || ((theNext->getCommand()->getNetCommandType() > msg->getCommand()->getNetCommandType()) || (theNext->getCommand()->getPlayerID() > msg->getCommand()->getPlayerID()) || - (theNext->getCommand()->getID() > msg->getCommand()->getID())))) { + isCommandIdNewer(theNext->getCommand()->getID(), msg->getCommand()->getID())))) { // Make sure this command isn't already in the list. if (isEqualCommandMsg(m_lastMessageInserted->getCommand(), msg->getCommand())) { @@ -281,7 +293,10 @@ NetCommandRef * NetCommandList::addMessage(NetCommandRef *&msg) { // Find the position within the player's section based on the command ID. // If the command type doesn't require a command ID, sort by whatever it should be sorted by. - while ((tempmsg != nullptr) && (msg->getCommand()->getNetCommandType() == tempmsg->getCommand()->getNetCommandType()) && (msg->getCommand()->getPlayerID() == tempmsg->getCommand()->getPlayerID()) && (msg->getCommand()->getSortNumber() > tempmsg->getCommand()->getSortNumber())) { + while (tempmsg != nullptr + && msg->getCommand()->getNetCommandType() == tempmsg->getCommand()->getNetCommandType() + && msg->getCommand()->getPlayerID() == tempmsg->getCommand()->getPlayerID() + && isCommandIdNewer(msg->getCommand()->getSortNumber(), tempmsg->getCommand()->getSortNumber())) { tempmsg = tempmsg->getNext(); } diff --git a/Core/GameEngine/Source/GameNetwork/Network.cpp b/Core/GameEngine/Source/GameNetwork/Network.cpp index b5501e32e26..39670637d32 100644 --- a/Core/GameEngine/Source/GameNetwork/Network.cpp +++ b/Core/GameEngine/Source/GameNetwork/Network.cpp @@ -53,7 +53,7 @@ #include "GameClient/MessageBox.h" -#if defined(DEBUG_CRC) +#if defined(DEBUG_CRC) && !RETAIL_COMPATIBLE_NETWORKING Int NET_CRC_INTERVAL = 1; #else Int NET_CRC_INTERVAL = 100; diff --git a/Core/GameEngine/Source/GameNetwork/NetworkUtil.cpp b/Core/GameEngine/Source/GameNetwork/NetworkUtil.cpp index d48280759b6..b709e670d7e 100644 --- a/Core/GameEngine/Source/GameNetwork/NetworkUtil.cpp +++ b/Core/GameEngine/Source/GameNetwork/NetworkUtil.cpp @@ -102,10 +102,10 @@ UnsignedInt ResolveIP(AsciiString host) /** * Returns the next network command ID. */ -UnsignedShort GenerateNextCommandID() { - static UnsignedShort commandID = 64000; - ++commandID; - return commandID; +static UnsignedShort s_commandID = 0; +UnsignedShort GenerateNextCommandID() +{ + return s_commandID++; } /** diff --git a/Generals/Code/GameEngine/Source/Common/CommandLine.cpp b/Generals/Code/GameEngine/Source/Common/CommandLine.cpp index 543576d78fc..8289418703a 100644 --- a/Generals/Code/GameEngine/Source/Common/CommandLine.cpp +++ b/Generals/Code/GameEngine/Source/Common/CommandLine.cpp @@ -314,7 +314,7 @@ Int parseLogObjectCRCs(char *args[], int argc) //============================================================================= Int parseNetCRCInterval(char *args[], int argc) { -#ifdef DEBUG_CRC +#if defined(DEBUG_CRC) && !RETAIL_COMPATIBLE_NETWORKING if (argc > 1) { NET_CRC_INTERVAL = atoi(args[1]); diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp index 543576d78fc..8289418703a 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp @@ -314,7 +314,7 @@ Int parseLogObjectCRCs(char *args[], int argc) //============================================================================= Int parseNetCRCInterval(char *args[], int argc) { -#ifdef DEBUG_CRC +#if defined(DEBUG_CRC) && !RETAIL_COMPATIBLE_NETWORKING if (argc > 1) { NET_CRC_INTERVAL = atoi(args[1]);