From ded13980ab4ce5b08565847f1b65e3fd3aba2ba7 Mon Sep 17 00:00:00 2001 From: Asecave Date: Sat, 9 Aug 2025 00:23:07 +0200 Subject: [PATCH] Implemented patch --- .../streamQualityDegredationFix/index.ts | 86 +++++++++++++++++++ src/utils/constants.ts | 4 + 2 files changed, 90 insertions(+) create mode 100644 src/plugins/streamQualityDegredationFix/index.ts diff --git a/src/plugins/streamQualityDegredationFix/index.ts b/src/plugins/streamQualityDegredationFix/index.ts new file mode 100644 index 00000000000..34c1c7636f1 --- /dev/null +++ b/src/plugins/streamQualityDegredationFix/index.ts @@ -0,0 +1,86 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { definePluginSettings } from "@api/Settings"; +import { Devs } from "@utils/constants"; +import definePlugin, { makeRange, OptionType } from "@utils/types"; + +const settings = definePluginSettings({ + refreshFrequency: { + description: "Stream refreshing frequency", + type: OptionType.SLIDER, + markers: makeRange(2, 60, 2), + default: 20, + stickToMarkers: false, + restartNeeded: true + } +}); + +var streaming = false; + +// This changes every time the user changes stream settings (quality/refreshrate) so the old refresh loop can check if it should stop +var userSettingId: number = 0; + +export default definePlugin({ + name: "streamQualityDegredationFix", + description: "If you are streaming on Linux it can happen that the stream sets the resolution to 480p after some time. This plugin stops this.", + authors: [Devs.Asecave], + settings, + + patches: [ + { + find: "}setDesktopEncodingOptions(", + replacement: { + match: /(setDesktopEncodingOptions\()(\i),(\i),(\i)(\){)/, + replace: "$&\ + const repeat = async () => {\ + const sleep = (time) => new Promise(r => setTimeout(r, time));\ + const userSettingsId = $self.getUserSettingsId();\ + while ($self.isStreaming() && $self.getUserSettingsId() === userSettingsId) {\ + console.log(\"[StreamQualityDegredationFix] refreshing stream quality\");\ + this.originalSetDesktopEncodingOptions(640,480,30);\ + this.originalSetDesktopEncodingOptions($2,$3,$4);\ + await sleep($self.getTimeoutDuration());\ + }\ + };\ + repeat();\ + }\ + originalSetDesktopEncodingOptions($2,$3,$4) {" + }, + + }, + { + find: "},setGoLiveSource(", + replacement: { + match: /(setGoLiveSource\()(\i)(\){)(\(null==\i\?void 0:\i\.qualityOptions\)!=null)/, + replace: "$1$2$3$self.setGoLiveSourceTrigger($2);$4" + } + } + ], + + getTimeoutDuration() { + return Math.floor(settings.store.refreshFrequency * 60000); + }, + + getUserSettingsId() { + return userSettingId; + }, + + isStreaming() { + return streaming; + }, + + setGoLiveSourceTrigger(options: any) { + userSettingId++; + if (!options || !Object.prototype.hasOwnProperty.call(options, "desktopSettings")) { + streaming = false; + return; + } + streaming = true; + }, +}); + + diff --git a/src/utils/constants.ts b/src/utils/constants.ts index eb19bf862f3..30d6adf4424 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -598,6 +598,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "Cootshk", id: 921605971577548820n }, + Asecave: { + name: "Asecave", + id: 398046840840388610n + }, } satisfies Record); // iife so #__PURE__ works correctly