generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 610
feat(YouTube Music): Add Change miniplayer color patch
#6259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+161
−0
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
805e644
feat(YouTube Music): Add `Change miniplayer color` patch
MarcaDian e621abd
api dump
LisoUseInAIKyrios aac8814
refactor
LisoUseInAIKyrios 86d5f01
unofficial 8.44.53
LisoUseInAIKyrios 0257236
refactor
LisoUseInAIKyrios 0db9df4
Update patches/src/main/kotlin/app/revanced/patches/music/layout/mini…
LisoUseInAIKyrios 32e01db
Update patches/src/main/resources/addresources/values/strings.xml
LisoUseInAIKyrios c6f517a
fix refactoring
LisoUseInAIKyrios File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
.../music/src/main/java/app/revanced/extension/music/patches/ChangeMiniplayerColorPatch.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package app.revanced.extension.music.patches; | ||
|
|
||
| import app.revanced.extension.music.settings.Settings; | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public class ChangeMiniplayerColorPatch { | ||
|
|
||
| /** | ||
| * Injection point | ||
| */ | ||
| public static boolean changeMiniplayerColor() { | ||
| return Settings.CHANGE_MINIPLAYER_COLOR.get(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
...rc/main/kotlin/app/revanced/patches/music/layout/miniplayercolor/ChangeMiniplayerColor.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| @file:Suppress("SpellCheckingInspection") | ||
|
|
||
| package app.revanced.patches.music.layout.miniplayercolor | ||
|
|
||
| import app.revanced.patcher.extensions.InstructionExtensions.getInstruction | ||
| import app.revanced.patcher.patch.bytecodePatch | ||
| import app.revanced.patches.all.misc.resources.addResources | ||
| import app.revanced.patches.all.misc.resources.addResourcesPatch | ||
| import app.revanced.patches.music.misc.extension.sharedExtensionPatch | ||
| import app.revanced.patches.music.misc.settings.PreferenceScreen | ||
| import app.revanced.patches.music.misc.settings.settingsPatch | ||
| import app.revanced.patches.shared.misc.mapping.get | ||
| import app.revanced.patches.shared.misc.mapping.resourceMappingPatch | ||
| import app.revanced.patches.shared.misc.mapping.resourceMappings | ||
| import app.revanced.patches.shared.misc.settings.preference.SwitchPreference | ||
| import app.revanced.util.addInstructionsAtControlFlowLabel | ||
| import app.revanced.util.findFreeRegister | ||
| import app.revanced.util.getReference | ||
| import app.revanced.util.indexOfFirstInstructionOrThrow | ||
| import app.revanced.util.indexOfFirstInstructionReversedOrThrow | ||
| import com.android.tools.smali.dexlib2.AccessFlags | ||
| import com.android.tools.smali.dexlib2.Opcode | ||
| import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction | ||
| import com.android.tools.smali.dexlib2.iface.reference.FieldReference | ||
| import com.android.tools.smali.dexlib2.iface.reference.MethodReference | ||
|
|
||
| internal var mpp_player_bottom_sheet = -1L | ||
| private set | ||
|
|
||
| private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/music/patches/ChangeMiniplayerColorPatch;" | ||
|
|
||
| @Suppress("unused") | ||
| val changeMiniplayerColor = bytecodePatch( | ||
| name = "Change miniplayer color", | ||
| description = "Adds an option to make the miniplayer match the fullscreen player color." | ||
| ) { | ||
| dependsOn( | ||
| sharedExtensionPatch, | ||
| settingsPatch, | ||
| addResourcesPatch, | ||
| resourceMappingPatch | ||
| ) | ||
|
|
||
| compatibleWith( | ||
| "com.google.android.apps.youtube.music"( | ||
| "7.29.52", | ||
| "8.10.52" | ||
| ) | ||
| ) | ||
|
|
||
| execute { | ||
| mpp_player_bottom_sheet = resourceMappings["id", "mpp_player_bottom_sheet"] | ||
|
|
||
| addResources("music", "layout.miniplayercolor.changeMiniplayerColor") | ||
|
|
||
| PreferenceScreen.PLAYER.addPreferences( | ||
| SwitchPreference("revanced_music_change_miniplayer_color"), | ||
| ) | ||
|
|
||
| switchToggleColorFingerprint.match(miniPlayerConstructorFingerprint.classDef).let { | ||
| val relativeIndex = it.patternMatch!!.endIndex + 1 | ||
|
|
||
| val invokeVirtualIndex = it.method.indexOfFirstInstructionOrThrow( | ||
| relativeIndex, Opcode.INVOKE_VIRTUAL | ||
| ) | ||
| val colorMathPlayerInvokeVirtualReference = it.method | ||
| .getInstruction<ReferenceInstruction>(invokeVirtualIndex).reference | ||
|
|
||
| val iGetIndex = it.method.indexOfFirstInstructionOrThrow( | ||
| relativeIndex, Opcode.IGET | ||
| ) | ||
| val colorMathPlayerIGetReference = it.method | ||
| .getInstruction<ReferenceInstruction>(iGetIndex).reference as FieldReference | ||
|
|
||
| val colorGreyIndex = miniPlayerConstructorFingerprint.method.indexOfFirstInstructionReversedOrThrow { | ||
| getReference<MethodReference>()?.name == "getColor" | ||
| } | ||
| val iPutIndex = miniPlayerConstructorFingerprint.method.indexOfFirstInstructionOrThrow( | ||
| colorGreyIndex, Opcode.IPUT | ||
| ) | ||
| val colorMathPlayerIPutReference = miniPlayerConstructorFingerprint.method | ||
| .getInstruction<ReferenceInstruction>(iPutIndex).reference | ||
|
|
||
| miniPlayerConstructorFingerprint.classDef.methods.single { method -> | ||
| method.accessFlags == AccessFlags.PUBLIC.value or AccessFlags.FINAL.value && | ||
| method.returnType == "V" && | ||
| method.parameters == it.originalMethod.parameters | ||
| }.apply { | ||
| val invokeDirectIndex = indexOfFirstInstructionReversedOrThrow(Opcode.INVOKE_DIRECT) | ||
|
|
||
| val insertIndex = invokeDirectIndex + 1 | ||
| val freeRegister = findFreeRegister(insertIndex) | ||
|
|
||
| addInstructionsAtControlFlowLabel( | ||
| insertIndex, | ||
| """ | ||
| invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->changeMiniplayerColor()Z | ||
| move-result v$freeRegister | ||
| if-eqz v$freeRegister, :off | ||
| invoke-virtual { p1 }, $colorMathPlayerInvokeVirtualReference | ||
| move-result-object v$freeRegister | ||
| check-cast v$freeRegister, ${colorMathPlayerIGetReference.definingClass} | ||
| iget v$freeRegister, v$freeRegister, $colorMathPlayerIGetReference | ||
| iput v$freeRegister, p0, $colorMathPlayerIPutReference | ||
| :off | ||
| nop | ||
| """ | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
27 changes: 27 additions & 0 deletions
27
patches/src/main/kotlin/app/revanced/patches/music/layout/miniplayercolor/Fingerprints.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package app.revanced.patches.music.layout.miniplayercolor | ||
|
|
||
| import app.revanced.patcher.fingerprint | ||
| import app.revanced.util.literal | ||
| import com.android.tools.smali.dexlib2.AccessFlags | ||
| import com.android.tools.smali.dexlib2.Opcode | ||
|
|
||
| internal val miniPlayerConstructorFingerprint = fingerprint { | ||
| returns("V") | ||
| strings("sharedToggleMenuItemMutations") | ||
| literal { mpp_player_bottom_sheet } | ||
| } | ||
|
|
||
| /** | ||
| * Matches to the class found in [miniPlayerConstructorFingerprint]. | ||
| */ | ||
| internal val switchToggleColorFingerprint = fingerprint { | ||
| accessFlags(AccessFlags.PRIVATE, AccessFlags.FINAL) | ||
| returns("V") | ||
| parameters("L", "J") | ||
| opcodes( | ||
| Opcode.INVOKE_VIRTUAL, | ||
| Opcode.MOVE_RESULT_OBJECT, | ||
| Opcode.CHECK_CAST, | ||
| Opcode.IGET | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.