generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(YouTube): Do not reset playback speed to 1.0x after closing comme…
…nt thread (Fixes stock YouTube bug) (#4195)
- Loading branch information
1 parent
9ce33cc
commit dda788c
Showing
6 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...c/main/java/app/revanced/extension/youtube/patches/FixPlaybackSpeedWhilePlayingPatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package app.revanced.extension.youtube.patches; | ||
|
||
import app.revanced.extension.shared.Logger; | ||
import app.revanced.extension.youtube.shared.PlayerType; | ||
|
||
@SuppressWarnings("unused") | ||
public class FixPlaybackSpeedWhilePlayingPatch { | ||
|
||
private static final float DEFAULT_YOUTUBE_PLAYBACK_SPEED = 1.0f; | ||
|
||
public static boolean playbackSpeedChanged(float playbackSpeed) { | ||
if (playbackSpeed == DEFAULT_YOUTUBE_PLAYBACK_SPEED && | ||
PlayerType.getCurrent().isMaximizedOrFullscreen()) { | ||
|
||
Logger.printDebug(() -> "Blocking call to change playback speed to 1.0x"); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
.../app/revanced/patches/youtube/misc/fix/playbackspeed/FIxPlaybackSpeedWhilePlayingPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package app.revanced.patches.youtube.misc.fix.playbackspeed | ||
|
||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels | ||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction | ||
import app.revanced.patcher.patch.bytecodePatch | ||
import app.revanced.patcher.util.smali.ExternalLabel | ||
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch | ||
import app.revanced.patches.youtube.misc.playertype.playerTypeHookPatch | ||
import app.revanced.patches.youtube.misc.playservice.is_19_34_or_greater | ||
import app.revanced.patches.youtube.misc.playservice.versionCheckPatch | ||
import app.revanced.util.indexOfFirstInstructionOrThrow | ||
import com.android.tools.smali.dexlib2.Opcode | ||
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction | ||
|
||
private const val EXTENSION_CLASS_DESCRIPTOR = | ||
"Lapp/revanced/extension/youtube/patches/FixPlaybackSpeedWhilePlayingPatch;" | ||
|
||
/** | ||
* Fixes a bug in YouTube 19.34+ where the playback speed | ||
* can incorrectly reset to 1.0x under certain conditions. | ||
* | ||
* Reproduction steps using 19.34+ | ||
* 1. Open a video and start playback | ||
* 2. Change the speed to any value that is not 1.0x. | ||
* 3. Open the comments panel. | ||
* 4. Tap any "N more replies" link at the bottom of a comment, or tap on a timestamp of a comment. | ||
* 5. Pause the video | ||
* 6. Resume the video | ||
* 7. Playback speed will incorrectly change to 1.0x. | ||
*/ | ||
@Suppress("unused") | ||
val fixPlaybackSpeedWhilePlayingPatch = bytecodePatch{ | ||
dependsOn( | ||
sharedExtensionPatch, | ||
playerTypeHookPatch, | ||
versionCheckPatch, | ||
) | ||
|
||
execute { | ||
if (!is_19_34_or_greater) { | ||
return@execute | ||
} | ||
|
||
playbackSpeedInFeedsFingerprint.method.apply { | ||
val freeRegister = implementation!!.registerCount - parameters.size - 2 | ||
val playbackSpeedIndex = indexOfGetPlaybackSpeedInstruction(this) | ||
val playbackSpeedRegister = getInstruction<TwoRegisterInstruction>(playbackSpeedIndex).registerA | ||
val returnIndex = indexOfFirstInstructionOrThrow(playbackSpeedIndex, Opcode.RETURN_VOID) | ||
|
||
addInstructionsWithLabels( | ||
playbackSpeedIndex + 1, | ||
""" | ||
invoke-static { v$playbackSpeedRegister }, $EXTENSION_CLASS_DESCRIPTOR->playbackSpeedChanged(F)Z | ||
move-result v$freeRegister | ||
if-nez v$freeRegister, :do_not_change | ||
""", | ||
ExternalLabel("do_not_change", getInstruction(returnIndex)) | ||
) | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playbackspeed/Fingerprints.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package app.revanced.patches.youtube.misc.fix.playbackspeed | ||
|
||
import app.revanced.patcher.fingerprint | ||
import app.revanced.util.getReference | ||
import app.revanced.util.indexOfFirstInstructionReversed | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
import com.android.tools.smali.dexlib2.Opcode | ||
import com.android.tools.smali.dexlib2.iface.Method | ||
import com.android.tools.smali.dexlib2.iface.reference.FieldReference | ||
|
||
/** | ||
* This method is usually used to set the initial speed (1.0x) when playback starts from the feed. | ||
* For some reason, in the latest YouTube, it is invoked even after the video has already started. | ||
*/ | ||
internal val playbackSpeedInFeedsFingerprint = fingerprint { | ||
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) | ||
returns("V") | ||
parameters("L") | ||
opcodes( | ||
Opcode.IGET, | ||
Opcode.MUL_INT_LIT16, | ||
Opcode.IGET_WIDE, | ||
Opcode.CONST_WIDE_16, | ||
Opcode.CMP_LONG, | ||
Opcode.IF_EQZ, | ||
Opcode.IF_LEZ, | ||
Opcode.SUB_LONG_2ADDR, | ||
) | ||
custom { method, _ -> | ||
indexOfGetPlaybackSpeedInstruction(method) >= 0 | ||
} | ||
} | ||
|
||
internal fun indexOfGetPlaybackSpeedInstruction(method: Method) = | ||
method.indexOfFirstInstructionReversed { | ||
opcode == Opcode.IGET && | ||
getReference<FieldReference>()?.type == "F" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters