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.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<StringReference>()?.string == "FEwhat_to_watch"
}
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
*/

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
internal object ShortcutsActivityFingerprint : MethodFingerprint(
internal object IntentActionFingerprint : MethodFingerprint(
parameters = listOf("Landroid/content/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">
<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_shorts</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_shorts</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_watch_later</item>
@ -41,24 +41,24 @@
<item>@string/revanced_change_start_page_entry_browse</item>
</string-array>
<string-array name="revanced_change_start_page_entry_values">
<item></item>
<!-- YouTube Shortcuts -->
<item>open.search</item>
<item>open.subscriptions</item>
<item>open.explore</item>
<item>open.shorts</item>
<!-- YouTube Widgets -->
<item>www.youtube.com/feed/library</item>
<item>www.youtube.com/playlist?list=LL</item>
<item>www.youtube.com/playlist?list=WL</item>
<item>www.youtube.com/feed/history</item>
<item>www.youtube.com/feed/trending</item>
<item>www.youtube.com/gaming</item>
<item>www.youtube.com/channel/UC4R8DWoMoI7CAwX8_LjQHig</item>
<item>www.youtube.com/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ</item>
<item>www.youtube.com/feed/storefront?bp=ogUCKAI%3D</item>
<item>www.youtube.com/channel/UCEgdi0XIXXZ-qJOFPf4JSKw</item>
<item>www.youtube.com/feed/guide_builder</item>
<item>ORIGINAL</item>
<!-- Intent Action -->
<item>SEARCH</item>
<item>SHORTS</item>
<!-- Browser Id -->
<item>SUBSCRIPTIONS</item>
<item>EXPLORE</item>
<item>LIBRARY</item>
<item>LIKED_VIDEO</item>
<item>WATCH_LATER</item>
<item>HISTORY</item>
<item>TRENDING</item>
<item>GAMING</item>
<item>LIVE</item>
<item>MUSIC</item>
<item>MOVIE</item>
<item>SPORTS</item>
<item>BROWSE</item>
</string-array>
<string-array name="revanced_change_shorts_repeat_state_entries">
<item>@string/revanced_change_shorts_repeat_state_entry_default</item>