diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/pivotbar/shortspivotbar/fingerprints/ReelWatchBundleFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/pivotbar/shortspivotbar/fingerprints/ReelWatchBundleFingerprint.kt new file mode 100644 index 000000000..5405308e0 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/pivotbar/shortspivotbar/fingerprints/ReelWatchBundleFingerprint.kt @@ -0,0 +1,15 @@ +package app.revanced.patches.youtube.layout.general.pivotbar.shortspivotbar.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.Opcode + +object ReelWatchBundleFingerprint : MethodFingerprint( + returnType = "V", + opcodes = listOf( + Opcode.CHECK_CAST, + Opcode.IGET_OBJECT, + Opcode.CONST_STRING, + Opcode.INVOKE_VIRTUAL + ), + strings = listOf("r_as") +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/pivotbar/shortspivotbar/fingerprints/ReelWatchEndpointFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/pivotbar/shortspivotbar/fingerprints/ReelWatchEndpointFingerprint.kt new file mode 100644 index 000000000..19a47822d --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/pivotbar/shortspivotbar/fingerprints/ReelWatchEndpointFingerprint.kt @@ -0,0 +1,8 @@ +package app.revanced.patches.youtube.layout.general.pivotbar.shortspivotbar.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +object ReelWatchEndpointFingerprint : MethodFingerprint( + returnType = "V", + customFingerprint = { it.name == "" } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/pivotbar/shortspivotbar/fingerprints/ReelWatchEndpointParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/pivotbar/shortspivotbar/fingerprints/ReelWatchEndpointParentFingerprint.kt new file mode 100644 index 000000000..54b48a145 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/pivotbar/shortspivotbar/fingerprints/ReelWatchEndpointParentFingerprint.kt @@ -0,0 +1,8 @@ +package app.revanced.patches.youtube.layout.general.pivotbar.shortspivotbar.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +object ReelWatchEndpointParentFingerprint : MethodFingerprint( + returnType = "V", + strings = listOf("Error parsing bytes for updated ReelWatchEndpoint.", "r_aoc") +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/pivotbar/shortspivotbar/fingerprints/SetPivotBarFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/pivotbar/shortspivotbar/fingerprints/SetPivotBarFingerprint.kt new file mode 100644 index 000000000..8e6e6e7a1 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/pivotbar/shortspivotbar/fingerprints/SetPivotBarFingerprint.kt @@ -0,0 +1,16 @@ +package app.revanced.patches.youtube.layout.general.pivotbar.shortspivotbar.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +object SetPivotBarFingerprint : MethodFingerprint( + returnType = "V", + access = AccessFlags.PRIVATE or AccessFlags.FINAL, + parameters = listOf("Z"), + opcodes = listOf( + Opcode.CHECK_CAST, + Opcode.IF_EQZ + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/pivotbar/shortspivotbar/patch/ShortsPivotBarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/pivotbar/shortspivotbar/patch/ShortsPivotBarPatch.kt new file mode 100644 index 000000000..6f24c2cae --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/pivotbar/shortspivotbar/patch/ShortsPivotBarPatch.kt @@ -0,0 +1,100 @@ +package app.revanced.patches.youtube.layout.general.pivotbar.shortspivotbar.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.data.toMethodWalker +import app.revanced.patcher.extensions.addInstruction +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.proxy.mutableTypes.MutableMethod +import app.revanced.patches.shared.annotation.YouTubeCompatibility +import app.revanced.patches.shared.fingerprints.PivotBarCreateButtonViewFingerprint +import app.revanced.patches.youtube.layout.general.pivotbar.shortspivotbar.fingerprints.* +import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch +import app.revanced.util.integrations.Constants.GENERAL_LAYOUT +import org.jf.dexlib2.dexbacked.reference.DexBackedTypeReference +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction +import org.jf.dexlib2.iface.instruction.ReferenceInstruction + +@Patch +@Name("hide-shorts-pivot-bar") +@Description("Hides the pivotbar when playing shorts.") +@DependsOn([SettingsPatch::class]) +@YouTubeCompatibility +@Version("0.0.1") +class ShortsPivotBarPatch : BytecodePatch( + listOf( + PivotBarCreateButtonViewFingerprint, + ReelWatchBundleFingerprint, + ReelWatchEndpointParentFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + + PivotBarCreateButtonViewFingerprint.result?.let { parentResult -> + SetPivotBarFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let { + with (it.mutableMethod) { + val startIndex = it.scanResult.patternScanResult!!.startIndex + val instructions = implementation!!.instructions + + val indexReference = ((instructions[startIndex] as ReferenceInstruction).reference as DexBackedTypeReference).toString() + if (indexReference != targetReference) return SetPivotBarFingerprint.toErrorResult() + val register = (instructions[startIndex] as OneRegisterInstruction).registerA + + addInstruction( + startIndex + 1, + "sput-object v$register, $GENERAL_LAYOUT->pivotbar:$targetReference" + ) + } + } ?: return SetPivotBarFingerprint.toErrorResult() + } ?: return PivotBarCreateButtonViewFingerprint.toErrorResult() + + ReelWatchBundleFingerprint.result?.let { + with (context + .toMethodWalker(it.method) + .nextMethod(it.scanResult.patternScanResult!!.endIndex, true) + .getMethod() as MutableMethod + ) { + addInstruction( + 0, + "invoke-static {}, $GENERAL_LAYOUT->hideShortsPlayerPivotBar()V" + ) + } + } ?: return ReelWatchBundleFingerprint.toErrorResult() + + ReelWatchEndpointParentFingerprint.result?.let { parentResult -> + ReelWatchEndpointFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.mutableMethod?.addInstruction( + 0, + "sput-object p1, $GENERAL_LAYOUT->shortsContext:Landroid/content/Context;" + ) ?: return ReelWatchEndpointFingerprint.toErrorResult() + } ?: return ReelWatchEndpointParentFingerprint.toErrorResult() + + /* + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "PREFERENCE: GENERAL_LAYOUT_SETTINGS", + "SETTINGS: SHORTS_COMPONENT.PARENT", + "SETTINGS: SHORTS_COMPONENT_PARENT.B", + "SETTINGS: HIDE_SHORTS_PLAYER_PIVOT_BAR" + ) + ) + + SettingsPatch.updatePatchStatus("hide-shorts-pivot-bar") + + return PatchResultSuccess() + } + + private companion object { + const val targetReference = + "Lcom/google/android/apps/youtube/app/ui/pivotbar/PivotBar;" + } +} \ No newline at end of file diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 44da6fa15..090d11e5d 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -411,6 +411,9 @@ Is it ready to submit?" Shorts player join button is shown Shorts player join button is hidden Hide shorts player join button + Shorts player pivotbar is shown + Shorts player pivotbar is hidden + Hide shorts player pivotbar Shorts player subscriptions button is shown Shorts player subscriptions button is hidden Hide shorts player subscriptions button diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 038dfbceb..f5277b1ce 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -82,6 +82,10 @@ SETTINGS: HIDE_SHORTS_COMPONENTS --> + + @@ -393,6 +397,7 @@ +