chore: lint code

This commit is contained in:
inotia00 2024-06-13 00:20:35 +09:00
parent 4adce1465c
commit a4c50493f7
14 changed files with 103 additions and 44 deletions

View File

@ -29,6 +29,7 @@ object SettingsPatch : BaseResourcePatch(
description = "The name of the RVX settings menu.", description = "The name of the RVX settings menu.",
required = true required = true
) )
override fun execute(context: ResourceContext) { override fun execute(context: ResourceContext) {
/** /**
* Replace settings icon and label * Replace settings icon and label

View File

@ -85,7 +85,8 @@ abstract class BaseAdsPatch(
internal fun MethodFingerprintResult.hookLithoFullscreenAds(context: BytecodeContext) { internal fun MethodFingerprintResult.hookLithoFullscreenAds(context: BytecodeContext) {
mutableMethod.apply { mutableMethod.apply {
val dialogCodeIndex = scanResult.patternScanResult!!.endIndex val dialogCodeIndex = scanResult.patternScanResult!!.endIndex
val dialogCodeField = getInstruction<ReferenceInstruction>(dialogCodeIndex).reference as FieldReference val dialogCodeField =
getInstruction<ReferenceInstruction>(dialogCodeIndex).reference as FieldReference
if (dialogCodeField.type != "I") if (dialogCodeField.type != "I")
throw PatchException("Invalid dialogCodeField: $dialogCodeField") throw PatchException("Invalid dialogCodeField: $dialogCodeField")
@ -119,7 +120,8 @@ abstract class BaseAdsPatch(
method.parameters == listOf("I") method.parameters == listOf("I")
&& method.returnType == "Landroid/widget/Button;" && method.returnType == "Landroid/widget/Button;"
} }
val getButtonCall = dialogDefiningClass + "->" + getButtonMethod.name + "(I)Landroid/widget/Button;" val getButtonCall =
dialogDefiningClass + "->" + getButtonMethod.name + "(I)Landroid/widget/Button;"
val dialogRegister = getInstruction<FiveRegisterInstruction>(dialogIndex).registerC val dialogRegister = getInstruction<FiveRegisterInstruction>(dialogIndex).registerC
val freeIndex = getTargetIndex(dialogIndex, Opcode.IF_EQZ) val freeIndex = getTargetIndex(dialogIndex, Opcode.IF_EQZ)
val freeRegister = getInstruction<OneRegisterInstruction>(freeIndex).registerA val freeRegister = getInstruction<OneRegisterInstruction>(freeIndex).registerA

View File

@ -38,12 +38,13 @@ object TranslationsUtils {
// Exception is thrown if an invalid path is used in the patch option. // Exception is thrown if an invalid path is used in the patch option.
throw PatchException("Invalid custom translations path: $customLang") throw PatchException("Invalid custom translations path: $customLang")
} }
}?: run { } ?: run {
// Process selected translations if no custom translation is set. // Process selected translations if no custom translation is set.
val selectedTranslationsArray = val selectedTranslationsArray =
selectedTranslations?.split(",")?.map { it.trim() }?.toTypedArray() selectedTranslations?.split(",")?.map { it.trim() }?.toTypedArray()
?: throw PatchException("Invalid selected languages.") ?: throw PatchException("Invalid selected languages.")
val filteredLanguages = translationsArray.filter { it in selectedTranslationsArray }.toTypedArray() val filteredLanguages =
translationsArray.filter { it in selectedTranslationsArray }.toTypedArray()
copyXml(sourceDirectory, filteredLanguages) copyXml(sourceDirectory, filteredLanguages)
} }

View File

@ -96,7 +96,11 @@ object MiniplayerPatch : BaseBytecodePatch(
MiniplayerDimensionsCalculatorParentFingerprint.resultOrThrow().classDef MiniplayerDimensionsCalculatorParentFingerprint.resultOrThrow().classDef
) )
MiniplayerOverrideNoContextFingerprint.resultOrThrow().mutableMethod.apply { MiniplayerOverrideNoContextFingerprint.resultOrThrow().mutableMethod.apply {
findReturnIndicesReversed().forEach { index -> insertLegacyTabletMiniplayerOverride(index) } findReturnIndicesReversed().forEach { index ->
insertLegacyTabletMiniplayerOverride(
index
)
}
} }
// endregion // endregion
@ -110,7 +114,11 @@ object MiniplayerPatch : BaseBytecodePatch(
val walkerMethod = getWalkerMethod(context, appNameStringIndex) val walkerMethod = getWalkerMethod(context, appNameStringIndex)
walkerMethod.apply { walkerMethod.apply {
findReturnIndicesReversed().forEach { index -> insertLegacyTabletMiniplayerOverride(index) } findReturnIndicesReversed().forEach { index ->
insertLegacyTabletMiniplayerOverride(
index
)
}
} }
} }
} }
@ -143,7 +151,11 @@ object MiniplayerPatch : BaseBytecodePatch(
insertModernMiniplayerTypeOverride(iPutIndex) insertModernMiniplayerTypeOverride(iPutIndex)
} else { } else {
findReturnIndicesReversed().forEach { index -> insertModernMiniplayerOverride(index) } findReturnIndicesReversed().forEach { index ->
insertModernMiniplayerOverride(
index
)
}
} }
} }
} }
@ -165,7 +177,8 @@ object MiniplayerPatch : BaseBytecodePatch(
YtOutlineXWhite to YtOutlinePictureInPictureWhite, YtOutlineXWhite to YtOutlinePictureInPictureWhite,
).forEach { (originalResource, replacementResource) -> ).forEach { (originalResource, replacementResource) ->
val imageResourceIndex = indexOfWideLiteralInstructionOrThrow(originalResource) val imageResourceIndex = indexOfWideLiteralInstructionOrThrow(originalResource)
val register = getInstruction<OneRegisterInstruction>(imageResourceIndex).registerA val register =
getInstruction<OneRegisterInstruction>(imageResourceIndex).registerA
replaceInstruction(imageResourceIndex, "const v$register, $replacementResource") replaceInstruction(imageResourceIndex, "const v$register, $replacementResource")
} }
@ -178,10 +191,26 @@ object MiniplayerPatch : BaseBytecodePatch(
// region Add hooks to hide tablet modern miniplayer buttons. // region Add hooks to hide tablet modern miniplayer buttons.
listOf( listOf(
Triple(MiniplayerModernExpandButtonFingerprint, ModernMiniPlayerExpand,"hideMiniplayerExpandClose"), Triple(
Triple(MiniplayerModernCloseButtonFingerprint, ModernMiniPlayerClose, "hideMiniplayerExpandClose"), MiniplayerModernExpandButtonFingerprint,
Triple(MiniplayerModernRewindButtonFingerprint, ModernMiniPlayerRewindButton, "hideMiniplayerRewindForward"), ModernMiniPlayerExpand,
Triple(MiniplayerModernForwardButtonFingerprint, ModernMiniPlayerForwardButton, "hideMiniplayerRewindForward"), "hideMiniplayerExpandClose"
),
Triple(
MiniplayerModernCloseButtonFingerprint,
ModernMiniPlayerClose,
"hideMiniplayerExpandClose"
),
Triple(
MiniplayerModernRewindButtonFingerprint,
ModernMiniPlayerRewindButton,
"hideMiniplayerRewindForward"
),
Triple(
MiniplayerModernForwardButtonFingerprint,
ModernMiniPlayerForwardButton,
"hideMiniplayerRewindForward"
),
Triple(MiniplayerModernOverlayViewFingerprint, ScrimOverlay, "adjustMiniplayerOpacity") Triple(MiniplayerModernOverlayViewFingerprint, ScrimOverlay, "adjustMiniplayerOpacity")
).forEach { (fingerprint, literalValue, methodName) -> ).forEach { (fingerprint, literalValue, methodName) ->
fingerprint.resolve( fingerprint.resolve(
@ -221,7 +250,11 @@ object MiniplayerPatch : BaseBytecodePatch(
listOf( listOf(
ImmutableMethodParameter("Landroid/view/View;", annotations, null), ImmutableMethodParameter("Landroid/view/View;", annotations, null),
ImmutableMethodParameter("I", annotations, null), ImmutableMethodParameter("I", annotations, null),
ImmutableMethodParameter("Landroid/view/ViewGroup\$LayoutParams;", annotations, null), ImmutableMethodParameter(
"Landroid/view/ViewGroup\$LayoutParams;",
annotations,
null
),
), ),
"V", "V",
AccessFlags.PUBLIC.value, AccessFlags.PUBLIC.value,

View File

@ -79,11 +79,14 @@ object CustomBrandingIconPatch : BaseResourcePatch(
) )
} }
private val launcherIconResourceGroups = mipmapDirectories.getResourceGroup(launcherIconResourceFileNames) private val launcherIconResourceGroups =
mipmapDirectories.getResourceGroup(launcherIconResourceFileNames)
private val splashIconResourceGroups = drawableDirectories.getResourceGroup(splashIconResourceFileNames) private val splashIconResourceGroups =
drawableDirectories.getResourceGroup(splashIconResourceFileNames)
private val oldSplashAnimationResourceGroups = listOf("drawable").getResourceGroup(oldSplashAnimationResourceFileNames) private val oldSplashAnimationResourceGroups =
listOf("drawable").getResourceGroup(oldSplashAnimationResourceFileNames)
// region patch option // region patch option
@ -178,7 +181,11 @@ object CustomBrandingIconPatch : BaseResourcePatch(
} }
} }
context.copyXmlNode("$stockResourcePath/splash", "values-v31/styles.xml", "resources") context.copyXmlNode(
"$stockResourcePath/splash",
"values-v31/styles.xml",
"resources"
)
} }
context.updatePatchStatusIcon(appIcon) context.updatePatchStatusIcon(appIcon)

View File

@ -50,8 +50,10 @@ object ChangeHeaderPatch : BaseResourcePatch(
premiumHeaderResourceDirectoryNames.keys.map { directory -> premiumHeaderResourceDirectoryNames.keys.map { directory ->
ResourceGroup( ResourceGroup(
directory, directory,
*variants.map { variant -> "${GENERIC_HEADER_FILE_NAME}_$variant.png" }.toTypedArray(), *variants.map { variant -> "${GENERIC_HEADER_FILE_NAME}_$variant.png" }
*variants.map { variant -> "${PREMIUM_HEADER_FILE_NAME}_$variant.png" }.toTypedArray(), .toTypedArray(),
*variants.map { variant -> "${PREMIUM_HEADER_FILE_NAME}_$variant.png" }
.toTypedArray(),
) )
} }
@ -82,14 +84,20 @@ object ChangeHeaderPatch : BaseResourcePatch(
The image dimensions must be as follows: The image dimensions must be as follows:
${genericHeaderResourceDirectoryNames.map { (dpi, dim) -> "- $dpi: $dim" }.joinToString("\n")} ${
genericHeaderResourceDirectoryNames.map { (dpi, dim) -> "- $dpi: $dim" }
.joinToString("\n")
}
[Premium header] [Premium header]
${variants.joinToString("\n") { variant -> "- ${PREMIUM_HEADER_FILE_NAME}_$variant.png" }} ${variants.joinToString("\n") { variant -> "- ${PREMIUM_HEADER_FILE_NAME}_$variant.png" }}
The image dimensions must be as follows: The image dimensions must be as follows:
${premiumHeaderResourceDirectoryNames.map { (dpi, dim) -> "- $dpi: $dim" }.joinToString("\n")} ${
premiumHeaderResourceDirectoryNames.map { (dpi, dim) -> "- $dpi: $dim" }
.joinToString("\n")
}
""".trimIndentMultiline(), """.trimIndentMultiline(),
required = true, required = true,
) )

View File

@ -1,7 +1,6 @@
package app.revanced.patches.youtube.layout.visual package app.revanced.patches.youtube.layout.visual
import app.revanced.patcher.data.ResourceContext import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatchOption import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatchOption
import app.revanced.patches.youtube.layout.branding.icon.CustomBrandingIconPatch import app.revanced.patches.youtube.layout.branding.icon.CustomBrandingIconPatch
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE

View File

@ -1,7 +1,7 @@
package app.revanced.patches.youtube.misc.codecs package app.revanced.patches.youtube.misc.codecs
import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH
import app.revanced.patches.shared.opus.BaseOpusCodecsPatch import app.revanced.patches.shared.opus.BaseOpusCodecsPatch
import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH
object OpusCodecBytecodePatch : BaseOpusCodecsPatch( object OpusCodecBytecodePatch : BaseOpusCodecsPatch(
"$MISC_PATH/OpusCodecPatch;->enableOpusCodec()Z" "$MISC_PATH/OpusCodecPatch;->enableOpusCodec()Z"

View File

@ -245,17 +245,17 @@ object SeekbarComponentsPatch : BaseBytecodePatch(
PlayerSeekbarColorFingerprint.resultOrThrow().let { parentResult -> PlayerSeekbarColorFingerprint.resultOrThrow().let { parentResult ->
TimeCounterFingerprint.also { it.resolve(context, parentResult.classDef) } TimeCounterFingerprint.also { it.resolve(context, parentResult.classDef) }
.resultOrThrow().let { .resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
addInstructionsWithLabels( addInstructionsWithLabels(
0, """ 0, """
invoke-static {}, $PLAYER_CLASS_DESCRIPTOR->hideTimeStamp()Z invoke-static {}, $PLAYER_CLASS_DESCRIPTOR->hideTimeStamp()Z
move-result v0 move-result v0
if-eqz v0, :show if-eqz v0, :show
return-void return-void
""", ExternalLabel("show", getInstruction(0)) """, ExternalLabel("show", getInstruction(0))
) )
}
} }
}
} }
// endregion // endregion

View File

@ -27,16 +27,16 @@ object ShortsNavigationBarPatch : BytecodePatch(
InitializeButtonsFingerprint.resultOrThrow().let { parentResult -> InitializeButtonsFingerprint.resultOrThrow().let { parentResult ->
SetPivotBarFingerprint.also { it.resolve(context, parentResult.classDef) } SetPivotBarFingerprint.also { it.resolve(context, parentResult.classDef) }
.resultOrThrow().let { .resultOrThrow().let {
it.mutableMethod.apply { it.mutableMethod.apply {
val startIndex = it.scanResult.patternScanResult!!.startIndex val startIndex = it.scanResult.patternScanResult!!.startIndex
val register = getInstruction<OneRegisterInstruction>(startIndex).registerA val register = getInstruction<OneRegisterInstruction>(startIndex).registerA
addInstruction( addInstruction(
startIndex + 1, startIndex + 1,
"invoke-static {v$register}, $SHORTS_CLASS_DESCRIPTOR->setNavigationBar(Ljava/lang/Object;)V" "invoke-static {v$register}, $SHORTS_CLASS_DESCRIPTOR->setNavigationBar(Ljava/lang/Object;)V"
) )
}
} }
}
} }
RenderBottomNavigationBarFingerprint.resultOrThrow().let { RenderBottomNavigationBarFingerprint.resultOrThrow().let {

View File

@ -300,8 +300,10 @@ object SpoofClientPatch : BaseBytecodePatch(
it.mutableMethod.apply { it.mutableMethod.apply {
// Find the conditional check if the playback speed menu item is not created. // Find the conditional check if the playback speed menu item is not created.
val shouldCreateMenuIndex = indexOfFirstInstructionOrThrow(scanResult.endIndex) { opcode == Opcode.IF_EQZ } val shouldCreateMenuIndex =
val shouldCreateMenuRegister = getInstruction<OneRegisterInstruction>(shouldCreateMenuIndex).registerA indexOfFirstInstructionOrThrow(scanResult.endIndex) { opcode == Opcode.IF_EQZ }
val shouldCreateMenuRegister =
getInstruction<OneRegisterInstruction>(shouldCreateMenuIndex).registerA
addInstructions( addInstructions(
shouldCreateMenuIndex, shouldCreateMenuIndex,

View File

@ -1,8 +1,8 @@
package app.revanced.patches.youtube.utils.fix.client.fingerprints package app.revanced.patches.youtube.utils.fix.client.fingerprints
import app.revanced.patcher.extensions.or import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.annotation.FuzzyPatternScanMethod
import app.revanced.patcher.fingerprint.MethodFingerprint import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patcher.fingerprint.annotation.FuzzyPatternScanMethod
import app.revanced.util.getReference import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.AccessFlags
@ -44,12 +44,12 @@ internal object PlayerGestureConfigSyntheticFingerprint : MethodFingerprint(
methodDef.indexOfFirstInstruction { methodDef.indexOfFirstInstruction {
val reference = getReference<MethodReference>() val reference = getReference<MethodReference>()
reference?.definingClass == "Lcom/google/android/libraries/youtube/innertube/model/media/PlayerConfigModel;" && reference?.definingClass == "Lcom/google/android/libraries/youtube/innertube/model/media/PlayerConfigModel;" &&
reference.parameterTypes.isEmpty() && reference.parameterTypes.isEmpty() &&
reference.returnType == "Z" reference.returnType == "Z"
} }
// This method is always called "a" because this kind of class always has a single method. // This method is always called "a" because this kind of class always has a single method.
methodDef.name == "a" && classDef.methods.count() == 2 && methodDef.name == "a" && classDef.methods.count() == 2 &&
indexOfDownAndOutAllowedInstruction(methodDef) >= 0 indexOfDownAndOutAllowedInstruction(methodDef) >= 0
}, },
) )

View File

@ -239,7 +239,10 @@ fun Method.indexOfFirstInstruction(startIndex: Int = 0, predicate: Instruction.(
* @throws PatchException * @throws PatchException
* @see indexOfFirstInstruction * @see indexOfFirstInstruction
*/ */
fun Method.indexOfFirstInstructionOrThrow(startIndex: Int = 0, predicate: Instruction.() -> Boolean): Int { fun Method.indexOfFirstInstructionOrThrow(
startIndex: Int = 0,
predicate: Instruction.() -> Boolean
): Int {
val index = indexOfFirstInstruction(startIndex, predicate) val index = indexOfFirstInstruction(startIndex, predicate)
if (index < 0) { if (index < 0) {
throw PatchException("Could not find instruction index") throw PatchException("Could not find instruction index")

View File

@ -106,7 +106,10 @@ fun ResourceContext.copyResources(
resourceGroup.resources.forEach { resource -> resourceGroup.resources.forEach { resource ->
val resourceFile = "${resourceGroup.resourceDirectoryName}/$resource" val resourceFile = "${resourceGroup.resourceDirectoryName}/$resource"
inputStreamFromBundledResource(sourceResourceDirectory, resourceFile)?.let { inputStream -> inputStreamFromBundledResource(
sourceResourceDirectory,
resourceFile
)?.let { inputStream ->
Files.copy( Files.copy(
inputStream, inputStream,
targetResourceDirectory.resolve(resourceFile).toPath(), targetResourceDirectory.resolve(resourceFile).toPath(),