Add $$vencordPatchedSource

This commit is contained in:
Nuckyz 2024-08-18 00:22:02 -03:00
parent 6cc2f53501
commit 50bb6d867b
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
2 changed files with 15 additions and 1 deletions

View file

@ -209,6 +209,10 @@ function defineModulesFactoryGetter(id: PropertyKey, factory: WrappedModuleFacto
if (factory.$$vencordOriginal != null) {
factory.toString = newFactory.toString.bind(newFactory);
factory.$$vencordOriginal = newFactory;
if (factory.$$vencordPatchedSource != null) {
newFactory.$$vencordPatchedSource = newFactory.$$vencordPatchedSource;
}
} else {
factory = newFactory;
}
@ -366,6 +370,13 @@ function wrapAndPatchFactory(id: PropertyKey, originalFactory: AnyModuleFactory)
wrappedFactory.toString = originalFactory.toString.bind(originalFactory);
wrappedFactory.$$vencordOriginal = originalFactory;
if (patchedFactory !== originalFactory) {
const patchedSource = String(patchedFactory);
wrappedFactory.$$vencordPatchedSource = patchedSource;
originalFactory.$$vencordPatchedSource = patchedSource;
}
return wrappedFactory;
}

View file

@ -193,10 +193,13 @@ export type AnyWebpackRequire = ((moduleId: PropertyKey) => ModuleExports) & Par
};
/** exports can be anything, however initially it is always an empty object */
export type AnyModuleFactory = (this: ModuleExports, module: Module, exports: ModuleExports, require: AnyWebpackRequire) => void;
export type AnyModuleFactory = ((this: ModuleExports, module: Module, exports: ModuleExports, require: AnyWebpackRequire) => void) & {
$$vencordPatchedSource?: string;
};
export type WrappedModuleFactory = AnyModuleFactory & {
$$vencordOriginal?: AnyModuleFactory;
$$vencordPatchedSource?: string;
};
export type WrappedModuleFactories = Record<PropertyKey, WrappedModuleFactory>;