Don't crash when reloading songs with players joined
This allows to call ScreenReloadSongs from SSM.
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
#include "GameManager.h"
|
#include "GameManager.h"
|
||||||
#include "GameState.h"
|
#include "GameState.h"
|
||||||
#include "LocalizedString.h"
|
#include "LocalizedString.h"
|
||||||
|
#include "MemoryCardManager.h"
|
||||||
#include "MsdFile.h"
|
#include "MsdFile.h"
|
||||||
#include "NoteSkinManager.h"
|
#include "NoteSkinManager.h"
|
||||||
#include "NotesLoaderDWI.h"
|
#include "NotesLoaderDWI.h"
|
||||||
@@ -37,6 +38,8 @@
|
|||||||
#include "UnlockManager.h"
|
#include "UnlockManager.h"
|
||||||
#include "SpecialFiles.h"
|
#include "SpecialFiles.h"
|
||||||
|
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
SongManager* SONGMAN = nullptr; // global and accessible from anywhere in our program
|
SongManager* SONGMAN = nullptr; // global and accessible from anywhere in our program
|
||||||
|
|
||||||
/** @brief The file that contains various random attacks. */
|
/** @brief The file that contains various random attacks. */
|
||||||
@@ -121,6 +124,39 @@ void SongManager::Reload( bool bAllowFastLoad, LoadingWindow *ld )
|
|||||||
|
|
||||||
// save scores before unloading songs, or the scores will be lost
|
// save scores before unloading songs, or the scores will be lost
|
||||||
PROFILEMAN->SaveMachineProfile();
|
PROFILEMAN->SaveMachineProfile();
|
||||||
|
GAMESTATE->SavePlayerProfiles();
|
||||||
|
|
||||||
|
std::vector<std::tuple<PlayerNumber, RString, bool>> rejoinPlayers;
|
||||||
|
FOREACH_HumanPlayer(pn)
|
||||||
|
{
|
||||||
|
if (GAMESTATE->m_bSideIsJoined[pn])
|
||||||
|
{
|
||||||
|
if (PROFILEMAN->ProfileWasLoadedFromMemoryCard(pn))
|
||||||
|
{
|
||||||
|
rejoinPlayers.push_back(std::make_tuple(pn, RString(""), true));
|
||||||
|
}
|
||||||
|
else if (PROFILEMAN->IsPersistentProfile(pn))
|
||||||
|
{
|
||||||
|
int numLocalProfiles = PROFILEMAN->GetNumLocalProfiles();
|
||||||
|
for (int i = 0; i < numLocalProfiles; i++)
|
||||||
|
{
|
||||||
|
Profile *profile = PROFILEMAN->GetLocalProfileFromIndex(i);
|
||||||
|
if (profile->m_sGuid == PROFILEMAN->GetProfile(pn)->m_sGuid)
|
||||||
|
{
|
||||||
|
RString profileID = PROFILEMAN->GetLocalProfileIDFromIndex(i);
|
||||||
|
rejoinPlayers.push_back(std::make_tuple(pn, profileID, false));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rejoinPlayers.push_back(std::make_tuple(pn, RString(""), false));
|
||||||
|
}
|
||||||
|
GAMESTATE->UnjoinPlayer(pn);
|
||||||
|
PROFILEMAN->UnloadProfile(pn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if( ld )
|
if( ld )
|
||||||
ld->SetText( UNLOADING_COURSES );
|
ld->SetText( UNLOADING_COURSES );
|
||||||
@@ -140,6 +176,31 @@ void SongManager::Reload( bool bAllowFastLoad, LoadingWindow *ld )
|
|||||||
|
|
||||||
// reload scores and unlocks afterward
|
// reload scores and unlocks afterward
|
||||||
PROFILEMAN->LoadMachineProfile();
|
PROFILEMAN->LoadMachineProfile();
|
||||||
|
MEMCARDMAN->WaitForCheckingToComplete();
|
||||||
|
for (auto& it : rejoinPlayers)
|
||||||
|
{
|
||||||
|
PlayerNumber pn;
|
||||||
|
RString profileID;
|
||||||
|
bool isMemoryCard;
|
||||||
|
std::tie(pn, profileID, isMemoryCard) = it;
|
||||||
|
|
||||||
|
GAMESTATE->JoinPlayer(pn);
|
||||||
|
if (isMemoryCard)
|
||||||
|
{
|
||||||
|
bool success = MEMCARDMAN->MountCard(pn);
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
PROFILEMAN->LoadProfileFromMemoryCard(pn, true);
|
||||||
|
MEMCARDMAN->UnmountCard(pn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PROFILEMAN->m_sDefaultLocalProfileID[pn].Set(profileID);
|
||||||
|
PROFILEMAN->LoadLocalProfileFromMachine(pn);
|
||||||
|
}
|
||||||
|
GAMESTATE->LoadCurrentSettingsFromProfile(pn);
|
||||||
|
}
|
||||||
UNLOCKMAN->Reload();
|
UNLOCKMAN->Reload();
|
||||||
|
|
||||||
if( !bAllowFastLoad )
|
if( !bAllowFastLoad )
|
||||||
|
|||||||
Reference in New Issue
Block a user