Skip to content

Commit

Permalink
fix(YouTube): Fix video playback by switching to ReVanced GmsCore vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Mar 24, 2024
1 parent dfd80a9 commit 1967547
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ abstract class BaseGmsCoreSupportPatch(
) : BytecodePatch(
name = "GmsCore support",
description = "Allows patched Google apps to run without root and under a different package name " +
"by using GmsCore instead of Google Play Services.",
"by using GmsCore instead of Google Play Services.",
dependencies = setOf(
ChangePackageNamePatch::class,
gmsCoreSupportResourcePatch::class,
integrationsPatchDependency
integrationsPatchDependency,
) + dependencies,
compatiblePackages = compatiblePackages,
fingerprints = setOf(GmsCoreSupportFingerprint, mainActivityOnCreateFingerprint) + fingerprints,
requiresIntegrations = true
requiresIntegrations = true,
) {
init {
// Manually register all options of the resource patch so that they are visible in the patch API.
Expand All @@ -77,7 +77,7 @@ abstract class BaseGmsCoreSupportPatch(
val transformations = arrayOf(
::commonTransform,
::contentUrisTransform,
packageNameTransform(fromPackageName, packageName)
packageNameTransform(fromPackageName, packageName),
)
context.transformStringReferences transform@{ string ->
transformations.forEach { transform ->
Expand All @@ -96,7 +96,7 @@ abstract class BaseGmsCoreSupportPatch(
// Check the availability of GmsCore.
mainActivityOnCreateFingerprint.result?.mutableMethod?.addInstruction(
1, // Hack to not disturb other patches (such as the integrations patch).
"invoke-static {}, Lapp/revanced/integrations/youtube/patches/GmsCoreSupport;->checkAvailability()V"
"invoke-static {}, Lapp/revanced/integrations/youtube/patches/GmsCoreSupport;->checkAvailability()V",
) ?: throw mainActivityOnCreateFingerprint.exception

// Change the vendor of GmsCore in ReVanced Integrations.
Expand Down Expand Up @@ -130,8 +130,8 @@ abstract class BaseGmsCoreSupportPatch(
BuilderInstruction21c(
Opcode.CONST_STRING,
instruction.registerA,
ImmutableStringReference(transformedString)
)
ImmutableStringReference(transformedString),
),
)
}
}
Expand All @@ -145,7 +145,8 @@ abstract class BaseGmsCoreSupportPatch(
"com.google.android.gms",
in PERMISSIONS,
in ACTIONS,
in AUTHORITIES -> referencedString.replace("com.google", gmsCoreVendor!!)
in AUTHORITIES,
-> referencedString.replace("com.google", gmsCoreVendor!!)

// No vendor prefix for whatever reason...
"subscribedfeeds" -> "$gmsCoreVendor.subscribedfeeds"
Expand All @@ -161,7 +162,7 @@ abstract class BaseGmsCoreSupportPatch(
if (str.startsWith(uriPrefix)) {
return str.replace(
uriPrefix,
"content://${authority.replace("com.google", gmsCoreVendor!!)}"
"content://${authority.replace("com.google", gmsCoreVendor!!)}",
)
}
}
Expand All @@ -174,13 +175,13 @@ abstract class BaseGmsCoreSupportPatch(
}

return null

}

private fun packageNameTransform(fromPackageName: String, toPackageName: String): (String) -> String? = { string ->
when (string) {
"$fromPackageName.SuggestionsProvider",
"$fromPackageName.fileprovider" -> string.replace(fromPackageName, toPackageName)
"$fromPackageName.fileprovider",
-> string.replace(fromPackageName, toPackageName)

else -> null
}
Expand Down Expand Up @@ -273,6 +274,9 @@ abstract class BaseGmsCoreSupportPatch(
// fido
"com.google.android.gms.fido.fido2.privileged.START",

// gass
"com.google.android.gms.gass.START",

// games
"com.google.android.gms.games.service.START",
"com.google.android.gms.games.PLAY_GAMES_UPGRADE",
Expand All @@ -292,8 +296,18 @@ abstract class BaseGmsCoreSupportPatch(
// misc
"com.google.android.gms.gmscompliance.service.START",
"com.google.android.gms.oss.licenses.service.START",
"com.google.android.gms.tapandpay.service.BIND",
"com.google.android.gms.measurement.START",
"com.google.android.gms.languageprofile.service.START",
"com.google.android.gms.clearcut.service.START",
"com.google.android.gms.icing.LIGHTWEIGHT_INDEX_SERVICE",

// potoken
"com.google.android.gms.potokens.service.START",

// droidguard/ safetynet
"com.google.android.gms.droidguard.service.START",
"com.google.android.gms.safetynet.service.START",
"com.google.android.gms.tapandpay.service.BIND"
)

/**
Expand All @@ -314,9 +328,9 @@ abstract class BaseGmsCoreSupportPatch(
"com.google.android.gms.fonts",

// phenotype
"com.google.android.gms.phenotype"
"com.google.android.gms.phenotype",
)
}

// endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ abstract class BaseGmsCoreSupportResourcePatch(
internal val gmsCoreVendorOption =
stringPatchOption(
key = "gmsCoreVendor",
default = "com.mgoogle",
default = "app.revanced",
values =
mapOf(
"Vanced" to "com.mgoogle",
"ReVanced" to "app.revanced",
),
title = "GmsCore Vendor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference

@Patch(
name = "Client spoof",
description = "Adds options to spoof the client to allow video playback.",
dependencies = [SpoofSignaturePatch::class],
description = "Spoofs the client to allow video playback.",
compatiblePackages = [
CompatiblePackage("com.google.android.youtube"),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,11 @@ import app.revanced.patches.shared.misc.settings.preference.PreferenceScreen
import app.revanced.patches.shared.misc.settings.preference.PreferenceScreen.Sorting
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.*
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.ParamsMapPutFingerprint
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.PlayerResponseModelImplGeneralFingerprint
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.PlayerResponseModelImplLiveStreamFingerprint
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.PlayerResponseModelImplRecommendedLevelFingerprint
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.ScrubbedPreviewLayoutFingerprint
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.StoryboardRendererDecoderRecommendedLevelFingerprint
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.StoryboardRendererDecoderSpecFingerprint
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.StoryboardRendererSpecFingerprint
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.StoryboardThumbnailFingerprint
import app.revanced.patches.youtube.misc.fix.playback.fingerprints.StoryboardThumbnailParentFingerprint
import app.revanced.patches.youtube.misc.playertype.PlayerTypeHookPatch
import app.revanced.patches.youtube.misc.settings.SettingsPatch
import app.revanced.patches.youtube.video.information.VideoInformationPatch
import app.revanced.patches.youtube.video.playerresponse.PlayerResponseMethodHookPatch
import app.revanced.util.*
import app.revanced.util.exception
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
Expand All @@ -43,6 +33,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
AddResourcesPatch::class,
],
)
@Deprecated("This patch will be removed in the future.")
object SpoofSignaturePatch : BytecodePatch(
setOf(
PlayerResponseModelImplGeneralFingerprint,
Expand Down

0 comments on commit 1967547

Please sign in to comment.