add hide-account-menu patch

This commit is contained in:
inotia00 2023-03-23 23:10:03 +09:00
parent f324e59ddd
commit f8c8b01b26
7 changed files with 129 additions and 0 deletions

View File

@ -0,0 +1,15 @@
package app.revanced.patches.youtube.layout.general.accountmenu.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode
object AccountMenuFingerprint : MethodFingerprint(
returnType = "V",
opcodes = listOf(
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_STATIC,
Opcode.IGET,
Opcode.AND_INT_LIT16
)
)

View File

@ -0,0 +1,21 @@
package app.revanced.patches.youtube.layout.general.accountmenu.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
object AccountMenuParentFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.CONST,
Opcode.CONST_4,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT
),
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any {
it.opcode.ordinal == Opcode.CONST.ordinal &&
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.compactLinkLabelId
} == true
}
)

View File

@ -0,0 +1,80 @@
package app.revanced.patches.youtube.layout.general.accountmenu.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.instruction
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.layout.general.accountmenu.fingerprints.AccountMenuFingerprint
import app.revanced.patches.youtube.layout.general.accountmenu.fingerprints.AccountMenuParentFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.GENERAL_LAYOUT
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
@Patch
@Name("hide-account-menu")
@Description("Hide account menu elements.")
@DependsOn(
[
SettingsPatch::class,
SharedResourceIdPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class AccountMenuPatch : BytecodePatch(
listOf(
AccountMenuParentFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
AccountMenuParentFingerprint.result?.let { parentResult ->
AccountMenuFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let {
with (it.mutableMethod) {
val targetIndex = it.scanResult.patternScanResult!!.startIndex + 1
val register = (instruction(targetIndex) as OneRegisterInstruction).registerA
addInstruction(
targetIndex + 1,
"invoke-static {v$register}, $GENERAL_LAYOUT->hideAccountMenu(Landroid/text/Spanned;)V"
)
}
} ?: return AccountMenuFingerprint.toErrorResult()
with (parentResult.mutableMethod) {
val endIndex = parentResult.scanResult.patternScanResult!!.endIndex
val register = (instruction(endIndex) as OneRegisterInstruction).registerA
addInstruction(
endIndex + 1,
"sput-object v$register, $GENERAL_LAYOUT->compactLink:Landroid/view/View;"
)
}
} ?: return AccountMenuParentFingerprint.toErrorResult()
/*
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: GENERAL_LAYOUT_SETTINGS",
"SETTINGS: HIDE_ACCOUNT_MENU"
)
)
SettingsPatch.updatePatchStatus("hide-account-menu")
return PatchResultSuccess()
}
}

View File

@ -22,6 +22,7 @@ class SharedResourceIdPatch : ResourcePatch {
var backgroundCategoryLabelId: Long = -1
var bottomUiContainerResourceId: Long = -1
var chapterRepeatOnResourceId: Long = -1
var compactLinkLabelId: Long = -1
var controlsLayoutStubResourceId: Long = -1
var donationCompanionResourceId: Long = -1
var emptyColorLabelId: Long = -1
@ -52,6 +53,7 @@ class SharedResourceIdPatch : ResourcePatch {
backgroundCategoryLabelId = findSharedResourceId("string", "pref_background_and_offline_category")
bottomUiContainerResourceId = findSharedResourceId("id", "bottom_ui_container_stub")
chapterRepeatOnResourceId = findSharedResourceId("string", "chapter_repeat_on")
compactLinkLabelId = findSharedResourceId("layout", "compact_link")
controlsLayoutStubResourceId = findSharedResourceId("id", "controls_layout_stub")
donationCompanionResourceId = findSharedResourceId("layout", "donation_companion")
emptyColorLabelId = findSharedResourceId("color", "inline_time_bar_colorized_bar_empty_color_dark")

View File

@ -262,6 +262,9 @@ Is it ready to submit?"</string>
<string name="revanced_fullscreen_layout">Fullscreen layout</string>
<string name="revanced_general_layout">General layout</string>
<string name="revanced_haptic_feedback_title">Haptic feedback</string>
<string name="revanced_hide_account_menu_summary_off">Account menus are shown</string>
<string name="revanced_hide_account_menu_summary_on">Account menus are hidden</string>
<string name="revanced_hide_account_menu_title">Hide account menu</string>
<string name="revanced_hide_action_buttons_summary_off">Action buttons are shown</string>
<string name="revanced_hide_action_buttons_summary_on">Action buttons are hidden</string>
<string name="revanced_hide_action_buttons_title">Hide action buttons</string>

View File

@ -3,6 +3,9 @@
<!-- Translation Exception Language Resources -->
<string name="about">@string/pref_about_category</string>
<string name="revanced_account_menu_custom_filter_summary">@string/revanced_adremover_custom_filter_summary</string>
<string name="revanced_account_menu_custom_filter_title">@string/revanced_adremover_custom_filter_title</string>
<string name="revanced_backup_title">@string/settings_ie</string>
<string name="revanced_extended_settings_title">ReVanced Extended</string>
<string name="revanced_whitelisting_speed_button">@string/camera_speed_button_label</string>

View File

@ -138,6 +138,10 @@
<SwitchPreference android:title="@string/revanced_adremover_web_search_panel_title" android:key="revanced_adremover_web_search_panel" android:defaultValue="true" android:summaryOn="@string/revanced_adremover_web_search_panel_summary_on" android:summaryOff="@string/revanced_adremover_web_search_panel_summary_off" />
<SwitchPreference android:title="@string/revanced_adremover_timed_reactions_title" android:key="revanced_adremover_timed_reactions" android:defaultValue="true" android:summaryOn="@string/revanced_adremover_timed_reactions_summary_on" android:summaryOff="@string/revanced_adremover_timed_reactions_summary_off" />SETTINGS: HIDE_GENERAL_LAYOUT_ADS -->
<!-- SETTINGS: HIDE_ACCOUNT_MENU
<SwitchPreference android:title="@string/revanced_hide_account_menu_title" android:key="revanced_hide_account_menu" android:defaultValue="false" android:summaryOn="@string/revanced_hide_account_menu_summary_on" android:summaryOff="@string/revanced_hide_account_menu_summary_off" />
<EditTextPreference android:title="@string/revanced_account_menu_custom_filter_title" android:key="revanced_account_menu_custom_filter" android:summary="@string/revanced_account_menu_custom_filter_summary" android:defaultValue="YouTube Music,YouTube Kids" android:inputType="text" android:dependency="revanced_hide_account_menu" />SETTINGS: HIDE_ACCOUNT_MENU -->
<!-- SETTINGS: HEADER_SWITCH
<SwitchPreference android:title="@string/revanced_override_premium_header_title" android:key="revanced_override_premium_header" android:defaultValue="false" android:summaryOn="@string/revanced_override_premium_header_summary_on" android:summaryOff="@string/revanced_override_premium_header_summary_off" />SETTINGS: HEADER_SWITCH -->
@ -420,6 +424,7 @@
<Preference android:title="hide-email-address" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-snackbar" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-floating-microphone" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-account-menu" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="header-switch" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title=" " android:selectable="false" android:summary="@string/revanced_player_layout" />