@@ -5,22 +5,22 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWith
55import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
66import app.revanced.patcher.patch.bytecodePatch
77import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable
8- import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
98import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
109import app.revanced.patches.all.misc.resources.addResources
1110import app.revanced.patches.all.misc.resources.addResourcesPatch
1211import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
1312import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
13+ import app.revanced.patches.youtube.misc.playservice.is_20_07_or_greater
14+ import app.revanced.patches.youtube.misc.playservice.versionCheckPatch
1415import app.revanced.patches.youtube.misc.settings.PreferenceScreen
1516import app.revanced.patches.youtube.misc.settings.settingsPatch
16- import app.revanced.util.getReference
17+ import app.revanced.util.findMethodFromToString
1718import app.revanced.util.indexOfFirstInstructionOrThrow
19+ import app.revanced.util.insertLiteralOverride
1820import com.android.tools.smali.dexlib2.AccessFlags
1921import com.android.tools.smali.dexlib2.Opcode
2022import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation
21- import com.android.tools.smali.dexlib2.iface.Method
2223import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
23- import com.android.tools.smali.dexlib2.iface.reference.MethodReference
2424import com.android.tools.smali.dexlib2.immutable.ImmutableField
2525import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
2626import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter
@@ -37,6 +37,7 @@ val forceOriginalAudioPatch = bytecodePatch(
3737 sharedExtensionPatch,
3838 settingsPatch,
3939 addResourcesPatch,
40+ versionCheckPatch
4041 )
4142
4243 compatibleWith(
@@ -60,29 +61,25 @@ val forceOriginalAudioPatch = bytecodePatch(
6061 )
6162 )
6263
63- fun Method.firstFormatStreamingModelCall (
64- returnType : String = "Ljava /lang/String ;"
65- ): MutableMethod {
66- val audioTrackIdIndex = indexOfFirstInstructionOrThrow {
67- val reference = getReference<MethodReference >()
68- reference?.definingClass == " Lcom/google/android/libraries/youtube/innertube/model/media/FormatStreamModel;"
69- && reference.returnType == returnType
70- }
71-
72- return navigate(this ).to(audioTrackIdIndex).stop()
64+ // Disable feature flag that ignores the default track flag
65+ // and instead overrides to the user region language.
66+ if (is_20_07_or_greater) {
67+ selectAudioStreamFingerprint.method.insertLiteralOverride(
68+ AUDIO_STREAM_IGNORE_DEFAULT_FEATURE_FLAG ,
69+ " $EXTENSION_CLASS_DESCRIPTOR ->ignoreDefaultAudioStream(Z)Z"
70+ )
7371 }
7472
75- // Accessor methods of FormatStreamModel have no string constants and
76- // opcodes are identical to other methods in the same class,
77- // so must walk from another class that use the methods.
78- val isDefaultMethod = streamingModelBuilderFingerprint.originalMethod.firstFormatStreamingModelCall(" Z" )
79- val audioTrackIdMethod = menuItemAudioTrackFingerprint.originalMethod.firstFormatStreamingModelCall()
80- val audioTrackDisplayNameMethod = audioStreamingTypeSelector.originalMethod.firstFormatStreamingModelCall()
81- val formatStreamModelClass = proxy(classes.first {
82- it.type == audioTrackIdMethod.definingClass
83- }).mutableClass
73+ val isDefaultAudioTrackMethod = formatStreamModelToStringFingerprint.originalMethod
74+ .findMethodFromToString(" isDefaultAudioTrack=" )
75+ val audioTrackDisplayNameMethod = formatStreamModelToStringFingerprint.originalMethod
76+ .findMethodFromToString(" audioTrackDisplayName=" )
77+ val audioTrackIdMethod = formatStreamModelToStringFingerprint.originalMethod
78+ .findMethodFromToString(" audioTrackId=" )
8479
85- formatStreamModelClass.apply {
80+ proxy(classes.first {
81+ it.type == audioTrackIdMethod.definingClass
82+ }).mutableClass.apply {
8683 // Add a new field to store the override.
8784 val helperFieldName = " isDefaultAudioTrackOverride"
8885 fields.add(
@@ -103,7 +100,7 @@ val forceOriginalAudioPatch = bytecodePatch(
103100
104101 // Add a helper method because the isDefaultAudioTrack() has only 2 registers and 3 are needed.
105102 val helperMethodClass = type
106- val helperMethodName = " extension_isDefaultAudioTrack "
103+ val helperMethodName = " patch_isDefaultAudioTrack "
107104 val helperMethod = ImmutableMethod (
108105 helperMethodClass,
109106 helperMethodName,
@@ -143,7 +140,7 @@ val forceOriginalAudioPatch = bytecodePatch(
143140 methods.add(helperMethod)
144141
145142 // Modify isDefaultAudioTrack() to call extension helper method.
146- isDefaultMethod .apply {
143+ isDefaultAudioTrackMethod .apply {
147144 val index = indexOfFirstInstructionOrThrow(Opcode .RETURN )
148145 val register = getInstruction<OneRegisterInstruction >(index).registerA
149146
0 commit comments