Implemented safer hooks for D-Pad movement (#129)

This commit is contained in:
Hyper 2025-01-19 15:01:11 +00:00 committed by GitHub
parent cdd801dcec
commit b56c0b8209
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 87 additions and 69 deletions

View file

@ -157,6 +157,7 @@ set(SWA_PATCHES_CXX_SOURCES
"patches/camera_patches.cpp"
"patches/CGameModeStageTitle_patches.cpp"
"patches/fps_patches.cpp"
"patches/input_patches.cpp"
"patches/inspire_patches.cpp"
"patches/misc_patches.cpp"
"patches/object_patches.cpp"
@ -470,7 +471,6 @@ 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")

View file

@ -117,11 +117,6 @@ CONFIG_DEFINE_LOCALE(AllowBackgroundInput)
{ ELanguage::English, { "Allow Background Input", "Allow 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(MasterVolume)
{
{ ELanguage::English, { "Master Volume", "Adjust the overall volume." } }

View file

@ -0,0 +1,35 @@
#include <api/SWA.h>
static void SetDPadAnalogDirectionX(PPCRegister& pPadState, PPCRegister& x, bool negate)
{
auto pGuestPadState = (SWA::SPadState*)g_memory.Translate(pPadState.u32);
if (pGuestPadState->IsDown(SWA::eKeyState_DpadLeft))
x.f64 = negate ? 1.0f : -1.0f;
if (pGuestPadState->IsDown(SWA::eKeyState_DpadRight))
x.f64 = negate ? -1.0f : 1.0f;
}
static void SetDPadAnalogDirectionY(PPCRegister& pPadState, PPCRegister& y, bool negate)
{
auto pGuestPadState = (SWA::SPadState*)g_memory.Translate(pPadState.u32);
if (pGuestPadState->IsDown(SWA::eKeyState_DpadUp))
y.f64 = negate ? -1.0f : 1.0f;
if (pGuestPadState->IsDown(SWA::eKeyState_DpadDown))
y.f64 = negate ? 1.0f : -1.0f;
}
void PostureDPadSupportMidAsmHook(PPCRegister& pPadState, PPCRegister& x, PPCRegister& y)
{
SetDPadAnalogDirectionX(pPadState, x, false);
SetDPadAnalogDirectionY(pPadState, y, true);
}
void PostureDPadSupportPathLocalMidAsmHook(PPCRegister& pPadState, PPCRegister& x, PPCRegister& y)
{
SetDPadAnalogDirectionX(pPadState, x, false);
SetDPadAnalogDirectionY(pPadState, y, false);
}

View file

@ -10,26 +10,6 @@ static uint32_t g_lastTrickScore;
static float g_lastDarkGaiaEnergy;
static bool g_isUnleashCancelled;
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);

View file

@ -894,7 +894,6 @@ static void DrawConfigOptions()
DrawConfigOption(rowCount++, yOffset, &Config::InvertCameraY, true);
DrawConfigOption(rowCount++, yOffset, &Config::Vibration, true);
DrawConfigOption(rowCount++, yOffset, &Config::AllowBackgroundInput, true);
DrawConfigOption(rowCount++, yOffset, &Config::AllowDPadMovement, true);
DrawConfigOption(rowCount++, yOffset, &Config::ControllerIcons, true);
break;

View file

@ -4,7 +4,6 @@
// TODO (Hyper): lower the resolution of these textures once final.
#include <res/images/options_menu/thumbnails/achievement_notifications.dds.h>
#include <res/images/options_menu/thumbnails/allow_background_input.dds.h>
#include <res/images/options_menu/thumbnails/allow_dpad_movement.dds.h>
#include <res/images/options_menu/thumbnails/antialiasing.dds.h>
#include <res/images/options_menu/thumbnails/aspect_ratio.dds.h>
#include <res/images/options_menu/thumbnails/battle_theme.dds.h>
@ -78,7 +77,6 @@ void LoadThumbnails()
g_configThumbnails[&Config::InvertCameraY] = LOAD_ZSTD_TEXTURE(g_invert_camera_y);
g_configThumbnails[&Config::Vibration] = LOAD_ZSTD_TEXTURE(g_vibration);
g_configThumbnails[&Config::AllowBackgroundInput] = LOAD_ZSTD_TEXTURE(g_allow_background_input);
g_configThumbnails[&Config::AllowDPadMovement] = LOAD_ZSTD_TEXTURE(g_allow_dpad_movement);
g_configThumbnails[&Config::ControllerIcons] = LOAD_ZSTD_TEXTURE(g_controller_icons);
g_configThumbnails[&Config::MasterVolume] = LOAD_ZSTD_TEXTURE(g_master_volume);
g_configThumbnails[&Config::MusicVolume] = LOAD_ZSTD_TEXTURE(g_music_volume);

View file

@ -614,7 +614,6 @@ public:
CONFIG_DEFINE_LOCALISED("Input", bool, InvertCameraY, false);
CONFIG_DEFINE_LOCALISED("Input", bool, Vibration, true);
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, MasterVolume, 1.0f);

View file

@ -551,26 +551,38 @@ address = 0x824DC9D4
# CPlayerSpeedPostureInputOnPath
[[midasm_hook]]
name = "PostureDPadSupportMidAsmHook"
address = 0x8234F174
registers = ["r3"]
address = 0x8234F194
registers = ["r31", "f13", "f0"]
# CPlayerSpeedPostureInputOnPathLocal
[[midasm_hook]]
name = "PostureDPadSupportMidAsmHook"
address = 0x8234F518
registers = ["r3"]
name = "PostureDPadSupportPathLocalMidAsmHook"
address = 0x8234F610
registers = ["r30", "f0", "f13"]
# CPlayerSpeedPostureInput3DStandard
[[midasm_hook]]
name = "PostureDPadSupportMidAsmHook"
address = 0x8234EEC8
registers = ["r3"]
address = 0x8234EEE8
registers = ["r31", "f12", "f13"]
# CEvilPostureInputStandard
[[midasm_hook]]
name = "PostureDPadSupportMidAsmHook"
address = 0x823CDA2C
registers = ["r3"]
address = 0x823CDA60
registers = ["r3", "f11", "f12"]
# CEvilPostureInputStandard
[[midasm_hook]]
name = "PostureDPadSupportXMidAsmHook"
address = 0x823CDA74
registers = ["r3", "f0"]
# CEvilPostureInputStandard
[[midasm_hook]]
name = "PostureDPadSupportYMidAsmHook"
address = 0x823CDA88
registers = ["r3", "f12"]
[[midasm_hook]]
name = "LoadingUpdateMidAsmHook"