This commit is contained in:
Mirco Wittrien 2022-10-12 16:24:47 +02:00
parent 8627bb7f71
commit 2f373784a8
2 changed files with 41 additions and 11 deletions

View File

@ -2,7 +2,7 @@
* @name BDFDB
* @author DevilBro
* @authorId 278543574059057154
* @version 2.7.0
* @version 2.7.2
* @description Required Library for DevilBro's Plugins
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -570,7 +570,9 @@ module.exports = (_ => {
if (plugin.css) BDFDB.DOMUtils.appendLocalStyle(plugin.name, plugin.css);
BDFDB.PatchUtils.unpatch(plugin);
Internal.addModulePatches(plugin);
Internal.addContextPatches(plugin);
BDFDB.PluginUtils.translate(plugin);
@ -1104,7 +1106,7 @@ module.exports = (_ => {
libraryCSS = css;
const backupObj = getBackup(dataFileName, dataFilePath);
if (backupObj.backup && backupObj.hashIsSame) parseData(backupObj.backup);
if (backupObj.backup && backupObj.hashIsSame || true) parseData(backupObj.backup);
else request.get(`https://mwittrien.github.io/BetterDiscordAddons/Library/_res/${dataFileName}`, (e, r, b) => {
if ((e || !b || r.statusCode != 200) && tryAgain) return BDFDB.TimeUtils.timeout(_ => requestLibraryData(), 10000);
if (!e && b && r.statusCode == 200) {
@ -2152,7 +2154,6 @@ module.exports = (_ => {
Internal.addModulePatches = function (plugin) {
plugin = plugin == BDFDB && Internal || plugin;
BDFDB.PatchUtils.unpatch(plugin);
if (!plugin || !plugin.modulePatches) return;
let patchPriority = !isNaN(plugin.patchPriority) ? plugin.patchPriority : 5;
patchPriority = patchPriority < 1 ? (plugin == Internal ? 0 : 1) : (patchPriority > 9 ? (plugin == Internal ? 10 : 9) : Math.round(patchPriority));
@ -2168,6 +2169,15 @@ module.exports = (_ => {
}
}
};
Internal.addContextPatches = function (plugin) {
if (!InternalData.ContextMenuTypes || !BdApi || !BdApi.ContextMenu || typeof BdApi.ContextMenu.patch != "function") return;
plugin = plugin == BDFDB && Internal || plugin;
if (!plugin) return;
for (let type in InternalData.ContextMenuTypes) if (typeof plugin[`on${type}`] == "function") {
if (!BDFDB.ArrayUtils.is(plugin.patchCancels)) plugin.patchCancels = [];
plugin.patchCancels.push(BdApi.ContextMenu.patch(InternalData.ContextMenuTypes[type], (returnValue, props) => typeof plugin[`on${type}`] == "function" && plugin[`on${type}`]({returnvalue: returnValue, instance: {props}})));
}
};
Internal.initiatePatch = function (plugin, type, e) {
plugin = plugin == BDFDB && Internal || plugin;
if (BDFDB.ObjectUtils.is(plugin) && !plugin.stopping && e.instance) {
@ -2383,12 +2393,15 @@ module.exports = (_ => {
else if (useCache && Cache && Cache.modules && Cache.modules.patch && Cache.modules.patch[type] == module) return true;
else {
let foundModule = null;
if (InternalData.PatchModules[type].strings) foundModule = Internal.checkModuleStrings(module, InternalData.PatchModules[type].strings) ? module : null;
if (InternalData.PatchModules[type].nonStrings) foundModule = Internal.checkModuleStrings(module, InternalData.PatchModules[type].nonStrings, {hasNot: true}) ? module : null;
if (InternalData.PatchModules[type].strings) foundModule = Internal.checkModuleStrings(module._originalFunction || module, InternalData.PatchModules[type].strings) ? module : null;
if (InternalData.PatchModules[type].props) foundModule = Internal.checkModuleProps(module, InternalData.PatchModules[type].props) ? module : null;
if (InternalData.PatchModules[type].nonProps) foundModule = Internal.checkModuleProps(module, InternalData.PatchModules[type].nonProps, {hasNot: true}) ? module : null;
if (InternalData.PatchModules[type].protos) foundModule = Internal.checkModuleProtos(module, InternalData.PatchModules[type].protos) ? module : null;
if (InternalData.PatchModules[type].nonProtos) foundModule = Internal.checkModuleProtos(module, InternalData.PatchModules[type].nonProtos, {hasNot: true}) ? module : null;
if (foundModule) {
if (InternalData.PatchModules[type].nonStrings) foundModule = Internal.checkModuleStrings(module._originalFunction || module, InternalData.PatchModules[type].nonStrings, {hasNot: true}) ? module : null;
if (InternalData.PatchModules[type].nonProps) foundModule = Internal.checkModuleProps(module, InternalData.PatchModules[type].nonProps, {hasNot: true}) ? module : null;
if (InternalData.PatchModules[type].nonProtos) foundModule = Internal.checkModuleProtos(module, InternalData.PatchModules[type].nonProtos, {hasNot: true}) ? module : null;
}
if (type == "GuildChannelUserContextMenu" && module._originalFunction) console.log(foundModule, module);
if (foundModule) {
if (useCache) {
if (!Cache.modules.patch) Cache.modules.patch = {};
@ -3017,7 +3030,7 @@ module.exports = (_ => {
if (!user) return;
if (guildId && !channelId) channelId = (BDFDB.LibraryStores.GuildChannelStore.getDefaultChannel(guildId) || {}).id;
e = BDFDB.ListenerUtils.copyEvent(e.nativeEvent || e, (e.nativeEvent || e).currentTarget);
let type = channelId ? "GuildChannelUserContextMenu" : "UserGenericContextMenu";
let type = channelId ? "UserMemberContextMenu" : "UserGenericContextMenu";
let moduleFindData = InternalData.PatchModules[type] && InternalData.PatchModules[type].strings;
if (!moduleFindData) return;
let menu = BDFDB.ModuleUtils.findByString(moduleFindData, {noWarnings: true});
@ -8284,7 +8297,9 @@ module.exports = (_ => {
changeLogs = BDFDB.DataUtils.load(BDFDB, "changeLogs");
BDFDB.PluginUtils.checkChangeLog(BDFDB);
BDFDB.PatchUtils.unpatch(BDFDB);
Internal.addModulePatches(BDFDB);
Internal.addContextPatches(BDFDB);
BDFDB.PatchUtils.patch(BDFDB, LibraryModules.React, "createElement", {
before: e => {

View File

@ -322,16 +322,30 @@
"UserSummaryItem": {"strings": ["popoutUserId:", ".clickableAvatar"]},
"VideoForwardRef": {"strings": ["HTMLSourceElement", "autoPlay"], "funcStrings": ["externalRef"]}
},
"ContextMenuTypes": {
"AudioDeviceContextMenu": "audio-device-context",
"ChannelContextMenu": "channel-context",
"DeveloperContextMenu": "dev-context",
"GroupDMContextMenu": "gdm-context",
"GuildContextMenu": "guild-context",
"GuilDiscoveryContextMenu": "guild-discovery-context-menu",
"GuildEntryContextMenu": "guild-entry-context",
"GuildHeaderContextMenu": "guild-header-popout",
"ImageContextMenu": "image-context",
"MessageActionsContextMenu": "message-actions",
"MessageContextMenu": "message",
"ThreadContextMenu": "thread-context",
"UserContextMenu": "user-context",
"UserSettingsContextMenu": "user-settings-cog"
},
"PatchModules": {
"Account": {"protos": ["renderAvatarWithPopout", "renderCopiableNameTag", "renderCopiedSuccess"]},
"AnalyticsContext": {"props": ["ObjectTypes", "Objects", "Pages", "Sections"]},
"BlobMask": {"protos": ["getBadgePositionInterpolation", "getUpperBadgeStyles"]},
"DiscordTag": {"strings": ["hidePersonalInformation", "isVerifiedBot", "botType"]},
"DMUserContextMenu": {"strings": ["USER_ACTIONS_MENU_LABEL", "navId:\"user", ".DM_USER_MENU"]},
"EmojiPickerListRow": {"strings": ["emojiSize", "surrogateCodePoint", "EMOJI_FAVORITE_TOOLTIP"]},
"GroupDMUserContextMenu": {"strings": ["USER_ACTIONS_MENU_LABEL", "navId:\"user", ".GROUP_DM_USER_MENU"]},
"GuildChannelListContextMenu": {"strings": ["GUILD_ACTIONS_MENU_LABEL", "\"guild-context\",\"aria-label\""]},
"GuildContextMenu": {"strings": ["GUILD_ACTIONS_MENU_LABEL", "navId:\"guild", "GuildContextMenu"]},
"GuildChannelUserContextMenu": {"strings": ["USER_ACTIONS_MENU_LABEL", "navId:\"user", ".GUILD_CHANNEL_USER_MENU"]},
"GuildsBar": {"strings": ["unreadMentionsIndicatorTop", "disableAppDownload", ".GUILD_MEMBER_VERIFICATION"]},
"GuildSidebar": {"strings": ["\"guildsnav\"", "unreadMentionsIndicatorBottom"]},
"InboxHeader": {"strings": [".UNREADS", ".TODOS", ".controls"]},
@ -354,6 +368,7 @@
"UnreadDMs": {"strings": ["getMutablePrivateChannels", "selectedVoiceGuildId", ".selectedVoiceChannelId"]},
"UseCopyIdItem": {"strings": ["\"devmode-copy-id\""]},
"UserGenericContextMenu": {"strings": ["USER_ACTIONS_MENU_LABEL", "navId:\"user", ".USER_GENERIC_MENU"]},
"UserMemberContextMenu": {"strings": ["USER_ACTIONS_MENU_LABEL", "navId:\"user", ".GUILD_CHANNEL_USER_MENU"]},
"UsernameSection": {"strings": [".shouldCopyOnClick", ".userTagDiscriminatorNoNickname"]},
"UserPopoutAvatar": {"strings": ["isNonUserBot", "avatarHintInnerText", "avatarDecorationHint"]},
"UserPopoutInfo": {"strings": [".hasCustomStatus", ".premiumGuildSince", "openPremiumSettings"]},