forked from ReVanced/revanced-patches-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
HideGetPremiumVideoAdvertisementPatch.kt
78 lines (71 loc) · 3.5 KB
/
HideGetPremiumVideoAdvertisementPatch.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package app.revanced.patches.youtube.ad.getpremium.bytecode.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.instruction
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.patches.shared.settings.preference.impl.StringResource
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
import app.revanced.patches.youtube.ad.getpremium.annotations.HideGetPremiumCompatibility
import app.revanced.patches.youtube.ad.getpremium.bytecode.fingerprints.GetPremiumViewFingerprint
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
@DependsOn([IntegrationsPatch::class, SettingsPatch::class])
@Name("hide-get-premium")
@HideGetPremiumCompatibility
@Version("0.0.1")
class HideGetPremiumPatch : BytecodePatch(listOf(GetPremiumViewFingerprint,)) {
override fun execute(context: BytecodeContext): PatchResult {
SettingsPatch.PreferenceScreen.ADS.addPreferences(
SwitchPreference(
"revanced_hide_get_premium",
StringResource(
"revanced_hide_get_premium_title",
"Hide YouTube Premium advertisement under video player"
),
StringResource(
"revanced_hide_get_premium_summary_on",
"YouTube Premium advertisement are hidden"
),
StringResource(
"revanced_hide_get_premium_summary_off",
"YouTube Premium advertisement are shown"
)
)
)
GetPremiumViewFingerprint.result?.let {
it.mutableMethod.apply {
val startIndex = it.scanResult.patternScanResult!!.startIndex
val measuredWidthRegister = instruction<TwoRegisterInstruction>(startIndex).registerA
val measuredHeightInstruction = instruction<TwoRegisterInstruction>(startIndex + 1)
val measuredHeightRegister = measuredHeightInstruction.registerA
val tempRegister = measuredHeightInstruction.registerB
addInstructions(
startIndex + 2,
"""
# Override the internal measurement of the layout with zero values.
invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->hideGetPremiumView()Z
move-result v$tempRegister
if-eqz v$tempRegister, :allow
const/4 v$measuredWidthRegister, 0x0
const/4 v$measuredHeightRegister, 0x0
:allow
nop
# Layout width/height is then passed to a protected class method.
"""
)
}
} ?: return GetPremiumViewFingerprint.toErrorResult()
return PatchResultSuccess()
}
private companion object {
const val INTEGRATIONS_CLASS_DESCRIPTOR =
"Lapp/revanced/integrations/patches/HideGetPremiumPatch;"
}
}