feat(youtube/microg-support): handle availability of Vanced MicroG

This commit is contained in:
oSumAtrIX 2022-10-29 03:03:47 +02:00
parent 6d66aed26c
commit bfd0d1418f
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
7 changed files with 46 additions and 6 deletions

View File

@ -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

View File

@ -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()
}
}

View File

@ -53,6 +53,10 @@ class MicroGResourcePatch : ResourcePatch {
SPOOFED_PACKAGE_NAME,
SPOOFED_PACKAGE_SIGNATURE
)
// add strings
MicroGResourceHelper.addStrings(context)
return PatchResultSuccess()
}
}

View File

@ -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

View File

@ -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].

View File

@ -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.
*/

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="microg_not_installed_warning">Vanced MicroG is not installed. Please install it.</string>
</resources>