From 66113e0655eb6faa121edee4fd9cc9fa27ab2771 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Sun, 9 Jul 2023 11:39:07 +0900 Subject: [PATCH] feat(youtube): add `enable-new-comment-popup-panels` patch --- .../ReelWatchFragmentBuilderFingerprint.kt | 13 ++++ .../patch/NewCommentPopupPanelsPatch.kt | 60 +++++++++++++++++++ .../youtube/settings/host/values/strings.xml | 3 + .../youtube/settings/xml/revanced_prefs.xml | 4 ++ 4 files changed, 80 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/shorts/commentpopuppanels/fingerprints/ReelWatchFragmentBuilderFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/shorts/commentpopuppanels/patch/NewCommentPopupPanelsPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/commentpopuppanels/fingerprints/ReelWatchFragmentBuilderFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/commentpopuppanels/fingerprints/ReelWatchFragmentBuilderFingerprint.kt new file mode 100644 index 000000000..9876d2b00 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/commentpopuppanels/fingerprints/ReelWatchFragmentBuilderFingerprint.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.youtube.shorts.commentpopuppanels.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.util.bytecode.isWide32LiteralExists +import org.jf.dexlib2.AccessFlags + +object ReelWatchFragmentBuilderFingerprint : MethodFingerprint( + returnType = "Landroid/view/View;", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("Landroid/view/LayoutInflater;", "Landroid/view/ViewGroup;", "Landroid/os/Bundle;"), + customFingerprint = { methodDef, _ -> methodDef.isWide32LiteralExists(45401415) } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/commentpopuppanels/patch/NewCommentPopupPanelsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/commentpopuppanels/patch/NewCommentPopupPanelsPatch.kt new file mode 100644 index 000000000..3dea5baa2 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/commentpopuppanels/patch/NewCommentPopupPanelsPatch.kt @@ -0,0 +1,60 @@ +package app.revanced.patches.youtube.shorts.commentpopuppanels.patch + +import app.revanced.extensions.toErrorResult +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.InstructionExtensions.addInstructions +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +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.shorts.commentpopuppanels.fingerprints.ReelWatchFragmentBuilderFingerprint +import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility +import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch +import app.revanced.util.bytecode.getWide32LiteralIndex +import app.revanced.util.integrations.Constants.SHORTS +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction + +@Patch +@Name("enable-new-comment-popup-panels") +@Description("Enables a new type of comment popup panel in the shorts player.") +@DependsOn([SettingsPatch::class]) +@YouTubeCompatibility +@Version("0.0.1") +class NewCommentPopupPanelsPatch : BytecodePatch( + listOf(ReelWatchFragmentBuilderFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + + ReelWatchFragmentBuilderFingerprint.result?.let { + it.mutableMethod.apply { + val targetIndex = getWide32LiteralIndex(45401415) + 2 + val targetRegister = getInstruction(targetIndex).registerA + + addInstructions( + targetIndex + 1, """ + invoke-static {}, $SHORTS->enableNewCommentPopupPanels()Z + move-result v$targetRegister + """ + ) + } + } ?: return ReelWatchFragmentBuilderFingerprint.toErrorResult() + + /** + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "SETTINGS: ENABLE_NEW_COMMENT_POPUP_PANELS" + ) + ) + + SettingsPatch.updatePatchStatus("enable-new-comment-popup-panels") + + return PatchResultSuccess() + } +} diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 94b7d8df5..e96fd63a6 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -83,6 +83,9 @@ External browser is disabled External browser is enabled Enable external browser + New comment popup panels is disabled + New comment popup panels is enabled + Enable new comment popup panels New splash animation is disabled New splash animation is enabled Enable new splash animation diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index f47c04812..59b164a9d 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -361,6 +361,7 @@ + @@ -543,6 +544,9 @@ + +