@@ -2,14 +2,18 @@ package app.revanced.patches.youtube.video.videoqualitymenu
2
2
3
3
import app.revanced.patcher.data.BytecodeContext
4
4
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
5
+ import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
5
6
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
6
7
import app.revanced.patcher.patch.BytecodePatch
7
8
import app.revanced.patcher.patch.annotation.CompatiblePackage
8
9
import app.revanced.patcher.patch.annotation.Patch
10
+ import app.revanced.patcher.util.smali.ExternalLabel
9
11
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
10
12
import app.revanced.patches.youtube.misc.litho.filter.LithoFilterPatch
11
13
import app.revanced.patches.youtube.misc.recyclerviewtree.hook.RecyclerViewTreeHookPatch
14
+ import app.revanced.patches.youtube.video.videoqualitymenu.fingerprints.VideoQualityMenuOptionsFingerprint
12
15
import app.revanced.patches.youtube.video.videoqualitymenu.fingerprints.VideoQualityMenuViewInflateFingerprint
16
+ import app.revanced.util.resultOrThrow
13
17
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
14
18
15
19
@Patch(
@@ -50,7 +54,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
50
54
)
51
55
@Suppress(" unused" )
52
56
object RestoreOldVideoQualityMenuPatch : BytecodePatch(
53
- setOf(VideoQualityMenuViewInflateFingerprint )
57
+ setOf(VideoQualityMenuViewInflateFingerprint , VideoQualityMenuOptionsFingerprint )
54
58
) {
55
59
private const val FILTER_CLASS_DESCRIPTOR =
56
60
" Lapp/revanced/integrations/youtube/patches/components/VideoQualityMenuFilterPatch;"
@@ -60,7 +64,8 @@ object RestoreOldVideoQualityMenuPatch : BytecodePatch(
60
64
61
65
override fun execute (context : BytecodeContext ) {
62
66
// 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.
64
69
65
70
VideoQualityMenuViewInflateFingerprint .result?.let {
66
71
it.mutableMethod.apply {
@@ -76,6 +81,29 @@ object RestoreOldVideoQualityMenuPatch : BytecodePatch(
76
81
}
77
82
}
78
83
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
+
79
107
// endregion
80
108
81
109
// region Patch for the new type of the video quality menu.
0 commit comments