diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreenpanels/fingerprints/FullscreenViewAdderFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreenpanels/fingerprints/FullscreenViewAdderFingerprint.kt new file mode 100644 index 000000000..4b26e092f --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreenpanels/fingerprints/FullscreenViewAdderFingerprint.kt @@ -0,0 +1,32 @@ +package app.revanced.patches.youtube.layout.fullscreenpanels.fingerprints + +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod +import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.layout.shorts.button.annotations.ShortsButtonCompatibility +import org.jf.dexlib2.Opcode + +@Name("fullscreen-view-adder-fingerprint") +@MatchingMethod( + "LFullscreenEngagementPanelOverlay;", "e" +) +@FuzzyPatternScanMethod(2) +@ShortsButtonCompatibility +@Version("0.0.1") +object FullscreenViewAdderFingerprint : MethodFingerprint( + null, + null, + listOf("L", "L"), + listOf( + Opcode.GOTO, + Opcode.IGET_BOOLEAN, + Opcode.IF_EQ, + Opcode.GOTO, + Opcode.CONST_4, + Opcode.INVOKE_VIRTUAL, + ), + null, + { it.definingClass.endsWith("FullscreenEngagementPanelOverlay;") } +) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreenpanels/patch/FullscreenPanelsRemoverPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreenpanels/patch/FullscreenPanelsRemoverPatch.kt index a6edd4c83..7c35abb73 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreenpanels/patch/FullscreenPanelsRemoverPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/fullscreenpanels/patch/FullscreenPanelsRemoverPatch.kt @@ -4,31 +4,47 @@ import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.impl.BytecodeData -import app.revanced.patcher.extensions.addInstructions -import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patcher.patch.impl.BytecodePatch +import app.revanced.patcher.extensions.addInstruction +import app.revanced.patcher.extensions.removeInstruction import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patcher.patch.impl.BytecodePatch import app.revanced.patches.youtube.layout.fullscreenpanels.annotations.FullscreenPanelsCompatibility +import app.revanced.patches.youtube.layout.fullscreenpanels.fingerprints.FullscreenViewAdderFingerprint +import org.jf.dexlib2.Opcode +import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction +import org.jf.dexlib2.iface.instruction.ReferenceInstruction +import org.jf.dexlib2.iface.reference.MethodReference @Patch @Name("disable-fullscreen-panels") @Description("Disable comments panel in fullscreen view.") @FullscreenPanelsCompatibility @Version("0.0.1") -class FullscreenPanelsRemovalPatch : BytecodePatch(listOf()) { +class FullscreenPanelsRemovalPatch : BytecodePatch( + listOf( + FullscreenViewAdderFingerprint + ) +) { override fun execute(data: BytecodeData): PatchResult { - val classDef = data.classes.first { it.type.endsWith("FullscreenEngagementPanelOverlay;") } - val method = data.proxy(classDef).resolve().methods.first { it.name == "" } + val method = FullscreenViewAdderFingerprint.result?.mutableMethod!! val implementation = method.implementation!! - method.addInstructions( - implementation.instructions.count() - 1, - """ - const/4 v1, 0x0 - iput-boolean v1, v0, ${classDef.type}->a:Z - """ - ) + val (visibilityCallIndex, visibilityCall) = + implementation.instructions.withIndex() + .first { ((it.value as? ReferenceInstruction)?.reference as? MethodReference)?.name == ("setVisibility") } + + val gotoIndex = + implementation.instructions.subList(0, visibilityCallIndex).indexOfLast { it.opcode == Opcode.GOTO } + + //force the if + method.removeInstruction(gotoIndex) + + val visibilityIntRegister = (visibilityCall as FiveRegisterInstruction).registerD + + //set the visibility to GONE + method.addInstruction(visibilityCallIndex - 1, "const/16 v$visibilityIntRegister, 0x8") return PatchResultSuccess() }