-
-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(youtube/custom-video-buffer): replace patch with removal notice (#…
…1718) Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
- Loading branch information
1 parent
bbe251f
commit fe03dbf
Showing
7 changed files
with
36 additions
and
230 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
...n/kotlin/app/revanced/patches/shared/settings/preference/impl/NonInteractivePreference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
.../app/revanced/patches/youtube/misc/videobuffer/fingerprints/InvokeMaxBufferFingerprint.kt
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
...kotlin/app/revanced/patches/youtube/misc/videobuffer/fingerprints/MaxBufferFingerprint.kt
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
...n/app/revanced/patches/youtube/misc/videobuffer/fingerprints/PlaybackBufferFingerprint.kt
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
.../kotlin/app/revanced/patches/youtube/misc/videobuffer/fingerprints/ReBufferFingerprint.kt
This file was deleted.
Oops, something went wrong.
183 changes: 9 additions & 174 deletions
183
...main/kotlin/app/revanced/patches/youtube/misc/videobuffer/patch/CustomVideoBufferPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
""" | ||
) | ||
} | ||
} | ||
} | ||
|