From af0d34c011f49f7c0cabaf174ca30d123c0a0859 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 8 Mar 2025 13:14:14 -0500 Subject: [PATCH] Extract max comment length into a constant --- src/chardat.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/chardat.rs b/src/chardat.rs index 979d2d5..75adbe8 100644 --- a/src/chardat.rs +++ b/src/chardat.rs @@ -192,6 +192,8 @@ pub struct CustomizeData { pub voice: u8, } +const MAX_COMMENT_LENGTH: usize = 164; + /// Represents the several options that make up a character data file (DAT) which is used by the game's character creation system to save and load presets. #[binrw] #[br(little)] @@ -217,8 +219,8 @@ pub struct CharacterData { pub timestamp: u32, // TODO: this is terrible, just read until string nul terminator - #[br(count = 164)] - #[bw(pad_size_to = 164)] + #[br(count = MAX_COMMENT_LENGTH)] + #[bw(pad_size_to = MAX_COMMENT_LENGTH)] #[br(map = read_string)] #[bw(map = write_string)] comment: String, @@ -261,7 +263,7 @@ impl CharacterData { buffer.extend_from_slice(&self.timestamp.to_le_bytes()); let mut comment = write_string(&self.comment); - comment.resize(164, 0); + comment.resize(MAX_COMMENT_LENGTH, 0); buffer.extend_from_slice(&comment); let mut checksum: u32 = 0;