From fdea41ba94fafc2a327d7f1f7efddacc195ac8d4 Mon Sep 17 00:00:00 2001 From: OxrxL <108184954+OxrxL@users.noreply.github.com> Date: Tue, 11 Oct 2022 14:38:11 +0200 Subject: [PATCH] fix(youtube/theme): colore the comment action bar (#762) Co-authored-by: oSumAtrIX --- .../CommentsFilterBarFingerprint.kt | 32 ++++++++++++++ .../theme/patch/CommentsFilterBarPatch.kt | 42 +++++++++++++++++++ .../youtube/layout/theme/patch/ThemePatch.kt | 2 +- 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/theme/fingerprints/CommentsFilterBarFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/theme/patch/CommentsFilterBarPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/fingerprints/CommentsFilterBarFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/fingerprints/CommentsFilterBarFingerprint.kt new file mode 100644 index 000000000..2fc6e94f5 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/fingerprints/CommentsFilterBarFingerprint.kt @@ -0,0 +1,32 @@ +package app.revanced.patches.youtube.layout.theme.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.theme.annotations.ThemeCompatibility +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +@Name("comment-actionbar-fingerprint") +@ThemeCompatibility +@Version("0.0.1") +object CommentsFilterBarFingerprint : MethodFingerprint( + "V", AccessFlags.PROTECTED or AccessFlags.FINAL, listOf("L"), listOf( + Opcode.APUT, + Opcode.NEW_INSTANCE, + Opcode.INVOKE_DIRECT, + Opcode.IGET_OBJECT, + Opcode.SGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.IPUT_OBJECT, + Opcode.IGET, + Opcode.IF_EQZ, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.IF_NEZ, + Opcode.IGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.RETURN_VOID + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/patch/CommentsFilterBarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/patch/CommentsFilterBarPatch.kt new file mode 100644 index 000000000..495bab904 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/patch/CommentsFilterBarPatch.kt @@ -0,0 +1,42 @@ +package app.revanced.patches.youtube.layout.theme.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.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.util.smali.ExternalLabel +import app.revanced.patches.youtube.layout.theme.annotations.ThemeCompatibility +import app.revanced.patches.youtube.layout.theme.fingerprints.CommentsFilterBarFingerprint + +@Name("comment-filter-bar-theme") +@Description("Applies custom theming to comments filter action bar.") +@ThemeCompatibility +@Version("0.0.1") +class CommentsFilterBarPatch : BytecodePatch( + listOf( + CommentsFilterBarFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + val result = CommentsFilterBarFingerprint.result!! + val method = result.mutableMethod + val patchIndex = result.scanResult.patternScanResult!!.endIndex - 1 + + method.addInstructions( + patchIndex, """ + const v1, -0x1 + if-ne v1, p1, :comments_filter_white + const v1, -0xdededf + if-ne v1, p1, :comments_filter_dark + const/4 p1, 0x0 + :comments_filter_white + """, listOf(ExternalLabel("comments_filter_dark", method.instruction(patchIndex))) + ) + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/patch/ThemePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/patch/ThemePatch.kt index bcb55a100..ede466659 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/patch/ThemePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/patch/ThemePatch.kt @@ -12,7 +12,7 @@ import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatc import org.w3c.dom.Element @Patch -@DependsOn([FixLocaleConfigErrorPatch::class]) +@DependsOn([CommentsFilterBarPatch::class, FixLocaleConfigErrorPatch::class]) @Name("theme") @Description("Applies a custom theme.") @ThemeCompatibility