From 6e1a538d34291d75f19bf66a188bc69241de3a7a Mon Sep 17 00:00:00 2001 From: bogadana <30848157+bogadana@users.noreply.github.com> Date: Tue, 5 Jul 2022 19:45:46 +0200 Subject: [PATCH] fix: show minimized playback options in settings (#118) --- .../MinimizedPlaybackSettingsFingerprint.kt | 40 +++++++++++++++++++ .../patch/MinimizedPlaybackPatch.kt | 34 +++++++++++++--- 2 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/minimizedplayback/fingerprints/MinimizedPlaybackSettingsFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/minimizedplayback/fingerprints/MinimizedPlaybackSettingsFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/minimizedplayback/fingerprints/MinimizedPlaybackSettingsFingerprint.kt new file mode 100644 index 00000000..ebb2e304 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/minimizedplayback/fingerprints/MinimizedPlaybackSettingsFingerprint.kt @@ -0,0 +1,40 @@ +package app.revanced.patches.youtube.layout.minimizedplayback.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.annotation.FuzzyPatternScanMethod +import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.layout.minimizedplayback.annotations.MinimizedPlaybackCompatibility +import app.revanced.patches.youtube.misc.mapping.patch.ResourceIdMappingProviderResourcePatch +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.iface.instruction.WideLiteralInstruction + +@Name("minimized-playback-manager-fingerprint") +@MatchingMethod( + "Ladj", "w" +) +@FuzzyPatternScanMethod(2) +@MinimizedPlaybackCompatibility +@Version("0.0.1") +object MinimizedPlaybackSettingsFingerprint : MethodFingerprint( + "L", + AccessFlags.PUBLIC or AccessFlags.FINAL, + null, + listOf( + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.IF_EQZ, + ), + customFingerprint = { + it.implementation!!.instructions.any { + (it as? WideLiteralInstruction)?.wideLiteral == resourceId + } + } +) + +val resourceId = ResourceIdMappingProviderResourcePatch.resourceMappings.first { it.type == "string" && it.name == "pref_background_category" }.id diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/minimizedplayback/patch/MinimizedPlaybackPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/minimizedplayback/patch/MinimizedPlaybackPatch.kt index 33a257ee..8d28616a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/minimizedplayback/patch/MinimizedPlaybackPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/minimizedplayback/patch/MinimizedPlaybackPatch.kt @@ -3,24 +3,32 @@ package app.revanced.patches.youtube.layout.minimizedplayback.patch import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version -import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.data.impl.BytecodeData -import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patcher.patch.impl.BytecodePatch +import app.revanced.patcher.data.impl.toMethodWalker +import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.Dependencies +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patcher.patch.impl.BytecodePatch +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.youtube.layout.minimizedplayback.annotations.MinimizedPlaybackCompatibility import app.revanced.patches.youtube.layout.minimizedplayback.fingerprints.MinimizedPlaybackManagerFingerprint +import app.revanced.patches.youtube.layout.minimizedplayback.fingerprints.MinimizedPlaybackSettingsFingerprint +import app.revanced.patches.youtube.misc.mapping.patch.ResourceIdMappingProviderResourcePatch +import org.jf.dexlib2.iface.instruction.ReferenceInstruction +import org.jf.dexlib2.iface.reference.MethodReference @Patch +@Dependencies(dependencies = [ResourceIdMappingProviderResourcePatch::class]) @Name("minimized-playback") @Description("Enable minimized and background playback.") @MinimizedPlaybackCompatibility @Version("0.0.1") class MinimizedPlaybackPatch : BytecodePatch( listOf( - MinimizedPlaybackManagerFingerprint + MinimizedPlaybackManagerFingerprint, MinimizedPlaybackSettingsFingerprint ) ) { override fun execute(data: BytecodeData): PatchResult { @@ -32,6 +40,22 @@ class MinimizedPlaybackPatch : BytecodePatch( return v0 """ ) + + val method = MinimizedPlaybackSettingsFingerprint.result!!.mutableMethod + val booleanCalls = method.implementation!!.instructions.withIndex() + .filter { ((it.value as? ReferenceInstruction)?.reference as? MethodReference)?.returnType == "Z" } + + val settingsBooleanIndex = booleanCalls.elementAt(1).index + val settingsBooleanMethod = + data.toMethodWalker(method).nextMethod(settingsBooleanIndex, true).getMethod() as MutableMethod + + settingsBooleanMethod.addInstructions( + 0, """ + const/4 v0, 0x1 + return v0 + """ + ) + return PatchResultSuccess() } -} \ No newline at end of file +}