mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 05:07:41 +02:00
feat: settings
patch framework (#266)
This commit is contained in:
@ -7,8 +7,14 @@ import app.revanced.patcher.data.impl.BytecodeData
|
||||
import app.revanced.patcher.extensions.addInstructions
|
||||
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.patch.impl.BytecodePatch
|
||||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
||||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.InputType
|
||||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.PreferenceScreen
|
||||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.StringResource
|
||||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.TextPreference
|
||||
import app.revanced.patches.youtube.misc.videobuffer.annotations.CustomVideoBufferCompatibility
|
||||
import app.revanced.patches.youtube.misc.videobuffer.fingerprints.MaxBufferFingerprint
|
||||
import app.revanced.patches.youtube.misc.videobuffer.fingerprints.PlaybackBufferFingerprint
|
||||
@ -18,6 +24,7 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
@Patch
|
||||
@Name("custom-video-buffer")
|
||||
@Description("Lets you change the buffers of videos.")
|
||||
@DependsOn([SettingsPatch::class])
|
||||
@CustomVideoBufferCompatibility
|
||||
@Version("0.0.1")
|
||||
class CustomVideoBufferPatch : BytecodePatch(
|
||||
@ -26,9 +33,52 @@ class CustomVideoBufferPatch : BytecodePatch(
|
||||
)
|
||||
) {
|
||||
override fun execute(data: BytecodeData): 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")
|
||||
)
|
||||
)
|
||||
|
||||
execMaxBuffer()
|
||||
execPlaybackBuffer(data)
|
||||
execReBuffer(data)
|
||||
execPlaybackBuffer()
|
||||
execReBuffer()
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
|
||||
@ -36,7 +86,7 @@ class CustomVideoBufferPatch : BytecodePatch(
|
||||
val result = MaxBufferFingerprint.result!!
|
||||
val method = result.mutableMethod
|
||||
val index = result.patternScanResult!!.endIndex - 1
|
||||
val register = (method.implementation!!.instructions.get(index) as OneRegisterInstruction).registerA
|
||||
val register = (method.implementation!!.instructions[index] as OneRegisterInstruction).registerA
|
||||
method.addInstructions(
|
||||
index + 1, """
|
||||
invoke-static {}, Lapp/revanced/integrations/patches/VideoBufferPatch;->getMaxBuffer()I
|
||||
@ -45,11 +95,11 @@ class CustomVideoBufferPatch : BytecodePatch(
|
||||
)
|
||||
}
|
||||
|
||||
private fun execPlaybackBuffer(data: BytecodeData) {
|
||||
private fun execPlaybackBuffer() {
|
||||
val result = PlaybackBufferFingerprint.result!!
|
||||
val method = result.mutableMethod
|
||||
val index = result.patternScanResult!!.startIndex
|
||||
val register = (method.implementation!!.instructions.get(index) as OneRegisterInstruction).registerA
|
||||
val register = (method.implementation!!.instructions[index] as OneRegisterInstruction).registerA
|
||||
method.addInstructions(
|
||||
index + 1, """
|
||||
invoke-static {}, Lapp/revanced/integrations/patches/VideoBufferPatch;->getPlaybackBuffer()I
|
||||
@ -58,7 +108,7 @@ class CustomVideoBufferPatch : BytecodePatch(
|
||||
)
|
||||
}
|
||||
|
||||
private fun execReBuffer(data: BytecodeData) {
|
||||
private fun execReBuffer() {
|
||||
val result = ReBufferFingerprint.result!!
|
||||
val method = result.mutableMethod
|
||||
val index = result.patternScanResult!!.startIndex
|
||||
|
Reference in New Issue
Block a user