From 24f504ef9b72de5d72705c15440cf27edf057743 Mon Sep 17 00:00:00 2001 From: Sirius902 <3645979-Sirius902@users.noreply.gitlab.com> Date: Sun, 17 Apr 2022 22:18:15 -0700 Subject: [PATCH 01/11] Rumble indefinitely until turned off --- libultraship/libultraship/SDLController.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libultraship/libultraship/SDLController.cpp b/libultraship/libultraship/SDLController.cpp index 47fb57441de..78b22188057 100644 --- a/libultraship/libultraship/SDLController.cpp +++ b/libultraship/libultraship/SDLController.cpp @@ -93,6 +93,9 @@ namespace Ship { } bool SDLController::Close() { + if (SDL_GameControllerHasRumble(Cont)) { + SDL_GameControllerRumble(Cont, 0, 0, 0); + } if (Cont != nullptr) { SDL_GameControllerClose(Cont); } @@ -331,7 +334,9 @@ namespace Ship { { if (SDL_GameControllerHasRumble(Cont)) { if (controller->rumble > 0) { - SDL_GameControllerRumble(Cont, 0xFFFF * Game::Settings.controller.rumble_strength, 0xFFFF * Game::Settings.controller.rumble_strength, 1); + SDL_GameControllerRumble(Cont, 0xFFFF * Game::Settings.controller.rumble_strength, 0xFFFF * Game::Settings.controller.rumble_strength, 0); + } else { + SDL_GameControllerRumble(Cont, 0, 0, 0); } } From a2c10b70322f39f0dc2f2f60f0eaced11adf7c90 Mon Sep 17 00:00:00 2001 From: Sirius902 <3645979-Sirius902@users.noreply.gitlab.com> Date: Sun, 17 Apr 2022 23:04:51 -0700 Subject: [PATCH 02/11] Add rumble cvar --- libultraship/libultraship/GameSettings.cpp | 4 ++++ libultraship/libultraship/GameSettings.h | 1 + libultraship/libultraship/SohImGuiImpl.cpp | 5 +++++ soh/soh/stubs.c | 4 ++-- soh/src/code/padmgr.c | 9 ++++++++- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/libultraship/libultraship/GameSettings.cpp b/libultraship/libultraship/GameSettings.cpp index 1b8d473b207..271bf6315ac 100644 --- a/libultraship/libultraship/GameSettings.cpp +++ b/libultraship/libultraship/GameSettings.cpp @@ -87,6 +87,9 @@ namespace Game { Settings.controller.rumble_strength = Ship::stof(Conf[ControllerSection]["rumble_strength"]); CVar_SetFloat("gRumbleStrength", Settings.controller.rumble_strength); + Settings.controller.rumble_enabled = Ship::stof(Conf[ControllerSection]["rumble_enabled"]); + CVar_SetS32("gRumbleEnabled", Settings.controller.rumble_enabled); + Settings.controller.input_scale = Ship::stof(Conf[ControllerSection]["input_scale"]); CVar_SetFloat("gInputScale", Settings.controller.input_scale); @@ -160,6 +163,7 @@ namespace Game { // Controllers Conf[ControllerSection]["gyro_sensitivity"] = std::to_string(Settings.controller.gyro_sensitivity); Conf[ControllerSection]["rumble_strength"] = std::to_string(Settings.controller.rumble_strength); + Conf[ControllerSection]["rumble_enabled"] = std::to_string(Settings.controller.rumble_enabled); Conf[ControllerSection]["input_scale"] = std::to_string(Settings.controller.input_scale); Conf[ControllerSection]["input_enabled"] = std::to_string(Settings.controller.input_enabled); Conf[ControllerSection]["dpad_pause_name"] = std::to_string(Settings.controller.dpad_pause_name); diff --git a/libultraship/libultraship/GameSettings.h b/libultraship/libultraship/GameSettings.h index 340e93d260f..058ec041507 100644 --- a/libultraship/libultraship/GameSettings.h +++ b/libultraship/libultraship/GameSettings.h @@ -31,6 +31,7 @@ struct SoHConfigType { struct { float gyro_sensitivity = 1.0f; float rumble_strength = 1.0f; + bool rumble_enabled = true; float input_scale = 1.0f; float gyroDriftX = 0.0f; float gyroDriftY = 0.0f; diff --git a/libultraship/libultraship/SohImGuiImpl.cpp b/libultraship/libultraship/SohImGuiImpl.cpp index 93dcd249201..cf06e115385 100644 --- a/libultraship/libultraship/SohImGuiImpl.cpp +++ b/libultraship/libultraship/SohImGuiImpl.cpp @@ -364,6 +364,11 @@ namespace SohImGui { ImGui::Separator(); + if (ImGui::Checkbox("Rumble Enabled", &Game::Settings.controller.rumble_enabled)) { + CVar_SetS32("gRumbleEnabled", Game::Settings.controller.rumble_enabled); + needs_save = true; + } + ImGui::Text("Rumble Strength: %d %%", static_cast(100 * Game::Settings.controller.rumble_strength)); if (ImGui::SliderFloat("##RUMBLE", &Game::Settings.controller.rumble_strength, 0.0f, 1.0f, "")) { needs_save = true; diff --git a/soh/soh/stubs.c b/soh/soh/stubs.c index 871d5ca22af..c47c1fa5d58 100644 --- a/soh/soh/stubs.c +++ b/soh/soh/stubs.c @@ -102,7 +102,7 @@ void osCreateViManager(OSPri pri) s32 osMotorInit(OSMesgQueue* ctrlrqueue, OSPfs* pfs, s32 channel) { - + return 0; } u32 osAiGetLength(void) @@ -2099,4 +2099,4 @@ u8 gSequenceFontTable[0x1C0] = { 0x01, 0x12, 0x01, 0x24, 0x01, 0x18, 0x01, 0x19, 0x01, 0x13, 0x01, 0x20, 0x01, 0x1B, 0x01, 0x1C, 0x01, 0x1D, 0x01, 0x03, 0x01, 0x1F, 0x01, 0x20, 0x01, 0x20, 0x01, 0x09, 0x01, 0x21, 0x01, 0x22, 0x01, 0x21, 0x01, 0x09, 0x01, 0x20, 0x01, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -}; \ No newline at end of file +}; diff --git a/soh/src/code/padmgr.c b/soh/src/code/padmgr.c index 973c2b44617..ccb4b17acd8 100644 --- a/soh/src/code/padmgr.c +++ b/soh/src/code/padmgr.c @@ -269,7 +269,7 @@ void PadMgr_ProcessInputs(PadMgr* padMgr) { input->press.stick_y += (s8)(input->cur.stick_y - input->prev.stick_y); } - controllerCallback.rumble = padMgr->rumbleEnable[0] > 0 ? 1 : 0; + controllerCallback.rumble = (CVar_GetS32("gRumbleEnabled", 0) != 0) && (padMgr->rumbleEnable[0] > 0) ? 1 : 0; if (HealthMeter_IsCritical()) { controllerCallback.ledColor = 0; @@ -303,6 +303,13 @@ void PadMgr_HandleRetraceMsg(PadMgr* padMgr) { } osRecvMesg(queue, NULL, OS_MESG_BLOCK); osContGetReadData(padMgr->pads); + + if (CVar_GetS32("gRumbleEnabled", 0) != 0) { + padMgr->padStatus[0].status = 1; + } else { + padMgr->padStatus[0].status = 0; + } + if (padMgr->preNMIShutdown) { memset(padMgr->pads, 0, sizeof(padMgr->pads)); } From 038757a9b6ec3f7c395c2a14d454ff4f53e6c3b5 Mon Sep 17 00:00:00 2001 From: Sirius902 <3645979-Sirius902@users.noreply.gitlab.com> Date: Mon, 18 Apr 2022 19:52:35 -0700 Subject: [PATCH 03/11] Register CVar --- soh/soh/Enhancements/bootcommands.c | 1 + 1 file changed, 1 insertion(+) diff --git a/soh/soh/Enhancements/bootcommands.c b/soh/soh/Enhancements/bootcommands.c index 68559317934..90e1d16a4fb 100644 --- a/soh/soh/Enhancements/bootcommands.c +++ b/soh/soh/Enhancements/bootcommands.c @@ -25,6 +25,7 @@ void BootCommands_Init() CVar_RegisterS32("gDebugEnabled", 0); CVar_RegisterS32("gPauseLiveLink", 0); CVar_RegisterS32("gMinimalUI", 0); + CVar_RegisterS32("gRumbleEnabled", 0); } //void BootCommands_ParseBootArgs(char* str) From 21e4e5a1405dbd9fa0da0a5ac769a45ec914bcfb Mon Sep 17 00:00:00 2001 From: Sirius902 <3645979-Sirius902@users.noreply.gitlab.com> Date: Mon, 18 Apr 2022 20:28:11 -0700 Subject: [PATCH 04/11] Check if controller can rumble to insert rumble pak --- libultraship/libultraship/Controller.h | 1 + libultraship/libultraship/KeyboardController.h | 1 + libultraship/libultraship/SDLController.h | 1 + soh/soh/OTRGlobals.cpp | 10 ++++++++++ soh/soh/OTRGlobals.h | 1 + soh/src/code/padmgr.c | 6 +----- 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/libultraship/libultraship/Controller.h b/libultraship/libultraship/Controller.h index c78142af42c..9deb912dce6 100644 --- a/libultraship/libultraship/Controller.h +++ b/libultraship/libultraship/Controller.h @@ -19,6 +19,7 @@ namespace Ship { void Read(OSContPad* pad); virtual void ReadFromSource() = 0; virtual void WriteToSource(ControllerCallback* controller) = 0; + virtual bool CanRumble() const = 0; bool isRumbling; void SetButtonMapping(const std::string& szButtonName, int32_t dwScancode); diff --git a/libultraship/libultraship/KeyboardController.h b/libultraship/libultraship/KeyboardController.h index ab0f98e6416..1a97065d5dc 100644 --- a/libultraship/libultraship/KeyboardController.h +++ b/libultraship/libultraship/KeyboardController.h @@ -10,6 +10,7 @@ namespace Ship { void ReadFromSource(); void WriteToSource(ControllerCallback* controller); + bool CanRumble() const { return false; } bool PressButton(int32_t dwScancode); bool ReleaseButton(int32_t dwScancode); diff --git a/libultraship/libultraship/SDLController.h b/libultraship/libultraship/SDLController.h index 5c71c50a9cb..f7b538cba82 100644 --- a/libultraship/libultraship/SDLController.h +++ b/libultraship/libultraship/SDLController.h @@ -12,6 +12,7 @@ namespace Ship { void ReadFromSource(); void WriteToSource(ControllerCallback* controller); + bool CanRumble() const { return SDL_GameControllerHasRumble(Cont); } std::string GetGuid() { return guid; }; diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 007afd70243..8bb2490b97a 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -814,3 +814,13 @@ extern "C" void AudioPlayer_Play(const uint8_t* buf, uint32_t len) { OTRGlobals::Instance->context->GetWindow()->GetAudioPlayer()->Play(buf, len); } } + +extern "C" int Controller_CanRumble(void) { + for (const auto& controller : Ship::Window::Controllers.at(0)) { + if (controller->CanRumble()) { + return 1; + } + } + + return 0; +} diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index 4f62f069436..0af73716c14 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -64,4 +64,5 @@ int AudioPlayer_Buffered(void); int AudioPlayer_GetDesiredBuffered(void); void AudioPlayer_Play(const uint8_t* buf, uint32_t len); void AudioMgr_CreateNextAudioBuffer(s16* samples, u32 num_samples); +int Controller_CanRumble(void); #endif diff --git a/soh/src/code/padmgr.c b/soh/src/code/padmgr.c index ccb4b17acd8..d473b47ad5f 100644 --- a/soh/src/code/padmgr.c +++ b/soh/src/code/padmgr.c @@ -304,11 +304,7 @@ void PadMgr_HandleRetraceMsg(PadMgr* padMgr) { osRecvMesg(queue, NULL, OS_MESG_BLOCK); osContGetReadData(padMgr->pads); - if (CVar_GetS32("gRumbleEnabled", 0) != 0) { - padMgr->padStatus[0].status = 1; - } else { - padMgr->padStatus[0].status = 0; - } + padMgr->padStatus[0].status = (CVar_GetS32("gRumbleEnabled", 0) != 0) && Controller_CanRumble(); if (padMgr->preNMIShutdown) { memset(padMgr->pads, 0, sizeof(padMgr->pads)); From 930ce7f3de0a0a368b7ba069428c82c04a39fe09 Mon Sep 17 00:00:00 2001 From: Sirius902 <3645979-Sirius902@users.noreply.gitlab.com> Date: Tue, 19 Apr 2022 21:25:32 -0700 Subject: [PATCH 05/11] Reduce verbosity of checks --- soh/src/code/padmgr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/soh/src/code/padmgr.c b/soh/src/code/padmgr.c index d473b47ad5f..2ae3abaa33a 100644 --- a/soh/src/code/padmgr.c +++ b/soh/src/code/padmgr.c @@ -269,7 +269,7 @@ void PadMgr_ProcessInputs(PadMgr* padMgr) { input->press.stick_y += (s8)(input->cur.stick_y - input->prev.stick_y); } - controllerCallback.rumble = (CVar_GetS32("gRumbleEnabled", 0) != 0) && (padMgr->rumbleEnable[0] > 0) ? 1 : 0; + controllerCallback.rumble = CVar_GetS32("gRumbleEnabled", 0) && (padMgr->rumbleEnable[0] > 0); if (HealthMeter_IsCritical()) { controllerCallback.ledColor = 0; @@ -304,7 +304,7 @@ void PadMgr_HandleRetraceMsg(PadMgr* padMgr) { osRecvMesg(queue, NULL, OS_MESG_BLOCK); osContGetReadData(padMgr->pads); - padMgr->padStatus[0].status = (CVar_GetS32("gRumbleEnabled", 0) != 0) && Controller_CanRumble(); + padMgr->padStatus[0].status = CVar_GetS32("gRumbleEnabled", 0) && Controller_CanRumble(); if (padMgr->preNMIShutdown) { memset(padMgr->pads, 0, sizeof(padMgr->pads)); From 51ec3ff67b61c962cf6fdab766585b9dbbeea568 Mon Sep 17 00:00:00 2001 From: Sirius902 <3645979-Sirius902@users.noreply.gitlab.com> Date: Sat, 23 Apr 2022 17:03:39 -0700 Subject: [PATCH 06/11] Remove extraneous const_cast --- libultraship/libultraship/GameSettings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libultraship/libultraship/GameSettings.cpp b/libultraship/libultraship/GameSettings.cpp index 9044837dcac..6195335496b 100644 --- a/libultraship/libultraship/GameSettings.cpp +++ b/libultraship/libultraship/GameSettings.cpp @@ -62,7 +62,7 @@ namespace Game { CVar_SetS32("gPauseLiveLink", Settings.enhancements.animated_pause_menu); Settings.enhancements.dynamic_wallet_icon = stob(Conf[EnhancementSection]["dynamic_wallet_icon"]); - CVar_SetS32(const_cast("gDynamicWalletIcon"), Settings.enhancements.dynamic_wallet_icon); + CVar_SetS32("gDynamicWalletIcon", Settings.enhancements.dynamic_wallet_icon); Settings.enhancements.minimal_ui = stob(Conf[EnhancementSection]["minimal_ui"]); CVar_SetS32("gMinimalUI", Settings.enhancements.minimal_ui); From 0e1e62713d81b54134af5c1ee74a137dfc249a41 Mon Sep 17 00:00:00 2001 From: Sirius902 <3645979-Sirius902@users.noreply.gitlab.com> Date: Sun, 24 Apr 2022 12:52:52 -0700 Subject: [PATCH 07/11] Once again remove extraneous const_cast --- libultraship/libultraship/SohImGuiImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libultraship/libultraship/SohImGuiImpl.cpp b/libultraship/libultraship/SohImGuiImpl.cpp index a85a184aa69..e6ebd5fb4af 100644 --- a/libultraship/libultraship/SohImGuiImpl.cpp +++ b/libultraship/libultraship/SohImGuiImpl.cpp @@ -447,7 +447,7 @@ namespace SohImGui { } if (ImGui::Checkbox("Dynamic Wallet Icon", &Game::Settings.enhancements.dynamic_wallet_icon)) { - CVar_SetS32(const_cast("gDynamicWalletIcon"), Game::Settings.enhancements.dynamic_wallet_icon); + CVar_SetS32("gDynamicWalletIcon", Game::Settings.enhancements.dynamic_wallet_icon); needs_save = true; } From 506ca1af3b7e6715d83f90503ba2f856ed9535c9 Mon Sep 17 00:00:00 2001 From: Sirius902 <3645979-Sirius902@users.noreply.gitlab.com> Date: Sun, 24 Apr 2022 15:05:14 -0700 Subject: [PATCH 08/11] Add per-controller settings --- libultraship/libultraship/Controller.h | 3 + libultraship/libultraship/GameSettings.cpp | 41 ++++++++++--- libultraship/libultraship/GameSettings.h | 11 ++-- .../libultraship/KeyboardController.cpp | 2 +- .../libultraship/KeyboardController.h | 3 + libultraship/libultraship/SDLController.cpp | 60 ++++++++++++++----- libultraship/libultraship/SDLController.h | 4 ++ libultraship/libultraship/SohImGuiImpl.cpp | 44 ++++++++++---- soh/soh/OTRGlobals.cpp | 7 ++- soh/soh/OTRGlobals.h | 2 +- soh/src/code/padmgr.c | 4 +- 11 files changed, 134 insertions(+), 47 deletions(-) diff --git a/libultraship/libultraship/Controller.h b/libultraship/libultraship/Controller.h index 9deb912dce6..19ec7c6dd7a 100644 --- a/libultraship/libultraship/Controller.h +++ b/libultraship/libultraship/Controller.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "stdint.h" #include "UltraController.h" #include "ControllerAttachment.h" @@ -25,6 +26,8 @@ namespace Ship { void SetButtonMapping(const std::string& szButtonName, int32_t dwScancode); std::shared_ptr GetAttachment() { return Attachment; } int32_t GetControllerNumber() { return dwControllerNumber; } + virtual bool HasPadConf() = 0; + virtual std::optional GetPadConfSection() = 0; protected: int32_t dwPressedButtons; diff --git a/libultraship/libultraship/GameSettings.cpp b/libultraship/libultraship/GameSettings.cpp index 56db78a1891..637d9d084be 100644 --- a/libultraship/libultraship/GameSettings.cpp +++ b/libultraship/libultraship/GameSettings.cpp @@ -15,6 +15,8 @@ #include #include "SohHooks.h" +#include "Window.h" + #define ABS(var) var < 0 ? -(var) : var using namespace Ship; @@ -93,12 +95,6 @@ namespace Game { CVar_SetFloat("gFanfareVolume", Settings.audio.fanfare); // Controllers - Settings.controller.gyro_sensitivity = Ship::stof(Conf[ControllerSection]["gyro_sensitivity"]); - CVar_SetFloat("gGyroSensitivity", Settings.controller.gyro_sensitivity); - - Settings.controller.rumble_strength = Ship::stof(Conf[ControllerSection]["rumble_strength"]); - CVar_SetFloat("gRumbleStrength", Settings.controller.rumble_strength); - Settings.controller.rumble_enabled = Ship::stof(Conf[ControllerSection]["rumble_enabled"]); CVar_SetS32("gRumbleEnabled", Settings.controller.rumble_enabled); @@ -157,9 +153,28 @@ namespace Game { Settings.cheats.freeze_time = stob(Conf[CheatSection]["freeze_time"]); CVar_SetS32("gFreezeTime", Settings.cheats.freeze_time); + // Per-Controller + LoadPadSettings(); + UpdateAudio(); } + void LoadPadSettings() { + const std::shared_ptr pConf = GlobalCtx2::GetInstance()->GetConfig(); + ConfigFile& Conf = *pConf; + + for (const auto& [i, controllers] : Ship::Window::Controllers) { + for (const auto& controller : controllers) { + if (auto padConfSection = controller->GetPadConfSection()) { + Settings.controller.extra[i].gyro_sensitivity = Ship::stof(Conf[*padConfSection]["gyro_sensitivity"]); + Settings.controller.extra[i].rumble_strength = Ship::stof(Conf[*padConfSection]["rumble_strength"]); + Settings.controller.extra[i].gyro_drift_x = Ship::stof(Conf[*padConfSection]["gyro_drift_x"], 0.0f); + Settings.controller.extra[i].gyro_drift_y = Ship::stof(Conf[*padConfSection]["gyro_drift_y"], 0.0f); + } + } + } + } + void SaveSettings() { const std::shared_ptr pConf = GlobalCtx2::GetInstance()->GetConfig(); ConfigFile& Conf = *pConf; @@ -190,8 +205,6 @@ namespace Game { // Controllers - Conf[ControllerSection]["gyro_sensitivity"] = std::to_string(Settings.controller.gyro_sensitivity); - Conf[ControllerSection]["rumble_strength"] = std::to_string(Settings.controller.rumble_strength); Conf[ControllerSection]["rumble_enabled"] = std::to_string(Settings.controller.rumble_enabled); Conf[ControllerSection]["input_scale"] = std::to_string(Settings.controller.input_scale); Conf[ControllerSection]["input_enabled"] = std::to_string(Settings.controller.input_enabled); @@ -210,6 +223,18 @@ namespace Game { Conf[CheatSection]["moon_jump_on_l"] = std::to_string(Settings.cheats.moon_jump_on_l); Conf[CheatSection]["super_tunic"] = std::to_string(Settings.cheats.super_tunic); + // Per-Controller + for (const auto& [i, controllers] : Ship::Window::Controllers) { + for (const auto& controller : controllers) { + if (auto padConfSection = controller->GetPadConfSection()) { + Conf[*padConfSection]["gyro_sensitivity"] = std::to_string(Settings.controller.extra[i].gyro_sensitivity); + Conf[*padConfSection]["rumble_strength"] = std::to_string(Settings.controller.extra[i].rumble_strength); + Conf[*padConfSection]["gyro_drift_x"] = std::to_string(Settings.controller.extra[i].gyro_drift_x); + Conf[*padConfSection]["gyro_drift_y"] = std::to_string(Settings.controller.extra[i].gyro_drift_y); + } + } + } + Conf.Save(); } diff --git a/libultraship/libultraship/GameSettings.h b/libultraship/libultraship/GameSettings.h index 4a553431ab6..f4d75938d24 100644 --- a/libultraship/libultraship/GameSettings.h +++ b/libultraship/libultraship/GameSettings.h @@ -34,12 +34,14 @@ struct SoHConfigType { // Controller struct { - float gyro_sensitivity = 1.0f; - float rumble_strength = 1.0f; + struct { + float gyro_sensitivity = 1.0f; + float rumble_strength = 1.0f; + float gyro_drift_x = 0.0f; + float gyro_drift_y = 0.0f; + } extra[4]; bool rumble_enabled = true; float input_scale = 1.0f; - float gyroDriftX = 0.0f; - float gyroDriftY = 0.0f; bool input_enabled = false; bool dpad_pause_name = false; bool dpad_ocarina_text = false; @@ -87,6 +89,7 @@ namespace Game { extern SoHConfigType Settings; void InitSettings(); void LoadSettings(); + void LoadPadSettings(); void SaveSettings(); void SetSeqPlayerVolume(SeqPlayers playerId, float volume); } diff --git a/libultraship/libultraship/KeyboardController.cpp b/libultraship/libultraship/KeyboardController.cpp index 6f78a1678ef..13014c6a72a 100644 --- a/libultraship/libultraship/KeyboardController.cpp +++ b/libultraship/libultraship/KeyboardController.cpp @@ -53,4 +53,4 @@ namespace Ship { std::string KeyboardController::GetBindingConfSection() { return GetControllerType() + " CONTROLLER BINDING " + std::to_string(GetControllerNumber() + 1); } -} \ No newline at end of file +} diff --git a/libultraship/libultraship/KeyboardController.h b/libultraship/libultraship/KeyboardController.h index 1a97065d5dc..97e2235ffab 100644 --- a/libultraship/libultraship/KeyboardController.h +++ b/libultraship/libultraship/KeyboardController.h @@ -16,6 +16,9 @@ namespace Ship { bool ReleaseButton(int32_t dwScancode); void ReleaseAllButtons(); + std::optional GetPadConfSection() { return {}; } + bool HasPadConf() { return false; }; + protected: std::string GetControllerType(); std::string GetConfSection(); diff --git a/libultraship/libultraship/SDLController.cpp b/libultraship/libultraship/SDLController.cpp index 78b22188057..26760704868 100644 --- a/libultraship/libultraship/SDLController.cpp +++ b/libultraship/libultraship/SDLController.cpp @@ -74,15 +74,21 @@ namespace Ship { Cont = NewCont; std::string BindingConfSection = GetBindingConfSection(); - std::shared_ptr pBindingConf = GlobalCtx2::GetInstance()->GetConfig(); - ConfigFile& BindingConf = *pBindingConf.get(); + std::string PadConfSection = *GetPadConfSection(); + std::shared_ptr config = GlobalCtx2::GetInstance()->GetConfig(); - if (!BindingConf.has(BindingConfSection)) { + if (!config->has(BindingConfSection)) { CreateDefaultBinding(); } + if (!config->has(PadConfSection)) { + CreateDefaultPadConf(); + } + LoadBinding(); LoadAxisThresholds(); + // Update per-controller settings in ImGui menu after opening controller. + Game::LoadPadSettings(); break; } @@ -181,37 +187,41 @@ namespace Ship { if (SDL_GameControllerHasSensor(Cont, SDL_SENSOR_GYRO)) { + size_t contNumber = GetControllerNumber(); + float& gyro_drift_x = Game::Settings.controller.extra[contNumber].gyro_drift_x; + float& gyro_drift_y = Game::Settings.controller.extra[contNumber].gyro_drift_y; + const float gyro_sensitivity = Game::Settings.controller.extra[contNumber].gyro_sensitivity; + float gyroData[3]; SDL_GameControllerGetSensorData(Cont, SDL_SENSOR_GYRO, gyroData, 3); const char* contName = SDL_GameControllerName(Cont); const int isSpecialController = !strcmp("PS5 Controller", contName); - const float gyroSensitivity = Game::Settings.controller.gyro_sensitivity; - if (Game::Settings.controller.gyroDriftX == 0) { - Game::Settings.controller.gyroDriftX = gyroData[0]; + if (gyro_drift_x == 0) { + gyro_drift_x = gyroData[0]; } - if (Game::Settings.controller.gyroDriftY == 0) { + if (gyro_drift_y == 0) { if (isSpecialController == 1) { - Game::Settings.controller.gyroDriftY = gyroData[2]; + gyro_drift_y = gyroData[2]; } else { - Game::Settings.controller.gyroDriftY = gyroData[1]; + gyro_drift_y = gyroData[1]; } } if (isSpecialController == 1) { - wGyroX = gyroData[0] - Game::Settings.controller.gyroDriftX; - wGyroY = -gyroData[2] - Game::Settings.controller.gyroDriftY; + wGyroX = gyroData[0] - gyro_drift_x; + wGyroY = -gyroData[2] - gyro_drift_y; } else { - wGyroX = gyroData[0] - Game::Settings.controller.gyroDriftX; - wGyroY = gyroData[1] - Game::Settings.controller.gyroDriftY; + wGyroX = gyroData[0] - gyro_drift_x; + wGyroY = gyroData[1] - gyro_drift_y; } - wGyroX *= gyroSensitivity; - wGyroY *= gyroSensitivity; + wGyroX *= gyro_sensitivity; + wGyroY *= gyro_sensitivity; } for (int32_t i = SDL_CONTROLLER_BUTTON_A; i < SDL_CONTROLLER_BUTTON_MAX; i++) { @@ -334,7 +344,8 @@ namespace Ship { { if (SDL_GameControllerHasRumble(Cont)) { if (controller->rumble > 0) { - SDL_GameControllerRumble(Cont, 0xFFFF * Game::Settings.controller.rumble_strength, 0xFFFF * Game::Settings.controller.rumble_strength, 0); + float rumble_strength = Game::Settings.controller.extra[GetControllerNumber()].rumble_strength; + SDL_GameControllerRumble(Cont, 0xFFFF * rumble_strength, 0xFFFF * rumble_strength, 0); } else { SDL_GameControllerRumble(Cont, 0, 0, 0); } @@ -396,6 +407,19 @@ namespace Ship { Conf.Save(); } + void SDLController::CreateDefaultPadConf() { + std::string ConfSection = *GetPadConfSection(); + std::shared_ptr pConf = GlobalCtx2::GetInstance()->GetConfig(); + ConfigFile& Conf = *pConf.get(); + + Conf[ConfSection]["gyro_sensitivity"] = std::to_string(1.0f); + Conf[ConfSection]["rumble_strength"] = std::to_string(1.0f); + Conf[ConfSection]["gyro_drift_x"] = std::to_string(0.0f); + Conf[ConfSection]["gyro_drift_y"] = std::to_string(0.0f); + + Conf.Save(); + } + void SDLController::SetButtonMapping(const std::string& szButtonName, int32_t dwScancode) { if (guid.compare(INVALID_SDL_CONTROLLER_GUID)) { return; @@ -415,4 +439,8 @@ namespace Ship { std::string SDLController::GetBindingConfSection() { return GetControllerType() + " CONTROLLER BINDING " + guid; } + + std::optional SDLController::GetPadConfSection() { + return GetControllerType() + " CONTROLLER PAD " + guid; + } } diff --git a/libultraship/libultraship/SDLController.h b/libultraship/libultraship/SDLController.h index f7b538cba82..f4c84822d25 100644 --- a/libultraship/libultraship/SDLController.h +++ b/libultraship/libultraship/SDLController.h @@ -16,12 +16,16 @@ namespace Ship { std::string GetGuid() { return guid; }; + std::optional GetPadConfSection(); + bool HasPadConf() { return true; }; + protected: std::string GetControllerType(); void SetButtonMapping(const std::string& szButtonName, int32_t dwScancode); std::string GetConfSection(); std::string GetBindingConfSection(); void CreateDefaultBinding(); + void CreateDefaultPadConf(); static bool IsGuidInUse(const std::string& guid); private: diff --git a/libultraship/libultraship/SohImGuiImpl.cpp b/libultraship/libultraship/SohImGuiImpl.cpp index e6ebd5fb4af..83de91939dd 100644 --- a/libultraship/libultraship/SohImGuiImpl.cpp +++ b/libultraship/libultraship/SohImGuiImpl.cpp @@ -3,6 +3,9 @@ #include #include #include +#include +#include +#include #include "Archive.h" #include "Environment.h" @@ -344,14 +347,34 @@ namespace SohImGui { } if (ImGui::BeginMenu("Controller")) { - ImGui::Text("Gyro Sensitivity: %d %%", static_cast(100 * Game::Settings.controller.gyro_sensitivity)); - if (ImGui::SliderFloat("##GYROSCOPE", &Game::Settings.controller.gyro_sensitivity, 0.0f, 1.0f, "")) { - needs_save = true; - } - - if (ImGui::Button("Recalibrate Gyro")) { - Game::Settings.controller.gyroDriftX = 0; - Game::Settings.controller.gyroDriftY = 0; + for (const auto& [i, controllers] : Ship::Window::Controllers) { + bool hasPad = std::find_if(controllers.begin(), controllers.end(), [](const auto& c) { + return c->HasPadConf(); + }) != controllers.end(); + if (!hasPad) continue; + + auto menuLabel = "Controller " + std::to_string(i + 1); + if (ImGui::BeginMenu(menuLabel.c_str())) { + ImGui::Text("Gyro Sensitivity: %d %%", static_cast(100 * Game::Settings.controller.extra[i].gyro_sensitivity)); + if (ImGui::SliderFloat("##GYROSCOPE", &Game::Settings.controller.extra[i].gyro_sensitivity, 0.0f, 1.0f, "")) { + needs_save = true; + } + + if (ImGui::Button("Recalibrate Gyro")) { + Game::Settings.controller.extra[i].gyro_drift_x = 0; + Game::Settings.controller.extra[i].gyro_drift_y = 0; + needs_save = true; + } + + ImGui::Separator(); + + ImGui::Text("Rumble Strength: %d %%", static_cast(100 * Game::Settings.controller.extra[i].rumble_strength)); + if (ImGui::SliderFloat("##RUMBLE", &Game::Settings.controller.extra[i].rumble_strength, 0.0f, 1.0f, "")) { + needs_save = true; + } + + ImGui::EndMenu(); + } } ImGui::Separator(); @@ -361,11 +384,6 @@ namespace SohImGui { needs_save = true; } - ImGui::Text("Rumble Strength: %d %%", static_cast(100 * Game::Settings.controller.rumble_strength)); - if (ImGui::SliderFloat("##RUMBLE", &Game::Settings.controller.rumble_strength, 0.0f, 1.0f, "")) { - needs_save = true; - } - if (ImGui::Checkbox("Show Inputs", &Game::Settings.controller.input_enabled)) { needs_save = true; } diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 0ad86ac6330..f125437ab56 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -3,6 +3,7 @@ #include #include #include "GlobalCtx2.h" +#include "GameSettings.h" #include "ResourceMgr.h" #include "DisplayList.h" #include "PlayerAnimation.h" @@ -886,9 +887,9 @@ extern "C" void AudioPlayer_Play(const uint8_t* buf, uint32_t len) { } } -extern "C" int Controller_CanRumble(void) { - for (const auto& controller : Ship::Window::Controllers.at(0)) { - if (controller->CanRumble()) { +extern "C" int Controller_ShouldRumble(size_t i) { + for (const auto& controller : Ship::Window::Controllers.at(i)) { + if (controller->CanRumble() && Game::Settings.controller.extra[i].rumble_strength > 0.001f) { return 1; } } diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index 6a4fe8c86f1..dfb23571258 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -64,5 +64,5 @@ int AudioPlayer_Buffered(void); int AudioPlayer_GetDesiredBuffered(void); void AudioPlayer_Play(const uint8_t* buf, uint32_t len); void AudioMgr_CreateNextAudioBuffer(s16* samples, u32 num_samples); -int Controller_CanRumble(void); +int Controller_ShouldRumble(size_t i); #endif diff --git a/soh/src/code/padmgr.c b/soh/src/code/padmgr.c index 2ae3abaa33a..08c89869f62 100644 --- a/soh/src/code/padmgr.c +++ b/soh/src/code/padmgr.c @@ -304,7 +304,9 @@ void PadMgr_HandleRetraceMsg(PadMgr* padMgr) { osRecvMesg(queue, NULL, OS_MESG_BLOCK); osContGetReadData(padMgr->pads); - padMgr->padStatus[0].status = CVar_GetS32("gRumbleEnabled", 0) && Controller_CanRumble(); + for (i = 0; i < __osMaxControllers; i++) { + padMgr->padStatus[i].status = CVar_GetS32("gRumbleEnabled", 0) && Controller_ShouldRumble(i); + } if (padMgr->preNMIShutdown) { memset(padMgr->pads, 0, sizeof(padMgr->pads)); From bec0cd47d9381a96784d4b0688b780f859be550b Mon Sep 17 00:00:00 2001 From: Sirius902 <3645979-Sirius902@users.noreply.gitlab.com> Date: Sun, 24 Apr 2022 18:00:32 -0700 Subject: [PATCH 09/11] Add nice spacing --- libultraship/libultraship/SohImGuiImpl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libultraship/libultraship/SohImGuiImpl.cpp b/libultraship/libultraship/SohImGuiImpl.cpp index 83de91939dd..d1af45617f2 100644 --- a/libultraship/libultraship/SohImGuiImpl.cpp +++ b/libultraship/libultraship/SohImGuiImpl.cpp @@ -351,6 +351,7 @@ namespace SohImGui { bool hasPad = std::find_if(controllers.begin(), controllers.end(), [](const auto& c) { return c->HasPadConf(); }) != controllers.end(); + if (!hasPad) continue; auto menuLabel = "Controller " + std::to_string(i + 1); From 36c66edf3a06390c83a59e6d95401ba9bd97101b Mon Sep 17 00:00:00 2001 From: Sirius902 <3645979-Sirius902@users.noreply.gitlab.com> Date: Sun, 24 Apr 2022 18:13:27 -0700 Subject: [PATCH 10/11] Only display controller entry if pad connected --- libultraship/libultraship/Controller.h | 1 + libultraship/libultraship/KeyboardController.h | 1 + libultraship/libultraship/SDLController.h | 1 + libultraship/libultraship/SohImGuiImpl.cpp | 2 +- 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libultraship/libultraship/Controller.h b/libultraship/libultraship/Controller.h index 19ec7c6dd7a..a993dc681d8 100644 --- a/libultraship/libultraship/Controller.h +++ b/libultraship/libultraship/Controller.h @@ -21,6 +21,7 @@ namespace Ship { virtual void ReadFromSource() = 0; virtual void WriteToSource(ControllerCallback* controller) = 0; virtual bool CanRumble() const = 0; + virtual bool Connected() = 0; bool isRumbling; void SetButtonMapping(const std::string& szButtonName, int32_t dwScancode); diff --git a/libultraship/libultraship/KeyboardController.h b/libultraship/libultraship/KeyboardController.h index 97e2235ffab..a955bab9665 100644 --- a/libultraship/libultraship/KeyboardController.h +++ b/libultraship/libultraship/KeyboardController.h @@ -11,6 +11,7 @@ namespace Ship { void ReadFromSource(); void WriteToSource(ControllerCallback* controller); bool CanRumble() const { return false; } + bool Connected() { return true; } bool PressButton(int32_t dwScancode); bool ReleaseButton(int32_t dwScancode); diff --git a/libultraship/libultraship/SDLController.h b/libultraship/libultraship/SDLController.h index f4c84822d25..788abdcb88f 100644 --- a/libultraship/libultraship/SDLController.h +++ b/libultraship/libultraship/SDLController.h @@ -13,6 +13,7 @@ namespace Ship { void ReadFromSource(); void WriteToSource(ControllerCallback* controller); bool CanRumble() const { return SDL_GameControllerHasRumble(Cont); } + bool Connected() { return Cont != nullptr; } std::string GetGuid() { return guid; }; diff --git a/libultraship/libultraship/SohImGuiImpl.cpp b/libultraship/libultraship/SohImGuiImpl.cpp index d1af45617f2..d93792d5552 100644 --- a/libultraship/libultraship/SohImGuiImpl.cpp +++ b/libultraship/libultraship/SohImGuiImpl.cpp @@ -349,7 +349,7 @@ namespace SohImGui { if (ImGui::BeginMenu("Controller")) { for (const auto& [i, controllers] : Ship::Window::Controllers) { bool hasPad = std::find_if(controllers.begin(), controllers.end(), [](const auto& c) { - return c->HasPadConf(); + return c->HasPadConf() && c->Connected(); }) != controllers.end(); if (!hasPad) continue; From fbce0553240118b77e9bfa00b22e71981f8fa985 Mon Sep 17 00:00:00 2001 From: Sirius902 <3645979-Sirius902@users.noreply.gitlab.com> Date: Sun, 24 Apr 2022 18:19:32 -0700 Subject: [PATCH 11/11] Const some stuff --- libultraship/libultraship/Controller.h | 5 +++-- libultraship/libultraship/KeyboardController.h | 4 ++-- libultraship/libultraship/SDLController.h | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/libultraship/libultraship/Controller.h b/libultraship/libultraship/Controller.h index a993dc681d8..256b31fee9b 100644 --- a/libultraship/libultraship/Controller.h +++ b/libultraship/libultraship/Controller.h @@ -20,14 +20,15 @@ namespace Ship { void Read(OSContPad* pad); virtual void ReadFromSource() = 0; virtual void WriteToSource(ControllerCallback* controller) = 0; + virtual bool Connected() const = 0; virtual bool CanRumble() const = 0; - virtual bool Connected() = 0; bool isRumbling; void SetButtonMapping(const std::string& szButtonName, int32_t dwScancode); std::shared_ptr GetAttachment() { return Attachment; } int32_t GetControllerNumber() { return dwControllerNumber; } - virtual bool HasPadConf() = 0; + + virtual bool HasPadConf() const = 0; virtual std::optional GetPadConfSection() = 0; protected: diff --git a/libultraship/libultraship/KeyboardController.h b/libultraship/libultraship/KeyboardController.h index a955bab9665..f6c109ca745 100644 --- a/libultraship/libultraship/KeyboardController.h +++ b/libultraship/libultraship/KeyboardController.h @@ -10,15 +10,15 @@ namespace Ship { void ReadFromSource(); void WriteToSource(ControllerCallback* controller); + bool Connected() const { return true; } bool CanRumble() const { return false; } - bool Connected() { return true; } bool PressButton(int32_t dwScancode); bool ReleaseButton(int32_t dwScancode); void ReleaseAllButtons(); + bool HasPadConf() const { return false; } std::optional GetPadConfSection() { return {}; } - bool HasPadConf() { return false; }; protected: std::string GetControllerType(); diff --git a/libultraship/libultraship/SDLController.h b/libultraship/libultraship/SDLController.h index 788abdcb88f..138466a8923 100644 --- a/libultraship/libultraship/SDLController.h +++ b/libultraship/libultraship/SDLController.h @@ -12,13 +12,13 @@ namespace Ship { void ReadFromSource(); void WriteToSource(ControllerCallback* controller); + bool Connected() const { return Cont != nullptr; } bool CanRumble() const { return SDL_GameControllerHasRumble(Cont); } - bool Connected() { return Cont != nullptr; } std::string GetGuid() { return guid; }; + bool HasPadConf() const { return true; } std::optional GetPadConfSection(); - bool HasPadConf() { return true; }; protected: std::string GetControllerType();