Skip to main content

rewrite_string_table_entry

Attribute Macro rewrite_string_table_entry 

Source
#[rewrite_string_table_entry]
Expand description

Rewrites one decoded string table entry update.

Use this for targeted string-table edits such as rewriting userinfo rows. The handler can receive ctx: &Context, tick: u32, table_name: &str, and entry: &mut StringTableEntryUpdate in any order. Return Result<(), ParserError>.

ยงExamples

#[rewrite_string_table_entry]
fn anonymize_userinfo(
    &mut self,
    table_name: &str,
    entry: &mut StringTableEntryUpdate,
) -> Result<(), ParserError> {
    if table_name == "userinfo" {
        if let Some(value) = entry.value_mut() {
            let mut player = CMsgPlayerInfo::decode(value.as_slice())?;
            player.name = Some("Anonymous".to_string());
            *value = player.encode_to_vec();
        }
    }
    Ok(())
}