Skip to content

Commit

Permalink
swc
Browse files Browse the repository at this point in the history
  • Loading branch information
yofukashino committed Jun 25, 2024
1 parent 1019eec commit 8b586c9
Show file tree
Hide file tree
Showing 13 changed files with 2,185 additions and 1,730 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-react": "^7.33.2",
"prettier": "^2.8.8",
"replugged": "4.7.9",
"replugged": "4.7.13",
"typescript": "^5.3.2"
}
}
3,768 changes: 2,078 additions & 1,690 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Components/AccountDetailsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const AccountDetailsButton = () => {
React.useEffect(() => {
setEnabled(SettingValues.get("enabled", defaultSettings.enabled));
}, [SettingValues.get("enabled", defaultSettings.enabled)]);

const Icon = <Icons.sound width="20" height="20" />;
const DisabledIcon = (
<Icons.sound width="20" height="20">
Expand Down
4 changes: 2 additions & 2 deletions src/Components/CenterTrayButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export default (): React.ReactElement | null => {
React.useEffect(() => {
setEnabled(SettingValues.get("enabled", defaultSettings.enabled));
}, [SettingValues.get("enabled", defaultSettings.enabled)]);
const Icon = <Icons.sound width="20" height="20" id="fake-deafen-enabled" />;
const Icon = <Icons.sound width="20" height="20" className="fake-deafen-enabled" />;
const DisabledIcon = (
<Icons.sound width="20" height="20" id="fake-deafen-disabled">
<Icons.sound width="20" height="20" className="fake-deafen-disabled">
<polygon
style={{
fill: "#a61616",
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const Settings = (): React.ReactElement => {
</SwitchItem>
<SwitchItem
note="Add a button in the voice chat's center tray to toggle faking voice status."
{...Utils.useSetting(SettingValues, "userPanel", defaultSettings.userPanel)}>
{...Utils.useSetting(SettingValues, "centerTray", defaultSettings.centerTray)}>
Center Tray
</SwitchItem>
<Category
Expand Down
13 changes: 12 additions & 1 deletion src/injections/CenterControlTray.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { webpack } from "replugged";
import { SettingValues } from "../index";
import CenterTrayButton from "../Components/CenterTrayButton";
import { PluginInjector } from "../index";
import Modules from "../lib/requiredModules";
import Utils from "../lib/utils";
import Types from "../types";
import { defaultSettings } from "../lib/consts";

export default (): void => {
PluginInjector.after(Modules.CenterControlTray, "default", (_args, res: Types.ReactTree) => {
const { CenterControlTray } = Modules;
const loader = webpack.getFunctionKeyBySource(
CenterControlTray,
"CenterControlTray: currentUser cannot be undefined",
);

PluginInjector.after(CenterControlTray, loader, (_args, res: Types.ReactTree) => {
if (!SettingValues.get("centerTray", defaultSettings.centerTray)) return res;
const Container = Utils.findInReactTree(
res,
(c: Types.ReactTree) => Array.isArray(c?.props?.children) && c.type === "div",
Expand Down
8 changes: 7 additions & 1 deletion src/injections/GatewayConnection.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { webpack } from "replugged";
import { PluginInjector, SettingValues } from "../index";
import { defaultSettings } from "../lib/consts";
import Modules from "../lib/requiredModules";
import Types from "../types";

export default (): void => {
const GatewayConnection = webpack.getFunctionBySource<Types.DefaultTypes.AnyFunction>(
Modules.GatewayConnection,
"voiceServerPing()",
);

PluginInjector.before(
Modules.GatewayConnection.default.prototype,
GatewayConnection.prototype,
"voiceStateUpdate",
(args: [Types.voiceStateUpdateArgs]) => {
const [voiceStateUpdateArgs] = args;
Expand Down
90 changes: 68 additions & 22 deletions src/lib/requiredModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,86 @@ import Types from "../types";
export const Modules: Types.Modules = {};

Modules.loadModules = async (): Promise<void> => {
Modules.WindowInfoStore ??= await webpack.waitForProps<Types.WindowInfoStore>(
"isFocused",
"isElementFullScreen",
"addChangeListener",
"removeChangeListener",
);
Modules.SoundUtilsModule = await webpack
.waitForModule<Types.GenericModule>(webpack.filters.bySource("SoundUtils"), {
timeout: 10000,
})
.catch(() => {
throw new Error("Failed To Find SoundUtils Module");
});

Modules.SoundUtils ??= await webpack.waitForProps<Types.SoundUtils>(
"playSound",
"createSound",
"createSoundForPack",
);
Modules.KeybindUtils ??= await webpack.waitForProps<Types.KeybindUtils>("toCombo");
Modules.SoundUtils ??= {
createSound: webpack.getFunctionBySource(Modules.SoundUtilsModule, "return new"),
createSoundForPack: webpack.getFunctionBySource(Modules.SoundUtilsModule, /return .\(null/),
playSound: webpack.getFunctionBySource(Modules.SoundUtilsModule, ".play()"),
};

Modules.KeybindUtilsModule ??= await webpack
.waitForModule<Types.GenericModule>(webpack.filters.bySource("numpad plus"), {
timeout: 10000,
})
.catch(() => {
throw new Error("Failed To Find KeybindUtils Module");
});

Modules.KeybindUtils ??= {
toCombo: webpack.getFunctionBySource(Modules.KeybindUtilsModule, "numpad plus"),
toBrowserEvents: webpack.getFunctionBySource(Modules.KeybindUtilsModule, "{keyCode:0,"),
};

Modules.GatewayConnection ??= await webpack
.waitForModule<Types.GatewayConnection>(webpack.filters.bySource("CALL_CONNECT=13"), {
timeout: 10000,
})
.catch(() => {
throw new Error("Failed To Find GatewayConnection Module");
});

Modules.GatewayConnection ??= await webpack.waitForProps<Types.GatewayConnection>("Opcode");
Modules.CenterControlTray ??= await webpack
.waitForModule<Types.CenterControlTray>(webpack.filters.bySource('.BROADCAST="BROADCAST"'), {
timeout: 10000,
})
.catch(() => {
throw new Error("Failed To Find CenterControlTray Module");
});

Modules.CenterControlTray ??= await webpack.waitForProps<Types.CenterControlTray>("GoLiveButton");
Modules.CenterControlButton ??= await webpack
.waitForProps<{
CenterControlButton: Types.CenterControlButton;
}>("CenterControlButton")
.then(({ CenterControlButton }) => CenterControlButton);
Modules.IdleHandler ??= await webpack.waitForProps<Types.IdleHandler>("usePreventIdle");
Modules.PanelButton ??= await webpack.waitForModule<Types.PanelButton>(
webpack.filters.bySource("Masks.PANEL_BUTTON"),
);
.waitForModule(webpack.filters.bySource(".centerButton,"), { timeout: 10000 })
.then((mod) => webpack.getFunctionBySource<Types.CenterControlButton>(mod, ".centerButton,"))
.catch(() => {
throw new Error("Failed To Find CenterControlButton Module");
});

Modules.IdleHandlerModule ??= await webpack
.waitForModule<Types.GenericModule>(webpack.filters.bySource("return{preventIdle:"), {
timeout: 10000,
})
.catch(() => {
throw new Error("Failed To Find IdleHandler Module");
});

Modules.IdleHandler ??= {
usePreventIdle: webpack.getFunctionBySource(Modules.IdleHandlerModule, "return{preventIdle:"),
default: webpack.getFunctionBySource(Modules.IdleHandlerModule, "div"),
};

Modules.PanelButton ??= await webpack
.waitForModule<Types.PanelButton>(webpack.filters.bySource("Masks.PANEL_BUTTON"), {
timeout: 10000,
})
.catch(() => {
throw new Error("Failed To Find PanelButton Module");
});

Modules.AudioResolverPromise = webpack.waitForModule<Types.AudioResolver>(
webpack.filters.bySource("./mute.mp3"),
{ raw: true },
);

Modules.GatewayConnectionStore ??=
webpack.getByStoreName<Types.GatewayConnectionStore>("GatewayConnectionStore");
Modules.MediaEngineStore ??= webpack.getByStoreName<Types.MediaEngineStore>("MediaEngineStore");
Modules.WindowStore ??= webpack.getByStoreName<Types.WindowStore>("WindowStore");
};

export default Modules;
2 changes: 1 addition & 1 deletion src/listeners/CleanCallback.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CurrentlyPressed } from "../index";
import Modules from "../lib/requiredModules";
export const cleanKeybindsCallback = (): void => {
if (Modules.WindowInfoStore.isFocused()) CurrentlyPressed.clear();
if (Modules.WindowStore.isFocused()) CurrentlyPressed.clear();
};
4 changes: 2 additions & 2 deletions src/listeners/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { keybindListener } from "./KeybindListener";

export const addListeners = async (): Promise<void> => {
await Modules.loadModules();
Modules.WindowInfoStore?.addChangeListener(cleanKeybindsCallback);
Modules.WindowStore?.addChangeListener(cleanKeybindsCallback);
window.addEventListener("keydown", keybindListener);
window.addEventListener("keyup", keybindListener);
};
export const removeListeners = (): void => {
Modules.WindowInfoStore.removeChangeListener(cleanKeybindsCallback);
Modules.WindowStore.removeChangeListener(cleanKeybindsCallback);
window.removeEventListener("keydown", keybindListener);
window.removeEventListener("keyup", keybindListener);
};
Expand Down
8 changes: 5 additions & 3 deletions src/plaintextPatches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ export default [
find: "isCopiedStreakGodlike",
replacements: [
{
match: /this\.renderNameZone\(\),\(0,.\.\w+\)\([\w_$]+.\w+,{grow:0,children:\[/,
replace: `$&replugged.plugins.getExports("dev.tharki.FakeDeafen")?._addPanelButton?.()??null,`,
match: /this\.renderNameZone\(\),\(0,.\.\w+\)\(.+?\.\w+,{grow:0,children:\[/,
replace: (suffix: string) =>
`${suffix}replugged.plugins.getExports("dev.tharki.FakeDeafen")?._addPanelButton?.()??null,`,
},
],
},
Expand All @@ -15,7 +16,8 @@ export default [
replacements: [
{
match: /null==\w+\?void 0:\w+\.selfDeaf/,
replace: `$&&&replugged.webpack.getByStoreName("MediaEngineStore")?.isDeaf?.()`,
replace: (suffix: string) =>
`${suffix}&&replugged.webpack.getByStoreName("MediaEngineStore")?.isDeaf?.()`,
},
],
},
Expand Down
4 changes: 2 additions & 2 deletions src/style.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[class*="withTagAsButton"] {
[class^="panels_"] > [class^="container_"] > [class^="avatarWrapper_"] + div {
min-width: 0;
flex: 1;
flex: 1 1 min-content !important;
}

.keybindRecorder-container:not(:hover) .closeButton {
Expand Down
9 changes: 5 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ export namespace Types {
export type UtilTree = util.Tree;
export type ReactTree = util.Tree & React.ReactElement;
export interface GenericModule extends Record<string, DefaultTypes.AnyFunction> {}
export interface WindowInfoStore {
export interface WindowStore extends Store {
isFocused: () => boolean;
addChangeListener: (callback: DefaultTypes.AnyFunction) => void;
removeChangeListener: (callback: DefaultTypes.AnyFunction) => void;
isElementFullScreen: () => boolean;
}
export interface AudioResolver {
Expand Down Expand Up @@ -313,14 +311,17 @@ export namespace Types {
}
export interface Modules {
loadModules?: () => Promise<void>;
WindowInfoStore?: WindowInfoStore;
WindowStore?: WindowStore;
SoundUtilsModule?: GenericModule;
SoundUtils?: SoundUtils;
KeybindUtilsModule?: GenericModule;
KeybindUtils?: KeybindUtils;
GatewayConnectionStore?: GatewayConnectionStore;
GatewayConnection?: GatewayConnection;
MediaEngineStore?: MediaEngineStore;
CenterControlTray?: CenterControlTray;
CenterControlButton?: CenterControlButton;
IdleHandlerModule?: GenericModule;
IdleHandler?: IdleHandler;
PanelButton?: PanelButton;
AudioResolverPromise?: Promise<AudioResolver>;
Expand Down

0 comments on commit 8b586c9

Please sign in to comment.