0.5.9
- added environment emulation feature - updated core library to 1.5.1
This commit is contained in:
parent
7aa54126c8
commit
c38fc3206a
6 changed files with 122 additions and 12 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "anime-launcher-sdk"
|
||||
version = "0.5.8"
|
||||
version = "0.5.9"
|
||||
authors = ["Nikita Podvirnyy <suimin.tu.mu.ga.mi@gmail.com>"]
|
||||
license = "GPL-3.0"
|
||||
readme = "README.md"
|
||||
|
@ -8,7 +8,7 @@ edition = "2021"
|
|||
|
||||
[dependencies.anime-game-core]
|
||||
git = "https://github.com/an-anime-team/anime-game-core"
|
||||
tag = "1.5.0"
|
||||
tag = "1.5.1"
|
||||
features = ["genshin", "all"]
|
||||
|
||||
# path = "../anime-game-core" # ! for dev purposes only
|
||||
|
@ -34,6 +34,7 @@ components = ["dep:wincompatlib", "dep:lazy_static"]
|
|||
game = ["components", "config"]
|
||||
fps-unlocker = ["dep:md-5"]
|
||||
discord-rpc = ["dep:discord-rich-presence"]
|
||||
environment-emulation = []
|
||||
|
||||
all = ["states", "config", "components", "game", "fps-unlocker", "discord-rpc"]
|
||||
all = ["states", "config", "components", "game", "fps-unlocker", "discord-rpc", "environment-emulation"]
|
||||
default = ["all"]
|
||||
|
|
|
@ -9,6 +9,9 @@ use anime_game_core::genshin::consts::GameEdition as CoreGameEdition;
|
|||
|
||||
use crate::consts::launcher_dir;
|
||||
|
||||
#[cfg(feature = "environment-emulation")]
|
||||
use crate::env_emulation::Environment;
|
||||
|
||||
pub mod repairer;
|
||||
|
||||
#[cfg(feature = "discord-rpc")]
|
||||
|
@ -87,7 +90,10 @@ pub struct Launcher {
|
|||
pub style: LauncherStyle,
|
||||
|
||||
#[cfg(feature = "discord-rpc")]
|
||||
pub discord_rpc: DiscordRpc
|
||||
pub discord_rpc: DiscordRpc,
|
||||
|
||||
#[cfg(feature = "environment-emulation")]
|
||||
pub environment: Environment
|
||||
}
|
||||
|
||||
impl Default for Launcher {
|
||||
|
@ -100,7 +106,10 @@ impl Default for Launcher {
|
|||
style: LauncherStyle::default(),
|
||||
|
||||
#[cfg(feature = "discord-rpc")]
|
||||
discord_rpc: DiscordRpc::default()
|
||||
discord_rpc: DiscordRpc::default(),
|
||||
|
||||
#[cfg(feature = "environment-emulation")]
|
||||
environment: Environment::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -148,6 +157,12 @@ impl From<&JsonValue> for Launcher {
|
|||
discord_rpc: match value.get("discord_rpc") {
|
||||
Some(value) => DiscordRpc::from(value),
|
||||
None => default.discord_rpc
|
||||
},
|
||||
|
||||
#[cfg(feature = "environment-emulation")]
|
||||
environment: match value.get("environment") {
|
||||
Some(value) => serde_json::from_value(value.clone()).unwrap_or(default.environment),
|
||||
None => default.environment
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,12 +95,14 @@ impl DiscordRpc {
|
|||
.assets(Assets::new().large_image(&config.icon))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn update(&self, update: RpcUpdates) -> Result<(), SendError<RpcUpdates>> {
|
||||
self.sender.send(update)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for DiscordRpc {
|
||||
#[inline]
|
||||
#[allow(unused_must_use)]
|
||||
fn drop(&mut self) {
|
||||
self.update(RpcUpdates::Disconnect);
|
||||
|
|
77
src/env_emulation.rs
Normal file
77
src/env_emulation.rs
Normal file
|
@ -0,0 +1,77 @@
|
|||
use serde::{Serialize, Deserialize};
|
||||
use enum_ordinalize::Ordinalize;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Ordinalize)]
|
||||
pub enum Environment {
|
||||
/// `config.ini` format:
|
||||
///
|
||||
/// ```ini
|
||||
/// [General]
|
||||
/// channel=1
|
||||
/// cps=mihoyo
|
||||
/// game_version=[game version]
|
||||
/// sub_channel=0
|
||||
/// ```
|
||||
PC,
|
||||
|
||||
/// `config.ini` format:
|
||||
///
|
||||
/// ```ini
|
||||
/// [General]
|
||||
/// channel=1
|
||||
/// cps=pcseaepic
|
||||
/// game_version=[game version]
|
||||
/// # plugin_sdk_version=2.14.2 (??? not used now)
|
||||
/// sub_channel=3
|
||||
/// ```
|
||||
Epic,
|
||||
|
||||
/// `config.ini` format:
|
||||
///
|
||||
/// ```ini
|
||||
/// [General]
|
||||
/// channel=1
|
||||
/// cps=pcgoogle
|
||||
/// game_version=[game version]
|
||||
/// sub_channel=6
|
||||
/// ```
|
||||
Android
|
||||
}
|
||||
|
||||
impl Default for Environment {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
Self::PC
|
||||
}
|
||||
}
|
||||
|
||||
impl Environment {
|
||||
/// Generate `config.ini`'s content
|
||||
pub fn generate_config(&self, game_version: impl AsRef<str>) -> String {
|
||||
match self {
|
||||
Self::PC => [
|
||||
"[General]",
|
||||
"channel=1",
|
||||
"cps=mihoyo",
|
||||
&format!("game_version={}", game_version.as_ref()),
|
||||
"sub_channel=0"
|
||||
].join("\n"),
|
||||
|
||||
Self::Epic => [
|
||||
"[General]",
|
||||
"channel=1",
|
||||
"cps=pcseaepic",
|
||||
&format!("game_version={}", game_version.as_ref()),
|
||||
"sub_channel=3"
|
||||
].join("\n"),
|
||||
|
||||
Self::Android => [
|
||||
"[General]",
|
||||
"channel=1",
|
||||
"cps=pcgoogle",
|
||||
&format!("game_version={}", game_version.as_ref()),
|
||||
"sub_channel=6"
|
||||
].join("\n")
|
||||
}
|
||||
}
|
||||
}
|
13
src/game.rs
13
src/game.rs
|
@ -1,6 +1,8 @@
|
|||
use std::process::{Command, Stdio};
|
||||
|
||||
use anime_game_core::prelude::*;
|
||||
use anime_game_core::genshin::telemetry;
|
||||
use anime_game_core::genshin::game::Game;
|
||||
|
||||
use super::consts;
|
||||
use super::config;
|
||||
|
@ -91,6 +93,17 @@ pub fn run() -> anyhow::Result<()> {
|
|||
.replace("start YuanShen.exe %*", &format!("start YuanShen.exe %*\n\nZ:\ncd \"{}\"\nstart unlocker.exe", unlocker.dir().to_string_lossy())))?;
|
||||
}
|
||||
|
||||
// Generate `config.ini` if environment emulation feature is presented
|
||||
|
||||
#[cfg(feature = "environment-emulation")] {
|
||||
let game = Game::new(&config.game.path);
|
||||
|
||||
std::fs::write(
|
||||
config.game.path.join("config.ini"),
|
||||
config.launcher.environment.generate_config(game.get_version()?.to_string())
|
||||
)?;
|
||||
}
|
||||
|
||||
// Prepare bash -c '<command>'
|
||||
|
||||
let mut bash_command = String::new();
|
||||
|
|
16
src/lib.rs
16
src/lib.rs
|
@ -23,6 +23,9 @@ pub mod fps_unlocker;
|
|||
#[cfg(feature = "discord-rpc")]
|
||||
pub mod discord_rpc;
|
||||
|
||||
#[cfg(feature = "environment-emulation")]
|
||||
pub mod env_emulation;
|
||||
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
/// Check if specified binary is available
|
||||
|
@ -35,12 +38,11 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
|||
pub fn is_available(binary: &str) -> bool {
|
||||
tracing::trace!("Checking package availability");
|
||||
|
||||
match Command::new(binary).stdout(Stdio::null()).stderr(Stdio::null()).spawn() {
|
||||
Ok(mut child) => {
|
||||
child.kill();
|
||||
let Ok(mut child) = Command::new(binary).stdout(Stdio::null()).stderr(Stdio::null()).spawn() else {
|
||||
return false;
|
||||
};
|
||||
|
||||
true
|
||||
},
|
||||
Err(_) => false
|
||||
}
|
||||
child.kill();
|
||||
|
||||
true
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue