From 9a3fd76b25f0db3804789891a10c51568121bf0c Mon Sep 17 00:00:00 2001 From: t895 Date: Wed, 21 Feb 2024 08:13:54 -0500 Subject: [PATCH 1/3] android: Enable all controller styles on emulation shutdown --- src/android/app/src/main/jni/native.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp index 4ea82e2170..1226219ad2 100644 --- a/src/android/app/src/main/jni/native.cpp +++ b/src/android/app/src/main/jni/native.cpp @@ -292,6 +292,9 @@ void EmulationSession::ShutdownEmulation() { // Unload user input. m_system.HIDCore().UnloadInputDevices(); + // Enable all controllers + m_system.HIDCore().SetSupportedStyleTag({Core::HID::NpadStyleSet::All}); + // Shutdown the main emulated process if (m_load_result == Core::SystemResultStatus::Success) { m_system.DetachDebugger(); From 45f450fca5c7fabbb30e0d193d1f4a1be6bd287b Mon Sep 17 00:00:00 2001 From: t895 Date: Wed, 21 Feb 2024 08:17:30 -0500 Subject: [PATCH 2/3] android: Add additional check for hasMapping Controls can have no mapping if they are either "[empty]" or and empty string. This was causing an issue if you reset mapping on all controllers and then tried to play a game. The check to determine whether auto mapping was required would fail and leave you will no mapped controllers. This feels a bit like user error but it smooths things out if you forget so I see it as necessary. --- .../org/yuzu/yuzu_emu/features/input/model/PlayerInput.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/input/model/PlayerInput.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/input/model/PlayerInput.kt index d35de80c47..a84ac77a22 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/input/model/PlayerInput.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/input/model/PlayerInput.kt @@ -64,17 +64,17 @@ data class PlayerInput( fun hasMapping(): Boolean { var hasMapping = false buttons.forEach { - if (it != "[empty]") { + if (it != "[empty]" && it.isNotEmpty()) { hasMapping = true } } analogs.forEach { - if (it != "[empty]") { + if (it != "[empty]" && it.isNotEmpty()) { hasMapping = true } } motions.forEach { - if (it != "[empty]") { + if (it != "[empty]" && it.isNotEmpty()) { hasMapping = true } } From de5422b1fde51a64d7ab887f2bf36465ee5e66ac Mon Sep 17 00:00:00 2001 From: t895 Date: Wed, 21 Feb 2024 08:21:43 -0500 Subject: [PATCH 3/3] android: Connect controllers with supported styles If you tried to connect a controller that was previously configured with an unsupported style for your game, when you try to connect that controller, it will immediately disconnect. This ensures that the controller that is being connected will be changed to the first supported style index before being connected. --- src/android/app/src/main/jni/native_input.cpp | 76 +++++++++++-------- 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/src/android/app/src/main/jni/native_input.cpp b/src/android/app/src/main/jni/native_input.cpp index 37a65f2b81..4935a46070 100644 --- a/src/android/app/src/main/jni/native_input.cpp +++ b/src/android/app/src/main/jni/native_input.cpp @@ -102,8 +102,50 @@ void ApplyControllerConfig(size_t player_index, } } +std::vector GetSupportedStyles(int player_index) { + auto& hid_core = EmulationSession::GetInstance().System().HIDCore(); + const auto npad_style_set = hid_core.GetSupportedStyleTag(); + std::vector supported_indexes; + if (npad_style_set.fullkey == 1) { + supported_indexes.push_back(static_cast(Core::HID::NpadStyleIndex::Fullkey)); + } + + if (npad_style_set.joycon_dual == 1) { + supported_indexes.push_back(static_cast(Core::HID::NpadStyleIndex::JoyconDual)); + } + + if (npad_style_set.joycon_left == 1) { + supported_indexes.push_back(static_cast(Core::HID::NpadStyleIndex::JoyconLeft)); + } + + if (npad_style_set.joycon_right == 1) { + supported_indexes.push_back(static_cast(Core::HID::NpadStyleIndex::JoyconRight)); + } + + if (player_index == 0 && npad_style_set.handheld == 1) { + supported_indexes.push_back(static_cast(Core::HID::NpadStyleIndex::Handheld)); + } + + if (npad_style_set.gamecube == 1) { + supported_indexes.push_back(static_cast(Core::HID::NpadStyleIndex::GameCube)); + } + + return supported_indexes; +} + void ConnectController(size_t player_index, bool connected) { auto& hid_core = EmulationSession::GetInstance().System().HIDCore(); + ApplyControllerConfig(player_index, [&](Core::HID::EmulatedController* controller) { + auto supported_styles = GetSupportedStyles(player_index); + auto controller_style = controller->GetNpadStyleIndex(true); + auto style = std::find(supported_styles.begin(), supported_styles.end(), + static_cast(controller_style)); + if (style == supported_styles.end() && !supported_styles.empty()) { + controller->SetNpadStyleIndex( + static_cast(supported_styles[0])); + } + }); + if (player_index == 0) { auto* handheld = hid_core.GetEmulatedController(Core::HID::NpadIdType::Handheld); auto* player_one = hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1); @@ -522,36 +564,10 @@ jint Java_org_yuzu_yuzu_1emu_features_input_NativeInput_getButtonNameImpl(JNIEnv jintArray Java_org_yuzu_yuzu_1emu_features_input_NativeInput_getSupportedStyleTagsImpl( JNIEnv* env, jobject j_obj, jint j_player_index) { - auto& hid_core = EmulationSession::GetInstance().System().HIDCore(); - const auto npad_style_set = hid_core.GetSupportedStyleTag(); - std::vector supported_indexes; - if (npad_style_set.fullkey == 1) { - supported_indexes.push_back(static_cast(Core::HID::NpadStyleIndex::Fullkey)); - } - - if (npad_style_set.joycon_dual == 1) { - supported_indexes.push_back(static_cast(Core::HID::NpadStyleIndex::JoyconDual)); - } - - if (npad_style_set.joycon_left == 1) { - supported_indexes.push_back(static_cast(Core::HID::NpadStyleIndex::JoyconLeft)); - } - - if (npad_style_set.joycon_right == 1) { - supported_indexes.push_back(static_cast(Core::HID::NpadStyleIndex::JoyconRight)); - } - - if (j_player_index == 0 && npad_style_set.handheld == 1) { - supported_indexes.push_back(static_cast(Core::HID::NpadStyleIndex::Handheld)); - } - - if (npad_style_set.gamecube == 1) { - supported_indexes.push_back(static_cast(Core::HID::NpadStyleIndex::GameCube)); - } - - jintArray j_supported_indexes = env->NewIntArray(supported_indexes.size()); - env->SetIntArrayRegion(j_supported_indexes, 0, supported_indexes.size(), - supported_indexes.data()); + auto supported_styles = GetSupportedStyles(j_player_index); + jintArray j_supported_indexes = env->NewIntArray(supported_styles.size()); + env->SetIntArrayRegion(j_supported_indexes, 0, supported_styles.size(), + supported_styles.data()); return j_supported_indexes; }