GithubHelp home page GithubHelp logo

theobori / tinywad Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 2.54 MB

๐Ÿฉธ A library to manage WAD for DOOM based game

Home Page: https://crates.io/crates/tinywad

License: MIT License

Rust 100.00%
composer doom manager modding rust iwad pwad library

tinywad's Introduction

๐Ÿฉธ tinywad

build

A library to manage WAD for DOOM based game. It has been tested with the following IWAD:

  • DOOM.WAD
  • DOOM2.WAD
  • HEXEN.WAD
  • CHEX.WAD
  • TNT.WAD
  • PLUTONIA.WAD
  • STRIFE0.WAD
  • STRIFE1.WAD
  • DOOMU.WAD
  • DOOM2F.WAD
  • HEXDD.WAD

It supports the following features:

  • Load WAD buffer/file
  • Extract lump raw content
  • Extract lump as original files (PNGs)
  • Extract the image lumps with a custom color palette
  • Update lump raw content
  • Build a IWAD/PWAD
  • Add/insert lumps then save the WAD file

๐Ÿ“– How to build and run ?

  1. Install the dependencies
    • cargo

โญ Use cases

Patching directly the IWAD

use tinywad::error::WadError;
use tinywad::models::operation::WadOp;
use tinywad::wad::Wad;

fn main() -> Result<(), WadError> {
    let mut doom_2 = Wad::new();
    doom_2.load_from_file("doom2.wad")?;

    let gate = doom_2.lump("GATE3").unwrap();

    let mut doom_1 = Wad::new();
    doom_1.load_from_file("doom1.wad")?;

    doom_1.select("^FLAT|FLOOR");
    doom_1.update_lumps_raw(&gate.data().buffer);
    doom_1.save("doom1.wad");

    Ok(())
}

Screenshot(s)

Extracting lumps with custom palettes

use std::fs;

use tinywad::dir::MAX_PAL;
use tinywad::error::WadError;
use tinywad::models::operation::WadOp;
use tinywad::wad::Wad;

fn main() -> Result<(), WadError> {
    let mut doom_2 = Wad::new();
    doom_2.load_from_file("doom2.wad")?;

    for pal in 0..MAX_PAL {
        doom_2.set_palette(pal);
        doom_2.reload()?;
        doom_2.select("^BOSF");
        
        let dirpath = format!("doom2/pal_{}", pal);

        fs::create_dir_all(dirpath.clone()).unwrap();

        doom_2.save_lumps(dirpath);
    }

    Ok(())
}

Extracted lumps (as PNGs)

Building a PWAD from scratch

use tinywad::error::WadError;
use tinywad::lump::{LumpAdd, LumpAddKind};
use tinywad::models::operation::WadOp;
use tinywad::wad::{Wad, WadKind,};

fn main() -> Result<(), WadError> {
    let mut src = Wad::new();

    let lump_names = [
        "FLOOR0_1", "FLOOR0_3", "FLOOR0_6",
        "FLOOR1_1", "FLOOR1_7", "FLOOR3_3",
        "FLOOR4_1", "FLOOR4_5", "FLOOR4_6",
        "FLOOR4_8", "FLOOR5_1", "FLOOR5_2",
        "FLOOR5_3", "FLOOR5_4", "FLOOR6_1",
        "FLOOR6_2", "FLOOR7_1", "FLOOR7_2",
    ];

    src.load_from_file("doom.wad")?;

    let gate = src.lump("FLOOR6_1").unwrap();

    let mut dest = Wad::new();

    dest.set_kind(WadKind::Pwad);
    dest.add_lump_raw(
        LumpAdd::new(
            LumpAddKind::Back,
            &vec![],
            "FF_START",
        )
    )?;

    for lump_name in lump_names {
        dest.add_lump_raw(
            LumpAdd::new(
                LumpAddKind::Back,
                &gate.data().buffer,
                lump_name,
            )
        )?;
    }

    dest.add_lump_raw(
        LumpAdd::new(
            LumpAddKind::Back,
            &vec![],
            "F_END",
        )
    )?;

    dest.save("doom1_patch.wad");

    Ok(())
}

Dumping metadata

use tinywad::error::WadError;
use tinywad::models::operation::WadOp;
use tinywad::wad::Wad;

fn main() -> Result<(), WadError> {
    let mut src = Wad::new();

    src.load_from_file("hexen.wad")?;
    src.dump();

    Ok(())
}

Output

Name: XXTIC, Size: 8, Offset: 12
Name: STARTUP, Size: 153648, Offset: 20
Name: PLAYPAL, Size: 21504, Offset: 153668, Palettes amount: 28
Name: COLORMAP, Size: 8704, Offset: 175172
Name: FOGMAP, Size: 8704, Offset: 183876
Name: TINTTAB, Size: 65536, Offset: 192580
Name: TRANTBL0, Size: 256, Offset: 258116
Name: TRANTBL1, Size: 256, Offset: 258372
Name: TRANTBL2, Size: 256, Offset: 258628
...

๐Ÿชง Supported lump types

  • DOOM image(s)
  • Flat
  • Palette
  • Markers
  • Music

โœ… Todo

Name State
Dump WAD header โœ…
Dump lumps metadata โœ…
Extract (save) lump โœ…
Update lump from raw buffer/file โœ…
Update lump from original buffer/files (PNG, MIDI, etc..) โŒ
Rebuild then save the WAD as a new file โœ…
Extract DOOM musics โœ…
Extract raw lump โœ…
Remove lumps โœ…
Add lump unique coherent IDs โœ…
Update lump size in the metadatas โœ…
Add lump with raw buffer โœ…

โ„น๏ธ Documentation

Run cargo doc --open to read the documentation in the browser.

tinywad's People

Contributors

theobori avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.