Skip to content

Commit

Permalink
feat(YouTube - Speed overlay): Change the speed overlay icon and fix …
Browse files Browse the repository at this point in the history
…patch for applying to earlier versions (#92)
  • Loading branch information
rufusin authored Mar 21, 2024
1 parent f8b40f8 commit d547cda
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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<OneRegisterInstruction>(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<OneRegisterInstruction>(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
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit d547cda

Please sign in to comment.