generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YouTube): Add
Announcements
patch (#3166)
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
src/main/kotlin/app/revanced/patches/youtube/misc/announcements/AnnouncementsPatch.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,61 @@ | ||
package app.revanced.patches.youtube.misc.announcements | ||
|
||
import app.revanced.extensions.exception | ||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions | ||
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.annotation.CompatiblePackage | ||
import app.revanced.patcher.patch.annotation.Patch | ||
import app.revanced.patches.shared.fingerprints.WatchWhileActivityFingerprint | ||
import app.revanced.patches.shared.settings.preference.impl.StringResource | ||
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference | ||
import app.revanced.patches.youtube.misc.settings.SettingsPatch | ||
import com.android.tools.smali.dexlib2.Opcode | ||
|
||
@Patch( | ||
name = "Announcements", | ||
description = "Shows announcements on startup.", | ||
compatiblePackages = [CompatiblePackage("com.google.android.youtube")], | ||
dependencies = [SettingsPatch::class] | ||
) | ||
@Suppress("unused") | ||
object AnnouncementsPatch : BytecodePatch( | ||
setOf(WatchWhileActivityFingerprint) | ||
) { | ||
private const val INTEGRATIONS_CLASS_DESCRIPTOR = | ||
"Lapp/revanced/integrations/patches/announcements/AnnouncementsPatch;" | ||
|
||
override fun execute(context: BytecodeContext) { | ||
val onCreateMethod = WatchWhileActivityFingerprint.result?.let { | ||
it.mutableClass.methods.find { method -> method.name == "onCreate" } | ||
} ?: throw WatchWhileActivityFingerprint.exception | ||
|
||
val superCallIndex = onCreateMethod.getInstructions().indexOfFirst { it.opcode == Opcode.INVOKE_SUPER_RANGE } | ||
|
||
onCreateMethod.addInstructions( | ||
superCallIndex + 1, | ||
"invoke-static { v1 }, $INTEGRATIONS_CLASS_DESCRIPTOR->showAnnouncement(Landroid/app/Activity;)V" | ||
) | ||
|
||
SettingsPatch.PreferenceScreen.MISC.addPreferences( | ||
SwitchPreference( | ||
"revanced_announcements", | ||
StringResource( | ||
"revanced_announcements_title", | ||
"Show announcements" | ||
), | ||
StringResource( | ||
"revanced_announcements_summary_on", | ||
"Announcements are shown on startup." | ||
), StringResource( | ||
"revanced_announcements_summary_off", | ||
"Announcements are not shown on startup." | ||
), StringResource( | ||
"revanced_announcements_enabled_summary", | ||
"Show announcements on startup." | ||
), | ||
) | ||
) | ||
} | ||
} |