diff --git a/Generals/Code/GameEngine/Include/Common/Recorder.h b/Generals/Code/GameEngine/Include/Common/Recorder.h index 9902a18c009..48605f92209 100644 --- a/Generals/Code/GameEngine/Include/Common/Recorder.h +++ b/Generals/Code/GameEngine/Include/Common/Recorder.h @@ -39,11 +39,27 @@ class ReplayGameInfo : public GameInfo GameSlot m_ReplaySlot[MAX_SLOTS]; public: - ReplayGameInfo() + ReplayGameInfo() : m_localSlotNum(-1) { for (Int i = 0; i< MAX_SLOTS; ++i) setSlotPointer(i, &m_ReplaySlot[i]); } + + virtual void reset() override + { + GameInfo::reset(); + m_localSlotNum = -1; + } + + virtual Int getLocalSlotNum() const override + { + return isInGame() ? m_localSlotNum : -1; + } + + void setLocalSlotNum(Int slotNum) { m_localSlotNum = slotNum; } + +private: + Int m_localSlotNum; }; enum RecorderModeType CPP_11(: Int) { diff --git a/Generals/Code/GameEngine/Source/Common/Recorder.cpp b/Generals/Code/GameEngine/Source/Common/Recorder.cpp index 91c44c437c8..21d7801a694 100644 --- a/Generals/Code/GameEngine/Source/Common/Recorder.cpp +++ b/Generals/Code/GameEngine/Source/Common/Recorder.cpp @@ -926,6 +926,8 @@ Bool RecorderClass::readReplayHeader(ReplayHeader& header, const AsciiString& fi m_file = nullptr; return FALSE; } + // TheSuperHackers @bugfix bobtista 17/09/2026 Preserve the recorded local slot, including -1 for no local player. + m_gameInfo.setLocalSlotNum(header.localPlayerIndex); if (header.localPlayerIndex >= 0) { Int localIP = m_gameInfo.getSlot(header.localPlayerIndex)->getIP(); @@ -1202,16 +1204,17 @@ Bool RecorderClass::playbackFile(AsciiString filename) } #endif - Bool isMultiplayer = m_gameInfo.getSlot(header.localPlayerIndex)->getIP() != 0; - m_crcInfo = CRCInfo(header.localPlayerIndex, isMultiplayer); REPLAY_CRC_INTERVAL = m_gameInfo.getCRCInterval(); - DEBUG_LOG(("Player index is %d, replay CRC interval is %d", m_crcInfo.getLocalPlayer(), REPLAY_CRC_INTERVAL)); Int difficulty = 0; m_file->read(&difficulty, sizeof(difficulty)); m_file->read(&m_originalGameMode, sizeof(m_originalGameMode)); + const Bool isMultiplayer = m_originalGameMode == GAME_LAN || m_originalGameMode == GAME_INTERNET; + m_crcInfo = CRCInfo(header.localPlayerIndex, isMultiplayer); + DEBUG_LOG(("Player index is %d, replay CRC interval is %d", m_crcInfo.getLocalPlayer(), REPLAY_CRC_INTERVAL)); + Int rankPoints = 0; m_file->read(&rankPoints, sizeof(rankPoints)); diff --git a/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index 932caa24f82..118cc3a898b 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -1315,7 +1315,8 @@ void GameLogic::tryStartNewGame( Bool loadingSaveGame ) d.setInt(TheKey_multiplayerStartIndex, slot->getStartPos()); // d.setBool(TheKey_multiplayerIsLocal, slot->isLocalPlayer()); // d.setBool(TheKey_multiplayerIsLocal, slot->getIP() == game->getLocalIP()); - d.setBool(TheKey_multiplayerIsLocal, slot->isHuman() && (slot->getName().compare(TheGameInfo->getSlot(TheGameInfo->getLocalSlotNum())->getName().str()) == 0)); + const Bool isLocalPlayer = slot->isHuman() && i == TheGameInfo->getLocalSlotNum(); + d.setBool(TheKey_multiplayerIsLocal, isLocalPlayer); /* if (slot->getIP() == game->getLocalIP()) @@ -1336,9 +1337,8 @@ void GameLogic::tryStartNewGame( Bool loadingSaveGame ) } } - AsciiString slotNameAscii; - slotNameAscii.translate(slot->getName()); - if (slot->isHuman() && TheGameInfo->getSlotNum(slotNameAscii) == TheGameInfo->getLocalSlotNum()) { + if (isLocalPlayer) + { localSlot = i; } TheSidesList->addSide(&d); diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h b/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h index 2149dd2caf0..766aa3b9216 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/Recorder.h @@ -39,11 +39,27 @@ class ReplayGameInfo : public GameInfo GameSlot m_ReplaySlot[MAX_SLOTS]; public: - ReplayGameInfo() + ReplayGameInfo() : m_localSlotNum(-1) { for (Int i = 0; i< MAX_SLOTS; ++i) setSlotPointer(i, &m_ReplaySlot[i]); } + + virtual void reset() override + { + GameInfo::reset(); + m_localSlotNum = -1; + } + + virtual Int getLocalSlotNum() const override + { + return isInGame() ? m_localSlotNum : -1; + } + + void setLocalSlotNum(Int slotNum) { m_localSlotNum = slotNum; } + +private: + Int m_localSlotNum; }; enum RecorderModeType CPP_11(: Int) { diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp index 8b9ecc5acbb..68b31530c64 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp @@ -928,6 +928,8 @@ Bool RecorderClass::readReplayHeader(ReplayHeader& header, const AsciiString& fi m_file = nullptr; return FALSE; } + // TheSuperHackers @bugfix bobtista 17/09/2026 Preserve the recorded local slot, including -1 for no local player. + m_gameInfo.setLocalSlotNum(header.localPlayerIndex); if (header.localPlayerIndex >= 0) { Int localIP = m_gameInfo.getSlot(header.localPlayerIndex)->getIP(); @@ -1205,16 +1207,17 @@ Bool RecorderClass::playbackFile(AsciiString filename) } #endif - Bool isMultiplayer = m_gameInfo.getSlot(header.localPlayerIndex)->getIP() != 0; - m_crcInfo = CRCInfo(header.localPlayerIndex, isMultiplayer); REPLAY_CRC_INTERVAL = m_gameInfo.getCRCInterval(); - DEBUG_LOG(("Player index is %d, replay CRC interval is %d", m_crcInfo.getLocalPlayer(), REPLAY_CRC_INTERVAL)); Int difficulty = 0; m_file->read(&difficulty, sizeof(difficulty)); m_file->read(&m_originalGameMode, sizeof(m_originalGameMode)); + const Bool isMultiplayer = m_originalGameMode == GAME_LAN || m_originalGameMode == GAME_INTERNET; + m_crcInfo = CRCInfo(header.localPlayerIndex, isMultiplayer); + DEBUG_LOG(("Player index is %d, replay CRC interval is %d", m_crcInfo.getLocalPlayer(), REPLAY_CRC_INTERVAL)); + Int rankPoints = 0; m_file->read(&rankPoints, sizeof(rankPoints)); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index 60bae04f186..dec2e14cc76 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -1476,7 +1476,8 @@ void GameLogic::tryStartNewGame( Bool loadingSaveGame ) d.setInt(TheKey_multiplayerStartIndex, slot->getStartPos()); // d.setBool(TheKey_multiplayerIsLocal, slot->isLocalPlayer()); // d.setBool(TheKey_multiplayerIsLocal, slot->getIP() == game->getLocalIP()); - d.setBool(TheKey_multiplayerIsLocal, slot->isHuman() && (slot->getName().compare(TheGameInfo->getSlot(TheGameInfo->getLocalSlotNum())->getName().str()) == 0)); + const Bool isLocalPlayer = slot->isHuman() && i == TheGameInfo->getLocalSlotNum(); + d.setBool(TheKey_multiplayerIsLocal, isLocalPlayer); /* if (slot->getIP() == game->getLocalIP()) @@ -1497,9 +1498,8 @@ void GameLogic::tryStartNewGame( Bool loadingSaveGame ) } } - AsciiString slotNameAscii; - slotNameAscii.translate(slot->getName()); - if (slot->isHuman() && TheGameInfo->getSlotNum(slotNameAscii) == TheGameInfo->getLocalSlotNum()) { + if (isLocalPlayer) + { localSlot = i; } TheSidesList->addSide(&d);