From f45ce5938bf07fd6873c7f51c3fff9572d61a76e Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Sun, 30 Oct 2022 21:01:40 +0900 Subject: [PATCH] feat: `hide-watch-in-vr` patch (#911) Co-authored-by: oSumAtrIX --- .../annotations/WatchinVRCompatibility.kt | 13 +++++ .../fingerprints/WatchinVRFingerprint.kt | 16 ++++++ .../layout/watchinvr/patch/WatchinVRPatch.kt | 55 +++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/watchinvr/annotations/WatchinVRCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/watchinvr/fingerprints/WatchinVRFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/watchinvr/patch/WatchinVRPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/watchinvr/annotations/WatchinVRCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/watchinvr/annotations/WatchinVRCompatibility.kt new file mode 100644 index 000000000..9f6fd4f55 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/watchinvr/annotations/WatchinVRCompatibility.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.youtube.layout.watchinvr.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility( + [Package( + "com.google.android.youtube", arrayOf("17.33.42", "17.34.36", "17.36.37", "17.41.37") + )] +) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class WatchinVRCompatibility \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/watchinvr/fingerprints/WatchinVRFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/watchinvr/fingerprints/WatchinVRFingerprint.kt new file mode 100644 index 000000000..111d6a7ee --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/watchinvr/fingerprints/WatchinVRFingerprint.kt @@ -0,0 +1,16 @@ +package app.revanced.patches.youtube.layout.watchinvr.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.watchinvr.annotations.WatchinVRCompatibility +import org.jf.dexlib2.AccessFlags + +@Name("watch-in-vr-fingerprint") +@WatchinVRCompatibility +@Version("0.0.1") +object WatchinVRFingerprint : MethodFingerprint( + "V", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf("Z"), + strings = listOf("menu_item_cardboard_vr") +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/watchinvr/patch/WatchinVRPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/watchinvr/patch/WatchinVRPatch.kt new file mode 100644 index 000000000..73e4f54a2 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/watchinvr/patch/WatchinVRPatch.kt @@ -0,0 +1,55 @@ +package app.revanced.patches.youtube.layout.watchinvr.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.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.layout.watchinvr.annotations.WatchinVRCompatibility +import app.revanced.patches.youtube.layout.watchinvr.fingerprints.WatchinVRFingerprint +import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch +import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch +import app.revanced.patches.youtube.misc.settings.framework.components.impl.StringResource +import app.revanced.patches.youtube.misc.settings.framework.components.impl.SwitchPreference + +@Patch +@DependsOn([IntegrationsPatch::class, SettingsPatch::class]) +@Name("hide-watch-in-vr") +@Description("Hides the Watch in VR option from the player settings flyout panel.") +@WatchinVRCompatibility +@Version("0.0.1") +class WatchinVRPatch : BytecodePatch( + listOf( + WatchinVRFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( + SwitchPreference( + "revanced_hide_watch_in_vr", + StringResource("revanced_hide_watch_in_vr_title", "Hide Watch in VR option"), + false, + StringResource("revanced_hide_watch_in_vr_summary_on", "Watch in VR option is hidden"), + StringResource("revanced_hide_watch_in_vr_summary_off", "Watch in VR option is shown") + ) + ) + + WatchinVRFingerprint.result!!.mutableMethod.addInstructions( + 0, """ + invoke-static {}, Lapp/revanced/integrations/patches/HideWatchinVRPatch;->hideWatchinVR()Z + move-result v0 + if-eqz v0, :shown + return-void + :shown + nop + """ + ) + + return PatchResultSuccess() + } +} \ No newline at end of file