Skip to content

Commit

Permalink
feat(YouTube): Merge multiple layout patches into `Hide Layout Compon…
Browse files Browse the repository at this point in the history
…ents` (ReVanced#3799)
  • Loading branch information
LisoUseInAIKyrios authored Oct 22, 2024
1 parent 7756842 commit bbcb57a
Show file tree
Hide file tree
Showing 18 changed files with 283 additions and 493 deletions.
Original file line number Diff line number Diff line change
@@ -1,56 +1,13 @@
package app.revanced.patches.youtube.layout.hide.albumcards

import app.revanced.util.exception
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.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.youtube.layout.hide.albumcards.fingerprints.AlbumCardsFingerprint
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import app.revanced.patches.youtube.layout.hide.general.HideLayoutComponentsPatch

@Patch(
name = "Hide album cards",
description = "Adds an option to hide album cards below artist descriptions.",
dependencies = [
IntegrationsPatch::class,
AlbumCardsResourcePatch::class
],
compatiblePackages = [
CompatiblePackage(
"com.google.android.youtube",
[
"18.38.44",
"18.49.37",
"19.16.39",
"19.25.37",
"19.34.42",
]
)
]
)
@Deprecated("This patch has been merged to HideLayoutComponentsPatch.")
@Suppress("unused")
object AlbumCardsPatch : BytecodePatch(
setOf(AlbumCardsFingerprint)
dependencies = setOf(HideLayoutComponentsPatch::class),
) {
override fun execute(context: BytecodeContext) {
AlbumCardsFingerprint.result?.let {
it.mutableMethod.apply {
val checkCastAnchorIndex = it.scanResult.patternScanResult!!.endIndex
val insertIndex = checkCastAnchorIndex + 1

val albumCardViewRegister = getInstruction<OneRegisterInstruction>(checkCastAnchorIndex).registerA

addInstruction(
insertIndex,
"invoke-static {v$albumCardViewRegister}, " +
"Lapp/revanced/integrations/youtube/patches/HideAlbumCardsPatch;" +
"->" +
"hideAlbumCard(Landroid/view/View;)V"
)
}
} ?: throw AlbumCardsFingerprint.exception
}
}
override fun execute(context: BytecodeContext) { }
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,12 @@ package app.revanced.patches.youtube.layout.hide.comments

import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.all.misc.resources.AddResourcesPatch
import app.revanced.patches.shared.misc.settings.preference.PreferenceScreen
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
import app.revanced.patches.youtube.misc.litho.filter.LithoFilterPatch
import app.revanced.patches.youtube.misc.settings.SettingsPatch
import app.revanced.patches.youtube.layout.hide.general.HideLayoutComponentsPatch

@Patch(
name = "Comments",
description = "Adds options to hide components related to comments.",
dependencies = [
SettingsPatch::class,
LithoFilterPatch::class,
AddResourcesPatch::class
],
compatiblePackages = [
CompatiblePackage(
"com.google.android.youtube",
[
"18.38.44",
"18.49.37",
"19.16.39",
"19.25.37",
"19.34.42",
]
)
]
)
@Deprecated("This patch has been merged to HideLayoutComponentsPatch.")
@Suppress("unused")
object CommentsPatch : ResourcePatch() {
private const val FILTER_CLASS_DESCRIPTOR =
"Lapp/revanced/integrations/youtube/patches/components/CommentsFilter;"

override fun execute(context: ResourceContext) {
AddResourcesPatch(this::class)

SettingsPatch.PreferenceScreen.PLAYER.addPreferences(
PreferenceScreen(
"revanced_comments_screen",
preferences = setOf(
SwitchPreference("revanced_hide_comments_by_members_header"),
SwitchPreference("revanced_hide_comments_section"),
SwitchPreference("revanced_hide_comments_create_a_short_button"),
SwitchPreference("revanced_hide_comments_preview_comment"),
SwitchPreference("revanced_hide_comments_thanks_button"),
SwitchPreference("revanced_hide_comments_timestamp_and_emoji_buttons")
),
sorting = PreferenceScreen.Sorting.UNSORTED
)
)

LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR)
}
}
object CommentsPatch : ResourcePatch(
dependencies = setOf(HideLayoutComponentsPatch::class),
) {
override fun execute(context: ResourceContext) { }
}
Original file line number Diff line number Diff line change
@@ -1,51 +1,13 @@
package app.revanced.patches.youtube.layout.hide.crowdfundingbox

import app.revanced.util.exception
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.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.youtube.layout.hide.crowdfundingbox.fingerprints.CrowdfundingBoxFingerprint
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import app.revanced.patches.youtube.layout.hide.general.HideLayoutComponentsPatch

@Patch(
name = "Hide crowdfunding box",
description = "Adds an option to hide the crowdfunding box between the player and video description.",
dependencies = [
IntegrationsPatch::class,
CrowdfundingBoxResourcePatch::class
],
compatiblePackages = [
CompatiblePackage(
"com.google.android.youtube",
[
"18.38.44",
"18.49.37",
"19.16.39",
"19.25.37",
"19.34.42",
]
)
]
)
@Deprecated("This patch has been merged to HideLayoutComponentsPatch.")
@Suppress("unused")
object CrowdfundingBoxPatch : BytecodePatch(
setOf(CrowdfundingBoxFingerprint)
dependencies = setOf(HideLayoutComponentsPatch::class),
) {
private const val INTEGRATIONS_METHOD_DESCRIPTOR =
"Lapp/revanced/integrations/youtube/patches/HideCrowdfundingBoxPatch;->hideCrowdfundingBox(Landroid/view/View;)V"

override fun execute(context: BytecodeContext) {
CrowdfundingBoxFingerprint.result?.let {
it.mutableMethod.apply {
val insertIndex = it.scanResult.patternScanResult!!.endIndex
val objectRegister = getInstruction<TwoRegisterInstruction>(insertIndex).registerA

addInstruction(insertIndex, "invoke-static {v$objectRegister}, $INTEGRATIONS_METHOD_DESCRIPTOR")
}
} ?: throw CrowdfundingBoxFingerprint.exception
}
}
override fun execute(context: BytecodeContext) { }
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,90 +1,12 @@
package app.revanced.patches.youtube.layout.hide.filterbar

import app.revanced.util.exception
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.youtube.layout.hide.filterbar.fingerprints.FilterBarHeightFingerprint
import app.revanced.patches.youtube.layout.hide.filterbar.fingerprints.RelatedChipCloudFingerprint
import app.revanced.patches.youtube.layout.hide.filterbar.fingerprints.SearchResultsChipBarFingerprint
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import app.revanced.patches.youtube.layout.hide.general.HideLayoutComponentsPatch

@Patch(
name = "Hide filter bar",
description = "Adds options to hide the category bar at the top of video feeds.",
dependencies = [HideFilterBarResourcePatch::class],
compatiblePackages = [
CompatiblePackage(
"com.google.android.youtube",
[
"18.38.44",
"18.49.37",
"19.16.39",
"19.25.37",
"19.34.42",
]
)
]
)
@Suppress("unused")
@Deprecated("This patch class has been merged into HideLayoutComponentsPatch.")
object HideFilterBarPatch : BytecodePatch(
setOf(
RelatedChipCloudFingerprint,
SearchResultsChipBarFingerprint,
FilterBarHeightFingerprint
)
dependencies = setOf(HideLayoutComponentsPatch::class)
) {
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
"Lapp/revanced/integrations/youtube/patches/HideFilterBarPatch;"

override fun execute(context: BytecodeContext) {
FilterBarHeightFingerprint.patch<TwoRegisterInstruction> { register ->
"""
invoke-static { v$register }, $INTEGRATIONS_CLASS_DESCRIPTOR->hideInFeed(I)I
move-result v$register
"""
}

RelatedChipCloudFingerprint.patch<OneRegisterInstruction>(1) { register ->
"invoke-static { v$register }, " +
"$INTEGRATIONS_CLASS_DESCRIPTOR->hideInRelatedVideos(Landroid/view/View;)V"
}

SearchResultsChipBarFingerprint.patch<OneRegisterInstruction>(-1, -2) { register ->
"""
invoke-static { v$register }, $INTEGRATIONS_CLASS_DESCRIPTOR->hideInSearch(I)I
move-result v$register
"""
}
}

/**
* Patch a [MethodFingerprint] with a given [instructions].
*
* @param RegisterInstruction The type of instruction to get the register from.
* @param insertIndexOffset The offset to add to the end index of the [MethodFingerprint].
* @param hookRegisterOffset The offset to add to the register of the hook.
* @param instructions The instructions to add with the register as a parameter.
*/
private fun <RegisterInstruction : OneRegisterInstruction> MethodFingerprint.patch(
insertIndexOffset: Int = 0,
hookRegisterOffset: Int = 0,
instructions: (Int) -> String
) =
result?.let {
it.mutableMethod.apply {
val endIndex = it.scanResult.patternScanResult!!.endIndex

val insertIndex = endIndex + insertIndexOffset
val register =
getInstruction<RegisterInstruction>(endIndex + hookRegisterOffset).registerA

addInstructions(insertIndex, instructions(register))
}
} ?: throw exception
}
override fun execute(context: BytecodeContext) {}
}

This file was deleted.

Loading

0 comments on commit bbcb57a

Please sign in to comment.