mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-13 05:37:40 +02:00
feat(YouTube - Shorts components): add Custom actions in toolbar
setting (YouTube 18.38.44+) (#106)
* feat(YouTube - Shorts Player): Hook `More` button * fix(YouTube - Shorts Player): Incorrect videoId when playing a Short * fix(YouTube - Shorts Player): `Open in normal player` didn't work when `Enable open links directly` was disabled * fix: Use an existing class --------- Co-authored-by: inotia00 <108592928+inotia00@users.noreply.github.com>
This commit is contained in:

committed by
GitHub

parent
7023e5b323
commit
73b95a5143
@ -14,9 +14,13 @@ import app.revanced.patches.youtube.utils.resourceid.reelRightLikeIcon
|
||||
import app.revanced.patches.youtube.utils.resourceid.reelVodTimeStampsContainer
|
||||
import app.revanced.patches.youtube.utils.resourceid.rightComment
|
||||
import app.revanced.util.fingerprint.legacyFingerprint
|
||||
import app.revanced.util.getReference
|
||||
import app.revanced.util.indexOfFirstInstruction
|
||||
import app.revanced.util.or
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.iface.Method
|
||||
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
||||
|
||||
internal val bottomSheetMenuListBuilderFingerprint = legacyFingerprint(
|
||||
name = "bottomSheetMenuListBuilderFingerprint",
|
||||
@ -32,6 +36,23 @@ internal val bottomSheetMenuListBuilderFingerprint = legacyFingerprint(
|
||||
strings = listOf("Bottom Sheet Menu is empty. No menu items were supported."),
|
||||
)
|
||||
|
||||
internal val liveHeaderElementsContainerFingerprint = legacyFingerprint(
|
||||
name = "liveHeaderElementsContainerFingerprint",
|
||||
returnType = "V",
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||
parameters = listOf("Landroid/view/ViewGroup;", "L"),
|
||||
strings = listOf("Header container is null, header cannot be presented."),
|
||||
customFingerprint = { method, _ ->
|
||||
indexOfAddLiveHeaderElementsContainerInstruction(method) >= 0
|
||||
},
|
||||
)
|
||||
|
||||
fun indexOfAddLiveHeaderElementsContainerInstruction(method: Method) =
|
||||
method.indexOfFirstInstruction {
|
||||
opcode == Opcode.INVOKE_DIRECT &&
|
||||
getReference<MethodReference>()?.name == "addView"
|
||||
}
|
||||
|
||||
internal val reelEnumConstructorFingerprint = legacyFingerprint(
|
||||
name = "reelEnumConstructorFingerprint",
|
||||
returnType = "V",
|
||||
|
@ -29,7 +29,9 @@ import app.revanced.patches.youtube.utils.navigation.navigationBarHookPatch
|
||||
import app.revanced.patches.youtube.utils.patch.PatchList.SHORTS_COMPONENTS
|
||||
import app.revanced.patches.youtube.utils.playertype.playerTypeHookPatch
|
||||
import app.revanced.patches.youtube.utils.playservice.is_18_31_or_greater
|
||||
import app.revanced.patches.youtube.utils.playservice.is_18_34_or_greater
|
||||
import app.revanced.patches.youtube.utils.playservice.is_18_49_or_greater
|
||||
import app.revanced.patches.youtube.utils.playservice.is_19_02_or_greater
|
||||
import app.revanced.patches.youtube.utils.playservice.is_19_25_or_greater
|
||||
import app.revanced.patches.youtube.utils.playservice.is_19_28_or_greater
|
||||
import app.revanced.patches.youtube.utils.playservice.versionCheckPatch
|
||||
@ -53,6 +55,8 @@ import app.revanced.patches.youtube.utils.resourceid.sharedResourceIdPatch
|
||||
import app.revanced.patches.youtube.utils.settings.ResourceUtils.addPreference
|
||||
import app.revanced.patches.youtube.utils.settings.ResourceUtils.getContext
|
||||
import app.revanced.patches.youtube.utils.settings.settingsPatch
|
||||
import app.revanced.patches.youtube.utils.toolbar.hookToolBar
|
||||
import app.revanced.patches.youtube.utils.toolbar.toolBarHookPatch
|
||||
import app.revanced.patches.youtube.video.information.hookShortsVideoInformation
|
||||
import app.revanced.patches.youtube.video.information.videoInformationPatch
|
||||
import app.revanced.patches.youtube.video.videoid.hookPlayerResponseVideoId
|
||||
@ -81,6 +85,7 @@ import app.revanced.util.or
|
||||
import app.revanced.util.replaceLiteralInstructionCall
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.RegisterRangeInstruction
|
||||
@ -153,16 +158,50 @@ private val shortsCustomActionsPatch = bytecodePatch(
|
||||
bottomSheetRecyclerViewPatch,
|
||||
lithoFilterPatch,
|
||||
playerTypeHookPatch,
|
||||
toolBarHookPatch,
|
||||
videoIdPatch,
|
||||
videoInformationPatch,
|
||||
versionCheckPatch,
|
||||
)
|
||||
|
||||
execute {
|
||||
if (!is_18_49_or_greater) {
|
||||
if (!is_18_34_or_greater) {
|
||||
return@execute
|
||||
}
|
||||
|
||||
// region hook toolbar more button
|
||||
|
||||
hookToolBar("$EXTENSION_CUSTOM_ACTIONS_CLASS_DESCRIPTOR->setToolbarMenu")
|
||||
|
||||
// toolbar in Shorts livestream
|
||||
liveHeaderElementsContainerFingerprint.methodOrThrow().apply {
|
||||
val addViewIndex = indexOfAddLiveHeaderElementsContainerInstruction(this)
|
||||
val viewRegister = getInstruction<FiveRegisterInstruction>(addViewIndex).registerD
|
||||
|
||||
addInstruction(
|
||||
addViewIndex + 1,
|
||||
"invoke-static {v$viewRegister}, " +
|
||||
"$EXTENSION_CUSTOM_ACTIONS_CLASS_DESCRIPTOR->onLiveHeaderElementsContainerCreate(Landroid/view/View;)V"
|
||||
)
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
// region add litho filter
|
||||
|
||||
hookPlayerResponseVideoId("$SHORTS_PLAYER_FLYOUT_MENU_FILTER_CLASS_DESCRIPTOR->newPlayerResponseVideoId(Ljava/lang/String;Z)V")
|
||||
hookShortsVideoInformation("$SHORTS_PLAYER_FLYOUT_MENU_FILTER_CLASS_DESCRIPTOR->newShortsVideoStarted(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JZ)V")
|
||||
|
||||
addLithoFilter(SHORTS_PLAYER_FLYOUT_MENU_FILTER_CLASS_DESCRIPTOR)
|
||||
|
||||
// endregion
|
||||
|
||||
if (!is_19_02_or_greater) {
|
||||
return@execute
|
||||
}
|
||||
|
||||
// region hook flyout menu
|
||||
|
||||
bottomSheetMenuListBuilderFingerprint.matchOrThrow().let {
|
||||
it.method.apply {
|
||||
val addListIndex = indexOfFirstInstructionOrThrow {
|
||||
@ -280,10 +319,7 @@ private val shortsCustomActionsPatch = bytecodePatch(
|
||||
|
||||
bottomSheetRecyclerViewHook("$EXTENSION_CUSTOM_ACTIONS_CLASS_DESCRIPTOR->onFlyoutMenuCreate(Landroid/support/v7/widget/RecyclerView;)V")
|
||||
|
||||
hookPlayerResponseVideoId("$SHORTS_PLAYER_FLYOUT_MENU_FILTER_CLASS_DESCRIPTOR->newPlayerResponseVideoId(Ljava/lang/String;Z)V")
|
||||
hookShortsVideoInformation("$SHORTS_PLAYER_FLYOUT_MENU_FILTER_CLASS_DESCRIPTOR->newShortsVideoStarted(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JZ)V")
|
||||
|
||||
addLithoFilter(SHORTS_PLAYER_FLYOUT_MENU_FILTER_CLASS_DESCRIPTOR)
|
||||
// endregion
|
||||
|
||||
}
|
||||
}
|
||||
@ -571,8 +607,13 @@ val shortsComponentPatch = bytecodePatch(
|
||||
settingArray += "SETTINGS: SHORTS_TIME_STAMP"
|
||||
}
|
||||
|
||||
if (is_18_49_or_greater) {
|
||||
settingArray += "SETTINGS: SHORTS_CUSTOM_ACTIONS"
|
||||
if (is_18_34_or_greater) {
|
||||
settingArray += "SETTINGS: SHORTS_CUSTOM_ACTIONS_SHARED"
|
||||
settingArray += "SETTINGS: SHORTS_CUSTOM_ACTIONS_TOOLBAR"
|
||||
}
|
||||
|
||||
if (is_19_02_or_greater) {
|
||||
settingArray += "SETTINGS: SHORTS_CUSTOM_ACTIONS_FLYOUT_MENU"
|
||||
}
|
||||
|
||||
// region patch for hide comments button (non-litho)
|
||||
|
@ -1364,6 +1364,11 @@ Limitations:
|
||||
• Does not work if app version is spoofed to 18.49.37 or earlier.
|
||||
• Does not work with livestream."</string>
|
||||
<string name="revanced_enable_shorts_custom_actions_flyout_menu_summary_off">Custom actions are disabled in flyout menu.</string>
|
||||
<string name="revanced_enable_shorts_custom_actions_toolbar_title">Enable custom actions in toolbar</string>
|
||||
<string name="revanced_enable_shorts_custom_actions_toolbar_summary_on">"Custom actions are enabled in toolbar.
|
||||
|
||||
Press and hold the More button to show the Custom actions dialog."</string>
|
||||
<string name="revanced_enable_shorts_custom_actions_toolbar_summary_off">Custom actions are disabled in toolbar.</string>
|
||||
<string name="revanced_shorts_custom_actions_toolbar_dialog_title">Custom actions</string>
|
||||
<string name="revanced_shorts_custom_actions_copy_video_url_label">Copy video URL</string>
|
||||
<string name="revanced_shorts_custom_actions_copy_video_url_title">Show copy video URL menu</string>
|
||||
@ -1385,6 +1390,10 @@ Limitations:
|
||||
<string name="revanced_shorts_custom_actions_repeat_state_title">Show repeat state menu</string>
|
||||
<string name="revanced_shorts_custom_actions_repeat_state_summary_on">Repeat state menu is shown.</string>
|
||||
<string name="revanced_shorts_custom_actions_repeat_state_summary_off">Repeat state menu is hidden.</string>
|
||||
<string name="revanced_shorts_custom_actions_about_title">About Custom actions</string>
|
||||
<string name="revanced_shorts_custom_actions_about_about_summary">"This feature is still experimental, so there is no guarantee that it will work perfectly.
|
||||
|
||||
Most bugs cannot be fixed due to client-side limitations, so use it only for testing purposes."</string>
|
||||
|
||||
<!-- PreferenceScreen: Shorts, PreferenceCategory: Shorts, PreferenceScreen: Shorts player, PreferenceCategory: Experimental Flags -->
|
||||
<string name="revanced_enable_shorts_time_stamp_title">Enable timestamps</string>
|
||||
|
@ -582,16 +582,26 @@
|
||||
<SwitchPreference android:title="@string/revanced_hide_shorts_play_pause_button_background_title" android:key="revanced_hide_shorts_play_pause_button_background" android:summaryOn="@string/revanced_hide_shorts_play_pause_button_background_summary_on" android:summaryOff="@string/revanced_hide_shorts_play_pause_button_background_summary_off" />
|
||||
<ListPreference android:entries="@array/revanced_shorts_double_tap_to_like_animation_entries" android:title="@string/revanced_shorts_double_tap_to_like_animation_title" android:key="revanced_shorts_double_tap_to_like_animation" android:entryValues="@array/revanced_shorts_double_tap_to_like_animation_entry_values" />SETTINGS: SHORTS_COMPONENTS -->
|
||||
|
||||
<!-- SETTINGS: SHORTS_CUSTOM_ACTIONS
|
||||
<PreferenceCategory android:title="@string/revanced_preference_category_custom_actions" android:layout="@layout/revanced_settings_preferences_category"/>
|
||||
<SwitchPreference android:title="@string/revanced_enable_shorts_custom_actions_flyout_menu_title" android:key="revanced_enable_shorts_custom_actions_flyout_menu" android:summaryOn="@string/revanced_enable_shorts_custom_actions_flyout_menu_summary_on" android:summaryOff="@string/revanced_enable_shorts_custom_actions_flyout_menu_summary_off" />
|
||||
<!-- SETTINGS: SHORTS_CUSTOM_ACTIONS_SHARED
|
||||
<PreferenceCategory android:title="@string/revanced_preference_category_custom_actions" android:layout="@layout/revanced_settings_preferences_category"/>SETTINGS: SHORTS_CUSTOM_ACTIONS_SHARED -->
|
||||
|
||||
<!-- SETTINGS: SHORTS_CUSTOM_ACTIONS_FLYOUT_MENU
|
||||
<SwitchPreference android:title="@string/revanced_enable_shorts_custom_actions_flyout_menu_title" android:key="revanced_enable_shorts_custom_actions_flyout_menu" android:summaryOn="@string/revanced_enable_shorts_custom_actions_flyout_menu_summary_on" android:summaryOff="@string/revanced_enable_shorts_custom_actions_flyout_menu_summary_off" />SETTINGS: SHORTS_CUSTOM_ACTIONS_FLYOUT_MENU -->
|
||||
|
||||
<!-- SETTINGS: SHORTS_CUSTOM_ACTIONS_TOOLBAR
|
||||
<SwitchPreference android:title="@string/revanced_enable_shorts_custom_actions_toolbar_title" android:key="revanced_enable_shorts_custom_actions_toolbar" android:summaryOn="@string/revanced_enable_shorts_custom_actions_toolbar_summary_on" android:summaryOff="@string/revanced_enable_shorts_custom_actions_toolbar_summary_off" />SETTINGS: SHORTS_CUSTOM_ACTIONS_TOOLBAR -->
|
||||
|
||||
<!-- SETTINGS: SHORTS_CUSTOM_ACTIONS_SHARED
|
||||
<SwitchPreference android:title="@string/revanced_shorts_custom_actions_copy_video_url_title" android:key="revanced_shorts_custom_actions_copy_video_url" android:summaryOn="@string/revanced_shorts_custom_actions_copy_video_url_summary_on" android:summaryOff="@string/revanced_shorts_custom_actions_copy_video_url_summary_off" />
|
||||
<SwitchPreference android:title="@string/revanced_shorts_custom_actions_copy_video_url_timestamp_title" android:key="revanced_shorts_custom_actions_copy_video_url_timestamp" android:summaryOn="@string/revanced_shorts_custom_actions_copy_video_url_timestamp_summary_on" android:summaryOff="@string/revanced_shorts_custom_actions_copy_video_url_timestamp_summary_off" />
|
||||
<SwitchPreference android:title="@string/revanced_shorts_custom_actions_external_downloader_title" android:key="revanced_shorts_custom_actions_external_downloader" android:summaryOn="@string/revanced_shorts_custom_actions_external_downloader_summary_on" android:summaryOff="@string/revanced_shorts_custom_actions_external_downloader_summary_off" />
|
||||
<SwitchPreference android:title="@string/revanced_shorts_custom_actions_open_video_title" android:key="revanced_shorts_custom_actions_open_video" android:summaryOn="@string/revanced_shorts_custom_actions_open_video_summary_on" android:summaryOff="@string/revanced_shorts_custom_actions_open_video_summary_off" />
|
||||
<SwitchPreference android:title="@string/revanced_shorts_custom_actions_repeat_state_title" android:key="revanced_shorts_custom_actions_repeat_state" android:summaryOn="@string/revanced_shorts_custom_actions_repeat_state_summary_on" android:summaryOff="@string/revanced_shorts_custom_actions_repeat_state_summary_off" />
|
||||
<app.revanced.extension.youtube.settings.preference.ExternalDownloaderVideoPreference android:title="@string/revanced_external_downloader_package_name_video_title" android:key="revanced_external_downloader_package_name_video" android:summary="@string/revanced_external_downloader_package_name_video_summary" />
|
||||
<Preference android:title="@string/revanced_shorts_custom_actions_about_title" android:selectable="false" android:summary="@string/revanced_shorts_custom_actions_about_about_summary" />SETTINGS: SHORTS_CUSTOM_ACTIONS_SHARED -->
|
||||
|
||||
<PreferenceCategory android:title="@string/revanced_preference_category_experimental_flag" android:layout="@layout/revanced_settings_preferences_category"/>SETTINGS: SHORTS_CUSTOM_ACTIONS -->
|
||||
<!-- SETTINGS: SHORTS_COMPONENTS
|
||||
<PreferenceCategory android:title="@string/revanced_preference_category_experimental_flag" android:layout="@layout/revanced_settings_preferences_category"/>SETTINGS: SHORTS_COMPONENTS -->
|
||||
|
||||
<!-- SETTINGS: SHORTS_TIME_STAMP
|
||||
<SwitchPreference android:title="@string/revanced_enable_shorts_time_stamp_title" android:key="revanced_enable_shorts_time_stamp" android:summaryOn="@string/revanced_enable_shorts_time_stamp_summary_on" android:summaryOff="@string/revanced_enable_shorts_time_stamp_summary_off" />
|
||||
|
Reference in New Issue
Block a user