diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hidecrowdfundingbox/annotations/CrowdfundingBoxCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hidecrowdfundingbox/annotations/CrowdfundingBoxCompatibility.kt new file mode 100644 index 000000000..65aa9d851 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hidecrowdfundingbox/annotations/CrowdfundingBoxCompatibility.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.youtube.layout.hidecrowdfundingbox.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility( + [Package( + "com.google.android.youtube", arrayOf("17.33.42", "17.34.35", "17.34.36", "17.36.37") + )] +) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class CrowdfundingBoxCompatibility diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hidecrowdfundingbox/fingerprints/CrowdfundingBoxFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hidecrowdfundingbox/fingerprints/CrowdfundingBoxFingerprint.kt new file mode 100644 index 000000000..2f8f48790 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hidecrowdfundingbox/fingerprints/CrowdfundingBoxFingerprint.kt @@ -0,0 +1,37 @@ +package app.revanced.patches.youtube.layout.hidecrowdfundingbox.fingerprints + +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.layout.hidecrowdfundingbox.annotations.CrowdfundingBoxCompatibility +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +@Name("crowdfunding-box-view-fingerprint") +@FuzzyPatternScanMethod(3) +@CrowdfundingBoxCompatibility +@Version("0.0.1") +object CrowdfundingBoxFingerprint : MethodFingerprint( + "V", + AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, + listOf("L", "L", "L", "L", "L", "L", "L", "[B", "[B"), + listOf( + Opcode.MOVE_OBJECT, + Opcode.MOVE_OBJECT_FROM16, + Opcode.INVOKE_DIRECT, + Opcode.MOVE_OBJECT_FROM16, + Opcode.IPUT_OBJECT, + Opcode.MOVE_OBJECT_FROM16, + Opcode.IPUT_OBJECT, + Opcode.IPUT_OBJECT, + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT_OBJECT, + Opcode.CONST_4, + Opcode.CONST_4, + Opcode.CONST, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hidecrowdfundingbox/patch/CrowdfundingBoxPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hidecrowdfundingbox/patch/CrowdfundingBoxPatch.kt new file mode 100644 index 000000000..ddc2a977f --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hidecrowdfundingbox/patch/CrowdfundingBoxPatch.kt @@ -0,0 +1,59 @@ +package app.revanced.patches.youtube.layout.hidecrowdfundingbox.patch + +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.addInstruction +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.patcher.patch.annotations.Patch +import app.revanced.patches.youtube.layout.hidecrowdfundingbox.annotations.CrowdfundingBoxCompatibility +import app.revanced.patches.youtube.layout.hidecrowdfundingbox.fingerprints.CrowdfundingBoxFingerprint +import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch +import app.revanced.patches.youtube.misc.mapping.patch.ResourceMappingResourcePatch +import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch +import app.revanced.patches.youtube.misc.settings.framework.components.impl.StringResource +import app.revanced.patches.youtube.misc.settings.framework.components.impl.SwitchPreference +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction + +@Patch +@DependsOn([IntegrationsPatch::class, SettingsPatch::class, ResourceMappingResourcePatch::class]) +@Name("hide-crowdfunding-box") +@Description("Hides the crowdfunding box between the player and video description.") +@CrowdfundingBoxCompatibility +@Version("0.0.1") +class CrowdfundingBoxPatch : BytecodePatch( + listOf( + CrowdfundingBoxFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( + SwitchPreference( + "revanced_hide_crowdfunding_box", + StringResource("revanced_hide_crowdfunding_box_title", "Hide the crowdfunding box"), + false, + StringResource("revanced_hide_crowdfunding_box_summary_on", "Crowdfunding box is hidden"), + StringResource("revanced_hide_crowdfunding_box_summary_off", "Crowdfunding box is visible") + ) + ) + + val crowdfundingBoxResult = CrowdfundingBoxFingerprint.result!! + val crowdfundingBoxMethod = crowdfundingBoxResult.mutableMethod + + val moveResultObjectIndex = crowdfundingBoxResult.scanResult.patternScanResult!!.endIndex + val patchIndex = moveResultObjectIndex + 1 + + crowdfundingBoxMethod.addInstruction( + patchIndex, """ + invoke-static {v${(crowdfundingBoxMethod.instruction(moveResultObjectIndex) as OneRegisterInstruction).registerA}}, Lapp/revanced/integrations/patches/HideCrowdfundingBoxPatch;->hideCrowdfundingBox(Landroid/view/View;)V + """ + ) + + return PatchResultSuccess() + } +}