From 29f952d73e07f8f666d4744d6d97374bebfdc3c6 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Mon, 13 Mar 2023 03:03:46 +0400 Subject: [PATCH] feat(youtube/custom-video-buffer): replace patch with removal notice (#1718) Co-authored-by: oSumAtrIX --- .../impl/NonInteractivePreference.kt | 26 +++ .../CustomVideoBufferCompatibility.kt | 1 + .../InvokeMaxBufferFingerprint.kt | 12 -- .../fingerprints/MaxBufferFingerprint.kt | 8 - .../fingerprints/PlaybackBufferFingerprint.kt | 18 -- .../fingerprints/ReBufferFingerprint.kt | 18 -- .../patch/CustomVideoBufferPatch.kt | 183 +----------------- 7 files changed, 36 insertions(+), 230 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/shared/settings/preference/impl/NonInteractivePreference.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/fingerprints/InvokeMaxBufferFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/fingerprints/MaxBufferFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/fingerprints/PlaybackBufferFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/fingerprints/ReBufferFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/shared/settings/preference/impl/NonInteractivePreference.kt b/src/main/kotlin/app/revanced/patches/shared/settings/preference/impl/NonInteractivePreference.kt new file mode 100644 index 0000000000..9332bd17d0 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/shared/settings/preference/impl/NonInteractivePreference.kt @@ -0,0 +1,26 @@ +package app.revanced.patches.shared.settings.preference.impl + +import app.revanced.patches.shared.settings.preference.BasePreference +import app.revanced.patches.shared.settings.preference.IResource +import app.revanced.patches.shared.settings.preference.addSummary +import org.w3c.dom.Document +import org.w3c.dom.Element + +/** + * A simple static title and summary that is not backed by any preference key/value, + * and cannot be changed by or interacted with by the user, + */ +internal class NonInteractivePreference( + title: StringResource, + val summary: StringResource, +) : BasePreference("", title) { + override val tag: String = "Preference" + + override fun serialize(ownerDocument: Document, resourceCallback: ((IResource) -> Unit)?): Element { + return super.serialize(ownerDocument, resourceCallback).apply { + addSummary(summary.also { resourceCallback?.invoke(it) + setAttribute("android:selectable", false.toString()) + }) + } + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/annotations/CustomVideoBufferCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/annotations/CustomVideoBufferCompatibility.kt index 070791b976..5139f029f7 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/annotations/CustomVideoBufferCompatibility.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/annotations/CustomVideoBufferCompatibility.kt @@ -3,6 +3,7 @@ package app.revanced.patches.youtube.misc.videobuffer.annotations import app.revanced.patcher.annotation.Compatibility import app.revanced.patcher.annotation.Package +// TODO: delete this @Compatibility( [Package( "com.google.android.youtube", arrayOf( diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/fingerprints/InvokeMaxBufferFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/fingerprints/InvokeMaxBufferFingerprint.kt deleted file mode 100644 index 1d00997a93..0000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/fingerprints/InvokeMaxBufferFingerprint.kt +++ /dev/null @@ -1,12 +0,0 @@ -package app.revanced.patches.youtube.misc.videobuffer.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode - -object InvokeMaxBufferFingerprint : MethodFingerprint( - "Z", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf("J", "J", "F"), - listOf(Opcode.CONST_WIDE_16), - strings = listOf("scl.") -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/fingerprints/MaxBufferFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/fingerprints/MaxBufferFingerprint.kt deleted file mode 100644 index 556d35d157..0000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/fingerprints/MaxBufferFingerprint.kt +++ /dev/null @@ -1,8 +0,0 @@ -package app.revanced.patches.youtube.misc.videobuffer.fingerprints - -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.Opcode - -object MaxBufferFingerprint : MethodFingerprint( - opcodes = listOf(Opcode.SGET_OBJECT, Opcode.IGET, Opcode.IF_EQZ, Opcode.RETURN), -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/fingerprints/PlaybackBufferFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/fingerprints/PlaybackBufferFingerprint.kt deleted file mode 100644 index b4de743581..0000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/fingerprints/PlaybackBufferFingerprint.kt +++ /dev/null @@ -1,18 +0,0 @@ -package app.revanced.patches.youtube.misc.videobuffer.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction - -object PlaybackBufferFingerprint : MethodFingerprint( - "I", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf(), - listOf(Opcode.IF_LEZ, Opcode.RETURN), - customFingerprint = { methodDef -> - methodDef.definingClass == "Lcom/google/android/libraries/youtube/innertube/model/media/PlayerConfigModel;" - && methodDef.implementation!!.instructions.any { - ((it as? NarrowLiteralInstruction)?.narrowLiteral == 1600) - } - } -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/fingerprints/ReBufferFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/fingerprints/ReBufferFingerprint.kt deleted file mode 100644 index d9754ddec3..0000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/fingerprints/ReBufferFingerprint.kt +++ /dev/null @@ -1,18 +0,0 @@ -package app.revanced.patches.youtube.misc.videobuffer.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction - -object ReBufferFingerprint : MethodFingerprint( - "I", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf(), - listOf(Opcode.IF_LEZ, Opcode.RETURN), - customFingerprint = { methodDef -> - methodDef.definingClass == "Lcom/google/android/libraries/youtube/innertube/model/media/PlayerConfigModel;" - && methodDef.implementation!!.instructions.any { - ((it as? NarrowLiteralInstruction)?.narrowLiteral == 5000) - } - } -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/patch/CustomVideoBufferPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/patch/CustomVideoBufferPatch.kt index 7b5f572c1d..b8b7a4da7c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/patch/CustomVideoBufferPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/videobuffer/patch/CustomVideoBufferPatch.kt @@ -1,201 +1,36 @@ package app.revanced.patches.youtube.misc.videobuffer.patch -import app.revanced.extensions.toErrorResult import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.data.toMethodWalker -import app.revanced.patcher.extensions.addInstructions -import app.revanced.patcher.extensions.instruction -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod -import app.revanced.patches.shared.settings.preference.impl.InputType -import app.revanced.patches.shared.settings.preference.impl.PreferenceScreen -import app.revanced.patches.shared.settings.preference.impl.StringResource -import app.revanced.patches.shared.settings.preference.impl.TextPreference +import app.revanced.patches.shared.settings.preference.impl.* import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch import app.revanced.patches.youtube.misc.videobuffer.annotations.CustomVideoBufferCompatibility -import app.revanced.patches.youtube.misc.videobuffer.fingerprints.InvokeMaxBufferFingerprint -import app.revanced.patches.youtube.misc.videobuffer.fingerprints.MaxBufferFingerprint -import app.revanced.patches.youtube.misc.videobuffer.fingerprints.PlaybackBufferFingerprint -import app.revanced.patches.youtube.misc.videobuffer.fingerprints.ReBufferFingerprint -import org.jf.dexlib2.iface.instruction.OneRegisterInstruction -@Patch +// TODO: delete this patch +@Patch(include = false) @Name("custom-video-buffer") @Description("Lets you change the buffers of videos.") @DependsOn([SettingsPatch::class]) @CustomVideoBufferCompatibility @Version("0.0.1") -class CustomVideoBufferPatch : BytecodePatch( - listOf( - InvokeMaxBufferFingerprint, - PlaybackBufferFingerprint, - ReBufferFingerprint, - ) -) { +class CustomVideoBufferPatch : BytecodePatch() { override fun execute(context: BytecodeContext): PatchResult { SettingsPatch.PreferenceScreen.MISC.addPreferences( - PreferenceScreen( - "revanced_custom_video_buffer", - StringResource("revanced_custom_video_buffer_title", "Video buffer settings"), - listOf( - TextPreference( - "revanced_pref_max_buffer_ms", - StringResource("revanced_pref_max_buffer_ms_title", "Maximum buffer size"), - InputType.NUMBER, - "120000", - StringResource( - "revanced_pref_max_buffer_ms_summary", - "The maximum size of a buffer for playback" - ) - ), - TextPreference( - "revanced_pref_buffer_for_playback_ms", - StringResource("revanced_pref_buffer_for_playback_ms_title", "Maximum buffer for playback"), - InputType.NUMBER, - "2500", - StringResource( - "revanced_pref_buffer_for_playback_ms_summary", - "Maximum size of a buffer for playback" - ) - ), - TextPreference( - "revanced_pref_buffer_for_playback_after_rebuffer_ms", - StringResource( - "revanced_pref_buffer_for_playback_after_rebuffer_ms_title", - "Maximum buffer for playback after rebuffer" - ), - InputType.NUMBER, - "5000", - StringResource( - "revanced_pref_buffer_for_playback_after_rebuffer_ms_summary", - "Maximum size of a buffer for playback after rebuffering" - ) - ) - ), - StringResource("revanced_custom_video_buffer_summary", "Custom settings for video buffer") + NonInteractivePreference( + StringResource("revanced_custom_video_buffer_disclaimer_title", "Custom video buffer"), + StringResource("revanced_custom_video_buffer_disclaimer_title_summary", + "These settings have been removed, because they were not functional for the duration of their existence"), ) ) - BufferType.values().forEach { type -> - type.hook(context) - } return PatchResultSuccess() } - - /** - * The type of buffer. - * - * @param patchInfo The corresponding information to patch the buffer type. - * @param preparation Optional preparation before patching. - */ - private enum class BufferType( - private val patchInfo: PatchInfo, - private val preparation: (BytecodeContext.() -> Unit)? = null, - ) { - - PLAYBACK(PatchInfo(PlaybackBufferFingerprint, "getPlaybackBuffer")), - RE(PatchInfo(ReBufferFingerprint, "getReBuffer")), - MAX( - PatchInfo( - MaxBufferFingerprint, - "getMaxBuffer", - PatchInfo.UnwrapInfo(true, -1) - ), - preparation@{ - InvokeMaxBufferFingerprint.result?.apply { - val maxBufferMethodCallOffset = 2 - - val maxBufferMethod = this@preparation.toMethodWalker(method) - .nextMethod(scanResult.patternScanResult!!.endIndex + maxBufferMethodCallOffset) - .getMethod() - - if (!MaxBufferFingerprint.resolve( - this@preparation, - maxBufferMethod, - // This is inefficient because toMethodWalker technically already has context about this. - // Alternatively you can iterate manually over all classes - // instead of relying on toMethodWalker. - this@preparation.findClass(maxBufferMethod.definingClass)!!.immutableClass, - ) - ) throw MaxBufferFingerprint.toErrorResult() - } ?: throw InvokeMaxBufferFingerprint.toErrorResult() - }); - - /** - * Information about a patch. - * - * @param fingerprint The corresponding [MethodFingerprint] for the patch. - * @param integrationsMethodName The corresponding name of the hooking method. - * @param unwrapInfo Optional information on how to treat the [MethodFingerprint]. - */ - private class PatchInfo( - val fingerprint: MethodFingerprint, - val integrationsMethodName: String, - val unwrapInfo: UnwrapInfo? = null - ) { - /** - * Information on how to treat a [MethodFingerprint]. - * - * @param useEndIndex Whether to retrieve information of the [MethodFingerprint] - * from the end index of its pattern scan result. - * @param offset An additional offset to [useEndIndex]. - */ - class UnwrapInfo(val useEndIndex: Boolean = false, val offset: Int = 0) - } - - fun hook(context: BytecodeContext) { - /** - * The resulting instruction info for unwrapping [MethodFingerprint]. - * - * @param index The index of the instruction. - * @param register The register of the instruction. - */ - data class InstructionResult(val index: Int, val register: Int) - - /*** - * The result of unwrapping [MethodFingerprint]. - * - * @param method The method which was retrieved from the [MethodFingerprint]. - * @param instructionResult The resulting instruction info for unwrapping [MethodFingerprint]. - */ - data class UnwrapResult(val method: MutableMethod, val instructionResult: InstructionResult) - - fun MethodFingerprint.unwrap(unwrapInfo: PatchInfo.UnwrapInfo? = null): UnwrapResult { - val result = this.result!! - val method = result.mutableMethod - val scanResult = result.scanResult.patternScanResult!! - val index = - if (unwrapInfo?.useEndIndex == true) scanResult.endIndex - else { - scanResult.startIndex - } + (unwrapInfo?.offset ?: 0) - - val register = (method.instruction(index) as OneRegisterInstruction).registerA - - return UnwrapResult(method, InstructionResult(index, register)) - } - - preparation?.invoke(context) - - val (method, result) = patchInfo.fingerprint.unwrap(patchInfo.unwrapInfo) - val (index, register) = result - - method.addInstructions( - index + 1, - """ - invoke-static {}, Lapp/revanced/integrations/patches/VideoBufferPatch;->${patchInfo.integrationsMethodName}()I - move-result v$register - """ - ) - } - } } +