Merge branch 'immediate-finds' into immediate-finds-modules-proxy

This commit is contained in:
Nuckyz 2024-06-27 18:42:57 -03:00
commit 1f2c26cdba
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
9 changed files with 88 additions and 42 deletions

View file

@ -1,7 +1,7 @@
{ {
"name": "vencord", "name": "vencord",
"private": "true", "private": "true",
"version": "1.9.1", "version": "1.9.2",
"description": "The cutest Discord client mod", "description": "The cutest Discord client mod",
"homepage": "https://github.com/Vendicated/Vencord#readme", "homepage": "https://github.com/Vendicated/Vencord#readme",
"bugs": { "bugs": {

View file

@ -131,7 +131,7 @@ export const SettingsStore = new SettingsStoreClass(settings, {
if (path === "plugins" && key in plugins) if (path === "plugins" && key in plugins)
return target[key] = { return target[key] = {
enabled: IS_REPORTER ?? plugins[key].required ?? plugins[key].enabledByDefault ?? false enabled: IS_REPORTER || plugins[key].required || plugins[key].enabledByDefault || false
}; };
// Since the property is not set, check if this is a plugin's setting and if so, try to resolve // Since the property is not set, check if this is a plugin's setting and if so, try to resolve

View file

@ -75,23 +75,32 @@ async function runReporter() {
if (findResult != null) { if (findResult != null) {
if (findResult.$$vencordCallbackCalled != null && findResult.$$vencordCallbackCalled()) { if (findResult.$$vencordCallbackCalled != null && findResult.$$vencordCallbackCalled()) {
result = findResult; result = findResult;
break;
} }
if (findResult[SYM_PROXY_INNER_GET] != null) { if (findResult[SYM_PROXY_INNER_GET] != null) {
result = findResult[SYM_PROXY_INNER_VALUE]; result = findResult[SYM_PROXY_INNER_VALUE];
if (result != null && searchType === "mapMangledModule") { break;
for (const innerMap in result) {
if (result[innerMap][SYM_PROXY_INNER_GET] != null) {
throw new Error("Webpack Find Fail");
}
}
}
} }
if (findResult[SYM_LAZY_COMPONENT_INNER] != null) { if (findResult[SYM_LAZY_COMPONENT_INNER] != null) {
result = findResult[SYM_LAZY_COMPONENT_INNER](); result = findResult[SYM_LAZY_COMPONENT_INNER]();
break;
} }
if (searchType === "mapMangledModule") {
result = findResult;
for (const innerMap in result) {
if (result[innerMap][SYM_PROXY_INNER_GET] != null && result[innerMap][SYM_PROXY_INNER_VALUE] == null) {
throw new Error("Webpack Find Fail");
}
}
}
// This can happen if a `find` was immediately found
result = findResult;
} }
break; break;
@ -142,7 +151,7 @@ async function runReporter() {
const [code, mappers] = parsedArgs; const [code, mappers] = parsedArgs;
const parsedFailedMappers = Object.entries<any>(mappers) const parsedFailedMappers = Object.entries<any>(mappers)
.filter(([key]) => result == null || result[key][SYM_PROXY_INNER_GET] != null) .filter(([key]) => result == null || (result[key][SYM_PROXY_INNER_GET] != null && result[key][SYM_PROXY_INNER_VALUE] == null))
.map(([key, filter]) => { .map(([key, filter]) => {
let parsedFilter: string; let parsedFilter: string;

View file

@ -9,7 +9,7 @@ import { Link } from "@components/Link";
import { openInviteModal } from "@utils/discord"; import { openInviteModal } from "@utils/discord";
import { Margins } from "@utils/margins"; import { Margins } from "@utils/margins";
import { closeAllModals, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal"; import { closeAllModals, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
import { findByProps, findComponentByCode } from "@webpack"; import { filters, findComponentByCode, mapMangledModule } from "@webpack";
import { Button, FluxDispatcher, Forms, GuildStore, NavigationRouter, Text, TextInput, useEffect, useMemo, UserStore, useState } from "@webpack/common"; import { Button, FluxDispatcher, Forms, GuildStore, NavigationRouter, Text, TextInput, useEffect, useMemo, UserStore, useState } from "@webpack/common";
import { GUILD_ID, INVITE_KEY, RAW_SKU_ID } from "../../lib/constants"; import { GUILD_ID, INVITE_KEY, RAW_SKU_ID } from "../../lib/constants";
@ -19,7 +19,10 @@ import { AvatarDecorationModalPreview } from "../components";
const FileUpload = findComponentByCode("fileUploadInput,"); const FileUpload = findComponentByCode("fileUploadInput,");
const HelpMessage = findComponentByCode(".iconDiv,", "messageType"); const HelpMessage = findComponentByCode(".iconDiv,", "messageType");
const HelpMessageTypes = findByProps("POSITIVE", "WARNING");
const { HelpMessageTypes } = mapMangledModule('POSITIVE=3]="POSITIVE', {
HelpMessageTypes: filters.byProps("POSITIVE", "WARNING"),
});
function useObjectURL(object: Blob | MediaSource | null) { function useObjectURL(object: Blob | MediaSource | null) {
const [url, setUrl] = useState<string | null>(null); const [url, setUrl] = useState<string | null>(null);

View file

@ -29,7 +29,7 @@ import { Menu } from "@webpack/common";
import { Guild } from "discord-types/general"; import { Guild } from "discord-types/general";
const updateGuildNotificationSettings = findByPropsAndExtract("updateGuildNotificationSettings"); const updateGuildNotificationSettings = findByPropsAndExtract("updateGuildNotificationSettings");
const OnboardingChannelUtils = mapMangledModule(".onboardExistingMember(", { const { toggleShowAllChannels } = mapMangledModule(".onboardExistingMember(", {
toggleShowAllChannels: m => { toggleShowAllChannels: m => {
const s = String(m); const s = String(m);
return s.length < 100 && !s.includes("onboardExistingMember") && !s.includes("getOptedInChannels"); return s.length < 100 && !s.includes("onboardExistingMember") && !s.includes("getOptedInChannels");
@ -111,7 +111,7 @@ function applyDefaultSettings(guildId: string | null) {
}); });
} }
if (settings.store.showAllChannels && isOptInEnabledForGuild(guildId)) { if (settings.store.showAllChannels && isOptInEnabledForGuild(guildId)) {
OnboardingChannelUtils.toggleShowAllChannels(guildId); toggleShowAllChannels(guildId);
} }
} }

View file

@ -14,7 +14,7 @@ import { Timestamp } from "@webpack/common";
import type { Message } from "discord-types/general"; import type { Message } from "discord-types/general";
import type { HTMLAttributes } from "react"; import type { HTMLAttributes } from "react";
const DateFormatUtils = mapMangledModule("millisecondsInUnit:", { const { calendarFormat, dateFormat, isSameDay } = mapMangledModule("millisecondsInUnit:", {
calendarFormat: filters.byCode("sameElse"), calendarFormat: filters.byCode("sameElse"),
dateFormat: filters.byCode(':").concat'), dateFormat: filters.byCode(':").concat'),
isSameDay: filters.byCode("Math.abs(+"), isSameDay: filters.byCode("Math.abs(+"),
@ -46,14 +46,14 @@ function ReplyTimestamp({
return ( return (
<Timestamp <Timestamp
className="vc-reply-timestamp" className="vc-reply-timestamp"
compact={DateFormatUtils.isSameDay(refTimestamp, baseTimestamp)} compact={isSameDay(refTimestamp, baseTimestamp)}
timestamp={refTimestamp} timestamp={refTimestamp}
isInline={false} isInline={false}
> >
<Sep>[</Sep> <Sep>[</Sep>
{DateFormatUtils.isSameDay(refTimestamp, baseTimestamp) {isSameDay(refTimestamp, baseTimestamp)
? DateFormatUtils.dateFormat(refTimestamp, "LT") ? dateFormat(refTimestamp, "LT")
: DateFormatUtils.calendarFormat(refTimestamp) : calendarFormat(refTimestamp)
} }
<Sep>]</Sep> <Sep>]</Sep>
</Timestamp> </Timestamp>

View file

@ -22,12 +22,11 @@ import { isNonNullish } from "@utils/guards";
import { sleep } from "@utils/misc"; import { sleep } from "@utils/misc";
import { Queue } from "@utils/Queue"; import { Queue } from "@utils/Queue";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import { webpackDependantLazy } from "@webpack";
import { Constants, FluxDispatcher, RestAPI, UserProfileStore, UserStore, useState } from "@webpack/common"; import { Constants, FluxDispatcher, RestAPI, UserProfileStore, UserStore, useState } from "@webpack/common";
import { type ComponentType, type ReactNode } from "react"; import { type ComponentType, type ReactNode } from "react";
// LYING to the type checker here // LYING to the type checker here
const UserFlags = webpackDependantLazy(() => Constants.UserFlags as Record<string, number>); const UserFlags = Constants.UserFlags as Record<string, number>;
const badges: Record<string, ProfileBadge> = { const badges: Record<string, ProfileBadge> = {
active_developer: { id: "active_developer", description: "Active Developer", icon: "6bdc42827a38498929a4920da12695d9", link: "https://support-dev.discord.com/hc/en-us/articles/10113997751447" }, active_developer: { id: "active_developer", description: "Active Developer", icon: "6bdc42827a38498929a4920da12695d9", link: "https://support-dev.discord.com/hc/en-us/articles/10113997751447" },
bug_hunter_level_1: { id: "bug_hunter_level_1", description: "Discord Bug Hunter", icon: "2717692c7dca7289b35297368a940dd0", link: "https://support.discord.com/hc/en-us/articles/360046057772-Discord-Bugs" }, bug_hunter_level_1: { id: "bug_hunter_level_1", description: "Discord Bug Hunter", icon: "2717692c7dca7289b35297368a940dd0", link: "https://support.discord.com/hc/en-us/articles/360046057772-Discord-Bugs" },

View file

@ -119,3 +119,22 @@ export function proxyLazy<T = AnyObject>(factory: () => T, attempts = 5): ProxyL
return proxy; return proxy;
} }
/**
* A string which returns the factory result every time its value is accessed.
*
* @param factory Factory returning the string to use as the value
*/
export function lazyString<T extends string>(factory: () => T) {
const descriptor: PropertyDescriptor = {
configurable: true,
enumerable: false,
writable: false,
value: factory
};
return Object.create(String.prototype, {
toString: descriptor,
valueOf: descriptor
});
}

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
*/ */
import { makeLazy, proxyLazy } from "@utils/lazy"; import { lazyString, makeLazy, proxyLazy } from "@utils/lazy";
import { LazyComponent, LazyComponentType, SYM_LAZY_COMPONENT_INNER } from "@utils/lazyReact"; import { LazyComponent, LazyComponentType, SYM_LAZY_COMPONENT_INNER } from "@utils/lazyReact";
import { Logger } from "@utils/Logger"; import { Logger } from "@utils/Logger";
import { canonicalizeMatch } from "@utils/patches"; import { canonicalizeMatch } from "@utils/patches";
@ -436,37 +436,53 @@ export function findByFactoryCode<T = AnyObject>(...code: string[] | [...string[
* @returns Unmangled exports as specified in mappers * @returns Unmangled exports as specified in mappers
*/ */
export function mapMangledModule<S extends PropertyKey>(code: string | string[], mappers: Record<S, FilterFn>) { export function mapMangledModule<S extends PropertyKey>(code: string | string[], mappers: Record<S, FilterFn>) {
const result = find<Record<S, ModuleExports>>(filters.byFactoryCode(...Array.isArray(code) ? code : [code]), exports => { const mapping = {} as Record<S, ModuleExports>;
const mapping = {} as Record<S, ModuleExports>; const setters = {} as Record<S, (innerValue: ModuleExports) => void>;
outer: for (const newName in mappers) {
for (const newName in mappers) { // Wrapper to select whether the parent factory filter or child mapper filter failed when the error is thrown
const filter = mappers[newName]; const errorMsgWrapper = lazyString(() => `Webpack mapMangledModule ${callbackCalled ? "mapper" : "factory"} filter matched no module. Filter: ${printFilter(callbackCalled ? mappers[newName] : factoryFilter)}`);
if (typeof exports === "object") { const [proxy, setInnerValue] = proxyInner(errorMsgWrapper, "Webpack find with proxy called on a primitive value.");
for (const exportKey in exports) { mapping[newName] = proxy;
const exportValue = exports[exportKey]; setters[newName] = setInnerValue;
}
if (exportValue != null && filter(exportValue)) { const factoryFilter = filters.byFactoryCode(...Array.isArray(code) ? code : [code]);
mapping[newName] = exportValue;
continue outer; let callbackCalled = false;
} waitFor(factoryFilter, exports => {
callbackCalled = true;
for (const exportKey in exports) {
const exportValue = exports[exportKey];
if (exportValue == null) continue;
for (const newName in mappers) {
const filter = mappers[newName];
if (filter(exportValue)) {
setters[newName](exportValue);
} }
} }
const [proxy] = proxyInner(`Webpack mapMangledModule mapper filter matched no module. Filter: ${printFilter(filter)}`, "Webpack find with proxy called on a primitive value.");
// Use the proxy to throw errors because no export matched the filter
mapping[newName] = proxy;
} }
return mapping;
}, { isIndirect: true }); }, { isIndirect: true });
if (IS_REPORTER) { if (IS_REPORTER) {
webpackSearchHistory.push(["mapMangledModule", [result, code, mappers]]); webpackSearchHistory.push(["mapMangledModule", [mapping, code, mappers]]);
} }
return result; if (callbackCalled) {
for (const innerMap in mapping) {
const innerValue = mapping[innerMap];
if (innerValue[SYM_PROXY_INNER_VALUE] != null) {
mapping[innerMap] = innerValue[SYM_PROXY_INNER_VALUE];
}
}
}
return mapping;
} }
/** /**