This commit is contained in:
Mirco Wittrien 2019-12-05 11:08:22 +01:00
parent ef8bfd6871
commit 755751918e
2 changed files with 64 additions and 51 deletions

View File

@ -930,67 +930,57 @@
BDFDB.ModuleUtils = {}; BDFDB.ModuleUtils = {};
BDFDB.ModuleUtils.cached = {}; BDFDB.ModuleUtils.cached = {};
BDFDB.ModuleUtils.find = function (filter) { BDFDB.ModuleUtils.find = function (filter, getExport) {
getExport = typeof getExport != "boolean" ? true : getExport;
var req = InternalBDFDB.getWebModuleReq(); var req = InternalBDFDB.getWebModuleReq();
for (let i in req.c) if (req.c.hasOwnProperty(i)) { for (let i in req.c) if (req.c.hasOwnProperty(i)) {
var m = req.c[i].exports; var m = req.c[i].exports;
if (m && (typeof m == "object" || typeof m == "function") && filter(m)) return m; if (m && (typeof m == "object" || typeof m == "function") && filter(m)) return getExport ? m : req.c[i];
if (m && m.__esModule) for (let j in m) if (m[j] && (typeof m[j] == "object" || typeof m[j] == "function") && filter(m[j])) return m[j]; if (m && m.__esModule) for (let j in m) if (m[j] && (typeof m[j] == "object" || typeof m[j] == "function") && filter(m[j])) return getExport ? m[j] : req.c[i];
} }
}; };
BDFDB.ModuleUtils.findByProperties = function (properties) { BDFDB.ModuleUtils.findByProperties = function (...properties) {
properties = BDFDB.ArrayUtils.is(properties) ? properties : Array.from(arguments); properties = properties.flat(10);
var cachestring = JSON.stringify(properties); let getExport = properties.pop();
if (!BDFDB.ObjectUtils.is(BDFDB.ModuleUtils.cached.prop)) BDFDB.ModuleUtils.cached.prop = {}; if (typeof getExport != "boolean") {
if (BDFDB.ModuleUtils.cached.prop[cachestring]) return BDFDB.ModuleUtils.cached.prop[cachestring]; properties.push(getExport);
else { getExport = true;
var m = BDFDB.ModuleUtils.find(m => properties.every(prop => m[prop] !== undefined));
if (m) {
BDFDB.ModuleUtils.cached.prop[cachestring] = m;
return m;
}
else BDFDB.LogUtils.warn(cachestring + " [properties] not found in WebModules");
} }
return InternalBDFDB.findModule("prop", JSON.stringify(properties), m => properties.every(prop => m[prop] !== undefined), getExport);
}; };
BDFDB.ModuleUtils.findByName = function (name) { BDFDB.ModuleUtils.findByName = function (name, getExport) {
var cachestring = JSON.stringify(name); return InternalBDFDB.findModule("name", JSON.stringify(name), m => m.displayName === name, typeof getExport != "boolean" ? true : getExport);
if (!BDFDB.ObjectUtils.is(BDFDB.ModuleUtils.cached.name)) BDFDB.ModuleUtils.cached.name = {}; };
if (BDFDB.ModuleUtils.cached.name[cachestring]) return BDFDB.ModuleUtils.cached.name[cachestring]; BDFDB.ModuleUtils.findByString = function (...strings) {
else { strings = strings.flat(10);
var m = BDFDB.ModuleUtils.find(m => m.displayName === name); let getExport = strings.pop();
if (m) { if (typeof getExport != "boolean") {
BDFDB.ModuleUtils.cached.name[cachestring] = m; strings.push(getExport);
return m; getExport = true;
}
else BDFDB.LogUtils.warn(cachestring + " [name] not found in WebModules");
} }
return InternalBDFDB.findModule("string", JSON.stringify(strings), m => strings.every(string => typeof m == "function" && (m.toString().indexOf(string) > -1 || m.originalsource && m.originalsource.toString().indexOf(string) > -1)), getExport);
}; };
BDFDB.ModuleUtils.findByString = function (strings) { BDFDB.ModuleUtils.findByPrototypes = function (...protoprops) {
strings = BDFDB.ArrayUtils.is(strings) ? strings : Array.from(arguments); protoprops = protoprops.flat(10);
var cachestring = JSON.stringify(strings); let getExport = protoprops.pop();
if (!BDFDB.ObjectUtils.is(BDFDB.ModuleUtils.cached.string)) BDFDB.ModuleUtils.cached.string = {}; if (typeof getExport != "boolean") {
if (BDFDB.ModuleUtils.cached.string[cachestring]) return BDFDB.ModuleUtils.cached.string[cachestring]; protoprops.push(getExport);
else { getExport = true;
var m = BDFDB.ModuleUtils.find(m => strings.every(string => typeof m == "function" && m.toString().indexOf(string) > -1));
if (m) {
BDFDB.ModuleUtils.cached.string[cachestring] = m;
return m;
}
else BDFDB.LogUtils.warn(cachestring + " [string] not found in WebModules");
} }
return InternalBDFDB.findModule("proto", JSON.stringify(protoprops), m => m.prototype && protoprops.every(prop => m.prototype[prop] !== undefined), getExport);
}; };
BDFDB.ModuleUtils.findByPrototypes = function (protoprops) { InternalBDFDB.findModule = function (type, cachestring, filter, getExport) {
protoprops = BDFDB.ArrayUtils.is(protoprops) ? protoprops : Array.from(arguments); if (!BDFDB.ObjectUtils.is(BDFDB.ModuleUtils.cached[type])) BDFDB.ModuleUtils.cached[type] = {module:{}, export:{}};
var cachestring = JSON.stringify(protoprops); if (getExport && BDFDB.ModuleUtils.cached[type].export[cachestring]) return BDFDB.ModuleUtils.cached[type].export[cachestring];
if (!BDFDB.ObjectUtils.is(BDFDB.ModuleUtils.cached.proto)) BDFDB.ModuleUtils.cached.proto = {}; else if (!getExport && BDFDB.ModuleUtils.cached[type].module[cachestring]) return BDFDB.ModuleUtils.cached[type].module[cachestring];
if (BDFDB.ModuleUtils.cached.proto[cachestring]) return BDFDB.ModuleUtils.cached.proto[cachestring];
else { else {
var m = BDFDB.ModuleUtils.find(m => m.prototype && protoprops.every(prop => m.prototype[prop] !== undefined)); var m = BDFDB.ModuleUtils.find(filter, getExport);
if (m) { if (m) {
BDFDB.ModuleUtils.cached.proto[cachestring] = m; if (getExport) BDFDB.ModuleUtils.cached[type].export[cachestring] = m;
else BDFDB.ModuleUtils.cached[type].module[cachestring] = m;
return m; return m;
} }
else BDFDB.LogUtils.warn(cachestring + " [prototypes] not found in WebModules"); else BDFDB.LogUtils.warn(`${cachestring} [${type}] not found in WebModules`);
} }
}; };
InternalBDFDB.getWebModuleReq = function () { InternalBDFDB.getWebModuleReq = function () {
@ -1063,10 +1053,10 @@
try {WebModulesData.GlobalModules["V2C_PluginCard"] = V2C_PluginCard;} catch(err) {BDFDB.LogUtils.warn(`Could not find global Module "V2C_PluginCard"`);} try {WebModulesData.GlobalModules["V2C_PluginCard"] = V2C_PluginCard;} catch(err) {BDFDB.LogUtils.warn(`Could not find global Module "V2C_PluginCard"`);}
try {WebModulesData.GlobalModules["V2C_ThemeCard"] = V2C_ThemeCard;} catch(err) {BDFDB.LogUtils.warn(`Could not find global Module "V2C_ThemeCard"`);} try {WebModulesData.GlobalModules["V2C_ThemeCard"] = V2C_ThemeCard;} catch(err) {BDFDB.LogUtils.warn(`Could not find global Module "V2C_ThemeCard"`);}
BDFDB.ModuleUtils.patch = function (plugin, module, modulefunctions, patchfunctions) { BDFDB.ModuleUtils.patch = function (plugin, module, modulefunctions, patchfunctions, injectOldSource) {
if (!plugin || !module || !modulefunctions || !BDFDB.ObjectUtils.is(patchfunctions)) return null; if (!plugin || !module || !modulefunctions || !BDFDB.ObjectUtils.is(patchfunctions)) return null;
patchfunctions = BDFDB.ObjectUtils.filter(patchfunctions, type => WebModulesData.Patchtypes.includes(type), true); patchfunctions = BDFDB.ObjectUtils.filter(patchfunctions, type => WebModulesData.Patchtypes.includes(type), true);
if (BDFDB.ObjectUtils.isEmpty(patchfunctions)) return; if (BDFDB.ObjectUtils.isEmpty(patchfunctions)) return null;
const pluginname = typeof plugin === "string" ? plugin : plugin.name; const pluginname = typeof plugin === "string" ? plugin : plugin.name;
const pluginid = pluginname.toLowerCase(); const pluginid = pluginname.toLowerCase();
if (!module.BDFDBpatch) module.BDFDBpatch = {}; if (!module.BDFDBpatch) module.BDFDBpatch = {};
@ -1103,6 +1093,7 @@
else BDFDB.TimeUtils.suppress(data.callOriginalMethod, `originalMethod of ${modulefunction} in ${module.constructor ? module.constructor.displayName || module.constructor.name : "module"}`)(); else BDFDB.TimeUtils.suppress(data.callOriginalMethod, `originalMethod of ${modulefunction} in ${module.constructor ? module.constructor.displayName || module.constructor.name : "module"}`)();
return modulefunction == "render" && data.returnValue === undefined ? null : data.returnValue; return modulefunction == "render" && data.returnValue === undefined ? null : data.returnValue;
}; };
module[modulefunction].originalsource = originalfunction;
} }
for (let type in patchfunctions) if (typeof patchfunctions[type] == "function") { for (let type in patchfunctions) if (typeof patchfunctions[type] == "function") {
module.BDFDBpatch[modulefunction][type][pluginid] = patchfunctions[type]; module.BDFDBpatch[modulefunction][type][pluginid] = patchfunctions[type];
@ -1322,6 +1313,7 @@
if (BDFDB.InternalData.patchMenuQueries[type].module) InternalBDFDB.patchContextMenuPlugin(plugin, type, BDFDB.InternalData.patchMenuQueries[type].module); if (BDFDB.InternalData.patchMenuQueries[type].module) InternalBDFDB.patchContextMenuPlugin(plugin, type, BDFDB.InternalData.patchMenuQueries[type].module);
else BDFDB.InternalData.patchMenuQueries[type].query.push(plugin); else BDFDB.InternalData.patchMenuQueries[type].query.push(plugin);
} }
for (let type of LibraryComponents.ContextMenus._NonRenderMenus) if (typeof plugin[`on${type}`] === "function") InternalBDFDB.patchNonRenderContextMenuPlugin(plugin, type, LibraryComponents.ContextMenus._Modules[type]);
}; };
InternalBDFDB.patchContextMenuPlugin = (plugin, type, module) => { InternalBDFDB.patchContextMenuPlugin = (plugin, type, module) => {
if (module && module.prototype) { if (module && module.prototype) {
@ -1340,6 +1332,11 @@
} }
} }
}; };
InternalBDFDB.patchNonRenderContextMenuPlugin = (plugin, type, module) => {
BDFDB.ModuleUtils.patch(plugin, module.exports, "default", {after: e => {
if (e.thisObject && e.returnValue && typeof plugin[`on${type}`] === "function") plugin[`on${type}`]({instance:{props:e.methodArguments[0]}, returnvalue:e.returnValue, methodname:"render"});
}});
};
InternalBDFDB.patchPopoutPlugin = (plugin, type, module) => { InternalBDFDB.patchPopoutPlugin = (plugin, type, module) => {
if (module && module.prototype) { if (module && module.prototype) {
// REMOVE // REMOVE
@ -6895,19 +6892,35 @@
}; };
LibraryComponents.ContextMenus = {}; LibraryComponents.ContextMenus = {};
LibraryComponents.ContextMenus._NormalMenus = ["ChannelContextMenu", "DeveloperContextMenu", "GuildContextMenu", "GuildRoleContextMenu", "MessageContextMenu", "NativeContextMenu", "ScreenshareContextMenu", "SlateContextMenu", "UserContextMenu", "UserSettingsCogContextMenu"]; LibraryComponents.ContextMenus._NormalMenus = ["DeveloperContextMenu", "GuildRoleContextMenu", "MessageContextMenu", "NativeContextMenu", "ScreenshareContextMenu", "UserSettingsCogContextMenu"];
LibraryComponents.ContextMenus._FluxMenus = ["ApplicationContextMenu", "GroupDMContextMenu"]; LibraryComponents.ContextMenus._FluxMenus = ["ApplicationContextMenu", "GroupDMContextMenu"];
LibraryComponents.ContextMenus._NonRenderMenus = ["ChannelContextMenu", "GuildContextMenu", "UserContextMenu"];
LibraryComponents.ContextMenus._Modules = {};
LibraryComponents.ContextMenus.ApplicationContextMenu = BDFDB.ModuleUtils.findByName("FluxContainer(ApplicationContextMenu)"); LibraryComponents.ContextMenus.ApplicationContextMenu = BDFDB.ModuleUtils.findByName("FluxContainer(ApplicationContextMenu)");
LibraryComponents.ContextMenus.ChannelContextMenu = BDFDB.ModuleUtils.findByString("Error - no such ctx menu type", BDFDB.DiscordConstants.ContextMenuTypes.CHANNEL_LIST_TEXT); LibraryComponents.ContextMenus.ChannelContextMenu = BDFDB.ModuleUtils.findByString("Error - no such ctx menu type", BDFDB.DiscordConstants.ContextMenuTypes.CHANNEL_LIST_TEXT);
LibraryComponents.ContextMenus._Modules.ChannelContextMenu = BDFDB.ModuleUtils.findByString("Error - no such ctx menu type", BDFDB.DiscordConstants.ContextMenuTypes.CHANNEL_LIST_TEXT, false);
LibraryComponents.ContextMenus.DeveloperContextMenu = BDFDB.ModuleUtils.findByName("DeveloperContextMenu"); LibraryComponents.ContextMenus.DeveloperContextMenu = BDFDB.ModuleUtils.findByName("DeveloperContextMenu");
LibraryComponents.ContextMenus.GroupDMContextMenu = BDFDB.ModuleUtils.findByName("FluxContainer(GroupDMContextMenu)"); LibraryComponents.ContextMenus.GroupDMContextMenu = BDFDB.ModuleUtils.findByName("FluxContainer(GroupDMContextMenu)");
LibraryComponents.ContextMenus.GuildContextMenu = BDFDB.ModuleUtils.findByString("Error - no such ctx menu type", BDFDB.DiscordConstants.ContextMenuTypes.GUILD_CHANNEL_LIST); LibraryComponents.ContextMenus.GuildContextMenu = BDFDB.ModuleUtils.findByString("Error - no such ctx menu type", BDFDB.DiscordConstants.ContextMenuTypes.GUILD_CHANNEL_LIST);
LibraryComponents.ContextMenus._Modules.GuildContextMenu = BDFDB.ModuleUtils.findByString("Error - no such ctx menu type", BDFDB.DiscordConstants.ContextMenuTypes.GUILD_CHANNEL_LIST, false);
LibraryComponents.ContextMenus.GuildRoleContextMenu = BDFDB.ModuleUtils.findByName("GuildRoleContextMenu"); LibraryComponents.ContextMenus.GuildRoleContextMenu = BDFDB.ModuleUtils.findByName("GuildRoleContextMenu");
LibraryComponents.ContextMenus.MessageContextMenu = BDFDB.ModuleUtils.findByName("MessageContextMenu"); LibraryComponents.ContextMenus.MessageContextMenu = BDFDB.ModuleUtils.findByName("MessageContextMenu");
LibraryComponents.ContextMenus.NativeContextMenu = BDFDB.ModuleUtils.findByName("NativeContextMenu"); LibraryComponents.ContextMenus.NativeContextMenu = BDFDB.ModuleUtils.findByName("NativeContextMenu");
LibraryComponents.ContextMenus.ScreenshareContextMenu = BDFDB.ModuleUtils.findByName("ScreenshareContextMenu"); LibraryComponents.ContextMenus.ScreenshareContextMenu = BDFDB.ModuleUtils.findByName("ScreenshareContextMenu");
LibraryComponents.ContextMenus.SlateContextMenu = BDFDB.ModuleUtils.findByName("SlateContextMenu");
LibraryComponents.ContextMenus.UserContextMenu = BDFDB.ModuleUtils.findByString("Error - no such ctx menu type", BDFDB.DiscordConstants.ContextMenuTypes.USER_CHANNEL_MEMBERS); LibraryComponents.ContextMenus.UserContextMenu = BDFDB.ModuleUtils.findByString("Error - no such ctx menu type", BDFDB.DiscordConstants.ContextMenuTypes.USER_CHANNEL_MEMBERS);
LibraryComponents.ContextMenus._Modules.UserContextMenu = BDFDB.ModuleUtils.findByString("Error - no such ctx menu type", BDFDB.DiscordConstants.ContextMenuTypes.USER_CHANNEL_MEMBERS, false);
LibraryComponents.ContextMenus.UserSettingsCogContextMenu = BDFDB.ModuleUtils.findByName("UserSettingsCogContextMenu"); LibraryComponents.ContextMenus.UserSettingsCogContextMenu = BDFDB.ModuleUtils.findByName("UserSettingsCogContextMenu");
LibraryComponents.FavButton = BDFDB.ReactUtils.getValue(window.BDFDB, "LibraryComponents.FavButton") || reactInitialized && class BDFDB_FavButton extends LibraryModules.React.Component { LibraryComponents.FavButton = BDFDB.ReactUtils.getValue(window.BDFDB, "LibraryComponents.FavButton") || reactInitialized && class BDFDB_FavButton extends LibraryModules.React.Component {

File diff suppressed because one or more lines are too long