Skip to content

Commit

Permalink
fix(youtube/sponsorblock): fix some segments skipping slightly too la…
Browse files Browse the repository at this point in the history
…te (#2634)
  • Loading branch information
LisoUseInAIKyrios committed Jul 14, 2023
1 parent 5c63fa2 commit 3175431
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 36 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
Expand Down Expand Up @@ -44,7 +43,6 @@ class VideoInformationPatch : BytecodePatch(
PlayerInitFingerprint,
CreateVideoPlayerSeekbarFingerprint,
PlayerControllerSetTimeReferenceFingerprint,
VideoTimeFingerprint,
OnPlaybackSpeedItemClickFingerprint,
)
) {
Expand Down Expand Up @@ -118,18 +116,10 @@ class VideoInformationPatch : BytecodePatch(
.getMethod() as MutableMethod
}

/*
* Set the high precision video time method
*/
highPrecisionTimeMethod =
(object : MethodFingerprint("V", null, listOf("J", "J", "J", "J", "I", "L"), null) {}).also {
it.resolve(context, VideoTimeFingerprint.result!!.classDef)
}.result!!.mutableMethod

/*
* Hook the methods which set the time
*/
highPrecisionTimeHook(INTEGRATIONS_CLASS_DESCRIPTOR, "setVideoTimeHighPrecision")
videoTimeHook(INTEGRATIONS_CLASS_DESCRIPTOR, "setVideoTime")


/*
Expand Down Expand Up @@ -164,9 +154,6 @@ class VideoInformationPatch : BytecodePatch(
private lateinit var timeMethod: MutableMethod
private var timeInitInsertIndex = 2

private lateinit var highPrecisionTimeMethod: MutableMethod
private var highPrecisionInsertIndex = 0

private fun MutableMethod.insert(insertIndex: Int, register: String, descriptor: String) =
addInstruction(insertIndex, "invoke-static { $register }, $descriptor")

Expand Down Expand Up @@ -202,20 +189,6 @@ class VideoInformationPatch : BytecodePatch(
"$targetMethodClass->$targetMethodName(J)V"
)

/**
* Hook the high precision video time.
* The hooks is called extremely often (10 to 15 times a seconds), so use with caution.
* Note: the hook is usually called _off_ the main thread
*
* @param targetMethodClass The descriptor for the static method to invoke when the player controller is created.
* @param targetMethodName The name of the static method to invoke when the player controller is created.
*/
internal fun highPrecisionTimeHook(targetMethodClass: String, targetMethodName: String) =
highPrecisionTimeMethod.insertTimeHook(
highPrecisionInsertIndex++,
"$targetMethodClass->$targetMethodName(J)V"
)

private fun getReference(instructions: List<BuilderInstruction>, offset: Int, opcode: Opcode) =
(instructions[instructions.indexOfFirst { it.opcode == opcode } + offset] as ReferenceInstruction)
.reference.toString()
Expand Down

0 comments on commit 3175431

Please sign in to comment.