mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-29 05:10:20 +02:00
fix(YouTube/Enable tablet layout): respect the original device layout
This commit is contained in:
parent
1bd7eb41f1
commit
5dd7f1485d
@ -2,21 +2,22 @@ package app.revanced.patches.youtube.misc.layoutswitch
|
|||||||
|
|
||||||
import app.revanced.extensions.exception
|
import app.revanced.extensions.exception
|
||||||
import app.revanced.patcher.data.BytecodeContext
|
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.addInstructions
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
|
||||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
|
||||||
import app.revanced.patcher.patch.BytecodePatch
|
import app.revanced.patcher.patch.BytecodePatch
|
||||||
import app.revanced.patcher.patch.annotation.CompatiblePackage
|
import app.revanced.patcher.patch.annotation.CompatiblePackage
|
||||||
import app.revanced.patcher.patch.annotation.Patch
|
import app.revanced.patcher.patch.annotation.Patch
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
|
||||||
import app.revanced.patcher.util.smali.ExternalLabel
|
import app.revanced.patcher.util.smali.ExternalLabel
|
||||||
import app.revanced.patches.youtube.misc.layoutswitch.fingerprints.ClientFormFactorFingerprint
|
import app.revanced.patches.youtube.misc.layoutswitch.fingerprints.GetFormFactorFingerprint
|
||||||
import app.revanced.patches.youtube.misc.layoutswitch.fingerprints.ClientFormFactorParentFingerprint
|
|
||||||
import app.revanced.patches.youtube.misc.layoutswitch.fingerprints.ClientFormFactorWalkerFingerprint
|
|
||||||
import app.revanced.patches.youtube.utils.fingerprints.LayoutSwitchFingerprint
|
import app.revanced.patches.youtube.utils.fingerprints.LayoutSwitchFingerprint
|
||||||
import app.revanced.patches.youtube.utils.settings.SettingsPatch
|
import app.revanced.patches.youtube.utils.settings.SettingsPatch
|
||||||
import app.revanced.util.integrations.Constants.MISC_PATH
|
import app.revanced.util.integrations.Constants.MISC_PATH
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
|
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction10x
|
||||||
|
|
||||||
@Patch(
|
@Patch(
|
||||||
name = "Layout switch",
|
name = "Layout switch",
|
||||||
@ -52,55 +53,50 @@ import com.android.tools.smali.dexlib2.Opcode
|
|||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
object LayoutSwitchPatch : BytecodePatch(
|
object LayoutSwitchPatch : BytecodePatch(
|
||||||
setOf(
|
setOf(
|
||||||
ClientFormFactorParentFingerprint,
|
GetFormFactorFingerprint,
|
||||||
LayoutSwitchFingerprint
|
LayoutSwitchFingerprint
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
override fun execute(context: BytecodeContext) {
|
override fun execute(context: BytecodeContext) {
|
||||||
|
|
||||||
fun MutableMethod.injectTabletLayout(jumpIndex: Int) {
|
GetFormFactorFingerprint.result?.let {
|
||||||
addInstructionsWithLabels(
|
it.mutableMethod.apply {
|
||||||
0, """
|
val returnCurrentFormFactorIndex = getInstructions().lastIndex - 2
|
||||||
invoke-static {}, $MISC_PATH/LayoutOverridePatch;->enableTabletLayout()Z
|
|
||||||
move-result v0
|
|
||||||
if-nez v0, :tablet_layout
|
|
||||||
""", ExternalLabel("tablet_layout", getInstruction(jumpIndex))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
ClientFormFactorParentFingerprint.result?.classDef?.let { classDef ->
|
val returnIsLargeFormFactorLabel = getInstruction(returnCurrentFormFactorIndex - 2)
|
||||||
try {
|
val returnFormFactorIndex = getInstruction(returnCurrentFormFactorIndex)
|
||||||
ClientFormFactorFingerprint.also { it.resolve(context, classDef) }.result!!.apply {
|
|
||||||
mutableMethod.injectTabletLayout(scanResult.patternScanResult!!.startIndex + 1)
|
val insertIndex = returnCurrentFormFactorIndex + 1
|
||||||
}
|
|
||||||
} catch (_: Exception) {
|
// Replace the labeled instruction with a nop and add the preserved instructions back
|
||||||
ClientFormFactorWalkerFingerprint.also {
|
replaceInstruction(returnCurrentFormFactorIndex, BuilderInstruction10x(Opcode.NOP))
|
||||||
it.resolve(
|
addInstruction(insertIndex, returnFormFactorIndex)
|
||||||
context,
|
|
||||||
classDef
|
// Because the labeled instruction is now a nop, we can add our own instructions right after it
|
||||||
|
addInstructionsWithLabels(
|
||||||
|
insertIndex, """
|
||||||
|
invoke-static { }, $MISC_PATH/LayoutOverridePatch;->enableTabletLayout()Z
|
||||||
|
move-result v0 # Free register
|
||||||
|
if-nez v0, :is_large_form_factor
|
||||||
|
""",
|
||||||
|
ExternalLabel(
|
||||||
|
"is_large_form_factor",
|
||||||
|
returnIsLargeFormFactorLabel
|
||||||
)
|
)
|
||||||
}.result?.let {
|
)
|
||||||
(context
|
|
||||||
.toMethodWalker(it.method)
|
|
||||||
.nextMethod(it.scanResult.patternScanResult!!.startIndex, true)
|
|
||||||
.getMethod() as MutableMethod).apply {
|
|
||||||
|
|
||||||
val jumpIndex = implementation!!.instructions.indexOfFirst { instruction ->
|
|
||||||
instruction.opcode == Opcode.RETURN_OBJECT
|
|
||||||
} - 1
|
|
||||||
|
|
||||||
injectTabletLayout(jumpIndex)
|
|
||||||
}
|
|
||||||
} ?: throw ClientFormFactorWalkerFingerprint.exception
|
|
||||||
}
|
}
|
||||||
} ?: throw ClientFormFactorParentFingerprint.exception
|
} ?: GetFormFactorFingerprint.exception
|
||||||
|
|
||||||
LayoutSwitchFingerprint.result?.mutableMethod?.addInstructions(
|
LayoutSwitchFingerprint.result?.let {
|
||||||
4, """
|
it.mutableMethod.apply {
|
||||||
invoke-static {p0}, $MISC_PATH/LayoutOverridePatch;->getLayoutOverride(I)I
|
addInstructions(
|
||||||
move-result p0
|
4, """
|
||||||
"""
|
invoke-static {p0}, $MISC_PATH/LayoutOverridePatch;->getLayoutOverride(I)I
|
||||||
) ?: throw LayoutSwitchFingerprint.exception
|
move-result p0
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} ?: throw LayoutSwitchFingerprint.exception
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add settings
|
* Add settings
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
package app.revanced.patches.youtube.misc.layoutswitch.fingerprints
|
|
||||||
|
|
||||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
|
||||||
|
|
||||||
object ClientFormFactorFingerprint : MethodFingerprint(
|
|
||||||
returnType = "L",
|
|
||||||
parameters = emptyList(),
|
|
||||||
opcodes = listOf(
|
|
||||||
Opcode.IF_EQZ,
|
|
||||||
Opcode.SGET_OBJECT,
|
|
||||||
Opcode.GOTO
|
|
||||||
)
|
|
||||||
)
|
|
@ -1,8 +0,0 @@
|
|||||||
package app.revanced.patches.youtube.misc.layoutswitch.fingerprints
|
|
||||||
|
|
||||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
|
||||||
|
|
||||||
object ClientFormFactorParentFingerprint : MethodFingerprint(
|
|
||||||
returnType = "V",
|
|
||||||
strings = listOf("ClientFormFactor"),
|
|
||||||
)
|
|
@ -1,14 +0,0 @@
|
|||||||
package app.revanced.patches.youtube.misc.layoutswitch.fingerprints
|
|
||||||
|
|
||||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
|
||||||
|
|
||||||
object ClientFormFactorWalkerFingerprint : MethodFingerprint(
|
|
||||||
returnType = "L",
|
|
||||||
parameters = emptyList(),
|
|
||||||
opcodes = listOf(
|
|
||||||
Opcode.INVOKE_STATIC,
|
|
||||||
Opcode.MOVE_RESULT_OBJECT,
|
|
||||||
Opcode.RETURN_OBJECT
|
|
||||||
)
|
|
||||||
)
|
|
@ -0,0 +1,25 @@
|
|||||||
|
package app.revanced.patches.youtube.misc.layoutswitch.fingerprints
|
||||||
|
|
||||||
|
import app.revanced.patcher.extensions.or
|
||||||
|
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||||
|
import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
|
|
||||||
|
object GetFormFactorFingerprint : MethodFingerprint(
|
||||||
|
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
|
||||||
|
returnType = "L",
|
||||||
|
parameters = listOf("Landroid/content/Context;", "Ljava/util/List;"),
|
||||||
|
opcodes = listOf(
|
||||||
|
Opcode.SGET_OBJECT,
|
||||||
|
Opcode.INVOKE_VIRTUAL,
|
||||||
|
Opcode.MOVE_RESULT_OBJECT,
|
||||||
|
Opcode.INVOKE_VIRTUAL,
|
||||||
|
Opcode.MOVE_RESULT,
|
||||||
|
Opcode.IF_EQZ,
|
||||||
|
Opcode.SGET_OBJECT,
|
||||||
|
Opcode.RETURN_OBJECT,
|
||||||
|
Opcode.INVOKE_STATIC,
|
||||||
|
Opcode.MOVE_RESULT_OBJECT,
|
||||||
|
Opcode.RETURN_OBJECT
|
||||||
|
)
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user