diff --git a/src/main/kotlin/app/revanced/patches/shared/annotation/YouTubeCompatibility.kt b/src/main/kotlin/app/revanced/patches/shared/annotation/YouTubeCompatibility.kt index be4bb84c8..348eacbd6 100644 --- a/src/main/kotlin/app/revanced/patches/shared/annotation/YouTubeCompatibility.kt +++ b/src/main/kotlin/app/revanced/patches/shared/annotation/YouTubeCompatibility.kt @@ -15,7 +15,8 @@ import app.revanced.patcher.annotation.Package "18.12.35", "18.13.38", "18.14.41", - "18.15.40" + "18.15.40", + "18.16.37" ) )] ) diff --git a/src/main/kotlin/app/revanced/patches/shared/fingerprints/PivotBarCreateButtonViewFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/fingerprints/PivotBarCreateButtonViewFingerprint.kt index 5a195aa7c..202e68781 100644 --- a/src/main/kotlin/app/revanced/patches/shared/fingerprints/PivotBarCreateButtonViewFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/shared/fingerprints/PivotBarCreateButtonViewFingerprint.kt @@ -10,6 +10,10 @@ import org.jf.dexlib2.Opcode object PivotBarCreateButtonViewFingerprint : MethodFingerprint( returnType = "V", access = AccessFlags.PUBLIC or AccessFlags.FINAL, + opcodes = listOf( + Opcode.MOVE_OBJECT, + Opcode.INVOKE_DIRECT_RANGE, // unique instruction anchor + ), customFingerprint = { methodDef -> methodDef.implementation?.instructions?.any { it.opcode.ordinal == Opcode.CONST.ordinal && diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/tabletminiplayer/fingerprints/MiniPlayerDimensionsCalculatorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/tabletminiplayer/fingerprints/MiniPlayerDimensionsCalculatorFingerprint.kt index a1c963c8b..1a550eb5d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/general/tabletminiplayer/fingerprints/MiniPlayerDimensionsCalculatorFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/tabletminiplayer/fingerprints/MiniPlayerDimensionsCalculatorFingerprint.kt @@ -13,7 +13,7 @@ object MiniPlayerDimensionsCalculatorFingerprint : MethodFingerprint( customFingerprint = { methodDef -> methodDef.implementation?.instructions?.any { it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.floatyBarQueueLabelId + (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.floatyBarTopMarginLabelId } == true } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/createbutton/fingerprints/PivotBarFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/createbutton/fingerprints/PivotBarFingerprint.kt deleted file mode 100644 index 6156174b4..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/createbutton/fingerprints/PivotBarFingerprint.kt +++ /dev/null @@ -1,25 +0,0 @@ -package app.revanced.patches.youtube.layout.navigation.createbutton.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch -import org.jf.dexlib2.iface.instruction.WideLiteralInstruction -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode - -object PivotBarFingerprint : MethodFingerprint( - returnType = "L", - access = AccessFlags.PUBLIC or AccessFlags.FINAL, - opcodes = listOf( - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT_OBJECT, - Opcode.RETURN_OBJECT - ), - customFingerprint = { methodDef -> - methodDef.definingClass == "Lcom/google/android/apps/youtube/app/ui/pivotbar/PivotBar;" && - methodDef.implementation?.instructions?.any { - it.opcode.ordinal == Opcode.CONST.ordinal && - (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.imageWithTextTabId - } == true - } -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/createbutton/patch/CreateButtonRemoverPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/createbutton/patch/CreateButtonRemoverPatch.kt index 6783ed9ba..ef58ed6c9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/createbutton/patch/CreateButtonRemoverPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/createbutton/patch/CreateButtonRemoverPatch.kt @@ -12,14 +12,12 @@ 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.shared.fingerprints.PivotBarCreateButtonViewFingerprint -import app.revanced.patches.youtube.layout.navigation.createbutton.fingerprints.PivotBarFingerprint 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.NAVIGATION import app.revanced.util.pivotbar.InjectionUtils.REGISTER_TEMPLATE_REPLACEMENT import app.revanced.util.pivotbar.InjectionUtils.injectHook -import org.jf.dexlib2.dexbacked.reference.DexBackedMethodReference -import org.jf.dexlib2.iface.instruction.ReferenceInstruction +import org.jf.dexlib2.Opcode @Patch @Name("hide-create-button") @@ -34,57 +32,37 @@ import org.jf.dexlib2.iface.instruction.ReferenceInstruction @Version("0.0.1") class CreateButtonRemoverPatch : BytecodePatch( listOf( - PivotBarCreateButtonViewFingerprint, - PivotBarFingerprint + PivotBarCreateButtonViewFingerprint ) ) { override fun execute(context: BytecodeContext): PatchResult { - /* - * Resolve fingerprints - */ - - PivotBarFingerprint.result?.let { - val startIndex = it.scanResult.patternScanResult!!.startIndex - val pivotBarInstructions = it.mutableMethod.implementation!!.instructions - createRef = (pivotBarInstructions.elementAt(startIndex) as ReferenceInstruction).reference as DexBackedMethodReference - } ?: return PivotBarFingerprint.toErrorResult() - PivotBarCreateButtonViewFingerprint.result?.let { result -> - with (result.mutableMethod){ - val createButtonInstructions = implementation!!.instructions - createButtonInstructions.filter { instruction -> - val fieldReference = (instruction as? ReferenceInstruction)?.reference as? DexBackedMethodReference - fieldReference?.let { it.definingClass == createRef.definingClass && it.name == createRef.name } == true - }.forEach { instruction -> - if (foundIndex == 0) { - foundIndex++ - return@forEach + with (result.mutableMethod) { + val insertIndex = implementation!!.instructions.let { + val scanStart = result.scanResult.patternScanResult!!.endIndex + + scanStart + it.subList(scanStart, it.size - 1).indexOfFirst { instruction -> + instruction.opcode == Opcode.INVOKE_STATIC } - - /* - * Inject hooks - */ - - injectHook(hook, createButtonInstructions.indexOf(instruction) + 2) - - /* - * Add settings - */ - SettingsPatch.addPreference( - arrayOf( - "PREFERENCE: NAVIGATION_SETTINGS", - "SETTINGS: HIDE_CREATE_BUTTON" - ) - ) - - SettingsPatch.updatePatchStatus("hide-create-button") - - return PatchResultSuccess() } - return PivotBarCreateButtonViewFingerprint.toErrorResult() + injectHook(hook, insertIndex) } } ?: return PivotBarCreateButtonViewFingerprint.toErrorResult() + + /* + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "PREFERENCE: NAVIGATION_SETTINGS", + "SETTINGS: HIDE_CREATE_BUTTON" + ) + ) + + SettingsPatch.updatePatchStatus("hide-create-button") + + return PatchResultSuccess() } private companion object { @@ -92,9 +70,5 @@ class CreateButtonRemoverPatch : BytecodePatch( "invoke-static { v$REGISTER_TEMPLATE_REPLACEMENT }, $NAVIGATION" + "->" + "hideCreateButton(Landroid/view/View;)V" - - lateinit var createRef: DexBackedMethodReference - - var foundIndex: Int = 0 } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/tabletnavbar/fingerprints/PivotBarChangedFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/tabletnavbar/fingerprints/PivotBarChangedFingerprint.kt index 8d4d9e3e2..a5d3089c9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/tabletnavbar/fingerprints/PivotBarChangedFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/tabletnavbar/fingerprints/PivotBarChangedFingerprint.kt @@ -9,6 +9,6 @@ object PivotBarChangedFingerprint : MethodFingerprint( Opcode.INVOKE_STATIC, Opcode.MOVE_RESULT ), - customFingerprint = { it.definingClass == "Lcom/google/android/apps/youtube/app/ui/pivotbar/PivotBar;" + customFingerprint = { it.definingClass.endsWith("PivotBar;") && it.name == "onConfigurationChanged" } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/tabletnavbar/fingerprints/PivotBarStyleFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/tabletnavbar/fingerprints/PivotBarStyleFingerprint.kt index 82dc49e14..de76fcfe7 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/tabletnavbar/fingerprints/PivotBarStyleFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/navigation/tabletnavbar/fingerprints/PivotBarStyleFingerprint.kt @@ -11,5 +11,5 @@ object PivotBarStyleFingerprint : MethodFingerprint( Opcode.MOVE_RESULT, Opcode.XOR_INT_2ADDR ), - customFingerprint = { it.definingClass == "Lcom/google/android/apps/youtube/app/ui/pivotbar/PivotBar;" } + customFingerprint = { it.definingClass.endsWith("PivotBar;") } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt index 1a8eafd5a..5512884c8 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt @@ -31,9 +31,8 @@ class SharedResourceIdPatch : ResourcePatch { var donationCompanionResourceId: Long = -1 var fabLabelId: Long = -1 var filterBarHeightLabelId: Long = -1 - var floatyBarQueueLabelId: Long = -1 + var floatyBarTopMarginLabelId: Long = -1 var imageOnlyTabId: Long = -1 - var imageWithTextTabId: Long = -1 var layoutCircle: Long = -1 var layoutIcon: Long = -1 var layoutVideo: Long = -1 @@ -72,9 +71,8 @@ class SharedResourceIdPatch : ResourcePatch { donationCompanionResourceId = find(LAYOUT, "donation_companion") fabLabelId = find(ID, "fab") filterBarHeightLabelId = find(DIMEN, "filter_bar_height") - floatyBarQueueLabelId = find(STRING, "floaty_bar_queue_status") + floatyBarTopMarginLabelId = find(DIMEN, "floaty_bar_button_top_margin") imageOnlyTabId = find(LAYOUT, "image_only_tab") - imageWithTextTabId = find(LAYOUT, "image_with_text_tab") layoutCircle = find(LAYOUT, "endscreen_element_layout_circle") layoutIcon = find(LAYOUT, "endscreen_element_layout_icon") layoutVideo = find(LAYOUT, "endscreen_element_layout_video")