From 636f3128230b6717fcae1eedead110eb0ccc0d88 Mon Sep 17 00:00:00 2001 From: Mr-Wiseguy Date: Thu, 4 Apr 2024 17:24:45 -0400 Subject: [PATCH] Add debug set time hook --- include/recomp_debug.h | 1 + patches/debug_patches.c | 8 ++++++++ patches/misc_funcs.h | 1 + src/game/debug.cpp | 10 ++++++++++ src/ui/ui_config.cpp | 7 +++++++ 5 files changed, 27 insertions(+) diff --git a/include/recomp_debug.h b/include/recomp_debug.h index 3c0cfd2..df538dd 100644 --- a/include/recomp_debug.h +++ b/include/recomp_debug.h @@ -19,6 +19,7 @@ namespace recomp { extern std::vector game_warps; void do_warp(int area, int scene, int entrance); + void set_time(uint8_t hour, uint8_t minute); } #endif diff --git a/patches/debug_patches.c b/patches/debug_patches.c index 883db18..2a41df0 100644 --- a/patches/debug_patches.c +++ b/patches/debug_patches.c @@ -53,4 +53,12 @@ void debug_play_update(PlayState* play) { if (pending_warp != 0xFFFF) { do_warp(play, pending_warp); } + + u16 pending_set_time = recomp_get_pending_set_time(); + if (pending_set_time != 0xFFFF) { + u8 hour = (pending_set_time >> 8) & 0xFF; + u8 minute = (pending_set_time >> 0) & 0xFF; + + gSaveContext.save.time = CLOCK_TIME(hour, minute); + } } diff --git a/patches/misc_funcs.h b/patches/misc_funcs.h index 8890dfe..9a0f0d6 100644 --- a/patches/misc_funcs.h +++ b/patches/misc_funcs.h @@ -8,5 +8,6 @@ DECLARE_FUNC(void, recomp_exit); DECLARE_FUNC(void, recomp_handle_quicksave_actions, OSMesgQueue* enter_mq, OSMesgQueue* exit_mq); DECLARE_FUNC(void, recomp_handle_quicksave_actions_main, OSMesgQueue* enter_mq, OSMesgQueue* exit_mq); DECLARE_FUNC(u16, recomp_get_pending_warp); +DECLARE_FUNC(u16, recomp_get_pending_set_time); #endif diff --git a/src/game/debug.cpp b/src/game/debug.cpp index 28e857c..c93255b 100644 --- a/src/game/debug.cpp +++ b/src/game/debug.cpp @@ -4,6 +4,7 @@ #include "../patches/input.h" std::atomic pending_warp = 0xFFFF; +std::atomic pending_set_time = 0xFFFF; void recomp::do_warp(int area, int scene, int entrance) { const recomp::SceneWarps game_scene = recomp::game_warps[area].scenes[scene]; @@ -15,3 +16,12 @@ extern "C" void recomp_get_pending_warp(uint8_t* rdram, recomp_context* ctx) { // Return the current warp value and reset it. _return(ctx, pending_warp.exchange(0xFFFF)); } + +void recomp::set_time(uint8_t hour, uint8_t minute) { + pending_set_time.store((uint16_t(hour) << 8) | minute); +} + +extern "C" void recomp_get_pending_set_time(uint8_t* rdram, recomp_context* ctx) { + // Return the current set time value and reset it. + _return(ctx, pending_set_time.exchange(0xFFFF)); +} \ No newline at end of file diff --git a/src/ui/ui_config.cpp b/src/ui/ui_config.cpp index 419fc7c..61516b3 100644 --- a/src/ui/ui_config.cpp +++ b/src/ui/ui_config.cpp @@ -199,6 +199,8 @@ struct DebugContext { int area_index = 0; int scene_index = 0; int entrance_index = 0; + uint8_t set_time_hour = 0; + uint8_t set_time_minute = 0; bool debug_enabled = false; DebugContext() { @@ -291,6 +293,11 @@ public: [](const std::string& param, Rml::Event& event) { recomp::do_warp(debug_context.area_index, debug_context.scene_index, debug_context.entrance_index); }); + + recomp::register_event(listener, "set_time", + [](const std::string& param, Rml::Event& event) { + recomp::set_time(debug_context.set_time_hour, debug_context.set_time_minute); + }); } void bind_config_list_events(Rml::DataModelConstructor &constructor) {