feat(youtube/hide-button-container): now it support versions other than YouTube v18.20.39 https://github.com/ReVanced/revanced-patches/pull/2723

This commit is contained in:
inotia00
2023-08-05 07:27:50 +09:00
parent d8a10fecf5
commit 1fbb5c4bee
10 changed files with 33 additions and 146 deletions

View File

@ -28,16 +28,6 @@ import app.revanced.util.integrations.Constants.PATCHES_PATH
class ButtonContainerPatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
if (SettingsPatch.below1820) {
LithoFilterPatch.addFilter("$PATCHES_PATH/ads/ActionButtonsFilter;")
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: BOTTOM_PLAYER_SETTINGS",
"SETTINGS: EXPERIMENTAL_BUTTON_CONTAINER"
)
)
}
LithoFilterPatch.addFilter("$PATCHES_PATH/ads/ButtonsFilter;")
/**

View File

@ -0,0 +1,13 @@
package app.revanced.patches.youtube.utils.litho.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import com.android.tools.smali.dexlib2.Opcode
object GeneralByteBufferFingerprint : MethodFingerprint(
returnType = "L",
opcodes = listOf(
Opcode.ADD_INT_2ADDR,
Opcode.INVOKE_VIRTUAL
),
strings = listOf("Unssuported TextDecorator adjustment. Extension: %s")
)

View File

@ -5,7 +5,7 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
object ByteBufferFingerprint : MethodFingerprint(
object LowLevelByteBufferFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
parameters = listOf("L", "L"),

View File

@ -3,6 +3,7 @@ package app.revanced.patches.youtube.utils.litho.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.data.toMethodWalker
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.removeInstructions
@ -11,12 +12,13 @@ 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.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.shared.patch.litho.ComponentParserPatch
import app.revanced.patches.shared.patch.litho.ComponentParserPatch.Companion.generalHook
import app.revanced.patches.shared.patch.litho.ComponentParserPatch.Companion.legacyHook
import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility
import app.revanced.patches.youtube.utils.litho.fingerprints.ByteBufferFingerprint
import app.revanced.patches.youtube.utils.litho.fingerprints.GeneralByteBufferFingerprint
import app.revanced.patches.youtube.utils.litho.fingerprints.LithoFilterFingerprint
import app.revanced.patches.youtube.utils.litho.fingerprints.LowLevelByteBufferFingerprint
import app.revanced.patches.youtube.utils.playertype.patch.PlayerTypeHookPatch
import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.ADS_PATH
@ -33,22 +35,33 @@ import java.io.Closeable
@Version("0.0.1")
class LithoFilterPatch : BytecodePatch(
listOf(
ByteBufferFingerprint,
LithoFilterFingerprint
GeneralByteBufferFingerprint,
LithoFilterFingerprint,
LowLevelByteBufferFingerprint
)
), Closeable {
override fun execute(context: BytecodeContext): PatchResult {
ByteBufferFingerprint.result?.mutableMethod?.addInstruction(
LowLevelByteBufferFingerprint.result?.mutableMethod?.addInstruction(
0,
"sput-object p0, $ADS_PATH/LowLevelFilter;->byteBuffer:Ljava/nio/ByteBuffer;"
) ?: return ByteBufferFingerprint.toErrorResult()
"invoke-static { p0 }, $ADS_PATH/LowLevelFilter;->setProtoBuffer(Ljava/nio/ByteBuffer;)V"
) ?: return LowLevelByteBufferFingerprint.toErrorResult()
if (SettingsPatch.below1820)
legacyHook("$ADS_PATH/LithoFilterPatch;->filters")
else
generalHook("$ADS_PATH/LithoFilterPatch;->filters")
GeneralByteBufferFingerprint.result?.let {
(context
.toMethodWalker(it.method)
.nextMethod(it.scanResult.patternScanResult!!.endIndex, true)
.getMethod() as MutableMethod
).apply {
addInstruction(
0,
"invoke-static { p2 }, $ADS_PATH/LithoFilterPatch;->setProtoBuffer(Ljava/nio/ByteBuffer;)V"
)
}
} ?: return GeneralByteBufferFingerprint.toErrorResult()
generalHook("$ADS_PATH/LithoFilterPatch;->filters")
LithoFilterFingerprint.result?.mutableMethod?.apply {
removeInstructions(2, 4) // Remove dummy filter.

View File

@ -74,7 +74,6 @@ class SettingsPatch : AbstractSettingsResourcePatch(
val playServicesVersion = node.textContent.toInt()
below1820 = playServicesVersion <= 232100000
upward1828 = playServicesVersion >= 232900000
break
@ -184,7 +183,6 @@ class SettingsPatch : AbstractSettingsResourcePatch(
private val threadPoolExecutor = Executors.newFixedThreadPool(THREAD_COUNT)
internal lateinit var contexts: ResourceContext
internal var below1820: Boolean = false
internal var upward1828: Boolean = false
internal fun addPreference(settingArray: Array<String>) {