mirror of
https://github.com/redstrate/Kawari.git
synced 2025-04-22 15:27:44 +00:00
Move more code out of packet module
This commit is contained in:
parent
dd83b335dd
commit
6aed610276
4 changed files with 36 additions and 37 deletions
19
src/common.rs
Normal file
19
src/common.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
use std::ffi::CString;
|
||||
|
||||
pub(crate) fn read_bool_from<T: std::convert::From<u8> + std::cmp::PartialEq>(x: T) -> bool {
|
||||
x == T::from(1u8)
|
||||
}
|
||||
|
||||
pub(crate) fn write_bool_as<T: std::convert::From<u8>>(x: &bool) -> T {
|
||||
if *x { T::from(1u8) } else { T::from(0u8) }
|
||||
}
|
||||
|
||||
pub(crate) fn read_string(byte_stream: Vec<u8>) -> String {
|
||||
let str = String::from_utf8(byte_stream).unwrap();
|
||||
str.trim_matches(char::from(0)).to_string() // trim \0 from the end of strings
|
||||
}
|
||||
|
||||
pub(crate) fn write_string(str: &String) -> Vec<u8> {
|
||||
let c_string = CString::new(&**str).unwrap();
|
||||
c_string.as_bytes_with_nul().to_vec()
|
||||
}
|
|
@ -2,7 +2,21 @@ use std::{io::Cursor, slice};
|
|||
|
||||
use binrw::{BinRead, BinResult, BinWrite};
|
||||
|
||||
use crate::packet::{blowfish_decode, blowfish_encode};
|
||||
#[link(name = "FFXIVBlowfish")]
|
||||
unsafe extern "C" {
|
||||
pub fn blowfish_encode(
|
||||
key: *const u8,
|
||||
keybytes: u32,
|
||||
pInput: *const u8,
|
||||
lSize: u32,
|
||||
) -> *const u8;
|
||||
pub fn blowfish_decode(
|
||||
key: *const u8,
|
||||
keybytes: u32,
|
||||
pInput: *const u8,
|
||||
lSize: u32,
|
||||
) -> *const u8;
|
||||
}
|
||||
|
||||
const GAME_VERSION: u16 = 7000;
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ pub mod config;
|
|||
pub mod encryption;
|
||||
pub mod packet;
|
||||
pub mod patchlist;
|
||||
mod common;
|
||||
|
||||
pub fn generate_sid() -> String {
|
||||
let random_id: String = rand::thread_rng()
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use std::{
|
||||
ffi::CString,
|
||||
fs::write,
|
||||
io::Cursor,
|
||||
time::{SystemTime, UNIX_EPOCH},
|
||||
|
@ -11,41 +10,7 @@ use tokio::{
|
|||
net::TcpStream,
|
||||
};
|
||||
|
||||
use crate::encryption::{decrypt, encrypt, generate_encryption_key};
|
||||
|
||||
pub(crate) fn read_bool_from<T: std::convert::From<u8> + std::cmp::PartialEq>(x: T) -> bool {
|
||||
x == T::from(1u8)
|
||||
}
|
||||
|
||||
pub(crate) fn write_bool_as<T: std::convert::From<u8>>(x: &bool) -> T {
|
||||
if *x { T::from(1u8) } else { T::from(0u8) }
|
||||
}
|
||||
|
||||
pub(crate) fn read_string(byte_stream: Vec<u8>) -> String {
|
||||
let str = String::from_utf8(byte_stream).unwrap();
|
||||
str.trim_matches(char::from(0)).to_string() // trim \0 from the end of strings
|
||||
}
|
||||
|
||||
pub(crate) fn write_string(str: &String) -> Vec<u8> {
|
||||
let c_string = CString::new(&**str).unwrap();
|
||||
c_string.as_bytes_with_nul().to_vec()
|
||||
}
|
||||
|
||||
#[link(name = "FFXIVBlowfish")]
|
||||
unsafe extern "C" {
|
||||
pub fn blowfish_encode(
|
||||
key: *const u8,
|
||||
keybytes: u32,
|
||||
pInput: *const u8,
|
||||
lSize: u32,
|
||||
) -> *const u8;
|
||||
pub fn blowfish_decode(
|
||||
key: *const u8,
|
||||
keybytes: u32,
|
||||
pInput: *const u8,
|
||||
lSize: u32,
|
||||
) -> *const u8;
|
||||
}
|
||||
use crate::{common::{read_bool_from, read_string, write_bool_as, write_string}, encryption::{blowfish_encode, decrypt, encrypt, generate_encryption_key}};
|
||||
|
||||
#[binrw]
|
||||
#[brw(repr = u16)]
|
||||
|
|
Loading…
Add table
Reference in a new issue