fix(YouTube - Spoof video streams): Make it work on 21.x (#6705)
Co-authored-by: wowitsjack <no@email> Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
parent
f045923cef
commit
fdfed3c9dd
8 changed files with 24 additions and 22 deletions
|
|
@ -1,6 +1,6 @@
|
|||
package app.revanced.extension.youtube.patches;
|
||||
|
||||
import android.widget.ImageView;
|
||||
import android.view.View;
|
||||
|
||||
import app.revanced.extension.shared.Logger;
|
||||
import app.revanced.extension.shared.Utils;
|
||||
|
|
@ -46,7 +46,7 @@ public class ExitFullscreenPatch {
|
|||
// To fix this, push the perform click to the back fo the main thread,
|
||||
// and by then the overlay controls will be visible since the video is now finished.
|
||||
Utils.runOnMainThreadDelayed(() -> {
|
||||
ImageView button = PlayerControlsPatch.fullscreenButtonRef.get();
|
||||
View button = PlayerControlsPatch.fullscreenButtonRef.get();
|
||||
if (button == null) {
|
||||
Logger.printDebug(() -> "Fullscreen button is null, cannot click");
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -109,13 +109,13 @@ public final class HidePlayerOverlayButtonsPatch {
|
|||
/**
|
||||
* Injection point.
|
||||
*/
|
||||
public static ImageView hideFullscreenButton(ImageView imageView) {
|
||||
public static View hideFullscreenButton(View view) {
|
||||
if (!Settings.HIDE_FULLSCREEN_BUTTON.get()) {
|
||||
return imageView;
|
||||
return view;
|
||||
}
|
||||
|
||||
if (imageView != null) {
|
||||
imageView.setVisibility(View.GONE);
|
||||
if (view != null) {
|
||||
view.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package app.revanced.extension.youtube.patches;
|
|||
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
|
|
@ -11,7 +10,7 @@ import app.revanced.extension.shared.Logger;
|
|||
@SuppressWarnings("unused")
|
||||
public class PlayerControlsPatch {
|
||||
|
||||
public static WeakReference<ImageView> fullscreenButtonRef = new WeakReference<>(null);
|
||||
public static WeakReference<View> fullscreenButtonRef = new WeakReference<>(null);
|
||||
|
||||
private static boolean fullscreenButtonVisibilityCallbacksExist() {
|
||||
return false; // Modified during patching if needed.
|
||||
|
|
@ -20,8 +19,8 @@ public class PlayerControlsPatch {
|
|||
/**
|
||||
* Injection point.
|
||||
*/
|
||||
public static void setFullscreenCloseButton(ImageView imageButton) {
|
||||
fullscreenButtonRef = new WeakReference<>(imageButton);
|
||||
public static void setFullscreenCloseButton(View button) {
|
||||
fullscreenButtonRef = new WeakReference<>(button);
|
||||
Logger.printDebug(() -> "Fullscreen button set");
|
||||
|
||||
if (!fullscreenButtonVisibilityCallbacksExist()) {
|
||||
|
|
@ -30,13 +29,13 @@ public class PlayerControlsPatch {
|
|||
|
||||
// Add a global listener, since the protected method
|
||||
// View#onVisibilityChanged() does not have any call backs.
|
||||
imageButton.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
button.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
int lastVisibility = View.VISIBLE;
|
||||
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
try {
|
||||
final int visibility = imageButton.getVisibility();
|
||||
final int visibility = button.getVisibility();
|
||||
if (lastVisibility != visibility) {
|
||||
lastVisibility = visibility;
|
||||
|
||||
|
|
|
|||
|
|
@ -216,10 +216,10 @@ internal fun spoofVideoStreamsPatch(
|
|||
// A proper fix may include modifying the request body to match the platforms expected body.
|
||||
|
||||
buildMediaDataSourceMethod.apply {
|
||||
val targetIndex = instructions.count() - 1
|
||||
// Find return-void, not the last instruction, which may be a throw in an error branch
|
||||
// where p0 is overwritten by new-instance IllegalArgumentException.
|
||||
val targetIndex = indexOfFirstInstructionOrThrow(Opcode.RETURN_VOID)
|
||||
|
||||
// Instructions are added just before the method returns,
|
||||
// so there's no concern of clobbering in-use registers.
|
||||
addInstructions(
|
||||
targetIndex,
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@ internal val BytecodePatchContext.fullscreenButtonMethodMatch by composingFirstM
|
|||
returnType("V")
|
||||
instructions(
|
||||
ResourceType.ID("fullscreen_button"),
|
||||
Opcode.CHECK_CAST()
|
||||
Opcode.INVOKE_VIRTUAL(), // findViewById call.
|
||||
Opcode.MOVE_RESULT_OBJECT() // The actual view, not a check-cast in 21.x.
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -169,14 +169,16 @@ val hidePlayerOverlayButtonsPatch = bytecodePatch(
|
|||
|
||||
fullscreenButtonMethodMatch.let {
|
||||
it.method.apply {
|
||||
val castIndex = it[1]
|
||||
val insertIndex = castIndex + 1
|
||||
val insertRegister = getInstruction<OneRegisterInstruction>(castIndex).registerA
|
||||
// Youtube 21.x doesn't cast the fullscreen button to ImageView anymore,
|
||||
// so match on move-result-object after findViewById instead of check-cast.
|
||||
val moveResultIndex = it[2]
|
||||
val insertIndex = moveResultIndex + 1
|
||||
val insertRegister = getInstruction<OneRegisterInstruction>(moveResultIndex).registerA
|
||||
|
||||
addInstructionsWithLabels(
|
||||
insertIndex,
|
||||
"""
|
||||
invoke-static { v$insertRegister }, ${EXTENSION_CLASS_DESCRIPTOR}->hideFullscreenButton(Landroid/widget/ImageView;)Landroid/widget/ImageView;
|
||||
invoke-static { v$insertRegister }, ${EXTENSION_CLASS_DESCRIPTOR}->hideFullscreenButton(Landroid/view/View;)Landroid/view/View;
|
||||
move-result-object v$insertRegister
|
||||
if-nez v$insertRegister, :show
|
||||
return-void
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ internal val BytecodePatchContext.overlayViewInflateMethodMatch by composingFirs
|
|||
instructions(
|
||||
ResourceType.ID("heatseeker_viewstub"),
|
||||
ResourceType.ID("fullscreen_button"),
|
||||
allOf(Opcode.CHECK_CAST(), type("Landroid/widget/ImageView;")),
|
||||
Opcode.CHECK_CAST(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -261,7 +261,7 @@ val playerControlsPatch = bytecodePatch(
|
|||
addInstruction(
|
||||
index + 1,
|
||||
"invoke-static { v$register }, " +
|
||||
"$EXTENSION_CLASS_DESCRIPTOR->setFullscreenCloseButton(Landroid/widget/ImageView;)V",
|
||||
"$EXTENSION_CLASS_DESCRIPTOR->setFullscreenCloseButton(Landroid/view/View;)V",
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue