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",
"private": "true",
"version": "1.9.1",
"version": "1.9.2",
"description": "The cutest Discord client mod",
"homepage": "https://github.com/Vendicated/Vencord#readme",
"bugs": {

View file

@ -131,7 +131,7 @@ export const SettingsStore = new SettingsStoreClass(settings, {
if (path === "plugins" && key in plugins)
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

View file

@ -75,23 +75,32 @@ async function runReporter() {
if (findResult != null) {
if (findResult.$$vencordCallbackCalled != null && findResult.$$vencordCallbackCalled()) {
result = findResult;
break;
}
if (findResult[SYM_PROXY_INNER_GET] != null) {
result = findResult[SYM_PROXY_INNER_VALUE];
if (result != null && searchType === "mapMangledModule") {
for (const innerMap in result) {
if (result[innerMap][SYM_PROXY_INNER_GET] != null) {
throw new Error("Webpack Find Fail");
}
}
}
break;
}
if (findResult[SYM_LAZY_COMPONENT_INNER] != null) {
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;
@ -142,7 +151,7 @@ async function runReporter() {
const [code, mappers] = parsedArgs;
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]) => {
let parsedFilter: string;

View file

@ -9,7 +9,7 @@ import { Link } from "@components/Link";
import { openInviteModal } from "@utils/discord";
import { Margins } from "@utils/margins";
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 { GUILD_ID, INVITE_KEY, RAW_SKU_ID } from "../../lib/constants";
@ -19,7 +19,10 @@ import { AvatarDecorationModalPreview } from "../components";
const FileUpload = findComponentByCode("fileUploadInput,");
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) {
const [url, setUrl] = useState<string | null>(null);

View file

@ -29,7 +29,7 @@ import { Menu } from "@webpack/common";
import { Guild } from "discord-types/general";
const updateGuildNotificationSettings = findByPropsAndExtract("updateGuildNotificationSettings");
const OnboardingChannelUtils = mapMangledModule(".onboardExistingMember(", {
const { toggleShowAllChannels } = mapMangledModule(".onboardExistingMember(", {
toggleShowAllChannels: m => {
const s = String(m);
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)) {
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 { HTMLAttributes } from "react";
const DateFormatUtils = mapMangledModule("millisecondsInUnit:", {
const { calendarFormat, dateFormat, isSameDay } = mapMangledModule("millisecondsInUnit:", {
calendarFormat: filters.byCode("sameElse"),
dateFormat: filters.byCode(':").concat'),
isSameDay: filters.byCode("Math.abs(+"),
@ -46,14 +46,14 @@ function ReplyTimestamp({
return (
<Timestamp
className="vc-reply-timestamp"
compact={DateFormatUtils.isSameDay(refTimestamp, baseTimestamp)}
compact={isSameDay(refTimestamp, baseTimestamp)}
timestamp={refTimestamp}
isInline={false}
>
<Sep>[</Sep>
{DateFormatUtils.isSameDay(refTimestamp, baseTimestamp)
? DateFormatUtils.dateFormat(refTimestamp, "LT")
: DateFormatUtils.calendarFormat(refTimestamp)
{isSameDay(refTimestamp, baseTimestamp)
? dateFormat(refTimestamp, "LT")
: calendarFormat(refTimestamp)
}
<Sep>]</Sep>
</Timestamp>

View file

@ -22,12 +22,11 @@ import { isNonNullish } from "@utils/guards";
import { sleep } from "@utils/misc";
import { Queue } from "@utils/Queue";
import definePlugin from "@utils/types";
import { webpackDependantLazy } from "@webpack";
import { Constants, FluxDispatcher, RestAPI, UserProfileStore, UserStore, useState } from "@webpack/common";
import { type ComponentType, type ReactNode } from "react";
// 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> = {
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" },

View file

@ -119,3 +119,22 @@ export function proxyLazy<T = AnyObject>(factory: () => T, attempts = 5): ProxyL
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
*/
import { makeLazy, proxyLazy } from "@utils/lazy";
import { lazyString, makeLazy, proxyLazy } from "@utils/lazy";
import { LazyComponent, LazyComponentType, SYM_LAZY_COMPONENT_INNER } from "@utils/lazyReact";
import { Logger } from "@utils/Logger";
import { canonicalizeMatch } from "@utils/patches";
@ -436,37 +436,53 @@ export function findByFactoryCode<T = AnyObject>(...code: string[] | [...string[
* @returns Unmangled exports as specified in mappers
*/
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) {
const filter = mappers[newName];
for (const newName in mappers) {
// Wrapper to select whether the parent factory filter or child mapper filter failed when the error is thrown
const errorMsgWrapper = lazyString(() => `Webpack mapMangledModule ${callbackCalled ? "mapper" : "factory"} filter matched no module. Filter: ${printFilter(callbackCalled ? mappers[newName] : factoryFilter)}`);
if (typeof exports === "object") {
for (const exportKey in exports) {
const exportValue = exports[exportKey];
const [proxy, setInnerValue] = proxyInner(errorMsgWrapper, "Webpack find with proxy called on a primitive value.");
mapping[newName] = proxy;
setters[newName] = setInnerValue;
}
if (exportValue != null && filter(exportValue)) {
mapping[newName] = exportValue;
continue outer;
}
const factoryFilter = filters.byFactoryCode(...Array.isArray(code) ? code : [code]);
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 });
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;
}
/**