From 3ce7f5998997d19a0daccc03c77c4f3c2f8a6703 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Fri, 10 Mar 2023 03:47:35 +0000 Subject: [PATCH] [jak1] fix concerning `game-save` bug (#2311) Not really sure if this actually caused any issues in-game, but better safe thatn sorry. --- goal_src/jak1/engine/game/game-save.gc | 7 ++++++- goal_src/jak1/engine/load/loader-h.gc | 2 ++ goal_src/jak1/engine/load/loader.gc | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/goal_src/jak1/engine/game/game-save.gc b/goal_src/jak1/engine/game/game-save.gc index da46bd5692..daf5cee7e9 100644 --- a/goal_src/jak1/engine/game/game-save.gc +++ b/goal_src/jak1/engine/game/game-save.gc @@ -1528,7 +1528,12 @@ ) (let ((gp-0 (the-as object loading-level))) (set! loading-level (-> self buffer)) - (set! (-> self save) (new 'loading-level 'game-save #x10000)) + ;; pc port note : the original game used 64K here's which is slightly too small for the save file. + ;; the buffer being used here is one of the spool buffers which are much larger + ;; this means that the original game only cleared the first 64K of that buffer when allocating + ;; a new save file which would leave the last parts to be filled with garbage, which may or may not cause issues. + ;; for the port we clear the entire spool buffer instead, entirely bypassing this potential issue. + (set! (-> self save) (new 'loading-level 'game-save SPOOL_HEAP_SIZE)) (save-game! *game-info* (-> self save) "save") (set! loading-level (the-as kheap gp-0)) 0 diff --git a/goal_src/jak1/engine/load/loader-h.gc b/goal_src/jak1/engine/load/loader-h.gc index 1a148292d1..40fa94b5bd 100644 --- a/goal_src/jak1/engine/load/loader-h.gc +++ b/goal_src/jak1/engine/load/loader-h.gc @@ -14,6 +14,8 @@ (defconstant SPOOL_PRIORITY_HIGHEST -20.0) (defconstant SPOOL_PRIORITY_HIGH -10.0) +(defconstant SPOOL_HEAP_SIZE (* 247 1024)) ;; size of the heap to be used for each spool + ;; A load-dir is a collection of references to loaded art. ;; This type didn't have a nomral inspect method, so these field names are made up. diff --git a/goal_src/jak1/engine/load/loader.gc b/goal_src/jak1/engine/load/loader.gc index 9fbcc9245e..0f219f6c63 100644 --- a/goal_src/jak1/engine/load/loader.gc +++ b/goal_src/jak1/engine/load/loader.gc @@ -358,9 +358,9 @@ (let ((v1-11 (-> obj heap))) ;; Scary: this is a hard coded address that points to the kernel memory. ;; it turns out the kernel doesn't need this. So we can use it! - (set! (-> v1-11 base) (the-as pointer (+ #x84000 (* #x3dc00 (-> obj index))))) + (set! (-> v1-11 base) (the-as pointer (+ #x84000 (* SPOOL_HEAP_SIZE (-> obj index))))) (set! (-> v1-11 current) (-> v1-11 base)) - (set! (-> v1-11 top-base) (&+ (-> v1-11 base) #x3dc00)) + (set! (-> v1-11 top-base) (&+ (-> v1-11 base) SPOOL_HEAP_SIZE)) (set! (-> v1-11 top) (-> v1-11 top-base)) ) (set! (-> obj status) 'inactive)