Skip to content

Commit

Permalink
feat: disable-auto-player-popup-panels (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
OxrxL committed Sep 21, 2022
1 parent d23570b commit 69c9b58
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package app.revanced.patches.youtube.layout.playerpopuppanels.annotations

import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package

@Compatibility(
[Package(
"com.google.android.youtube", arrayOf("17.25.34", "17.26.35", "17.27.39", "17.28.34", "17.29.34", "17.32.35", "17.33.42", "17.36.37")
)]
)
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
internal annotation class PlayerPopupPanelsCompatibility
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package app.revanced.patches.youtube.layout.playerpopuppanels.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.FuzzyPatternScanMethod
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.layout.playerpopuppanels.annotations.PlayerPopupPanelsCompatibility
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode

@Name("engagement-player-controller-fingerprint")
@MatchingMethod("Lucf;", "L")
@FuzzyPatternScanMethod(3)
@PlayerPopupPanelsCompatibility
@Version("0.0.1")
object EngagementPanelControllerFingerprint : MethodFingerprint(
"L", AccessFlags.PRIVATE or AccessFlags.FINAL, listOf("L", "L", "Z", "Z", "Z"), listOf(
Opcode.MOVE_OBJECT_FROM16,
Opcode.MOVE_OBJECT_FROM16,
Opcode.MOVE_FROM16,
Opcode.IGET_BOOLEAN,
Opcode.CONST_4,
Opcode.IF_NEZ,
Opcode.CONST_STRING,
Opcode.INVOKE_STATIC,
Opcode.SGET_OBJECT,
Opcode.SGET_OBJECT,
Opcode.CONST_STRING,
Opcode.INVOKE_STATIC,
Opcode.RETURN_OBJECT,
Opcode.IGET_OBJECT,
Opcode.IGET_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.CONST_4,
Opcode.CONST_4,
Opcode.CONST_4,
Opcode.CONST_4,
Opcode.CONST_4,
Opcode.CONST_4,
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package app.revanced.patches.youtube.layout.playerpopuppanels.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.playerpopuppanels.annotations.PlayerPopupPanelsCompatibility
import app.revanced.patches.youtube.layout.playerpopuppanels.fingerprints.EngagementPanelControllerFingerprint
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

@Patch
@DependsOn([IntegrationsPatch::class, SettingsPatch::class])
@Name("disable-auto-player-popup-panels")
@Description("Disable automatic popup panels (playlist or live chat) on video player.")
@PlayerPopupPanelsCompatibility
@Version("0.0.1")
class PlayerPopupPanelsPatch : BytecodePatch(
listOf(
EngagementPanelControllerFingerprint
)
) {
override fun execute(data: BytecodeData): PatchResult {
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
SwitchPreference(
"revanced_player_popup_panels_enabled",
StringResource("revanced_player_popup_panels_title", "Disable player popup panels"),
false,
StringResource("revanced_player_popup_panels_summary_on", "Player popup panels are enabled"),
StringResource("revanced_player_popup_panels_summary_off", "Player popup panels are disabled")
)
)

val engagementPanelControllerMethod = EngagementPanelControllerFingerprint.result!!.mutableMethod

engagementPanelControllerMethod.addInstructions(
0, """
invoke-static { }, Lapp/revanced/integrations/patches/DisablePlayerPopupPanelsPatch;->disablePlayerPopupPanels()Z
move-result v0
if-eqz v0, :player_popup_panels
if-eqz p4, :player_popup_panels
const/4 v0, 0x0
return-object v0
:player_popup_panels
nop
"""
)

return PatchResultSuccess()
}
}

0 comments on commit 69c9b58

Please sign in to comment.