From 2a8256aa657feea3ead0e6d4589950fbb38e23b7 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Mon, 30 Oct 2023 00:05:46 +0900 Subject: [PATCH] feat(YouTube): add `Disable speed overlay` patch --- .../player/speedoverlay/SpeedOverlayPatch.kt | 98 +++++++++++++++++++ .../fingerprints/SpeedOverlayFingerprint.kt | 36 +++++++ .../youtube/settings/host/values/strings.xml | 5 + .../youtube/settings/xml/revanced_prefs.xml | 4 + 4 files changed, 143 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/player/speedoverlay/SpeedOverlayPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/player/speedoverlay/fingerprints/SpeedOverlayFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/speedoverlay/SpeedOverlayPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/speedoverlay/SpeedOverlayPatch.kt new file mode 100644 index 000000000..32860f5db --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/player/speedoverlay/SpeedOverlayPatch.kt @@ -0,0 +1,98 @@ +package app.revanced.patches.youtube.player.speedoverlay + +import app.revanced.extensions.exception +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.youtube.player.speedoverlay.fingerprints.SpeedOverlayFingerprint +import app.revanced.patches.youtube.utils.settings.SettingsPatch +import app.revanced.util.integrations.Constants.PLAYER +import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction +import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction + +@Patch( + name = "Disable speed overlay", + description = "Disable 'Play at 2x speed' while holding down.", + dependencies = [SettingsPatch::class], + compatiblePackages = [ + CompatiblePackage( + "com.google.android.youtube", + [ + "18.25.40", + "18.27.36", + "18.29.38", + "18.30.37", + "18.31.40", + "18.32.39", + "18.33.40", + "18.34.38", + "18.35.36", + "18.36.39", + "18.37.36", + "18.38.44", + "18.39.41", + "18.40.34", + "18.41.39" + ] + ) + ] +) +@Suppress("unused") +object SpeedOverlayPatch : BytecodePatch( + setOf(SpeedOverlayFingerprint) +) { + override fun execute(context: BytecodeContext) { + + SpeedOverlayFingerprint.result?.let { + it.mutableMethod.apply { + val endIndex = it.scanResult.patternScanResult!!.endIndex + + for (index in endIndex downTo 0) { + if (getInstruction(index).opcode != Opcode.RETURN_VOID) continue + + val replaceIndex = index + 1 + + val replaceReference = + getInstruction(replaceIndex).reference + + val replaceInstruction = getInstruction(replaceIndex) + val registerA = replaceInstruction.registerA + val registerB = replaceInstruction.registerB + + addInstructionsWithLabels( + replaceIndex + 1, """ + invoke-static { }, $PLAYER->disableSpeedOverlay()Z + move-result v$registerA + if-eqz v$registerA, :show + return-void + :show + iget-object v$registerA, v$registerB, $replaceReference + """ + ) + removeInstruction(replaceIndex) + + break + } + } + } ?: throw SpeedOverlayFingerprint.exception + + + /** + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "PREFERENCE: PLAYER_SETTINGS", + "SETTINGS: DISABLE_SPEED_OVERLAY" + ) + ) + + SettingsPatch.updatePatchStatus("Disable speed overlay") + + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/speedoverlay/fingerprints/SpeedOverlayFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/player/speedoverlay/fingerprints/SpeedOverlayFingerprint.kt new file mode 100644 index 000000000..1f87a09e0 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/player/speedoverlay/fingerprints/SpeedOverlayFingerprint.kt @@ -0,0 +1,36 @@ +package app.revanced.patches.youtube.player.speedoverlay.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.Opcode + +object SpeedOverlayFingerprint : MethodFingerprint( + returnType = "V", + opcodes = listOf( + Opcode.INVOKE_VIRTUAL, + Opcode.IGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.IF_EQZ, + Opcode.GOTO, + Opcode.IGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT_OBJECT, + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT_OBJECT, + Opcode.IPUT_OBJECT, + Opcode.IGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.CHECK_CAST, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.IGET, + Opcode.CMPL_FLOAT, + Opcode.IF_GEZ, + Opcode.IGET_OBJECT, + Opcode.INVOKE_VIRTUAL + ), + customFingerprint = { methodDef, _ -> methodDef.name == "run" } +) \ No newline at end of file diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 3824cff12..9cc2d96e6 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -90,6 +90,10 @@ Disable landscape mode "Disable CronetEngine's QUIC protocol" Disable QUIC protocol + "Disable 'Playing at 2x speed' while holding down + +Note: Disabling the speed overlay does not restore the 'Slide to seek' behavior of the old layout" + Disable speed overlay Shorts player is enabled at app startup Shorts player is disabled at app startup Disable shorts player at app startup @@ -542,6 +546,7 @@ Known issue: Official headers in search results are hidden" Suggested actions hidden Hide suggested actions "Hides suggested video overlay to play next + Known issue: Autoplay does not work" Hide suggested video overlay "Hides following shelves: diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 44c8029e7..047cf544b 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -401,6 +401,7 @@ + @@ -504,6 +505,9 @@ + +