Skip to content

Commit

Permalink
feat(youtube/default-video-quality): Enable save video quality not …
Browse files Browse the repository at this point in the history
…working in new layout
  • Loading branch information
inotia00 committed Jun 29, 2023
1 parent 9821754 commit 0d04270
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package app.revanced.patches.youtube.utils.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 NewFlyoutPanelsOnClickListenerFingerprint : MethodFingerprint(
returnType = "L",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L"),
opcodes = listOf(
Opcode.IGET,
Opcode.AND_INT_LIT8,
Opcode.IF_EQZ,
Opcode.IGET_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.IF_NEZ,
Opcode.NEW_INSTANCE,
Opcode.INVOKE_DIRECT,
Opcode.IGET_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.NEW_INSTANCE,
Opcode.CONST_16,
Opcode.INVOKE_DIRECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.IGET_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.NEW_INSTANCE
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package app.revanced.patches.youtube.video.quality.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 NewVideoQualityChangedFingerprint : MethodFingerprint(
returnType = "L",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L"),
opcodes = listOf(
Opcode.IGET,
Opcode.CONST_4,
Opcode.IF_NE,
Opcode.NEW_INSTANCE,
Opcode.IGET_OBJECT,
Opcode.CHECK_CAST,
Opcode.IGET
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import app.revanced.patcher.patch.PatchResultSuccess
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.NewFlyoutPanelsOnClickListenerFingerprint
import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch
import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch.Companion.contexts
import app.revanced.patches.youtube.utils.videocpn.patch.VideoCpnPatch
import app.revanced.patches.youtube.video.quality.fingerprints.NewVideoQualityChangedFingerprint
import app.revanced.patches.youtube.video.quality.fingerprints.VideoQualityReferenceFingerprint
import app.revanced.patches.youtube.video.quality.fingerprints.VideoQualitySetterFingerprint
import app.revanced.patches.youtube.video.quality.fingerprints.VideoQualitySettingsFingerprint
Expand All @@ -26,6 +28,7 @@ import app.revanced.patches.youtube.video.quality.fingerprints.VideoUserQualityC
import app.revanced.util.integrations.Constants.VIDEO_PATH
import app.revanced.util.resources.ResourceUtils.copyXmlNode
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
import org.jf.dexlib2.iface.reference.FieldReference

@Patch
Expand All @@ -41,11 +44,32 @@ import org.jf.dexlib2.iface.reference.FieldReference
@Version("0.0.1")
class VideoQualityPatch : BytecodePatch(
listOf(
NewFlyoutPanelsOnClickListenerFingerprint,
VideoQualitySetterFingerprint,
VideoQualitySettingsParentFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {

NewFlyoutPanelsOnClickListenerFingerprint.result?.let { parentResult ->
NewVideoQualityChangedFingerprint.also {
it.resolve(
context,
parentResult.classDef
)
}.result?.let {
it.mutableMethod.apply {
val index = it.scanResult.patternScanResult!!.endIndex
val register = getInstruction<TwoRegisterInstruction>(index).registerA

addInstruction(
index + 1,
"invoke-static {v$register}, $INTEGRATIONS_VIDEO_QUALITY_CLASS_DESCRIPTOR->userChangedQualityInNewFlyoutPanels(I)V"
)
}
}
} ?: return NewFlyoutPanelsOnClickListenerFingerprint.toErrorResult()

VideoQualitySetterFingerprint.result?.let { parentResult ->
VideoQualityReferenceFingerprint.also {
it.resolve(
Expand Down

3 comments on commit 0d04270

@inotia00
Copy link
Owner Author

@inotia00 inotia00 commented on 0d04270 Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very little information about the class makes it very difficult to identify the target method

Since the target method is called from an abstract class, Method Walker could not be used.

[NewFlyoutPanelsOnClickListenerFingerprint] looks brittle, but it is available on YouTube v18.08.39 through v18.25.39

@oSumAtrIX
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can start the walker from a class that extends from the abstract class and then get its super class. Then form the super class get the method which was overriden (where you last walked)

@inotia00
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tried importing the extends and super class
I know that the swipe-controls patch changes the super class.. I will study a little more and improve this patch

Please sign in to comment.