generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(youtube): add
hide-filter-bar
patch
- Loading branch information
Showing
7 changed files
with
250 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...in/kotlin/app/revanced/patches/youtube/layout/hide/filterbar/annotations/HideFilterBar.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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package app.revanced.patches.youtube.layout.hide.filterbar.annotations | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
@Compatibility([Package("com.google.android.youtube", arrayOf("18.16.37"))]) | ||
@Target(AnnotationTarget.CLASS) | ||
internal annotation class HideFilterBar |
14 changes: 14 additions & 0 deletions
14
...revanced/patches/youtube/layout/hide/filterbar/fingerprints/FilterBarHeightFingerprint.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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package app.revanced.patches.youtube.layout.hide.filterbar.fingerprints | ||
|
||
import app.revanced.patches.youtube.layout.hide.filterbar.patch.HideFilterBarResourcePatch.Companion.filterBarHeightId | ||
import org.jf.dexlib2.Opcode | ||
|
||
object FilterBarHeightFingerprint : LiteralOpcodesFingerprint( | ||
opcodes = listOf( | ||
Opcode.CONST, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.MOVE_RESULT, | ||
Opcode.IPUT | ||
), | ||
filterBarHeightId | ||
) |
19 changes: 19 additions & 0 deletions
19
.../revanced/patches/youtube/layout/hide/filterbar/fingerprints/LiteralOpcodesFingerprint.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package app.revanced.patches.youtube.layout.hide.filterbar.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import org.jf.dexlib2.Opcode | ||
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction | ||
|
||
|
||
abstract class LiteralOpcodesFingerprint(opcodes: List<Opcode>, literal: Long) : MethodFingerprint( | ||
opcodes = opcodes, | ||
customFingerprint = { | ||
it.implementation?.instructions?.any { instruction -> | ||
if (instruction.opcode != Opcode.CONST) return@any false | ||
|
||
val wideLiteral = (instruction as WideLiteralInstruction).wideLiteral | ||
|
||
literal == wideLiteral | ||
} ?: false | ||
} | ||
) |
13 changes: 13 additions & 0 deletions
13
...evanced/patches/youtube/layout/hide/filterbar/fingerprints/RelatedChipCloudFingerprint.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package app.revanced.patches.youtube.layout.hide.filterbar.fingerprints | ||
|
||
import app.revanced.patches.youtube.layout.hide.filterbar.patch.HideFilterBarResourcePatch.Companion.relatedChipCloudMarginId | ||
import org.jf.dexlib2.Opcode | ||
|
||
object RelatedChipCloudFingerprint : LiteralOpcodesFingerprint( | ||
opcodes = listOf( | ||
Opcode.CONST, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.MOVE_RESULT_OBJECT | ||
), | ||
relatedChipCloudMarginId | ||
) |
15 changes: 15 additions & 0 deletions
15
...ced/patches/youtube/layout/hide/filterbar/fingerprints/SearchResultsChipBarFingerprint.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package app.revanced.patches.youtube.layout.hide.filterbar.fingerprints | ||
|
||
import app.revanced.patches.youtube.layout.hide.filterbar.patch.HideFilterBarResourcePatch.Companion.barContainerHeightId | ||
import org.jf.dexlib2.Opcode | ||
|
||
object SearchResultsChipBarFingerprint : LiteralOpcodesFingerprint( | ||
opcodes = listOf( | ||
Opcode.CONST, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.MOVE_RESULT, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.MOVE_RESULT_OBJECT | ||
), | ||
barContainerHeightId | ||
) |
87 changes: 87 additions & 0 deletions
87
...ain/kotlin/app/revanced/patches/youtube/layout/hide/filterbar/patch/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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package app.revanced.patches.youtube.layout.hide.filterbar.patch | ||
|
||
import app.revanced.extensions.toErrorResult | ||
import app.revanced.patcher.annotation.Description | ||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.addInstructions | ||
import app.revanced.patcher.extensions.instruction | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patcher.patch.annotations.DependsOn | ||
import app.revanced.patcher.patch.annotations.Patch | ||
import app.revanced.patches.youtube.layout.hide.filterbar.annotations.HideFilterBar | ||
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 org.jf.dexlib2.iface.instruction.OneRegisterInstruction | ||
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction | ||
|
||
@Patch | ||
@Name("hide-filter-bar") | ||
@Description("Hides the filter bar in video feeds.") | ||
@DependsOn([HideFilterBarResourcePatch::class]) | ||
@HideFilterBar | ||
@Version("0.0.1") | ||
class HideFilterBarPatch : BytecodePatch( | ||
listOf( | ||
RelatedChipCloudFingerprint, | ||
SearchResultsChipBarFingerprint, | ||
FilterBarHeightFingerprint | ||
) | ||
) { | ||
override fun execute(context: BytecodeContext): PatchResult { | ||
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 | ||
""" | ||
} | ||
|
||
return PatchResultSuccess() | ||
} | ||
|
||
private companion object { | ||
const val INTEGRATIONS_CLASS_DESCRIPTOR = | ||
"Lapp/revanced/integrations/patches/HideFilterBarPatch;" | ||
|
||
/** | ||
* 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 = instruction<RegisterInstruction>(endIndex + hookRegisterOffset).registerA | ||
|
||
addInstructions(insertIndex, instructions(register)) | ||
} | ||
} ?: throw toErrorResult() | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...in/app/revanced/patches/youtube/layout/hide/filterbar/patch/HideFilterBarResourcePatch.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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package app.revanced.patches.youtube.layout.hide.filterbar.patch | ||
|
||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.data.ResourceContext | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patcher.patch.ResourcePatch | ||
import app.revanced.patcher.patch.annotations.DependsOn | ||
import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch | ||
import app.revanced.patches.shared.settings.preference.impl.PreferenceScreen | ||
import app.revanced.patches.shared.settings.preference.impl.StringResource | ||
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference | ||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch | ||
|
||
@DependsOn([SettingsPatch::class, ResourceMappingPatch::class]) | ||
@Version("0.0.1") | ||
class HideFilterBarResourcePatch : ResourcePatch { | ||
override fun execute(context: ResourceContext): PatchResult { | ||
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( | ||
PreferenceScreen( | ||
"revanced_hide_filter_bar_preference", | ||
StringResource( | ||
"revanced_hide_filter_bar_preference_title", | ||
"Hide filter bar" | ||
), | ||
listOf( | ||
SwitchPreference( | ||
"revanced_hide_filter_bar_feed_in_feed", | ||
StringResource( | ||
"revanced_hide_filter_bar_feed_in_feed_title", | ||
"Hide in feed" | ||
), | ||
false, | ||
StringResource( | ||
"revanced_hide_filter_bar_feed_in_feed_summary_on", | ||
"Hidden in feed" | ||
), | ||
StringResource( | ||
"revanced_hide_filter_bar_feed_in_feed_summary_off", | ||
"Shown in feed" | ||
) | ||
), | ||
SwitchPreference( | ||
"revanced_hide_filter_bar_feed_in_search", | ||
StringResource( | ||
"revanced_hide_filter_bar_feed_in_search_title", | ||
"Hide in search" | ||
), | ||
false, | ||
StringResource( | ||
"revanced_hide_filter_bar_feed_in_search_summary_on", | ||
"Hidden in search" | ||
), | ||
StringResource( | ||
"revanced_hide_filter_bar_feed_in_search_summary_off", | ||
"Shown in search" | ||
) | ||
), | ||
SwitchPreference( | ||
"revanced_hide_filter_bar_feed_in_related_videos", | ||
StringResource( | ||
"revanced_hide_filter_bar_feed_in_related_videos_title", | ||
"Hide in related videos" | ||
), | ||
false, | ||
StringResource( | ||
"revanced_hide_filter_bar_feed_in_related_videos_summary_on", | ||
"Hidden in related videos" | ||
), | ||
StringResource( | ||
"revanced_hide_filter_bar_feed_in_related_videos_summary_off", | ||
"Shown in related videos" | ||
) | ||
), | ||
), | ||
) | ||
) | ||
|
||
relatedChipCloudMarginId = "related_chip_cloud_reduced_margins".layoutResourceId("layout") | ||
filterBarHeightId = "filter_bar_height".layoutResourceId() | ||
barContainerHeightId = "bar_container_height".layoutResourceId() | ||
|
||
return PatchResultSuccess() | ||
} | ||
|
||
internal companion object { | ||
var filterBarHeightId = -1L | ||
var relatedChipCloudMarginId = -1L | ||
var barContainerHeightId = -1L | ||
|
||
private fun String.layoutResourceId(type: String = "dimen") = | ||
ResourceMappingPatch.resourceMappings.single { it.type == type && it.name == this }.id | ||
} | ||
} |