add hide-category-bar patch

This commit is contained in:
inotia00
2023-03-27 22:31:10 +09:00
parent e991663779
commit 274247e619
6 changed files with 146 additions and 1 deletions

View File

@ -0,0 +1,21 @@
package app.revanced.patches.youtube.layout.general.categorybar.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
object FilterBarHeightFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.CONST,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT,
Opcode.IPUT
),
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any {
it.opcode.ordinal == Opcode.CONST.ordinal &&
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.filterBarHeightLabelId
} == true
}
)

View File

@ -0,0 +1,20 @@
package app.revanced.patches.youtube.layout.general.categorybar.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
object RelatedChipCloudFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.CONST,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT
),
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any {
it.opcode.ordinal == Opcode.CONST.ordinal &&
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.relatedChipCloudMarginLabelId
} == true
}
)

View File

@ -0,0 +1,91 @@
package app.revanced.patches.youtube.layout.general.categorybar.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.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.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.layout.general.categorybar.fingerprints.FilterBarHeightFingerprint
import app.revanced.patches.youtube.layout.general.categorybar.fingerprints.RelatedChipCloudFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.GENERAL_LAYOUT
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
@Patch
@Name("hide-category-bar")
@Description("Hide the category bar at the top of the feed and at the top of related videos.")
@DependsOn(
[
SettingsPatch::class,
SharedResourceIdPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class CategoryBarPatch : BytecodePatch(
listOf(
FilterBarHeightFingerprint,
RelatedChipCloudFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
/**
* Category Bar in feed
* Home feed and subscriptions feed
*/
FilterBarHeightFingerprint.result?.let {
with (it.mutableMethod) {
val insertIndex = it.scanResult.patternScanResult!!.endIndex
val register = (instruction(insertIndex) as TwoRegisterInstruction).registerA
addInstructions(
insertIndex, """
invoke-static {v$register}, $GENERAL_LAYOUT->hideCategoryBarInFeed(I)I
move-result v$register
"""
)
}
} ?: return FilterBarHeightFingerprint.toErrorResult()
/**
* Category Bar in related video
*/
RelatedChipCloudFingerprint.result?.let {
with (it.mutableMethod) {
val insertIndex = it.scanResult.patternScanResult!!.endIndex
val register = (instruction(insertIndex) as OneRegisterInstruction).registerA
addInstruction(
insertIndex + 1,
"invoke-static {v$register}, $GENERAL_LAYOUT->hideCategoryBarInRelatedVideo(Landroid/view/View;)V"
)
}
} ?: return RelatedChipCloudFingerprint.toErrorResult()
/*
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: GENERAL_LAYOUT_SETTINGS",
"SETTINGS: HIDE_CATEGORY_BAR"
)
)
SettingsPatch.updatePatchStatus("hide-category-bar")
return PatchResultSuccess()
}
}

View File

@ -27,6 +27,7 @@ class SharedResourceIdPatch : ResourcePatch {
var donationCompanionResourceId: Long = -1
var emptyColorLabelId: Long = -1
var fabLabelId: Long = -1
var filterBarHeightLabelId: Long = -1
var floatyBarQueueLabelId: Long = -1
var imageOnlyTabId: Long = -1
var imageWithTextTabId: Long = -1
@ -35,6 +36,7 @@ class SharedResourceIdPatch : ResourcePatch {
var layoutVideo: Long = -1
var liveChatButtonId: Long = -1
var reelPlayerFooterLabelId: Long = -1
var relatedChipCloudMarginLabelId: Long = -1
var scrubbingLabelId: Long = -1
var timeStampsContainerLabelId: Long = -1
var tooltipLabelId: Long = -1
@ -58,6 +60,7 @@ class SharedResourceIdPatch : ResourcePatch {
donationCompanionResourceId = findSharedResourceId("layout", "donation_companion")
emptyColorLabelId = findSharedResourceId("color", "inline_time_bar_colorized_bar_empty_color_dark")
fabLabelId = findSharedResourceId("id", "fab")
filterBarHeightLabelId = findSharedResourceId("dimen", "filter_bar_height")
floatyBarQueueLabelId = findSharedResourceId("string", "floaty_bar_queue_status")
imageOnlyTabId = findSharedResourceId("layout", "image_only_tab")
imageWithTextTabId = findSharedResourceId("layout", "image_with_text_tab")
@ -66,6 +69,7 @@ class SharedResourceIdPatch : ResourcePatch {
layoutVideo = findSharedResourceId("layout", "endscreen_element_layout_video")
liveChatButtonId = findSharedResourceId("id", "live_chat_overlay_button")
reelPlayerFooterLabelId = findSharedResourceId("layout", "reel_player_dyn_footer_vert_stories3")
relatedChipCloudMarginLabelId = findSharedResourceId("layout", "related_chip_cloud_reduced_margins")
scrubbingLabelId = findSharedResourceId("dimen", "vertical_touch_offset_to_enter_fine_scrubbing")
timeStampsContainerLabelId = findSharedResourceId("id", "timestamps_container")
tooltipLabelId = findSharedResourceId("layout", "tooltip_content_view")