Skip to content

Commit

Permalink
feat(YouTube): Support version 19.43.41 (#3854)
Browse files Browse the repository at this point in the history
  • Loading branch information
LisoUseInAIKyrios authored and oSumAtrIX committed Nov 6, 2024
1 parent b7b97eb commit 0cad269
Show file tree
Hide file tree
Showing 59 changed files with 249 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@

/** @noinspection unused*/
public final class DisableFullscreenAmbientModePatch {
public static boolean enableFullScreenAmbientMode() {
return !Settings.DISABLE_FULLSCREEN_AMBIENT_MODE.get();

private static final boolean DISABLE_FULLSCREEN_AMBIENT_MODE = Settings.DISABLE_FULLSCREEN_AMBIENT_MODE.get();

/**
* Constant found in: androidx.window.embedding.DividerAttributes
*/
private static final int DIVIDER_ATTRIBUTES_COLOR_SYSTEM_DEFAULT = -16777216;

/**
* Injection point.
*/
public static int getFullScreenBackgroundColor(int originalColor) {
if (DISABLE_FULLSCREEN_AMBIENT_MODE) {
return DIVIDER_ATTRIBUTES_COLOR_SYSTEM_DEFAULT;
}

return originalColor;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package app.revanced.extension.youtube.patches;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import app.revanced.extension.shared.Logger;
import app.revanced.extension.shared.settings.BaseSettings;

@SuppressWarnings("unused")
public final class EnableDebuggingPatch {

private static final ConcurrentMap<Long, Boolean> featureFlags
= new ConcurrentHashMap<>(150, 0.75f, 1);

public static boolean isFeatureFlagEnabled(long flag, boolean value) {
if (value && BaseSettings.DEBUG.get()) {
if (featureFlags.putIfAbsent(flag, true) == null) {
Logger.printDebug(() -> "feature is enabled: " + flag);
}
}

return value;
}
}
10 changes: 5 additions & 5 deletions patches/api/patches.api
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,10 @@ public final class app/revanced/patches/youtube/interaction/seekbar/EnableSlideT
public static final fun getEnableSlideToSeekPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
}

public final class app/revanced/patches/youtube/interaction/seekbar/SeekbarThumbnailsPatchKt {
public static final fun getSeekbarThumbnailsPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
}

public final class app/revanced/patches/youtube/interaction/swipecontrols/SwipeControlsPatchKt {
public static final fun getSwipeControlsPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
}
Expand Down Expand Up @@ -1196,10 +1200,6 @@ public final class app/revanced/patches/youtube/layout/seekbar/SeekbarColorPatch
public static final fun getSeekbarColorPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
}

public final class app/revanced/patches/youtube/layout/seekbar/SeekbarThumbnailsPatchKt {
public static final fun getSeekbarThumbnailsPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
}

public final class app/revanced/patches/youtube/layout/shortsautoplay/ShortsAutoplayPatchKt {
public static final fun getShortsAutoplayPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
}
Expand Down Expand Up @@ -1263,7 +1263,7 @@ public final class app/revanced/patches/youtube/misc/check/CheckEnvironmentPatch
}

public final class app/revanced/patches/youtube/misc/debugging/EnableDebuggingPatchKt {
public static final fun getEnableDebuggingPatch ()Lapp/revanced/patcher/patch/ResourcePatch;
public static final fun getEnableDebuggingPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
}

public final class app/revanced/patches/youtube/misc/dimensions/spoof/SpoofDeviceDimensionsPatchKt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ val hideAdsPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ val hideGetPremiumPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ val videoAdsPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ val copyVideoUrlPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ val removeViewerDiscretionDialogPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ val downloadsPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ val disablePreciseSeekingGesturePatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ val enableSeekbarTappingPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ val enableSlideToSeekPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package app.revanced.patches.youtube.layout.seekbar
package app.revanced.patches.youtube.interaction.seekbar

import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.all.misc.resources.addResources
import app.revanced.patches.all.misc.resources.addResourcesPatch
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
import app.revanced.patches.youtube.interaction.seekbar.fullscreenSeekbarThumbnailsQualityFingerprint
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
import app.revanced.patches.youtube.misc.playservice.is_19_17_or_greater
import app.revanced.patches.youtube.misc.playservice.versionCheckPatch
Expand All @@ -32,6 +31,7 @@ val seekbarThumbnailsPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ val swipeControlsPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ val autoCaptionsPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ val hideButtonsPatch = resourcePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ val navigationButtonsPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ val hidePlayerOverlayButtonsPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ val hideEndscreenCardsPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package app.revanced.patches.youtube.layout.hide.fullscreenambientmode

import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.all.misc.resources.addResources
import app.revanced.patches.all.misc.resources.addResourcesPatch
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
import app.revanced.patches.youtube.misc.playservice.is_19_43_or_greater
import app.revanced.patches.youtube.misc.playservice.versionCheckPatch
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
import app.revanced.patches.youtube.misc.settings.settingsPatch
import java.util.logging.Logger
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference

internal const val EXTENSION_CLASS_DESCRIPTOR =
"Lapp/revanced/extension/youtube/patches/DisableFullscreenAmbientModePatch;"
Expand All @@ -24,7 +26,6 @@ val disableFullscreenAmbientModePatch = bytecodePatch(
settingsPatch,
sharedExtensionPatch,
addResourcesPatch,
versionCheckPatch,
)

compatibleWith(
Expand All @@ -34,33 +35,31 @@ val disableFullscreenAmbientModePatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

val initializeAmbientModeMatch by initializeAmbientModeFingerprint()
val setFullScreenBackgroundColorMatch by setFullScreenBackgroundColorFingerprint()

execute {
// TODO: fix this patch when 19.43+ is eventually supported.
if (is_19_43_or_greater) {
// 19.43+ the feature flag was inlined as false and no longer exists.
// This patch can be updated to change a single method, but for now show a more descriptive error.
return@execute Logger.getLogger(this::class.java.name)
.severe("'Disable fullscreen ambient mode' does not yet support 19.43+")
}

addResources("youtube", "layout.hide.fullscreenambientmode.disableFullscreenAmbientModePatch")

PreferenceScreen.PLAYER.addPreferences(
SwitchPreference("revanced_disable_fullscreen_ambient_mode"),
)

initializeAmbientModeMatch.mutableMethod.apply {
val moveIsEnabledIndex = initializeAmbientModeMatch.patternMatch!!.endIndex
setFullScreenBackgroundColorMatch.mutableMethod.apply {
val insertIndex = indexOfFirstInstructionReversedOrThrow {
getReference<MethodReference>()?.name == "setBackgroundColor"
}
val register = getInstruction<FiveRegisterInstruction>(insertIndex).registerD

addInstruction(
moveIsEnabledIndex,
"invoke-static { }, " +
"$EXTENSION_CLASS_DESCRIPTOR->enableFullScreenAmbientMode()Z",
addInstructions(
insertIndex,
"""
invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->getFullScreenBackgroundColor(I)I
move-result v$register
"""
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package app.revanced.patches.youtube.layout.hide.fullscreenambientmode

import app.revanced.util.literal
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.AccessFlags
import app.revanced.patcher.fingerprint
import com.android.tools.smali.dexlib2.AccessFlags

internal val initializeAmbientModeFingerprint = fingerprint {
internal val setFullScreenBackgroundColorFingerprint = fingerprint {
returns("V")
accessFlags(AccessFlags.CONSTRUCTOR, AccessFlags.PUBLIC)
opcodes(Opcode.MOVE_RESULT)
literal { 45389368 }
accessFlags(AccessFlags.PROTECTED, AccessFlags.FINAL)
parameters("Z", "I", "I", "I", "I")
custom { method, classDef ->
classDef.type.endsWith("/YouTubePlayerViewNotForReflection;")
&& method.name == "onLayout"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ val hideLayoutComponentsPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ val hideInfoCardsPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ val hidePlayerFlyoutMenuPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ val disableRollingNumberAnimationPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ val hideSeekbarPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ val hideShortsComponentsPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ val disableSuggestedVideoEndScreenPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ val hideTimestampPatch = bytecodePatch(
"19.16.39",
"19.25.37",
"19.34.42",
"19.43.41",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ val miniplayerPatch = bytecodePatch(
// 19.32.36 // 19.32+ and beyond all work without issues.
// 19.33.35
"19.34.42",
"19.43.41",
),
)

Expand Down
Loading

0 comments on commit 0cad269

Please sign in to comment.