mirror of
https://github.com/ALEZ-DEV/Babylonia-terminal.git
synced 2025-12-15 00:48:52 +00:00
the launcher can now patch the game
This commit is contained in:
parent
52a6b921a9
commit
cf05625135
134
babylonia-terminal-cli/Cargo.lock
generated
134
babylonia-terminal-cli/Cargo.lock
generated
@ -83,6 +83,7 @@ dependencies = [
|
||||
"fs_extra",
|
||||
"log",
|
||||
"reqwest 0.12.2",
|
||||
"rust-embed",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tar",
|
||||
@ -137,6 +138,15 @@ dependencies = [
|
||||
"constant_time_eq",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.15.4"
|
||||
@ -252,6 +262,15 @@ version = "0.8.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.4.0"
|
||||
@ -261,6 +280,16 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "deranged"
|
||||
version = "0.3.11"
|
||||
@ -270,6 +299,16 @@ dependencies = [
|
||||
"powerfmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "5.0.1"
|
||||
@ -493,6 +532,16 @@ dependencies = [
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.12"
|
||||
@ -1251,6 +1300,40 @@ dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-embed"
|
||||
version = "8.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fb78f46d0066053d16d4ca7b898e9343bc3530f71c61d5ad84cd404ada068745"
|
||||
dependencies = [
|
||||
"rust-embed-impl",
|
||||
"rust-embed-utils",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-embed-impl"
|
||||
version = "8.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b91ac2a3c6c0520a3fb3dd89321177c3c692937c4eb21893378219da10c44fc8"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rust-embed-utils",
|
||||
"syn",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-embed-utils"
|
||||
version = "8.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86f69089032567ffff4eada41c573fc43ff466c7db7c5688b2e7969584345581"
|
||||
dependencies = [
|
||||
"sha2",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.23"
|
||||
@ -1319,6 +1402,15 @@ version = "1.0.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
|
||||
|
||||
[[package]]
|
||||
name = "same-file"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "schannel"
|
||||
version = "0.1.23"
|
||||
@ -1410,6 +1502,17 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook-registry"
|
||||
version = "1.4.1"
|
||||
@ -1699,6 +1802,12 @@ version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.15"
|
||||
@ -1749,6 +1858,22 @@ version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "walkdir"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
|
||||
dependencies = [
|
||||
"same-file",
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "want"
|
||||
version = "0.3.1"
|
||||
@ -1846,6 +1971,15 @@ version = "0.25.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b"
|
||||
dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wincompatlib"
|
||||
version = "0.7.4"
|
||||
|
||||
@ -99,7 +99,7 @@ async fn main() {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let mut dir = PathBuf::new();
|
||||
let dir;
|
||||
if let Some(i) = &mut input {
|
||||
if i.is_empty() {
|
||||
dir = GameState::get_config_directory();
|
||||
@ -116,12 +116,19 @@ async fn main() {
|
||||
}
|
||||
|
||||
GameManager::install_game(
|
||||
GameState::get_config_directory().join("PGR"),
|
||||
GameState::get_game_dir().await.unwrap(),
|
||||
DownloadReporter::create(false),
|
||||
)
|
||||
.await
|
||||
.expect("Failed to install the game");
|
||||
}
|
||||
GameState::GameNotPatched => {
|
||||
info!("Patching game...");
|
||||
GameManager::patch_game(GameState::get_game_dir().await.unwrap())
|
||||
.await
|
||||
.expect("Failed to patch the game");
|
||||
info!("Game patched!");
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@ -134,7 +141,9 @@ async fn main() {
|
||||
debug!("{:?}", proton);
|
||||
GameManager::start_game(
|
||||
&proton.unwrap(),
|
||||
GameState::get_config_directory().join("PGR"),
|
||||
GameState::get_game_dir()
|
||||
.await
|
||||
.expect("Failed to start game, the game directory was not found"),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
134
babylonia-terminal-sdk/Cargo.lock
generated
134
babylonia-terminal-sdk/Cargo.lock
generated
@ -70,6 +70,7 @@ dependencies = [
|
||||
"fs_extra",
|
||||
"log",
|
||||
"reqwest 0.12.2",
|
||||
"rust-embed",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tar",
|
||||
@ -124,6 +125,15 @@ dependencies = [
|
||||
"constant_time_eq",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.15.4"
|
||||
@ -216,6 +226,15 @@ version = "0.8.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.4.0"
|
||||
@ -225,6 +244,26 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "5.0.1"
|
||||
@ -442,6 +481,16 @@ dependencies = [
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.12"
|
||||
@ -1112,6 +1161,40 @@ dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-embed"
|
||||
version = "8.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fb78f46d0066053d16d4ca7b898e9343bc3530f71c61d5ad84cd404ada068745"
|
||||
dependencies = [
|
||||
"rust-embed-impl",
|
||||
"rust-embed-utils",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-embed-impl"
|
||||
version = "8.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b91ac2a3c6c0520a3fb3dd89321177c3c692937c4eb21893378219da10c44fc8"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rust-embed-utils",
|
||||
"syn",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-embed-utils"
|
||||
version = "8.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86f69089032567ffff4eada41c573fc43ff466c7db7c5688b2e7969584345581"
|
||||
dependencies = [
|
||||
"sha2",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.23"
|
||||
@ -1180,6 +1263,15 @@ version = "1.0.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
|
||||
|
||||
[[package]]
|
||||
name = "same-file"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "schannel"
|
||||
version = "0.1.23"
|
||||
@ -1265,6 +1357,17 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.9"
|
||||
@ -1486,6 +1589,12 @@ version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.15"
|
||||
@ -1530,6 +1639,22 @@ version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "walkdir"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
|
||||
dependencies = [
|
||||
"same-file",
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "want"
|
||||
version = "0.3.1"
|
||||
@ -1627,6 +1752,15 @@ version = "0.25.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b"
|
||||
dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wincompatlib"
|
||||
version = "0.7.4"
|
||||
|
||||
@ -15,6 +15,7 @@ flate2 = "1.0.28"
|
||||
fs_extra = "1.3.0"
|
||||
log = "0.4.21"
|
||||
reqwest = { version = "0.12.2", features = ["gzip"] }
|
||||
rust-embed = "8.3.0"
|
||||
serde = { version = "1.0.197", features = ["derive"] }
|
||||
serde_json = "1.0.115"
|
||||
tar = "0.4.40"
|
||||
|
||||
BIN
babylonia-terminal-sdk/assets/patched.exe
Normal file
BIN
babylonia-terminal-sdk/assets/patched.exe
Normal file
Binary file not shown.
@ -21,6 +21,7 @@ use tokio::sync::mpsc::Sender;
|
||||
use tokio::time::timeout;
|
||||
|
||||
use super::component_downloader::ComponentDownloader;
|
||||
use crate::utils::get_game_name;
|
||||
use crate::utils::github_requester::GithubRequester;
|
||||
use crate::utils::kuro_prod_api;
|
||||
use crate::utils::kuro_prod_api::Resource;
|
||||
@ -32,7 +33,9 @@ pub struct GameComponent {
|
||||
|
||||
impl GameComponent {
|
||||
pub fn new(game_dir: PathBuf) -> Self {
|
||||
Self { game_dir }
|
||||
Self {
|
||||
game_dir: game_dir.join(get_game_name()),
|
||||
}
|
||||
}
|
||||
|
||||
async fn check_and_get_resources_to_download(
|
||||
@ -101,6 +104,7 @@ impl ComponentDownloader for GameComponent {
|
||||
&self,
|
||||
progress: Option<std::sync::Arc<P>>,
|
||||
) -> anyhow::Result<()> {
|
||||
let _ = create_dir_all(&self.game_dir).await;
|
||||
Self::download(&self.game_dir, progress).await?;
|
||||
|
||||
Ok(())
|
||||
|
||||
@ -2,6 +2,7 @@ use std::{
|
||||
fs::{create_dir, remove_file, rename, File},
|
||||
io::{BufRead, BufReader},
|
||||
path::PathBuf,
|
||||
str::FromStr,
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
};
|
||||
@ -22,7 +23,9 @@ use crate::{
|
||||
game_component::GameComponent,
|
||||
proton_component::ProtonComponent,
|
||||
},
|
||||
game_patcher,
|
||||
game_state::GameState,
|
||||
utils::{get_game_name, get_game_name_with_executable},
|
||||
};
|
||||
|
||||
pub struct GameManager;
|
||||
@ -146,9 +149,21 @@ impl GameManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn patch_game(game_dir: PathBuf) -> anyhow::Result<()> {
|
||||
game_patcher::patch_game(game_dir).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn start_game(proton: &Proton, game_dir: PathBuf) {
|
||||
debug!("Wine version : {:?}", proton.wine().version().unwrap());
|
||||
let mut child = proton.run(game_dir.join("PGR.exe")).unwrap();
|
||||
let mut child = proton
|
||||
.run(
|
||||
game_dir
|
||||
.join(get_game_name())
|
||||
.join(get_game_name_with_executable()),
|
||||
)
|
||||
.unwrap();
|
||||
child.wait().expect("The game failed to run");
|
||||
}
|
||||
}
|
||||
|
||||
104
babylonia-terminal-sdk/src/game_patcher.rs
Normal file
104
babylonia-terminal-sdk/src/game_patcher.rs
Normal file
@ -0,0 +1,104 @@
|
||||
use std::{
|
||||
io::Read,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use dirs::executable_dir;
|
||||
use log::debug;
|
||||
use rust_embed::RustEmbed;
|
||||
use tokio::{
|
||||
fs::{remove_file, rename, File},
|
||||
io::AsyncWriteExt,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
game_state::GameState,
|
||||
utils::{get_game_name, get_game_name_with_executable},
|
||||
};
|
||||
|
||||
pub async fn patch_game(game_dir: PathBuf) -> anyhow::Result<()> {
|
||||
// section to fix bad named file
|
||||
|
||||
debug!("{:?}", game_dir);
|
||||
|
||||
let unity_resources = game_dir.join(get_game_name()).join(format!(
|
||||
"{}{}",
|
||||
get_game_name(),
|
||||
"_Data/Resources/unity%20default%20resources"
|
||||
));
|
||||
|
||||
debug!("unity resources exist? : {}", unity_resources.exists());
|
||||
if unity_resources.exists() {
|
||||
rename(
|
||||
unity_resources.clone(),
|
||||
unity_resources
|
||||
.parent()
|
||||
.unwrap()
|
||||
.join("unity default resources"),
|
||||
)
|
||||
.await?;
|
||||
} else if !unity_resources
|
||||
.parent()
|
||||
.unwrap()
|
||||
.join("unity default resources")
|
||||
.exists()
|
||||
{
|
||||
anyhow::bail!(
|
||||
"{} file doesn't exists ? Please restart the launcher and make a repair.",
|
||||
unity_resources.to_str().unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
// section to replace KRSDKExternal.exe by an empty one
|
||||
//
|
||||
let krsdk_external_path = game_dir.join(get_game_name()).join(format!(
|
||||
"{}{}",
|
||||
get_game_name(),
|
||||
"_Data/Plugins/KRSDKExternal.exe"
|
||||
));
|
||||
|
||||
remove_file(krsdk_external_path.clone()).await?;
|
||||
File::create(krsdk_external_path).await?;
|
||||
|
||||
// section to replace the executable with the patched one
|
||||
|
||||
let executable_path = game_dir
|
||||
.join(get_game_name())
|
||||
.join(get_game_name_with_executable());
|
||||
|
||||
debug!("{:?}", executable_path);
|
||||
|
||||
if executable_path.exists() {
|
||||
remove_file(executable_path.clone()).await?;
|
||||
}
|
||||
|
||||
match PatchedGameExecutable::get_exectable() {
|
||||
Some(exe) => {
|
||||
let mut file = File::create(executable_path).await?;
|
||||
|
||||
let data: Result<Vec<_>, _> = exe.data.bytes().collect();
|
||||
let data = data.expect("Unable to read executable data");
|
||||
|
||||
file.write_all(&data).await?;
|
||||
}
|
||||
None => anyhow::bail!(
|
||||
"Game executable not included in the binary! Please report this to the developer!"
|
||||
),
|
||||
}
|
||||
|
||||
let mut config = GameState::get_config().await;
|
||||
config.is_game_patched = true;
|
||||
GameState::save_config(config).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "assets/"]
|
||||
struct PatchedGameExecutable;
|
||||
|
||||
impl PatchedGameExecutable {
|
||||
fn get_exectable() -> Option<rust_embed::EmbeddedFile> {
|
||||
PatchedGameExecutable::get("patched.exe")
|
||||
}
|
||||
}
|
||||
@ -16,6 +16,7 @@ pub enum GameState {
|
||||
FontNotInstalled,
|
||||
DependecieNotInstalled,
|
||||
GameNotInstalled,
|
||||
GameNotPatched,
|
||||
GameInstalled,
|
||||
}
|
||||
|
||||
@ -28,6 +29,7 @@ pub struct GameConfig {
|
||||
pub is_dependecies_installed: bool,
|
||||
pub game_dir: Option<PathBuf>,
|
||||
pub is_game_installed: bool,
|
||||
pub is_game_patched: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
@ -45,6 +47,7 @@ impl Default for GameConfig {
|
||||
is_dependecies_installed: false,
|
||||
game_dir: None,
|
||||
is_game_installed: false,
|
||||
is_game_patched: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -117,6 +120,10 @@ impl GameState {
|
||||
return GameState::GameNotInstalled;
|
||||
}
|
||||
|
||||
if !config.is_game_patched {
|
||||
return GameState::GameNotPatched;
|
||||
}
|
||||
|
||||
GameState::GameInstalled
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,2 +1,10 @@
|
||||
pub mod github_requester;
|
||||
pub mod kuro_prod_api;
|
||||
|
||||
pub fn get_game_name() -> String {
|
||||
concat!("P", "G", "R").to_string()
|
||||
}
|
||||
|
||||
pub fn get_game_name_with_executable() -> String {
|
||||
format!("{}.exe", get_game_name())
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user