Adjust injection for core
This commit is contained in:
parent
5536bac463
commit
331ece8ca1
|
@ -15,15 +15,7 @@ const discordPath = (function() {
|
|||
const basedir = path.join(process.env.LOCALAPPDATA, release.replace(/ /g, ""));
|
||||
if (!fs.existsSync(basedir)) throw new Error(`Cannot find directory for ${release}`);
|
||||
const version = fs.readdirSync(basedir).filter(f => fs.lstatSync(path.join(basedir, f)).isDirectory() && f.split(".").length > 1).sort().reverse()[0];
|
||||
resourcePath = path.join(basedir, version, "resources");
|
||||
}
|
||||
else if (process.platform === "darwin") {
|
||||
const appPath = releaseInput === "canary" ? path.join("/Applications", "Discord Canary.app")
|
||||
: releaseInput === "ptb" ? path.join("/Applications", "Discord PTB.app")
|
||||
: useBdRelease && args[3] ? args[3] ? args[2] : args[2]
|
||||
: path.join("/Applications", "Discord.app");
|
||||
|
||||
resourcePath = path.join(appPath, "Contents", "Resources");
|
||||
resourcePath = path.join(basedir, version, "modules", "discord_desktop_core-1", "discord_desktop_core");
|
||||
}
|
||||
else {
|
||||
const userData = process.env.XDG_CONFIG_HOME ? process.env.XDG_CONFIG_HOME : path.join(process.env.HOME, ".config");
|
||||
|
@ -46,50 +38,11 @@ console.log(`Injecting into ${release}`);
|
|||
if (!fs.existsSync(discordPath)) throw new Error(`Cannot find directory for ${release}`);
|
||||
console.log(` ✅ Found ${release} in ${discordPath}`);
|
||||
|
||||
const appPath = process.platform === "win32" || process.platform === "darwin" ? path.join(discordPath, "app") : discordPath;
|
||||
const packageJson = path.join(appPath, "package.json");
|
||||
const indexJs = path.join(appPath, "index.js");
|
||||
|
||||
if (!fs.existsSync(appPath)) fs.mkdirSync(appPath);
|
||||
if (fs.existsSync(packageJson)) fs.unlinkSync(packageJson);
|
||||
const indexJs = path.join(discordPath, "index.js");
|
||||
if (fs.existsSync(indexJs)) fs.unlinkSync(indexJs);
|
||||
|
||||
if (process.platform === "win32" || process.platform === "darwin") {
|
||||
fs.writeFileSync(packageJson, JSON.stringify({
|
||||
name: "betterdiscord",
|
||||
main: "index.js",
|
||||
}, null, 4));
|
||||
console.log(" ✅ Wrote package.json");
|
||||
|
||||
fs.writeFileSync(indexJs, `require("${bdPath.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}");`);
|
||||
}
|
||||
else {
|
||||
fs.writeFileSync(indexJs, `require("${bdPath.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}");\nmodule.exports = require("./core.asar");`);
|
||||
}
|
||||
fs.writeFileSync(indexJs, `require("${bdPath.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}");\nmodule.exports = require("./core.asar");`);
|
||||
|
||||
console.log(" ✅ Wrote index.js");
|
||||
console.log("");
|
||||
|
||||
const asarPath = path.join(discordPath, "app.asar");
|
||||
const modifiedPath = path.join(discordPath, "discord.asar");
|
||||
|
||||
if (!fs.existsSync(modifiedPath)) {
|
||||
console.log("Renaming app.asar -> discord.asar");
|
||||
console.log("");
|
||||
|
||||
if (!fs.existsSync(asarPath)) {
|
||||
console.log(" ❌ Unable to rename app.asar -> discord.asar, discord installation appears to be corrupt.");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
try {
|
||||
fs.renameSync(asarPath, modifiedPath);
|
||||
console.log(" ✅ Successfully renamed app.asar -> discord.asar");
|
||||
console.log("");
|
||||
} catch (error) {
|
||||
console.log(" ❌ Failed to rename app.asar -> discord.asar:", error);
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Injection successful, please restart ${release}.`);
|
||||
|
|
Loading…
Reference in New Issue