Skip to content

Commit 4ba0300

Browse files
feat(YouTube): Merge multiple player overlay patches into Hide player overlay buttons (#3800)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
1 parent bbcb57a commit 4ba0300

13 files changed

+209
-259
lines changed

api/revanced-patches.api

+6
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,12 @@ public final class app/revanced/patches/youtube/layout/buttons/navigation/Naviga
16701670
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
16711671
}
16721672

1673+
public final class app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch : app/revanced/patcher/patch/BytecodePatch {
1674+
public static final field INSTANCE Lapp/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch;
1675+
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
1676+
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
1677+
}
1678+
16731679
public final class app/revanced/patches/youtube/layout/buttons/player/hide/HidePlayerButtonsPatch : app/revanced/patcher/patch/BytecodePatch {
16741680
public static final field INSTANCE Lapp/revanced/patches/youtube/layout/buttons/player/hide/HidePlayerButtonsPatch;
16751681
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V

src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/AutoCaptionsPatch.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import app.revanced.patcher.patch.annotation.Patch
99
import app.revanced.patches.all.misc.resources.AddResourcesPatch
1010
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
1111
import app.revanced.patches.youtube.layout.autocaptions.fingerprints.StartVideoInformerFingerprint
12-
import app.revanced.patches.youtube.layout.autocaptions.fingerprints.SubtitleButtonControllerFingerprint
1312
import app.revanced.patches.youtube.layout.autocaptions.fingerprints.SubtitleTrackFingerprint
1413
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
1514
import app.revanced.patches.youtube.misc.settings.SettingsPatch
15+
import app.revanced.patches.youtube.shared.fingerprints.SubtitleButtonControllerFingerprint
1616
import app.revanced.util.exception
1717

1818

Original file line numberDiff line numberDiff line change
@@ -1,84 +1,14 @@
11
package app.revanced.patches.youtube.layout.buttons.autoplay
22

33
import app.revanced.patcher.data.BytecodeContext
4-
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
5-
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
64
import app.revanced.patcher.patch.BytecodePatch
7-
import app.revanced.patcher.patch.annotation.CompatiblePackage
8-
import app.revanced.patcher.patch.annotation.Patch
9-
import app.revanced.patcher.util.smali.ExternalLabel
10-
import app.revanced.patches.all.misc.resources.AddResourcesPatch
11-
import app.revanced.patches.shared.misc.mapping.ResourceMappingPatch
12-
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
13-
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
14-
import app.revanced.patches.youtube.misc.settings.SettingsPatch
15-
import app.revanced.patches.youtube.shared.fingerprints.LayoutConstructorFingerprint
16-
import app.revanced.util.getReference
17-
import app.revanced.util.indexOfFirstInstructionOrThrow
18-
import app.revanced.util.indexOfIdResourceOrThrow
19-
import app.revanced.util.resultOrThrow
20-
import com.android.tools.smali.dexlib2.Opcode
21-
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
22-
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
5+
import app.revanced.patches.youtube.layout.buttons.overlay.HidePlayerOverlayButtonsPatch
236

24-
@Patch(
25-
name = "Hide autoplay button",
26-
description = "Adds an option to hide the autoplay button in the video player.",
27-
dependencies = [
28-
IntegrationsPatch::class,
29-
SettingsPatch::class,
30-
ResourceMappingPatch::class,
31-
AddResourcesPatch::class,
32-
],
33-
compatiblePackages = [
34-
CompatiblePackage(
35-
"com.google.android.youtube",
36-
[
37-
"18.38.44",
38-
"18.49.37",
39-
"19.16.39",
40-
"19.25.37",
41-
"19.34.42",
42-
],
43-
),
44-
],
45-
)
467
@Suppress("unused")
8+
@Deprecated("This patch has been merged into HidePlayerOverlayButtonsPatch.")
479
object HideAutoplayButtonPatch : BytecodePatch(
48-
setOf(LayoutConstructorFingerprint),
10+
dependencies = setOf(HidePlayerOverlayButtonsPatch::class),
4911
) {
50-
51-
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
52-
"Lapp/revanced/integrations/youtube/patches/HideAutoplayButtonPatch;"
53-
5412
override fun execute(context: BytecodeContext) {
55-
AddResourcesPatch(this::class)
56-
57-
SettingsPatch.PreferenceScreen.PLAYER.addPreferences(
58-
SwitchPreference("revanced_hide_autoplay_button"),
59-
)
60-
61-
LayoutConstructorFingerprint.resultOrThrow().mutableMethod.apply {
62-
val constIndex = indexOfIdResourceOrThrow("autonav_toggle")
63-
val constRegister = getInstruction<OneRegisterInstruction>(constIndex).registerA
64-
65-
// Add a conditional branch around the code that inflates and adds the auto repeat button.
66-
val gotoIndex = indexOfFirstInstructionOrThrow(constIndex) {
67-
val parameterTypes = getReference<MethodReference>()?.parameterTypes
68-
opcode == Opcode.INVOKE_VIRTUAL &&
69-
parameterTypes?.size == 2 &&
70-
parameterTypes.first() == "Landroid/view/ViewStub;"
71-
} + 1
72-
73-
addInstructionsWithLabels(
74-
constIndex,
75-
"""
76-
invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->hideAutoPlayButton()Z
77-
move-result v$constRegister
78-
if-nez v$constRegister, :hidden
79-
""",
80-
ExternalLabel("hidden", getInstruction(gotoIndex)),
81-
)
82-
}
8313
}
84-
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,14 @@
11
package app.revanced.patches.youtube.layout.buttons.captions
22

33
import app.revanced.patcher.data.BytecodeContext
4-
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
54
import app.revanced.patcher.patch.BytecodePatch
6-
import app.revanced.patcher.patch.annotation.CompatiblePackage
7-
import app.revanced.patcher.patch.annotation.Patch
8-
import app.revanced.patches.all.misc.resources.AddResourcesPatch
9-
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
10-
import app.revanced.patches.youtube.layout.autocaptions.fingerprints.SubtitleButtonControllerFingerprint
11-
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
12-
import app.revanced.patches.youtube.misc.settings.SettingsPatch
13-
import com.android.tools.smali.dexlib2.Opcode
5+
import app.revanced.patches.youtube.layout.buttons.overlay.HidePlayerOverlayButtonsPatch
146

15-
@Patch(
16-
name = "Hide captions button",
17-
description = "Adds an option to hide the captions button in the video player.",
18-
dependencies = [
19-
IntegrationsPatch::class,
20-
SettingsPatch::class,
21-
AddResourcesPatch::class
22-
],
23-
compatiblePackages = [
24-
CompatiblePackage(
25-
"com.google.android.youtube",
26-
[
27-
"18.38.44",
28-
"18.49.37",
29-
"19.16.39",
30-
"19.25.37",
31-
"19.34.42",
32-
]
33-
)
34-
]
35-
)
367
@Suppress("unused")
8+
@Deprecated("This patch has been merged into HidePlayerOverlayButtonsPatch.")
379
object HideCaptionsButtonPatch : BytecodePatch(
38-
setOf(SubtitleButtonControllerFingerprint)
10+
dependencies = setOf(HidePlayerOverlayButtonsPatch::class),
3911
) {
4012
override fun execute(context: BytecodeContext) {
41-
AddResourcesPatch(this::class)
42-
43-
SettingsPatch.PreferenceScreen.PLAYER.addPreferences(
44-
SwitchPreference("revanced_hide_captions_button")
45-
)
46-
47-
val subtitleButtonControllerMethod = SubtitleButtonControllerFingerprint.result!!.mutableMethod
48-
49-
// Due to previously applied patches, scanResult index cannot be used in this context
50-
val insertIndex = subtitleButtonControllerMethod.implementation!!.instructions.indexOfFirst {
51-
it.opcode == Opcode.IGET_BOOLEAN
52-
} + 1
53-
54-
subtitleButtonControllerMethod.addInstruction(
55-
insertIndex,
56-
"""
57-
invoke-static {v0}, Lapp/revanced/integrations/youtube/patches/HideCaptionsButtonPatch;->hideCaptionsButton(Landroid/widget/ImageView;)V
58-
"""
59-
)
6013
}
6114
}
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,14 @@
11
package app.revanced.patches.youtube.layout.buttons.cast
22

33
import app.revanced.patcher.data.BytecodeContext
4-
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
54
import app.revanced.patcher.patch.BytecodePatch
6-
import app.revanced.patcher.patch.PatchException
7-
import app.revanced.patcher.patch.annotation.CompatiblePackage
8-
import app.revanced.patcher.patch.annotation.Patch
9-
import app.revanced.patches.all.misc.resources.AddResourcesPatch
10-
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
11-
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
12-
import app.revanced.patches.youtube.misc.settings.SettingsPatch
5+
import app.revanced.patches.youtube.layout.buttons.overlay.HidePlayerOverlayButtonsPatch
136

14-
@Patch(
15-
name = "Hide cast button",
16-
description = "Adds an option to hide the cast button in the video player.",
17-
dependencies = [
18-
IntegrationsPatch::class,
19-
SettingsPatch::class,
20-
AddResourcesPatch::class,
21-
],
22-
compatiblePackages = [
23-
CompatiblePackage("com.google.android.youtube"),
24-
],
25-
)
26-
object HideCastButtonPatch : BytecodePatch(emptySet()) {
7+
@Suppress("unused")
8+
@Deprecated("This patch has been merged into HidePlayerOverlayButtonsPatch.")
9+
object HideCastButtonPatch : BytecodePatch(
10+
dependencies = setOf(HidePlayerOverlayButtonsPatch::class),
11+
) {
2712
override fun execute(context: BytecodeContext) {
28-
AddResourcesPatch(this::class)
29-
30-
SettingsPatch.PreferenceScreen.PLAYER.addPreferences(
31-
SwitchPreference("revanced_hide_cast_button")
32-
)
33-
34-
val buttonClass = context.findClass("MediaRouteButton")
35-
?: throw PatchException("MediaRouteButton class not found.")
36-
37-
buttonClass.mutableClass.methods.find { it.name == "setVisibility" }?.apply {
38-
addInstructions(
39-
0,
40-
"""
41-
invoke-static {p1}, Lapp/revanced/integrations/youtube/patches/HideCastButtonPatch;->getCastButtonOverrideV2(I)I
42-
move-result p1
43-
""",
44-
)
45-
} ?: throw PatchException("setVisibility method not found.")
4613
}
47-
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
package app.revanced.patches.youtube.layout.buttons.overlay
2+
3+
import app.revanced.patcher.data.BytecodeContext
4+
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
5+
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
6+
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
7+
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
8+
import app.revanced.patcher.patch.BytecodePatch
9+
import app.revanced.patcher.patch.annotation.CompatiblePackage
10+
import app.revanced.patcher.patch.annotation.Patch
11+
import app.revanced.patcher.util.smali.ExternalLabel
12+
import app.revanced.patches.all.misc.resources.AddResourcesPatch
13+
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
14+
import app.revanced.patches.youtube.layout.buttons.overlay.fingerprints.MediaRouteButtonFingerprint
15+
import app.revanced.patches.youtube.layout.buttons.overlay.fingerprints.PlayerControlsPreviousNextOverlayTouchFingerprint
16+
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
17+
import app.revanced.patches.youtube.misc.settings.SettingsPatch
18+
import app.revanced.patches.youtube.shared.fingerprints.LayoutConstructorFingerprint
19+
import app.revanced.patches.youtube.shared.fingerprints.SubtitleButtonControllerFingerprint
20+
import app.revanced.util.getReference
21+
import app.revanced.util.indexOfFirstInstructionOrThrow
22+
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
23+
import app.revanced.util.indexOfIdResourceOrThrow
24+
import app.revanced.util.resultOrThrow
25+
import com.android.tools.smali.dexlib2.Opcode
26+
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
27+
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
28+
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
29+
30+
@Patch(
31+
name = "Hide player overlay buttons",
32+
description = "Adds options to hide the player cast, autoplay, caption button and next/ previous buttons.",
33+
dependencies = [
34+
IntegrationsPatch::class,
35+
SettingsPatch::class,
36+
AddResourcesPatch::class,
37+
HidePlayerOverlayButtonsResourcePatch::class,
38+
],
39+
compatiblePackages = [
40+
CompatiblePackage(
41+
"com.google.android.youtube",
42+
[
43+
"18.38.44",
44+
"18.49.37",
45+
"19.16.39",
46+
"19.25.37",
47+
"19.34.42",
48+
]
49+
)
50+
]
51+
)
52+
@Suppress("unused")
53+
object HidePlayerOverlayButtonsPatch : BytecodePatch(
54+
setOf(
55+
PlayerControlsPreviousNextOverlayTouchFingerprint,
56+
MediaRouteButtonFingerprint,
57+
SubtitleButtonControllerFingerprint,
58+
LayoutConstructorFingerprint
59+
)
60+
) {
61+
62+
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
63+
"Lapp/revanced/integrations/youtube/patches/HidePlayerOverlayButtonsPatch;"
64+
65+
override fun execute(context: BytecodeContext) {
66+
AddResourcesPatch(this::class)
67+
68+
SettingsPatch.PreferenceScreen.PLAYER.addPreferences(
69+
SwitchPreference("revanced_hide_player_previous_next_buttons"),
70+
SwitchPreference("revanced_hide_cast_button"),
71+
SwitchPreference("revanced_hide_captions_button"),
72+
SwitchPreference("revanced_hide_autoplay_button"),
73+
)
74+
75+
// region hide player next/previous button
76+
77+
PlayerControlsPreviousNextOverlayTouchFingerprint.resultOrThrow().mutableMethod.apply {
78+
val resourceIndex = indexOfFirstWideLiteralInstructionValueOrThrow(
79+
HidePlayerOverlayButtonsResourcePatch.playerControlPreviousButtonTouchArea
80+
)
81+
82+
val insertIndex = indexOfFirstInstructionOrThrow(resourceIndex) {
83+
opcode == Opcode.INVOKE_STATIC
84+
&& getReference<MethodReference>()?.parameterTypes?.firstOrNull() == "Landroid/view/View;"
85+
}
86+
87+
val viewRegister = getInstruction<FiveRegisterInstruction>(insertIndex).registerC
88+
89+
addInstruction(
90+
insertIndex,
91+
"invoke-static { v$viewRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR" +
92+
"->hidePreviousNextButtons(Landroid/view/View;)V"
93+
)
94+
}
95+
96+
// endregion
97+
98+
// region hide cast button
99+
100+
MediaRouteButtonFingerprint.resultOrThrow().mutableMethod.addInstructions(
101+
0,
102+
"""
103+
invoke-static { p1 }, $INTEGRATIONS_CLASS_DESCRIPTOR->getCastButtonOverrideV2(I)I
104+
move-result p1
105+
"""
106+
)
107+
108+
// endregion
109+
110+
// region hide captions button
111+
112+
SubtitleButtonControllerFingerprint.resultOrThrow().mutableMethod.apply {
113+
// Due to previously applied patches, scanResult index cannot be used in this context
114+
val insertIndex = indexOfFirstInstructionOrThrow(Opcode.IGET_BOOLEAN) + 1
115+
116+
addInstruction(
117+
insertIndex,
118+
"invoke-static {v0}, $INTEGRATIONS_CLASS_DESCRIPTOR->hideCaptionsButton(Landroid/widget/ImageView;)V"
119+
)
120+
}
121+
122+
// endregion
123+
124+
// region hide auto play button
125+
126+
LayoutConstructorFingerprint.resultOrThrow().mutableMethod.apply {
127+
val constIndex = indexOfIdResourceOrThrow("autonav_toggle")
128+
val constRegister = getInstruction<OneRegisterInstruction>(constIndex).registerA
129+
130+
// Add a conditional branch around the code that inflates and adds the auto repeat button.
131+
val gotoIndex = indexOfFirstInstructionOrThrow(constIndex) {
132+
val parameterTypes = getReference<MethodReference>()?.parameterTypes
133+
opcode == Opcode.INVOKE_VIRTUAL &&
134+
parameterTypes?.size == 2 &&
135+
parameterTypes.first() == "Landroid/view/ViewStub;"
136+
} + 1
137+
138+
addInstructionsWithLabels(
139+
constIndex,
140+
"""
141+
invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->hideAutoPlayButton()Z
142+
move-result v$constRegister
143+
if-nez v$constRegister, :hidden
144+
""",
145+
ExternalLabel("hidden", getInstruction(gotoIndex)),
146+
)
147+
}
148+
149+
// endregion
150+
}
151+
}

0 commit comments

Comments
 (0)