feat(music/hide-flyout-panel): code refactoring

This commit is contained in:
inotia00
2023-09-13 12:03:51 +09:00
parent a00578ddc8
commit 27b9ba8328
5 changed files with 49 additions and 21 deletions

View File

@ -10,9 +10,10 @@ import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.music.flyoutpanel.hide.fingerprints.MenuItemFingerprint import app.revanced.patches.music.utils.fingerprints.MenuItemFingerprint
import app.revanced.patches.music.flyoutpanel.utils.EnumUtils.getEnumIndex
import app.revanced.patches.music.utils.annotations.MusicCompatibility import app.revanced.patches.music.utils.annotations.MusicCompatibility
import app.revanced.patches.music.utils.flyoutbuttonhook.patch.FlyoutButtonHookPatch import app.revanced.patches.music.utils.flyoutbutton.patch.FlyoutButtonContainerResourcePatch
import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch
import app.revanced.util.enum.CategoryType import app.revanced.util.enum.CategoryType
import app.revanced.util.integrations.Constants.MUSIC_FLYOUT import app.revanced.util.integrations.Constants.MUSIC_FLYOUT
@ -26,7 +27,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
@Description("Hides flyout panel components.") @Description("Hides flyout panel components.")
@DependsOn( @DependsOn(
[ [
FlyoutButtonHookPatch::class, FlyoutButtonContainerResourcePatch::class,
SettingsPatch::class SettingsPatch::class
] ]
) )
@ -42,15 +43,15 @@ class FlyoutPanelPatch : BytecodePatch(
} }
val freeRegister = getInstruction<TwoRegisterInstruction>(freeIndex).registerA val freeRegister = getInstruction<TwoRegisterInstruction>(freeIndex).registerA
val targetIndex = it.scanResult.patternScanResult!!.startIndex + 3 val enumIndex = getEnumIndex()
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA val enumRegister = getInstruction<OneRegisterInstruction>(enumIndex).registerA
val jumpInstruction = val jumpInstruction =
getInstruction<Instruction>(implementation!!.instructions.size - 1) getInstruction<Instruction>(implementation!!.instructions.size - 1)
addInstructionsWithLabels( addInstructionsWithLabels(
targetIndex, """ enumIndex + 1, """
invoke-static {v$targetRegister}, $MUSIC_FLYOUT->hideFlyoutPanels(Ljava/lang/Enum;)Z invoke-static {v$enumRegister}, $MUSIC_FLYOUT->hideFlyoutPanels(Ljava/lang/Enum;)Z
move-result v$freeRegister move-result v$freeRegister
if-nez v$freeRegister, :hide if-nez v$freeRegister, :hide
""", ExternalLabel("hide", jumpInstruction) """, ExternalLabel("hide", jumpInstruction)

View File

@ -12,7 +12,7 @@ import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.music.flyoutpanel.playbackspeed.fingerprints.FlyoutPanelLikeButtonFingerprint import app.revanced.patches.music.flyoutpanel.playbackspeed.fingerprints.FlyoutPanelLikeButtonFingerprint
import app.revanced.patches.music.utils.annotations.MusicCompatibility import app.revanced.patches.music.utils.annotations.MusicCompatibility
import app.revanced.patches.music.utils.flyoutbuttonhook.patch.FlyoutButtonHookPatch import app.revanced.patches.music.utils.flyoutbutton.patch.FlyoutButtonContainerResourcePatch
import app.revanced.patches.music.utils.overridespeed.patch.OverrideSpeedHookPatch import app.revanced.patches.music.utils.overridespeed.patch.OverrideSpeedHookPatch
import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch import app.revanced.patches.music.utils.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch import app.revanced.patches.music.utils.settings.resource.patch.SettingsPatch
@ -27,7 +27,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@Description("Add playback speed button to the flyout panel.") @Description("Add playback speed button to the flyout panel.")
@DependsOn( @DependsOn(
[ [
FlyoutButtonHookPatch::class, FlyoutButtonContainerResourcePatch::class,
OverrideSpeedHookPatch::class, OverrideSpeedHookPatch::class,
SettingsPatch::class, SettingsPatch::class,
SharedResourceIdPatch::class SharedResourceIdPatch::class

View File

@ -0,0 +1,28 @@
package app.revanced.patches.music.flyoutpanel.utils
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
internal object EnumUtils {
fun MutableMethod.getEnumIndex(): Int {
var targetIndex = 0
for ((index, instruction) in implementation!!.instructions.withIndex()) {
if (instruction.opcode != Opcode.INVOKE_STATIC) continue
val targetParameter = getInstruction<ReferenceInstruction>(index).reference
if (!targetParameter.toString().contains("(I)")) continue
targetIndex = index + 1
break
}
if (targetIndex == 0)
throw PatchException("Target reference not found!")
return targetIndex
}
}

View File

@ -1,4 +1,4 @@
package app.revanced.patches.music.flyoutpanel.hide.fingerprints package app.revanced.patches.music.utils.fingerprints
import app.revanced.patcher.extensions.or import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
@ -10,14 +10,9 @@ object MenuItemFingerprint : MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = emptyList(), parameters = emptyList(),
opcodes = listOf( opcodes = listOf(
Opcode.IGET, Opcode.CHECK_CAST,
Opcode.INVOKE_STATIC, Opcode.INVOKE_DIRECT,
Opcode.MOVE_RESULT_OBJECT, Opcode.MOVE_RESULT_OBJECT
Opcode.IF_NEZ,
Opcode.SGET_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT,
Opcode.IF_EQZ
), ),
strings = listOf("toggleMenuItemMutations") strings = listOf("toggleMenuItemMutations")
) )

View File

@ -1,11 +1,11 @@
package app.revanced.patches.music.utils.flyoutbuttonhook.patch package app.revanced.patches.music.utils.flyoutbutton.patch
import app.revanced.patcher.data.ResourceContext import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.ResourcePatch import app.revanced.patcher.patch.ResourcePatch
import app.revanced.util.resources.ResourceUtils import app.revanced.util.resources.ResourceUtils
import app.revanced.util.resources.ResourceUtils.copyResources import app.revanced.util.resources.ResourceUtils.copyResources
class FlyoutButtonHookPatch : ResourcePatch { class FlyoutButtonContainerResourcePatch : ResourcePatch {
override fun execute(context: ResourceContext) { override fun execute(context: ResourceContext) {
/** /**
@ -26,8 +26,12 @@ class FlyoutButtonHookPatch : ResourcePatch {
resourceGroups.forEach { context.copyResources("music/flyout", it) } resourceGroups.forEach { context.copyResources("music/flyout", it) }
} }
val resourceFileNames = arrayOf(
"yt_outline_play_arrow_half_circle_black_24"
).map { "$it.png" }.toTypedArray()
fun createGroup(directory: String) = ResourceUtils.ResourceGroup( fun createGroup(directory: String) = ResourceUtils.ResourceGroup(
directory, "yt_outline_play_arrow_half_circle_black_24.png" directory, *resourceFileNames
) )
arrayOf("xxxhdpi", "xxhdpi", "xhdpi", "hdpi", "mdpi") arrayOf("xxxhdpi", "xxhdpi", "xhdpi", "hdpi", "mdpi")