2022-08-22 01:59:43 +02:00
|
|
|
package app.revanced.patches.youtube.misc.minimizedplayback.patch
|
2022-05-18 23:58:54 +02:00
|
|
|
|
|
|
|
import app.revanced.patcher.annotation.Description
|
|
|
|
import app.revanced.patcher.annotation.Name
|
|
|
|
import app.revanced.patcher.annotation.Version
|
2022-10-05 04:03:10 +02:00
|
|
|
import app.revanced.patcher.data.BytecodeContext
|
|
|
|
import app.revanced.patcher.data.toMethodWalker
|
2022-07-05 19:45:46 +02:00
|
|
|
import app.revanced.patcher.extensions.addInstructions
|
2022-10-05 04:03:10 +02:00
|
|
|
import app.revanced.patcher.patch.BytecodePatch
|
2022-06-26 15:15:59 +02:00
|
|
|
import app.revanced.patcher.patch.PatchResult
|
|
|
|
import app.revanced.patcher.patch.PatchResultSuccess
|
2022-08-03 03:53:35 +02:00
|
|
|
import app.revanced.patcher.patch.annotations.DependsOn
|
2022-07-05 19:45:46 +02:00
|
|
|
import app.revanced.patcher.patch.annotations.Patch
|
|
|
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
2022-10-05 04:03:10 +02:00
|
|
|
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
2022-08-22 01:59:43 +02:00
|
|
|
import app.revanced.patches.youtube.misc.minimizedplayback.annotations.MinimizedPlaybackCompatibility
|
|
|
|
import app.revanced.patches.youtube.misc.minimizedplayback.fingerprints.MinimizedPlaybackKidsFingerprint
|
|
|
|
import app.revanced.patches.youtube.misc.minimizedplayback.fingerprints.MinimizedPlaybackManagerFingerprint
|
|
|
|
import app.revanced.patches.youtube.misc.minimizedplayback.fingerprints.MinimizedPlaybackSettingsFingerprint
|
|
|
|
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
2022-11-28 20:13:34 +01:00
|
|
|
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
|
|
|
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
|
2022-07-05 19:45:46 +02:00
|
|
|
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
|
|
|
|
import org.jf.dexlib2.iface.reference.MethodReference
|
2022-05-18 23:58:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Patch
|
|
|
|
@Name("minimized-playback")
|
2022-07-08 06:30:59 +02:00
|
|
|
@Description("Enables minimized and background playback.")
|
2022-08-22 01:59:43 +02:00
|
|
|
@DependsOn([IntegrationsPatch::class, SettingsPatch::class])
|
2022-05-18 23:58:54 +02:00
|
|
|
@MinimizedPlaybackCompatibility
|
|
|
|
@Version("0.0.1")
|
|
|
|
class MinimizedPlaybackPatch : BytecodePatch(
|
|
|
|
listOf(
|
2022-07-18 16:29:51 +02:00
|
|
|
MinimizedPlaybackKidsFingerprint, MinimizedPlaybackManagerFingerprint, MinimizedPlaybackSettingsFingerprint
|
2022-05-18 23:58:54 +02:00
|
|
|
)
|
|
|
|
) {
|
2022-10-05 04:03:10 +02:00
|
|
|
override fun execute(context: BytecodeContext): PatchResult {
|
2022-08-22 01:59:43 +02:00
|
|
|
SettingsPatch.PreferenceScreen.MISC.addPreferences(
|
|
|
|
SwitchPreference(
|
|
|
|
"revanced_enable_minimized_playback",
|
|
|
|
StringResource("revanced_minimized_playback_enabled_title", "Enable minimized playback"),
|
|
|
|
true,
|
|
|
|
StringResource("revanced_minimized_playback_summary_on", "Minimized playback is enabled"),
|
|
|
|
StringResource("revanced_minimized_playback_summary_off", "Minimized playback is disabled")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2022-05-18 23:58:54 +02:00
|
|
|
// Instead of removing all instructions like Vanced,
|
|
|
|
// we return the method at the beginning instead
|
2022-06-26 15:15:59 +02:00
|
|
|
MinimizedPlaybackManagerFingerprint.result!!.mutableMethod.addInstructions(
|
2022-05-18 23:58:54 +02:00
|
|
|
0, """
|
2022-07-18 22:59:21 +02:00
|
|
|
invoke-static {}, Lapp/revanced/integrations/patches/MinimizedPlaybackPatch;->isMinimizedPlaybackEnabled()Z
|
|
|
|
move-result v0
|
2022-05-18 23:58:54 +02:00
|
|
|
return v0
|
2022-06-23 02:22:42 +02:00
|
|
|
"""
|
2022-05-18 23:58:54 +02:00
|
|
|
)
|
2022-07-05 19:45:46 +02:00
|
|
|
|
|
|
|
val method = MinimizedPlaybackSettingsFingerprint.result!!.mutableMethod
|
|
|
|
val booleanCalls = method.implementation!!.instructions.withIndex()
|
|
|
|
.filter { ((it.value as? ReferenceInstruction)?.reference as? MethodReference)?.returnType == "Z" }
|
|
|
|
|
|
|
|
val settingsBooleanIndex = booleanCalls.elementAt(1).index
|
|
|
|
val settingsBooleanMethod =
|
2022-10-05 04:03:10 +02:00
|
|
|
context.toMethodWalker(method).nextMethod(settingsBooleanIndex, true).getMethod() as MutableMethod
|
2022-07-05 19:45:46 +02:00
|
|
|
|
|
|
|
settingsBooleanMethod.addInstructions(
|
|
|
|
0, """
|
2022-07-18 22:59:21 +02:00
|
|
|
invoke-static {}, Lapp/revanced/integrations/patches/MinimizedPlaybackPatch;->isMinimizedPlaybackEnabled()Z
|
|
|
|
move-result v0
|
2022-07-05 19:45:46 +02:00
|
|
|
return v0
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
2022-07-18 16:29:51 +02:00
|
|
|
MinimizedPlaybackKidsFingerprint.result!!.mutableMethod.addInstructions(
|
|
|
|
0, """
|
2022-07-18 22:59:21 +02:00
|
|
|
invoke-static {}, Lapp/revanced/integrations/patches/MinimizedPlaybackPatch;->isMinimizedPlaybackEnabled()Z
|
|
|
|
move-result v0
|
|
|
|
if-eqz v0, :enable
|
2022-07-18 16:29:51 +02:00
|
|
|
return-void
|
2022-07-18 22:59:21 +02:00
|
|
|
:enable
|
|
|
|
nop
|
2022-07-18 16:29:51 +02:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
|
2022-05-18 23:58:54 +02:00
|
|
|
return PatchResultSuccess()
|
|
|
|
}
|
2022-07-05 19:45:46 +02:00
|
|
|
}
|