Skip to content

Instantly share code, notes, and snippets.

@Diyagi
Created July 15, 2024 18:57
Show Gist options
  • Save Diyagi/42027b10b8a96bc19f23cc337de8d5bd to your computer and use it in GitHub Desktop.
Save Diyagi/42027b10b8a96bc19f23cc337de8d5bd to your computer and use it in GitHub Desktop.
Vencord Stereo Mic
import definePlugin, { OptionType } from "@utils/types";
import { definePluginSettings } from "@api/Settings";
const settings = definePluginSettings({
voiceBitrate: {
type: OptionType.SLIDER,
description: "Voice Bitrate",
markers: [8, 64, 256, 384, 512],
default: 512,
stickToMarkers: false,
componentProps: {
// This will skip the save, but oh well, im too lazy to figure out how to properly math floor this b4 saving
onValueChange: (v: number) => settings.store.voiceBitrate = Math.floor(v),
onValueRender: (v: number): string => `${v.toFixed(0)}kbps`,
onMarkerRender: (v: number): string => `${v.toFixed(0)}kbps`
}
},
enableFec: {
type: OptionType.BOOLEAN,
description: "Enable Forward Error Corretion",
default: false
}
});
export default definePlugin({
name: "Stereo Mic",
description: "2 channels... scawwy",
authors: [{ name: "Diyagi", id: 651109069565853764n }],
// These regexes probably could be better, idk regex c:
patches: [{
find: "...this.getAttenuationOptions()",
replacement: [
{
match: /freq:48e3,pacsize:960,channels:1,rate:64e3/,
replace: "freq:48e3,pacsize:960,channels:2,params:{stereo:\"1\"},rate:64e3"
},
{
match: /setBitRate\(\i\){this\.setVoiceBitRate\(\i\)}/,
replace: "setBitRate($1){$self.setVoiceBitratePatch(this, $1)}"
},
{
match: /fec:!0/,
replace: "fec:$self.isFecEnabled()"
}
]
}],
settings,
isFecEnabled() {
console.log(`[StereoMic] Overriding FEC`)
return settings.store.enableFec
},
setVoiceBitratePatch(moduleContext: any, orgBitrate: number) {
console.log(`[StereoMic] Overriding Voice Bitrate (From ${orgBitrate/1000}kbps to ${settings.store.voiceBitrate}kbps)`)
moduleContext.setVoiceBitRate(settings.store.voiceBitrate*1000)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment