Skip to content

Commit

Permalink
fix(YouTube - Restore old video quality menu): Show advanced quality …
Browse files Browse the repository at this point in the history
…menu in Shorts quality flyout (ReVanced#3155)

Co-authored-by: oSumAtrIX <[email protected]>
  • Loading branch information
LisoUseInAIKyrios and oSumAtrIX authored May 11, 2024
1 parent d3b8733 commit c2b5bb7
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ package app.revanced.patches.youtube.video.videoqualitymenu

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
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.patcher.util.smali.ExternalLabel
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
import app.revanced.patches.youtube.misc.litho.filter.LithoFilterPatch
import app.revanced.patches.youtube.misc.recyclerviewtree.hook.RecyclerViewTreeHookPatch
import app.revanced.patches.youtube.video.videoqualitymenu.fingerprints.VideoQualityMenuOptionsFingerprint
import app.revanced.patches.youtube.video.videoqualitymenu.fingerprints.VideoQualityMenuViewInflateFingerprint
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction

@Patch(
Expand Down Expand Up @@ -50,7 +54,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
)
@Suppress("unused")
object RestoreOldVideoQualityMenuPatch : BytecodePatch(
setOf(VideoQualityMenuViewInflateFingerprint)
setOf(VideoQualityMenuViewInflateFingerprint, VideoQualityMenuOptionsFingerprint)
) {
private const val FILTER_CLASS_DESCRIPTOR =
"Lapp/revanced/integrations/youtube/patches/components/VideoQualityMenuFilterPatch;"
Expand All @@ -60,7 +64,8 @@ object RestoreOldVideoQualityMenuPatch : 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.
// Used for regular videos when spoofing to old app version,
// and for the Shorts quality flyout on newer app versions.

VideoQualityMenuViewInflateFingerprint.result?.let {
it.mutableMethod.apply {
Expand All @@ -76,6 +81,29 @@ object RestoreOldVideoQualityMenuPatch : BytecodePatch(
}
}

// Force YT to add the 'advanced' quality menu for Shorts.
VideoQualityMenuOptionsFingerprint.resultOrThrow().let {
val result = it.scanResult.patternScanResult!!
val startIndex = result.startIndex
val endIndex = result.endIndex

it.mutableMethod.apply {
val freeRegister = getInstruction<OneRegisterInstruction>(startIndex).registerA

// A condition controls whether to show the three or four items quality menu.
// Force the four items quality menu to make the "Advanced" item visible, necessary for the patch.
addInstructionsWithLabels(
startIndex + 1,
"""
invoke-static { }, $INTEGRATIONS_CLASS_DESCRIPTOR->forceAdvancedVideoQualityMenuCreation()Z
move-result v$freeRegister
if-nez v$freeRegister, :includeAdvancedMenu
""",
ExternalLabel("includeAdvancedMenu", getInstruction(endIndex))
)
}
}

// endregion

// region Patch for the new type of the video quality menu.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import app.revanced.patches.youtube.misc.settings.SettingsPatch
)
object RestoreOldVideoQualityMenuResourcePatch : ResourcePatch() {
internal var videoQualityBottomSheetListFragmentTitle = -1L
internal var videoQualityQuickMenuAdvancedMenuDescription = -1L

override fun execute(context: ResourceContext) {
AddResourcesPatch(this::class)
Expand All @@ -26,5 +27,10 @@ object RestoreOldVideoQualityMenuResourcePatch : ResourcePatch() {
"layout",
"video_quality_bottom_sheet_list_fragment_title",
]

videoQualityQuickMenuAdvancedMenuDescription = ResourceMappingPatch[
"string",
"video_quality_quick_menu_advanced_menu_description"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package app.revanced.patches.youtube.video.videoqualitymenu.fingerprints

import app.revanced.patches.youtube.video.videoqualitymenu.RestoreOldVideoQualityMenuResourcePatch
import app.revanced.util.patch.LiteralValueFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode

internal object VideoQualityMenuOptionsFingerprint : LiteralValueFingerprint(
accessFlags = AccessFlags.STATIC.value,
parameters = listOf("Landroid/content/Context", "L", "L"),
returnType = "[L",
opcodes = listOf(
Opcode.IF_EQZ, // Check if advanced menu should be shown.
Opcode.NEW_ARRAY,
Opcode.APUT_OBJECT,
Opcode.APUT_OBJECT,
Opcode.APUT_OBJECT,
Opcode.RETURN_OBJECT,
Opcode.CONST_4 // Advanced menu code path.
),
literalSupplier = { RestoreOldVideoQualityMenuResourcePatch.videoQualityQuickMenuAdvancedMenuDescription }
)

0 comments on commit c2b5bb7

Please sign in to comment.