Skip to content

Commit

Permalink
Merge pull request #26 from dark0dave/feature/writers
Browse files Browse the repository at this point in the history
feature/writers
  • Loading branch information
dark0dave authored Nov 2, 2024
2 parents 0139bfb + 9ffbe13 commit 5686b33
Show file tree
Hide file tree
Showing 20 changed files with 362 additions and 144 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
run: |
cargo build --release
- name: Archive release artifacts
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: post_infinity-${{ matrix.target }}${{ matrix.suffix }}
path: ./target/release/post_infinity${{ matrix.suffix }}
Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
suffix: .exe
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: post_infinity-${{ matrix.target }}${{ matrix.suffix }}
- name: Upload Release Asset - ${{ matrix.os }}
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
default_install_hook_types: [pre-commit, commit-msg]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
exclude: (?x)^([models/fixtures|docs])
Expand Down Expand Up @@ -29,7 +29,7 @@ repos:
stages: [pre-commit]

- repo: https://github.com/commitizen-tools/commitizen
rev: v3.27.0
rev: v3.30.0
hooks:
- id: commitizen
stages: [commit-msg]
Expand Down
83 changes: 79 additions & 4 deletions Cargo.lock

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

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ edition = "2021"
[workspace]

[dependencies]
binrw = "0.14.0"
clap = { version = "4.0", features = ["derive"] }
binrw = "^0.14.1"
clap = { version = "^4.0", features = ["derive", "env"] }
env_logger = "^0.11.1"
erased-serde = "0.4"
log = "^0.4.22"
models = { path = "./models" }
serde_json = "1.0"
serde_json = "^1.0"
14 changes: 7 additions & 7 deletions models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
binrw = "0.14.0"
erased-serde = "0.4"
flate2 = { version = "1.0.17" }
serde = { version = "1.0.189", features = ["derive"] }
serde_json = "1.0.94"
binrw = "^0.14.1"
erased-serde = "^0.4"
flate2 = { version = "^1.0.17" }
serde = { version = "^1.0.189", features = ["derive"] }
serde_json = "^1.0.94"

[dev-dependencies]
pretty_assertions = "1.3.0"
tempfile = "3"
pretty_assertions = "^1.3.0"
tempfile = "^3"
2 changes: 2 additions & 0 deletions models/src/character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ pub struct ExpandedCharacter {
#[serde(skip)]
#[br(parse_with = until_eof, restore_position)]
pub original_bytes: Vec<u8>,
#[bw(ignore)]
#[serde(flatten)]
pub character: BGCharacter,
#[bw(ignore)]
#[serde(flatten)]
pub creature: Creature,
}
Expand Down
12 changes: 12 additions & 0 deletions models/src/common/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![allow(dead_code, unused_variables)]

use std::{error::Error, path::Path};

use binrw::{BinRead, BinWrite};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -106,6 +108,16 @@ impl std::fmt::Display for ResourceType {
}
}

impl TryFrom<&Path> for ResourceType {
type Error = Box<dyn Error>;
fn try_from(value: &Path) -> Result<Self, Self::Error> {
let extension = value.extension().ok_or("Path has no extension")?;
Ok(Self::from(
extension.to_str().ok_or("Could not convert to string")?,
))
}
}

impl From<&str> for ResourceType {
fn from(value: &str) -> Self {
match value.to_ascii_lowercase().as_str() {
Expand Down
7 changes: 7 additions & 0 deletions models/src/creature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,25 @@ pub struct Creature {
pub original_bytes: Vec<u8>,
#[serde(flatten)]
pub header: BGEECreatureHeader,
#[bw(ignore)]
#[br(count=header.count_of_known_spells, seek_before=SeekFrom::Start(header.offset_to_known_spells as u64))]
pub known_spells: Vec<KnownSpells>,
#[bw(ignore)]
#[br(count=header.count_of_spell_memorization_info, seek_before=SeekFrom::Start(header.offset_to_spell_memorization_info as u64))]
pub memorized_spell_info: Vec<SpellMemorizationInfo>,
#[bw(ignore)]
#[br(count=header.count_of_memorized_spell_table, seek_before=SeekFrom::Start(header.offset_to_memorized_spell_table as u64))]
pub memorized_spells: Vec<SpellMemorizationTable>,
#[bw(ignore)]
#[br(if(header.effstructure == 0), count=header.count_of_effects, seek_before=SeekFrom::Start(header.offset_to_effects as u64))]
pub effects_v1: Vec<EffectV1>,
#[bw(ignore)]
#[br(if(header.effstructure == 1), count=header.count_of_effects, seek_before=SeekFrom::Start(header.offset_to_effects as u64))]
pub effects_v2: Vec<EffectV2Body>,
#[bw(ignore)]
#[br(count=header.count_of_items, seek_before=SeekFrom::Start(header.offset_to_items as u64))]
pub item_table: Vec<ItemReferenceTable>,
#[bw(ignore)]
#[br(seek_before=SeekFrom::Start(header.offset_to_item_slots as u64))]
pub item_slots: Option<ItemSlots>,
}
Expand Down
6 changes: 6 additions & 0 deletions models/src/dialogue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@ pub struct Dialogue {
#[serde(skip)]
#[br(parse_with = until_eof, restore_position)]
pub original_bytes: Vec<u8>,
#[bw(ignore)]
#[serde(flatten)]
pub header: DialogueHeader,
#[bw(ignore)]
#[br(count=header.count_of_state_tables)]
pub state_tables: Vec<StateTable>,
#[bw(ignore)]
#[br(count=header.count_of_transitions)]
pub transitions: Vec<Transition>,
#[bw(ignore)]
#[br(count=header.count_of_state_triggers)]
pub state_triggers: Vec<StateTrigger>,
#[bw(ignore)]
#[br(count=header.count_of_transition_triggers)]
pub transition_triggers: Vec<TransitionTrigger>,
#[bw(ignore)]
#[br(count=header.count_of_action_tables)]
pub action_tables: Vec<ActionTable>,
}
Expand Down
11 changes: 11 additions & 0 deletions models/src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,37 @@ pub struct Game {
#[serde(skip)]
#[br(parse_with = until_eof, restore_position)]
pub original_bytes: Vec<u8>,
#[bw(ignore)]
#[serde(flatten)]
pub header: BGEEGameHeader,
#[bw(ignore)]
#[br(count=header.count_of_npc_structs_for_party_members)]
pub party_npcs: Vec<GameNPC>,
#[bw(ignore)]
#[br(parse_with = |reader, _, _:()| parse_creatures(reader, &party_npcs))]
pub party_npcs_cres: Vec<Creature>,
#[bw(ignore)]
#[br(count=header.count_of_npc_structs_for_npcs)]
pub non_party_npcs: Vec<GameNPC>,
#[bw(ignore)]
#[br(parse_with = |reader, _, _:()| parse_creatures(reader, &non_party_npcs))]
pub non_party_npcs_cres: Vec<Creature>,
#[bw(ignore)]
#[br(count=header.count_of_global_namespace_variables)]
pub global_variables: Vec<GlobalVariables>,
#[bw(ignore)]
#[br(if(header.offset_to_journal_entries != u32::MAX), count=header.count_of_journal_entries, seek_before=SeekFrom::Start(header.offset_to_journal_entries as u64))]
pub journal_entries: Vec<JournalEntries>,
#[bw(ignore)]
#[br(seek_before=SeekFrom::Start(header.offset_to_familiar as u64))]
pub familiar: Option<Familiar>,
#[bw(ignore)]
#[br(count=header.count_of_stored_locations, seek_before=SeekFrom::Start(header.offset_to_stored_locations as u64))]
pub stored_locations: Vec<Location>,
#[bw(ignore)]
#[br(count=header.count_of_pocket_plane_locations, seek_before=SeekFrom::Start(header.offset_to_pocket_plane_locations as u64))]
pub pocket_plane_locations: Vec<Location>,
#[bw(ignore)]
#[br(if(header.offset_to_familiar_extra != u32::MAX), parse_with=binrw::helpers::until_eof, seek_before=SeekFrom::Start(header.offset_to_familiar_extra as u64))]
pub familiar_extra: Vec<FamiliarExtra>,
}
Expand Down
1 change: 1 addition & 0 deletions models/src/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct Ids {
#[serde(skip)]
#[br(parse_with = until_eof, restore_position)]
pub original_bytes: Vec<u8>,
#[bw(ignore)]
#[br(parse_with = |reader, _, _:()| read_to_end(reader))]
pub data: CharArray,
}
Expand Down
3 changes: 3 additions & 0 deletions models/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ pub struct Item {
#[serde(skip)]
#[br(parse_with = until_eof, restore_position)]
pub original_bytes: Vec<u8>,
#[bw(ignore)]
#[serde(flatten)]
pub header: ItemHeader,
#[bw(ignore)]
#[br(count=header.count_of_extended_headers)]
pub extended_headers: Vec<ItemExtendedHeader>,
#[bw(ignore)]
#[br(count=header.count_of_feature_blocks)]
pub equipping_feature_blocks: Vec<ItemFeatureBlock>,
}
Expand Down
7 changes: 5 additions & 2 deletions models/src/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ pub struct Save {
#[serde(skip)]
#[br(parse_with = until_eof, restore_position)]
pub original_bytes: Vec<u8>,
#[bw(ignore)]
#[br(count = 4)]
signature: CharArray,
pub signature: CharArray,
#[bw(ignore)]
#[br(count = 4)]
version: CharArray,
pub version: CharArray,
#[bw(ignore)]
#[br(parse_with=binrw::helpers::until_eof)]
pub files: Vec<SavedFile>,
}
Expand Down
3 changes: 3 additions & 0 deletions models/src/spell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ pub struct Spell {
#[serde(skip)]
#[br(parse_with = until_eof, restore_position)]
pub original_bytes: Vec<u8>,
#[bw(ignore)]
#[serde(flatten)]
pub header: SpellHeader,
#[bw(ignore)]
#[br(count=header.count_of_extended_headers)]
pub extended_headers: Vec<SpellExtendedHeader>,
#[bw(ignore)]
#[br(parse_with=binrw::helpers::until_eof)]
pub equipping_feature_blocks: Vec<SpellFeatureBlock>,
}
Expand Down
Loading

0 comments on commit 5686b33

Please sign in to comment.