From 956c1ed37b7333a6c348da09844f391476af00c8 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Fri, 28 Apr 2023 16:26:09 +0900 Subject: [PATCH] refactor(layout-switch): community posts in channels are no longer hidden when `Enable tablet layout` is on --- .../ClientFormFactorFingerprint.kt | 14 +++++++++++++ .../ClientFormFactorParentFingerprint.kt | 8 ++++++++ .../layoutswitch/patch/LayoutSwitchPatch.kt | 20 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/layoutswitch/fingerprints/ClientFormFactorFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/layoutswitch/fingerprints/ClientFormFactorParentFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/layoutswitch/fingerprints/ClientFormFactorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/layoutswitch/fingerprints/ClientFormFactorFingerprint.kt new file mode 100644 index 000000000..5016f54e6 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/layoutswitch/fingerprints/ClientFormFactorFingerprint.kt @@ -0,0 +1,14 @@ +package app.revanced.patches.youtube.misc.layoutswitch.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.Opcode + +object ClientFormFactorFingerprint : MethodFingerprint( + returnType = "L", + parameters = listOf(), + opcodes = listOf( + Opcode.IF_EQZ, + Opcode.SGET_OBJECT, + Opcode.GOTO + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/layoutswitch/fingerprints/ClientFormFactorParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/layoutswitch/fingerprints/ClientFormFactorParentFingerprint.kt new file mode 100644 index 000000000..99c0fdf32 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/layoutswitch/fingerprints/ClientFormFactorParentFingerprint.kt @@ -0,0 +1,8 @@ +package app.revanced.patches.youtube.misc.layoutswitch.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +object ClientFormFactorParentFingerprint : MethodFingerprint( + returnType = "V", + strings = listOf("ClientFormFactor"), +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/layoutswitch/patch/LayoutSwitchPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/layoutswitch/patch/LayoutSwitchPatch.kt index 9c1044560..f93befed7 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/layoutswitch/patch/LayoutSwitchPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/layoutswitch/patch/LayoutSwitchPatch.kt @@ -6,13 +6,17 @@ import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.instruction +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve 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.LayoutSwitchFingerprint +import app.revanced.patches.youtube.misc.layoutswitch.fingerprints.* import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch import app.revanced.util.integrations.Constants.MISC_PATH @@ -24,11 +28,27 @@ import app.revanced.util.integrations.Constants.MISC_PATH @Version("0.0.1") class LayoutSwitchPatch : BytecodePatch( listOf( + ClientFormFactorParentFingerprint, LayoutSwitchFingerprint ) ) { override fun execute(context: BytecodeContext): PatchResult { + ClientFormFactorParentFingerprint.result?.let { parentResult -> + ClientFormFactorFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let { + with (it.mutableMethod) { + val jumpIndex = it.scanResult.patternScanResult!!.startIndex + 1 + addInstructions( + 1, """ + invoke-static {}, $MISC_PATH/LayoutOverridePatch;->enableTabletLayout()Z + move-result v2 + if-nez v2, :tablet_layout + """, listOf(ExternalLabel("tablet_layout", instruction(jumpIndex))) + ) + } + } ?: return ClientFormFactorFingerprint.toErrorResult() + } ?: return ClientFormFactorParentFingerprint.toErrorResult() + LayoutSwitchFingerprint.result?.mutableMethod?.addInstructions( 4, """ invoke-static {p0}, $MISC_PATH/LayoutOverridePatch;->getLayoutOverride(I)I