mirror of
https://github.com/revanced/revanced-patches
synced 2025-01-06 02:26:02 +01:00
feat: set the correct theme of the settings screen
This commit is contained in:
parent
36a2ae886c
commit
70d850cf29
@ -0,0 +1,29 @@
|
|||||||
|
package app.revanced.patches.youtube.misc.settings.bytecode.fingerprints
|
||||||
|
|
||||||
|
import app.revanced.patcher.annotation.Name
|
||||||
|
import app.revanced.patcher.annotation.Version
|
||||||
|
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod
|
||||||
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
|
import app.revanced.patches.youtube.layout.returnyoutubedislike.annotations.ReturnYouTubeDislikeCompatibility
|
||||||
|
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
||||||
|
import org.jf.dexlib2.Opcode
|
||||||
|
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
|
||||||
|
|
||||||
|
@Name("theme-setter-fingerprint")
|
||||||
|
@MatchingMethod(
|
||||||
|
"Lfyq;", "a"
|
||||||
|
)
|
||||||
|
@ReturnYouTubeDislikeCompatibility
|
||||||
|
@Version("0.0.1")
|
||||||
|
object ThemeSetterFingerprint : MethodFingerprint(
|
||||||
|
"L",
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
listOf(Opcode.RETURN_OBJECT),
|
||||||
|
null,
|
||||||
|
{ methodDef ->
|
||||||
|
methodDef.implementation?.instructions?.any {
|
||||||
|
it.opcode.ordinal == Opcode.CONST.ordinal && (it as WideLiteralInstruction).wideLiteral == SettingsPatch.appearanceStringId
|
||||||
|
} == true
|
||||||
|
}
|
||||||
|
)
|
@ -11,10 +11,13 @@ import app.revanced.patcher.patch.PatchResultSuccess
|
|||||||
import app.revanced.patcher.patch.annotations.Dependencies
|
import app.revanced.patcher.patch.annotations.Dependencies
|
||||||
import app.revanced.patcher.patch.annotations.Patch
|
import app.revanced.patcher.patch.annotations.Patch
|
||||||
import app.revanced.patcher.patch.impl.BytecodePatch
|
import app.revanced.patcher.patch.impl.BytecodePatch
|
||||||
|
import app.revanced.patcher.util.smali.toInstruction
|
||||||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
||||||
|
import app.revanced.patches.youtube.misc.mapping.patch.ResourceIdMappingProviderResourcePatch
|
||||||
import app.revanced.patches.youtube.misc.settings.annotations.SettingsCompatibility
|
import app.revanced.patches.youtube.misc.settings.annotations.SettingsCompatibility
|
||||||
import app.revanced.patches.youtube.misc.settings.bytecode.fingerprints.LicenseActivityFingerprint
|
import app.revanced.patches.youtube.misc.settings.bytecode.fingerprints.LicenseActivityFingerprint
|
||||||
import app.revanced.patches.youtube.misc.settings.bytecode.fingerprints.ReVancedSettingsActivityFingerprint
|
import app.revanced.patches.youtube.misc.settings.bytecode.fingerprints.ReVancedSettingsActivityFingerprint
|
||||||
|
import app.revanced.patches.youtube.misc.settings.bytecode.fingerprints.ThemeSetterFingerprint
|
||||||
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsResourcePatch
|
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsResourcePatch
|
||||||
|
|
||||||
@Patch
|
@Patch
|
||||||
@ -24,11 +27,12 @@ import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsResourc
|
|||||||
@SettingsCompatibility
|
@SettingsCompatibility
|
||||||
@Version("0.0.1")
|
@Version("0.0.1")
|
||||||
class SettingsPatch : BytecodePatch(
|
class SettingsPatch : BytecodePatch(
|
||||||
listOf(LicenseActivityFingerprint, ReVancedSettingsActivityFingerprint)
|
listOf(LicenseActivityFingerprint, ReVancedSettingsActivityFingerprint, ThemeSetterFingerprint)
|
||||||
) {
|
) {
|
||||||
override fun execute(data: BytecodeData): PatchResult {
|
override fun execute(data: BytecodeData): PatchResult {
|
||||||
val licenseActivityResult = LicenseActivityFingerprint.result!!
|
val licenseActivityResult = LicenseActivityFingerprint.result!!
|
||||||
val settingsResult = ReVancedSettingsActivityFingerprint.result!!
|
val settingsResult = ReVancedSettingsActivityFingerprint.result!!
|
||||||
|
val themeSetterResult = ThemeSetterFingerprint.result!!
|
||||||
|
|
||||||
val licenseActivityClass = licenseActivityResult.mutableClass
|
val licenseActivityClass = licenseActivityResult.mutableClass
|
||||||
val settingsClass = settingsResult.mutableClass
|
val settingsClass = settingsResult.mutableClass
|
||||||
@ -37,7 +41,25 @@ class SettingsPatch : BytecodePatch(
|
|||||||
val setThemeMethodName = "setTheme"
|
val setThemeMethodName = "setTheme"
|
||||||
val initializeSettings = settingsResult.mutableMethod
|
val initializeSettings = settingsResult.mutableMethod
|
||||||
|
|
||||||
// First add the setTheme call to the onCreate method to not affect the offsets.
|
val setThemeInstruction =
|
||||||
|
"invoke-static {v0}, Lapp/revanced/integrations/utils/ThemeHelper;->setTheme(Ljava/lang/Object;)V".toInstruction(
|
||||||
|
themeSetterResult.mutableMethod
|
||||||
|
)
|
||||||
|
|
||||||
|
// add instructions to set the theme of the settings activity
|
||||||
|
themeSetterResult.mutableMethod.implementation!!.let {
|
||||||
|
it.addInstruction(
|
||||||
|
themeSetterResult.patternScanResult!!.startIndex,
|
||||||
|
setThemeInstruction
|
||||||
|
)
|
||||||
|
|
||||||
|
it.addInstruction(
|
||||||
|
it.instructions.size - 1, // add before return
|
||||||
|
setThemeInstruction
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// add the setTheme call to the onCreate method to not affect the offsets.
|
||||||
onCreate.addInstructions(
|
onCreate.addInstructions(
|
||||||
1,
|
1,
|
||||||
"""
|
"""
|
||||||
@ -46,11 +68,18 @@ class SettingsPatch : BytecodePatch(
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add the initializeSettings call to the onCreate method.
|
// add the initializeSettings call to the onCreate method.
|
||||||
onCreate.addInstruction(
|
onCreate.addInstruction(
|
||||||
0,
|
0,
|
||||||
"invoke-static { p0 }, ${settingsClass.type}->$setThemeMethodName(${licenseActivityClass.type})V"
|
"invoke-static { p0 }, ${settingsClass.type}->$setThemeMethodName(${licenseActivityClass.type})V"
|
||||||
)
|
)
|
||||||
|
|
||||||
return PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal companion object {
|
||||||
|
val appearanceStringId = ResourceIdMappingProviderResourcePatch.resourceMappings.find {
|
||||||
|
it.type == "string" && it.name == "app_theme_appearance_dark"
|
||||||
|
}!!.id
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user