refactor(video-id-hook): integrate

This commit is contained in:
inotia00 2023-04-12 20:34:12 +09:00
parent a70aa372a8
commit acd15e331e
16 changed files with 35 additions and 118 deletions

View File

@ -9,14 +9,14 @@ import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.misc.playercontrols.patch.PlayerControlsPatch import app.revanced.patches.youtube.misc.playercontrols.patch.PlayerControlsPatch
import app.revanced.patches.youtube.misc.videoid.mainstream.patch.MainstreamVideoIdPatch import app.revanced.patches.youtube.misc.videoid.patch.VideoIdPatch
import app.revanced.util.integrations.Constants.BUTTON_PATH import app.revanced.util.integrations.Constants.BUTTON_PATH
@Name("overlay-buttons-bytecode-patch") @Name("overlay-buttons-bytecode-patch")
@DependsOn( @DependsOn(
dependencies = [ dependencies = [
PlayerControlsPatch::class, PlayerControlsPatch::class,
MainstreamVideoIdPatch::class VideoIdPatch::class
] ]
) )
@YouTubeCompatibility @YouTubeCompatibility

View File

@ -16,7 +16,6 @@ import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.layout.flyoutpanel.oldqualitylayout.fingerprints.QualityMenuViewInflateFingerprint import app.revanced.patches.youtube.layout.flyoutpanel.oldqualitylayout.fingerprints.QualityMenuViewInflateFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.patches.youtube.misc.videoid.legacy.patch.LegacyVideoIdPatch
import app.revanced.util.integrations.Constants.FLYOUT_PANEL import app.revanced.util.integrations.Constants.FLYOUT_PANEL
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
@ -25,7 +24,6 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
@Description("Enables the original quality flyout menu.") @Description("Enables the original quality flyout menu.")
@DependsOn( @DependsOn(
[ [
LegacyVideoIdPatch::class,
SettingsPatch::class, SettingsPatch::class,
SharedResourceIdPatch::class SharedResourceIdPatch::class
] ]

View File

@ -19,7 +19,7 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.misc.returnyoutubedislike.fingerprints.* import app.revanced.patches.youtube.misc.returnyoutubedislike.fingerprints.*
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.patches.youtube.misc.videoid.mainstream.patch.MainstreamVideoIdPatch import app.revanced.patches.youtube.misc.videoid.patch.VideoIdPatch
import app.revanced.util.integrations.Constants.UTILS_PATH import app.revanced.util.integrations.Constants.UTILS_PATH
import org.jf.dexlib2.Opcode import org.jf.dexlib2.Opcode
import org.jf.dexlib2.builder.instruction.BuilderInstruction3rc import org.jf.dexlib2.builder.instruction.BuilderInstruction3rc
@ -35,8 +35,8 @@ import org.jf.dexlib2.iface.reference.MethodReference
@Description("Shows the dislike count of videos using the Return YouTube Dislike API.") @Description("Shows the dislike count of videos using the Return YouTube Dislike API.")
@DependsOn( @DependsOn(
[ [
MainstreamVideoIdPatch::class, SettingsPatch::class,
SettingsPatch::class VideoIdPatch::class
] ]
) )
@YouTubeCompatibility @YouTubeCompatibility
@ -168,7 +168,7 @@ class ReturnYouTubeDislikePatch : BytecodePatch(
} ?: return ShortsTextComponentParentFingerprint.toErrorResult() } ?: return ShortsTextComponentParentFingerprint.toErrorResult()
MainstreamVideoIdPatch.injectCall("$INTEGRATIONS_RYD_CLASS_DESCRIPTOR->newVideoLoaded(Ljava/lang/String;)V") VideoIdPatch.injectCall("$INTEGRATIONS_RYD_CLASS_DESCRIPTOR->newVideoLoaded(Ljava/lang/String;)V")
/* /*
* Add ReVanced Settings * Add ReVanced Settings

View File

@ -17,8 +17,7 @@ import app.revanced.patches.youtube.misc.playercontrols.patch.PlayerControlsPatc
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.youtube.misc.sponsorblock.bytecode.fingerprints.* import app.revanced.patches.youtube.misc.sponsorblock.bytecode.fingerprints.*
import app.revanced.patches.youtube.misc.timebar.patch.HookTimebarPatch import app.revanced.patches.youtube.misc.timebar.patch.HookTimebarPatch
import app.revanced.patches.youtube.misc.videoid.legacy.patch.LegacyVideoIdPatch import app.revanced.patches.youtube.misc.videoid.patch.VideoIdPatch
import app.revanced.patches.youtube.misc.videoid.mainstream.patch.MainstreamVideoIdPatch
import app.revanced.util.bytecode.BytecodeHelper.injectInit import app.revanced.util.bytecode.BytecodeHelper.injectInit
import app.revanced.util.bytecode.BytecodeHelper.updatePatchStatus import app.revanced.util.bytecode.BytecodeHelper.updatePatchStatus
import org.jf.dexlib2.Opcode import org.jf.dexlib2.Opcode
@ -32,11 +31,10 @@ import org.jf.dexlib2.iface.reference.MethodReference
@Name("sponsorblock-bytecode-patch") @Name("sponsorblock-bytecode-patch")
@DependsOn( @DependsOn(
[ [
LegacyVideoIdPatch::class,
MainstreamVideoIdPatch::class,
OverrideSpeedHookPatch::class, OverrideSpeedHookPatch::class,
PlayerControlsPatch::class, PlayerControlsPatch::class,
SharedResourceIdPatch::class SharedResourceIdPatch::class,
VideoIdPatch::class
] ]
) )
@YouTubeCompatibility @YouTubeCompatibility
@ -51,7 +49,7 @@ class SponsorBlockBytecodePatch : BytecodePatch(
/* /*
* Hook the video time methods * Hook the video time methods
*/ */
with(MainstreamVideoIdPatch) { with(VideoIdPatch) {
videoTimeHook( videoTimeHook(
INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR, INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR,
"setVideoTime" "setVideoTime"
@ -61,7 +59,7 @@ class SponsorBlockBytecodePatch : BytecodePatch(
/* /*
* Inject VideoIdPatch * Inject VideoIdPatch
*/ */
MainstreamVideoIdPatch.injectCall("$INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->setCurrentVideoId(Ljava/lang/String;)V") VideoIdPatch.injectCall("$INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->setCurrentVideoId(Ljava/lang/String;)V")
/* /*
@ -148,7 +146,7 @@ class SponsorBlockBytecodePatch : BytecodePatch(
val register = (instruction as OneRegisterInstruction).registerA val register = (instruction as OneRegisterInstruction).registerA
it.replaceInstruction( it.replaceInstruction(
index, index,
"const-string v$register, \"${MainstreamVideoIdPatch.reactReference}\"" "const-string v$register, \"${VideoIdPatch.reactReference}\""
) )
break break
} }

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.misc.videoid.mainstream.fingerprint package app.revanced.patches.youtube.misc.videoid.fingerprint
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode import org.jf.dexlib2.Opcode

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.misc.videoid.mainstream.fingerprint package app.revanced.patches.youtube.misc.videoid.fingerprint
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.misc.videoid.mainstream.fingerprint package app.revanced.patches.youtube.misc.videoid.fingerprint
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.misc.videoid.mainstream.fingerprint package app.revanced.patches.youtube.misc.videoid.fingerprint
import app.revanced.patcher.extensions.or import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint

View File

@ -1,11 +1,11 @@
package app.revanced.patches.youtube.misc.videoid.mainstream.fingerprint package app.revanced.patches.youtube.misc.videoid.fingerprint
import app.revanced.patcher.extensions.or import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode import org.jf.dexlib2.Opcode
object MainstreamVideoIdFingerprint : MethodFingerprint( object VideoIdFingerprint : MethodFingerprint(
returnType = "V", returnType = "V",
access = AccessFlags.PUBLIC or AccessFlags.FINAL, access = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L"), parameters = listOf("L"),

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.misc.videoid.mainstream.fingerprint package app.revanced.patches.youtube.misc.videoid.fingerprint
import app.revanced.patcher.extensions.or import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.misc.videoid.mainstream.fingerprint package app.revanced.patches.youtube.misc.videoid.fingerprint
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint

View File

@ -1,16 +0,0 @@
package app.revanced.patches.youtube.misc.videoid.legacy.fingerprint
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
object LegacyVideoIdFingerprint : MethodFingerprint(
returnType = "V",
access = AccessFlags.DECLARED_SYNCHRONIZED or AccessFlags.FINAL or AccessFlags.PUBLIC,
parameters = listOf("L"),
opcodes = listOf(Opcode.INVOKE_INTERFACE),
customFingerprint = {
it.definingClass.endsWith("PlaybackLifecycleMonitor;")
}
)

View File

@ -1,63 +0,0 @@
package app.revanced.patches.youtube.misc.videoid.legacy.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.misc.videoid.legacy.fingerprint.LegacyVideoIdFingerprint
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
@Name("video-id-hook-legacy")
@Description("Hook to detect when the video id changes (legacy)")
@YouTubeCompatibility
@Version("0.0.1")
class LegacyVideoIdPatch : BytecodePatch(
listOf(
LegacyVideoIdFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
LegacyVideoIdFingerprint.result?.let {
insertIndex = it.scanResult.patternScanResult!!.endIndex
with (it.mutableMethod) {
insertMethod = this
videoIdRegister = (implementation!!.instructions[insertIndex + 1] as OneRegisterInstruction).registerA
}
offset++ // offset so setCurrentVideoId is called before any injected call
} ?: return LegacyVideoIdFingerprint.toErrorResult()
return PatchResultSuccess()
}
companion object {
private var offset = 2
private var insertIndex: Int = 0
private var videoIdRegister: Int = 0
private lateinit var insertMethod: MutableMethod
/**
* Adds an invoke-static instruction, called with the new id when the video changes
* @param methodDescriptor which method to call. Params have to be `Ljava/lang/String;`
*/
fun injectCall(
methodDescriptor: String
) {
insertMethod.addInstructions(
insertIndex + offset, // move-result-object offset
"invoke-static {v$videoIdRegister}, $methodDescriptor"
)
}
}
}

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.misc.videoid.mainstream.patch package app.revanced.patches.youtube.misc.videoid.patch
import app.revanced.extensions.toErrorResult import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Description
@ -19,7 +19,7 @@ import app.revanced.patches.shared.fingerprints.VideoEndFingerprint
import app.revanced.patches.shared.fingerprints.VideoEndParentFingerprint import app.revanced.patches.shared.fingerprints.VideoEndParentFingerprint
import app.revanced.patches.youtube.misc.playertype.patch.PlayerTypeHookPatch import app.revanced.patches.youtube.misc.playertype.patch.PlayerTypeHookPatch
import app.revanced.patches.youtube.misc.timebar.patch.HookTimebarPatch import app.revanced.patches.youtube.misc.timebar.patch.HookTimebarPatch
import app.revanced.patches.youtube.misc.videoid.mainstream.fingerprint.* import app.revanced.patches.youtube.misc.videoid.fingerprint.*
import app.revanced.util.integrations.Constants.VIDEO_PATH import app.revanced.util.integrations.Constants.VIDEO_PATH
import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.builder.MutableMethodImplementation import org.jf.dexlib2.builder.MutableMethodImplementation
@ -32,8 +32,8 @@ import org.jf.dexlib2.immutable.ImmutableMethod
import org.jf.dexlib2.immutable.ImmutableMethodParameter import org.jf.dexlib2.immutable.ImmutableMethodParameter
import org.jf.dexlib2.util.MethodUtil import org.jf.dexlib2.util.MethodUtil
@Name("video-id-hook-mainstream") @Name("video-id-hook")
@Description("Hook to detect when the video id changes (mainstream)") @Description("Hook to detect when the video id changes")
@YouTubeCompatibility @YouTubeCompatibility
@Version("0.0.1") @Version("0.0.1")
@DependsOn( @DependsOn(
@ -42,14 +42,14 @@ import org.jf.dexlib2.util.MethodUtil
PlayerTypeHookPatch::class PlayerTypeHookPatch::class
] ]
) )
class MainstreamVideoIdPatch : BytecodePatch( class VideoIdPatch : BytecodePatch(
listOf( listOf(
MainstreamVideoIdFingerprint,
PlayerControllerSetTimeReferenceFingerprint, PlayerControllerSetTimeReferenceFingerprint,
PlayerInitFingerprint, PlayerInitFingerprint,
SeekFingerprint, SeekFingerprint,
TimebarFingerprint, TimebarFingerprint,
VideoEndParentFingerprint, VideoEndParentFingerprint,
VideoIdFingerprint,
VideoTimeHighPrecisionFingerprint, VideoTimeHighPrecisionFingerprint,
VideoTimeHighPrecisionParentFingerprint VideoTimeHighPrecisionParentFingerprint
) )
@ -154,7 +154,7 @@ class MainstreamVideoIdPatch : BytecodePatch(
} }
MainstreamVideoIdFingerprint.result?.let { VideoIdFingerprint.result?.let {
insertIndex = it.scanResult.patternScanResult!!.endIndex insertIndex = it.scanResult.patternScanResult!!.endIndex
with (it.mutableMethod) { with (it.mutableMethod) {
@ -162,7 +162,7 @@ class MainstreamVideoIdPatch : BytecodePatch(
videoIdRegister = (implementation!!.instructions[insertIndex] as OneRegisterInstruction).registerA videoIdRegister = (implementation!!.instructions[insertIndex] as OneRegisterInstruction).registerA
} }
offset++ // offset so setVideoId is called before any injected call offset++ // offset so setVideoId is called before any injected call
} ?: return MainstreamVideoIdFingerprint.toErrorResult() } ?: return VideoIdFingerprint.toErrorResult()
injectCall("$INTEGRATIONS_CLASS_DESCRIPTOR->setVideoId(Ljava/lang/String;)V") injectCall("$INTEGRATIONS_CLASS_DESCRIPTOR->setVideoId(Ljava/lang/String;)V")

View File

@ -12,14 +12,14 @@ import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.misc.videoid.legacy.patch.LegacyVideoIdPatch import app.revanced.patches.youtube.misc.videoid.patch.VideoIdPatch
import app.revanced.patches.youtube.video.quality.bytecode.fingerprints.* import app.revanced.patches.youtube.video.quality.bytecode.fingerprints.*
import app.revanced.util.integrations.Constants.VIDEO_PATH import app.revanced.util.integrations.Constants.VIDEO_PATH
import org.jf.dexlib2.iface.instruction.ReferenceInstruction import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.reference.FieldReference import org.jf.dexlib2.iface.reference.FieldReference
@Name("default-video-quality-bytecode-patch") @Name("default-video-quality-bytecode-patch")
@DependsOn([LegacyVideoIdPatch::class]) @DependsOn([VideoIdPatch::class])
@YouTubeCompatibility @YouTubeCompatibility
@Version("0.0.1") @Version("0.0.1")
class VideoQualityBytecodePatch : BytecodePatch( class VideoQualityBytecodePatch : BytecodePatch(
@ -62,7 +62,7 @@ class VideoQualityBytecodePatch : BytecodePatch(
) )
} ?: return VideoQualitySettingsParentFingerprint.toErrorResult() } ?: return VideoQualitySettingsParentFingerprint.toErrorResult()
LegacyVideoIdPatch.injectCall("$INTEGRATIONS_VIDEO_QUALITY_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;)V") VideoIdPatch.injectCall("$INTEGRATIONS_VIDEO_QUALITY_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;)V")
return PatchResultSuccess() return PatchResultSuccess()
} }

View File

@ -13,7 +13,7 @@ import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.misc.overridespeed.bytecode.fingerprints.VideoSpeedSettingsFingerprint import app.revanced.patches.youtube.misc.overridespeed.bytecode.fingerprints.VideoSpeedSettingsFingerprint
import app.revanced.patches.youtube.misc.overridespeed.bytecode.patch.OverrideSpeedHookPatch import app.revanced.patches.youtube.misc.overridespeed.bytecode.patch.OverrideSpeedHookPatch
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.youtube.misc.videoid.legacy.patch.LegacyVideoIdPatch import app.revanced.patches.youtube.misc.videoid.patch.VideoIdPatch
import app.revanced.patches.youtube.video.livestream.patch.LiveStreamPatch import app.revanced.patches.youtube.video.livestream.patch.LiveStreamPatch
import app.revanced.patches.youtube.video.speed.bytecode.fingerprints.* import app.revanced.patches.youtube.video.speed.bytecode.fingerprints.*
import app.revanced.util.bytecode.BytecodeHelper.updatePatchStatus import app.revanced.util.bytecode.BytecodeHelper.updatePatchStatus
@ -23,10 +23,10 @@ import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction
@Name("default-video-speed-bytecode-patch") @Name("default-video-speed-bytecode-patch")
@DependsOn( @DependsOn(
[ [
LegacyVideoIdPatch::class,
LiveStreamPatch::class, LiveStreamPatch::class,
OverrideSpeedHookPatch::class, OverrideSpeedHookPatch::class,
SharedResourceIdPatch::class SharedResourceIdPatch::class,
VideoIdPatch::class
] ]
) )
@YouTubeCompatibility @YouTubeCompatibility
@ -56,7 +56,7 @@ class VideoSpeedBytecodePatch : BytecodePatch(
"invoke-static {}, $INTEGRATIONS_VIDEO_SPEED_CLASS_DESCRIPTOR->setDefaultSpeed()V" "invoke-static {}, $INTEGRATIONS_VIDEO_SPEED_CLASS_DESCRIPTOR->setDefaultSpeed()V"
) ?: return VideoSpeedSettingsFingerprint.toErrorResult() ) ?: return VideoSpeedSettingsFingerprint.toErrorResult()
LegacyVideoIdPatch.injectCall("$INTEGRATIONS_VIDEO_SPEED_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;)V") VideoIdPatch.injectCall("$INTEGRATIONS_VIDEO_SPEED_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;)V")
context.updatePatchStatus("VideoSpeed") context.updatePatchStatus("VideoSpeed")