diff --git a/src/main/kotlin/app/revanced/patches/youtube/interaction/swipecontrols/patch/bytecode/SwipeControlsBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/interaction/swipecontrols/patch/bytecode/SwipeControlsBytecodePatch.kt index 19522ed95..60f9aa77d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/interaction/swipecontrols/patch/bytecode/SwipeControlsBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/interaction/swipecontrols/patch/bytecode/SwipeControlsBytecodePatch.kt @@ -14,7 +14,7 @@ import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable import app.revanced.patches.youtube.interaction.swipecontrols.annotation.SwipeControlsCompatibility import app.revanced.patches.youtube.interaction.swipecontrols.fingerprints.SwipeControlsHostActivityFingerprint -import app.revanced.patches.youtube.interaction.swipecontrols.fingerprints.WatchWhileActivityFingerprint +import app.revanced.shared.fingerprints.WatchWhileActivityFingerprint import app.revanced.patches.youtube.interaction.swipecontrols.patch.resource.SwipeControlsResourcePatch import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.youtube.misc.playertype.patch.PlayerTypeHookPatch diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt index 41cf0a838..f309d7bc4 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt @@ -4,10 +4,13 @@ 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.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.shared.fingerprints.WatchWhileActivityFingerprint import app.revanced.patches.youtube.layout.castbutton.patch.HideCastButtonPatch import app.revanced.patches.youtube.misc.clientspoof.patch.ClientSpoofPatch import app.revanced.patches.youtube.misc.microg.annotations.MicroGPatchCompatibility @@ -38,9 +41,10 @@ class MicroGBytecodePatch : BytecodePatch( CastDynamiteModuleV2Fingerprint, CastContextFetchFingerprint, PrimeFingerprint, + WatchWhileActivityFingerprint ) ) { - override fun execute(context: BytecodeContext) = + override fun execute(context: BytecodeContext): PatchResult { // apply common microG patch MicroGBytecodeHelper.patchBytecode( context, arrayOf( @@ -62,5 +66,11 @@ class MicroGBytecodePatch : BytecodePatch( CastDynamiteModuleV2Fingerprint, CastContextFetchFingerprint ) - ).let { PatchResultSuccess() } + ) + + // inject the notice for MicroG + MicroGBytecodeHelper.injectNotice(WatchWhileActivityFingerprint) + + return PatchResultSuccess() + } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/resource/MicroGResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/resource/MicroGResourcePatch.kt index feb3fc59b..6d747a448 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/resource/MicroGResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/resource/MicroGResourcePatch.kt @@ -53,6 +53,10 @@ class MicroGResourcePatch : ResourcePatch { SPOOFED_PACKAGE_NAME, SPOOFED_PACKAGE_SIGNATURE ) + + // add strings + MicroGResourceHelper.addStrings(context) + return PatchResultSuccess() } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/interaction/swipecontrols/fingerprints/WatchWhileActivityFingerprint.kt b/src/main/kotlin/app/revanced/shared/fingerprints/WatchWhileActivityFingerprint.kt similarity index 87% rename from src/main/kotlin/app/revanced/patches/youtube/interaction/swipecontrols/fingerprints/WatchWhileActivityFingerprint.kt rename to src/main/kotlin/app/revanced/shared/fingerprints/WatchWhileActivityFingerprint.kt index d587cffb1..24256f19c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/interaction/swipecontrols/fingerprints/WatchWhileActivityFingerprint.kt +++ b/src/main/kotlin/app/revanced/shared/fingerprints/WatchWhileActivityFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.interaction.swipecontrols.fingerprints +package app.revanced.shared.fingerprints import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version diff --git a/src/main/kotlin/app/revanced/util/microg/MicroGBytecodeHelper.kt b/src/main/kotlin/app/revanced/util/microg/MicroGBytecodeHelper.kt index 6b7d68d41..b4b4038cb 100644 --- a/src/main/kotlin/app/revanced/util/microg/MicroGBytecodeHelper.kt +++ b/src/main/kotlin/app/revanced/util/microg/MicroGBytecodeHelper.kt @@ -1,6 +1,7 @@ package app.revanced.util.microg import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint @@ -20,6 +21,17 @@ import org.jf.dexlib2.immutable.reference.ImmutableStringReference * Helper class for applying bytecode patches needed for the microg-support patches. */ internal object MicroGBytecodeHelper { + /** + * Hook a method to check the availability of MicroG. + * + * @param fingerprint The fingerprint of the method to add the call for the notice in. + */ + fun injectNotice(fingerprint: MethodFingerprint) { + fingerprint.result!!.mutableMethod.addInstruction( + 0, + "invoke-static {}, Lapp/revanced/integrations/patches/MicroGSupport;->checkAvailability()V" + ) + } /** * Transform strings with package name out of [fromPackageName] and [toPackageName]. diff --git a/src/main/kotlin/app/revanced/util/microg/MicroGResourceHelper.kt b/src/main/kotlin/app/revanced/util/microg/MicroGResourceHelper.kt index f3ab36f6d..6c8af526b 100644 --- a/src/main/kotlin/app/revanced/util/microg/MicroGResourceHelper.kt +++ b/src/main/kotlin/app/revanced/util/microg/MicroGResourceHelper.kt @@ -1,16 +1,26 @@ package app.revanced.util.microg import app.revanced.patcher.data.ResourceContext +import app.revanced.util.resources.ResourceUtils.Settings.mergeStrings /** * Helper class for applying resource patches needed for the microg-support patches. */ internal object MicroGResourceHelper { + + /** + * Add necessary strings to the strings.xml file. + * + * @param context The resource context. + * @param stringsHost The file which hosts the strings. + */ + fun addStrings(context: ResourceContext, stringsHost: String = "microg/host/values/strings.xml") = context.mergeStrings(stringsHost) + /** * Patch the manifest to work with MicroG. * - * @param context Bytecode context. - * @param fromPackageName Original package name. + * @param context The resource context. + * @param fromPackageName The original package name. * @param toPackageName The package name to accept. * @param toName The new name of the app. */ diff --git a/src/main/resources/microg/host/values/strings.xml b/src/main/resources/microg/host/values/strings.xml new file mode 100644 index 000000000..c5c1f69bd --- /dev/null +++ b/src/main/resources/microg/host/values/strings.xml @@ -0,0 +1,4 @@ + + + Vanced MicroG is not installed. Please install it. +