From 10db8888c2511e0167299bcc104f7c9b55577744 Mon Sep 17 00:00:00 2001 From: Jake Probst Date: Sat, 29 Jun 2019 09:54:17 -0700 Subject: [PATCH] the rest of the patchserver packets --- src/patch/packet.rs | 116 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 112 insertions(+), 4 deletions(-) diff --git a/src/patch/packet.rs b/src/patch/packet.rs index 0a5bb54..b3f8102 100644 --- a/src/patch/packet.rs +++ b/src/patch/packet.rs @@ -3,6 +3,8 @@ use crate::{PSOPacket, PacketParseError}; use std::io::{Read, Seek, SeekFrom}; +pub const PATCH_FILE_CHUNK_SIZE: u16 = 0x8000; // 32kb + #[allow(non_camel_case_types)] type u8_str = u8; @@ -44,6 +46,93 @@ pub struct LoginReply { unused2: [u8; 64], } +#[pso_packet(0x06)] +pub struct StartFileSend { + id: u32, + size: u32, + filename: [u8_str; 48], +} + +impl StartFileSend { + pub fn new(filename: &str, size: u32, id: u32) -> StartFileSend { + let mut f = [0u8; 48]; + for (src, dst) in filename.as_bytes().iter().zip(f.iter_mut()) { + *dst = *src + } + StartFileSend { + id: id, + size: size, + filename: f, + } + } +} + +//#[pso_packet(0x07)] +pub struct FileSend { + pub chunk_num: u32, + pub checksum: u32, + pub chunk_size: u32, + pub buffer: [u8; PATCH_FILE_CHUNK_SIZE as usize], +} + +impl PSOPacket for FileSend { + fn from_bytes(_data: &Vec) -> Result { + // TODO: implement this? it shouldn't be called on the server side ever... + unimplemented!(); + } + + fn as_bytes(&self) -> Vec { + let mut buf: Vec = Vec::new(); + buf.extend_from_slice(&u32::to_le_bytes(self.chunk_num)); + buf.extend_from_slice(&u32::to_le_bytes(self.checksum)); + buf.extend_from_slice(&u32::to_le_bytes(self.chunk_size)); + buf.extend_from_slice(&self.buffer[0..self.chunk_size as usize]); + while buf.len() % 4 != 0 { + buf.push(0); + } + //buf + + //buf.extend_from_slice(&u16::to_le_bytes((4 * 4) as u16 + self.chunk_size as u16)); + //buf.extend_from_slice(&u16::to_le_bytes(0x07)); + let pkt_len = (buf.len() + 4) as u16; + let mut prebuf: Vec = Vec::new(); + + prebuf.extend_from_slice(&u16::to_le_bytes(pkt_len)); + prebuf.extend_from_slice(&u16::to_le_bytes(0x07)); + prebuf.append(&mut buf); + + prebuf + + } +} + +impl std::fmt::Debug for FileSend { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "packet FileSend {{\n").unwrap(); + write!(f, " chunk_num: {:?}\n", self.chunk_num).unwrap(); + write!(f, " checksum: {:X?}\n", self.checksum).unwrap(); + write!(f, " chunk_size: {:X?}\n", self.chunk_size).unwrap(); + write!(f, " buffer: [...a large array ...]\n").unwrap(); + write!(f, "}}") + } +} + + +#[pso_packet(0x08)] +pub struct EndFileSend { + padding: u32, +} + +impl EndFileSend { + pub fn new() -> EndFileSend { + EndFileSend { + padding: 0, + } + } +} + + + #[pso_packet(0x0B)] pub struct PatchStartList { } @@ -95,14 +184,33 @@ pub struct PatchEndList { #[pso_packet(0x0F)] pub struct FileInfoReply { - id: u32, - checksum: u32, - size: u32, + pub id: u32, + pub checksum: u32, + pub size: u32, +} + +#[pso_packet(0x10)] +pub struct FileInfoListEnd { +} + +#[pso_packet(0x11)] +pub struct FilesToPatchMetadata { + data_size: u32, + file_count: u32, +} + +impl FilesToPatchMetadata { + pub fn new(data_size: u32, file_count: u32) -> FilesToPatchMetadata { + FilesToPatchMetadata { + data_size: data_size, + file_count: file_count, + } + } } #[pso_packet(0x12)] -pub struct EndIt { +pub struct FinalizePatching { }