mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-23 18:37:14 +02:00
fix(YouTube/Settings): when the user first installs the app and opens Import/Export settings
, it is not an empty value
This commit is contained in:
parent
d895abd41a
commit
b440417246
@ -10,7 +10,7 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||
import app.revanced.patches.youtube.misc.splashanimation.fingerprints.WatchWhileActivityWithOutFlagsFingerprint
|
||||
import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH
|
||||
import app.revanced.patches.youtube.utils.mainactivity.MainActivityResolvePatch
|
||||
import app.revanced.patches.youtube.utils.mainactivity.MainActivityResolvePatch.mainActivityClassDef
|
||||
import app.revanced.patches.youtube.utils.mainactivity.MainActivityResolvePatch.mainActivityMutableClass
|
||||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
|
||||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.DarkSplashAnimation
|
||||
import app.revanced.patches.youtube.utils.settings.SettingsPatch
|
||||
@ -64,7 +64,7 @@ object NewSplashAnimationPatch : BytecodePatch(emptySet()) {
|
||||
"$MISC_PATH/SplashAnimationPatch;"
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
WatchWhileActivityWithOutFlagsFingerprint.resolve(context, mainActivityClassDef)
|
||||
WatchWhileActivityWithOutFlagsFingerprint.resolve(context, mainActivityMutableClass)
|
||||
|
||||
/**
|
||||
* YouTube v18.28.xx~
|
||||
|
@ -10,9 +10,7 @@ import app.revanced.patches.youtube.utils.fix.doublebacktoclose.fingerprint.Scro
|
||||
import app.revanced.patches.youtube.utils.fix.doublebacktoclose.fingerprint.ScrollTopParentFingerprint
|
||||
import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH
|
||||
import app.revanced.patches.youtube.utils.mainactivity.MainActivityResolvePatch
|
||||
import app.revanced.patches.youtube.utils.mainactivity.MainActivityResolvePatch.onBackPressedMethod
|
||||
import app.revanced.util.exception
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
|
||||
@Patch(dependencies = [MainActivityResolvePatch::class])
|
||||
object DoubleBackToClosePatch : BytecodePatch(
|
||||
@ -21,23 +19,15 @@ object DoubleBackToClosePatch : BytecodePatch(
|
||||
ScrollTopParentFingerprint
|
||||
)
|
||||
) {
|
||||
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
|
||||
"$UTILS_PATH/DoubleBackToClosePatch;"
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
|
||||
/**
|
||||
* Hook onBackPressed method inside MainActivity (WatchWhileActivity)
|
||||
*/
|
||||
onBackPressedMethod.apply {
|
||||
val insertIndex = implementation!!.instructions.indexOfFirst { instruction ->
|
||||
instruction.opcode == Opcode.RETURN_VOID
|
||||
}
|
||||
|
||||
addInstruction(
|
||||
insertIndex,
|
||||
"invoke-static {p0}, $INTEGRATIONS_CLASS_DESCRIPTOR" +
|
||||
"->" +
|
||||
"closeActivityOnBackPressed(Landroid/app/Activity;)V"
|
||||
)
|
||||
}
|
||||
MainActivityResolvePatch.injectOnBackPressedMethodCall(INTEGRATIONS_CLASS_DESCRIPTOR, "closeActivityOnBackPressed")
|
||||
|
||||
|
||||
/**
|
||||
@ -67,9 +57,6 @@ object DoubleBackToClosePatch : BytecodePatch(
|
||||
|
||||
}
|
||||
|
||||
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
|
||||
"$UTILS_PATH/DoubleBackToClosePatch;"
|
||||
|
||||
private fun MutableMethod.injectScrollView(
|
||||
index: Int,
|
||||
descriptor: String
|
||||
|
@ -6,39 +6,63 @@ import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.PatchException
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableClass
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||
import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH
|
||||
import app.revanced.patches.youtube.utils.mainactivity.fingerprints.MainActivityFingerprint
|
||||
import app.revanced.util.exception
|
||||
import com.android.tools.smali.dexlib2.iface.ClassDef
|
||||
import app.revanced.util.getTargetIndex
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.util.MethodUtil
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
object MainActivityResolvePatch : BytecodePatch(
|
||||
setOf(MainActivityFingerprint)
|
||||
) {
|
||||
lateinit var mainActivityClassDef: ClassDef
|
||||
lateinit var mainActivityMutableClass: MutableClass
|
||||
lateinit var onBackPressedMethod: MutableMethod
|
||||
private lateinit var constructorMethod: MutableMethod
|
||||
private lateinit var onBackPressedMethod: MutableMethod
|
||||
private lateinit var onCreateMethod: MutableMethod
|
||||
private var constructorMethodIndex by Delegates.notNull<Int>()
|
||||
private var onBackPressedMethodIndex by Delegates.notNull<Int>()
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
MainActivityFingerprint.result?.let {
|
||||
mainActivityClassDef = it.classDef
|
||||
mainActivityMutableClass = it.mutableClass
|
||||
onBackPressedMethod =
|
||||
mainActivityMutableClass.methods.find { method -> method.name == "onBackPressed" }
|
||||
?: throw PatchException("Could not find onBackPressedMethod")
|
||||
onCreateMethod = it.mutableMethod
|
||||
} ?: throw MainActivityFingerprint.exception
|
||||
val mainActivityResult = MainActivityFingerprint.result
|
||||
?: throw MainActivityFingerprint.exception
|
||||
onCreateMethod = mainActivityResult.mutableMethod
|
||||
mainActivityMutableClass = mainActivityResult.mutableClass
|
||||
|
||||
/**
|
||||
* Set Constructor Method
|
||||
*/
|
||||
constructorMethod =
|
||||
mainActivityMutableClass.methods.find { method -> MethodUtil.isConstructor(method) }
|
||||
?: throw PatchException("Could not find constructorMethod")
|
||||
constructorMethodIndex = constructorMethod.implementation!!.instructions.size - 1
|
||||
|
||||
/**
|
||||
* Set OnBackPressed Method
|
||||
*/
|
||||
onBackPressedMethod =
|
||||
mainActivityMutableClass.methods.find { method -> method.name == "onBackPressed" }
|
||||
?: throw PatchException("Could not find onBackPressedMethod")
|
||||
onBackPressedMethodIndex = onBackPressedMethod.getTargetIndex(Opcode.RETURN_VOID)
|
||||
}
|
||||
|
||||
fun injectInit(
|
||||
methods: String,
|
||||
descriptor: String
|
||||
fun injectConstructorMethodCall(classDescriptor: String, methodDescriptor: String) =
|
||||
constructorMethod.injectMethodCall(classDescriptor, methodDescriptor, constructorMethodIndex)
|
||||
|
||||
fun injectOnBackPressedMethodCall(classDescriptor: String, methodDescriptor: String) =
|
||||
onBackPressedMethod.injectMethodCall(classDescriptor, methodDescriptor, onBackPressedMethodIndex)
|
||||
|
||||
fun injectOnCreateMethodCall(classDescriptor: String, methodDescriptor: String) =
|
||||
onCreateMethod.injectMethodCall(classDescriptor, methodDescriptor, 0)
|
||||
|
||||
private fun MutableMethod.injectMethodCall(
|
||||
classDescriptor: String,
|
||||
methodDescriptor: String,
|
||||
insertIndex: Int
|
||||
) {
|
||||
onCreateMethod.apply {
|
||||
addInstruction(
|
||||
2,
|
||||
"invoke-static/range {p0 .. p0}, $UTILS_PATH/$methods;->$descriptor(Landroid/content/Context;)V"
|
||||
)
|
||||
}
|
||||
addInstruction(
|
||||
insertIndex,
|
||||
"invoke-static/range {p0 .. p0}, $classDescriptor->$methodDescriptor(Landroid/app/Activity;)V"
|
||||
)
|
||||
}
|
||||
}
|
@ -8,8 +8,8 @@ import app.revanced.patches.shared.patch.microg.MicroGBytecodeHelper
|
||||
import app.revanced.patches.shared.patch.packagename.PackageNamePatch
|
||||
import app.revanced.patches.youtube.utils.fix.clientspoof.ClientSpoofPatch
|
||||
import app.revanced.patches.youtube.utils.fix.parameter.SpoofPlayerParameterPatch
|
||||
import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH
|
||||
import app.revanced.patches.youtube.utils.mainactivity.MainActivityResolvePatch
|
||||
import app.revanced.patches.youtube.utils.mainactivity.MainActivityResolvePatch.injectInit
|
||||
import app.revanced.patches.youtube.utils.microg.Constants.PACKAGE_NAME
|
||||
import app.revanced.patches.youtube.utils.microg.fingerprints.CastContextFetchFingerprint
|
||||
import app.revanced.patches.youtube.utils.microg.fingerprints.CastDynamiteModuleFingerprint
|
||||
@ -36,6 +36,9 @@ object MicroGBytecodePatch : BytecodePatch(
|
||||
ServiceCheckFingerprint
|
||||
)
|
||||
) {
|
||||
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
|
||||
"$UTILS_PATH/MicroGPatch;"
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
|
||||
val packageName = PackageNamePatch.PackageNameYouTube
|
||||
@ -66,7 +69,7 @@ object MicroGBytecodePatch : BytecodePatch(
|
||||
)
|
||||
)
|
||||
|
||||
injectInit("MicroGPatch", "checkAvailability")
|
||||
MainActivityResolvePatch.injectOnCreateMethodCall(INTEGRATIONS_CLASS_DESCRIPTOR, "checkAvailability")
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,21 @@
|
||||
package app.revanced.patches.youtube.utils.settings
|
||||
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.annotation.Patch
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||
import app.revanced.patches.shared.patch.mapping.ResourceMappingPatch
|
||||
import app.revanced.patches.youtube.utils.integrations.Constants.INTEGRATIONS_PATH
|
||||
import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH
|
||||
import app.revanced.patches.youtube.utils.integrations.IntegrationsPatch
|
||||
import app.revanced.patches.youtube.utils.mainactivity.MainActivityResolvePatch
|
||||
import app.revanced.patches.youtube.utils.mainactivity.MainActivityResolvePatch.injectInit
|
||||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
|
||||
import app.revanced.patches.youtube.utils.settings.fingerprints.ThemeSetterSystemFingerprint
|
||||
import app.revanced.util.exception
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
|
||||
@Patch(
|
||||
dependencies = [
|
||||
@ -25,35 +28,39 @@ import app.revanced.util.exception
|
||||
object SettingsBytecodePatch : BytecodePatch(
|
||||
setOf(ThemeSetterSystemFingerprint)
|
||||
) {
|
||||
private const val INTEGRATIONS_INITIALIZATION_CLASS_DESCRIPTOR =
|
||||
"$UTILS_PATH/InitializationPatch;"
|
||||
|
||||
private const val INTEGRATIONS_THEME_METHOD_DESCRIPTOR =
|
||||
"$INTEGRATIONS_PATH/utils/ThemeHelper;->setTheme(Ljava/lang/Object;)V"
|
||||
|
||||
internal lateinit var contexts: BytecodeContext
|
||||
|
||||
override fun execute(context: BytecodeContext) {
|
||||
contexts = context
|
||||
|
||||
// apply the current theme of the settings page
|
||||
ThemeSetterSystemFingerprint.result?.let {
|
||||
it.mutableMethod.apply {
|
||||
val targetIndex = it.scanResult.patternScanResult!!.startIndex
|
||||
replaceInstruction(
|
||||
targetIndex,
|
||||
SET_THEME
|
||||
)
|
||||
addInstruction(
|
||||
targetIndex + 1,
|
||||
"return-object v0"
|
||||
)
|
||||
addInstruction(
|
||||
this.implementation!!.instructions.size - 1,
|
||||
SET_THEME
|
||||
)
|
||||
injectCall(implementation!!.instructions.size - 1)
|
||||
injectCall(it.scanResult.patternScanResult!!.startIndex)
|
||||
}
|
||||
} ?: throw ThemeSetterSystemFingerprint.exception
|
||||
|
||||
injectInit("InitializationPatch", "setDeviceInformation")
|
||||
injectInit("InitializationPatch", "initializeReVancedSettings")
|
||||
MainActivityResolvePatch.injectOnCreateMethodCall(INTEGRATIONS_INITIALIZATION_CLASS_DESCRIPTOR, "setDeviceInformation")
|
||||
MainActivityResolvePatch.injectOnCreateMethodCall(INTEGRATIONS_INITIALIZATION_CLASS_DESCRIPTOR, "onCreate")
|
||||
MainActivityResolvePatch.injectConstructorMethodCall(INTEGRATIONS_INITIALIZATION_CLASS_DESCRIPTOR, "setMainActivity")
|
||||
|
||||
}
|
||||
private fun MutableMethod.injectCall(index: Int) {
|
||||
val register = getInstruction<OneRegisterInstruction>(index).registerA
|
||||
|
||||
internal lateinit var contexts: BytecodeContext
|
||||
|
||||
private const val SET_THEME =
|
||||
"invoke-static {v0}, $INTEGRATIONS_PATH/utils/ThemeHelper;->setTheme(Ljava/lang/Object;)V"
|
||||
addInstructions(
|
||||
index + 1, """
|
||||
invoke-static {v$register}, $INTEGRATIONS_THEME_METHOD_DESCRIPTOR
|
||||
return-object v$register
|
||||
"""
|
||||
)
|
||||
removeInstruction(index)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user