Game version checking

This commit is contained in:
Benj
2022-08-31 22:06:52 +08:00
parent ff8f35c52a
commit 8077285e79
3 changed files with 56 additions and 5 deletions

View File

@@ -12,7 +12,7 @@ import Plus from '../../resources/icons/plus.svg'
import './ServerLaunchSection.css'
import { dataDir } from '@tauri-apps/api/path'
import { getGameExecutable } from '../../utils/game'
import { getGameExecutable, getGameVersion } from '../../utils/game'
import { patchGame, unpatchGame } from '../../utils/metadata'
interface IProps {
@@ -110,6 +110,24 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
// Connect to proxy
if (config.toggle_grasscutter) {
if (config.patch_metadata) {
const gameVersion = await getGameVersion()
console.log(gameVersion)
if(gameVersion == null) {
alert('Game version could not be determined. Please make sure you have the game correctly selected and try again.')
return
}
if(gameVersion?.major == 2 && gameVersion?.minor < 8) {
alert('Game version is too old for metadata patching. Please disable metadata patching in the settings and try again.')
return
}
if(gameVersion?.major == 3 && gameVersion?.minor >= 1) {
alert('Game version is too new for metadata patching. Please disable metadata patching in the settings to launch the game.\nNOTE: You will require a UA patch to play the game.')
return
}
const patched = await patchGame()
if (!patched) {

View File

@@ -1,3 +1,4 @@
import { invoke } from '@tauri-apps/api'
import { getConfig } from './configuration'
export async function getGameExecutable() {
@@ -25,3 +26,34 @@ export async function getGameFolder() {
return path
}
export async function getGameDataFolder() {
const gameExec = await getGameExecutable()
if (!gameExec) {
return null
}
return (await getGameFolder()) + '\\' + gameExec.replace('.exe', '_Data')
}
export async function getGameVersion() {
const GameData = await getGameDataFolder();
if (!GameData) {
return null
}
const settings = JSON.parse(await invoke('read_file', {
path: GameData + '\\StreamingAssets\\asb_settings.json',
}))
const versionRaw = settings.variance.split('.');
const version = {
major: parseInt(versionRaw[0]),
minor: parseInt(versionRaw[1].split('_')[0]),
release: parseInt(versionRaw[1].split('_')[1]),
}
return version;
}

View File

@@ -1,7 +1,7 @@
import { invoke } from '@tauri-apps/api'
import { dataDir } from '@tauri-apps/api/path'
import DownloadHandler from './download'
import { getGameExecutable, getGameFolder } from './game'
import { getGameDataFolder, getGameExecutable, getGameFolder, getGameVersion } from './game'
export async function patchMetadata() {
const metadataExists = await invoke('dir_exists', {
@@ -171,13 +171,13 @@ export async function unpatchGame() {
}
export async function getGameMetadataPath() {
const gameExec = await getGameExecutable()
const gameData = await getGameDataFolder()
if (!gameExec) {
if (!gameData) {
return null
}
return ((await getGameFolder()) + '\\' + gameExec.replace('.exe', '_Data') + '\\Managed\\Metadata').replace(
return (gameData + '\\Managed\\Metadata').replace(
/\\/g,
'/'
)
@@ -188,6 +188,7 @@ export async function getBackupMetadataPath() {
}
export async function globalMetadataLink() {
// TODO: Get metadata based on current game version.
const versionAPIUrl =
'https://sdk-os-static.mihoyo.com/hk4e_global/mdk/launcher/api/resource?channel_id=1&key=gcStgarh&launcher_id=10&sub_channel_id=0'