From 6c595355b6fe8d6ba9fb1217c0e963d6d4ce99f1 Mon Sep 17 00:00:00 2001 From: Hat Kid <6624576+Hat-Kid@users.noreply.github.com> Date: Sun, 3 Jul 2022 23:28:29 +0200 Subject: [PATCH] game: add real-time time of day cheat code (#1595) --- goal_src/jak1/pc/pckernel-h.gc | 1 + goal_src/jak1/pc/pckernel.gc | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/goal_src/jak1/pc/pckernel-h.gc b/goal_src/jak1/pc/pckernel-h.gc index 1ebbd18fb5..e2204e8b3e 100644 --- a/goal_src/jak1/pc/pckernel-h.gc +++ b/goal_src/jak1/pc/pckernel-h.gc @@ -123,6 +123,7 @@ (invinc) (sidekick-blue) (tunes) + (sky) ) (defmacro pc-cheats? (obj &rest cheats) diff --git a/goal_src/jak1/pc/pckernel.gc b/goal_src/jak1/pc/pckernel.gc index ac6e00b56d..d8d94279d2 100644 --- a/goal_src/jak1/pc/pckernel.gc +++ b/goal_src/jak1/pc/pckernel.gc @@ -224,7 +224,7 @@ (none)) -(define *pc-cheat-temp* (the-as (pointer int32) (malloc 'global (* 4 7)))) +(define *pc-cheat-temp* (the-as (pointer int32) (malloc 'global (* 4 8)))) (defmacro pc-cheat-toggle-and-tune (obj cheat) `(begin (cpad-clear! 0 r1) @@ -233,6 +233,11 @@ ) ) +(defun bcd->dec ((bcd uint)) + "Convert a number encoded in BCD to its decimal equivalent" + (+ (* (shr (logand bcd #xf0) 4) 10) (logand bcd #x0f)) + ) + (defmethod update pc-settings ((obj pc-settings)) "Update settings to/from PC kernel. Call this at the start of every frame. This will update things like the aspect-ratio, which will be used for graphics code later." @@ -365,6 +370,9 @@ (pc-check-cheat-code (-> *pc-cheat-temp* 6) 0 (t u n e s) (pc-cheat-toggle-and-tune obj tunes)) + + (pc-check-cheat-code (-> *pc-cheat-temp* 7) 0 (s k y) + (pc-cheat-toggle-and-tune obj sky)) ) (when *target* @@ -421,6 +429,15 @@ (set! (-> obj flava-hack) 0) ) + (if (pc-cheats? obj sky) + (let ((date (new 'stack 'scf-time))) + (scf-get-time date) + (when (zero? (-> date stat)) + (set-time-of-day (+ (the float (bcd->dec (-> date hour))) (/ (the float (bcd->dec (-> date minute))) 60))) + ) + ) + ) + (logior! (-> obj cheats-known) (-> obj cheats)) 0)