Skip to content

Commit

Permalink
Merge pull request #10 from Bytekeeper/linux
Browse files Browse the repository at this point in the history
Improved Linux support; added JRE download support
  • Loading branch information
Bytekeeper committed Feb 27, 2023
2 parents a0e2413 + e91b1d8 commit 9e28296
Show file tree
Hide file tree
Showing 11 changed files with 325 additions and 173 deletions.
68 changes: 28 additions & 40 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion game.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ time_out_at_frame = 85714

# This one will run NiteKatT and ZergHell in a window, so you can observe
# Known bug: If the game is hosted by a headful bot, it will not be created automatically - you'll have to click 'create'
#game_type = { Melee = [{name = "NitekatT", race = "Protoss", headful = true}, {name = "MarineHell"}, {name = "ZergHell", headful = true}] }
#game_type = { Melee = [{name = "NitekatT", race = "Protoss", headful = true}, {name = "MarineHell"}, {name = "ZergHell", headful = { On = {} }}] }

# Want to join the fray? Uncomment this and open a game
# human_host = true
Expand Down
2 changes: 0 additions & 2 deletions game_table/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ edition = "2021"
[dependencies]
shared_memory = "0.12"
log = "0.4"
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
9 changes: 6 additions & 3 deletions game_table/src/game_table.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
#[cfg(target_os = "windows")]
use log::debug;
use serde::{Deserialize, Serialize};
#[cfg(target_os = "windows")]
use shared_memory::*;
#[cfg(target_os = "windows")]
use std::mem::size_of;

#[repr(C)]
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug)]
pub struct GameInstance {
pub server_process_id: u32,
pub is_connected: bool,
pub last_keep_alive_time: u32,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug)]
pub struct GameTable {
pub game_instances: [GameInstance; 8],
}

#[cfg(target_os = "windows")]
pub struct GameTableAccess {
game_table: Option<Shmem>,
}
Expand Down
4 changes: 3 additions & 1 deletion game_table/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod game_table;

pub use crate::game_table::{GameTable, GameTableAccess};
pub use crate::game_table::GameTable;
#[cfg(target_os = "windows")]
pub use crate::game_table::GameTableAccess;
10 changes: 6 additions & 4 deletions game_table/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
mod game_table;
use crate::game_table::*;
use std::io::Write;

fn main() {
#[cfg(target_os = "windows")]
GameTableAccess::new()
.get_game_table()
.and_then(|out| serde_json::to_string(&out).ok())
.map(|out| println!("{out}"));
GameTableAccess::new().get_game_table().map(|out| {
std::io::stdout().write(unsafe {
&std::mem::transmute::<GameTable, [u8; std::mem::size_of::<GameTable>()]>(out)[..]
})
});
}
28 changes: 23 additions & 5 deletions src/bwapi.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
use crate::botsetup::BotSetup;
use crate::{tools_folder, Binary, Race};
#[cfg(not(target_os = "windows"))]
use crate::tools_folder;
use crate::{Binary, Race};
#[cfg(not(target_os = "windows"))]
use anyhow::Context;
use game_table::GameTable;
#[cfg(not(target_os = "windows"))]
use log::trace;
use std::io::Write;
use std::path::PathBuf;
#[cfg(not(target_os = "windows"))]
use std::process::{Command, Stdio};

pub struct GameTableAccess {
Expand Down Expand Up @@ -34,9 +39,14 @@ impl GameTableAccess {
.output()
.context("Executing game_table.exe with wine")
.expect("Unable to execute game_table.exe with wine");
let res = serde_json::from_slice(&output.stdout).ok();
trace!("{res:?}");
res
if output.stdout.len() == std::mem::size_of::<GameTable>() {
let res: GameTable =
unsafe { std::ptr::read_unaligned(output.stdout.as_slice().as_ptr().cast()) };
trace!("{res:?}");
Some(res)
} else {
None
}
}
}

Expand Down Expand Up @@ -148,6 +158,13 @@ impl BwapiIni {
if let Some(tm) = &self.tm_module {
writeln!(out, "tournament = {}", tm.to_string_lossy())?;
}
writeln!(out, "[config]")?;
writeln!(out, "holiday = OFF")?;
// writeln!(out, "console_attach_on_startup = FALSE")?;
// writeln!(out, "console_alloc_on_startup = FALSE")?;
// writeln!(out, "console_attach_auto = TRUE")?;
// writeln!(out, "console_alloc_auto = TRUE")?;

writeln!(out, "[auto_menu]")?;
match &self.auto_menu {
AutoMenu::Unused => (),
Expand Down Expand Up @@ -182,7 +199,8 @@ impl BwapiIni {
writeln!(out, "[starcraft]")?;
writeln!(out, "speed_override = {}", self.game_speed)?;
let sound = if self.sound { "ON" } else { "OFF" };
writeln!(out, "sound = {sound}")
writeln!(out, "sound = {sound}")?;
writeln!(out, "drop_players = ON")
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/java_setup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use crate::base_folder;
use crate::setup::{ComponentConfig, ComponentInstallation};
use hex_literal::hex;
use std::path::PathBuf;

pub fn java_component(config: ComponentConfig) -> ComponentInstallation {
ComponentInstallation {
name: "Java 8 JRE",
download_name: "jre.zip",
download_url: "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u362-b09/OpenJDK8U-jre_x86-32_windows_hotspot_8u362b09.zip",
locator: || Ok(PathBuf::from("javaw.exe")),
provider: |component| component.download_and_unzip(true).map(|_| component.internal_folder.join("bin").join("javaw.exe")),
config,
hashes: &[hex!("ab1c3756c0f94e982edf77e7048263d2c7fc1048c57dd1185e5f441f007e9653") ],
internal_folder: base_folder().join("jre"),
}
}

pub fn java_default_config() -> ComponentConfig {
#[cfg(target_os = "windows")]
return ComponentConfig::Locate;
#[cfg(not(target_os = "windows"))]
return ComponentConfig::Internal;
}
Loading

0 comments on commit 9e28296

Please sign in to comment.