generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(youtube/comments): hide shorts comments button (#866)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
- Loading branch information
Showing
3 changed files
with
112 additions
and
10 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
.../patches/youtube/layout/comments/bytecode/fingerprints/ShortsCommentsButtonFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package app.revanced.patches.youtube.layout.comments.bytecode.fingerprints | ||
|
||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patches.youtube.layout.comments.annotations.CommentsCompatibility | ||
import app.revanced.patches.youtube.layout.comments.resource.patch.CommentsResourcePatch | ||
import org.jf.dexlib2.AccessFlags | ||
import org.jf.dexlib2.Opcode | ||
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction | ||
|
||
@Name("shorts-comments-button-fingerprint") | ||
@CommentsCompatibility | ||
@Version("0.0.1") | ||
object ShortsCommentsButtonFingerprint : MethodFingerprint( | ||
"V", AccessFlags.PRIVATE or AccessFlags.FINAL, listOf("Z", "Z", "L"), | ||
customFingerprint = { methodDef -> | ||
methodDef.implementation?.instructions?.any { | ||
it.opcode.ordinal == Opcode.CONST.ordinal && (it as WideLiteralInstruction).wideLiteral == CommentsResourcePatch.shortsCommentsButtonId | ||
} == true | ||
} | ||
) |
68 changes: 68 additions & 0 deletions
68
src/main/kotlin/app/revanced/patches/youtube/layout/comments/bytecode/patch/CommentsPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package app.revanced.patches.youtube.layout.comments.bytecode.patch | ||
|
||
import app.revanced.patcher.annotation.Description | ||
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.extensions.instruction | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve | ||
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.patcher.patch.annotations.Patch | ||
import app.revanced.patches.youtube.ad.general.bytecode.patch.GeneralBytecodeAdsPatch | ||
import app.revanced.patches.youtube.layout.comments.annotations.CommentsCompatibility | ||
import app.revanced.patches.youtube.layout.comments.bytecode.fingerprints.ShortsCommentsButtonFingerprint | ||
import app.revanced.patches.youtube.layout.comments.resource.patch.CommentsResourcePatch | ||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch | ||
import app.revanced.patches.youtube.misc.mapping.patch.ResourceMappingResourcePatch | ||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch | ||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.PreferenceScreen | ||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.StringResource | ||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.SwitchPreference | ||
import org.jf.dexlib2.Opcode | ||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction | ||
|
||
@Patch | ||
@DependsOn([IntegrationsPatch::class, CommentsResourcePatch::class]) | ||
@Name("comments") | ||
@Description("Hides components related to comments.") | ||
@CommentsCompatibility | ||
@Version("0.0.1") | ||
class CommentsPatch : BytecodePatch( | ||
listOf( | ||
ShortsCommentsButtonFingerprint | ||
) | ||
) { | ||
override fun execute(context: BytecodeContext): PatchResult { | ||
val shortsCommentsButtonResult = ShortsCommentsButtonFingerprint.result!! | ||
val shortsCommentsButtonMethod = shortsCommentsButtonResult.mutableMethod | ||
|
||
val checkCastAnchorFingerprint = object : MethodFingerprint( | ||
opcodes = listOf( | ||
Opcode.CONST, | ||
Opcode.CONST_HIGH16, | ||
Opcode.IF_EQZ, | ||
Opcode.CONST, | ||
Opcode.INVOKE_STATIC, | ||
Opcode.MOVE_RESULT_OBJECT, | ||
Opcode.CHECK_CAST, | ||
) | ||
) {} | ||
|
||
val checkCastAnchorIndex = checkCastAnchorFingerprint.also { | ||
it.resolve(context, shortsCommentsButtonMethod, shortsCommentsButtonResult.classDef) | ||
}.result!!.scanResult.patternScanResult!!.endIndex | ||
|
||
shortsCommentsButtonMethod.addInstructions( | ||
checkCastAnchorIndex + 1, """ | ||
invoke-static {v${(shortsCommentsButtonMethod.instruction(checkCastAnchorIndex) as OneRegisterInstruction).registerA}}, Lapp/revanced/integrations/patches/HideShortsCommentsButtonPatch;->hideShortsCommentsButton(Landroid/view/View;)V | ||
""" | ||
) | ||
|
||
return PatchResultSuccess() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters