mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-27 20:30:19 +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.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.getInstructions
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.annotation.CompatiblePackage
|
||||
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.patches.youtube.misc.layoutswitch.fingerprints.ClientFormFactorFingerprint
|
||||
import app.revanced.patches.youtube.misc.layoutswitch.fingerprints.ClientFormFactorParentFingerprint
|
||||
import app.revanced.patches.youtube.misc.layoutswitch.fingerprints.ClientFormFactorWalkerFingerprint
|
||||
import app.revanced.patches.youtube.misc.layoutswitch.fingerprints.GetFormFactorFingerprint
|
||||
import app.revanced.patches.youtube.utils.fingerprints.LayoutSwitchFingerprint
|
||||
import app.revanced.patches.youtube.utils.settings.SettingsPatch
|
||||
import app.revanced.util.integrations.Constants.MISC_PATH
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction10x
|
||||
|
||||
@Patch(
|
||||
name = "Layout switch",
|
||||
@ -52,55 +53,50 @@ import com.android.tools.smali.dexlib2.Opcode
|
||||
@Suppress("unused")
|
||||
object LayoutSwitchPatch : BytecodePatch(
|
||||
setOf(
|
||||
ClientFormFactorParentFingerprint,
|
||||
GetFormFactorFingerprint,
|
||||
LayoutSwitchFingerprint
|
||||
)
|
||||
) {
|
||||
override fun execute(context: BytecodeContext) {
|
||||
|
||||
fun MutableMethod.injectTabletLayout(jumpIndex: Int) {
|
||||
addInstructionsWithLabels(
|
||||
0, """
|
||||
invoke-static {}, $MISC_PATH/LayoutOverridePatch;->enableTabletLayout()Z
|
||||
move-result v0
|
||||
if-nez v0, :tablet_layout
|
||||
""", ExternalLabel("tablet_layout", getInstruction(jumpIndex))
|
||||
)
|
||||
}
|
||||
GetFormFactorFingerprint.result?.let {
|
||||
it.mutableMethod.apply {
|
||||
val returnCurrentFormFactorIndex = getInstructions().lastIndex - 2
|
||||
|
||||
ClientFormFactorParentFingerprint.result?.classDef?.let { classDef ->
|
||||
try {
|
||||
ClientFormFactorFingerprint.also { it.resolve(context, classDef) }.result!!.apply {
|
||||
mutableMethod.injectTabletLayout(scanResult.patternScanResult!!.startIndex + 1)
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
ClientFormFactorWalkerFingerprint.also {
|
||||
it.resolve(
|
||||
context,
|
||||
classDef
|
||||
val returnIsLargeFormFactorLabel = getInstruction(returnCurrentFormFactorIndex - 2)
|
||||
val returnFormFactorIndex = getInstruction(returnCurrentFormFactorIndex)
|
||||
|
||||
val insertIndex = returnCurrentFormFactorIndex + 1
|
||||
|
||||
// Replace the labeled instruction with a nop and add the preserved instructions back
|
||||
replaceInstruction(returnCurrentFormFactorIndex, BuilderInstruction10x(Opcode.NOP))
|
||||
addInstruction(insertIndex, returnFormFactorIndex)
|
||||
|
||||
// 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(
|
||||
4, """
|
||||
invoke-static {p0}, $MISC_PATH/LayoutOverridePatch;->getLayoutOverride(I)I
|
||||
move-result p0
|
||||
"""
|
||||
) ?: throw LayoutSwitchFingerprint.exception
|
||||
LayoutSwitchFingerprint.result?.let {
|
||||
it.mutableMethod.apply {
|
||||
addInstructions(
|
||||
4, """
|
||||
invoke-static {p0}, $MISC_PATH/LayoutOverridePatch;->getLayoutOverride(I)I
|
||||
move-result p0
|
||||
"""
|
||||
)
|
||||
}
|
||||
} ?: throw LayoutSwitchFingerprint.exception
|
||||
|
||||
/**
|
||||
* 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