fix(YouTube): Restore functionality of Old video quality menu and Custom speeds on tablets (#2999)

This commit is contained in:
LisoUseInAIKyrios
2023-09-19 06:22:38 +04:00
committed by GitHub
parent ce6a9fc1ec
commit 2a340d21d7
7 changed files with 67 additions and 80 deletions
@@ -1,13 +0,0 @@
package app.revanced.patches.youtube.misc.bottomsheet.hook.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patches.youtube.misc.bottomsheet.hook.patch.BottomSheetHookResourcePatch
import app.revanced.util.patch.LiteralValueFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
object CreateBottomSheetFingerprint : LiteralValueFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L"),
returnType = "Landroid/widget/LinearLayout;",
literal = BottomSheetHookResourcePatch.bottomSheetMargins
)
@@ -1,39 +0,0 @@
package app.revanced.patches.youtube.misc.bottomsheet.hook.patch
import app.revanced.extensions.exception
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patches.youtube.misc.bottomsheet.hook.fingerprints.CreateBottomSheetFingerprint
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@DependsOn([IntegrationsPatch::class, BottomSheetHookResourcePatch::class])
class BottomSheetHookPatch : BytecodePatch(
listOf(CreateBottomSheetFingerprint)
) {
override fun execute(context: BytecodeContext) {
CreateBottomSheetFingerprint.result?.let {
it.mutableMethod.apply {
val returnLinearLayoutIndex = implementation!!.instructions.lastIndex
val linearLayoutRegister = getInstruction<OneRegisterInstruction>(returnLinearLayoutIndex).registerA
addHook = { classDescriptor ->
addInstruction(
returnLinearLayoutIndex,
"invoke-static { v$linearLayoutRegister }, " +
"${classDescriptor}->" +
"onFlyoutMenuCreate(Landroid/widget/LinearLayout;)V"
)
}
}
} ?: throw CreateBottomSheetFingerprint.exception
}
internal companion object {
internal lateinit var addHook: (String) -> Unit
private set
}
}
@@ -1,19 +0,0 @@
package app.revanced.patches.youtube.misc.bottomsheet.hook.patch
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch
@DependsOn([ResourceMappingPatch::class])
class BottomSheetHookResourcePatch : ResourcePatch {
override fun execute(context: ResourceContext) {
bottomSheetMargins = ResourceMappingPatch.resourceMappings.find { it.name == "bottom_sheet_margins" }?.id
?: throw PatchException("Could not find resource")
}
internal companion object {
var bottomSheetMargins = -1L
}
}
@@ -0,0 +1,21 @@
package app.revanced.patches.youtube.misc.recyclerviewtree.hook.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
object RecyclerViewTreeObserverFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
opcodes = listOf(
Opcode.NEW_INSTANCE,
Opcode.INVOKE_DIRECT,
Opcode.IPUT_OBJECT,
Opcode.IGET_BOOLEAN,
Opcode.IF_NEZ,
Opcode.INVOKE_VIRTUAL_RANGE,
Opcode.MOVE_RESULT_OBJECT
),
strings = listOf("LithoRVSLCBinder")
)
@@ -0,0 +1,37 @@
package app.revanced.patches.youtube.misc.recyclerviewtree.hook.patch
import app.revanced.extensions.exception
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
import app.revanced.patches.youtube.misc.recyclerviewtree.hook.fingerprints.RecyclerViewTreeObserverFingerprint
@DependsOn([IntegrationsPatch::class])
class RecyclerViewTreeHookPatch : BytecodePatch(
listOf(RecyclerViewTreeObserverFingerprint)
) {
override fun execute(context: BytecodeContext) {
RecyclerViewTreeObserverFingerprint.result?.let {
it.mutableMethod.apply {
val insertIndex = it.scanResult.patternScanResult!!.startIndex + 5
val recyclerViewParameter = 2
addHook = { classDescriptor ->
addInstruction(
insertIndex,
"invoke-static/range { p$recyclerViewParameter .. p$recyclerViewParameter }, $classDescriptor->onFlyoutMenuCreate(Landroid/support/v7/widget/RecyclerView;)V"
)
}
}
} ?: throw RecyclerViewTreeObserverFingerprint.exception
}
internal companion object {
internal lateinit var addHook: (String) -> Unit
private set
}
}