add hide-live-chat-button, hide-next-button , hide-prev-button patches (player controller)

This commit is contained in:
inotia00
2023-01-27 19:28:11 +09:00
parent 2c1fe86a60
commit 96d8f6b02b
7 changed files with 211 additions and 0 deletions

View File

@ -0,0 +1,49 @@
package app.revanced.patches.youtube.layout.player.livechatbutton.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
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.patcher.patch.annotations.Patch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.shared.annotation.YouTubeCompatibility
import app.revanced.shared.patches.playerbutton.PlayerButtonPatch
import app.revanced.shared.util.resources.ResourceHelper
@Patch
@Name("hide-live-chat-button")
@Description("Hides the live chat button in the video player.")
@DependsOn(
[
PlayerButtonPatch::class,
SettingsPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class HideLiveChatButtonPatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
/*
add settings
*/
ResourceHelper.addSettings2(
context,
"PREFERENCE_CATEGORY: REVANCED_SETTINGS",
"PREFERENCE: LAYOUT_SETTINGS",
"PREFERENCE_HEADER: PLAYER",
"SETTINGS: HIDE_LIVE_CHAT_BUTTON"
)
ResourceHelper.patchSuccess(
context,
"hide-live-chat-button"
)
return PatchResultSuccess()
}
}

View File

@ -0,0 +1,50 @@
package app.revanced.patches.youtube.layout.player.nextprevbutton.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
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.patcher.patch.annotations.Patch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.shared.annotation.YouTubeCompatibility
import app.revanced.shared.patches.playerbutton.PlayerButtonPatch
import app.revanced.shared.util.resources.ResourceHelper
@Patch
@Name("hide-next-prev-button")
@Description("Hides the next prev button in the player controller.")
@DependsOn(
[
PlayerButtonPatch::class,
SettingsPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class HideNextPrevButtonPatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
/*
add settings
*/
ResourceHelper.addSettings3(
context,
"PREFERENCE_CATEGORY: REVANCED_SETTINGS",
"PREFERENCE: LAYOUT_SETTINGS",
"PREFERENCE_HEADER: PLAYER",
"SETTINGS: HIDE_NEXT_BUTTON",
"SETTINGS: HIDE_PREV_BUTTON"
)
ResourceHelper.patchSuccess(
context,
"hide-next-prev-button"
)
return PatchResultSuccess()
}
}

View File

@ -32,6 +32,7 @@ class SharedResourcdIdPatch : ResourcePatch {
var layoutCircle: Long = -1
var layoutIcon: Long = -1
var layoutVideo: Long = -1
var liveChatButtonId: Long = -1
var scrubbingLabelId: Long = -1
var timebarColorLabelId: Long = -1
var videoqualityfragmentLabelId: Long = -1
@ -59,6 +60,7 @@ class SharedResourcdIdPatch : ResourcePatch {
layoutCircle = findSharedResourceId("layout", "endscreen_element_layout_circle")
layoutIcon = findSharedResourceId("layout", "endscreen_element_layout_icon")
layoutVideo = findSharedResourceId("layout", "endscreen_element_layout_video")
liveChatButtonId = findSharedResourceId("id", "live_chat_overlay_button")
scrubbingLabelId = findSharedResourceId("dimen", "vertical_touch_offset_to_enter_fine_scrubbing")
timebarColorLabelId = findSharedResourceId("color", "inline_time_bar_progress_color")
videoqualityfragmentLabelId = findSharedResourceId("layout", "video_quality_bottom_sheet_list_fragment_title")

View File

@ -0,0 +1,16 @@
package app.revanced.shared.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourcdIdPatch
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
import org.jf.dexlib2.Opcode
object LiveChatFingerprint : MethodFingerprint(
opcodes = listOf(Opcode.NEW_INSTANCE),
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any {
it.opcode.ordinal == Opcode.CONST.ordinal &&
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourcdIdPatch.liveChatButtonId
} == true
}
)

View File

@ -0,0 +1,74 @@
package app.revanced.shared.patches.playerbutton
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.patches.youtube.misc.resourceid.patch.SharedResourcdIdPatch
import app.revanced.shared.annotation.YouTubeCompatibility
import app.revanced.shared.extensions.findMutableMethodOf
import app.revanced.shared.extensions.toErrorResult
import app.revanced.shared.fingerprints.LiveChatFingerprint
import app.revanced.shared.util.integrations.Constants.PLAYER_LAYOUT
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.builder.instruction.BuilderInstruction21c
import org.jf.dexlib2.builder.instruction.BuilderInstruction35c
@Name("hook-player-button-patch")
@DependsOn([SharedResourcdIdPatch::class])
@YouTubeCompatibility
@Version("0.0.1")
class PlayerButtonPatch : BytecodePatch(
listOf(
LiveChatFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
LiveChatFingerprint.result?.let {
val endIndex = it.scanResult.patternScanResult!!.endIndex
val instuctions = it.mutableMethod.instruction(endIndex)
val imageButtonClass =
context
.findClass((instuctions as BuilderInstruction21c)
.reference.toString())!!
.mutableClass
for (method in imageButtonClass.methods) {
with (imageButtonClass.findMutableMethodOf(method)) {
var jumpInstruction = true
implementation!!.instructions.forEachIndexed { index, instuctions ->
if (instuctions.opcode.ordinal == Opcode.INVOKE_VIRTUAL.ordinal) {
val definedInstruction = (instuctions as? BuilderInstruction35c)
if (definedInstruction?.reference.toString() ==
"Landroid/view/View;->setVisibility(I)V") {
jumpInstruction = !jumpInstruction
if (jumpInstruction) return@forEachIndexed
val firstRegister = definedInstruction?.registerC
val secondRegister = definedInstruction?.registerD
addInstructions(
index, """
invoke-static {v$firstRegister, v$secondRegister}, $PLAYER_LAYOUT->hidePlayerButton(Landroid/view/View;I)I
move-result v$secondRegister
"""
)
}
}
}
}
}
} ?: return LiveChatFingerprint.toErrorResult()
return PatchResultSuccess()
}
}