fix(youtube/hide-shorts-components): Hide pivot button makes empty space

This commit is contained in:
inotia00
2023-09-28 23:08:49 +09:00
parent 4faea22fb0
commit f711d21b2f
4 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,14 @@
package app.revanced.patches.youtube.shorts.shortscomponent.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.ReelForcedMuteButton
import app.revanced.util.bytecode.isWideLiteralExists
import com.android.tools.smali.dexlib2.AccessFlags
object ShortsPivotFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PRIVATE or AccessFlags.FINAL,
parameters = listOf("Z", "Z", "L"),
customFingerprint = { methodDef, _ -> methodDef.isWideLiteralExists(ReelForcedMuteButton) }
)

View File

@ -29,6 +29,7 @@ import app.revanced.util.integrations.Constants.PATCHES_PATH
ShortsLikeButtonPatch::class,
ShortsNavigationBarPatch::class,
ShortsPaidPromotionBannerPatch::class,
ShortsPivotButtonPatch::class,
ShortsRemixButtonPatch::class,
ShortsShareButtonPatch::class,
ShortsSubscriptionsButtonPatch::class,

View File

@ -0,0 +1,71 @@
package app.revanced.patches.youtube.shorts.shortscomponent.patch
import app.revanced.extensions.exception
import app.revanced.patcher.data.BytecodeContext
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.PatchException
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.youtube.shorts.shortscomponent.fingerprints.ShortsPivotFingerprint
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.ReelForcedMuteButton
import app.revanced.util.bytecode.getWideLiteralIndex
import app.revanced.util.integrations.Constants.SHORTS
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
class ShortsPivotButtonPatch : BytecodePatch(
listOf(ShortsPivotFingerprint)
) {
override fun execute(context: BytecodeContext) {
ShortsPivotFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex = getWideLiteralIndex(ReelForcedMuteButton)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
val insertIndex = getTargetIndexDownTo(targetIndex, Opcode.IF_EQZ)
val jumpIndex = getTargetIndexUpTo(targetIndex, Opcode.GOTO)
if (insertIndex == -1 || jumpIndex == -1)
throw PatchException("Failed to find hook method")
addInstructionsWithLabels(
insertIndex, """
invoke-static {}, $SHORTS->hideShortsPlayerPivotButton()Z
move-result v$targetRegister
if-nez v$targetRegister, :hide
""", ExternalLabel("hide", getInstruction(jumpIndex))
)
}
} ?: throw ShortsPivotFingerprint.exception
}
private companion object {
fun MutableMethod.getTargetIndexDownTo(
startIndex: Int,
opcode: Opcode
): Int {
for (index in startIndex downTo 0) {
if (getInstruction(index).opcode != opcode)
continue
return index
}
return -1
}
fun MutableMethod.getTargetIndexUpTo(
startIndex: Int,
opcode: Opcode
): Int {
for (index in startIndex until implementation!!.instructions.size) {
if (getInstruction(index).opcode != opcode)
continue
return index
}
return -1
}
}
}

View File

@ -58,6 +58,7 @@ class SharedResourceIdPatch : ResourcePatch {
var QuickActionsElementContainer: Long = -1
var ReelDynRemix: Long = -1
var ReelDynShare: Long = -1
var ReelForcedMuteButton: Long = -1
var ReelPlayerBadge: Long = -1
var ReelPlayerBadge2: Long = -1
var ReelPlayerFooter: Long = -1
@ -137,6 +138,7 @@ class SharedResourceIdPatch : ResourcePatch {
QuickActionsElementContainer = find(ID, "quick_actions_element_container")
ReelDynRemix = find(ID, "reel_dyn_remix")
ReelDynShare = find(ID, "reel_dyn_share")
ReelForcedMuteButton = find(ID, "reel_player_forced_mute_button")
ReelPlayerBadge = find(ID, "reel_player_badge")
ReelPlayerBadge2 = find(ID, "reel_player_badge2")
ReelPlayerFooter = find(LAYOUT, "reel_player_dyn_footer_vert_stories3")