diff --git a/src/main/kotlin/app/revanced/patches/shared/settingmenu/SettingsMenuPatch.kt b/src/main/kotlin/app/revanced/patches/shared/settingmenu/SettingsMenuPatch.kt new file mode 100644 index 000000000..3ed3ba57c --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/shared/settingmenu/SettingsMenuPatch.kt @@ -0,0 +1,39 @@ +package app.revanced.patches.shared.settingmenu + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.shared.integrations.Constants.PATCHES_PATH +import app.revanced.patches.shared.settingmenu.fingerprints.SettingsMenuFingerprint +import app.revanced.patches.shared.viewgroup.ViewGroupMarginLayoutParamsHookPatch +import app.revanced.util.getTargetIndexWithFieldReferenceTypeOrThrow +import app.revanced.util.resultOrThrow +import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction + +@Patch( + description = "Hide the settings menu for YouTube or YouTube Music.", + dependencies = [ViewGroupMarginLayoutParamsHookPatch::class] +) +object SettingsMenuPatch : BytecodePatch( + setOf(SettingsMenuFingerprint) +) { + private const val INTEGRATIONS_CLASS_DESCRIPTOR = + "$PATCHES_PATH/SettingsMenuPatch;" + + override fun execute(context: BytecodeContext) { + + SettingsMenuFingerprint.resultOrThrow().mutableMethod.apply { + val insertIndex = + getTargetIndexWithFieldReferenceTypeOrThrow("Landroid/support/v7/widget/RecyclerView;") + val insertRegister = getInstruction(insertIndex).registerA + + addInstruction( + insertIndex, + "invoke-static {v$insertRegister}, " + + "$INTEGRATIONS_CLASS_DESCRIPTOR->hideSettingsMenu(Landroid/support/v7/widget/RecyclerView;)V" + ) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/components/fingerprints/SettingsMenuFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/settingmenu/fingerprints/SettingsMenuFingerprint.kt similarity index 74% rename from src/main/kotlin/app/revanced/patches/youtube/general/components/fingerprints/SettingsMenuFingerprint.kt rename to src/main/kotlin/app/revanced/patches/shared/settingmenu/fingerprints/SettingsMenuFingerprint.kt index 59f65767d..67f06179a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/components/fingerprints/SettingsMenuFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/shared/settingmenu/fingerprints/SettingsMenuFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.general.components.fingerprints +package app.revanced.patches.shared.settingmenu.fingerprints import app.revanced.util.fingerprint.LiteralValueFingerprint diff --git a/src/main/kotlin/app/revanced/patches/shared/viewgroup/ViewGroupMarginLayoutParamsHookPatch.kt b/src/main/kotlin/app/revanced/patches/shared/viewgroup/ViewGroupMarginLayoutParamsHookPatch.kt new file mode 100644 index 000000000..adda1e540 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/shared/viewgroup/ViewGroupMarginLayoutParamsHookPatch.kt @@ -0,0 +1,43 @@ +package app.revanced.patches.shared.viewgroup + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchException +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.shared.viewgroup.fingerprints.ViewGroupMarginFingerprint +import app.revanced.patches.shared.viewgroup.fingerprints.ViewGroupMarginParentFingerprint +import app.revanced.patches.shared.integrations.Constants.INTEGRATIONS_UTILS_CLASS_DESCRIPTOR +import app.revanced.util.resultOrThrow + +@Patch( + description = "Hook YouTube or YouTube Music to use ViewGroup.MarginLayoutParams in the integration.", +) +object ViewGroupMarginLayoutParamsHookPatch : BytecodePatch( + setOf(ViewGroupMarginParentFingerprint) +) { + override fun execute(context: BytecodeContext) { + + val method = + context.findClass(INTEGRATIONS_UTILS_CLASS_DESCRIPTOR)?.mutableClass?.methods?.first { method -> + method.name == "hideViewGroupByMarginLayoutParams" + } ?: throw PatchException("Could not find hideViewGroupByMarginLayoutParams method") + + ViewGroupMarginFingerprint.resolve( + context, + ViewGroupMarginParentFingerprint.resultOrThrow().classDef + ) + ViewGroupMarginFingerprint.resultOrThrow().let { + it.mutableMethod.apply { + val setViewGroupMarginCall = "$definingClass->$name(Landroid/view/View;II)V" + + method.addInstructions( + 0, """ + const/4 v0, 0x0 + invoke-static {p0, v0, v0}, $setViewGroupMarginCall + """ + ) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/shared/viewgroup/fingerprints/ViewGroupMarginFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/viewgroup/fingerprints/ViewGroupMarginFingerprint.kt new file mode 100644 index 000000000..82e4b5df0 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/shared/viewgroup/fingerprints/ViewGroupMarginFingerprint.kt @@ -0,0 +1,11 @@ +package app.revanced.patches.shared.viewgroup.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +internal object ViewGroupMarginFingerprint : MethodFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC, + parameters = listOf("Landroid/view/View;", "I", "I"), +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/shared/viewgroup/fingerprints/ViewGroupMarginParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/viewgroup/fingerprints/ViewGroupMarginParentFingerprint.kt new file mode 100644 index 000000000..857f42af7 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/shared/viewgroup/fingerprints/ViewGroupMarginParentFingerprint.kt @@ -0,0 +1,12 @@ +package app.revanced.patches.shared.viewgroup.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +internal object ViewGroupMarginParentFingerprint : MethodFingerprint( + returnType = "Landroid/view/ViewGroup${'$'}LayoutParams;", + accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC, + parameters = listOf("Ljava/lang/Class;", "Landroid/view/ViewGroup${'$'}LayoutParams;"), + strings = listOf("SafeLayoutParams"), +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/components/LayoutComponentsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/components/LayoutComponentsPatch.kt index 7ed0dbf65..297c3a878 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/components/LayoutComponentsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/components/LayoutComponentsPatch.kt @@ -8,27 +8,26 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.PatchException import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.shared.litho.LithoFilterPatch +import app.revanced.patches.shared.settingmenu.SettingsMenuPatch +import app.revanced.patches.shared.viewgroup.ViewGroupMarginLayoutParamsHookPatch import app.revanced.patches.youtube.general.components.fingerprints.AccountListFingerprint import app.revanced.patches.youtube.general.components.fingerprints.AccountListParentFingerprint import app.revanced.patches.youtube.general.components.fingerprints.AccountMenuFingerprint +import app.revanced.patches.youtube.general.components.fingerprints.AccountMenuParentFingerprint import app.revanced.patches.youtube.general.components.fingerprints.AccountSwitcherAccessibilityLabelFingerprint import app.revanced.patches.youtube.general.components.fingerprints.AppBlockingCheckResultToStringFingerprint import app.revanced.patches.youtube.general.components.fingerprints.BottomUiContainerFingerprint import app.revanced.patches.youtube.general.components.fingerprints.FloatingMicrophoneFingerprint import app.revanced.patches.youtube.general.components.fingerprints.PiPNotificationFingerprint -import app.revanced.patches.youtube.general.components.fingerprints.SettingsMenuFingerprint import app.revanced.patches.youtube.general.components.fingerprints.TooltipContentFullscreenFingerprint import app.revanced.patches.youtube.general.components.fingerprints.TooltipContentViewFingerprint import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE -import app.revanced.patches.youtube.utils.fingerprints.AccountMenuParentFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.AccountSwitcherAccessibility import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.patches.youtube.utils.viewgroup.ViewGroupMarginLayoutParamsHookPatch import app.revanced.util.getTargetIndexOrThrow -import app.revanced.util.getTargetIndexWithFieldReferenceTypeOrThrow import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch @@ -46,6 +45,7 @@ object LayoutComponentsPatch : BaseBytecodePatch( description = "Adds options to hide general layout components.", dependencies = setOf( LithoFilterPatch::class, + SettingsMenuPatch::class, SettingsPatch::class, SharedResourceIdPatch::class, ViewGroupMarginLayoutParamsHookPatch::class @@ -59,7 +59,6 @@ object LayoutComponentsPatch : BaseBytecodePatch( BottomUiContainerFingerprint, FloatingMicrophoneFingerprint, PiPNotificationFingerprint, - SettingsMenuFingerprint, TooltipContentFullscreenFingerprint, TooltipContentViewFingerprint ) @@ -190,24 +189,6 @@ object LayoutComponentsPatch : BaseBytecodePatch( // endregion - // region patch for hide settings menu - - SettingsMenuFingerprint.resultOrThrow().let { - it.mutableMethod.apply { - val insertIndex = - getTargetIndexWithFieldReferenceTypeOrThrow("Landroid/support/v7/widget/RecyclerView;") - val insertRegister = getInstruction(insertIndex).registerA - - addInstruction( - insertIndex, - "invoke-static {v$insertRegister}, " + - "$GENERAL_CLASS_DESCRIPTOR->hideSettingsMenu(Landroid/support/v7/widget/RecyclerView;)V" - ) - } - } - - // endregion - // region patch for hide snack bar BottomUiContainerFingerprint.resultOrThrow().let { diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/AccountMenuParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/general/components/fingerprints/AccountMenuParentFingerprint.kt similarity index 86% rename from src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/AccountMenuParentFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/general/components/fingerprints/AccountMenuParentFingerprint.kt index 1ad9860a1..927439b10 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/AccountMenuParentFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/components/fingerprints/AccountMenuParentFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.utils.fingerprints +package app.revanced.patches.youtube.general.components.fingerprints import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.CompactLink import app.revanced.util.fingerprint.LiteralValueFingerprint diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/viewgroup/ViewGroupMarginLayoutParamsHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/viewgroup/ViewGroupMarginLayoutParamsHookPatch.kt deleted file mode 100644 index af8179ab2..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/viewgroup/ViewGroupMarginLayoutParamsHookPatch.kt +++ /dev/null @@ -1,52 +0,0 @@ -package app.revanced.patches.youtube.utils.viewgroup - -import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.InstructionExtensions.addInstructions -import app.revanced.patcher.extensions.InstructionExtensions.getInstruction -import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patcher.patch.PatchException -import app.revanced.patcher.patch.annotation.Patch -import app.revanced.patches.youtube.utils.fingerprints.AccountMenuParentFingerprint -import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH -import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch -import app.revanced.patches.youtube.utils.viewgroup.fingerprints.SetViewGroupMarginFingerprint -import app.revanced.util.resultOrThrow -import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction - -@Patch( - description = "Hook YouTube to use ViewGroup.MarginLayoutParams in the integration.", - dependencies = [SharedResourceIdPatch::class], -) -object ViewGroupMarginLayoutParamsHookPatch : BytecodePatch( - setOf(AccountMenuParentFingerprint) -) { - private const val INTEGRATIONS_CLASS_DESCRIPTOR = - "$UTILS_PATH/ViewGroupMarginLayoutParamsPatch;" - - override fun execute(context: BytecodeContext) { - - val method = - context.findClass(INTEGRATIONS_CLASS_DESCRIPTOR)?.mutableClass?.methods?.first { method -> - method.name == "hideViewGroupByMarginLayoutParams" - } ?: throw PatchException("Could not find hideViewGroupByMarginLayoutParams method") - - SetViewGroupMarginFingerprint.resolve( - context, - AccountMenuParentFingerprint.resultOrThrow().classDef - ) - SetViewGroupMarginFingerprint.resultOrThrow().let { - it.mutableMethod.apply { - val setViewGroupMarginIndex = it.scanResult.patternScanResult!!.startIndex - val setViewGroupMarginReference = - getInstruction(setViewGroupMarginIndex).reference - - method.addInstructions( - 0, """ - const/4 v0, 0x0 - invoke-static {p0, v0, v0}, $setViewGroupMarginReference - """ - ) - } - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/viewgroup/fingerprints/SetViewGroupMarginFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/viewgroup/fingerprints/SetViewGroupMarginFingerprint.kt deleted file mode 100644 index 1253cf6f3..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/viewgroup/fingerprints/SetViewGroupMarginFingerprint.kt +++ /dev/null @@ -1,18 +0,0 @@ -package app.revanced.patches.youtube.utils.viewgroup.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.MethodFingerprint -import com.android.tools.smali.dexlib2.AccessFlags -import com.android.tools.smali.dexlib2.Opcode - -internal object SetViewGroupMarginFingerprint : MethodFingerprint( - returnType = "V", - accessFlags = AccessFlags.PRIVATE or AccessFlags.FINAL, - parameters = listOf("Z"), - opcodes = listOf( - Opcode.INVOKE_STATIC, - Opcode.IGET_OBJECT, - Opcode.CONST_16, - Opcode.INVOKE_VIRTUAL - ) -) \ No newline at end of file diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 5874def65..0db92bfd0 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -171,7 +171,7 @@