From 0ab252d39d5d4ea0f1c56a7f06d0f3d3ea294d61 Mon Sep 17 00:00:00 2001 From: Matt Dallmeyer Date: Thu, 19 Jun 2025 08:47:42 -0700 Subject: [PATCH] [jak1] Fix speedrun mode bug where loading a save is counted as new run (#3960) Fixes a small bug introduced in #3902. Without this change, whenever you load a save it is treated as if you started a new game and resets the autosplitter back to 0s. --- goal_src/jak1/engine/game/game-save.gc | 4 ++++ goal_src/jak1/pc/features/speedruns.gc | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/goal_src/jak1/engine/game/game-save.gc b/goal_src/jak1/engine/game/game-save.gc index eb1d4e9bb9..30fa51e2dd 100644 --- a/goal_src/jak1/engine/game/game-save.gc +++ b/goal_src/jak1/engine/game/game-save.gc @@ -16,6 +16,7 @@ ;; Having two state machines, one in C++ and one in GOAL is kind of a questionable and confusing design. +(define-extern mark-speedrun-started (function none)) ;; DECOMP BEGINS ;; version identifier @@ -607,6 +608,9 @@ (set! save-data (the-as game-save-tag (&+ (the-as pointer save-data) (logand -16 (+ (* (the-as int (-> save-data elt-size)) (-> save-data elt-count)) 31))))))) + ;; og:preserve-this make sure loading a save doesn't reset speedrun state + (when (and (-> *pc-settings* speedrunner-mode?) (zero? (-> save new-game))) + (mark-speedrun-started)) ;; if we're a new game, set our checkpoint. (when (nonzero? (-> save new-game)) (set-continue! this "game-start") diff --git a/goal_src/jak1/pc/features/speedruns.gc b/goal_src/jak1/pc/features/speedruns.gc index 1218293c08..c958eb51bb 100644 --- a/goal_src/jak1/pc/features/speedruns.gc +++ b/goal_src/jak1/pc/features/speedruns.gc @@ -385,6 +385,10 @@ (set! (-> *speedrun-info* should-display?) #f) (none)) +(defun mark-speedrun-started () + (true! (-> *speedrun-info* has-started?)) + (none)) + (defun speedrun-mode-update () "A per frame update for speedrunning related stuff" (when (-> *pc-settings* speedrunner-mode?) @@ -397,7 +401,7 @@ ;; target has landed on ground/water, or we're about to enter target-hit-ground state (or (logtest? (-> *target* control status) (cshape-moving-flags onground onsurf on-water)) (= (-> *target* next-state name) 'target-hit-ground))) - (true! (-> *speedrun-info* has-started?)) + (mark-speedrun-started) ;; spawn a process that resets autosplitter after suspending for 1 frame (process-spawn-function process (lambda ()