From dc28d621dcc733633e915b140cf078945ff968b5 Mon Sep 17 00:00:00 2001 From: HoraceHuang-ui Date: Wed, 1 May 2024 01:28:57 +0800 Subject: [PATCH 01/11] feat: add registry editing --- electron-builder.json5 | 7 +++ electron/main/index.ts | 76 ++++++++++++++++++++++++++++++--- electron/preload/index.ts | 14 ++++++ package.json | 2 + src/store/index.ts | 6 ++- src/types/genshin/gsRegInfo.ts | 7 +++ src/types/index.d.ts | 11 +++++ src/types/starrail/srRegInfo.ts | 7 +++ 8 files changed, 122 insertions(+), 8 deletions(-) create mode 100644 src/types/genshin/gsRegInfo.ts create mode 100644 src/types/starrail/srRegInfo.ts diff --git a/electron-builder.json5 b/electron-builder.json5 index 9398de35..2279dea0 100644 --- a/electron-builder.json5 +++ b/electron-builder.json5 @@ -46,5 +46,12 @@ "src/assets/hi3banner.webp", "src/assets/gpIcons/Xbox/*", "src/assets/gpIcons/PS/*", + { + "from": "node_modules/regedit/vbs", + "to": "regedit/vbs", + "filter": [ + "**/*", + ], + }, ], } diff --git a/electron/main/index.ts b/electron/main/index.ts index 3419dc46..8b274ee6 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -15,14 +15,12 @@ import { DynamicTextAssets, EnkaClient, TextAssets } from 'enka-network-api' import { promises as fs } from 'fs' import { Octokit } from '@octokit/core' import path from 'path' -import { useStore } from '../../src/store' -import { createPinia } from 'pinia' -import piniaPluginPersistedstate from 'pinia-plugin-persistedstate' +import regedit, { promisified as reg } from 'regedit' +import { SrRegInfo } from '../../src/types/starrail/srRegInfo' +import { GsRegInfo } from '../../src/types/genshin/gsRegInfo' -const pinia = createPinia() -pinia.use(piniaPluginPersistedstate) +regedit.setExternalVBSLocation('resources/regedit/vbs') -const store = useStore(pinia) const enka = new EnkaClient({ requestTimeout: 10000, }) @@ -316,6 +314,72 @@ async function createWindow() { return result }) + ipcMain.on('reg:gsSet', (_event, acc: string) => { + // await reg.deleteKey(['HKCU\\Software\\miHoYo\\原神']) + // await reg.createKey(['HKCU\\Software\\miHoYo\\原神']) + const account = JSON.parse(acc) + + reg.putValue({ + 'HKCU\\Software\\miHoYo\\原神': { + GENERAL_DATA_h2389025596: { + value: account.generalData, + type: 'REG_BINARY', + }, + MIHOYOSDK_ADL_PROD_CN_h3123967166: { + value: account.mihoyoSdk, + type: 'REG_BINARY', + }, + }, + }) + }) + + ipcMain.on('reg:srSet', (_event, acc: string) => { + // await reg.deleteKey(['HKCU\\Software\\miHoYo\\崩坏:星穹铁道']) + // await reg.createKey(['HKCU\\Software\\miHoYo\\崩坏:星穹铁道']) + const account = JSON.parse(acc) + + reg.putValue({ + 'HKCU\\Software\\miHoYo\\崩坏:星穹铁道': { + MIHOYOSDK_ADL_PROD_CN_h3123247166: { + value: account.mihoyoSdk, + type: 'REG_BINARY', + }, + App_LastUserID_h2841324341: { + value: account.lastUserId, + type: 'REG_DWORD', + }, + }, + }) + }) + + ipcMain.handle('reg:gsGet', async (): Promise => { + const result = (await reg.list(['HKCU\\Software\\miHoYo\\原神']))[ + 'HKCU\\Software\\miHoYo\\原神' + ] + return result.exists && result.values + ? { + name: '', + generalData: result.values.GENERAL_DATA_h2389025596.value as number[], + mihoyoSdk: result.values.MIHOYOSDK_ADL_PROD_CN_h3123967166 + .value as number[], + } + : undefined + }) + + ipcMain.handle('reg:srGet', async (): Promise => { + const result = (await reg.list(['HKCU\\Software\\miHoYo\\崩坏:星穹铁道']))[ + 'HKCU\\Software\\miHoYo\\崩坏:星穹铁道' + ] + return result.exists && result.values + ? { + name: '', + lastUserId: result.values.App_LastUserID_h2841324341.value as number, + mihoyoSdk: result.values.MIHOYOSDK_ADL_PROD_CN_h3123247166 + .value as number[], + } + : undefined + }) + // --------- Window configs ------------ // win.setWindowButtonVisibility(true) // nativeTheme.themeSource = 'light' diff --git a/electron/preload/index.ts b/electron/preload/index.ts index fe3e74e1..c6a37c33 100644 --- a/electron/preload/index.ts +++ b/electron/preload/index.ts @@ -58,6 +58,20 @@ contextBridge.exposeInMainWorld('github', { return await ipcRenderer.invoke('github:getLatestRelease') }, }) +contextBridge.exposeInMainWorld('reg', { + gsGet: async () => { + return await ipcRenderer.invoke('reg:gsGet') + }, + srGet: async () => { + return await ipcRenderer.invoke('reg:srGet') + }, + gsSet: (account: string) => { + ipcRenderer.send('reg:gsSet', account) + }, + srSet: (account: string) => { + ipcRenderer.send('reg:srSet', account) + }, +}) function domReady( condition: DocumentReadyState[] = ['complete', 'interactive'], diff --git a/package.json b/package.json index 4c14da76..a8f5e855 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ }, "devDependencies": { "@electron-forge/cli": "^7.3.0", + "@types/winreg": "^1.2.36", "@vitejs/plugin-vue": "^5.0.4", "@vue/eslint-config-typescript": "^10.0.0", "autoprefixer": "^10.4.18", @@ -55,6 +56,7 @@ "enka-network-api": "^4.3.0", "marked": "^12.0.1", "path": "^0.12.7", + "regedit": "^5.1.3", "sass": "^1.72.0", "vue-i18n": "^9.10.1" } diff --git a/src/store/index.ts b/src/store/index.ts index 18303ab8..d0e5a88a 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -2,6 +2,8 @@ import { defineStore } from 'pinia' import { DialogStyle } from '../types/dialog/dialog' import { Lang } from '../i18n' import { FormattedApiInfo } from '../types/starrail/srPlayerInfo' +import { GsRegInfo } from '../types/genshin/gsRegInfo' +import { SrRegInfo } from '../types/starrail/srRegInfo' export const useStore = defineStore('userStore', { state: () => ({ @@ -35,18 +37,18 @@ export const useStore = defineStore('userStore', { }, game: { gs: { - // gs launcherPath: undefined as string | undefined, gamePath: undefined as string | undefined, upd: false, playerInfo: undefined as any, + accounts: [] as GsRegInfo[], }, sr: { - // sr launcherPath: undefined as string | undefined, gamePath: undefined as string | undefined, upd: false, playerInfo: undefined as FormattedApiInfo | undefined, + accounts: [] as SrRegInfo[], }, hi3: { // hi3 diff --git a/src/types/genshin/gsRegInfo.ts b/src/types/genshin/gsRegInfo.ts new file mode 100644 index 00000000..4a0f210f --- /dev/null +++ b/src/types/genshin/gsRegInfo.ts @@ -0,0 +1,7 @@ +export interface GsRegInfo { + name: string + // GENERAL_DATA_h2389025596 + generalData: number[] + // MIHOYOSDK_ADL_PROD_CN_h3123967166 + mihoyoSdk: number[] +} diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 72e53d17..2bf4a943 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -1,3 +1,6 @@ +import { GsRegInfo } from './genshin/gsRegInfo' +import { SrRegInfo } from './starrail/srRegInfo' + export {} // export * from './starrail/srPlayerInfo' @@ -42,6 +45,13 @@ export interface IGithub { getLatestRelease: () => Promise } +export interface IReg { + gsGet: () => Promise + gsSet: (data: string) => Promise + srGet: () => Promise + srSet: (data: string) => Promise +} + declare global { interface Window { child: IChild @@ -52,5 +62,6 @@ declare global { axios: IAxios electron: IElectron github: IGithub + reg: IReg } } diff --git a/src/types/starrail/srRegInfo.ts b/src/types/starrail/srRegInfo.ts new file mode 100644 index 00000000..baa40177 --- /dev/null +++ b/src/types/starrail/srRegInfo.ts @@ -0,0 +1,7 @@ +export interface SrRegInfo { + name: string + // App_LastUserID_h2841324341 + lastUserId: number + // MIHOYOSDK_ADL_PROD_CN_h3123247166 + mihoyoSdk: number[] +} From c3950ed470915039491fef1a31797c0694de2be4 Mon Sep 17 00:00:00 2001 From: HoraceHuang-ui Date: Sun, 5 May 2024 10:37:23 +0800 Subject: [PATCH 02/11] feat: add account switching for genshin & star rail --- electron/main/index.ts | 9 +- src/pages/GamePage.vue | 238 +++++++++++++++--- .../Components/GenshinInfoCard.vue | 4 +- .../Components/StarRailDialog.vue | 4 - .../Components/StarRailInfoCard.vue | 2 +- src/store/index.ts | 2 + src/types/starrail/srRegInfo.ts | 4 +- 7 files changed, 219 insertions(+), 44 deletions(-) diff --git a/electron/main/index.ts b/electron/main/index.ts index 8b274ee6..a45aa6ff 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -340,11 +340,11 @@ async function createWindow() { reg.putValue({ 'HKCU\\Software\\miHoYo\\崩坏:星穹铁道': { - MIHOYOSDK_ADL_PROD_CN_h3123247166: { + MIHOYOSDK_ADL_PROD_CN_h3123967166: { value: account.mihoyoSdk, type: 'REG_BINARY', }, - App_LastUserID_h2841324341: { + App_LastUserID_h2841727341: { value: account.lastUserId, type: 'REG_DWORD', }, @@ -370,11 +370,12 @@ async function createWindow() { const result = (await reg.list(['HKCU\\Software\\miHoYo\\崩坏:星穹铁道']))[ 'HKCU\\Software\\miHoYo\\崩坏:星穹铁道' ] + console.log(result) return result.exists && result.values ? { name: '', - lastUserId: result.values.App_LastUserID_h2841324341.value as number, - mihoyoSdk: result.values.MIHOYOSDK_ADL_PROD_CN_h3123247166 + lastUserId: result.values.App_LastUserID_h2841727341.value as number, + mihoyoSdk: result.values.MIHOYOSDK_ADL_PROD_CN_h3123967166 .value as number[], } : undefined diff --git a/src/pages/GamePage.vue b/src/pages/GamePage.vue index 92c63558..6c8509b7 100644 --- a/src/pages/GamePage.vue +++ b/src/pages/GamePage.vue @@ -1,5 +1,5 @@