Skip to content

Commit

Permalink
fix: show minimized playback options in settings (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
bogadana committed Jul 5, 2022
1 parent 6146ef0 commit 6e1a538
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
}
}
}

0 comments on commit 6e1a538

Please sign in to comment.