Skip to content

Commit

Permalink
Fix multiplayer KeyNotFoundException
Browse files Browse the repository at this point in the history
  • Loading branch information
ReadieFur committed Sep 18, 2021
1 parent 1c633c8 commit 2d1c913
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/Client/MapEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,35 @@ public void Initialize()

if (MainRequiredObjectsExist())
{
timer.Elapsed += TimerElapsedEvent;

beatmapObjectManager.noteWasCutEvent += NoteWasCutEvent;
beatmapObjectManager.noteWasMissedEvent += NoteWasMissedEvent;

gameEnergyCounter.gameEnergyDidChangeEvent += EnergyDidChangeEvent;

if (scoreController is ScoreController && multiplayerController is MultiplayerController) //Multiplayer
{
Plugin.Logger.Info("In multiplayer.");
scoreController.scoreDidChangeEvent += ScoreDidChangeEvent;
scoreController.immediateMaxPossibleScoreDidChangeEvent += ImmediateMaxPossibleScoreDidChangeEvent;

MapData.Reset();
LiveData.Reset();
MapData.Send();
LiveData.Send();

multiplayerController.stateChangedEvent += MultiplayerController_stateChangedEvent;
scoreController.scoreDidChangeEvent += ScoreDidChangeEvent;
scoreController.immediateMaxPossibleScoreDidChangeEvent += ImmediateMaxPossibleScoreDidChangeEvent;

MapData.IsMultiplayer = true;
}
else if (IsLegacyReplay() && relativeScoreAndImmediateRankCounter is RelativeScoreAndImmediateRankCounter && scoreUIController is ScoreUIController) //Legacy Replay
{
Plugin.Logger.Info("In legacy replay.");
relativeScoreAndImmediateRankCounter.relativeScoreOrImmediateRankDidChangeEvent += RelativeScoreOrImmediateRankDidChangeEvent;

SetupMapDataAndMisc();
LevelLoaded();

relativeScoreAndImmediateRankCounter.relativeScoreOrImmediateRankDidChangeEvent += RelativeScoreOrImmediateRankDidChangeEvent;
}
else if (scoreController is ScoreController && pauseController is PauseController && standardLevelGameplayManager is StandardLevelGameplayManager) //Singleplayer or New Replay.
{
Plugin.Logger.Info("In singleplayer.");

LevelLoaded();

//In replay mode the scorecontroller does not work so 'RelativeScoreOrImmediateRankDidChangeEvent' will read from the UI
scoreController.scoreDidChangeEvent += ScoreDidChangeEvent;
scoreController.immediateMaxPossibleScoreDidChangeEvent += ImmediateMaxPossibleScoreDidChangeEvent;
Expand All @@ -84,8 +86,6 @@ public void Initialize()

standardLevelGameplayManager.levelFailedEvent += LevelFailedEvent;
standardLevelGameplayManager.levelFinishedEvent += LevelFinishedEvent;

SetupMapDataAndMisc();
}
else
{
Expand Down Expand Up @@ -163,7 +163,7 @@ public void Dispose()
MapData.Send();
}

public void SetupMapDataAndMisc()
public void LevelLoaded()
{
PlayerData playerData = Resources.FindObjectsOfTypeAll<PlayerDataModel>().FirstOrDefault().playerData;
IBeatmapLevel levelData = gameplayCoreSceneSetupData.difficultyBeatmap.level;
Expand Down Expand Up @@ -281,6 +281,11 @@ void getBeatsaverMap()
MapData.PracticeModeModifiers.Add("startInAdvanceAndClearNotes", MapData.PracticeMode ? gameplayCoreSceneSetupData.practiceSettings.startInAdvanceAndClearNotes ? 1 : 0 : 0);
MapData.PracticeModeModifiers.Add("startSongTime", MapData.PracticeMode ? gameplayCoreSceneSetupData.practiceSettings.startSongTime : 0);

timer.Elapsed += TimerElapsedEvent;
beatmapObjectManager.noteWasCutEvent += NoteWasCutEvent;
beatmapObjectManager.noteWasMissedEvent += NoteWasMissedEvent;
gameEnergyCounter.gameEnergyDidChangeEvent += EnergyDidChangeEvent;

MapData.InLevel = true;
timer.Start();

Expand Down Expand Up @@ -312,7 +317,7 @@ private void MultiplayerController_stateChangedEvent(MultiplayerController.State
{
if (multiplayerState == MultiplayerController.State.Gameplay)
{
SetupMapDataAndMisc();
LevelLoaded();
}
else if (multiplayerState == MultiplayerController.State.Finished)
{
Expand Down

0 comments on commit 2d1c913

Please sign in to comment.