forked from ReVanced/revanced-patches
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(youtube/general-ads): restore swipe back to exit gesture (ReVance…
…d#1405) Co-authored-by: oSumAtrIX <[email protected]>
- Loading branch information
Showing
7 changed files
with
181 additions
and
1 deletion.
There are no files selected for viewing
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
13 changes: 13 additions & 0 deletions
13
...atches/youtube/misc/fix/backtoexitgesture/annotation/FixBackToExitGestureCompatibility.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,13 @@ | ||
package app.revanced.patches.youtube.misc.fix.backtoexitgesture.annotation | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
@Compatibility( | ||
[Package( | ||
"com.google.android.youtube", arrayOf("17.49.37") | ||
)] | ||
) | ||
@Target(AnnotationTarget.CLASS) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
internal annotation class FixBackToExitGestureCompatibility |
14 changes: 14 additions & 0 deletions
14
...anced/patches/youtube/misc/fix/backtoexitgesture/fingerprints/OnBackPressedFingerprint.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,14 @@ | ||
package app.revanced.patches.youtube.misc.fix.backtoexitgesture.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import org.jf.dexlib2.Opcode | ||
|
||
object OnBackPressedFingerprint : MethodFingerprint( | ||
opcodes = listOf( | ||
Opcode.RETURN_VOID | ||
), | ||
customFingerprint = { methodDef -> | ||
methodDef.definingClass.endsWith("WatchWhileActivity;") | ||
&& methodDef.name == "onBackPressed" | ||
} | ||
) |
19 changes: 19 additions & 0 deletions
19
...tches/youtube/misc/fix/backtoexitgesture/fingerprints/RecyclerViewScrollingFingerprint.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,19 @@ | ||
package app.revanced.patches.youtube.misc.fix.backtoexitgesture.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import org.jf.dexlib2.Opcode | ||
|
||
object RecyclerViewScrollingFingerprint : MethodFingerprint( | ||
opcodes = listOf( | ||
Opcode.IGET_OBJECT, | ||
Opcode.IGET_OBJECT, | ||
Opcode.IF_EQZ, | ||
Opcode.IGET_OBJECT, | ||
Opcode.CHECK_CAST, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.MOVE_RESULT, | ||
Opcode.IF_LEZ, | ||
Opcode.IGET_OBJECT, | ||
Opcode.CONST_4, | ||
) | ||
) |
27 changes: 27 additions & 0 deletions
27
...es/youtube/misc/fix/backtoexitgesture/fingerprints/RecyclerViewTopScrollingFingerprint.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,27 @@ | ||
package app.revanced.patches.youtube.misc.fix.backtoexitgesture.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import org.jf.dexlib2.AccessFlags | ||
import org.jf.dexlib2.Opcode | ||
|
||
object RecyclerViewTopScrollingFingerprint : MethodFingerprint( | ||
"V", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf(), listOf( | ||
Opcode.IGET_OBJECT, | ||
Opcode.IF_EQZ, | ||
Opcode.IGET_OBJECT, | ||
Opcode.INVOKE_INTERFACE, | ||
Opcode.MOVE_RESULT_OBJECT, | ||
Opcode.INVOKE_INTERFACE, | ||
Opcode.MOVE_RESULT, | ||
Opcode.IF_EQZ, | ||
Opcode.INVOKE_INTERFACE, | ||
Opcode.MOVE_RESULT_OBJECT, | ||
Opcode.CHECK_CAST, | ||
Opcode.CONST_4, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.GOTO, | ||
Opcode.IGET_OBJECT, | ||
Opcode.INVOKE_INTERFACE, | ||
) | ||
) |
20 changes: 20 additions & 0 deletions
20
...tube/misc/fix/backtoexitgesture/fingerprints/RecyclerViewTopScrollingParentFingerprint.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,20 @@ | ||
package app.revanced.patches.youtube.misc.fix.backtoexitgesture.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import org.jf.dexlib2.Opcode | ||
|
||
object RecyclerViewTopScrollingParentFingerprint : MethodFingerprint( | ||
opcodes = listOf( | ||
Opcode.INVOKE_DIRECT, | ||
Opcode.IPUT_OBJECT, | ||
Opcode.IPUT_OBJECT, | ||
Opcode.IPUT_OBJECT, | ||
Opcode.IPUT_OBJECT, | ||
Opcode.CONST_16, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.NEW_INSTANCE | ||
), | ||
customFingerprint = { methodDef -> | ||
methodDef.name == "<init>" | ||
} | ||
) |
86 changes: 86 additions & 0 deletions
86
...pp/revanced/patches/youtube/misc/fix/backtoexitgesture/patch/FixBackToExitGesturePatch.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,86 @@ | ||
package app.revanced.patches.youtube.misc.fix.backtoexitgesture.patch | ||
|
||
import app.revanced.extensions.toErrorResult | ||
import app.revanced.patcher.annotation.Description | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.addInstruction | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultError | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patches.youtube.misc.fix.backtoexitgesture.annotation.FixBackToExitGestureCompatibility | ||
import app.revanced.patches.youtube.misc.fix.backtoexitgesture.fingerprints.OnBackPressedFingerprint | ||
import app.revanced.patches.youtube.misc.fix.backtoexitgesture.fingerprints.RecyclerViewScrollingFingerprint | ||
import app.revanced.patches.youtube.misc.fix.backtoexitgesture.fingerprints.RecyclerViewTopScrollingFingerprint | ||
import app.revanced.patches.youtube.misc.fix.backtoexitgesture.fingerprints.RecyclerViewTopScrollingParentFingerprint | ||
|
||
@Description("Fixes the swipe back to exit gesture.") | ||
@FixBackToExitGestureCompatibility | ||
@Version("0.0.1") | ||
class FixBackToExitGesturePatch : BytecodePatch( | ||
listOf( | ||
RecyclerViewTopScrollingParentFingerprint, | ||
RecyclerViewScrollingFingerprint, | ||
OnBackPressedFingerprint, | ||
) | ||
) { | ||
override fun execute(context: BytecodeContext): PatchResult { | ||
RecyclerViewTopScrollingFingerprint.apply { | ||
resolve( | ||
context, | ||
RecyclerViewTopScrollingParentFingerprint.result?.classDef | ||
?: return RecyclerViewTopScrollingParentFingerprint.toErrorResult() | ||
) | ||
} | ||
|
||
mapOf( | ||
RecyclerViewTopScrollingFingerprint to IntegrationsMethod( | ||
methodName = "onTopView" | ||
), | ||
RecyclerViewScrollingFingerprint to IntegrationsMethod( | ||
methodName = "onScrollingViews" | ||
), | ||
OnBackPressedFingerprint to IntegrationsMethod( | ||
"p0", "onBackPressed", "Lcom/google/android/apps/youtube/app/watchwhile/WatchWhileActivity;" | ||
) | ||
).forEach { (fingerprint, target) -> | ||
try { | ||
fingerprint.injectCall(target) | ||
} catch (error: PatchResultError) { | ||
return error | ||
} | ||
} | ||
|
||
return PatchResultSuccess() | ||
} | ||
|
||
private companion object { | ||
/** | ||
* A reference to a method from the integrations for [FixBackToExitGesturePatch]. | ||
* | ||
* @param register The method registers. | ||
* @param methodName The method name. | ||
* @param parameterTypes The parameters of the method. | ||
*/ | ||
data class IntegrationsMethod( | ||
val register: String = "", val methodName: String, val parameterTypes: String = "" | ||
) { | ||
override fun toString() = | ||
"invoke-static {$register}, Lapp/revanced/integrations/patches/FixBackToExitGesturePatch;->$methodName($parameterTypes)V" | ||
} | ||
|
||
/** | ||
* Inject a call to a method from the integrations. | ||
* | ||
* @param targetMethod The target method to call. | ||
*/ | ||
fun MethodFingerprint.injectCall(targetMethod: IntegrationsMethod) = result?.apply { | ||
mutableMethod.addInstruction( | ||
scanResult.patternScanResult!!.endIndex, targetMethod.toString() | ||
) | ||
} ?: throw this.toErrorResult() | ||
} | ||
} |