generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Readd
swipe-controls
patch (#123)
- Loading branch information
1 parent
54d67a4
commit 7f2a2b2
Showing
5 changed files
with
301 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
Repo for all ReVanced patches | ||
|
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
14 changes: 14 additions & 0 deletions
14
...otlin/app/revanced/patches/youtube/interaction/fenster/annotation/FensterCompatibility.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.interaction.fenster.annotation | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
//TODO the patch may be compatible with more versions, but this is the one i'm testing on right now... | ||
@Compatibility( | ||
[Package( | ||
"com.google.android.youtube", arrayOf("17.24.34") | ||
)] | ||
) | ||
@Target(AnnotationTarget.CLASS) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
internal annotation class FensterCompatibility |
45 changes: 45 additions & 0 deletions
45
.../revanced/patches/youtube/interaction/fenster/fingerprints/UpdatePlayerTypeFingerprint.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,45 @@ | ||
package app.revanced.patches.youtube.interaction.fenster.fingerprints | ||
|
||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod | ||
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patches.youtube.interaction.fenster.annotation.FensterCompatibility | ||
import org.jf.dexlib2.AccessFlags | ||
import org.jf.dexlib2.Opcode | ||
|
||
@Name("update-player-type-fingerprint") | ||
@MatchingMethod( | ||
"LYoutubePlayerOverlaysLayout;", | ||
"nM" | ||
) | ||
@FuzzyPatternScanMethod(2) | ||
@FensterCompatibility | ||
@Version("0.0.1") | ||
object UpdatePlayerTypeFingerprint : MethodFingerprint( | ||
"V", | ||
AccessFlags.PUBLIC or AccessFlags.FINAL, | ||
null, | ||
listOf( | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.IGET_OBJECT, | ||
Opcode.IF_NE, | ||
Opcode.RETURN_VOID, | ||
Opcode.IPUT_OBJECT, | ||
Opcode.INVOKE_DIRECT, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.MOVE_RESULT, | ||
Opcode.IF_EQZ, | ||
Opcode.CONST_4, | ||
Opcode.INVOKE_STATIC, | ||
Opcode.RETURN_VOID, | ||
Opcode.CONST_4, | ||
Opcode.INVOKE_STATIC, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.RETURN_VOID | ||
) | ||
) |
121 changes: 121 additions & 0 deletions
121
src/main/kotlin/app/revanced/patches/youtube/interaction/fenster/patch/FensterPatch.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,121 @@ | ||
package app.revanced.patches.youtube.interaction.fenster.patch | ||
|
||
import app.revanced.extensions.injectConsumableEventHook | ||
import app.revanced.extensions.injectIntoNamedMethod | ||
import app.revanced.patcher.annotation.Description | ||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.data.impl.BytecodeData | ||
import app.revanced.patcher.extensions.addInstruction | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultError | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patcher.patch.annotations.Dependencies | ||
import app.revanced.patcher.patch.annotations.Patch | ||
import app.revanced.patcher.patch.impl.BytecodePatch | ||
import app.revanced.patches.youtube.interaction.fenster.annotation.FensterCompatibility | ||
import app.revanced.patches.youtube.interaction.fenster.fingerprints.UpdatePlayerTypeFingerprint | ||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch | ||
import org.jf.dexlib2.immutable.reference.ImmutableMethodReference | ||
|
||
@Patch | ||
@Name("fenster-swipe-controls") | ||
@Description("volume and brightness swipe controls") | ||
@FensterCompatibility | ||
@Version("0.0.1") | ||
@Dependencies(dependencies = [IntegrationsPatch::class]) | ||
class FensterPatch : BytecodePatch( | ||
listOf( | ||
UpdatePlayerTypeFingerprint | ||
) | ||
) { | ||
override fun execute(data: BytecodeData): PatchResult { | ||
// hook WatchWhileActivity.onStart (main activity lifecycle hook) | ||
data.injectIntoNamedMethod( | ||
"com/google/android/apps/youtube/app/watchwhile/WatchWhileActivity", | ||
"onStart", | ||
0, | ||
"invoke-static { p0 }, Lapp/revanced/integrations/patches/FensterSwipePatch;->WatchWhileActivity_onStartHookEX(Ljava/lang/Object;)V" | ||
) | ||
|
||
// hook YoutubePlayerOverlaysLayout.onFinishInflate (player overlays init hook) | ||
data.injectIntoNamedMethod( | ||
"com/google/android/apps/youtube/app/common/player/overlay/YouTubePlayerOverlaysLayout", | ||
"onFinishInflate", | ||
-2, | ||
"invoke-static { p0 }, Lapp/revanced/integrations/patches/FensterSwipePatch;->YouTubePlayerOverlaysLayout_onFinishInflateHookEX(Ljava/lang/Object;)V" | ||
) | ||
|
||
// hook YoutubePlayerOverlaysLayout.UpdatePlayerType | ||
injectUpdatePlayerTypeHook( | ||
UpdatePlayerTypeFingerprint.result!!, | ||
"com/google/android/apps/youtube/app/common/player/overlay/YouTubePlayerOverlaysLayout" | ||
) | ||
|
||
// hook NextGenWatchLayout.onTouchEvent and NextGenWatchLayout.onInterceptTouchEvent (player touch event hook) | ||
injectWatchLayoutTouchHooks( | ||
data, | ||
"com/google/android/apps/youtube/app/watch/nextgenwatch/ui/NextGenWatchLayout" | ||
) | ||
|
||
return PatchResultSuccess() | ||
} | ||
|
||
@Suppress("SameParameterValue") | ||
private fun injectUpdatePlayerTypeHook(fingerPrintResult: MethodFingerprintResult, targetClass: String) { | ||
// validate fingerprint found the right class | ||
if (!fingerPrintResult.classDef.type.endsWith("$targetClass;")) { | ||
throw PatchResultError("$targetClass.UpdatePlayerType fingerprint could not be validated") | ||
} | ||
|
||
// insert the hook | ||
fingerPrintResult.mutableMethod.addInstruction( | ||
0, | ||
"invoke-static { p1 }, Lapp/revanced/integrations/patches/FensterSwipePatch;->YouTubePlayerOverlaysLayout_updatePlayerTypeHookEX(Ljava/lang/Object;)V" | ||
) | ||
} | ||
|
||
/** | ||
* Inject onTouch event hooks into the watch layout class | ||
* | ||
* @param data bytecode data | ||
* @param targetClass watch layout class name | ||
*/ | ||
@Suppress("SameParameterValue") | ||
private fun injectWatchLayoutTouchHooks(data: BytecodeData, targetClass: String) { | ||
var touchHooksCount = 0 | ||
data.classes.filter { it.type.endsWith("$targetClass;") }.forEach { classDef -> | ||
// hook onTouchEvent | ||
data.proxy(classDef).resolve().methods.filter { it.name == "onTouchEvent" }.forEach { methodDef -> | ||
touchHooksCount++ | ||
methodDef.injectConsumableEventHook( | ||
ImmutableMethodReference( | ||
"Lapp/revanced/integrations/patches/FensterSwipePatch;", | ||
"NextGenWatchLayout_onTouchEventHookEX", | ||
listOf("Ljava/lang/Object;", "Ljava/lang/Object;"), | ||
"Z" | ||
) | ||
) | ||
} | ||
|
||
// hook onInterceptTouchEvent | ||
data.proxy(classDef).resolve().methods.filter { it.name == "onInterceptTouchEvent" }.forEach { methodDef -> | ||
touchHooksCount++ | ||
methodDef.injectConsumableEventHook( | ||
ImmutableMethodReference( | ||
"Lapp/revanced/integrations/patches/FensterSwipePatch;", | ||
"NextGenWatchLayout_onInterceptTouchEventHookEX", | ||
listOf("Ljava/lang/Object;", "Ljava/lang/Object;"), | ||
"Z" | ||
) | ||
) | ||
} | ||
} | ||
|
||
// fail if no touch hooks were inserted | ||
if (touchHooksCount <= 0) { | ||
throw PatchResultError("failed to inject onTouchEvent hook into NextGenWatchLayout: none found") | ||
} | ||
} | ||
} |