diff --git a/api/revanced-patches.api b/api/revanced-patches.api index 4bba02a52..28f813bcb 100644 --- a/api/revanced-patches.api +++ b/api/revanced-patches.api @@ -1819,6 +1819,7 @@ public final class app/revanced/util/BytecodeUtilsKt { public static final fun containsWideLiteralInstructionValue (Lcom/android/tools/smali/dexlib2/iface/Method;J)Z public static final fun findIndexForIdResource (Lcom/android/tools/smali/dexlib2/iface/Method;Ljava/lang/String;)I public static final fun findMutableMethodOf (Lapp/revanced/patcher/util/proxy/mutableTypes/MutableClass;Lcom/android/tools/smali/dexlib2/iface/Method;)Lapp/revanced/patcher/util/proxy/mutableTypes/MutableMethod; + public static final fun firstIndexForIdResource (Lcom/android/tools/smali/dexlib2/iface/Method;Ljava/lang/String;)I public static final fun getException (Lapp/revanced/patcher/fingerprint/MethodFingerprint;)Lapp/revanced/patcher/patch/PatchException; public static final fun indexOfFirstInstruction (Lcom/android/tools/smali/dexlib2/iface/Method;Lkotlin/jvm/functions/Function1;)I public static final fun indexOfFirstWideLiteralInstructionValue (Lcom/android/tools/smali/dexlib2/iface/Method;J)I diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/HideAutoplayButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/HideAutoplayButtonPatch.kt index d96caab79..037609b3c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/HideAutoplayButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/HideAutoplayButtonPatch.kt @@ -14,7 +14,7 @@ import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.SettingsPatch import app.revanced.patches.youtube.shared.fingerprints.LayoutConstructorFingerprint import app.revanced.util.exception -import app.revanced.util.findIndexForIdResource +import app.revanced.util.firstIndexForIdResource import com.android.tools.smali.dexlib2.iface.instruction.Instruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -69,7 +69,7 @@ object HideAutoplayButtonPatch : BytecodePatch( val layoutGenMethodInstructions = implementation!!.instructions // resolve the offsets of where to insert the branch instructions and ... - val insertIndex = findIndexForIdResource("autonav_preview_stub") + val insertIndex = firstIndexForIdResource("autonav_preview_stub") // where to branch away val branchIndex = diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsPatch.kt index e65eced6c..e43a598e9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsPatch.kt @@ -16,6 +16,7 @@ import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch import app.revanced.patches.youtube.misc.litho.filter.LithoFilterPatch import app.revanced.patches.youtube.misc.navigation.NavigationBarHookPatch import app.revanced.patches.youtube.misc.playertype.PlayerTypeHookPatch +import app.revanced.util.firstIndexForIdResource import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @@ -159,7 +160,7 @@ object HideShortsComponentsPatch : BytecodePatch( SHARE("reel_dyn_share", "hideShortsShareButton"); fun injectHideCall(method: MutableMethod) { - val referencedIndex = method.findIndexForIdResource(resourceName) + val referencedIndex = method.firstIndexForIdResource(resourceName) val setIdIndex = referencedIndex + 1 val viewRegister = method.getInstruction(setIdIndex).registerC diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsResourcePatch.kt index 8593cd056..7b80feade 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsResourcePatch.kt @@ -52,9 +52,8 @@ object HideShortsComponentsResourcePatch : ResourcePatch() { reelMultipleItemShelfId = it.id } - reelPlayerRightCellButtonHeight = - ResourceMappingPatch.resourceMappings.single { - it.type == "dimen" && it.name == "reel_player_right_cell_button_height" - }.id + reelPlayerRightCellButtonHeight = ResourceMappingPatch.resourceMappings.first { + it.type == "dimen" && it.name == "reel_player_right_cell_button_height" + }.id } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/fingerprints/CreateShortsButtonsFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/fingerprints/CreateShortsButtonsFingerprint.kt index 97ac69121..da5cdc634 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/fingerprints/CreateShortsButtonsFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/fingerprints/CreateShortsButtonsFingerprint.kt @@ -1,13 +1,10 @@ package app.revanced.patches.youtube.layout.hide.shorts.fingerprints -import app.revanced.patcher.extensions.or import app.revanced.patches.youtube.layout.hide.shorts.HideShortsComponentsResourcePatch import app.revanced.util.patch.LiteralValueFingerprint -import com.android.tools.smali.dexlib2.AccessFlags internal object CreateShortsButtonsFingerprint : LiteralValueFingerprint( - accessFlags = AccessFlags.PRIVATE or AccessFlags.FINAL, + // YT 19.12.x moved this code inside another method, and each method has different parameters. returnType = "V", - parameters = listOf("Z", "Z", "L"), literalSupplier = { HideShortsComponentsResourcePatch.reelPlayerRightCellButtonHeight } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerDimensionsCalculatorParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerDimensionsCalculatorParentFingerprint.kt index 244bf33d0..2e1612373 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerDimensionsCalculatorParentFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerDimensionsCalculatorParentFingerprint.kt @@ -12,7 +12,7 @@ internal object MiniPlayerDimensionsCalculatorParentFingerprint : MethodFingerpr opcodes = listOf( Opcode.CONST_HIGH16, Opcode.ADD_FLOAT_2ADDR, - Opcode.MUL_FLOAT, + null, // Opcode.MUL_FLOAT or Opcode.MUL_FLOAT_2ADDR Opcode.CONST_4, Opcode.INVOKE_STATIC, Opcode.MOVE_RESULT, diff --git a/src/main/kotlin/app/revanced/util/BytecodeUtils.kt b/src/main/kotlin/app/revanced/util/BytecodeUtils.kt index 8daf77702..bf5f759f0 100644 --- a/src/main/kotlin/app/revanced/util/BytecodeUtils.kt +++ b/src/main/kotlin/app/revanced/util/BytecodeUtils.kt @@ -70,13 +70,26 @@ fun MutableMethod.injectHideViewCall( * * @param resourceName the name of the resource to find the id for. * @return the index of the first instruction with the id of the given resource name, or -1 if not found. + * @see [firstIndexForIdResource] */ fun Method.findIndexForIdResource(resourceName: String): Int { - fun getIdResourceId(resourceName: String) = ResourceMappingPatch.resourceMappings.single { + val resource = ResourceMappingPatch.resourceMappings.find { it.type == "id" && it.name == resourceName - }.id + } ?: throw PatchException("Could not find resource id: $resourceName") - return indexOfFirstWideLiteralInstructionValue(getIdResourceId(resourceName)) + return indexOfFirstWideLiteralInstructionValue(resource.id) +} + +/** + * Identical to [findIndexForIdResource], except this throws an exception if the method does not contain + * the resource id literal value. + * + * @throws [PatchException] if the resource is not found, or the method does not contain the resource id literal value. + */ +fun Method.firstIndexForIdResource(resourceName: String): Int { + val index = findIndexForIdResource(resourceName); + if (index < 0) throw PatchException("Found resource id for: '$resourceName' but method does not contain the id: $this") + return index; } /**