diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/landscapemode/fingerprints/OrientationParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/landscapemode/fingerprints/OrientationParentFingerprint.kt new file mode 100644 index 000000000..c2b1f9ee8 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/landscapemode/fingerprints/OrientationParentFingerprint.kt @@ -0,0 +1,8 @@ +package app.revanced.patches.youtube.layout.fullscreen.landscapemode.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +object OrientationParentFingerprint : MethodFingerprint( + returnType = "Z", + strings = listOf("NoClassDefFoundError thrown while verifying stack trace.") +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/landscapemode/fingerprints/OrientationPrimaryFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/landscapemode/fingerprints/OrientationPrimaryFingerprint.kt new file mode 100644 index 000000000..16ab45bf2 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/landscapemode/fingerprints/OrientationPrimaryFingerprint.kt @@ -0,0 +1,17 @@ +package app.revanced.patches.youtube.layout.fullscreen.landscapemode.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +object OrientationPrimaryFingerprint : MethodFingerprint ( + returnType = "V", + access = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, + parameters = listOf("L"), + opcodes = listOf( + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT + ), + customFingerprint = {it.name == ""} +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/landscapemode/fingerprints/OrientationSecondaryFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/landscapemode/fingerprints/OrientationSecondaryFingerprint.kt new file mode 100644 index 000000000..6e23b6012 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/landscapemode/fingerprints/OrientationSecondaryFingerprint.kt @@ -0,0 +1,16 @@ +package app.revanced.patches.youtube.layout.fullscreen.landscapemode.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +object OrientationSecondaryFingerprint : MethodFingerprint ( + returnType = "V", + access = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("L"), + opcodes = listOf( + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/landscapemode/patch/LandScapeModePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/landscapemode/patch/LandScapeModePatch.kt new file mode 100644 index 000000000..00d8fa809 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/landscapemode/patch/LandScapeModePatch.kt @@ -0,0 +1,77 @@ +package app.revanced.patches.youtube.layout.fullscreen.landscapemode.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.instruction +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.shared.annotation.YouTubeCompatibility +import app.revanced.patches.youtube.layout.fullscreen.landscapemode.fingerprints.* +import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch +import app.revanced.util.integrations.Constants.FULLSCREEN +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction + +@Patch(false) +@Name("diable-landscape-mode") +@Description("Disable landscape mode when entering fullscreen.") +@DependsOn([SettingsPatch::class]) +@YouTubeCompatibility +@Version("0.0.1") +class LandScapeModePatch : BytecodePatch( + listOf( + OrientationParentFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + OrientationParentFingerprint.result?.classDef?.let { classDef -> + arrayOf( + OrientationPrimaryFingerprint, + OrientationSecondaryFingerprint + ).forEach { fingerprint -> + fingerprint.also { it.resolve(context, classDef) }.result?.injectOverride() ?: return fingerprint.toErrorResult() + } + } ?: return OrientationParentFingerprint.toErrorResult() + + /* + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "PREFERENCE: FULLSCREEN_SETTINGS", + "SETTINGS: DISABLE_LANDSCAPE_MODE" + ) + ) + + SettingsPatch.updatePatchStatus("diable-landscape-mode") + + return PatchResultSuccess() + } + + private companion object { + const val INTEGRATIONS_CLASS_DESCRIPTOR = + "$FULLSCREEN->disableLandScapeMode(Z)Z" + + fun MethodFingerprintResult.injectOverride() { + with (mutableMethod) { + val index = scanResult.patternScanResult!!.endIndex + val register = (instruction(index) as OneRegisterInstruction).registerA + + addInstructions( + index +1, """ + invoke-static {v$register}, $INTEGRATIONS_CLASS_DESCRIPTOR + move-result v$register + """ + ) + } + } + } +} diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index de94058e3..cc94c9503 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -176,6 +176,9 @@ Is it ready to submit?" Zoom haptic feedback is enabled Zoom haptic feedback is disabled Disable zoom haptic feedback + Landscape mode when entering fullscreen is enabled + Landscape mode when entering fullscreen is disabled + Disable landscape mode when entering fullscreen "Disable CronetEngine's QUIC protocol" Disable QUIC protocol The amount of seconds the double press back to exit diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 9ac5ecb69..ebc8dced9 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -216,6 +216,10 @@ + +