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 * @name BDFDB
* @author DevilBro * @author DevilBro
* @authorId 278543574059057154 * @authorId 278543574059057154
* @version 3.4.1 * @version 3.4.2
* @description Required Library for DevilBro's Plugins * @description Required Library for DevilBro's Plugins
* @invite Jx3TjNS * @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien * @donate https://www.paypal.me/MircoWittrien
@ -1290,7 +1290,7 @@ module.exports = (_ => {
if (all) found.push(defaultExport ? r : req.c[i]); if (all) found.push(defaultExport ? r : req.c[i]);
else return 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]); if (all) found.push(defaultExport ? r : req.c[i]);
else return 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}; if (!module[methodName]) module[methodName] = _ => {return null};
let patches = module[methodName].BDFDB_Patches || {}; let patches = module[methodName].BDFDB_Patches || {};
for (let type in patchMethods) { for (let type in patchMethods) {
if (!patches[type]) { 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 originalMethod = module[methodName].__originalFunction || module[methodName]; const name = internalData && internalData[0] || config.name || (module.constructor ? (module.constructor.displayName || module.constructor.name) : "module");
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]; try {
const name = internalData && internalData[0] || config.name || (module.constructor ? (module.constructor.displayName || module.constructor.name) : "module"); if (!patches[type]) {
const mainCancel = BdApi.Patcher[type](Internal.name, internalData && internalData._originalModule || module, internalData && internalData._mappedItems[methodName] || methodName, function(...args) { const originalMethod = module[methodName].__originalFunction || module[methodName];
let callInsteadAfterwards = false, stopInsteadCall = false; const mainCancel = BdApi.Patcher[type](Internal.name, internalData && internalData._originalModule || module, internalData && internalData._mappedItems[methodName] || methodName, function(...args) {
const data = { let callInsteadAfterwards = false, stopInsteadCall = false;
component: module, const data = {
methodArguments: args[1], component: module,
returnValue: args[2], methodArguments: args[1],
originalMethod: originalMethod, returnValue: args[2],
originalMethodName: methodName originalMethod: originalMethod,
}; originalMethodName: methodName
if (type == "instead") { };
data.callOriginalMethod = _ => data.returnValue = data.originalMethod.apply(this && this !== window ? this : {}, data.methodArguments); if (type == "instead") {
data.callOriginalMethodAfterwards = _ => (callInsteadAfterwards = true, data.returnValue); data.callOriginalMethod = _ => data.returnValue = data.originalMethod.apply(this && this !== window ? this : {}, data.methodArguments);
data.stopOriginalMethodCall = _ => stopInsteadCall = true; 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] = {};
if (!patches[type].plugins[patchPriority]) patches[type].plugins[patchPriority] = {}; patches[type].plugins[patchPriority][pluginId] = (...args) => {
patches[type].plugins[patchPriority][pluginId] = (...args) => { if (config.once || !plugin.started) cancel();
if (config.once || !plugin.started) cancel(); return patchMethods[type](...args);
return patchMethods[type](...args); };
}; patches[type].plugins[patchPriority][pluginId].pluginName = pluginName;
patches[type].plugins[patchPriority][pluginId].pluginName = pluginName; patches[type].plugins[patchPriority][pluginId].pluginVersion = pluginVersion;
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) { if (BDFDB.ObjectUtils.is(plugin) && !config.once && !config.noCache) {