Skip to content

Commit

Permalink
feat(youtube/microg-support): handle availability of Vanced MicroG
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Oct 29, 2022
1 parent 45ce4a2 commit 81db614
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -62,5 +66,11 @@ class MicroGBytecodePatch : BytecodePatch(
CastDynamiteModuleV2Fingerprint,
CastContextFetchFingerprint
)
).let { PatchResultSuccess() }
)

// inject the notice for MicroG
MicroGBytecodeHelper.injectNotice(WatchWhileActivityFingerprint)

return PatchResultSuccess()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class MicroGResourcePatch : ResourcePatch {
SPOOFED_PACKAGE_NAME,
SPOOFED_PACKAGE_SIGNATURE
)

// add strings
MicroGResourceHelper.addStrings(context)

return PatchResultSuccess()
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/main/kotlin/app/revanced/util/microg/MicroGBytecodeHelper.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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].
Expand Down
14 changes: 12 additions & 2 deletions src/main/kotlin/app/revanced/util/microg/MicroGResourceHelper.kt
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/microg/host/values/strings.xml
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 81db614

Please sign in to comment.