Compare commits
No commits in common. "7198aade7547154fd27731e602f0db8cb514f9ac" and "73fca2e983de7f6b2af2e6422729605cd125e544" have entirely different histories.
7198aade75
...
73fca2e983
@ -205,19 +205,18 @@ fn generate_psopacket_impl(pkt_cmd: u16, name: syn::Ident, attrs: &Vec<AttrType>
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn generate_debug_impl(name: syn::Ident, attrs: &Vec<AttrType>) -> proc_macro2::TokenStream {
|
fn generate_debug_impl(name: syn::Ident, attrs: &Vec<AttrType>) -> proc_macro2::TokenStream {
|
||||||
let dbg_write = attrs
|
let mut dbg_write = Vec::new();
|
||||||
.iter()
|
for attr in attrs {
|
||||||
.map(|attr| {
|
let element = match attr {
|
||||||
match attr {
|
|
||||||
AttrType::Value(ty, name, meta) => {
|
AttrType::Value(ty, name, meta) => {
|
||||||
let ident_str = name.to_string();
|
let ident_str = name.to_string();
|
||||||
let type_str = ty.path.segments[0].ident.to_string();
|
let type_str = ty.path.segments[0].ident.to_string();
|
||||||
match meta {
|
match meta {
|
||||||
AttrMeta::NoDebug => quote! {
|
AttrMeta::NoDebug => quote! {
|
||||||
.field(&format!("{} [{}]", #ident_str, #type_str), &format_args!("[...]"))
|
write!(f, " {} {}: [...]\n", #ident_str, #type_str)?;
|
||||||
},
|
},
|
||||||
_ => quote! {
|
_ => quote! {
|
||||||
.field(&format!("{} [{}]", #ident_str, #type_str), &self.#name)
|
write!(f, " {} {}: {:?}\n", #ident_str, #type_str, self.#name)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -226,38 +225,35 @@ fn generate_debug_impl(name: syn::Ident, attrs: &Vec<AttrType>) -> proc_macro2::
|
|||||||
let type_str = ty.path.segments[0].ident.to_string();
|
let type_str = ty.path.segments[0].ident.to_string();
|
||||||
match meta {
|
match meta {
|
||||||
AttrMeta::Utf8 => quote! {
|
AttrMeta::Utf8 => quote! {
|
||||||
.field(&format!("{} [utf8; {}]", #ident_str, #len),
|
|
||||||
match std::str::from_utf8(&self.#name) {
|
match std::str::from_utf8(&self.#name) {
|
||||||
Ok(ref s) => s,
|
Ok(v) => write!(f, " {} [utf8; {}]: {:?}\n", #ident_str, #len, v)?,
|
||||||
Err(_) => &self.#name
|
Err(_) => write!(f, " {} [{}; {}]: {:?}\n", #ident_str, #type_str, #len, self.#name.to_vec())?,
|
||||||
})
|
};
|
||||||
},
|
},
|
||||||
AttrMeta::Utf16 => quote! {
|
AttrMeta::Utf16 => quote! {
|
||||||
.field(&format!("{} [utf16; {}]", #ident_str, #len),
|
match String::from_utf16(&self.#name) {
|
||||||
match std::str::from_utf16(&self.#name) {
|
Ok(v) => write!(f, " {} [utf16; {}]: {:?}\n", #ident_str, #len, v)?,
|
||||||
Ok(ref s) => s,
|
Err(_) => write!(f, " {} [{}; {}]: {:?}\n", #ident_str, #type_str, #len, self.#name.to_vec())?,
|
||||||
Err(_) => &self.#name
|
};
|
||||||
})
|
|
||||||
},
|
},
|
||||||
AttrMeta::NoDebug => quote! {
|
AttrMeta::NoDebug => quote! {
|
||||||
.field(&format!("{} [{}; {}]", #ident_str, #type_str, #len), &format_args!("[...]"))
|
write!(f, " {} [{}; {}]: [...]\n", #ident_str, #type_str, #len)?;
|
||||||
},
|
},
|
||||||
_ => quote! {
|
_ => quote! {
|
||||||
.field(&format!("{} [{}; {}]", #ident_str, #type_str, #len), &format_args!("{:?}", &self.#name))
|
write!(f, " {} [{}; {}]: {:?}\n", #ident_str, #type_str, #len, self.#name.to_vec())?;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
dbg_write.push(element);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
let name_str = name.to_string();
|
let name_str = name.to_string();
|
||||||
quote! {
|
quote! {
|
||||||
impl std::fmt::Debug for #name {
|
impl std::fmt::Debug for #name {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
f.debug_struct(#name_str)
|
write!(f, "{} {{\n", #name_str)?;
|
||||||
#(#dbg_write)*
|
#(#dbg_write)*
|
||||||
.finish()
|
write!(f, "}}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ impl std::default::Default for Character {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, PSOPacketData, Default)]
|
#[derive(Copy, Clone, Debug, PartialEq, Default)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct SelectScreenCharacter {
|
pub struct SelectScreenCharacter {
|
||||||
pub exp: u32,
|
pub exp: u32,
|
||||||
@ -169,6 +169,20 @@ pub struct SelectScreenCharacter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SelectScreenCharacter {
|
impl SelectScreenCharacter {
|
||||||
|
pub const SIZE: usize = 0x7C;
|
||||||
|
|
||||||
|
pub fn from_le_bytes(bytes: [u8; 0x7C]) -> Result<SelectScreenCharacter, crate::PacketParseError> {
|
||||||
|
unsafe {
|
||||||
|
Ok(std::mem::transmute(bytes))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_le_bytes(&self) -> [u8; 0x7C] {
|
||||||
|
unsafe {
|
||||||
|
std::mem::transmute(*self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn as_character(&self) -> Character {
|
pub fn as_character(&self) -> Character {
|
||||||
Character {
|
Character {
|
||||||
exp: self.exp,
|
exp: self.exp,
|
||||||
|
@ -292,6 +292,18 @@ pub struct CharAck {
|
|||||||
pub code: u32, // TODO: enum?
|
pub code: u32, // TODO: enum?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PSOPacketData for SelectScreenCharacter {
|
||||||
|
fn from_bytes<R: Read>(cursor: &mut R) -> Result<Self, PacketParseError> {
|
||||||
|
let mut buf = [0u8; SelectScreenCharacter::SIZE];
|
||||||
|
cursor.read(&mut buf).map_err(|_| PacketParseError::ReadError)?;
|
||||||
|
SelectScreenCharacter::from_le_bytes(buf)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_bytes(&self) -> Vec<u8> {
|
||||||
|
self.to_le_bytes().to_vec()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[pso_packet(0xE5)]
|
#[pso_packet(0xE5)]
|
||||||
pub struct CharacterPreview {
|
pub struct CharacterPreview {
|
||||||
pub slot: u32,
|
pub slot: u32,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user