This commit is contained in:
Mirco Wittrien 2020-03-09 13:24:58 +01:00
parent c5e73ac003
commit 0766df4175
2 changed files with 16 additions and 13 deletions

View File

@ -1338,11 +1338,11 @@
plugin.patchedModules[patchType][mappedType] = plugin.patchedModules[patchType][type]; plugin.patchedModules[patchType][mappedType] = plugin.patchedModules[patchType][type];
delete plugin.patchedModules[patchType][type]; delete plugin.patchedModules[patchType][type];
} }
if (propertyFind) patchInstance((BDFDB.ModuleUtils.findByProperties(propertyFind, false) || {}).exports, mappedType, patchType, true); if (className && DiscordClasses[className]) checkForInstance(className, mappedType, patchType, WebModulesData.ForceObserve.includes(unmappedType), WebModulesData.NonRender.includes(unmappedType));
else if (propertyFind) patchInstance((BDFDB.ModuleUtils.findByProperties(propertyFind, false) || {}).exports, mappedType, patchType, true);
else if (WebModulesData.NonRender.includes(unmappedType)) patchInstance((BDFDB.ModuleUtils.findByName(name, false) || {}).exports, mappedType, patchType, true); else if (WebModulesData.NonRender.includes(unmappedType)) patchInstance((BDFDB.ModuleUtils.findByName(name, false) || {}).exports, mappedType, patchType, true);
else if (WebModulesData.MemoComponent.includes(unmappedType)) patchInstance((BDFDB.ModuleUtils.findByName(name, false) || {exports:{}}).exports.default, mappedType, patchType, true); else if (WebModulesData.MemoComponent.includes(unmappedType)) patchInstance((BDFDB.ModuleUtils.findByName(name, false) || {exports:{}}).exports.default, mappedType, patchType, true);
else if (!className) patchInstance(BDFDB.ModuleUtils.findByName(name), mappedType, patchType); else patchInstance(BDFDB.ModuleUtils.findByName(name), mappedType, patchType);
else if (DiscordClasses[className]) checkForInstance(className, mappedType, patchType, WebModulesData.ForceObserve.includes(unmappedType));
} }
} }
} }
@ -1359,26 +1359,29 @@
} }
} }
} }
function checkForInstance(className, type, patchType, forceobserve) { function patchFoundInstance(instance, type, patchType, exported) {
patchInstance(exported ? (BDFDB.ModuleUtils.find(m => m == instance.type, false) || {}).exports : instance, type, patchType, exported);
}
function checkForInstance(className, type, patchType, forceObserve, exported) {
const app = document.querySelector(BDFDB.dotCN.app), bdsettings = document.querySelector("#bd-settingspane-container " + BDFDB.dotCN.scrollerwrap); const app = document.querySelector(BDFDB.dotCN.app), bdsettings = document.querySelector("#bd-settingspane-container " + BDFDB.dotCN.scrollerwrap);
let instancefound = false; let instanceFound = false;
if (!forceobserve) { if (!forceObserve) {
if (app) { if (app) {
let appins = BDFDB.ReactUtils.findConstructor(app, type, {unlimited:true}) || BDFDB.ReactUtils.findConstructor(app, type, {unlimited:true, up:true}); let appins = BDFDB.ReactUtils.findConstructor(app, type, {unlimited:true}) || BDFDB.ReactUtils.findConstructor(app, type, {unlimited:true, up:true});
if (appins && (instancefound = true)) patchInstance(appins, type, patchType); if (appins && (instanceFound = true)) patchFoundInstance(appins, type, patchType, exported);
} }
if (!instancefound && bdsettings) { if (!instanceFound && bdsettings) {
let bdsettingsins = BDFDB.ReactUtils.findConstructor(bdsettings, type, {unlimited:true}); let bdsettingsins = BDFDB.ReactUtils.findConstructor(bdsettings, type, {unlimited:true});
if (bdsettingsins && (instancefound = true)) patchInstance(bdsettingsins, type, patchType); if (bdsettingsins && (instanceFound = true)) patchFoundInstance(bdsettingsins, type, patchType, exported);
} }
} }
if (!instancefound) { if (!instanceFound) {
let found = false, disclass = BDFDB.disCN[className], dotclass = BDFDB.dotCN[className]; let found = false, disclass = BDFDB.disCN[className], dotclass = BDFDB.dotCN[className];
for (let ele of document.querySelectorAll(dotclass)) { for (let ele of document.querySelectorAll(dotclass)) {
let ins = BDFDB.ReactUtils.getInstance(ele); let ins = BDFDB.ReactUtils.getInstance(ele);
if (isCorrectInstance(ins, type)) { if (isCorrectInstance(ins, type)) {
found = true; found = true;
patchInstance(ins, type, patchType); patchFoundInstance(ins, type, patchType, exported);
BDFDB.ModuleUtils.forceAllUpdates(plugin, type); BDFDB.ModuleUtils.forceAllUpdates(plugin, type);
break; break;
} }
@ -1392,7 +1395,7 @@
if (isCorrectInstance(ins, type)) { if (isCorrectInstance(ins, type)) {
found = true; found = true;
instanceobserver.disconnect(); instanceobserver.disconnect();
patchInstance(ins, type, patchType); patchFoundInstance(ins, type, patchType, exported);
BDFDB.ModuleUtils.forceAllUpdates(plugin, type); BDFDB.ModuleUtils.forceAllUpdates(plugin, type);
} }
} }

File diff suppressed because one or more lines are too long