feat(youtube/append-time-stamps-information): change patch name enable-time-stamps-speedappend-time-stamps-information

This commit is contained in:
inotia00
2023-09-20 15:09:31 +09:00
parent 68b34f0f37
commit 09a94b88b7
3 changed files with 35 additions and 24 deletions

View File

@ -1,9 +1,10 @@
package app.revanced.patches.youtube.seekbar.speed.patch
package app.revanced.patches.youtube.seekbar.append.patch
import app.revanced.extensions.exception
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
@ -12,6 +13,7 @@ import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility
import app.revanced.patches.youtube.utils.fingerprints.TotalTimeFingerprint
import app.revanced.patches.youtube.utils.overridequality.patch.OverrideQualityHookPatch
import app.revanced.patches.youtube.utils.overridespeed.patch.OverrideSpeedHookPatch
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch
@ -21,43 +23,49 @@ import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c
@Patch
@Name("Enable time stamps speed")
@Description("Add the current playback speed in brackets next to the current time.")
@Name("Append time stamps information")
@Description("Add the current video quality or playback speed in brackets next to the current time.")
@DependsOn(
[
OverrideQualityHookPatch::class,
OverrideSpeedHookPatch::class,
SettingsPatch::class,
SharedResourceIdPatch::class
]
)
@YouTubeCompatibility
class AppendSpeedPatch : BytecodePatch(
class AppendTimeStampInformationPatch : BytecodePatch(
listOf(TotalTimeFingerprint)
) {
override fun execute(context: BytecodeContext) {
TotalTimeFingerprint.result?.let {
it.mutableMethod.apply {
var insertIndex = -1
var setTextIndex = -1
for ((targetIndex, targetInstruction) in implementation!!.instructions.withIndex()) {
if (targetInstruction.opcode != Opcode.INVOKE_VIRTUAL) continue
for ((textViewIndex, textViewInstruction) in implementation!!.instructions.withIndex()) {
if (textViewInstruction.opcode != Opcode.INVOKE_VIRTUAL) continue
if (getInstruction<ReferenceInstruction>(targetIndex).reference.toString() ==
if (getInstruction<ReferenceInstruction>(textViewIndex).reference.toString() ==
"Landroid/widget/TextView;->getText()Ljava/lang/CharSequence;"
) {
insertIndex = targetIndex + 2
val insertRegister = getInstruction<Instruction35c>(insertIndex).registerC
setTextIndex = textViewIndex + 2
val setTextRegister = getInstruction<Instruction35c>(setTextIndex).registerC
val textViewRegister = getInstruction<Instruction35c>(textViewIndex).registerC
addInstructions(
insertIndex, """
invoke-static {v$insertRegister}, $SEEKBAR->enableTimeStampSpeed(Ljava/lang/String;)Ljava/lang/String;
move-result-object v$insertRegister
setTextIndex, """
invoke-static {v$setTextRegister}, $SEEKBAR->appendTimeStampInformation(Ljava/lang/String;)Ljava/lang/String;
move-result-object v$setTextRegister
"""
)
addInstruction(
textViewIndex,
"invoke-static {v$textViewRegister}, $SEEKBAR->setContainerClickListener(Landroid/view/View;)V"
)
break
}
}
if (insertIndex == -1)
if (setTextIndex == -1)
throw PatchException("target Instruction not found!")
}
} ?: throw TotalTimeFingerprint.exception
@ -68,11 +76,11 @@ class AppendSpeedPatch : BytecodePatch(
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: SEEKBAR_SETTINGS",
"SETTINGS: ENABLE_TIME_STAMP_SPEED"
"SETTINGS: APPEND_TIME_STAMP_INFORMATION"
)
)
SettingsPatch.updatePatchStatus("enable-timestamps-speed")
SettingsPatch.updatePatchStatus("append-timestamps-information")
}
}