Skip to content

Commit

Permalink
chore(YouTube Music): replace with a fingerprint that supports a wide…
Browse files Browse the repository at this point in the history
…r range of versions
  • Loading branch information
inotia00 committed Oct 18, 2024
1 parent 6af5fdb commit 486a007
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.music.flyoutmenu.components.fingerprints.DialogSolidFingerprint
import app.revanced.patches.music.flyoutmenu.components.fingerprints.EndButtonsContainerFingerprint
import app.revanced.patches.music.flyoutmenu.components.fingerprints.MenuItemFingerprint
import app.revanced.patches.music.flyoutmenu.components.fingerprints.ScreenWidthFingerprint
import app.revanced.patches.music.flyoutmenu.components.fingerprints.ScreenWidthParentFingerprint
import app.revanced.patches.music.flyoutmenu.components.fingerprints.SleepTimerFingerprint
import app.revanced.patches.music.flyoutmenu.components.fingerprints.TouchOutsideFingerprint
import app.revanced.patches.music.flyoutmenu.components.fingerprints.TrimSilenceConfigFingerprint
Expand All @@ -25,6 +26,7 @@ import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.patches.music.utils.videotype.VideoTypeHookPatch
import app.revanced.patches.music.video.information.VideoInformationPatch
import app.revanced.patches.shared.litho.LithoFilterPatch
import app.revanced.util.alsoResolve
import app.revanced.util.findMethodOrThrow
import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod
Expand Down Expand Up @@ -55,9 +57,9 @@ object FlyoutMenuComponentsPatch : BaseBytecodePatch(
),
compatiblePackages = COMPATIBLE_PACKAGE,
fingerprints = setOf(
DialogSolidFingerprint,
EndButtonsContainerFingerprint,
MenuItemFingerprint,
ScreenWidthParentFingerprint,
SleepTimerFingerprint,
TouchOutsideFingerprint,
TrimSilenceConfigFingerprint,
Expand All @@ -72,15 +74,20 @@ object FlyoutMenuComponentsPatch : BaseBytecodePatch(

// region patch for enable compact dialog

DialogSolidFingerprint.resultOrThrow().let {
val walkerMethod =
it.getWalkerMethod(context, it.scanResult.patternScanResult!!.endIndex)
walkerMethod.addInstructions(
2, """
invoke-static {p0}, $FLYOUT_CLASS_DESCRIPTOR->enableCompactDialog(I)I
move-result p0
"""
)
ScreenWidthFingerprint.alsoResolve(
context, ScreenWidthParentFingerprint
).let {
it.mutableMethod.apply {
val index = it.scanResult.patternScanResult!!.startIndex
val register = getInstruction<TwoRegisterInstruction>(index).registerA

addInstructions(
index, """
invoke-static {v$register}, $FLYOUT_CLASS_DESCRIPTOR->enableCompactDialog(I)I
move-result v$register
"""
)
}
}

// endregion
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package app.revanced.patches.music.flyoutmenu.components.fingerprints

import app.revanced.util.fingerprint.LiteralValueFingerprint
import com.android.tools.smali.dexlib2.Opcode

internal object ScreenWidthFingerprint : LiteralValueFingerprint(
returnType = "Z",
parameters = listOf("L"),
opcodes = listOf(Opcode.IF_LT),
literalSupplier = { 600 },
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package app.revanced.patches.music.flyoutmenu.components.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionReversed
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.reference.MethodReference

internal object ScreenWidthParentFingerprint : MethodFingerprint(
returnType = "Landroid/graphics/Bitmap;",
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
parameters = listOf("Landroid/app/Activity;", "I"),
customFingerprint = { methodDef, _ ->
methodDef.indexOfFirstInstructionReversed {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "destroyDrawingCache"
} >= 0
}
)

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.booleanPat
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatchOption
import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.music.utils.settings.ResourceUtils.setIconType
import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.util.ResourceGroup
import app.revanced.util.Utils.trimIndentMultiline
import app.revanced.util.copyResources
Expand All @@ -15,13 +16,16 @@ import app.revanced.util.underBarOrThrow
import org.w3c.dom.Element
import java.io.File
import java.nio.file.Files
import java.nio.file.StandardCopyOption

@Suppress("DEPRECATION", "unused")
object CustomBrandingIconPatch : BaseResourcePatch(
name = "Custom branding icon for YouTube Music",
description = "Changes the YouTube Music app icon to the icon specified in options.json.",
compatiblePackages = COMPATIBLE_PACKAGE
) {
private const val ADAPTIVE_ICON_BACKGROUND_FILE_NAME = "adaptiveproduct_youtube_music_background_color_108"
private const val ADAPTIVE_ICON_FOREGROUND_FILE_NAME = "adaptiveproduct_youtube_music_foreground_color_108"
private const val DEFAULT_ICON = "revancify_blue"

private val availableIcon = mapOf(
Expand Down Expand Up @@ -60,8 +64,8 @@ object CustomBrandingIconPatch : BaseResourcePatch(
private val mipmapDirectories = sizeArray.map { "mipmap-$it" }

private val launcherIconResourceFileNames = arrayOf(
"adaptiveproduct_youtube_music_background_color_108",
"adaptiveproduct_youtube_music_foreground_color_108",
ADAPTIVE_ICON_BACKGROUND_FILE_NAME,
ADAPTIVE_ICON_FOREGROUND_FILE_NAME,
"ic_launcher_release"
).map { "$it.png" }.toTypedArray()

Expand Down Expand Up @@ -224,5 +228,50 @@ object CustomBrandingIconPatch : BaseResourcePatch(

setIconType(appIcon)
}

// region fix app icon

if (!SettingsPatch.upward0723) {
return
}

fun getAdaptiveIconResourceFile(tag: String): String {
context.xmlEditor["res/mipmap-anydpi/ic_launcher_release.xml"].use { editor ->
val adaptiveIcon = editor
.file
.getElementsByTagName("adaptive-icon")
.item(0) as Element

val childNodes = adaptiveIcon.childNodes
for (i in 0 until childNodes.length) {
val node = childNodes.item(i)
if (node is Element && node.tagName == tag && node.hasAttribute("android:drawable")) {
return node.getAttribute("android:drawable").split("/")[1]
}
}
throw PatchException("Element not found: $tag")
}
}

mapOf(
ADAPTIVE_ICON_BACKGROUND_FILE_NAME to getAdaptiveIconResourceFile("background"),
ADAPTIVE_ICON_FOREGROUND_FILE_NAME to getAdaptiveIconResourceFile("foreground")
).forEach { (oldIconResourceFile, newIconResourceFile) ->
mipmapDirectories.forEach {
val mipmapDirectory = context["res"].resolve(it)
Files.move(
mipmapDirectory
.resolve("$oldIconResourceFile.png")
.toPath(),
mipmapDirectory
.resolve("$newIconResourceFile.png")
.toPath(),
StandardCopyOption.REPLACE_EXISTING
)
}
}

// endregion

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ object SharedResourceIdPatch : ResourcePatch() {
var ColorGrey = -1L
var DarkBackground = -1L
var DesignBottomSheetDialog = -1L
var DialogSolid = -1L
var EndButtonsContainer = -1L
var FloatingLayout = -1L
var HistoryMenuItem = -1L
Expand Down Expand Up @@ -68,7 +67,6 @@ object SharedResourceIdPatch : ResourcePatch() {
ColorGrey = getId(COLOR, "ytm_color_grey_12")
DarkBackground = getId(ID, "dark_background")
DesignBottomSheetDialog = getId(LAYOUT, "design_bottom_sheet_dialog")
DialogSolid = getId(STYLE, "Theme.YouTubeMusic.Dialog.Solid")
EndButtonsContainer = getId(ID, "end_buttons_container")
FloatingLayout = getId(ID, "floating_layout")
HistoryMenuItem = getId(ID, "history_menu_item")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ object SettingsPatch : BaseResourcePatch(
internal var upward0706 = false
internal var upward0718 = false
internal var upward0720 = false
internal var upward0723 = false

override fun execute(context: ResourceContext) {

Expand Down Expand Up @@ -142,6 +143,7 @@ object SettingsPatch : BaseResourcePatch(
upward0706 = 242499000 <= playServicesVersion
upward0718 = 243699000 <= playServicesVersion
upward0720 = 243899000 <= playServicesVersion
upward0723 = 244199000 <= playServicesVersion

break
}
Expand Down

0 comments on commit 486a007

Please sign in to comment.