feat(YouTube/Hide shorts components): remove the Hide toolbar setting and add settings to hide each toolbar button

This commit is contained in:
inotia00
2023-10-19 08:24:31 +09:00
parent e5ce2b707d
commit fed4961f43
8 changed files with 67 additions and 37 deletions

View File

@ -9,7 +9,7 @@ import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.youtube.general.widesearchbar.fingerprints.SetActionBarRingoFingerprint
import app.revanced.patches.youtube.utils.fingerprints.SetToolBarPaddingFingerprint
import app.revanced.patches.youtube.general.widesearchbar.fingerprints.SetToolBarPaddingFingerprint
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.patches.youtube.utils.settings.SettingsPatch.contexts

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.utils.fingerprints
package app.revanced.patches.youtube.general.widesearchbar.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ToolBarPaddingHome

View File

@ -22,7 +22,6 @@ import app.revanced.patches.youtube.shorts.shortscomponent.fingerprints.ShortsPi
import app.revanced.patches.youtube.shorts.shortscomponent.fingerprints.ShortsRemixFingerprint
import app.revanced.patches.youtube.shorts.shortscomponent.fingerprints.ShortsShareFingerprint
import app.revanced.patches.youtube.utils.litho.LithoFilterPatch
import app.revanced.patches.youtube.utils.navbarindex.NavBarIndexHookPatch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelDynRemix
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelDynShare
@ -46,7 +45,6 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
description = "Hides other Shorts components.",
dependencies = [
LithoFilterPatch::class,
NavBarIndexHookPatch::class,
SettingsPatch::class,
SharedResourceIdPatch::class,
ShortsNavigationBarPatch::class,

View File

@ -3,46 +3,46 @@ package app.revanced.patches.youtube.shorts.shortscomponent
import app.revanced.extensions.exception
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.PatchException
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.youtube.shorts.shortscomponent.fingerprints.ShortsCommentFingerprint
import app.revanced.patches.youtube.utils.fingerprints.SetToolBarPaddingFingerprint
import app.revanced.patches.youtube.utils.navbarindex.NavBarIndexHookPatch.injectIndex
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ToolBarPaddingHome
import app.revanced.util.bytecode.getWideLiteralIndex
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.youtube.shorts.shortscomponent.fingerprints.ToolBarBannerFingerprint
import app.revanced.patches.youtube.utils.fingerprints.ToolBarPatchFingerprint
import app.revanced.util.integrations.Constants.SHORTS
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
object ShortsToolBarPatch : BytecodePatch(
setOf(
SetToolBarPaddingFingerprint,
ShortsCommentFingerprint
ToolBarBannerFingerprint,
ToolBarPatchFingerprint
)
) {
override fun execute(context: BytecodeContext) {
SetToolBarPaddingFingerprint.result?.let {
val targetIndex = it.mutableMethod.getWideLiteralIndex(ToolBarPaddingHome) + 3
(context.toMethodWalker(it.method)
.nextMethod(targetIndex, true)
ToolBarBannerFingerprint.result?.let {
val targetMethod = context
.toMethodWalker(it.method)
.nextMethod(it.scanResult.patternScanResult!!.endIndex, true)
.getMethod() as MutableMethod
).apply {
val targetParameter = getInstruction<ReferenceInstruction>(0).reference
if (!targetParameter.toString().endsWith("Landroid/support/v7/widget/Toolbar;"))
throw PatchException("Method signature parameter did not match: $targetParameter")
val targetRegister = getInstruction<TwoRegisterInstruction>(0).registerA
addInstruction(
1,
"invoke-static {v$targetRegister}, $SHORTS->hideShortsPlayerToolBar(Landroid/support/v7/widget/Toolbar;)V"
)
}
} ?: throw SetToolBarPaddingFingerprint.exception
ShortsCommentFingerprint.injectIndex(1)
targetMethod.apply {
addInstructionsWithLabels(
0, """
invoke-static {}, $SHORTS->hideShortsToolBarBanner()Z
move-result v0
if-nez v0, :hide
""", ExternalLabel("hide", getInstruction(implementation!!.instructions.size - 1))
)
}
} ?: throw ToolBarBannerFingerprint.exception
ToolBarPatchFingerprint.result?.let {
it.mutableMethod.apply {
addInstruction(
0,
"invoke-static {p0, p1}, $SHORTS->hideShortsToolBarButton(Ljava/lang/String;Landroid/view/View;)V"
)
}
} ?: throw ToolBarPatchFingerprint.exception
}
}

View File

@ -0,0 +1,17 @@
package app.revanced.patches.youtube.shorts.shortscomponent.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import com.android.tools.smali.dexlib2.Opcode
object ToolBarBannerFingerprint : MethodFingerprint(
returnType = "Landroid/view/View;",
opcodes = listOf(
Opcode.IF_NEZ,
Opcode.IGET_OBJECT,
Opcode.CONST,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_VIRTUAL
),
strings = listOf("r_pfcv")
)

View File

@ -18,6 +18,7 @@ import app.revanced.util.integrations.Constants.UTILS_PATH
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction35c
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@Suppress("unused")
object NavBarIndexHookPatch : BytecodePatch(
setOf(
MobileTopBarButtonOnClickFingerprint,