From 67de9b7c162ea52387cb936ae101b9d2f7e8b7c5 Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Sun, 23 Oct 2022 01:08:58 +0200 Subject: [PATCH] remove wincript(PASSWORD IS PLAIN IN CONFIG FOR NOW!) make linux compatible --- app.js | 64 ++++++++++++++++++++++++++++++------------------- config.js | 3 +-- osuUtil.js | 25 ++++++++----------- package.json | 3 +-- test/encrypt.js | 26 -------------------- 5 files changed, 51 insertions(+), 70 deletions(-) delete mode 100644 test/encrypt.js diff --git a/app.js b/app.js index 4ad1cd9..ea73f0d 100644 --- a/app.js +++ b/app.js @@ -10,6 +10,8 @@ const windowName = require('get-window-by-name'); let tempOsuPath; let osuWindowInfo; +let isIngame; +const platform = process.platform; const run = () => { const gotTheLock = app.requestSingleInstanceLock() @@ -18,34 +20,44 @@ const run = () => { return; } - setInterval(() => { - osuWindowInfo = windowName.getWindowText("osu!.exe"); - const firstInstance = osuWindowInfo[0]; - if (firstInstance) { - if (firstInstance.processTitle && firstInstance.processTitle.length > 0) { - const windowTitle = firstInstance.processTitle; - let rpcOsuVersion = ""; - let currentMap = undefined; - if (!windowTitle.includes("-")) { - rpcOsuVersion = windowTitle; - rpc.updateState("Idle..."); - } else { - var string = windowTitle; - var components = string.split(' - '); - const splitArray = [components.shift(), components.join(' - ')]; - rpcOsuVersion = splitArray[0]; - currentMap = splitArray[1]; - rpc.updateState("Playing..."); - } + setInterval(async () => { + if (platform == "win32") { + osuWindowInfo = windowName.getWindowText("osu!.exe"); + const firstInstance = osuWindowInfo[0]; + if (firstInstance) { + if (firstInstance.processTitle && firstInstance.processTitle.length > 0) { + const windowTitle = firstInstance.processTitle; + let rpcOsuVersion = ""; + let currentMap = undefined; + if (!windowTitle.includes("-")) { + rpcOsuVersion = windowTitle; + rpc.updateState("Idle..."); + } else { + var string = windowTitle; + var components = string.split(' - '); + const splitArray = [components.shift(), components.join(' - ')]; + rpcOsuVersion = splitArray[0]; + currentMap = splitArray[1]; + rpc.updateState("Playing..."); + } - rpc.updateStatus(currentMap, rpcOsuVersion); + rpc.updateStatus(currentMap, rpcOsuVersion); + } else { + rpc.updateState("Idle in Launcher..."); + rpc.updateStatus(undefined, undefined); + } } else { rpc.updateState("Idle in Launcher..."); rpc.updateStatus(undefined, undefined); } } else { - rpc.updateState("Idle in Launcher..."); - rpc.updateStatus(undefined, undefined); + if(isIngame){ + rpc.updateState("Playing..."); + rpc.updateStatus("Clicking circles!", "runningunderwine"); + }else{ + rpc.updateState("Idle in Launcher..."); + rpc.updateStatus(undefined, undefined); + } } }, 2000); @@ -77,14 +89,16 @@ const run = () => { await osuUtil.setConfigValue(osuConfig.path, "SaveUsername", "1"); await osuUtil.setConfigValue(osuConfig.path, "SavePassword", "1"); await osuUtil.setConfigValue(osuConfig.path, "Username", username); - await osuUtil.setConfigValue(osuConfig.path, "Password", await osuUtil.decryptString(password)); + await osuUtil.setConfigValue(osuConfig.path, "Password", password); await osuUtil.setConfigValue(osuConfig.path, "CredentialEndpoint", "ez-pp.farm"); } else { await osuUtil.setConfigValue(osuConfig.path, "Username", ""); await osuUtil.setConfigValue(osuConfig.path, "Password", ""); } rpc.updateState("Launching osu!..."); + isIngame = true; const result = await osuUtil.startOsuWithDevServer(tempOsuPath, "ez-pp.farm", async () => { + isIngame = false; await doUpdateCheck(mainWindow); }); return result; @@ -151,7 +165,7 @@ const run = () => { const loginData = await ezppUtil.performLogin(username, password); if (loginData && loginData.code === 200) { await config.set("username", username); - await config.set("password", await osuUtil.encryptString(password)); + await config.set("password", password); } return loginData; }) @@ -173,7 +187,7 @@ async function tryLogin(window) { const username = await config.get("username", ""); const password = await config.get("password", ""); if ((username && username.length > 0) && (password && password.length > 0)) { - const passwordPlain = await osuUtil.decryptString(password); + const passwordPlain = password; const loginResponse = await ezppUtil.performLogin(username, passwordPlain); if (loginResponse && loginResponse.code === 200) { window.webContents.send('account_update', { diff --git a/config.js b/config.js index b60e5ca..1a2123e 100644 --- a/config.js +++ b/config.js @@ -1,14 +1,13 @@ const path = require('path'); const fs = require('fs'); -const configFolder = path.join(process.env['LOCALAPPDATA'], 'EZPPLauncher'); +const configFolder = path.join(process.platform == "win32" ? process.env['LOCALAPPDATA'] : process.env['HOME'], 'EZPPLauncher'); if (!fs.existsSync(configFolder)) fs.mkdirSync(configFolder); const configLocation = path.join(configFolder, `ezpplauncher.${path.basename(process.env['USERNAME'])}.cfg`); if (!fs.existsSync(configLocation)) fs.writeFileSync(configLocation, ""); - async function get(key, defaultValue) { const fileStream = await fs.promises.readFile(configLocation, "utf-8"); const lines = fileStream.split(/\r?\n/) diff --git a/osuUtil.js b/osuUtil.js index b67c7c6..83efc58 100644 --- a/osuUtil.js +++ b/osuUtil.js @@ -3,13 +3,11 @@ const fu = require('./fileUtil'); const path = require('path'); const crypto = require('crypto'); const axios = require('axios').default; -const dpapi = require('wincrypt'); const executeUtil = require('./executeUtil'); const { EventEmitter } = require('events'); const { DownloaderHelper } = require('node-downloader-helper'); const checkUpdateURL = "https://osu.ppy.sh/web/check-updates.php?action=check&stream="; -const osuEncryptBuffer = Buffer.from('cu24180ncjeiu0ci1nwui', "utf-8") const osuEntities = [ 'avcodec-51.dll', 'avformat-52.dll', @@ -143,17 +141,15 @@ async function downloadUpdateFiles(osuPath, filesToUpdate) { async function startWithDevServer(osuPath, serverDomain, onExit) { const osuExe = path.join(osuPath, "osu!.exe"); if (!await fu.existsAsync(osuExe)) return false; - executeUtil.runFile(osuPath, osuExe, ["-devserver", serverDomain], onExit); - return true; -} - -async function encryptString(value) { - return Buffer.from(await dpapi.protect(Buffer.from(value, 'utf-8'), osuEncryptBuffer, 'CurrentUser'), 'utf-8').toString('base64'); -} - -async function decryptString(value) { - const decrypted = await dpapi.unprotect(Buffer.from(value, 'base64'), osuEncryptBuffer, 'CurrentUser'); - return decrypted.toString(); + switch (process.platform) { + case "linux": + executeUtil.runFile(osuPath, 'osu-stable', ["-devserver", serverDomain], onExit); + return true; + case "win32": + executeUtil.runFile(osuPath, osuExe, ["-devserver", serverDomain], onExit); + return true; + } + return false; } async function setConfigValue(configPath, key, value) { @@ -178,6 +174,5 @@ async function setConfigValue(configPath, key, value) { module.exports = { isValidOsuFolder, getLatestConfig, getUpdateFiles, filesThatNeedUpdate, - downloadUpdateFiles, startOsuWithDevServer: startWithDevServer, setConfigValue, - encryptString, decryptString + downloadUpdateFiles, startOsuWithDevServer: startWithDevServer, setConfigValue } \ No newline at end of file diff --git a/package.json b/package.json index 9fe401c..9258d22 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,6 @@ "get-window-by-name": "^2.0.0", "jquery": "^3.6.0", "node-downloader-helper": "^2.1.4", - "sweetalert2": "^11.5.2", - "wincrypt": "^1.5.0" + "sweetalert2": "^11.5.2" } } diff --git a/test/encrypt.js b/test/encrypt.js deleted file mode 100644 index ce9b690..0000000 --- a/test/encrypt.js +++ /dev/null @@ -1,26 +0,0 @@ -const dpapi = require('wincrypt'); -const entropyBuffer = Buffer.from('cu24180ncjeiu0ci1nwui', 'utf-8'); - -const run = async () => { - const stringToEncrypt = "Test123456!"; - - - const encrypted = await encryptString(stringToEncrypt) - console.log(encrypted); - const decrypted = await decryptString(encrypted); - console.log(decrypted); - -} - -async function encryptString(value) { - const encryptedString = await dpapi.protect(Buffer.from(value, 'utf-8'), entropyBuffer, 'CurrentUser'); - const encodedBase64 = Buffer.from(encryptedString, 'utf-8').toString('base64'); - return encodedBase64; -} - -async function decryptString(value) { - const decrypted = await dpapi.unprotect(Buffer.from(value, 'base64'), entropyBuffer, 'CurrentUser'); - return decrypted.toString(); -} - -run(); \ No newline at end of file