Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b5358ff
Start aoe2de support
the-eater May 14, 2021
31b140a
genie-rec: move to state based header reader, and define traits for e…
the-eater May 16, 2021
3f6fdfa
Make building optional
the-eater May 19, 2021
dc452ba
Improve DE support
the-eater May 19, 2021
9e27ad5
Add lint to get rid of unused macro rule temporarily
simonsan Sep 24, 2022
7010447
Bubble err
simonsan Sep 24, 2022
e79b506
Continue implementation
simonsan Sep 24, 2022
6559538
Fix some header stuff
simonsan Sep 25, 2022
c4b28c4
Adding some enums
simonsan Sep 25, 2022
2d51a25
Merge remote-tracking branch 'origin/default' into feature/aoe2de_sup…
simonsan Sep 26, 2022
673f3a5
Fix some more clippy lints
simonsan Sep 26, 2022
03ca3d2
#[allow(dead_code)] for genie-rec until stabilised
simonsan Sep 26, 2022
9d94c09
Implement Peek for BufReader
simonsan Sep 26, 2022
c98fe42
Add bacon file for development purposes
simonsan Sep 27, 2022
584f990
Add comment for using nextest
simonsan Sep 27, 2022
17e1614
Refactor modules
simonsan Sep 28, 2022
31ee546
Continue to fix header parsing
simonsan Sep 29, 2022
b8aa9d1
Implement dbg_dmp! macro for easier debugging with file offsets
simonsan Sep 29, 2022
b85ec1b
Create debug table for seeking
simonsan Sep 29, 2022
3bec314
Add utf-8 to dbg_dmp macro
simonsan Sep 29, 2022
1289adc
Fix clippy lint
simonsan Sep 30, 2022
a8ffa80
Rename example files to be better readable
simonsan Oct 1, 2022
a564802
Add cfg to only use dbg_dmp in debug builds
simonsan Oct 1, 2022
3f81228
Remove binary file
simonsan Oct 1, 2022
08a938b
Rename read_hd_style_str to read_tlv_str (type-length-value)
simonsan Oct 1, 2022
f8b4d1e
Increase version of genie-support due to api breaking change of renam…
simonsan Oct 1, 2022
c9760e8
Add better handling for TLV strings during debugging
simonsan Oct 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/target
**/*.rs.bk
Cargo.lock
.vscode
.vscode
crates/genie-rec/examples/nom.rs
59 changes: 39 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
[package]
name = "genie"
version = "0.5.0"
authors = ["Renée Kooi <renee@kooi.me>"]
edition = "2018"
license = "GPL-3.0"
description = "Libraries for reading/writing Age of Empires II data files"
documentation = "https://docs.rs/genie/"
homepage = "https://github.com/SiegeEngineers/genie-rs"
readme = "./README.md"

[workspace]
members = [
"crates/genie-cpx",
"crates/genie-dat",
"crates/genie-drs",
"crates/genie-hki",
"crates/genie-lang",
"crates/genie-rec",
"crates/genie-scx",
"crates/genie-support",
"crates/jascpal",
]

[workspace.package]
authors = ["Renée Kooi <renee@kooi.me>"]
edition = "2021"
rust-version = "1.64.0"
license = "GPL-3.0"
repository = "https://github.com/SiegeEngineers/genie-rs"
readme = "README.md"

[workspace.dependencies]
structopt = "0.3.26"
anyhow = "1.0.65"
simplelog = "0.12.0"
thiserror = "1.0.36"
byteorder = "1.4.3"
flate2 = { version = "1.0.24", features = [
"rust_backend",
], default-features = false }
encoding_rs = "0.8.31"
encoding_rs_io = "0.1.7"
rgb = "0.8.34"
num_enum = "0.5.7"
arrayvec = "0.7.2"

[dependencies]
genie-cpx = { version = "0.5.0", path = "crates/genie-cpx" }
Expand All @@ -20,19 +52,6 @@ genie-scx = { version = "4.0.0", path = "crates/genie-scx" }
jascpal = { version = "0.1.1", path = "crates/jascpal" }

[dev-dependencies]
structopt = "0.3.20"
anyhow = "1.0.33"
simplelog = "0.10.0"

[workspace]
members = [
"crates/genie-cpx",
"crates/genie-dat",
"crates/genie-drs",
"crates/genie-hki",
"crates/genie-lang",
"crates/genie-rec",
"crates/genie-scx",
"crates/genie-support",
"crates/jascpal"
]
structopt.workspace = true
anyhow.workspace = true
simplelog.workspace = true
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# genie-rs

Rust libraries for reading/writing various Age of Empires I/II files.
[![docs.rs](https://img.shields.io/badge/docs.rs-genie-blue?style=flat-square)](https://docs.rs/genie/)
[![crates.io](https://img.shields.io/crates/v/genie.svg?style=flat-square)](https://crates.io/crates/genie)
[![GitHub license](https://img.shields.io/github/license/SiegeEngineers/genie-rs?style=flat-square&color=darkred)](https://github.com/SiegeEngineers/genie-rs/blob/default/LICENSE.md)
![MSRV](https://img.shields.io/badge/MSRV-1.64.0%2B-blue?style=flat-square)

See [docs.rs](https://docs.rs/genie) for documentation.
Rust libraries for reading/writing various Age of Empires I/II files.

## Example Programs

Expand Down
101 changes: 101 additions & 0 deletions bacon.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# This is a configuration file for the bacon tool
# More info at https://github.com/Canop/bacon

default_job = "check"

[jobs]

[jobs.check]
command = ["cargo", "check", "--color", "always"]
need_stdout = false

[jobs.check-all]
command = ["cargo", "check", "--all-targets", "--color", "always"]
need_stdout = false
watch = ["tests", "benches", "examples"]

[jobs.clippy]
command = ["cargo", "clippy", "--color", "always"]
need_stdout = false

[jobs.clippy-all]
command = ["cargo", "clippy", "--all-targets", "--color", "always"]
need_stdout = false
watch = ["tests", "benches", "examples"]

[jobs.test]
command = ["cargo", "test", "--workspace", "--color", "always"]
need_stdout = true
watch = ["tests"]

# Uses nextest
[jobs.ntest]
command = [
"cargo",
"nextest",
"run",
"--workspace",
"--color",
"always",
"--build-jobs",
"14",
"--fail-fast",
"--test-threads",
"14",
]
need_stdout = true
watch = ["tests"]

# Only test a single package
# Uses nextest
[jobs.mtest]
command = [
"cargo",
"nextest",
"run",
"--color",
"always",
"--build-jobs",
"14",
"--fail-fast",
"--test-threads",
"14",
"-p",
"genie-rec",
]
need_stdout = true
watch = ["tests"]


[jobs.doc]
command = ["cargo", "doc", "--color", "always", "--no-deps"]
need_stdout = false

# if the doc compiles, then it opens in your browser and bacon switches
# to the previous job
[jobs.doc-open]
command = ["cargo", "doc", "--color", "always", "--no-deps", "--open"]
need_stdout = false
on_success = "back" # so that we don't open the browser at each change

# You can run your application and have the result displayed in bacon,
# *if* it makes sense for this crate. You can run an example the same
# way. Don't forget the `--color always` part or the errors won't be
# properly parsed.
[jobs.run]
command = ["cargo", "run", "--color", "always"]
need_stdout = true
allow_warnings = true

# You may define here keybindings that would be specific to
# a project, for example a shortcut to launch a specific job.
# Shortcuts to internal functions (scrolling, toggling, etc.)
# should go in your personal prefs.toml file instead.
[keybindings]
a = "job:check-all"
i = "job:initial"
c = "job:clippy"
d = "job:doc-open"
t = "job:ntest"
r = "job:run"
e = "job:mtest"
21 changes: 12 additions & 9 deletions crates/genie-cpx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
[package]
name = "genie-cpx"
version = "0.5.0"
authors = ["Renée Kooi <renee@kooi.me>"]
edition = "2018"
license = "GPL-3.0"
rust-version.workspace = true
authors.workspace = true
edition.workspace = true
license.workspace = true
description = "Read and write Age of Empires I/II campaign files."
homepage = "https://github.com/SiegeEngineers/genie-rs"
repository = "https://github.com/SiegeEngineers/genie-rs"
homepage = "https://github.com/SiegeEngineers/genie-rs/tree/default/crates/genie-cpx"
documentation = "https://docs.rs/genie-cpx"
repository.workspace = true
readme = "./README.md"
exclude = ["test/campaigns"]

[dependencies]
byteorder = "1.3.4"
byteorder.workspace = true
chardet = "0.2.4"
encoding_rs = "0.8.24"
encoding_rs.workspace = true
genie-scx = { version = "4.0.0", path = "../genie-scx" }
thiserror = "1.0.21"
thiserror.workspace = true

[dev-dependencies]
anyhow = "1.0.33"
anyhow.workspace = true
9 changes: 5 additions & 4 deletions crates/genie-cpx/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# genie-cpx

Read and write Age of Empires I/II campaign files.

## Usage
[![docs.rs](https://img.shields.io/badge/docs.rs-genie--cpx-blue?style=flat-square&color=blue)](https://docs.rs/genie-cpx/)
[![crates.io](https://img.shields.io/crates/v/genie-cpx.svg?style=flat-square&color=orange)](https://crates.io/crates/genie-cpx)
[![GitHub license](https://img.shields.io/github/license/SiegeEngineers/genie-rs?style=flat-square&color=darkred)](https://github.com/SiegeEngineers/genie-rs/blob/default/LICENSE.md)
![MSRV](https://img.shields.io/badge/MSRV-1.64.0%2B-blue?style=flat-square)

See [docs.rs](https://docs.rs/genie-cpx) for API documentation.
Read and write Age of Empires I/II campaign files.

## License

Expand Down
4 changes: 2 additions & 2 deletions crates/genie-cpx/src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ fn decode_str(bytes: &[u8]) -> Result<String> {
return Ok("".to_string());
}

let (encoding_name, _confidence, _language) = detect_encoding(&bytes);
let (encoding_name, _confidence, _language) = detect_encoding(bytes);
Encoding::for_label(encoding_name.as_bytes())
.ok_or(ReadCampaignError::DecodeStringError)
.and_then(|encoding| {
let (decoded, _enc, failed) = encoding.decode(&bytes);
let (decoded, _enc, failed) = encoding.decode(bytes);
if failed {
return Err(ReadCampaignError::DecodeStringError);
}
Expand Down
27 changes: 15 additions & 12 deletions crates/genie-dat/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
[package]
name = "genie-dat"
version = "0.1.0"
authors = ["Renée Kooi <renee@kooi.me>"]
edition = "2018"
license = "GPL-3.0"
rust-version.workspace = true
authors.workspace = true
edition.workspace = true
license.workspace = true
description = "Read and write Age of Empires I/II data files."
homepage = "https://github.com/SiegeEngineers/genie-rs"
repository = "https://github.com/SiegeEngineers/genie-rs"
homepage = "https://github.com/SiegeEngineers/genie-rs/tree/default/crates/genie-dat"
documentation = "https://docs.rs/genie-dat"
repository.workspace = true
readme = "./README.md"

[dependencies]
arrayvec = "0.7.0"
byteorder = "1.3.4"
encoding_rs = "0.8.24"
flate2 = { version = "1.0.18", features = ["rust_backend"], default-features = false }
genie-support = { version = "^1.0.0", path = "../genie-support" }
arrayvec.workspace = true
byteorder.workspace = true
encoding_rs.workspace = true
flate2.workspace = true
genie-support = { version = "^2.0.0", path = "../genie-support" }
jascpal = { version = "^0.1.0", path = "../jascpal" }
thiserror = "1.0.21"
thiserror.workspace = true

[dev-dependencies]
anyhow = "1.0.33"
anyhow.workspace = true
12 changes: 12 additions & 0 deletions crates/genie-dat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# genie-dat

[![docs.rs](https://img.shields.io/badge/docs.rs-genie--dat-blue?style=flat-square&color=blue)](https://docs.rs/genie-dat/)
[![crates.io](https://img.shields.io/crates/v/genie-dat.svg?style=flat-square&color=orange)](https://crates.io/crates/genie-dat)
[![GitHub license](https://img.shields.io/github/license/SiegeEngineers/genie-rs?style=flat-square&color=darkred)](https://github.com/SiegeEngineers/genie-rs/blob/default/LICENSE.md)
![MSRV](https://img.shields.io/badge/MSRV-1.64.0%2B-blue?style=flat-square)

Read and write Age of Empires I/II data files.

## License

[GPL-3.0](../../LICENSE.md)
10 changes: 4 additions & 6 deletions crates/genie-dat/src/civ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Civilization {
let mut bytes = [0; 20];
input.read_exact(&mut bytes)?;
let bytes = &bytes[..bytes.iter().position(|&c| c == 0).unwrap_or(bytes.len())];
let (name, _encoding, _failed) = WINDOWS_1252.decode(&bytes);
let (name, _encoding, _failed) = WINDOWS_1252.decode(bytes);
civ.name = CivName::from(&name).unwrap();
let num_attributes = input.read_u16::<LE>()?;
civ.civ_effect = input.read_u16::<LE>()?;
Expand Down Expand Up @@ -112,7 +112,7 @@ impl Civilization {
/// Write civilization data to an output stream.
pub fn write_to(&self, mut output: impl Write, version: GameVersion) -> Result<()> {
let mut name = [0; 20];
(&mut name[..self.name.len()]).copy_from_slice(self.name.as_bytes());
(name[..self.name.len()]).copy_from_slice(self.name.as_bytes());
output.write_all(&name)?;
output.write_u16::<LE>(self.attributes.len().try_into().unwrap())?;
output.write_u16::<LE>(self.civ_effect)?;
Expand All @@ -129,10 +129,8 @@ impl Civilization {
None => 0,
})?;
}
for opt in &self.unit_types {
if let Some(unit_type) = opt {
unit_type.write_to(&mut output, version.as_f32())?;
}
for unit_type in self.unit_types.iter().flatten() {
unit_type.write_to(&mut output, version.as_f32())?;
}
Ok(())
}
Expand Down
10 changes: 4 additions & 6 deletions crates/genie-dat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl GameVersion {
}

/// A data file version.
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FileVersion([u8; 8]);

impl From<[u8; 8]> for FileVersion {
Expand All @@ -80,7 +80,7 @@ impl From<&str> for FileVersion {
fn from(string: &str) -> Self {
assert!(string.len() <= 8);
let mut bytes = [0; 8];
(&mut bytes[..string.len()]).copy_from_slice(string.as_bytes());
(bytes[..string.len()]).copy_from_slice(string.as_bytes());
Self::from(bytes)
}
}
Expand Down Expand Up @@ -400,10 +400,8 @@ impl DatFile {
None => 0,
})?;
}
for maybe_sprite in &self.sprites {
if let Some(sprite) = maybe_sprite {
sprite.write_to(&mut output)?;
}
for sprite in self.sprites.iter().flatten() {
sprite.write_to(&mut output)?;
}

output.write_u32::<LE>(0)?; // map vtable pointer
Expand Down
Loading