Added rustii CLI command to replace content in a WAD

Also added required library features to make this possible. Rust makes the whole "getting content's index from its CID" thing so much easier.
This commit is contained in:
2025-04-25 14:45:38 -04:00
parent 96ace71546
commit 577d5a0efa
4 changed files with 100 additions and 3 deletions

View File

@@ -110,6 +110,20 @@ impl ContentRegion {
}
Ok(buf)
}
/// Gets the index of content using its Content ID.
pub fn get_index_from_cid(&self, cid: u32) -> Result<usize, ContentError> {
// Use fancy Rust find and map methods to find the index matching the provided CID. Take
// that libWiiPy!
let content_index = self.content_records.iter()
.find(|record| record.content_id == cid)
.map(|record| record.index);
if let Some(index) = content_index {
Ok(index as usize)
} else {
Err(ContentError::CIDNotFound(cid))
}
}
/// Gets the encrypted content file from the ContentRegion at the specified index.
pub fn get_enc_content_by_index(&self, index: usize) -> Result<Vec<u8>, ContentError> {