diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/autoplaypreview/patch/HideAutoplayPreviewPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/autoplaypreview/patch/HideAutoplayPreviewPatch.kt new file mode 100644 index 000000000..daae72154 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreen/autoplaypreview/patch/HideAutoplayPreviewPatch.kt @@ -0,0 +1,94 @@ +package app.revanced.patches.youtube.layout.fullscreen.autoplaypreview.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.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.patcher.util.smali.ExternalLabel +import app.revanced.patches.shared.annotation.YouTubeCompatibility +import app.revanced.patches.shared.fingerprints.LayoutConstructorFingerprint +import app.revanced.patches.shared.patch.mapping.ResourceMappingPatch +import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch +import app.revanced.util.integrations.Constants.FULLSCREEN_LAYOUT +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.builder.instruction.BuilderInstruction21c +import org.jf.dexlib2.iface.instruction.Instruction +import org.jf.dexlib2.iface.instruction.ReferenceInstruction +import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import org.jf.dexlib2.iface.instruction.formats.Instruction21c +import org.jf.dexlib2.iface.reference.FieldReference + +@Patch +@Name("hide-autoplay-preview") +@Description("Hides the autoplay preview container in the fullscreen.") +@DependsOn( + [ + ResourceMappingPatch::class, + SettingsPatch::class + ] +) +@YouTubeCompatibility +@Version("0.0.1") +class HideAutoplayPreviewPatch : BytecodePatch( + listOf( + LayoutConstructorFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + // resolve the offsets such as ... + val autoNavPreviewStubId = ResourceMappingPatch.resourceMappings.single { + it.type == "id" && it.name == "autonav_preview_stub" + }.id + + LayoutConstructorFingerprint.result?.mutableMethod?.let { method -> + with (method.implementation!!.instructions) { + val registerIndex = indexOfFirst { + it.opcode == Opcode.CONST_STRING && + (it as BuilderInstruction21c).reference.toString() == "1.0x" + } + val dummyRegister = (this[registerIndex] as Instruction21c).registerA + + // where to insert the branch instructions and ... + val insertIndex = this.indexOfFirst { + (it as? WideLiteralInstruction)?.wideLiteral == autoNavPreviewStubId + } + + val branchIndex = this.subList(insertIndex + 1, this.size - 1).indexOfFirst { + ((it as? ReferenceInstruction)?.reference as? FieldReference)?.type == "Lcom/google/android/apps/youtube/app/player/autonav/AutonavToggleController;" + } + 1 + + val jumpInstruction = this[insertIndex + branchIndex] as Instruction + + method.addInstructions( + insertIndex, """ + invoke-static {}, $FULLSCREEN_LAYOUT->hideAutoPlayPreview()Z + move-result v$dummyRegister + if-nez v$dummyRegister, :hidden + """, listOf(ExternalLabel("hidden", jumpInstruction)) + ) + } + } ?: return LayoutConstructorFingerprint.toErrorResult() + + /* + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "PREFERENCE: FULLSCREEN_LAYOUT_SETTINGS", + "SETTINGS: HIDE_AUTOPLAY_PREVIEW" + ) + ) + + SettingsPatch.updatePatchStatus("hide-autoplay-preview") + + return PatchResultSuccess() + } +} + diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 65758cc64..d316cda26 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -265,6 +265,9 @@ Is it ready to submit?" Autoplay button is shown Autoplay button is hidden Hide autoplay button + Autoplay preview container is shown + Autoplay preview container is hidden + Hide autoplay preview container Captions are enabled when playing a video with captioning is enforced "Captions aren't enabled when playing a video with captioning is enforced" Hide auto captions diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 9adc5fc35..830344329 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -209,6 +209,9 @@ + + @@ -441,6 +444,7 @@ +