From 8ea34036e54b8bc80ea83c4912c800243aa128cb Mon Sep 17 00:00:00 2001 From: epicsampler <102923070+epicsampler@users.noreply.github.com> Date: Thu, 28 Apr 2022 15:50:43 +0000 Subject: [PATCH] refactor: YouTube Music patches --- src/main/kotlin/app/revanced/patches/Index.kt | 5 ++-- .../patches/music/audio/CodecsUnlockPatch.kt | 4 ++-- ...derPatch.kt => RemoveTasteBuilderPatch.kt} | 24 +++++++++++++------ 3 files changed, 22 insertions(+), 11 deletions(-) rename src/main/kotlin/app/revanced/patches/music/layout/{RemoveTastebuilderPatch.kt => RemoveTasteBuilderPatch.kt} (75%) diff --git a/src/main/kotlin/app/revanced/patches/Index.kt b/src/main/kotlin/app/revanced/patches/Index.kt index 6aacc9a78..f55a8b013 100644 --- a/src/main/kotlin/app/revanced/patches/Index.kt +++ b/src/main/kotlin/app/revanced/patches/Index.kt @@ -3,8 +3,9 @@ package app.revanced.patches import app.revanced.patcher.patch.Patch import app.revanced.patches.music.audio.EnableAudioOnlyPatch import app.revanced.patches.music.layout.RemoveUpgradeTabPatch -import app.revanced.patches.music.layout.RemoveTastebuilderPatch +import app.revanced.patches.music.layout.RemoveTasteBuilderPatch import app.revanced.patches.music.premium.BackgroundPlayPatch +import app.revanced.patches.music.audio.CodecsUnlockPatch import app.revanced.patches.youtube.ad.HomeAdsPatch import app.revanced.patches.youtube.ad.HomePromoPatch import app.revanced.patches.youtube.ad.VideoAdsPatch @@ -34,7 +35,7 @@ object Index { ::EnableSeekbarTappingPatch, ::EnableAudioOnlyPatch, ::RemoveUpgradeTabPatch, - ::RemoveTastebuilderPatch, + ::RemoveTasteBuilderPatch, ::BackgroundPlayPatch, ::CodecsUnlockPatch ) diff --git a/src/main/kotlin/app/revanced/patches/music/audio/CodecsUnlockPatch.kt b/src/main/kotlin/app/revanced/patches/music/audio/CodecsUnlockPatch.kt index 6323ff3e4..df24b4de5 100644 --- a/src/main/kotlin/app/revanced/patches/music/audio/CodecsUnlockPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/audio/CodecsUnlockPatch.kt @@ -1,4 +1,4 @@ -package app.revanced.patches +package app.revanced.patches.music.audio import app.revanced.patcher.PatcherData import app.revanced.patcher.extensions.or @@ -22,7 +22,7 @@ private val packageMetadata = listOf( private val patchMetadata = PatchMetadata( "codecs-unlock", "Audio codecs unlock patch", - "Patch to unlock more audio codecs", + "Enables more audio codecs. Usually results in better audio quality but may depend on song and device.", packageMetadata, "0.0.1" ) diff --git a/src/main/kotlin/app/revanced/patches/music/layout/RemoveTastebuilderPatch.kt b/src/main/kotlin/app/revanced/patches/music/layout/RemoveTasteBuilderPatch.kt similarity index 75% rename from src/main/kotlin/app/revanced/patches/music/layout/RemoveTastebuilderPatch.kt rename to src/main/kotlin/app/revanced/patches/music/layout/RemoveTasteBuilderPatch.kt index 723ba6a09..de03987e0 100644 --- a/src/main/kotlin/app/revanced/patches/music/layout/RemoveTastebuilderPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/layout/RemoveTasteBuilderPatch.kt @@ -20,18 +20,18 @@ private val compatiblePackages = listOf( ) ) -class RemoveTastebuilderPatch : Patch( +class RemoveTasteBuilderPatch : Patch( PatchMetadata( - "tastebuilder-remover", - "Remove Tastebuilder Patch", - "Remove the tastebuilder from the Home screen.", + "tasteBuilder-remover", + "Remove TasteBuilder Patch", + "Removes the \"Tell us which artists you like\" card from the Home screen. The same functionality can be triggered from the settings anyway.", compatiblePackages, "0.0.1" ), listOf( MethodSignature( MethodSignatureMetadata( - "tastebuilder-constructor", + "taste-builder-constructor", MethodMetadata("Lkyu;", ""), PatternScanMethod.Fuzzy(2), // FIXME: Test this threshold and find the best value. compatiblePackages, @@ -53,6 +53,14 @@ class RemoveTastebuilderPatch : Patch( Opcode.CONST_4, Opcode.INVOKE_VIRTUAL, Opcode.MOVE_RESULT_OBJECT, + Opcode.IPUT_OBJECT, + Opcode.CONST, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.CHECK_CAST, + Opcode.IPUT_OBJECT, + Opcode.NEW_INSTANCE, + Opcode.INVOKE_DIRECT, Opcode.IPUT_OBJECT ) ) @@ -62,7 +70,9 @@ class RemoveTastebuilderPatch : Patch( val result = signatures.first().result!! val implementation = result.method.implementation!! - val register = (implementation.instructions[result.scanData.endIndex] as Instruction22c).registerA + val insertIndex = result.scanData.endIndex - 8 + + val register = (implementation.instructions[insertIndex] as Instruction22c).registerA val instructionList = """ @@ -71,7 +81,7 @@ class RemoveTastebuilderPatch : Patch( """.trimIndent().toInstructions().toMutableList() implementation.addInstructions( - result.scanData.endIndex, + insertIndex, instructionList )