refactor(default-video-speed): default video speed does not apply when playing live video

This commit is contained in:
inotia00 2023-03-12 01:55:48 +09:00
parent ac838db35a
commit 1f95b63b45
2 changed files with 49 additions and 1 deletions

View File

@ -0,0 +1,23 @@
package app.revanced.patches.youtube.video.speed.bytecode.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
import org.jf.dexlib2.Opcode
object LiveLabelFingerprint : MethodFingerprint(
returnType = "V",
opcodes = listOf(
Opcode.IGET_OBJECT,
Opcode.IF_NEZ,
Opcode.RETURN_VOID,
Opcode.INVOKE_VIRTUAL,
Opcode.RETURN_VOID
),
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any {
it.opcode.ordinal == Opcode.CONST.ordinal &&
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.chapterRepeatOnResourceId
} == true
}
)

View File

@ -12,28 +12,52 @@ 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.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.videoid.legacy.patch.LegacyVideoIdPatch import app.revanced.patches.youtube.misc.videoid.legacy.patch.LegacyVideoIdPatch
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
import app.revanced.util.integrations.Constants.VIDEO_PATH import app.revanced.util.integrations.Constants.VIDEO_PATH
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.builder.instruction.BuilderInstruction35c
import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction
@Name("default-video-speed-bytecode-patch") @Name("default-video-speed-bytecode-patch")
@DependsOn( @DependsOn(
[ [
LegacyVideoIdPatch::class, LegacyVideoIdPatch::class,
OverrideSpeedHookPatch::class OverrideSpeedHookPatch::class,
SharedResourceIdPatch::class
] ]
) )
@YouTubeCompatibility @YouTubeCompatibility
@Version("0.0.1") @Version("0.0.1")
class VideoSpeedBytecodePatch : BytecodePatch( class VideoSpeedBytecodePatch : BytecodePatch(
listOf( listOf(
LiveLabelFingerprint,
VideoSpeedSettingsFingerprint VideoSpeedSettingsFingerprint
) )
) { ) {
override fun execute(context: BytecodeContext): PatchResult { override fun execute(context: BytecodeContext): PatchResult {
LiveLabelFingerprint.result?.mutableMethod?.let {
with (it.implementation!!.instructions) {
for ((index, instructions) in this.withIndex()) {
if (instructions.opcode != Opcode.INVOKE_VIRTUAL) continue
if ((instructions as BuilderInstruction35c).reference.toString() !=
"Landroid/widget/TextView;->setText(Ljava/lang/CharSequence;)V") continue
insertIndex = index + 1
it.addInstruction(
insertIndex,
"invoke-static {}, $INTEGRATIONS_VIDEO_SPEED_CLASS_DESCRIPTOR->liveVideoStarted()V"
)
break
}
}
if (insertIndex == 0) return LiveLabelFingerprint.toErrorResult()
} ?: return LiveLabelFingerprint.toErrorResult()
with(OverrideSpeedHookPatch.videoSpeedChangedResult) { with(OverrideSpeedHookPatch.videoSpeedChangedResult) {
val index = scanResult.patternScanResult!!.endIndex val index = scanResult.patternScanResult!!.endIndex
val register = val register =
@ -62,5 +86,6 @@ class VideoSpeedBytecodePatch : BytecodePatch(
private companion object { private companion object {
const val INTEGRATIONS_VIDEO_SPEED_CLASS_DESCRIPTOR = const val INTEGRATIONS_VIDEO_SPEED_CLASS_DESCRIPTOR =
"$VIDEO_PATH/VideoSpeedPatch;" "$VIDEO_PATH/VideoSpeedPatch;"
var insertIndex: Int = 0
} }
} }