mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-14 08:04:52 +01:00
Fix could not patch on very first run
This commit is contained in:
@@ -121,23 +121,19 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (gameVersion?.major == 2 && gameVersion?.minor < 9) {
|
if (gameVersion?.major == 2 && gameVersion?.minor < 9) {
|
||||||
alert(
|
alert('Game version is too old for RSA patching. Please disable RSA patching in the settings and try again.')
|
||||||
'Game version is too old for RSA patching. Please disable RSA patching in the settings and try again.'
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gameVersion?.major == 3 && gameVersion?.minor < 1) {
|
if (gameVersion?.major == 3 && gameVersion?.minor < 1) {
|
||||||
alert(
|
alert('Game version is too old for RSA patching. Please disable RSA patching in the settings and try again.')
|
||||||
'Game version is too old for RSA patching. Please disable RSA patching in the settings and try again.'
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const patched = await patchGame()
|
const patched = await patchGame()
|
||||||
|
|
||||||
if (!patched) {
|
if (!patched) {
|
||||||
alert('Could not patch game!')
|
alert('Could not patch! Try launching again, or patching manually.')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,11 @@
|
|||||||
import { invoke } from '@tauri-apps/api'
|
import { invoke } from '@tauri-apps/api'
|
||||||
import { dataDir } from '@tauri-apps/api/path'
|
import { dataDir } from '@tauri-apps/api/path'
|
||||||
|
import { listen } from '@tauri-apps/api/event'
|
||||||
import DownloadHandler from './download'
|
import DownloadHandler from './download'
|
||||||
import { getGameFolder } from './game'
|
import { getGameFolder } from './game'
|
||||||
|
|
||||||
const downloadHandler = new DownloadHandler()
|
const downloadHandler = new DownloadHandler()
|
||||||
|
|
||||||
export async function patchRSA() {
|
|
||||||
const rsaExists = await invoke('dir_exists', {
|
|
||||||
path: (await getBackupRSAPath()) + '\\version.dll',
|
|
||||||
})
|
|
||||||
|
|
||||||
if (rsaExists) {
|
|
||||||
// Already patched
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Downloading rsa patch to backup location')
|
|
||||||
|
|
||||||
// Download RSA patch to backup location
|
|
||||||
const downloadedRSA = await downloadRSA(downloadHandler)
|
|
||||||
|
|
||||||
if (!downloadedRSA) {
|
|
||||||
console.log(await getBackupRSAPath())
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('RSA download successful!')
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function patchGame() {
|
export async function patchGame() {
|
||||||
// Do we have a patch already?
|
// Do we have a patch already?
|
||||||
const patchedExists = await invoke('dir_exists', {
|
const patchedExists = await invoke('dir_exists', {
|
||||||
@@ -38,7 +14,7 @@ export async function patchGame() {
|
|||||||
|
|
||||||
if (!patchedExists) {
|
if (!patchedExists) {
|
||||||
// No patch found? Patching creates one
|
// No patch found? Patching creates one
|
||||||
const patched = await patchRSA()
|
const patched = await downloadRSA()
|
||||||
|
|
||||||
if (!patched) {
|
if (!patched) {
|
||||||
return false
|
return false
|
||||||
@@ -94,7 +70,7 @@ export async function getBackupRSAPath() {
|
|||||||
return (await dataDir()) + 'cultivation\\rsa'
|
return (await dataDir()) + 'cultivation\\rsa'
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadRSA(manager: DownloadHandler) {
|
export async function downloadRSA() {
|
||||||
const rsaLink = 'https://github.com/34736384/RSAPatch/releases/download/v1.1.0/RSAPatch.dll'
|
const rsaLink = 'https://github.com/34736384/RSAPatch/releases/download/v1.1.0/RSAPatch.dll'
|
||||||
|
|
||||||
// Should make sure rsa path exists
|
// Should make sure rsa path exists
|
||||||
@@ -103,9 +79,37 @@ export async function downloadRSA(manager: DownloadHandler) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Download the file
|
// Download the file
|
||||||
manager.addDownload(rsaLink, (await getBackupRSAPath()) + '\\version.dll', () => {
|
downloadHandler.addDownload(rsaLink, (await getBackupRSAPath()) + '\\version.dll', () => {
|
||||||
null
|
null
|
||||||
})
|
})
|
||||||
|
let errored = false
|
||||||
|
|
||||||
|
listen('download_error', ({ payload }) => {
|
||||||
|
// @ts-expect-error shut up typescript
|
||||||
|
const errorData: {
|
||||||
|
path: string
|
||||||
|
error: string
|
||||||
|
} = payload
|
||||||
|
|
||||||
|
errored = true
|
||||||
|
})
|
||||||
|
|
||||||
|
// There is 100% a better way to do this but I don't use ts enough to know
|
||||||
|
let downloadComplete = false
|
||||||
|
while (!downloadComplete) {
|
||||||
|
// Waits until download completes before continuing
|
||||||
|
if (
|
||||||
|
(await invoke('dir_exists', {
|
||||||
|
path: (await getBackupRSAPath()) + '\\version.dll',
|
||||||
|
})) ||
|
||||||
|
errored
|
||||||
|
) {
|
||||||
|
downloadComplete = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errored) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user