diff --git a/src/main/kotlin/app/revanced/patches/music/misc/quality/patch/VideoQualityPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/quality/patch/VideoQualityPatch.kt index e6ddac4ec8..803f8f9b21 100644 --- a/src/main/kotlin/app/revanced/patches/music/misc/quality/patch/VideoQualityPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/misc/quality/patch/VideoQualityPatch.kt @@ -63,11 +63,26 @@ class VideoQualityPatch : BytecodePatch( for ((index, instruction) in implementation!!.instructions.withIndex()) { if (instruction.opcode != Opcode.INVOKE_INTERFACE) continue - qualityReference = - getInstruction(index - 1).reference qIndexMethodName = ((getInstruction(index).reference) as MethodReference).name + val qIndexMethodClass = + ((getInstruction(index).reference) as MethodReference).definingClass + + for (qualityReferenceIndex in index downTo 0) { + if (getInstruction(qualityReferenceIndex).opcode != Opcode.IGET_OBJECT) continue + + val targetReference = + getInstruction(qualityReferenceIndex).reference + + if (!targetReference.toString() + .endsWith(qIndexMethodClass) + ) continue + + qualityReference = targetReference + break + } + addInstruction( 0, "invoke-static {p3}, $INTEGRATIONS_VIDEO_QUALITY_CLASS_DESCRIPTOR->userChangedQuality(I)V"