forked from ReVanced/revanced-patches-template
-
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):
hide-mix-playlists
patch (ReVanced#816)
- Loading branch information
1 parent
8852f09
commit e76c73b
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...ced/patches/youtube/layout/hidemixplaylists/annotations/MixPlaylistsPatchCompatibility.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.hidemixplaylists.annotations | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
@Compatibility( | ||
[Package( | ||
"com.google.android.youtube", arrayOf("17.32.39", "17.34.36", "17.36.37", "17.36.39", "17.37.35", "17.38.36", "17.39.35", "17.40.41") | ||
)] | ||
) | ||
@Target(AnnotationTarget.CLASS) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
internal annotation class MixPlaylistsPatchCompatibility |
31 changes: 31 additions & 0 deletions
31
...nced/patches/youtube/layout/hidemixplaylists/fingerprints/MixPlaylistsPatchFingerprint.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,31 @@ | ||
package app.revanced.patches.youtube.layout.hidemixplaylists.fingerprints | ||
|
||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patches.youtube.layout.hidemixplaylists.annotations.MixPlaylistsPatchCompatibility | ||
import org.jf.dexlib2.AccessFlags | ||
import org.jf.dexlib2.Opcode | ||
|
||
@Name("mix-playlists-fingerprint") | ||
@MixPlaylistsPatchCompatibility | ||
@Version("0.0.1") | ||
object MixPlaylistsPatchFingerprint : MethodFingerprint( | ||
"V", AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, listOf("L", "L", "L", "L", "L", "L", "L"), listOf( | ||
Opcode.INVOKE_DIRECT, | ||
Opcode.IPUT_OBJECT, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.IPUT_OBJECT, | ||
Opcode.IPUT_OBJECT, | ||
Opcode.IPUT_OBJECT, | ||
Opcode.IPUT_OBJECT, | ||
Opcode.NEW_INSTANCE, | ||
Opcode.INVOKE_DIRECT, | ||
Opcode.IPUT_OBJECT, | ||
Opcode.IPUT_OBJECT, | ||
Opcode.IPUT_OBJECT, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.RETURN_VOID | ||
) | ||
) |
55 changes: 55 additions & 0 deletions
55
...in/kotlin/app/revanced/patches/youtube/layout/hidemixplaylists/patch/MixPlaylistsPatch.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,55 @@ | ||
package app.revanced.patches.youtube.layout.hidemixplaylists.patch | ||
|
||
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.addInstruction | ||
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.patcher.patch.BytecodePatch | ||
import app.revanced.patches.youtube.layout.hidemixplaylists.annotations.MixPlaylistsPatchCompatibility | ||
import app.revanced.patches.youtube.layout.hidemixplaylists.fingerprints.MixPlaylistsPatchFingerprint | ||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch | ||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch | ||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.StringResource | ||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.SwitchPreference | ||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction | ||
|
||
@Patch | ||
@DependsOn([IntegrationsPatch::class]) | ||
@Name("hide-my-mix") | ||
@Description("Removes mix playlists from the feed.") | ||
@MixPlaylistsPatchCompatibility | ||
@Version("0.0.1") | ||
class MixPlaylistsPatch : BytecodePatch( | ||
listOf( | ||
MixPlaylistsPatchFingerprint | ||
) | ||
) { | ||
override fun execute(context: BytecodeContext): PatchResult { | ||
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( | ||
SwitchPreference( | ||
"revanced_mix_playlists_hidden", | ||
StringResource("revanced_mix_playlists_title", "Show mix playlists"), | ||
true, | ||
StringResource("revanced_mix_playlists_summary_on", "Mix playlists are shown"), | ||
StringResource("revanced_mix_playlists_summary_off", "Mix playlists are hidden") | ||
) | ||
) | ||
|
||
val result = MixPlaylistsPatchFingerprint.result!! | ||
val method = result.mutableMethod | ||
val index = result.scanResult.patternScanResult!!.endIndex - 6 | ||
val register = (method.implementation!!.instructions[index] as OneRegisterInstruction).registerA | ||
|
||
method.addInstruction( | ||
index + 2, | ||
"invoke-static {v$register}, Lapp/revanced/integrations/patches/HideMixPlaylistsPatch;->hideMixPlaylists(Landroid/view/View;)V" | ||
) | ||
|
||
return PatchResultSuccess() | ||
} | ||
} |