brickadia / brs

Read and write Brickadia saves.
8 stars 2 forks source link

Library may be reading data incorrectly for some saves #2

Closed qoh closed 4 years ago

qoh commented 4 years ago

brs-rs does not read owners correctly

use brs::{Brick, Reader};
use std::collections::HashSet;
use std::fs::File;
use std::io::Error;
use std::result::Result;

// open and read a brs file, returns parsed write data
pub fn open(filename: &'_ str) -> Result<Vec<Brick>, Error> {
    // open brs file
    let reader = Reader::new(File::open(filename)?)?;

    // read headers and bricks
    let (_reader, bricks) = reader
        .read_header1()?
        .read_header2()?
        .iter_bricks_and_reader()?;

    // enerate some writedata as a mirror of the reader output
    Ok(bricks.map(|b| b.unwrap()).collect::<Vec<Brick>>())
}

fn main() {
    let bricks = open("./brickadia city.brs").expect("error!!");

    println!("Found {} bricks", bricks.len());

    // read all owners into a set
    let mut owners = HashSet::new();
    bricks.into_iter().for_each(|b| {
        owners.insert(b.owner_index);
    });

    println!("owners {:?}", owners);
}

brickadia_city.brs expected: owners {1,2,3,4,5,6,7,8,9,10,11} received: owners {8709136, 396740, 3901, 654432, 9776, 948106795, 92975640, 1114638700, 496275152, 3489, 33875467, 793, 12636, 327235, 10604, 16268, 7760, 11150, 1973305, 1651430, 160352779, ...

so i think i narrowed down the issue w/ brs to saves that have colors outside of the colorset, none of the img2brs saves work and sylvs dont work because he has dis weird gradient brick thing in de middle. these bricks are loaded w/ wack sizes, positions, brick_owners, etc.

Suficio commented 4 years ago

Im responsible for this block. Not sure what would have caused the bad owners since I no longer have the original code. I do know though that I generated it through my node-brs.

I had owner index default to 0, while brickOwners was empty. Would check there.