Skip to content

Commit e0a41cf

Browse files
committed
fix(YouTube): Adjusting patches to apply correctly to earlier versions.
1 parent 13c7790 commit e0a41cf

File tree

17 files changed

+277
-274
lines changed

17 files changed

+277
-274
lines changed

src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/player/ChangeTogglePatch.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ object ChangeTogglePatch : BytecodePatch(
7070
)
7171
) {
7272
override fun execute(context: BytecodeContext) {
73-
if (SettingsPatch.upward1905) throw PatchException("This version is not supported. Please use YouTube 19.05.36 or earlier.")
7473

7574
val additionalSettingsConfigResult = AdditionalSettingsConfigFingerprint.result
7675
?: throw AdditionalSettingsConfigFingerprint.exception
@@ -108,6 +107,7 @@ object ChangeTogglePatch : BytecodePatch(
108107
}
109108

110109
private fun MethodFingerprint.injectCall(descriptor: String) {
110+
111111
result?.let {
112112
it.mutableMethod.apply {
113113
val insertIndex = implementation!!.instructions.indexOfFirst { instruction ->
@@ -124,6 +124,7 @@ object ChangeTogglePatch : BytecodePatch(
124124
"""
125125
)
126126
}
127-
} ?: throw exception
127+
} ?: throw PatchException("This version is not supported. Please use YouTube 19.05.36 or earlier.")
128+
128129
}
129130
}

src/main/kotlin/app/revanced/patches/youtube/fullscreen/landscapemode/keep/KeepLandScapeModePatch.kt

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ object KeepLandScapeModePatch : BytecodePatch(
5454
)
5555
) {
5656
override fun execute(context: BytecodeContext) {
57+
5758
LandScapeModeConfigFingerprint.result?.let {
5859
it.mutableMethod.apply {
5960
val insertIndex = implementation!!.instructions.size - 1

src/main/kotlin/app/revanced/patches/youtube/general/rollingnumber/DisableRollingNumberAnimationPatch.kt

+26-21
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import app.revanced.patcher.util.smali.ExternalLabel
1212
import app.revanced.patches.youtube.utils.fingerprints.RollingNumberTextViewAnimationUpdateFingerprint
1313
import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL
1414
import app.revanced.patches.youtube.utils.settings.SettingsPatch
15+
import app.revanced.util.exception
1516
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
1617

1718
@Patch(
@@ -52,29 +53,33 @@ object DisableRollingNumberAnimationPatch : BytecodePatch(
5253

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

62-
// ReturnYouTubeDislike also makes changes to this same method,
63-
// and must add control flow label to a noop instruction to
64-
// ensure RYD patch adds it's changes after the control flow label.
65-
addInstructions(blockEndIndex, "nop")
64+
// ReturnYouTubeDislike also makes changes to this same method,
65+
// and must add control flow label to a noop instruction to
66+
// ensure RYD patch adds it's changes after the control flow label.
67+
addInstructions(blockEndIndex, "nop")
6668

67-
addInstructionsWithLabels(
68-
blockStartIndex,
69-
"""
70-
invoke-static {}, $GENERAL->disableRollingNumberAnimations()Z
71-
move-result v$freeRegister
72-
if-nez v$freeRegister, :disable_animations
73-
""",
74-
ExternalLabel("disable_animations", getInstruction(blockEndIndex))
75-
)
76-
}
77-
} ?: throw PatchException("This version is not supported. Please use YouTube 18.30.37 or later.")
69+
addInstructionsWithLabels(
70+
blockStartIndex,
71+
"""
72+
invoke-static {}, $GENERAL->disableRollingNumberAnimations()Z
73+
move-result v$freeRegister
74+
if-nez v$freeRegister, :disable_animations
75+
""",
76+
ExternalLabel("disable_animations", getInstruction(blockEndIndex))
77+
)
78+
}
79+
} ?: RollingNumberTextViewAnimationUpdateFingerprint.exception
80+
} else {
81+
throw PatchException("This version is not supported. Please use YouTube 18.43.45 or later.")
82+
}
7883

7984
/**
8085
* Add settings

src/main/kotlin/app/revanced/patches/youtube/general/songsearch/SongSearchPatch.kt

+1
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,6 @@ object SongSearchPatch : BytecodePatch(
7979
)
8080

8181
SettingsPatch.updatePatchStatus("Enable song search")
82+
8283
}
8384
}

src/main/kotlin/app/revanced/patches/youtube/layout/doubletapbackground/DoubleTapOverlayBackgroundPatch.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ import app.revanced.patches.youtube.utils.settings.SettingsPatch
4747
"19.09.37"
4848
]
4949
)
50-
],
51-
use = true
50+
]
5251
)
5352
@Suppress("unused")
5453
object DoubleTapOverlayBackgroundPatch : AbstractOverlayBackgroundPatch(

src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/fingerprints/PowerSaveModeOneFingerprint.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package app.revanced.patches.youtube.misc.ambientmode.fingerprints /** #C# Add START */
1+
package app.revanced.patches.youtube.misc.ambientmode.fingerprints
22

33
import app.revanced.patcher.extensions.or
44
import app.revanced.patcher.fingerprint.MethodFingerprint
@@ -40,4 +40,4 @@ object PowerSaveModeOneFingerprint : MethodFingerprint(
4040
}
4141
count == 1
4242
}
43-
) /** #C# Add END */
43+
)

src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/fingerprints/PowerSaveModeTwoFingerprint.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package app.revanced.patches.youtube.misc.ambientmode.fingerprints /** #C# Add START */
1+
package app.revanced.patches.youtube.misc.ambientmode.fingerprints
22

33
import app.revanced.patcher.extensions.or
44
import app.revanced.patcher.fingerprint.MethodFingerprint
@@ -41,4 +41,4 @@ object PowerSaveModeTwoFingerprint : MethodFingerprint(
4141
}
4242
count == 1
4343
}
44-
) /** #C# Add END */
44+
)

src/main/kotlin/app/revanced/patches/youtube/navigation/navigationbuttons/NavigationButtonsPatch.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ object NavigationButtonsPatch : BytecodePatch(
102102
val buttonViewResult = this[1]
103103

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

107107
mapOf(
108108
BUTTON_HOOK to buttonHookInsertIndex,

src/main/kotlin/app/revanced/patches/youtube/navigation/navigationbuttons/fingerprints/PivotBarShortsButtonViewFingerprint.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ object PivotBarShortsButtonViewFingerprint : MethodFingerprint(
77
opcodes = listOf(
88
Opcode.INVOKE_VIRTUAL_RANGE,
99
Opcode.MOVE_RESULT_OBJECT, // target reference
10-
Opcode.GOTO,
10+
null, // Opcode.GOTO_16 or Opcode.GOTO
11+
Opcode.IF_NE
1112
)
1213
)

src/main/kotlin/app/revanced/patches/youtube/overlaybutton/download/hook/fingerprints/PlaylistOfflineDownloadOnClickFingerprint.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object PlaylistOfflineDownloadOnClickFingerprint : MethodFingerprint(
1414
Opcode.INVOKE_STATIC,
1515
Opcode.MOVE_RESULT,
1616
Opcode.IF_EQZ,
17-
null, // Opcode.RETURN_VOID, Opcode.GOTO
17+
null, // Opcode.RETURN_VOID or Opcode.GOTO
1818
Opcode.IGET_OBJECT
1919
),
2020
customFingerprint = { methodDef, classDef ->

src/main/kotlin/app/revanced/patches/youtube/player/musicbutton/HideMusicButtonPatch.kt

+29-17
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import app.revanced.patcher.patch.annotation.Patch
99
import app.revanced.patcher.util.smali.ExternalLabel
1010
import app.revanced.patches.youtube.player.musicbutton.fingerprints.MusicAppDeeplinkButtonAlternativeFingerprint
1111
import app.revanced.patches.youtube.player.musicbutton.fingerprints.MusicAppDeeplinkButtonFingerprint
12-
import app.revanced.patches.youtube.player.musicbutton.fingerprints.MusicAppDeeplinkButtonParentFingerprint
1312
import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER
1413
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
1514
import app.revanced.patches.youtube.utils.settings.SettingsPatch
@@ -63,25 +62,38 @@ import app.revanced.util.exception
6362
)
6463
@Suppress("unused")
6564
object HideMusicButtonPatch : BytecodePatch(
66-
setOf(MusicAppDeeplinkButtonParentFingerprint)
65+
setOf(
66+
MusicAppDeeplinkButtonAlternativeFingerprint,
67+
MusicAppDeeplinkButtonFingerprint
68+
)
6769
) {
6870
override fun execute(context: BytecodeContext) {
6971

70-
MusicAppDeeplinkButtonParentFingerprint.result?.mutableClass?.let { mutableClass ->
71-
MusicAppDeeplinkButtonFingerprint.also { it.resolve(context, mutableClass) }.result?.let {
72-
it.mutableMethod.apply {
73-
addInstructionsWithLabels(
74-
0,
75-
"""
76-
invoke-static {}, $PLAYER->hideMusicButton()Z
77-
move-result v0
78-
if-nez v0, :hidden
79-
""",
80-
ExternalLabel("hidden", getInstruction(implementation!!.instructions.size - 1))
81-
)
82-
}
83-
} ?: throw MusicAppDeeplinkButtonFingerprint.exception
84-
} ?: throw MusicAppDeeplinkButtonParentFingerprint.exception
72+
MusicAppDeeplinkButtonFingerprint.result?.let {
73+
it.mutableMethod.apply {
74+
addInstructionsWithLabels(
75+
0,
76+
"""
77+
invoke-static {}, $PLAYER->hideMusicButton()Z
78+
move-result v0
79+
if-nez v0, :hidden
80+
""",
81+
ExternalLabel("hidden", getInstruction(implementation!!.instructions.size - 1))
82+
)
83+
}
84+
} ?: MusicAppDeeplinkButtonAlternativeFingerprint.result?.let {
85+
it.mutableMethod.apply {
86+
addInstructionsWithLabels(
87+
0,
88+
"""
89+
invoke-static {}, $PLAYER->hideMusicButton()Z
90+
move-result v0
91+
if-nez v0, :hidden
92+
""",
93+
ExternalLabel("hidden", getInstruction(implementation!!.instructions.size - 1))
94+
)
95+
}
96+
} ?: throw MusicAppDeeplinkButtonFingerprint.exception
8597

8698
/**
8799
* Add settings

src/main/kotlin/app/revanced/patches/youtube/player/musicbutton/fingerprints/MusicAppDeeplinkButtonFingerprint.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package app.revanced.patches.youtube.player.musicbutton.fingerprints
22

33
import app.revanced.patcher.extensions.or
44
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.MusicAppDeeplinkButtonView
5-
import app.revanced.patcher.fingerprint.MethodFingerprint
5+
import app.revanced.util.fingerprint.LiteralValueFingerprint
66
import com.android.tools.smali.dexlib2.AccessFlags
77

8-
object MusicAppDeeplinkButtonFingerprint : MethodFingerprint(
8+
object MusicAppDeeplinkButtonFingerprint : LiteralValueFingerprint(
99
returnType = "V",
1010
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
1111
parameters = listOf("Z", "Z"),
12+
literalSupplier = { MusicAppDeeplinkButtonView }
1213
)

src/main/kotlin/app/revanced/patches/youtube/player/musicbutton/fingerprints/MusicAppDeeplinkButtonParentFingerprint.kt

-12
This file was deleted.

src/main/kotlin/app/revanced/patches/youtube/player/speedoverlay/SpeedOverlayPatch.kt

-9
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
2121
CompatiblePackage(
2222
"com.google.android.youtube",
2323
[
24-
"18.25.40",
25-
"18.27.36",
26-
"18.29.38",
27-
"18.30.37",
28-
"18.31.40",
29-
"18.32.39",
30-
"18.33.40",
31-
"18.34.38",
32-
"18.35.36",
3324
"18.36.39",
3425
"18.37.36",
3526
"18.38.44",

src/main/kotlin/app/revanced/patches/youtube/swipe/controls/SwipeControlsPatch.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ object SwipeControlsPatch : BytecodePatch(
129129
}
130130
} ?: throw FullScreenEngagementOverlayFingerprint.exception
131131

132-
if (SettingsPatch.upward1909) {
132+
try {
133133
HDRBrightnessFingerprint.result?.let {
134134
it.mutableMethod.apply {
135135
addInstructionsWithLabels(
@@ -141,7 +141,7 @@ object SwipeControlsPatch : BytecodePatch(
141141
""", ExternalLabel("default", getInstruction(0))
142142
)
143143
}
144-
}
144+
} ?: throw HDRBrightnessFingerprint.exception
145145

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

158+
156159
/**
157160
* Add settings
158161
*/

src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt

-4
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ object SettingsPatch : AbstractSettingsResourcePatch(
105105
upward1841 = 234200000 <= playServicesVersion
106106
upward1843 = 234400000 <= playServicesVersion
107107
upward1904 = 240502000 <= playServicesVersion
108-
upward1905 = 240700000 <= playServicesVersion
109-
upward1909 = 241002000 > playServicesVersion
110108

111109
break
112110
}
@@ -199,8 +197,6 @@ object SettingsPatch : AbstractSettingsResourcePatch(
199197
internal var upward1841: Boolean = false
200198
internal var upward1843: Boolean = false
201199
internal var upward1904: Boolean = false
202-
internal var upward1905: Boolean = false
203-
internal var upward1909: Boolean = false
204200

205201
internal fun addPreference(settingArray: Array<String>) {
206202
contexts.addPreference(settingArray)

0 commit comments

Comments
 (0)