From 512b2526ba1b4b2c5d74d5b51f1679814ec4065e Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:35:06 +0900 Subject: [PATCH] chore: Lint code --- .../versioncode/ChangeVersionCodePatch.kt | 1 + .../components/ActionBarComponentsPatch.kt | 6 +- .../music/general/redirection/Fingerprints.kt | 4 +- .../branding/icon/CustomBrandingIconPatch.kt | 10 +- .../patches/music/misc/drc/DrcAudioPatch.kt | 3 +- .../components/PlayerComponentsPatch.kt | 2 +- .../utils/fix/client/SpoofClientPatch.kt | 54 +++--- .../utils/sponsorblock/SponsorBlockPatch.kt | 9 +- .../patches/shared/gms/GmsCoreSupportPatch.kt | 6 +- .../BaseSpoofStreamingDataPatch.kt | 161 ++++++++++-------- .../general/miniplayer/Fingerprints.kt | 1 + .../NavigationBarComponentsPatch.kt | 18 +- .../branding/icon/CustomBrandingIconPatch.kt | 10 +- .../player/seekbar/SeekbarComponentsPatch.kt | 28 ++- .../shorts/components/ShortsComponentPatch.kt | 40 +++-- .../utils/playertype/PlayerTypeHookPatch.kt | 3 +- .../information/VideoInformationPatch.kt | 5 +- 17 files changed, 219 insertions(+), 142 deletions(-) diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/versioncode/ChangeVersionCodePatch.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/versioncode/ChangeVersionCodePatch.kt index 370200a11..7018d5a5d 100644 --- a/patches/src/main/kotlin/app/revanced/patches/all/misc/versioncode/ChangeVersionCodePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/versioncode/ChangeVersionCodePatch.kt @@ -49,6 +49,7 @@ val changeVersionCodePatch = resourcePatch( "Invalid versionCode: $versionCodeString, " + "Version code should be larger than 1 and smaller than $MAX_VALUE." ) + val versionCodeString = versionCodeOption.valueOrThrow() val versionCode: Int diff --git a/patches/src/main/kotlin/app/revanced/patches/music/actionbar/components/ActionBarComponentsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/actionbar/components/ActionBarComponentsPatch.kt index 0f5e0ad6d..765f6709f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/actionbar/components/ActionBarComponentsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/actionbar/components/ActionBarComponentsPatch.kt @@ -116,7 +116,8 @@ val actionBarComponentsPatch = bytecodePatch( .endsWith("Lcom/google/android/libraries/youtube/common/ui/YouTubeButton;->(Landroid/content/Context;)V") } - 2 val replaceInstruction = getInstruction(replaceIndex) - val replaceReference = getInstruction(replaceIndex).reference + val replaceReference = + getInstruction(replaceIndex).reference addInstructionsWithLabels( replaceIndex + 1, """ @@ -140,7 +141,8 @@ val actionBarComponentsPatch = bytecodePatch( } val spannedRegister = getInstruction(spannedIndex).registerC - val spannedReference = getInstruction(spannedIndex).reference + val spannedReference = + getInstruction(spannedIndex).reference addInstructionsWithLabels( spannedIndex + 1, """ diff --git a/patches/src/main/kotlin/app/revanced/patches/music/general/redirection/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/music/general/redirection/Fingerprints.kt index 3b66075ad..527af433a 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/general/redirection/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/general/redirection/Fingerprints.kt @@ -12,7 +12,9 @@ internal val dislikeButtonOnClickListenerFingerprint = legacyFingerprint( parameters = listOf("Landroid/view/View;"), customFingerprint = { method, _ -> method.name == "onClick" && - (method.containsLiteralInstruction(53465L) || method.containsLiteralInstruction(98173L)) + (method.containsLiteralInstruction(53465L) || method.containsLiteralInstruction( + 98173L + )) } ) diff --git a/patches/src/main/kotlin/app/revanced/patches/music/layout/branding/icon/CustomBrandingIconPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/layout/branding/icon/CustomBrandingIconPatch.kt index 3f1bdbb75..e04c23f67 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/layout/branding/icon/CustomBrandingIconPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/layout/branding/icon/CustomBrandingIconPatch.kt @@ -252,8 +252,14 @@ val customBrandingIconPatch = resourcePatch( } mapOf( - ADAPTIVE_ICON_BACKGROUND_FILE_NAME to getAdaptiveIconResourceFile("res/mipmap-anydpi/ic_launcher_release.xml", "background"), - ADAPTIVE_ICON_FOREGROUND_FILE_NAME to getAdaptiveIconResourceFile("res/mipmap-anydpi/ic_launcher_release.xml", "foreground") + ADAPTIVE_ICON_BACKGROUND_FILE_NAME to getAdaptiveIconResourceFile( + "res/mipmap-anydpi/ic_launcher_release.xml", + "background" + ), + ADAPTIVE_ICON_FOREGROUND_FILE_NAME to getAdaptiveIconResourceFile( + "res/mipmap-anydpi/ic_launcher_release.xml", + "foreground" + ) ).forEach { (oldIconResourceFile, newIconResourceFile) -> if (oldIconResourceFile != newIconResourceFile) { mipmapDirectories.forEach { diff --git a/patches/src/main/kotlin/app/revanced/patches/music/misc/drc/DrcAudioPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/misc/drc/DrcAudioPatch.kt index 1ba486ee1..695afc9b2 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/misc/drc/DrcAudioPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/misc/drc/DrcAudioPatch.kt @@ -40,7 +40,8 @@ val DrcAudioPatch = bytecodePatch( fingerprint.matchOrThrow(formatStreamModelConstructorFingerprint).let { it.method.apply { val insertIndex = it.patternMatch!!.endIndex - val insertRegister = getInstruction(insertIndex - 1).registerA + val insertRegister = + getInstruction(insertIndex - 1).registerA addInstructions( insertIndex, diff --git a/patches/src/main/kotlin/app/revanced/patches/music/player/components/PlayerComponentsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/player/components/PlayerComponentsPatch.kt index b09e21d01..1528f747d 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/player/components/PlayerComponentsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/player/components/PlayerComponentsPatch.kt @@ -823,7 +823,7 @@ val playerComponentsPatch = bytecodePatch( // region patch for remember repeat state val (repeatTrackMethod, repeatTrackIndex) = repeatTrackFingerprint.matchOrThrow().let { - with (it.method) { + with(it.method) { val targetIndex = it.patternMatch!!.endIndex val targetRegister = getInstruction(targetIndex).registerA diff --git a/patches/src/main/kotlin/app/revanced/patches/music/utils/fix/client/SpoofClientPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/utils/fix/client/SpoofClientPatch.kt index 4b0fed168..e0001e9e9 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/utils/fix/client/SpoofClientPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/utils/fix/client/SpoofClientPatch.kt @@ -80,10 +80,11 @@ val spoofClientPatch = bytecodePatch( val clientInfoVersionIndex = result.stringMatches!!.first().index val clientInfoVersionRegister = getInstruction(clientInfoVersionIndex).registerA - val clientInfoClientVersionFieldIndex = indexOfFirstInstructionOrThrow(clientInfoVersionIndex) { - opcode == Opcode.IPUT_OBJECT && - (this as TwoRegisterInstruction).registerA == clientInfoVersionRegister - } + val clientInfoClientVersionFieldIndex = + indexOfFirstInstructionOrThrow(clientInfoVersionIndex) { + opcode == Opcode.IPUT_OBJECT && + (this as TwoRegisterInstruction).registerA == clientInfoVersionRegister + } // Client info object's client version field. val clientInfoClientVersionField = @@ -95,27 +96,30 @@ val spoofClientPatch = bytecodePatch( } } - val clientInfoClientModelField = with (createPlayerRequestBodyWithModelFingerprint.methodOrThrow()) { - // The next IPUT_OBJECT instruction after getting the client model is setting the client model field. - val clientInfoClientModelIndex = indexOfFirstInstructionOrThrow(indexOfModelInstruction(this)) { - val reference = getReference() - opcode == Opcode.IPUT_OBJECT && - reference?.definingClass == CLIENT_INFO_CLASS_DESCRIPTOR && - reference.type == "Ljava/lang/String;" + val clientInfoClientModelField = + with(createPlayerRequestBodyWithModelFingerprint.methodOrThrow()) { + // The next IPUT_OBJECT instruction after getting the client model is setting the client model field. + val clientInfoClientModelIndex = + indexOfFirstInstructionOrThrow(indexOfModelInstruction(this)) { + val reference = getReference() + opcode == Opcode.IPUT_OBJECT && + reference?.definingClass == CLIENT_INFO_CLASS_DESCRIPTOR && + reference.type == "Ljava/lang/String;" + } + getInstruction(clientInfoClientModelIndex).reference } - getInstruction(clientInfoClientModelIndex).reference - } - val clientInfoOsVersionField = with (createPlayerRequestBodyWithVersionReleaseFingerprint.methodOrThrow()) { - val buildIndex = indexOfBuildInstruction(this) - val clientInfoOsVersionIndex = indexOfFirstInstructionOrThrow(buildIndex - 5) { - val reference = getReference() - opcode == Opcode.IPUT_OBJECT && - reference?.definingClass == CLIENT_INFO_CLASS_DESCRIPTOR && - reference.type == "Ljava/lang/String;" + val clientInfoOsVersionField = + with(createPlayerRequestBodyWithVersionReleaseFingerprint.methodOrThrow()) { + val buildIndex = indexOfBuildInstruction(this) + val clientInfoOsVersionIndex = indexOfFirstInstructionOrThrow(buildIndex - 5) { + val reference = getReference() + opcode == Opcode.IPUT_OBJECT && + reference?.definingClass == CLIENT_INFO_CLASS_DESCRIPTOR && + reference.type == "Ljava/lang/String;" + } + getInstruction(clientInfoOsVersionIndex).reference } - getInstruction(clientInfoOsVersionIndex).reference - } // endregion @@ -229,7 +233,8 @@ val spoofClientPatch = bytecodePatch( reference?.returnType == "V" && reference.parameterTypes.firstOrNull()?.startsWith("[L") == true } - val createPlaybackSpeedMenuItemMethod = getWalkerMethod(createPlaybackSpeedMenuItemIndex) + val createPlaybackSpeedMenuItemMethod = + getWalkerMethod(createPlaybackSpeedMenuItemIndex) createPlaybackSpeedMenuItemMethod.apply { val shouldCreateMenuIndex = indexOfFirstInstructionOrThrow { val reference = getReference() @@ -237,7 +242,8 @@ val spoofClientPatch = bytecodePatch( reference?.returnType == "Z" && reference.parameterTypes.isEmpty() } + 2 - val shouldCreateMenuRegister = getInstruction(shouldCreateMenuIndex - 1).registerA + val shouldCreateMenuRegister = + getInstruction(shouldCreateMenuIndex - 1).registerA addInstructions( shouldCreateMenuIndex, diff --git a/patches/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/SponsorBlockPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/SponsorBlockPatch.kt index e48153c4b..c50967393 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/SponsorBlockPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/SponsorBlockPatch.kt @@ -111,10 +111,11 @@ private val sponsorBlockBytecodePatch = bytecodePatch( rectangleFieldName = musicPlaybackControlsTimeBarOnMeasureFingerprint.matchOrThrow().let { with(it.method) { - val rectangleIndex = indexOfFirstInstructionReversedOrThrow(it.patternMatch!!.endIndex) { - opcode == Opcode.IGET_OBJECT && - getReference()?.type == "Landroid/graphics/Rect;" - } + val rectangleIndex = + indexOfFirstInstructionReversedOrThrow(it.patternMatch!!.endIndex) { + opcode == Opcode.IGET_OBJECT && + getReference()?.type == "Landroid/graphics/Rect;" + } val rectangleReference = getInstruction(rectangleIndex).reference (rectangleReference as FieldReference).name diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/gms/GmsCoreSupportPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/gms/GmsCoreSupportPatch.kt index f23b5411f..f22bd9fb4 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/gms/GmsCoreSupportPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/gms/GmsCoreSupportPatch.kt @@ -84,9 +84,9 @@ fun gmsCoreSupportPatch( key = "gmsCoreVendorGroupId", default = "app.revanced", values = - mapOf( - "ReVanced" to "app.revanced", - ), + mapOf( + "ReVanced" to "app.revanced", + ), title = "GmsCore vendor group ID", description = "The vendor's group ID for GmsCore.", required = true, diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/spoof/streamingdata/BaseSpoofStreamingDataPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/spoof/streamingdata/BaseSpoofStreamingDataPatch.kt index ea19354b6..bb1480f52 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/spoof/streamingdata/BaseSpoofStreamingDataPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/spoof/streamingdata/BaseSpoofStreamingDataPatch.kt @@ -81,50 +81,59 @@ fun baseSpoofStreamingDataPatch( // region Replace the streaming data. - createStreamingDataFingerprint.matchOrThrow(createStreamingDataParentFingerprint).let { result -> - result.method.apply { - val setStreamDataMethodName = "patch_setStreamingData" - val resultMethodType = result.classDef.type - val setStreamingDataIndex = result.patternMatch!!.startIndex - val setStreamingDataField = - getInstruction(setStreamingDataIndex).getReference().toString() + createStreamingDataFingerprint.matchOrThrow(createStreamingDataParentFingerprint) + .let { result -> + result.method.apply { + val setStreamDataMethodName = "patch_setStreamingData" + val resultMethodType = result.classDef.type + val setStreamingDataIndex = result.patternMatch!!.startIndex + val setStreamingDataField = + getInstruction(setStreamingDataIndex).getReference() + .toString() - val playerProtoClass = - getInstruction(setStreamingDataIndex + 1).getReference()!!.definingClass - val protobufClass = - protobufClassParseByteBufferFingerprint.definingClassOrThrow() + val playerProtoClass = + getInstruction(setStreamingDataIndex + 1).getReference()!!.definingClass + val protobufClass = + protobufClassParseByteBufferFingerprint.definingClassOrThrow() - val getStreamingDataField = instructions.find { instruction -> - instruction.opcode == Opcode.IGET_OBJECT && - instruction.getReference()?.definingClass == playerProtoClass - }?.getReference() - ?: throw PatchException("Could not find getStreamingDataField") + val getStreamingDataField = instructions.find { instruction -> + instruction.opcode == Opcode.IGET_OBJECT && + instruction.getReference()?.definingClass == playerProtoClass + }?.getReference() + ?: throw PatchException("Could not find getStreamingDataField") - val videoDetailsIndex = result.patternMatch!!.endIndex - val videoDetailsRegister = getInstruction(videoDetailsIndex).registerA - val videoDetailsClass = - getInstruction(videoDetailsIndex).getReference()!!.type + val videoDetailsIndex = result.patternMatch!!.endIndex + val videoDetailsRegister = + getInstruction(videoDetailsIndex).registerA + val videoDetailsClass = + getInstruction(videoDetailsIndex).getReference()!!.type - addInstruction( - videoDetailsIndex + 1, - "invoke-direct { p0, v$videoDetailsRegister }, " + - "$resultMethodType->$setStreamDataMethodName($videoDetailsClass)V", - ) + addInstruction( + videoDetailsIndex + 1, + "invoke-direct { p0, v$videoDetailsRegister }, " + + "$resultMethodType->$setStreamDataMethodName($videoDetailsClass)V", + ) - result.classDef.methods.add( - ImmutableMethod( - resultMethodType, - setStreamDataMethodName, - listOf(ImmutableMethodParameter(videoDetailsClass, annotations, "videoDetails")), - "V", - AccessFlags.PRIVATE.value or AccessFlags.FINAL.value, - annotations, - null, - MutableMethodImplementation(9), - ).toMutable().apply { - addInstructionsWithLabels( - 0, - """ + result.classDef.methods.add( + ImmutableMethod( + resultMethodType, + setStreamDataMethodName, + listOf( + ImmutableMethodParameter( + videoDetailsClass, + annotations, + "videoDetails" + ) + ), + "V", + AccessFlags.PRIVATE.value or AccessFlags.FINAL.value, + annotations, + null, + MutableMethodImplementation(9), + ).toMutable().apply { + addInstructionsWithLabels( + 0, + """ invoke-static { }, $EXTENSION_CLASS_DESCRIPTOR->isSpoofingEnabled()Z move-result v0 if-eqz v0, :disabled @@ -153,44 +162,52 @@ fun baseSpoofStreamingDataPatch( :disabled return-void """, - ) - }, + ) + }, + ) + } + } + + videoStreamingDataConstructorFingerprint.methodOrThrow(videoStreamingDataToStringFingerprint) + .apply { + val formatStreamModelInitIndex = indexOfFormatStreamModelInitInstruction(this) + val getVideoIdIndex = + indexOfFirstInstructionReversedOrThrow(formatStreamModelInitIndex) { + val reference = getReference() + opcode == Opcode.IGET_OBJECT && + reference?.type == "Ljava/lang/String;" && + reference.definingClass == definingClass + } + val getVideoIdReference = + getInstruction(getVideoIdIndex).reference + val insertIndex = indexOfFirstInstructionReversedOrThrow(getVideoIdIndex) { + opcode == Opcode.IGET_OBJECT && + getReference()?.definingClass == STREAMING_DATA_INTERFACE + } + + val (freeRegister, streamingDataRegister) = with( + getInstruction( + insertIndex + ) + ) { + Pair(registerA, registerB) + } + val definingClassRegister = + getInstruction(getVideoIdIndex).registerB + val insertReference = getInstruction(insertIndex).reference + + replaceInstruction( + insertIndex, + "iget-object v$freeRegister, v$freeRegister, $insertReference" ) - } - } - - videoStreamingDataConstructorFingerprint.methodOrThrow(videoStreamingDataToStringFingerprint).apply { - val formatStreamModelInitIndex = indexOfFormatStreamModelInitInstruction(this) - val getVideoIdIndex = indexOfFirstInstructionReversedOrThrow(formatStreamModelInitIndex) { - val reference = getReference() - opcode == Opcode.IGET_OBJECT && - reference?.type == "Ljava/lang/String;" && - reference.definingClass == definingClass - } - val getVideoIdReference = getInstruction(getVideoIdIndex).reference - val insertIndex = indexOfFirstInstructionReversedOrThrow(getVideoIdIndex) { - opcode == Opcode.IGET_OBJECT && - getReference()?.definingClass == STREAMING_DATA_INTERFACE - } - - val (freeRegister, streamingDataRegister) = with(getInstruction(insertIndex)) { - Pair(registerA, registerB) - } - val definingClassRegister = getInstruction(getVideoIdIndex).registerB - val insertReference = getInstruction(insertIndex).reference - - replaceInstruction( - insertIndex, - "iget-object v$freeRegister, v$freeRegister, $insertReference" - ) - addInstructions( - insertIndex, """ + addInstructions( + insertIndex, """ iget-object v$freeRegister, v$definingClassRegister, $getVideoIdReference invoke-static { v$freeRegister, v$streamingDataRegister }, $EXTENSION_CLASS_DESCRIPTOR->getOriginalStreamingData(Ljava/lang/String;$STREAMING_DATA_INTERFACE)$STREAMING_DATA_INTERFACE move-result-object v$freeRegister """ - ) - } + ) + } // endregion diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/general/miniplayer/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/general/miniplayer/Fingerprints.kt index f349da03e..304c4d0f9 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/general/miniplayer/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/general/miniplayer/Fingerprints.kt @@ -45,6 +45,7 @@ internal val miniplayerModernCloseButtonFingerprint = legacyFingerprint( ) internal const val MINIPLAYER_MODERN_FEATURE_KEY = 45622882L + // In later targets this feature flag does nothing and is dead code. internal const val MINIPLAYER_MODERN_FEATURE_LEGACY_KEY = 45630429L internal const val MINIPLAYER_DOUBLE_TAP_FEATURE_KEY = 45628823L diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/general/navigation/NavigationBarComponentsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/general/navigation/NavigationBarComponentsPatch.kt index 3b0e48a3e..8524ae122 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/general/navigation/NavigationBarComponentsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/general/navigation/NavigationBarComponentsPatch.kt @@ -173,13 +173,15 @@ val navigationBarComponentsPatch = bytecodePatch( * It was not too hard to fix, so it was implemented as a patch. */ if (is_19_28_or_greater) { - val cairoNotificationEnumReference = with (imageEnumConstructorFingerprint.methodOrThrow()) { - val stringIndex = indexOfFirstStringInstructionOrThrow(TAB_ACTIVITY_CAIRO_STRING) - val cairoNotificationEnumIndex = indexOfFirstInstructionOrThrow(stringIndex) { - opcode == Opcode.SPUT_OBJECT + val cairoNotificationEnumReference = + with(imageEnumConstructorFingerprint.methodOrThrow()) { + val stringIndex = + indexOfFirstStringInstructionOrThrow(TAB_ACTIVITY_CAIRO_STRING) + val cairoNotificationEnumIndex = indexOfFirstInstructionOrThrow(stringIndex) { + opcode == Opcode.SPUT_OBJECT + } + getInstruction(cairoNotificationEnumIndex).reference } - getInstruction(cairoNotificationEnumIndex).reference - } setEnumMapFingerprint.methodOrThrow().apply { val enumMapIndex = indexOfFirstInstructionReversedOrThrow { @@ -189,7 +191,9 @@ val navigationBarComponentsPatch = bytecodePatch( reference.name == "put" && reference.parameterTypes.firstOrNull() == "Ljava/lang/Enum;" } - val (enumMapRegister, enumRegister) = getInstruction(enumMapIndex).let { + val (enumMapRegister, enumRegister) = getInstruction( + enumMapIndex + ).let { Pair(it.registerC, it.registerD) } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/CustomBrandingIconPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/CustomBrandingIconPatch.kt index f45d688d0..ecfbe66c8 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/CustomBrandingIconPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/CustomBrandingIconPatch.kt @@ -209,8 +209,14 @@ val customBrandingIconPatch = resourcePatch( } mapOf( - ADAPTIVE_ICON_BACKGROUND_FILE_NAME to getAdaptiveIconResourceFile("res/mipmap-anydpi/ic_launcher.xml", "background"), - ADAPTIVE_ICON_FOREGROUND_FILE_NAME to getAdaptiveIconResourceFile("res/mipmap-anydpi/ic_launcher.xml", "foreground") + ADAPTIVE_ICON_BACKGROUND_FILE_NAME to getAdaptiveIconResourceFile( + "res/mipmap-anydpi/ic_launcher.xml", + "background" + ), + ADAPTIVE_ICON_FOREGROUND_FILE_NAME to getAdaptiveIconResourceFile( + "res/mipmap-anydpi/ic_launcher.xml", + "foreground" + ) ).forEach { (oldIconResourceFile, newIconResourceFile) -> if (oldIconResourceFile != newIconResourceFile) { mipmapDirectories.forEach { diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/player/seekbar/SeekbarComponentsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/player/seekbar/SeekbarComponentsPatch.kt index 6d6b94963..c4691d7d3 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/player/seekbar/SeekbarComponentsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/player/seekbar/SeekbarComponentsPatch.kt @@ -73,6 +73,7 @@ private fun create9BitSeekbarColorStyles(): String = StringBuilder().apply { fun roundTo3BitHex(channel8Bits: Int) = (channel8Bits * 255 / 7).toString(16).padStart(2, '0') + val r = roundTo3BitHex(red) val g = roundTo3BitHex(green) val b = roundTo3BitHex(blue) @@ -261,8 +262,10 @@ val seekbarComponentsPatch = bytecodePatch( onCreateMethod ).forEach { method -> method.apply { - val literalIndex = indexOfFirstLiteralInstructionOrThrow(launchScreenLayoutTypeLotteFeatureFlag) - val resultIndex = indexOfFirstInstructionOrThrow(literalIndex, Opcode.MOVE_RESULT) + val literalIndex = + indexOfFirstLiteralInstructionOrThrow(launchScreenLayoutTypeLotteFeatureFlag) + val resultIndex = + indexOfFirstInstructionOrThrow(literalIndex, Opcode.MOVE_RESULT) val register = getInstruction(resultIndex).registerA addInstructions( @@ -282,8 +285,10 @@ val seekbarComponentsPatch = bytecodePatch( reference?.definingClass == "Landroid/widget/ImageView;" && reference.name == "getDrawable" } - val checkCastIndex = indexOfFirstInstructionOrThrow(drawableIndex, Opcode.CHECK_CAST) - val drawableRegister = getInstruction(checkCastIndex).registerA + val checkCastIndex = + indexOfFirstInstructionOrThrow(drawableIndex, Opcode.CHECK_CAST) + val drawableRegister = + getInstruction(checkCastIndex).registerA addInstruction( checkCastIndex + 1, @@ -319,7 +324,10 @@ val seekbarComponentsPatch = bytecodePatch( // instead of allowing 24 bit color the style is restricted to 9-bit (3 bits per color channel) // and the style color closest to the users custom color is used for the splash screen. arrayOf( - inputStreamFromBundledResource("youtube/seekbar/values", "attrs.xml")!! to "res/values/attrs.xml", + inputStreamFromBundledResource( + "youtube/seekbar/values", + "attrs.xml" + )!! to "res/values/attrs.xml", ByteArrayInputStream(create9BitSeekbarColorStyles().toByteArray()) to "res/values/styles.xml" ).forEach { (source, destination) -> "resources".copyXmlNode( @@ -328,7 +336,10 @@ val seekbarComponentsPatch = bytecodePatch( ).close() } - fun setSplashDrawablePathFillColor(xmlFileNames: Iterable, vararg resourceNames: String) { + fun setSplashDrawablePathFillColor( + xmlFileNames: Iterable, + vararg resourceNames: String + ) { xmlFileNames.forEach { xmlFileName -> context.document(xmlFileName).use { document -> resourceNames.forEach { elementId -> @@ -342,7 +353,10 @@ val seekbarComponentsPatch = bytecodePatch( throw PatchException("Could not find $attribute for $elementId") } - element.setAttribute(attribute, "?attr/$splashSeekbarColorAttributeName") + element.setAttribute( + attribute, + "?attr/$splashSeekbarColorAttributeName" + ) } } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsComponentPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsComponentPatch.kt index 9531d723f..e68949a0e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsComponentPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsComponentPatch.kt @@ -217,7 +217,8 @@ private val shortsCustomActionsPatch = bytecodePatch( opcode == Opcode.INVOKE_VIRTUAL && getReference()?.returnType == "Ljava/lang/Object;" } - val getObjectReference = getInstruction(getObjectIndex).reference as MethodReference + val getObjectReference = + getInstruction(getObjectIndex).reference as MethodReference val bottomSheetMenuInitializeIndex = indexOfFirstInstructionOrThrow { val reference = getReference() @@ -225,17 +226,22 @@ private val shortsCustomActionsPatch = bytecodePatch( reference?.returnType == "V" && reference.parameterTypes[1] == "Ljava/lang/Object;" } - val bottomSheetMenuObjectRegister = getInstruction(bottomSheetMenuInitializeIndex).startRegister - val bottomSheetMenuObject = (getInstruction(bottomSheetMenuInitializeIndex).reference as MethodReference).parameterTypes[0]!! + val bottomSheetMenuObjectRegister = + getInstruction(bottomSheetMenuInitializeIndex).startRegister + val bottomSheetMenuObject = + (getInstruction(bottomSheetMenuInitializeIndex).reference as MethodReference).parameterTypes[0]!! val bottomSheetMenuListIndex = it.patternMatch!!.startIndex - val bottomSheetMenuListField = (getInstruction(bottomSheetMenuListIndex).reference as FieldReference) + val bottomSheetMenuListField = + (getInstruction(bottomSheetMenuListIndex).reference as FieldReference) val bottomSheetMenuClass = bottomSheetMenuListField.definingClass val bottomSheetMenuList = bottomSheetMenuListField.type - val bottomSheetMenuClassRegister = getInstruction(bottomSheetMenuListIndex).registerB - val bottomSheetMenuListRegister = getInstruction(bottomSheetMenuListIndex).registerA + val bottomSheetMenuClassRegister = + getInstruction(bottomSheetMenuListIndex).registerB + val bottomSheetMenuListRegister = + getInstruction(bottomSheetMenuListIndex).registerA addInstruction( bottomSheetMenuListIndex + 1, @@ -249,10 +255,11 @@ private val shortsCustomActionsPatch = bytecodePatch( "$EXTENSION_CUSTOM_ACTIONS_CLASS_DESCRIPTOR->setFlyoutMenuObject(Ljava/lang/Object;)V" ) - val addFlyoutMenuMethod = findMethodOrThrow(EXTENSION_CUSTOM_ACTIONS_CLASS_DESCRIPTOR) { - name == "addFlyoutMenu" && - accessFlags == AccessFlags.PRIVATE or AccessFlags.STATIC - } + val addFlyoutMenuMethod = + findMethodOrThrow(EXTENSION_CUSTOM_ACTIONS_CLASS_DESCRIPTOR) { + name == "addFlyoutMenu" && + accessFlags == AccessFlags.PRIVATE or AccessFlags.STATIC + } val customActionClass = with(addFlyoutMenuMethod) { val thirdParameter = parameters[2] @@ -277,7 +284,8 @@ private val shortsCustomActionsPatch = bytecodePatch( val bottomSheetMenuItemBuilderMethod = bottomSheetMenuItemBuilderFingerprint .methodOrThrow() - val newParameter = bottomSheetMenuItemBuilderMethod.parameters + listOf(customActionClass) + val newParameter = + bottomSheetMenuItemBuilderMethod.parameters + listOf(customActionClass) it.classDef.methods.add( bottomSheetMenuItemBuilderMethod @@ -291,7 +299,8 @@ private val shortsCustomActionsPatch = bytecodePatch( opcode == Opcode.INVOKE_DIRECT && getReference()?.returnType == "Landroid/graphics/drawable/Drawable;" } - val drawableRegister = getInstruction(drawableIndex + 1).registerA + val drawableRegister = + getInstruction(drawableIndex + 1).registerA addInstructions( drawableIndex + 2, """ @@ -301,11 +310,14 @@ private val shortsCustomActionsPatch = bytecodePatch( ) val charSequenceIndex = indexOfSpannedCharSequenceInstruction(this) - val charSequenceRegister = getInstruction(charSequenceIndex + 1).registerA + val charSequenceRegister = + getInstruction(charSequenceIndex + 1).registerA val insertIndex = charSequenceIndex + 2 - if (getInstruction(insertIndex).reference.toString().startsWith("Lapp/revanced")) { + if (getInstruction(insertIndex).reference.toString() + .startsWith("Lapp/revanced") + ) { removeInstructions(insertIndex, 2) } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/PlayerTypeHookPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/PlayerTypeHookPatch.kt index 7edd10a61..3bcb4e63f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/PlayerTypeHookPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/PlayerTypeHookPatch.kt @@ -137,7 +137,8 @@ val playerTypeHookPatch = bytecodePatch( searchQueryClassFingerprint.methodOrThrow().apply { val searchQueryIndex = indexOfStringIsEmptyInstruction(this) - 1 - val searchQueryFieldReference = getInstruction(searchQueryIndex).reference + val searchQueryFieldReference = + getInstruction(searchQueryIndex).reference val searchQueryClass = (searchQueryFieldReference as FieldReference).definingClass findMethodOrThrow(searchQueryClass).apply { diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt index 9d96c3d1f..288fc190c 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt @@ -187,7 +187,10 @@ val videoInformationPatch = bytecodePatch( } } - fun Pair.getPlayerResponseInstruction(returnType: String, fromString: Boolean? = null): String { + fun Pair.getPlayerResponseInstruction( + returnType: String, + fromString: Boolean? = null + ): String { methodOrThrow().apply { val startIndex = if (fromString == true) matchOrThrow().stringMatches!!.first().index