view examples/dump_ecl.rs @ 733:770e5057f6bc

ecl_vm: time stop/random sakuya bullets impl
author Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
date Sun, 03 Nov 2019 03:04:41 +0100
parents eea03c9ca604
children 4d91790cf8ab
line wrap: on
line source

use touhou::th06::ecl::{Ecl, CallMain, CallSub, Rank};
use std::env;
use std::path::Path;

#[path = "common.rs"]
mod common;
use common::{load_file_into_vec};

fn format_rank(rank: &Rank) -> String {
    format!("{}{}{}{}", if rank.contains(Rank::EASY) { 'E' } else { ' ' },
                        if rank.contains(Rank::NORMAL) { 'N' } else { ' ' },
                        if rank.contains(Rank::HARD) { 'H' } else { ' ' },
                        if rank.contains(Rank::LUNATIC) { 'L' } else { ' ' })
}

fn print_sub_instruction(call: &CallSub) {
    let CallSub { time, rank_mask, param_mask: _, instr } = call;
    println!("    {:>5}: {}: {:?}", time, format_rank(rank_mask), instr);
}

fn print_main_instruction(call: &CallMain) {
    let CallMain { time, sub, instr } = call;
    println!("    {:>5}: sub {:>2}: {:?}", time, sub, instr);
}

fn main() {
    // Parse arguments.
    let args: Vec<_> = env::args().collect();
    if args.len() != 2 {
        eprintln!("Usage: {} <ECL file>", args[0]);
        return;
    }
    let ecl_filename = Path::new(&args[1]);

    // Open the ECL file.
    let buf = load_file_into_vec(ecl_filename);
    let (_, ecl) = Ecl::from_slice(&buf).unwrap();

    for (i, main) in ecl.mains.iter().enumerate() {
        println!("Main {} {{", i);
        for call in main.instructions.iter() {
            print_main_instruction(call);
        }
        println!("}}");
        println!();
    }

    for (i, sub) in ecl.subs.iter().enumerate() {
        println!("Sub {} {{", i);
        for call in sub.instructions.iter() {
            print_sub_instruction(call);
        }
        println!("}}");
        println!();
    }
}