diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/shortspip/bytecode/fingerprints/DisableShortsPiPFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/shortspip/bytecode/fingerprints/DisableShortsPiPFingerprint.kt new file mode 100644 index 000000000..779a7755f --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/shortspip/bytecode/fingerprints/DisableShortsPiPFingerprint.kt @@ -0,0 +1,12 @@ +package app.revanced.patches.youtube.layout.general.bytecode.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags + +object DisableShortsPiPFingerprint : MethodFingerprint( + returnType = "L", + access = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("L"), + customFingerprint = { it.definingClass == "Lcom/google/android/apps/youtube/app/common/ui/pip/DefaultPipController;" } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/shortspip/bytecode/patch/DisableShortsPiPBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/shortspip/bytecode/patch/DisableShortsPiPBytecodePatch.kt new file mode 100644 index 000000000..50a92527d --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/shortspip/bytecode/patch/DisableShortsPiPBytecodePatch.kt @@ -0,0 +1,78 @@ +package app.revanced.patches.youtube.layout.general.bytecode.patch + +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.extensions.removeInstruction +import app.revanced.patcher.extensions.replaceInstruction +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.util.smali.ExternalLabel +import app.revanced.patches.youtube.layout.general.bytecode.fingerprints.DisableShortsPiPFingerprint +import app.revanced.patches.youtube.misc.playertype.patch.PlayerTypeHookPatch +import app.revanced.shared.annotation.YouTubeCompatibility +import app.revanced.shared.extensions.toErrorResult +import app.revanced.shared.util.integrations.Constants.GENERAL_LAYOUT +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.builder.instruction.BuilderInstruction35c +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction + +@Name("disable-shorts-pip-bytecode-patch") +@DependsOn( + [ + PlayerTypeHookPatch::class + ] +) +@YouTubeCompatibility +@Version("0.0.1") +class DisableShortsPiPBytecodePatch : BytecodePatch( + listOf( + DisableShortsPiPFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + + DisableShortsPiPFingerprint.result?.mutableMethod?.let { method -> + + with (method.implementation!!) { + val invokeIndex = this.instructions.indexOfFirst { + it.opcode.ordinal == Opcode.INVOKE_VIRTUAL.ordinal && + ((it as? BuilderInstruction35c)?.reference.toString() == + "$REFERENCE_DESCRIPTOR") + } + val registerA = (method.instruction(invokeIndex + 1) as OneRegisterInstruction).registerA + + val registerC = (method.instruction(invokeIndex) as BuilderInstruction35c).registerC + val registerE = (method.instruction(invokeIndex) as BuilderInstruction35c).registerE + + method.addInstructions( + invokeIndex + 1,""" + invoke-static {}, $GENERAL_LAYOUT->disableShortsPlayerPiP()Z + move-result v$registerA + if-eqz v$registerA, :pip + goto :disablepip + :pip + invoke-virtual {v${registerC}, v${registerE}}, $REFERENCE_DESCRIPTOR + move-result v$registerA + """, listOf(ExternalLabel("disablepip", method.instruction(invokeIndex + 1))) + ) + method.removeInstruction(invokeIndex) + method.replaceInstruction( + invokeIndex + 6, "nop" + ) + + } + } ?: return DisableShortsPiPFingerprint.toErrorResult() + + return PatchResultSuccess() + } + + private companion object { + const val REFERENCE_DESCRIPTOR = + "Landroid/app/Activity;->enterPictureInPictureMode(Landroid/app/PictureInPictureParams;)Z" + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/shortspip/resource/patch/DisableShortsPiPPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/shortspip/resource/patch/DisableShortsPiPPatch.kt new file mode 100644 index 000000000..ebd4eac8c --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/shortspip/resource/patch/DisableShortsPiPPatch.kt @@ -0,0 +1,51 @@ +package app.revanced.patches.youtube.layout.general.resource.patch + +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patches.youtube.layout.general.bytecode.patch.DisableShortsPiPBytecodePatch +import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch +import app.revanced.shared.annotation.YouTubeCompatibility +import app.revanced.shared.util.resources.ResourceHelper + +@Patch +@Name("disable-shorts-player-pip") +@Description("Disable PiP mode in YouTube Shorts player.") +@DependsOn( + [ + DisableShortsPiPBytecodePatch::class, + SettingsPatch::class + ] +) +@YouTubeCompatibility +@Version("0.0.1") +class DisableShortsPiPPatch : ResourcePatch { + override fun execute(context: ResourceContext): PatchResult { + + /* + add settings + */ + ResourceHelper.addSettings4( + context, + "PREFERENCE_CATEGORY: REVANCED_SETTINGS", + "PREFERENCE: LAYOUT_SETTINGS", + "PREFERENCE_HEADER: GENERAL", + "SETTINGS: SHORTS_COMPONENT.PARENT", + "SETTINGS: SHORTS_COMPONENT_PARENT.B", + "SETTINGS: DISABLE_SHORTS_PLAYER_PIP" + ) + + ResourceHelper.patchSuccess( + context, + "disable-shorts-player-pip" + ) + + return PatchResultSuccess() + } +} \ No newline at end of file diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 8a115b893..2d6a65465 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -188,6 +188,9 @@ Is it ready to submit?" Zoom haptic feedback is enabled Zoom haptic feedback is disabled Disable zoom haptic feedback + PiP mode in shorts player is enabled + PiP mode in shorts player is disabled + Disable pip mode in shorts player Time Stamp copied to clipboard Always auto repeat is disabled Always auto repeat is enabled diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index df3d2b64f..5aa01fa0f 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -106,6 +106,9 @@ + + @@ -363,6 +366,7 @@ +