diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/annotations/StartupShortsResetCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/annotations/StartupShortsResetCompatibility.kt new file mode 100644 index 00000000..259d89b8 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/annotations/StartupShortsResetCompatibility.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.youtube.layout.startupshortsreset.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility( + [Package( + "com.google.android.youtube", arrayOf("17.33.42", "17.36.37") + )] +) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class StartupShortsResetCompatibility diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/fingerprints/ActionOpenShortsFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/fingerprints/ActionOpenShortsFingerprint.kt new file mode 100644 index 00000000..15264297 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/fingerprints/ActionOpenShortsFingerprint.kt @@ -0,0 +1,40 @@ +package app.revanced.patches.youtube.layout.startupshortsreset.fingerprints + +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.layout.startupshortsreset.annotations.StartupShortsResetCompatibility +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +@Name("action-open-shorts-fingerprint") +@MatchingMethod("Lkyt;", "l") +@StartupShortsResetCompatibility +@Version("0.0.1") +object ActionOpenShortsFingerprint : MethodFingerprint( + "V", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf("L", "L"), listOf( + Opcode.IF_EQZ, + Opcode.INVOKE_VIRTUAL, + Opcode.CONST_STRING, + Opcode.CONST_4, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.IPUT_BOOLEAN, + Opcode.IGET_BOOLEAN, + Opcode.IF_NEZ, + Opcode.IF_EQZ, + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT, + Opcode.IF_EQZ, + Opcode.IGET_OBJECT, + Opcode.IF_EQZ, + Opcode.IGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.IF_EQZ, + Opcode.CONST_CLASS, + ), + listOf("com.google.android.youtube.action.open.shorts"), +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/patch/DisableShortsOnStartupPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/patch/DisableShortsOnStartupPatch.kt new file mode 100644 index 00000000..d09a18b4 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/patch/DisableShortsOnStartupPatch.kt @@ -0,0 +1,68 @@ +package app.revanced.patches.youtube.layout.startupshortsreset.patch + +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.impl.BytecodeData +import app.revanced.patcher.extensions.addInstructions +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.patch.impl.BytecodePatch +import app.revanced.patches.youtube.layout.startupshortsreset.annotations.StartupShortsResetCompatibility +import app.revanced.patches.youtube.layout.startupshortsreset.fingerprints.ActionOpenShortsFingerprint +import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch +import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch +import app.revanced.patches.youtube.misc.settings.framework.components.impl.StringResource +import app.revanced.patches.youtube.misc.settings.framework.components.impl.SwitchPreference +import org.jf.dexlib2.builder.instruction.BuilderInstruction21c +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction +import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction + +@Patch +@DependsOn([IntegrationsPatch::class, SettingsPatch::class]) +@Name("disable-startup-shorts-player") +@Description("Disables playing YouTube Shorts when launching YouTube.") +@StartupShortsResetCompatibility +@Version("0.0.1") +class DisableShortsOnStartupPatch : BytecodePatch( + listOf( + ActionOpenShortsFingerprint + ) +) { + override fun execute(data: BytecodeData): PatchResult { + SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( + SwitchPreference( + "revanced_startup_shorts_player_enabled", + StringResource("revanced_startup_shorts_player_title", "Disable shorts player at app startup"), + false, + StringResource("revanced_startup_shorts_player_summary_on", "Shorts player is disabled at app startup"), + StringResource("revanced_startup_shorts_player_summary_off", "Shorts player is enabled at app startup") + ) + ) + + val actionOpenShortsResult = ActionOpenShortsFingerprint.result + val actionOpenShortsMethod = actionOpenShortsResult!!.mutableMethod + val actionOpenShortsInstructions = actionOpenShortsMethod.implementation!!.instructions + + val moveResultIndex = actionOpenShortsResult.scanResult.stringsScanResult!!.matches.first().index + 5 + val iPutBooleanIndex = moveResultIndex + 6 + + val moveResultRegister = (actionOpenShortsInstructions[moveResultIndex] as OneRegisterInstruction).registerA + val iPutBooleanRegister = (actionOpenShortsInstructions[iPutBooleanIndex] as TwoRegisterInstruction).registerA + + actionOpenShortsMethod.addInstructions( + moveResultIndex + 1, """ + invoke-static { }, Lapp/revanced/integrations/patches/DisableStartupShortsPlayerPatch;->disableStartupShortsPlayer()Z + move-result v$moveResultRegister + if-nez v$moveResultRegister, :cond_startup_shorts_reset + const/4 v$iPutBooleanRegister, 0x0 + :cond_startup_shorts_reset + nop + """ + ) + + return PatchResultSuccess() + } +}