mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 21:27:43 +02:00
feat(YouTube): add Hook download actions
patch (#70)
* feat(YouTube/Download Playlist Button): add playlist download button Co-authored-by: Hoàng Gia Bảo <70064328+YT-Advanced@users.noreply.github.com> Co-authored-by: inotia00 <108592928+inotia00@users.noreply.github.com> * feat(YouTube/Download Playlist Button): add playlist external downloader field * refactor(YouTube/Download Playlist Button): remove duplicate resources --------- Co-authored-by: Hoàng Gia Bảo <70064328+YT-Advanced@users.noreply.github.com> Co-authored-by: inotia00 <108592928+inotia00@users.noreply.github.com>
This commit is contained in:

committed by
GitHub

parent
e2a9e5b556
commit
d647061d94
@ -1,29 +1,19 @@
|
||||
package app.revanced.patches.youtube.player.overlaybuttons
|
||||
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.PatchException
|
||||
import app.revanced.patcher.patch.annotation.Patch
|
||||
import app.revanced.patcher.util.smali.ExternalLabel
|
||||
import app.revanced.patches.youtube.player.overlaybuttons.fingerprints.OfflineVideoEndpointFingerprint
|
||||
import app.revanced.patches.youtube.player.overlaybuttons.fingerprints.PiPPlaybackFingerprint
|
||||
import app.revanced.patches.youtube.player.overlaybuttons.fingerprints.PlayerButtonConstructorFingerprint
|
||||
import app.revanced.patches.youtube.utils.integrations.Constants.INTEGRATIONS_PATH
|
||||
import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH
|
||||
import app.revanced.patches.youtube.utils.mainactivity.MainActivityResolvePatch
|
||||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
|
||||
import app.revanced.patches.youtube.video.information.VideoInformationPatch
|
||||
import app.revanced.util.addFieldAndInstructions
|
||||
import app.revanced.util.getReference
|
||||
import app.revanced.util.getTargetIndexWithReferenceOrThrow
|
||||
import app.revanced.util.indexOfFirstInstruction
|
||||
import app.revanced.util.indexOfFirstInstructionOrThrow
|
||||
import app.revanced.util.resultOrThrow
|
||||
import app.revanced.util.*
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
|
||||
@ -38,48 +28,14 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
||||
)
|
||||
object OverlayButtonsBytecodePatch : BytecodePatch(
|
||||
setOf(
|
||||
OfflineVideoEndpointFingerprint,
|
||||
PiPPlaybackFingerprint,
|
||||
PlayerButtonConstructorFingerprint
|
||||
)
|
||||
) {
|
||||
private const val INTEGRATIONS_ALWAYS_REPEAT_CLASS_DESCRIPTOR =
|
||||
"$UTILS_PATH/AlwaysRepeatPatch;"
|
||||
|
||||
private const val INTEGRATIONS_VIDEO_UTILS_CLASS_DESCRIPTOR =
|
||||
"$INTEGRATIONS_PATH/utils/VideoUtils;"
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
|
||||
// region patch for hook download button
|
||||
|
||||
OfflineVideoEndpointFingerprint.resultOrThrow().mutableMethod.apply {
|
||||
addInstructionsWithLabels(
|
||||
0, """
|
||||
invoke-static/range {p3 .. p3}, $INTEGRATIONS_VIDEO_UTILS_CLASS_DESCRIPTOR->inAppDownloadButtonOnClick(Ljava/lang/String;)Z
|
||||
move-result v0
|
||||
if-eqz v0, :show_native_downloader
|
||||
return-void
|
||||
""", ExternalLabel("show_native_downloader", getInstruction(0))
|
||||
)
|
||||
}
|
||||
|
||||
PiPPlaybackFingerprint.resultOrThrow().let {
|
||||
it.mutableMethod.apply {
|
||||
val insertIndex = it.scanResult.patternScanResult!!.endIndex
|
||||
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
|
||||
|
||||
addInstructions(
|
||||
insertIndex, """
|
||||
invoke-static {v$insertRegister}, $INTEGRATIONS_VIDEO_UTILS_CLASS_DESCRIPTOR->getExternalDownloaderLaunchedState(Z)Z
|
||||
move-result v$insertRegister
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
// region patch for always repeat and pause
|
||||
|
||||
PlayerButtonConstructorFingerprint.resultOrThrow().mutableMethod.apply {
|
||||
|
@ -1,17 +0,0 @@
|
||||
package app.revanced.patches.youtube.player.overlaybuttons.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
|
||||
internal object OfflineVideoEndpointFingerprint : MethodFingerprint(
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||
returnType = "V",
|
||||
parameters = listOf(
|
||||
"Ljava/util/Map;",
|
||||
"L",
|
||||
"Ljava/lang/String", // VideoId
|
||||
"L"
|
||||
),
|
||||
strings = listOf("Object is not an offlineable video: ")
|
||||
)
|
@ -1,16 +0,0 @@
|
||||
package app.revanced.patches.youtube.player.overlaybuttons.fingerprints
|
||||
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
|
||||
internal object PiPPlaybackFingerprint : MethodFingerprint(
|
||||
returnType = "Z",
|
||||
parameters = listOf("Lcom/google/android/libraries/youtube/innertube/model/player/PlayerResponseModel;"),
|
||||
opcodes = listOf(
|
||||
Opcode.INVOKE_INTERFACE,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.INVOKE_STATIC,
|
||||
Opcode.MOVE_RESULT,
|
||||
Opcode.IF_NEZ
|
||||
)
|
||||
)
|
Reference in New Issue
Block a user