generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 310
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-overlay): make it toggleable in settings (#2044
) Co-authored-by: oSumAtrIX <[email protected]>
- Loading branch information
1 parent
3ec25bb
commit f693d55
Showing
5 changed files
with
126 additions
and
51 deletions.
There are no files selected for viewing
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
28 changes: 28 additions & 0 deletions
28
...utube/layout/hide/player/overlay/bytecode/fingerprints/CreatePlayerOverviewFingerprint.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,28 @@ | ||
package app.revanced.patches.youtube.layout.hide.player.overlay.bytecode.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patches.youtube.layout.hide.player.overlay.resource.patch.HidePlayerOverlayResourcePatch | ||
import org.jf.dexlib2.AccessFlags | ||
import org.jf.dexlib2.Opcode | ||
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction | ||
|
||
object CreatePlayerOverviewFingerprint : MethodFingerprint( | ||
returnType = "V", | ||
access = AccessFlags.PRIVATE or AccessFlags.FINAL, | ||
opcodes = listOf( | ||
Opcode.CONST, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.MOVE_RESULT_OBJECT, | ||
Opcode.CHECK_CAST | ||
), | ||
customFingerprint = { methodDef -> | ||
methodDef.implementation?.instructions?.any { | ||
if (it.opcode != Opcode.INVOKE_VIRTUAL) return@any false | ||
|
||
val literal = (it as WideLiteralInstruction).wideLiteral | ||
|
||
literal == HidePlayerOverlayResourcePatch.scrimOverlayId | ||
} ?: false | ||
} | ||
) |
53 changes: 53 additions & 0 deletions
53
...anced/patches/youtube/layout/hide/player/overlay/bytecode/patch/HidePlayerOverlayPatch.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,53 @@ | ||
package app.revanced.patches.youtube.layout.hide.player.overlay.bytecode.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.addInstruction | ||
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.youtube.layout.hide.player.overlay.annotations.HidePlayerOverlayPatchCompatibility | ||
import app.revanced.patches.youtube.layout.hide.player.overlay.bytecode.fingerprints.CreatePlayerOverviewFingerprint | ||
import app.revanced.patches.youtube.layout.hide.player.overlay.resource.patch.HidePlayerOverlayResourcePatch | ||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction | ||
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction | ||
|
||
@Patch | ||
@Name("hide-player-overlay") | ||
@Description("Hides the dark background overlay from the player when player controls are visible.") | ||
@DependsOn([HidePlayerOverlayResourcePatch::class]) | ||
@HidePlayerOverlayPatchCompatibility | ||
@Version("0.0.2") | ||
class HidePlayerOverlayPatch : BytecodePatch(listOf(CreatePlayerOverviewFingerprint)) { | ||
override fun execute(context: BytecodeContext): PatchResult { | ||
CreatePlayerOverviewFingerprint.result?.let { result -> | ||
result.mutableMethod.apply { | ||
val viewRegisterIndex = implementation!!.instructions.indexOfFirst { | ||
val literal = (it as? WideLiteralInstruction)?.wideLiteral | ||
|
||
literal == HidePlayerOverlayResourcePatch.scrimOverlayId | ||
} + 3 | ||
val viewRegister = instruction<OneRegisterInstruction>(viewRegisterIndex).registerA | ||
|
||
val insertIndex = viewRegisterIndex + 1 | ||
addInstruction( | ||
insertIndex, | ||
"invoke-static { v$viewRegister }, " + | ||
"$INTEGRATIONS_CLASS_DESCRIPTOR->hidePlayerOverlay(Landroid/widget/ImageView;)V" | ||
) | ||
} | ||
} ?: return CreatePlayerOverviewFingerprint.toErrorResult() | ||
|
||
return PatchResultSuccess() | ||
} | ||
|
||
private companion object { | ||
const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/HidePlayerOverlayPatch;" | ||
} | ||
} |
46 changes: 0 additions & 46 deletions
46
...n/app/revanced/patches/youtube/layout/hide/player/overlay/patch/HidePlayerOverlayPatch.kt
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
...tches/youtube/layout/hide/player/overlay/resource/patch/HidePlayerOverlayResourcePatch.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.hide.player.overlay.resource.patch | ||
|
||
import app.revanced.patcher.data.ResourceContext | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patcher.patch.ResourcePatch | ||
import app.revanced.patcher.patch.annotations.DependsOn | ||
import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch | ||
import app.revanced.patches.shared.settings.preference.impl.StringResource | ||
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference | ||
import app.revanced.patches.youtube.layout.hide.player.overlay.annotations.HidePlayerOverlayPatchCompatibility | ||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch | ||
import jdk.jfr.Name | ||
|
||
@Name("hide-player-overlay-resource-patch") | ||
@DependsOn([SettingsPatch::class, ResourceMappingPatch::class]) | ||
@HidePlayerOverlayPatchCompatibility | ||
class HidePlayerOverlayResourcePatch : ResourcePatch { | ||
override fun execute(context: ResourceContext): PatchResult { | ||
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( | ||
SwitchPreference( | ||
"revanced_hide_player_overlay", | ||
StringResource("revanced_hide_player_overlay_title", "Hide background overlay in player"), | ||
false, | ||
StringResource("revanced_hide_player_overlay_summary_on", "Background overlay is hidden"), | ||
StringResource("revanced_hide_player_overlay_summary_off", "Background overlay is shown") | ||
) | ||
) | ||
|
||
scrimOverlayId = ResourceMappingPatch.resourceMappings.single { | ||
it.type == "id" && it.name == "scrim_overlay" | ||
}.id | ||
|
||
return PatchResultSuccess() | ||
} | ||
|
||
internal companion object { | ||
var scrimOverlayId: Long = -1 | ||
} | ||
} |