From 570aa0b0fdb9c803da1e6341676d82a261914cdf Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Fri, 27 Oct 2023 12:40:53 +0900 Subject: [PATCH] fix(YouTube/Hide seek message): force closes in `YouTube v18.36.39` --- .../player/seekmessage/SeekMessagePatch.kt | 33 ++++++++++++++++++- .../youtube/utils/settings/SettingsPatch.kt | 6 ++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/seekmessage/SeekMessagePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/seekmessage/SeekMessagePatch.kt index 0c33f5c24..2760aa716 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/seekmessage/SeekMessagePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/seekmessage/SeekMessagePatch.kt @@ -94,8 +94,12 @@ object SeekMessagePatch : BytecodePatch( if (((targetInstruction as Instruction35c).reference as MethodReference).name != "setOnClickListener") continue + // Force close occurs only in YouTube v18.36.xx unless we add this. + if (SettingsPatch.is1836) + addComponent(insertIndex, index - 1) + addInstructionsWithLabels( - insertIndex, """ + insertIndex, fixComponent + """ invoke-static {}, $PLAYER->hideSeekUndoMessage()Z move-result v$insertRegister if-nez v$insertRegister, :default @@ -130,4 +134,31 @@ object SeekMessagePatch : BytecodePatch( SettingsPatch.updatePatchStatus("Hide seek message") } + + private var fixComponent: String = "" + + private fun MutableMethod.addComponent( + startIndex: Int, + endIndex: Int + ) { + val fixRegister = + getInstruction(endIndex).registerE + + for (index in endIndex downTo startIndex) { + val opcode = getInstruction(index).opcode + if (opcode != Opcode.CONST_16) + continue + + val register = getInstruction(index).registerA + + if (register != fixRegister) + continue + + val fixValue = getInstruction(index).wideLiteral.toInt() + + fixComponent = "const/16 v$fixRegister, $fixValue" + + break + } + } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt index 5f0aa30cc..84af23254 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt @@ -90,8 +90,9 @@ object SettingsPatch : AbstractSettingsResourcePatch( val playServicesVersion = node.textContent.toInt() - upward1828 = playServicesVersion >= 232900000 - upward1834 = playServicesVersion >= 233502000 + upward1828 = 232900000 <= playServicesVersion + upward1834 = 233502000 <= playServicesVersion + is1836 = playServicesVersion in 233700000..233801999 break } @@ -198,6 +199,7 @@ object SettingsPatch : AbstractSettingsResourcePatch( private val threadPoolExecutor = Executors.newFixedThreadPool(THREAD_COUNT) internal lateinit var contexts: ResourceContext + internal var is1836: Boolean = false internal var upward1828: Boolean = false internal var upward1834: Boolean = false