Skip to content

Commit bbcb57a

Browse files
feat(YouTube): Merge multiple layout patches into Hide Layout Components (ReVanced#3799)
1 parent 7756842 commit bbcb57a

18 files changed

+283
-493
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,13 @@
11
package app.revanced.patches.youtube.layout.hide.albumcards
22

3-
import app.revanced.util.exception
43
import app.revanced.patcher.data.BytecodeContext
5-
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
6-
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
74
import app.revanced.patcher.patch.BytecodePatch
8-
import app.revanced.patcher.patch.annotation.CompatiblePackage
9-
import app.revanced.patcher.patch.annotation.Patch
10-
import app.revanced.patches.youtube.layout.hide.albumcards.fingerprints.AlbumCardsFingerprint
11-
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
12-
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
5+
import app.revanced.patches.youtube.layout.hide.general.HideLayoutComponentsPatch
136

14-
@Patch(
15-
name = "Hide album cards",
16-
description = "Adds an option to hide album cards below artist descriptions.",
17-
dependencies = [
18-
IntegrationsPatch::class,
19-
AlbumCardsResourcePatch::class
20-
],
21-
compatiblePackages = [
22-
CompatiblePackage(
23-
"com.google.android.youtube",
24-
[
25-
"18.38.44",
26-
"18.49.37",
27-
"19.16.39",
28-
"19.25.37",
29-
"19.34.42",
30-
]
31-
)
32-
]
33-
)
7+
@Deprecated("This patch has been merged to HideLayoutComponentsPatch.")
348
@Suppress("unused")
359
object AlbumCardsPatch : BytecodePatch(
36-
setOf(AlbumCardsFingerprint)
10+
dependencies = setOf(HideLayoutComponentsPatch::class),
3711
) {
38-
override fun execute(context: BytecodeContext) {
39-
AlbumCardsFingerprint.result?.let {
40-
it.mutableMethod.apply {
41-
val checkCastAnchorIndex = it.scanResult.patternScanResult!!.endIndex
42-
val insertIndex = checkCastAnchorIndex + 1
43-
44-
val albumCardViewRegister = getInstruction<OneRegisterInstruction>(checkCastAnchorIndex).registerA
45-
46-
addInstruction(
47-
insertIndex,
48-
"invoke-static {v$albumCardViewRegister}, " +
49-
"Lapp/revanced/integrations/youtube/patches/HideAlbumCardsPatch;" +
50-
"->" +
51-
"hideAlbumCard(Landroid/view/View;)V"
52-
)
53-
}
54-
} ?: throw AlbumCardsFingerprint.exception
55-
}
56-
}
12+
override fun execute(context: BytecodeContext) { }
13+
}

src/main/kotlin/app/revanced/patches/youtube/layout/hide/albumcards/AlbumCardsResourcePatch.kt

-30
This file was deleted.

src/main/kotlin/app/revanced/patches/youtube/layout/hide/comments/CommentsPatch.kt

+7-53
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,12 @@ package app.revanced.patches.youtube.layout.hide.comments
22

33
import app.revanced.patcher.data.ResourceContext
44
import app.revanced.patcher.patch.ResourcePatch
5-
import app.revanced.patcher.patch.annotation.CompatiblePackage
6-
import app.revanced.patcher.patch.annotation.Patch
7-
import app.revanced.patches.all.misc.resources.AddResourcesPatch
8-
import app.revanced.patches.shared.misc.settings.preference.PreferenceScreen
9-
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
10-
import app.revanced.patches.youtube.misc.litho.filter.LithoFilterPatch
11-
import app.revanced.patches.youtube.misc.settings.SettingsPatch
5+
import app.revanced.patches.youtube.layout.hide.general.HideLayoutComponentsPatch
126

13-
@Patch(
14-
name = "Comments",
15-
description = "Adds options to hide components related to comments.",
16-
dependencies = [
17-
SettingsPatch::class,
18-
LithoFilterPatch::class,
19-
AddResourcesPatch::class
20-
],
21-
compatiblePackages = [
22-
CompatiblePackage(
23-
"com.google.android.youtube",
24-
[
25-
"18.38.44",
26-
"18.49.37",
27-
"19.16.39",
28-
"19.25.37",
29-
"19.34.42",
30-
]
31-
)
32-
]
33-
)
7+
@Deprecated("This patch has been merged to HideLayoutComponentsPatch.")
348
@Suppress("unused")
35-
object CommentsPatch : ResourcePatch() {
36-
private const val FILTER_CLASS_DESCRIPTOR =
37-
"Lapp/revanced/integrations/youtube/patches/components/CommentsFilter;"
38-
39-
override fun execute(context: ResourceContext) {
40-
AddResourcesPatch(this::class)
41-
42-
SettingsPatch.PreferenceScreen.PLAYER.addPreferences(
43-
PreferenceScreen(
44-
"revanced_comments_screen",
45-
preferences = setOf(
46-
SwitchPreference("revanced_hide_comments_by_members_header"),
47-
SwitchPreference("revanced_hide_comments_section"),
48-
SwitchPreference("revanced_hide_comments_create_a_short_button"),
49-
SwitchPreference("revanced_hide_comments_preview_comment"),
50-
SwitchPreference("revanced_hide_comments_thanks_button"),
51-
SwitchPreference("revanced_hide_comments_timestamp_and_emoji_buttons")
52-
),
53-
sorting = PreferenceScreen.Sorting.UNSORTED
54-
)
55-
)
56-
57-
LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR)
58-
}
59-
}
9+
object CommentsPatch : ResourcePatch(
10+
dependencies = setOf(HideLayoutComponentsPatch::class),
11+
) {
12+
override fun execute(context: ResourceContext) { }
13+
}
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,13 @@
11
package app.revanced.patches.youtube.layout.hide.crowdfundingbox
22

3-
import app.revanced.util.exception
43
import app.revanced.patcher.data.BytecodeContext
5-
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
6-
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
74
import app.revanced.patcher.patch.BytecodePatch
8-
import app.revanced.patcher.patch.annotation.CompatiblePackage
9-
import app.revanced.patcher.patch.annotation.Patch
10-
import app.revanced.patches.youtube.layout.hide.crowdfundingbox.fingerprints.CrowdfundingBoxFingerprint
11-
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
12-
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
5+
import app.revanced.patches.youtube.layout.hide.general.HideLayoutComponentsPatch
136

14-
@Patch(
15-
name = "Hide crowdfunding box",
16-
description = "Adds an option to hide the crowdfunding box between the player and video description.",
17-
dependencies = [
18-
IntegrationsPatch::class,
19-
CrowdfundingBoxResourcePatch::class
20-
],
21-
compatiblePackages = [
22-
CompatiblePackage(
23-
"com.google.android.youtube",
24-
[
25-
"18.38.44",
26-
"18.49.37",
27-
"19.16.39",
28-
"19.25.37",
29-
"19.34.42",
30-
]
31-
)
32-
]
33-
)
7+
@Deprecated("This patch has been merged to HideLayoutComponentsPatch.")
348
@Suppress("unused")
359
object CrowdfundingBoxPatch : BytecodePatch(
36-
setOf(CrowdfundingBoxFingerprint)
10+
dependencies = setOf(HideLayoutComponentsPatch::class),
3711
) {
38-
private const val INTEGRATIONS_METHOD_DESCRIPTOR =
39-
"Lapp/revanced/integrations/youtube/patches/HideCrowdfundingBoxPatch;->hideCrowdfundingBox(Landroid/view/View;)V"
40-
41-
override fun execute(context: BytecodeContext) {
42-
CrowdfundingBoxFingerprint.result?.let {
43-
it.mutableMethod.apply {
44-
val insertIndex = it.scanResult.patternScanResult!!.endIndex
45-
val objectRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA
46-
47-
addInstruction(insertIndex, "invoke-static {v$objectRegister}, $INTEGRATIONS_METHOD_DESCRIPTOR")
48-
}
49-
} ?: throw CrowdfundingBoxFingerprint.exception
50-
}
51-
}
12+
override fun execute(context: BytecodeContext) { }
13+
}

src/main/kotlin/app/revanced/patches/youtube/layout/hide/crowdfundingbox/CrowdfundingBoxResourcePatch.kt

-33
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,12 @@
11
package app.revanced.patches.youtube.layout.hide.filterbar
22

3-
import app.revanced.util.exception
43
import app.revanced.patcher.data.BytecodeContext
5-
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
6-
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
7-
import app.revanced.patcher.fingerprint.MethodFingerprint
84
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.patches.youtube.layout.hide.filterbar.fingerprints.FilterBarHeightFingerprint
12-
import app.revanced.patches.youtube.layout.hide.filterbar.fingerprints.RelatedChipCloudFingerprint
13-
import app.revanced.patches.youtube.layout.hide.filterbar.fingerprints.SearchResultsChipBarFingerprint
14-
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
15-
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
5+
import app.revanced.patches.youtube.layout.hide.general.HideLayoutComponentsPatch
166

17-
@Patch(
18-
name = "Hide filter bar",
19-
description = "Adds options to hide the category bar at the top of video feeds.",
20-
dependencies = [HideFilterBarResourcePatch::class],
21-
compatiblePackages = [
22-
CompatiblePackage(
23-
"com.google.android.youtube",
24-
[
25-
"18.38.44",
26-
"18.49.37",
27-
"19.16.39",
28-
"19.25.37",
29-
"19.34.42",
30-
]
31-
)
32-
]
33-
)
34-
@Suppress("unused")
7+
@Deprecated("This patch class has been merged into HideLayoutComponentsPatch.")
358
object HideFilterBarPatch : BytecodePatch(
36-
setOf(
37-
RelatedChipCloudFingerprint,
38-
SearchResultsChipBarFingerprint,
39-
FilterBarHeightFingerprint
40-
)
9+
dependencies = setOf(HideLayoutComponentsPatch::class)
4110
) {
42-
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
43-
"Lapp/revanced/integrations/youtube/patches/HideFilterBarPatch;"
44-
45-
override fun execute(context: BytecodeContext) {
46-
FilterBarHeightFingerprint.patch<TwoRegisterInstruction> { register ->
47-
"""
48-
invoke-static { v$register }, $INTEGRATIONS_CLASS_DESCRIPTOR->hideInFeed(I)I
49-
move-result v$register
50-
"""
51-
}
52-
53-
RelatedChipCloudFingerprint.patch<OneRegisterInstruction>(1) { register ->
54-
"invoke-static { v$register }, " +
55-
"$INTEGRATIONS_CLASS_DESCRIPTOR->hideInRelatedVideos(Landroid/view/View;)V"
56-
}
57-
58-
SearchResultsChipBarFingerprint.patch<OneRegisterInstruction>(-1, -2) { register ->
59-
"""
60-
invoke-static { v$register }, $INTEGRATIONS_CLASS_DESCRIPTOR->hideInSearch(I)I
61-
move-result v$register
62-
"""
63-
}
64-
}
65-
66-
/**
67-
* Patch a [MethodFingerprint] with a given [instructions].
68-
*
69-
* @param RegisterInstruction The type of instruction to get the register from.
70-
* @param insertIndexOffset The offset to add to the end index of the [MethodFingerprint].
71-
* @param hookRegisterOffset The offset to add to the register of the hook.
72-
* @param instructions The instructions to add with the register as a parameter.
73-
*/
74-
private fun <RegisterInstruction : OneRegisterInstruction> MethodFingerprint.patch(
75-
insertIndexOffset: Int = 0,
76-
hookRegisterOffset: Int = 0,
77-
instructions: (Int) -> String
78-
) =
79-
result?.let {
80-
it.mutableMethod.apply {
81-
val endIndex = it.scanResult.patternScanResult!!.endIndex
82-
83-
val insertIndex = endIndex + insertIndexOffset
84-
val register =
85-
getInstruction<RegisterInstruction>(endIndex + hookRegisterOffset).registerA
86-
87-
addInstructions(insertIndex, instructions(register))
88-
}
89-
} ?: throw exception
90-
}
11+
override fun execute(context: BytecodeContext) {}
12+
}

src/main/kotlin/app/revanced/patches/youtube/layout/hide/filterbar/HideFilterBarResourcePatch.kt

-36
This file was deleted.

0 commit comments

Comments
 (0)