mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-03 16:14:28 +02:00
refactor(sponsorblock): use better patch method
This commit is contained in:
parent
4e9eff5de2
commit
bb16f48ba3
@ -1,5 +1,6 @@
|
||||
package app.revanced.patches.youtube.misc.sponsorblock.bytecode.patch
|
||||
|
||||
import app.revanced.extensions.toErrorResult
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.annotation.Version
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
@ -21,7 +22,6 @@ import org.jf.dexlib2.Opcode
|
||||
import org.jf.dexlib2.builder.BuilderInstruction
|
||||
import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction
|
||||
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction22c
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction35c
|
||||
import org.jf.dexlib2.iface.reference.MethodReference
|
||||
|
||||
@ -58,11 +58,10 @@ class SponsorBlockBytecodePatch : BytecodePatch(
|
||||
Get the instance of the seekbar rectangle
|
||||
*/
|
||||
for ((index, instruction) in insertInstructions.withIndex()) {
|
||||
if (instruction.opcode != Opcode.IGET_OBJECT) continue
|
||||
val seekbarRegister = (instruction as Instruction22c).registerB
|
||||
if (instruction.opcode != Opcode.INVOKE_DIRECT_RANGE) continue
|
||||
insertMethod.addInstruction(
|
||||
index - 1,
|
||||
"invoke-static {v$seekbarRegister}, $INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->setSponsorBarRect(Ljava/lang/Object;)V"
|
||||
index,
|
||||
"invoke-static/range {p0 .. p0}, $INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->setSponsorBarRect(Ljava/lang/Object;)V"
|
||||
)
|
||||
break
|
||||
}
|
||||
@ -124,10 +123,10 @@ class SponsorBlockBytecodePatch : BytecodePatch(
|
||||
|
||||
// set SegmentHelperLayout.context to the player layout instance
|
||||
val instanceRegister = 0
|
||||
NextGenWatchLayoutFingerprint.result!!.mutableMethod.addInstruction(
|
||||
3, // after super call
|
||||
NextGenWatchLayoutFingerprint.result?.mutableMethod?.addInstruction(
|
||||
3,
|
||||
"invoke-static/range {p$instanceRegister}, $INTEGRATIONS_PLAYER_CONTROLLER_CLASS_DESCRIPTOR->addSkipSponsorView15(Landroid/view/View;)V"
|
||||
)
|
||||
) ?: return NextGenWatchLayoutFingerprint.toErrorResult()
|
||||
|
||||
context.injectInit("FirstRun", "initializationSB")
|
||||
context.updatePatchStatus("Sponsorblock")
|
||||
|
@ -25,9 +25,9 @@ import org.jf.dexlib2.AccessFlags
|
||||
import org.jf.dexlib2.Opcode
|
||||
import org.jf.dexlib2.builder.MutableMethodImplementation
|
||||
import org.jf.dexlib2.builder.instruction.BuilderInstruction35c
|
||||
import org.jf.dexlib2.dexbacked.reference.DexBackedMethodReference
|
||||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction21c
|
||||
import org.jf.dexlib2.iface.instruction.formats.Instruction31i
|
||||
import org.jf.dexlib2.iface.reference.FieldReference
|
||||
import org.jf.dexlib2.iface.reference.MethodReference
|
||||
@ -145,29 +145,27 @@ class MainstreamVideoIdPatch : BytecodePatch(
|
||||
|
||||
|
||||
with (HookTimebarPatch.emptyColorMethod) {
|
||||
val timebarResult = TimebarFingerprint.result ?: return TimebarFingerprint.toErrorResult()
|
||||
val timebarInstructions = timebarResult.method.implementation!!.instructions
|
||||
val methodReference =
|
||||
(timebarInstructions.elementAt(2) as ReferenceInstruction).reference as MethodReference
|
||||
val timeBarResult = TimebarFingerprint.result ?: return TimebarFingerprint.toErrorResult()
|
||||
val timeBarInstructions = timeBarResult.method.implementation!!.instructions
|
||||
val timeBarReference =
|
||||
(timeBarInstructions.elementAt(2) as ReferenceInstruction).reference as MethodReference
|
||||
|
||||
val instructions = implementation!!.instructions
|
||||
|
||||
reactReference =
|
||||
((instructions.elementAt(instructions.count() - 3) as ReferenceInstruction).reference as FieldReference).name
|
||||
|
||||
|
||||
for ((index, instruction) in instructions.withIndex()) {
|
||||
if (instruction.opcode != Opcode.CHECK_CAST) continue
|
||||
val primaryRegister = (instruction as Instruction21c).registerA + 1
|
||||
val secondaryRegister = primaryRegister + 1
|
||||
addInstructions(
|
||||
index, """
|
||||
invoke-virtual {p0}, $methodReference
|
||||
move-result-wide v$primaryRegister
|
||||
invoke-static {v$primaryRegister, v$secondaryRegister}, $VideoInformation->setCurrentVideoLength(J)V
|
||||
"""
|
||||
)
|
||||
break
|
||||
val fieldReference = (instruction as? ReferenceInstruction)?.reference as? DexBackedMethodReference
|
||||
if (fieldReference?.let { it.name == timeBarReference.name } == true) {
|
||||
val primaryRegister = (instructions.elementAt(index + 1) as OneRegisterInstruction).registerA
|
||||
val secondaryRegister = primaryRegister + 1
|
||||
addInstruction(
|
||||
index + 3,
|
||||
"invoke-static {v$primaryRegister, v$secondaryRegister}, $VideoInformation->setCurrentVideoLength(J)V"
|
||||
)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user