2022-07-31 12:15:26 +02:00
|
|
|
package app.revanced.patches.youtube.misc.settings.bytecode.patch
|
|
|
|
|
|
|
|
import app.revanced.patcher.annotation.Description
|
|
|
|
import app.revanced.patcher.annotation.Name
|
|
|
|
import app.revanced.patcher.annotation.Version
|
|
|
|
import app.revanced.patcher.data.impl.BytecodeData
|
|
|
|
import app.revanced.patcher.extensions.addInstruction
|
|
|
|
import app.revanced.patcher.extensions.addInstructions
|
|
|
|
import app.revanced.patcher.patch.PatchResult
|
|
|
|
import app.revanced.patcher.patch.PatchResultSuccess
|
|
|
|
import app.revanced.patcher.patch.annotations.Dependencies
|
|
|
|
import app.revanced.patcher.patch.annotations.Patch
|
|
|
|
import app.revanced.patcher.patch.impl.BytecodePatch
|
2022-08-03 03:09:52 +02:00
|
|
|
import app.revanced.patcher.util.smali.toInstruction
|
2022-07-31 12:15:26 +02:00
|
|
|
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
2022-08-03 03:09:52 +02:00
|
|
|
import app.revanced.patches.youtube.misc.mapping.patch.ResourceIdMappingProviderResourcePatch
|
2022-07-31 12:15:26 +02:00
|
|
|
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.ReVancedSettingsActivityFingerprint
|
2022-08-03 03:09:52 +02:00
|
|
|
import app.revanced.patches.youtube.misc.settings.bytecode.fingerprints.ThemeSetterFingerprint
|
2022-07-31 12:15:26 +02:00
|
|
|
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsResourcePatch
|
|
|
|
|
|
|
|
@Patch
|
2022-08-03 03:07:49 +02:00
|
|
|
@Dependencies([IntegrationsPatch::class, SettingsResourcePatch::class, ResourceIdMappingProviderResourcePatch::class])
|
2022-07-31 12:15:26 +02:00
|
|
|
@Name("settings")
|
|
|
|
@Description("Adds settings for ReVanced to YouTube.")
|
|
|
|
@SettingsCompatibility
|
|
|
|
@Version("0.0.1")
|
|
|
|
class SettingsPatch : BytecodePatch(
|
2022-08-03 03:09:52 +02:00
|
|
|
listOf(LicenseActivityFingerprint, ReVancedSettingsActivityFingerprint, ThemeSetterFingerprint)
|
2022-07-31 12:15:26 +02:00
|
|
|
) {
|
|
|
|
override fun execute(data: BytecodeData): PatchResult {
|
|
|
|
val licenseActivityResult = LicenseActivityFingerprint.result!!
|
|
|
|
val settingsResult = ReVancedSettingsActivityFingerprint.result!!
|
2022-08-03 03:09:52 +02:00
|
|
|
val themeSetterResult = ThemeSetterFingerprint.result!!
|
2022-07-31 12:15:26 +02:00
|
|
|
|
|
|
|
val licenseActivityClass = licenseActivityResult.mutableClass
|
|
|
|
val settingsClass = settingsResult.mutableClass
|
|
|
|
|
|
|
|
val onCreate = licenseActivityResult.mutableMethod
|
|
|
|
val setThemeMethodName = "setTheme"
|
|
|
|
val initializeSettings = settingsResult.mutableMethod
|
|
|
|
|
2022-08-03 03:09:52 +02:00
|
|
|
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.
|
2022-07-31 12:15:26 +02:00
|
|
|
onCreate.addInstructions(
|
|
|
|
1,
|
|
|
|
"""
|
|
|
|
invoke-static { p0 }, ${settingsClass.type}->${initializeSettings.name}(${licenseActivityClass.type})V
|
|
|
|
return-void
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
2022-08-03 03:09:52 +02:00
|
|
|
// add the initializeSettings call to the onCreate method.
|
2022-07-31 12:15:26 +02:00
|
|
|
onCreate.addInstruction(
|
|
|
|
0,
|
|
|
|
"invoke-static { p0 }, ${settingsClass.type}->$setThemeMethodName(${licenseActivityClass.type})V"
|
|
|
|
)
|
2022-08-03 03:09:52 +02:00
|
|
|
|
2022-07-31 12:15:26 +02:00
|
|
|
return PatchResultSuccess()
|
|
|
|
}
|
2022-08-03 03:09:52 +02:00
|
|
|
|
|
|
|
internal companion object {
|
|
|
|
val appearanceStringId = ResourceIdMappingProviderResourcePatch.resourceMappings.find {
|
|
|
|
it.type == "string" && it.name == "app_theme_appearance_dark"
|
|
|
|
}!!.id
|
|
|
|
}
|
2022-07-31 12:15:26 +02:00
|
|
|
}
|