generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
disable-startup-shorts-player
patch (#670)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
- Loading branch information
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
.../patches/youtube/layout/startupshortsreset/annotations/StartupShortsResetCompatibility.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
40 changes: 40 additions & 0 deletions
40
...ced/patches/youtube/layout/startupshortsreset/fingerprints/ActionOpenShortsFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"), | ||
) |
68 changes: 68 additions & 0 deletions
68
...p/revanced/patches/youtube/layout/startupshortsreset/patch/DisableShortsOnStartupPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |