Add debug set time hook

This commit is contained in:
Mr-Wiseguy 2024-04-04 17:24:45 -04:00
parent 13bb773f4d
commit 636f312823
5 changed files with 27 additions and 0 deletions

View File

@ -19,6 +19,7 @@ namespace recomp {
extern std::vector<AreaWarps> game_warps;
void do_warp(int area, int scene, int entrance);
void set_time(uint8_t hour, uint8_t minute);
}
#endif

View File

@ -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);
}
}

View File

@ -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

View File

@ -4,6 +4,7 @@
#include "../patches/input.h"
std::atomic<uint16_t> pending_warp = 0xFFFF;
std::atomic<uint16_t> 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));
}

View File

@ -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) {