forked from ReVanced/revanced-patches
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YouTube): Merge multiple layout patches into `Hide Layout Compon…
…ents` (ReVanced#3799)
- Loading branch information
1 parent
7756842
commit bbcb57a
Showing
18 changed files
with
283 additions
and
493 deletions.
There are no files selected for viewing
53 changes: 5 additions & 48 deletions
53
src/main/kotlin/app/revanced/patches/youtube/layout/hide/albumcards/AlbumCardsPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { } | ||
} |
30 changes: 0 additions & 30 deletions
30
...ain/kotlin/app/revanced/patches/youtube/layout/hide/albumcards/AlbumCardsResourcePatch.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 5 additions & 43 deletions
48
...n/kotlin/app/revanced/patches/youtube/layout/hide/crowdfundingbox/CrowdfundingBoxPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { } | ||
} |
33 changes: 0 additions & 33 deletions
33
.../app/revanced/patches/youtube/layout/hide/crowdfundingbox/CrowdfundingBoxResourcePatch.kt
This file was deleted.
Oops, something went wrong.
88 changes: 5 additions & 83 deletions
88
src/main/kotlin/app/revanced/patches/youtube/layout/hide/filterbar/HideFilterBarPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) {} | ||
} |
36 changes: 0 additions & 36 deletions
36
...n/kotlin/app/revanced/patches/youtube/layout/hide/filterbar/HideFilterBarResourcePatch.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.