Browse Source

param data packets

pull/3/head
jake 5 years ago
parent
commit
88a42695a1
  1. 69
      src/packet/login.rs

69
src/packet/login.rs

@ -7,6 +7,7 @@ use std::io::{Read, Seek, SeekFrom};
pub const PATCH_FILE_CHUNK_SIZE: u16 = 0x8000; // 32kb
pub const GUILD_CARD_CHUNK_SIZE: usize = 0x6800;
pub const PARAM_DATA_CHUNK_SIZE: usize = 0x6800;
#[allow(non_camel_case_types)]
type u8_str = u8;
@ -327,6 +328,74 @@ impl std::fmt::Debug for GuildcardDataChunk {
}
#[pso_packet(0x4EB)]
pub struct ParamDataRequest {
flag: u32,
}
#[derive(Clone)]
pub struct ParamFile {
pub size: u32,
pub checksum: u32,
pub offset: u32,
pub filename: [u8; 0x40],
}
#[derive(Clone)]
pub struct ParamDataHeader {
pub files: Vec<ParamFile>
}
impl PSOPacket for ParamDataHeader {
fn from_bytes(_data: &[u8]) -> Result<ParamDataHeader, PacketParseError> {
unimplemented!();
}
fn as_bytes(&self) -> Vec<u8> {
let mut buf: Vec<u8> = Vec::new();
buf.extend_from_slice(&u32::to_le_bytes(self.files.len() as u32));
for f in &self.files {
buf.extend_from_slice(&u32::to_le_bytes(f.size));
buf.extend_from_slice(&u32::to_le_bytes(f.checksum));
buf.extend_from_slice(&u32::to_le_bytes(f.offset));
buf.extend_from_slice(&f.filename[..]);
}
while buf.len() % 4 != 0 {
buf.push(0);
}
let pkt_len = (buf.len() + 4) as u16;
let mut prebuf: Vec<u8> = Vec::new();
prebuf.extend_from_slice(&u16::to_le_bytes(pkt_len));
prebuf.extend_from_slice(&u16::to_le_bytes(0x1EB));
prebuf.append(&mut buf);
prebuf
}
}
impl std::fmt::Debug for ParamDataHeader {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "packet ParamDataHeader{{\n").unwrap();
write!(f, " files: [..]\n").unwrap();
write!(f, "}}")
}
}
#[pso_packet(0x3EB)]
pub struct ParamDataChunkRequest {
flag: u32,
}
#[pso_packet(0x2EB)]
pub struct ParamDataChunk {
pub flag: u32,
pub chunk: u32,
pub data: [u8; 0x6800], // TODO: why wont the const work here? (blame macros?)
}
#[cfg(test)]
mod tests {

Loading…
Cancel
Save