diff --git a/dom_shit.js b/dom_shit.js index 2561701..f76c829 100644 --- a/dom_shit.js +++ b/dom_shit.js @@ -1,13 +1,14 @@ -const path = window.require('path'); -const fs = window.require('fs'); -const electron = window.require('electron'); -const Module = window.require('module').Module; -Module.globalPaths.push(path.resolve(electron.remote.app.getAppPath(), 'node_modules')); -const currentWindow = electron.remote.getCurrentWindow(); -if (currentWindow.__preload) { - process.electronBinding('command_line').appendSwitch('preload', currentWindow.__preload); - electron.contextBridge.exposeInMainWorld = (key, val) => window[key] = val; // Expose DiscordNative - require(currentWindow.__preload); +const path = require('path'); +const fs = require('fs'); +const electron = require('electron'); +const mainProcessInfo = JSON.parse(electron.ipcRenderer.sendSync('main-process-info')); +const Module = require('module'); +Module.globalPaths.push(mainProcessInfo.originalNodeModulesPath); +if (mainProcessInfo.originalPreloadScript) { + process.electronBinding('command_line').appendSwitch('preload', mainProcessInfo.originalPreloadScript); + // This hack is no longer needed due to context isolation having to be on + //electron.contextBridge.exposeInMainWorld = (key, val) => window[key] = val; // Expose DiscordNative + require(mainProcessInfo.originalPreloadScript); } //Get inject directory @@ -122,13 +123,16 @@ process.once('loaded', async () => { ED.plugins = plugins; c.log(`Plugins validated.`); - while (!window.webpackJsonp) + //while (!electron.webFrame.top.context.window.webpackJsonp) + //electron.webFrame.executeJavaScript(` + // preloadInfoShare.webpackJsonp = window.webpackJsonp; + //`); await c.sleep(100); // wait until this is loaded in order to use it for modules - ED.webSocket = window._ws; + //ED.webSocket = window._ws; - /* Add helper functions that make plugins easy to create */ - window.req = window.webpackJsonp.push([[], { + /* Add helper functions that make plugins easy to create */ + window.req = electron.webFrame.top.context.window.webpackJsonp.push([[], { '__extra_id__': (module, exports, req) => module.exports = req }, [['__extra_id__']]]); delete window.req.m['__extra_id__']; @@ -210,17 +214,6 @@ process.once('loaded', async () => { EDApi.monkeyPatch(ht, 'showToken', window.fixedShowToken); if (!ED.localStorage.getItem('token') && ht.getToken()) window.fixedShowToken(); // prevent you from being logged out for no reason - - // change the console warning to be more fun - const wc = require('electron').remote.getCurrentWebContents(); - wc.removeAllListeners('devtools-opened'); - wc.on('devtools-opened', () => { - console.log('%cHold Up!', 'color: #FF5200; -webkit-text-stroke: 2px black; font-size: 72px; font-weight: bold;'); - console.log('%cIf you\'re reading this, you\'re probably smarter than most Discord developers.', 'font-size: 16px;'); - console.log('%cPasting anything in here could actually improve the Discord client.', 'font-size: 18px; font-weight: bold; color: red;'); - console.log('%cUnless you understand exactly what you\'re doing, keep this window open to browse our bad code.', 'font-size: 16px;'); - console.log('%cIf you don\'t understand exactly what you\'re doing, you should come work with us: https://discordapp.com/jobs', 'font-size: 16px;'); - }); }); @@ -577,4 +570,4 @@ window.BdApi.Themes = new class AddonAPI { reload() {} get() {return null;} getAll() {return [];} -}; +}; \ No newline at end of file diff --git a/injection.js b/injection.js index 01bf5ee..4804883 100644 --- a/injection.js +++ b/injection.js @@ -1,3 +1,4 @@ +require('./main_process_shit'); const electron = require('electron'); const path = require('path'); electron.app.commandLine.appendSwitch("no-force-async-hooks-checks"); @@ -11,23 +12,29 @@ electron.session.defaultSession.webRequest.onHeadersReceived(function(details, c class BrowserWindow extends electron.BrowserWindow { constructor(originalOptions) { - if (!originalOptions || !originalOptions.webPreferences || !originalOptions.title) return super(originalOptions); // eslint-disable-line constructor-super + let win = new electron.BrowserWindow(originalOptions); + if (!originalOptions || !originalOptions.webPreferences || !originalOptions.title) return win; // eslint-disable-line constructor-super const originalPreloadScript = originalOptions.webPreferences.preload; - // Make sure Node integration is enabled - originalOptions.webPreferences.nodeIntegration = true; - // Make sure remote module is enabled - originalOptions.webPreferences.enableRemoteModule = true; - // Make sure context isolation is disabled - originalOptions.webPreferences.contextIsolation = false; originalOptions.webPreferences.preload = path.join(process.env.injDir, 'dom_shit.js'); originalOptions.webPreferences.transparency = true; - super(originalOptions); - this.__preload = originalPreloadScript; + // change the console warning to be more fun + win.webContents.on('devtools-opened', (event) => { + console.log('%cHold Up!', 'color: #FF5200; -webkit-text-stroke: 2px black; font-size: 72px; font-weight: bold;'); + console.log('%cIf you\'re reading this, you\'re probably smarter than most Discord developers.', 'font-size: 16px;'); + console.log('%cPasting anything in here could actually improve the Discord client.', 'font-size: 18px; font-weight: bold; color: red;'); + console.log('%cUnless you understand exactly what you\'re doing, keep this window open to browse our bad code.', 'font-size: 16px;'); + console.log('%cIf you don\'t understand exactly what you\'re doing, you should come work with us: https://discordapp.com/jobs', 'font-size: 16px;'); + }); + win = new electron.BrowserWindow(originalOptions); + win.webContents.__preload = originalPreloadScript; + return win; } } +BrowserWindow.webContents; + const electron_path = require.resolve('electron'); Object.assign(BrowserWindow, electron.BrowserWindow); // Assigns the new chrome-specific ones diff --git a/main_process_shit.js b/main_process_shit.js new file mode 100644 index 0000000..02f4ae8 --- /dev/null +++ b/main_process_shit.js @@ -0,0 +1,20 @@ +const electron = require('electron'); +const ipcMain = require('electron').ipcMain; +const path = require('path'); + +ipcMain.on('main-process-info', (event, arg) => { + event.returnValue = `{ + "originalNodeModulesPath": "${path.resolve(electron.app.getAppPath(), 'node_modules')}", + "originalPreloadScript": "${event.sender.__preload}" + }` +}); + +ipcMain.on('current-web-contents', (event, arg) => { + event.returnValue = event.sender.__currentWebContents +}); + +ipcMain.on('main-process-utils', (event, arg) => { + event.returnValue = `{ + "dialog": "${electron.dialog}" + }` +}); \ No newline at end of file diff --git a/plugins/direct_download.js b/plugins/direct_download.js index 6f5cf16..275e728 100644 --- a/plugins/direct_download.js +++ b/plugins/direct_download.js @@ -1,7 +1,8 @@ const Plugin = require('../plugin'); // contains modified code from https://stackoverflow.com/a/47820271 -const { dialog } = require('electron').remote; +const ipcRenderer = require('electron').ipcRenderer; +const { dialog } = JSON.parse(ipcRenderer.sendSync('main-process-utils')); const http = require('https'); const fs = require('fs'); let ttM = {}, iteM = {}; diff --git a/plugins/ed_settings.js b/plugins/ed_settings.js index 75f3620..390d03a 100644 --- a/plugins/ed_settings.js +++ b/plugins/ed_settings.js @@ -420,7 +420,7 @@ module.exports = new Plugin({ const DiscordUIGenerator = { reactMarkdownRules: (() => { const simpleMarkdown = EDApi.findModule("markdownToReact"); - const rules = window._.clone(simpleMarkdown.defaultRules); + const rules = require("electron").webFrame.top.context.window._.clone(simpleMarkdown.defaultRules); rules.paragraph.react = (node, output, state) => { return e(Fragment, null, output(node.content, state)) diff --git a/plugins/hidden_channels.js b/plugins/hidden_channels.js index 311460a..2bb7fe4 100644 --- a/plugins/hidden_channels.js +++ b/plugins/hidden_channels.js @@ -16,7 +16,7 @@ module.exports = new Plugin({ ai = EDApi.findModule('actionIcon'); const getUser = EDApi.findModule('getCurrentUser').getCurrentUser; - const getAllChannels = EDApi.findModule('getGuildChannels').getGuildChannels; + const getAllChannels = EDApi.findModule('getChannels').getChannels; const can = EDApi.findModule('computePermissions').can; g_dc = EDApi.findModule('getDefaultChannel'); @@ -137,7 +137,7 @@ module.exports = new Plugin({ return egg; });*/ - const cancan = EDApi.findModuleByProps('can', 'canUser').can; + const cancan = EDApi.findModuleByProps('can').can; gsr = EDApi.findModuleByDisplayName("FluxContainer(GuildSettingsRoles)").prototype; EDApi.monkeyPatch(gsr, 'render', b => { const egg = b.callOriginalMethod(b.methodArguments);