forked from ReVanced/revanced-patches-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(youtube):
hide-player-buttons
patch
Signed-off-by: oSumAtrIX <[email protected]>
- Loading branch information
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...anced/patches/youtube/layout/player/buttons/annotations/HidePlayerButtonsCompatibility.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.player.buttons.annotations | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
@Compatibility( | ||
[Package( | ||
"com.google.android.youtube", arrayOf() | ||
)] | ||
) | ||
@Target(AnnotationTarget.CLASS) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
internal annotation class HidePlayerButtonsCompatibility |
9 changes: 9 additions & 0 deletions
9
...es/youtube/layout/player/buttons/fingerprints/PlayerControlsVisibilityModelFingerprint.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,9 @@ | ||
package app.revanced.patches.youtube.layout.player.buttons.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import org.jf.dexlib2.Opcode | ||
|
||
object PlayerControlsVisibilityModelFingerprint : MethodFingerprint( | ||
opcodes = listOf(Opcode.INVOKE_DIRECT_RANGE), | ||
strings = listOf("hasNext", "hasPrevious", "Missing required properties:") | ||
) |
74 changes: 74 additions & 0 deletions
74
...kotlin/app/revanced/patches/youtube/layout/player/buttons/patch/HidePlayerButtonsPatch.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,74 @@ | ||
package app.revanced.patches.youtube.layout.player.buttons.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.extensions.instruction | ||
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.patches.shared.settings.preference.impl.StringResource | ||
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference | ||
import app.revanced.patches.youtube.layout.player.buttons.annotations.HidePlayerButtonsCompatibility | ||
import app.revanced.patches.youtube.layout.player.buttons.fingerprints.PlayerControlsVisibilityModelFingerprint | ||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch | ||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch | ||
import org.jf.dexlib2.iface.instruction.formats.Instruction3rc | ||
|
||
@Patch | ||
@DependsOn([IntegrationsPatch::class, SettingsPatch::class]) | ||
@Name("hide-player-buttons") | ||
@Description("Adds the option to hide video player previous and next buttons.") | ||
@HidePlayerButtonsCompatibility | ||
@Version("0.0.1") | ||
class HidePlayerButtonsPatch : BytecodePatch( | ||
listOf(PlayerControlsVisibilityModelFingerprint) | ||
) { | ||
private object ParameterOffsets { | ||
const val HAS_NEXT = 5 | ||
} | ||
|
||
override fun execute(context: BytecodeContext): PatchResult { | ||
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( | ||
SwitchPreference( | ||
"revanced_hide_player_buttons", | ||
StringResource( | ||
"revanced_hide_player_buttons_title", | ||
"Hide previous & next video buttons" | ||
), | ||
false, | ||
StringResource( | ||
"revanced_hide_player_buttons_summary_on", | ||
"The buttons are hidden" | ||
), | ||
StringResource( | ||
"revanced_hide_player_buttons_summary_off", | ||
"The buttons are shown" | ||
) | ||
) | ||
) | ||
|
||
PlayerControlsVisibilityModelFingerprint.result?.apply { | ||
val callIndex = scanResult.patternScanResult!!.endIndex | ||
val callInstruction = mutableMethod.instruction(callIndex) as Instruction3rc | ||
|
||
// overriding this parameter register hides the previous and next buttons | ||
val hasNextParameterRegister = callInstruction.startRegister + ParameterOffsets.HAS_NEXT | ||
|
||
mutableMethod.addInstructions( | ||
callIndex, | ||
""" | ||
invoke-static { }, Lapp/revanced/integrations/patches/HidePlayerButtonsPatch;->hideButtons()Z | ||
move-result v$hasNextParameterRegister | ||
xor-int/lit8 v$hasNextParameterRegister, v$hasNextParameterRegister, 1 | ||
""" | ||
) | ||
} ?: return PlayerControlsVisibilityModelFingerprint.toErrorResult() | ||
return PatchResultSuccess() | ||
} | ||
} |