mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 21:27:43 +02:00
feat(music/hide-flyout-panel): code refactoring
This commit is contained in:
@ -10,9 +10,10 @@ import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.annotations.DependsOn
|
||||
import app.revanced.patcher.patch.annotations.Patch
|
||||
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.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.util.enum.CategoryType
|
||||
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.")
|
||||
@DependsOn(
|
||||
[
|
||||
FlyoutButtonHookPatch::class,
|
||||
FlyoutButtonContainerResourcePatch::class,
|
||||
SettingsPatch::class
|
||||
]
|
||||
)
|
||||
@ -42,15 +43,15 @@ class FlyoutPanelPatch : BytecodePatch(
|
||||
}
|
||||
val freeRegister = getInstruction<TwoRegisterInstruction>(freeIndex).registerA
|
||||
|
||||
val targetIndex = it.scanResult.patternScanResult!!.startIndex + 3
|
||||
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
|
||||
val enumIndex = getEnumIndex()
|
||||
val enumRegister = getInstruction<OneRegisterInstruction>(enumIndex).registerA
|
||||
|
||||
val jumpInstruction =
|
||||
getInstruction<Instruction>(implementation!!.instructions.size - 1)
|
||||
|
||||
addInstructionsWithLabels(
|
||||
targetIndex, """
|
||||
invoke-static {v$targetRegister}, $MUSIC_FLYOUT->hideFlyoutPanels(Ljava/lang/Enum;)Z
|
||||
enumIndex + 1, """
|
||||
invoke-static {v$enumRegister}, $MUSIC_FLYOUT->hideFlyoutPanels(Ljava/lang/Enum;)Z
|
||||
move-result v$freeRegister
|
||||
if-nez v$freeRegister, :hide
|
||||
""", ExternalLabel("hide", jumpInstruction)
|
||||
|
@ -12,7 +12,7 @@ import app.revanced.patcher.patch.annotations.DependsOn
|
||||
import app.revanced.patcher.patch.annotations.Patch
|
||||
import app.revanced.patches.music.flyoutpanel.playbackspeed.fingerprints.FlyoutPanelLikeButtonFingerprint
|
||||
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.resourceid.patch.SharedResourceIdPatch
|
||||
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.")
|
||||
@DependsOn(
|
||||
[
|
||||
FlyoutButtonHookPatch::class,
|
||||
FlyoutButtonContainerResourcePatch::class,
|
||||
OverrideSpeedHookPatch::class,
|
||||
SettingsPatch::class,
|
||||
SharedResourceIdPatch::class
|
||||
|
@ -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
|
||||
}
|
||||
}
|
@ -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.fingerprint.method.impl.MethodFingerprint
|
||||
@ -10,14 +10,9 @@ object MenuItemFingerprint : MethodFingerprint(
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||
parameters = emptyList(),
|
||||
opcodes = listOf(
|
||||
Opcode.IGET,
|
||||
Opcode.INVOKE_STATIC,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.IF_NEZ,
|
||||
Opcode.SGET_OBJECT,
|
||||
Opcode.INVOKE_INTERFACE,
|
||||
Opcode.MOVE_RESULT,
|
||||
Opcode.IF_EQZ
|
||||
Opcode.CHECK_CAST,
|
||||
Opcode.INVOKE_DIRECT,
|
||||
Opcode.MOVE_RESULT_OBJECT
|
||||
),
|
||||
strings = listOf("toggleMenuItemMutations")
|
||||
)
|
@ -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.patch.ResourcePatch
|
||||
import app.revanced.util.resources.ResourceUtils
|
||||
import app.revanced.util.resources.ResourceUtils.copyResources
|
||||
|
||||
class FlyoutButtonHookPatch : ResourcePatch {
|
||||
class FlyoutButtonContainerResourcePatch : ResourcePatch {
|
||||
override fun execute(context: ResourceContext) {
|
||||
|
||||
/**
|
||||
@ -26,8 +26,12 @@ class FlyoutButtonHookPatch : ResourcePatch {
|
||||
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(
|
||||
directory, "yt_outline_play_arrow_half_circle_black_24.png"
|
||||
directory, *resourceFileNames
|
||||
)
|
||||
|
||||
arrayOf("xxxhdpi", "xxhdpi", "xhdpi", "hdpi", "mdpi")
|
Reference in New Issue
Block a user