2024-09-01 20:38:00 -04:00
|
|
|
/*
|
|
|
|
* Vencord, a Discord client mod
|
|
|
|
* Copyright (c) 2023 Vendicated and contributors
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
|
|
|
|
|
|
|
import "./styles.css";
|
|
|
|
|
|
|
|
import { DataStore } from "@api/index";
|
|
|
|
import { definePluginSettings } from "@api/Settings";
|
|
|
|
import { Devs, EquicordDevs } from "@utils/constants";
|
|
|
|
import definePlugin, { OptionType } from "@utils/types";
|
|
|
|
import { React } from "@webpack/common";
|
|
|
|
|
|
|
|
import { SoundOverrideComponent } from "./components/SoundOverrideComponent";
|
|
|
|
import { makeEmptyOverride, SoundOverride, soundTypes } from "./types";
|
|
|
|
|
|
|
|
const OVERRIDES_KEY = "CustomSounds_overrides";
|
|
|
|
let overrides: Record<string, SoundOverride> = soundTypes.reduce((result, sound) => ({ ...result, [sound.id]: makeEmptyOverride() }), {});
|
|
|
|
|
|
|
|
const settings = definePluginSettings({
|
|
|
|
overrides: {
|
|
|
|
type: OptionType.COMPONENT,
|
|
|
|
description: "",
|
|
|
|
component: () =>
|
|
|
|
<>
|
|
|
|
{soundTypes.map(type =>
|
|
|
|
<SoundOverrideComponent
|
|
|
|
key={type.id}
|
|
|
|
type={type}
|
|
|
|
override={overrides[type.id]}
|
|
|
|
onChange={() => DataStore.set(OVERRIDES_KEY, overrides)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export function isOverriden(id: string): boolean {
|
|
|
|
return overrides[id]?.enabled ?? false;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function findOverride(id: string): SoundOverride | null {
|
|
|
|
const result = overrides[id];
|
|
|
|
if (!result?.enabled)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default definePlugin({
|
|
|
|
name: "CustomSounds",
|
|
|
|
description: "Replace Discord's sounds with your own.",
|
|
|
|
authors: [Devs.TheKodeToad, EquicordDevs.SpikeHD],
|
|
|
|
patches: [
|
|
|
|
// sound class
|
|
|
|
{
|
2024-09-10 22:41:59 -04:00
|
|
|
find: '"_ensureAudioPromise"',
|
2024-09-01 20:38:00 -04:00
|
|
|
replacement: [
|
|
|
|
// override URL
|
|
|
|
{
|
2024-09-11 00:31:17 -04:00
|
|
|
match: /\i\([0-9]+\)\(.{1,20}(\i),"\.mp3"\)/,
|
|
|
|
replace: "$self.findOverride($1)?.url || $&"
|
2024-09-01 20:38:00 -04:00
|
|
|
},
|
|
|
|
// override volume
|
|
|
|
{
|
2024-09-10 22:41:59 -04:00
|
|
|
match: /Math.min\(\i\.\i\.getOutputVolume\(\).{0,20}volume/,
|
2024-09-01 20:38:00 -04:00
|
|
|
replace: "$& * ($self.findOverride(this.name)?.volume ?? 100) / 100"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
// force classic soundpack for overriden sounds
|
|
|
|
{
|
|
|
|
find: ".playWithListener().then",
|
|
|
|
replacement: {
|
|
|
|
match: /\i\.\i\.getSoundpack\(\)/,
|
|
|
|
replace: '$self.isOverriden(arguments[0]) ? "classic" : $&'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
settings,
|
|
|
|
findOverride,
|
|
|
|
isOverriden,
|
|
|
|
async start() {
|
|
|
|
overrides = await DataStore.get(OVERRIDES_KEY) ?? {};
|
|
|
|
for (const type of soundTypes)
|
|
|
|
overrides[type.id] ??= makeEmptyOverride();
|
|
|
|
}
|
|
|
|
});
|