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()
}
}