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.
feat(youtube): add
hide-suggested-video-overlay
patch
- Loading branch information
Showing
6 changed files
with
111 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
17 changes: 17 additions & 0 deletions
17
...ches/youtube/player/suggestedvideooverlay/fingerprints/CoreConatinerBuilderFingerprint.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.player.suggestedvideooverlay.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.CoreContainer | ||
import app.revanced.util.bytecode.isWideLiteralExists | ||
import org.jf.dexlib2.AccessFlags | ||
|
||
object CoreConatinerBuilderFingerprint : MethodFingerprint( | ||
returnType = "Landroid/view/View;", | ||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, | ||
parameters = listOf("Landroid/content/Context;"), | ||
customFingerprint = { methodDef, _ -> | ||
methodDef.isWideLiteralExists( | ||
CoreContainer | ||
) | ||
}) |
81 changes: 81 additions & 0 deletions
81
...revanced/patches/youtube/player/suggestedvideooverlay/patch/SuggestedVideoOverlayPatch.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,81 @@ | ||
package app.revanced.patches.youtube.player.suggestedvideooverlay.patch | ||
|
||
import app.revanced.extensions.toErrorResult | ||
import app.revanced.patcher.annotation.Description | ||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction | ||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction | ||
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.patcher.patch.annotations.DependsOn | ||
import app.revanced.patcher.patch.annotations.Patch | ||
import app.revanced.patches.youtube.player.suggestedvideooverlay.fingerprints.CoreConatinerBuilderFingerprint | ||
import app.revanced.patches.youtube.utils.annotations.YouTubeCompatibility | ||
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch | ||
import app.revanced.patches.youtube.utils.resourceid.patch.SharedResourceIdPatch.Companion.CoreContainer | ||
import app.revanced.patches.youtube.utils.settings.resource.patch.SettingsPatch | ||
import app.revanced.util.bytecode.getWideLiteralIndex | ||
import app.revanced.util.integrations.Constants.PLAYER | ||
import org.jf.dexlib2.iface.instruction.ReferenceInstruction | ||
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction | ||
|
||
@Patch | ||
@Name("Hide suggested video overlay") | ||
@Description("Hide the suggested video overlay to play next.") | ||
@DependsOn( | ||
[ | ||
SettingsPatch::class, | ||
SharedResourceIdPatch::class | ||
] | ||
) | ||
@YouTubeCompatibility | ||
@Version("0.0.1") | ||
class SuggestedVideoOverlayPatch : BytecodePatch( | ||
listOf(CoreConatinerBuilderFingerprint) | ||
) { | ||
override fun execute(context: BytecodeContext): PatchResult { | ||
|
||
CoreConatinerBuilderFingerprint.result?.let { | ||
it.mutableMethod.apply { | ||
val targetIndex = getWideLiteralIndex(CoreContainer) + 4 | ||
val targetReference = | ||
getInstruction<ReferenceInstruction>(targetIndex).reference | ||
|
||
if (!targetReference.toString().endsWith("Landroid/view/ViewGroup;")) | ||
return PatchResultError("Reference did not match: $targetReference") | ||
|
||
val targetRegister = | ||
getInstruction<TwoRegisterInstruction>(targetIndex).registerA | ||
|
||
addInstruction( | ||
targetIndex, | ||
"invoke-static {v$targetRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR" | ||
) | ||
} | ||
} ?: return CoreConatinerBuilderFingerprint.toErrorResult() | ||
|
||
/** | ||
* Add settings | ||
*/ | ||
SettingsPatch.addPreference( | ||
arrayOf( | ||
"PREFERENCE: PLAYER_SETTINGS", | ||
"SETTINGS: PLAYER_EXPERIMENTAL_FLAGS", | ||
"SETTINGS: HIDE_SUGGESTED_VIDEO_OVERLAY" | ||
) | ||
) | ||
|
||
SettingsPatch.updatePatchStatus("hide-suggested-video-overlay") | ||
|
||
return PatchResultSuccess() | ||
} | ||
|
||
private companion object { | ||
const val INTEGRATIONS_CLASS_DESCRIPTOR = | ||
"$PLAYER->hideSuggestedVideoOverlay(Landroid/view/ViewGroup;)V" | ||
} | ||
} |
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
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