feat(YouTube): Add Disable fullscreen ambient mode patch

This commit is contained in:
oSumAtrIX 2023-10-25 01:46:47 +02:00
parent 71a00177d9
commit 2a5514a6b3
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
2 changed files with 79 additions and 0 deletions

View File

@ -0,0 +1,66 @@
package app.revanced.patches.youtube.layout.hide.fullscreenambientmode
import app.revanced.extensions.exception
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.shared.settings.preference.impl.StringResource
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
import app.revanced.patches.youtube.layout.hide.fullscreenambientmode.fingerprints.InitializeAmbientModeFingerprint
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
import app.revanced.patches.youtube.misc.settings.SettingsPatch
@Patch(
name = "Disable fullscreen ambient mode",
description = "Disables the ambient mode when in fullscreen.",
dependencies = [IntegrationsPatch::class, SettingsPatch::class, IntegrationsPatch::class],
compatiblePackages = [
CompatiblePackage(
"com.google.android.youtube", [
"18.37.36",
"18.38.44"
]
)
]
)
@Suppress("unused")
object DisableFullscreenAmbientModePatch : BytecodePatch(
setOf(InitializeAmbientModeFingerprint)
) {
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
"Lapp/revanced/integrations/patches/DisableFullscreenAmbientModePatch;"
override fun execute(context: BytecodeContext) {
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
SwitchPreference(
"revanced_disable_fullscreen_ambient_mode",
StringResource(
"revanced_disable_fullscreen_ambient_mode_title",
"Disable ambient mode in fullscreen"
),
StringResource(
"revanced_disable_fullscreen_ambient_mode_summary_on",
"Ambient mode disabled"
),
StringResource(
"revanced_disable_fullscreen_ambient_mode_summary_off",
"Ambient mode enabled"
),
)
)
InitializeAmbientModeFingerprint.result?.let {
it.mutableMethod.apply {
val moveIsEnabledIndex = it.scanResult.patternScanResult!!.endIndex
addInstruction(
moveIsEnabledIndex,
"invoke-static { }, " +
"$INTEGRATIONS_CLASS_DESCRIPTOR->enableFullScreenAmbientMode()Z"
)
}
} ?: throw InitializeAmbientModeFingerprint.exception
}
}

View File

@ -0,0 +1,13 @@
package app.revanced.patches.youtube.layout.hide.fullscreenambientmode.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.util.patch.LiteralValueFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
object InitializeAmbientModeFingerprint : LiteralValueFingerprint(
returnType = "V",
accessFlags = AccessFlags.CONSTRUCTOR or AccessFlags.PUBLIC,
opcodes = listOf(Opcode.MOVE_RESULT),
literalSupplier = { 45389368 }
)