fix(Shorts components): Hide sound button doesn't work (A/B tests)

This commit is contained in:
inotia00 2024-06-27 23:44:44 +09:00
parent ea2f4eac25
commit df97e5340a
3 changed files with 23 additions and 24 deletions

View File

@ -13,7 +13,6 @@ import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.litho.LithoFilterPatch
import app.revanced.patches.youtube.shorts.components.fingerprints.ShortsButtonFingerprint
import app.revanced.patches.youtube.shorts.components.fingerprints.ShortsPaidPromotionFingerprint
import app.revanced.patches.youtube.shorts.components.fingerprints.ShortsPivotFingerprint
import app.revanced.patches.youtube.shorts.components.fingerprints.ShortsPivotLegacyFingerprint
import app.revanced.patches.youtube.shorts.components.fingerprints.ShortsSubscriptionsTabletFingerprint
import app.revanced.patches.youtube.shorts.components.fingerprints.ShortsSubscriptionsTabletParentFingerprint
@ -27,17 +26,19 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelDynRemix
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelDynShare
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelForcedMuteButton
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelPivotButton
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelPlayerFooter
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelPlayerRightPivotV2Size
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelRightDislikeIcon
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelRightLikeIcon
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.RightComment
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.patches.youtube.video.information.VideoInformationPatch
import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT
import app.revanced.util.getTargetIndexOrThrow
import app.revanced.util.getTargetIndexReversedOrThrow
import app.revanced.util.getTargetIndexWithReferenceOrThrow
import app.revanced.util.getWideLiteralInstructionIndex
import app.revanced.util.literalInstructionHook
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
@ -45,7 +46,6 @@ import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.WideLiteralInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
@Suppress("unused")
@ -65,7 +65,6 @@ object ShortsComponentPatch : BaseBytecodePatch(
fingerprints = setOf(
ShortsButtonFingerprint,
ShortsPaidPromotionFingerprint,
ShortsPivotFingerprint,
ShortsPivotLegacyFingerprint,
ShortsSubscriptionsTabletParentFingerprint,
TextComponentSpecFingerprint
@ -134,8 +133,11 @@ object ShortsComponentPatch : BaseBytecodePatch(
// region patch for hide sound button
ShortsPivotLegacyFingerprint.result?.let {
it.mutableMethod.apply {
val shortsPivotLegacyFingerprintResult = ShortsPivotLegacyFingerprint.result
if (shortsPivotLegacyFingerprintResult != null) {
// Legacy method.
shortsPivotLegacyFingerprintResult.mutableMethod.apply {
val targetIndex = getWideLiteralInstructionIndex(ReelForcedMuteButton)
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
@ -150,23 +152,19 @@ object ShortsComponentPatch : BaseBytecodePatch(
""", ExternalLabel("hide", getInstruction(jumpIndex))
)
}
} ?: ShortsPivotFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val constCalls = implementation!!.instructions.withIndex()
.filter { instruction ->
(instruction.value as? WideLiteralInstruction)?.wideLiteral == ReelPivotButton
}
val targetIndex = constCalls.elementAt(constCalls.size - 1).index
val insertIndex =
getTargetIndexReversedOrThrow(targetIndex, Opcode.INVOKE_STATIC) + 1
if (insertIndex == 0)
throw PatchException("insert index not found")
} else if (ReelPlayerRightPivotV2Size != -1L) {
// Invoke Sound button dimen into integrations.
val smaliInstruction = """
invoke-static {v$REGISTER_TEMPLATE_REPLACEMENT}, $SHORTS_CLASS_DESCRIPTOR->getShortsSoundButtonDimenId(I)I
move-result v$REGISTER_TEMPLATE_REPLACEMENT
"""
hideButtons(
insertIndex,
"hideShortsSoundButton(Ljava/lang/Object;)Ljava/lang/Object;"
)
}
context.literalInstructionHook(
ReelPlayerRightPivotV2Size,
smaliInstruction
)
} else {
throw PatchException("ReelPlayerRightPivotV2Size is not found")
}
// endregion

View File

@ -79,8 +79,8 @@ object SharedResourceIdPatch : ResourcePatch() {
var ReelDynRemix = -1L
var ReelDynShare = -1L
var ReelForcedMuteButton = -1L
var ReelPivotButton = -1L
var ReelPlayerFooter = -1L
var ReelPlayerRightPivotV2Size = -1L
var ReelRightDislikeIcon = -1L
var ReelRightLikeIcon = -1L
var ReelTimeBarPlayedColor = -1L
@ -176,8 +176,8 @@ object SharedResourceIdPatch : ResourcePatch() {
ReelDynRemix = getId(ID, "reel_dyn_remix")
ReelDynShare = getId(ID, "reel_dyn_share")
ReelForcedMuteButton = getId(ID, "reel_player_forced_mute_button")
ReelPivotButton = getId(ID, "reel_pivot_button")
ReelPlayerFooter = getId(LAYOUT, "reel_player_dyn_footer_vert_stories3")
ReelPlayerRightPivotV2Size = getId(DIMEN, "reel_player_right_pivot_v2_size")
ReelRightDislikeIcon = getId(DRAWABLE, "reel_right_dislike_icon")
ReelRightLikeIcon = getId(DRAWABLE, "reel_right_like_icon")
ReelTimeBarPlayedColor = getId(COLOR, "reel_time_bar_played_color")

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="dimen" name="revanced_zero_padding">0.0dip</item>
<item type="dimen" name="revanced_edit_text_dialog_min_width_major">80.0%</item>
<item type="dimen" name="revanced_edit_text_dialog_min_width_minor">90.0%</item>
</resources>