diff --git a/src/main/kotlin/app/revanced/patches/shared/integrations/BaseIntegrationsPatch.kt b/src/main/kotlin/app/revanced/patches/shared/integrations/BaseIntegrationsPatch.kt index 674b7ed36c..c00eb6273d 100644 --- a/src/main/kotlin/app/revanced/patches/shared/integrations/BaseIntegrationsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/shared/integrations/BaseIntegrationsPatch.kt @@ -7,7 +7,8 @@ import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchException import app.revanced.patches.shared.integrations.BaseIntegrationsPatch.IntegrationsFingerprint.IRegisterResolver import app.revanced.patches.shared.integrations.Constants.INTEGRATIONS_UTILS_CLASS_DESCRIPTOR -import app.revanced.util.deprecatedOrResultOrThrow +import app.revanced.util.isDeprecated +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.ClassDef import com.android.tools.smali.dexlib2.iface.Method @@ -53,7 +54,9 @@ abstract class BaseIntegrationsPatch( ) { fun invoke(integrationsDescriptor: String) { - deprecatedOrResultOrThrow()?.mutableMethod?.let { method -> + if (isDeprecated()) return + + resultOrThrow().mutableMethod.let { method -> val insertIndex = insertIndexResolver(method) val contextRegister = contextRegisterResolver(method) diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/spoofappversion/SpoofAppVersionPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/spoofappversion/SpoofAppVersionPatch.kt index 5c53e03c11..54a4a0b0a7 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/spoofappversion/SpoofAppVersionPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/spoofappversion/SpoofAppVersionPatch.kt @@ -2,11 +2,11 @@ package app.revanced.patches.youtube.general.spoofappversion import app.revanced.patcher.data.ResourceContext import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE +import app.revanced.patches.youtube.utils.settings.ResourceUtils.addEntryValues import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.util.patch.BaseResourcePatch -import org.w3c.dom.Element -@Suppress("DEPRECATION", "unused") +@Suppress("unused") object SpoofAppVersionPatch : BaseResourcePatch( name = "Spoof app version", description = "Adds options to spoof the YouTube client version. " + @@ -17,31 +17,20 @@ object SpoofAppVersionPatch : BaseResourcePatch( ), compatiblePackages = COMPATIBLE_PACKAGE ) { + private const val ATTRIBUTE_NAME_ENTRIES = + "revanced_spoof_app_version_target_entries" + + private const val ATTRIBUTE_NAME_ENTRY_VALUE = + "revanced_spoof_app_version_target_entry_values" + override fun execute(context: ResourceContext) { if (SettingsPatch.upward1834) { - context.appendChild( - arrayOf( - "revanced_spoof_app_version_target_entries" to "@string/revanced_spoof_app_version_target_entry_18_33_40", - "revanced_spoof_app_version_target_entry_values" to "18.33.40", - ) - ) - + context.appendAppVersion("18.33.40") if (SettingsPatch.upward1839) { - context.appendChild( - arrayOf( - "revanced_spoof_app_version_target_entries" to "@string/revanced_spoof_app_version_target_entry_18_38_45", - "revanced_spoof_app_version_target_entry_values" to "18.38.45" - ) - ) - + context.appendAppVersion("18.38.45") if (SettingsPatch.upward1849) { - context.appendChild( - arrayOf( - "revanced_spoof_app_version_target_entries" to "@string/revanced_spoof_app_version_target_entry_18_48_39", - "revanced_spoof_app_version_target_entry_values" to "18.48.39" - ) - ) + context.appendAppVersion("18.48.39") } } } @@ -60,25 +49,16 @@ object SpoofAppVersionPatch : BaseResourcePatch( SettingsPatch.updatePatchStatus(this) } - private fun ResourceContext.appendChild(entryArray: Array>) { - entryArray.map { (attributeName, attributeValue) -> - this.xmlEditor["res/values/arrays.xml"].use { editor -> - editor.file.apply { - val resourcesNode = getElementsByTagName("resources").item(0) as Element - - val newElement: Element = createElement("item") - for (i in 0 until resourcesNode.childNodes.length) { - val node = resourcesNode.childNodes.item(i) as? Element ?: continue - - if (node.getAttribute("name") == attributeName) { - newElement.appendChild(createTextNode(attributeValue)) - val firstChild = node.firstChild - - node.insertBefore(newElement, firstChild) - } - } - } - } - } + private fun ResourceContext.appendAppVersion(appVersion: String) { + addEntryValues( + ATTRIBUTE_NAME_ENTRIES, + "@string/revanced_spoof_app_version_target_entry_" + appVersion.replace(".", "_"), + prepend = false + ) + addEntryValues( + ATTRIBUTE_NAME_ENTRY_VALUE, + appVersion, + prepend = false + ) } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/doubletaplength/DoubleTapLengthPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/doubletaplength/DoubleTapLengthPatch.kt index 65bc0860ec..ad981948c8 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/doubletaplength/DoubleTapLengthPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/doubletaplength/DoubleTapLengthPatch.kt @@ -56,8 +56,16 @@ object DoubleTapLengthPatch : BaseResourcePatch( ) for (index in 0 until splits.count()) { - context.addEntryValues(arrayPath, lengthElements[index], entryValueName) - context.addEntryValues(arrayPath, lengthElements[index], entriesName) + context.addEntryValues( + entryValueName, + lengthElements[index], + path = arrayPath + ) + context.addEntryValues( + entriesName, + lengthElements[index], + path = arrayPath + ) } SettingsPatch.updatePatchStatus(this) diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/buttons/PlayerButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/buttons/PlayerButtonsPatch.kt index 922deb2b7d..69e42d03fb 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/buttons/PlayerButtonsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/buttons/PlayerButtonsPatch.kt @@ -30,8 +30,8 @@ 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.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.instruction.RegisterRangeInstruction import com.android.tools.smali.dexlib2.iface.instruction.WideLiteralInstruction -import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction3rc @Suppress("unused") object PlayerButtonsPatch : BaseBytecodePatch( @@ -182,7 +182,7 @@ object PlayerButtonsPatch : BaseBytecodePatch( PlayerControlsVisibilityModelFingerprint.resultOrThrow().let { it.mutableMethod.apply { val callIndex = indexOfFirstInstructionOrThrow(Opcode.INVOKE_DIRECT_RANGE) - val callInstruction = getInstruction(callIndex) + val callInstruction = getInstruction(callIndex) val hasNextParameterRegister = callInstruction.startRegister + HAS_NEXT val hasPreviousParameterRegister = callInstruction.startRegister + HAS_PREVIOUS diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/settings/ResourceUtils.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/settings/ResourceUtils.kt index 26c3649ac3..451cd2b863 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/settings/ResourceUtils.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/settings/ResourceUtils.kt @@ -50,23 +50,27 @@ object ResourceUtils { } fun ResourceContext.addEntryValues( - path: String, - speedEntryValues: String, - attributeName: String + attributeName: String, + attributeValue: String, + path: String = "res/values/arrays.xml", + prepend: Boolean = true, ) { xmlEditor[path].use { with(it.file) { val resourcesNode = getElementsByTagName("resources").item(0) as Element val newElement: Element = createElement("item") - for (i in 0 until resourcesNode.childNodes.length) { val node = resourcesNode.childNodes.item(i) as? Element ?: continue if (node.getAttribute("name") == attributeName) { - newElement.appendChild(createTextNode(speedEntryValues)) + newElement.appendChild(createTextNode(attributeValue)) - node.appendChild(newElement) + if (prepend) { + node.appendChild(newElement) + } else { + node.insertBefore(newElement, node.firstChild) + } } } } diff --git a/src/main/kotlin/app/revanced/util/BytecodeUtils.kt b/src/main/kotlin/app/revanced/util/BytecodeUtils.kt index e512a92360..686c14fa90 100644 --- a/src/main/kotlin/app/revanced/util/BytecodeUtils.kt +++ b/src/main/kotlin/app/revanced/util/BytecodeUtils.kt @@ -33,8 +33,8 @@ import com.android.tools.smali.dexlib2.util.MethodUtil const val REGISTER_TEMPLATE_REPLACEMENT: String = "REGISTER_INDEX" -fun MethodFingerprint.deprecatedOrResultOrThrow() = - if (javaClass.annotations[0].toString().contains("Deprecated")) result else resultOrThrow() +fun MethodFingerprint.isDeprecated() = + javaClass.annotations[0].toString().contains("Deprecated") fun MethodFingerprint.resultOrThrow() = result ?: throw exception diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index bcfd4e08b3..309b260095 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -78,8 +78,8 @@ - - + + @@ -92,7 +92,7 @@ - + @@ -601,12 +601,58 @@ + + + + + + + + + + + PREFERENCE_SCREEN: RETURN_YOUTUBE_DISLIKE --> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + PREFERENCE_SCREEN: SPONSOR_BLOCK -->