From aae675f31d3ca95ec4f678e48e318777b3662200 Mon Sep 17 00:00:00 2001 From: ghostlyzsh Date: Sun, 7 Jan 2024 01:17:50 -0600 Subject: [PATCH] ok now saving saves everything in theory --- savefile_decoder/src/main.rs | 2 +- server/src/main.rs | 22 +++++++++++----------- starkingdoms-common/src/lib.rs | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/savefile_decoder/src/main.rs b/savefile_decoder/src/main.rs index 760a7148e50a579e7511f270eb7d97e8495fba1c..19a9851110a9b9ef31c5340388e00b8f0b33bc01 100644 --- a/savefile_decoder/src/main.rs +++ b/savefile_decoder/src/main.rs @@ -3,7 +3,7 @@ use std::fs; use starkingdoms_common::unpack_savefile; fn main() { - let save = std::env::args().next().unwrap(); + let save = std::env::args().nth(1).unwrap(); let key = fs::read_to_string("/etc/starkingdoms/app_key").unwrap(); let save_data = unpack_savefile(&key, save).unwrap(); println!("{:#?}", save_data); diff --git a/server/src/main.rs b/server/src/main.rs index c186d733824b11c710a581b033a92ec29f8275c5..2dbc4e371c606a08bf66e345b5ad56c652392ebe 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -891,7 +891,7 @@ fn on_message( // HEY! GHOSTLY! PLEASE FILL THIS STRUCT WITH DATA! // THANKS! let save = SaveData { - module: construct_save_data(attach.clone(), &attached_query), + children: construct_save_data(attach.clone(), &attached_query), }; let save_string = pack_savefile(&app_keys.app_key, save); let packet = Packet::SaveData { @@ -922,26 +922,26 @@ fn construct_save_data( &Velocity, Option<&CanAttach>, Option<&LooseAttach>, + &mut PartFlags, ), (Without, Without), >, -) -> SaveModule { - let mut save_module = SaveModule { - part_type: starkingdoms_common::PartType::Placeholder, - children: vec![None, None, None, None], - }; +) -> Vec> { + let mut modules = vec![None, None, None, None]; for (i, child) in attach.children.iter().enumerate() { if let Some(child) = child { - let (_, part_type, _, attach, _, _, _) = attached_query.get(*child).unwrap(); + let (_, part_type, _, attach, _, _, _, _) = attached_query.get(*child).unwrap(); if *part_type == PartType::LandingThrusterSuspension { continue; } let child_save_module = construct_save_data(attach.clone(), attached_query); - save_module.part_type = (*part_type).into(); - save_module.children[i] = Some(child_save_module); + modules[i] = Some(SaveModule { + part_type: (*part_type).into(), + children: child_save_module, + }); } } - save_module + modules } fn detach_recursive( @@ -1454,7 +1454,7 @@ fn break_modules( commands.entity(entity).insert(LooseAttach { children: attach.children, }); - if (attach.children[2].is_some()) { + if attach.children[2].is_some() { commands .entity(attach.children[2].unwrap()) .remove::(); diff --git a/starkingdoms-common/src/lib.rs b/starkingdoms-common/src/lib.rs index 398dccdd11623d2809c1e3c914d595c5ce2dce9c..3145e511cf3fbeaa8ccaf8a24eeacb8f481b214e 100644 --- a/starkingdoms-common/src/lib.rs +++ b/starkingdoms-common/src/lib.rs @@ -29,7 +29,7 @@ pub struct SaveData { // FILL THIS WITH STUFF // ---------------------------------------------------------------------- // THANKS! -core - pub module: SaveModule, + pub children: Vec>, } #[derive(Serialize, Deserialize, Debug)] @@ -77,7 +77,7 @@ pub fn unpack_savefile(key: &str, file: String) -> Result = Hmac::new_from_slice(key.as_bytes()).map_err(|e| format!("error loading hmac-sha256: {e}")); + let mut mac: Hmac = Hmac::new_from_slice(key.as_bytes()).map_err(|e| format!("error loading hmac-sha256: {e}"))?; mac.update(&save_file.data_msgpack); mac.verify_slice(&save_file.mac).map_err(|e| format!("error verifying signature: {e}"))?;