diff --git a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/general/OpenChannelOfLiveAvatarPatch.java b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/general/OpenChannelOfLiveAvatarPatch.java index bce03fedf..448a94f54 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/general/OpenChannelOfLiveAvatarPatch.java +++ b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/general/OpenChannelOfLiveAvatarPatch.java @@ -2,6 +2,7 @@ package app.revanced.extension.youtube.patches.general; import androidx.annotation.Nullable; +import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import app.revanced.extension.shared.utils.Logger; @@ -15,9 +16,14 @@ public final class OpenChannelOfLiveAvatarPatch { Settings.CHANGE_LIVE_RING_CLICK_ACTION.get(); private static final AtomicBoolean engagementPanelOpen = new AtomicBoolean(false); - private static volatile boolean liveChannelAvatarClicked = false; private static volatile String videoId = ""; + /** + * If the video is open by clicking live ring, this key does not exists. + */ + private static final String VIDEO_THUMBNAIL_VIEW_KEY = + "VideoPresenterConstants.VIDEO_THUMBNAIL_VIEW_KEY"; + public static void showEngagementPanel(@Nullable Object object) { engagementPanelOpen.set(object != null); } @@ -26,19 +32,15 @@ public final class OpenChannelOfLiveAvatarPatch { engagementPanelOpen.compareAndSet(true, false); } - public static void liveChannelAvatarClicked() { - liveChannelAvatarClicked = true; - } - public static boolean openChannelOfLiveAvatar() { try { if (!CHANGE_LIVE_RING_CLICK_ACTION) { return false; } - if (!liveChannelAvatarClicked) { + if (engagementPanelOpen.get()) { return false; } - if (engagementPanelOpen.get()) { + if (videoId.isEmpty()) { return false; } VideoDetailsRequest request = VideoDetailsRequest.getRequestForVideoId(videoId); @@ -46,7 +48,6 @@ public final class OpenChannelOfLiveAvatarPatch { String channelId = request.getInfo(); if (channelId != null) { videoId = ""; - liveChannelAvatarClicked = false; VideoUtils.openChannel(channelId); return true; } @@ -57,12 +58,15 @@ public final class OpenChannelOfLiveAvatarPatch { return false; } - public static void openChannelOfLiveAvatar(String newlyLoadedVideoId) { + public static void openChannelOfLiveAvatar(Map playbackStartDescriptorMap, String newlyLoadedVideoId) { try { if (!CHANGE_LIVE_RING_CLICK_ACTION) { return; } - if (!liveChannelAvatarClicked) { + if (playbackStartDescriptorMap == null) { + return; + } + if (playbackStartDescriptorMap.containsKey(VIDEO_THUMBNAIL_VIEW_KEY)) { return; } if (engagementPanelOpen.get()) { diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/general/livering/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/general/livering/Fingerprints.kt index 873ef9df8..b41ad0aac 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/general/livering/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/general/livering/Fingerprints.kt @@ -1,6 +1,5 @@ package app.revanced.patches.youtube.general.livering -import app.revanced.patches.youtube.utils.resourceid.elementsImage import app.revanced.util.fingerprint.legacyFingerprint import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstruction @@ -10,14 +9,6 @@ import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.Method import com.android.tools.smali.dexlib2.iface.reference.MethodReference -internal val elementsImageFingerprint = legacyFingerprint( - name = "elementsImageFingerprint", - returnType = "Landroid/view/View;", - accessFlags = AccessFlags.PRIVATE or AccessFlags.STATIC, - parameters = listOf("Landroid/view/View;"), - literals = listOf(elementsImage), -) - internal val clientSettingEndpointFingerprint = legacyFingerprint( name = "clientSettingEndpointFingerprint", returnType = "V", diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/general/livering/OpenChannelOfLiveAvatarPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/general/livering/OpenChannelOfLiveAvatarPatch.kt index 7f7798982..dc511073e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/general/livering/OpenChannelOfLiveAvatarPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/general/livering/OpenChannelOfLiveAvatarPatch.kt @@ -1,6 +1,5 @@ package app.revanced.patches.youtube.general.livering -import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.getInstruction @@ -10,16 +9,18 @@ import app.revanced.patches.youtube.utils.engagement.engagementPanelHookPatch import app.revanced.patches.youtube.utils.engagement.hookEngagementPanelState import app.revanced.patches.youtube.utils.extension.Constants.GENERAL_PATH import app.revanced.patches.youtube.utils.patch.PatchList.CHANGE_LIVE_RING_CLICK_ACTION -import app.revanced.patches.youtube.utils.resourceid.sharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.ResourceUtils.addPreference import app.revanced.patches.youtube.utils.settings.settingsPatch import app.revanced.patches.youtube.video.playbackstart.playbackStartDescriptorPatch import app.revanced.patches.youtube.video.playbackstart.playbackStartVideoIdReference import app.revanced.util.fingerprint.methodOrThrow +import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.indexOfFirstInstructionReversedOrThrow import com.android.tools.smali.dexlib2.Opcode +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.reference.MethodReference private const val EXTENSION_CLASS_DESCRIPTOR = "$GENERAL_PATH/OpenChannelOfLiveAvatarPatch;" @@ -33,18 +34,12 @@ val openChannelOfLiveAvatarPatch = bytecodePatch( dependsOn( settingsPatch, - sharedResourceIdPatch, playbackStartDescriptorPatch, engagementPanelHookPatch, ) execute { - elementsImageFingerprint.methodOrThrow().addInstruction( - 0, - "invoke-static { }, $EXTENSION_CLASS_DESCRIPTOR->liveChannelAvatarClicked()V" - ) - hookEngagementPanelState(EXTENSION_CLASS_DESCRIPTOR) clientSettingEndpointFingerprint.methodOrThrow().apply { @@ -66,6 +61,14 @@ val openChannelOfLiveAvatarPatch = bytecodePatch( val playbackStartIndex = indexOfPlaybackStartDescriptorInstruction(this) + 1 val playbackStartRegister = getInstruction(playbackStartIndex).registerA + val mapIndex = indexOfFirstInstructionOrThrow(playbackStartIndex) { + val reference = getReference() + opcode == Opcode.INVOKE_STATIC && + reference?.returnType == "Ljava/lang/Object;" && + reference.parameterTypes.firstOrNull() == "Ljava/util/Map;" + } + val mapRegister = getInstruction(mapIndex).registerC + freeIndex = indexOfFirstInstructionOrThrow(playbackStartIndex, Opcode.CONST_STRING) freeRegister = getInstruction(freeIndex).registerA @@ -73,7 +76,7 @@ val openChannelOfLiveAvatarPatch = bytecodePatch( playbackStartIndex + 1, """ invoke-virtual { v$playbackStartRegister }, $playbackStartVideoIdReference move-result-object v$freeRegister - invoke-static { v$freeRegister }, $EXTENSION_CLASS_DESCRIPTOR->openChannelOfLiveAvatar(Ljava/lang/String;)V + invoke-static { v$mapRegister, v$freeRegister }, $EXTENSION_CLASS_DESCRIPTOR->openChannelOfLiveAvatar(Ljava/util/Map;Ljava/lang/String;)V """ ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt index 36fcedfee..29151695f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt @@ -83,8 +83,6 @@ var easySeekEduContainer = -1L private set var editSettingsAction = -1L private set -var elementsImage = -1L - private set var endScreenElementLayoutCircle = -1L private set var endScreenElementLayoutIcon = -1L @@ -390,10 +388,6 @@ internal val sharedResourceIdPatch = resourcePatch( STRING, "edit_settings_action" ] - elementsImage = resourceMappings[ - ID, - "elements_image" - ] endScreenElementLayoutCircle = resourceMappings[ LAYOUT, "endscreen_element_layout_circle"