mirror of
https://github.com/revanced/revanced-patches
synced 2024-12-29 11:05:48 +01:00
feat(youtube/hide-autoplay-button): do not disable autoplay button when hidden
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
parent
7680838829
commit
98d00848c9
@ -1,20 +0,0 @@
|
|||||||
package app.revanced.patches.youtube.layout.buttons.autoplay.fingerprints
|
|
||||||
|
|
||||||
import app.revanced.patcher.extensions.or
|
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
|
||||||
import org.jf.dexlib2.AccessFlags
|
|
||||||
import org.jf.dexlib2.Opcode
|
|
||||||
|
|
||||||
object AutoNavInformerFingerprint : MethodFingerprint(
|
|
||||||
"Z",
|
|
||||||
AccessFlags.PUBLIC or AccessFlags.FINAL,
|
|
||||||
opcodes = listOf(
|
|
||||||
Opcode.IGET_OBJECT,
|
|
||||||
Opcode.INVOKE_INTERFACE,
|
|
||||||
Opcode.MOVE_RESULT_OBJECT,
|
|
||||||
Opcode.CHECK_CAST,
|
|
||||||
Opcode.INVOKE_VIRTUAL,
|
|
||||||
Opcode.MOVE_RESULT,
|
|
||||||
),
|
|
||||||
customFingerprint = { it.definingClass.endsWith("WillAutonavInformer;") }
|
|
||||||
)
|
|
@ -1,5 +1,6 @@
|
|||||||
package app.revanced.patches.youtube.layout.buttons.autoplay.patch
|
package app.revanced.patches.youtube.layout.buttons.autoplay.patch
|
||||||
|
|
||||||
|
import app.revanced.extensions.toErrorResult
|
||||||
import app.revanced.patcher.annotation.Description
|
import app.revanced.patcher.annotation.Description
|
||||||
import app.revanced.patcher.annotation.Name
|
import app.revanced.patcher.annotation.Name
|
||||||
import app.revanced.patcher.annotation.Version
|
import app.revanced.patcher.annotation.Version
|
||||||
@ -15,7 +16,6 @@ import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch
|
|||||||
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
||||||
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
|
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
|
||||||
import app.revanced.patches.youtube.layout.buttons.autoplay.annotations.AutoplayButtonCompatibility
|
import app.revanced.patches.youtube.layout.buttons.autoplay.annotations.AutoplayButtonCompatibility
|
||||||
import app.revanced.patches.youtube.layout.buttons.autoplay.fingerprints.AutoNavInformerFingerprint
|
|
||||||
import app.revanced.patches.youtube.layout.buttons.autoplay.fingerprints.LayoutConstructorFingerprint
|
import app.revanced.patches.youtube.layout.buttons.autoplay.fingerprints.LayoutConstructorFingerprint
|
||||||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
||||||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
||||||
@ -31,9 +31,7 @@ import org.jf.dexlib2.iface.reference.MethodReference
|
|||||||
@AutoplayButtonCompatibility
|
@AutoplayButtonCompatibility
|
||||||
@Version("0.0.1")
|
@Version("0.0.1")
|
||||||
class HideAutoplayButtonPatch : BytecodePatch(
|
class HideAutoplayButtonPatch : BytecodePatch(
|
||||||
listOf(
|
listOf(LayoutConstructorFingerprint)
|
||||||
LayoutConstructorFingerprint, AutoNavInformerFingerprint
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
override fun execute(context: BytecodeContext): PatchResult {
|
override fun execute(context: BytecodeContext): PatchResult {
|
||||||
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
|
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
|
||||||
@ -43,49 +41,40 @@ class HideAutoplayButtonPatch : BytecodePatch(
|
|||||||
true,
|
true,
|
||||||
StringResource("revanced_hide_autoplay_button_summary_on", "Autoplay button is hidden"),
|
StringResource("revanced_hide_autoplay_button_summary_on", "Autoplay button is hidden"),
|
||||||
StringResource("revanced_hide_autoplay_button_summary_off", "Autoplay button is shown")
|
StringResource("revanced_hide_autoplay_button_summary_off", "Autoplay button is shown")
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
val autoNavInformerMethod = AutoNavInformerFingerprint.result!!.mutableMethod
|
LayoutConstructorFingerprint.result?.mutableMethod?.apply {
|
||||||
|
val layoutGenMethodInstructions = implementation!!.instructions
|
||||||
val layoutGenMethodResult = LayoutConstructorFingerprint.result!!
|
|
||||||
val layoutGenMethod = layoutGenMethodResult.mutableMethod
|
|
||||||
val layoutGenMethodInstructions = layoutGenMethod.implementation!!.instructions
|
|
||||||
|
|
||||||
// resolve the offsets such as ...
|
// resolve the offsets such as ...
|
||||||
val autoNavPreviewStubId = ResourceMappingPatch.resourceMappings.single {
|
val autoNavPreviewStubId = ResourceMappingPatch.resourceMappings.single {
|
||||||
it.name == "autonav_preview_stub"
|
it.name == "autonav_preview_stub"
|
||||||
}.id
|
}.id
|
||||||
|
|
||||||
// where to insert the branch instructions and ...
|
// where to insert the branch instructions and ...
|
||||||
val insertIndex = layoutGenMethodInstructions.indexOfFirst {
|
val insertIndex = layoutGenMethodInstructions.indexOfFirst {
|
||||||
(it as? WideLiteralInstruction)?.wideLiteral == autoNavPreviewStubId
|
(it as? WideLiteralInstruction)?.wideLiteral == autoNavPreviewStubId
|
||||||
}
|
}
|
||||||
|
|
||||||
// where to branch away
|
// where to branch away
|
||||||
val branchIndex = layoutGenMethodInstructions.subList(insertIndex + 1, layoutGenMethodInstructions.size - 1).indexOfFirst {
|
val branchIndex =
|
||||||
|
layoutGenMethodInstructions.subList(insertIndex + 1, layoutGenMethodInstructions.size - 1)
|
||||||
|
.indexOfFirst {
|
||||||
((it as? ReferenceInstruction)?.reference as? MethodReference)?.name == "addOnLayoutChangeListener"
|
((it as? ReferenceInstruction)?.reference as? MethodReference)?.name == "addOnLayoutChangeListener"
|
||||||
} + 2
|
} + 2
|
||||||
|
|
||||||
val jumpInstruction = layoutGenMethodInstructions[insertIndex + branchIndex] as Instruction
|
val jumpInstruction = layoutGenMethodInstructions[insertIndex + branchIndex] as Instruction
|
||||||
layoutGenMethod.addInstructions(
|
|
||||||
insertIndex, """
|
addInstructions(
|
||||||
|
insertIndex,
|
||||||
|
"""
|
||||||
invoke-static {}, Lapp/revanced/integrations/patches/HideAutoplayButtonPatch;->isButtonShown()Z
|
invoke-static {}, Lapp/revanced/integrations/patches/HideAutoplayButtonPatch;->isButtonShown()Z
|
||||||
move-result v11
|
move-result v11
|
||||||
if-eqz v11, :hidden
|
if-eqz v11, :hidden
|
||||||
""", listOf(ExternalLabel("hidden", jumpInstruction))
|
""", listOf(ExternalLabel("hidden", jumpInstruction))
|
||||||
)
|
)
|
||||||
|
} ?: return LayoutConstructorFingerprint.toErrorResult()
|
||||||
//force disable autoplay since it's hard to do without the button
|
|
||||||
autoNavInformerMethod.addInstructions(
|
|
||||||
0, """
|
|
||||||
invoke-static {}, Lapp/revanced/integrations/patches/HideAutoplayButtonPatch;->isButtonShown()Z
|
|
||||||
move-result v0
|
|
||||||
if-nez v0, :hidden
|
|
||||||
const/4 v0, 0x0
|
|
||||||
return v0
|
|
||||||
:hidden
|
|
||||||
nop
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
return PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user