Skip to content

Commit

Permalink
Add basic crash recovery mode
Browse files Browse the repository at this point in the history
  • Loading branch information
thearst3rd committed Jun 24, 2023
1 parent 8037327 commit 4ed9045
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ screenshot_*.png
testMission.mis
WEprefs.cs
DeleteDSOs.bat
rtaProgress.cs

# Specific paths
Marble Blast Platinum/packages
Expand Down
1 change: 1 addition & 0 deletions Marble Blast Platinum/platinum/main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ function onExit() {
export("$LBPref::*", "~/client/lbprefs.cs", False);

MPsavePrefs();
RtaSpeedrun.saveProgress();

//So we don't hear the menu when we quit
alxSetChannelVolume(1, 0);
Expand Down
64 changes: 62 additions & 2 deletions Marble Blast Platinum/platinum/server/scripts/rtaspeedrun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ class = "RtaSpeedrun";
%this.currentGameDuration = -1;

%this.smartHideSplits = true;
if (%this.loadProgress()) {
ASSERT("RTA Speedrun Recovery", "RTA Speedrun in-progress detected!\nResume the next level to continue the speedrun.");
%this.setIsCrashRecoveryMode(true);
%this.updateTimers();
}
%this.setIsValid(true);
}
RtaSpeedrun.create();
RtaSpeedrun.schedule(100, create);


function RtaSpeedrun::onFrameAdvance(%this, %timeDelta) {
if (%this.isEnabled && !($Client::Loading || $Game::Loading || $Menu::Loading)) {
Expand All @@ -65,7 +71,7 @@ function onFrameAdvance(%timeDelta) {

function RtaSpeedrun::updateTimers(%this) {
if (!%this.isEnabled && !%this.isDone) {
if (%this.shouldStartRun)
if (%this.shouldStartRun || %this.isCrashRecoveryMode)
%this.setTimerText(formatTimeHoursMs(%this.time));
else
%this.setTimerText("");
Expand Down Expand Up @@ -137,7 +143,9 @@ function onFrameAdvance(%timeDelta) {
%this.setShouldStartRun(false);
%this.setIsEnabled(false);
%this.setIsDone(false);
%this.setIsCrashRecoveryMode(false);
%this.updateTimers();
%this.clearProgress();
}

function RtaSpeedrun::setEnd(%this) {
Expand All @@ -147,6 +155,11 @@ function onFrameAdvance(%timeDelta) {

function RtaSpeedrun::missionStarted(%this) {
RTAAS_setCurrentMission($Server::MissionFile);
if (%this.isCrashRecoveryMode) {
echo("Crash recovery run resumed!");
%this.setIsCrashRecoveryMode(false);
%this.setIsEnabled(true);
}
if (%this.shouldStartRun && !%this.isEnabled) {
echo("Speedrun mode began timing!");
%this.setIsEnabled(true);
Expand All @@ -166,6 +179,7 @@ function onFrameAdvance(%timeDelta) {
%this.setCurrentGameBeganTime(%this.time);
}
%this.updateTimers();
%this.saveProgress();
}

function RtaSpeedrun::missionEnded(%this) {
Expand All @@ -176,6 +190,7 @@ function onFrameAdvance(%timeDelta) {
echo("Final time:" SPC %this.time);
%this.setIsEnabled(false);
%this.setIsDone(true);
%this.clearProgress();
}
%isEndOfMissionType = false;
%isEndOfCurrentGame = false;
Expand All @@ -199,6 +214,7 @@ function onFrameAdvance(%timeDelta) {
if (%isEndOfCurrentGame)
%this.currentGameDuration = sub64_int(%this.time, %this.currentGameBeganTime);
%this.updateTimers();
%this.saveProgress();
}

function RtaSpeedrun::pauseGame(%this) {
Expand Down Expand Up @@ -237,6 +253,46 @@ function onFrameAdvance(%timeDelta) {
return false;
}

function RtaSpeedrun::saveProgress(%this) {
if (%this.isCrashRecoveryMode)
return;
if (!%this.isEnabled) {
%this.clearProgress();
return;
}
$RtaProgress::time = %this.time;
$RtaProgress::endMission = %this.endMission;
$RtaProgress::missionType = %this.missionType;
$RtaProgress::missionTypeBeganTime = %this.missionTypeBeganTime;
$RtaProgress::currentGame = %this.currentGame;
$RtaProgress::currentGameBeganTime = %this.currentGameBeganTime;
export("$RtaProgress::*", "~/client/rtaProgress.cs", False);
}

function RtaSpeedrun::loadProgress(%this) {
%progressFile = "platinum/client/rtaProgress.cs";
if (!isFile(%progressFile)) {
return false;
}
exec(%progressFile);
%this.setTime($RtaProgress::time);
%this.endMission = $RtaProgress::endMission;
%this.missionType = $RtaProgress::missionType;
%this.missionTypeBeganTime = $RtaProgress::missionTypeBeganTime;
%this.currentGame = $RtaProgress::currentGame;
%this.currentGameBeganTime = $RtaProgress::currentGameBeganTime;
echo("Loaded" SPC %progressFile @ ", RTA Speedrun in progress!!!");
return true;
}

function RtaSpeedrun::clearProgress(%this) {
%progressFile = "platinum/client/rtaProgress.cs";
if (isFile(%progressFile))
deleteFile(%progressFile);
if (isFile(%progressFile @ ".dso"))
deleteFile(%progressFile @ ".dso");
}

// Setters for most properties, to update the RTAAutosplitter plugin's values as well
function RtaSpeedrun::setIsValid(%this, %isValid) {
%this.isValid = %isValid;
Expand All @@ -254,6 +310,10 @@ function onFrameAdvance(%timeDelta) {
%this.shouldStartRun = %shouldStartRun;
RTAAS_setShouldStartRun(%this.shouldStartRun);
}
function RtaSpeedrun::setIsCrashRecoveryMode(%this, %isCrashRecoveryMode) {
%this.isCrashRecoveryMode = %isCrashRecoveryMode;
RTAAS_setIsCrashRecoveryMode(%this.isCrashRecoveryMode);
}
function RtaSpeedrun::setTime(%this, %time) {
%this.time = %time;
RTAAS_setTime(%this.time);
Expand Down

0 comments on commit 4ed9045

Please sign in to comment.