Skip to content

Commit 37e00d4

Browse files
committed
feat(YouTube/Change start page): change the actual start page instead of redirecting the Url inotia00/ReVanced_Extended#2395
1 parent c2a0da8 commit 37e00d4

File tree

5 files changed

+69
-43
lines changed

5 files changed

+69
-43
lines changed

src/main/kotlin/app/revanced/patches/youtube/general/startpage/ChangeStartPagePatch.kt

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@ package app.revanced.patches.youtube.general.startpage
22

33
import app.revanced.patcher.data.BytecodeContext
44
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
5-
import app.revanced.patches.youtube.general.startpage.fingerprints.ShortcutsActivityFingerprint
6-
import app.revanced.patches.youtube.general.startpage.fingerprints.UrlActivityFingerprint
5+
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
6+
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
7+
import app.revanced.patches.youtube.general.startpage.fingerprints.BrowseIdFingerprint
8+
import app.revanced.patches.youtube.general.startpage.fingerprints.IntentActionFingerprint
79
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
8-
import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR
10+
import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_PATH
911
import app.revanced.patches.youtube.utils.settings.SettingsPatch
12+
import app.revanced.util.getReference
13+
import app.revanced.util.indexOfFirstInstructionOrThrow
1014
import app.revanced.util.patch.BaseBytecodePatch
1115
import app.revanced.util.resultOrThrow
16+
import com.android.tools.smali.dexlib2.Opcode
17+
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
18+
import com.android.tools.smali.dexlib2.iface.reference.StringReference
1219

1320
@Suppress("unused")
1421
object ChangeStartPagePatch : BaseBytecodePatch(
@@ -17,22 +24,37 @@ object ChangeStartPagePatch : BaseBytecodePatch(
1724
dependencies = setOf(SettingsPatch::class),
1825
compatiblePackages = COMPATIBLE_PACKAGE,
1926
fingerprints = setOf(
20-
ShortcutsActivityFingerprint,
21-
UrlActivityFingerprint
27+
BrowseIdFingerprint,
28+
IntentActionFingerprint,
2229
)
2330
) {
31+
private const val INTEGRATIONS_CLASS_DESCRIPTOR = "$GENERAL_PATH/ChangeStartPagePatch;"
32+
2433
override fun execute(context: BytecodeContext) {
2534

26-
mapOf(
27-
ShortcutsActivityFingerprint to "changeStartPageToShortcuts",
28-
UrlActivityFingerprint to "changeStartPageToUrl"
29-
).forEach { (fingerprint, method) ->
30-
fingerprint.resultOrThrow().mutableMethod.addInstruction(
31-
0,
32-
"invoke-static { p1 }, $GENERAL_CLASS_DESCRIPTOR->$method(Landroid/content/Intent;)V"
35+
// Hook broseId.
36+
BrowseIdFingerprint.resultOrThrow().mutableMethod.apply {
37+
val browseIdIndex = indexOfFirstInstructionOrThrow {
38+
opcode == Opcode.CONST_STRING &&
39+
getReference<StringReference>()?.string == "FEwhat_to_watch"
40+
}
41+
val browseIdRegister = getInstruction<OneRegisterInstruction>(browseIdIndex).registerA
42+
43+
addInstructions(
44+
browseIdIndex + 1, """
45+
invoke-static { v$browseIdRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->overrideBrowseId(Ljava/lang/String;)Ljava/lang/String;
46+
move-result-object v$browseIdRegister
47+
"""
3348
)
3449
}
3550

51+
// There is no browserId assigned to Shorts and Search.
52+
// Just hook the Intent action.
53+
IntentActionFingerprint.resultOrThrow().mutableMethod.addInstruction(
54+
0,
55+
"invoke-static { p1 }, $INTEGRATIONS_CLASS_DESCRIPTOR->overrideIntentAction(Landroid/content/Intent;)V"
56+
)
57+
3658
/**
3759
* Add settings
3860
*/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package app.revanced.patches.youtube.general.startpage.fingerprints
2+
3+
import app.revanced.patcher.fingerprint.MethodFingerprint
4+
import com.android.tools.smali.dexlib2.Opcode
5+
6+
internal object BrowseIdFingerprint : MethodFingerprint(
7+
returnType = "Lcom/google/android/apps/youtube/app/common/ui/navigation/PaneDescriptor;",
8+
parameters = emptyList(),
9+
opcodes = listOf(
10+
Opcode.INVOKE_VIRTUAL,
11+
Opcode.MOVE_RESULT_OBJECT,
12+
Opcode.RETURN_OBJECT,
13+
),
14+
strings = listOf("FEwhat_to_watch"),
15+
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package app.revanced.patches.youtube.general.startpage.fingerprints
22

33
import app.revanced.patcher.fingerprint.MethodFingerprint
44

5-
internal object ShortcutsActivityFingerprint : MethodFingerprint(
5+
internal object IntentActionFingerprint : MethodFingerprint(
66
parameters = listOf("Landroid/content/Intent;"),
77
strings = listOf("has_handled_intent"),
88
)

src/main/kotlin/app/revanced/patches/youtube/general/startpage/fingerprints/UrlActivityFingerprint.kt

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/main/resources/youtube/settings/host/values/arrays.xml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
<string-array name="revanced_change_start_page_entries">
2626
<item>@string/revanced_change_start_page_entry_default</item>
2727
<item>@string/revanced_change_start_page_entry_search</item>
28+
<item>@string/revanced_change_start_page_entry_shorts</item>
2829
<item>@string/revanced_change_start_page_entry_subscriptions</item>
2930
<item>@string/revanced_change_start_page_entry_explore</item>
30-
<item>@string/revanced_change_start_page_entry_shorts</item>
3131
<item>@string/revanced_change_start_page_entry_library</item>
3232
<item>@string/revanced_change_start_page_entry_liked_videos</item>
3333
<item>@string/revanced_change_start_page_entry_watch_later</item>
@@ -41,24 +41,24 @@
4141
<item>@string/revanced_change_start_page_entry_browse</item>
4242
</string-array>
4343
<string-array name="revanced_change_start_page_entry_values">
44-
<item></item>
45-
<!-- YouTube Shortcuts -->
46-
<item>open.search</item>
47-
<item>open.subscriptions</item>
48-
<item>open.explore</item>
49-
<item>open.shorts</item>
50-
<!-- YouTube Widgets -->
51-
<item>www.youtube.com/feed/library</item>
52-
<item>www.youtube.com/playlist?list=LL</item>
53-
<item>www.youtube.com/playlist?list=WL</item>
54-
<item>www.youtube.com/feed/history</item>
55-
<item>www.youtube.com/feed/trending</item>
56-
<item>www.youtube.com/gaming</item>
57-
<item>www.youtube.com/channel/UC4R8DWoMoI7CAwX8_LjQHig</item>
58-
<item>www.youtube.com/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ</item>
59-
<item>www.youtube.com/feed/storefront?bp=ogUCKAI%3D</item>
60-
<item>www.youtube.com/channel/UCEgdi0XIXXZ-qJOFPf4JSKw</item>
61-
<item>www.youtube.com/feed/guide_builder</item>
44+
<item>ORIGINAL</item>
45+
<!-- Intent Action -->
46+
<item>SEARCH</item>
47+
<item>SHORTS</item>
48+
<!-- Browser Id -->
49+
<item>SUBSCRIPTIONS</item>
50+
<item>EXPLORE</item>
51+
<item>LIBRARY</item>
52+
<item>LIKED_VIDEO</item>
53+
<item>WATCH_LATER</item>
54+
<item>HISTORY</item>
55+
<item>TRENDING</item>
56+
<item>GAMING</item>
57+
<item>LIVE</item>
58+
<item>MUSIC</item>
59+
<item>MOVIE</item>
60+
<item>SPORTS</item>
61+
<item>BROWSE</item>
6262
</string-array>
6363
<string-array name="revanced_change_shorts_repeat_state_entries">
6464
<item>@string/revanced_change_shorts_repeat_state_entry_default</item>

0 commit comments

Comments
 (0)