feat(YouTube): add Disable auto audio tracks patch

This commit is contained in:
inotia00 2024-04-26 06:33:01 +09:00
parent da63185b81
commit 03280af7be
4 changed files with 86 additions and 0 deletions

View File

@ -0,0 +1,68 @@
package app.revanced.patches.youtube.general.audiotracks
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patches.youtube.general.audiotracks.fingerprints.StreamingModelBuilderFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getTargetIndexWithReference
import app.revanced.util.indexOfFirstInstruction
import app.revanced.util.patch.BaseBytecodePatch
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
@Suppress("unused")
object AudioTracksPatch : BaseBytecodePatch(
name = "Disable auto audio tracks",
description = "Adds an option to disable audio tracks from being automatically enabled.",
dependencies = setOf(SettingsPatch::class),
compatiblePackages = COMPATIBLE_PACKAGE,
fingerprints = setOf(StreamingModelBuilderFingerprint)
) {
override fun execute(context: BytecodeContext) {
StreamingModelBuilderFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val formatStreamModelIndex = indexOfFirstInstruction {
opcode == Opcode.CHECK_CAST
&& (this as ReferenceInstruction).reference.toString() == "Lcom/google/android/libraries/youtube/innertube/model/media/FormatStreamModel;"
}
val arrayListIndex = getTargetIndexWithReference(formatStreamModelIndex, "Ljava/util/List;->add(Ljava/lang/Object;)Z")
val insertIndex = getTargetIndexWithReference(arrayListIndex, "Ljava/util/List;->isEmpty()Z") + 2
val formatStreamModelRegister = getInstruction<OneRegisterInstruction>(formatStreamModelIndex).registerA
val arrayListRegister = getInstruction<FiveRegisterInstruction>(arrayListIndex).registerC
addInstructions(
insertIndex, """
invoke-static {v$arrayListRegister}, $GENERAL_CLASS_DESCRIPTOR->getFormatStreamModelArray(Ljava/util/ArrayList;)Ljava/util/ArrayList;
move-result-object v$arrayListRegister
"""
)
addInstructions(
formatStreamModelIndex + 1,
"invoke-static {v$formatStreamModelRegister}, $GENERAL_CLASS_DESCRIPTOR->setFormatStreamModelArray(Ljava/lang/Object;)V"
)
}
}
/**
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE_SCREEN: GENERAL",
"SETTINGS: DISABLE_AUTO_AUDIO_TRACKS"
)
)
SettingsPatch.updatePatchStatus(this)
}
}

View File

@ -0,0 +1,11 @@
package app.revanced.patches.youtube.general.audiotracks.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
internal object StreamingModelBuilderFingerprint : MethodFingerprint(
returnType = "L",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
strings = listOf("vprng")
)

View File

@ -254,6 +254,9 @@ Limitations:
<string name="revanced_change_start_page_entry_subscriptions">Subscriptions</string>
<string name="revanced_change_start_page_entry_trending">Trending</string>
<string name="revanced_change_start_page_warning">Invalid start page, resetting to default.</string>
<string name="revanced_disable_auto_audio_tracks_title">Disable forced auto audio tracks</string>
<string name="revanced_disable_auto_audio_tracks_summary_on">Forced auto audio tracks are disabled.</string>
<string name="revanced_disable_auto_audio_tracks_summary_off">Forced auto audio tracks are enabled.</string>
<string name="revanced_disable_auto_captions_title">Disable forced auto captions</string>
<string name="revanced_disable_auto_captions_summary_on">Forced auto captions are disabled.</string>
<string name="revanced_disable_auto_captions_summary_off">Forced auto captions are enabled.</string>

View File

@ -128,6 +128,9 @@
<!-- SETTINGS: CHANGE_START_PAGE
<ListPreference android:entries="@array/revanced_change_start_page_entries" android:title="@string/revanced_change_start_page_title" android:key="revanced_change_start_page" android:defaultValue="" android:entryValues="@array/revanced_change_start_page_entry_values" />SETTINGS: CHANGE_START_PAGE -->
<!-- SETTINGS: DISABLE_AUTO_AUDIO_TRACKS
<SwitchPreference android:title="@string/revanced_disable_auto_audio_tracks_title" android:key="revanced_disable_auto_audio_tracks" android:defaultValue="false" android:summaryOn="@string/revanced_disable_auto_audio_tracks_summary_on" android:summaryOff="@string/revanced_disable_auto_audio_tracks_summary_off" />SETTINGS: DISABLE_AUTO_AUDIO_TRACKS -->
<!-- SETTINGS: DISABLE_AUTO_CAPTIONS
<SwitchPreference android:title="@string/revanced_disable_auto_captions_title" android:key="revanced_disable_auto_captions" android:defaultValue="false" android:summaryOn="@string/revanced_disable_auto_captions_summary_on" android:summaryOff="@string/revanced_disable_auto_captions_summary_off" />SETTINGS: DISABLE_AUTO_CAPTIONS -->
@ -536,6 +539,7 @@
<PreferenceCategory android:title="@string/revanced_preference_screen_general_title" android:layout="@layout/revanced_settings_preferences_category">
<Preference android:title="Change start page" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Disable auto audio tracks" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Disable auto captions" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Disable splash animation" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Enable gradient loading screen" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>