diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/speedoverlay/SpeedOverlayPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/speedoverlay/SpeedOverlayPatch.kt index b7de53205..6856a46cb 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/speedoverlay/SpeedOverlayPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/speedoverlay/SpeedOverlayPatch.kt @@ -4,14 +4,17 @@ import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch import app.revanced.patches.youtube.player.speedoverlay.fingerprints.RestoreSlideToSeekBehaviorFingerprint import app.revanced.patches.youtube.player.speedoverlay.fingerprints.SpeedOverlayFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER import app.revanced.patches.youtube.utils.settings.SettingsPatch +import app.revanced.util.doRecursively import app.revanced.util.exception import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import org.w3c.dom.Element @Patch( name = "Disable speed overlay", @@ -65,24 +68,43 @@ object SpeedOverlayPatch : BytecodePatch( ) { override fun execute(context: BytecodeContext) { - arrayOf( - RestoreSlideToSeekBehaviorFingerprint, - SpeedOverlayFingerprint - ).forEach { fingerprint -> - fingerprint.result?.let { - it.mutableMethod.apply { - val insertIndex = it.scanResult.patternScanResult!!.endIndex + 1 - val insertRegister = - getInstruction(insertIndex).registerA + if (SettingsPatch.upward1836) { + arrayOf( + RestoreSlideToSeekBehaviorFingerprint, + SpeedOverlayFingerprint + ).forEach { fingerprint -> + fingerprint.result?.let { + it.mutableMethod.apply { + val insertIndex = it.scanResult.patternScanResult!!.endIndex + 1 + val insertRegister = + getInstruction(insertIndex).registerA + + addInstructions( + insertIndex, """ + invoke-static {v$insertRegister}, $PLAYER->disableSpeedOverlay(Z)Z + move-result v$insertRegister + """ + ) + } + } ?: throw fingerprint.exception + } + } else { + throw PatchException("This version is not supported. Please use YouTube 18.36.39 or later.") + } + + if (SettingsPatch.upward1839) { + SettingsPatch.contexts.xmlEditor["res/layout/speedmaster_icon_edu_overlay.xml"].use { editor -> + editor.file.doRecursively { + arrayOf("height", "width").forEach replacement@{ replacement -> + if (it !is Element) return@replacement - addInstructions( - insertIndex, """ - invoke-static {v$insertRegister}, $PLAYER->disableSpeedOverlay(Z)Z - move-result v$insertRegister - """ - ) + if (it.attributes.getNamedItem("android:src")?.nodeValue?.endsWith("_24") == true) { + it.getAttributeNode("android:layout_$replacement") + ?.let { attribute -> attribute.textContent = "12.0dip" } + } + } } - } ?: throw fingerprint.exception + } } /** diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt index 99d690409..bb54c40e7 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt @@ -101,6 +101,7 @@ object SettingsPatch : AbstractSettingsResourcePatch( upward1828 = 232900000 <= playServicesVersion upward1831 = 233200000 <= playServicesVersion upward1834 = 233502000 <= playServicesVersion + upward1836 = 233700000 <= playServicesVersion upward1839 = 234002000 <= playServicesVersion upward1841 = 234200000 <= playServicesVersion upward1843 = 234400000 <= playServicesVersion @@ -136,26 +137,6 @@ object SettingsPatch : AbstractSettingsResourcePatch( context.copyResources("youtube/settings", resourceGroup) } - if (SettingsPatch.upward1843) { - arrayOf( - ResourceGroup( - "layout", - "speedmaster_icon_edu_overlay.xml" - ) - ).forEach { resourceGroup -> - context.copyResources("youtube/settings/speedmaster_icon/1843", resourceGroup) - } - if (SettingsPatch.upward1904) { - arrayOf( - ResourceGroup( - "layout", - "speedmaster_icon_edu_overlay.xml" - ) - ).forEach { resourceGroup -> - context.copyResources("youtube/settings/speedmaster_icon/1904", resourceGroup) - } - } - } /** * initialize ReVanced Extended Settings @@ -195,6 +176,7 @@ object SettingsPatch : AbstractSettingsResourcePatch( internal var upward1828: Boolean = false internal var upward1831: Boolean = false internal var upward1834: Boolean = false + internal var upward1836: Boolean = false internal var upward1839: Boolean = false internal var upward1841: Boolean = false internal var upward1843: Boolean = false diff --git a/src/main/resources/youtube/settings/speedmaster_icon/1843/layout/speedmaster_icon_edu_overlay.xml b/src/main/resources/youtube/settings/speedmaster_icon/1843/layout/speedmaster_icon_edu_overlay.xml deleted file mode 100644 index a5531ddb7..000000000 --- a/src/main/resources/youtube/settings/speedmaster_icon/1843/layout/speedmaster_icon_edu_overlay.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/youtube/settings/speedmaster_icon/1904/layout/speedmaster_icon_edu_overlay.xml b/src/main/resources/youtube/settings/speedmaster_icon/1904/layout/speedmaster_icon_edu_overlay.xml deleted file mode 100644 index ec1aa10e3..000000000 --- a/src/main/resources/youtube/settings/speedmaster_icon/1904/layout/speedmaster_icon_edu_overlay.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - \ No newline at end of file