Skip to content

Commit

Permalink
fix(YouTube): Restore functionality of Old video quality menu and `…
Browse files Browse the repository at this point in the history
…Custom speeds` on tablets (ReVanced#2999)
  • Loading branch information
LisoUseInAIKyrios authored Sep 19, 2023
1 parent 50733f5 commit 238bed1
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 80 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package app.revanced.patches.youtube.misc.recyclerviewtree.hook.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode

object RecyclerViewTreeObserverFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
opcodes = listOf(
Opcode.NEW_INSTANCE,
Opcode.INVOKE_DIRECT,
Opcode.IPUT_OBJECT,
Opcode.IGET_BOOLEAN,
Opcode.IF_NEZ,
Opcode.INVOKE_VIRTUAL_RANGE,
Opcode.MOVE_RESULT_OBJECT
),
strings = listOf("LithoRVSLCBinder")
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package app.revanced.patches.youtube.misc.recyclerviewtree.hook.patch

import app.revanced.extensions.exception
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
import app.revanced.patches.youtube.misc.recyclerviewtree.hook.fingerprints.RecyclerViewTreeObserverFingerprint

@DependsOn([IntegrationsPatch::class])
class RecyclerViewTreeHookPatch : BytecodePatch(
listOf(RecyclerViewTreeObserverFingerprint)
) {
override fun execute(context: BytecodeContext) {

RecyclerViewTreeObserverFingerprint.result?.let {
it.mutableMethod.apply {
val insertIndex = it.scanResult.patternScanResult!!.startIndex + 5
val recyclerViewParameter = 2

addHook = { classDescriptor ->
addInstruction(
insertIndex,
"invoke-static/range { p$recyclerViewParameter .. p$recyclerViewParameter }, $classDescriptor->onFlyoutMenuCreate(Landroid/support/v7/widget/RecyclerView;)V"
)
}
}
} ?: throw RecyclerViewTreeObserverFingerprint.exception

}

internal companion object {
internal lateinit var addHook: (String) -> Unit
private set
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMut
import app.revanced.patches.shared.settings.preference.impl.InputType
import app.revanced.patches.shared.settings.preference.impl.StringResource
import app.revanced.patches.shared.settings.preference.impl.TextPreference
import app.revanced.patches.youtube.misc.bottomsheet.hook.patch.BottomSheetHookPatch
import app.revanced.patches.youtube.misc.recyclerviewtree.hook.patch.RecyclerViewTreeHookPatch
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
import app.revanced.patches.youtube.misc.litho.filter.patch.LithoFilterPatch
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
Expand All @@ -32,7 +32,7 @@ import com.android.tools.smali.dexlib2.immutable.ImmutableField

@Name("Custom playback speed")
@Description("Adds custom playback speed options.")
@DependsOn([IntegrationsPatch::class, LithoFilterPatch::class, SettingsPatch::class, BottomSheetHookPatch::class])
@DependsOn([IntegrationsPatch::class, LithoFilterPatch::class, SettingsPatch::class, RecyclerViewTreeHookPatch::class])
class CustomPlaybackSpeedPatch : BytecodePatch(
listOf(
SpeedArrayGeneratorFingerprint,
Expand Down Expand Up @@ -116,20 +116,19 @@ class CustomPlaybackSpeedPatch : BytecodePatch(
val limiterMinConstDestination = (limiterMinConst as OneRegisterInstruction).registerA
val limiterMaxConstDestination = (limiterMaxConst as OneRegisterInstruction).registerA

// edit: alternatively this might work by overriding with fixed values such as 0.1x and 10x
limiterMethod.replaceInstruction(
limiterMinConstIndex,
"sget v$limiterMinConstDestination, $INTEGRATIONS_CLASS_DESCRIPTOR->minPlaybackSpeed:F"
"const/high16 v$limiterMinConstDestination, 0x0"
)
limiterMethod.replaceInstruction(
limiterMaxConstIndex,
"sget v$limiterMaxConstDestination, $INTEGRATIONS_CLASS_DESCRIPTOR->maxPlaybackSpeed:F"
"const/high16 v$limiterMaxConstDestination, 0x41200000 # 10.0f"
)

// region Force old video quality menu.
// This is necessary, because there is no known way of adding custom playback speeds to the new menu.

BottomSheetHookPatch.addHook(INTEGRATIONS_CLASS_DESCRIPTOR)
RecyclerViewTreeHookPatch.addHook(INTEGRATIONS_CLASS_DESCRIPTOR)

// Required to check if the playback speed menu is currently shown.
LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.youtube.misc.bottomsheet.hook.patch.BottomSheetHookPatch
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
import app.revanced.patches.youtube.misc.litho.filter.patch.LithoFilterPatch
import app.revanced.patches.youtube.misc.recyclerviewtree.hook.patch.RecyclerViewTreeHookPatch
import app.revanced.patches.youtube.video.videoqualitymenu.annotations.OldVideoQualityMenuCompatibility
import app.revanced.patches.youtube.video.videoqualitymenu.fingerprints.VideoQualityMenuViewInflateFingerprint
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
Expand All @@ -20,7 +20,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
IntegrationsPatch::class,
OldVideoQualityMenuResourcePatch::class,
LithoFilterPatch::class,
BottomSheetHookPatch::class
RecyclerViewTreeHookPatch::class
])
@Name("Old video quality menu")
@Description("Shows the old video quality with the advanced video quality options instead of the new one.")
Expand All @@ -30,6 +30,7 @@ class OldVideoQualityMenuPatch : BytecodePatch(
) {
override fun execute(context: BytecodeContext) {
// region Patch for the old type of the video quality menu.
// Only used when spoofing to old app version.

VideoQualityMenuViewInflateFingerprint.result?.let {
it.mutableMethod.apply {
Expand All @@ -49,7 +50,7 @@ class OldVideoQualityMenuPatch : BytecodePatch(

// region Patch for the new type of the video quality menu.

BottomSheetHookPatch.addHook(INTEGRATIONS_CLASS_DESCRIPTOR)
RecyclerViewTreeHookPatch.addHook(INTEGRATIONS_CLASS_DESCRIPTOR)

// Required to check if the video quality menu is currently shown in order to click on the "Advanced" item.
LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR)
Expand Down

0 comments on commit 238bed1

Please sign in to comment.