feat(YouTube/Disable speed overlay): Disable speed overlay now restores the old Slide to seek behavior 🥳

This commit is contained in:
inotia00 2023-11-09 16:14:30 +09:00
parent 0cbf99a8fa
commit 0ede198754
4 changed files with 46 additions and 67 deletions

View File

@ -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<OneRegisterInstruction>(insertIndex).registerA
for (index in endIndex downTo 0) {
if (getInstruction(index).opcode != Opcode.RETURN_VOID) continue
val replaceIndex = index + 1
val replaceReference =
getInstruction<ReferenceInstruction>(replaceIndex).reference
val replaceInstruction = getInstruction<TwoRegisterInstruction>(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

View File

@ -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) }
)

View File

@ -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) }
)

View File

@ -89,9 +89,7 @@
<string name="revanced_disable_landscape_mode_title">Disable landscape mode</string>
<string name="revanced_disable_quic_protocol_summary">"Disable CronetEngine's QUIC protocol."</string>
<string name="revanced_disable_quic_protocol_title">Disable QUIC protocol</string>
<string name="revanced_disable_speed_overlay_summary">"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."</string>
<string name="revanced_disable_speed_overlay_summary">"Disable 'Playing at 2x speed' while holding down."</string>
<string name="revanced_disable_speed_overlay_title">Disable speed overlay</string>
<string name="revanced_disable_startup_shorts_player_summary_off">Shorts player is enabled at app startup.</string>
<string name="revanced_disable_startup_shorts_player_summary_on">Shorts player is disabled at app startup.</string>