Skip to content

Commit

Permalink
feat: settings patch
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Jul 31, 2022
1 parent b3d8dc2 commit 0e229a4
Show file tree
Hide file tree
Showing 19 changed files with 646 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
import app.revanced.patches.youtube.misc.playeroverlay.patch.PlayerOverlaysHookPatch
import app.revanced.patches.youtube.misc.playertype.patch.PlayerTypeHookPatch

@Patch(include = false)
@Patch
@Name("swipe-controls")
@Description("Adds volume and brightness swipe controls.")
@SwipeControlsCompatibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import app.revanced.patches.youtube.layout.widesearchbar.fingerprints.WideSearch
import app.revanced.patches.youtube.layout.widesearchbar.fingerprints.WideSearchbarTwoParentFingerprint
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch

@Patch(include = false)
@Patch
@Dependencies([IntegrationsPatch::class])
@Name("enable-wide-searchbar")
@Description("Replaces the search icon with a wide search bar. This will hide the YouTube logo when active.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import app.revanced.patches.youtube.misc.autorepeat.fingerprints.AutoRepeatFinge
import app.revanced.patches.youtube.misc.autorepeat.fingerprints.AutoRepeatParentFingerprint
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch

@Patch(include = false)
@Patch
@Dependencies([IntegrationsPatch::class])
@Name("always-autorepeat")
@Description("Always repeats the playing video again.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.reference.FieldReference

@Patch(include = false)
@Patch
@Dependencies([IntegrationsPatch::class])
@Name("force-vp9-codec")
@Description("Forces the VP9 codec for videos.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
import org.jf.dexlib2.iface.reference.FieldReference

@Patch(false)
@Patch
@Name("hdr-auto-brightness")
@Description("Makes the brightness of HDR videos follow the system default.")
@HDRBrightnessCompatibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import app.revanced.patches.youtube.misc.microg.annotations.MicroGPatchCompatibi
import app.revanced.patches.youtube.misc.microg.shared.Constants.BASE_MICROG_PACKAGE_NAME
import app.revanced.patches.youtube.misc.microg.shared.Constants.REVANCED_APP_NAME
import app.revanced.patches.youtube.misc.microg.shared.Constants.REVANCED_PACKAGE_NAME
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsResourcePatch

@Name("microg-resource-patch")
@Dependencies([FixLocaleConfigErrorPatch::class])
@Dependencies([FixLocaleConfigErrorPatch::class, SettingsResourcePatch::class])
@Description("Resource patch to allow YouTube ReVanced to run without root and under a different package name.")
@MicroGPatchCompatibility
@Version("0.0.1")
Expand All @@ -27,12 +28,18 @@ class MicroGResourcePatch : ResourcePatch() {
settingsElementIntent.setAttribute("android:targetClass", "org.microg.gms.ui.SettingsActivity")

val settingsElement = it.file.createElement("Preference")
settingsElement.setAttribute("android:title", "MicroG")
settingsElement.setAttribute("android:title", "@string/microg_settings")
settingsElement.appendChild(settingsElementIntent)

it.file.firstChild.appendChild(settingsElement)
}

val settings_fragment = data.get("res/xml/settings_fragment.xml")
val text = settings_fragment.readText()
settings_fragment.writeText(
text.replace("android:targetPackage=\"com.google.android.youtube", "android:targetPackage=\"$REVANCED_PACKAGE_NAME")
)

val manifest = data.get("AndroidManifest.xml").readText()

data.get("AndroidManifest.xml").writeText(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package app.revanced.patches.youtube.misc.settings.annotations

import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Package

@Compatibility(
[Package(
"com.google.android.youtube", arrayOf()
)]
)
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
internal annotation class SettingsCompatibility
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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.FuzzyPatternScanMethod
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

// TODO: This is more of a class fingerprint than a method fingerprint.
// Convert to a class fingerprint whenever possible.
@Name("license-activity-fingerprint")
@MatchingMethod(
"Lcom/google/android/libraries/social/licenses/LicenseActivity;", "onCreate"
)
@FuzzyPatternScanMethod(2)
@ReturnYouTubeDislikeCompatibility
@Version("0.0.2")
object LicenseActivityFingerprint : MethodFingerprint(
null,
null,
null,
null,
null,
{ methodDef ->
methodDef.definingClass.endsWith("LicenseActivity;") && methodDef.name == "onCreate"
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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.FuzzyPatternScanMethod
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

// TODO: This is more of a class fingerprint than a method fingerprint.
// Convert to a class fingerprint whenever possible.
@Name("revanced-settings-activity-fingerprint")
@MatchingMethod(
"Lapp/revanced/integrations/settingsmenu/ReVancedSettingActivity;", "initializeSettings"
)
@FuzzyPatternScanMethod(2)
@ReturnYouTubeDislikeCompatibility
@Version("0.0.2")
object ReVancedSettingsActivityFingerprint : MethodFingerprint(
null,
null,
null,
null,
null,
{ methodDef ->
methodDef.definingClass.endsWith("ReVancedSettingActivity;") && methodDef.name == "initializeSettings"
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
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
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsResourcePatch

@Patch
@Dependencies([IntegrationsPatch::class, SettingsResourcePatch::class])
@Name("settings")
@Description("Adds settings for ReVanced to YouTube.")
@SettingsCompatibility
@Version("0.0.1")
class SettingsPatch : BytecodePatch(
listOf(LicenseActivityFingerprint, ReVancedSettingsActivityFingerprint)
) {
override fun execute(data: BytecodeData): PatchResult {
val licenseActivityResult = LicenseActivityFingerprint.result!!
val settingsResult = ReVancedSettingsActivityFingerprint.result!!

val licenseActivityClass = licenseActivityResult.mutableClass
val settingsClass = settingsResult.mutableClass

val onCreate = licenseActivityResult.mutableMethod
val setThemeMethodName = "setTheme"
val initializeSettings = settingsResult.mutableMethod

// First add the setTheme call to the onCreate method to not affect the offsets.
onCreate.addInstructions(
1,
"""
invoke-static { p0 }, ${settingsClass.type}->${initializeSettings.name}(${licenseActivityClass.type})V
return-void
"""
)

// Add the initializeSettings call to the onCreate method.
onCreate.addInstruction(
0,
"invoke-static { p0 }, ${settingsClass.type}->$setThemeMethodName(${licenseActivityClass.type})V"
)
return PatchResultSuccess()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package app.revanced.patches.youtube.misc.settings.resource.patch

import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.impl.ResourceData
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.Dependencies
import app.revanced.patcher.patch.impl.ResourcePatch
import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch
import app.revanced.patches.youtube.misc.settings.annotations.SettingsCompatibility
import app.revanced.util.resources.ResourceUtils
import app.revanced.util.resources.ResourceUtils.copyResources
import app.revanced.util.resources.ResourceUtils.copyXmlNode

@Name("settings-resource-patch")
@SettingsCompatibility
@Dependencies([FixLocaleConfigErrorPatch::class])
@Version("0.0.1")
class SettingsResourcePatch : ResourcePatch() {
override fun execute(data: ResourceData): PatchResult {
/*
* Copy strings
*/

data.copyXmlNode("settings/host", "values/strings.xml", "resources")

/*
* Copy arrays
*/

data.copyXmlNode("settings/host", "values/arrays.xml", "resources")

/*
* Copy preference fragments
*/

data.copyXmlNode("settings/host", "xml/settings_fragment.xml", "PreferenceScreen")

/*
* Copy layout resources
*/
arrayOf(
ResourceUtils.ResourceGroup(
"layout",
"xsettings_toolbar.xml",
"xsettings_with_toolbar.xml",
"xsettings_with_toolbar_layout.xml"
),
ResourceUtils.ResourceGroup(
"xml",
"revanced_prefs.xml"
)
).forEach { resourceGroup ->
data.copyResources("settings", resourceGroup)
}

return PatchResultSuccess()
}
}
14 changes: 14 additions & 0 deletions src/main/resources/settings/host/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<resources>
<string-array name="revanced_button_location_entries">
<item>@string/revanced_button_location_entry_none</item>
<item>@string/revanced_button_location_entry_player</item>
<item>@string/revanced_button_location_entry_buttoncontainer</item>
<item>@string/revanced_button_location_entry_both</item>
</string-array>
<string-array name="revanced_button_location_entry_values">
<item>NONE</item>
<item>PLAYER</item>
<item>BUTTON_CONTAINER</item>
<item>BOTH</item>
</string-array>
</resources>
Loading

0 comments on commit 0e229a4

Please sign in to comment.