rgmk/
lib.rs

1//! Library for manipulating Game Maker Studio's "data.win" (GEN8) data files.
2
3#![warn( /*missing_docs,*/
4 trivial_casts, trivial_numeric_casts)]
5
6extern crate byteorder;
7
8mod serde;
9mod io_util;
10
11use std::io::{self, BufReader, BufWriter};
12use std::path;
13use std::error::Error;
14use std::fs::File;
15
16/// The data of a Game Maker Studio game.
17///
18/// This is the collective information acquired from "data.win".
19pub struct GameData {
20    pub gen8: Box<[u8]>,
21    pub optn: Box<[u8]>,
22    pub extn: Box<[u8]>,
23    pub sond: Box<[u8]>,
24    pub agrp: Option<Box<[u8]>>,
25    pub sprt: Box<[u8]>,
26    pub bgnd: Box<[u8]>,
27    pub path: Box<[u8]>,
28    pub scpt: Box<[u8]>,
29    pub shdr: Box<[u8]>,
30    pub font: Box<[u8]>,
31    pub tmln: Box<[u8]>,
32    pub objt: Box<[u8]>,
33    pub room: Box<[u8]>,
34    pub dafl: Box<[u8]>,
35    pub tpag: Box<[u8]>,
36    pub code: Box<[u8]>,
37    pub vari: Box<[u8]>,
38    pub func: Box<[u8]>,
39    pub strg: Box<[u8]>,
40    pub txtr: Txtr,
41    pub audo: Box<[u8]>,
42    pub lang: Option<Box<[u8]>>,
43    pub glob: Option<Box<[u8]>>,
44    reader: FileBufRead,
45}
46
47pub struct Texture {
48    unknown: u32,
49    source: TextureSource,
50}
51
52pub enum TextureSource {
53    Original { offset: u64 },
54}
55
56pub struct Txtr {
57    textures: Vec<Texture>,
58    end_offset: u64,
59}
60
61type FileBufRead = BufReader<File>;
62type FileBufWrite = BufWriter<File>;
63
64impl GameData {
65    /// Reads a GameData from a file.
66    pub fn open<P: AsRef<path::Path>>(path: P) -> Result<GameData, Box<Error>> {
67        let file = File::open(path)?;
68        serde::open_and_read(BufReader::new(file))
69    }
70    /// Writes self to a file.
71    pub fn save_to_file<P: AsRef<path::Path>>(&mut self, path: P) -> io::Result<()> {
72        let file = File::create(path)?;
73        serde::write_to(self, &mut BufWriter::new(file))
74    }
75}