diff --git a/src/main/kotlin/app/revanced/patches/shared/mainactivity/BaseMainActivityResolvePatch.kt b/src/main/kotlin/app/revanced/patches/shared/mainactivity/BaseMainActivityResolvePatch.kt index 1621e61bf..cb720a8bb 100644 --- a/src/main/kotlin/app/revanced/patches/shared/mainactivity/BaseMainActivityResolvePatch.kt +++ b/src/main/kotlin/app/revanced/patches/shared/mainactivity/BaseMainActivityResolvePatch.kt @@ -19,8 +19,8 @@ abstract class BaseMainActivityResolvePatch( setOf(mainActivityOnCreateFingerprint) ) { 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() private var onBackPressedMethodIndex by Delegates.notNull() diff --git a/src/main/kotlin/app/revanced/patches/youtube/feed/components/FeedComponentsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/feed/components/FeedComponentsPatch.kt index 20ec516e3..3394c9d81 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/feed/components/FeedComponentsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/feed/components/FeedComponentsPatch.kt @@ -19,7 +19,6 @@ import app.revanced.patches.youtube.feed.components.fingerprints.LatestVideosBut import app.revanced.patches.youtube.feed.components.fingerprints.RelatedChipCloudFingerprint import app.revanced.patches.youtube.feed.components.fingerprints.SearchResultsChipBarFingerprint import app.revanced.patches.youtube.feed.components.fingerprints.ShowMoreButtonFingerprint -import app.revanced.patches.youtube.utils.browseid.BrowseIdHookPatch import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.FEED_CLASS_DESCRIPTOR @@ -43,7 +42,6 @@ object FeedComponentsPatch : BaseBytecodePatch( name = "Hide feed components", description = "Adds options to hide components related to feed.", dependencies = setOf( - BrowseIdHookPatch::class, LithoFilterPatch::class, NavigationBarHookPatch::class, SettingsPatch::class, diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/browseid/BrowseIdHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/browseid/BrowseIdHookPatch.kt index 7099543fa..aca1ab4fe 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/browseid/BrowseIdHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/browseid/BrowseIdHookPatch.kt @@ -10,7 +10,9 @@ import app.revanced.patcher.patch.annotation.Patch import app.revanced.patches.shared.litho.LithoFilterPatch import app.revanced.patches.shared.litho.fingerprints.PathBuilderFingerprint import app.revanced.patches.youtube.utils.browseid.fingerprints.BrowseIdClassFingerprint +import app.revanced.patches.youtube.utils.browseid.fingerprints.MobileTopBarDialogFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.SHARED_PATH +import app.revanced.patches.youtube.utils.mainactivity.MainActivityResolvePatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.util.getStringInstructionIndex import app.revanced.util.getTargetIndex @@ -22,18 +24,24 @@ import com.android.tools.smali.dexlib2.iface.reference.FieldReference @Patch( dependencies = [ LithoFilterPatch::class, + MainActivityResolvePatch::class, SharedResourceIdPatch::class ] ) +@Deprecated("This patch will be removed in the future.") object BrowseIdHookPatch : BytecodePatch( setOf( BrowseIdClassFingerprint, + MobileTopBarDialogFingerprint, PathBuilderFingerprint ) ) { private const val INTEGRATIONS_CLASS_DESCRIPTOR = "$SHARED_PATH/BrowseId;" + private const val SETTINGS_ACTIVITY_CLASS_DESCRIPTOR = + "Lcom/google/android/apps/youtube/app/settings/SettingsActivity;" + override fun execute(context: BytecodeContext) { /** @@ -62,16 +70,40 @@ object BrowseIdHookPatch : BytecodePatch( } } + val mobileTopBarDialogClass = + MobileTopBarDialogFingerprint.resultOrThrow().mutableClass + + val mobileTopBarDialogOnBackPressedMethod = + mobileTopBarDialogClass.methods.single { method -> + method.name == "onBackPressed" + } + + val mobileTopBarDialogOnStopMethod = + mobileTopBarDialogClass.methods.single { method -> + method.name == "onStop" + } + + val pathBuilderMethod = PathBuilderFingerprint.resultOrThrow().mutableMethod + + val settingsActivityOnBackPressedMethod = + context.findClass(SETTINGS_ACTIVITY_CLASS_DESCRIPTOR)!!.mutableClass.methods.single { method -> + method.name == "onBackPressed" + } + /** * Set BrowseId to integrations. */ - PathBuilderFingerprint.resultOrThrow().let { - it.mutableMethod.apply { - addInstruction( - 0, - "invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->setBrowseIdFromField()V" - ) - } + listOf( + MainActivityResolvePatch.onBackPressedMethod, + mobileTopBarDialogOnBackPressedMethod, + mobileTopBarDialogOnStopMethod, + pathBuilderMethod, + settingsActivityOnBackPressedMethod + ).forEach { method -> + method.addInstruction( + 0, + "invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->setBrowseIdFromField()V" + ) } } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/browseid/fingerprints/MobileTopBarDialogFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/browseid/fingerprints/MobileTopBarDialogFingerprint.kt new file mode 100644 index 000000000..f6b1af9c2 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/browseid/fingerprints/MobileTopBarDialogFingerprint.kt @@ -0,0 +1,11 @@ +package app.revanced.patches.youtube.utils.browseid.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint + +internal object MobileTopBarDialogFingerprint : MethodFingerprint( + returnType = "V", + customFingerprint = { methodDef, classDef -> + methodDef.name == "setContentView" && + classDef.superclass == "Landroid/app/Dialog;" + } +) \ No newline at end of file