Merge branch 'modules-proxy-patches' into immediate-finds-modules-proxy
This commit is contained in:
commit
2656b60347
|
@ -190,6 +190,7 @@ const moduleFactoriesHandler: ProxyHandler<PatchedModuleFactories> = {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Patches a module factory.
|
* Patches a module factory.
|
||||||
*
|
*
|
||||||
|
@ -218,10 +219,8 @@ function patchFactory(id: PropertyKey, factory: ModuleFactory) {
|
||||||
const patch = patches[i];
|
const patch = patches[i];
|
||||||
if (patch.predicate && !patch.predicate()) continue;
|
if (patch.predicate && !patch.predicate()) continue;
|
||||||
|
|
||||||
// indexOf is faster than includes because it doesn't check if searchString is a RegExp
|
|
||||||
// https://github.com/moonlight-mod/moonlight/blob/53ae39d4010277f49f3b70bebbd27b9cbcdb1c8b/packages/core/src/patch.ts#L61
|
|
||||||
const moduleMatches = typeof patch.find === "string"
|
const moduleMatches = typeof patch.find === "string"
|
||||||
? code.indexOf(patch.find) !== -1
|
? code.includes(patch.find)
|
||||||
: (patch.find.global && (patch.find.lastIndex = 0), patch.find.test(code));
|
: (patch.find.global && (patch.find.lastIndex = 0), patch.find.test(code));
|
||||||
|
|
||||||
if (!moduleMatches) continue;
|
if (!moduleMatches) continue;
|
||||||
|
|
|
@ -46,7 +46,7 @@ export const filters = {
|
||||||
if (typeof m !== "function") return false;
|
if (typeof m !== "function") return false;
|
||||||
const s = Function.prototype.toString.call(m);
|
const s = Function.prototype.toString.call(m);
|
||||||
for (const c of code) {
|
for (const c of code) {
|
||||||
if (s.indexOf(c) === -1) return false;
|
if (!s.includes(c)) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
@ -476,7 +476,7 @@ export const findModuleId = traceFunction("findModuleId", function findModuleId(
|
||||||
const str = String(wreq.m[id]);
|
const str = String(wreq.m[id]);
|
||||||
|
|
||||||
for (const c of code) {
|
for (const c of code) {
|
||||||
if (str.indexOf(c) === -1) continue outer;
|
if (!str.includes(c)) continue outer;
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -729,7 +729,7 @@ export function search(...filters: Array<string | RegExp>) {
|
||||||
const factory = factories[id];
|
const factory = factories[id];
|
||||||
const factoryStr = String(factory);
|
const factoryStr = String(factory);
|
||||||
for (const filter of filters) {
|
for (const filter of filters) {
|
||||||
if (typeof filter === "string" && factoryStr.indexOf(filter) === -1) continue outer;
|
if (typeof filter === "string" && !factoryStr.includes(filter)) continue outer;
|
||||||
if (filter instanceof RegExp && !filter.test(factoryStr)) continue outer;
|
if (filter instanceof RegExp && !filter.test(factoryStr)) continue outer;
|
||||||
}
|
}
|
||||||
results[id] = factory;
|
results[id] = factory;
|
||||||
|
|
Loading…
Reference in a new issue