refactor(hide-shorts-component): add Hide shorts player info panels settings

This commit is contained in:
inotia00
2023-04-08 06:38:39 +09:00
parent c505d28c1a
commit ff43393daa
6 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,16 @@
package app.revanced.patches.youtube.layout.general.shortscomponent.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
object ShortsInfoPanelFingerprint : MethodFingerprint(
returnType = "V",
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any {
it.opcode.ordinal == Opcode.CONST.ordinal &&
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.reelPlayerInfoPanelLabelId
} == true
}
)

View File

@ -28,6 +28,7 @@ import app.revanced.util.bytecode.BytecodeHelper.updatePatchStatus
SettingsPatch::class,
SharedResourceIdPatch::class,
ShortsCommentButtonPatch::class,
ShortsInfoPanelPatch::class,
ShortsRemixButtonPatch::class,
ShortsSubscriptionsButtonPatch::class
]

View File

@ -0,0 +1,46 @@
package app.revanced.patches.youtube.layout.general.shortscomponent.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.layout.general.shortscomponent.fingerprints.ShortsInfoPanelFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import app.revanced.util.integrations.Constants.GENERAL
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
@Name("hide-shorts-info-panel")
@DependsOn([SharedResourceIdPatch::class])
@YouTubeCompatibility
@Version("0.0.1")
class ShortsInfoPanelPatch : BytecodePatch(
listOf(ShortsInfoPanelFingerprint)
) {
override fun execute(context: BytecodeContext): PatchResult {
ShortsInfoPanelFingerprint.result?.mutableMethod?.let { method ->
with (method.implementation!!.instructions) {
val insertIndex = this.indexOfFirst {
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.reelPlayerInfoPanelLabelId
} + 3
val insertRegister = (elementAt(insertIndex) as OneRegisterInstruction).registerA
method.addInstructions(
insertIndex + 1, """
invoke-static {v$insertRegister}, $GENERAL->hideShortsPlayerInfoPanel(Landroid/view/ViewGroup;)Landroid/view/ViewGroup;
move-result-object v$insertRegister
"""
)
}
} ?: return ShortsInfoPanelFingerprint.toErrorResult()
return PatchResultSuccess()
}
}