From ad98601954f5593887a5cd21b3442d5eddda5901 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Tue, 12 Dec 2023 18:21:34 +0900 Subject: [PATCH] feat(YouTube): add `Change start page` patch --- .../general/startpage/ChangeStartPagePatch.kt | 78 +++++++++++++++++++ .../fingerprints/StartActivityFingerprint.kt | 11 +++ .../youtube/settings/host/values/strings.xml | 12 +++ .../youtube/settings/xml/revanced_prefs.xml | 4 + .../youtube/startpage/host/values/arrays.xml | 29 +++++++ 5 files changed, 134 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/general/startpage/ChangeStartPagePatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/general/startpage/fingerprints/StartActivityFingerprint.kt create mode 100644 src/main/resources/youtube/startpage/host/values/arrays.xml diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/startpage/ChangeStartPagePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/startpage/ChangeStartPagePatch.kt new file mode 100644 index 000000000..26f299df3 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/general/startpage/ChangeStartPagePatch.kt @@ -0,0 +1,78 @@ +package app.revanced.patches.youtube.general.startpage + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.youtube.general.startpage.fingerprints.StartActivityFingerprint +import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL +import app.revanced.patches.youtube.utils.settings.SettingsPatch +import app.revanced.patches.youtube.utils.settings.SettingsPatch.contexts +import app.revanced.util.copyXmlNode +import app.revanced.util.exception + +@Patch( + name = "Change start page", + description = "Changes the start page of the app.", + dependencies = [SettingsPatch::class], + compatiblePackages = [ + CompatiblePackage( + "com.google.android.youtube", + [ + "18.25.40", + "18.27.36", + "18.29.38", + "18.30.37", + "18.31.40", + "18.32.39", + "18.33.40", + "18.34.38", + "18.35.36", + "18.36.39", + "18.37.36", + "18.38.44", + "18.39.41", + "18.40.34", + "18.41.39", + "18.42.41", + "18.43.45", + "18.44.41", + "18.45.43" + ] + ) + ] +) +@Suppress("unused") +object ChangeStartPagePatch : BytecodePatch( + setOf(StartActivityFingerprint) +) { + override fun execute(context: BytecodeContext) { + StartActivityFingerprint.result?.let { + it.mutableMethod.apply { + addInstruction( + 0, + "invoke-static { p1 }, $GENERAL->changeStartPage(Landroid/content/Intent;)V" + ) + } + } ?: throw StartActivityFingerprint.exception + + /** + * Copy arrays + */ + contexts.copyXmlNode("youtube/startpage/host", "values/arrays.xml", "resources") + + /** + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "PREFERENCE: GENERAL_SETTINGS", + "SETTINGS: CHANGE_START_PAGE" + ) + ) + + SettingsPatch.updatePatchStatus("Change start page") + + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/startpage/fingerprints/StartActivityFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/general/startpage/fingerprints/StartActivityFingerprint.kt new file mode 100644 index 000000000..7f305ec6f --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/general/startpage/fingerprints/StartActivityFingerprint.kt @@ -0,0 +1,11 @@ +package app.revanced.patches.youtube.general.startpage.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint + +object StartActivityFingerprint : MethodFingerprint( + parameters = listOf("Landroid/content/Intent;"), + customFingerprint = { methodDef, classDef -> + methodDef.name == "startActivity" + && classDef.type.endsWith("/Shell_HomeActivity;") + } +) \ No newline at end of file diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 944c3e296..fe73e5624 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -58,6 +58,18 @@ Tap here to learn more about DeArrow." Current homepage: Home. Current homepage: Subscriptions. Change homepage to subscriptions + Default + Explore + History + Library + Liked videos + Podcasts + Search + Shorts + Subscriptions + Trending + Change start page + Invalid start page, resetting to default. Channel bar Channel profile "Automatically close interstitial ads. diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 56a9016a7..0e2b47c78 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -175,6 +175,9 @@ PREFERENCE: GENERAL_SETTINGS --> + + @@ -395,6 +398,7 @@ + diff --git a/src/main/resources/youtube/startpage/host/values/arrays.xml b/src/main/resources/youtube/startpage/host/values/arrays.xml new file mode 100644 index 000000000..1bedc0f1b --- /dev/null +++ b/src/main/resources/youtube/startpage/host/values/arrays.xml @@ -0,0 +1,29 @@ + + + + @string/revanced_change_start_page_entry_default + @string/revanced_change_start_page_entry_search + @string/revanced_change_start_page_entry_subscriptions + @string/revanced_change_start_page_entry_explore + @string/revanced_change_start_page_entry_shorts + @string/revanced_change_start_page_entry_library + @string/revanced_change_start_page_entry_liked_videos + @string/revanced_change_start_page_entry_history + @string/revanced_change_start_page_entry_trending + @string/revanced_change_start_page_entry_podcasts + + + + + open.search + open.subscriptions + open.explore + open.shorts + + www.youtube.com/feed/library + www.youtube.com/playlist?list=LL + www.youtube.com/feed/history + www.youtube.com/feed/trending + www.youtube.com/podcasts + +