refactor(hide-category-bar): add Hide category bar in search results setting

This commit is contained in:
inotia00
2023-03-28 21:46:19 +09:00
parent 49aca64088
commit e41fc03e64
5 changed files with 47 additions and 2 deletions

View File

@ -0,0 +1,22 @@
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 SearchResultsChipBarFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.CONST,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT
),
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any {
it.opcode.ordinal == Opcode.CONST.ordinal &&
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.barContainerHeightLabelId
} == true
}
)

View File

@ -16,6 +16,7 @@ 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.layout.general.categorybar.fingerprints.SearchResultsChipBarFingerprint
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
@ -36,7 +37,8 @@ import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
class CategoryBarPatch : BytecodePatch(
listOf(
FilterBarHeightFingerprint,
RelatedChipCloudFingerprint
RelatedChipCloudFingerprint,
SearchResultsChipBarFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
@ -74,6 +76,23 @@ class CategoryBarPatch : BytecodePatch(
}
} ?: return RelatedChipCloudFingerprint.toErrorResult()
/**
* Category Bar in search results
*/
SearchResultsChipBarFingerprint.result?.let {
with (it.mutableMethod) {
val targetIndex = it.scanResult.patternScanResult!!.endIndex - 2
val register = (instruction(targetIndex) as OneRegisterInstruction).registerA
addInstructions(
targetIndex + 1, """
invoke-static {v$register}, $GENERAL_LAYOUT->hideCategoryBarInSearchResults(I)I
move-result v$register
"""
)
}
} ?: return SearchResultsChipBarFingerprint.toErrorResult()
/*
* Add settings
*/