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 index bca0fe45ee..57a13e8110 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/startpage/ChangeStartPagePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/startpage/ChangeStartPagePatch.kt @@ -2,13 +2,20 @@ package app.revanced.patches.youtube.general.startpage import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstruction -import app.revanced.patches.youtube.general.startpage.fingerprints.ShortcutsActivityFingerprint -import app.revanced.patches.youtube.general.startpage.fingerprints.UrlActivityFingerprint +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patches.youtube.general.startpage.fingerprints.BrowseIdFingerprint +import app.revanced.patches.youtube.general.startpage.fingerprints.IntentActionFingerprint import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE -import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR +import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_PATH import app.revanced.patches.youtube.utils.settings.SettingsPatch +import app.revanced.util.getReference +import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.resultOrThrow +import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.StringReference @Suppress("unused") object ChangeStartPagePatch : BaseBytecodePatch( @@ -17,22 +24,37 @@ object ChangeStartPagePatch : BaseBytecodePatch( dependencies = setOf(SettingsPatch::class), compatiblePackages = COMPATIBLE_PACKAGE, fingerprints = setOf( - ShortcutsActivityFingerprint, - UrlActivityFingerprint + BrowseIdFingerprint, + IntentActionFingerprint, ) ) { + private const val INTEGRATIONS_CLASS_DESCRIPTOR = "$GENERAL_PATH/ChangeStartPagePatch;" + override fun execute(context: BytecodeContext) { - mapOf( - ShortcutsActivityFingerprint to "changeStartPageToShortcuts", - UrlActivityFingerprint to "changeStartPageToUrl" - ).forEach { (fingerprint, method) -> - fingerprint.resultOrThrow().mutableMethod.addInstruction( - 0, - "invoke-static { p1 }, $GENERAL_CLASS_DESCRIPTOR->$method(Landroid/content/Intent;)V" + // Hook broseId. + BrowseIdFingerprint.resultOrThrow().mutableMethod.apply { + val browseIdIndex = indexOfFirstInstructionOrThrow { + opcode == Opcode.CONST_STRING && + getReference()?.string == "FEwhat_to_watch" + } + val browseIdRegister = getInstruction(browseIdIndex).registerA + + addInstructions( + browseIdIndex + 1, """ + invoke-static { v$browseIdRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->overrideBrowseId(Ljava/lang/String;)Ljava/lang/String; + move-result-object v$browseIdRegister + """ ) } + // There is no browserId assigned to Shorts and Search. + // Just hook the Intent action. + IntentActionFingerprint.resultOrThrow().mutableMethod.addInstruction( + 0, + "invoke-static { p1 }, $INTEGRATIONS_CLASS_DESCRIPTOR->overrideIntentAction(Landroid/content/Intent;)V" + ) + /** * Add settings */ diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/startpage/fingerprints/BrowseIdFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/general/startpage/fingerprints/BrowseIdFingerprint.kt new file mode 100644 index 0000000000..f53490ac40 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/general/startpage/fingerprints/BrowseIdFingerprint.kt @@ -0,0 +1,15 @@ +package app.revanced.patches.youtube.general.startpage.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.Opcode + +internal object BrowseIdFingerprint : MethodFingerprint( + returnType = "Lcom/google/android/apps/youtube/app/common/ui/navigation/PaneDescriptor;", + parameters = emptyList(), + opcodes = listOf( + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.RETURN_OBJECT, + ), + strings = listOf("FEwhat_to_watch"), +) diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/startpage/fingerprints/ShortcutsActivityFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/general/startpage/fingerprints/IntentActionFingerprint.kt similarity index 77% rename from src/main/kotlin/app/revanced/patches/youtube/general/startpage/fingerprints/ShortcutsActivityFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/general/startpage/fingerprints/IntentActionFingerprint.kt index c0bd159175..8d6292c7de 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/startpage/fingerprints/ShortcutsActivityFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/startpage/fingerprints/IntentActionFingerprint.kt @@ -2,7 +2,7 @@ package app.revanced.patches.youtube.general.startpage.fingerprints import app.revanced.patcher.fingerprint.MethodFingerprint -internal object ShortcutsActivityFingerprint : MethodFingerprint( +internal object IntentActionFingerprint : MethodFingerprint( parameters = listOf("Landroid/content/Intent;"), strings = listOf("has_handled_intent"), ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/startpage/fingerprints/UrlActivityFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/general/startpage/fingerprints/UrlActivityFingerprint.kt deleted file mode 100644 index 680ef6e29b..0000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/general/startpage/fingerprints/UrlActivityFingerprint.kt +++ /dev/null @@ -1,11 +0,0 @@ -package app.revanced.patches.youtube.general.startpage.fingerprints - -import app.revanced.patcher.fingerprint.MethodFingerprint - -internal object UrlActivityFingerprint : 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/arrays.xml b/src/main/resources/youtube/settings/host/values/arrays.xml index a329bc5554..ba6d4cc258 100644 --- a/src/main/resources/youtube/settings/host/values/arrays.xml +++ b/src/main/resources/youtube/settings/host/values/arrays.xml @@ -25,9 +25,9 @@ @string/revanced_change_start_page_entry_default @string/revanced_change_start_page_entry_search + @string/revanced_change_start_page_entry_shorts @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_watch_later @@ -41,24 +41,24 @@ @string/revanced_change_start_page_entry_browse - - - open.search - open.subscriptions - open.explore - open.shorts - - www.youtube.com/feed/library - www.youtube.com/playlist?list=LL - www.youtube.com/playlist?list=WL - www.youtube.com/feed/history - www.youtube.com/feed/trending - www.youtube.com/gaming - www.youtube.com/channel/UC4R8DWoMoI7CAwX8_LjQHig - www.youtube.com/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ - www.youtube.com/feed/storefront?bp=ogUCKAI%3D - www.youtube.com/channel/UCEgdi0XIXXZ-qJOFPf4JSKw - www.youtube.com/feed/guide_builder + ORIGINAL + + SEARCH + SHORTS + + SUBSCRIPTIONS + EXPLORE + LIBRARY + LIKED_VIDEO + WATCH_LATER + HISTORY + TRENDING + GAMING + LIVE + MUSIC + MOVIE + SPORTS + BROWSE @string/revanced_change_shorts_repeat_state_entry_default