generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
416 additions
and
61 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
...n/app/revanced/patches/youtube/interaction/downloads/annotation/DownloadsCompatibility.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,14 @@ | ||
package app.revanced.patches.youtube.interaction.downloads.annotation | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
@Compatibility( | ||
[Package( | ||
"com.google.android.youtube", arrayOf("17.27.39", "17.32.35") | ||
)] | ||
) | ||
@Target(AnnotationTarget.CLASS) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
internal annotation class DownloadsCompatibility | ||
|
52 changes: 52 additions & 0 deletions
52
...p/revanced/patches/youtube/interaction/downloads/bytecode/patch/DownloadsBytecodePatch.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,52 @@ | ||
package app.revanced.patches.youtube.interaction.downloads.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.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.patcher.patch.impl.BytecodePatch | ||
import app.revanced.patches.youtube.interaction.downloads.annotation.DownloadsCompatibility | ||
import app.revanced.patches.youtube.interaction.downloads.resource.patch.DownloadsResourcePatch | ||
import app.revanced.patches.youtube.misc.playercontrols.bytecode.patch.PlayerControlsBytecodePatch | ||
import app.revanced.patches.youtube.misc.videoid.patch.VideoIdPatch | ||
|
||
@Patch | ||
@Name("downloads") | ||
@DependsOn([DownloadsResourcePatch::class, PlayerControlsBytecodePatch::class, VideoIdPatch::class]) | ||
@Description("Enables downloading music and videos from YouTube.") | ||
@DownloadsCompatibility | ||
@Version("0.0.1") | ||
class DownloadsBytecodePatch : BytecodePatch() { | ||
override fun execute(data: BytecodeData): PatchResult { | ||
val integrationsPackage = "app/revanced/integrations" | ||
val classDescriptor = "L$integrationsPackage/videoplayer/DownloadButton;" | ||
|
||
/* | ||
initialize the control | ||
*/ | ||
|
||
val initializeDownloadsDescriptor = "$classDescriptor->initializeDownloadButton(Ljava/lang/Object;)V" | ||
PlayerControlsBytecodePatch.initializeControl(initializeDownloadsDescriptor) | ||
|
||
/* | ||
add code to change the visibility of the control | ||
*/ | ||
|
||
val changeVisibilityDescriptor = "$classDescriptor->changeVisibility(Z)V" | ||
PlayerControlsBytecodePatch.injectVisibilityCheckCall(changeVisibilityDescriptor) | ||
|
||
/* | ||
add code to change to update the video id | ||
*/ | ||
|
||
val setVideoIdDescriptor = | ||
"L$integrationsPackage/patches/downloads/DownloadsPatch;->setVideoId(Ljava/lang/String;)V" | ||
VideoIdPatch.injectCall(setVideoIdDescriptor) | ||
|
||
return PatchResultSuccess() | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...p/revanced/patches/youtube/interaction/downloads/resource/patch/DownloadsResourcePatch.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,56 @@ | ||
package app.revanced.patches.youtube.interaction.downloads.resource.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.ResourceData | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patcher.patch.annotations.DependsOn | ||
import app.revanced.patcher.patch.impl.ResourcePatch | ||
import app.revanced.patches.youtube.interaction.downloads.annotation.DownloadsCompatibility | ||
import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch | ||
import app.revanced.patches.youtube.misc.playercontrols.resource.patch.BottomControlsResourcePatch | ||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch | ||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.StringResource | ||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.SwitchPreference | ||
import app.revanced.util.resources.ResourceUtils | ||
import app.revanced.util.resources.ResourceUtils.Settings.mergeStrings | ||
import app.revanced.util.resources.ResourceUtils.copyResources | ||
|
||
@Name("downloads-resource-patch") | ||
@DependsOn([BottomControlsResourcePatch::class, FixLocaleConfigErrorPatch::class, SettingsPatch::class]) | ||
@Description("Makes necessary changes to resources for the download button.") | ||
@DownloadsCompatibility | ||
@Version("0.0.1") | ||
class DownloadsResourcePatch : ResourcePatch() { | ||
override fun execute(data: ResourceData): PatchResult { | ||
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(SwitchPreference( | ||
"revanced_downloads", | ||
StringResource("revanced_downloads_enabled_title", "Show download button"), | ||
true, | ||
StringResource("revanced_downloads_enabled_summary_on", "Download button is visible"), | ||
StringResource("revanced_downloads_enabled_summary_off", "Download button is hidden") | ||
)) | ||
|
||
/* | ||
* Copy strings | ||
*/ | ||
|
||
data.mergeStrings("downloads/host/values/strings.xml") | ||
|
||
/* | ||
* Copy resources | ||
*/ | ||
|
||
data.copyResources("downloads", ResourceUtils.ResourceGroup("drawable", "revanced_yt_download_button.xml")) | ||
|
||
/* | ||
* Add download button node | ||
*/ | ||
|
||
BottomControlsResourcePatch.addControls("downloads/host/layout/${BottomControlsResourcePatch.TARGET_RESOURCE_NAME}") | ||
|
||
return PatchResultSuccess() | ||
} | ||
} |
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
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
19 changes: 0 additions & 19 deletions
19
...atches/youtube/layout/sponsorblock/bytecode/fingerprints/ShowPlayerControlsFingerprint.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
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
13 changes: 13 additions & 0 deletions
13
...pp/revanced/patches/youtube/misc/playercontrols/annotation/PlayerControlsCompatibility.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,13 @@ | ||
package app.revanced.patches.youtube.misc.playercontrols.annotation | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
@Compatibility( | ||
[Package( | ||
"com.google.android.youtube", arrayOf("17.27.39", "17.32.35") | ||
)] | ||
) | ||
@Target(AnnotationTarget.CLASS) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
internal annotation class PlayerControlsCompatibility |
83 changes: 83 additions & 0 deletions
83
...evanced/patches/youtube/misc/playercontrols/bytecode/patch/PlayerControlsBytecodePatch.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,83 @@ | ||
package app.revanced.patches.youtube.misc.playercontrols.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.fingerprint.method.impl.MethodFingerprintResult | ||
import app.revanced.patcher.fingerprint.method.utils.MethodFingerprintUtils.resolve | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patcher.patch.annotations.DependsOn | ||
import app.revanced.patcher.patch.impl.BytecodePatch | ||
import app.revanced.patches.youtube.misc.mapping.patch.ResourceIdMappingProviderResourcePatch | ||
import app.revanced.patches.youtube.misc.playercontrols.annotation.PlayerControlsCompatibility | ||
import app.revanced.patches.youtube.misc.playercontrols.fingerprints.BottomControlsInflateFingerprint | ||
import app.revanced.patches.youtube.misc.playercontrols.fingerprints.PlayerControlsVisibilityFingerprint | ||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction | ||
|
||
@Name("player-controls-bytecode-patch") | ||
@DependsOn([ResourceIdMappingProviderResourcePatch::class]) | ||
@Description("Manages the code for the player controls of the YouTube player.") | ||
@PlayerControlsCompatibility | ||
@Version("0.0.1") | ||
class PlayerControlsBytecodePatch : BytecodePatch( | ||
listOf(PlayerControlsVisibilityFingerprint) | ||
) { | ||
override fun execute(data: BytecodeData): PatchResult { | ||
showPlayerControlsFingerprintResult = PlayerControlsVisibilityFingerprint.result!! | ||
|
||
bottomUiContainerResourceId = ResourceIdMappingProviderResourcePatch | ||
.resourceMappings | ||
.single { it.type == "id" && it.name == "bottom_ui_container_stub" }.id | ||
|
||
// TODO: another solution is required, this is hacky | ||
listOf(BottomControlsInflateFingerprint).resolve(data, data.classes) | ||
inflateFingerprintResult = BottomControlsInflateFingerprint.result!! | ||
|
||
return PatchResultSuccess() | ||
} | ||
|
||
internal companion object { | ||
var bottomUiContainerResourceId: Long = 0 | ||
|
||
lateinit var showPlayerControlsFingerprintResult: MethodFingerprintResult | ||
|
||
private var inflateFingerprintResult: MethodFingerprintResult? = null | ||
set(fingerprint) { | ||
field = fingerprint!!.also { | ||
moveToRegisterInstructionIndex = it.patternScanResult!!.endIndex | ||
viewRegister = | ||
(it.mutableMethod.implementation!!.instructions[moveToRegisterInstructionIndex] as OneRegisterInstruction).registerA | ||
} | ||
} | ||
|
||
private var moveToRegisterInstructionIndex: Int = 0 | ||
private var viewRegister: Int = 0 | ||
|
||
/** | ||
* Injects the code to change the visibility of controls. | ||
* @param descriptor The descriptor of the method which should be called. | ||
*/ | ||
fun injectVisibilityCheckCall(descriptor: String) { | ||
showPlayerControlsFingerprintResult.mutableMethod.addInstruction( | ||
0, | ||
""" | ||
invoke-static {p1}, $descriptor | ||
""" | ||
) | ||
} | ||
|
||
/** | ||
* Injects the code to initialize the controls. | ||
* @param descriptor The descriptor of the method which should be calleed. | ||
*/ | ||
fun initializeControl(descriptor: String) { | ||
inflateFingerprintResult!!.mutableMethod.addInstruction( | ||
moveToRegisterInstructionIndex + 1, | ||
"invoke-static {v$viewRegister}, $descriptor" | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.