feat(youtube): add hide-latest-videos-button patch

This commit is contained in:
inotia00
2023-08-03 12:52:51 +09:00
parent 350e51691c
commit ab663b8820
5 changed files with 93 additions and 0 deletions

View File

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

View File

@ -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<OneRegisterInstruction>(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()
}
}

View File

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