Skip to content

Commit c2b5bb7

Browse files
fix(YouTube - Restore old video quality menu): Show advanced quality menu in Shorts quality flyout (ReVanced#3155)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
1 parent d3b8733 commit c2b5bb7

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

src/main/kotlin/app/revanced/patches/youtube/video/videoqualitymenu/RestoreOldVideoQualityMenuPatch.kt

+30-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ package app.revanced.patches.youtube.video.videoqualitymenu
22

33
import app.revanced.patcher.data.BytecodeContext
44
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
5+
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
56
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
67
import app.revanced.patcher.patch.BytecodePatch
78
import app.revanced.patcher.patch.annotation.CompatiblePackage
89
import app.revanced.patcher.patch.annotation.Patch
10+
import app.revanced.patcher.util.smali.ExternalLabel
911
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
1012
import app.revanced.patches.youtube.misc.litho.filter.LithoFilterPatch
1113
import app.revanced.patches.youtube.misc.recyclerviewtree.hook.RecyclerViewTreeHookPatch
14+
import app.revanced.patches.youtube.video.videoqualitymenu.fingerprints.VideoQualityMenuOptionsFingerprint
1215
import app.revanced.patches.youtube.video.videoqualitymenu.fingerprints.VideoQualityMenuViewInflateFingerprint
16+
import app.revanced.util.resultOrThrow
1317
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
1418

1519
@Patch(
@@ -50,7 +54,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
5054
)
5155
@Suppress("unused")
5256
object RestoreOldVideoQualityMenuPatch : BytecodePatch(
53-
setOf(VideoQualityMenuViewInflateFingerprint)
57+
setOf(VideoQualityMenuViewInflateFingerprint, VideoQualityMenuOptionsFingerprint)
5458
) {
5559
private const val FILTER_CLASS_DESCRIPTOR =
5660
"Lapp/revanced/integrations/youtube/patches/components/VideoQualityMenuFilterPatch;"
@@ -60,7 +64,8 @@ object RestoreOldVideoQualityMenuPatch : BytecodePatch(
6064

6165
override fun execute(context: BytecodeContext) {
6266
// region Patch for the old type of the video quality menu.
63-
// Only used when spoofing to old app version.
67+
// Used for regular videos when spoofing to old app version,
68+
// and for the Shorts quality flyout on newer app versions.
6469

6570
VideoQualityMenuViewInflateFingerprint.result?.let {
6671
it.mutableMethod.apply {
@@ -76,6 +81,29 @@ object RestoreOldVideoQualityMenuPatch : BytecodePatch(
7681
}
7782
}
7883

84+
// Force YT to add the 'advanced' quality menu for Shorts.
85+
VideoQualityMenuOptionsFingerprint.resultOrThrow().let {
86+
val result = it.scanResult.patternScanResult!!
87+
val startIndex = result.startIndex
88+
val endIndex = result.endIndex
89+
90+
it.mutableMethod.apply {
91+
val freeRegister = getInstruction<OneRegisterInstruction>(startIndex).registerA
92+
93+
// A condition controls whether to show the three or four items quality menu.
94+
// Force the four items quality menu to make the "Advanced" item visible, necessary for the patch.
95+
addInstructionsWithLabels(
96+
startIndex + 1,
97+
"""
98+
invoke-static { }, $INTEGRATIONS_CLASS_DESCRIPTOR->forceAdvancedVideoQualityMenuCreation()Z
99+
move-result v$freeRegister
100+
if-nez v$freeRegister, :includeAdvancedMenu
101+
""",
102+
ExternalLabel("includeAdvancedMenu", getInstruction(endIndex))
103+
)
104+
}
105+
}
106+
79107
// endregion
80108

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

src/main/kotlin/app/revanced/patches/youtube/video/videoqualitymenu/RestoreOldVideoQualityMenuResourcePatch.kt

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import app.revanced.patches.youtube.misc.settings.SettingsPatch
1313
)
1414
object RestoreOldVideoQualityMenuResourcePatch : ResourcePatch() {
1515
internal var videoQualityBottomSheetListFragmentTitle = -1L
16+
internal var videoQualityQuickMenuAdvancedMenuDescription = -1L
1617

1718
override fun execute(context: ResourceContext) {
1819
AddResourcesPatch(this::class)
@@ -26,5 +27,10 @@ object RestoreOldVideoQualityMenuResourcePatch : ResourcePatch() {
2627
"layout",
2728
"video_quality_bottom_sheet_list_fragment_title",
2829
]
30+
31+
videoQualityQuickMenuAdvancedMenuDescription = ResourceMappingPatch[
32+
"string",
33+
"video_quality_quick_menu_advanced_menu_description"
34+
]
2935
}
3036
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package app.revanced.patches.youtube.video.videoqualitymenu.fingerprints
2+
3+
import app.revanced.patches.youtube.video.videoqualitymenu.RestoreOldVideoQualityMenuResourcePatch
4+
import app.revanced.util.patch.LiteralValueFingerprint
5+
import com.android.tools.smali.dexlib2.AccessFlags
6+
import com.android.tools.smali.dexlib2.Opcode
7+
8+
internal object VideoQualityMenuOptionsFingerprint : LiteralValueFingerprint(
9+
accessFlags = AccessFlags.STATIC.value,
10+
parameters = listOf("Landroid/content/Context", "L", "L"),
11+
returnType = "[L",
12+
opcodes = listOf(
13+
Opcode.IF_EQZ, // Check if advanced menu should be shown.
14+
Opcode.NEW_ARRAY,
15+
Opcode.APUT_OBJECT,
16+
Opcode.APUT_OBJECT,
17+
Opcode.APUT_OBJECT,
18+
Opcode.RETURN_OBJECT,
19+
Opcode.CONST_4 // Advanced menu code path.
20+
),
21+
literalSupplier = { RestoreOldVideoQualityMenuResourcePatch.videoQualityQuickMenuAdvancedMenuDescription }
22+
)

0 commit comments

Comments
 (0)