From 1a0a6ee90be8168f46ada6dfc736f3609a921561 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+lisouseinaikyrios@users.noreply.github.com> Date: Sat, 1 Apr 2023 15:15:24 +0200 Subject: [PATCH] fix(youtube/spoof-signature-verification): fixed subtitles in wrong location (#343) --- .../SpoofSignatureVerificationPatch.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/app/src/main/java/app/revanced/integrations/patches/SpoofSignatureVerificationPatch.java b/app/src/main/java/app/revanced/integrations/patches/SpoofSignatureVerificationPatch.java index 78661d64..d5f9645e 100644 --- a/app/src/main/java/app/revanced/integrations/patches/SpoofSignatureVerificationPatch.java +++ b/app/src/main/java/app/revanced/integrations/patches/SpoofSignatureVerificationPatch.java @@ -95,4 +95,65 @@ public class SpoofSignatureVerificationPatch { LogHelper.printException(() -> "onResponse failure", ex); } } + + /** + * Last WindowsSetting constructor values. Values are checked for changes to reduce log spam. + */ + private static int lastAnchorPosition, lastAnchorHorizontal, lastAnchorVertical; + private static boolean lastVs, lastSd; + + /** + * Injection point. Overrides values passed into SubtitleWindowSettings constructor. + * + * @param anchorPosition bitmask with 6 bit fields, that appears to be indicate the layout position on screen + * @param anchorHorizontal percentage [0, 100], that appears to be a horizontal text anchor point + * @param anchorVertical percentage [0, 100], that appears to be a vertical text anchor point + * @param vs appears to indicate is subtitles exist, and value is always true. + * @param sd appears to indicate if video has non standard aspect ratio (4:3, or a rotated orientation) + * Always true for Shorts playback. + */ + public static int[] getSubtitleWindowSettingsOverride(int anchorPosition, int anchorHorizontal, int anchorVertical, + boolean vs, boolean sd) { + int[] override = {anchorPosition, anchorHorizontal, anchorVertical}; + + // Videos with custom captions that specify screen positions appear to always have correct screen positions (even with spoofing). + // But for auto generated and most other captions, the spoof incorrectly gives Shorts caption settings for all videos. + // Override the parameters if the video is not a Short but it has Short caption settings. + if (SettingsEnum.SIGNATURE_SPOOFING.getBoolean() + && !PlayerType.getCurrent().isNoneOrHidden() // video is not a Short or Story + && anchorPosition == 9 // but it has shorts specific subtitle parameters + && anchorHorizontal == 20 + && anchorVertical == 0) { + if (sd) { + // values observed during playback + override[0] = 33; + override[1] = 20; + override[2] = 100; + } else { + // Default values used for regular (non Shorts) playback of videos with a standard aspect ratio + // Values are found in SubtitleWindowSettings static field + override[0] = 34; + override[1] = 50; + override[2] = 95; + } + } + + if (!SettingsEnum.DEBUG.getBoolean()) { + return override; + } + if (anchorPosition != lastAnchorPosition + || anchorHorizontal != lastAnchorHorizontal || anchorVertical != lastAnchorVertical + || vs != lastVs || sd != lastSd) { + LogHelper.printDebug(() -> "SubtitleWindowSettings anchorPosition:" + anchorPosition + + " anchorHorizontal:" + anchorHorizontal + " anchorVertical:" + anchorVertical + + " vs:" + vs + " sd:" + sd); + lastAnchorPosition = anchorPosition; + lastAnchorHorizontal = anchorHorizontal; + lastAnchorVertical = anchorVertical; + lastVs = vs; + lastSd = sd; + } + + return override; + } }