forked from inotia00/revanced-patches
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(YouTube/Shorts components): even if
Hide navigation bar
is turn…
…ed on, the navigation bar will reappear when the user opens the comments or description panel in Shorts
- Loading branch information
Showing
10 changed files
with
301 additions
and
84 deletions.
There are no files selected for viewing
98 changes: 55 additions & 43 deletions
98
src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsNavigationBarPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,83 @@ | ||
package app.revanced.patches.youtube.shorts.components | ||
|
||
import app.revanced.patcher.data.BytecodeContext | ||
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.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.patcher.patch.annotation.Patch | ||
import app.revanced.patches.youtube.shorts.components.fingerprints.BottomBarContainerHeightFingerprint | ||
import app.revanced.patches.youtube.shorts.components.fingerprints.ReelWatchPagerFingerprint | ||
import app.revanced.patches.youtube.utils.integrations.Constants.SHORTS_CLASS_DESCRIPTOR | ||
import app.revanced.patches.youtube.utils.navigation.fingerprints.InitializeButtonsFingerprint | ||
import app.revanced.patches.youtube.utils.navigation.NavigationBarHookPatch | ||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.BottomBarContainer | ||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelWatchPlayer | ||
import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT | ||
import app.revanced.util.fingerprint.MultiMethodFingerprint | ||
import app.revanced.util.getReference | ||
import app.revanced.util.getWalkerMethod | ||
import app.revanced.util.indexOfFirstInstructionOrThrow | ||
import app.revanced.util.indexOfFirstWideLiteralInstructionValue | ||
import app.revanced.util.injectLiteralInstructionViewCall | ||
import app.revanced.util.patch.MultiMethodBytecodePatch | ||
import app.revanced.util.resultOrThrow | ||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction | ||
import com.android.tools.smali.dexlib2.iface.reference.MethodReference | ||
|
||
object ShortsNavigationBarPatch : BytecodePatch( | ||
setOf( | ||
BottomNavigationBarFingerprint, | ||
InitializeButtonsFingerprint, | ||
RenderBottomNavigationBarFingerprint | ||
) | ||
/** | ||
* Up to YouTube 19.28.42, there are two Methods with almost the same pattern. | ||
* | ||
* In certain YouTube versions, the hook should be done not on the first matching Method, but also on the last matching Method. | ||
* | ||
* 'Multiple fingerprint search' feature is not yet implemented in ReVanced Patcher, | ||
* So I just implement it via [MultiMethodFingerprint]. | ||
* | ||
* Related Issues: | ||
* https://github.com/ReVanced/revanced-patcher/issues/74 | ||
* https://github.com/ReVanced/revanced-patcher/issues/308 | ||
*/ | ||
@Patch(dependencies = [NavigationBarHookPatch::class]) | ||
object ShortsNavigationBarPatch : MultiMethodBytecodePatch( | ||
fingerprints = setOf(ReelWatchPagerFingerprint), | ||
multiFingerprints = setOf(BottomBarContainerHeightFingerprint) | ||
) { | ||
override fun execute(context: BytecodeContext) { | ||
super.execute(context) | ||
|
||
InitializeButtonsFingerprint.resultOrThrow().let { parentResult -> | ||
SetPivotBarFingerprint.also { it.resolve(context, parentResult.classDef) } | ||
.resultOrThrow().let { | ||
it.mutableMethod.apply { | ||
val startIndex = it.scanResult.patternScanResult!!.startIndex | ||
val register = getInstruction<OneRegisterInstruction>(startIndex).registerA | ||
// region patch for set navigation bar height. | ||
|
||
addInstruction( | ||
startIndex + 1, | ||
"invoke-static {v$register}, $SHORTS_CLASS_DESCRIPTOR->setNavigationBar(Ljava/lang/Object;)V" | ||
) | ||
} | ||
} | ||
} | ||
|
||
RenderBottomNavigationBarFingerprint.resultOrThrow().let { | ||
val walkerMethod = | ||
it.getWalkerMethod(context, it.scanResult.patternScanResult!!.endIndex) | ||
|
||
walkerMethod.addInstruction( | ||
0, | ||
"invoke-static {}, $SHORTS_CLASS_DESCRIPTOR->hideShortsNavigationBar()V" | ||
) | ||
} | ||
|
||
BottomNavigationBarFingerprint.result?.let { | ||
BottomBarContainerHeightFingerprint.resultOrThrow().forEach { | ||
it.mutableMethod.apply { | ||
val targetIndex = indexOfFirstInstructionOrThrow { | ||
getReference<MethodReference>()?.name == "findViewById" | ||
val constIndex = indexOfFirstWideLiteralInstructionValue(BottomBarContainer) | ||
|
||
val targetIndex = indexOfFirstInstructionOrThrow(constIndex) { | ||
getReference<MethodReference>()?.name == "getHeight" | ||
} + 1 | ||
val insertRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA | ||
|
||
val heightRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA | ||
|
||
addInstructions( | ||
targetIndex + 1, """ | ||
invoke-static {v$insertRegister}, $SHORTS_CLASS_DESCRIPTOR->hideShortsNavigationBar(Landroid/view/View;)Landroid/view/View; | ||
move-result-object v$insertRegister | ||
invoke-static {v$heightRegister}, $SHORTS_CLASS_DESCRIPTOR->overrideNavigationBarHeight(I)I | ||
move-result v$heightRegister | ||
""" | ||
) | ||
} | ||
} | ||
|
||
NavigationBarHookPatch.addBottomBarContainerHook("$SHORTS_CLASS_DESCRIPTOR->setNavigationBar(Landroid/view/View;)V") | ||
|
||
// endregion. | ||
|
||
// region patch for addOnAttachStateChangeListener. | ||
|
||
val smaliInstruction = """ | ||
invoke-static {v$REGISTER_TEMPLATE_REPLACEMENT}, $SHORTS_CLASS_DESCRIPTOR->onShortsCreate(Landroid/view/View;)V | ||
""" | ||
|
||
ReelWatchPagerFingerprint.injectLiteralInstructionViewCall( | ||
ReelWatchPlayer, | ||
smaliInstruction | ||
) | ||
|
||
// endregion. | ||
|
||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ced/patches/youtube/shorts/components/fingerprints/BottomBarContainerHeightFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package app.revanced.patches.youtube.shorts.components.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.BottomBarContainer | ||
import app.revanced.util.containsWideLiteralInstructionValue | ||
import app.revanced.util.fingerprint.MultiMethodFingerprint | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
|
||
internal object BottomBarContainerHeightFingerprint : MultiMethodFingerprint( | ||
returnType = "V", | ||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, | ||
parameters = listOf("Landroid/view/View;", "Landroid/os/Bundle;"), | ||
strings = listOf("r_pfvc"), | ||
customFingerprint = { methodDef, _ -> | ||
methodDef.containsWideLiteralInstructionValue(BottomBarContainer) | ||
}, | ||
) |
12 changes: 0 additions & 12 deletions
12
...revanced/patches/youtube/shorts/components/fingerprints/BottomNavigationBarFingerprint.kt
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
.../app/revanced/patches/youtube/shorts/components/fingerprints/ReelWatchPagerFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package app.revanced.patches.youtube.shorts.components.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelWatchPlayer | ||
import app.revanced.util.fingerprint.LiteralValueFingerprint | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
|
||
internal object ReelWatchPagerFingerprint : LiteralValueFingerprint( | ||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, | ||
returnType = "Landroid/view/View;", | ||
literalSupplier = { ReelWatchPlayer } | ||
) |
13 changes: 0 additions & 13 deletions
13
...ed/patches/youtube/shorts/components/fingerprints/RenderBottomNavigationBarFingerprint.kt
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
...lin/app/revanced/patches/youtube/shorts/components/fingerprints/SetPivotBarFingerprint.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.