From 6998088f643257a609da7cf6452fb6911ef005c2 Mon Sep 17 00:00:00 2001 From: Dan Guzek Date: Tue, 24 Nov 2015 18:03:16 -0500 Subject: [PATCH] handle negative StageTokens for not-EventMode As the inline comment states: This is somewhat hackish, but it serves to counteract Lua Hacks. If ScreenGameplay was reloaded by a "gimmick" chart, then it is very possible that the Engine's concept of remaining stages will be incongruent with the Theme's. Add stages back, Engine-side, if necessary. This prevents us from returning to ScreenSelectMusic with negative stage tokens (engine-side) which manifests as an empty MusicWheel. --- Scripts/SL-Branches.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Scripts/SL-Branches.lua b/Scripts/SL-Branches.lua index 1b91cdb..0a8d921 100644 --- a/Scripts/SL-Branches.lua +++ b/Scripts/SL-Branches.lua @@ -84,6 +84,21 @@ Branch.AfterProfileSave = function() SL.Global.Stages.Remaining = SL.Global.Stages.Remaining + StagesToAddBack end + + -- This is somewhat hackish, but it serves to counteract Lua Hacks. + -- If ScreenGameplay was reloaded by a "gimmick" chart, then it is + -- very possible that the Engine's concept of remaining stages will + -- be incongruent with the Theme's. Add stages back, engine-side, if necessary. + if GAMESTATE:GetNumStagesLeft(GAMESTATE:GetMasterPlayerNumber()) < SL.Global.Stages.Remaining then + StagesToAddBack = math.abs(SL.Global.Stages.Remaining - GAMESTATE:GetNumStagesLeft(GAMESTATE:GetMasterPlayerNumber())) + local Players = GAMESTATE:GetHumanPlayers() + for pn in ivalues(Players) do + for i=1, StagesToAddBack do + GAMESTATE:AddStageToPlayer(pn) + end + end + end + -- If we don't allow players to fail out of a set early if ThemePrefs.Get("AllowFailingOutOfSet") == false then