diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/latestvideosbutton/fingerprints/LatestVideosButtonFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/general/latestvideosbutton/fingerprints/LatestVideosButtonFingerprint.kt new file mode 100644 index 000000000..4f01f9608 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/general/latestvideosbutton/fingerprints/LatestVideosButtonFingerprint.kt @@ -0,0 +1,21 @@ +package app.revanced.patches.youtube.general.latestvideosbutton.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.Bar +import app.revanced.util.bytecode.isWideLiteralExists +import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.Opcode + +object LatestVideosButtonFingerprint : MethodFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("L", "Z"), + opcodes = listOf( + Opcode.CONST, + Opcode.IGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT + ), + customFingerprint = { methodDef, _ -> methodDef.isWideLiteralExists(Bar) } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/latestvideosbutton/patch/LatestVideosButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/latestvideosbutton/patch/LatestVideosButtonPatch.kt new file mode 100644 index 000000000..f99ef20b6 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/general/latestvideosbutton/patch/LatestVideosButtonPatch.kt @@ -0,0 +1,63 @@ +package app.revanced.patches.youtube.general.latestvideosbutton.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.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +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.patches.youtube.general.latestvideosbutton.fingerprints.LatestVideosButtonFingerprint +import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility +import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch +import app.revanced.util.integrations.Constants.GENERAL +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction + +@Patch +@Name("Hide latest videos button") +@Description("Hides latest videos button in home feed.") +@DependsOn( + [ + SettingsPatch::class, + SharedResourceIdPatch::class, + ] +) +@YouTubeCompatibility +@Version("0.0.1") +class LatestVideosButtonPatch : BytecodePatch( + listOf(LatestVideosButtonFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + LatestVideosButtonFingerprint.result?.let { + it.mutableMethod.apply { + val targetIndex = it.scanResult.patternScanResult!!.endIndex + val targetRegister = getInstruction(targetIndex).registerA + + addInstruction( + targetIndex + 1, + "invoke-static {v$targetRegister}, $GENERAL->hideLatestVideosButton(Landroid/view/View;)V" + ) + } + } ?: return LatestVideosButtonFingerprint.toErrorResult() + + /** + * Add settings + */ + SettingsPatch.addPreference( + arrayOf( + "PREFERENCE: GENERAL_SETTINGS", + "SETTINGS: HIDE_LATEST_VIDEOS_BUTTON" + ) + ) + + SettingsPatch.updatePatchStatus("hide-latest-videos-button") + + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/patch/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/patch/SharedResourceIdPatch.kt index f66f618f2..6fb7aa2b0 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/patch/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/patch/SharedResourceIdPatch.kt @@ -28,6 +28,7 @@ class SharedResourceIdPatch : ResourcePatch { var AutoNavPreviewStub: Long = -1 var AutoNavToggle: Long = -1 var BackgroundCategory: Long = -1 + var Bar: Long = -1 var BarContainerHeight: Long = -1 var BottomPanelOverlayText: Long = -1 var BottomSheetMargins: Long = -1 @@ -101,6 +102,7 @@ class SharedResourceIdPatch : ResourcePatch { AutoNavPreviewStub = find(ID, "autonav_preview_stub") AutoNavToggle = find(ID, "autonav_toggle") BackgroundCategory = find(STRING, "pref_background_and_offline_category") + Bar = find(LAYOUT, "bar") BarContainerHeight = find(DIMEN, "bar_container_height") BottomPanelOverlayText = find(ID, "bottom_panel_overlay_text") BottomSheetMargins = find(DIMEN, "bottom_sheet_margins") diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 91b9f51d4..baa71d9ad 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -338,6 +338,9 @@ Library button is shown Library button is hidden Hide library button + Latest videos button is shown + Latest videos button is hidden + Hide latest videos button Load more button is shown Load more button is hidden Hide load more button diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index a94d7bdb4..99bb840bc 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -169,6 +169,9 @@ + + @@ -326,6 +329,7 @@ +