feat(YouTube - Speed overlay): Change the speed overlay icon and fix patch for applying to earlier versions (#92)

This commit is contained in:
CaM/7oCe6e 2024-03-21 14:23:41 +03:00 committed by GitHub
parent f8b40f81bd
commit d547cda236
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 40 additions and 53 deletions

View file

@ -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<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
"""
)
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
if (it.attributes.getNamedItem("android:src")?.nodeValue?.endsWith("_24") == true) {
it.getAttributeNode("android:layout_$replacement")
?.let { attribute -> attribute.textContent = "12.0dip" }
}
}
}
} ?: throw fingerprint.exception
}
}
/**

View file

@ -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

View file

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@id/speedmaster_edu_container" style="@style/PlayerOverlayEduContainerStyle"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout style="@style/PlayerOverlayEduWrapperStyle">
<ImageView android:layout_gravity="center_vertical" android:id="@id/rewind_icon" android:layout_width="12.0dip" android:layout_height="12.0dip" android:src="@drawable/quantum_ic_fast_rewind_white_24" android:tint="?ytOverlayButtonPrimary" />
<com.google.android.libraries.youtube.common.ui.YouTubeTextView android:id="@id/speedmaster_edu_text" android:text="2x" android:layout_marginHorizontal="4.0dip" style="@style/PlayerOverlayEduTextStyle" />
<ImageView android:layout_gravity="center_vertical" android:id="@id/fast_forward_icon" android:layout_width="12.0dip" android:layout_height="12.0dip" android:src="@drawable/yt_fill_fast_forward_vd_theme_24" android:tint="?ytOverlayButtonPrimary" />
</LinearLayout>
</FrameLayout>

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@id/speedmaster_edu_container" style="@style/PlayerOverlayEduContainerStyle"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout style="@style/PlayerOverlayEduWrapperStyle">
<com.google.android.libraries.youtube.common.ui.YouTubeTextView android:id="@id/speedmaster_edu_text" android:text="2x" android:layout_marginHorizontal="4.0dip" style="@style/PlayerOverlayEduTextStyle" />
<ImageView android:layout_gravity="center_vertical" android:id="@id/fast_forward_icon" android:layout_width="12.0dip" android:layout_height="12.0dip" android:src="@drawable/yt_fill_fast_forward_vd_theme_24" android:tint="?ytOverlayButtonPrimary" />
</LinearLayout>
</FrameLayout>