Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(YouTube - Restore old video quality menu): Show advanced quality menu in Shorts quality flyout #3155

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,9 +64,10 @@ 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 {
VideoQualityMenuViewInflateFingerprint.resultOrThrow().let {
LisoUseInAIKyrios marked this conversation as resolved.
Show resolved Hide resolved
it.mutableMethod.apply {
val checkCastIndex = it.scanResult.patternScanResult!!.endIndex
val listViewRegister = getInstruction<OneRegisterInstruction>(checkCastIndex).registerA
Expand All @@ -76,6 +81,28 @@ 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

// Add a conditional branch around the 3 menu code to force the 4 menu (Advanced menu) code path.
LisoUseInAIKyrios marked this conversation as resolved.
Show resolved Hide resolved
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 }
)
Loading