mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-28 12:50:19 +02:00
refactor(hide-account-menu
): now you can remove the 'Your videos' and 'Downloads' menus in the library tab
This commit is contained in:
parent
e5c112a94b
commit
781df4ef8d
@ -0,0 +1,14 @@
|
||||
package app.revanced.patches.youtube.layout.general.accountmenu.fingerprints
|
||||
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import org.jf.dexlib2.Opcode
|
||||
|
||||
object LibraryMenuFingerprint : MethodFingerprint(
|
||||
returnType = "V",
|
||||
parameters = listOf("L", "L"),
|
||||
opcodes = listOf(
|
||||
Opcode.INVOKE_STATIC,
|
||||
Opcode.MOVE_RESULT_OBJECT,
|
||||
Opcode.IGET_OBJECT
|
||||
)
|
||||
)
|
@ -0,0 +1,21 @@
|
||||
package app.revanced.patches.youtube.layout.general.accountmenu.fingerprints
|
||||
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
|
||||
import org.jf.dexlib2.Opcode
|
||||
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
|
||||
|
||||
object LibraryMenuParentFingerprint : MethodFingerprint(
|
||||
opcodes = listOf(
|
||||
Opcode.CONST,
|
||||
Opcode.CONST_4,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
Opcode.MOVE_RESULT_OBJECT
|
||||
),
|
||||
customFingerprint = { methodDef ->
|
||||
methodDef.implementation?.instructions?.any {
|
||||
it.opcode.ordinal == Opcode.CONST.ordinal &&
|
||||
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.compactListLabelId
|
||||
} == true
|
||||
}
|
||||
)
|
@ -8,14 +8,14 @@ import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.addInstruction
|
||||
import app.revanced.patcher.extensions.instruction
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
|
||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult
|
||||
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.shared.annotation.YouTubeCompatibility
|
||||
import app.revanced.patches.youtube.layout.general.accountmenu.fingerprints.AccountMenuFingerprint
|
||||
import app.revanced.patches.youtube.layout.general.accountmenu.fingerprints.AccountMenuParentFingerprint
|
||||
import app.revanced.patches.youtube.layout.general.accountmenu.fingerprints.*
|
||||
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
|
||||
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
|
||||
import app.revanced.util.integrations.Constants.GENERAL_LAYOUT
|
||||
@ -34,35 +34,24 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
@Version("0.0.1")
|
||||
class AccountMenuPatch : BytecodePatch(
|
||||
listOf(
|
||||
AccountMenuParentFingerprint
|
||||
AccountMenuParentFingerprint,
|
||||
LibraryMenuParentFingerprint
|
||||
)
|
||||
) {
|
||||
override fun execute(context: BytecodeContext): PatchResult {
|
||||
|
||||
AccountMenuParentFingerprint.result?.let { parentResult ->
|
||||
AccountMenuFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let {
|
||||
with (it.mutableMethod) {
|
||||
val targetIndex = it.scanResult.patternScanResult!!.startIndex + 1
|
||||
val register = (instruction(targetIndex) as OneRegisterInstruction).registerA
|
||||
|
||||
addInstruction(
|
||||
targetIndex + 1,
|
||||
"invoke-static {v$register}, $GENERAL_LAYOUT->hideAccountMenu(Landroid/text/Spanned;)V"
|
||||
)
|
||||
}
|
||||
insert(parentResult, it, "hideAccountMenu", "compactLink")
|
||||
} ?: return AccountMenuFingerprint.toErrorResult()
|
||||
|
||||
with (parentResult.mutableMethod) {
|
||||
val endIndex = parentResult.scanResult.patternScanResult!!.endIndex
|
||||
val register = (instruction(endIndex) as OneRegisterInstruction).registerA
|
||||
|
||||
addInstruction(
|
||||
endIndex + 1,
|
||||
"sput-object v$register, $GENERAL_LAYOUT->compactLink:Landroid/view/View;"
|
||||
)
|
||||
}
|
||||
} ?: return AccountMenuParentFingerprint.toErrorResult()
|
||||
|
||||
LibraryMenuParentFingerprint.result?.let { parentResult ->
|
||||
LibraryMenuFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let {
|
||||
insert(parentResult, it, "hideLibraryMenu", "libraryList")
|
||||
} ?: return LibraryMenuFingerprint.toErrorResult()
|
||||
} ?: return LibraryMenuParentFingerprint.toErrorResult()
|
||||
|
||||
/*
|
||||
* Add settings
|
||||
*/
|
||||
@ -77,4 +66,32 @@ class AccountMenuPatch : BytecodePatch(
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
private companion object {
|
||||
fun insert(
|
||||
viewResult: MethodFingerprintResult,
|
||||
spanResult: MethodFingerprintResult,
|
||||
targetMethod: String,
|
||||
targetField: String
|
||||
) {
|
||||
with (spanResult.mutableMethod) {
|
||||
val targetIndex = spanResult.scanResult.patternScanResult!!.startIndex + 1
|
||||
val register = (instruction(targetIndex) as OneRegisterInstruction).registerA
|
||||
|
||||
addInstruction(
|
||||
targetIndex + 1,
|
||||
"invoke-static {v$register}, $GENERAL_LAYOUT->$targetMethod(Landroid/text/Spanned;)V"
|
||||
)
|
||||
}
|
||||
|
||||
with (viewResult.mutableMethod) {
|
||||
val endIndex = viewResult.scanResult.patternScanResult!!.endIndex
|
||||
val register = (instruction(endIndex) as OneRegisterInstruction).registerA
|
||||
|
||||
addInstruction(
|
||||
endIndex + 1,
|
||||
"sput-object v$register, $GENERAL_LAYOUT->$targetField:Landroid/view/View;"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ class SharedResourceIdPatch : ResourcePatch {
|
||||
var bottomUiContainerResourceId: Long = -1
|
||||
var chapterRepeatOnResourceId: Long = -1
|
||||
var compactLinkLabelId: Long = -1
|
||||
var compactListLabelId: Long = -1
|
||||
var controlsLayoutStubResourceId: Long = -1
|
||||
var donationCompanionResourceId: Long = -1
|
||||
var emptyColorLabelId: Long = -1
|
||||
@ -56,6 +57,7 @@ class SharedResourceIdPatch : ResourcePatch {
|
||||
bottomUiContainerResourceId = findSharedResourceId("id", "bottom_ui_container_stub")
|
||||
chapterRepeatOnResourceId = findSharedResourceId("string", "chapter_repeat_on")
|
||||
compactLinkLabelId = findSharedResourceId("layout", "compact_link")
|
||||
compactListLabelId = findSharedResourceId("layout", "compact_list_item")
|
||||
controlsLayoutStubResourceId = findSharedResourceId("id", "controls_layout_stub")
|
||||
donationCompanionResourceId = findSharedResourceId("layout", "donation_companion")
|
||||
emptyColorLabelId = findSharedResourceId("color", "inline_time_bar_colorized_bar_empty_color_dark")
|
||||
|
Loading…
x
Reference in New Issue
Block a user