refactor(layout-switch): community posts in channels are no longer hidden when Enable tablet layout is on

This commit is contained in:
inotia00 2023-04-28 16:26:09 +09:00
parent 0266725e6e
commit 956c1ed37b
3 changed files with 42 additions and 0 deletions

View File

@ -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
)
)

View File

@ -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"),
)

View File

@ -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