fix(youtube/hide-feed-flyout-panel): doesn't work on tablet

This commit is contained in:
inotia00 2023-09-18 19:16:02 +09:00
parent 9bceb9d8fc
commit 1d96d5ee2a
3 changed files with 62 additions and 2 deletions

View File

@ -0,0 +1,22 @@
package app.revanced.patches.youtube.flyoutpanel.feed.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.PosterArtWidthDefault
import app.revanced.util.bytecode.isWideLiteralExists
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
object ContextualMenuItemBuilderFingerprint : MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL or AccessFlags.SYNTHETIC,
parameters = listOf("L", "L"),
returnType = "V",
opcodes = listOf(
Opcode.CHECK_CAST,
Opcode.INVOKE_VIRTUAL,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT,
Opcode.ADD_INT_2ADDR
),
customFingerprint = { methodDef, _ -> methodDef.isWideLiteralExists(PosterArtWidthDefault) }
)

View File

@ -4,6 +4,7 @@ import app.revanced.extensions.exception
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
@ -11,22 +12,37 @@ import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.youtube.flyoutpanel.feed.fingerprints.BottomSheetMenuItemBuilderFingerprint
import app.revanced.patches.youtube.flyoutpanel.feed.fingerprints.ContextualMenuItemBuilderFingerprint
import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.FLYOUT_PANEL
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@Patch
@Name("Hide feed flyout panel")
@Description("Hides feed flyout panel components.")
@DependsOn([SettingsPatch::class])
@DependsOn(
[
SettingsPatch::class,
SharedResourceIdPatch::class
]
)
@YouTubeCompatibility
class FeedFlyoutPanelPatch : BytecodePatch(
listOf(BottomSheetMenuItemBuilderFingerprint)
listOf(
BottomSheetMenuItemBuilderFingerprint,
ContextualMenuItemBuilderFingerprint
)
) {
override fun execute(context: BytecodeContext) {
/**
* Phone
*/
BottomSheetMenuItemBuilderFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex = it.scanResult.patternScanResult!!.endIndex
@ -46,6 +62,26 @@ class FeedFlyoutPanelPatch : BytecodePatch(
}
} ?: throw BottomSheetMenuItemBuilderFingerprint.exception
/**
* Tablet
*/
ContextualMenuItemBuilderFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex = it.scanResult.patternScanResult!!.startIndex + 1
val targetInstruction = getInstruction<Instruction35c>(targetIndex)
val targetReferenceName =
(targetInstruction.reference as MethodReference).name
if (targetReferenceName != "setText")
throw PatchException("Method name did not match: $targetReferenceName")
addInstruction(
targetIndex + 1,
"invoke-static {v${targetInstruction.registerC}, v${targetInstruction.registerD}}, $FLYOUT_PANEL->hideFeedFlyoutPanel(Landroid/widget/TextView;Ljava/lang/CharSequence;)V"
)
}
} ?: throw ContextualMenuItemBuilderFingerprint.exception
/**
* Add settings
*/

View File

@ -52,6 +52,7 @@ class SharedResourceIdPatch : ResourcePatch {
var InsetOverlayViewLayout: Long = -1
var LiveChatButton: Long = -1
var MusicAppDeeplinkButtonView: Long = -1
var PosterArtWidthDefault: Long = -1
var QuickActionsElementContainer: Long = -1
var ReelDynRemix: Long = -1
var ReelDynShare: Long = -1
@ -128,6 +129,7 @@ class SharedResourceIdPatch : ResourcePatch {
InsetOverlayViewLayout = find(ID, "inset_overlay_view_layout")
LiveChatButton = find(ID, "live_chat_overlay_button")
MusicAppDeeplinkButtonView = find(ID, "music_app_deeplink_button_view")
PosterArtWidthDefault = find(DIMEN, "poster_art_width_default")
QuickActionsElementContainer = find(ID, "quick_actions_element_container")
ReelDynRemix = find(ID, "reel_dyn_remix")
ReelDynShare = find(ID, "reel_dyn_share")