mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-01 15:14:34 +02:00
add enable-timestamps-speed
patch
This commit is contained in:
parent
8b522b6f3a
commit
f901b807d1
@ -0,0 +1,105 @@
|
|||||||
|
package app.revanced.patches.youtube.layout.seekbar.speed.patch
|
||||||
|
|
||||||
|
import app.revanced.extensions.findMutableMethodOf
|
||||||
|
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.extensions.addInstructions
|
||||||
|
import app.revanced.patcher.patch.BytecodePatch
|
||||||
|
import app.revanced.patcher.patch.PatchResult
|
||||||
|
import app.revanced.patcher.patch.PatchResultError
|
||||||
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
|
import app.revanced.patcher.patch.annotations.DependsOn
|
||||||
|
import app.revanced.patcher.patch.annotations.Patch
|
||||||
|
import app.revanced.patches.shared.annotation.YouTubeCompatibility
|
||||||
|
import app.revanced.patches.shared.patch.mapping.ResourceMappingPatch
|
||||||
|
import app.revanced.patches.youtube.misc.overridespeed.bytecode.patch.OverrideSpeedHookPatch
|
||||||
|
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
|
||||||
|
import app.revanced.util.integrations.Constants.SEEKBAR_LAYOUT
|
||||||
|
import org.jf.dexlib2.Opcode
|
||||||
|
import org.jf.dexlib2.dexbacked.instruction.DexBackedInstruction35c
|
||||||
|
import org.jf.dexlib2.iface.instruction.formats.Instruction31i
|
||||||
|
import org.jf.dexlib2.iface.instruction.formats.Instruction35c
|
||||||
|
|
||||||
|
@Patch
|
||||||
|
@Name("enable-timestamps-speed")
|
||||||
|
@Description("Add the current video speed in brackets next to the current time.")
|
||||||
|
@DependsOn(
|
||||||
|
[
|
||||||
|
OverrideSpeedHookPatch::class,
|
||||||
|
ResourceMappingPatch::class,
|
||||||
|
SettingsPatch::class
|
||||||
|
]
|
||||||
|
)
|
||||||
|
@YouTubeCompatibility
|
||||||
|
@Version("0.0.1")
|
||||||
|
class AppendSpeedPatch : BytecodePatch() {
|
||||||
|
|
||||||
|
// list of resource names to get the id of
|
||||||
|
private val resourceIds = arrayOf(
|
||||||
|
"string" to "total_time"
|
||||||
|
).map { (type, name) ->
|
||||||
|
ResourceMappingPatch
|
||||||
|
.resourceMappings
|
||||||
|
.single { it.type == type && it.name == name }.id
|
||||||
|
}
|
||||||
|
private var patchSuccessArray = Array(resourceIds.size) {false}
|
||||||
|
|
||||||
|
override fun execute(context: BytecodeContext): PatchResult {
|
||||||
|
context.classes.forEach { classDef ->
|
||||||
|
classDef.methods.forEach { method ->
|
||||||
|
with(method.implementation) {
|
||||||
|
this?.instructions?.forEachIndexed { _, instruction ->
|
||||||
|
when (instruction.opcode) {
|
||||||
|
Opcode.CONST -> {
|
||||||
|
when ((instruction as Instruction31i).wideLiteral) {
|
||||||
|
resourceIds[0] -> { // total time
|
||||||
|
val mutableMethod = context.proxy(classDef).mutableClass.findMutableMethodOf(method)
|
||||||
|
|
||||||
|
for ((targetIndex, targetInstruction) in instructions.withIndex()) {
|
||||||
|
if (targetInstruction.opcode != Opcode.INVOKE_VIRTUAL) continue
|
||||||
|
|
||||||
|
if ((targetInstruction as DexBackedInstruction35c).reference.toString() ==
|
||||||
|
"Landroid/widget/TextView;->getText()Ljava/lang/CharSequence;") {
|
||||||
|
val insertIndex = targetIndex + 2
|
||||||
|
val insertRegister = (instructions.elementAt(insertIndex) as Instruction35c).registerC
|
||||||
|
mutableMethod.addInstructions(
|
||||||
|
insertIndex, """
|
||||||
|
invoke-static {v$insertRegister}, $SEEKBAR_LAYOUT->enableTimeStampSpeed(Ljava/lang/String;)Ljava/lang/String;
|
||||||
|
move-result-object v$insertRegister
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
patchSuccessArray[0] = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> return@forEachIndexed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val errorIndex: Int = patchSuccessArray.indexOf(false)
|
||||||
|
|
||||||
|
if (errorIndex == -1) {
|
||||||
|
/*
|
||||||
|
* Add settings
|
||||||
|
*/
|
||||||
|
SettingsPatch.addPreference(
|
||||||
|
arrayOf(
|
||||||
|
"PREFERENCE: SEEKBAR_LAYOUT_SETTINGS",
|
||||||
|
"SETTINGS: ENABLE_TIME_STAMP_SPEED"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
SettingsPatch.updatePatchStatus("enable-timestamps-speed")
|
||||||
|
|
||||||
|
return PatchResultSuccess()
|
||||||
|
} else
|
||||||
|
return PatchResultError("Instruction not found: $errorIndex")
|
||||||
|
}
|
||||||
|
}
|
@ -242,6 +242,9 @@ Is it ready to submit?"</string>
|
|||||||
<string name="revanced_enable_tablet_miniplayer_title">Enable tablet mini player</string>
|
<string name="revanced_enable_tablet_miniplayer_title">Enable tablet mini player</string>
|
||||||
<string name="revanced_enable_tablet_layout_summary">Tricks the dpi to use some tablet layouts</string>
|
<string name="revanced_enable_tablet_layout_summary">Tricks the dpi to use some tablet layouts</string>
|
||||||
<string name="revanced_enable_tablet_layout_title">Enable tablet layout</string>
|
<string name="revanced_enable_tablet_layout_title">Enable tablet layout</string>
|
||||||
|
<string name="revanced_enable_time_stamp_speed_summary_off">Append time stamp speed is disabled</string>
|
||||||
|
<string name="revanced_enable_time_stamp_speed_summary_on">Append time stamp speed is enabled</string>
|
||||||
|
<string name="revanced_enable_time_stamp_speed_title">Enable time stamp speed</string>
|
||||||
<string name="revanced_enable_wide_searchbar_summary_off">Wide search bar is disabled</string>
|
<string name="revanced_enable_wide_searchbar_summary_off">Wide search bar is disabled</string>
|
||||||
<string name="revanced_enable_wide_searchbar_summary_on">Wide search bar is enabled</string>
|
<string name="revanced_enable_wide_searchbar_summary_on">Wide search bar is enabled</string>
|
||||||
<string name="revanced_enable_wide_searchbar_title">Enable wide search bar</string>
|
<string name="revanced_enable_wide_searchbar_title">Enable wide search bar</string>
|
||||||
|
@ -298,6 +298,9 @@
|
|||||||
<!-- SETTINGS: HIDE_TIME_STAMP
|
<!-- SETTINGS: HIDE_TIME_STAMP
|
||||||
<SwitchPreference android:title="@string/revanced_hide_time_stamp_title" android:key="revanced_hide_time_stamp" android:defaultValue="false" android:summaryOn="@string/revanced_hide_time_stamp_summary_on" android:summaryOff="@string/revanced_hide_time_stamp_summary_off" />SETTINGS: HIDE_TIME_STAMP -->
|
<SwitchPreference android:title="@string/revanced_hide_time_stamp_title" android:key="revanced_hide_time_stamp" android:defaultValue="false" android:summaryOn="@string/revanced_hide_time_stamp_summary_on" android:summaryOff="@string/revanced_hide_time_stamp_summary_off" />SETTINGS: HIDE_TIME_STAMP -->
|
||||||
|
|
||||||
|
<!-- SETTINGS: ENABLE_TIME_STAMP_SPEED
|
||||||
|
<SwitchPreference android:title="@string/revanced_enable_time_stamp_speed_title" android:key="revanced_enable_time_stamp_speed" android:defaultValue="true" android:summaryOn="@string/revanced_enable_time_stamp_speed_summary_on" android:summaryOff="@string/revanced_enable_time_stamp_speed_summary_off" />SETTINGS: ENABLE_TIME_STAMP_SPEED -->
|
||||||
|
|
||||||
<!-- PREFERENCE: SEEKBAR_LAYOUT_SETTINGS
|
<!-- PREFERENCE: SEEKBAR_LAYOUT_SETTINGS
|
||||||
</PreferenceScreen>PREFERENCE: SEEKBAR_LAYOUT_SETTINGS -->
|
</PreferenceScreen>PREFERENCE: SEEKBAR_LAYOUT_SETTINGS -->
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user