Skip to main content

Ghost

Struct Ghost 

Source
pub struct Ghost { /* private fields */ }
Expand description

A fully parsed Mario Kart Wii RKG ghost file.

Holds the file header, decompressed or compressed input data, optional external footers (CTGP or SP), and CRC-32 checksums. All setter operations update the parsed fields; call update_raw_data (or save_to_file, which calls it implicitly) to flush all changes back into the raw byte buffer before writing.

Implementations§

Source§

impl Ghost

Source

pub fn new_from_file<T: AsRef<Path>>(path: T) -> Result<Self, GhostError>

Parses a Ghost from an RKG file at the given path.

§Errors

Returns GhostError::IOError if the file cannot be opened or read, and other GhostError variants if parsing fails.

Source

pub fn new(bytes: &[u8]) -> Result<Self, GhostError>

Parses a Ghost from a byte slice.

Detects and parses an optional CTGP or SP footer if present. The base CRC-32 is read from just before the footer when one is found, or from the last 4 bytes of the file otherwise.

§Errors

Returns GhostError::DataLengthTooShort if bytes is shorter than 0x8E bytes. Returns other GhostError variants if any field fails to parse.

Source

pub fn update_raw_data(&mut self) -> Result<(), GhostError>

Flushes all parsed field modifications back into the raw byte buffer.

This method recomputes the Mii CRC-16, rebuilds the raw buffer from the current header and input data, resizes the buffer if the input data length has changed, re-inserts any preserved external footer, and finally recomputes both the base CRC-32 and the file-level CRC-32. The CTGP footer SHA-1 field is also updated if a CTGP footer is present.

§Errors

Returns GhostError::MiiError if the Mii data is invalid, or GhostError::CTGPFooterError if the SHA-1 field cannot be written.

Source

pub fn save_to_file<T: AsRef<Path>>( &mut self, path: T, ) -> Result<(), GhostError>

Flushes all modifications and writes the ghost to a file at the given path.

§Errors

Returns any error from update_raw_data or from file creation/writing.

Source

pub fn compress_input_data(&mut self)

Compresses the input data using Yaz1 encoding and sets the compression flag in the header.

Does nothing if the input data is already compressed.

Source

pub fn decompress_input_data(&mut self)

Decompresses the input data and clears the compression flag in the header.

Does nothing if the input data is not compressed.

Source

pub fn raw_data(&self) -> &[u8]

Returns the raw file bytes.

May not reflect recent modifications until update_raw_data is called.

Source

pub fn raw_data_mut(&mut self) -> &mut [u8]

Returns a mutable reference to the raw file bytes.

Source

pub fn header(&self) -> &Header

Returns the parsed RKG file header.

Source

pub fn header_mut(&mut self) -> &mut Header

Returns a mutable reference to the parsed RKG file header.

Source

pub fn input_data(&self) -> &InputData

Returns the ghost’s controller input data.

Source

pub fn input_data_mut(&mut self) -> &mut InputData

Returns a mutable reference to the ghost’s controller input data.

Returns the CTGP footer, if present.

Returns a mutable reference to the CTGP footer, if present.

Returns the SP footer, if present.

Source

pub fn base_crc32(&self) -> u32

Returns the CRC-32 of the header and input data, excluding any external footer.

Source

pub fn verify_base_crc32(&self) -> bool

Returns true if the stored base CRC-32 matches a freshly computed checksum of the current header and input data bytes.

Source

pub fn file_crc32(&self) -> u32

Returns the CRC-32 of the entire file excluding its final 4 bytes.

Source

pub fn verify_file_crc32(&self) -> bool

Returns true if the stored file CRC-32 matches a freshly computed checksum of the entire file excluding its final 4 bytes.

Returns whether an existing external footer will be preserved when saving.

Sets whether an existing external footer should be preserved when saving.

Auto Trait Implementations§

§

impl Freeze for Ghost

§

impl RefUnwindSafe for Ghost

§

impl Send for Ghost

§

impl Sync for Ghost

§

impl Unpin for Ghost

§

impl UnsafeUnpin for Ghost

§

impl UnwindSafe for Ghost

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.