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 index 464e4091b..842e8e1d5 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/speedoverlay/SpeedOverlayPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/speedoverlay/SpeedOverlayPatch.kt @@ -2,18 +2,16 @@ 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.addInstructions 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.RestoreSlideToSeekBehaviorFingerprint 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 +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Patch( name = "Disable speed overlay", @@ -43,43 +41,32 @@ import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction ) @Suppress("unused") object SpeedOverlayPatch : BytecodePatch( - setOf(SpeedOverlayFingerprint) + setOf( + RestoreSlideToSeekBehaviorFingerprint, + SpeedOverlayFingerprint + ) ) { override fun execute(context: BytecodeContext) { - SpeedOverlayFingerprint.result?.let { - it.mutableMethod.apply { - val endIndex = it.scanResult.patternScanResult!!.endIndex + arrayOf( + RestoreSlideToSeekBehaviorFingerprint, + SpeedOverlayFingerprint + ).forEach { fingerprint -> + fingerprint.result?.let { + it.mutableMethod.apply { + val insertIndex = it.scanResult.patternScanResult!!.endIndex + 1 + val insertRegister = + getInstruction(insertIndex).registerA - 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 + addInstructions( + insertIndex, """ + invoke-static {v$insertRegister}, $PLAYER->disableSpeedOverlay(Z)Z + move-result v$insertRegister """ ) - removeInstruction(replaceIndex) - - break } - } - } ?: throw SpeedOverlayFingerprint.exception - + } ?: throw fingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/speedoverlay/fingerprints/RestoreSlideToSeekBehaviorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/player/speedoverlay/fingerprints/RestoreSlideToSeekBehaviorFingerprint.kt new file mode 100644 index 000000000..089e2a5d3 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/player/speedoverlay/fingerprints/RestoreSlideToSeekBehaviorFingerprint.kt @@ -0,0 +1,15 @@ +package app.revanced.patches.youtube.player.speedoverlay.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint +import app.revanced.util.bytecode.isWide32LiteralExists +import com.android.tools.smali.dexlib2.Opcode + +/** + * This value restores the 'Slide to seek' behavior. + */ +object RestoreSlideToSeekBehaviorFingerprint : MethodFingerprint( + returnType = "Z", + parameters = emptyList(), + opcodes = listOf(Opcode.MOVE_RESULT), + customFingerprint = { methodDef, _ -> methodDef.isWide32LiteralExists(45411329) } +) \ 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 index 1f87a09e0..b74f1f0ab 100644 --- 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 @@ -1,36 +1,15 @@ package app.revanced.patches.youtube.player.speedoverlay.fingerprints import app.revanced.patcher.fingerprint.MethodFingerprint +import app.revanced.util.bytecode.isWide32LiteralExists import com.android.tools.smali.dexlib2.Opcode +/** + * This value disables 'Playing at 2x speed' while holding down. + */ 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" } + returnType = "Z", + parameters = emptyList(), + opcodes = listOf(Opcode.MOVE_RESULT), + customFingerprint = { methodDef, _ -> methodDef.isWide32LiteralExists(45411330) } ) \ 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 5daedb125..082c35746 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -89,9 +89,7 @@ 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 'Playing at 2x speed' while holding down." Disable speed overlay Shorts player is enabled at app startup. Shorts player is disabled at app startup.