Skip to content

Commit

Permalink
Added support for BE releases, changed UI layout, installer can now d…
Browse files Browse the repository at this point in the history
…etect game arch
  • Loading branch information
funlennysub committed Oct 21, 2022
1 parent 807efe8 commit d0dc47d
Show file tree
Hide file tree
Showing 18 changed files with 501 additions and 155 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = ["bepinex_installer/", "bepinex_helpers/", "bepinex_sources/"]

[workspace.dependencies]
semver = "1.0.14"
anyhow = "1.0.65"
lazy_static = "1"

[profile.release]
Expand Down
77 changes: 54 additions & 23 deletions bepinex_helpers/src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,33 @@ use std::{
};
use steamlocate::SteamDir;

#[macro_export]
macro_rules! game_type {
($ty:expr) => {
$ty.as_ref()
.unwrap()
.to_string()
.split('.')
.collect::<Vec<_>>()
.join("")
};
}

#[derive(Debug)]
pub enum GameArch {
X64,
X86,
}

impl Display for GameArch {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
GameArch::X64 => write!(f, "x64"),
GameArch::X86 => write!(f, "x86"),
}
}
}

#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub enum GameType {
UnityMono,
Expand All @@ -16,8 +43,8 @@ pub enum GameType {
impl Display for GameType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
GameType::UnityMono => write!(f, "UnityMono"),
GameType::UnityIL2CPP => write!(f, "UnityIL2CPP"),
GameType::UnityMono => write!(f, "Unity.Mono"),
GameType::UnityIL2CPP => write!(f, "Unity.IL2CPP"),
}
}
}
Expand All @@ -32,12 +59,12 @@ pub struct Game {
}

impl Game {
pub fn set_bix(&mut self, bix: Option<Version>) {
self.bepinex_version = bix;
pub fn set_bie(&mut self, bie: Option<Version>) {
self.bepinex_version = bie;
}

pub fn set_arch(&mut self, arch: String) {
self.arch = arch;
pub fn set_arch(&mut self, arch: GameArch) {
self.arch = arch.to_string();
}

pub fn set_ty(&mut self, ty: Option<GameType>) {
Expand All @@ -59,6 +86,22 @@ impl Game {
}
}

pub fn get_game_arch(&self) -> GameArch {
let path = &self.path.join(format!("{}.exe", &self.name));
fs::read(path)
.map(|bytes| {
let start =
i32::from_le_bytes(bytes[60..64].try_into().unwrap_or_default()) as usize;
let machine_type =
u16::from_le_bytes(bytes[start + 4..start + 6].try_into().unwrap_or_default());
match machine_type {
34404 => GameArch::X64,
_ => GameArch::X86,
}
})
.unwrap_or_else(|_| GameArch::X64)
}

pub fn get_game_type(&self) -> Option<GameType> {
let mono = "Managed";
let il2cpp = "il2cpp_data";
Expand Down Expand Up @@ -96,20 +139,6 @@ impl Default for Game {
}
}

impl Game {
pub fn to_query(&self, target: &Version) -> String {
match target.major {
6 => format!(
"BepInEx_{}_{}_{}.zip",
self.ty.as_ref().unwrap(),
self.arch,
target
),
_ => format!("BepInEx_{}_{}.0.zip", self.arch, target),
}
}
}

impl Display for Game {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.name)
Expand All @@ -135,10 +164,12 @@ pub fn get_unity_games() -> Result<Vec<Game>, Box<dyn error::Error>> {
ty: None,
};

let bix_ver = game.get_installed_bepinex_version();
let bie_ver = game.get_installed_bepinex_version();
let game_type = game.get_game_type();
game.set_bix(bix_ver);
let game_arch = game.get_game_arch();
game.set_bie(bie_ver);
game.set_ty(game_type);
game.set_arch(game_arch);

Some(game)
}
Expand Down Expand Up @@ -175,6 +206,6 @@ pub fn get_dll_version(path: PathBuf) -> Result<Version, Box<dyn error::Error>>
return Ok(Version::parse(&ver).unwrap());
}

// TODO: Do some proper handling of invalid semver that bix has in older versions 💀
// TODO: Do some proper handling of invalid semver that bie has in older versions 💀
Ok(Version::parse(version).unwrap())
}
13 changes: 5 additions & 8 deletions bepinex_installer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@ name = "bepinex-installer"
version = "0.2.0"
edition = "2021"

# [profile.release]
# strip = true
# lto = true
# panic = "abort"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bepinex_helpers = { path = "../bepinex_helpers" }
bepinex_sources = { path = "../bepinex_sources" }
eframe = "0.19.0"
egui_extras = "0.19.0"
semver = { workspace = true }
lazy_static = { workspace = true }
reqwest = { version = "0.11.12", features = ["json", "blocking"] }
semver.workspace = true
lazy_static.workspace = true
egui-toast = "0.4.0"
poll-promise = "0.1.0"
anyhow.workspace = true
parking_lot = "0.12.1"
2 changes: 1 addition & 1 deletion bepinex_installer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
| Name | Description | Status |
| ------------------------ | ----------------------- | :----: |
| Stable Releases | Install stable releases ||
| BE Releases | Install BE releases | |
| BE Releases | Install BE releases | |
| Better UI | Make UI look pretty | 👷‍♀️ |
| Support other game types | Support for .NET games ||
Loading

0 comments on commit d0dc47d

Please sign in to comment.