Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More coremods/modules fixes #649

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/renderer/coremods/badges/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export async function start(): Promise<void> {
}

badgeElements.forEach((badgeElement) => {
if (badgeElement.id in badgeCache) {
if (badgeCache[badgeElement.id as keyof APIRepluggedBadges]) {
const { component, ...props } = badgeElement;
const badgeColor = badgeCache.custom.color;

Expand Down
8 changes: 2 additions & 6 deletions src/renderer/coremods/notices/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ function Announcement({
);
}

export function AnnouncementContainer({
originalRes,
}: {
originalRes: React.ReactElement;
}): React.ReactElement | null {
export function AnnouncementContainer(): React.ReactElement | undefined {
const [announcement, setAnnouncement] = React.useState<RepluggedAnnouncement | undefined>(
undefined,
);
Expand All @@ -57,5 +53,5 @@ export function AnnouncementContainer({
};
}, []);

return announcement ? <Announcement {...announcement} /> : originalRes;
return announcement && <Announcement {...announcement} />;
}
5 changes: 2 additions & 3 deletions src/renderer/coremods/notices/plaintextPatches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ export default [
find: /hasNotice:\w+,sidebarTheme:\w+/,
replacements: [
{
match: /(\w+\.base,children:\[.{0,50})(\w+\.\w+\?null.{10,30}}\)),/,
replace: (_, prefix, noticeWrapper) =>
`${prefix}${coremodStr}?.AnnouncementContainer?${coremodStr}.AnnouncementContainer({originalRes:${noticeWrapper}}):${noticeWrapper},`,
match: /\w+\.base,children:\[/,
replace: `$&${coremodStr}?.AnnouncementContainer?.(),`,
},
],
},
Expand Down
3 changes: 0 additions & 3 deletions src/renderer/coremods/rpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ type RPCMod = { commands: Commands };
let commands: Commands = {};

async function injectRpc(): Promise<void> {
//const rpcValidatorMod = await waitForProps<{
// fetchApplicationsRPC: (socket: Socket, client_id: string, origin: string) => Promise<void>;
//}>("fetchApplicationsRPC");
const rpcValidatorMod = await waitForModule<
Record<string, (socket: Socket, client_id: string, origin: string) => Promise<void>>
>(filters.bySource("Invalid Client ID"));
Expand Down
21 changes: 4 additions & 17 deletions src/renderer/modules/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { virtualMerge } from "src/renderer/util";
import { filters, getExportsForProps, waitForModule } from "../webpack";
import { filters, getExportsForProps, waitForModule, waitForProps } from "../webpack";

type StringConcat = (...rest: string[]) => string;

//const ConstantsCommon = await waitForProps<Record<string, unknown>>("Links", "RPCCommands");
const ConstantsCommon = await waitForModule<Record<string, unknown>>(
filters.bySource("dis.gd/request"),
);
//const Constants = await waitForProps<Record<string, unknown>>("Endpoints", "Routes");
const Constants = await waitForModule<Record<string, unknown>>(
filters.bySource("users/@me/relationships"),
);
Expand All @@ -18,10 +16,7 @@ export const Permissions = getExportsForProps<Record<string, bigint>>(ConstantsC
"MANAGE_GUILD",
]);
// OAuth2Scopes
export const Scopes = getExportsForProps<Record<string, string>>(ConstantsCommon, [
"BOT",
"GUILDS",
])!;
export const Scopes = await waitForProps<Record<string, string>>("BOT", "GUILDS");
// RPCCloseCodes
export const RPCErrors = getExportsForProps<Record<string, string | number>>(ConstantsCommon, [
"RATELIMITED",
Expand Down Expand Up @@ -72,16 +67,10 @@ export const UserFlags = getExportsForProps<Record<string, string | number>>(Con
])!;

// ThemeColor
//Ambiguous: should this be the just-dashed-names or --var(css-var-strings)?
// Go with the latter for now.
/*
export const CSSVariables = await waitForProps<Record<string, string>>(
"TEXT_NORMAL",
"BACKGROUND_PRIMARY",
);
*/
// We *should* be able to do props, but there's so much extra junk with the current search implementation.
export const CSSVariables = await waitForModule(filters.bySource('="var(--background-floating)"'));

interface ColorResponse {
hex: () => string;
Expand Down Expand Up @@ -127,11 +116,9 @@ interface ColorMod {
shadows: Record<string, ShadowColor>;
// eslint-disable-next-line @typescript-eslint/naming-convention
unsafe_rawColors: Record<string, UnsafeRawColor>;
layout: Record<string, string>;
}

// This could really be a search by props, for unsafe_rawColors.
export const ColorGenerator = await waitForModule<ColorMod>(
filters.bySource(/\w+\.unsafe_rawColors\[\w+\]\.resolve\(\w+\)/),
);
export const ColorGenerator = await waitForProps<ColorMod>("unsafe_rawColors", "layout");

export const Themes = ColorGenerator.themes;
30 changes: 16 additions & 14 deletions src/renderer/modules/common/fluxHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,32 @@ export interface FluxHooks {
) => T;
}

type EqualityComparer = (a: unknown[], b: unknown[]) => boolean;
type ShallowEqual = <T>(
a: T,
b: T,
excludeKeys?: string[],
callback?: (message: string) => void,
) => boolean;
type AreArraysShallowEqual = <T extends []>(a: T, b: T) => boolean;

const FluxEquatorMod = await waitForModule(filters.bySource("shallowEqual: unequal key"));
const isEqualObject = getFunctionBySource<EqualityComparer>(
FluxEquatorMod,
"shallowEqual: unequal key",
)!;
const isEqualArray = getFunctionBySource<EqualityComparer>(FluxEquatorMod, ".some")!;
const shallowEqualMod = await waitForModule(filters.bySource("shallowEqual: unequal key"));
const shallowEqual = getFunctionBySource<ShallowEqual>(shallowEqualMod, "shallowEqual")!;
const areArraysShallowEqual = getFunctionBySource<AreArraysShallowEqual>(shallowEqualMod, ".some")!;

//const fluxHooksMod = await waitForProps<FluxHooks>("useStateFromStores");
const fluxHooksMod = await waitForModule<Record<string, ValueOf<FluxHooks>>>(
const useStateFromStoresMod = await waitForModule<Record<string, ValueOf<FluxHooks>>>(
filters.bySource("useStateFromStores"),
);

const useStateFromStores: FluxHooks["useStateFromStores"] = getFunctionBySource(
fluxHooksMod,
const useStateFromStores = getFunctionBySource<FluxHooks["useStateFromStores"]>(
useStateFromStoresMod,
"useStateFromStores",
)!;

export default {
useStateFromStores,
statesWillNeverBeEqual: getFunctionBySource(fluxHooksMod, "return!1"),
statesWillNeverBeEqual: getFunctionBySource(useStateFromStoresMod, "return!1"),
useStateFromStoresArray: (stores, callback, deps) =>
useStateFromStores(stores, callback, deps, isEqualArray),
useStateFromStores(stores, callback, deps, areArraysShallowEqual),
useStateFromStoresObject: (stores, callback, deps) =>
useStateFromStores(stores, callback, deps, isEqualObject),
useStateFromStores(stores, callback, deps, shallowEqual),
} as FluxHooks;