From a34aabe45425f26fa660419edac577d1445e6d35 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Sun, 16 Apr 2023 01:07:26 +0900 Subject: [PATCH] refactor: abstract integrations patch away from YouTube and YT Music --- .../integrations/patch/MusicIntegrationsPatch.kt | 2 -- .../patch/integrations/AbstractIntegrationsPatch.kt | 12 +++++++----- .../misc/integrations/patch/IntegrationsPatch.kt | 1 - 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/music/misc/integrations/patch/MusicIntegrationsPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/integrations/patch/MusicIntegrationsPatch.kt index df21983cc..5cc1c2e34 100644 --- a/src/main/kotlin/app/revanced/patches/music/misc/integrations/patch/MusicIntegrationsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/misc/integrations/patch/MusicIntegrationsPatch.kt @@ -5,12 +5,10 @@ import app.revanced.patcher.patch.annotations.RequiresIntegrations import app.revanced.patches.music.misc.integrations.fingerprints.InitFingerprint import app.revanced.patches.shared.patch.integrations.AbstractIntegrationsPatch import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility -import app.revanced.util.integrations.Constants.MUSIC_SETTINGS_PATH @Name("music-integrations") @YouTubeMusicCompatibility @RequiresIntegrations class MusicIntegrationsPatch : AbstractIntegrationsPatch( - "$MUSIC_SETTINGS_PATH", listOf(InitFingerprint), ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/shared/patch/integrations/AbstractIntegrationsPatch.kt b/src/main/kotlin/app/revanced/patches/shared/patch/integrations/AbstractIntegrationsPatch.kt index 4987d3636..ff9f21796 100644 --- a/src/main/kotlin/app/revanced/patches/shared/patch/integrations/AbstractIntegrationsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/shared/patch/integrations/AbstractIntegrationsPatch.kt @@ -10,12 +10,12 @@ import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultError import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.extensions.toErrorResult +import app.revanced.util.integrations.Constants.INTEGRATIONS_PATH import org.jf.dexlib2.iface.Method @Description("Applies mandatory patches to implement the ReVanced integrations into the application.") @Version("0.0.1") abstract class AbstractIntegrationsPatch( - private val integrationsDescriptor: String, private val hooks: Iterable ) : BytecodePatch(hooks) { /** @@ -29,14 +29,14 @@ abstract class AbstractIntegrationsPatch( customFingerprint: ((methodDef: Method) -> Boolean)? = null, private val contextRegisterResolver: (Method) -> Int = object : RegisterResolver {} ) : MethodFingerprint(strings = strings, customFingerprint = customFingerprint) { - fun invoke(integrationsDescriptor: String): PatchResult { + fun invoke(): PatchResult { result?.mutableMethod?.let { method -> val contextRegister = contextRegisterResolver(method) method.addInstruction( 0, "sput-object v$contextRegister, " + - "$integrationsDescriptor->context:Landroid/content/Context;" + "$INTEGRATIONS_CLASS_DESCRIPTOR->context:Landroid/content/Context;" ) } ?: return toErrorResult() return PatchResultSuccess() @@ -48,9 +48,9 @@ abstract class AbstractIntegrationsPatch( } override fun execute(context: BytecodeContext): PatchResult { - if (context.findClass(integrationsDescriptor) == null) return MISSING_INTEGRATIONS + if (context.findClass(INTEGRATIONS_CLASS_DESCRIPTOR) == null) return MISSING_INTEGRATIONS - for (hook in hooks) hook.invoke(integrationsDescriptor).let { + for (hook in hooks) hook.invoke().let { if (it is PatchResultError) return it } @@ -58,6 +58,8 @@ abstract class AbstractIntegrationsPatch( } private companion object { + const val INTEGRATIONS_CLASS_DESCRIPTOR = + "$INTEGRATIONS_PATH/utils/ReVancedUtils;" val MISSING_INTEGRATIONS = PatchResultError( "Integrations have not been merged yet. " + "This patch can not succeed without merging the integrations." diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/integrations/patch/IntegrationsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/integrations/patch/IntegrationsPatch.kt index 9f2a1a4e7..81f43fcea 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/integrations/patch/IntegrationsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/integrations/patch/IntegrationsPatch.kt @@ -10,6 +10,5 @@ import app.revanced.patches.youtube.misc.integrations.fingerprints.* @YouTubeCompatibility @RequiresIntegrations class IntegrationsPatch : AbstractIntegrationsPatch( - "Lapp/revanced/integrations/utils/ReVancedUtils;", listOf(InitFingerprint, StandalonePlayerFingerprint, ServiceFingerprint), ) \ No newline at end of file