Update 0BDFDB.plugin.js

This commit is contained in:
Mirco Wittrien 2023-10-25 11:33:54 +02:00
parent 11c20db477
commit de8739cd78
1 changed files with 48 additions and 46 deletions

View File

@ -2,7 +2,7 @@
* @name BDFDB
* @author DevilBro
* @authorId 278543574059057154
* @version 3.4.1
* @version 3.4.2
* @description Required Library for DevilBro's Plugins
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -1290,7 +1290,7 @@ module.exports = (_ => {
if (all) found.push(defaultExport ? r : req.c[i]);
else return defaultExport ? r : req.c[i];
}
else for (let key of Object.keys(m)) if (key.length < 4 && m[key] && !!(r = filter(m[key]))) {
else if (Object.keys(m).length < 400) for (let key of Object.keys(m)) if (m[key] && !!(r = filter(m[key]))) {
if (all) found.push(defaultExport ? r : req.c[i]);
else return defaultExport ? r : req.c[i];
}
@ -2258,52 +2258,54 @@ module.exports = (_ => {
if (!module[methodName]) module[methodName] = _ => {return null};
let patches = module[methodName].BDFDB_Patches || {};
for (let type in patchMethods) {
if (!patches[type]) {
const originalMethod = module[methodName].__originalFunction || module[methodName];
const internalData = (Object.entries(InternalData.LibraryModules).find(n => n && n[0] && LibraryModules[n[0]] == module && n[1] && n[1]._originalModule && n[1]._mappedItems[methodName]) || [])[1];
const name = internalData && internalData[0] || config.name || (module.constructor ? (module.constructor.displayName || module.constructor.name) : "module");
const mainCancel = BdApi.Patcher[type](Internal.name, internalData && internalData._originalModule || module, internalData && internalData._mappedItems[methodName] || methodName, function(...args) {
let callInsteadAfterwards = false, stopInsteadCall = false;
const data = {
component: module,
methodArguments: args[1],
returnValue: args[2],
originalMethod: originalMethod,
originalMethodName: methodName
};
if (type == "instead") {
data.callOriginalMethod = _ => data.returnValue = data.originalMethod.apply(this && this !== window ? this : {}, data.methodArguments);
data.callOriginalMethodAfterwards = _ => (callInsteadAfterwards = true, data.returnValue);
data.stopOriginalMethodCall = _ => stopInsteadCall = true;
const internalData = (Object.entries(InternalData.LibraryModules).find(n => n && n[0] && LibraryModules[n[0]] == module && n[1] && n[1]._originalModule && n[1]._mappedItems[methodName]) || [])[1];
const name = internalData && internalData[0] || config.name || (module.constructor ? (module.constructor.displayName || module.constructor.name) : "module");
try {
if (!patches[type]) {
const originalMethod = module[methodName].__originalFunction || module[methodName];
const mainCancel = BdApi.Patcher[type](Internal.name, internalData && internalData._originalModule || module, internalData && internalData._mappedItems[methodName] || methodName, function(...args) {
let callInsteadAfterwards = false, stopInsteadCall = false;
const data = {
component: module,
methodArguments: args[1],
returnValue: args[2],
originalMethod: originalMethod,
originalMethodName: methodName
};
if (type == "instead") {
data.callOriginalMethod = _ => data.returnValue = data.originalMethod.apply(this && this !== window ? this : {}, data.methodArguments);
data.callOriginalMethodAfterwards = _ => (callInsteadAfterwards = true, data.returnValue);
data.stopOriginalMethodCall = _ => stopInsteadCall = true;
}
if (args[0] != module) data.instance = args[0] || {props: args[1][0]};
for (let priority in patches[type].plugins) for (let id in BDFDB.ObjectUtils.sort(patches[type].plugins[priority])) {
let tempReturn = BDFDB.TimeUtils.suppress(patches[type].plugins[priority][id], `"${type}" callback of ${methodName} in ${name}`, {name: patches[type].plugins[priority][id].pluginName, version: patches[type].plugins[priority][id].pluginVersion})(data);
if (type != "before" && tempReturn !== undefined) data.returnValue = tempReturn;
}
if (type == "instead" && callInsteadAfterwards && !stopInsteadCall) BDFDB.TimeUtils.suppress(data.callOriginalMethod, `originalMethod of ${methodName} in ${name}`, {name: "Discord"})();
if (type != "before") return (methodName == "render" || methodName == "type") && data.returnValue === undefined ? null : data.returnValue;
});
module[methodName].BDFDB_Patches = patches;
patches[type] = {plugins: {}, cancel: _ => {
if (!config.noCache) BDFDB.ArrayUtils.remove(Internal.patchCancels, patches[type].cancel, true);
delete patches[type];
if (!config.noCache && BDFDB.ObjectUtils.isEmpty(patches)) delete module[methodName].BDFDB_Patches;
mainCancel();
}};
if (!config.noCache) {
if (!BDFDB.ArrayUtils.is(Internal.patchCancels)) Internal.patchCancels = [];
Internal.patchCancels.push(patches[type].cancel);
}
if (args[0] != module) data.instance = args[0] || {props: args[1][0]};
for (let priority in patches[type].plugins) for (let id in BDFDB.ObjectUtils.sort(patches[type].plugins[priority])) {
let tempReturn = BDFDB.TimeUtils.suppress(patches[type].plugins[priority][id], `"${type}" callback of ${methodName} in ${name}`, {name: patches[type].plugins[priority][id].pluginName, version: patches[type].plugins[priority][id].pluginVersion})(data);
if (type != "before" && tempReturn !== undefined) data.returnValue = tempReturn;
}
if (type == "instead" && callInsteadAfterwards && !stopInsteadCall) BDFDB.TimeUtils.suppress(data.callOriginalMethod, `originalMethod of ${methodName} in ${name}`, {name: "Discord"})();
if (type != "before") return (methodName == "render" || methodName == "type") && data.returnValue === undefined ? null : data.returnValue;
});
module[methodName].BDFDB_Patches = patches;
patches[type] = {plugins: {}, cancel: _ => {
if (!config.noCache) BDFDB.ArrayUtils.remove(Internal.patchCancels, patches[type].cancel, true);
delete patches[type];
if (!config.noCache && BDFDB.ObjectUtils.isEmpty(patches)) delete module[methodName].BDFDB_Patches;
mainCancel();
}};
if (!config.noCache) {
if (!BDFDB.ArrayUtils.is(Internal.patchCancels)) Internal.patchCancels = [];
Internal.patchCancels.push(patches[type].cancel);
}
}
if (!patches[type].plugins[patchPriority]) patches[type].plugins[patchPriority] = {};
patches[type].plugins[patchPriority][pluginId] = (...args) => {
if (config.once || !plugin.started) cancel();
return patchMethods[type](...args);
};
patches[type].plugins[patchPriority][pluginId].pluginName = pluginName;
patches[type].plugins[patchPriority][pluginId].pluginVersion = pluginVersion;
if (!patches[type].plugins[patchPriority]) patches[type].plugins[patchPriority] = {};
patches[type].plugins[patchPriority][pluginId] = (...args) => {
if (config.once || !plugin.started) cancel();
return patchMethods[type](...args);
};
patches[type].plugins[patchPriority][pluginId].pluginName = pluginName;
patches[type].plugins[patchPriority][pluginId].pluginVersion = pluginVersion;
} catch (err) {BDFDB.LogUtils.error(["Could not patch Component!", `"${type}" Patch of ${methodName} in ${name}`, err], plugin);}
}
}
if (BDFDB.ObjectUtils.is(plugin) && !config.once && !config.noCache) {