feat(YouTube/Description components): add Disable rolling number animations settings

This commit is contained in:
inotia00
2024-05-03 02:01:31 +09:00
parent 75449aa709
commit b09e3b6d86
7 changed files with 84 additions and 42 deletions

View File

@ -2,12 +2,16 @@ package app.revanced.patches.youtube.player.descriptions
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.litho.LithoFilterPatch
import app.revanced.patches.youtube.player.descriptions.fingerprints.EngagementPanelSubHeaderFingerprint
import app.revanced.patches.youtube.player.descriptions.fingerprints.TextViewComponentFingerprint
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.fingerprints.RollingNumberTextViewAnimationUpdateFingerprint
import app.revanced.patches.youtube.utils.fingerprints.RollingNumberTextViewFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH
import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR
import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch
@ -36,6 +40,7 @@ object DescriptionComponentsPatch : BaseBytecodePatch(
compatiblePackages = COMPATIBLE_PACKAGE,
fingerprints = setOf(
EngagementPanelSubHeaderFingerprint,
RollingNumberTextViewFingerprint,
TextViewComponentFingerprint
)
) {
@ -44,7 +49,49 @@ object DescriptionComponentsPatch : BaseBytecodePatch(
override fun execute(context: BytecodeContext) {
// patch for disable video description interaction and expand video description.
// region patch for disable rolling number animation
// RollingNumber is applied to YouTube v18.49.37+.
// In order to maintain compatibility with YouTube v18.48.39 or previous versions,
// This patch is applied only to the version after YouTube v18.49.37.
if (SettingsPatch.upward1849) {
RollingNumberTextViewAnimationUpdateFingerprint.resolve(
context,
RollingNumberTextViewFingerprint.resultOrThrow().classDef
)
RollingNumberTextViewAnimationUpdateFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val freeRegister = implementation!!.registerCount - parameters.size - 2
val imageSpanIndex = it.scanResult.patternScanResult!!.startIndex
val setTextIndex = getTargetIndexWithMethodReferenceName("setText")
addInstruction(setTextIndex, "nop")
addInstructionsWithLabels(
imageSpanIndex, """
invoke-static {}, $PLAYER_CLASS_DESCRIPTOR->disableRollingNumberAnimations()Z
move-result v$freeRegister
if-nez v$freeRegister, :disable_animations
""", ExternalLabel("disable_animations", getInstruction(setTextIndex))
)
}
}
/**
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE_SCREEN: PLAYER",
"SETTINGS: DESCRIPTION_COMPONENTS",
"SETTINGS: DISABLE_ROLLING_NUMBER_ANIMATIONS"
)
)
}
// endregion
// region patch for disable video description interaction and expand video description
// since these patches are still A/B tested, they are classified as 'Experimental flags'.
if (SettingsPatch.upward1902) {
TextViewComponentFingerprint.resultOrThrow().let {
@ -85,6 +132,8 @@ object DescriptionComponentsPatch : BaseBytecodePatch(
)
}
// endregion
LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR)
/**

View File

@ -0,0 +1,17 @@
package app.revanced.patches.youtube.utils.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
internal object RollingNumberTextViewAnimationUpdateFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Landroid/graphics/Bitmap;"),
opcodes = listOf(
Opcode.NEW_INSTANCE, // bitmap ImageSpan
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT
)
)

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.fingerprints
package app.revanced.patches.youtube.utils.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint

View File

@ -9,13 +9,13 @@ import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.youtube.utils.fingerprints.RollingNumberTextViewAnimationUpdateFingerprint
import app.revanced.patches.youtube.utils.fingerprints.RollingNumberTextViewFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH
import app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.fingerprints.RollingNumberMeasureAnimatedTextFingerprint
import app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.fingerprints.RollingNumberMeasureStaticLabelFingerprint
import app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.fingerprints.RollingNumberMeasureTextParentFingerprint
import app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.fingerprints.RollingNumberSetterFingerprint
import app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.fingerprints.RollingNumberTextViewAnimationUpdateFingerprint
import app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.fingerprints.RollingNumberTextViewFingerprint
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndex
import app.revanced.util.getTargetIndexWithMethodReferenceName
@ -33,8 +33,7 @@ object ReturnYouTubeDislikeRollingNumberPatch : BytecodePatch(
RollingNumberSetterFingerprint,
RollingNumberMeasureTextParentFingerprint,
RollingNumberTextViewFingerprint,
RollingNumberMeasureAnimatedTextFingerprint,
RollingNumberTextViewAnimationUpdateFingerprint
RollingNumberMeasureAnimatedTextFingerprint
)
) {
private const val INTEGRATIONS_RYD_CLASS_DESCRIPTOR =
@ -138,15 +137,16 @@ object ReturnYouTubeDislikeRollingNumberPatch : BytecodePatch(
// 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.resultOrThrow().let {
RollingNumberTextViewFingerprint.resultOrThrow().let { parentResult ->
// Initial TextView is set in this method.
val initiallyCreatedTextViewMethod = it.mutableMethod
val initiallyCreatedTextViewMethod = parentResult.mutableMethod
// Video less than 24 hours after uploaded, like counts will be updated in real time.
// Whenever like counts are updated, TextView is set in this method.
val realTimeUpdateTextViewMethod = it.mutableClass.methods.find { method ->
method.parameterTypes.first() == "Landroid/graphics/Bitmap;"
} ?: throw PatchException("Failed to find realTimeUpdateTextViewMethod")
val realTimeUpdateTextViewMethod =
RollingNumberTextViewAnimationUpdateFingerprint.also {
it.resolve(context, parentResult.classDef)
}.resultOrThrow().mutableMethod
arrayOf(
initiallyCreatedTextViewMethod,

View File

@ -1,30 +0,0 @@
package app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.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
internal object RollingNumberTextViewAnimationUpdateFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Landroid/graphics/Bitmap;"),
opcodes = listOf(
Opcode.NEW_INSTANCE, // bitmap ImageSpan
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.CONST_4,
Opcode.INVOKE_DIRECT,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT,
Opcode.CONST_16,
Opcode.INVOKE_VIRTUAL,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT,
Opcode.INT_TO_FLOAT,
Opcode.INVOKE_VIRTUAL, // set textview padding using bitmap width
),
customFingerprint = { _, classDef ->
classDef.superclass == "Landroid/support/v7/widget/AppCompatTextView;"
}
)