diff --git a/blf_lib/src/blf/chunks/halo3/v12070_08_09_05_2031_halo3_ship/s_blf_chunk_hopper_configuration_table.rs b/blf_lib/src/blf/chunks/halo3/v12070_08_09_05_2031_halo3_ship/s_blf_chunk_hopper_configuration_table.rs index 5008a4b..73ed11e 100644 --- a/blf_lib/src/blf/chunks/halo3/v12070_08_09_05_2031_halo3_ship/s_blf_chunk_hopper_configuration_table.rs +++ b/blf_lib/src/blf/chunks/halo3/v12070_08_09_05_2031_halo3_ship/s_blf_chunk_hopper_configuration_table.rs @@ -172,7 +172,7 @@ impl SerializableBlfChunk for s_blf_chunk_hopper_configuration_table { let category = &self.hopper_categories[i]; bitstream.write_integer(category.category_identifier as u32, 16); bitstream.write_integer(category.category_image_index as u32, 6); - bitstream.write_string_utf8(&category.category_name.get_string(), 32); + bitstream.write_string_utf8(&category.category_name.get_string(), 16); } // Encode hopper_configuration_count @@ -181,7 +181,7 @@ impl SerializableBlfChunk for s_blf_chunk_hopper_configuration_table { // Encode each hopper configuration for i in 0..self.hopper_configuration_count as usize { let configuration = &self.hopper_configurations[i]; - bitstream.write_string_utf8(&configuration.hopper_name.get_string(), 32); + bitstream.write_string_utf8(&configuration.hopper_name.get_string(), 16); bitstream.write_raw_data(&configuration.game_set_hash.data, 0xA0); bitstream.write_integer(configuration.hopper_identifier as u32, 16); bitstream.write_integer(configuration.hopper_category as u32, 16); @@ -302,7 +302,7 @@ impl SerializableBlfChunk for s_blf_chunk_hopper_configuration_table { let category = &mut self.hopper_categories[i]; category.category_identifier = bitstream.read_u16(16); category.category_image_index = bitstream.read_u8(6); - category.category_name.set_string(&bitstream.read_string_utf8(32)).unwrap(); + category.category_name.set_string(&bitstream.read_string_utf8(16)).unwrap(); } self.hopper_configuration_count = bitstream.read_u8(6); @@ -310,7 +310,7 @@ impl SerializableBlfChunk for s_blf_chunk_hopper_configuration_table { for i in 0..self.hopper_configuration_count as usize { let configuration = &mut self.hopper_configurations[i]; - configuration.hopper_name.set_string(&bitstream.read_string_utf8(32)).unwrap(); + configuration.hopper_name.set_string(&bitstream.read_string_utf8(16)).unwrap(); configuration.game_set_hash = s_network_http_request_hash::try_from(bitstream.read_raw_data(0xA0)).unwrap(); configuration.hopper_identifier = bitstream.read_u16(16); configuration.hopper_category = bitstream.read_u16(16); diff --git a/blf_lib/src/types/c_string.rs b/blf_lib/src/types/c_string.rs index eb53c5d..d6df090 100644 --- a/blf_lib/src/types/c_string.rs +++ b/blf_lib/src/types/c_string.rs @@ -1,4 +1,4 @@ -use std::ffi::{c_char, CStr}; +use std::ffi::c_char; use std::fmt::Write; use blf_lib::types::array::StaticArray; use serde::{Deserializer, Serialize, Serializer}; @@ -141,7 +141,11 @@ impl StaticString { } pub fn set_string(&mut self, value: &String) -> Result<(), String> { - let bytes = value.as_bytes(); + let mut bytes = value.as_bytes(); + // if a null termination was provided at the end, chop it off + if bytes.len() > 0 && bytes[bytes.len() - 1] == 0 { + bytes = &bytes[0..bytes.len() - 1]; + } if bytes.len() > N { return Err(format!("String \"{value}\" too long ({} > {}) bytes", N, bytes.len())); } @@ -151,7 +155,8 @@ impl StaticString { } pub fn get_string(&self) -> String { - CStr::from_bytes_until_nul(self.buf.as_slice()).unwrap().to_str().unwrap().to_string() + let null_index = self.buf.iter().position(|c|c == &0u8).unwrap_or(N); + String::from_utf8(self.buf.as_slice()[0..null_index].to_vec()).unwrap() } }