fix(youtube): improve patching speed (#2514)
This commit is contained in:
committed by
GitHub
parent
23537557b5
commit
38dda9346b
+3
-12
@@ -5,42 +5,33 @@ import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.annotation.Version
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult
|
||||
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.patches.shared.mapping.misc.patch.ResourceMappingPatch
|
||||
import app.revanced.patches.youtube.misc.playercontrols.annotation.PlayerControlsCompatibility
|
||||
import app.revanced.patches.youtube.misc.playercontrols.fingerprints.BottomControlsInflateFingerprint
|
||||
import app.revanced.patches.youtube.misc.playercontrols.fingerprints.PlayerControlsVisibilityFingerprint
|
||||
import app.revanced.patches.youtube.misc.playercontrols.resource.patch.BottomControlsResourcePatch
|
||||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
|
||||
@Name("player-controls-bytecode-patch")
|
||||
@DependsOn([ResourceMappingPatch::class])
|
||||
@DependsOn([BottomControlsResourcePatch::class])
|
||||
@Description("Manages the code for the player controls of the YouTube player.")
|
||||
@PlayerControlsCompatibility
|
||||
@Version("0.0.1")
|
||||
class PlayerControlsBytecodePatch : BytecodePatch(
|
||||
listOf(PlayerControlsVisibilityFingerprint)
|
||||
listOf(PlayerControlsVisibilityFingerprint, BottomControlsInflateFingerprint)
|
||||
) {
|
||||
override fun execute(context: BytecodeContext): PatchResult {
|
||||
showPlayerControlsFingerprintResult = PlayerControlsVisibilityFingerprint.result!!
|
||||
|
||||
bottomUiContainerResourceId = ResourceMappingPatch
|
||||
.resourceMappings
|
||||
.single { it.type == "id" && it.name == "bottom_ui_container_stub" }.id
|
||||
|
||||
// TODO: another solution is required, this is hacky
|
||||
listOf(BottomControlsInflateFingerprint).resolve(context, context.classes)
|
||||
inflateFingerprintResult = BottomControlsInflateFingerprint.result!!
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
|
||||
internal companion object {
|
||||
var bottomUiContainerResourceId: Long = 0
|
||||
|
||||
lateinit var showPlayerControlsFingerprintResult: MethodFingerprintResult
|
||||
|
||||
|
||||
+9
-11
@@ -1,21 +1,19 @@
|
||||
package app.revanced.patches.youtube.misc.playercontrols.fingerprints
|
||||
|
||||
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import app.revanced.patches.youtube.misc.playercontrols.bytecode.patch.PlayerControlsBytecodePatch
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.util.patch.LiteralValueFingerprint
|
||||
import app.revanced.patches.youtube.misc.playercontrols.resource.patch.BottomControlsResourcePatch
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
import org.jf.dexlib2.Opcode
|
||||
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
|
||||
|
||||
object BottomControlsInflateFingerprint : MethodFingerprint(
|
||||
object BottomControlsInflateFingerprint : LiteralValueFingerprint(
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL or AccessFlags.SYNTHETIC,
|
||||
returnType = "L",
|
||||
parameters = listOf(),
|
||||
opcodes = listOf(
|
||||
Opcode.CHECK_CAST,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.MOVE_RESULT_OBJECT
|
||||
),
|
||||
customFingerprint = { methodDef, _ ->
|
||||
methodDef.implementation?.instructions?.any { instruction ->
|
||||
instruction.opcode.ordinal == Opcode.CONST.ordinal &&
|
||||
(instruction as? WideLiteralInstruction)?.wideLiteral == PlayerControlsBytecodePatch.bottomUiContainerResourceId
|
||||
} == true
|
||||
}
|
||||
literal = BottomControlsResourcePatch.bottomUiContainerResourceId
|
||||
)
|
||||
+4
-2
@@ -1,10 +1,12 @@
|
||||
package app.revanced.patches.youtube.misc.playercontrols.fingerprints
|
||||
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import org.jf.dexlib2.AccessFlags
|
||||
|
||||
object PlayerControlsVisibilityFingerprint : MethodFingerprint(
|
||||
"V",
|
||||
accessFlags = AccessFlags.PRIVATE or AccessFlags.FINAL,
|
||||
returnType = "V",
|
||||
parameters = listOf("Z", "Z"),
|
||||
customFingerprint = { methodDef, _ ->
|
||||
methodDef.definingClass.endsWith("YouTubeControlsOverlay;")
|
||||
|
||||
+8
-2
@@ -8,22 +8,30 @@ 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.youtube.misc.playercontrols.annotation.PlayerControlsCompatibility
|
||||
import java.io.Closeable
|
||||
|
||||
@Name("bottom-controls-resource-patch")
|
||||
@Description("Manages the resources for the bottom controls of the YouTube player.")
|
||||
@PlayerControlsCompatibility
|
||||
@DependsOn([ResourceMappingPatch::class])
|
||||
@Version("0.0.1")
|
||||
class BottomControlsResourcePatch : ResourcePatch, Closeable {
|
||||
override fun execute(context: ResourceContext): PatchResult {
|
||||
resourceContext = context
|
||||
targetXmlEditor = context.xmlEditor[TARGET_RESOURCE]
|
||||
|
||||
bottomUiContainerResourceId = ResourceMappingPatch.resourceMappings
|
||||
.single { it.type == "id" && it.name == "bottom_ui_container_stub" }.id
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
|
||||
companion object {
|
||||
internal var bottomUiContainerResourceId : Long = -1
|
||||
|
||||
internal const val TARGET_RESOURCE_NAME = "youtube_controls_bottom_ui_container.xml"
|
||||
private const val TARGET_RESOURCE = "res/layout/$TARGET_RESOURCE_NAME"
|
||||
|
||||
@@ -33,8 +41,6 @@ class BottomControlsResourcePatch : ResourcePatch, Closeable {
|
||||
// The element to which to add the new elements to
|
||||
private var lastLeftOf = "fullscreen_button"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Add new controls to the bottom of the YouTube player.
|
||||
* @param hostYouTubeControlsBottomUiResourceName The hosting resource name containing the elements.
|
||||
|
||||
Reference in New Issue
Block a user