aboutsummaryrefslogtreecommitdiff
path: root/src/patcher.ts
diff options
context:
space:
mode:
authorVen <vendicated@riseup.net>2022-10-22 18:17:02 +0200
committerGitHub <noreply@github.com>2022-10-22 18:17:02 +0200
commita7dbd73547104540218d4699fcf643fca727d2fc (patch)
tree6c9adfac3a7b975733d7c3ece8adebf0f3e5c566 /src/patcher.ts
parentc116d00d037b9831b2d5cac4df15c10b0c6c4085 (diff)
downloadVencord-a7dbd73547104540218d4699fcf643fca727d2fc.tar.gz
Vencord-a7dbd73547104540218d4699fcf643fca727d2fc.tar.bz2
Vencord-a7dbd73547104540218d4699fcf643fca727d2fc.zip
Windows: Patch host updater to reinject (#138)
Diffstat (limited to 'src/patcher.ts')
-rw-r--r--src/patcher.ts36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/patcher.ts b/src/patcher.ts
index eca35f0..14f0812 100644
--- a/src/patcher.ts
+++ b/src/patcher.ts
@@ -17,13 +17,27 @@
*/
import electron, { app, BrowserWindowConstructorOptions } from "electron";
-import { join } from "path";
+import { dirname, join } from "path";
import { initIpc } from "./ipcMain";
import { installExt } from "./ipcMain/extensions";
import { readSettings } from "./ipcMain/index";
+import { readFileSync } from "fs";
console.log("[Vencord] Starting up...");
+// Our injector file at app/index.js
+const injectorPath = require.main!.filename;
+// The original app.asar
+const discordPath = join(dirname(injectorPath), "..", "app.asar");
+// Full main path Discord uses
+require.main!.filename = join(discordPath, "app_bootstrap/index.js");
+// @ts-ignore Untyped method? Dies from cringe
+app.setAppPath(discordPath);
+
+// Repatch after host updates on Windows
+if (process.platform === "win32")
+ require("./patchWin32Updater");
+
class BrowserWindow extends electron.BrowserWindow {
constructor(options: BrowserWindowConstructorOptions) {
if (options?.webPreferences?.preload && options.title) {
@@ -88,3 +102,23 @@ electron.app.whenReady().then(() => {
cb({ cancel: false, responseHeaders });
});
});
+
+console.log("[Vencord] Loading original Discord app.asar");
+// Legacy Vencord Injector requires "../app.asar". However, because we
+// restore the require.main above this is messed up, so monkey patch Module._load to
+// redirect such requires
+// FIXME: remove this eventually
+if (readFileSync(injectorPath, "utf-8").includes('require("../app.asar")')) {
+ console.warn("[Vencord] [--> WARNING <--] You have a legacy Vencord install. Please reinject");
+ const Module = require("module");
+ const loadModule = Module._load;
+ Module._load = function (path: string) {
+ if (path === "../app.asar") {
+ Module._load = loadModule;
+ arguments[0] = require.main!.filename;
+ }
+ return loadModule.apply(this, arguments);
+ };
+} else {
+ require(discordPath);
+}