From 98d00848c9a0aa0247d77e9ae16450697a6c154c Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sun, 26 Feb 2023 22:38:09 +0100 Subject: [PATCH] feat(youtube/hide-autoplay-button): do not disable autoplay button when hidden Signed-off-by: oSumAtrIX --- .../AutoNavInformerFingerprint.kt | 20 ------ .../autoplay/patch/HideAutoplayButtonPatch.kt | 65 ++++++++----------- 2 files changed, 27 insertions(+), 58 deletions(-) delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/fingerprints/AutoNavInformerFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/fingerprints/AutoNavInformerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/fingerprints/AutoNavInformerFingerprint.kt deleted file mode 100644 index e980dffcb..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/fingerprints/AutoNavInformerFingerprint.kt +++ /dev/null @@ -1,20 +0,0 @@ -package app.revanced.patches.youtube.layout.buttons.autoplay.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode - -object AutoNavInformerFingerprint : MethodFingerprint( - "Z", - AccessFlags.PUBLIC or AccessFlags.FINAL, - opcodes = listOf( - Opcode.IGET_OBJECT, - Opcode.INVOKE_INTERFACE, - Opcode.MOVE_RESULT_OBJECT, - Opcode.CHECK_CAST, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT, - ), - customFingerprint = { it.definingClass.endsWith("WillAutonavInformer;") } -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/patch/HideAutoplayButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/patch/HideAutoplayButtonPatch.kt index e3ffd9c43..cdc013341 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/patch/HideAutoplayButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/patch/HideAutoplayButtonPatch.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.layout.buttons.autoplay.patch +import app.revanced.extensions.toErrorResult import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version @@ -15,7 +16,6 @@ import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch import app.revanced.patches.shared.settings.preference.impl.StringResource import app.revanced.patches.shared.settings.preference.impl.SwitchPreference import app.revanced.patches.youtube.layout.buttons.autoplay.annotations.AutoplayButtonCompatibility -import app.revanced.patches.youtube.layout.buttons.autoplay.fingerprints.AutoNavInformerFingerprint import app.revanced.patches.youtube.layout.buttons.autoplay.fingerprints.LayoutConstructorFingerprint import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch @@ -31,9 +31,7 @@ import org.jf.dexlib2.iface.reference.MethodReference @AutoplayButtonCompatibility @Version("0.0.1") class HideAutoplayButtonPatch : BytecodePatch( - listOf( - LayoutConstructorFingerprint, AutoNavInformerFingerprint - ) + listOf(LayoutConstructorFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( @@ -43,49 +41,40 @@ class HideAutoplayButtonPatch : BytecodePatch( true, StringResource("revanced_hide_autoplay_button_summary_on", "Autoplay button is hidden"), StringResource("revanced_hide_autoplay_button_summary_off", "Autoplay button is shown") - ) + ), ) - val autoNavInformerMethod = AutoNavInformerFingerprint.result!!.mutableMethod + LayoutConstructorFingerprint.result?.mutableMethod?.apply { + val layoutGenMethodInstructions = implementation!!.instructions - val layoutGenMethodResult = LayoutConstructorFingerprint.result!! - val layoutGenMethod = layoutGenMethodResult.mutableMethod - val layoutGenMethodInstructions = layoutGenMethod.implementation!!.instructions + // resolve the offsets such as ... + val autoNavPreviewStubId = ResourceMappingPatch.resourceMappings.single { + it.name == "autonav_preview_stub" + }.id - // resolve the offsets such as ... - val autoNavPreviewStubId = ResourceMappingPatch.resourceMappings.single { - it.name == "autonav_preview_stub" - }.id - // where to insert the branch instructions and ... - val insertIndex = layoutGenMethodInstructions.indexOfFirst { - (it as? WideLiteralInstruction)?.wideLiteral == autoNavPreviewStubId - } - // where to branch away - val branchIndex = layoutGenMethodInstructions.subList(insertIndex + 1, layoutGenMethodInstructions.size - 1).indexOfFirst { - ((it as? ReferenceInstruction)?.reference as? MethodReference)?.name == "addOnLayoutChangeListener" - } + 2 + // where to insert the branch instructions and ... + val insertIndex = layoutGenMethodInstructions.indexOfFirst { + (it as? WideLiteralInstruction)?.wideLiteral == autoNavPreviewStubId + } - val jumpInstruction = layoutGenMethodInstructions[insertIndex + branchIndex] as Instruction - layoutGenMethod.addInstructions( - insertIndex, """ + // where to branch away + val branchIndex = + layoutGenMethodInstructions.subList(insertIndex + 1, layoutGenMethodInstructions.size - 1) + .indexOfFirst { + ((it as? ReferenceInstruction)?.reference as? MethodReference)?.name == "addOnLayoutChangeListener" + } + 2 + + val jumpInstruction = layoutGenMethodInstructions[insertIndex + branchIndex] as Instruction + + addInstructions( + insertIndex, + """ invoke-static {}, Lapp/revanced/integrations/patches/HideAutoplayButtonPatch;->isButtonShown()Z move-result v11 if-eqz v11, :hidden """, listOf(ExternalLabel("hidden", jumpInstruction)) - ) - - //force disable autoplay since it's hard to do without the button - autoNavInformerMethod.addInstructions( - 0, """ - invoke-static {}, Lapp/revanced/integrations/patches/HideAutoplayButtonPatch;->isButtonShown()Z - move-result v0 - if-nez v0, :hidden - const/4 v0, 0x0 - return v0 - :hidden - nop - """ - ) + ) + } ?: return LayoutConstructorFingerprint.toErrorResult() return PatchResultSuccess() }