feat(YouTube/Change start page): change the actual start page instead of redirecting the Url https://github.com/inotia00/ReVanced_Extended/issues/2395

This commit is contained in:
inotia00 2024-09-18 19:41:13 +09:00
parent c2a0da8d75
commit 37e00d462d
5 changed files with 69 additions and 43 deletions

View File

@ -2,13 +2,20 @@ package app.revanced.patches.youtube.general.startpage
import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patches.youtube.general.startpage.fingerprints.ShortcutsActivityFingerprint import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patches.youtube.general.startpage.fingerprints.UrlActivityFingerprint 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.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.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.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow 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") @Suppress("unused")
object ChangeStartPagePatch : BaseBytecodePatch( object ChangeStartPagePatch : BaseBytecodePatch(
@ -17,22 +24,37 @@ object ChangeStartPagePatch : BaseBytecodePatch(
dependencies = setOf(SettingsPatch::class), dependencies = setOf(SettingsPatch::class),
compatiblePackages = COMPATIBLE_PACKAGE, compatiblePackages = COMPATIBLE_PACKAGE,
fingerprints = setOf( fingerprints = setOf(
ShortcutsActivityFingerprint, BrowseIdFingerprint,
UrlActivityFingerprint IntentActionFingerprint,
) )
) { ) {
private const val INTEGRATIONS_CLASS_DESCRIPTOR = "$GENERAL_PATH/ChangeStartPagePatch;"
override fun execute(context: BytecodeContext) { override fun execute(context: BytecodeContext) {
mapOf( // Hook broseId.
ShortcutsActivityFingerprint to "changeStartPageToShortcuts", BrowseIdFingerprint.resultOrThrow().mutableMethod.apply {
UrlActivityFingerprint to "changeStartPageToUrl" val browseIdIndex = indexOfFirstInstructionOrThrow {
).forEach { (fingerprint, method) -> opcode == Opcode.CONST_STRING &&
fingerprint.resultOrThrow().mutableMethod.addInstruction( getReference<StringReference>()?.string == "FEwhat_to_watch"
0, }
"invoke-static { p1 }, $GENERAL_CLASS_DESCRIPTOR->$method(Landroid/content/Intent;)V" val browseIdRegister = getInstruction<OneRegisterInstruction>(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 * Add settings
*/ */

View File

@ -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"),
)

View File

@ -2,7 +2,7 @@ package app.revanced.patches.youtube.general.startpage.fingerprints
import app.revanced.patcher.fingerprint.MethodFingerprint import app.revanced.patcher.fingerprint.MethodFingerprint
internal object ShortcutsActivityFingerprint : MethodFingerprint( internal object IntentActionFingerprint : MethodFingerprint(
parameters = listOf("Landroid/content/Intent;"), parameters = listOf("Landroid/content/Intent;"),
strings = listOf("has_handled_intent"), strings = listOf("has_handled_intent"),
) )

View File

@ -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;")
}
)

View File

@ -25,9 +25,9 @@
<string-array name="revanced_change_start_page_entries"> <string-array name="revanced_change_start_page_entries">
<item>@string/revanced_change_start_page_entry_default</item> <item>@string/revanced_change_start_page_entry_default</item>
<item>@string/revanced_change_start_page_entry_search</item> <item>@string/revanced_change_start_page_entry_search</item>
<item>@string/revanced_change_start_page_entry_shorts</item>
<item>@string/revanced_change_start_page_entry_subscriptions</item> <item>@string/revanced_change_start_page_entry_subscriptions</item>
<item>@string/revanced_change_start_page_entry_explore</item> <item>@string/revanced_change_start_page_entry_explore</item>
<item>@string/revanced_change_start_page_entry_shorts</item>
<item>@string/revanced_change_start_page_entry_library</item> <item>@string/revanced_change_start_page_entry_library</item>
<item>@string/revanced_change_start_page_entry_liked_videos</item> <item>@string/revanced_change_start_page_entry_liked_videos</item>
<item>@string/revanced_change_start_page_entry_watch_later</item> <item>@string/revanced_change_start_page_entry_watch_later</item>
@ -41,24 +41,24 @@
<item>@string/revanced_change_start_page_entry_browse</item> <item>@string/revanced_change_start_page_entry_browse</item>
</string-array> </string-array>
<string-array name="revanced_change_start_page_entry_values"> <string-array name="revanced_change_start_page_entry_values">
<item></item> <item>ORIGINAL</item>
<!-- YouTube Shortcuts --> <!-- Intent Action -->
<item>open.search</item> <item>SEARCH</item>
<item>open.subscriptions</item> <item>SHORTS</item>
<item>open.explore</item> <!-- Browser Id -->
<item>open.shorts</item> <item>SUBSCRIPTIONS</item>
<!-- YouTube Widgets --> <item>EXPLORE</item>
<item>www.youtube.com/feed/library</item> <item>LIBRARY</item>
<item>www.youtube.com/playlist?list=LL</item> <item>LIKED_VIDEO</item>
<item>www.youtube.com/playlist?list=WL</item> <item>WATCH_LATER</item>
<item>www.youtube.com/feed/history</item> <item>HISTORY</item>
<item>www.youtube.com/feed/trending</item> <item>TRENDING</item>
<item>www.youtube.com/gaming</item> <item>GAMING</item>
<item>www.youtube.com/channel/UC4R8DWoMoI7CAwX8_LjQHig</item> <item>LIVE</item>
<item>www.youtube.com/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ</item> <item>MUSIC</item>
<item>www.youtube.com/feed/storefront?bp=ogUCKAI%3D</item> <item>MOVIE</item>
<item>www.youtube.com/channel/UCEgdi0XIXXZ-qJOFPf4JSKw</item> <item>SPORTS</item>
<item>www.youtube.com/feed/guide_builder</item> <item>BROWSE</item>
</string-array> </string-array>
<string-array name="revanced_change_shorts_repeat_state_entries"> <string-array name="revanced_change_shorts_repeat_state_entries">
<item>@string/revanced_change_shorts_repeat_state_entry_default</item> <item>@string/revanced_change_shorts_repeat_state_entry_default</item>