refactor: move the patch to the correct path

This commit is contained in:
inotia00
2023-06-18 23:09:08 +09:00
parent 03148b5c81
commit 5c99e9a16a
410 changed files with 3807 additions and 3505 deletions

View File

@ -0,0 +1,82 @@
package app.revanced.patches.youtube.fullscreen.autoplaypreview.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
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.util.smali.ExternalLabel
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.shared.fingerprints.LayoutConstructorFingerprint
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.AutoNavPreviewStub
import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch
import app.revanced.util.bytecode.getStringIndex
import app.revanced.util.bytecode.getWideLiteralIndex
import app.revanced.util.integrations.Constants.FULLSCREEN
import org.jf.dexlib2.iface.instruction.Instruction
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.reference.FieldReference
@Patch
@Name("hide-autoplay-preview")
@Description("Hides the autoplay preview container in the fullscreen.")
@DependsOn(
[
SettingsPatch::class,
SharedResourceIdPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class HideAutoplayPreviewPatch : BytecodePatch(
listOf(LayoutConstructorFingerprint)
) {
override fun execute(context: BytecodeContext): PatchResult {
LayoutConstructorFingerprint.result?.let {
it.mutableMethod.apply {
val insertInstruction = implementation!!.instructions
val dummyRegister = getInstruction<OneRegisterInstruction>(getStringIndex("1.0x")).registerA
val insertIndex = getWideLiteralIndex(AutoNavPreviewStub)
val branchIndex = insertInstruction.subList(insertIndex + 1, insertInstruction.size - 1).indexOfFirst { instruction ->
((instruction as? ReferenceInstruction)?.reference as? FieldReference)?.type == "Lcom/google/android/apps/youtube/app/player/autonav/AutonavToggleController;"
} + 1
val jumpInstruction = getInstruction<Instruction>(insertIndex + branchIndex)
addInstructionsWithLabels(
insertIndex, """
invoke-static {}, $FULLSCREEN->hideAutoPlayPreview()Z
move-result v$dummyRegister
if-nez v$dummyRegister, :hidden
""", ExternalLabel("hidden", jumpInstruction)
)
}
} ?: return LayoutConstructorFingerprint.toErrorResult()
/**
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: FULLSCREEN_SETTINGS",
"SETTINGS: HIDE_AUTOPLAY_PREVIEW"
)
)
SettingsPatch.updatePatchStatus("hide-autoplay-preview")
return PatchResultSuccess()
}
}

View File

@ -0,0 +1,10 @@
package app.revanced.patches.youtube.fullscreen.endscreenoverlay.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.AppRelatedEndScreenResults
import app.revanced.util.bytecode.isWideLiteralExists
object EndScreenResultsFingerprint : MethodFingerprint(
returnType = "V",
customFingerprint = { it, _ -> it.isWideLiteralExists(AppRelatedEndScreenResults) }
)

View File

@ -0,0 +1,64 @@
package app.revanced.patches.youtube.fullscreen.endscreenoverlay.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
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.util.smali.ExternalLabel
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.fullscreen.endscreenoverlay.fingerprints.EndScreenResultsFingerprint
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.FULLSCREEN
@Patch
@Name("hide-endscreen-overlay")
@Description("Hide endscreen overlay on swipe controls.")
@DependsOn(
[
SettingsPatch::class,
SharedResourceIdPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class HideEndScreenOverlayPatch : BytecodePatch(
listOf(EndScreenResultsFingerprint)
) {
override fun execute(context: BytecodeContext): PatchResult {
EndScreenResultsFingerprint.result?.let {
it.mutableMethod.apply {
addInstructionsWithLabels(
0, """
invoke-static {}, $FULLSCREEN->hideEndScreenOverlay()Z
move-result v0
if-eqz v0, :show
return-void
""", ExternalLabel("show", getInstruction(0))
)
}
} ?: return EndScreenResultsFingerprint.toErrorResult()
/**
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: FULLSCREEN_SETTINGS",
"SETTINGS: HIDE_END_SCREEN_OVERLAY"
)
)
SettingsPatch.updatePatchStatus("hide-endscreen-overlay")
return PatchResultSuccess()
}
}

View File

@ -0,0 +1,10 @@
package app.revanced.patches.youtube.fullscreen.fullscreenpanels.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.FullScreenEngagementPanel
import app.revanced.util.bytecode.isWideLiteralExists
object FullscreenEngagementPanelFingerprint : MethodFingerprint(
returnType = "L",
customFingerprint = { it, _ -> it.definingClass.endsWith("FullscreenEngagementPanelOverlay;") && it.isWideLiteralExists(FullScreenEngagementPanel) }
)

View File

@ -0,0 +1,16 @@
package app.revanced.patches.youtube.fullscreen.fullscreenpanels.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode
object FullscreenViewAdderFingerprint : MethodFingerprint(
parameters = listOf("L", "L"),
opcodes = listOf(
Opcode.IGET_BOOLEAN,
Opcode.IF_EQ,
Opcode.GOTO,
Opcode.CONST_4,
Opcode.INVOKE_VIRTUAL
),
customFingerprint = { it, _ -> it.definingClass.endsWith("FullscreenEngagementPanelOverlay;") }
)

View File

@ -0,0 +1,118 @@
package app.revanced.patches.youtube.fullscreen.fullscreenpanels.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
import app.revanced.patcher.patch.BytecodePatch
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.util.smali.ExternalLabel
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.shared.fingerprints.LayoutConstructorFingerprint
import app.revanced.patches.youtube.fullscreen.fullscreenpanels.fingerprints.FullscreenEngagementPanelFingerprint
import app.revanced.patches.youtube.fullscreen.fullscreenpanels.fingerprints.FullscreenViewAdderFingerprint
import app.revanced.patches.youtube.utils.quickactionscontainer.patch.HideQuickActionsContainerPatch
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.FullScreenEngagementPanel
import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch
import app.revanced.util.bytecode.getStringIndex
import app.revanced.util.bytecode.getWideLiteralIndex
import app.revanced.util.integrations.Constants.FULLSCREEN
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.instruction.formats.Instruction35c
@Patch
@Name("hide-fullscreen-panels")
@Description("Hides video description and comments panel in fullscreen view.")
@DependsOn(
[
HideQuickActionsContainerPatch::class,
SettingsPatch::class,
SharedResourceIdPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class HideFullscreenPanelsPatch : BytecodePatch(
listOf(
FullscreenEngagementPanelFingerprint,
FullscreenViewAdderFingerprint,
LayoutConstructorFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
FullscreenEngagementPanelFingerprint.result?.let {
it.mutableMethod.apply {
val targetIndex = getWideLiteralIndex(FullScreenEngagementPanel) + 3
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
addInstruction(
targetIndex + 1,
"invoke-static {v$targetRegister}, $FULLSCREEN->hideFullscreenPanels(Landroidx/coordinatorlayout/widget/CoordinatorLayout;)V"
)
}
} ?: return FullscreenEngagementPanelFingerprint.toErrorResult()
FullscreenViewAdderFingerprint.result?.let {
it.mutableMethod.apply {
val endIndex = it.scanResult.patternScanResult!!.endIndex
val register = getInstruction<Instruction35c>(endIndex).registerD
for (i in 1..3) removeInstruction(endIndex - i)
addInstructions(
endIndex - 3, """
invoke-static {}, $FULLSCREEN->hideFullscreenPanels()I
move-result v$register
"""
)
}
}
LayoutConstructorFingerprint.result?.let {
it.mutableMethod.apply {
val dummyRegister = getInstruction<OneRegisterInstruction>(getStringIndex("1.0x")).registerA
val invokeIndex = implementation!!.instructions.indexOfFirst { instruction ->
instruction.opcode == Opcode.INVOKE_VIRTUAL &&
((instruction as ReferenceInstruction).reference.toString() ==
"Landroid/widget/FrameLayout;->addView(Landroid/view/View;)V")
}
addInstructionsWithLabels(
invokeIndex, """
invoke-static {}, $FULLSCREEN->showFullscreenTitle()Z
move-result v$dummyRegister
if-eqz v$dummyRegister, :hidden
""", ExternalLabel("hidden", getInstruction(invokeIndex + 1))
)
}
} ?: return LayoutConstructorFingerprint.toErrorResult()
/**
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: FULLSCREEN_SETTINGS",
"SETTINGS: HIDE_FULLSCREEN_PANELS"
)
)
SettingsPatch.updatePatchStatus("hide-fullscreen-panels")
return PatchResultSuccess()
}
}

View File

@ -0,0 +1,8 @@
package app.revanced.patches.youtube.fullscreen.landscapemode.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
object OrientationParentFingerprint : MethodFingerprint(
returnType = "Z",
strings = listOf("NoClassDefFoundError thrown while verifying stack trace.")
)

View File

@ -0,0 +1,17 @@
package app.revanced.patches.youtube.fullscreen.landscapemode.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 OrientationPrimaryFingerprint : MethodFingerprint (
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
parameters = listOf("L"),
opcodes = listOf(
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT
),
customFingerprint = { it, _ -> it.name == "<init>"}
)

View File

@ -0,0 +1,16 @@
package app.revanced.patches.youtube.fullscreen.landscapemode.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 OrientationSecondaryFingerprint : MethodFingerprint (
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L"),
opcodes = listOf(
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT
)
)

View File

@ -0,0 +1,75 @@
package app.revanced.patches.youtube.fullscreen.landscapemode.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult
import app.revanced.patcher.patch.BytecodePatch
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.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.fullscreen.landscapemode.fingerprints.*
import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.FULLSCREEN
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
@Patch(false)
@Name("disable-landscape-mode")
@Description("Disable landscape mode when entering fullscreen.")
@DependsOn([SettingsPatch::class])
@YouTubeCompatibility
@Version("0.0.1")
class LandScapeModePatch : BytecodePatch(
listOf(OrientationParentFingerprint)
) {
override fun execute(context: BytecodeContext): PatchResult {
OrientationParentFingerprint.result?.classDef?.let { classDef ->
arrayOf(
OrientationPrimaryFingerprint,
OrientationSecondaryFingerprint
).forEach {
it.also { it.resolve(context, classDef) }.result?.injectOverride() ?: return it.toErrorResult()
}
} ?: return OrientationParentFingerprint.toErrorResult()
/**
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: FULLSCREEN_SETTINGS",
"SETTINGS: DISABLE_LANDSCAPE_MODE"
)
)
SettingsPatch.updatePatchStatus("disable-landscape-mode")
return PatchResultSuccess()
}
private companion object {
const val INTEGRATIONS_CLASS_DESCRIPTOR =
"$FULLSCREEN->disableLandScapeMode(Z)Z"
fun MethodFingerprintResult.injectOverride() {
mutableMethod.apply {
val index = scanResult.patternScanResult!!.endIndex
val register = getInstruction<OneRegisterInstruction>(index).registerA
addInstructions(
index +1, """
invoke-static {v$register}, $INTEGRATIONS_CLASS_DESCRIPTOR
move-result v$register
"""
)
}
}
}
}

View File

@ -0,0 +1,46 @@
package app.revanced.patches.youtube.fullscreen.quickactions.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.ads.general.resource.patch.GeneralAdsPatch
import app.revanced.patches.youtube.utils.quickactionscontainer.patch.HideQuickActionsContainerPatch
import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch
@Patch
@Name("hide-quick-actions")
@Description("Adds the options to hide quick actions components in the fullscreen.")
@DependsOn(
[
GeneralAdsPatch::class,
HideQuickActionsContainerPatch::class,
SettingsPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class QuickActionsPatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
/**
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: BOTTOM_PLAYER_SETTINGS",
"SETTINGS: HIDE_QUICK_ACTIONS"
)
)
SettingsPatch.updatePatchStatus("hide-quick-actions")
return PatchResultSuccess()
}
}