mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-28 12:50:19 +02:00
refactor(YouTube/Hide settings menu): switch to shared patch
This commit is contained in:
parent
84db62ac9d
commit
1d4adaff4c
@ -0,0 +1,39 @@
|
||||
package app.revanced.patches.shared.settingmenu
|
||||
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.annotation.Patch
|
||||
import app.revanced.patches.shared.integrations.Constants.PATCHES_PATH
|
||||
import app.revanced.patches.shared.settingmenu.fingerprints.SettingsMenuFingerprint
|
||||
import app.revanced.patches.shared.viewgroup.ViewGroupMarginLayoutParamsHookPatch
|
||||
import app.revanced.util.getTargetIndexWithFieldReferenceTypeOrThrow
|
||||
import app.revanced.util.resultOrThrow
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
|
||||
|
||||
@Patch(
|
||||
description = "Hide the settings menu for YouTube or YouTube Music.",
|
||||
dependencies = [ViewGroupMarginLayoutParamsHookPatch::class]
|
||||
)
|
||||
object SettingsMenuPatch : BytecodePatch(
|
||||
setOf(SettingsMenuFingerprint)
|
||||
) {
|
||||
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
|
||||
"$PATCHES_PATH/SettingsMenuPatch;"
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
|
||||
SettingsMenuFingerprint.resultOrThrow().mutableMethod.apply {
|
||||
val insertIndex =
|
||||
getTargetIndexWithFieldReferenceTypeOrThrow("Landroid/support/v7/widget/RecyclerView;")
|
||||
val insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA
|
||||
|
||||
addInstruction(
|
||||
insertIndex,
|
||||
"invoke-static {v$insertRegister}, " +
|
||||
"$INTEGRATIONS_CLASS_DESCRIPTOR->hideSettingsMenu(Landroid/support/v7/widget/RecyclerView;)V"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package app.revanced.patches.youtube.general.components.fingerprints
|
||||
package app.revanced.patches.shared.settingmenu.fingerprints
|
||||
|
||||
import app.revanced.util.fingerprint.LiteralValueFingerprint
|
||||
|
@ -0,0 +1,43 @@
|
||||
package app.revanced.patches.shared.viewgroup
|
||||
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.PatchException
|
||||
import app.revanced.patcher.patch.annotation.Patch
|
||||
import app.revanced.patches.shared.viewgroup.fingerprints.ViewGroupMarginFingerprint
|
||||
import app.revanced.patches.shared.viewgroup.fingerprints.ViewGroupMarginParentFingerprint
|
||||
import app.revanced.patches.shared.integrations.Constants.INTEGRATIONS_UTILS_CLASS_DESCRIPTOR
|
||||
import app.revanced.util.resultOrThrow
|
||||
|
||||
@Patch(
|
||||
description = "Hook YouTube or YouTube Music to use ViewGroup.MarginLayoutParams in the integration.",
|
||||
)
|
||||
object ViewGroupMarginLayoutParamsHookPatch : BytecodePatch(
|
||||
setOf(ViewGroupMarginParentFingerprint)
|
||||
) {
|
||||
override fun execute(context: BytecodeContext) {
|
||||
|
||||
val method =
|
||||
context.findClass(INTEGRATIONS_UTILS_CLASS_DESCRIPTOR)?.mutableClass?.methods?.first { method ->
|
||||
method.name == "hideViewGroupByMarginLayoutParams"
|
||||
} ?: throw PatchException("Could not find hideViewGroupByMarginLayoutParams method")
|
||||
|
||||
ViewGroupMarginFingerprint.resolve(
|
||||
context,
|
||||
ViewGroupMarginParentFingerprint.resultOrThrow().classDef
|
||||
)
|
||||
ViewGroupMarginFingerprint.resultOrThrow().let {
|
||||
it.mutableMethod.apply {
|
||||
val setViewGroupMarginCall = "$definingClass->$name(Landroid/view/View;II)V"
|
||||
|
||||
method.addInstructions(
|
||||
0, """
|
||||
const/4 v0, 0x0
|
||||
invoke-static {p0, v0, v0}, $setViewGroupMarginCall
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package app.revanced.patches.shared.viewgroup.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
|
||||
internal object ViewGroupMarginFingerprint : MethodFingerprint(
|
||||
returnType = "V",
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
|
||||
parameters = listOf("Landroid/view/View;", "I", "I"),
|
||||
)
|
@ -0,0 +1,12 @@
|
||||
package app.revanced.patches.shared.viewgroup.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
|
||||
internal object ViewGroupMarginParentFingerprint : MethodFingerprint(
|
||||
returnType = "Landroid/view/ViewGroup${'$'}LayoutParams;",
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
|
||||
parameters = listOf("Ljava/lang/Class;", "Landroid/view/ViewGroup${'$'}LayoutParams;"),
|
||||
strings = listOf("SafeLayoutParams"),
|
||||
)
|
@ -8,27 +8,26 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||
import app.revanced.patcher.patch.PatchException
|
||||
import app.revanced.patcher.util.smali.ExternalLabel
|
||||
import app.revanced.patches.shared.litho.LithoFilterPatch
|
||||
import app.revanced.patches.shared.settingmenu.SettingsMenuPatch
|
||||
import app.revanced.patches.shared.viewgroup.ViewGroupMarginLayoutParamsHookPatch
|
||||
import app.revanced.patches.youtube.general.components.fingerprints.AccountListFingerprint
|
||||
import app.revanced.patches.youtube.general.components.fingerprints.AccountListParentFingerprint
|
||||
import app.revanced.patches.youtube.general.components.fingerprints.AccountMenuFingerprint
|
||||
import app.revanced.patches.youtube.general.components.fingerprints.AccountMenuParentFingerprint
|
||||
import app.revanced.patches.youtube.general.components.fingerprints.AccountSwitcherAccessibilityLabelFingerprint
|
||||
import app.revanced.patches.youtube.general.components.fingerprints.AppBlockingCheckResultToStringFingerprint
|
||||
import app.revanced.patches.youtube.general.components.fingerprints.BottomUiContainerFingerprint
|
||||
import app.revanced.patches.youtube.general.components.fingerprints.FloatingMicrophoneFingerprint
|
||||
import app.revanced.patches.youtube.general.components.fingerprints.PiPNotificationFingerprint
|
||||
import app.revanced.patches.youtube.general.components.fingerprints.SettingsMenuFingerprint
|
||||
import app.revanced.patches.youtube.general.components.fingerprints.TooltipContentFullscreenFingerprint
|
||||
import app.revanced.patches.youtube.general.components.fingerprints.TooltipContentViewFingerprint
|
||||
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
|
||||
import app.revanced.patches.youtube.utils.fingerprints.AccountMenuParentFingerprint
|
||||
import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH
|
||||
import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR
|
||||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
|
||||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.AccountSwitcherAccessibility
|
||||
import app.revanced.patches.youtube.utils.settings.SettingsPatch
|
||||
import app.revanced.patches.youtube.utils.viewgroup.ViewGroupMarginLayoutParamsHookPatch
|
||||
import app.revanced.util.getTargetIndexOrThrow
|
||||
import app.revanced.util.getTargetIndexWithFieldReferenceTypeOrThrow
|
||||
import app.revanced.util.getTargetIndexWithMethodReferenceName
|
||||
import app.revanced.util.getWideLiteralInstructionIndex
|
||||
import app.revanced.util.patch.BaseBytecodePatch
|
||||
@ -46,6 +45,7 @@ object LayoutComponentsPatch : BaseBytecodePatch(
|
||||
description = "Adds options to hide general layout components.",
|
||||
dependencies = setOf(
|
||||
LithoFilterPatch::class,
|
||||
SettingsMenuPatch::class,
|
||||
SettingsPatch::class,
|
||||
SharedResourceIdPatch::class,
|
||||
ViewGroupMarginLayoutParamsHookPatch::class
|
||||
@ -59,7 +59,6 @@ object LayoutComponentsPatch : BaseBytecodePatch(
|
||||
BottomUiContainerFingerprint,
|
||||
FloatingMicrophoneFingerprint,
|
||||
PiPNotificationFingerprint,
|
||||
SettingsMenuFingerprint,
|
||||
TooltipContentFullscreenFingerprint,
|
||||
TooltipContentViewFingerprint
|
||||
)
|
||||
@ -190,24 +189,6 @@ object LayoutComponentsPatch : BaseBytecodePatch(
|
||||
|
||||
// endregion
|
||||
|
||||
// region patch for hide settings menu
|
||||
|
||||
SettingsMenuFingerprint.resultOrThrow().let {
|
||||
it.mutableMethod.apply {
|
||||
val insertIndex =
|
||||
getTargetIndexWithFieldReferenceTypeOrThrow("Landroid/support/v7/widget/RecyclerView;")
|
||||
val insertRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA
|
||||
|
||||
addInstruction(
|
||||
insertIndex,
|
||||
"invoke-static {v$insertRegister}, " +
|
||||
"$GENERAL_CLASS_DESCRIPTOR->hideSettingsMenu(Landroid/support/v7/widget/RecyclerView;)V"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
// region patch for hide snack bar
|
||||
|
||||
BottomUiContainerFingerprint.resultOrThrow().let {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package app.revanced.patches.youtube.utils.fingerprints
|
||||
package app.revanced.patches.youtube.general.components.fingerprints
|
||||
|
||||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.CompactLink
|
||||
import app.revanced.util.fingerprint.LiteralValueFingerprint
|
@ -1,52 +0,0 @@
|
||||
package app.revanced.patches.youtube.utils.viewgroup
|
||||
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.PatchException
|
||||
import app.revanced.patcher.patch.annotation.Patch
|
||||
import app.revanced.patches.youtube.utils.fingerprints.AccountMenuParentFingerprint
|
||||
import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH
|
||||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
|
||||
import app.revanced.patches.youtube.utils.viewgroup.fingerprints.SetViewGroupMarginFingerprint
|
||||
import app.revanced.util.resultOrThrow
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
|
||||
|
||||
@Patch(
|
||||
description = "Hook YouTube to use ViewGroup.MarginLayoutParams in the integration.",
|
||||
dependencies = [SharedResourceIdPatch::class],
|
||||
)
|
||||
object ViewGroupMarginLayoutParamsHookPatch : BytecodePatch(
|
||||
setOf(AccountMenuParentFingerprint)
|
||||
) {
|
||||
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
|
||||
"$UTILS_PATH/ViewGroupMarginLayoutParamsPatch;"
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
|
||||
val method =
|
||||
context.findClass(INTEGRATIONS_CLASS_DESCRIPTOR)?.mutableClass?.methods?.first { method ->
|
||||
method.name == "hideViewGroupByMarginLayoutParams"
|
||||
} ?: throw PatchException("Could not find hideViewGroupByMarginLayoutParams method")
|
||||
|
||||
SetViewGroupMarginFingerprint.resolve(
|
||||
context,
|
||||
AccountMenuParentFingerprint.resultOrThrow().classDef
|
||||
)
|
||||
SetViewGroupMarginFingerprint.resultOrThrow().let {
|
||||
it.mutableMethod.apply {
|
||||
val setViewGroupMarginIndex = it.scanResult.patternScanResult!!.startIndex
|
||||
val setViewGroupMarginReference =
|
||||
getInstruction<ReferenceInstruction>(setViewGroupMarginIndex).reference
|
||||
|
||||
method.addInstructions(
|
||||
0, """
|
||||
const/4 v0, 0x0
|
||||
invoke-static {p0, v0, v0}, $setViewGroupMarginReference
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package app.revanced.patches.youtube.utils.viewgroup.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
|
||||
internal object SetViewGroupMarginFingerprint : MethodFingerprint(
|
||||
returnType = "V",
|
||||
accessFlags = AccessFlags.PRIVATE or AccessFlags.FINAL,
|
||||
parameters = listOf("Z"),
|
||||
opcodes = listOf(
|
||||
Opcode.INVOKE_STATIC,
|
||||
Opcode.IGET_OBJECT,
|
||||
Opcode.CONST_16,
|
||||
Opcode.INVOKE_VIRTUAL
|
||||
)
|
||||
)
|
@ -171,7 +171,7 @@
|
||||
<!-- SETTINGS: HIDE_LAYOUT_COMPONENTS
|
||||
<PreferenceScreen android:title="@string/revanced_preference_screen_settings_menu_title" android:key="revanced_preference_screen_settings_menu" android:summary="@string/revanced_preference_screen_settings_menu_summary">
|
||||
<SwitchPreference android:title="@string/revanced_hide_settings_menu_title" android:key="revanced_hide_settings_menu" android:summary="@string/revanced_hide_settings_menu_summary" />
|
||||
<app.revanced.integrations.shared.settings.preference.ResettableEditTextPreference android:title="@string/revanced_hide_settings_menu_filter_strings_title" android:key="revanced_hide_settings_menu_filter_strings" android:summary="@string/revanced_hide_settings_menu_filter_strings_summary" android:hint="@string/revanced_hide_settings_menu_filter_strings_hint" android:inputType="textMultiLine" />
|
||||
<app.revanced.integrations.shared.settings.preference.ResettableEditTextPreference android:title="@string/revanced_hide_settings_menu_filter_strings_title" android:key="revanced_hide_settings_menu_filter_strings" android:summary="@string/revanced_hide_settings_menu_filter_strings_summary" android:hint="@string/revanced_hide_settings_menu_filter_strings_hint" android:inputType="textMultiLine" android:dependency="revanced_hide_settings_menu" />
|
||||
</PreferenceScreen>SETTINGS: HIDE_LAYOUT_COMPONENTS -->
|
||||
|
||||
<!-- SETTINGS: TOOLBAR_COMPONENTS
|
||||
|
Loading…
x
Reference in New Issue
Block a user