arcdps\extras\message/
npc.rs1use crate::util::str_from_cstr_len;
2use std::ffi::c_char;
3
4#[cfg(feature = "serde")]
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone)]
19#[repr(C)]
20pub struct NpcMessage {
21 character_name: *const c_char,
25 character_name_length: u64,
26
27 text: *const c_char,
31 text_length: u64,
32
33 pub timestamp: u64,
37}
38
39impl NpcMessage {
40 #[inline]
42 pub fn to_owned(&self) -> NpcMessageOwned {
43 self.into()
44 }
45
46 #[inline]
48 pub fn character_name(&self) -> &str {
49 unsafe { str_from_cstr_len(self.character_name, self.character_name_length) }
50 }
51
52 #[inline]
54 pub fn character_name_ptr(&self) -> *const c_char {
55 self.character_name
56 }
57
58 #[inline]
60 pub fn character_name_len(&self) -> usize {
61 self.character_name_length as _
62 }
63
64 #[inline]
66 pub fn text(&self) -> &str {
67 unsafe { str_from_cstr_len(self.text, self.text_length) }
68 }
69
70 #[inline]
72 pub fn text_ptr(&self) -> *const c_char {
73 self.text
74 }
75
76 #[inline]
78 pub fn text_len(&self) -> usize {
79 self.text_length as _
80 }
81}
82
83#[derive(Debug, Clone)]
85#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
86pub struct NpcMessageOwned {
87 pub character_name: String,
89
90 pub text: String,
92}
93
94impl From<NpcMessage> for NpcMessageOwned {
95 #[inline]
96 fn from(msg: NpcMessage) -> Self {
97 (&msg).into()
98 }
99}
100
101impl From<&NpcMessage> for NpcMessageOwned {
102 #[inline]
103 fn from(msg: &NpcMessage) -> Self {
104 Self {
105 character_name: msg.character_name().to_owned(),
106 text: msg.text().to_owned(),
107 }
108 }
109}