diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/layoutswitch/LayoutSwitchPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/layoutswitch/LayoutSwitchPatch.kt index f4c8c6139..6758e0449 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/layoutswitch/LayoutSwitchPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/layoutswitch/LayoutSwitchPatch.kt @@ -2,19 +2,22 @@ package app.revanced.patches.youtube.general.layoutswitch import app.revanced.patcher.data.BytecodeContext 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.util.smali.ExternalLabel -import app.revanced.patches.youtube.general.layoutswitch.fingerprints.GetFormFactorFingerprint +import app.revanced.patches.shared.fingerprints.CreatePlayerRequestBodyWithModelFingerprint +import app.revanced.patches.youtube.general.layoutswitch.fingerprints.FormFactorEnumConstructorFingerprint import app.revanced.patches.youtube.general.layoutswitch.fingerprints.LayoutSwitchFingerprint import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE -import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR +import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_PATH import app.revanced.patches.youtube.utils.settings.SettingsPatch +import app.revanced.util.getReference +import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.indexOfFirstInstructionReversedOrThrow import app.revanced.util.patch.BaseBytecodePatch import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.FieldReference @Suppress("unused") object LayoutSwitchPatch : BaseBytecodePatch( @@ -23,52 +26,51 @@ object LayoutSwitchPatch : BaseBytecodePatch( dependencies = setOf(SettingsPatch::class), compatiblePackages = COMPATIBLE_PACKAGE, fingerprints = setOf( - GetFormFactorFingerprint, + CreatePlayerRequestBodyWithModelFingerprint, + FormFactorEnumConstructorFingerprint, LayoutSwitchFingerprint ) ) { + private const val INTEGRATIONS_CLASS_DESCRIPTOR = "$GENERAL_PATH/LayoutSwitchPatch;" + override fun execute(context: BytecodeContext) { - // region patch for enable tablet layout + val formFactorEnumClass = FormFactorEnumConstructorFingerprint + .resultOrThrow() + .mutableMethod + .definingClass - GetFormFactorFingerprint.resultOrThrow().let { - it.mutableMethod.apply { - val jumpIndex = indexOfFirstInstructionReversedOrThrow(Opcode.SGET_OBJECT) - - addInstructionsWithLabels( - 0, """ - invoke-static { }, $GENERAL_CLASS_DESCRIPTOR->enableTabletLayout()Z - move-result v0 # Free register - if-nez v0, :is_large_form_factor - """, - ExternalLabel( - "is_large_form_factor", - getInstruction(jumpIndex) - ) - ) + CreatePlayerRequestBodyWithModelFingerprint.resultOrThrow().mutableMethod.apply { + val index = indexOfFirstInstructionOrThrow { + val reference = getReference() + opcode == Opcode.IGET && + reference?.definingClass == formFactorEnumClass && + reference.type == "I" } + val register = getInstruction(index).registerA + + addInstructions( + index + 1, """ + invoke-static {v$register}, $INTEGRATIONS_CLASS_DESCRIPTOR->getFormFactor(I)I + move-result v$register + """ + ) } - // endregion - - // region patch for enable phone layout - LayoutSwitchFingerprint.resultOrThrow().let { it.mutableMethod.apply { - val insertIndex = indexOfFirstInstructionReversedOrThrow(Opcode.IF_NEZ) - val insertRegister = getInstruction(insertIndex).registerA + val index = indexOfFirstInstructionReversedOrThrow(Opcode.IF_NEZ) + val register = getInstruction(index).registerA addInstructions( - insertIndex, """ - invoke-static {v$insertRegister}, $GENERAL_CLASS_DESCRIPTOR->enablePhoneLayout(I)I - move-result v$insertRegister + index, """ + invoke-static {v$register}, $INTEGRATIONS_CLASS_DESCRIPTOR->getWidthDp(I)I + move-result v$register """ ) } } - // endregion - /** * Add settings */ diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/layoutswitch/fingerprints/FormFactorEnumConstructorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/general/layoutswitch/fingerprints/FormFactorEnumConstructorFingerprint.kt new file mode 100644 index 000000000..2c2f41211 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/general/layoutswitch/fingerprints/FormFactorEnumConstructorFingerprint.kt @@ -0,0 +1,12 @@ +package app.revanced.patches.youtube.general.layoutswitch.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint + +internal object FormFactorEnumConstructorFingerprint : MethodFingerprint( + returnType = "V", + strings = listOf( + "UNKNOWN_FORM_FACTOR", + "SMALL_FORM_FACTOR", + "LARGE_FORM_FACTOR" + ) +) diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/layoutswitch/fingerprints/GetFormFactorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/general/layoutswitch/fingerprints/GetFormFactorFingerprint.kt deleted file mode 100644 index c3f22c424..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/general/layoutswitch/fingerprints/GetFormFactorFingerprint.kt +++ /dev/null @@ -1,25 +0,0 @@ -package app.revanced.patches.youtube.general.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 - -internal 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 - ) -) \ No newline at end of file diff --git a/src/main/resources/youtube/settings/host/values/arrays.xml b/src/main/resources/youtube/settings/host/values/arrays.xml index 616c6bc4b..e5c6ba418 100644 --- a/src/main/resources/youtube/settings/host/values/arrays.xml +++ b/src/main/resources/youtube/settings/host/values/arrays.xml @@ -22,6 +22,20 @@ MIDDLE END + + @string/revanced_change_layout_entry_1 + @string/revanced_change_layout_entry_2 + @string/revanced_change_layout_entry_3 + @string/revanced_change_layout_entry_4 + @string/revanced_change_layout_entry_5 + + + ORIGINAL + SMALL_FORM_FACTOR + SMALL_FORM_FACTOR_WIDTH_DP + LARGE_FORM_FACTOR + LARGE_FORM_FACTOR_WIDTH_DP + @string/revanced_change_start_page_entry_default @string/revanced_change_start_page_entry_search diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index e466d7ab0..67b9161c1 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -364,10 +364,12 @@ Limitation: Back button on the toolbar may not work." "Removes the viewer discretion dialog. This does not bypass the age restriction. It just accepts it automatically." - Enable phone layout - Spoofs the dpi to use some phone layouts. - Enable tablet layout - Spoofs the dpi to use some tablet layouts. + Change layout + Original + Phone + Phone (Max 480 dip) + Tablet + Tablet (Min 600 dip) Spoof app version Version spoofed diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 67047fead..832a693c9 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -256,8 +256,7 @@ PREFERENCE_CATEGORY: GENERAL_EXPERIMENTAL_FLAGS --> + SETTINGS: LAYOUT_SWITCH -->