Skip to content

Commit

Permalink
fix(YouTube): Adjusting patches to apply correctly to earlier version…
Browse files Browse the repository at this point in the history
…s. (#94)

* fix(YouTube): Adjusting patches to apply correctly to earlier versions.

* Update revanced_prefs.xml

---------

Co-authored-by: Aaron Veil <[email protected]>
  • Loading branch information
rufusin and anddea authored Mar 21, 2024
1 parent d547cda commit cb02ba7
Show file tree
Hide file tree
Showing 17 changed files with 272 additions and 269 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ object ChangeTogglePatch : BytecodePatch(
)
) {
override fun execute(context: BytecodeContext) {
if (SettingsPatch.upward1905) throw PatchException("This version is not supported. Please use YouTube 19.05.36 or earlier.")

val additionalSettingsConfigResult = AdditionalSettingsConfigFingerprint.result
?: throw AdditionalSettingsConfigFingerprint.exception
Expand Down Expand Up @@ -108,6 +107,7 @@ object ChangeTogglePatch : BytecodePatch(
}

private fun MethodFingerprint.injectCall(descriptor: String) {

result?.let {
it.mutableMethod.apply {
val insertIndex = implementation!!.instructions.indexOfFirst { instruction ->
Expand All @@ -124,6 +124,7 @@ object ChangeTogglePatch : BytecodePatch(
"""
)
}
} ?: throw exception
} ?: throw PatchException("This version is not supported. Please use YouTube 19.05.36 or earlier.")

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ object KeepLandScapeModePatch : BytecodePatch(
)
) {
override fun execute(context: BytecodeContext) {

LandScapeModeConfigFingerprint.result?.let {
it.mutableMethod.apply {
val insertIndex = implementation!!.instructions.size - 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.youtube.utils.fingerprints.RollingNumberTextViewAnimationUpdateFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.exception
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction

@Patch(
Expand Down Expand Up @@ -52,29 +53,33 @@ object DisableRollingNumberAnimationPatch : BytecodePatch(

// Animations are disabled by preventing an Image from being applied to the text span,
// which prevents the animations from appearing.
RollingNumberTextViewAnimationUpdateFingerprint.result?.apply {
val patternScanResult = scanResult.patternScanResult!!
val blockStartIndex = patternScanResult.startIndex
val blockEndIndex = patternScanResult.endIndex + 1
mutableMethod.apply {
val freeRegister = getInstruction<OneRegisterInstruction>(blockStartIndex).registerA
if (SettingsPatch.upward1843) {
RollingNumberTextViewAnimationUpdateFingerprint.result?.apply {
val patternScanResult = scanResult.patternScanResult!!
val blockStartIndex = patternScanResult.startIndex
val blockEndIndex = patternScanResult.endIndex + 1
mutableMethod.apply {
val freeRegister = getInstruction<OneRegisterInstruction>(blockStartIndex).registerA

// ReturnYouTubeDislike also makes changes to this same method,
// and must add control flow label to a noop instruction to
// ensure RYD patch adds it's changes after the control flow label.
addInstructions(blockEndIndex, "nop")
// ReturnYouTubeDislike also makes changes to this same method,
// and must add control flow label to a noop instruction to
// ensure RYD patch adds it's changes after the control flow label.
addInstructions(blockEndIndex, "nop")

addInstructionsWithLabels(
blockStartIndex,
"""
invoke-static {}, $GENERAL->disableRollingNumberAnimations()Z
move-result v$freeRegister
if-nez v$freeRegister, :disable_animations
""",
ExternalLabel("disable_animations", getInstruction(blockEndIndex))
)
}
} ?: throw PatchException("This version is not supported. Please use YouTube 18.30.37 or later.")
addInstructionsWithLabels(
blockStartIndex,
"""
invoke-static {}, $GENERAL->disableRollingNumberAnimations()Z
move-result v$freeRegister
if-nez v$freeRegister, :disable_animations
""",
ExternalLabel("disable_animations", getInstruction(blockEndIndex))
)
}
} ?: RollingNumberTextViewAnimationUpdateFingerprint.exception
} else {
throw PatchException("This version is not supported. Please use YouTube 18.43.45 or later.")
}

/**
* Add settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@ object SongSearchPatch : BytecodePatch(
)

SettingsPatch.updatePatchStatus("Enable song search")

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ import app.revanced.patches.youtube.utils.settings.SettingsPatch
"19.09.37"
]
)
],
use = true
]
)
@Suppress("unused")
object DoubleTapOverlayBackgroundPatch : AbstractOverlayBackgroundPatch(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.revanced.patches.youtube.misc.ambientmode.fingerprints /** #C# Add START */
package app.revanced.patches.youtube.misc.ambientmode.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
Expand Down Expand Up @@ -40,4 +40,4 @@ object PowerSaveModeOneFingerprint : MethodFingerprint(
}
count == 1
}
) /** #C# Add END */
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.revanced.patches.youtube.misc.ambientmode.fingerprints /** #C# Add START */
package app.revanced.patches.youtube.misc.ambientmode.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
Expand Down Expand Up @@ -41,4 +41,4 @@ object PowerSaveModeTwoFingerprint : MethodFingerprint(
}
count == 1
}
) /** #C# Add END */
)
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ object NavigationButtonsPatch : BytecodePatch(
val buttonViewResult = this[1]

val enumHookInsertIndex = enumScanResult.startIndex + 2
val buttonHookInsertIndex = buttonViewResult.endIndex
val buttonHookInsertIndex = buttonViewResult.endIndex - 1

mapOf(
BUTTON_HOOK to buttonHookInsertIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ object PivotBarShortsButtonViewFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.INVOKE_VIRTUAL_RANGE,
Opcode.MOVE_RESULT_OBJECT, // target reference
Opcode.GOTO,
null, // Opcode.GOTO_16 or Opcode.GOTO
Opcode.IF_NE
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object PlaylistOfflineDownloadOnClickFingerprint : MethodFingerprint(
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT,
Opcode.IF_EQZ,
null, // Opcode.RETURN_VOID, Opcode.GOTO
null, // Opcode.RETURN_VOID or Opcode.GOTO
Opcode.IGET_OBJECT
),
customFingerprint = { methodDef, classDef ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.youtube.player.musicbutton.fingerprints.MusicAppDeeplinkButtonAlternativeFingerprint
import app.revanced.patches.youtube.player.musicbutton.fingerprints.MusicAppDeeplinkButtonFingerprint
import app.revanced.patches.youtube.player.musicbutton.fingerprints.MusicAppDeeplinkButtonParentFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.settings.SettingsPatch
Expand Down Expand Up @@ -63,25 +62,38 @@ import app.revanced.util.exception
)
@Suppress("unused")
object HideMusicButtonPatch : BytecodePatch(
setOf(MusicAppDeeplinkButtonParentFingerprint)
setOf(
MusicAppDeeplinkButtonAlternativeFingerprint,
MusicAppDeeplinkButtonFingerprint
)
) {
override fun execute(context: BytecodeContext) {

MusicAppDeeplinkButtonParentFingerprint.result?.mutableClass?.let { mutableClass ->
MusicAppDeeplinkButtonFingerprint.also { it.resolve(context, mutableClass) }.result?.let {
it.mutableMethod.apply {
addInstructionsWithLabels(
0,
"""
invoke-static {}, $PLAYER->hideMusicButton()Z
move-result v0
if-nez v0, :hidden
""",
ExternalLabel("hidden", getInstruction(implementation!!.instructions.size - 1))
)
}
} ?: throw MusicAppDeeplinkButtonFingerprint.exception
} ?: throw MusicAppDeeplinkButtonParentFingerprint.exception
MusicAppDeeplinkButtonFingerprint.result?.let {
it.mutableMethod.apply {
addInstructionsWithLabels(
0,
"""
invoke-static {}, $PLAYER->hideMusicButton()Z
move-result v0
if-nez v0, :hidden
""",
ExternalLabel("hidden", getInstruction(implementation!!.instructions.size - 1))
)
}
} ?: MusicAppDeeplinkButtonAlternativeFingerprint.result?.let {
it.mutableMethod.apply {
addInstructionsWithLabels(
0,
"""
invoke-static {}, $PLAYER->hideMusicButton()Z
move-result v0
if-nez v0, :hidden
""",
ExternalLabel("hidden", getInstruction(implementation!!.instructions.size - 1))
)
}
} ?: throw MusicAppDeeplinkButtonFingerprint.exception

/**
* Add settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package app.revanced.patches.youtube.player.musicbutton.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.MusicAppDeeplinkButtonView
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.util.fingerprint.LiteralValueFingerprint
import com.android.tools.smali.dexlib2.AccessFlags

object MusicAppDeeplinkButtonFingerprint : MethodFingerprint(
object MusicAppDeeplinkButtonFingerprint : LiteralValueFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Z", "Z"),
literalSupplier = { MusicAppDeeplinkButtonView }
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ import org.w3c.dom.Element
CompatiblePackage(
"com.google.android.youtube",
[
"18.25.40",
"18.27.36",
"18.29.38",
"18.30.37",
"18.31.40",
"18.32.39",
"18.33.40",
"18.34.38",
"18.35.36",
"18.36.39",
"18.37.36",
"18.38.44",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ object SwipeControlsPatch : BytecodePatch(
}
} ?: throw FullScreenEngagementOverlayFingerprint.exception

if (SettingsPatch.upward1909) {
try {
HDRBrightnessFingerprint.result?.let {
it.mutableMethod.apply {
addInstructionsWithLabels(
Expand All @@ -141,7 +141,7 @@ object SwipeControlsPatch : BytecodePatch(
""", ExternalLabel("default", getInstruction(0))
)
}
}
} ?: throw HDRBrightnessFingerprint.exception

/**
* Add settings
Expand All @@ -151,8 +151,11 @@ object SwipeControlsPatch : BytecodePatch(
"SETTINGS: SWIPE_EXPERIMENTAL_FLAGS"
)
)
} catch (e: Exception) {
println("WARNING: Disable auto HDR brightness is not supported in this version. Use YouTube 19.08.36 or earlier (${e.message})")
}


/**
* Add settings
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ object SettingsPatch : AbstractSettingsResourcePatch(
upward1841 = 234200000 <= playServicesVersion
upward1843 = 234400000 <= playServicesVersion
upward1904 = 240502000 <= playServicesVersion
upward1905 = 240700000 <= playServicesVersion
upward1909 = 241002000 > playServicesVersion

break
}
Expand Down Expand Up @@ -181,8 +179,6 @@ object SettingsPatch : AbstractSettingsResourcePatch(
internal var upward1841: Boolean = false
internal var upward1843: Boolean = false
internal var upward1904: Boolean = false
internal var upward1905: Boolean = false
internal var upward1909: Boolean = false

internal fun addPreference(settingArray: Array<String>) {
contexts.addPreference(settingArray)
Expand Down
Loading

0 comments on commit cb02ba7

Please sign in to comment.