From 587b22248304b080384d1d875a16f7ae18f92415 Mon Sep 17 00:00:00 2001 From: Hyper <34012267+hyperbx@users.noreply.github.com> Date: Sun, 15 Dec 2024 01:44:01 +0000 Subject: [PATCH] Implemented D-Pad player input This is mainly beneficial for 2D sections with PlayStation controllers where the D-Pad may be more preferable, but it also works in 3D too. --- UnleashedRecomp/CMakeLists.txt | 1 + UnleashedRecomp/locale/config_locale.h | 5 ++++ UnleashedRecomp/patches/player_patches.cpp | 20 ++++++++++++++++ UnleashedRecomp/ui/options_menu.cpp | 1 + UnleashedRecomp/ui/options_menu_thumbnails.h | 2 ++ UnleashedRecomp/user/config.h | 1 + UnleashedRecompLib/config/SWA.toml | 24 ++++++++++++++++++++ UnleashedRecompResources | 2 +- 8 files changed, 55 insertions(+), 1 deletion(-) diff --git a/UnleashedRecomp/CMakeLists.txt b/UnleashedRecomp/CMakeLists.txt index 79e04da..b45e186 100644 --- a/UnleashedRecomp/CMakeLists.txt +++ b/UnleashedRecomp/CMakeLists.txt @@ -378,6 +378,7 @@ BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/in BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/installer/pulse_install.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/installer/pulse_install.dds" ARRAY_NAME "g_pulse_install" COMPRESSION_TYPE "zstd") BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/options_menu/thumbnails/achievement_notifications.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/options_menu/thumbnails/achievement_notifications.dds" ARRAY_NAME "g_achievement_notifications" COMPRESSION_TYPE "zstd") BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/options_menu/thumbnails/allow_background_input.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/options_menu/thumbnails/allow_background_input.dds" ARRAY_NAME "g_allow_background_input" COMPRESSION_TYPE "zstd") +BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/options_menu/thumbnails/allow_dpad_movement.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/options_menu/thumbnails/allow_dpad_movement.dds" ARRAY_NAME "g_allow_dpad_movement" COMPRESSION_TYPE "zstd") BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/options_menu/thumbnails/antialiasing.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/options_menu/thumbnails/antialiasing.dds" ARRAY_NAME "g_antialiasing" COMPRESSION_TYPE "zstd") BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/options_menu/thumbnails/aspect_ratio.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/options_menu/thumbnails/aspect_ratio.dds" ARRAY_NAME "g_aspect_ratio" COMPRESSION_TYPE "zstd") BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/options_menu/thumbnails/battle_theme.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/options_menu/thumbnails/battle_theme.dds" ARRAY_NAME "g_battle_theme" COMPRESSION_TYPE "zstd") diff --git a/UnleashedRecomp/locale/config_locale.h b/UnleashedRecomp/locale/config_locale.h index a06d2ab..6a9d0d7 100644 --- a/UnleashedRecomp/locale/config_locale.h +++ b/UnleashedRecomp/locale/config_locale.h @@ -142,6 +142,11 @@ CONFIG_DEFINE_LOCALE(AllowBackgroundInput) { ELanguage::English, { "Allow Background Input", "Accept controller input whilst the game window is unfocused." } } }; +CONFIG_DEFINE_LOCALE(AllowDPadMovement) +{ + { ELanguage::English, { "Allow D-Pad Movement", "Allow the player to also be controlled using the directional pad." } } +}; + CONFIG_DEFINE_LOCALE(MusicVolume) { { ELanguage::English, { "Music Volume", "Adjust the volume for the music." } } diff --git a/UnleashedRecomp/patches/player_patches.cpp b/UnleashedRecomp/patches/player_patches.cpp index c3699fd..dfa1142 100644 --- a/UnleashedRecomp/patches/player_patches.cpp +++ b/UnleashedRecomp/patches/player_patches.cpp @@ -9,6 +9,26 @@ uint32_t m_lastCheckpointScore = 0; float m_lastDarkGaiaEnergy = 0.0f; bool m_isUnleashCancelled = false; +void PostureDPadSupportMidAsmHook(PPCRegister& r3) +{ + if (!Config::AllowDPadMovement) + return; + + auto pPadState = (SWA::SPadState*)g_memory.Translate(r3.u32); + + if (pPadState->IsDown(SWA::eKeyState_DpadUp)) + pPadState->LeftStickVertical = 1.0f; + + if (pPadState->IsDown(SWA::eKeyState_DpadDown)) + pPadState->LeftStickVertical = -1.0f; + + if (pPadState->IsDown(SWA::eKeyState_DpadLeft)) + pPadState->LeftStickHorizontal = -1.0f; + + if (pPadState->IsDown(SWA::eKeyState_DpadRight)) + pPadState->LeftStickHorizontal = 1.0f; +} + /* Hook function for when checkpoints are activated to preserve the current checkpoint score. */ PPC_FUNC_IMPL(__imp__sub_82624308); diff --git a/UnleashedRecomp/ui/options_menu.cpp b/UnleashedRecomp/ui/options_menu.cpp index 066b7e8..ac60ec9 100644 --- a/UnleashedRecomp/ui/options_menu.cpp +++ b/UnleashedRecomp/ui/options_menu.cpp @@ -809,6 +809,7 @@ static void DrawConfigOptions() DrawConfigOption(rowCount++, yOffset, &Config::InvertCameraX, true); DrawConfigOption(rowCount++, yOffset, &Config::InvertCameraY, true); DrawConfigOption(rowCount++, yOffset, &Config::AllowBackgroundInput, true); + DrawConfigOption(rowCount++, yOffset, &Config::AllowDPadMovement, true); DrawConfigOption(rowCount++, yOffset, &Config::ControllerIcons, true); break; case 2: // AUDIO diff --git a/UnleashedRecomp/ui/options_menu_thumbnails.h b/UnleashedRecomp/ui/options_menu_thumbnails.h index 43e26c1..db5d49a 100644 --- a/UnleashedRecomp/ui/options_menu_thumbnails.h +++ b/UnleashedRecomp/ui/options_menu_thumbnails.h @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -48,6 +49,7 @@ inline void LoadThumbnails() g_thumbnails[Config::InvertCameraX.Name] = LOAD_ZSTD_TEXTURE(g_invert_camera_x); g_thumbnails[Config::InvertCameraY.Name] = LOAD_ZSTD_TEXTURE(g_invert_camera_y); g_thumbnails[Config::AllowBackgroundInput.Name] = LOAD_ZSTD_TEXTURE(g_allow_background_input); + g_thumbnails[Config::AllowDPadMovement.Name] = LOAD_ZSTD_TEXTURE(g_allow_dpad_movement); g_thumbnails[Config::ControllerIcons.Name] = LOAD_ZSTD_TEXTURE(g_controller_icons); g_thumbnails[Config::MusicVolume.Name] = LOAD_ZSTD_TEXTURE(g_music_volume); g_thumbnails[Config::EffectsVolume.Name] = LOAD_ZSTD_TEXTURE(g_effects_volume); diff --git a/UnleashedRecomp/user/config.h b/UnleashedRecomp/user/config.h index 502d854..5e14580 100644 --- a/UnleashedRecomp/user/config.h +++ b/UnleashedRecomp/user/config.h @@ -19,6 +19,7 @@ public: CONFIG_DEFINE_LOCALISED("Input", bool, InvertCameraX, false); CONFIG_DEFINE_LOCALISED("Input", bool, InvertCameraY, false); CONFIG_DEFINE_LOCALISED("Input", bool, AllowBackgroundInput, false); + CONFIG_DEFINE_LOCALISED("Input", bool, AllowDPadMovement, false); CONFIG_DEFINE_ENUM_LOCALISED("Input", EControllerIcons, ControllerIcons, EControllerIcons::Auto); CONFIG_DEFINE_LOCALISED("Audio", float, MusicVolume, 1.0f); diff --git a/UnleashedRecompLib/config/SWA.toml b/UnleashedRecompLib/config/SWA.toml index 7ccbab9..cc13d6a 100644 --- a/UnleashedRecompLib/config/SWA.toml +++ b/UnleashedRecompLib/config/SWA.toml @@ -564,3 +564,27 @@ jump_address = 0x82585480 [[midasm_hook]] name = "LoadingScreenControllerMidAsmHook" address = 0x824DC9D4 + +# CPlayerSpeedPostureInputOnPath +[[midasm_hook]] +name = "PostureDPadSupportMidAsmHook" +address = 0x8234F174 +registers = ["r3"] + +# CPlayerSpeedPostureInputOnPathLocal +[[midasm_hook]] +name = "PostureDPadSupportMidAsmHook" +address = 0x8234F518 +registers = ["r3"] + +# CPlayerSpeedPostureInput3DStandard +[[midasm_hook]] +name = "PostureDPadSupportMidAsmHook" +address = 0x8234EEC8 +registers = ["r3"] + +# CEvilPostureInputStandard +[[midasm_hook]] +name = "PostureDPadSupportMidAsmHook" +address = 0x823CDA2C +registers = ["r3"] diff --git a/UnleashedRecompResources b/UnleashedRecompResources index 7179a84..c6f5cb5 160000 --- a/UnleashedRecompResources +++ b/UnleashedRecompResources @@ -1 +1 @@ -Subproject commit 7179a84509ac565edd07bddeee131fb229e0e99f +Subproject commit c6f5cb55a370da3bbc55bf7e1ec938b10dbc159d