From 324162e561fc4e9a76d4a821c909f9ebed954be6 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Thu, 4 Apr 2024 04:05:13 +0900 Subject: [PATCH] refactor: fix patch structure --- .../account/component/MenuComponentPatch.kt | 6 +-- .../music/account/handle/HandlePatch.kt | 10 ++--- .../music/account/tos/TermsContainerPatch.kt | 6 +-- .../component/ActionBarComponentPatch.kt | 10 ++--- .../music/ads/general/GeneralAdsPatch.kt | 18 ++++---- .../compactdialog/CompactDialogPatch.kt | 6 +-- .../flyoutpanel/component/FlyoutPanelPatch.kt | 6 +-- .../flyoutpanel/replace/ReplaceReportPatch.kt | 6 +-- .../shared/FlyoutPanelMenuItemPatch.kt | 6 +-- .../general/castbutton/CastButtonPatch.kt | 10 ++--- .../general/categorybar/CategoryBarPatch.kt | 6 +-- .../floatingbutton/FloatingButtonPatch.kt | 10 ++--- .../historybutton/HistoryButtonPatch.kt | 6 +-- .../landscapemode/LandScapeModePatch.kt | 6 +-- .../OldStyleLibraryShelfPatch.kt | 6 +-- .../redirection/DislikeRedirectionPatch.kt | 10 ++--- .../general/startpage/ChangeStartPagePatch.kt | 6 +-- .../taptoupdate/TapToUpdateButtonPatch.kt | 6 +-- .../tooltip/TooltipContentViewPatch.kt | 6 +-- .../OverlayFilterBytecodePatch.kt | 6 +-- .../backgroundplay/BackgroundPlayPatch.kt | 6 +-- .../misc/bitrate/BitrateDefaultValuePatch.kt | 5 +-- .../exclusiveaudio/ExclusiveAudioPatch.kt | 14 +++--- .../MinimizedPlaybackPatch.kt | 6 +-- .../music/misc/premium/GetPremiumPatch.kt | 18 ++++---- .../misc/tastebuilder/TasteBuilderPatch.kt | 10 ++--- .../black/BlackNavigationBarPatch.kt | 6 +-- .../component/NavigationBarComponentPatch.kt | 10 ++--- .../colormatchplayer/ColorMatchPlayerPatch.kt | 10 ++--- .../minimizedplayer/MinimizedPlayerPatch.kt | 6 +-- .../nextprevious/MiniPlayerButtonPatch.kt | 35 +++++++-------- .../player/repeat/RememberRepeatPatch.kt | 6 +-- .../player/replace/ReplaceCastButtonPatch.kt | 6 +-- .../music/player/share/ShareButtonPatch.kt | 6 +-- .../player/shuffle/RememberShufflePatch.kt | 10 ++--- .../SwipeToDismissMiniPlayerPatch.kt | 30 ++++++------- .../music/player/zenmode/ZenModePatch.kt | 10 ++--- .../AndroidAutoCertificatePatch.kt | 6 +-- .../utils/fix/clientspoof/ClientSpoofPatch.kt | 4 +- .../fix/fileprovider/FileProviderPatch.kt | 6 +-- .../mainactivity/MainActivityResolvePatch.kt | 6 +-- .../OverrideQualityHookPatch.kt | 14 +++--- .../overridespeed/OverrideSpeedHookPatch.kt | 18 ++++---- .../playerresponse/PlayerResponsePatch.kt | 5 +-- .../utils/playertype/PlayerTypeHookPatch.kt | 11 +++-- .../ReturnYouTubeDislikeBytecodePatch.kt | 16 +++---- .../utils/settings/SettingsBytecodePatch.kt | 18 ++++---- .../sponsorblock/SponsorBlockBytecodePatch.kt | 17 ++++--- .../utils/videotype/VideoTypeHookPatch.kt | 10 ++--- .../information/VideoInformationPatch.kt | 18 ++++---- .../music/video/quality/VideoQualityPatch.kt | 6 +-- .../music/video/speed/PlaybackSpeedPatch.kt | 10 ++--- .../music/video/videoid/VideoIdPatch.kt | 15 ++++--- .../reddit/ad/comments/CommentAdsPatch.kt | 6 +-- .../patches/reddit/ad/general/AdsPatch.kt | 10 ++--- .../navigation/NavigationButtonsPatch.kt | 6 +-- .../layout/premiumicon/PremiumIconPatch.kt | 6 +-- .../RecentlyVisitedShelfPatch.kt | 6 +-- .../screenshotpopup/ScreenshotPopupPatch.kt | 6 +-- .../subredditdialog/SubRedditDialogPatch.kt | 10 ++--- .../layout/toolbar/ToolBarButtonPatch.kt | 6 +-- .../misc/openlink/OpenLinksDirectlyPatch.kt | 6 +-- .../misc/openlink/OpenLinksExternallyPatch.kt | 6 +-- .../tracking/url/SanitizeUrlQueryPatch.kt | 6 +-- .../utils/settings/SettingsBytecodePatch.kt | 17 ++++--- .../patches/shared/ads/BaseAdsPatch.kt | 10 ++--- .../shared/captions/BaseAutoCaptionsPatch.kt | 10 ++--- ...tSpoofPatch.kt => BaseClientSpoofPatch.kt} | 2 +- .../BaseCustomPlaybackSpeedPatch.kt | 16 +++---- .../dialog/BaseViewerDiscretionDialogPatch.kt | 9 ++-- .../shared/drawable/DrawableColorPatch.kt | 6 +-- .../shared/gms/BaseGmsCoreSupportPatch.kt | 29 +++++++----- .../integrations/BaseIntegrationsPatch.kt | 7 +-- .../patches/shared/litho/LithoFilterPatch.kt | 14 +++--- .../shared/opus/BaseOpusCodecsPatch.kt | 10 ++--- .../BaseSpoofAppVersionPatch.kt | 10 ++--- .../tracking/BaseSanitizeUrlQueryPatch.kt | 6 +-- .../shared/translations/TranslationsUtils.kt | 6 +-- .../ads/fullscreen/FullscreenAdsPatch.kt | 10 ++--- .../youtube/ads/getpremium/GetPremiumPatch.kt | 6 +-- .../general/AlternativeThumbnailsPatch.kt | 9 ++-- .../comment/CommentComponentPatch.kt | 10 ++--- .../flyoutpanel/feed/FeedFlyoutPanelPatch.kt | 9 ++-- .../oldqualitylayout/OldQualityLayoutPatch.kt | 9 ++-- .../oldspeedlayout/OldSpeedLayoutPatch.kt | 10 ++--- .../flyoutpanel/toggle/ChangeTogglePatch.kt | 21 ++++----- .../autoplaypreview/AutoplayPreviewPatch.kt | 6 +-- .../CompactControlsOverlayPatch.kt | 6 +-- .../endscreenoverlay/EndScreenOverlayPatch.kt | 6 +-- .../forcefullscreen/ForceFullscreenPatch.kt | 10 ++--- .../fullscreenpanels/FullscreenPanelsPatch.kt | 10 ++--- .../landscapemode/LandScapeModePatch.kt | 20 ++++----- .../general/accountmenu/AccountMenuPatch.kt | 26 +++++------ .../autopopuppanels/PlayerPopupPanelsPatch.kt | 6 +-- .../general/castbutton/CastButtonPatch.kt | 6 +-- .../general/categorybar/CategoryBarPatch.kt | 6 +-- .../ChannelListSubMenuPatch.kt | 6 +-- .../ChannelProfileComponentsPatch.kt | 6 +-- .../crowdfundingbox/CrowdfundingBoxPatch.kt | 6 +-- .../DescriptionComponentsPatch.kt | 6 +-- .../FloatingMicrophonePatch.kt | 6 +-- .../youtube/general/handle/HandlePatch.kt | 6 +-- .../LatestVideosButtonPatch.kt | 6 +-- .../loadmorebutton/LoadMoreButtonPatch.kt | 6 +-- .../general/mixplaylists/MixPlaylistsPatch.kt | 10 ++--- .../searchterm/SearchTermThumbnailPatch.kt | 6 +-- .../youtube/general/snackbar/SnackBarPatch.kt | 6 +-- .../general/startpage/ChangeStartPagePatch.kt | 6 +-- .../suggestionshelf/SuggestionsShelfPatch.kt | 6 +-- .../tabletminiplayer/TabletMiniPlayerPatch.kt | 18 ++++---- .../widesearchbar/WideSearchBarPatch.kt | 21 ++++----- .../pipnotification/PiPNotificationPatch.kt | 6 +-- .../PlayerButtonBackgroundPatch.kt | 2 +- ...hemeBytecodePatch.kt => BaseThemePatch.kt} | 2 +- .../youtube/layout/theme/MaterialYouPatch.kt | 4 +- .../youtube/layout/theme/ThemePatch.kt | 6 +-- .../layout/tooltip/TooltipContentViewPatch.kt | 6 +-- .../ambientmode/AmbientModeSwitchPatch.kt | 6 +-- .../misc/codec/video/ForceVideoCodecPatch.kt | 25 +++++------ .../misc/layoutswitch/LayoutSwitchPatch.kt | 10 ++--- .../MinimizedPlaybackPatch.kt | 18 ++++---- .../OpenLinksDirectlyPatch.kt | 6 +-- .../youtube/misc/quic/QUICProtocolPatch.kt | 6 +-- .../NewSplashAnimationPatch.kt | 18 ++++---- .../SpoofDeviceDimensionsPatch.kt | 6 +-- .../tracking/SanitizeUrlQueryBytecodePatch.kt | 6 +-- .../misc/updatescreen/UpdateScreenPatch.kt | 8 ++-- .../navigation/label/NavigationLabelPatch.kt | 6 +-- .../NavigationButtonsPatch.kt | 12 ++--- .../tabletnavbar/TabletNavigationBarPatch.kt | 4 +- .../alwaysrepeat/AlwaysRepeatPatch.kt | 6 +-- .../download/hook/DownloadButtonHookPatch.kt | 6 +-- .../download/pip/DisablePiPPatch.kt | 6 +-- .../fullscreen/FullscreenButtonPatch.kt | 6 +-- .../general/OverlayButtonsPatch.kt | 1 - .../autoplaybutton/AutoplayButtonPatch.kt | 6 +-- .../captionsbutton/CaptionsButtonPatch.kt | 6 +-- .../collapsebutton/CollapseButtonPatch.kt | 6 +-- .../endscreencards/EndScreenCardsPatch.kt | 6 +-- .../filmstripoverlay/FilmstripOverlayPatch.kt | 25 +++++------ .../hapticfeedback/HapticFeedBackPatch.kt | 6 +-- .../player/infocards/InfoCardsPatch.kt | 6 +-- .../player/musicbutton/MusicButtonPatch.kt | 9 ++-- .../CustomPlayerOverlayOpacityPatch.kt | 6 +-- .../PreviousNextButtonPatch.kt | 6 +-- .../player/seekmessage/SeekMessagePatch.kt | 10 ++--- .../suggestactions/SuggestedActionsPatch.kt | 6 +-- .../SuggestedVideoOverlayPatch.kt | 14 +++--- .../player/watermark/ChannelWatermarkPatch.kt | 10 ++--- .../append/AppendTimeStampInformationPatch.kt | 6 +-- .../seekbar/color/SeekbarColorPatch.kt | 23 +++++----- .../youtube/seekbar/hide/SeekbarPatch.kt | 10 ++--- .../seekbar/tapping/SeekbarTappingPatch.kt | 6 +-- .../seekbar/timestamps/TimeStampPatch.kt | 10 ++--- .../shorts/components/ShortsComponentPatch.kt | 31 +++++++------ .../components/ShortsNavigationBarPatch.kt | 27 +++++------ .../ShortsSubscriptionsButtonPatch.kt | 43 +++++++++--------- .../shorts/components/ShortsToolBarPatch.kt | 15 +++---- .../shorts/repeat/ShortsRepeatPatch.kt | 10 ++--- .../ResumingShortsOnStartupPatch.kt | 10 ++--- .../swipe/controls/SwipeControlsPatch.kt | 9 ++-- .../utils/browseid/BrowseIdHookPatch.kt | 10 ++--- .../utils/fix/clientspoof/ClientSpoofPatch.kt | 4 +- .../DoubleBackToClosePatch.kt | 14 +++--- .../parameter/SpoofPlayerParameterPatch.kt | 45 +++++++++---------- .../fix/swiperefresh/SwipeRefreshPatch.kt | 6 +-- .../lockmodestate/LockModeStateHookPatch.kt | 6 +-- .../mainactivity/MainActivityResolvePatch.kt | 5 +-- .../utils/navbarindex/NavBarIndexHookPatch.kt | 10 ++--- .../OverrideQualityHookPatch.kt | 14 +++--- .../overridespeed/OverrideSpeedHookPatch.kt | 30 ++++++------- .../playercontrols/PlayerControlsPatch.kt | 39 ++++++---------- .../playerresponse/PlayerResponsePatch.kt | 5 +-- .../utils/playertype/PlayerTypeHookPatch.kt | 20 ++++----- .../quickactions/QuickActionsHookPatch.kt | 16 +++---- .../BottomSheetRecyclerViewPatch.kt | 7 ++- .../general/ReturnYouTubeDislikePatch.kt | 19 ++++---- .../ReturnYouTubeDislikeRollingNumberPatch.kt | 28 ++++++------ .../shorts/ReturnYouTubeDislikeShortsPatch.kt | 14 +++--- .../utils/settings/SettingsBytecodePatch.kt | 6 +-- .../sponsorblock/SponsorBlockBytecodePatch.kt | 27 ++++++----- .../utils/sponsorblock/SponsorBlockPatch.kt | 31 +++++++++---- .../youtube/utils/toolbar/ToolBarHookPatch.kt | 9 ++-- .../youtube/utils/videocpn/VideoCpnPatch.kt | 5 +-- .../utils/videoid/general/VideoIdPatch.kt | 26 +++++------ .../VideoIdWithoutShortsPatch.kt | 6 +-- .../youtube/video/hdr/HDRVideoPatch.kt | 6 +-- .../video/quality/VideoQualityPatch.kt | 10 ++--- .../youtube/video/speed/PlaybackSpeedPatch.kt | 24 +++++----- .../kotlin/app/revanced/util/BytecodeUtils.kt | 10 +++-- .../kotlin/app/revanced/util/ResourceUtils.kt | 15 +++++-- 191 files changed, 996 insertions(+), 1034 deletions(-) rename src/main/kotlin/app/revanced/patches/shared/clientspoof/{AbstractClientSpoofPatch.kt => BaseClientSpoofPatch.kt} (98%) rename src/main/kotlin/app/revanced/patches/youtube/{player => layout}/playerbuttonbg/PlayerButtonBackgroundPatch.kt (95%) rename src/main/kotlin/app/revanced/patches/youtube/layout/theme/{ThemeBytecodePatch.kt => BaseThemePatch.kt} (98%) diff --git a/src/main/kotlin/app/revanced/patches/music/account/component/MenuComponentPatch.kt b/src/main/kotlin/app/revanced/patches/music/account/component/MenuComponentPatch.kt index 92353523f..aca17623c 100644 --- a/src/main/kotlin/app/revanced/patches/music/account/component/MenuComponentPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/account/component/MenuComponentPatch.kt @@ -9,9 +9,9 @@ import app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAG import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction @Suppress("unused") @@ -27,7 +27,7 @@ object MenuComponentPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - MenuEntryFingerprint.result?.let { + MenuEntryFingerprint.resultOrThrow().let { it.mutableMethod.apply { val textIndex = getTargetIndexWithMethodReferenceName("setText") val viewIndex = getTargetIndexWithMethodReferenceName("addView") @@ -40,7 +40,7 @@ object MenuComponentPatch : BaseBytecodePatch( "invoke-static {v$textRegister, v$viewRegister}, $ACCOUNT_CLASS_DESCRIPTOR->hideAccountMenu(Ljava/lang/CharSequence;Landroid/view/View;)V" ) } - } ?: throw MenuEntryFingerprint.exception + } SettingsPatch.addMusicPreference( CategoryType.ACCOUNT, diff --git a/src/main/kotlin/app/revanced/patches/music/account/handle/HandlePatch.kt b/src/main/kotlin/app/revanced/patches/music/account/handle/HandlePatch.kt index 8a6e9f1dc..d8908d71b 100644 --- a/src/main/kotlin/app/revanced/patches/music/account/handle/HandlePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/account/handle/HandlePatch.kt @@ -11,9 +11,9 @@ import app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAG import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -36,7 +36,7 @@ object HandlePatch : BaseBytecodePatch( /** * Hide handle in account menu */ - AccountSwitcherAccessibilityLabelFingerprint.result?.let { result -> + AccountSwitcherAccessibilityLabelFingerprint.resultOrThrow().let { result -> result.mutableMethod.apply { val textColorIndex = getTargetIndexWithMethodReferenceName("setTextColor") @@ -48,12 +48,12 @@ object HandlePatch : BaseBytecodePatch( "invoke-static {v${textViewInstruction.registerC}, v${textViewInstruction.registerD}}, $ACCOUNT_CLASS_DESCRIPTOR->hideHandle(Landroid/widget/TextView;I)V" ) } - } ?: throw AccountSwitcherAccessibilityLabelFingerprint.exception + } /** * Hide handle in account switcher */ - NamesInactiveAccountThumbnailSizeFingerprint.result?.let { + NamesInactiveAccountThumbnailSizeFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.startIndex val targetRegister = getInstruction(targetIndex).registerA @@ -65,7 +65,7 @@ object HandlePatch : BaseBytecodePatch( """ ) } - } ?: throw NamesInactiveAccountThumbnailSizeFingerprint.exception + } SettingsPatch.addMusicPreference( CategoryType.ACCOUNT, diff --git a/src/main/kotlin/app/revanced/patches/music/account/tos/TermsContainerPatch.kt b/src/main/kotlin/app/revanced/patches/music/account/tos/TermsContainerPatch.kt index 63ea6d680..3d220d071 100644 --- a/src/main/kotlin/app/revanced/patches/music/account/tos/TermsContainerPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/account/tos/TermsContainerPatch.kt @@ -10,9 +10,9 @@ import app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAG import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithReference import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction @Suppress("unused") @@ -28,7 +28,7 @@ object TermsContainerPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - TermsOfServiceFingerprint.result?.let { + TermsOfServiceFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = getTargetIndexWithReference("/PrivacyTosFooter;->setVisibility(I)V") val visibilityRegister = @@ -45,7 +45,7 @@ object TermsContainerPatch : BaseBytecodePatch( """ ) } - } ?: throw TermsOfServiceFingerprint.exception + } SettingsPatch.addMusicPreference( CategoryType.ACCOUNT, diff --git a/src/main/kotlin/app/revanced/patches/music/actionbar/component/ActionBarComponentPatch.kt b/src/main/kotlin/app/revanced/patches/music/actionbar/component/ActionBarComponentPatch.kt index ff2931614..cd9cca076 100644 --- a/src/main/kotlin/app/revanced/patches/music/actionbar/component/ActionBarComponentPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/actionbar/component/ActionBarComponentPatch.kt @@ -17,12 +17,12 @@ import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.LikeDis import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch import app.revanced.patches.music.video.information.VideoInformationPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithReference import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.indexOfFirstInstruction import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -46,7 +46,7 @@ object ActionBarComponentPatch : BaseBytecodePatch( ) ) { override fun execute(context: BytecodeContext) { - ActionBarComponentFingerprint.result?.let { + ActionBarComponentFingerprint.resultOrThrow().let { it.mutableMethod.apply { // hook download button @@ -118,9 +118,9 @@ object ActionBarComponentPatch : BaseBytecodePatch( "invoke-static {v$buttonTypeDownloadRegister}, $ACTIONBAR_CLASS_DESCRIPTOR->setButtonTypeDownload(I)V" ) } - } ?: throw ActionBarComponentFingerprint.exception + } - LikeDislikeContainerFingerprint.result?.let { parentResult -> + LikeDislikeContainerFingerprint.resultOrThrow().let { parentResult -> // Resolves fingerprints LikeDislikeContainerVisibilityFingerprint.resolve(context, parentResult.classDef) @@ -151,7 +151,7 @@ object ActionBarComponentPatch : BaseBytecodePatch( "invoke-static {v$insertRegister}, $ACTIONBAR_CLASS_DESCRIPTOR->hideLikeDislikeButton(Landroid/view/View;)V" ) } - } ?: throw LikeDislikeContainerFingerprint.exception + } SettingsPatch.addMusicPreference( CategoryType.ACTION_BAR, diff --git a/src/main/kotlin/app/revanced/patches/music/ads/general/GeneralAdsPatch.kt b/src/main/kotlin/app/revanced/patches/music/ads/general/GeneralAdsPatch.kt index 1758abcae..5b86c9750 100644 --- a/src/main/kotlin/app/revanced/patches/music/ads/general/GeneralAdsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/ads/general/GeneralAdsPatch.kt @@ -20,9 +20,9 @@ import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.Interst import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch import app.revanced.patches.shared.litho.LithoFilterPatch -import app.revanced.util.exception import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -62,7 +62,7 @@ object GeneralAdsPatch : BaseBytecodePatch( * Hides fullscreen ads * Non-litho view, used in some old clients. */ - InterstitialsContainerFingerprint.result?.let { + InterstitialsContainerFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = getWideLiteralInstructionIndex(InterstitialsContainer) + 2 val targetRegister = getInstruction(targetIndex).registerA @@ -72,13 +72,13 @@ object GeneralAdsPatch : BaseBytecodePatch( "invoke-static {v$targetRegister}, $FULLSCREEN_ADS_CLASS_DESCRIPTOR->hideFullscreenAds(Landroid/view/View;)V" ) } - } ?: throw InterstitialsContainerFingerprint.exception + } /** * Hides fullscreen ads * Litho view, used in 'ShowDialogCommandOuterClass' in innertube */ - ShowDialogCommandFingerprint.result?.let { + ShowDialogCommandFingerprint.resultOrThrow().let { it.mutableMethod.apply { // In this method, custom dialog is created and shown. // There were no issues despite adding “return-void” to the first index. @@ -125,12 +125,12 @@ object GeneralAdsPatch : BaseBytecodePatch( // """ // ) } - } ?: throw ShowDialogCommandFingerprint.exception + } /** * Hides premium promotion popup */ - FloatingLayoutFingerprint.result?.let { + FloatingLayoutFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = getWideLiteralInstructionIndex(FloatingLayout) + 2 val targetRegister = getInstruction(targetIndex).registerA @@ -140,12 +140,12 @@ object GeneralAdsPatch : BaseBytecodePatch( "invoke-static {v$targetRegister}, $PREMIUM_PROMOTION_POP_UP_CLASS_DESCRIPTOR->hidePremiumPromotion(Landroid/view/View;)V" ) } - } ?: throw FloatingLayoutFingerprint.exception + } /** * Hides premium renewal banner */ - NotifierShelfFingerprint.result?.let { + NotifierShelfFingerprint.resultOrThrow().let { it.mutableMethod.apply { val linearLayoutIndex = getWideLiteralInstructionIndex(ButtonContainer) + 3 val linearLayoutRegister = @@ -156,7 +156,7 @@ object GeneralAdsPatch : BaseBytecodePatch( "invoke-static {v$linearLayoutRegister}, $PREMIUM_PROMOTION_BANNER_CLASS_DESCRIPTOR->hidePremiumRenewal(Landroid/widget/LinearLayout;)V" ) } - } ?: throw NotifierShelfFingerprint.exception + } SettingsPatch.addMusicPreference( CategoryType.ADS, diff --git a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/compactdialog/CompactDialogPatch.kt b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/compactdialog/CompactDialogPatch.kt index ffebd2714..0500817d9 100644 --- a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/compactdialog/CompactDialogPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/compactdialog/CompactDialogPatch.kt @@ -8,9 +8,9 @@ import app.revanced.patches.music.utils.integrations.Constants.FLYOUT_CLASS_DESC import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getWalkerMethod import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object CompactDialogPatch : BaseBytecodePatch( @@ -24,7 +24,7 @@ object CompactDialogPatch : BaseBytecodePatch( fingerprints = setOf(DialogSolidFingerprint) ) { override fun execute(context: BytecodeContext) { - DialogSolidFingerprint.result?.let { + DialogSolidFingerprint.resultOrThrow().let { val walkerMethod = it.getWalkerMethod(context, it.scanResult.patternScanResult!!.endIndex) walkerMethod.addInstructions( 2, """ @@ -32,7 +32,7 @@ object CompactDialogPatch : BaseBytecodePatch( move-result p0 """ ) - } ?: throw DialogSolidFingerprint.exception + } SettingsPatch.addMusicPreference( CategoryType.FLYOUT, diff --git a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/component/FlyoutPanelPatch.kt b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/component/FlyoutPanelPatch.kt index 429e9c23a..20ea0fd22 100644 --- a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/component/FlyoutPanelPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/component/FlyoutPanelPatch.kt @@ -14,10 +14,10 @@ import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.EndButt import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch import app.revanced.patches.shared.litho.LithoFilterPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndex import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -43,7 +43,7 @@ object FlyoutPanelPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { FlyoutPanelMenuItemPatch.hideComponents() - EndButtonsContainerFingerprint.result?.let { + EndButtonsContainerFingerprint.resultOrThrow().let { it.mutableMethod.apply { val startIndex = getWideLiteralInstructionIndex(EndButtonsContainer) val targetIndex = getTargetIndex(startIndex, Opcode.MOVE_RESULT_OBJECT) @@ -54,7 +54,7 @@ object FlyoutPanelPatch : BaseBytecodePatch( "invoke-static {v$targetRegister}, $FLYOUT_CLASS_DESCRIPTOR->hideLikeDislikeContainer(Landroid/view/View;)V" ) } - } ?: throw EndButtonsContainerFingerprint.exception + } /** * Forces sleep timer menu to be enabled. diff --git a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/replace/ReplaceReportPatch.kt b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/replace/ReplaceReportPatch.kt index 9efa298d4..664996873 100644 --- a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/replace/ReplaceReportPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/replace/ReplaceReportPatch.kt @@ -11,9 +11,9 @@ import app.revanced.patches.music.utils.overridespeed.OverrideSpeedHookPatch import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction @Suppress("unused") @@ -33,7 +33,7 @@ object ReplaceReportPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { FlyoutPanelMenuItemPatch.replaceComponents() - TouchOutsideFingerprint.result?.let { + TouchOutsideFingerprint.resultOrThrow().let { it.mutableMethod.apply { val setOnClickListenerIndex = getTargetIndexWithMethodReferenceName("setOnClickListener") val setOnClickListenerRegister = getInstruction(setOnClickListenerIndex).registerC @@ -43,7 +43,7 @@ object ReplaceReportPatch : BaseBytecodePatch( "sput-object v$setOnClickListenerRegister, $FLYOUT_CLASS_DESCRIPTOR->touchOutSideView:Landroid/view/View;" ) } - } ?: throw TouchOutsideFingerprint.exception + } SettingsPatch.addMusicPreference( CategoryType.FLYOUT, diff --git a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/shared/FlyoutPanelMenuItemPatch.kt b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/shared/FlyoutPanelMenuItemPatch.kt index 8edd55ff3..c78c72b14 100644 --- a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/shared/FlyoutPanelMenuItemPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/shared/FlyoutPanelMenuItemPatch.kt @@ -9,9 +9,9 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.music.flyoutpanel.shared.fingerprints.MenuItemFingerprint import app.revanced.patches.music.utils.integrations.Constants.FLYOUT_CLASS_DESCRIPTOR -import app.revanced.util.exception import app.revanced.util.getTargetIndex import app.revanced.util.indexOfFirstInstruction +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -28,7 +28,7 @@ object FlyoutPanelMenuItemPatch : BytecodePatch( private var instructionAdded = false override fun execute(context: BytecodeContext) { - MenuItemFingerprint.result?.let { + MenuItemFingerprint.resultOrThrow().let { it.mutableMethod.apply { val freeIndex = getTargetIndex(Opcode.OR_INT_LIT16) val textViewIndex = it.scanResult.patternScanResult!!.startIndex @@ -43,7 +43,7 @@ object FlyoutPanelMenuItemPatch : BytecodePatch( menuItemMethod = this } - } ?: throw MenuItemFingerprint.exception + } } private fun MutableMethod.getEnumIndex() = indexOfFirstInstruction { diff --git a/src/main/kotlin/app/revanced/patches/music/general/castbutton/CastButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/castbutton/CastButtonPatch.kt index 5bfb85840..545586e5a 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/castbutton/CastButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/castbutton/CastButtonPatch.kt @@ -13,9 +13,9 @@ import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.PlayerOverlayChip import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -37,7 +37,7 @@ object CastButtonPatch : BaseBytecodePatch( /** * Hide cast button */ - MediaRouteButtonFingerprint.result?.let { + MediaRouteButtonFingerprint.resultOrThrow().let { val setVisibilityMethod = it.mutableClass.methods.find { method -> method.name == "setVisibility" } @@ -49,12 +49,12 @@ object CastButtonPatch : BaseBytecodePatch( """ ) } ?: throw PatchException("Failed to find setVisibility method") - } ?: throw MediaRouteButtonFingerprint.exception + } /** * Hide floating cast banner */ - PlayerOverlayChipFingerprint.result?.let { + PlayerOverlayChipFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = getWideLiteralInstructionIndex(PlayerOverlayChip) + 2 val targetRegister = getInstruction(targetIndex).registerA @@ -64,7 +64,7 @@ object CastButtonPatch : BaseBytecodePatch( "invoke-static {v$targetRegister}, $GENERAL_CLASS_DESCRIPTOR->hideCastButton(Landroid/view/View;)V" ) } - } ?: throw PlayerOverlayChipFingerprint.exception + } SettingsPatch.addMusicPreference( CategoryType.GENERAL, diff --git a/src/main/kotlin/app/revanced/patches/music/general/categorybar/CategoryBarPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/categorybar/CategoryBarPatch.kt index 06b2be61b..10d78c6da 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/categorybar/CategoryBarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/categorybar/CategoryBarPatch.kt @@ -9,8 +9,8 @@ import app.revanced.patches.music.utils.integrations.Constants.GENERAL_CLASS_DES import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -25,7 +25,7 @@ object CategoryBarPatch : BaseBytecodePatch( fingerprints = setOf(ChipCloudFingerprint) ) { override fun execute(context: BytecodeContext) { - ChipCloudFingerprint.result?.let { + ChipCloudFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.endIndex val targetRegister = getInstruction(targetIndex).registerA @@ -35,7 +35,7 @@ object CategoryBarPatch : BaseBytecodePatch( "invoke-static { v$targetRegister }, $GENERAL_CLASS_DESCRIPTOR->hideCategoryBar(Landroid/view/View;)V" ) } - } ?: throw ChipCloudFingerprint.exception + } SettingsPatch.addMusicPreference( CategoryType.GENERAL, diff --git a/src/main/kotlin/app/revanced/patches/music/general/floatingbutton/FloatingButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/floatingbutton/FloatingButtonPatch.kt index de0ecf910..878360f60 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/floatingbutton/FloatingButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/floatingbutton/FloatingButtonPatch.kt @@ -11,8 +11,8 @@ import app.revanced.patches.music.utils.integrations.Constants.GENERAL_CLASS_DES import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object FloatingButtonPatch : BaseBytecodePatch( @@ -27,13 +27,13 @@ object FloatingButtonPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - FloatingButtonParentFingerprint.result?.let { parentResult -> + FloatingButtonParentFingerprint.resultOrThrow().let { parentResult -> FloatingButtonFingerprint.also { it.resolve( context, parentResult.classDef ) - }.result?.let { + }.resultOrThrow().let { it.mutableMethod.apply { addInstructionsWithLabels( 1, """ @@ -44,8 +44,8 @@ object FloatingButtonPatch : BaseBytecodePatch( """, ExternalLabel("show", getInstruction(1)) ) } - } ?: throw FloatingButtonFingerprint.exception - } ?: throw FloatingButtonParentFingerprint.exception + } + } SettingsPatch.addMusicPreference( CategoryType.GENERAL, diff --git a/src/main/kotlin/app/revanced/patches/music/general/historybutton/HistoryButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/historybutton/HistoryButtonPatch.kt index 082c5b427..d0f83e776 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/historybutton/HistoryButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/historybutton/HistoryButtonPatch.kt @@ -10,8 +10,8 @@ import app.revanced.patches.music.utils.integrations.Constants.GENERAL_CLASS_DES import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction @Suppress("unused") @@ -34,7 +34,7 @@ object HistoryButtonPatch : BaseBytecodePatch( HistoryMenuItemFingerprint, HistoryMenuItemOfflineTabFingerprint ).forEach { fingerprint -> - fingerprint.result?.let { + fingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.startIndex val insertRegister = getInstruction(insertIndex).registerD @@ -46,7 +46,7 @@ object HistoryButtonPatch : BaseBytecodePatch( """ ) } - } ?: throw fingerprint.exception + } } SettingsPatch.addMusicPreference( diff --git a/src/main/kotlin/app/revanced/patches/music/general/landscapemode/LandScapeModePatch.kt b/src/main/kotlin/app/revanced/patches/music/general/landscapemode/LandScapeModePatch.kt index 117c3e2a7..6fb38889b 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/landscapemode/LandScapeModePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/landscapemode/LandScapeModePatch.kt @@ -9,8 +9,8 @@ import app.revanced.patches.music.utils.integrations.Constants.GENERAL_CLASS_DES import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -25,7 +25,7 @@ object LandScapeModePatch : BaseBytecodePatch( fingerprints = setOf(TabletIdentifierFingerprint) ) { override fun execute(context: BytecodeContext) { - TabletIdentifierFingerprint.result?.let { + TabletIdentifierFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.endIndex val targetRegister = getInstruction(targetIndex).registerA @@ -37,7 +37,7 @@ object LandScapeModePatch : BaseBytecodePatch( """ ) } - } ?: throw TabletIdentifierFingerprint.exception + } SettingsPatch.addMusicPreference( CategoryType.GENERAL, diff --git a/src/main/kotlin/app/revanced/patches/music/general/oldstylelibraryshelf/OldStyleLibraryShelfPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/oldstylelibraryshelf/OldStyleLibraryShelfPatch.kt index be788de0f..56f0c3bc9 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/oldstylelibraryshelf/OldStyleLibraryShelfPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/oldstylelibraryshelf/OldStyleLibraryShelfPatch.kt @@ -8,10 +8,10 @@ import app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAG import app.revanced.patches.music.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getStringInstructionIndex import app.revanced.util.getTargetIndexReversed import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @@ -25,7 +25,7 @@ object OldStyleLibraryShelfPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - BrowseIdFingerprint.result?.let { + BrowseIdFingerprint.resultOrThrow().let { it.mutableMethod.apply { val stringIndex = getStringInstructionIndex("FEmusic_offline") val targetIndex = getTargetIndexReversed(stringIndex, Opcode.IGET_OBJECT) @@ -38,7 +38,7 @@ object OldStyleLibraryShelfPatch : BaseBytecodePatch( """ ) } - } ?: throw BrowseIdFingerprint.exception + } SettingsPatch.addMusicPreference( CategoryType.GENERAL, diff --git a/src/main/kotlin/app/revanced/patches/music/general/redirection/DislikeRedirectionPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/redirection/DislikeRedirectionPatch.kt index 7c7247d39..644e4ce38 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/redirection/DislikeRedirectionPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/redirection/DislikeRedirectionPatch.kt @@ -11,13 +11,13 @@ import app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAG import app.revanced.patches.music.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getStringInstructionIndex import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexWithReference import app.revanced.util.getWalkerMethod import app.revanced.util.indexOfFirstInstruction import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -39,7 +39,7 @@ object DislikeRedirectionPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { - PendingIntentReceiverFingerprint.result?.let { + PendingIntentReceiverFingerprint.resultOrThrow().let { it.mutableMethod.apply { val startIndex = getStringInstructionIndex("YTM Dislike") val onClickRelayIndex = getTargetIndexReversed(startIndex, Opcode.INVOKE_VIRTUAL) @@ -63,14 +63,14 @@ object DislikeRedirectionPatch : BaseBytecodePatch( } } } - } ?: throw PendingIntentReceiverFingerprint.exception + } - DislikeButtonOnClickListenerFingerprint.result?.let { + DislikeButtonOnClickListenerFingerprint.resultOrThrow().let { it.mutableMethod.apply { val onClickIndex = getTargetIndexWithReference(onClickReference.toString()) injectCall(onClickIndex) } - } ?: throw DislikeButtonOnClickListenerFingerprint.exception + } SettingsPatch.addMusicPreference( CategoryType.GENERAL, diff --git a/src/main/kotlin/app/revanced/patches/music/general/startpage/ChangeStartPagePatch.kt b/src/main/kotlin/app/revanced/patches/music/general/startpage/ChangeStartPagePatch.kt index 1ef9dec5b..80091a742 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/startpage/ChangeStartPagePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/startpage/ChangeStartPagePatch.kt @@ -11,8 +11,8 @@ import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch import app.revanced.patches.music.utils.settings.SettingsPatch.contexts import app.revanced.util.copyXmlNode -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -25,7 +25,7 @@ object ChangeStartPagePatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - ColdStartUpFingerprint.result?.let { + ColdStartUpFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.endIndex val targetRegister = getInstruction(targetIndex).registerA @@ -39,7 +39,7 @@ object ChangeStartPagePatch : BaseBytecodePatch( ) removeInstruction(targetIndex) } - } ?: throw ColdStartUpFingerprint.exception + } /** * Copy arrays diff --git a/src/main/kotlin/app/revanced/patches/music/general/taptoupdate/TapToUpdateButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/taptoupdate/TapToUpdateButtonPatch.kt index e6e48ada9..2fb254470 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/taptoupdate/TapToUpdateButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/taptoupdate/TapToUpdateButtonPatch.kt @@ -9,8 +9,8 @@ import app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAG import app.revanced.patches.music.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object TapToUpdateButtonPatch : BaseBytecodePatch( @@ -22,7 +22,7 @@ object TapToUpdateButtonPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - ContentPillInFingerprint.result?.let { + ContentPillInFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstructionsWithLabels( 0, @@ -34,7 +34,7 @@ object TapToUpdateButtonPatch : BaseBytecodePatch( """, ExternalLabel("show", getInstruction(0)) ) } - } ?: throw ContentPillInFingerprint.exception + } SettingsPatch.addMusicPreference( CategoryType.GENERAL, diff --git a/src/main/kotlin/app/revanced/patches/music/general/tooltip/TooltipContentViewPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/tooltip/TooltipContentViewPatch.kt index 29c60497b..aa5009d3d 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/tooltip/TooltipContentViewPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/tooltip/TooltipContentViewPatch.kt @@ -5,8 +5,8 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patches.music.general.tooltip.fingerprints.TooltipContentViewFingerprint import app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object TooltipContentViewPatch : BaseBytecodePatch( @@ -18,10 +18,10 @@ object TooltipContentViewPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - TooltipContentViewFingerprint.result?.mutableMethod?.addInstruction( + TooltipContentViewFingerprint.resultOrThrow().mutableMethod.addInstruction( 0, "return-void" - ) ?: throw TooltipContentViewFingerprint.exception + ) } } diff --git a/src/main/kotlin/app/revanced/patches/music/layout/overlayfilter/OverlayFilterBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/music/layout/overlayfilter/OverlayFilterBytecodePatch.kt index 96a462f9d..d7dc0ec22 100644 --- a/src/main/kotlin/app/revanced/patches/music/layout/overlayfilter/OverlayFilterBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/layout/overlayfilter/OverlayFilterBytecodePatch.kt @@ -9,7 +9,7 @@ import app.revanced.patches.music.layout.overlayfilter.fingerprints.DesignBottom import app.revanced.patches.music.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.music.utils.integrations.IntegrationsPatch import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch -import app.revanced.util.exception +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Patch( @@ -24,7 +24,7 @@ object OverlayFilterBytecodePatch : BytecodePatch( ) { override fun execute(context: BytecodeContext) { - DesignBottomSheetDialogFingerprint.result?.let { + DesignBottomSheetDialogFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.endIndex - 1 val freeRegister = getInstruction(insertIndex + 1).registerA @@ -37,7 +37,7 @@ object OverlayFilterBytecodePatch : BytecodePatch( """ ) } - } ?: throw DesignBottomSheetDialogFingerprint.exception + } } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/misc/backgroundplay/BackgroundPlayPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/backgroundplay/BackgroundPlayPatch.kt index 4d41b60c9..e3b2db008 100644 --- a/src/main/kotlin/app/revanced/patches/music/misc/backgroundplay/BackgroundPlayPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/misc/backgroundplay/BackgroundPlayPatch.kt @@ -4,8 +4,8 @@ import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patches.music.misc.backgroundplay.fingerprints.BackgroundPlaybackFingerprint import app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAGE -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object BackgroundPlayPatch : BaseBytecodePatch( @@ -16,7 +16,7 @@ object BackgroundPlayPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - BackgroundPlaybackFingerprint.result?.let { + BackgroundPlaybackFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstructions( 0, """ @@ -25,7 +25,7 @@ object BackgroundPlayPatch : BaseBytecodePatch( """ ) } - } ?: throw BackgroundPlaybackFingerprint.exception + } } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/misc/bitrate/BitrateDefaultValuePatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/bitrate/BitrateDefaultValuePatch.kt index 202222f5f..4086af7a5 100644 --- a/src/main/kotlin/app/revanced/patches/music/misc/bitrate/BitrateDefaultValuePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/misc/bitrate/BitrateDefaultValuePatch.kt @@ -10,6 +10,8 @@ object BitrateDefaultValuePatch : BaseResourcePatch( description = "Sets the audio quality to \"Always High\" when you first install the app.", compatiblePackages = COMPATIBLE_PACKAGE ) { + private const val RESOURCE_FILE_PATH = "res/xml/data_saving_settings.xml" + override fun execute(context: ResourceContext) { context.xmlEditor[RESOURCE_FILE_PATH].use { editor -> editor.file.getElementsByTagName("com.google.android.apps.youtube.music.ui.preference.PreferenceCategoryCompat") @@ -29,8 +31,5 @@ object BitrateDefaultValuePatch : BaseResourcePatch( } } } - } - - private const val RESOURCE_FILE_PATH = "res/xml/data_saving_settings.xml" } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/misc/exclusiveaudio/ExclusiveAudioPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/exclusiveaudio/ExclusiveAudioPatch.kt index 5cc4d60c3..4dc523015 100644 --- a/src/main/kotlin/app/revanced/patches/music/misc/exclusiveaudio/ExclusiveAudioPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/misc/exclusiveaudio/ExclusiveAudioPatch.kt @@ -8,10 +8,10 @@ import app.revanced.patches.music.misc.exclusiveaudio.fingerprints.DataSavingSet import app.revanced.patches.music.misc.exclusiveaudio.fingerprints.MusicBrowserServiceFingerprint import app.revanced.patches.music.misc.exclusiveaudio.fingerprints.PodCastConfigFingerprint import app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAGE -import app.revanced.util.exception import app.revanced.util.getStringInstructionIndex import app.revanced.util.getWalkerMethod import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -33,7 +33,7 @@ object ExclusiveAudioPatch : BaseBytecodePatch( /** * Don't play music videos */ - MusicBrowserServiceFingerprint.result?.let { + MusicBrowserServiceFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = getStringInstructionIndex("MBS: Return empty root for client: %s, isFullMediaBrowserEnabled: %b, is client browsable: %b, isRedAccount: %b") @@ -56,12 +56,12 @@ object ExclusiveAudioPatch : BaseBytecodePatch( break } } - } ?: throw MusicBrowserServiceFingerprint.exception + } /** * Don't play podcast videos */ - PodCastConfigFingerprint.result?.let { + PodCastConfigFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = implementation!!.instructions.size - 1 val targetRegister = getInstruction(insertIndex).registerA @@ -71,9 +71,9 @@ object ExclusiveAudioPatch : BaseBytecodePatch( "const/4 v$targetRegister, 0x1" ) } - } ?: throw PodCastConfigFingerprint.exception + } - DataSavingSettingsFragmentFingerprint.result?.let { + DataSavingSettingsFragmentFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = getStringInstructionIndex("pref_key_dont_play_nma_video") + 4 val targetRegister = getInstruction(insertIndex).registerD @@ -83,6 +83,6 @@ object ExclusiveAudioPatch : BaseBytecodePatch( "const/4 v$targetRegister, 0x1" ) } - } ?: throw DataSavingSettingsFragmentFingerprint.exception + } } } diff --git a/src/main/kotlin/app/revanced/patches/music/misc/minimizedplayback/MinimizedPlaybackPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/minimizedplayback/MinimizedPlaybackPatch.kt index c59142f1d..563a02dc7 100644 --- a/src/main/kotlin/app/revanced/patches/music/misc/minimizedplayback/MinimizedPlaybackPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/misc/minimizedplayback/MinimizedPlaybackPatch.kt @@ -4,8 +4,8 @@ import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patches.music.misc.minimizedplayback.fingerprints.MinimizedPlaybackManagerFingerprint import app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAGE -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object MinimizedPlaybackPatch : BaseBytecodePatch( @@ -16,9 +16,9 @@ object MinimizedPlaybackPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - MinimizedPlaybackManagerFingerprint.result?.mutableMethod?.addInstruction( + MinimizedPlaybackManagerFingerprint.resultOrThrow().mutableMethod.addInstruction( 0, "return-void" - ) ?: throw MinimizedPlaybackManagerFingerprint.exception + ) } } diff --git a/src/main/kotlin/app/revanced/patches/music/misc/premium/GetPremiumPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/premium/GetPremiumPatch.kt index e6564aaf6..2c316c8d7 100644 --- a/src/main/kotlin/app/revanced/patches/music/misc/premium/GetPremiumPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/misc/premium/GetPremiumPatch.kt @@ -12,12 +12,12 @@ import app.revanced.patches.music.navigation.component.NavigationBarComponentPat import app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.PrivacyTosFooter -import app.revanced.util.exception import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexWithReference import app.revanced.util.getWalkerMethod import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -41,7 +41,7 @@ object GetPremiumPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { // Hides get premium button at the bottom of the account switching menu - HideGetPremiumFingerprint.result?.let { + HideGetPremiumFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.startIndex val register = getInstruction(insertIndex).registerA @@ -51,10 +51,10 @@ object GetPremiumPatch : BaseBytecodePatch( "const/4 v$register, 0x0" ) } - } ?: throw HideGetPremiumFingerprint.exception + } // Hides get premium button at the top of the account switching menu - AccountMenuFooterFingerprint.result?.let { + AccountMenuFooterFingerprint.resultOrThrow().let { it.mutableMethod.apply { val constIndex = getWideLiteralInstructionIndex(PrivacyTosFooter) val walkerIndex = getTargetIndex(constIndex + 2, Opcode.INVOKE_VIRTUAL) @@ -73,18 +73,18 @@ object GetPremiumPatch : BaseBytecodePatch( ) } } - } ?: throw AccountMenuFooterFingerprint.exception + } // Hides premium membership menu in settings - MembershipSettingsParentFingerprint.result?.classDef?.let { classDef -> + MembershipSettingsParentFingerprint.resultOrThrow().classDef.let { classDef -> MembershipSettingsFingerprint.resolve(context, classDef) - MembershipSettingsFingerprint.result?.mutableMethod?.addInstructions( + MembershipSettingsFingerprint.resultOrThrow().mutableMethod.addInstructions( 0, """ const/4 v0, 0x0 return-object v0 """ - ) ?: throw MembershipSettingsFingerprint.exception - } ?: throw MembershipSettingsParentFingerprint.exception + ) + } } } diff --git a/src/main/kotlin/app/revanced/patches/music/misc/tastebuilder/TasteBuilderPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/tastebuilder/TasteBuilderPatch.kt index 43d84c4b5..d57fcb76a 100644 --- a/src/main/kotlin/app/revanced/patches/music/misc/tastebuilder/TasteBuilderPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/misc/tastebuilder/TasteBuilderPatch.kt @@ -9,10 +9,10 @@ import app.revanced.patches.music.misc.tastebuilder.fingerprints.TasteBuilderSyn import app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.MusicTasteBuilderShelf -import app.revanced.util.exception import app.revanced.util.getTargetIndex import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -25,7 +25,7 @@ object TasteBuilderPatch : BaseBytecodePatch( fingerprints = setOf(TasteBuilderConstructorFingerprint) ) { override fun execute(context: BytecodeContext) { - TasteBuilderConstructorFingerprint.result?.let { parentResult -> + TasteBuilderConstructorFingerprint.resultOrThrow().let { parentResult -> TasteBuilderSyntheticFingerprint.resolve(context, parentResult.classDef) parentResult.mutableMethod.apply { @@ -41,9 +41,9 @@ object TasteBuilderPatch : BaseBytecodePatch( """ ) } - } ?: throw TasteBuilderConstructorFingerprint.exception + } - TasteBuilderSyntheticFingerprint.result?.let { + TasteBuilderSyntheticFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.startIndex val insertRegister = getInstruction(insertIndex).registerA @@ -53,6 +53,6 @@ object TasteBuilderPatch : BaseBytecodePatch( "const/4 v$insertRegister, 0x0" ) } - } ?: throw TasteBuilderSyntheticFingerprint.exception + } } } diff --git a/src/main/kotlin/app/revanced/patches/music/navigation/black/BlackNavigationBarPatch.kt b/src/main/kotlin/app/revanced/patches/music/navigation/black/BlackNavigationBarPatch.kt index 8e2111c41..60ffb6d6e 100644 --- a/src/main/kotlin/app/revanced/patches/music/navigation/black/BlackNavigationBarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/navigation/black/BlackNavigationBarPatch.kt @@ -9,8 +9,8 @@ import app.revanced.patches.music.utils.integrations.Constants.NAVIGATION_CLASS_ import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -26,7 +26,7 @@ object BlackNavigationBarPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - TabLayoutFingerprint.result?.let { + TabLayoutFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.endIndex val targetRegister = getInstruction(targetIndex).registerA @@ -38,7 +38,7 @@ object BlackNavigationBarPatch : BaseBytecodePatch( """ ) } - } ?: throw TabLayoutFingerprint.exception + } SettingsPatch.addMusicPreference( CategoryType.NAVIGATION, diff --git a/src/main/kotlin/app/revanced/patches/music/navigation/component/NavigationBarComponentPatch.kt b/src/main/kotlin/app/revanced/patches/music/navigation/component/NavigationBarComponentPatch.kt index ef92a6fee..a04261187 100644 --- a/src/main/kotlin/app/revanced/patches/music/navigation/component/NavigationBarComponentPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/navigation/component/NavigationBarComponentPatch.kt @@ -10,11 +10,11 @@ import app.revanced.patches.music.utils.integrations.Constants.NAVIGATION_CLASS_ import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -38,7 +38,7 @@ object NavigationBarComponentPatch : BaseBytecodePatch( /** * Hide navigation labels */ - TabLayoutTextFingerprint.result?.let { + TabLayoutTextFingerprint.resultOrThrow().let { it.mutableMethod.apply { val constIndex = getWideLiteralInstructionIndex(SharedResourceIdPatch.Text1) val targetIndex = getTargetIndex(constIndex, Opcode.CHECK_CAST) @@ -53,7 +53,7 @@ object NavigationBarComponentPatch : BaseBytecodePatch( "invoke-static {v$targetRegister}, $NAVIGATION_CLASS_DESCRIPTOR->hideNavigationLabel(Landroid/widget/TextView;)V" ) } - } ?: throw TabLayoutTextFingerprint.exception + } SettingsPatch.contexts.xmlEditor[RESOURCE_FILE_PATH].use { editor -> val document = editor.file @@ -71,7 +71,7 @@ object NavigationBarComponentPatch : BaseBytecodePatch( /** * Hide navigation bar & buttons */ - TabLayoutTextFingerprint.result?.let { + TabLayoutTextFingerprint.resultOrThrow().let { it.mutableMethod.apply { val enumIndex = it.scanResult.patternScanResult!!.startIndex + 3 val enumRegister = getInstruction(enumIndex).registerA @@ -90,7 +90,7 @@ object NavigationBarComponentPatch : BaseBytecodePatch( "sput-object v$enumRegister, $NAVIGATION_CLASS_DESCRIPTOR->lastPivotTab:Ljava/lang/Enum;" ) } - } ?: throw TabLayoutTextFingerprint.exception + } SettingsPatch.addMusicPreference( CategoryType.NAVIGATION, diff --git a/src/main/kotlin/app/revanced/patches/music/player/colormatchplayer/ColorMatchPlayerPatch.kt b/src/main/kotlin/app/revanced/patches/music/player/colormatchplayer/ColorMatchPlayerPatch.kt index 5da975855..77d6f6447 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/colormatchplayer/ColorMatchPlayerPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/colormatchplayer/ColorMatchPlayerPatch.kt @@ -13,11 +13,11 @@ import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.ColorGrey import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexReversed import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.MethodParameter @@ -43,11 +43,11 @@ object ColorMatchPlayerPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { - MiniPlayerConstructorFingerprint.result?.let { parentResult -> + MiniPlayerConstructorFingerprint.resultOrThrow().let { parentResult -> // Resolves fingerprints SwitchToggleColorFingerprint.resolve(context, parentResult.classDef) - SwitchToggleColorFingerprint.result?.let { + SwitchToggleColorFingerprint.resultOrThrow().let { it.mutableMethod.apply { methodParameter = parameters @@ -94,8 +94,8 @@ object ColorMatchPlayerPatch : BaseBytecodePatch( removeInstruction(invokeDirectIndex) } } - } ?: throw SwitchToggleColorFingerprint.exception - } ?: throw MiniPlayerConstructorFingerprint.exception + } + } SettingsPatch.addMusicPreference( CategoryType.PLAYER, diff --git a/src/main/kotlin/app/revanced/patches/music/player/minimizedplayer/MinimizedPlayerPatch.kt b/src/main/kotlin/app/revanced/patches/music/player/minimizedplayer/MinimizedPlayerPatch.kt index 07d644f37..e9993bad0 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/minimizedplayer/MinimizedPlayerPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/minimizedplayer/MinimizedPlayerPatch.kt @@ -8,8 +8,8 @@ import app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAG import app.revanced.patches.music.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -22,7 +22,7 @@ object MinimizedPlayerPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - MinimizedPlayerFingerprint.result?.let { + MinimizedPlayerFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.endIndex val insertRegister = getInstruction(insertIndex).registerA @@ -34,7 +34,7 @@ object MinimizedPlayerPatch : BaseBytecodePatch( """ ) } - } ?: throw MinimizedPlayerFingerprint.exception + } SettingsPatch.addMusicPreference( CategoryType.PLAYER, diff --git a/src/main/kotlin/app/revanced/patches/music/player/nextprevious/MiniPlayerButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/player/nextprevious/MiniPlayerButtonPatch.kt index 6c940bc3b..071060d52 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/nextprevious/MiniPlayerButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/nextprevious/MiniPlayerButtonPatch.kt @@ -23,12 +23,12 @@ import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.TopEnd import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch.TopStart import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getStringInstructionIndex import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexReversed import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction @@ -81,23 +81,20 @@ object MiniPlayerButtonPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { val miniPlayerConstructorMutableMethod = - MiniPlayerConstructorFingerprint.result?.mutableMethod - ?: throw MiniPlayerConstructorFingerprint.exception + MiniPlayerConstructorFingerprint.resultOrThrow().mutableMethod val mppWatchWhileLayoutMutableMethod = - MppWatchWhileLayoutFingerprint.result?.mutableMethod - ?: throw MppWatchWhileLayoutFingerprint.exception + MppWatchWhileLayoutFingerprint.resultOrThrow().mutableMethod val pendingIntentReceiverMutableMethod = - PendingIntentReceiverFingerprint.result?.mutableMethod - ?: throw PendingIntentReceiverFingerprint.exception + PendingIntentReceiverFingerprint.resultOrThrow().mutableMethod if (!SettingsPatch.upward0642) { - MiniPlayerParentFingerprint.result?.let { parentResult -> + MiniPlayerParentFingerprint.resultOrThrow().let { parentResult -> // Resolves fingerprints NextButtonVisibilityFingerprint.resolve(context, parentResult.classDef) - NextButtonVisibilityFingerprint.result?.let { + NextButtonVisibilityFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.startIndex + 1 val targetRegister = @@ -110,8 +107,8 @@ object MiniPlayerButtonPatch : BaseBytecodePatch( """ ) } - } ?: throw NextButtonVisibilityFingerprint.exception - } ?: throw MiniPlayerParentFingerprint.exception + } + } } else { miniPlayerConstructorMutableMethod.setInstanceFieldValue(NEXT_BUTTON_METHOD_NAME, TopStart) mppWatchWhileLayoutMutableMethod.setStaticFieldValue(NEXT_BUTTON_FIELD_NAME, TopStart) @@ -210,7 +207,7 @@ object MiniPlayerButtonPatch : BaseBytecodePatch( ) } ?: throw PatchException("onClickClass not found!") - PlayerPatchConstructorFingerprint.result?.let { + PlayerPatchConstructorFingerprint.resultOrThrow().let { val mutableClass = it.mutableClass mutableClass.methods.find { method -> method.name == methodName } ?.apply { @@ -227,14 +224,14 @@ object MiniPlayerButtonPatch : BaseBytecodePatch( ) addInstructionsWithLabels( 0, """ - sget-object v0, $PLAYER_CLASS_DESCRIPTOR->$fieldName:$onClickReferenceDefiningClass - if-eqz v0, :ignore - invoke-virtual {v0}, $onClickReference - :ignore - return-void - """ + sget-object v0, $PLAYER_CLASS_DESCRIPTOR->$fieldName:$onClickReferenceDefiningClass + if-eqz v0, :ignore + invoke-virtual {v0}, $onClickReference + :ignore + return-void + """ ) } - } ?: throw PlayerPatchConstructorFingerprint.exception + } } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/player/repeat/RememberRepeatPatch.kt b/src/main/kotlin/app/revanced/patches/music/player/repeat/RememberRepeatPatch.kt index 023f7008f..19b0c0970 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/repeat/RememberRepeatPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/repeat/RememberRepeatPatch.kt @@ -8,8 +8,8 @@ import app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAG import app.revanced.patches.music.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -21,7 +21,7 @@ object RememberRepeatPatch : BaseBytecodePatch( fingerprints = setOf(RepeatTrackFingerprint) ) { override fun execute(context: BytecodeContext) { - RepeatTrackFingerprint.result?.let { + RepeatTrackFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.endIndex val targetRegister = getInstruction(targetIndex).registerA @@ -33,7 +33,7 @@ object RememberRepeatPatch : BaseBytecodePatch( """ ) } - } ?: throw RepeatTrackFingerprint.exception + } SettingsPatch.addMusicPreference( CategoryType.PLAYER, diff --git a/src/main/kotlin/app/revanced/patches/music/player/replace/ReplaceCastButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/player/replace/ReplaceCastButtonPatch.kt index b49987085..5e123fdb7 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/replace/ReplaceCastButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/replace/ReplaceCastButtonPatch.kt @@ -19,9 +19,9 @@ import app.revanced.patches.music.utils.settings.SettingsPatch.contexts import app.revanced.patches.music.utils.videotype.VideoTypeHookPatch import app.revanced.util.ResourceGroup import app.revanced.util.copyResources -import app.revanced.util.exception import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -46,7 +46,7 @@ object ReplaceCastButtonPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { CastButtonContainerFingerprint.resolve(context, mainActivityClassDef) - CastButtonContainerFingerprint.result?.let { + CastButtonContainerFingerprint.resultOrThrow().let { it.mutableMethod.apply { val freeIndex = getWideLiteralInstructionIndex(PlayerCastMediaRouteButton) + 1 val freeRegister = getInstruction(freeIndex).registerA @@ -82,7 +82,7 @@ object ReplaceCastButtonPatch : BaseBytecodePatch( break } } - } ?: throw CastButtonContainerFingerprint.exception + } PlayerResponsePatch.injectPlaylistCall( "$UTILS_PATH/CheckMusicVideoPatch;" + diff --git a/src/main/kotlin/app/revanced/patches/music/player/share/ShareButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/player/share/ShareButtonPatch.kt index 80df0e887..522bf87cc 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/share/ShareButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/share/ShareButtonPatch.kt @@ -9,8 +9,8 @@ import app.revanced.patches.music.utils.integrations.Constants.PLAYER_CLASS_DESC import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @Suppress("unused") @@ -25,7 +25,7 @@ object ShareButtonPatch : BaseBytecodePatch( fingerprints = setOf(RemixGenericButtonFingerprint) ) { override fun execute(context: BytecodeContext) { - RemixGenericButtonFingerprint.result?.let { + RemixGenericButtonFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.endIndex val targetRegister = getInstruction(targetIndex).registerA @@ -37,7 +37,7 @@ object ShareButtonPatch : BaseBytecodePatch( """ ) } - } ?: throw RemixGenericButtonFingerprint.exception + } SettingsPatch.addMusicPreference( CategoryType.PLAYER, diff --git a/src/main/kotlin/app/revanced/patches/music/player/shuffle/RememberShufflePatch.kt b/src/main/kotlin/app/revanced/patches/music/player/shuffle/RememberShufflePatch.kt index 055fecc9b..2305bdb61 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/shuffle/RememberShufflePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/shuffle/RememberShufflePatch.kt @@ -15,8 +15,8 @@ import app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAG import app.revanced.patches.music.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import app.revanced.util.transformFields import app.revanced.util.traverseClassHierarchy import com.android.tools.smali.dexlib2.AccessFlags @@ -48,7 +48,7 @@ object RememberShufflePatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { - ShuffleClassReferenceFingerprint.result?.let { + ShuffleClassReferenceFingerprint.resultOrThrow().let { it.mutableMethod.apply { val startIndex = it.scanResult.patternScanResult!!.startIndex val endIndex = it.scanResult.patternScanResult!!.endIndex @@ -110,9 +110,9 @@ object RememberShufflePatch : BaseBytecodePatch( ).toMutable() } } - } ?: throw ShuffleClassReferenceFingerprint.exception + } - MusicPlaybackControlsFingerprint.result?.let { + MusicPlaybackControlsFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstruction( 0, @@ -158,7 +158,7 @@ object RememberShufflePatch : BaseBytecodePatch( it.mutableClass.methods.add(shuffleMethod) it.mutableClass.staticFields.add(shuffleField) } - } ?: throw MusicPlaybackControlsFingerprint.exception + } SettingsPatch.addMusicPreference( CategoryType.PLAYER, diff --git a/src/main/kotlin/app/revanced/patches/music/player/swipetodismiss/SwipeToDismissMiniPlayerPatch.kt b/src/main/kotlin/app/revanced/patches/music/player/swipetodismiss/SwipeToDismissMiniPlayerPatch.kt index bda49451d..6c80a972a 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/swipetodismiss/SwipeToDismissMiniPlayerPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/swipetodismiss/SwipeToDismissMiniPlayerPatch.kt @@ -19,7 +19,6 @@ import app.revanced.patches.music.utils.integrations.Constants.PLAYER_CLASS_DESC import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getReference import app.revanced.util.getStringInstructionIndex import app.revanced.util.getTargetIndex @@ -27,6 +26,7 @@ import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexWithFieldReferenceType import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -67,7 +67,7 @@ object SwipeToDismissMiniPlayerPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { if (!SettingsPatch.upward0642) { - SwipeToCloseFingerprint.result?.let { + SwipeToCloseFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = implementation!!.instructions.size - 1 val targetRegister = getInstruction(insertIndex).registerA @@ -79,21 +79,21 @@ object SwipeToDismissMiniPlayerPatch : BaseBytecodePatch( """ ) } - } ?: throw SwipeToCloseFingerprint.exception + } } else { // Dismiss mini player by swiping down - InteractionLoggingEnumFingerprint.result?.let { + InteractionLoggingEnumFingerprint.resultOrThrow().let { it.mutableMethod.apply { val stringIndex = getStringInstructionIndex("INTERACTION_LOGGING_GESTURE_TYPE_SWIPE") val sPutObjectIndex = getTargetIndex(stringIndex, Opcode.SPUT_OBJECT) sGetObjectReference = getInstruction(sPutObjectIndex).reference } - } ?: throw InteractionLoggingEnumFingerprint.exception + } - MusicActivityWidgetFingerprint.result?.let { + MusicActivityWidgetFingerprint.resultOrThrow().let { it.mutableMethod.apply { widgetIndex = getWideLiteralInstructionIndex(79500) @@ -105,13 +105,13 @@ object SwipeToDismissMiniPlayerPatch : BaseBytecodePatch( invokeDirectReference = getReference(Opcode.INVOKE_DIRECT, false) invokeInterfaceSecondaryReference = getReference(Opcode.INVOKE_INTERFACE, false) } - } ?: throw MusicActivityWidgetFingerprint.exception + } - HandleSearchRenderedFingerprint.result?.let { parentResult -> + HandleSearchRenderedFingerprint.resultOrThrow().let { parentResult -> // Resolves fingerprints HandleSignInEventFingerprint.resolve(context, parentResult.classDef) - HandleSignInEventFingerprint.result?.let { + HandleSignInEventFingerprint.resultOrThrow().let { val dismissBehaviorMethod = context.toMethodWalker(it.method) .nextMethod(it.scanResult.patternScanResult!!.startIndex, true) .getMethod() as MutableMethod @@ -145,14 +145,14 @@ object SwipeToDismissMiniPlayerPatch : BaseBytecodePatch( """, ExternalLabel("dismiss", getInstruction(insertIndex)) ) } - } ?: throw HandleSignInEventFingerprint.exception - } ?: throw HandleSearchRenderedFingerprint.exception + } + } // Endregion // Hides default text display when the app is cold started - MiniPlayerDefaultTextFingerprint.result?.let { + MiniPlayerDefaultTextFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.endIndex val insertRegister = getInstruction(insertIndex).registerB @@ -164,13 +164,13 @@ object SwipeToDismissMiniPlayerPatch : BaseBytecodePatch( """ ) } - } ?: throw MiniPlayerDefaultTextFingerprint.exception + } // Endregion // Hides default text display after dismissing the mini player - MiniPlayerDefaultViewVisibilityFingerprint.result?.let { + MiniPlayerDefaultViewVisibilityFingerprint.resultOrThrow().let { it.mutableClass.methods.find { method -> method.parameters == listOf("Landroid/view/View;", "I") }?.apply { @@ -193,7 +193,7 @@ object SwipeToDismissMiniPlayerPatch : BaseBytecodePatch( ) } ?: throw PatchException("Could not find targetMethod") - } ?: throw MiniPlayerDefaultViewVisibilityFingerprint.exception + } // Endregion diff --git a/src/main/kotlin/app/revanced/patches/music/player/zenmode/ZenModePatch.kt b/src/main/kotlin/app/revanced/patches/music/player/zenmode/ZenModePatch.kt index 0177625fa..9c4b1b333 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/zenmode/ZenModePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/zenmode/ZenModePatch.kt @@ -12,10 +12,10 @@ import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch import app.revanced.patches.music.utils.videotype.VideoTypeHookPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndex import app.revanced.util.getWalkerMethod import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -33,7 +33,7 @@ object ZenModePatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - MiniPlayerConstructorFingerprint.result?.let { parentResult -> + MiniPlayerConstructorFingerprint.resultOrThrow().let { parentResult -> // Resolves fingerprints SwitchToggleColorFingerprint.resolve(context, parentResult.classDef) ZenModeFingerprint.resolve(context, parentResult.classDef) @@ -56,7 +56,7 @@ object ZenModePatch : BaseBytecodePatch( } } - SwitchToggleColorFingerprint.result?.let { + SwitchToggleColorFingerprint.resultOrThrow().let { it.mutableMethod.apply { val invokeDirectIndex = getTargetIndex(Opcode.INVOKE_DIRECT) val walkerMethod = getWalkerMethod(context, invokeDirectIndex) @@ -70,8 +70,8 @@ object ZenModePatch : BaseBytecodePatch( """ ) } - } ?: throw SwitchToggleColorFingerprint.exception - } ?: throw MiniPlayerConstructorFingerprint.exception + } + } SettingsPatch.addMusicPreference( CategoryType.PLAYER, diff --git a/src/main/kotlin/app/revanced/patches/music/utils/fix/androidauto/AndroidAutoCertificatePatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/fix/androidauto/AndroidAutoCertificatePatch.kt index 45305c1d0..608d192e1 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/fix/androidauto/AndroidAutoCertificatePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/fix/androidauto/AndroidAutoCertificatePatch.kt @@ -4,8 +4,8 @@ import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patches.music.utils.fix.androidauto.fingerprints.CertificateCheckFingerprint import app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAGE -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object AndroidAutoCertificatePatch : BaseBytecodePatch( @@ -16,7 +16,7 @@ object AndroidAutoCertificatePatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - CertificateCheckFingerprint.result?.let { + CertificateCheckFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstructions( 0, """ @@ -25,7 +25,7 @@ object AndroidAutoCertificatePatch : BaseBytecodePatch( """ ) } - } ?: throw CertificateCheckFingerprint.exception + } } } diff --git a/src/main/kotlin/app/revanced/patches/music/utils/fix/clientspoof/ClientSpoofPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/fix/clientspoof/ClientSpoofPatch.kt index ffc66a83f..cbf2b5fda 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/fix/clientspoof/ClientSpoofPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/fix/clientspoof/ClientSpoofPatch.kt @@ -1,5 +1,5 @@ package app.revanced.patches.music.utils.fix.clientspoof -import app.revanced.patches.shared.clientspoof.AbstractClientSpoofPatch +import app.revanced.patches.shared.clientspoof.BaseClientSpoofPatch -object ClientSpoofPatch : AbstractClientSpoofPatch("com.google.android.apps.youtube.music") \ No newline at end of file +object ClientSpoofPatch : BaseClientSpoofPatch("com.google.android.apps.youtube.music") \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/utils/fix/fileprovider/FileProviderPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/fix/fileprovider/FileProviderPatch.kt index 31e762987..af0397b0f 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/fix/fileprovider/FileProviderPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/fix/fileprovider/FileProviderPatch.kt @@ -8,7 +8,7 @@ import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.music.utils.fix.fileprovider.fingerprints.FileProviderResolverFingerprint import app.revanced.patches.shared.packagename.PackageNamePatch -import app.revanced.util.exception +import app.revanced.util.resultOrThrow @Patch(dependencies = [PackageNamePatch::class]) object FileProviderPatch : BytecodePatch( @@ -28,7 +28,7 @@ object FileProviderPatch : BytecodePatch( * * To solve this issue, replace the package name of YouTube with YT Music's package name. */ - FileProviderResolverFingerprint.result?.let { + FileProviderResolverFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstructionsWithLabels( 0, """ @@ -40,7 +40,7 @@ object FileProviderPatch : BytecodePatch( """, ExternalLabel("ignore", getInstruction(0)) ) } - } ?: throw FileProviderResolverFingerprint.exception + } } } diff --git a/src/main/kotlin/app/revanced/patches/music/utils/mainactivity/MainActivityResolvePatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/mainactivity/MainActivityResolvePatch.kt index 9cd92cc43..496deb08c 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/mainactivity/MainActivityResolvePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/mainactivity/MainActivityResolvePatch.kt @@ -6,7 +6,7 @@ import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.music.utils.integrations.Constants.UTILS_PATH import app.revanced.patches.music.utils.mainactivity.fingerprints.MainActivityFingerprint -import app.revanced.util.exception +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.ClassDef object MainActivityResolvePatch : BytecodePatch( @@ -16,10 +16,10 @@ object MainActivityResolvePatch : BytecodePatch( private lateinit var onCreateMethod: MutableMethod override fun execute(context: BytecodeContext) { - MainActivityFingerprint.result?.let { + MainActivityFingerprint.resultOrThrow().let { mainActivityClassDef = it.classDef onCreateMethod = it.mutableMethod - } ?: throw MainActivityFingerprint.exception + } } fun injectInit( diff --git a/src/main/kotlin/app/revanced/patches/music/utils/overridequality/OverrideQualityHookPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/overridequality/OverrideQualityHookPatch.kt index e06385b71..fa6e45982 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/overridequality/OverrideQualityHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/overridequality/OverrideQualityHookPatch.kt @@ -15,7 +15,7 @@ import app.revanced.patches.music.utils.overridequality.fingerprints.VideoQualit import app.revanced.patches.music.utils.overridequality.fingerprints.VideoQualityPatchFingerprint import app.revanced.patches.music.utils.overridequality.fingerprints.VideoQualityTextFingerprint import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch -import app.revanced.util.exception +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @@ -41,7 +41,7 @@ object OverrideQualityHookPatch : BytecodePatch( override fun execute(context: BytecodeContext) { - VideoQualityListFingerprint.result?.let { + VideoQualityListFingerprint.resultOrThrow().let { val constructorMethod = it.mutableClass.methods.first { method -> MethodUtil.isConstructor(method) } val overrideMethod = @@ -67,9 +67,9 @@ object OverrideQualityHookPatch : BytecodePatch( "invoke-static {v$listRegister}, $INTEGRATIONS_VIDEO_QUALITY_CLASS_DESCRIPTOR->setVideoQualityList([Ljava/lang/Object;)V" ) } - } ?: throw VideoQualityListFingerprint.exception + } - VideoQualityPatchFingerprint.result?.let { + VideoQualityPatchFingerprint.resultOrThrow().let { it.mutableMethod.apply { it.mutableClass.staticFields.add( ImmutableField( @@ -90,9 +90,9 @@ object OverrideQualityHookPatch : BytecodePatch( """ ) } - } ?: throw VideoQualityPatchFingerprint.exception + } - VideoQualityTextFingerprint.result?.let { + VideoQualityTextFingerprint.resultOrThrow().let { it.mutableMethod.apply { val textIndex = it.scanResult.patternScanResult!!.endIndex val textRegister = getInstruction(textIndex).registerA @@ -102,6 +102,6 @@ object OverrideQualityHookPatch : BytecodePatch( "sput-object v$textRegister, $INTEGRATIONS_VIDEO_UTILS_CLASS_DESCRIPTOR->currentQuality:Ljava/lang/String;" ) } - } ?: throw VideoQualityTextFingerprint.exception + } } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/utils/overridespeed/OverrideSpeedHookPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/overridespeed/OverrideSpeedHookPatch.kt index 0d1e51c19..352bf16f1 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/overridespeed/OverrideSpeedHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/overridespeed/OverrideSpeedHookPatch.kt @@ -14,10 +14,10 @@ import app.revanced.patches.music.utils.overridespeed.fingerprints.PlaybackSpeed import app.revanced.patches.music.utils.overridespeed.fingerprints.PlaybackSpeedOnClickListenerFingerprint import app.revanced.patches.music.utils.overridespeed.fingerprints.PlaybackSpeedParentFingerprint import app.revanced.patches.music.utils.overridespeed.fingerprints.PlaybackSpeedPatchFingerprint -import app.revanced.util.exception import app.revanced.util.getTargetIndex import app.revanced.util.getWalkerMethod import app.revanced.util.getWideLiteralInstructionIndex +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -49,7 +49,7 @@ object OverrideSpeedHookPatch : BytecodePatch( override fun execute(context: BytecodeContext) { - PlaybackSpeedOnClickListenerFingerprint.result?.let { + PlaybackSpeedOnClickListenerFingerprint.resultOrThrow().let { it.mutableMethod.apply { val startIndex = getWideLiteralInstructionIndex(147448) val iGetObjectIndex = getTargetIndex(startIndex, Opcode.IGET_OBJECT) @@ -77,15 +77,15 @@ object OverrideSpeedHookPatch : BytecodePatch( "sput-object v$iPutRegister, $INTEGRATIONS_PLAYBACK_SPEED_CLASS_DESCRIPTOR->objectClass:$objectClass" ) } - } ?: throw PlaybackSpeedOnClickListenerFingerprint.exception + } - PlaybackSpeedParentFingerprint.result?.let { parentResult -> + PlaybackSpeedParentFingerprint.resultOrThrow().let { parentResult -> PlaybackSpeedFingerprint.also { it.resolve( context, parentResult.classDef ) - }.result?.let { + }.resultOrThrow().let { it.mutableMethod.apply { val startIndex = it.scanResult.patternScanResult!!.startIndex val endIndex = it.scanResult.patternScanResult!!.endIndex @@ -108,10 +108,10 @@ object OverrideSpeedHookPatch : BytecodePatch( ) } - } ?: throw PlaybackSpeedFingerprint.exception - } ?: throw PlaybackSpeedParentFingerprint.exception + } + } - PlaybackSpeedPatchFingerprint.result?.let { + PlaybackSpeedPatchFingerprint.resultOrThrow().let { it.mutableMethod.apply { it.mutableClass.staticFields.add( ImmutableField( @@ -138,6 +138,6 @@ object OverrideSpeedHookPatch : BytecodePatch( """ ) } - } ?: throw PlaybackSpeedPatchFingerprint.exception + } } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/utils/playerresponse/PlayerResponsePatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/playerresponse/PlayerResponsePatch.kt index 39c13d7b9..ad57dea5d 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/playerresponse/PlayerResponsePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/playerresponse/PlayerResponsePatch.kt @@ -5,7 +5,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.music.utils.playerresponse.fingerprints.PlaybackStartDescriptorFingerprint -import app.revanced.util.exception +import app.revanced.util.resultOrThrow object PlayerResponsePatch : BytecodePatch( setOf(PlaybackStartDescriptorFingerprint) @@ -37,8 +37,7 @@ object PlayerResponsePatch : BytecodePatch( override fun execute(context: BytecodeContext) { - insertMethod = PlaybackStartDescriptorFingerprint.result?.mutableMethod - ?: throw PlaybackStartDescriptorFingerprint.exception + insertMethod = PlaybackStartDescriptorFingerprint.resultOrThrow().mutableMethod } diff --git a/src/main/kotlin/app/revanced/patches/music/utils/playertype/PlayerTypeHookPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/playertype/PlayerTypeHookPatch.kt index e549e91fc..2a3bd7c43 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/playertype/PlayerTypeHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/playertype/PlayerTypeHookPatch.kt @@ -5,25 +5,24 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patches.music.utils.integrations.Constants.UTILS_PATH import app.revanced.patches.music.utils.playertype.fingerprint.PlayerTypeFingerprint -import app.revanced.util.exception +import app.revanced.util.resultOrThrow @Suppress("unused") object PlayerTypeHookPatch : BytecodePatch( setOf(PlayerTypeFingerprint) ) { + private const val INTEGRATIONS_CLASS_DESCRIPTOR = + "$UTILS_PATH/PlayerTypeHookPatch;" override fun execute(context: BytecodeContext) { - PlayerTypeFingerprint.result?.let { + PlayerTypeFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstruction( 0, "invoke-static {p1}, $INTEGRATIONS_CLASS_DESCRIPTOR->setPlayerType(Ljava/lang/Enum;)V" ) } - } ?: throw PlayerTypeFingerprint.exception + } } - - private const val INTEGRATIONS_CLASS_DESCRIPTOR = - "$UTILS_PATH/PlayerTypeHookPatch;" } diff --git a/src/main/kotlin/app/revanced/patches/music/utils/returnyoutubedislike/ReturnYouTubeDislikeBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/returnyoutubedislike/ReturnYouTubeDislikeBytecodePatch.kt index 85062a167..967304481 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/returnyoutubedislike/ReturnYouTubeDislikeBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/returnyoutubedislike/ReturnYouTubeDislikeBytecodePatch.kt @@ -13,8 +13,8 @@ import app.revanced.patches.music.utils.returnyoutubedislike.fingerprints.LikeFi import app.revanced.patches.music.utils.returnyoutubedislike.fingerprints.RemoveLikeFingerprint import app.revanced.patches.music.utils.returnyoutubedislike.fingerprints.TextComponentFingerprint import app.revanced.patches.music.video.videoid.VideoIdPatch -import app.revanced.util.exception import app.revanced.util.indexOfFirstInstruction +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -42,18 +42,16 @@ object ReturnYouTubeDislikeBytecodePatch : BytecodePatch( DislikeFingerprint.toPatch(Vote.DISLIKE), RemoveLikeFingerprint.toPatch(Vote.REMOVE_LIKE) ).forEach { (fingerprint, vote) -> - with(fingerprint.result ?: throw fingerprint.exception) { - mutableMethod.addInstructions( - 0, - """ + fingerprint.resultOrThrow().mutableMethod.addInstructions( + 0, + """ const/4 v0, ${vote.value} invoke-static {v0}, $INTEGRATIONS_RYD_CLASS_DESCRIPTOR->sendVote(I)V """ - ) - } + ) } - TextComponentFingerprint.result?.let { + TextComponentFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = indexOfFirstInstruction { opcode == Opcode.INVOKE_STATIC @@ -68,7 +66,7 @@ object ReturnYouTubeDislikeBytecodePatch : BytecodePatch( """ ) } - } ?: throw TextComponentFingerprint.exception + } VideoIdPatch.hookVideoId("$INTEGRATIONS_RYD_CLASS_DESCRIPTOR->newVideoLoaded(Ljava/lang/String;)V") diff --git a/src/main/kotlin/app/revanced/patches/music/utils/settings/SettingsBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/settings/SettingsBytecodePatch.kt index 397cbf09f..e45c85476 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/settings/SettingsBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/settings/SettingsBytecodePatch.kt @@ -16,8 +16,8 @@ import app.revanced.patches.music.utils.settings.fingerprints.GoogleApiActivityF import app.revanced.patches.music.utils.settings.fingerprints.PreferenceFingerprint import app.revanced.patches.music.utils.settings.fingerprints.SettingsHeadersFragmentFingerprint import app.revanced.patches.shared.settings.fingerprints.SharedSettingFingerprint -import app.revanced.util.exception import app.revanced.util.getTargetIndex +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -47,7 +47,7 @@ object SettingsBytecodePatch : BytecodePatch( /** * Set SharedPrefCategory */ - SharedSettingFingerprint.result?.let { + SharedSettingFingerprint.resultOrThrow().let { it.mutableMethod.apply { val stringIndex = getTargetIndex(Opcode.CONST_STRING) val stringRegister = getInstruction(stringIndex).registerA @@ -57,12 +57,12 @@ object SettingsBytecodePatch : BytecodePatch( "const-string v$stringRegister, \"youtube\"" ) } - } ?: throw SharedSettingFingerprint.exception + } /** * Inject settings Activity */ - SettingsHeadersFragmentFingerprint.result?.let { + SettingsHeadersFragmentFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.endIndex val targetRegister = getInstruction(targetIndex).registerA @@ -72,12 +72,12 @@ object SettingsBytecodePatch : BytecodePatch( "invoke-static {v$targetRegister}, $INTEGRATIONS_ACTIVITY_CLASS_DESCRIPTOR->setActivity(Ljava/lang/Object;)V" ) } - } ?: throw SettingsHeadersFragmentFingerprint.exception + } /** * Values are loaded when preferences change */ - PreferenceFingerprint.result?.let { + PreferenceFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.endIndex val keyRegister = getInstruction(targetIndex).registerD @@ -88,12 +88,12 @@ object SettingsBytecodePatch : BytecodePatch( "invoke-static {v$keyRegister, v$valueRegister}, $INTEGRATIONS_FRAGMENT_CLASS_DESCRIPTOR->onPreferenceChanged(Ljava/lang/String;Z)V" ) } - } ?: throw PreferenceFingerprint.exception + } /** * Inject dummy Activity for intent */ - GoogleApiActivityFingerprint.result?.let { + GoogleApiActivityFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstructionsWithLabels( 1, """ @@ -104,7 +104,7 @@ object SettingsBytecodePatch : BytecodePatch( """, ExternalLabel("show", getInstruction(1)) ) } - } ?: throw GoogleApiActivityFingerprint.exception + } injectInit("InitializationPatch", "setDeviceInformation") injectInit("InitializationPatch", "onCreate") diff --git a/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/SponsorBlockBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/SponsorBlockBytecodePatch.kt index e1891aa48..d92ad5445 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/SponsorBlockBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/SponsorBlockBytecodePatch.kt @@ -14,9 +14,9 @@ import app.revanced.patches.music.utils.sponsorblock.fingerprints.MusicPlaybackC import app.revanced.patches.music.utils.sponsorblock.fingerprints.SeekbarOnDrawFingerprint import app.revanced.patches.music.video.information.VideoInformationPatch import app.revanced.patches.music.video.videoid.VideoIdPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameReversed +import app.revanced.util.resultOrThrow 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 @@ -55,11 +55,10 @@ object SponsorBlockBytecodePatch : BytecodePatch( /** * Responsible for seekbar in fullscreen */ - val seekBarClass = SeekBarConstructorFingerprint.result?.mutableClass - ?: throw SeekBarConstructorFingerprint.exception + val seekBarClass = SeekBarConstructorFingerprint.resultOrThrow().mutableClass SeekbarOnDrawFingerprint.resolve(context, seekBarClass) - SeekbarOnDrawFingerprint.result?.let { + SeekbarOnDrawFingerprint.resultOrThrow().let { it.mutableMethod.apply { // Initialize seekbar method addInstructions( @@ -88,22 +87,22 @@ object SponsorBlockBytecodePatch : BytecodePatch( "$INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR->drawSponsorTimeBars(Landroid/graphics/Canvas;F)V" ) } - } ?: throw SeekbarOnDrawFingerprint.exception + } /** * Responsible for seekbar in player */ - MusicPlaybackControlsTimeBarOnMeasureFingerprint.result?.let { + MusicPlaybackControlsTimeBarOnMeasureFingerprint.resultOrThrow().let { it.mutableMethod.apply { val rectangleIndex = it.scanResult.patternScanResult!!.startIndex val rectangleReference = getInstruction(rectangleIndex).reference rectangleFieldName = (rectangleReference as FieldReference).name } - } ?: throw MusicPlaybackControlsTimeBarOnMeasureFingerprint.exception + } - MusicPlaybackControlsTimeBarDrawFingerprint.result?.let { + MusicPlaybackControlsTimeBarDrawFingerprint.resultOrThrow().let { it.mutableMethod.apply { // Initialize seekbar method addInstructions( @@ -123,7 +122,7 @@ object SponsorBlockBytecodePatch : BytecodePatch( "$INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR->drawSponsorTimeBars(Landroid/graphics/Canvas;F)V" ) } - } ?: throw MusicPlaybackControlsTimeBarDrawFingerprint.exception + } /** * Set current video id diff --git a/src/main/kotlin/app/revanced/patches/music/utils/videotype/VideoTypeHookPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/videotype/VideoTypeHookPatch.kt index e1e988f6d..b200542cb 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/videotype/VideoTypeHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/videotype/VideoTypeHookPatch.kt @@ -7,7 +7,7 @@ import app.revanced.patcher.patch.BytecodePatch import app.revanced.patches.music.utils.integrations.Constants.UTILS_PATH import app.revanced.patches.music.utils.videotype.fingerprint.VideoTypeFingerprint import app.revanced.patches.music.utils.videotype.fingerprint.VideoTypeParentFingerprint -import app.revanced.util.exception +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @Suppress("SpellCheckingInspection", "unused") @@ -19,13 +19,13 @@ object VideoTypeHookPatch : BytecodePatch( override fun execute(context: BytecodeContext) { - VideoTypeParentFingerprint.result?.let { parentResult -> + VideoTypeParentFingerprint.resultOrThrow().let { parentResult -> VideoTypeFingerprint.also { it.resolve( context, parentResult.classDef ) - }.result?.let { + }.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.startIndex + 3 val referenceIndex = insertIndex + 1 @@ -41,7 +41,7 @@ object VideoTypeHookPatch : BytecodePatch( """ ) } - } ?: throw VideoTypeFingerprint.exception - } ?: throw VideoTypeParentFingerprint.exception + } + } } } diff --git a/src/main/kotlin/app/revanced/patches/music/video/information/VideoInformationPatch.kt b/src/main/kotlin/app/revanced/patches/music/video/information/VideoInformationPatch.kt index 306965575..6dc62e1f7 100644 --- a/src/main/kotlin/app/revanced/patches/music/video/information/VideoInformationPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/video/information/VideoInformationPatch.kt @@ -16,10 +16,10 @@ import app.revanced.patches.music.video.information.fingerprints.PlayerControlle import app.revanced.patches.music.video.information.fingerprints.VideoEndFingerprint import app.revanced.patches.music.video.information.fingerprints.VideoLengthFingerprint import app.revanced.patches.music.video.videoid.VideoIdPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithFieldReferenceTypeReversed import app.revanced.util.getTargetIndexWithMethodReferenceNameReversed import app.revanced.util.getWalkerMethod +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -90,7 +90,7 @@ object VideoInformationPatch : BytecodePatch( ) override fun execute(context: BytecodeContext) { - VideoEndFingerprint.result?.let { + VideoEndFingerprint.resultOrThrow().let { playerInitMethod = it.mutableClass.methods.first { method -> MethodUtil.isConstructor(method) } @@ -120,19 +120,19 @@ object VideoInformationPatch : BytecodePatch( ) it.mutableClass.methods.add(seekHelperMethod) } - } ?: throw VideoEndFingerprint.exception + } /** * Set current video length */ - SeekBarConstructorFingerprint.result?.classDef?.let { classDef -> + SeekBarConstructorFingerprint.resultOrThrow().classDef.let { classDef -> VideoLengthFingerprint.also { it.resolve( context, classDef ) - }.result?.let { + }.resultOrThrow().let { it.mutableMethod.apply { val invalidateIndex = getTargetIndexWithMethodReferenceNameReversed("invalidate") val rectangleIndex = getTargetIndexWithFieldReferenceTypeReversed(invalidateIndex + 1, "Landroid/graphics/Rect;") @@ -149,16 +149,16 @@ object VideoInformationPatch : BytecodePatch( "invoke-static {v$videoLengthRegister, v$dummyRegisterForLong}, $INTEGRATIONS_CLASS_DESCRIPTOR->setVideoLength(J)V" ) } - } ?: throw VideoLengthFingerprint.exception - } ?: throw SeekBarConstructorFingerprint.exception + } + } /** * Set the video time method */ - PlayerControllerSetTimeReferenceFingerprint.result?.let { + PlayerControllerSetTimeReferenceFingerprint.resultOrThrow().let { timeMethod = it.getWalkerMethod(context, it.scanResult.patternScanResult!!.startIndex) - } ?: throw PlayerControllerSetTimeReferenceFingerprint.exception + } /** diff --git a/src/main/kotlin/app/revanced/patches/music/video/quality/VideoQualityPatch.kt b/src/main/kotlin/app/revanced/patches/music/video/quality/VideoQualityPatch.kt index 57f53320f..50c235667 100644 --- a/src/main/kotlin/app/revanced/patches/music/video/quality/VideoQualityPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/video/quality/VideoQualityPatch.kt @@ -11,8 +11,8 @@ import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch import app.revanced.patches.music.video.quality.fingerprints.UserQualityChangeFingerprint import app.revanced.patches.music.video.videoid.VideoIdPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction21c @Suppress("unused") @@ -32,7 +32,7 @@ object VideoQualityPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { - UserQualityChangeFingerprint.result?.let { + UserQualityChangeFingerprint.resultOrThrow().let { it.mutableMethod.apply { val endIndex = it.scanResult.patternScanResult!!.endIndex val qualityChangedClass = @@ -54,7 +54,7 @@ object VideoQualityPatch : BaseBytecodePatch( ) } ?: throw PatchException("Failed to find onItemClick method") } - } ?: throw UserQualityChangeFingerprint.exception + } VideoIdPatch.hookVideoId("$INTEGRATIONS_VIDEO_QUALITY_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;)V") diff --git a/src/main/kotlin/app/revanced/patches/music/video/speed/PlaybackSpeedPatch.kt b/src/main/kotlin/app/revanced/patches/music/video/speed/PlaybackSpeedPatch.kt index 750f54d5a..b778c5cb1 100644 --- a/src/main/kotlin/app/revanced/patches/music/video/speed/PlaybackSpeedPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/video/speed/PlaybackSpeedPatch.kt @@ -10,8 +10,8 @@ import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch import app.revanced.patches.music.video.speed.fingerprints.PlaybackSpeedBottomSheetFingerprint import app.revanced.patches.music.video.speed.fingerprints.PlaybackSpeedBottomSheetParentFingerprint -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction @Suppress("unused") @@ -30,13 +30,13 @@ object PlaybackSpeedPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { - PlaybackSpeedBottomSheetParentFingerprint.result?.let { parentResult -> + PlaybackSpeedBottomSheetParentFingerprint.resultOrThrow().let { parentResult -> PlaybackSpeedBottomSheetFingerprint.also { it.resolve( context, parentResult.classDef ) - }.result?.let { + }.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.startIndex val targetRegister = @@ -47,8 +47,8 @@ object PlaybackSpeedPatch : BaseBytecodePatch( "invoke-static {v$targetRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->userChangedSpeed(F)V" ) } - } ?: throw PlaybackSpeedBottomSheetFingerprint.exception - } ?: throw PlaybackSpeedBottomSheetParentFingerprint.exception + } + } SettingsPatch.addMusicPreference( CategoryType.VIDEO, diff --git a/src/main/kotlin/app/revanced/patches/music/video/videoid/VideoIdPatch.kt b/src/main/kotlin/app/revanced/patches/music/video/videoid/VideoIdPatch.kt index a7d60b130..9683ac09c 100644 --- a/src/main/kotlin/app/revanced/patches/music/video/videoid/VideoIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/video/videoid/VideoIdPatch.kt @@ -10,8 +10,8 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.music.video.videoid.fingerprints.PlayerResponseModelStoryboardRendererFingerprint import app.revanced.patches.music.video.videoid.fingerprints.VideoIdParentFingerprint -import app.revanced.util.exception import app.revanced.util.getTargetIndexReversed +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -36,7 +36,7 @@ object VideoIdPatch : BytecodePatch( override fun execute(context: BytecodeContext) { - VideoIdParentFingerprint.result?.let { result -> + VideoIdParentFingerprint.resultOrThrow().let { result -> val targetIndex = result.scanResult.patternScanResult!!.endIndex val targetReference = result.mutableMethod.getInstruction(targetIndex).reference val targetClass = (targetReference as FieldReference).type @@ -55,14 +55,17 @@ object VideoIdPatch : BytecodePatch( videoIdRegister = getInstruction(videoIdInsertIndex - 1).registerA } - } ?: throw VideoIdParentFingerprint.exception + } - PlayerResponseModelStoryboardRendererFingerprint.result - ?.mutableClass?.methods?.find { method -> method.name == backgroundPlaybackMethodName } + PlayerResponseModelStoryboardRendererFingerprint + .resultOrThrow() + .mutableClass + .methods + .find { method -> method.name == backgroundPlaybackMethodName } ?.apply { backgroundPlaybackMethod = this backgroundPlaybackInsertIndex = implementation!!.instructions.size - 1 - } ?: throw PlayerResponseModelStoryboardRendererFingerprint.exception + } } override fun close () { diff --git a/src/main/kotlin/app/revanced/patches/reddit/ad/comments/CommentAdsPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/ad/comments/CommentAdsPatch.kt index 8c328992d..74d90c4e6 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/ad/comments/CommentAdsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/ad/comments/CommentAdsPatch.kt @@ -7,8 +7,8 @@ import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.reddit.ad.comments.fingerprints.CommentAdsFingerprint import app.revanced.patches.reddit.utils.integrations.Constants.PATCHES_PATH -import app.revanced.util.exception import app.revanced.util.getWalkerMethod +import app.revanced.util.resultOrThrow object CommentAdsPatch : BytecodePatch( setOf(CommentAdsFingerprint) @@ -17,7 +17,7 @@ object CommentAdsPatch : BytecodePatch( "$PATCHES_PATH/GeneralAdsPatch;->hideCommentAds()Z" override fun execute(context: BytecodeContext) { - CommentAdsFingerprint.result?.apply { + CommentAdsFingerprint.resultOrThrow().apply { val walkerMethod = getWalkerMethod(context, scanResult.patternScanResult!!.startIndex) walkerMethod.apply { addInstructionsWithLabels( @@ -31,7 +31,7 @@ object CommentAdsPatch : BytecodePatch( """, ExternalLabel("show", getInstruction(0)) ) } - } ?: throw CommentAdsFingerprint.exception + } } } diff --git a/src/main/kotlin/app/revanced/patches/reddit/ad/general/AdsPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/ad/general/AdsPatch.kt index 40b3a0f48..65a0f99b7 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/ad/general/AdsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/ad/general/AdsPatch.kt @@ -13,10 +13,10 @@ import app.revanced.patches.reddit.utils.integrations.Constants.COMPATIBLE_PACKA import app.revanced.patches.reddit.utils.integrations.Constants.PATCHES_PATH import app.revanced.patches.reddit.utils.settings.SettingsBytecodePatch.updateSettingsStatus import app.revanced.patches.reddit.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithFieldReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @@ -41,7 +41,7 @@ object AdsPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { // region Filter promoted ads (does not work in popular or latest feed) - AdPostFingerprint.result?.let { + AdPostFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = getTargetIndexWithFieldReferenceName("children") val targetRegister = getInstruction(targetIndex).registerA @@ -53,12 +53,12 @@ object AdsPatch : BaseBytecodePatch( """ ) } - } ?: throw AdPostFingerprint.exception + } // The new feeds work by inserting posts into lists. // AdElementConverter is conveniently responsible for inserting all feed ads. // By removing the appending instruction no ad posts gets appended to the feed. - NewAdPostFingerprint.result?.let { + NewAdPostFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = getTargetIndexWithMethodReferenceName("add") val targetRegister = @@ -72,7 +72,7 @@ object AdsPatch : BaseBytecodePatch( """, ExternalLabel("show", getInstruction(targetIndex + 1)) ) } - } ?: throw NewAdPostFingerprint.exception + } updateSettingsStatus("enableGeneralAds") diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/NavigationButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/NavigationButtonsPatch.kt index 4a301daa4..367746f52 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/NavigationButtonsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/NavigationButtonsPatch.kt @@ -8,8 +8,8 @@ import app.revanced.patches.reddit.utils.integrations.Constants.COMPATIBLE_PACKA import app.revanced.patches.reddit.utils.integrations.Constants.PATCHES_PATH import app.revanced.patches.reddit.utils.settings.SettingsBytecodePatch.updateSettingsStatus import app.revanced.patches.reddit.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction @Suppress("unused") @@ -25,7 +25,7 @@ object NavigationButtonsPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { - BottomNavScreenFingerprint.result?.let { + BottomNavScreenFingerprint.resultOrThrow().let { it.mutableMethod.apply { val startIndex = it.scanResult.patternScanResult!!.startIndex val targetRegister = @@ -36,7 +36,7 @@ object NavigationButtonsPatch : BaseBytecodePatch( "invoke-static {v$targetRegister}, $INTEGRATIONS_METHOD_DESCRIPTOR" ) } - } ?: throw BottomNavScreenFingerprint.exception + } updateSettingsStatus("enableNavigationButtons") diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/premiumicon/PremiumIconPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/premiumicon/PremiumIconPatch.kt index ab8a048ea..27aef0b97 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/layout/premiumicon/PremiumIconPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/premiumicon/PremiumIconPatch.kt @@ -4,8 +4,8 @@ import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patches.reddit.layout.premiumicon.fingerprints.PremiumIconFingerprint import app.revanced.patches.reddit.utils.integrations.Constants.COMPATIBLE_PACKAGE -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object PremiumIconPatch : BaseBytecodePatch( @@ -16,7 +16,7 @@ object PremiumIconPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - PremiumIconFingerprint.result?.let { + PremiumIconFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstructions( 0, """ @@ -25,7 +25,7 @@ object PremiumIconPatch : BaseBytecodePatch( """ ) } - } ?: throw PremiumIconFingerprint.exception + } } } diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/recentlyvisited/RecentlyVisitedShelfPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/recentlyvisited/RecentlyVisitedShelfPatch.kt index ea4e63f34..2953e350b 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/layout/recentlyvisited/RecentlyVisitedShelfPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/recentlyvisited/RecentlyVisitedShelfPatch.kt @@ -9,12 +9,12 @@ import app.revanced.patches.reddit.utils.integrations.Constants.COMPATIBLE_PACKA import app.revanced.patches.reddit.utils.integrations.Constants.PATCHES_PATH import app.revanced.patches.reddit.utils.settings.SettingsBytecodePatch.updateSettingsStatus import app.revanced.patches.reddit.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexWithFieldReferenceName import app.revanced.util.getTargetIndexWithReference import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -35,7 +35,7 @@ object RecentlyVisitedShelfPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { - CommunityDrawerPresenterFingerprint.result?.let { + CommunityDrawerPresenterFingerprint.resultOrThrow().let { lateinit var recentlyVisitedReference: Reference it.mutableClass.methods.find { method -> method.name == "" } @@ -63,7 +63,7 @@ object RecentlyVisitedShelfPatch : BaseBytecodePatch( ) } } - } ?: throw CommunityDrawerPresenterFingerprint.exception + } updateSettingsStatus("enableRecentlyVisitedShelf") diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/ScreenshotPopupPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/ScreenshotPopupPatch.kt index 3690d1c4b..209873271 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/ScreenshotPopupPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/ScreenshotPopupPatch.kt @@ -10,8 +10,8 @@ import app.revanced.patches.reddit.utils.integrations.Constants.PATCHES_PATH import app.revanced.patches.reddit.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.reddit.utils.settings.SettingsBytecodePatch.updateSettingsStatus import app.revanced.patches.reddit.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object ScreenshotPopupPatch : BaseBytecodePatch( @@ -29,7 +29,7 @@ object ScreenshotPopupPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { - ScreenshotTakenBannerFingerprint.result?.let { + ScreenshotTakenBannerFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstructionsWithLabels( 0, """ @@ -40,7 +40,7 @@ object ScreenshotPopupPatch : BaseBytecodePatch( """, ExternalLabel("dismiss", getInstruction(0)) ) } - } ?: throw ScreenshotTakenBannerFingerprint.exception + } updateSettingsStatus("enableScreenshotPopup") diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/subredditdialog/SubRedditDialogPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/subredditdialog/SubRedditDialogPatch.kt index caa94ebf9..e0f193a5f 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/layout/subredditdialog/SubRedditDialogPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/subredditdialog/SubRedditDialogPatch.kt @@ -12,9 +12,9 @@ import app.revanced.patches.reddit.utils.resourceid.SharedResourceIdPatch.Cancel import app.revanced.patches.reddit.utils.resourceid.SharedResourceIdPatch.TextAppearanceRedditBaseOldButtonColored import app.revanced.patches.reddit.utils.settings.SettingsBytecodePatch.updateSettingsStatus import app.revanced.patches.reddit.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -37,7 +37,7 @@ object SubRedditDialogPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { - FrequentUpdatesSheetScreenFingerprint.result?.let { + FrequentUpdatesSheetScreenFingerprint.resultOrThrow().let { it.mutableMethod.apply { val cancelButtonViewIndex = getWideLiteralInstructionIndex(CancelButton) + 2 val cancelButtonViewRegister = getInstruction(cancelButtonViewIndex).registerA @@ -47,9 +47,9 @@ object SubRedditDialogPatch : BaseBytecodePatch( "invoke-static {v$cancelButtonViewRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->dismissDialog(Landroid/view/View;)V" ) } - } ?: throw FrequentUpdatesSheetScreenFingerprint.exception + } - RedditAlertDialogsFingerprint.result?.let { + RedditAlertDialogsFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = getWideLiteralInstructionIndex(TextAppearanceRedditBaseOldButtonColored) + 1 val insertRegister = getInstruction(insertIndex).registerC @@ -59,7 +59,7 @@ object SubRedditDialogPatch : BaseBytecodePatch( "invoke-static {v$insertRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->confirmDialog(Landroid/widget/TextView;)V" ) } - } ?: throw RedditAlertDialogsFingerprint.exception + } updateSettingsStatus("enableSubRedditDialog") diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/toolbar/ToolBarButtonPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/toolbar/ToolBarButtonPatch.kt index 6c8b80c3d..3acb9c125 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/layout/toolbar/ToolBarButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/toolbar/ToolBarButtonPatch.kt @@ -10,9 +10,9 @@ import app.revanced.patches.reddit.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.reddit.utils.resourceid.SharedResourceIdPatch.ToolBarNavSearchCtaContainer import app.revanced.patches.reddit.utils.settings.SettingsBytecodePatch.updateSettingsStatus import app.revanced.patches.reddit.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -31,7 +31,7 @@ object ToolBarButtonPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { - HomePagerScreenFingerprint.result?.let { + HomePagerScreenFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = getWideLiteralInstructionIndex(ToolBarNavSearchCtaContainer) + 3 @@ -43,7 +43,7 @@ object ToolBarButtonPatch : BaseBytecodePatch( "invoke-static {v$targetRegister}, $INTEGRATIONS_METHOD_DESCRIPTOR" ) } - } ?: throw HomePagerScreenFingerprint.exception + } updateSettingsStatus("enableToolBarButton") diff --git a/src/main/kotlin/app/revanced/patches/reddit/misc/openlink/OpenLinksDirectlyPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/misc/openlink/OpenLinksDirectlyPatch.kt index 067fe112b..c685f62d9 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/misc/openlink/OpenLinksDirectlyPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/misc/openlink/OpenLinksDirectlyPatch.kt @@ -7,8 +7,8 @@ import app.revanced.patches.reddit.utils.integrations.Constants.COMPATIBLE_PACKA import app.revanced.patches.reddit.utils.integrations.Constants.PATCHES_PATH import app.revanced.patches.reddit.utils.settings.SettingsBytecodePatch.updateSettingsStatus import app.revanced.patches.reddit.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object OpenLinksDirectlyPatch : BaseBytecodePatch( @@ -24,7 +24,7 @@ object OpenLinksDirectlyPatch : BaseBytecodePatch( "parseRedirectUri(Landroid/net/Uri;)Landroid/net/Uri;" override fun execute(context: BytecodeContext) { - ScreenNavigatorFingerprint.result?.let { + ScreenNavigatorFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstructions( 0, """ @@ -33,7 +33,7 @@ object OpenLinksDirectlyPatch : BaseBytecodePatch( """ ) } - } ?: throw ScreenNavigatorFingerprint.exception + } updateSettingsStatus("enableOpenLinksDirectly") diff --git a/src/main/kotlin/app/revanced/patches/reddit/misc/openlink/OpenLinksExternallyPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/misc/openlink/OpenLinksExternallyPatch.kt index 6c6e0fd53..fc6ae8796 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/misc/openlink/OpenLinksExternallyPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/misc/openlink/OpenLinksExternallyPatch.kt @@ -9,9 +9,9 @@ import app.revanced.patches.reddit.utils.integrations.Constants.COMPATIBLE_PACKA import app.revanced.patches.reddit.utils.integrations.Constants.PATCHES_PATH import app.revanced.patches.reddit.utils.settings.SettingsBytecodePatch.updateSettingsStatus import app.revanced.patches.reddit.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getStringInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object OpenLinksExternallyPatch : BaseBytecodePatch( @@ -25,7 +25,7 @@ object OpenLinksExternallyPatch : BaseBytecodePatch( "$PATCHES_PATH/OpenLinksExternallyPatch;" override fun execute(context: BytecodeContext) { - ScreenNavigatorFingerprint.result?.let { + ScreenNavigatorFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = getStringInstructionIndex("uri") + 2 @@ -38,7 +38,7 @@ object OpenLinksExternallyPatch : BaseBytecodePatch( """, ExternalLabel("dismiss", getInstruction(insertIndex)) ) } - } ?: throw ScreenNavigatorFingerprint.exception + } updateSettingsStatus("enableOpenLinksExternally") diff --git a/src/main/kotlin/app/revanced/patches/reddit/misc/tracking/url/SanitizeUrlQueryPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/misc/tracking/url/SanitizeUrlQueryPatch.kt index 26b6f959a..aeb6802c6 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/misc/tracking/url/SanitizeUrlQueryPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/misc/tracking/url/SanitizeUrlQueryPatch.kt @@ -9,8 +9,8 @@ import app.revanced.patches.reddit.utils.integrations.Constants.COMPATIBLE_PACKA import app.revanced.patches.reddit.utils.integrations.Constants.PATCHES_PATH import app.revanced.patches.reddit.utils.settings.SettingsBytecodePatch.updateSettingsStatus import app.revanced.patches.reddit.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object SanitizeUrlQueryPatch : BaseBytecodePatch( @@ -24,7 +24,7 @@ object SanitizeUrlQueryPatch : BaseBytecodePatch( "$PATCHES_PATH/SanitizeUrlQueryPatch;->stripQueryParameters()Z" override fun execute(context: BytecodeContext) { - ShareLinkFormatterFingerprint.result?.let { result -> + ShareLinkFormatterFingerprint.resultOrThrow().let { result -> result.mutableMethod.apply { addInstructionsWithLabels( 0, @@ -36,7 +36,7 @@ object SanitizeUrlQueryPatch : BaseBytecodePatch( """, ExternalLabel("off", getInstruction(0)) ) } - } ?: throw ShareLinkFormatterFingerprint.exception + } updateSettingsStatus("enableSanitizeUrlQuery") diff --git a/src/main/kotlin/app/revanced/patches/reddit/utils/settings/SettingsBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/reddit/utils/settings/SettingsBytecodePatch.kt index 3f07599d7..238ee14ca 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/utils/settings/SettingsBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/utils/settings/SettingsBytecodePatch.kt @@ -15,9 +15,9 @@ import app.revanced.patches.reddit.utils.settings.fingerprints.AcknowledgementsL import app.revanced.patches.reddit.utils.settings.fingerprints.OssLicensesMenuActivityOnCreateFingerprint import app.revanced.patches.reddit.utils.settings.fingerprints.SettingsStatusLoadFingerprint import app.revanced.patches.shared.settings.fingerprints.SharedSettingFingerprint -import app.revanced.util.exception import app.revanced.util.getTargetIndex import app.revanced.util.getWideLiteralInstructionIndex +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -47,7 +47,7 @@ object SettingsBytecodePatch : BytecodePatch( /** * Set SharedPrefCategory */ - SharedSettingFingerprint.result?.let { + SharedSettingFingerprint.resultOrThrow().let { it.mutableMethod.apply { val stringIndex = getTargetIndex(Opcode.CONST_STRING) val stringRegister = getInstruction(stringIndex).registerA @@ -57,12 +57,12 @@ object SettingsBytecodePatch : BytecodePatch( "const-string v$stringRegister, \"reddit_revanced\"" ) } - } ?: throw SharedSettingFingerprint.exception + } /** * Replace settings label */ - AcknowledgementsLabelBuilderFingerprint.result?.let { + AcknowledgementsLabelBuilderFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = getWideLiteralInstructionIndex(LabelAcknowledgements) + 3 @@ -74,12 +74,12 @@ object SettingsBytecodePatch : BytecodePatch( "const-string v$insertRegister, \"ReVanced Extended\"" ) } - } ?: throw AcknowledgementsLabelBuilderFingerprint.exception + } /** * Initialize settings activity */ - OssLicensesMenuActivityOnCreateFingerprint.result?.let { + OssLicensesMenuActivityOnCreateFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.startIndex + 1 @@ -90,10 +90,9 @@ object SettingsBytecodePatch : BytecodePatch( """ ) } - } ?: throw OssLicensesMenuActivityOnCreateFingerprint.exception + } - settingsStatusLoadMethod = SettingsStatusLoadFingerprint.result?.mutableMethod - ?: throw SettingsStatusLoadFingerprint.exception + settingsStatusLoadMethod = SettingsStatusLoadFingerprint.resultOrThrow().mutableMethod } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/shared/ads/BaseAdsPatch.kt b/src/main/kotlin/app/revanced/patches/shared/ads/BaseAdsPatch.kt index 287849422..a6ac1724e 100644 --- a/src/main/kotlin/app/revanced/patches/shared/ads/BaseAdsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/shared/ads/BaseAdsPatch.kt @@ -8,9 +8,9 @@ import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.shared.ads.fingerprints.MusicAdsFingerprint import app.revanced.patches.shared.ads.fingerprints.VideoAdsFingerprint -import app.revanced.util.exception import app.revanced.util.getWalkerMethod import app.revanced.util.indexOfFirstInstruction +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.reference.MethodReference @@ -25,7 +25,7 @@ abstract class BaseAdsPatch( ) ) { override fun execute(context: BytecodeContext) { - MusicAdsFingerprint.result?.let { + MusicAdsFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = indexOfFirstInstruction { val reference = ((this as? ReferenceInstruction)?.reference as? MethodReference) @@ -44,9 +44,9 @@ abstract class BaseAdsPatch( """ ) } - } ?: throw MusicAdsFingerprint.exception + } - VideoAdsFingerprint.result?.let { + VideoAdsFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstructionsWithLabels( 0, """ @@ -57,6 +57,6 @@ abstract class BaseAdsPatch( """, ExternalLabel("show_ads", getInstruction(0)) ) } - } ?: throw VideoAdsFingerprint.exception + } } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/shared/captions/BaseAutoCaptionsPatch.kt b/src/main/kotlin/app/revanced/patches/shared/captions/BaseAutoCaptionsPatch.kt index d147f76d8..7be4be1d8 100644 --- a/src/main/kotlin/app/revanced/patches/shared/captions/BaseAutoCaptionsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/shared/captions/BaseAutoCaptionsPatch.kt @@ -7,9 +7,9 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patches.shared.captions.fingerprints.StartVideoInformerFingerprint import app.revanced.patches.shared.captions.fingerprints.SubtitleTrackFingerprint -import app.revanced.util.exception import app.revanced.util.getWalkerMethod import app.revanced.util.indexOfFirstInstruction +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -25,16 +25,16 @@ abstract class BaseAutoCaptionsPatch( ) { override fun execute(context: BytecodeContext) { - StartVideoInformerFingerprint.result?.let { + StartVideoInformerFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstruction( 0, "invoke-static {}, $classDescriptor->prefetchSubtitleTrack()V" ) } - } ?: throw StartVideoInformerFingerprint.exception + } - SubtitleTrackFingerprint.result?.let { + SubtitleTrackFingerprint.resultOrThrow().let { val targetMethod = it.getWalkerMethod(context, it.scanResult.patternScanResult!!.startIndex + 1) targetMethod.apply { @@ -51,7 +51,7 @@ abstract class BaseAutoCaptionsPatch( """ ) } - } ?: throw SubtitleTrackFingerprint.exception + } } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/shared/clientspoof/AbstractClientSpoofPatch.kt b/src/main/kotlin/app/revanced/patches/shared/clientspoof/BaseClientSpoofPatch.kt similarity index 98% rename from src/main/kotlin/app/revanced/patches/shared/clientspoof/AbstractClientSpoofPatch.kt rename to src/main/kotlin/app/revanced/patches/shared/clientspoof/BaseClientSpoofPatch.kt index 046bf903a..c21ad9bc6 100644 --- a/src/main/kotlin/app/revanced/patches/shared/clientspoof/AbstractClientSpoofPatch.kt +++ b/src/main/kotlin/app/revanced/patches/shared/clientspoof/BaseClientSpoofPatch.kt @@ -16,7 +16,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.Instruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.reference.MethodReference -abstract class AbstractClientSpoofPatch( +abstract class BaseClientSpoofPatch( private val packageName: String ) : BaseTransformInstructionsPatch() { override fun filterMap( diff --git a/src/main/kotlin/app/revanced/patches/shared/customspeed/BaseCustomPlaybackSpeedPatch.kt b/src/main/kotlin/app/revanced/patches/shared/customspeed/BaseCustomPlaybackSpeedPatch.kt index 2bcb3f0a6..be7954ba6 100644 --- a/src/main/kotlin/app/revanced/patches/shared/customspeed/BaseCustomPlaybackSpeedPatch.kt +++ b/src/main/kotlin/app/revanced/patches/shared/customspeed/BaseCustomPlaybackSpeedPatch.kt @@ -8,10 +8,10 @@ import app.revanced.patcher.patch.BytecodePatch import app.revanced.patches.shared.customspeed.fingerprints.SpeedArrayGeneratorFingerprint import app.revanced.patches.shared.customspeed.fingerprints.SpeedLimiterFallBackFingerprint import app.revanced.patches.shared.customspeed.fingerprints.SpeedLimiterFingerprint -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithFieldReferenceType import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.indexOfFirstInstruction +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.NarrowLiteralInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -25,9 +25,9 @@ abstract class BaseCustomPlaybackSpeedPatch( ) ) { override fun execute(context: BytecodeContext) { - SpeedArrayGeneratorFingerprint.result?.let { result -> - result.mutableMethod.apply { - val targetIndex = result.scanResult.patternScanResult!!.startIndex + SpeedArrayGeneratorFingerprint.resultOrThrow().let { + it.mutableMethod.apply { + val targetIndex = it.scanResult.patternScanResult!!.startIndex val targetRegister = getInstruction(targetIndex).registerA addInstructions( @@ -57,13 +57,11 @@ abstract class BaseCustomPlaybackSpeedPatch( """ ) } - } ?: throw SpeedArrayGeneratorFingerprint.exception + } - val speedLimiterParentResult = SpeedLimiterFallBackFingerprint.result - ?: throw SpeedLimiterFallBackFingerprint.exception + val speedLimiterParentResult = SpeedLimiterFallBackFingerprint.resultOrThrow() SpeedLimiterFingerprint.resolve(context, speedLimiterParentResult.classDef) - val speedLimiterResult = SpeedLimiterFingerprint.result - ?: throw SpeedLimiterFingerprint.exception + val speedLimiterResult = SpeedLimiterFingerprint.resultOrThrow() arrayOf( speedLimiterParentResult, diff --git a/src/main/kotlin/app/revanced/patches/shared/dialog/BaseViewerDiscretionDialogPatch.kt b/src/main/kotlin/app/revanced/patches/shared/dialog/BaseViewerDiscretionDialogPatch.kt index 1a5820f0f..4fbfd9fa3 100644 --- a/src/main/kotlin/app/revanced/patches/shared/dialog/BaseViewerDiscretionDialogPatch.kt +++ b/src/main/kotlin/app/revanced/patches/shared/dialog/BaseViewerDiscretionDialogPatch.kt @@ -7,9 +7,9 @@ import app.revanced.patcher.fingerprint.MethodFingerprint import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.shared.dialog.fingerprints.CreateDialogFingerprint -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getWalkerMethod +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction abstract class BaseViewerDiscretionDialogPatch( @@ -38,15 +38,14 @@ abstract class BaseViewerDiscretionDialogPatch( } override fun execute(context: BytecodeContext) { - CreateDialogFingerprint.result?.mutableMethod?.invoke(false) - ?: throw CreateDialogFingerprint.exception + CreateDialogFingerprint.resultOrThrow().mutableMethod.invoke(false) if (additionalFingerprints.isNotEmpty()) { additionalFingerprints.forEach { fingerprint -> - fingerprint.result?.let { + fingerprint.resultOrThrow().let { it.getWalkerMethod(context, it.scanResult.patternScanResult!!.endIndex - 1) .invoke(true) - } ?: throw fingerprint.exception + } } } diff --git a/src/main/kotlin/app/revanced/patches/shared/drawable/DrawableColorPatch.kt b/src/main/kotlin/app/revanced/patches/shared/drawable/DrawableColorPatch.kt index 4be705cf7..6761122a4 100644 --- a/src/main/kotlin/app/revanced/patches/shared/drawable/DrawableColorPatch.kt +++ b/src/main/kotlin/app/revanced/patches/shared/drawable/DrawableColorPatch.kt @@ -6,8 +6,8 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.shared.drawable.fingerprints.DrawableFingerprint -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithMethodReferenceNameReversed +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction object DrawableColorPatch : BytecodePatch( @@ -15,11 +15,11 @@ object DrawableColorPatch : BytecodePatch( ) { override fun execute(context: BytecodeContext) { - DrawableFingerprint.result?.mutableMethod?.apply { + DrawableFingerprint.resultOrThrow().mutableMethod?.apply { insertMethod = this insertIndex = getTargetIndexWithMethodReferenceNameReversed("setColor") insertRegister = getInstruction(insertIndex).registerD - } ?: throw DrawableFingerprint.exception + } } private var offset = 0 diff --git a/src/main/kotlin/app/revanced/patches/shared/gms/BaseGmsCoreSupportPatch.kt b/src/main/kotlin/app/revanced/patches/shared/gms/BaseGmsCoreSupportPatch.kt index ad26be13f..3596d91d0 100644 --- a/src/main/kotlin/app/revanced/patches/shared/gms/BaseGmsCoreSupportPatch.kt +++ b/src/main/kotlin/app/revanced/patches/shared/gms/BaseGmsCoreSupportPatch.kt @@ -7,15 +7,21 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstructions import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patcher.fingerprint.MethodFingerprint import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patches.shared.gms.fingerprints.* -import app.revanced.patches.shared.gms.fingerprints.GmsCoreSupportFingerprint.GET_GMS_CORE_VENDOR_GROUP_ID_METHOD_NAME import app.revanced.patches.shared.gms.BaseGmsCoreSupportPatch.Constants.ACTIONS import app.revanced.patches.shared.gms.BaseGmsCoreSupportPatch.Constants.AUTHORITIES import app.revanced.patches.shared.gms.BaseGmsCoreSupportPatch.Constants.PERMISSIONS +import app.revanced.patches.shared.gms.fingerprints.CastContextFetchFingerprint +import app.revanced.patches.shared.gms.fingerprints.CastDynamiteModuleFingerprint +import app.revanced.patches.shared.gms.fingerprints.CastDynamiteModuleV2Fingerprint +import app.revanced.patches.shared.gms.fingerprints.GmsCoreSupportFingerprint +import app.revanced.patches.shared.gms.fingerprints.GmsCoreSupportFingerprint.GET_GMS_CORE_VENDOR_GROUP_ID_METHOD_NAME +import app.revanced.patches.shared.gms.fingerprints.GooglePlayUtilityFingerprint +import app.revanced.patches.shared.gms.fingerprints.PrimeMethodFingerprint +import app.revanced.patches.shared.gms.fingerprints.ServiceCheckFingerprint import app.revanced.patches.shared.integrations.Constants.INTEGRATIONS_PATH import app.revanced.patches.shared.packagename.PackageNamePatch -import app.revanced.util.exception import app.revanced.util.getReference +import app.revanced.util.resultOrThrow import app.revanced.util.returnEarly import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction21c @@ -98,17 +104,16 @@ abstract class BaseGmsCoreSupportPatch( ).returnEarly() // Verify GmsCore is installed and whitelisted for power optimizations and background usage. - mainActivityOnCreateFingerprint.result?.mutableMethod?.addInstructions( + mainActivityOnCreateFingerprint.resultOrThrow().mutableMethod.addInstructions( 1, // Hack to not disturb other patches (such as the YTMusic integrations patch). "invoke-static/range { p0 .. p0 }, $INTEGRATIONS_PATH/patches/GmsCoreSupport;->" + - "checkGmsCore(Landroid/content/Context;)V", - ) ?: throw mainActivityOnCreateFingerprint.exception + "checkGmsCore(Landroid/content/Context;)V", + ) // Change the vendor of GmsCore in ReVanced Integrations. - GmsCoreSupportFingerprint.result?.mutableClass?.methods - ?.single { it.name == GET_GMS_CORE_VENDOR_GROUP_ID_METHOD_NAME } - ?.replaceInstruction(0, "const-string v0, \"$gmsCoreVendorGroupId\"") - ?: throw GmsCoreSupportFingerprint.exception + GmsCoreSupportFingerprint.resultOrThrow().mutableClass.methods + .single { it.name == GET_GMS_CORE_VENDOR_GROUP_ID_METHOD_NAME } + .replaceInstruction(0, "const-string v0, \"$gmsCoreVendorGroupId\"") } private fun BytecodeContext.transformStringReferences(transform: (str: String) -> String?) = classes.forEach { @@ -193,7 +198,7 @@ abstract class BaseGmsCoreSupportPatch( } private fun transformPrimeMethod(packageName: String) { - PrimeMethodFingerprint.result?.mutableMethod?.apply { + PrimeMethodFingerprint.resultOrThrow().mutableMethod.apply { var register = 2 val index = getInstructions().indexOfFirst { @@ -204,7 +209,7 @@ abstract class BaseGmsCoreSupportPatch( } replaceInstruction(index, "const-string v$register, \"$packageName\"") - } ?: throw PrimeMethodFingerprint.exception + } } /** diff --git a/src/main/kotlin/app/revanced/patches/shared/integrations/BaseIntegrationsPatch.kt b/src/main/kotlin/app/revanced/patches/shared/integrations/BaseIntegrationsPatch.kt index 27c2c9be0..964cf7fcb 100644 --- a/src/main/kotlin/app/revanced/patches/shared/integrations/BaseIntegrationsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/shared/integrations/BaseIntegrationsPatch.kt @@ -7,6 +7,7 @@ import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchException import app.revanced.patches.shared.integrations.BaseIntegrationsPatch.IntegrationsFingerprint.IRegisterResolver import app.revanced.patches.shared.integrations.Constants.INTEGRATIONS_UTILS_CLASS_DESCRIPTOR +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.ClassDef import com.android.tools.smali.dexlib2.iface.Method @@ -83,16 +84,16 @@ abstract class BaseIntegrationsPatch( ) fun invoke(integrationsDescriptor: String) { - result?.mutableMethod?.let { method -> + resultOrThrow().mutableMethod.let { method -> val insertIndex = insertIndexResolver(method) val contextRegister = contextRegisterResolver(method) method.addInstruction( insertIndex, "invoke-static/range { v$contextRegister .. v$contextRegister }, " + - "$integrationsDescriptor->setContext(Landroid/content/Context;)V", + "$integrationsDescriptor->setContext(Landroid/content/Context;)V", ) - } ?: throw PatchException("Could not find hook target fingerprint.") + } } interface IHookInsertIndexResolver : (Method) -> Int { diff --git a/src/main/kotlin/app/revanced/patches/shared/litho/LithoFilterPatch.kt b/src/main/kotlin/app/revanced/patches/shared/litho/LithoFilterPatch.kt index 861b8fbc0..5e08b10cd 100644 --- a/src/main/kotlin/app/revanced/patches/shared/litho/LithoFilterPatch.kt +++ b/src/main/kotlin/app/revanced/patches/shared/litho/LithoFilterPatch.kt @@ -12,11 +12,11 @@ import app.revanced.patches.shared.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.shared.litho.fingerprints.LithoFilterPatchConstructorFingerprint import app.revanced.patches.shared.litho.fingerprints.PathBuilderFingerprint import app.revanced.patches.shared.litho.fingerprints.SetByteBufferFingerprint -import app.revanced.util.exception import app.revanced.util.getEmptyStringInstructionIndex import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexWithFieldReferenceType +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction35c import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -44,7 +44,7 @@ object LithoFilterPatch : BytecodePatch( override fun execute(context: BytecodeContext) { - SetByteBufferFingerprint.result?.let { + SetByteBufferFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = getTargetIndex(Opcode.IF_EQZ) + 1 @@ -53,9 +53,9 @@ object LithoFilterPatch : BytecodePatch( "invoke-static { p2 }, $INTEGRATIONS_LITHO_FILER_CLASS_DESCRIPTOR->setProtoBuffer(Ljava/nio/ByteBuffer;)V" ) } - } ?: throw SetByteBufferFingerprint.exception + } - PathBuilderFingerprint.result?.let { + PathBuilderFingerprint.resultOrThrow().let { it.mutableMethod.apply { val emptyComponentMethodIndex = it.scanResult.patternScanResult!!.startIndex + 1 val emptyComponentMethodReference = @@ -89,9 +89,9 @@ object LithoFilterPatch : BytecodePatch( """, ExternalLabel("filter", getInstruction(insertIndex)) ) } - } ?: throw PathBuilderFingerprint.exception + } - LithoFilterPatchConstructorFingerprint.result?.let { + LithoFilterPatchConstructorFingerprint.resultOrThrow().let { it.mutableMethod.apply { removeInstructions(0, 6) @@ -106,7 +106,7 @@ object LithoFilterPatch : BytecodePatch( ) } } - } ?: throw LithoFilterPatchConstructorFingerprint.exception + } } override fun close() = LithoFilterPatchConstructorFingerprint.result!! diff --git a/src/main/kotlin/app/revanced/patches/shared/opus/BaseOpusCodecsPatch.kt b/src/main/kotlin/app/revanced/patches/shared/opus/BaseOpusCodecsPatch.kt index 974cced74..10293947e 100644 --- a/src/main/kotlin/app/revanced/patches/shared/opus/BaseOpusCodecsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/shared/opus/BaseOpusCodecsPatch.kt @@ -7,8 +7,8 @@ import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.shared.opus.fingerprints.CodecReferenceFingerprint import app.revanced.patches.shared.opus.fingerprints.CodecSelectorFingerprint -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithReference +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.reference.Reference @@ -25,14 +25,14 @@ abstract class BaseOpusCodecsPatch( override fun execute(context: BytecodeContext) { - CodecReferenceFingerprint.result?.let { + CodecReferenceFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = getTargetIndexWithReference("Ljava/util/Set;") targetReference = getInstruction(targetIndex).reference } - } ?: throw CodecReferenceFingerprint.exception + } - CodecSelectorFingerprint.result?.let { + CodecSelectorFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.endIndex val targetRegister = getInstruction(targetIndex).registerA @@ -47,6 +47,6 @@ abstract class BaseOpusCodecsPatch( """, ExternalLabel("mp4a", getInstruction(targetIndex + 1)) ) } - } ?: throw CodecSelectorFingerprint.exception + } } } diff --git a/src/main/kotlin/app/revanced/patches/shared/spoofappversion/BaseSpoofAppVersionPatch.kt b/src/main/kotlin/app/revanced/patches/shared/spoofappversion/BaseSpoofAppVersionPatch.kt index 9c6d8fde9..5a23a3f7d 100644 --- a/src/main/kotlin/app/revanced/patches/shared/spoofappversion/BaseSpoofAppVersionPatch.kt +++ b/src/main/kotlin/app/revanced/patches/shared/spoofappversion/BaseSpoofAppVersionPatch.kt @@ -6,9 +6,9 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patches.shared.spoofappversion.fingerprints.ClientInfoFingerprint import app.revanced.patches.shared.spoofappversion.fingerprints.ClientInfoParentFingerprint -import app.revanced.util.exception import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexWithFieldReferenceName +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @@ -19,10 +19,10 @@ abstract class BaseSpoofAppVersionPatch( ) { override fun execute(context: BytecodeContext) { - ClientInfoParentFingerprint.result?.let { parentResult -> + ClientInfoParentFingerprint.resultOrThrow().let { parentResult -> ClientInfoFingerprint.resolve(context, parentResult.classDef) - ClientInfoFingerprint.result?.let { + ClientInfoFingerprint.resultOrThrow().let { it.mutableMethod.apply { val versionIndex = getTargetIndexWithFieldReferenceName("RELEASE") + 1 val insertIndex = getTargetIndexReversed(versionIndex, Opcode.IPUT_OBJECT) @@ -35,8 +35,8 @@ abstract class BaseSpoofAppVersionPatch( """ ) } - } ?: throw ClientInfoFingerprint.exception - } ?: throw ClientInfoParentFingerprint.exception + } + } } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/shared/tracking/BaseSanitizeUrlQueryPatch.kt b/src/main/kotlin/app/revanced/patches/shared/tracking/BaseSanitizeUrlQueryPatch.kt index 508b3d6ee..a8cc7da0f 100644 --- a/src/main/kotlin/app/revanced/patches/shared/tracking/BaseSanitizeUrlQueryPatch.kt +++ b/src/main/kotlin/app/revanced/patches/shared/tracking/BaseSanitizeUrlQueryPatch.kt @@ -5,7 +5,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.fingerprint.MethodFingerprint import app.revanced.patcher.patch.BytecodePatch -import app.revanced.util.exception +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction abstract class BaseSanitizeUrlQueryPatch( @@ -19,7 +19,7 @@ abstract class BaseSanitizeUrlQueryPatch( } ) { private fun MethodFingerprint.invoke() { - result?.let { + resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.startIndex val targetRegister = getInstruction(targetIndex).registerA @@ -31,7 +31,7 @@ abstract class BaseSanitizeUrlQueryPatch( """ ) } - } ?: throw exception + } } override fun execute(context: BytecodeContext) { diff --git a/src/main/kotlin/app/revanced/patches/shared/translations/TranslationsUtils.kt b/src/main/kotlin/app/revanced/patches/shared/translations/TranslationsUtils.kt index 4096bd1d3..e282f81b8 100644 --- a/src/main/kotlin/app/revanced/patches/shared/translations/TranslationsUtils.kt +++ b/src/main/kotlin/app/revanced/patches/shared/translations/TranslationsUtils.kt @@ -1,7 +1,7 @@ package app.revanced.patches.shared.translations import app.revanced.patcher.data.ResourceContext -import app.revanced.util.classLoader +import app.revanced.util.inputStreamFromBundledResource import java.nio.file.Files import java.nio.file.StandardCopyOption @@ -13,12 +13,10 @@ object TranslationsUtils { ) { languageArray.forEach { language -> val directory = "values-$language-v21" - val relativePath = "$language/strings.xml" - this["res/$directory"].mkdir() Files.copy( - classLoader.getResourceAsStream("$sourceDirectory/translations/$relativePath")!!, + inputStreamFromBundledResource("$sourceDirectory/translations", "$language/strings.xml")!!, this["res"].resolve("$directory/strings.xml").toPath(), StandardCopyOption.REPLACE_EXISTING ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/ads/fullscreen/FullscreenAdsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/ads/fullscreen/FullscreenAdsPatch.kt index d7ce81b74..89a9f33bb 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/ads/fullscreen/FullscreenAdsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/ads/fullscreen/FullscreenAdsPatch.kt @@ -12,8 +12,8 @@ import app.revanced.patches.youtube.ads.fullscreen.fingerprints.ShowDialogComman import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.InterstitialsContainer -import app.revanced.util.exception import app.revanced.util.getWideLiteralInstructionIndex +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Patch(dependencies = [SharedResourceIdPatch::class]) @@ -31,7 +31,7 @@ object FullscreenAdsPatch : BytecodePatch( * Hides fullscreen ads * Non-litho view, used in some old clients. */ - InterstitialsContainerFingerprint.result?.let { + InterstitialsContainerFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = getWideLiteralInstructionIndex(InterstitialsContainer) + 2 val targetRegister = getInstruction(targetIndex).registerA @@ -41,13 +41,13 @@ object FullscreenAdsPatch : BytecodePatch( "invoke-static {v$targetRegister}, $FILTER_CLASS_DESCRIPTOR->hideFullscreenAds(Landroid/view/View;)V" ) } - } ?: throw InterstitialsContainerFingerprint.exception + } /** * Hides fullscreen ads * Litho view, used in 'ShowDialogCommandOuterClass' in innertube */ - ShowDialogCommandFingerprint.result?.let { + ShowDialogCommandFingerprint.resultOrThrow().let { it.mutableMethod.apply { // In this method, custom dialog is created and shown. // There were no issues despite adding “return-void” to the first index. @@ -94,6 +94,6 @@ object FullscreenAdsPatch : BytecodePatch( // """ // ) } - } ?: throw ShowDialogCommandFingerprint.exception + } } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/ads/getpremium/GetPremiumPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/ads/getpremium/GetPremiumPatch.kt index d42acd7a2..6ee18acb2 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/ads/getpremium/GetPremiumPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/ads/getpremium/GetPremiumPatch.kt @@ -7,7 +7,7 @@ import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.youtube.ads.getpremium.fingerprints.CompactYpcOfferModuleViewFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH -import app.revanced.util.exception +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction object GetPremiumPatch : BytecodePatch( @@ -18,7 +18,7 @@ object GetPremiumPatch : BytecodePatch( override fun execute(context: BytecodeContext) { - CompactYpcOfferModuleViewFingerprint.result?.let { + CompactYpcOfferModuleViewFingerprint.resultOrThrow().let { it.mutableMethod.apply { val startIndex = it.scanResult.patternScanResult!!.startIndex val measuredWidthRegister = @@ -38,7 +38,7 @@ object GetPremiumPatch : BytecodePatch( """, ExternalLabel("show", getInstruction(startIndex + 2)) ) } - } ?: throw CompactYpcOfferModuleViewFingerprint.exception + } } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/alternativethumbnails/general/AlternativeThumbnailsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/alternativethumbnails/general/AlternativeThumbnailsPatch.kt index f25d2cae2..1365ed6d1 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/alternativethumbnails/general/AlternativeThumbnailsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/alternativethumbnails/general/AlternativeThumbnailsPatch.kt @@ -18,8 +18,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch.contexts import app.revanced.util.copyXmlNode -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation @@ -90,11 +90,8 @@ object AlternativeThumbnailsPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { - fun MethodFingerprint.getResultOrThrow() = - result ?: throw exception - fun MethodFingerprint.alsoResolve(fingerprint: MethodFingerprint) = - also { resolve(context, fingerprint.getResultOrThrow().classDef) }.getResultOrThrow() + also { resolve(context, fingerprint.resultOrThrow().classDef) }.resultOrThrow() fun MethodFingerprint.resolveAndLetMutableMethod( fingerprint: MethodFingerprint, @@ -118,7 +115,7 @@ object AlternativeThumbnailsPatch : BaseBytecodePatch( // The URL is required for the failure callback hook, but the URL field is obfuscated. // Add a helper get method that returns the URL field. - RequestFingerprint.getResultOrThrow().apply { + RequestFingerprint.resultOrThrow().apply { // The url is the only string field that is set inside the constructor. val urlFieldInstruction = mutableMethod.getInstructions().first { if (it.opcode != Opcode.IPUT_OBJECT) diff --git a/src/main/kotlin/app/revanced/patches/youtube/buttomplayer/comment/CommentComponentPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/buttomplayer/comment/CommentComponentPatch.kt index f99d53175..2370ba394 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/buttomplayer/comment/CommentComponentPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/buttomplayer/comment/CommentComponentPatch.kt @@ -13,11 +13,11 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndex import app.revanced.util.getWalkerMethod import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -41,7 +41,7 @@ object CommentComponentPatch : BaseBytecodePatch( "$COMPONENTS_PATH/CommentsFilter;" override fun execute(context: BytecodeContext) { - ShortsLiveStreamEmojiPickerOpacityFingerprint.result?.let { + ShortsLiveStreamEmojiPickerOpacityFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = implementation!!.instructions.size - 1 val insertRegister= getInstruction(insertIndex).registerA @@ -51,9 +51,9 @@ object CommentComponentPatch : BaseBytecodePatch( "invoke-static {v$insertRegister}, $BOTTOM_PLAYER_CLASS_DESCRIPTOR->changeEmojiPickerOpacity(Landroid/widget/ImageView;)V" ) } - } ?: throw ShortsLiveStreamEmojiPickerOpacityFingerprint.exception + } - ShortsLiveStreamEmojiPickerOnClickListenerFingerprint.result?.let { parentResult -> + ShortsLiveStreamEmojiPickerOnClickListenerFingerprint.resultOrThrow().let { parentResult -> parentResult.mutableMethod.apply { val emojiPickerEndpointIndex = getWideLiteralInstructionIndex(126326492) val emojiPickerOnClickListenerIndex = getTargetIndex(emojiPickerEndpointIndex, Opcode.INVOKE_DIRECT) @@ -77,7 +77,7 @@ object CommentComponentPatch : BaseBytecodePatch( context, parentResult.classDef ) - }.result?.let { + }.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.startIndex val insertInstruction = getInstruction(insertIndex) diff --git a/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/feed/FeedFlyoutPanelPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/feed/FeedFlyoutPanelPatch.kt index d686e955d..4b7d39d63 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/feed/FeedFlyoutPanelPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/feed/FeedFlyoutPanelPatch.kt @@ -12,8 +12,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.FLYOUT_PANEL_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c @@ -40,8 +40,7 @@ object FeedFlyoutPanelPatch : BaseBytecodePatch( * Phone */ val bottomSheetMenuItemBuilderResult = BottomSheetMenuItemBuilderLegacyFingerprint.result - ?: BottomSheetMenuItemBuilderFingerprint.result - ?: throw BottomSheetMenuItemBuilderFingerprint.exception + ?: BottomSheetMenuItemBuilderFingerprint.resultOrThrow() bottomSheetMenuItemBuilderResult.let { it.mutableMethod.apply { @@ -65,7 +64,7 @@ object FeedFlyoutPanelPatch : BaseBytecodePatch( /** * Tablet */ - ContextualMenuItemBuilderFingerprint.result?.let { + ContextualMenuItemBuilderFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.startIndex + 1 val targetInstruction = getInstruction(targetIndex) @@ -81,7 +80,7 @@ object FeedFlyoutPanelPatch : BaseBytecodePatch( "$FLYOUT_PANEL_CLASS_DESCRIPTOR->hideFeedFlyoutPanel(Landroid/widget/TextView;Ljava/lang/CharSequence;)V" ) } - } ?: throw ContextualMenuItemBuilderFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/oldqualitylayout/OldQualityLayoutPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/oldqualitylayout/OldQualityLayoutPatch.kt index aa8b83dd2..99c4da39a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/oldqualitylayout/OldQualityLayoutPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/oldqualitylayout/OldQualityLayoutPatch.kt @@ -15,11 +15,11 @@ import app.revanced.patches.youtube.utils.integrations.Constants.FLYOUT_PANEL_CL import app.revanced.patches.youtube.utils.recyclerview.BottomSheetRecyclerViewPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getReference import app.revanced.util.getTargetIndex import app.revanced.util.indexOfFirstInstruction import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @@ -49,10 +49,9 @@ object OldQualityLayoutPatch : BaseBytecodePatch( /** * Non-litho view, used in old clients and Shorts. */ - val videoQualityClass = VideoQualitySetterFingerprint.result?.mutableMethod?.definingClass - ?: throw VideoQualitySetterFingerprint.exception + val videoQualityClass = VideoQualitySetterFingerprint.resultOrThrow().mutableMethod.definingClass - QualityMenuViewInflateFingerprint.result?.let { + QualityMenuViewInflateFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.endIndex val insertRegister = getInstruction(insertIndex).registerA @@ -82,7 +81,7 @@ object OldQualityLayoutPatch : BaseBytecodePatch( """, ExternalLabel("show", getInstruction(jumpIndex)) ) } ?: throw PatchException("Failed to find onItemClick method") - } ?: throw QualityMenuViewInflateFingerprint.exception + } /** * Litho view diff --git a/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/oldspeedlayout/OldSpeedLayoutPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/oldspeedlayout/OldSpeedLayoutPatch.kt index 02b1a1eea..9672c72b5 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/oldspeedlayout/OldSpeedLayoutPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/oldspeedlayout/OldSpeedLayoutPatch.kt @@ -15,7 +15,7 @@ import app.revanced.patches.youtube.flyoutpanel.oldspeedlayout.fingerprints.Play import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.VIDEO_PATH import app.revanced.patches.youtube.utils.recyclerview.BottomSheetRecyclerViewPatch -import app.revanced.util.exception +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.immutable.ImmutableField @@ -45,7 +45,7 @@ object OldSpeedLayoutPatch : BytecodePatch( /** * Input 'playbackRateBottomSheetClass' in FlyoutPanelPatch. */ - PlaybackRateBottomSheetClassFingerprint.result?.let { + PlaybackRateBottomSheetClassFingerprint.resultOrThrow().let { it.mutableMethod.apply { playbackRateBottomSheetClass = definingClass playbackRateBottomSheetBuilderMethod = @@ -58,13 +58,13 @@ object OldSpeedLayoutPatch : BytecodePatch( "sput-object p0, $INTEGRATIONS_CLASS_DESCRIPTOR->playbackRateBottomSheetClass:$playbackRateBottomSheetClass" ) } - } ?: throw PlaybackRateBottomSheetClassFingerprint.exception + } /** * Create a static field in the patch * Add a call the Playback Speed Bottom Sheet Fragment method */ - CustomPlaybackSpeedIntegrationsFingerprint.result?.let { + CustomPlaybackSpeedIntegrationsFingerprint.resultOrThrow().let { it.mutableMethod.apply { // Create a static field 'playbackRateBottomSheetClass' in FlyoutPanelPatch. it.mutableClass.staticFields.add( @@ -92,7 +92,7 @@ object OldSpeedLayoutPatch : BytecodePatch( """ ) } - } ?: throw CustomPlaybackSpeedIntegrationsFingerprint.exception + } BottomSheetRecyclerViewPatch.injectCall("$INTEGRATIONS_CLASS_DESCRIPTOR->onFlyoutMenuCreate(Landroid/support/v7/widget/RecyclerView;)V") diff --git a/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/toggle/ChangeTogglePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/toggle/ChangeTogglePatch.kt index 15df73345..38e831c09 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/toggle/ChangeTogglePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/flyoutpanel/toggle/ChangeTogglePatch.kt @@ -15,12 +15,12 @@ import app.revanced.patches.youtube.flyoutpanel.toggle.fingerprints.StableVolume import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.FLYOUT_PANEL_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getStringInstructionIndex import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexReversed import app.revanced.util.indexOfFirstInstruction import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -41,15 +41,11 @@ object ChangeTogglePatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - val additionalSettingsConfigResult = AdditionalSettingsConfigFingerprint.result - ?: throw AdditionalSettingsConfigFingerprint.exception - - val additionalSettingsConfigMethod = additionalSettingsConfigResult.mutableMethod + val additionalSettingsConfigMethod = AdditionalSettingsConfigFingerprint.resultOrThrow().mutableMethod val methodToCall = additionalSettingsConfigMethod.definingClass + "->" + additionalSettingsConfigMethod.name + "()Z" // Resolves fingerprints - val playbackLoopOnClickListenerResult = PlaybackLoopOnClickListenerFingerprint.result - ?: throw PlaybackLoopOnClickListenerFingerprint.exception + val playbackLoopOnClickListenerResult = PlaybackLoopOnClickListenerFingerprint.resultOrThrow() PlaybackLoopInitFingerprint.resolve(context, playbackLoopOnClickListenerResult.classDef) arrayOf( @@ -79,7 +75,7 @@ object ChangeTogglePatch : BaseBytecodePatch( fingerprint: MethodFingerprint, methodToCall: String ) { - fingerprint.result?.let { + fingerprint.resultOrThrow().let { it.mutableMethod.apply { val referenceIndex = indexOfFirstInstruction { opcode == Opcode.INVOKE_VIRTUAL @@ -102,12 +98,11 @@ object ChangeTogglePatch : BaseBytecodePatch( throw PatchException("Target reference'$methodToCall' was not found in ${this.javaClass.simpleName}.") } } - } ?: throw fingerprint.exception + } } private fun injectCinematicLightingMethod() { - val stableVolumeMethod = StableVolumeFingerprint.result?.mutableMethod - ?: throw StableVolumeFingerprint.exception + val stableVolumeMethod = StableVolumeFingerprint.resultOrThrow().mutableMethod val stringReferenceIndex = stableVolumeMethod.indexOfFirstInstruction { opcode == Opcode.INVOKE_VIRTUAL @@ -118,7 +113,7 @@ object ChangeTogglePatch : BaseBytecodePatch( val stringReference = stableVolumeMethod.getInstruction(stringReferenceIndex).reference - CinematicLightingFingerprint.result?.let { + CinematicLightingFingerprint.resultOrThrow().let { it.mutableMethod.apply { val stringIndex = getStringInstructionIndex("menu_item_cinematic_lighting") @@ -163,6 +158,6 @@ object ChangeTogglePatch : BaseBytecodePatch( """, ExternalLabel("ignore", getInstruction(insertIndex)) ) } - } ?: throw CinematicLightingFingerprint.exception + } } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/fullscreen/autoplaypreview/AutoplayPreviewPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/fullscreen/autoplaypreview/AutoplayPreviewPatch.kt index 7f48a288b..04787b447 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/fullscreen/autoplaypreview/AutoplayPreviewPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/fullscreen/autoplaypreview/AutoplayPreviewPatch.kt @@ -11,10 +11,10 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.AutoNavPreviewStub import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.AutoNavToggle import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getStringInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -29,7 +29,7 @@ object AutoplayPreviewPatch : BaseBytecodePatch( fingerprints = setOf(LayoutConstructorFingerprint) ) { override fun execute(context: BytecodeContext) { - LayoutConstructorFingerprint.result?.let { + LayoutConstructorFingerprint.resultOrThrow().let { it.mutableMethod.apply { val dummyRegister = getInstruction(getStringInstructionIndex("1.0x")).registerA @@ -44,7 +44,7 @@ object AutoplayPreviewPatch : BaseBytecodePatch( """, ExternalLabel("hidden", getInstruction(jumpIndex)) ) } - } ?: throw LayoutConstructorFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/fullscreen/compactcontrolsoverlay/CompactControlsOverlayPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/fullscreen/compactcontrolsoverlay/CompactControlsOverlayPatch.kt index 6d307f939..a4fab7c9e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/fullscreen/compactcontrolsoverlay/CompactControlsOverlayPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/fullscreen/compactcontrolsoverlay/CompactControlsOverlayPatch.kt @@ -8,9 +8,9 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.FULLSCREEN_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getWalkerMethod import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -26,7 +26,7 @@ object CompactControlsOverlayPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - YouTubeControlsOverlayFingerprint.result?.let { + YouTubeControlsOverlayFingerprint.resultOrThrow().let { val walkerMethod = it.getWalkerMethod(context, it.scanResult.patternScanResult!!.startIndex) walkerMethod.apply { val insertIndex = implementation!!.instructions.size - 1 @@ -40,7 +40,7 @@ object CompactControlsOverlayPatch : BaseBytecodePatch( """ ) } - } ?: throw YouTubeControlsOverlayFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/fullscreen/endscreenoverlay/EndScreenOverlayPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/fullscreen/endscreenoverlay/EndScreenOverlayPatch.kt index 2f06e9749..ec3d670fe 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/fullscreen/endscreenoverlay/EndScreenOverlayPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/fullscreen/endscreenoverlay/EndScreenOverlayPatch.kt @@ -10,8 +10,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.FULLSCREEN_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object EndScreenOverlayPatch : BaseBytecodePatch( @@ -25,7 +25,7 @@ object EndScreenOverlayPatch : BaseBytecodePatch( fingerprints = setOf(EndScreenResultsParentFingerprint) ) { override fun execute(context: BytecodeContext) { - EndScreenResultsParentFingerprint.result?.let { + EndScreenResultsParentFingerprint.resultOrThrow().let { it.mutableClass.methods.find { method -> method.parameters == listOf("I", "Z", "I") } ?.apply { addInstructionsWithLabels( @@ -37,7 +37,7 @@ object EndScreenOverlayPatch : BaseBytecodePatch( """, ExternalLabel("show", getInstruction(0)) ) } ?: throw PatchException("Could not find targetMethod") - } ?: throw EndScreenResultsParentFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/fullscreen/forcefullscreen/ForceFullscreenPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/fullscreen/forcefullscreen/ForceFullscreenPatch.kt index aa42b10f8..9894a6bc3 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/fullscreen/forcefullscreen/ForceFullscreenPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/fullscreen/forcefullscreen/ForceFullscreenPatch.kt @@ -10,10 +10,10 @@ import app.revanced.patches.youtube.fullscreen.forcefullscreen.fingerprints.Vide import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.FULLSCREEN_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getStringInstructionIndex import app.revanced.util.getTargetIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -35,7 +35,7 @@ object ForceFullscreenPatch : BaseBytecodePatch( /** * Process that hooks Activity for using {Activity.setRequestedOrientation}. */ - ClientSettingEndpointFingerprint.result?.let { + ClientSettingEndpointFingerprint.resultOrThrow().let { it.mutableMethod.apply { val getActivityIndex = getStringInstructionIndex("watch") + 2 val getActivityReference = @@ -66,13 +66,13 @@ object ForceFullscreenPatch : BaseBytecodePatch( """ ) } - } ?: throw ClientSettingEndpointFingerprint.exception + } /** * Don't rotate the screen in vertical video. * Add an instruction to check the vertical video. */ - VideoPortraitParentFingerprint.result?.let { + VideoPortraitParentFingerprint.resultOrThrow().let { it.mutableMethod.apply { val stringIndex = getStringInstructionIndex("Acquiring NetLatencyActionLogger failed. taskId=") @@ -90,7 +90,7 @@ object ForceFullscreenPatch : BaseBytecodePatch( ) } ?: throw PatchException("Could not find targetMethod") } - } ?: throw VideoPortraitParentFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/fullscreen/fullscreenpanels/FullscreenPanelsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/fullscreen/fullscreenpanels/FullscreenPanelsPatch.kt index bda87b971..e17f6f426 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/fullscreen/fullscreenpanels/FullscreenPanelsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/fullscreen/fullscreenpanels/FullscreenPanelsPatch.kt @@ -12,11 +12,11 @@ import app.revanced.patches.youtube.utils.integrations.Constants.FULLSCREEN_CLAS import app.revanced.patches.youtube.utils.quickactions.QuickActionsHookPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.FullScreenEngagementPanel import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -36,7 +36,7 @@ object FullscreenPanelsPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - FullscreenEngagementPanelFingerprint.result?.let { + FullscreenEngagementPanelFingerprint.resultOrThrow().let { it.mutableMethod.apply { val literalIndex = getWideLiteralInstructionIndex(FullScreenEngagementPanel) val targetIndex = getTargetIndex(literalIndex, Opcode.CHECK_CAST) @@ -47,9 +47,9 @@ object FullscreenPanelsPatch : BaseBytecodePatch( "invoke-static {v$targetRegister}, $FULLSCREEN_CLASS_DESCRIPTOR->hideFullscreenPanels(Landroidx/coordinatorlayout/widget/CoordinatorLayout;)V" ) } - } ?: throw FullscreenEngagementPanelFingerprint.exception + } - LayoutConstructorFingerprint.result?.let { + LayoutConstructorFingerprint.resultOrThrow().let { it.mutableMethod.apply { val dummyIndex = getWideLiteralInstructionIndex(159962) val dummyRegister = getInstruction(dummyIndex).registerA @@ -63,7 +63,7 @@ object FullscreenPanelsPatch : BaseBytecodePatch( """, ExternalLabel("hidden", getInstruction(addViewIndex + 1)) ) } - } ?: throw LayoutConstructorFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/fullscreen/landscapemode/LandScapeModePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/fullscreen/landscapemode/LandScapeModePatch.kt index 6306220d8..e56ef8f24 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/fullscreen/landscapemode/LandScapeModePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/fullscreen/landscapemode/LandScapeModePatch.kt @@ -12,10 +12,10 @@ import app.revanced.patches.youtube.fullscreen.landscapemode.fingerprints.Orient import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.FULLSCREEN_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getStringInstructionIndex import app.revanced.util.getTargetIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -36,28 +36,28 @@ object LandScapeModePatch : BaseBytecodePatch( /** * Disable landscape mode */ - OrientationParentFingerprint.result?.classDef?.let { classDef -> + OrientationParentFingerprint.resultOrThrow().classDef.let { classDef -> arrayOf( OrientationPrimaryFingerprint, OrientationSecondaryFingerprint ).forEach { fingerprint -> fingerprint.resolve(context, classDef) - fingerprint.result?.let { + fingerprint.resultOrThrow().let { it.mutableMethod.apply { val index = it.scanResult.patternScanResult!!.endIndex val register = getInstruction(index).registerA addInstructions( index + 1, """ - invoke-static {v$register}, $FULLSCREEN_CLASS_DESCRIPTOR->disableLandScapeMode(Z)Z - move-result v$register - """ + invoke-static {v$register}, $FULLSCREEN_CLASS_DESCRIPTOR->disableLandScapeMode(Z)Z + move-result v$register + """ ) } - } ?: throw fingerprint.exception + } } - } ?: throw OrientationParentFingerprint.exception + } /** * Keep landscape mode @@ -75,7 +75,7 @@ object LandScapeModePatch : BaseBytecodePatch( ) } - BroadcastReceiverFingerprint.result?.let { result -> + BroadcastReceiverFingerprint.resultOrThrow().let { result -> result.mutableMethod.apply { val stringIndex = getStringInstructionIndex("android.intent.action.SCREEN_ON") val insertIndex = getTargetIndex(stringIndex, Opcode.IF_EQZ) + 1 @@ -85,7 +85,7 @@ object LandScapeModePatch : BaseBytecodePatch( "invoke-static {}, $FULLSCREEN_CLASS_DESCRIPTOR->setScreenStatus()V" ) } - } ?: throw BroadcastReceiverFingerprint.exception + } SettingsPatch.addPreference( arrayOf( diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/accountmenu/AccountMenuPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/accountmenu/AccountMenuPatch.kt index 811a2e032..485c9cba8 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/accountmenu/AccountMenuPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/accountmenu/AccountMenuPatch.kt @@ -14,8 +14,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -36,10 +36,10 @@ object AccountMenuPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - AccountListParentFingerprint.result?.let { parentResult -> + AccountListParentFingerprint.resultOrThrow().let { parentResult -> AccountListFingerprint.resolve(context, parentResult.classDef) - AccountListFingerprint.result?.let { + AccountListFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.startIndex + 3 val targetInstruction = getInstruction(targetIndex) @@ -50,14 +50,14 @@ object AccountMenuPatch : BaseBytecodePatch( "$GENERAL_CLASS_DESCRIPTOR->hideAccountList(Landroid/view/View;Ljava/lang/CharSequence;)V" ) } - } ?: throw AccountListFingerprint.exception - } ?: throw AccountListParentFingerprint.exception + } + } - AccountMenuParentFingerprint.result?.let { parentResult -> + AccountMenuParentFingerprint.resultOrThrow().let { parentResult -> AccountMenuFingerprint.resolve(context, parentResult.classDef) SetViewGroupMarginFingerprint.resolve(context, parentResult.classDef) - AccountMenuFingerprint.result?.let { + AccountMenuFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.startIndex + 2 val targetInstruction = getInstruction(targetIndex) @@ -68,23 +68,23 @@ object AccountMenuPatch : BaseBytecodePatch( "$GENERAL_CLASS_DESCRIPTOR->hideAccountMenu(Landroid/view/View;Ljava/lang/CharSequence;)V" ) } - } ?: throw AccountMenuFingerprint.exception + } - SetViewGroupMarginFingerprint.result?.let { + SetViewGroupMarginFingerprint.resultOrThrow().let { it.mutableMethod.apply { val setViewGroupMarginIndex = it.scanResult.patternScanResult!!.startIndex val setViewGroupMarginReference = getInstruction(setViewGroupMarginIndex).reference - AccountMenuPatchFingerprint.result?.mutableMethod?.addInstructions( + AccountMenuPatchFingerprint.resultOrThrow().mutableMethod.addInstructions( 0, """ const/4 v0, 0x0 invoke-static {p0, v0, v0}, $setViewGroupMarginReference """ - ) ?: throw AccountMenuPatchFingerprint.exception + ) } - } ?: throw SetViewGroupMarginFingerprint.exception - } ?: throw AccountMenuParentFingerprint.exception + } + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/autopopuppanels/PlayerPopupPanelsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/autopopuppanels/PlayerPopupPanelsPatch.kt index 83339de42..0a3d60cf9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/autopopuppanels/PlayerPopupPanelsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/autopopuppanels/PlayerPopupPanelsPatch.kt @@ -8,8 +8,8 @@ import app.revanced.patches.youtube.general.autopopuppanels.fingerprints.Engagem import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object PlayerPopupPanelsPatch : BaseBytecodePatch( @@ -21,7 +21,7 @@ object PlayerPopupPanelsPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - EngagementPanelControllerFingerprint.result?.let { + EngagementPanelControllerFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstructionsWithLabels( 0, """ @@ -35,7 +35,7 @@ object PlayerPopupPanelsPatch : BaseBytecodePatch( """, ExternalLabel("shown", getInstruction(0)) ) } - } ?: throw EngagementPanelControllerFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/castbutton/CastButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/castbutton/CastButtonPatch.kt index e9af5d3ba..cfa3f6b22 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/castbutton/CastButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/castbutton/CastButtonPatch.kt @@ -6,8 +6,8 @@ import app.revanced.patches.youtube.general.castbutton.fingerprints.CastButtonFi import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object CastButtonPatch : BaseBytecodePatch( @@ -18,7 +18,7 @@ object CastButtonPatch : BaseBytecodePatch( fingerprints = setOf(CastButtonFingerprint) ) { override fun execute(context: BytecodeContext) { - CastButtonFingerprint.result?.let { + CastButtonFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstructions( 0, """ @@ -27,7 +27,7 @@ object CastButtonPatch : BaseBytecodePatch( """ ) } - } ?: throw CastButtonFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/categorybar/CategoryBarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/categorybar/CategoryBarPatch.kt index c9b02faff..f1afea80a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/categorybar/CategoryBarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/categorybar/CategoryBarPatch.kt @@ -11,8 +11,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @@ -71,7 +71,7 @@ object CategoryBarPatch : BaseBytecodePatch( hookRegisterOffset: Int = 0, instructions: (Int) -> String ) = - result?.let { + resultOrThrow().let { it.mutableMethod.apply { val endIndex = it.scanResult.patternScanResult!!.endIndex @@ -81,5 +81,5 @@ object CategoryBarPatch : BaseBytecodePatch( addInstructions(insertIndex, instructions(register)) } - } ?: throw exception + } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/channellistsubmenu/ChannelListSubMenuPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/channellistsubmenu/ChannelListSubMenuPatch.kt index 4d6cbee3f..b4b293f59 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/channellistsubmenu/ChannelListSubMenuPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/channellistsubmenu/ChannelListSubMenuPatch.kt @@ -10,8 +10,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -32,7 +32,7 @@ object ChannelListSubMenuPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR) - ChannelListSubMenuFingerprint.result?.let { + ChannelListSubMenuFingerprint.resultOrThrow().let { it.mutableMethod.apply { val endIndex = it.scanResult.patternScanResult!!.endIndex val register = getInstruction(endIndex).registerA @@ -42,7 +42,7 @@ object ChannelListSubMenuPatch : BaseBytecodePatch( "invoke-static {v$register}, $GENERAL_CLASS_DESCRIPTOR->hideChannelListSubMenu(Landroid/view/View;)V" ) } - } ?: throw ChannelListSubMenuFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/channelprofile/ChannelProfileComponentsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/channelprofile/ChannelProfileComponentsPatch.kt index 90039a052..bac4baffa 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/channelprofile/ChannelProfileComponentsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/channelprofile/ChannelProfileComponentsPatch.kt @@ -10,9 +10,9 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.TabsBarTextTabView import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -32,7 +32,7 @@ object ChannelProfileComponentsPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { - DefaultsTabsBarFingerprint.result?.let { + DefaultsTabsBarFingerprint.resultOrThrow().let { it.mutableMethod.apply { val viewIndex = getWideLiteralInstructionIndex(TabsBarTextTabView) + 2 val viewRegister = getInstruction(viewIndex).registerA @@ -42,7 +42,7 @@ object ChannelProfileComponentsPatch : BaseBytecodePatch( "sput-object v$viewRegister, $FILTER_CLASS_DESCRIPTOR->channelTabView:Landroid/view/View;" ) } - } ?: throw DefaultsTabsBarFingerprint.exception + } LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR) diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/crowdfundingbox/CrowdfundingBoxPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/crowdfundingbox/CrowdfundingBoxPatch.kt index 4dfb7bdc0..37e36473d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/crowdfundingbox/CrowdfundingBoxPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/crowdfundingbox/CrowdfundingBoxPatch.kt @@ -8,8 +8,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @Suppress("unused") @@ -25,7 +25,7 @@ object CrowdfundingBoxPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - CrowdfundingBoxFingerprint.result?.let { + CrowdfundingBoxFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.endIndex val register = getInstruction(insertIndex).registerA @@ -35,7 +35,7 @@ object CrowdfundingBoxPatch : BaseBytecodePatch( "invoke-static {v$register}, $GENERAL_CLASS_DESCRIPTOR->hideCrowdfundingBox(Landroid/view/View;)V" ) } - } ?: throw CrowdfundingBoxFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/descriptions/DescriptionComponentsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/descriptions/DescriptionComponentsPatch.kt index 93f9c84a3..313ae030f 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/descriptions/DescriptionComponentsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/descriptions/DescriptionComponentsPatch.kt @@ -10,9 +10,9 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.recyclerview.BottomSheetRecyclerViewPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction @Suppress("unused") @@ -33,7 +33,7 @@ object DescriptionComponentsPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { if (SettingsPatch.upward1902) { - TextViewComponentFingerprint.result?.let { + TextViewComponentFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = getTargetIndexWithMethodReferenceName("setTextIsSelectable") val insertInstruction = getInstruction(insertIndex) @@ -44,7 +44,7 @@ object DescriptionComponentsPatch : BaseBytecodePatch( "$GENERAL_CLASS_DESCRIPTOR->disableDescriptionInteraction(Landroid/widget/TextView;Z)V" ) } - } ?: throw TextViewComponentFingerprint.exception + } BottomSheetRecyclerViewPatch.injectCall("$GENERAL_CLASS_DESCRIPTOR->onDescriptionPanelCreate(Landroid/support/v7/widget/RecyclerView;)V") diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/floatingmicrophone/FloatingMicrophonePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/floatingmicrophone/FloatingMicrophonePatch.kt index 1f0f14765..782a524b3 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/floatingmicrophone/FloatingMicrophonePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/floatingmicrophone/FloatingMicrophonePatch.kt @@ -8,8 +8,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @Suppress("unused") @@ -25,7 +25,7 @@ object FloatingMicrophonePatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - FloatingMicrophoneFingerprint.result?.let { + FloatingMicrophoneFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.startIndex val register = getInstruction(insertIndex).registerA @@ -37,7 +37,7 @@ object FloatingMicrophonePatch : BaseBytecodePatch( """ ) } - } ?: throw FloatingMicrophoneFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/handle/HandlePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/handle/HandlePatch.kt index afd300200..0702319b6 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/handle/HandlePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/handle/HandlePatch.kt @@ -11,11 +11,11 @@ import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_D import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.AccountSwitcherAccessibility import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction @@ -36,7 +36,7 @@ object HandlePatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { - AccountSwitcherAccessibilityLabelFingerprint.result?.let { + AccountSwitcherAccessibilityLabelFingerprint.resultOrThrow().let { it.mutableMethod.apply { val constIndex = getWideLiteralInstructionIndex(AccountSwitcherAccessibility) val insertIndex = getTargetIndex(constIndex, Opcode.IF_EQZ) @@ -50,7 +50,7 @@ object HandlePatch : BaseBytecodePatch( """ ) } - } ?: throw AccountSwitcherAccessibilityLabelFingerprint.exception + } LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR) diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/latestvideosbutton/LatestVideosButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/latestvideosbutton/LatestVideosButtonPatch.kt index f42264da9..c1a87220a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/latestvideosbutton/LatestVideosButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/latestvideosbutton/LatestVideosButtonPatch.kt @@ -8,8 +8,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -24,7 +24,7 @@ object LatestVideosButtonPatch : BaseBytecodePatch( fingerprints = setOf(LatestVideosButtonFingerprint) ) { override fun execute(context: BytecodeContext) { - LatestVideosButtonFingerprint.result?.let { + LatestVideosButtonFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.endIndex val targetRegister = getInstruction(targetIndex).registerA @@ -34,7 +34,7 @@ object LatestVideosButtonPatch : BaseBytecodePatch( "invoke-static {v$targetRegister}, $GENERAL_CLASS_DESCRIPTOR->hideLatestVideosButton(Landroid/view/View;)V" ) } - } ?: throw LatestVideosButtonFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/loadmorebutton/LoadMoreButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/loadmorebutton/LoadMoreButtonPatch.kt index 6d255de9f..0e5567367 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/loadmorebutton/LoadMoreButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/loadmorebutton/LoadMoreButtonPatch.kt @@ -9,8 +9,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -25,7 +25,7 @@ object LoadMoreButtonPatch : BaseBytecodePatch( fingerprints = setOf(LoadMoreButtonFingerprint) ) { override fun execute(context: BytecodeContext) { - LoadMoreButtonFingerprint.result?.let { + LoadMoreButtonFingerprint.resultOrThrow().let { val getViewMethod = it.mutableClass.methods.find { method -> method.parameters.isEmpty() && @@ -41,7 +41,7 @@ object LoadMoreButtonPatch : BaseBytecodePatch( "invoke-static {v$targetRegister}, $GENERAL_CLASS_DESCRIPTOR->hideLoadMoreButton(Landroid/view/View;)V" ) } ?: throw PatchException("Failed to find getView method") - } ?: throw LoadMoreButtonFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/mixplaylists/MixPlaylistsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/mixplaylists/MixPlaylistsPatch.kt index 962098be3..b2afc5356 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/mixplaylists/MixPlaylistsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/mixplaylists/MixPlaylistsPatch.kt @@ -11,10 +11,10 @@ import app.revanced.patches.youtube.general.mixplaylists.fingerprints.ElementPar 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.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndex import app.revanced.util.indexOfFirstInstruction import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @@ -36,10 +36,10 @@ object MixPlaylistsPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { - ElementParserParentFingerprint.result?.let { parentResult -> + ElementParserParentFingerprint.resultOrThrow().let { parentResult -> ElementParserFingerprint.resolve(context, parentResult.classDef) - ElementParserFingerprint.result?.let { + ElementParserFingerprint.resultOrThrow().let { it.mutableMethod.apply { val freeRegister = implementation!!.registerCount - parameters.size - 2 val insertIndex = indexOfFirstInstruction { @@ -68,8 +68,8 @@ object MixPlaylistsPatch : BaseBytecodePatch( "move-object/from16 v$freeRegister, p3" ) } - } ?: throw ElementParserFingerprint.exception - } ?: throw ElementParserParentFingerprint.exception + } + } LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR) diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/searchterm/SearchTermThumbnailPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/searchterm/SearchTermThumbnailPatch.kt index 7eb8f89d7..3333be9ac 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/searchterm/SearchTermThumbnailPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/searchterm/SearchTermThumbnailPatch.kt @@ -9,11 +9,11 @@ import app.revanced.patches.youtube.general.searchterm.fingerprints.CreateSearch import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithReference import app.revanced.util.getTargetIndexWithReferenceReversed import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @@ -26,7 +26,7 @@ object SearchTermThumbnailPatch : BaseBytecodePatch( fingerprints = setOf(CreateSearchSuggestionsFingerprint) ) { override fun execute(context: BytecodeContext) { - CreateSearchSuggestionsFingerprint.result?.let { result -> + CreateSearchSuggestionsFingerprint.resultOrThrow().let { result -> result.mutableMethod.apply { val relativeIndex = getWideLiteralInstructionIndex(40) val replaceIndex = getTargetIndexWithReferenceReversed( @@ -53,7 +53,7 @@ object SearchTermThumbnailPatch : BaseBytecodePatch( ) removeInstruction(replaceIndex) } - } ?: throw CreateSearchSuggestionsFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/snackbar/SnackBarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/snackbar/SnackBarPatch.kt index 98d079e5b..ae9d8bd26 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/snackbar/SnackBarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/snackbar/SnackBarPatch.kt @@ -8,8 +8,8 @@ import app.revanced.patches.youtube.general.snackbar.fingerprints.BottomUiContai import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object SnackBarPatch : BaseBytecodePatch( @@ -21,7 +21,7 @@ object SnackBarPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - BottomUiContainerFingerprint.result?.let { + BottomUiContainerFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstructionsWithLabels( 0, """ @@ -32,7 +32,7 @@ object SnackBarPatch : BaseBytecodePatch( """, ExternalLabel("show", getInstruction(0)) ) } - } ?: throw BottomUiContainerFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/startpage/ChangeStartPagePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/startpage/ChangeStartPagePatch.kt index f5d18593f..287e24425 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/startpage/ChangeStartPagePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/startpage/ChangeStartPagePatch.kt @@ -8,8 +8,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_D import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch.contexts import app.revanced.util.copyXmlNode -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object ChangeStartPagePatch : BaseBytecodePatch( @@ -20,14 +20,14 @@ object ChangeStartPagePatch : BaseBytecodePatch( fingerprints = setOf(StartActivityFingerprint) ) { override fun execute(context: BytecodeContext) { - StartActivityFingerprint.result?.let { + StartActivityFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstruction( 0, "invoke-static { p1 }, $GENERAL_CLASS_DESCRIPTOR->changeStartPage(Landroid/content/Intent;)V" ) } - } ?: throw StartActivityFingerprint.exception + } /** * Copy arrays diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/suggestionshelf/SuggestionsShelfPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/suggestionshelf/SuggestionsShelfPatch.kt index dec9b19be..2f5bcd2f6 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/suggestionshelf/SuggestionsShelfPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/suggestionshelf/SuggestionsShelfPatch.kt @@ -9,8 +9,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.navbarindex.NavBarIndexHookPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -33,7 +33,7 @@ object SuggestionsShelfPatch : BaseBytecodePatch( /** * Only used to tablet layout. */ - BreakingNewsFingerprint.result?.let { + BreakingNewsFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.endIndex val targetRegister = getInstruction(targetIndex).registerA @@ -43,7 +43,7 @@ object SuggestionsShelfPatch : BaseBytecodePatch( "invoke-static {v$targetRegister}, $FILTER_CLASS_DESCRIPTOR->hideBreakingNewsShelf(Landroid/view/View;)V" ) } - } ?: throw BreakingNewsFingerprint.exception + } LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR) diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/tabletminiplayer/TabletMiniPlayerPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/tabletminiplayer/TabletMiniPlayerPatch.kt index d81f9be7b..16cf7ef39 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/tabletminiplayer/TabletMiniPlayerPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/tabletminiplayer/TabletMiniPlayerPatch.kt @@ -12,12 +12,12 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getStringInstructionIndex import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexReversed import app.revanced.util.getWalkerMethod import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -38,17 +38,17 @@ object TabletMiniPlayerPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - MiniPlayerDimensionsCalculatorFingerprint.result?.let { parentResult -> + MiniPlayerDimensionsCalculatorFingerprint.resultOrThrow().let { parentResult -> MiniPlayerOverrideNoContextFingerprint.resolve(context, parentResult.classDef) - MiniPlayerOverrideNoContextFingerprint.result?.let { + MiniPlayerOverrideNoContextFingerprint.resultOrThrow().let { it.mutableMethod.apply { hook(getTargetIndex(Opcode.RETURN)) hook(getTargetIndexReversed(Opcode.RETURN)) } - } ?: throw MiniPlayerOverrideNoContextFingerprint.exception - } ?: throw MiniPlayerDimensionsCalculatorFingerprint.exception + } + } - MiniPlayerOverrideFingerprint.result?.let { + MiniPlayerOverrideFingerprint.resultOrThrow().let { it.mutableMethod.apply { val walkerMethod = getWalkerMethod(context, getStringInstructionIndex("appName") + 2) @@ -57,13 +57,13 @@ object TabletMiniPlayerPatch : BaseBytecodePatch( hook(getTargetIndexReversed(Opcode.RETURN)) } } - } ?: throw MiniPlayerOverrideFingerprint.exception + } - MiniPlayerResponseModelSizeCheckFingerprint.result?.let { + MiniPlayerResponseModelSizeCheckFingerprint.resultOrThrow().let { it.mutableMethod.apply { hook(it.scanResult.patternScanResult!!.endIndex) } - } ?: throw MiniPlayerResponseModelSizeCheckFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/WideSearchBarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/WideSearchBarPatch.kt index 22b942659..7128ebf82 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/WideSearchBarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/general/widesearchbar/WideSearchBarPatch.kt @@ -12,8 +12,9 @@ import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_D import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch.contexts -import app.revanced.util.exception +import app.revanced.util.getWalkerMethod import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("DEPRECATION", "unused") @@ -36,33 +37,29 @@ object WideSearchBarPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { // resolves fingerprints - val parentClassDef = SetActionBarRingoFingerprint.result?.classDef - ?: throw SetActionBarRingoFingerprint.exception + val parentClassDef = SetActionBarRingoFingerprint.resultOrThrow().classDef YouActionBarFingerprint.resolve(context, parentClassDef) // patch methods - SetWordMarkHeaderFingerprint.result?.let { - val targetMethod = - context.toMethodWalker(it.method) - .nextMethod(1, true) - .getMethod() as MutableMethod + SetWordMarkHeaderFingerprint.resultOrThrow().let { + val walkerMethod = it.getWalkerMethod(context, it.scanResult.patternScanResult!!.startIndex + 1) - targetMethod.apply { + walkerMethod.apply { injectSearchBarHook( implementation!!.instructions.size - 1, "enableWideSearchBar" ) } - } ?: throw SetWordMarkHeaderFingerprint.exception + } - YouActionBarFingerprint.result?.let { + YouActionBarFingerprint.resultOrThrow().let { it.mutableMethod.apply { injectSearchBarHook( it.scanResult.patternScanResult!!.endIndex, "enableWideSearchBarInYouTab" ) } - } ?: throw YouActionBarFingerprint.exception + } /** * Set Wide SearchBar Start Margin diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/pipnotification/PiPNotificationPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/pipnotification/PiPNotificationPatch.kt index 0bf6a64f3..a9fff35f6 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/pipnotification/PiPNotificationPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/pipnotification/PiPNotificationPatch.kt @@ -7,8 +7,8 @@ import app.revanced.patches.youtube.layout.pipnotification.fingerprints.PiPNotif import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @Suppress("unused") @@ -24,7 +24,7 @@ object PiPNotificationPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - PiPNotificationFingerprint.result?.let { + PiPNotificationFingerprint.resultOrThrow().let { it.mutableMethod.apply { val checkCastCalls = implementation!!.instructions.withIndex() .filter { instruction -> @@ -44,7 +44,7 @@ object PiPNotificationPatch : BaseBytecodePatch( ) } } - } ?: throw PiPNotificationFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/playerbuttonbg/PlayerButtonBackgroundPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/playerbuttonbg/PlayerButtonBackgroundPatch.kt similarity index 95% rename from src/main/kotlin/app/revanced/patches/youtube/player/playerbuttonbg/PlayerButtonBackgroundPatch.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/playerbuttonbg/PlayerButtonBackgroundPatch.kt index 6eb3f5d14..c86a7becd 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/playerbuttonbg/PlayerButtonBackgroundPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/playerbuttonbg/PlayerButtonBackgroundPatch.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.player.playerbuttonbg +package app.revanced.patches.youtube.layout.playerbuttonbg import app.revanced.patcher.data.ResourceContext import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemeBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/BaseThemePatch.kt similarity index 98% rename from src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemeBytecodePatch.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/theme/BaseThemePatch.kt index 31184a87d..d0e95dc1a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemeBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/BaseThemePatch.kt @@ -9,7 +9,7 @@ import org.w3c.dom.Element @Patch(dependencies = [DrawableColorPatch::class]) @Suppress("DEPRECATION") -object ThemeBytecodePatch : ResourcePatch() { +object BaseThemePatch : ResourcePatch() { override fun execute(context: ResourceContext) { DrawableColorPatch.injectCall("$UTILS_PATH/DrawableColorPatch;->getColor(I)I") diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/MaterialYouPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/MaterialYouPatch.kt index f332a100a..232184a74 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/MaterialYouPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/MaterialYouPatch.kt @@ -1,7 +1,7 @@ package app.revanced.patches.youtube.layout.theme import app.revanced.patcher.data.ResourceContext -import app.revanced.patches.youtube.layout.theme.ThemeBytecodePatch.isMonetPatchIncluded +import app.revanced.patches.youtube.layout.theme.BaseThemePatch.isMonetPatchIncluded import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.settings.ResourceUtils.updatePatchStatusTheme import app.revanced.patches.youtube.utils.settings.SettingsPatch @@ -15,8 +15,8 @@ object MaterialYouPatch : BaseResourcePatch( name = "MaterialYou", description = "Enables MaterialYou theme for Android 12+", dependencies = setOf( + BaseThemePatch::class, SettingsPatch::class, - ThemeBytecodePatch::class ), compatiblePackages = COMPATIBLE_PACKAGE, use = false diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt index 4de902c20..54d0070f8 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt @@ -3,7 +3,7 @@ package app.revanced.patches.youtube.layout.theme import app.revanced.patcher.data.ResourceContext import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatchOption -import app.revanced.patches.youtube.layout.theme.ThemeBytecodePatch.isMonetPatchIncluded +import app.revanced.patches.youtube.layout.theme.BaseThemePatch.isMonetPatchIncluded import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.settings.ResourceUtils.updatePatchStatusTheme import app.revanced.patches.youtube.utils.settings.SettingsPatch @@ -15,8 +15,8 @@ object ThemePatch : BaseResourcePatch( name = "Theme", description = "Change the app's theme to the values specified in options.json.", dependencies = setOf( - SettingsPatch::class, - ThemeBytecodePatch::class + BaseThemePatch::class, + SettingsPatch::class ), compatiblePackages = COMPATIBLE_PACKAGE ) { diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/tooltip/TooltipContentViewPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/tooltip/TooltipContentViewPatch.kt index 95f7006ab..39a891e6c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/tooltip/TooltipContentViewPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/tooltip/TooltipContentViewPatch.kt @@ -6,8 +6,8 @@ import app.revanced.patches.youtube.layout.tooltip.fingerprints.TooltipContentVi import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object TooltipContentViewPatch : BaseBytecodePatch( @@ -22,10 +22,10 @@ object TooltipContentViewPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - TooltipContentViewFingerprint.result?.mutableMethod?.addInstruction( + TooltipContentViewFingerprint.resultOrThrow().mutableMethod.addInstruction( 0, "return-void" - ) ?: throw TooltipContentViewFingerprint.exception + ) /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/AmbientModeSwitchPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/AmbientModeSwitchPatch.kt index 87ef41454..fb19cc843 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/AmbientModeSwitchPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/AmbientModeSwitchPatch.kt @@ -10,10 +10,10 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.FULLSCREEN_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithMethodReferenceNameReversed import app.revanced.util.literalInstructionBooleanHook import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -29,7 +29,7 @@ object AmbientModeSwitchPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - PowerSaveModeFingerprint.result?.let { + PowerSaveModeFingerprint.resultOrThrow().let { it.mutableMethod.apply { val powerSaveModePrimaryIndex = getTargetIndexWithMethodReferenceNameReversed("isPowerSaveMode") val powerSaveModeSecondaryIndex = getTargetIndexWithMethodReferenceNameReversed(powerSaveModePrimaryIndex - 1, "isPowerSaveMode") @@ -41,7 +41,7 @@ object AmbientModeSwitchPatch : BaseBytecodePatch( hook(index) } } - } ?: throw PowerSaveModeFingerprint.exception + } AmbientModeInFullscreenFingerprint.literalInstructionBooleanHook( 45389368, diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/codec/video/ForceVideoCodecPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/codec/video/ForceVideoCodecPatch.kt index e43457cf6..a3d908c9b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/codec/video/ForceVideoCodecPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/codec/video/ForceVideoCodecPatch.kt @@ -14,9 +14,9 @@ import app.revanced.patches.youtube.utils.fingerprints.LayoutSwitchFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithFieldReferenceName import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -38,23 +38,22 @@ object ForceVideoCodecPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { - LayoutSwitchFingerprint.result?.classDef?.let { classDef -> + LayoutSwitchFingerprint.resultOrThrow().classDef.let { classDef -> arrayOf( VideoPrimaryFingerprint, VideoSecondaryFingerprint ).forEach { fingerprint -> - fingerprint.also { it.resolve(context, classDef) }.result?.injectOverride() - ?: throw fingerprint.exception + fingerprint.also { it.resolve(context, classDef) }.resultOrThrow().injectOverride() } - } ?: throw LayoutSwitchFingerprint.exception + } - VideoPropsParentFingerprint.result?.let { parentResult -> + VideoPropsParentFingerprint.resultOrThrow().let { parentResult -> VideoPropsFingerprint.also { it.resolve( context, parentResult.classDef ) - }.result?.mutableMethod?.let { + }.resultOrThrow().mutableMethod.let { mapOf( "MANUFACTURER" to "getManufacturer", "BRAND" to "getBrand", @@ -62,8 +61,8 @@ object ForceVideoCodecPatch : BaseBytecodePatch( ).forEach { (fieldName, descriptor) -> it.hookProps(fieldName, descriptor) } - } ?: throw VideoPropsFingerprint.exception - } ?: throw VideoPropsParentFingerprint.exception + } + } /** * Add settings @@ -100,10 +99,10 @@ object ForceVideoCodecPatch : BaseBytecodePatch( ) { addInstructions( index, """ - invoke-static {v$register}, $INTEGRATIONS_CLASS_METHOD_REFERENCE - move-result v$register - return v$register - """ + invoke-static {v$register}, $INTEGRATIONS_CLASS_METHOD_REFERENCE + move-result v$register + return v$register + """ ) } diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/layoutswitch/LayoutSwitchPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/layoutswitch/LayoutSwitchPatch.kt index 6b6cd125a..8f5ab7ae3 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/layoutswitch/LayoutSwitchPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/layoutswitch/LayoutSwitchPatch.kt @@ -12,11 +12,11 @@ import app.revanced.patches.youtube.utils.fingerprints.LayoutSwitchFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getStringInstructionIndex import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexReversed import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -36,7 +36,7 @@ object LayoutSwitchPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { // tablet layout - GetFormFactorFingerprint.result?.let { + GetFormFactorFingerprint.resultOrThrow().let { it.mutableMethod.apply { val jumpIndex = getTargetIndexReversed(Opcode.SGET_OBJECT) @@ -52,10 +52,10 @@ object LayoutSwitchPatch : BaseBytecodePatch( ) ) } - } ?: throw GetFormFactorFingerprint.exception + } // phone layout - LayoutSwitchFingerprint.result?.let { + LayoutSwitchFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstructions( 4, """ @@ -64,7 +64,7 @@ object LayoutSwitchPatch : BaseBytecodePatch( """ ) } - } ?: throw LayoutSwitchFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/MinimizedPlaybackPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/MinimizedPlaybackPatch.kt index 16c0a71b2..db4753fb2 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/MinimizedPlaybackPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/MinimizedPlaybackPatch.kt @@ -12,9 +12,9 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH import app.revanced.patches.youtube.utils.integrations.IntegrationsPatch import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch -import app.revanced.util.exception import app.revanced.util.getWalkerMethod import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction import com.android.tools.smali.dexlib2.iface.reference.MethodReference @@ -39,16 +39,16 @@ object MinimizedPlaybackPatch : BaseBytecodePatch( "$MISC_PATH/MinimizedPlaybackPatch;->isPlaybackNotShort()Z" override fun execute(context: BytecodeContext) { - KidsMinimizedPlaybackPolicyControllerFingerprint.result?.let { + KidsMinimizedPlaybackPolicyControllerFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstruction( 0, "return-void" ) } - } ?: throw KidsMinimizedPlaybackPolicyControllerFingerprint.exception + } - MinimizedPlaybackManagerFingerprint.result?.let { + MinimizedPlaybackManagerFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstructions( 0, """ @@ -58,9 +58,9 @@ object MinimizedPlaybackPatch : BaseBytecodePatch( """ ) } - } ?: throw MinimizedPlaybackManagerFingerprint.exception + } - MinimizedPlaybackSettingsFingerprint.result?.let { + MinimizedPlaybackSettingsFingerprint.resultOrThrow().let { it.mutableMethod.apply { val booleanCalls = implementation!!.instructions.withIndex() .filter { instruction -> @@ -77,9 +77,9 @@ object MinimizedPlaybackPatch : BaseBytecodePatch( """ ) } - } ?: throw MinimizedPlaybackSettingsFingerprint.exception + } - PiPControllerFingerprint.result?.let { + PiPControllerFingerprint.resultOrThrow().let { val targetMethod = it.getWalkerMethod(context, it.scanResult.patternScanResult!!.endIndex) targetMethod.apply { @@ -90,6 +90,6 @@ object MinimizedPlaybackPatch : BaseBytecodePatch( "const/4 v$targetRegister, 0x1" ) } - } ?: throw PiPControllerFingerprint.exception + } } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/openlinksdirectly/OpenLinksDirectlyPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/openlinksdirectly/OpenLinksDirectlyPatch.kt index c2a215742..0221e22b2 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/openlinksdirectly/OpenLinksDirectlyPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/openlinksdirectly/OpenLinksDirectlyPatch.kt @@ -8,8 +8,8 @@ import app.revanced.patches.youtube.misc.openlinksdirectly.fingerprints.OpenLink import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c import com.android.tools.smali.dexlib2.iface.reference.MethodReference @@ -31,7 +31,7 @@ object OpenLinksDirectlyPatch : BaseBytecodePatch( OpenLinksDirectlyFingerprintPrimary, OpenLinksDirectlyFingerprintSecondary ).forEach { fingerprint -> - fingerprint.result?.let { + fingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = implementation!!.instructions .indexOfFirst { instruction -> @@ -44,7 +44,7 @@ object OpenLinksDirectlyPatch : BaseBytecodePatch( "invoke-static {v$insertRegister}, $MISC_PATH/OpenLinksDirectlyPatch;->enableBypassRedirect(Ljava/lang/String;)Landroid/net/Uri;" ) } - } ?: throw fingerprint.exception + } } /** diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/quic/QUICProtocolPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/quic/QUICProtocolPatch.kt index 9a3392f66..d82f90e27 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/quic/QUICProtocolPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/quic/QUICProtocolPatch.kt @@ -7,8 +7,8 @@ import app.revanced.patches.youtube.misc.quic.fingerprints.ExperimentalCronetEng import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object QUICProtocolPatch : BaseBytecodePatch( @@ -27,12 +27,12 @@ object QUICProtocolPatch : BaseBytecodePatch( CronetEngineBuilderFingerprint, ExperimentalCronetEngineBuilderFingerprint ).forEach { - it.result?.mutableMethod?.addInstructions( + it.resultOrThrow().mutableMethod.addInstructions( 0, """ invoke-static {p1}, $MISC_PATH/QUICProtocolPatch;->disableQUICProtocol(Z)Z move-result p1 """ - ) ?: throw it.exception + ) } /** diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/splashanimation/NewSplashAnimationPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/splashanimation/NewSplashAnimationPatch.kt index a0d0ecc30..ebab9ec19 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/splashanimation/NewSplashAnimationPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/splashanimation/NewSplashAnimationPatch.kt @@ -12,9 +12,9 @@ import app.revanced.patches.youtube.utils.mainactivity.MainActivityResolvePatch. 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 -import app.revanced.util.exception import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @@ -39,7 +39,7 @@ object NewSplashAnimationPatch : BaseBytecodePatch( /** * YouTube v18.28.xx~ */ - WatchWhileActivityWithOutFlagsFingerprint.result?.let { + WatchWhileActivityWithOutFlagsFingerprint.resultOrThrow().let { it.mutableMethod.apply { var startIndex = getWideLiteralInstructionIndex(DarkSplashAnimation) - 1 val endIndex = startIndex - 30 @@ -67,7 +67,7 @@ object NewSplashAnimationPatch : BaseBytecodePatch( break } } - } ?: throw WatchWhileActivityWithOutFlagsFingerprint.exception + } /** * Add settings @@ -96,9 +96,9 @@ object NewSplashAnimationPatch : BaseBytecodePatch( addInstructions( index, """ - invoke-static {v$register}, $INTEGRATIONS_CLASS_DESCRIPTOR->enableNewSplashAnimationBoolean(Z)Z - move-result v$register - """ + invoke-static {v$register}, $INTEGRATIONS_CLASS_DESCRIPTOR->enableNewSplashAnimationBoolean(Z)Z + move-result v$register + """ ) } @@ -107,9 +107,9 @@ object NewSplashAnimationPatch : BaseBytecodePatch( addInstructions( index, """ - invoke-static {v$register}, $INTEGRATIONS_CLASS_DESCRIPTOR->enableNewSplashAnimationInt(I)I - move-result v$register - """ + invoke-static {v$register}, $INTEGRATIONS_CLASS_DESCRIPTOR->enableNewSplashAnimationInt(I)I + move-result v$register + """ ) } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/spoofdimensions/SpoofDeviceDimensionsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/spoofdimensions/SpoofDeviceDimensionsPatch.kt index b754cef75..dcefeebb0 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/spoofdimensions/SpoofDeviceDimensionsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/spoofdimensions/SpoofDeviceDimensionsPatch.kt @@ -6,8 +6,8 @@ import app.revanced.patches.youtube.misc.spoofdimensions.fingerprints.DeviceDime import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.util.MethodUtil @Suppress("unused") @@ -22,7 +22,7 @@ object SpoofDeviceDimensionsPatch : BaseBytecodePatch( "$MISC_PATH/SpoofDeviceDimensionsPatch;" override fun execute(context: BytecodeContext) { - DeviceDimensionsModelToStringFingerprint.result?.let { result -> + DeviceDimensionsModelToStringFingerprint.resultOrThrow().let { result -> result.mutableClass.methods.first { method -> MethodUtil.isConstructor(method) } .addInstructions( 1, // Add after super call. @@ -38,7 +38,7 @@ object SpoofDeviceDimensionsPatch : BaseBytecodePatch( """ }.joinToString("\n") { it } ) - } ?: throw DeviceDimensionsModelToStringFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/tracking/SanitizeUrlQueryBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/tracking/SanitizeUrlQueryBytecodePatch.kt index 5512eb0a8..77f7dee2a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/tracking/SanitizeUrlQueryBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/tracking/SanitizeUrlQueryBytecodePatch.kt @@ -9,7 +9,7 @@ import app.revanced.patches.youtube.misc.tracking.fingerprints.ShareLinkFormatte import app.revanced.patches.youtube.misc.tracking.fingerprints.SystemShareLinkFormatterFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -32,7 +32,7 @@ object SanitizeUrlQueryBytecodePatch : BaseSanitizeUrlQueryPatch( ShareLinkFormatterFingerprint, SystemShareLinkFormatterFingerprint ).forEach { fingerprint -> - fingerprint.result?.let { + fingerprint.resultOrThrow().let { it.mutableMethod.apply { for ((index, instruction) in implementation!!.instructions.withIndex()) { if (instruction.opcode != Opcode.INVOKE_VIRTUAL) @@ -53,7 +53,7 @@ object SanitizeUrlQueryBytecodePatch : BaseSanitizeUrlQueryPatch( ) } } - } ?: throw fingerprint.exception + } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/updatescreen/UpdateScreenPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/updatescreen/UpdateScreenPatch.kt index 1bfd7209e..c07ce1da1 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/updatescreen/UpdateScreenPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/updatescreen/UpdateScreenPatch.kt @@ -6,8 +6,8 @@ import app.revanced.patches.youtube.misc.updatescreen.fingerprints.AppBlockingCh import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.MISC_PATH import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.util.MethodUtil @Suppress("unused") @@ -22,13 +22,13 @@ object UpdateScreenPatch : BaseBytecodePatch( "$MISC_PATH/UpdateScreenPatch;" override fun execute(context: BytecodeContext) { - AppBlockingCheckResultToStringFingerprint.result?.mutableClass?.methods?.first { method -> + AppBlockingCheckResultToStringFingerprint.resultOrThrow().mutableClass.methods.first { method -> MethodUtil.isConstructor(method) && method.parameters == listOf("Landroid/content/Intent;", "Z") - }?.addInstructions( + }.addInstructions( 1, "const/4 p1, 0x0" - ) ?: throw AppBlockingCheckResultToStringFingerprint.exception + ) SettingsPatch.updatePatchStatus("Disable update screen") } diff --git a/src/main/kotlin/app/revanced/patches/youtube/navigation/label/NavigationLabelPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/navigation/label/NavigationLabelPatch.kt index 70a6d05a0..4a33c4946 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/navigation/label/NavigationLabelPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/navigation/label/NavigationLabelPatch.kt @@ -7,9 +7,9 @@ import app.revanced.patches.youtube.navigation.label.fingerprints.PivotBarSetTex import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.NAVIGATION_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction @Suppress("unused") @@ -22,7 +22,7 @@ object NavigationLabelPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - PivotBarSetTextFingerprint.result?.let { + PivotBarSetTextFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = getTargetIndexWithMethodReferenceName("setText") val targetRegister = getInstruction(targetIndex).registerC @@ -32,7 +32,7 @@ object NavigationLabelPatch : BaseBytecodePatch( "invoke-static {v$targetRegister}, $NAVIGATION_CLASS_DESCRIPTOR->hideNavigationLabel(Landroid/widget/TextView;)V" ) } - } ?: throw PivotBarSetTextFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/navigation/navigationbuttons/NavigationButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/navigation/navigationbuttons/NavigationButtonsPatch.kt index 9dfb8ed46..8f3e4423d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/navigation/navigationbuttons/NavigationButtonsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/navigation/navigationbuttons/NavigationButtonsPatch.kt @@ -14,11 +14,11 @@ import app.revanced.patches.youtube.utils.integrations.Constants.NAVIGATION_CLAS import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ImageOnlyTab import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getStringInstructionIndex import app.revanced.util.getTargetIndex import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.Opcode.MOVE_RESULT_OBJECT import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -39,7 +39,7 @@ object NavigationButtonsPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - PivotBarCreateButtonViewFingerprint.result?.let { parentResult -> + PivotBarCreateButtonViewFingerprint.resultOrThrow().let { parentResult -> /** * Home, Shorts, Subscriptions Button @@ -55,7 +55,7 @@ object NavigationButtonsPatch : BaseBytecodePatch( parentResult.mutableClass ) }.map { - it.result?.scanResult?.patternScanResult ?: throw it.exception + it.resultOrThrow().scanResult.patternScanResult!! } ) { val enumScanResult = this[0] @@ -81,12 +81,12 @@ object NavigationButtonsPatch : BaseBytecodePatch( injectHook(CREATE_BUTTON_HOOK, insertIndex) } - } ?: throw PivotBarCreateButtonViewFingerprint.exception + } /** * Switch create button with notifications button */ - AutoMotiveFingerprint.result?.let { + AutoMotiveFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = getStringInstructionIndex("Android Automotive") - 1 val register = getInstruction(insertIndex).registerA @@ -98,7 +98,7 @@ object NavigationButtonsPatch : BaseBytecodePatch( """ ) } - } ?: throw AutoMotiveFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/navigation/tabletnavbar/TabletNavigationBarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/navigation/tabletnavbar/TabletNavigationBarPatch.kt index 889ce25c1..62b1fc63b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/navigation/tabletnavbar/TabletNavigationBarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/navigation/tabletnavbar/TabletNavigationBarPatch.kt @@ -9,8 +9,8 @@ import app.revanced.patches.youtube.navigation.tabletnavbar.fingerprints.PivotBa import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.NAVIGATION_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -30,7 +30,7 @@ object TabletNavigationBarPatch : BaseBytecodePatch( PivotBarChangedFingerprint, PivotBarStyleFingerprint ).forEach { - it.result?.insertHook() ?: throw it.exception + it.resultOrThrow().insertHook() } /** diff --git a/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/alwaysrepeat/AlwaysRepeatPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/alwaysrepeat/AlwaysRepeatPatch.kt index 23cc670c6..79a988284 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/alwaysrepeat/AlwaysRepeatPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/alwaysrepeat/AlwaysRepeatPatch.kt @@ -6,8 +6,8 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patches.youtube.overlaybutton.alwaysrepeat.fingerprints.AutoNavInformerFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH -import app.revanced.util.exception import app.revanced.util.getWalkerMethod +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction object AlwaysRepeatPatch : BytecodePatch( @@ -15,7 +15,7 @@ object AlwaysRepeatPatch : BytecodePatch( ) { override fun execute(context: BytecodeContext) { - AutoNavInformerFingerprint.result?.let { + AutoNavInformerFingerprint.resultOrThrow().let { val walkerMethod = it.getWalkerMethod(context, it.scanResult.patternScanResult!!.startIndex) walkerMethod.apply { val index = implementation!!.instructions.size - 2 @@ -28,7 +28,7 @@ object AlwaysRepeatPatch : BytecodePatch( """ ) } - } ?: throw AutoNavInformerFingerprint.exception + } } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/download/hook/DownloadButtonHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/download/hook/DownloadButtonHookPatch.kt index a8a935cc9..803d510bc 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/download/hook/DownloadButtonHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/download/hook/DownloadButtonHookPatch.kt @@ -7,7 +7,7 @@ import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.youtube.overlaybutton.download.hook.fingerprints.DownloadActionsFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH -import app.revanced.util.exception +import app.revanced.util.resultOrThrow object DownloadButtonHookPatch : BytecodePatch( setOf(DownloadActionsFingerprint) @@ -15,7 +15,7 @@ object DownloadButtonHookPatch : BytecodePatch( private const val INTEGRATIONS_CLASS_DESCRIPTOR = "$UTILS_PATH/HookDownloadButtonPatch;" override fun execute(context: BytecodeContext) { - DownloadActionsFingerprint.result?.let { + DownloadActionsFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.startIndex @@ -29,7 +29,7 @@ object DownloadButtonHookPatch : BytecodePatch( """, ExternalLabel("default", getInstruction(targetIndex)) ) } - } ?: throw DownloadActionsFingerprint.exception + } } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/download/pip/DisablePiPPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/download/pip/DisablePiPPatch.kt index 0975f8ed7..f235acf8a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/download/pip/DisablePiPPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/download/pip/DisablePiPPatch.kt @@ -6,7 +6,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patches.youtube.overlaybutton.download.pip.fingerprints.PiPPlaybackFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.INTEGRATIONS_PATH -import app.revanced.util.exception +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction /** @@ -20,7 +20,7 @@ object DisablePiPPatch : BytecodePatch( "$INTEGRATIONS_PATH/utils/VideoUtils;" override fun execute(context: BytecodeContext) { - PiPPlaybackFingerprint.result?.let { + PiPPlaybackFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.endIndex val insertRegister = getInstruction(insertIndex).registerA @@ -32,7 +32,7 @@ object DisablePiPPatch : BytecodePatch( """ ) } - } ?: throw PiPPlaybackFingerprint.exception + } } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/fullscreen/FullscreenButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/fullscreen/FullscreenButtonPatch.kt index 184fd24ff..55714770e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/fullscreen/FullscreenButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/fullscreen/FullscreenButtonPatch.kt @@ -9,8 +9,8 @@ import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.youtube.overlaybutton.fullscreen.fingerprints.FullScreenButtonFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithReference +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction @Patch(dependencies = [SharedResourceIdPatch::class]) @@ -19,7 +19,7 @@ object FullscreenButtonPatch : BytecodePatch( ) { override fun execute(context: BytecodeContext) { - FullScreenButtonFingerprint.result?.let { + FullScreenButtonFingerprint.resultOrThrow().let { it.mutableMethod.apply { val viewIndex = getTargetIndexWithReference("Landroid/widget/ImageView;->getResources()Landroid/content/res/Resources;") val viewRegister = getInstruction(viewIndex).registerC @@ -33,7 +33,7 @@ object FullscreenButtonPatch : BytecodePatch( """, ExternalLabel("show", getInstruction(viewIndex)) ) } - } ?: throw FullScreenButtonFingerprint.exception + } } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/general/OverlayButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/general/OverlayButtonsPatch.kt index a63a783b9..a4e220c41 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/general/OverlayButtonsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/overlaybutton/general/OverlayButtonsPatch.kt @@ -230,7 +230,6 @@ object OverlayButtonsPatch : BaseResourcePatch( } } } - } diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/autoplaybutton/AutoplayButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/autoplaybutton/AutoplayButtonPatch.kt index 590cc0a73..2f75aee10 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/autoplaybutton/AutoplayButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/autoplaybutton/AutoplayButtonPatch.kt @@ -11,10 +11,10 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.AutoNavPreviewStub import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.VideoZoomIndicatorLayout import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getStringInstructionIndex import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -30,7 +30,7 @@ object AutoplayButtonPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - LayoutConstructorFingerprint.result?.let { + LayoutConstructorFingerprint.resultOrThrow().let { it.mutableMethod.apply { val dummyRegister = getInstruction(getStringInstructionIndex("1.0x")).registerA @@ -45,7 +45,7 @@ object AutoplayButtonPatch : BaseBytecodePatch( """, ExternalLabel("hidden", getInstruction(jumpIndex)) ) } - } ?: throw LayoutConstructorFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/captionsbutton/CaptionsButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/captionsbutton/CaptionsButtonPatch.kt index 8c8cf7452..189f60c22 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/captionsbutton/CaptionsButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/captionsbutton/CaptionsButtonPatch.kt @@ -12,8 +12,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -56,7 +56,7 @@ object CaptionsButtonPatch : BaseBytecodePatch( } } - YouTubeControlsOverlaySubtitleButtonFingerprint.result?.let { + YouTubeControlsOverlaySubtitleButtonFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = implementation!!.instructions.size - 1 val insertRegister = getInstruction(insertIndex).registerA @@ -66,7 +66,7 @@ object CaptionsButtonPatch : BaseBytecodePatch( "invoke-static {v$insertRegister}, $PLAYER_CLASS_DESCRIPTOR->hideCaptionsButton(Landroid/view/View;)V" ) } - } ?: throw YouTubeControlsOverlaySubtitleButtonFingerprint.exception + } LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR) diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/collapsebutton/CollapseButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/collapsebutton/CollapseButtonPatch.kt index c41962efd..924e2f2ff 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/collapsebutton/CollapseButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/collapsebutton/CollapseButtonPatch.kt @@ -8,9 +8,9 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.findMutableMethodOf import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction21c import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction35c @@ -28,7 +28,7 @@ object CollapseButtonPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - LiveChatFingerprint.result?.let { + LiveChatFingerprint.resultOrThrow().let { val endIndex = it.scanResult.patternScanResult!!.endIndex val instructions = it.mutableMethod.getInstruction(endIndex) val imageButtonClass = context @@ -64,7 +64,7 @@ object CollapseButtonPatch : BaseBytecodePatch( } } } - } ?: throw LiveChatFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/endscreencards/EndScreenCardsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/endscreencards/EndScreenCardsPatch.kt index 0a8851256..eb76659bc 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/endscreencards/EndScreenCardsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/endscreencards/EndScreenCardsPatch.kt @@ -10,8 +10,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -35,7 +35,7 @@ object EndScreenCardsPatch : BaseBytecodePatch( LayoutIconFingerprint, LayoutVideoFingerprint ).forEach{ fingerprint -> - fingerprint.result?.let { + fingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.endIndex val viewRegister = getInstruction(insertIndex).registerA @@ -45,7 +45,7 @@ object EndScreenCardsPatch : BaseBytecodePatch( "invoke-static { v$viewRegister }, $PLAYER_CLASS_DESCRIPTOR->hideEndScreenCards(Landroid/view/View;)V" ) } - } ?: throw fingerprint.exception + } } /** diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/filmstripoverlay/FilmstripOverlayPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/filmstripoverlay/FilmstripOverlayPatch.kt index 4da233c93..567d793fb 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/filmstripoverlay/FilmstripOverlayPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/filmstripoverlay/FilmstripOverlayPatch.kt @@ -17,8 +17,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -42,19 +42,18 @@ object FilmstripOverlayPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - FilmStripOverlayParentFingerprint.result?.classDef?.let { classDef -> + FilmStripOverlayParentFingerprint.resultOrThrow().classDef.let { classDef -> arrayOf( FilmStripOverlayConfigFingerprint, FilmStripOverlayInteractionFingerprint, FilmStripOverlayPreviewFingerprint ).forEach { fingerprint -> fingerprint.resolve(context, classDef) - fingerprint.result?.mutableMethod?.injectHook() - ?: throw fingerprint.exception + fingerprint.resultOrThrow().mutableMethod.injectHook() } - } ?: throw FilmStripOverlayParentFingerprint.exception + } - FineScrubbingOverlayFingerprint.result?.let { + FineScrubbingOverlayFingerprint.resultOrThrow().let { it.mutableMethod.apply { var insertIndex = it.scanResult.patternScanResult!!.startIndex + 2 val jumpIndex = getTargetIndexUpTo(insertIndex, Opcode.GOTO, Opcode.GOTO_16) @@ -79,7 +78,7 @@ object FilmstripOverlayPatch : BaseBytecodePatch( ) removeInstruction(insertIndex) } - } ?: throw FineScrubbingOverlayFingerprint.exception + } /** * Add settings @@ -151,12 +150,12 @@ object FilmstripOverlayPatch : BaseBytecodePatch( private fun MutableMethod.injectHook() { addInstructionsWithLabels( 0, """ - invoke-static {}, $PLAYER_CLASS_DESCRIPTOR->hideFilmstripOverlay()Z - move-result v0 - if-eqz v0, :shown - const/4 v0, 0x0 - return v0 - """, ExternalLabel("shown", getInstruction(0)) + invoke-static {}, $PLAYER_CLASS_DESCRIPTOR->hideFilmstripOverlay()Z + move-result v0 + if-eqz v0, :shown + const/4 v0, 0x0 + return v0 + """, ExternalLabel("shown", getInstruction(0)) ) } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/hapticfeedback/HapticFeedBackPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/hapticfeedback/HapticFeedBackPatch.kt index 1034a5616..85853a65d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/hapticfeedback/HapticFeedBackPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/hapticfeedback/HapticFeedBackPatch.kt @@ -13,9 +13,9 @@ import app.revanced.patches.youtube.player.hapticfeedback.fingerprints.ZoomHapti import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -60,7 +60,7 @@ object HapticFeedBackPatch : BaseBytecodePatch( } private fun MethodFingerprint.injectHook(methodName: String) { - result?.let { + resultOrThrow().let { it.mutableMethod.apply { var index = 0 var register = 0 @@ -79,7 +79,7 @@ object HapticFeedBackPatch : BaseBytecodePatch( """, ExternalLabel("vibrate", getInstruction(index)) ) } - } ?: throw exception + } } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/infocards/InfoCardsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/infocards/InfoCardsPatch.kt index fc0a46dea..373243c7e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/infocards/InfoCardsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/infocards/InfoCardsPatch.kt @@ -9,8 +9,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @Suppress("unused") @@ -28,7 +28,7 @@ object InfoCardsPatch : BaseBytecodePatch( "$COMPONENTS_PATH/InfoCardsFilter;" override fun execute(context: BytecodeContext) { - InfoCardsIncognitoFingerprint.result?.let { + InfoCardsIncognitoFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.startIndex val targetRegister = @@ -41,7 +41,7 @@ object InfoCardsPatch : BaseBytecodePatch( """ ) } - } ?: throw InfoCardsIncognitoFingerprint.exception + } LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR) diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/musicbutton/MusicButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/musicbutton/MusicButtonPatch.kt index 16045fe8b..e5f244362 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/musicbutton/MusicButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/musicbutton/MusicButtonPatch.kt @@ -10,8 +10,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object MusicButtonPatch : BaseBytecodePatch( @@ -26,11 +26,10 @@ object MusicButtonPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - val mutableClass = MusicAppDeeplinkButtonParentFingerprint.result?.mutableClass - ?: throw MusicAppDeeplinkButtonParentFingerprint.exception + val mutableClass = MusicAppDeeplinkButtonParentFingerprint.resultOrThrow().mutableClass MusicAppDeeplinkButtonFingerprint.resolve(context, mutableClass) - MusicAppDeeplinkButtonFingerprint.result?.let { + MusicAppDeeplinkButtonFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstructionsWithLabels( 0, @@ -42,7 +41,7 @@ object MusicButtonPatch : BaseBytecodePatch( ExternalLabel("hidden", getInstruction(implementation!!.instructions.size - 1)) ) } - } ?: throw MusicAppDeeplinkButtonFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/playeroverlay/CustomPlayerOverlayOpacityPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/playeroverlay/CustomPlayerOverlayOpacityPatch.kt index 34ea66d9e..e48765dae 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/playeroverlay/CustomPlayerOverlayOpacityPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/playeroverlay/CustomPlayerOverlayOpacityPatch.kt @@ -10,9 +10,9 @@ import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DE import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ScrimOverlay import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -29,7 +29,7 @@ object CustomPlayerOverlayOpacityPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - YouTubeControlsOverlayFingerprint.result?.let { + YouTubeControlsOverlayFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = getWideLiteralInstructionIndex(ScrimOverlay) + 3 val targetParameter = getInstruction(targetIndex).reference @@ -43,7 +43,7 @@ object CustomPlayerOverlayOpacityPatch : BaseBytecodePatch( "invoke-static {v$targetRegister}, $PLAYER_CLASS_DESCRIPTOR->changePlayerOpacity(Landroid/widget/ImageView;)V" ) } - } ?: throw YouTubeControlsOverlayFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/previousnextbutton/PreviousNextButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/previousnextbutton/PreviousNextButtonPatch.kt index 579b44589..8bea46b8f 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/previousnextbutton/PreviousNextButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/previousnextbutton/PreviousNextButtonPatch.kt @@ -7,8 +7,8 @@ import app.revanced.patches.youtube.utils.fingerprints.PlayerControlsVisibilityM import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction3rc @Suppress("unused") @@ -27,7 +27,7 @@ object PreviousNextButtonPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { - PlayerControlsVisibilityModelFingerprint.result?.let { + PlayerControlsVisibilityModelFingerprint.resultOrThrow().let { it.mutableMethod.apply { val callIndex = it.scanResult.patternScanResult!!.endIndex val callInstruction = getInstruction(callIndex) @@ -44,7 +44,7 @@ object PreviousNextButtonPatch : BaseBytecodePatch( """ ) } - } ?: throw PlayerControlsVisibilityModelFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/seekmessage/SeekMessagePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/seekmessage/SeekMessagePatch.kt index dd1918ef3..98326294e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/seekmessage/SeekMessagePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/seekmessage/SeekMessagePatch.kt @@ -13,9 +13,9 @@ import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DE import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.SeekUndoEduOverlayStub import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow 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.WideLiteralInstruction @@ -37,7 +37,7 @@ object SeekMessagePatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - SeekEduContainerFingerprint.result?.let { + SeekEduContainerFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstructionsWithLabels( 0, """ @@ -48,12 +48,12 @@ object SeekMessagePatch : BaseBytecodePatch( """, ExternalLabel("default", getInstruction(0)) ) } - } ?: throw SeekEduContainerFingerprint.exception + } /** * Added in YouTube v18.29.xx~ */ - SeekEduUndoOverlayFingerprint.result?.let { result -> + SeekEduUndoOverlayFingerprint.resultOrThrow().let { result -> result.mutableMethod.apply { val seekUndoCalls = implementation!!.instructions.withIndex() .filter { instruction -> @@ -73,7 +73,7 @@ object SeekMessagePatch : BaseBytecodePatch( """, ExternalLabel("default", getInstruction(onClickListenerIndex + 1)) ) } - } ?: throw SeekEduUndoOverlayFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/suggestactions/SuggestedActionsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/suggestactions/SuggestedActionsPatch.kt index 481163706..fd561d149 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/suggestactions/SuggestedActionsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/suggestactions/SuggestedActionsPatch.kt @@ -10,8 +10,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Suppress("unused") @@ -31,7 +31,7 @@ object SuggestedActionsPatch : BaseBytecodePatch( "$COMPONENTS_PATH/SuggestedActionFilter;" override fun execute(context: BytecodeContext) { - SuggestedActionsFingerprint.result?.let { + SuggestedActionsFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.endIndex val targetRegister = getInstruction(targetIndex).registerA @@ -42,7 +42,7 @@ object SuggestedActionsPatch : BaseBytecodePatch( ) } - } ?: throw SuggestedActionsFingerprint.exception + } LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR) diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/SuggestedVideoOverlayPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/SuggestedVideoOverlayPatch.kt index c0f9cdd23..4fe1ab0b1 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/SuggestedVideoOverlayPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/suggestedvideooverlay/SuggestedVideoOverlayPatch.kt @@ -13,9 +13,9 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction @Suppress("unused") @@ -34,7 +34,7 @@ object SuggestedVideoOverlayPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - CoreContainerBuilderFingerprint.result?.let { parentResult -> + CoreContainerBuilderFingerprint.resultOrThrow().let { parentResult -> parentResult.mutableMethod.apply { val addOnClickEventListenerIndex = parentResult.scanResult.patternScanResult!!.endIndex - 1 val viewRegister = getInstruction(addOnClickEventListenerIndex).registerC @@ -48,7 +48,7 @@ object SuggestedVideoOverlayPatch : BaseBytecodePatch( // Resolves fingerprints MiniPlayerPlayButtonFingerprint.resolve(context, parentResult.classDef) - MiniPlayerPlayButtonFingerprint.result?.let { + MiniPlayerPlayButtonFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstructionsWithLabels( 0, """ @@ -59,10 +59,10 @@ object SuggestedVideoOverlayPatch : BaseBytecodePatch( """, ExternalLabel("show", getInstruction(0)) ) } - } ?: throw MiniPlayerPlayButtonFingerprint.exception - } ?: throw CoreContainerBuilderFingerprint.exception + } + } - TouchAreaOnClickListenerFingerprint.result?.let { + TouchAreaOnClickListenerFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertMethod = it.mutableClass.methods.find { method -> method.parameters == listOf("Landroid/view/View${'$'}OnClickListener;") } @@ -76,7 +76,7 @@ object SuggestedVideoOverlayPatch : BaseBytecodePatch( ) } ?: throw PatchException("Failed to find setOnClickListener method") } - } ?: throw TouchAreaOnClickListenerFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/player/watermark/ChannelWatermarkPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/player/watermark/ChannelWatermarkPatch.kt index 08b11b91b..a41928005 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/player/watermark/ChannelWatermarkPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/player/watermark/ChannelWatermarkPatch.kt @@ -10,8 +10,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.COMPONENTS_PATH import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @Suppress("unused") @@ -30,13 +30,13 @@ object ChannelWatermarkPatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { - WatermarkParentFingerprint.result?.let { parentResult -> + WatermarkParentFingerprint.resultOrThrow().let { parentResult -> WatermarkFingerprint.also { it.resolve( context, parentResult.classDef ) - }.result?.let { + }.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.endIndex val register = getInstruction(insertIndex).registerA @@ -48,8 +48,8 @@ object ChannelWatermarkPatch : BaseBytecodePatch( """ ) } - } ?: throw WatermarkFingerprint.exception - } ?: throw WatermarkParentFingerprint.exception + } + } LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR) diff --git a/src/main/kotlin/app/revanced/patches/youtube/seekbar/append/AppendTimeStampInformationPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/seekbar/append/AppendTimeStampInformationPatch.kt index 5f2421aff..9729098fa 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/seekbar/append/AppendTimeStampInformationPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/seekbar/append/AppendTimeStampInformationPatch.kt @@ -10,9 +10,9 @@ import app.revanced.patches.youtube.utils.overridequality.OverrideQualityHookPat import app.revanced.patches.youtube.utils.overridespeed.OverrideSpeedHookPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -30,7 +30,7 @@ object AppendTimeStampInformationPatch : BaseBytecodePatch( fingerprints = setOf(TotalTimeFingerprint) ) { override fun execute(context: BytecodeContext) { - TotalTimeFingerprint.result?.let { + TotalTimeFingerprint.resultOrThrow().let { it.mutableMethod.apply { val charSequenceIndex = getTargetIndexWithMethodReferenceName("getString") + 1 val charSequenceRegister = getInstruction(charSequenceIndex).registerA @@ -46,7 +46,7 @@ object AppendTimeStampInformationPatch : BaseBytecodePatch( """ ) } - } ?: throw TotalTimeFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/seekbar/color/SeekbarColorPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/seekbar/color/SeekbarColorPatch.kt index 3a4f372ee..18d0d3692 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/seekbar/color/SeekbarColorPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/seekbar/color/SeekbarColorPatch.kt @@ -17,9 +17,10 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.Inlin import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelTimeBarPlayedColor import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch.contexts -import app.revanced.util.exception +import app.revanced.util.getWalkerMethod import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction import org.w3c.dom.Element @@ -41,22 +42,18 @@ object SeekbarColorPatch : BaseBytecodePatch( ) ) { override fun execute(context: BytecodeContext) { - PlayerSeekbarColorFingerprint.result?.mutableMethod?.apply { + PlayerSeekbarColorFingerprint.resultOrThrow().mutableMethod.apply { hook(getWideLiteralInstructionIndex(InlineTimeBarColorizedBarPlayedColorDark) + 2) hook(getWideLiteralInstructionIndex(InlineTimeBarPlayedNotHighlightedColor) + 2) - } ?: throw PlayerSeekbarColorFingerprint.exception + } - ShortsSeekbarColorFingerprint.result?.mutableMethod?.apply { + ShortsSeekbarColorFingerprint.resultOrThrow().mutableMethod.apply { hook(getWideLiteralInstructionIndex(ReelTimeBarPlayedColor) + 2) - } ?: throw ShortsSeekbarColorFingerprint.exception + } - ControlsOverlayStyleFingerprint.result?.let { - with( - context - .toMethodWalker(it.method) - .nextMethod(it.scanResult.patternScanResult!!.startIndex + 1, true) - .getMethod() as MutableMethod - ) { + ControlsOverlayStyleFingerprint.resultOrThrow().let { + val walkerMethod = it.getWalkerMethod(context, it.scanResult.patternScanResult!!.startIndex + 1) + walkerMethod.apply { val colorRegister = getInstruction(0).registerA addInstructions( @@ -66,7 +63,7 @@ object SeekbarColorPatch : BaseBytecodePatch( """ ) } - } ?: throw ControlsOverlayStyleFingerprint.exception + } DrawableColorPatch.injectCall("$SEEKBAR_CLASS_DESCRIPTOR->getColor(I)I") diff --git a/src/main/kotlin/app/revanced/patches/youtube/seekbar/hide/SeekbarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/seekbar/hide/SeekbarPatch.kt index 2c23d004e..2b97238a3 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/seekbar/hide/SeekbarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/seekbar/hide/SeekbarPatch.kt @@ -10,8 +10,8 @@ import app.revanced.patches.youtube.utils.fingerprints.SeekbarOnDrawFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.SEEKBAR_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object SeekbarPatch : BaseBytecodePatch( @@ -26,8 +26,8 @@ object SeekbarPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - SeekbarFingerprint.result?.mutableClass?.let { mutableClass -> - SeekbarOnDrawFingerprint.also { it.resolve(context, mutableClass) }.result?.let { + SeekbarFingerprint.resultOrThrow().mutableClass.let { mutableClass -> + SeekbarOnDrawFingerprint.also { it.resolve(context, mutableClass) }.resultOrThrow().let { it.mutableMethod.apply { addInstructionsWithLabels( 0, """ @@ -38,8 +38,8 @@ object SeekbarPatch : BaseBytecodePatch( """, ExternalLabel("show", getInstruction(0)) ) } - } ?: throw SeekbarOnDrawFingerprint.exception - } ?: throw SeekbarFingerprint.exception + } + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/seekbar/tapping/SeekbarTappingPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/seekbar/tapping/SeekbarTappingPatch.kt index ad1653aeb..84155a58b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/seekbar/tapping/SeekbarTappingPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/seekbar/tapping/SeekbarTappingPatch.kt @@ -10,8 +10,8 @@ import app.revanced.patches.youtube.seekbar.tapping.fingerprints.SeekbarTappingF import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.SEEKBAR_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction35c import com.android.tools.smali.dexlib2.dexbacked.reference.DexBackedMethodReference @@ -26,7 +26,7 @@ object SeekbarTappingPatch : BaseBytecodePatch( fingerprints = setOf(SeekbarTappingFingerprint) ) { override fun execute(context: BytecodeContext) { - SeekbarTappingFingerprint.result?.let { + SeekbarTappingFingerprint.resultOrThrow().let { it.mutableMethod.apply { val tapSeekIndex = it.scanResult.patternScanResult!!.startIndex + 1 val tapSeekReference = getInstruction(tapSeekIndex).reference @@ -77,7 +77,7 @@ object SeekbarTappingPatch : BaseBytecodePatch( """, ExternalLabel("disabled", getInstruction(insertIndex)) ) } - } ?: throw SeekbarTappingFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/seekbar/timestamps/TimeStampPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/seekbar/timestamps/TimeStampPatch.kt index a9eb70b59..cf2dc542f 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/seekbar/timestamps/TimeStampPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/seekbar/timestamps/TimeStampPatch.kt @@ -10,8 +10,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.SEEKBAR_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object TimeStampPatch : BaseBytecodePatch( @@ -26,8 +26,8 @@ object TimeStampPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - PlayerSeekbarColorFingerprint.result?.let { parentResult -> - TimeCounterFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let { + PlayerSeekbarColorFingerprint.resultOrThrow().let { parentResult -> + TimeCounterFingerprint.also { it.resolve(context, parentResult.classDef) }.resultOrThrow().let { it.mutableMethod.apply { addInstructionsWithLabels( 0, """ @@ -38,8 +38,8 @@ object TimeStampPatch : BaseBytecodePatch( """, ExternalLabel("show", getInstruction(0)) ) } - } ?: throw TimeCounterFingerprint.exception - } ?: throw PlayerSeekbarColorFingerprint.exception + } + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsComponentPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsComponentPatch.kt index 9cc108be4..c2af8056f 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsComponentPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsComponentPatch.kt @@ -31,11 +31,11 @@ import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelR import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelRightLikeIcon import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.RightComment import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexReversed import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -62,6 +62,11 @@ object ShortsComponentPatch : BaseBytecodePatch( ShortsPivotLegacyFingerprint ) ) { + private const val BUTTON_FILTER_CLASS_DESCRIPTOR = + "$COMPONENTS_PATH/ShortsButtonFilter;" + private const val SHELF_FILTER_CLASS_DESCRIPTOR = + "$COMPONENTS_PATH/ShortsShelfFilter;" + override fun execute(context: BytecodeContext) { /** @@ -72,7 +77,7 @@ object ShortsComponentPatch : BaseBytecodePatch( /** * Dislike button */ - ShortsButtonFingerprint.result?.let { + ShortsButtonFingerprint.resultOrThrow().let { it.mutableMethod.apply { val constIndex = getWideLiteralInstructionIndex(ReelRightDislikeIcon) val constRegister = getInstruction(constIndex).registerA @@ -88,7 +93,7 @@ object ShortsComponentPatch : BaseBytecodePatch( """, ExternalLabel("hide", getInstruction(jumpIndex)) ) } - } ?: throw ShortsButtonFingerprint.exception + } /** * Info panel @@ -98,7 +103,7 @@ object ShortsComponentPatch : BaseBytecodePatch( /** * Like button */ - ShortsButtonFingerprint.result?.let { + ShortsButtonFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = getWideLiteralInstructionIndex(ReelRightLikeIcon) val insertRegister = getInstruction(insertIndex).registerA @@ -113,7 +118,7 @@ object ShortsComponentPatch : BaseBytecodePatch( """, ExternalLabel("hide", getInstruction(jumpIndex)) ) } - } ?: throw ShortsButtonFingerprint.exception + } /** * Paid promotion @@ -140,14 +145,14 @@ object ShortsComponentPatch : BaseBytecodePatch( """, ExternalLabel("hide", getInstruction(jumpIndex)) ) } - } ?: ShortsPivotFingerprint.result?.let { + } ?: ShortsPivotFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = getWideLiteralInstructionIndex(ReelPivotButton) val insertIndex = getTargetIndexReversed(targetIndex, Opcode.INVOKE_STATIC) + 1 hideButtons(insertIndex, "hideShortsPlayerPivotButton(Ljava/lang/Object;)Ljava/lang/Object;") } - } ?: throw ShortsPivotFingerprint.exception + } /** * Remix button @@ -159,8 +164,8 @@ object ShortsComponentPatch : BaseBytecodePatch( */ ShortsButtonFingerprint.hideButton(ReelDynShare, "hideShortsPlayerShareButton", true) - LithoFilterPatch.addFilter("$COMPONENTS_PATH/ShortsButtonFilter;") - LithoFilterPatch.addFilter("$COMPONENTS_PATH/ShortsShelfFilter;") + LithoFilterPatch.addFilter(BUTTON_FILTER_CLASS_DESCRIPTOR) + LithoFilterPatch.addFilter(SHELF_FILTER_CLASS_DESCRIPTOR) /** * Add settings @@ -183,7 +188,7 @@ object ShortsComponentPatch : BaseBytecodePatch( descriptor: String, reversed: Boolean ) { - result?.let { + resultOrThrow().let { it.mutableMethod.apply { val constIndex = getWideLiteralInstructionIndex(id) val insertIndex = if (reversed) @@ -197,21 +202,21 @@ object ShortsComponentPatch : BaseBytecodePatch( "invoke-static {v$insertRegister}, $SHORTS_CLASS_DESCRIPTOR->$descriptor(Landroid/view/View;)V" ) } - } ?: throw exception + } } private fun MethodFingerprint.hideButtons( id: Long, descriptor: String ) { - result?.let { + resultOrThrow().let { it.mutableMethod.apply { val constIndex = getWideLiteralInstructionIndex(id) val insertIndex = getTargetIndex(constIndex, Opcode.CHECK_CAST) hideButtons(insertIndex, descriptor) } - } ?: throw exception + } } private fun MutableMethod.hideButtons( diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsNavigationBarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsNavigationBarPatch.kt index c329dfc8f..b4594a63b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsNavigationBarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsNavigationBarPatch.kt @@ -5,14 +5,14 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.youtube.shorts.components.fingerprints.BottomNavigationBarFingerprint import app.revanced.patches.youtube.shorts.components.fingerprints.RenderBottomNavigationBarFingerprint import app.revanced.patches.youtube.shorts.components.fingerprints.SetPivotBarFingerprint import app.revanced.patches.youtube.utils.fingerprints.PivotBarCreateButtonViewFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.SHORTS_CLASS_DESCRIPTOR -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithMethodReferenceName +import app.revanced.util.getWalkerMethod +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction object ShortsNavigationBarPatch : BytecodePatch( @@ -24,8 +24,8 @@ object ShortsNavigationBarPatch : BytecodePatch( ) { override fun execute(context: BytecodeContext) { - PivotBarCreateButtonViewFingerprint.result?.let { parentResult -> - SetPivotBarFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let { + PivotBarCreateButtonViewFingerprint.resultOrThrow().let { parentResult -> + SetPivotBarFingerprint.also { it.resolve(context, parentResult.classDef) }.resultOrThrow().let { it.mutableMethod.apply { val startIndex = it.scanResult.patternScanResult!!.startIndex val register = getInstruction(startIndex).registerA @@ -35,22 +35,19 @@ object ShortsNavigationBarPatch : BytecodePatch( "sput-object v$register, $SHORTS_CLASS_DESCRIPTOR->pivotBar:Ljava/lang/Object;" ) } - } ?: throw SetPivotBarFingerprint.exception - } ?: throw PivotBarCreateButtonViewFingerprint.exception + } + } - RenderBottomNavigationBarFingerprint.result?.let { - val targetMethod = context - .toMethodWalker(it.method) - .nextMethod(it.scanResult.patternScanResult!!.startIndex + 1, true) - .getMethod() as MutableMethod + RenderBottomNavigationBarFingerprint.resultOrThrow().let { + val walkerMethod = it.getWalkerMethod(context, it.scanResult.patternScanResult!!.startIndex + 1) - targetMethod.addInstruction( + walkerMethod.addInstruction( 0, "invoke-static {}, $SHORTS_CLASS_DESCRIPTOR->hideShortsPlayerNavigationBar()V" ) - } ?: throw RenderBottomNavigationBarFingerprint.exception + } - BottomNavigationBarFingerprint.result?.let { + BottomNavigationBarFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = getTargetIndexWithMethodReferenceName("findViewById") + 1 val insertRegister = getInstruction(targetIndex).registerA @@ -62,7 +59,7 @@ object ShortsNavigationBarPatch : BytecodePatch( """ ) } - } ?: throw BottomNavigationBarFingerprint.exception + } } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsSubscriptionsButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsSubscriptionsButtonPatch.kt index 0602532ab..28b1ec8dd 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsSubscriptionsButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsSubscriptionsButtonPatch.kt @@ -13,8 +13,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.SHORTS_CLASS_DE import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelPlayerFooter import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelPlayerPausedStateButton import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getWideLiteralInstructionIndex +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -28,8 +28,10 @@ object ShortsSubscriptionsButtonPatch : BytecodePatch( ShortsSubscriptionsTabletParentFingerprint ) ) { + private lateinit var subscriptionFieldReference: FieldReference + override fun execute(context: BytecodeContext) { - ShortsSubscriptionsFingerprint.result?.let { + ShortsSubscriptionsFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = getWideLiteralInstructionIndex(ReelPlayerPausedStateButton) + 2 val insertRegister = getInstruction(insertIndex).registerA @@ -39,17 +41,15 @@ object ShortsSubscriptionsButtonPatch : BytecodePatch( "invoke-static {v$insertRegister}, $SHORTS_CLASS_DESCRIPTOR->hideShortsPlayerSubscriptionsButton(Landroid/view/View;)V" ) } - } ?: throw ShortsSubscriptionsFingerprint.exception + } /** * Deprecated in YouTube v18.31.xx+ */ if (!SettingsPatch.upward1831) { - ShortsSubscriptionsTabletParentFingerprint.result?.let { parentResult -> + ShortsSubscriptionsTabletParentFingerprint.resultOrThrow().let { parentResult -> parentResult.mutableMethod.apply { val targetIndex = getWideLiteralInstructionIndex(ReelPlayerFooter) - 1 - if (getInstruction(targetIndex).opcode != Opcode.IPUT) - throw ShortsSubscriptionsTabletFingerprint.exception subscriptionFieldReference = (getInstruction(targetIndex)).reference as FieldReference } @@ -59,28 +59,25 @@ object ShortsSubscriptionsButtonPatch : BytecodePatch( context, parentResult.classDef ) - }.result?.mutableMethod?.let { - with(it.implementation!!.instructions) { - filter { instruction -> - val fieldReference = - (instruction as? ReferenceInstruction)?.reference as? FieldReference - instruction.opcode == Opcode.IGET && fieldReference == subscriptionFieldReference - }.forEach { instruction -> - val insertIndex = indexOf(instruction) + 1 - val register = (instruction as TwoRegisterInstruction).registerA + }.resultOrThrow().mutableMethod.apply { + implementation!!.instructions.filter { instruction -> + val fieldReference = + (instruction as? ReferenceInstruction)?.reference as? FieldReference + instruction.opcode == Opcode.IGET + && fieldReference == subscriptionFieldReference + }.forEach { instruction -> + val insertIndex = implementation!!.instructions.indexOf(instruction) + 1 + val register = (instruction as TwoRegisterInstruction).registerA - it.addInstructions( - insertIndex, """ + addInstructions( + insertIndex, """ invoke-static {v$register}, $SHORTS_CLASS_DESCRIPTOR->hideShortsPlayerSubscriptionsButton(I)I move-result v$register """ - ) - } + ) } - } ?: throw ShortsSubscriptionsTabletFingerprint.exception - } ?: throw ShortsSubscriptionsTabletParentFingerprint.exception + } + } } } - - private lateinit var subscriptionFieldReference: FieldReference } diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsToolBarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsToolBarPatch.kt index db2f0554d..4a07c7327 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsToolBarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsToolBarPatch.kt @@ -5,25 +5,22 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWith import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotation.Patch -import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.youtube.shorts.components.fingerprints.ToolBarBannerFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.SHORTS_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.toolbar.ToolBarHookPatch -import app.revanced.util.exception +import app.revanced.util.getWalkerMethod +import app.revanced.util.resultOrThrow @Patch(dependencies = [ToolBarHookPatch::class]) object ShortsToolBarPatch : BytecodePatch( setOf(ToolBarBannerFingerprint) ) { override fun execute(context: BytecodeContext) { - ToolBarBannerFingerprint.result?.let { - val targetMethod = context - .toMethodWalker(it.method) - .nextMethod(it.scanResult.patternScanResult!!.endIndex, true) - .getMethod() as MutableMethod + ToolBarBannerFingerprint.resultOrThrow().let { + val walkerMethod = it.getWalkerMethod(context, it.scanResult.patternScanResult!!.endIndex) - targetMethod.apply { + walkerMethod.apply { addInstructionsWithLabels( 0, """ @@ -34,7 +31,7 @@ object ShortsToolBarPatch : BytecodePatch( ExternalLabel("hide", getInstruction(implementation!!.instructions.size - 1)) ) } - } ?: throw ToolBarBannerFingerprint.exception + } ToolBarHookPatch.injectCall("$SHORTS_CLASS_DESCRIPTOR->hideShortsToolBarButton") } diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/repeat/ShortsRepeatPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/repeat/ShortsRepeatPatch.kt index 07422c47c..df8ae200a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/shorts/repeat/ShortsRepeatPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/repeat/ShortsRepeatPatch.kt @@ -13,11 +13,11 @@ import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch.contexts import app.revanced.util.containsReferenceInstructionIndex import app.revanced.util.copyXmlNode -import app.revanced.util.exception import app.revanced.util.findMutableMethodOf import app.revanced.util.getStringInstructionIndex import app.revanced.util.getTargetIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -32,7 +32,7 @@ object ShortsRepeatPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - ReelEnumConstructorFingerprint.result?.let { + ReelEnumConstructorFingerprint.resultOrThrow().let { it.mutableMethod.apply { ReelEnumStaticFingerprint.resolve(context, it.mutableClass) @@ -48,14 +48,12 @@ object ShortsRepeatPatch : BaseBytecodePatch( val endScreenReferenceIndex = getTargetIndex(endScreenStringIndex, Opcode.SPUT_OBJECT) val endScreenReference = getInstruction(endScreenReferenceIndex).reference.toString() - val enumMethodName = ReelEnumStaticFingerprint.result?.mutableMethod?.name - ?: throw ReelEnumStaticFingerprint.exception - + val enumMethodName = ReelEnumStaticFingerprint.resultOrThrow().mutableMethod.name val enumMethodCall = "$definingClass->$enumMethodName(I)$definingClass" context.injectHook(endScreenReference, enumMethodCall) } - } ?: throw ReelEnumConstructorFingerprint.exception + } /** * Copy arrays diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/startupshortsreset/ResumingShortsOnStartupPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/startupshortsreset/ResumingShortsOnStartupPatch.kt index 32871582e..adafb3fd2 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/shorts/startupshortsreset/ResumingShortsOnStartupPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/startupshortsreset/ResumingShortsOnStartupPatch.kt @@ -11,12 +11,12 @@ import app.revanced.patches.youtube.shorts.startupshortsreset.fingerprints.UserW import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.integrations.Constants.SHORTS_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getStringInstructionIndex import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexReversed import app.revanced.util.getWalkerMethod import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @@ -34,7 +34,7 @@ object ResumingShortsOnStartupPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - UserWasInShortsABConfigFingerprint.result?.let { + UserWasInShortsABConfigFingerprint.resultOrThrow().let { val walkerMethod = it.getWalkerMethod(context, it.scanResult.patternScanResult!!.startIndex) // This method will only be called for the user being A/B tested. @@ -53,9 +53,9 @@ object ResumingShortsOnStartupPatch : BaseBytecodePatch( """, ExternalLabel("show", getInstruction(insertIndex)) ) } - } ?: throw UserWasInShortsABConfigFingerprint.exception + } - UserWasInShortsFingerprint.result?.let { + UserWasInShortsFingerprint.resultOrThrow().let { it.mutableMethod.apply { val startIndex = getStringInstructionIndex("Failed to read user_was_in_shorts proto after successful warmup") val exceptionIndex = getTargetIndexReversed(startIndex, Opcode.RETURN_VOID) - 1 @@ -79,7 +79,7 @@ object ResumingShortsOnStartupPatch : BaseBytecodePatch( ) removeInstruction(targetIndex) } - } ?: throw UserWasInShortsFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/swipe/controls/SwipeControlsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/swipe/controls/SwipeControlsPatch.kt index 5eb8a21b1..2fddb8448 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/swipe/controls/SwipeControlsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/swipe/controls/SwipeControlsPatch.kt @@ -21,9 +21,9 @@ import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch.contexts import app.revanced.util.ResourceGroup import app.revanced.util.copyResources -import app.revanced.util.exception import app.revanced.util.getWideLiteralInstructionIndex import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import app.revanced.util.transformMethods import app.revanced.util.traverseClassHierarchy import com.android.tools.smali.dexlib2.AccessFlags @@ -52,8 +52,7 @@ object SwipeControlsPatch : BaseBytecodePatch( "$SWIPE_PATH/SwipeControlsPatch;" override fun execute(context: BytecodeContext) { - val wrapperClass = SwipeControlsHostActivityFingerprint.result?.mutableClass - ?: throw SwipeControlsHostActivityFingerprint.exception + val wrapperClass = SwipeControlsHostActivityFingerprint.resultOrThrow().mutableClass val targetClass = mainActivityMutableClass // inject the wrapper class from integrations into the class hierarchy of MainActivity (WatchWhileActivity) @@ -77,7 +76,7 @@ object SwipeControlsPatch : BaseBytecodePatch( } } - FullScreenEngagementOverlayFingerprint.result?.let { + FullScreenEngagementOverlayFingerprint.resultOrThrow().let { it.mutableMethod.apply { val viewIndex = getWideLiteralInstructionIndex(FullScreenEngagementOverlay) + 3 val viewRegister = getInstruction(viewIndex).registerA @@ -87,7 +86,7 @@ object SwipeControlsPatch : BaseBytecodePatch( "sput-object v$viewRegister, $INTEGRATIONS_CLASS_DESCRIPTOR->engagementOverlay:Landroid/view/View;" ) } - } ?: throw FullScreenEngagementOverlayFingerprint.exception + } HDRBrightnessFingerprint.result?.let { it.mutableMethod.apply { 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 9f607068a..c40d1f769 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 @@ -12,9 +12,9 @@ import app.revanced.patches.shared.litho.fingerprints.PathBuilderFingerprint import app.revanced.patches.youtube.utils.browseid.fingerprints.BrowseIdClassFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch -import app.revanced.util.exception import app.revanced.util.getStringInstructionIndex import app.revanced.util.getTargetIndex +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.reference.FieldReference @@ -40,7 +40,7 @@ object BrowseIdHookPatch : BytecodePatch( * This class handles BrowseId. * Pass an instance of this class to integrations to use Java Reflection. */ - BrowseIdClassFingerprint.result?.let { + BrowseIdClassFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = getStringInstructionIndex("VL") - 1 val targetReference = getInstruction(targetIndex).reference @@ -60,18 +60,18 @@ object BrowseIdHookPatch : BytecodePatch( ) } ?: throw PatchException("BrowseIdClass not found!") } - } ?: throw BrowseIdClassFingerprint.exception + } /** * Set BrowseId to integrations. */ - PathBuilderFingerprint.result?.let { + PathBuilderFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstruction( 0, "invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->setBrowseIdFromField()V" ) } - } ?: throw PathBuilderFingerprint.exception + } } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/fix/clientspoof/ClientSpoofPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/fix/clientspoof/ClientSpoofPatch.kt index 9e7789472..8fa655d65 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/fix/clientspoof/ClientSpoofPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/fix/clientspoof/ClientSpoofPatch.kt @@ -1,5 +1,5 @@ package app.revanced.patches.youtube.utils.fix.clientspoof -import app.revanced.patches.shared.clientspoof.AbstractClientSpoofPatch +import app.revanced.patches.shared.clientspoof.BaseClientSpoofPatch -object ClientSpoofPatch : AbstractClientSpoofPatch("com.google.android.youtube") \ No newline at end of file +object ClientSpoofPatch : BaseClientSpoofPatch("com.google.android.youtube") \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/fix/doublebacktoclose/DoubleBackToClosePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/fix/doublebacktoclose/DoubleBackToClosePatch.kt index 6e4a989c8..0803f53b1 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/fix/doublebacktoclose/DoubleBackToClosePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/fix/doublebacktoclose/DoubleBackToClosePatch.kt @@ -10,8 +10,8 @@ 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.util.exception import app.revanced.util.getWalkerMethod +import app.revanced.util.resultOrThrow @Patch(dependencies = [MainActivityResolvePatch::class]) object DoubleBackToClosePatch : BytecodePatch( @@ -34,24 +34,24 @@ object DoubleBackToClosePatch : BytecodePatch( /** * Inject the methods which start of ScrollView */ - ScrollPositionFingerprint.result?.let { + ScrollPositionFingerprint.resultOrThrow().let { val walkerMethod = it.getWalkerMethod(context, it.scanResult.patternScanResult!!.startIndex + 1) val insertIndex = walkerMethod.implementation!!.instructions.size - 1 - 1 walkerMethod.injectScrollView(insertIndex, "onStartScrollView") - } ?: throw ScrollPositionFingerprint.exception + } /** * Inject the methods which stop of ScrollView */ - ScrollTopParentFingerprint.result?.let { parentResult -> - ScrollTopFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let { + ScrollTopParentFingerprint.resultOrThrow().let { parentResult -> + ScrollTopFingerprint.also { it.resolve(context, parentResult.classDef) }.resultOrThrow().let { val insertIndex = it.scanResult.patternScanResult!!.endIndex it.mutableMethod.injectScrollView(insertIndex, "onStopScrollView") - } ?: throw ScrollTopFingerprint.exception - } ?: throw ScrollTopParentFingerprint.exception + } + } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/fix/parameter/SpoofPlayerParameterPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/fix/parameter/SpoofPlayerParameterPatch.kt index 6b95feb31..1a5cffbe5 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/fix/parameter/SpoofPlayerParameterPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/fix/parameter/SpoofPlayerParameterPatch.kt @@ -23,8 +23,8 @@ import app.revanced.patches.youtube.utils.playerresponse.PlayerResponsePatch import app.revanced.patches.youtube.utils.playertype.PlayerTypeHookPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.videoid.general.VideoIdPatch -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -65,13 +65,13 @@ object SpoofPlayerParameterPatch : BaseBytecodePatch( // Force the seekbar time and chapters to always show up. // This is used if the storyboard spec fetch fails, for viewing paid videos, // or if storyboard spoofing is turned off. - StoryboardThumbnailParentFingerprint.result?.classDef?.let { classDef -> + StoryboardThumbnailParentFingerprint.resultOrThrow().classDef.let { classDef -> StoryboardThumbnailFingerprint.also { it.resolve( context, classDef ) - }.result?.let { + }.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = it.scanResult.patternScanResult!!.endIndex val targetRegister = @@ -81,22 +81,22 @@ object SpoofPlayerParameterPatch : BaseBytecodePatch( addInstructions( targetIndex + 1, """ - invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->getSeekbarThumbnailOverrideValue()Z - move-result v$targetRegister - return v$targetRegister - """ + invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->getSeekbarThumbnailOverrideValue()Z + move-result v$targetRegister + return v$targetRegister + """ ) removeInstruction(targetIndex) } - } ?: throw StoryboardThumbnailFingerprint.exception - } ?: throw StoryboardThumbnailParentFingerprint.exception + } + } // Hook storyboard renderer url. arrayOf( PlayerResponseModelGeneralStoryboardRendererFingerprint, PlayerResponseModelLiveStreamStoryboardRendererFingerprint ).forEach { fingerprint -> - fingerprint.result?.let { + fingerprint.resultOrThrow().let { it.mutableMethod.apply { val getStoryboardIndex = it.scanResult.patternScanResult!!.endIndex val getStoryboardRegister = @@ -110,11 +110,11 @@ object SpoofPlayerParameterPatch : BaseBytecodePatch( """ ) } - } ?: throw fingerprint.exception + } } // Hook recommended seekbar thumbnails quality level. - StoryboardRendererDecoderRecommendedLevelFingerprint.result?.let { + StoryboardRendererDecoderRecommendedLevelFingerprint.resultOrThrow().let { it.mutableMethod.apply { val moveOriginalRecommendedValueIndex = it.scanResult.patternScanResult!!.endIndex val originalValueRegister = @@ -127,10 +127,10 @@ object SpoofPlayerParameterPatch : BaseBytecodePatch( """ ) } - } ?: throw StoryboardRendererDecoderRecommendedLevelFingerprint.exception + } // Hook the recommended precise seeking thumbnails quality level. - PlayerResponseModelStoryboardRecommendedLevelFingerprint.result?.let { + PlayerResponseModelStoryboardRecommendedLevelFingerprint.resultOrThrow().let { it.mutableMethod.apply { val moveOriginalRecommendedValueIndex = it.scanResult.patternScanResult!!.endIndex val originalValueRegister = @@ -143,9 +143,9 @@ object SpoofPlayerParameterPatch : BaseBytecodePatch( """ ) } - } ?: throw PlayerResponseModelStoryboardRecommendedLevelFingerprint.exception + } - StoryboardRendererSpecFingerprint.result?.let { + StoryboardRendererSpecFingerprint.resultOrThrow().let { it.mutableMethod.apply { val storyBoardUrlParams = 0 @@ -157,10 +157,10 @@ object SpoofPlayerParameterPatch : BaseBytecodePatch( """, ExternalLabel("ignore", getInstruction(0)) ) } - } ?: throw StoryboardRendererSpecFingerprint.exception + } // Hook the seekbar thumbnail decoder and use a NULL spec for live streams. - StoryboardRendererDecoderSpecFingerprint.result?.let { + StoryboardRendererDecoderSpecFingerprint.resultOrThrow().let { val storyBoardUrlIndex = it.scanResult.patternScanResult!!.startIndex + 1 val storyboardUrlRegister = it.mutableMethod.getInstruction(storyBoardUrlIndex).registerA @@ -171,16 +171,15 @@ object SpoofPlayerParameterPatch : BaseBytecodePatch( move-result-object v$storyboardUrlRegister """ ) - } ?: throw StoryboardRendererDecoderSpecFingerprint.exception + } // Fix stats not being tracked. // Due to signature spoofing "adformat" is present in query parameters made for /stats requests, // even though, for regular videos, it should not be. // This breaks stats tracking. // Replace the ad parameter with the video parameter in the query parameters. - StatsQueryParameterFingerprint.result?.let { - val putMethod = ParamsMapPutFingerprint.result?.method?.toString() - ?: throw ParamsMapPutFingerprint.exception + StatsQueryParameterFingerprint.resultOrThrow().let { + val putMethod = ParamsMapPutFingerprint.resultOrThrow().method.toString() it.mutableMethod.apply { val adParamIndex = it.scanResult.stringsScanResult!!.matches.first().index @@ -202,7 +201,7 @@ object SpoofPlayerParameterPatch : BaseBytecodePatch( putMethod, ) } - } ?: throw StatsQueryParameterFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/fix/swiperefresh/SwipeRefreshPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/fix/swiperefresh/SwipeRefreshPatch.kt index 60fecba57..364f8ea88 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/fix/swiperefresh/SwipeRefreshPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/fix/swiperefresh/SwipeRefreshPatch.kt @@ -5,7 +5,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patches.youtube.utils.fix.swiperefresh.fingerprint.SwipeRefreshLayoutFingerprint -import app.revanced.util.exception +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction object SwipeRefreshPatch : BytecodePatch( @@ -13,7 +13,7 @@ object SwipeRefreshPatch : BytecodePatch( ) { override fun execute(context: BytecodeContext) { - SwipeRefreshLayoutFingerprint.result?.let { + SwipeRefreshLayoutFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.endIndex val register = getInstruction(insertIndex).registerA @@ -23,7 +23,7 @@ object SwipeRefreshPatch : BytecodePatch( "const/4 v$register, 0x0" ) } - } ?: throw SwipeRefreshLayoutFingerprint.exception + } } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/lockmodestate/LockModeStateHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/lockmodestate/LockModeStateHookPatch.kt index 23a43c9c6..48a325eb3 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/lockmodestate/LockModeStateHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/lockmodestate/LockModeStateHookPatch.kt @@ -7,7 +7,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH import app.revanced.patches.youtube.utils.lockmodestate.fingerprint.LockModeStateFingerprint -import app.revanced.util.exception +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction object LockModeStateHookPatch : BytecodePatch( @@ -15,7 +15,7 @@ object LockModeStateHookPatch : BytecodePatch( ) { override fun execute(context: BytecodeContext) { - LockModeStateFingerprint.result?.let { + LockModeStateFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.endIndex val insertRegister = getInstruction(insertIndex).registerA @@ -28,7 +28,7 @@ object LockModeStateHookPatch : BytecodePatch( ) removeInstruction(insertIndex) } - } ?: throw LockModeStateFingerprint.exception + } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/mainactivity/MainActivityResolvePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/mainactivity/MainActivityResolvePatch.kt index 9e773f190..6f6dadc5f 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/mainactivity/MainActivityResolvePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/mainactivity/MainActivityResolvePatch.kt @@ -7,8 +7,8 @@ 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.mainactivity.fingerprints.MainActivityFingerprint -import app.revanced.util.exception import app.revanced.util.getTargetIndex +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.util.MethodUtil import kotlin.properties.Delegates @@ -24,8 +24,7 @@ object MainActivityResolvePatch : BytecodePatch( private var onBackPressedMethodIndex by Delegates.notNull() override fun execute(context: BytecodeContext) { - val mainActivityResult = MainActivityFingerprint.result - ?: throw MainActivityFingerprint.exception + val mainActivityResult = MainActivityFingerprint.resultOrThrow() onCreateMethod = mainActivityResult.mutableMethod mainActivityMutableClass = mainActivityResult.mutableClass diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/navbarindex/NavBarIndexHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/navbarindex/NavBarIndexHookPatch.kt index 9d612057b..3a42af7cd 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/navbarindex/NavBarIndexHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/navbarindex/NavBarIndexHookPatch.kt @@ -10,7 +10,7 @@ import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH import app.revanced.patches.youtube.utils.navbarindex.fingerprints.MobileTopBarButtonOnClickFingerprint import app.revanced.patches.youtube.utils.navbarindex.fingerprints.PivotBarIndexFingerprint import app.revanced.patches.youtube.utils.navbarindex.fingerprints.SettingsActivityOnBackPressedFingerprint -import app.revanced.util.exception +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction @Suppress("unused") @@ -29,7 +29,7 @@ object NavBarIndexHookPatch : BytecodePatch( /** * Change NavBar Index value according to selected Tab. */ - PivotBarIndexFingerprint.result?.let { + PivotBarIndexFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.startIndex + 1 val booleanRegister = getInstruction(insertIndex).registerD @@ -44,7 +44,7 @@ object NavBarIndexHookPatch : BytecodePatch( "move/16 v$freeRegister, p1" ) } - } ?: throw PivotBarIndexFingerprint.exception + } /** * Since it is used only after opening the library tab, set index to 4. @@ -58,7 +58,7 @@ object NavBarIndexHookPatch : BytecodePatch( } private fun MethodFingerprint.injectIndex() { - result?.let { + resultOrThrow().let { it.mutableMethod.apply { addInstructions( 0, """ @@ -67,6 +67,6 @@ object NavBarIndexHookPatch : BytecodePatch( """ ) } - } ?: throw exception + } } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/overridequality/OverrideQualityHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/overridequality/OverrideQualityHookPatch.kt index 1f7ea5a6d..194416de3 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/overridequality/OverrideQualityHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/overridequality/OverrideQualityHookPatch.kt @@ -16,8 +16,8 @@ import app.revanced.patches.youtube.utils.overridequality.fingerprints.VideoQual import app.revanced.patches.youtube.utils.overridequality.fingerprints.VideoQualityTextFingerprint import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.QualityAuto -import app.revanced.util.exception import app.revanced.util.getWideLiteralInstructionIndex +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -44,7 +44,7 @@ object OverrideQualityHookPatch : BytecodePatch( override fun execute(context: BytecodeContext) { - VideoQualityListFingerprint.result?.let { + VideoQualityListFingerprint.resultOrThrow().let { val constructorMethod = it.mutableClass.methods.first { method -> MethodUtil.isConstructor(method) } val overrideMethod = @@ -79,9 +79,9 @@ object OverrideQualityHookPatch : BytecodePatch( "sput-object v$qualityAutoRegister, $INTEGRATIONS_VIDEO_UTILS_CLASS_DESCRIPTOR->qualityAutoString:Ljava/lang/String;" ) } - } ?: throw VideoQualityListFingerprint.exception + } - VideoQualityPatchFingerprint.result?.let { + VideoQualityPatchFingerprint.resultOrThrow().let { it.mutableMethod.apply { it.mutableClass.staticFields.add( ImmutableField( @@ -102,9 +102,9 @@ object OverrideQualityHookPatch : BytecodePatch( """ ) } - } ?: throw VideoQualityPatchFingerprint.exception + } - VideoQualityTextFingerprint.result?.let { + VideoQualityTextFingerprint.resultOrThrow().let { it.mutableMethod.apply { val textIndex = it.scanResult.patternScanResult!!.endIndex val textRegister = getInstruction(textIndex).registerA @@ -114,6 +114,6 @@ object OverrideQualityHookPatch : BytecodePatch( "sput-object v$textRegister, $INTEGRATIONS_VIDEO_UTILS_CLASS_DESCRIPTOR->currentQuality:Ljava/lang/String;" ) } - } ?: throw VideoQualityTextFingerprint.exception + } } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/overridespeed/OverrideSpeedHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/overridespeed/OverrideSpeedHookPatch.kt index 286e96c10..926364caa 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/overridespeed/OverrideSpeedHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/overridespeed/OverrideSpeedHookPatch.kt @@ -9,7 +9,6 @@ import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.MethodFingerprintResult import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable -import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable import app.revanced.patcher.util.smali.toInstructions import app.revanced.patches.youtube.utils.integrations.Constants.INTEGRATIONS_PATH @@ -18,7 +17,8 @@ import app.revanced.patches.youtube.utils.overridespeed.fingerprints.PlaybackSpe import app.revanced.patches.youtube.utils.overridespeed.fingerprints.PlaybackSpeedParentFingerprint import app.revanced.patches.youtube.utils.overridespeed.fingerprints.PlaybackSpeedPatchFingerprint import app.revanced.patches.youtube.utils.overridespeed.fingerprints.SpeedClassFingerprint -import app.revanced.util.exception +import app.revanced.util.getWalkerMethod +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -46,7 +46,7 @@ object OverrideSpeedHookPatch : BytecodePatch( private lateinit var objectClass: String override fun execute(context: BytecodeContext) { - PlaybackSpeedParentFingerprint.result?.let { parentResult -> + PlaybackSpeedParentFingerprint.resultOrThrow().let { parentResult -> val parentClassDef = parentResult.classDef PlaybackSpeedChangedFingerprint.also { @@ -54,7 +54,7 @@ object OverrideSpeedHookPatch : BytecodePatch( context, parentClassDef ) - }.result?.let { + }.resultOrThrow().let { it.mutableMethod.apply { playbackSpeedChangedResult = it val startIndex = it.scanResult.patternScanResult!!.startIndex @@ -92,12 +92,9 @@ object OverrideSpeedHookPatch : BytecodePatch( ).toMutable() ) - with( - context - .toMethodWalker(this) - .nextMethod(endIndex, true) - .getMethod() as MutableMethod - ) { + val walkerMethod = getWalkerMethod(context, endIndex) + + walkerMethod.apply { addInstruction( this.implementation!!.instructions.size - 1, "sput p1, $INTEGRATIONS_VIDEO_UTILS_CLASS_DESCRIPTOR->currentSpeed:F" @@ -105,11 +102,11 @@ object OverrideSpeedHookPatch : BytecodePatch( } } - } ?: throw PlaybackSpeedChangedFingerprint.exception - } ?: throw PlaybackSpeedParentFingerprint.exception + } + } - SpeedClassFingerprint.result?.let { + SpeedClassFingerprint.resultOrThrow().let { it.mutableMethod.apply { val index = it.scanResult.patternScanResult!!.endIndex val register = getInstruction(index).registerA @@ -123,10 +120,9 @@ object OverrideSpeedHookPatch : BytecodePatch( "return-object v$register" ) } + } - } ?: throw SpeedClassFingerprint.exception - - PlaybackSpeedPatchFingerprint.result?.let { + PlaybackSpeedPatchFingerprint.resultOrThrow().let { it.mutableMethod.apply { it.mutableClass.staticFields.add( ImmutableField( @@ -148,7 +144,7 @@ object OverrideSpeedHookPatch : BytecodePatch( ) } - } ?: throw PlaybackSpeedPatchFingerprint.exception + } } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/playercontrols/PlayerControlsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/playercontrols/PlayerControlsPatch.kt index c9c6665f7..2e95d688a 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/playercontrols/PlayerControlsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/playercontrols/PlayerControlsPatch.kt @@ -20,9 +20,9 @@ import app.revanced.patches.youtube.utils.playercontrols.fingerprints.QuickSeekV import app.revanced.patches.youtube.utils.playercontrols.fingerprints.SeekEDUVisibleFingerprint import app.revanced.patches.youtube.utils.playercontrols.fingerprints.UserScrubbingFingerprint import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch -import app.revanced.util.exception import app.revanced.util.getStringInstructionIndex import app.revanced.util.getTargetIndexWithReference +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -44,12 +44,10 @@ object PlayerControlsPatch : BytecodePatch( override fun execute(context: BytecodeContext) { val playerControlsVisibilityModelClass = - PlayerControlsVisibilityModelFingerprint.result?.mutableClass - ?: throw PlayerControlsVisibilityModelFingerprint.exception + PlayerControlsVisibilityModelFingerprint.resultOrThrow().mutableClass val youTubeControlsOverlayClass = - YouTubeControlsOverlayFingerprint.result?.mutableClass - ?: throw YouTubeControlsOverlayFingerprint.exception + YouTubeControlsOverlayFingerprint.resultOrThrow().mutableClass QuickSeekVisibleFingerprint.resolve(context, playerControlsVisibilityModelClass) SeekEDUVisibleFingerprint.resolve(context, playerControlsVisibilityModelClass) @@ -57,39 +55,30 @@ object PlayerControlsPatch : BytecodePatch( PlayerControlsVisibilityFingerprint.resolve(context, youTubeControlsOverlayClass) - quickSeekVisibleMutableMethod = QuickSeekVisibleFingerprint.result?.mutableMethod - ?: throw QuickSeekVisibleFingerprint.exception + quickSeekVisibleMutableMethod = QuickSeekVisibleFingerprint.resultOrThrow().mutableMethod - seekEDUVisibleMutableMethod = SeekEDUVisibleFingerprint.result?.mutableMethod - ?: throw SeekEDUVisibleFingerprint.exception + seekEDUVisibleMutableMethod = SeekEDUVisibleFingerprint.resultOrThrow().mutableMethod - userScrubbingMutableMethod = UserScrubbingFingerprint.result?.mutableMethod - ?: throw UserScrubbingFingerprint.exception + userScrubbingMutableMethod = UserScrubbingFingerprint.resultOrThrow().mutableMethod - playerControlsVisibilityMutableMethod = PlayerControlsVisibilityFingerprint.result?.mutableMethod - ?: throw PlayerControlsVisibilityFingerprint.exception + playerControlsVisibilityMutableMethod = PlayerControlsVisibilityFingerprint.resultOrThrow().mutableMethod - controlsLayoutInflateResult = - ControlsLayoutInflateFingerprint.result - ?: throw ControlsLayoutInflateFingerprint.exception + controlsLayoutInflateResult = ControlsLayoutInflateFingerprint.resultOrThrow() - inflateResult = - BottomControlsInflateFingerprint.result - ?: throw BottomControlsInflateFingerprint.exception + inflateResult = BottomControlsInflateFingerprint.resultOrThrow() - FullscreenEngagementSpeedEduVisibleToStringFingerprint.result?.let { + FullscreenEngagementSpeedEduVisibleToStringFingerprint.resultOrThrow().let { FullscreenEngagementSpeedEduVisibleFingerprint.resolve(context, it.classDef) - fullscreenEngagementSpeedEduVisibleMutableMethod = FullscreenEngagementSpeedEduVisibleFingerprint.result?.mutableMethod - ?: throw FullscreenEngagementSpeedEduVisibleFingerprint.exception + fullscreenEngagementSpeedEduVisibleMutableMethod = FullscreenEngagementSpeedEduVisibleFingerprint.resultOrThrow().mutableMethod it.mutableMethod.apply { fullscreenEngagementViewVisibleReference = findReference(", isFullscreenEngagementViewVisible=") speedEDUVisibleReference = findReference(", isSpeedmasterEDUVisible=") } - } ?: throw FullscreenEngagementSpeedEduVisibleToStringFingerprint.exception + } - ThumbnailPreviewConfigFingerprint.result?.let { + ThumbnailPreviewConfigFingerprint.resultOrThrow().let { it.mutableMethod.apply { bigBoardsVisibilityMutableMethod = this @@ -98,7 +87,7 @@ object PlayerControlsPatch : BytecodePatch( "const/4 v0, 0x1" ) } - } ?: throw ThumbnailPreviewConfigFingerprint.exception + } } private lateinit var controlsLayoutInflateResult: MethodFingerprintResult diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/playerresponse/PlayerResponsePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/playerresponse/PlayerResponsePatch.kt index 00d34246e..ffed9f4e9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/playerresponse/PlayerResponsePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/playerresponse/PlayerResponsePatch.kt @@ -6,7 +6,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.youtube.utils.playerresponse.fingerprints.PlayerParameterBuilderFingerprint -import app.revanced.util.exception +import app.revanced.util.resultOrThrow import java.io.Closeable object PlayerResponsePatch : BytecodePatch( @@ -21,8 +21,7 @@ object PlayerResponsePatch : BytecodePatch( private lateinit var playerResponseMethod: MutableMethod override fun execute(context: BytecodeContext) { - playerResponseMethod = PlayerParameterBuilderFingerprint.result?.mutableMethod - ?: throw PlayerParameterBuilderFingerprint.exception + playerResponseMethod = PlayerParameterBuilderFingerprint.resultOrThrow().mutableMethod playerResponseMethod.apply { freeRegister = implementation!!.registerCount - parameters.size - 2 diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/PlayerTypeHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/PlayerTypeHookPatch.kt index 1387157ed..eb836cfb1 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/PlayerTypeHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/playertype/PlayerTypeHookPatch.kt @@ -11,7 +11,7 @@ import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH import app.revanced.patches.youtube.utils.playertype.fingerprint.PlayerTypeFingerprint import app.revanced.patches.youtube.utils.playertype.fingerprint.VideoStateFingerprint import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch -import app.revanced.util.exception +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @Patch(dependencies = [SharedResourceIdPatch::class]) @@ -21,24 +21,27 @@ object PlayerTypeHookPatch : BytecodePatch( YouTubeControlsOverlayFingerprint ) ) { + private const val INTEGRATIONS_CLASS_DESCRIPTOR = + "$UTILS_PATH/PlayerTypeHookPatch;" + override fun execute(context: BytecodeContext) { - PlayerTypeFingerprint.result?.let { + PlayerTypeFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstruction( 0, "invoke-static {p1}, $INTEGRATIONS_CLASS_DESCRIPTOR->setPlayerType(Ljava/lang/Enum;)V" ) } - } ?: throw PlayerTypeFingerprint.exception + } - YouTubeControlsOverlayFingerprint.result?.let { parentResult -> + YouTubeControlsOverlayFingerprint.resultOrThrow().let { parentResult -> VideoStateFingerprint.also { it.resolve( context, parentResult.classDef ) - }.result?.let { + }.resultOrThrow().let { it.mutableMethod.apply { val endIndex = it.scanResult.patternScanResult!!.endIndex val videoStateFieldName = @@ -50,11 +53,8 @@ object PlayerTypeHookPatch : BytecodePatch( """ ) } - } ?: throw VideoStateFingerprint.exception - } ?: throw YouTubeControlsOverlayFingerprint.exception + } + } } - - private const val INTEGRATIONS_CLASS_DESCRIPTOR = - "$UTILS_PATH/PlayerTypeHookPatch;" } diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/quickactions/QuickActionsHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/quickactions/QuickActionsHookPatch.kt index 09d59d2ec..c7279c677 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/quickactions/QuickActionsHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/quickactions/QuickActionsHookPatch.kt @@ -10,7 +10,7 @@ import app.revanced.patches.youtube.utils.integrations.Constants.FULLSCREEN_CLAS import app.revanced.patches.youtube.utils.quickactions.fingerprints.QuickActionsElementFingerprint import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.QuickActionsElementContainer -import app.revanced.util.exception +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.WideLiteralInstruction @@ -23,7 +23,7 @@ object QuickActionsHookPatch : BytecodePatch( private var insertRegister: Int = 0 override fun execute(context: BytecodeContext) { - QuickActionsElementFingerprint.result?.let { + QuickActionsElementFingerprint.resultOrThrow().let { it.mutableMethod.apply { insertMethod = this val containerCalls = implementation!!.instructions.withIndex() @@ -40,15 +40,13 @@ object QuickActionsHookPatch : BytecodePatch( ) insertIndex = constIndex + 5 } - } ?: throw QuickActionsElementFingerprint.exception + } } internal fun injectQuickActionMargin() { - insertMethod.apply { - addInstruction( - insertIndex, - "invoke-static {v$insertRegister}, $FULLSCREEN_CLASS_DESCRIPTOR->setQuickActionMargin(Landroid/widget/FrameLayout;)V" - ) - } + insertMethod.addInstruction( + insertIndex, + "invoke-static {v$insertRegister}, $FULLSCREEN_CLASS_DESCRIPTOR->setQuickActionMargin(Landroid/widget/FrameLayout;)V" + ) } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/recyclerview/BottomSheetRecyclerViewPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/recyclerview/BottomSheetRecyclerViewPatch.kt index 3dc49e9fb..47cad01e1 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/recyclerview/BottomSheetRecyclerViewPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/recyclerview/BottomSheetRecyclerViewPatch.kt @@ -7,8 +7,8 @@ import app.revanced.patcher.fingerprint.MethodFingerprintResult import app.revanced.patcher.patch.BytecodePatch import app.revanced.patches.youtube.utils.recyclerview.fingerprints.BottomSheetRecyclerViewBuilderFingerprint import app.revanced.patches.youtube.utils.recyclerview.fingerprints.RecyclerViewTreeObserverFingerprint -import app.revanced.util.exception import app.revanced.util.getWideLiteralInstructionIndex +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction object BottomSheetRecyclerViewPatch : BytecodePatch( @@ -37,10 +37,9 @@ object BottomSheetRecyclerViewPatch : BytecodePatch( "const/4 v$targetRegister, 0x1" ) } - } ?: throw BottomSheetRecyclerViewBuilderFingerprint.exception + } - recyclerViewTreeObserverResult = RecyclerViewTreeObserverFingerprint.result - ?: throw RecyclerViewTreeObserverFingerprint.exception + recyclerViewTreeObserverResult = RecyclerViewTreeObserverFingerprint.resultOrThrow() } diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/returnyoutubedislike/general/ReturnYouTubeDislikePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/returnyoutubedislike/general/ReturnYouTubeDislikePatch.kt index 21bb527ad..c84fa61d2 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/returnyoutubedislike/general/ReturnYouTubeDislikePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/returnyoutubedislike/general/ReturnYouTubeDislikePatch.kt @@ -18,9 +18,9 @@ import app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.Ret import app.revanced.patches.youtube.utils.returnyoutubedislike.shorts.ReturnYouTubeDislikeShortsPatch import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.videoid.general.VideoIdPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndexWithFieldReferenceType import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @@ -56,23 +56,20 @@ object ReturnYouTubeDislikePatch : BaseBytecodePatch( DislikeFingerprint.toPatch(Vote.DISLIKE), RemoveLikeFingerprint.toPatch(Vote.REMOVE_LIKE) ).forEach { (fingerprint, vote) -> - with(fingerprint.result ?: throw fingerprint.exception) { - mutableMethod.addInstructions( - 0, - """ + fingerprint.resultOrThrow().mutableMethod.addInstructions( + 0, """ const/4 v0, ${vote.value} invoke-static {v0}, $INTEGRATIONS_RYD_CLASS_DESCRIPTOR->sendVote(I)V """ - ) - } + ) } - TextComponentConstructorFingerprint.result?.let { parentResult -> + TextComponentConstructorFingerprint.resultOrThrow().let { parentResult -> // Resolves fingerprints TextComponentContextFingerprint.resolve(context, parentResult.classDef) - TextComponentContextFingerprint.result?.let { + TextComponentContextFingerprint.resultOrThrow().let { it.mutableMethod.apply { val conversionContextFieldIndex = getTargetIndexWithFieldReferenceType("Ljava/util/Map;") - 1 val conversionContextFieldReference = @@ -91,8 +88,8 @@ object ReturnYouTubeDislikePatch : BaseBytecodePatch( """ ) } - } ?: throw TextComponentContextFingerprint.exception - } ?: throw TextComponentConstructorFingerprint.exception + } + } VideoIdPatch.injectCall("$INTEGRATIONS_RYD_CLASS_DESCRIPTOR->newVideoLoaded(Ljava/lang/String;)V") VideoIdPatch.injectPlayerResponseVideoId("$INTEGRATIONS_RYD_CLASS_DESCRIPTOR->preloadVideoId(Ljava/lang/String;Z)V") diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/returnyoutubedislike/rollingnumber/ReturnYouTubeDislikeRollingNumberPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/returnyoutubedislike/rollingnumber/ReturnYouTubeDislikeRollingNumberPatch.kt index 684410774..d1d594b14 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/returnyoutubedislike/rollingnumber/ReturnYouTubeDislikeRollingNumberPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/returnyoutubedislike/rollingnumber/ReturnYouTubeDislikeRollingNumberPatch.kt @@ -17,9 +17,9 @@ import app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.fin import app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.fingerprints.RollingNumberTextViewAnimationUpdateFingerprint import app.revanced.patches.youtube.utils.returnyoutubedislike.rollingnumber.fingerprints.RollingNumberTextViewFingerprint import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexWithMethodReferenceName +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction21c import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction @@ -50,7 +50,7 @@ object ReturnYouTubeDislikeRollingNumberPatch : BytecodePatch( */ if (SettingsPatch.upward1849) { - RollingNumberSetterFingerprint.result?.let { + RollingNumberSetterFingerprint.resultOrThrow().let { it.mutableMethod.apply { val rollingNumberClassIndex = it.scanResult.patternScanResult!!.startIndex val rollingNumberClassReference = @@ -87,11 +87,11 @@ object ReturnYouTubeDislikeRollingNumberPatch : BytecodePatch( """ ) } - } ?: throw RollingNumberSetterFingerprint.exception + } // Rolling Number text views use the measured width of the raw string for layout. // Modify the measure text calculation to include the left drawable separator if needed. - RollingNumberMeasureAnimatedTextFingerprint.result?.let { + RollingNumberMeasureAnimatedTextFingerprint.resultOrThrow().let { it.mutableMethod.apply { val endIndex = it.scanResult.patternScanResult!!.endIndex val measuredTextWidthIndex = endIndex - 2 @@ -115,31 +115,31 @@ object ReturnYouTubeDislikeRollingNumberPatch : BytecodePatch( """, ExternalLabel("jump", getInstruction(endIndex)) ) } - } ?: throw RollingNumberMeasureAnimatedTextFingerprint.exception + } - RollingNumberMeasureTextParentFingerprint.result?.classDef?.let { parentClassDef -> + RollingNumberMeasureTextParentFingerprint.resultOrThrow().classDef.let { parentClassDef -> RollingNumberMeasureStaticLabelFingerprint.resolve(context, parentClassDef) // Additional text measurement method. Used if YouTube decides not to animate the likes count // and sometimes used for initial video load. - RollingNumberMeasureStaticLabelFingerprint.result?.let { + RollingNumberMeasureStaticLabelFingerprint.resultOrThrow().let { it.mutableMethod.apply { val measureTextIndex = it.scanResult.patternScanResult!!.startIndex + 1 val freeRegister = getInstruction(0).registerA addInstructions( measureTextIndex + 1, """ - move-result v$freeRegister - invoke-static {p1, v$freeRegister}, $INTEGRATIONS_RYD_CLASS_DESCRIPTOR->onRollingNumberMeasured(Ljava/lang/String;F)F - """ + move-result v$freeRegister + invoke-static {p1, v$freeRegister}, $INTEGRATIONS_RYD_CLASS_DESCRIPTOR->onRollingNumberMeasured(Ljava/lang/String;F)F + """ ) } - } ?: throw RollingNumberMeasureStaticLabelFingerprint.exception - } ?: throw RollingNumberMeasureTextParentFingerprint.exception + } + } // The rolling number Span is missing styling since it's initially set as a String. // Modify the UI text view and use the styled like/dislike Span. - RollingNumberTextViewFingerprint.result?.let { + RollingNumberTextViewFingerprint.resultOrThrow().let { // Initial TextView is set in this method. val initiallyCreatedTextViewMethod = it.mutableMethod @@ -168,7 +168,7 @@ object ReturnYouTubeDislikeRollingNumberPatch : BytecodePatch( ) } } - } ?: throw RollingNumberTextViewFingerprint.exception + } } } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/returnyoutubedislike/shorts/ReturnYouTubeDislikeShortsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/returnyoutubedislike/shorts/ReturnYouTubeDislikeShortsPatch.kt index 6ebdc06b5..de51dbcc2 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/returnyoutubedislike/shorts/ReturnYouTubeDislikeShortsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/returnyoutubedislike/shorts/ReturnYouTubeDislikeShortsPatch.kt @@ -14,10 +14,10 @@ import app.revanced.patches.youtube.utils.returnyoutubedislike.shorts.fingerprin import app.revanced.patches.youtube.utils.returnyoutubedislike.shorts.fingerprints.ShortsTextViewFingerprint import app.revanced.patches.youtube.utils.returnyoutubedislike.shorts.fingerprints.TextComponentSpecFingerprint import app.revanced.patches.youtube.utils.settings.SettingsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexReversed import app.revanced.util.getTargetIndexWithReference +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -35,7 +35,7 @@ object ReturnYouTubeDislikeShortsPatch : BytecodePatch( "$UTILS_PATH/ReturnYouTubeDislikePatch;" override fun execute(context: BytecodeContext) { - ShortsTextViewFingerprint.result?.let { + ShortsTextViewFingerprint.resultOrThrow().let { it.mutableMethod.apply { val startIndex = it.scanResult.patternScanResult!!.startIndex @@ -69,10 +69,10 @@ object ReturnYouTubeDislikeShortsPatch : BytecodePatch( """, ExternalLabel("ryd_disabled", getInstruction(insertIndex)) ) } - } ?: throw ShortsTextViewFingerprint.exception + } if (SettingsPatch.upward1834) { - TextComponentSpecFingerprint.result?.let { + TextComponentSpecFingerprint.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = getTargetIndexWithReference("Landroid/text/SpannableString;->valueOf(Ljava/lang/CharSequence;)Landroid/text/SpannableString;") @@ -93,16 +93,16 @@ object ReturnYouTubeDislikeShortsPatch : BytecodePatch( ) removeInstruction(insertIndex) } - } ?: throw TextComponentSpecFingerprint.exception + } - IncognitoFingerprint.result?.let { + IncognitoFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstruction( 1, "sput-boolean p4, $INTEGRATIONS_RYD_CLASS_DESCRIPTOR->isIncognito:Z" ) } - } ?: throw IncognitoFingerprint.exception + } } } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsBytecodePatch.kt index 1a8a6a658..b5629a000 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsBytecodePatch.kt @@ -13,7 +13,7 @@ import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH import app.revanced.patches.youtube.utils.mainactivity.MainActivityResolvePatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.settings.fingerprints.ThemeSetterSystemFingerprint -import app.revanced.util.exception +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Patch( @@ -38,12 +38,12 @@ object SettingsBytecodePatch : BytecodePatch( contexts = context // apply the current theme of the settings page - ThemeSetterSystemFingerprint.result?.let { + ThemeSetterSystemFingerprint.resultOrThrow().let { it.mutableMethod.apply { injectCall(implementation!!.instructions.size - 1) injectCall(it.scanResult.patternScanResult!!.startIndex) } - } ?: throw ThemeSetterSystemFingerprint.exception + } MainActivityResolvePatch.injectOnCreateMethodCall(INTEGRATIONS_INITIALIZATION_CLASS_DESCRIPTOR, "setDeviceInformation") MainActivityResolvePatch.injectOnCreateMethodCall(INTEGRATIONS_INITIALIZATION_CLASS_DESCRIPTOR, "onCreate") diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/sponsorblock/SponsorBlockBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/sponsorblock/SponsorBlockBytecodePatch.kt index 5133617c7..d49f7a2f2 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/sponsorblock/SponsorBlockBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/sponsorblock/SponsorBlockBytecodePatch.kt @@ -20,12 +20,12 @@ import app.revanced.patches.youtube.utils.sponsorblock.fingerprints.RectangleFie import app.revanced.patches.youtube.utils.sponsorblock.fingerprints.SegmentPlaybackControllerFingerprint import app.revanced.patches.youtube.utils.videoid.general.VideoIdPatch import app.revanced.patches.youtube.utils.videoid.withoutshorts.VideoIdWithoutShortsPatch -import app.revanced.util.exception import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexWithFieldReferenceTypeReversed import app.revanced.util.getTargetIndexWithMethodReferenceName import app.revanced.util.getTargetIndexWithMethodReferenceNameReversed import app.revanced.util.getWideLiteralInstructionIndex +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -73,13 +73,12 @@ object SponsorBlockBytecodePatch : BytecodePatch( ) } - val seekBarClass = SeekbarFingerprint.result?.mutableClass - ?: throw SeekbarFingerprint.exception + val seekBarClass = SeekbarFingerprint.resultOrThrow().mutableClass SeekbarOnDrawFingerprint.resolve(context, seekBarClass) RectangleFieldInvalidatorFingerprint.resolve(context, seekBarClass) - SeekbarOnDrawFingerprint.result?.mutableMethod?.apply { - // Get left and right of seekbar rectangle + SeekbarOnDrawFingerprint.resultOrThrow().mutableMethod.apply { + // Get left and right of seekbar rectangle val moveObjectIndex = getTargetIndex(Opcode.MOVE_OBJECT_FROM16) addInstruction( @@ -106,7 +105,7 @@ object SponsorBlockBytecodePatch : BytecodePatch( "invoke-static {v${drawCircleInstruction.registerC}, v${drawCircleInstruction.registerE}}, " + "$INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR->drawSponsorTimeBars(Landroid/graphics/Canvas;F)V" ) - } ?: throw SeekbarOnDrawFingerprint.exception + } // Voting & Shield button arrayOf("CreateSegmentButtonController;", "VotingButtonController;").forEach { className -> @@ -115,7 +114,7 @@ object SponsorBlockBytecodePatch : BytecodePatch( } // Append timestamp - TotalTimeFingerprint.result?.let { + TotalTimeFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = getTargetIndexWithMethodReferenceName("getString") + 1 val targetRegister = getInstruction(targetIndex).registerA @@ -127,10 +126,10 @@ object SponsorBlockBytecodePatch : BytecodePatch( """ ) } - } ?: throw TotalTimeFingerprint.exception + } // Initialize the SponsorBlock view - YouTubeControlsOverlayFingerprint.result?.let { + YouTubeControlsOverlayFingerprint.resultOrThrow().let { it.mutableMethod.apply { val targetIndex = getWideLiteralInstructionIndex(InsetOverlayViewLayout) val checkCastIndex = getTargetIndex(targetIndex, Opcode.CHECK_CAST) @@ -141,16 +140,16 @@ object SponsorBlockBytecodePatch : BytecodePatch( "invoke-static {v$targetRegister}, $INTEGRATIONS_SPONSOR_BLOCK_UI_PATH/SponsorBlockViewController;->initialize(Landroid/view/ViewGroup;)V" ) } - } ?: throw YouTubeControlsOverlayFingerprint.exception + } // Replace strings - RectangleFieldInvalidatorFingerprint.result?.let { result -> + RectangleFieldInvalidatorFingerprint.resultOrThrow().let { result -> result.mutableMethod.apply { val invalidateIndex = getTargetIndexWithMethodReferenceNameReversed("invalidate") val rectangleIndex = getTargetIndexWithFieldReferenceTypeReversed(invalidateIndex + 1, "Landroid/graphics/Rect;") val rectangleFieldName = (getInstruction(rectangleIndex).reference as FieldReference).name - SegmentPlaybackControllerFingerprint.result?.let { + SegmentPlaybackControllerFingerprint.resultOrThrow().let { it.mutableMethod.apply { val replaceIndex = it.scanResult.patternScanResult!!.startIndex val replaceRegister = @@ -161,9 +160,9 @@ object SponsorBlockBytecodePatch : BytecodePatch( "const-string v$replaceRegister, \"$rectangleFieldName\"" ) } - } ?: throw SegmentPlaybackControllerFingerprint.exception + } } - } ?: throw YouTubeControlsOverlayFingerprint.exception + } // Inject VideoIdPatch VideoIdWithoutShortsPatch.injectCall("$INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR->setCurrentVideoId(Ljava/lang/String;)V") diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/sponsorblock/SponsorBlockPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/sponsorblock/SponsorBlockPatch.kt index 6dcd19f3a..96ee047ec 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/sponsorblock/SponsorBlockPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/sponsorblock/SponsorBlockPatch.kt @@ -1,12 +1,14 @@ package app.revanced.patches.youtube.utils.sponsorblock import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.booleanPatchOption import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.util.ResourceGroup import app.revanced.util.copyResources import app.revanced.util.copyXmlNode +import app.revanced.util.inputStreamFromBundledResource import app.revanced.util.patch.BaseResourcePatch @Suppress("DEPRECATION", "unused") @@ -91,37 +93,48 @@ object SponsorBlockPatch : BaseResourcePatch( */ // copy nodes from host resources to their real xml files val hostingResourceStream = - this.javaClass.classLoader.getResourceAsStream("youtube/sponsorblock/shared/host/layout/youtube_controls_layout.xml")!! + inputStreamFromBundledResource( + "youtube/sponsorblock", + "shared/host/layout/youtube_controls_layout.xml", + )!! - val targetXmlEditor = context.xmlEditor["res/layout/youtube_controls_layout.xml"] + var modifiedControlsLayout = false + val editor = context.xmlEditor["res/layout/youtube_controls_layout.xml"] // voting button id from the voting button view from the youtube_controls_layout.xml host file val votingButtonId = "@+id/revanced_sb_voting_button" "RelativeLayout".copyXmlNode( context.xmlEditor[hostingResourceStream], - targetXmlEditor + editor ).also { - val children = targetXmlEditor.file.getElementsByTagName("RelativeLayout") - .item(0).childNodes + val document = editor.file + val children = document.getElementsByTagName("RelativeLayout").item(0).childNodes // Replace the startOf with the voting button view so that the button does not overlap for (i in 1 until children.length) { val view = children.item(i) // Replace the attribute for a specific node only - if (!view.hasAttributes()) - continue - if (!view.attributes.getNamedItem("android:id").nodeValue.endsWith("player_video_heading")) + if (!( + view.hasAttributes() && + view.attributes.getNamedItem( + "android:id", + ).nodeValue.endsWith("player_video_heading") + ) + ) { continue + } view.attributes.getNamedItem("android:layout_toStartOf").nodeValue = votingButtonId + modifiedControlsLayout = true break } - }.close() // close afterwards + }.close() + if (!modifiedControlsLayout) throw PatchException("Could not modify controls layout") /** * Add ReVanced Extended Settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/toolbar/ToolBarHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/toolbar/ToolBarHookPatch.kt index 0d9c7bfb1..d7033ede0 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/toolbar/ToolBarHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/toolbar/ToolBarHookPatch.kt @@ -11,7 +11,7 @@ import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.youtube.utils.toolbar.fingerprints.ToolBarButtonFingerprint import app.revanced.patches.youtube.utils.toolbar.fingerprints.ToolBarPatchFingerprint -import app.revanced.util.exception +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @@ -25,7 +25,7 @@ object ToolBarHookPatch : BytecodePatch( ) { override fun execute(context: BytecodeContext) { - ToolBarButtonFingerprint.result?.let { + ToolBarButtonFingerprint.resultOrThrow().let { it.mutableMethod.apply { val replaceIndex = it.scanResult.patternScanResult!!.startIndex val freeIndex = it.scanResult.patternScanResult!!.endIndex - 1 @@ -49,10 +49,9 @@ object ToolBarHookPatch : BytecodePatch( ) removeInstruction(replaceIndex) } - } ?: throw ToolBarButtonFingerprint.exception + } - insertMethod = ToolBarPatchFingerprint.result?.mutableMethod - ?: throw ToolBarPatchFingerprint.exception + insertMethod = ToolBarPatchFingerprint.resultOrThrow().mutableMethod } private const val INTEGRATIONS_CLASS_DESCRIPTOR = diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/videocpn/VideoCpnPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/videocpn/VideoCpnPatch.kt index f24fe3b5a..47918e1e6 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/videocpn/VideoCpnPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/videocpn/VideoCpnPatch.kt @@ -7,7 +7,7 @@ import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.youtube.utils.fingerprints.OrganicPlaybackContextModelFingerprint import app.revanced.patches.youtube.utils.videoid.general.VideoIdPatch -import app.revanced.util.exception +import app.revanced.util.resultOrThrow @Patch(dependencies = [VideoIdPatch::class]) object VideoCpnPatch : BytecodePatch( @@ -15,8 +15,7 @@ object VideoCpnPatch : BytecodePatch( ) { override fun execute(context: BytecodeContext) { - insertMethod = OrganicPlaybackContextModelFingerprint.result?.mutableMethod - ?: throw OrganicPlaybackContextModelFingerprint.exception + insertMethod = OrganicPlaybackContextModelFingerprint.resultOrThrow().mutableMethod } diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/general/VideoIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/general/VideoIdPatch.kt index 1a8e7925c..2541669fc 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/general/VideoIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/general/VideoIdPatch.kt @@ -20,8 +20,8 @@ import app.revanced.patches.youtube.utils.videoid.general.fingerprint.PlayerCont import app.revanced.patches.youtube.utils.videoid.general.fingerprint.VideoIdFingerprint import app.revanced.patches.youtube.utils.videoid.general.fingerprint.VideoIdParentFingerprint import app.revanced.patches.youtube.utils.videoid.general.fingerprint.VideoLengthFingerprint -import app.revanced.util.exception import app.revanced.util.getWalkerMethod +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -46,7 +46,7 @@ object VideoIdPatch : BytecodePatch( ) { override fun execute(context: BytecodeContext) { - VideoEndFingerprint.result?.let { + VideoEndFingerprint.resultOrThrow().let { playerInitMethod = it.mutableClass.methods.first { method -> MethodUtil.isConstructor(method) } @@ -89,14 +89,14 @@ object VideoIdPatch : BytecodePatch( ) } } - } ?: throw VideoEndFingerprint.exception + } /** * Set current video time */ - PlayerControllerSetTimeReferenceFingerprint.result?.let { + PlayerControllerSetTimeReferenceFingerprint.resultOrThrow().let { timeMethod = it.getWalkerMethod(context, it.scanResult.patternScanResult!!.startIndex) - } ?: throw PlayerControllerSetTimeReferenceFingerprint.exception + } /** * Hook the methods which set the time @@ -106,19 +106,19 @@ object VideoIdPatch : BytecodePatch( /** * Set current video is livestream */ - OrganicPlaybackContextModelFingerprint.result?.let { + OrganicPlaybackContextModelFingerprint.resultOrThrow().let { it.mutableMethod.apply { addInstruction( 2, "sput-boolean p2, $INTEGRATIONS_CLASS_DESCRIPTOR->isLiveStream:Z" ) } - } ?: throw OrganicPlaybackContextModelFingerprint.exception + } /** * Set current video length */ - VideoLengthFingerprint.result?.let { + VideoLengthFingerprint.resultOrThrow().let { it.mutableMethod.apply { val startIndex = it.scanResult.patternScanResult!!.startIndex val primaryRegister = getInstruction(startIndex).registerA @@ -129,23 +129,23 @@ object VideoIdPatch : BytecodePatch( "invoke-static {v$primaryRegister, v$secondaryRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->setVideoLength(J)V" ) } - } ?: throw VideoLengthFingerprint.exception + } - VideoIdParentFingerprint.result?.let { parentResult -> + VideoIdParentFingerprint.resultOrThrow().let { parentResult -> VideoIdFingerprint.also { it.resolve( context, parentResult.classDef ) - }.result?.let { + }.resultOrThrow().let { it.mutableMethod.apply { insertMethod = this insertIndex = it.scanResult.patternScanResult!!.endIndex videoIdRegister = getInstruction(insertIndex).registerA } offset++ // offset so setVideoId is called before any injected call - } ?: throw VideoIdFingerprint.exception - } ?: throw VideoIdParentFingerprint.exception + } + } injectCall("$INTEGRATIONS_CLASS_DESCRIPTOR->setVideoId(Ljava/lang/String;)V") injectPlayerResponseVideoId("$INTEGRATIONS_CLASS_DESCRIPTOR->setPlayerResponseVideoId(Ljava/lang/String;Z)V") diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/withoutshorts/VideoIdWithoutShortsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/withoutshorts/VideoIdWithoutShortsPatch.kt index a22acfe0d..55e070504 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/withoutshorts/VideoIdWithoutShortsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/videoid/withoutshorts/VideoIdWithoutShortsPatch.kt @@ -7,8 +7,8 @@ import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.youtube.utils.integrations.Constants.VIDEO_PATH import app.revanced.patches.youtube.utils.videoid.withoutshorts.fingerprint.VideoIdWithoutShortsFingerprint -import app.revanced.util.exception import app.revanced.util.getTargetIndex +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -17,13 +17,13 @@ object VideoIdWithoutShortsPatch : BytecodePatch( ) { override fun execute(context: BytecodeContext) { - VideoIdWithoutShortsFingerprint.result?.let { + VideoIdWithoutShortsFingerprint.resultOrThrow().let { it.mutableMethod.apply { insertMethod = this insertIndex = getTargetIndex(Opcode.INVOKE_INTERFACE) insertRegister = getInstruction(insertIndex + 1).registerA } - } ?: throw VideoIdWithoutShortsFingerprint.exception + } injectCall("$VIDEO_PATH/VideoInformation;->setVideoId(Ljava/lang/String;)V") diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/hdr/HDRVideoPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/hdr/HDRVideoPatch.kt index b00b49d17..9780110ba 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/hdr/HDRVideoPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/hdr/HDRVideoPatch.kt @@ -8,8 +8,8 @@ import app.revanced.patches.youtube.utils.integrations.Constants.COMPATIBLE_PACK import app.revanced.patches.youtube.utils.integrations.Constants.VIDEO_PATH import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.video.hdr.fingerprints.HDRCapabilityFingerprint -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow @Suppress("unused") object HDRVideoPatch : BaseBytecodePatch( @@ -21,7 +21,7 @@ object HDRVideoPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - HDRCapabilityFingerprint.result?.mutableMethod?.apply { + HDRCapabilityFingerprint.resultOrThrow().mutableMethod.apply { addInstructionsWithLabels( 0, """ invoke-static {}, $VIDEO_PATH/HDRVideoPatch;->disableHDRVideo()Z @@ -30,7 +30,7 @@ object HDRVideoPatch : BaseBytecodePatch( return v0 """, ExternalLabel("default", getInstruction(0)) ) - } ?: throw HDRCapabilityFingerprint.exception + } /** * Add settings diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/quality/VideoQualityPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/quality/VideoQualityPatch.kt index a73872ead..172eac490 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/quality/VideoQualityPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/quality/VideoQualityPatch.kt @@ -17,8 +17,8 @@ import app.revanced.patches.youtube.utils.settings.SettingsPatch.contexts import app.revanced.patches.youtube.utils.videoid.general.VideoIdPatch import app.revanced.patches.youtube.utils.videoid.withoutshorts.VideoIdWithoutShortsPatch import app.revanced.util.copyXmlNode -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction @Suppress("unused") @@ -42,7 +42,7 @@ object VideoQualityPatch : BaseBytecodePatch( ) { override fun execute(context: BytecodeContext) { - NewVideoQualityChangedFingerprint.result?.let { + NewVideoQualityChangedFingerprint.resultOrThrow().let { it.mutableMethod.apply { val index = it.scanResult.patternScanResult!!.startIndex val qualityRegister = getInstruction(index).registerA @@ -53,9 +53,9 @@ object VideoQualityPatch : BaseBytecodePatch( ) } - } ?: throw NewVideoQualityChangedFingerprint.exception + } - VideoQualitySetterFingerprint.result?.let { + VideoQualitySetterFingerprint.resultOrThrow().let { val onItemClickMethod = it.mutableClass.methods.find { method -> method.name == "onItemClick" } @@ -67,7 +67,7 @@ object VideoQualityPatch : BaseBytecodePatch( "invoke-static {p$listItemIndexParameter}, $INTEGRATIONS_VIDEO_QUALITY_CLASS_DESCRIPTOR->userChangedQualityIndex(I)V" ) } ?: throw PatchException("Failed to find onItemClick method") - } ?: throw VideoQualitySetterFingerprint.exception + } VideoIdPatch.injectCall("$INTEGRATIONS_VIDEO_QUALITY_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;)V") VideoIdWithoutShortsPatch.injectCall("$INTEGRATIONS_VIDEO_QUALITY_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;)V") diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/speed/PlaybackSpeedPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/speed/PlaybackSpeedPatch.kt index 20261eff3..a1e4842c0 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/speed/PlaybackSpeedPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/speed/PlaybackSpeedPatch.kt @@ -14,8 +14,8 @@ import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.patches.youtube.utils.videocpn.VideoCpnPatch import app.revanced.patches.youtube.video.speed.fingerprints.NewPlaybackSpeedChangedFingerprint import app.revanced.patches.youtube.video.speed.fingerprints.PlaybackSpeedInitializeFingerprint -import app.revanced.util.exception import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow import app.revanced.util.updatePatchStatus import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -35,15 +35,18 @@ object PlaybackSpeedPatch : BaseBytecodePatch( VideoEndFingerprint ) ) { + private const val INTEGRATIONS_PLAYBACK_SPEED_CLASS_DESCRIPTOR = + "$VIDEO_PATH/PlaybackSpeedPatch;" + override fun execute(context: BytecodeContext) { - NewVideoQualityChangedFingerprint.result?.let { parentResult -> + NewVideoQualityChangedFingerprint.resultOrThrow().let { parentResult -> NewPlaybackSpeedChangedFingerprint.also { it.resolve( context, parentResult.classDef ) - }.result?.let { result -> + }.resultOrThrow().let { result -> arrayOf(result, OverrideSpeedHookPatch.playbackSpeedChangedResult).forEach { it.mutableMethod.apply { val index = it.scanResult.patternScanResult!!.endIndex @@ -55,16 +58,16 @@ object PlaybackSpeedPatch : BaseBytecodePatch( ) } } - } ?: throw NewPlaybackSpeedChangedFingerprint.exception - } ?: throw NewVideoQualityChangedFingerprint.exception + } + } - VideoEndFingerprint.result?.let { parentResult -> + VideoEndFingerprint.resultOrThrow().let { parentResult -> PlaybackSpeedInitializeFingerprint.also { it.resolve( context, parentResult.classDef ) - }.result?.let { + }.resultOrThrow().let { it.mutableMethod.apply { val insertIndex = it.scanResult.patternScanResult!!.endIndex val insertRegister = getInstruction(insertIndex).registerA @@ -76,8 +79,8 @@ object PlaybackSpeedPatch : BaseBytecodePatch( """ ) } - } ?: throw PlaybackSpeedInitializeFingerprint.exception - } ?: throw VideoEndFingerprint.exception + } + } VideoCpnPatch.injectCall("$INTEGRATIONS_PLAYBACK_SPEED_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;)V") @@ -97,7 +100,4 @@ object PlaybackSpeedPatch : BaseBytecodePatch( context.updatePatchStatus("$UTILS_PATH/PatchStatus;", "DefaultPlaybackSpeed") } - - private const val INTEGRATIONS_PLAYBACK_SPEED_CLASS_DESCRIPTOR = - "$VIDEO_PATH/PlaybackSpeedPatch;" } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/util/BytecodeUtils.kt b/src/main/kotlin/app/revanced/util/BytecodeUtils.kt index d480cf951..df5412453 100644 --- a/src/main/kotlin/app/revanced/util/BytecodeUtils.kt +++ b/src/main/kotlin/app/revanced/util/BytecodeUtils.kt @@ -25,6 +25,8 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference import com.android.tools.smali.dexlib2.iface.reference.Reference import com.android.tools.smali.dexlib2.util.MethodUtil +fun MethodFingerprint.resultOrThrow() = result ?: throw exception + /** * The [PatchException] of failing to resolve a [MethodFingerprint]. * @@ -133,7 +135,7 @@ fun MethodFingerprint.literalInstructionViewHook( literal: Long, descriptor: String ) { - result?.mutableMethod?.apply { + resultOrThrow().mutableMethod.apply { val literalIndex = getWideLiteralInstructionIndex(literal) val targetIndex = getTargetIndex(literalIndex, Opcode.MOVE_RESULT_OBJECT) val targetRegister = getInstruction(targetIndex).registerA @@ -142,7 +144,7 @@ fun MethodFingerprint.literalInstructionViewHook( targetIndex + 1, "invoke-static {v$targetRegister}, $descriptor" ) - } ?: throw exception + } } /** @@ -380,7 +382,7 @@ fun BytecodeContext.updatePatchStatus( fun List.returnEarly(bool: Boolean = false) { val const = if (bool) "0x1" else "0x0" this.forEach { fingerprint -> - fingerprint.result?.let { result -> + fingerprint.resultOrThrow().let { result -> val stringInstructions = when (result.method.returnType.first()) { 'L' -> """ const/4 v0, $const @@ -395,6 +397,6 @@ fun List.returnEarly(bool: Boolean = false) { } result.mutableMethod.addInstructions(0, stringInstructions) - } ?: throw fingerprint.exception + } } } diff --git a/src/main/kotlin/app/revanced/util/ResourceUtils.kt b/src/main/kotlin/app/revanced/util/ResourceUtils.kt index 727589d20..b71cb1516 100644 --- a/src/main/kotlin/app/revanced/util/ResourceUtils.kt +++ b/src/main/kotlin/app/revanced/util/ResourceUtils.kt @@ -6,6 +6,7 @@ import app.revanced.patcher.data.ResourceContext import app.revanced.patcher.util.DomFileEditor import org.w3c.dom.Element import org.w3c.dom.Node +import java.io.InputStream import java.nio.file.Files import java.nio.file.StandardCopyOption @@ -49,12 +50,13 @@ fun String.startsWithAny(vararg prefixes: String): Boolean { /** * Copy resources from the current class loader to the resource directory. + * * @param sourceResourceDirectory The source resource directory name. * @param resources The resources to copy. */ fun ResourceContext.copyResources( sourceResourceDirectory: String, - vararg resources: ResourceGroup + vararg resources: ResourceGroup, ) { val targetResourceDirectory = this["res"] @@ -62,14 +64,19 @@ fun ResourceContext.copyResources( resourceGroup.resources.forEach { resource -> val resourceFile = "${resourceGroup.resourceDirectoryName}/$resource" Files.copy( - classLoader.getResourceAsStream("$sourceResourceDirectory/$resourceFile")!!, + inputStreamFromBundledResource(sourceResourceDirectory, resourceFile)!!, targetResourceDirectory.resolve(resourceFile).toPath(), - StandardCopyOption.REPLACE_EXISTING + StandardCopyOption.REPLACE_EXISTING, ) } } } +internal fun inputStreamFromBundledResource( + sourceResourceDirectory: String, + resourceFile: String, +): InputStream? = classLoader.getResourceAsStream("$sourceResourceDirectory/$resourceFile") + /** * Resource names mapped to their corresponding resource data. * @param resourceDirectoryName The name of the directory of the resource. @@ -89,7 +96,7 @@ fun ResourceContext.copyXmlNode( elementTag: String ) { val stringsResourceInputStream = - classLoader.getResourceAsStream("$resourceDirectory/$targetResource")!! + inputStreamFromBundledResource(resourceDirectory, targetResource)!! // Copy nodes from the resources node to the real resource node elementTag.copyXmlNode(