From ad9ba37c0568bd303d807b3ddf1a22daa8f8ec59 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Tue, 12 Dec 2023 00:34:26 +0100 Subject: [PATCH] feat(YouTube): Add `Change start page` patch --- api/revanced-patches.api | 18 ++++- .../fingerprints/HomeActivityFingerprint.kt | 2 +- .../layout/startpage/ChangeStartPagePatch.kt | 78 +++++++++++++++++++ .../fingerprints/StartActivityFingerprint.kt | 7 ++ .../youtube/misc/gms/GmsCoreSupportPatch.kt | 1 + 5 files changed, 101 insertions(+), 5 deletions(-) rename src/main/kotlin/app/revanced/patches/{youtube/misc/gms => shared}/fingerprints/HomeActivityFingerprint.kt (83%) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/startpage/ChangeStartPagePatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/startpage/fingerprints/StartActivityFingerprint.kt diff --git a/api/revanced-patches.api b/api/revanced-patches.api index 54ae49970..1bc81b63c 100644 --- a/api/revanced-patches.api +++ b/api/revanced-patches.api @@ -521,6 +521,10 @@ public final class app/revanced/patches/serviceportalbund/detection/root/RootDet public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V } +public final class app/revanced/patches/shared/fingerprints/HomeActivityFingerprint : app/revanced/patches/shared/integrations/AbstractIntegrationsPatch$IntegrationsFingerprint { + public static final field INSTANCE Lapp/revanced/patches/shared/fingerprints/HomeActivityFingerprint; +} + public abstract class app/revanced/patches/shared/integrations/AbstractIntegrationsPatch : app/revanced/patcher/patch/BytecodePatch { public fun (Ljava/lang/String;Ljava/util/Set;)V public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V @@ -1338,6 +1342,16 @@ public final class app/revanced/patches/youtube/layout/spoofappversion/SpoofAppV public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V } +public final class app/revanced/patches/youtube/layout/startpage/ChangeStartPagePatch : app/revanced/patcher/patch/BytecodePatch { + public static final field INSTANCE Lapp/revanced/patches/youtube/layout/startpage/ChangeStartPagePatch; + public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V + public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V +} + +public final class app/revanced/patches/youtube/layout/startpage/fingerprints/StartActivityFingerprint : app/revanced/patcher/fingerprint/MethodFingerprint { + public static final field INSTANCE Lapp/revanced/patches/youtube/layout/startpage/fingerprints/StartActivityFingerprint; +} + public final class app/revanced/patches/youtube/layout/startupshortsreset/DisableResumingShortsOnStartupPatch : app/revanced/patcher/patch/BytecodePatch { public static final field INSTANCE Lapp/revanced/patches/youtube/layout/startupshortsreset/DisableResumingShortsOnStartupPatch; public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V @@ -1423,10 +1437,6 @@ public final class app/revanced/patches/youtube/misc/gms/GmsCoreSupportResourceP public fun execute (Lapp/revanced/patcher/data/ResourceContext;)V } -public final class app/revanced/patches/youtube/misc/gms/fingerprints/HomeActivityFingerprint : app/revanced/patches/shared/integrations/AbstractIntegrationsPatch$IntegrationsFingerprint { - public static final field INSTANCE Lapp/revanced/patches/youtube/misc/gms/fingerprints/HomeActivityFingerprint; -} - public final class app/revanced/patches/youtube/misc/integrations/IntegrationsPatch : app/revanced/patches/shared/integrations/AbstractIntegrationsPatch { public static final field INSTANCE Lapp/revanced/patches/youtube/misc/integrations/IntegrationsPatch; } diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/gms/fingerprints/HomeActivityFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/fingerprints/HomeActivityFingerprint.kt similarity index 83% rename from src/main/kotlin/app/revanced/patches/youtube/misc/gms/fingerprints/HomeActivityFingerprint.kt rename to src/main/kotlin/app/revanced/patches/shared/fingerprints/HomeActivityFingerprint.kt index f818c59a5..8edf3e003 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/gms/fingerprints/HomeActivityFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/shared/fingerprints/HomeActivityFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.misc.gms.fingerprints +package app.revanced.patches.shared.fingerprints import app.revanced.patches.shared.integrations.AbstractIntegrationsPatch.IntegrationsFingerprint diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/startpage/ChangeStartPagePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/startpage/ChangeStartPagePatch.kt new file mode 100644 index 000000000..5e11bf838 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/startpage/ChangeStartPagePatch.kt @@ -0,0 +1,78 @@ +package app.revanced.patches.youtube.layout.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.shared.fingerprints.HomeActivityFingerprint +import app.revanced.patches.shared.settings.preference.impl.ArrayResource +import app.revanced.patches.shared.settings.preference.impl.ListPreference +import app.revanced.patches.shared.settings.preference.impl.StringResource +import app.revanced.patches.youtube.layout.startpage.fingerprints.StartActivityFingerprint +import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch +import app.revanced.patches.youtube.misc.settings.SettingsPatch +import app.revanced.util.exception + +@Patch( + name = "Change start page", + description = "Changes the start page of the app.", + dependencies = [IntegrationsPatch::class, SettingsPatch::class], + compatiblePackages = [ + CompatiblePackage( + "com.google.android.youtube" + ) + ] +) +@Suppress("unused") +object ChangeStartPagePatch : BytecodePatch( + setOf(HomeActivityFingerprint) +) { + private const val INTEGRATIONS_CLASS_DESCRIPTOR = + "Lapp/revanced/integrations/patches/ChangeStartPagePatch;" + + override fun execute(context: BytecodeContext) { + SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( + ListPreference( + "revanced_start_page", + StringResource( + "revanced_start_page_title", + "Set start page" + ), + ArrayResource( + "revanced_start_page_entries", + listOf( + StringResource("revanced_start_page_home_entry_0", "Default"), + StringResource("revanced_start_page_home_entry_1", "Home"), + StringResource("revanced_start_page_search_entry_2", "Search"), + StringResource("revanced_start_page_subscriptions_entry_3", "Subscriptions"), + StringResource("revanced_start_page_explore_entry_4", "Explore"), + StringResource("revanced_start_page_shorts_entry_5", "Shorts"), + ) + ), + ArrayResource( + "revanced_start_page_values", + listOf( + StringResource("revanced_start_page_home_value_0", ""), + StringResource("revanced_start_page_home_value_1", "MAIN"), + StringResource("revanced_start_page_search_value_2", "open.search"), + StringResource("revanced_start_page_subscriptions_value_3", "open.subscriptions"), + StringResource("revanced_start_page_explore_value_4", "open.explore"), + StringResource("revanced_start_page_shorts_value_5", "open.shorts"), + ) + ), + default = "" + ) + ) + + StartActivityFingerprint.resolve( + context, + HomeActivityFingerprint.result?.classDef ?: throw HomeActivityFingerprint.exception + ) + + StartActivityFingerprint.result?.mutableMethod?.addInstruction( + 0, + "invoke-static { p1 }, $INTEGRATIONS_CLASS_DESCRIPTOR->changeIntent(Landroid/content/Intent;)V" + ) ?: throw StartActivityFingerprint.exception + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/startpage/fingerprints/StartActivityFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/startpage/fingerprints/StartActivityFingerprint.kt new file mode 100644 index 000000000..746187218 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/startpage/fingerprints/StartActivityFingerprint.kt @@ -0,0 +1,7 @@ +package app.revanced.patches.youtube.layout.startpage.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint + +object StartActivityFingerprint : MethodFingerprint( + parameters = listOf("Landroid/content/Intent;"), +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/gms/GmsCoreSupportPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/gms/GmsCoreSupportPatch.kt index aeaa4a049..7d1a11e33 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/gms/GmsCoreSupportPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/gms/GmsCoreSupportPatch.kt @@ -2,6 +2,7 @@ package app.revanced.patches.youtube.misc.gms import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patches.shared.fingerprints.HomeActivityFingerprint import app.revanced.patches.shared.misc.gms.AbstractGmsCoreSupportPatch import app.revanced.patches.youtube.layout.buttons.cast.HideCastButtonPatch import app.revanced.patches.youtube.misc.fix.playback.ClientSpoofPatch