From 6f9a1cb1fe4828e91821e76ff4151ae4c47ed81c Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Sat, 23 Dec 2023 16:37:54 +0900 Subject: [PATCH] fix(YouTube/Enable wide search bar): layout breaks on devices above 720 dpi --- .../widesearchbar/WideSearchBarPatch.kt | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/WideSearchBarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/WideSearchBarPatch.kt index 930257279..dec9c5ac2 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/WideSearchBarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/WideSearchBarPatch.kt @@ -10,7 +10,6 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.youtube.general.widesearchbar.fingerprints.SetActionBarRingoFingerprint import app.revanced.patches.youtube.general.widesearchbar.fingerprints.SetWordMarkHeaderFingerprint import app.revanced.patches.youtube.general.widesearchbar.fingerprints.YouActionBarFingerprint -import app.revanced.patches.youtube.utils.fingerprints.LayoutSwitchFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch @@ -55,11 +54,13 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") object WideSearchBarPatch : BytecodePatch( setOf( - LayoutSwitchFingerprint, SetActionBarRingoFingerprint, SetWordMarkHeaderFingerprint ) ) { + private const val FLAG = "android:paddingStart" + private const val TARGET_RESOURCE_PATH = "res/layout/action_bar_ringo_background.xml" + override fun execute(context: BytecodeContext) { // resolves fingerprints @@ -74,22 +75,19 @@ object WideSearchBarPatch : BytecodePatch( .nextMethod(1, true) .getMethod() as MutableMethod - targetMethod.injectSearchBarHook() + targetMethod.apply { + injectSearchBarHook( + implementation!!.instructions.size - 1, + "enableWideSearchBar" + ) + } } ?: throw SetWordMarkHeaderFingerprint.exception - LayoutSwitchFingerprint.result?.mutableMethod?.injectSearchBarHook() - ?: throw LayoutSwitchFingerprint.exception - YouActionBarFingerprint.result?.let { it.mutableMethod.apply { - val insertIndex = it.scanResult.patternScanResult!!.endIndex - val insertRegister = getInstruction(insertIndex).registerA - - addInstructions( - insertIndex, """ - invoke-static {v$insertRegister}, $GENERAL->enableWideSearchBarInYouTab(Z)Z - move-result v$insertRegister - """ + injectSearchBarHook( + it.scanResult.patternScanResult!!.endIndex, + "enableWideSearchBarInYouTab" ) } } ?: throw YouActionBarFingerprint.exception @@ -123,17 +121,19 @@ object WideSearchBarPatch : BytecodePatch( } - private const val FLAG = "android:paddingStart" - private const val TARGET_RESOURCE_PATH = "res/layout/action_bar_ringo_background.xml" - /** * Injects instructions required for certain methods. */ - private fun MutableMethod.injectSearchBarHook() { + private fun MutableMethod.injectSearchBarHook( + insertIndex: Int, + descriptor: String + ) { + val insertRegister = getInstruction(insertIndex).registerA + addInstructions( - implementation!!.instructions.size - 1, """ - invoke-static {}, $GENERAL->enableWideSearchBar()Z - move-result p0 + insertIndex, """ + invoke-static {v$insertRegister}, $GENERAL->$descriptor(Z)Z + move-result v$insertRegister """ ) }