diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/downloads/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/downloads/Fingerprints.kt index a2b1530b8b..9b8d09bfa7 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/downloads/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/downloads/Fingerprints.kt @@ -1,7 +1,9 @@ package app.revanced.patches.reddit.customclients.boostforreddit.fix.downloads -import app.revanced.patcher.fingerprint +import app.revanced.patcher.BytecodePatchContextMethodMatching.gettingFirstMutableMethodDeclaratively +import app.revanced.patcher.patch.BytecodePatchContext -internal val downloadAudioFingerprint = fingerprint { - strings("/DASH_audio.mp4", "/audio") -} +internal val BytecodePatchContext.downloadAudioMethod by gettingFirstMutableMethodDeclaratively( + "/DASH_audio.mp4", + "/audio" +) diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/downloads/FixAudioMissingInDownloadsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/downloads/FixAudioMissingInDownloadsPatch.kt index ec0f99ec7a..8df738f2b9 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/downloads/FixAudioMissingInDownloadsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/downloads/FixAudioMissingInDownloadsPatch.kt @@ -2,12 +2,15 @@ package app.revanced.patches.reddit.customclients.boostforreddit.fix.downloads import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.extensions.replaceInstruction -import app.revanced.patcher.patch.bytecodePatch +import app.revanced.patcher.patch.creatingBytecodePatch +import app.revanced.util.findInstructionIndicesReversed +import app.revanced.util.getReference +import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.StringReference -@Suppress("unused") -val fixAudioMissingInDownloadsPatch = bytecodePatch( - name = "Fix missing audio in video downloads", +@Suppress("unused", "ObjectPropertyName") +val `Fix missing audio in video downloads` by creatingBytecodePatch( description = "Fixes audio missing in videos downloaded from v.redd.it.", ) { compatibleWith("com.rubenmayayo.reddit") @@ -18,12 +21,15 @@ val fixAudioMissingInDownloadsPatch = bytecodePatch( "/audio" to "/DASH_AUDIO_64.mp4", ) - downloadAudioFingerprint.method.apply { - downloadAudioFingerprint.stringMatches.forEach { match -> - val replacement = endpointReplacements[match.string] - val register = getInstruction(match.index).registerA - - replaceInstruction(match.index, "const-string v$register, \"$replacement\"") + downloadAudioMethod.apply { + endpointReplacements.forEach { (target, replacement) -> + // Find all occurrences of the target string in the method + findInstructionIndicesReversed { + opcode == Opcode.CONST_STRING && getReference()?.string == target + }.forEach { index -> + val register = getInstruction(index).registerA + replaceInstruction(index, "const-string v$register, \"$replacement\"") + } } } }