diff --git a/patches/autosaving.c b/patches/autosaving.c index bcf5c3c..da46a57 100644 --- a/patches/autosaving.c +++ b/patches/autosaving.c @@ -114,7 +114,7 @@ RECOMP_PATCH void func_80147314(SramContext* sramCtx, s32 fileNum) { // @recomp Prevent owl save/autosave deletion if autosaving is enabled, and... // @recomp_use_export_var loading_deletes_owl_save: Prevent owl save deletion if mods disable it. - if (!recomp_autosave_enabled() && loading_deletes_owl_save) { + if (!recomp_get_autosave_enabled() && loading_deletes_owl_save) { gSaveContext.save.saveInfo.playerData.newf[0] = '\0'; gSaveContext.save.saveInfo.playerData.newf[1] = '\0'; gSaveContext.save.saveInfo.playerData.newf[2] = '\0'; @@ -390,7 +390,7 @@ RECOMP_EXPORT void recomp_reset_autosave_timer_slow() { void autosave_post_play_update(PlayState* play) { static int frames_since_save_changed = 0; static int frames_since_autosave_ready = 0; - if (recomp_autosave_enabled()) { + if (recomp_get_autosave_enabled()) { if (autosave_compare_saves(&gSaveContext, &prev_save_ctx)) { frames_since_save_changed = 0; Lib_MemCpy(&prev_save_ctx, &gSaveContext, offsetof(SaveContext, fileNum)); @@ -801,7 +801,7 @@ RECOMP_PATCH void ObjWarpstone_Update(Actor* thisx, PlayState* play) { } // @recomp_use_export_var loading_deletes_owl_save: Skip the text talking about the save being deleted on load, if autosave is enabled or if owl save deletion is disabled. - if (recomp_autosave_enabled() || !loading_deletes_owl_save) { + if (recomp_get_autosave_enabled() || !loading_deletes_owl_save) { if (this->isTalking && play->msgCtx.currentTextId == 0xC01 && play->msgCtx.msgBufPos == 269) { play->msgCtx.msgBufPos = 530; } diff --git a/patches/camera_patches.c b/patches/camera_patches.c index 46e018f..938b2b8 100644 --- a/patches/camera_patches.c +++ b/patches/camera_patches.c @@ -788,7 +788,7 @@ RECOMP_PATCH s32 Camera_Normal1(Camera* camera) { } // @recomp Update the analog camera. - if (recomp_analog_cam_enabled()) { + if (recomp_get_analog_cam_enabled()) { update_analog_cam(camera); if (analog_cam_active) { @@ -844,7 +844,7 @@ RECOMP_PATCH s32 Camera_Normal1(Camera* camera) { phi_f2 = (gSaveContext.save.saveInfo.playerData.health <= 0x10) ? 0.8f : 1.0f; // @recomp Don't zoom in on low health when dual analog is used - if (recomp_analog_cam_enabled()) { + if (recomp_get_analog_cam_enabled()) { phi_f2 = 1.0f; } @@ -1028,7 +1028,7 @@ RECOMP_PATCH s32 Camera_Jump2(Camera* camera) { spB4.pitch = CLAMP_MIN(spB4.pitch, -DEG_TO_BINANG(60.43f)); // @recomp Update the analog camera. - if (recomp_analog_cam_enabled()) { + if (recomp_get_analog_cam_enabled()) { update_analog_cam(camera); if (analog_cam_active) { @@ -1431,7 +1431,7 @@ RECOMP_PATCH s32 Camera_Parallel1(Camera* camera) { } // @recomp Update the analog camera. - if (recomp_analog_cam_enabled()) { + if (recomp_get_analog_cam_enabled()) { update_analog_cam(camera); if (analog_cam_active) { @@ -1654,7 +1654,7 @@ RECOMP_PATCH s32 Camera_Normal3(Camera* camera) { } // @recomp Update the analog camera. - if (recomp_analog_cam_enabled()) { + if (recomp_get_analog_cam_enabled()) { update_analog_cam(camera); if (analog_cam_active) { @@ -1892,7 +1892,7 @@ RECOMP_PATCH s32 Camera_Jump3(Camera* camera) { } // @recomp Update the analog camera. - if (recomp_analog_cam_enabled()) { + if (recomp_get_analog_cam_enabled()) { update_analog_cam(camera); if (analog_cam_active) { @@ -2006,7 +2006,7 @@ RECOMP_PATCH void func_809EC568(Boss04* this, PlayState* play) { this->unk_2D0 = 2000.0f; // @recomp do not require being in c-up mode if analog cam is enabled // also, use the new variable instead of the vanilla value to check if the player is looking at the boss. - if (((player->stateFlags1 & PLAYER_STATE1_100000) || (recomp_analog_cam_enabled())) && (this->actor.projectedPos.z > 0.0f) && + if (((player->stateFlags1 & PLAYER_STATE1_100000) || (recomp_get_analog_cam_enabled())) && (this->actor.projectedPos.z > 0.0f) && (fabsf(this->actor.projectedPos.x) < maxProjectedPosToStartFight) && (fabsf(this->actor.projectedPos.y) < maxProjectedPosToStartFight)) { if ((this->unk_704 >= 15) && (CutsceneManager_GetCurrentCsId() == CS_ID_NONE)) { Actor* boss; diff --git a/patches/effect_patches.c b/patches/effect_patches.c index 1b34a12..f267ff8 100644 --- a/patches/effect_patches.c +++ b/patches/effect_patches.c @@ -17,7 +17,7 @@ RECOMP_PATCH void TransitionWipe3_Draw(void* thisx, Gfx** gfxP) { // @recomp Modify the scale based on the aspect ratio to make sure the transition circle covers the whole screen float original_aspect_ratio = ((float)SCREEN_WIDTH) / ((float)SCREEN_HEIGHT); - scale *= recomp_get_aspect_ratio(original_aspect_ratio) / original_aspect_ratio; + scale *= recomp_get_target_aspect_ratio(original_aspect_ratio) / original_aspect_ratio; THIS->frame ^= 1; gDPPipeSync(gfx++); @@ -129,7 +129,7 @@ RECOMP_PATCH void Play_DrawMotionBlur(PlayState* this) { RECOMP_PATCH void Actor_DrawLensOverlay(Gfx** gfxP, s32 lensMaskSize) { // @recomp Calculate the increase in aspect ratio. f32 original_aspect_ratio = (float)SCREEN_WIDTH / SCREEN_HEIGHT; - f32 aspect_ratio_scale = recomp_get_aspect_ratio(original_aspect_ratio) / original_aspect_ratio; + f32 aspect_ratio_scale = recomp_get_target_aspect_ratio(original_aspect_ratio) / original_aspect_ratio; // @recomp Increase the circle's scale based on the aspect ratio scale. Also increase the base scaling // from 0.003f to 0.004f to account for overscan removal. diff --git a/patches/graphics.h b/patches/graphics.h index 5d517d7..31837f8 100644 --- a/patches/graphics.h +++ b/patches/graphics.h @@ -3,7 +3,8 @@ #include "patch_helpers.h" -DECLARE_FUNC(float, recomp_get_aspect_ratio, float); +DECLARE_FUNC(void, recomp_get_window_resolution, u32*, u32*); +DECLARE_FUNC(float, recomp_get_target_aspect_ratio, float); DECLARE_FUNC(s32, recomp_get_target_framerate, s32); DECLARE_FUNC(s32, recomp_high_precision_fb_enabled); DECLARE_FUNC(float, recomp_get_resolution_scale); diff --git a/patches/input.c b/patches/input.c index 7812dc4..3acf7a2 100644 --- a/patches/input.c +++ b/patches/input.c @@ -34,7 +34,7 @@ RECOMP_PATCH s32 func_80847190(PlayState* play, Player* this, s32 arg2) { // @recomp Get the analog camera input values if analog cam is enabled, or right-stick aiming is being forced. s32 analog_x = 0; s32 analog_y = 0; - if (recomp_analog_cam_enabled() || recomp_aiming_override_mode == RECOMP_AIMING_OVERRIDE_FORCE_RIGHT_STICK) { + if (recomp_get_analog_cam_enabled() || recomp_aiming_override_mode == RECOMP_AIMING_OVERRIDE_FORCE_RIGHT_STICK) { float analog_x_float = 0.0f; float analog_y_float = 0.0f; recomp_get_camera_inputs(&analog_x_float, &analog_y_float); @@ -198,7 +198,7 @@ RECOMP_PATCH void func_8083A98C(Actor* thisx, PlayState* play2) { // @recomp Get the analog camera input values if analog cam is enabled. s32 analog_x = 0; s32 analog_y = 0; - if (recomp_analog_cam_enabled()) { + if (recomp_get_analog_cam_enabled()) { float analog_x_float = 0.0f; float analog_y_float = 0.0f; recomp_get_camera_inputs(&analog_x_float, &analog_y_float); diff --git a/patches/input.h b/patches/input.h index efb4443..e505bfc 100644 --- a/patches/input.h +++ b/patches/input.h @@ -21,7 +21,7 @@ DECLARE_FUNC(void, recomp_get_gyro_deltas, float* x, float* y); DECLARE_FUNC(void, recomp_get_mouse_deltas, float* x, float* y); DECLARE_FUNC(s32, recomp_get_targeting_mode); DECLARE_FUNC(void, recomp_get_inverted_axes, s32* x, s32* y); -DECLARE_FUNC(s32, recomp_analog_cam_enabled); +DECLARE_FUNC(s32, recomp_get_analog_cam_enabled); DECLARE_FUNC(void, recomp_get_analog_inverted_axes, s32* x, s32* y); DECLARE_FUNC(void, recomp_get_camera_inputs, float* x, float* y); DECLARE_FUNC(void, recomp_set_right_analog_suppressed, s32 suppressed); diff --git a/patches/input_latency.c b/patches/input_latency.c index b5974f9..10c32a5 100644 --- a/patches/input_latency.c +++ b/patches/input_latency.c @@ -70,7 +70,7 @@ void poll_inputs(void) { // Begin reading controller data osContStartReadData(serialEventQueue); - bool needs_right_stick = recomp_analog_cam_enabled() || recomp_aiming_override_mode == RECOMP_AIMING_OVERRIDE_FORCE_RIGHT_STICK; + bool needs_right_stick = recomp_get_analog_cam_enabled() || recomp_aiming_override_mode == RECOMP_AIMING_OVERRIDE_FORCE_RIGHT_STICK; // Suppress the right analog stick if analog camera is active unless the ocarina is in use. recomp_set_right_analog_suppressed(needs_right_stick && sOcarinaInstrumentId == OCARINA_INSTRUMENT_OFF); // Resets this flag for the next frame; diff --git a/patches/misc_funcs.h b/patches/misc_funcs.h index 853877b..9eae368 100644 --- a/patches/misc_funcs.h +++ b/patches/misc_funcs.h @@ -10,6 +10,6 @@ DECLARE_FUNC(void, recomp_handle_quicksave_actions, OSMesgQueue* enter_mq, OSMes DECLARE_FUNC(void, recomp_handle_quicksave_actions_main, OSMesgQueue* enter_mq, OSMesgQueue* exit_mq); DECLARE_FUNC(u16, recomp_get_pending_warp); DECLARE_FUNC(u32, recomp_get_pending_set_time); -DECLARE_FUNC(s32, recomp_autosave_enabled); +DECLARE_FUNC(s32, recomp_get_autosave_enabled); #endif diff --git a/patches/sky_transform_tagging.c b/patches/sky_transform_tagging.c index c776468..dff8ca8 100644 --- a/patches/sky_transform_tagging.c +++ b/patches/sky_transform_tagging.c @@ -150,7 +150,7 @@ RECOMP_PATCH void Environment_DrawSkyboxStarsImpl(PlayState* play, Gfx** gfxP) { f32(*viewProjectionMtxF)[4]; // @recomp Get the original and actual aspect ratios. f32 original_aspect_ratio = view_aspect_ratio(&play->view); - f32 recomp_aspect_ratio = recomp_get_aspect_ratio(original_aspect_ratio); + f32 recomp_aspect_ratio = recomp_get_target_aspect_ratio(original_aspect_ratio); f32 recomp_aspect_ratio_scale = recomp_aspect_ratio / original_aspect_ratio; // @recomp Store the original billboard matrix. diff --git a/patches/syms.ld b/patches/syms.ld index af8c4f3..cd67a44 100644 --- a/patches/syms.ld +++ b/patches/syms.ld @@ -8,7 +8,7 @@ recomp_handle_quicksave_actions_main = 0x8F00000C; */ osRecvMesg_recomp = 0x8F000010; osSendMesg_recomp = 0x8F000014; recomp_get_gyro_deltas = 0x8F000018; -recomp_get_aspect_ratio = 0x8F00001C; +recomp_get_target_aspect_ratio = 0x8F00001C; recomp_get_pending_warp = 0x8F000020; recomp_powf = 0x8F000024; recomp_get_target_framerate = 0x8F000028; @@ -34,13 +34,14 @@ osContGetQuery_recomp = 0x8F00007C; recomp_get_mouse_deltas = 0x8F000080; bcmp_recomp = 0x8F000084; osGetTime_recomp = 0x8F000088; -recomp_autosave_enabled = 0x8F00008C; +recomp_get_autosave_enabled = 0x8F00008C; recomp_load_overlays = 0x8F000090; osInvalICache_recomp = 0x8F000094; -recomp_analog_cam_enabled = 0x8F000098; +recomp_get_analog_cam_enabled = 0x8F000098; recomp_get_camera_inputs = 0x8F00009C; recomp_set_right_analog_suppressed = 0x8F0000A0; recomp_get_inverted_axes = 0x8F0000A4; recomp_high_precision_fb_enabled = 0x8F0000A8; recomp_get_resolution_scale = 0x8F0000AC; recomp_get_analog_inverted_axes = 0x8F0000B0; +recomp_get_window_resolution = 0x8F0000B4; diff --git a/src/game/recomp_api.cpp b/src/game/recomp_api.cpp index 00c8f34..9ad08be 100644 --- a/src/game/recomp_api.cpp +++ b/src/game/recomp_api.cpp @@ -58,7 +58,18 @@ extern "C" void recomp_get_target_framerate(uint8_t* rdram, recomp_context* ctx) _return(ctx, ultramodern::get_target_framerate(60 / frame_divisor)); } -extern "C" void recomp_get_aspect_ratio(uint8_t* rdram, recomp_context* ctx) { +extern "C" void recomp_get_window_resolution(uint8_t* rdram, recomp_context* ctx) { + int width, height; + recompui::get_window_size(width, height); + + gpr width_out = _arg<0, PTR(u32)>(rdram, ctx); + gpr height_out = _arg<1, PTR(u32)>(rdram, ctx); + + MEM_W(0, width_out) = (u32)width; + MEM_W(0, height_out) = (u32)height; +} + +extern "C" void recomp_get_target_aspect_ratio(uint8_t* rdram, recomp_context* ctx) { ultramodern::renderer::GraphicsConfig graphics_config = ultramodern::renderer::get_graphics_config(); float original = _arg<0, float>(rdram, ctx); int width, height; @@ -91,7 +102,7 @@ extern "C" void recomp_time_us(uint8_t* rdram, recomp_context* ctx) { _return(ctx, static_cast(std::chrono::duration_cast(ultramodern::time_since_start()).count())); } -extern "C" void recomp_autosave_enabled(uint8_t* rdram, recomp_context* ctx) { +extern "C" void recomp_get_autosave_enabled(uint8_t* rdram, recomp_context* ctx) { _return(ctx, static_cast(zelda64::get_autosave_mode() == zelda64::AutosaveMode::On)); } @@ -131,7 +142,7 @@ extern "C" void recomp_get_analog_inverted_axes(uint8_t* rdram, recomp_context* *y_out = (mode == zelda64::CameraInvertMode::InvertY || mode == zelda64::CameraInvertMode::InvertBoth); } -extern "C" void recomp_analog_cam_enabled(uint8_t* rdram, recomp_context* ctx) { +extern "C" void recomp_get_analog_cam_enabled(uint8_t* rdram, recomp_context* ctx) { _return(ctx, zelda64::get_analog_cam_mode() == zelda64::AnalogCamMode::On); } diff --git a/src/main/main.cpp b/src/main/main.cpp index 8162f87..69f130c 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -29,6 +29,12 @@ #include "ovl_patches.hpp" #include "librecomp/game.hpp" #include "librecomp/mods.hpp" +#include "librecomp/helpers.hpp" + +#include "../../patches/graphics.h" +#include "../../patches/input.h" +#include "../../patches/sound.h" +#include "../../patches/misc_funcs.h" #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN @@ -540,6 +546,8 @@ void disable_texture_pack(recomp::mods::ModContext& context, const recomp::mods: zelda64::renderer::disable_texture_pack(mod); } +#define REGISTER_FUNC(name) recomp::overlays::register_base_export(#name, name) + int main(int argc, char** argv) { (void)argc; (void)argv; @@ -599,6 +607,20 @@ int main(int argc, char** argv) { recomp::register_game(game); } + REGISTER_FUNC(recomp_get_window_resolution); + REGISTER_FUNC(recomp_get_target_aspect_ratio); + REGISTER_FUNC(recomp_get_target_framerate); + REGISTER_FUNC(recomp_get_autosave_enabled); + REGISTER_FUNC(recomp_get_analog_cam_enabled); + REGISTER_FUNC(recomp_get_camera_inputs); + REGISTER_FUNC(recomp_get_targeting_mode); + REGISTER_FUNC(recomp_get_bgm_volume); + REGISTER_FUNC(recomp_get_low_health_beeps_enabled); + REGISTER_FUNC(recomp_get_gyro_deltas); + REGISTER_FUNC(recomp_get_mouse_deltas); + REGISTER_FUNC(recomp_get_inverted_axes); + REGISTER_FUNC(recomp_get_analog_inverted_axes); + zelda64::register_overlays(); zelda64::register_patches(); zelda64::load_config();