feat(youtube/custom-seekbar-color): change the color of the last watched progress bar https://github.com/inotia00/ReVanced_Extended/issues/748

This commit is contained in:
inotia00
2023-05-06 01:43:25 +09:00
parent 6c742b4e99
commit ae49cd421a
13 changed files with 169 additions and 81 deletions

View File

@ -0,0 +1,19 @@
package app.revanced.patches.youtube.misc.litho.fingerprints
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 LithoThemeFingerprint : MethodFingerprint(
returnType = "V",
access = AccessFlags.PROTECTED or AccessFlags.FINAL,
parameters = listOf("L"),
opcodes = listOf(
Opcode.IF_NEZ,
Opcode.IGET_OBJECT,
Opcode.INVOKE_VIRTUAL, // Paint.setColor: inject point
Opcode.RETURN_VOID
),
customFingerprint = { it.name == "onBoundsChange" }
)

View File

@ -0,0 +1,65 @@
package app.revanced.patches.youtube.misc.litho.patch
import app.revanced.extensions.toErrorResult
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.litho.fingerprints.LithoThemeFingerprint
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.instruction.formats.Instruction35c
import org.jf.dexlib2.iface.reference.MethodReference
@Name("litho-theme-hook")
@YouTubeCompatibility
@Version("0.0.1")
class LithoThemePatch : BytecodePatch(
listOf(
LithoThemeFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
LithoThemeFingerprint.result?.mutableMethod?.let {
with (it.implementation!!.instructions) {
for (index in size - 1 downTo 0) {
val invokeInstruction = this[index] as? ReferenceInstruction ?: continue
if ((invokeInstruction.reference as MethodReference).name != "setColor") continue
insertIndex = index
insertRegister = (this[index] as Instruction35c).registerD
insertMethod = it
break
}
}
} ?: return LithoThemeFingerprint.toErrorResult()
return PatchResultSuccess()
}
companion object {
private var offset = 0
private var insertIndex: Int = 0
private var insertRegister: Int = 0
private lateinit var insertMethod: MutableMethod
fun injectCall(
methodDescriptor: String
) {
insertMethod.addInstructions(
insertIndex + offset, """
invoke-static {v$insertRegister}, $methodDescriptor
move-result v$insertRegister
"""
)
offset += 2
}
}
}