generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(youtube/theme): change seekbar color via preference
- Loading branch information
Showing
5 changed files
with
153 additions
and
63 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...d/patches/youtube/layout/theme/bytecode/fingerprints/CreateDarkThemeSeekbarFingerprint.kt
This file contains 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,25 @@ | ||
package app.revanced.patches.youtube.layout.theme.bytecode.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patches.youtube.layout.theme.bytecode.fingerprints.CreateDarkThemeSeekbarFingerprint.indexOfInstructionWithSeekbarId | ||
import app.revanced.patches.youtube.layout.theme.resource.ThemeResourcePatch | ||
import org.jf.dexlib2.AccessFlags | ||
import org.jf.dexlib2.Opcode | ||
import org.jf.dexlib2.iface.Method | ||
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction | ||
|
||
object CreateDarkThemeSeekbarFingerprint : MethodFingerprint( | ||
access = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, | ||
customFingerprint = { method -> method.indexOfInstructionWithSeekbarId != -1 }, | ||
) { | ||
/** | ||
* The index of the instruction that loads the resource id of the seekbar. | ||
*/ | ||
internal val Method.indexOfInstructionWithSeekbarId | ||
get() = implementation?.let { | ||
it.instructions.indexOfFirst { instruction -> | ||
instruction.opcode == Opcode.CONST && (instruction as WideLiteralInstruction).wideLiteral == ThemeResourcePatch.inlineTimeBarColorizedBarPlayedColorDarkId | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...ain/kotlin/app/revanced/patches/youtube/layout/theme/bytecode/patch/ThemeBytecodePatch.kt
This file contains 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,51 @@ | ||
package app.revanced.patches.youtube.layout.theme.bytecode.patch | ||
|
||
import app.revanced.extensions.toErrorResult | ||
import app.revanced.patcher.annotation.Description | ||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.addInstructions | ||
import app.revanced.patcher.extensions.instruction | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patcher.patch.annotations.DependsOn | ||
import app.revanced.patcher.patch.annotations.Patch | ||
import app.revanced.patches.youtube.layout.theme.annotations.ThemeCompatibility | ||
import app.revanced.patches.youtube.layout.theme.bytecode.fingerprints.CreateDarkThemeSeekbarFingerprint | ||
import app.revanced.patches.youtube.layout.theme.bytecode.fingerprints.CreateDarkThemeSeekbarFingerprint.indexOfInstructionWithSeekbarId | ||
import app.revanced.patches.youtube.layout.theme.resource.ThemeResourcePatch | ||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch | ||
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction | ||
|
||
@Patch | ||
@Name("theme") | ||
@Description("Applies a custom theme.") | ||
@DependsOn([ThemeLithoComponentsPatch::class, ThemeResourcePatch::class, IntegrationsPatch::class]) | ||
@ThemeCompatibility | ||
@Version("0.0.1") | ||
class ThemeBytecodePatch : BytecodePatch(listOf(CreateDarkThemeSeekbarFingerprint)) { | ||
override fun execute(context: BytecodeContext): PatchResult { | ||
CreateDarkThemeSeekbarFingerprint.result?.let { | ||
val putColorValueIndex = it.method.indexOfInstructionWithSeekbarId!! + 3 | ||
|
||
it.mutableMethod.apply { | ||
val overrideRegister = (instruction(putColorValueIndex) as TwoRegisterInstruction).registerA | ||
|
||
addInstructions( | ||
putColorValueIndex, | ||
""" | ||
invoke-static { }, $INTEGRATIONS_CLASS_DESCRIPTOR->getSeekbarColorValue()I | ||
move-result v$overrideRegister | ||
""" | ||
) | ||
} | ||
} ?: return CreateDarkThemeSeekbarFingerprint.toErrorResult() | ||
return PatchResultSuccess() | ||
} | ||
|
||
private companion object { | ||
private const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/theme/ThemePatch;" | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...lin/app/revanced/patches/youtube/layout/theme/bytecode/patch/ThemeLithoComponentsPatch.kt
This file contains 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,40 @@ | ||
package app.revanced.patches.youtube.layout.theme.bytecode.patch | ||
|
||
import app.revanced.extensions.toErrorResult | ||
import app.revanced.patcher.annotation.Description | ||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.addInstructions | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patches.youtube.layout.theme.annotations.ThemeCompatibility | ||
import app.revanced.patches.youtube.layout.theme.fingerprints.LithoThemeFingerprint | ||
|
||
@Name("theme-litho-components") | ||
@Description("Applies a custom theme to Litho components.") | ||
@ThemeCompatibility | ||
@Version("0.0.1") | ||
class ThemeLithoComponentsPatch : BytecodePatch(listOf(LithoThemeFingerprint)) { | ||
override fun execute(context: BytecodeContext): PatchResult { | ||
LithoThemeFingerprint.result?.let { | ||
it.mutableMethod.apply { | ||
val patchIndex = it.scanResult.patternScanResult!!.endIndex - 1 | ||
|
||
addInstructions( | ||
patchIndex, | ||
""" | ||
invoke-static {p1}, $INTEGRATIONS_CLASS_DESCRIPTOR->getValue(I)I | ||
move-result p1 | ||
""" | ||
) | ||
} | ||
} ?: return LithoThemeFingerprint.toErrorResult() | ||
return PatchResultSuccess() | ||
} | ||
|
||
private companion object { | ||
private const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/theme/ThemeLithoComponentsPatch;" | ||
} | ||
} |
36 changes: 0 additions & 36 deletions
36
src/main/kotlin/app/revanced/patches/youtube/layout/theme/patch/LithoThemePatch.kt
This file was deleted.
Oops, something went wrong.
This file contains 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