Skip to content

Commit

Permalink
fix(YouTube - Enable tablet layout): Respect the original device layout
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Nov 23, 2023
1 parent da81a19 commit b2c5bab
Showing 1 changed file with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package app.revanced.patches.youtube.layout.tablet

import app.revanced.extensions.exception
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
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
Expand All @@ -13,6 +16,8 @@ import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
import app.revanced.patches.youtube.layout.tablet.fingerprints.GetFormFactorFingerprint
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
import app.revanced.patches.youtube.misc.settings.SettingsPatch
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction10x

@Patch(
name = "Enable tablet layout",
Expand All @@ -37,18 +42,28 @@ object EnableTabletLayoutPatch : BytecodePatch(

GetFormFactorFingerprint.result?.let {
it.mutableMethod.apply {
val returnLargeFormFactorIndex = it.scanResult.patternScanResult!!.endIndex - 4
val returnCurrentFormFactorIndex = getInstructions().lastIndex - 2

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(
0,
insertIndex,
"""
invoke-static {}, Lapp/revanced/integrations/patches/EnableTabletLayoutPatch;->enableTabletLayout()Z
move-result v0
invoke-static { }, Lapp/revanced/integrations/patches/EnableTabletLayoutPatch;->enableTabletLayout()Z
move-result v0 # Free register
if-nez v0, :is_large_form_factor
""",
ExternalLabel(
"is_large_form_factor",
getInstruction(returnLargeFormFactorIndex)
returnIsLargeFormFactorLabel
)
)
}
Expand Down

0 comments on commit b2c5bab

Please sign in to comment.