diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/general/fingerprint/VideoEndFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/VideoEndFingerprint.kt similarity index 85% rename from src/main/kotlin/app/revanced/patches/youtube/utils/videoid/general/fingerprint/VideoEndFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/VideoEndFingerprint.kt index 249758142..5c96f66ea 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/general/fingerprint/VideoEndFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/VideoEndFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.utils.videoid.general.fingerprint +package app.revanced.patches.youtube.utils.fingerprints import app.revanced.patcher.fingerprint.MethodFingerprint import com.android.tools.smali.dexlib2.Opcode diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/videocpn/VideoCpnPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/videocpn/VideoCpnPatch.kt index a5fe347fc..f24fe3b5a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/videocpn/VideoCpnPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/videocpn/VideoCpnPatch.kt @@ -3,10 +3,13 @@ package app.revanced.patches.youtube.utils.videocpn import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.youtube.utils.fingerprints.OrganicPlaybackContextModelFingerprint +import app.revanced.patches.youtube.utils.videoid.general.VideoIdPatch import app.revanced.util.exception +@Patch(dependencies = [VideoIdPatch::class]) object VideoCpnPatch : BytecodePatch( setOf(OrganicPlaybackContextModelFingerprint) ) { @@ -24,7 +27,7 @@ object VideoCpnPatch : BytecodePatch( ) { insertMethod.addInstructions( 2, - "invoke-static {p1,p2}, $methodDescriptor" + "invoke-static {p1}, $methodDescriptor" ) } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/general/VideoIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/general/VideoIdPatch.kt index a8d3ece77..49a36841f 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/general/VideoIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/general/VideoIdPatch.kt @@ -12,11 +12,11 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.youtube.utils.fingerprints.OrganicPlaybackContextModelFingerprint +import app.revanced.patches.youtube.utils.fingerprints.VideoEndFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.VIDEO_PATH import app.revanced.patches.youtube.utils.playerresponse.PlayerResponsePatch import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch import app.revanced.patches.youtube.utils.videoid.general.fingerprint.PlayerControllerSetTimeReferenceFingerprint -import app.revanced.patches.youtube.utils.videoid.general.fingerprint.VideoEndFingerprint import app.revanced.patches.youtube.utils.videoid.general.fingerprint.VideoIdFingerprint import app.revanced.patches.youtube.utils.videoid.general.fingerprint.VideoIdParentFingerprint import app.revanced.patches.youtube.utils.videoid.general.fingerprint.VideoLengthFingerprint @@ -107,7 +107,7 @@ object VideoIdPatch : BytecodePatch( videoTimeHook(INTEGRATIONS_CLASS_DESCRIPTOR, "setVideoTime") /** - * + * Set current video is livestream */ OrganicPlaybackContextModelFingerprint.result?.let { it.mutableMethod.apply { diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/quality/VideoQualityPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/quality/VideoQualityPatch.kt index a5f1be30f..8d0282601 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/quality/VideoQualityPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/quality/VideoQualityPatch.kt @@ -112,6 +112,7 @@ object VideoQualityPatch : BytecodePatch( SettingsPatch.addPreference( arrayOf( "PREFERENCE: VIDEO_SETTINGS", + "SETTINGS: VIDEO_EXPERIMENTAL_FLAGS", "SETTINGS: DEFAULT_VIDEO_QUALITY" ) ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/speed/PlaybackSpeedPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/speed/PlaybackSpeedPatch.kt index 35f4cd07a..4e6eb04c4 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/speed/PlaybackSpeedPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/speed/PlaybackSpeedPatch.kt @@ -2,20 +2,24 @@ package app.revanced.patches.youtube.video.speed import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.getInstruction 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.utils.fingerprints.NewVideoQualityChangedFingerprint +import app.revanced.patches.youtube.utils.fingerprints.VideoEndFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.VIDEO_PATH import app.revanced.patches.youtube.utils.overridespeed.OverrideSpeedHookPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.videocpn.VideoCpnPatch +import app.revanced.patches.youtube.video.speed.fingerprints.PlaybackSpeedInitializeFingerprint import app.revanced.patches.youtube.video.speed.fingerprints.NewPlaybackSpeedChangedFingerprint import app.revanced.util.exception import app.revanced.util.updatePatchStatus import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Patch( name = "Default playback speed", @@ -54,7 +58,10 @@ import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction ) @Suppress("unused") object PlaybackSpeedPatch : BytecodePatch( - setOf(NewVideoQualityChangedFingerprint) + setOf( + NewVideoQualityChangedFingerprint, + VideoEndFingerprint + ) ) { override fun execute(context: BytecodeContext) { @@ -79,7 +86,28 @@ object PlaybackSpeedPatch : BytecodePatch( } ?: throw NewPlaybackSpeedChangedFingerprint.exception } ?: throw NewVideoQualityChangedFingerprint.exception - VideoCpnPatch.injectCall("$INTEGRATIONS_PLAYBACK_SPEED_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;Z)V") + VideoEndFingerprint.result?.let { parentResult -> + PlaybackSpeedInitializeFingerprint.also { + it.resolve( + context, + parentResult.classDef + ) + }.result?.let { + it.mutableMethod.apply { + val insertIndex = it.scanResult.patternScanResult!!.endIndex + val insertRegister = getInstruction(insertIndex).registerA + + addInstructions( + insertIndex, """ + invoke-static {v$insertRegister}, $INTEGRATIONS_PLAYBACK_SPEED_CLASS_DESCRIPTOR->getPlaybackSpeedInShorts(F)F + move-result v$insertRegister + """ + ) + } + } ?: throw PlaybackSpeedInitializeFingerprint.exception + } ?: throw VideoEndFingerprint.exception + + VideoCpnPatch.injectCall("$INTEGRATIONS_PLAYBACK_SPEED_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;)V") /** * Add settings @@ -87,6 +115,7 @@ object PlaybackSpeedPatch : BytecodePatch( SettingsPatch.addPreference( arrayOf( "PREFERENCE: VIDEO_SETTINGS", + "SETTINGS: VIDEO_EXPERIMENTAL_FLAGS", "SETTINGS: DEFAULT_PLAYBACK_SPEED" ) ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/speed/fingerprints/PlaybackSpeedInitializeFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/video/speed/fingerprints/PlaybackSpeedInitializeFingerprint.kt new file mode 100644 index 000000000..09f5fff50 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/video/speed/fingerprints/PlaybackSpeedInitializeFingerprint.kt @@ -0,0 +1,16 @@ +package app.revanced.patches.youtube.video.speed.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.Opcode + +object PlaybackSpeedInitializeFingerprint : MethodFingerprint( + returnType = "F", + accessFlags = AccessFlags.PRIVATE or AccessFlags.STATIC, + parameters = listOf("L"), + opcodes = listOf( + Opcode.IGET, + Opcode.RETURN + ) +) diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 37d34d2f5..a53a25f94 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -158,6 +158,9 @@ Note: Disabling the speed overlay restores the 'Slide to seek' behavior of the o Debug logs are disabled. Debug logs are enabled. Enable debug logging + Default playback speed does not apply to Shorts. + Default playback speed applies to Shorts. + Enable shorts default playback speed External browser is disabled. External browser is enabled. Enable external browser diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 4cf82f60e..6aa3454af 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -754,8 +754,15 @@ SETTINGS: DEFAULT_PLAYBACK_SPEED --> + + + + + +