From 6b891d9737f394bd845638aed4d0d3a5f098ee7e Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Wed, 7 Aug 2024 13:52:04 +0900 Subject: [PATCH] feat(YouTube Music): add `Change share sheet` patch --- .../music/misc/share/ShareSheetPatch.kt | 62 +++++++++++++++++++ .../BottomSheetRecyclerViewFingerprint.kt | 13 ++++ .../utils/resourceid/SharedResourceIdPatch.kt | 2 + .../music/settings/host/values/strings.xml | 2 + 4 files changed, 79 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/music/misc/share/ShareSheetPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/music/misc/share/fingerprints/BottomSheetRecyclerViewFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/music/misc/share/ShareSheetPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/share/ShareSheetPatch.kt new file mode 100644 index 000000000..204d168a0 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/misc/share/ShareSheetPatch.kt @@ -0,0 +1,62 @@ +package app.revanced.patches.music.misc.share + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patches.music.misc.share.fingerprints.BottomSheetRecyclerViewFingerprint +import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKAGE +import app.revanced.patches.music.utils.integrations.Constants.COMPONENTS_PATH +import app.revanced.patches.music.utils.integrations.Constants.MISC_PATH +import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch +import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.BottomSheetRecyclerView +import app.revanced.patches.music.utils.settings.CategoryType +import app.revanced.patches.music.utils.settings.SettingsPatch +import app.revanced.patches.shared.litho.LithoFilterPatch +import app.revanced.util.getTargetIndexOrThrow +import app.revanced.util.getWideLiteralInstructionIndex +import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow +import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction + +@Suppress("unused") +object ShareSheetPatch : BaseBytecodePatch( + name = "Change share sheet", + description = "Add option to change from in-app share sheet to system share sheet.", + dependencies = setOf( + LithoFilterPatch::class, + SettingsPatch::class, + SharedResourceIdPatch::class + ), + compatiblePackages = COMPATIBLE_PACKAGE, + fingerprints = setOf(BottomSheetRecyclerViewFingerprint) +) { + private const val INTEGRATIONS_CLASS_DESCRIPTOR = + "$MISC_PATH/ShareSheetPatch;" + + private const val FILTER_CLASS_DESCRIPTOR = + "$COMPONENTS_PATH/ShareSheetMenuFilter;" + + override fun execute(context: BytecodeContext) { + + BottomSheetRecyclerViewFingerprint.resultOrThrow().mutableMethod.apply { + val constIndex = getWideLiteralInstructionIndex(BottomSheetRecyclerView) + val targetIndex = getTargetIndexOrThrow(constIndex, Opcode.CHECK_CAST) + val targetRegister = getInstruction(targetIndex).registerA + + addInstruction( + targetIndex + 1, + "invoke-static {v$targetRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->onShareSheetMenuCreate(Landroid/support/v7/widget/RecyclerView;)V" + ) + } + + LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR) + + SettingsPatch.addSwitchPreference( + CategoryType.MISC, + "revanced_change_share_sheet", + "false" + ) + + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/misc/share/fingerprints/BottomSheetRecyclerViewFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/misc/share/fingerprints/BottomSheetRecyclerViewFingerprint.kt new file mode 100644 index 000000000..4de97d056 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/misc/share/fingerprints/BottomSheetRecyclerViewFingerprint.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.music.misc.share.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.BottomSheetRecyclerView +import app.revanced.util.fingerprint.LiteralValueFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +internal object BottomSheetRecyclerViewFingerprint : LiteralValueFingerprint( + returnType = "Lj${'$'}/util/Optional;", + accessFlags = AccessFlags.PROTECTED or AccessFlags.FINAL, + parameters = emptyList(), + literalSupplier = { BottomSheetRecyclerView } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/utils/resourceid/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/resourceid/SharedResourceIdPatch.kt index 5b22e16f1..e911ff8b8 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/resourceid/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/resourceid/SharedResourceIdPatch.kt @@ -17,6 +17,7 @@ import app.revanced.patches.shared.mapping.ResourceType.STYLE object SharedResourceIdPatch : ResourcePatch() { var AccountSwitcherAccessibility = -1L var AudioVideoSwitchToggle = -1L + var BottomSheetRecyclerView = -1L var ButtonContainer = -1L var ButtonIconPaddingMedium = -1L var ChipCloud = -1L @@ -61,6 +62,7 @@ object SharedResourceIdPatch : ResourcePatch() { AccountSwitcherAccessibility = getId(STRING, "account_switcher_accessibility_label") AudioVideoSwitchToggle = getId(ID, "audio_video_switch_toggle") + BottomSheetRecyclerView = getId(LAYOUT, "bottom_sheet_recycler_view") ButtonContainer = getId(ID, "button_container") ButtonIconPaddingMedium = getId(DIMEN, "button_icon_padding_medium") ChipCloud = getId(LAYOUT, "chip_cloud") diff --git a/src/main/resources/music/settings/host/values/strings.xml b/src/main/resources/music/settings/host/values/strings.xml index f544c11d0..b39aec33e 100644 --- a/src/main/resources/music/settings/host/values/strings.xml +++ b/src/main/resources/music/settings/host/values/strings.xml @@ -371,6 +371,8 @@ Some features may not work properly in the old player layout." Bypass image region restrictions Replaces the domain that is blocked in some regions so that playlist thumbnails, channel avatars, etc. can be received. + Change share sheet + Change from in-app share sheet to system share sheet. Enable Cairo splash animation Enables Cairo splash animation when the app starts up. Enable debug logging