@@ -2,14 +2,18 @@ package app.revanced.patches.youtube.video.videoqualitymenu
22
33import app.revanced.patcher.data.BytecodeContext
44import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
5+ import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
56import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
67import app.revanced.patcher.patch.BytecodePatch
78import app.revanced.patcher.patch.annotation.CompatiblePackage
89import app.revanced.patcher.patch.annotation.Patch
10+ import app.revanced.patcher.util.smali.ExternalLabel
911import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
1012import app.revanced.patches.youtube.misc.litho.filter.LithoFilterPatch
1113import app.revanced.patches.youtube.misc.recyclerviewtree.hook.RecyclerViewTreeHookPatch
14+ import app.revanced.patches.youtube.video.videoqualitymenu.fingerprints.VideoQualityMenuOptionsFingerprint
1215import app.revanced.patches.youtube.video.videoqualitymenu.fingerprints.VideoQualityMenuViewInflateFingerprint
16+ import app.revanced.util.resultOrThrow
1317import 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" )
5256object 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.
0 commit comments