use std::io; use crate::ggez::GameResult; /// Engine's internal text script VM operation codes. /// Based on https://www.cavestory.org/guides/basicmodding/guide/tscnotes.htm and game reverse engineering. pub enum OpCode { // ---- Internal opcodes (used by bytecode, no TSC representation) /// internal: no operation NOP, // ---- Official opcodes ---- /// (mut data: R) -> GameResult { let mut buf = Vec::new(); data.read_to_end(&mut buf)?; let half = buf.len() / 2; let key = if let Some(0) = buf.get(half) { 0xf9 } else { (-(*buf.get(half).unwrap() as isize)) as u8 }; for (idx, byte) in buf.iter_mut().enumerate() { if idx == half { continue; } *byte = byte.wrapping_add(key); } TextScript::compile(&buf) } /// Compiles a decrypted text script data into internal bytecode. pub fn compile(data: &[u8]) -> GameResult { println!("data: {}", String::from_utf8(data.to_vec())?); let tsc = TextScript {}; Ok(tsc) } }