This repository has been archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
56 lines (42 loc) · 1.92 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const {readFileSync, existsSync} = require("fs");
const Module = require("module");
const path = require("path");
const originalLoad = Module._load;
Module._load = function (mod, parent) {
if (parent?.id?.indexOf("betterdiscord") > -1) {
switch (mod) {
case "fs": {
const exports = originalLoad.apply(this, arguments);
// BD would uninject kernel because it tries to clean up an "old injection method" but it would clean up
// kernel injection so I just trick it. :clueless:
return new Proxy(exports, {
get(t, k) {
if (k === "existsSync") return (...args) => {
if (args[0].endsWith("app")) return;
return t[k].apply(t, args);
}
return t[k];
}
});
};
}
}
return originalLoad.apply(this, arguments);
}
const original = Module._extensions[".js"];
Module._extensions[".js"] = function (mod, filename) {
if (mod.id?.includes?.("betterdiscord.asar") && mod.id.endsWith("injector.js")) {
let content = readFileSync(filename, "utf8");
if (existsSync(path.resolve(__dirname, "..", "vencord-loader"))) {
content = content.replace(`"appSettings"`, "appSettingsUndefined");
}
content = content.replace("static patchBrowserWindow(){", "static patchBrowserWindow(){return;");
content = content.replace("Z:()=>BetterDiscord", "Z:()=>(global.BetterDiscordInstance = BetterDiscord)");
return mod._compile(content, filename);
}
return original.apply(this, arguments);
}
require("electron").app.on("browser-window-created", (_, win) => {
BetterDiscordInstance?.setup(win);
});
queueMicrotask(() => require("./betterdiscord.asar"));