#map #valve #source #vmf #parser

vmf-forge

A parser for Valve Map Format (VMF) files

3 releases (breaking)

new 0.3.0 Feb 9, 2025
0.2.0 Jan 28, 2025
0.1.0 Dec 31, 2024

#876 in Parser implementations

Download history 66/week @ 2024-12-25 48/week @ 2025-01-01 7/week @ 2025-01-08 52/week @ 2025-01-22 62/week @ 2025-01-29 129/week @ 2025-02-05

244 downloads per month

MIT license

91KB
2K SLoC

logo

VMF_Forge

Crates.io Docs.rs License

vmf-forge is a Rust library for parsing, manipulating, and serializing Valve Map Format (VMF) files used in Source Engine games.

Features

  • Parses VMF files into convenient Rust data structures.
  • Allows modification of VMF data.
  • Serializes the modified data back into a VMF file.

Installation

Add vmf-forge to your Cargo.toml:

[dependencies]
vmf-forge = "0.3.0"

Usage Example

use vmf_forge::prelude::*;
use std::fs::File;

fn main() -> Result<(), VmfError> {
    let mut file = File::open("your_map.vmf")?;
    let vmf_file = VmfFile::parse_file(&mut file)?;

    // Access and modify the VMF data
    println!("Map Version: {}", vmf_file.versioninfo.map_version);

    // Find info_player_start entity
    if let Some(player_start) = vmf_file.entities.find_by_classname("info_player_start").next() {
       println!("Found player start: {:?}", player_start);
   }

    // Add a new entity
    let mut new_entity = Entity::default();
    new_entity.key_values.insert("classname".to_string(), "prop_static".to_string());
    new_entity.key_values.insert("model".to_string(), "models/props_foliage/urban_tree001a.mdl".to_string());
    new_entity.key_values.insert("origin".to_string(), "0 0 0".to_string());
    vmf_file.entities.push(new_entity);

    // Save the modified VMF file
    vmf_file.save("modified_map.vmf")?;

    Ok(())
}

Contributing

Contributions are welcome! Please feel free to open issues or submit pull requests.

License

vmf-forge is distributed under the terms of either the MIT license.

Dependencies

~3–4.5MB
~86K SLoC