feat(genshin): removed patch support

This commit is contained in:
Observer KRypt0n_ 2023-08-17 11:51:09 +02:00
parent 0a2b5e8711
commit 847214f52e
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
5 changed files with 11 additions and 171 deletions

View file

@ -9,7 +9,7 @@ edition = "2021"
[dependencies.anime-game-core]
git = "https://github.com/an-anime-team/anime-game-core"
tag = "1.14.0"
tag = "1.15.0"
features = ["all"]
# path = "../anime-game-core" # ! for dev purposes only
@ -35,7 +35,6 @@ star-rail = ["anime-game-core/star-rail"]
honkai = ["anime-game-core/honkai"]
pgr = ["anime-game-core/pgr"]
genshin-patch = ["anime-game-core/patch-dawn"]
star-rail-patch = ["anime-game-core/patch-jadeite"]
honkai-patch = [
"anime-game-core/patch-jadeite",

View file

@ -19,7 +19,6 @@ use crate::components::{
pub mod launcher;
pub mod game;
pub mod patch;
#[cfg(feature = "components")]
pub mod components;
@ -30,7 +29,6 @@ pub mod prelude {
pub use super::launcher::prelude::*;
pub use super::game::*;
pub use super::patch::*;
#[cfg(feature = "components")]
pub use super::components::*;
@ -47,9 +45,7 @@ pub struct Schema {
pub sandbox: Sandbox,
#[cfg(feature = "components")]
pub components: Components,
pub patch: Patch
pub components: Components
}
impl From<&JsonValue> for Schema {
@ -77,12 +73,7 @@ impl From<&JsonValue> for Schema {
components: match value.get("components") {
Some(value) => Components::from(value),
None => default.components
},
patch: match value.get("patch") {
Some(value) => Patch::from(value),
None => default.patch
},
}
}
}
}

View file

@ -1,94 +0,0 @@
use std::path::PathBuf;
use serde::{Serialize, Deserialize};
use serde_json::Value as JsonValue;
use crate::genshin::consts::launcher_dir;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Patch {
pub path: PathBuf,
pub servers: Vec<String>,
pub apply: bool,
pub root: bool,
pub disable_mhypbase: bool
}
impl Default for Patch {
#[inline]
fn default() -> Self {
let launcher_dir = launcher_dir().expect("Failed to get launcher dir");
Self {
path: launcher_dir.join("patch"),
servers: vec![
String::from("https://codeberg.org/an-anime-team/dawn"),
String::from("https://notabug.org/Krock/dawn")
],
apply: false,
// Disable root requirement for patching if we're running launcher in flatpak
root: !PathBuf::from("/.flatpak-info").exists(),
disable_mhypbase: false
}
}
}
impl From<&JsonValue> for Patch {
fn from(value: &JsonValue) -> Self {
let default = Self::default();
Self {
path: match value.get("path") {
Some(value) => match value.as_str() {
Some(value) => PathBuf::from(value),
None => default.path
},
None => default.path
},
servers: match value.get("servers") {
Some(value) => match value.as_array() {
Some(values) => {
let mut servers = Vec::new();
for value in values {
if let Some(server) = value.as_str() {
servers.push(server.to_string());
}
}
servers
},
None => default.servers
},
None => default.servers
},
apply: match value.get("apply") {
Some(value) => value.as_bool().unwrap_or(default.apply),
// Migration from 1.7.8 to 1.8.0
// Xlua patch doesn't exist now so there's only one patch
// and thus it's main, and doesn't need this suffix here
None => match value.get("apply_main") {
Some(value) => value.as_bool().unwrap_or(default.apply),
None => default.apply
}
},
root: match value.get("root") {
Some(value) => value.as_bool().unwrap_or(default.root),
None => default.root
},
disable_mhypbase: match value.get("disable_mhypbase") {
Some(value) => value.as_bool().unwrap_or(default.disable_mhypbase),
None => default.disable_mhypbase
}
}
}
}

View file

@ -50,12 +50,10 @@ pub fn run() -> anyhow::Result<()> {
let config = Config::get()?;
let game_executable = config.patch.apply
.then_some("launcher.bat")
.unwrap_or_else(|| match config.launcher.edition {
let game_executable = match config.launcher.edition {
genshin::GameEdition::Global => "GenshinImpact.exe",
genshin::GameEdition::China => "YuanShen.exe"
});
};
let game_path = config.game.path.for_edition(config.launcher.edition);
@ -117,21 +115,10 @@ pub fn run() -> anyhow::Result<()> {
return Err(anyhow::anyhow!("Failed to update FPS unlocker config: {err}"));
}
let launcher_bat = game_path.join("launcher.bat");
let fps_unlocker_bat = game_path.join("fps_unlocker.bat");
// Generate fps_unlocker.bat
if config.patch.apply {
std::fs::write(fps_unlocker_bat, std::fs::read_to_string(launcher_bat)?
.replace("start GenshinImpact.exe %*", &format!("start GenshinImpact.exe %*\n\nZ:\ncd \"{}\"\nstart unlocker.exe", unlocker.dir().to_string_lossy()))
.replace("start YuanShen.exe %*", &format!("start YuanShen.exe %*\n\nZ:\ncd \"{}\"\nstart unlocker.exe", unlocker.dir().to_string_lossy())))?;
}
else {
// If patch applying is disabled, then game_executable is either GenshinImpact.exe or YuanShen.exe
// so we don't need to check it here
std::fs::write(fps_unlocker_bat, format!("start {game_executable} %*\n\nZ:\ncd \"{}\"\nstart unlocker.exe", unlocker.dir().to_string_lossy()))?;
}
std::fs::write(game_path.join("fps_unlocker.bat"), format!("start {game_executable} %*\n\nZ:\ncd \"{}\"\nstart unlocker.exe", unlocker.dir().to_string_lossy()))?;
}
// Generate `config.ini` if environment emulation feature is presented

View file

@ -22,11 +22,6 @@ pub enum LauncherState {
cleanup_folder: Option<PathBuf>
},
PlayerPatchAvailable {
patch: PlayerPatch,
disable_mhypbase: bool
},
TelemetryNotDisabled,
#[cfg(feature = "components")]
@ -56,8 +51,7 @@ pub enum LauncherState {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StateUpdating {
Game,
Voice(VoiceLocale),
Patch
Voice(VoiceLocale)
}
#[derive(Debug, Clone, PartialEq, Eq)]
@ -68,11 +62,6 @@ pub struct LauncherStateParams<F: Fn(StateUpdating)> {
pub wine_prefix: PathBuf,
pub selected_voices: Vec<VoiceLocale>,
pub patch_servers: Vec<String>,
pub patch_folder: PathBuf,
pub use_patch: bool,
pub disable_mhypbase: bool,
pub status_updater: F
}
@ -122,33 +111,6 @@ impl LauncherState {
}
}
// Check game patch status
(params.status_updater)(StateUpdating::Patch);
let patch = Patch::new(&params.patch_folder, params.game_edition);
// Sync local patch folder with remote if needed
// TODO: maybe I shouldn't do it here?
if patch.is_sync(&params.patch_servers)?.is_none() {
for server in &params.patch_servers {
if patch.sync(server).is_ok() {
break;
}
}
}
// Check UnityPlayer patch
if params.use_patch {
let player_patch = patch.player_patch()?;
if !player_patch.is_applied(&params.game_path)? {
return Ok(Self::PlayerPatchAvailable {
patch: player_patch,
disable_mhypbase: params.disable_mhypbase
});
}
}
// Check telemetry servers
let disabled = telemetry::is_disabled(params.game_edition)
@ -219,11 +181,6 @@ impl LauncherState {
wine_prefix: config.get_wine_prefix_path(),
selected_voices: voices,
patch_servers: config.patch.servers,
patch_folder: config.patch.path,
use_patch: config.patch.apply,
disable_mhypbase: config.patch.disable_mhypbase,
status_updater
})
}