Fixed minor issues with script parsing

This commit is contained in:
G2-Games 2024-09-18 10:28:57 -05:00
parent 43b65cf173
commit 9b3fcb2480

View file

@ -1,4 +1,4 @@
use std::{fs::File, io::{Read, Seek}, process::exit}; use std::{fs::File, io::{Read, Seek}};
use byteorder::{ReadBytesExt, LE}; use byteorder::{ReadBytesExt, LE};
use num_derive::{FromPrimitive, ToPrimitive}; use num_derive::{FromPrimitive, ToPrimitive};
use num_traits::{FromPrimitive, ToPrimitive}; use num_traits::{FromPrimitive, ToPrimitive};
@ -14,19 +14,18 @@ fn main() {
opcode.to_u8().unwrap(), opcode.to_u8().unwrap(),
opcode opcode
); );
if opcode == Opcode::TASK {
break;
}
match opcode { match opcode {
Opcode::MESSAGE => { Opcode::MESSAGE => {
let variables = script.read_u8().unwrap(); let variables = script.read_u8().unwrap();
match variables { match variables {
1 => continue, 1 => continue,
4 => { 4 => {
dbg!(script.read_u32::<LE>().unwrap()); script.read_u32::<LE>().unwrap();
continue; continue;
} }
_ => (), 3 => (),
_ => unimplemented!(),
} }
let message = Message { let message = Message {
variables, variables,
@ -38,9 +37,33 @@ fn main() {
message.messages.unwrap().iter().for_each(|m| println!("{}", m.to_string())); message.messages.unwrap().iter().for_each(|m| println!("{}", m.to_string()));
println!("-----"); println!("-----");
}, },
Opcode::IMAGELOAD => {
let mode = script.read_u8().unwrap();
match mode {
0 => script.read_u16::<LE>().unwrap(),
_ => {
script.read_u16::<LE>().unwrap();
script.read_u16::<LE>().unwrap()
},
};
let image_id = script.read_u16::<LE>().unwrap();
println!("Image ID: {image_id}\n-----");
},
/*
Opcode::SELECT => {
let var_id = script.read_u16::<LE>().unwrap();
script.read_u16::<LE>().unwrap();
script.read_u16::<LE>().unwrap();
script.read_u16::<LE>().unwrap();
let msg_str = script.read_u16::<LE>().unwrap();
script.read_u16::<LE>().unwrap();
script.read_u16::<LE>().unwrap();
script.read_u16::<LE>().unwrap();
println!("{var_id} & {msg_str}\n-----");
},
*/
Opcode::JUMP => { Opcode::JUMP => {
dbg!(script.read_u32::<LE>().unwrap()); script.read_u16::<LE>().unwrap();
println!("------");
} }
_ => (), _ => (),
} }