From 1e4eaeae1bfd794213f8eee09cb189e7c6fff4d6 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Tue, 19 May 2020 15:39:38 +0200 Subject: implement Error statechange --- src/event.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/event.rs b/src/event.rs index df0d5d3..a598d3d 100644 --- a/src/event.rs +++ b/src/event.rs @@ -19,6 +19,8 @@ pub enum FromRawEventError { UnknownStateChange(raw::CbtStateChange), #[error("event contains an unknown damage event")] UnknownDamageEvent, + #[error("the event contains invalid text")] + InvalidText, } /// A rusty enum for all possible combat events. @@ -177,6 +179,9 @@ pub enum EventKind { raw_bytes: [u8; 16], api_guild_id: Option, }, + + /// An error was reported by arcdps. + Error { text: String }, } /// A higher-level representation of a combat event. @@ -354,6 +359,15 @@ impl TryFrom<&raw::CbtEvent> for Event { agent_addr: raw_event.src_agent, targetable: raw_event.dst_agent != 0, }, + CbtStateChange::Error => { + let data = get_error_bytes(&raw_event); + EventKind::Error { + text: raw::cstr_up_to_nul(&data) + .ok_or(FromRawEventError::InvalidText)? + .to_string_lossy() + .into_owned(), + } + } // XXX: implement proper handling of those events! CbtStateChange::BuffInitial | CbtStateChange::ReplInfo @@ -365,7 +379,6 @@ impl TryFrom<&raw::CbtEvent> for Event { | CbtStateChange::SkillTiming | CbtStateChange::BreakbarState | CbtStateChange::BreakbarPercent - | CbtStateChange::Error | CbtStateChange::Unknown => { return Err(FromRawEventError::UnknownStateChange( raw_event.is_statechange, @@ -490,6 +503,17 @@ fn get_api_guild_string(bytes: &[u8; 16]) -> Option { Some(result) } +fn get_error_bytes(raw_event: &raw::CbtEvent) -> [u8; 32] { + let mut result = [0; 32]; + let mut cursor = io::Cursor::new(&mut result as &mut [u8]); + cursor.write_u64::(raw_event.time).unwrap(); + cursor.write_u64::(raw_event.src_agent).unwrap(); + cursor.write_u64::(raw_event.dst_agent).unwrap(); + cursor.write_i32::(raw_event.value).unwrap(); + cursor.write_i32::(raw_event.buff_dmg).unwrap(); + result +} + /// The different weapon-sets in game. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum WeaponSet { -- cgit v1.2.3