diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/ReturnYouTubeDislikePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/ReturnYouTubeDislikePatch.kt index e94b694853..35879b1c67 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/ReturnYouTubeDislikePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/ReturnYouTubeDislikePatch.kt @@ -55,7 +55,8 @@ object ReturnYouTubeDislikePatch : BytecodePatch( DislikeFingerprint, RemoveLikeFingerprint, RollingNumberSetterFingerprint, - RollingNumberTextViewFingerprint + RollingNumberTextViewFingerprint, + RollingNumberMeasureTextParentFingerprint ) ) { private const val INTEGRATIONS_CLASS_DESCRIPTOR = @@ -181,6 +182,31 @@ object ReturnYouTubeDislikePatch : BytecodePatch( } } ?: throw RollingNumberSetterFingerprint.exception + // Rolling Number text views use the measured width of the raw string for layout. + // Modify the measure text calculation to include the left drawable separator if needed. + RollingNumberMeasureTextFingerprint.also { + if (!it.resolve(context, RollingNumberMeasureTextParentFingerprint.result!!.classDef)) + throw it.exception + }.result?.also { + it.mutableMethod.apply { + val returnInstructionIndex = it.scanResult.patternScanResult!!.endIndex + val measuredTextWidthRegister = + getInstruction(returnInstructionIndex).registerA + + replaceInstruction( // Replace instruction to preserve control flow label. + returnInstructionIndex, + "invoke-static {p1, v$measuredTextWidthRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->onRollingNumberMeasured(Ljava/lang/String;F)F" + ) + addInstructions( + returnInstructionIndex + 1, + """ + move-result v$measuredTextWidthRegister + return v$measuredTextWidthRegister + """ + ) + } + } ?: throw RollingNumberMeasureTextFingerprint.exception + // The rolling number Span is missing styling since it's initially set as a String. // Modify the UI text view and use the styled like/dislike Span. RollingNumberTextViewFingerprint.result?.let { diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/RollingNumberMeasureTextFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/RollingNumberMeasureTextFingerprint.kt new file mode 100644 index 0000000000..e3469e4546 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/RollingNumberMeasureTextFingerprint.kt @@ -0,0 +1,23 @@ +package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.Opcode + +/** + * Resolves to class found in [RollingNumberMeasureTextParentFingerprint]. + */ +object RollingNumberMeasureTextFingerprint : MethodFingerprint( + returnType = "F", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("Ljava/lang/String;"), + opcodes = listOf( + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.ADD_FLOAT_2ADDR, + Opcode.ADD_INT_LIT8, + Opcode.GOTO, + Opcode.RETURN + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/RollingNumberMeasureTextParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/RollingNumberMeasureTextParentFingerprint.kt new file mode 100644 index 0000000000..1d8b16e856 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/RollingNumberMeasureTextParentFingerprint.kt @@ -0,0 +1,12 @@ +package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +object RollingNumberMeasureTextParentFingerprint : MethodFingerprint( + returnType = "Ljava/lang/String;", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf(), + strings = listOf("RollingNumberFontProperties{paint=") +) \ No newline at end of file