Skip to content

Commit d547cda

Browse files
authored
feat(YouTube - Speed overlay): Change the speed overlay icon and fix patch for applying to earlier versions (#92)
1 parent f8b40f8 commit d547cda

File tree

4 files changed

+40
-53
lines changed

4 files changed

+40
-53
lines changed

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

+38-16
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ import app.revanced.patcher.data.BytecodeContext
44
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
55
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
66
import app.revanced.patcher.patch.BytecodePatch
7+
import app.revanced.patcher.patch.PatchException
78
import app.revanced.patcher.patch.annotation.CompatiblePackage
89
import app.revanced.patcher.patch.annotation.Patch
910
import app.revanced.patches.youtube.player.speedoverlay.fingerprints.RestoreSlideToSeekBehaviorFingerprint
1011
import app.revanced.patches.youtube.player.speedoverlay.fingerprints.SpeedOverlayFingerprint
1112
import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER
1213
import app.revanced.patches.youtube.utils.settings.SettingsPatch
14+
import app.revanced.util.doRecursively
1315
import app.revanced.util.exception
1416
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
17+
import org.w3c.dom.Element
1518

1619
@Patch(
1720
name = "Disable speed overlay",
@@ -65,24 +68,43 @@ object SpeedOverlayPatch : BytecodePatch(
6568
) {
6669
override fun execute(context: BytecodeContext) {
6770

68-
arrayOf(
69-
RestoreSlideToSeekBehaviorFingerprint,
70-
SpeedOverlayFingerprint
71-
).forEach { fingerprint ->
72-
fingerprint.result?.let {
73-
it.mutableMethod.apply {
74-
val insertIndex = it.scanResult.patternScanResult!!.endIndex + 1
75-
val insertRegister =
76-
getInstruction<OneRegisterInstruction>(insertIndex).registerA
71+
if (SettingsPatch.upward1836) {
72+
arrayOf(
73+
RestoreSlideToSeekBehaviorFingerprint,
74+
SpeedOverlayFingerprint
75+
).forEach { fingerprint ->
76+
fingerprint.result?.let {
77+
it.mutableMethod.apply {
78+
val insertIndex = it.scanResult.patternScanResult!!.endIndex + 1
79+
val insertRegister =
80+
getInstruction<OneRegisterInstruction>(insertIndex).registerA
81+
82+
addInstructions(
83+
insertIndex, """
84+
invoke-static {v$insertRegister}, $PLAYER->disableSpeedOverlay(Z)Z
85+
move-result v$insertRegister
86+
"""
87+
)
88+
}
89+
} ?: throw fingerprint.exception
90+
}
91+
} else {
92+
throw PatchException("This version is not supported. Please use YouTube 18.36.39 or later.")
93+
}
94+
95+
if (SettingsPatch.upward1839) {
96+
SettingsPatch.contexts.xmlEditor["res/layout/speedmaster_icon_edu_overlay.xml"].use { editor ->
97+
editor.file.doRecursively {
98+
arrayOf("height", "width").forEach replacement@{ replacement ->
99+
if (it !is Element) return@replacement
77100

78-
addInstructions(
79-
insertIndex, """
80-
invoke-static {v$insertRegister}, $PLAYER->disableSpeedOverlay(Z)Z
81-
move-result v$insertRegister
82-
"""
83-
)
101+
if (it.attributes.getNamedItem("android:src")?.nodeValue?.endsWith("_24") == true) {
102+
it.getAttributeNode("android:layout_$replacement")
103+
?.let { attribute -> attribute.textContent = "12.0dip" }
104+
}
105+
}
84106
}
85-
} ?: throw fingerprint.exception
107+
}
86108
}
87109

88110
/**

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

+2-20
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ object SettingsPatch : AbstractSettingsResourcePatch(
101101
upward1828 = 232900000 <= playServicesVersion
102102
upward1831 = 233200000 <= playServicesVersion
103103
upward1834 = 233502000 <= playServicesVersion
104+
upward1836 = 233700000 <= playServicesVersion
104105
upward1839 = 234002000 <= playServicesVersion
105106
upward1841 = 234200000 <= playServicesVersion
106107
upward1843 = 234400000 <= playServicesVersion
@@ -136,26 +137,6 @@ object SettingsPatch : AbstractSettingsResourcePatch(
136137
context.copyResources("youtube/settings", resourceGroup)
137138
}
138139

139-
if (SettingsPatch.upward1843) {
140-
arrayOf(
141-
ResourceGroup(
142-
"layout",
143-
"speedmaster_icon_edu_overlay.xml"
144-
)
145-
).forEach { resourceGroup ->
146-
context.copyResources("youtube/settings/speedmaster_icon/1843", resourceGroup)
147-
}
148-
if (SettingsPatch.upward1904) {
149-
arrayOf(
150-
ResourceGroup(
151-
"layout",
152-
"speedmaster_icon_edu_overlay.xml"
153-
)
154-
).forEach { resourceGroup ->
155-
context.copyResources("youtube/settings/speedmaster_icon/1904", resourceGroup)
156-
}
157-
}
158-
}
159140

160141
/**
161142
* initialize ReVanced Extended Settings
@@ -195,6 +176,7 @@ object SettingsPatch : AbstractSettingsResourcePatch(
195176
internal var upward1828: Boolean = false
196177
internal var upward1831: Boolean = false
197178
internal var upward1834: Boolean = false
179+
internal var upward1836: Boolean = false
198180
internal var upward1839: Boolean = false
199181
internal var upward1841: Boolean = false
200182
internal var upward1843: Boolean = false

src/main/resources/youtube/settings/speedmaster_icon/1843/layout/speedmaster_icon_edu_overlay.xml

-9
This file was deleted.

src/main/resources/youtube/settings/speedmaster_icon/1904/layout/speedmaster_icon_edu_overlay.xml

-8
This file was deleted.

0 commit comments

Comments
 (0)