mirror of
https://github.com/redstrate/Kawari.git
synced 2025-04-22 23:27:46 +00:00
Re-run format, re-organize some code and run Clippy auto-fix
This commit is contained in:
parent
aacd128a9e
commit
dd83b335dd
8 changed files with 47 additions and 55 deletions
|
@ -2,10 +2,10 @@ use std::net::SocketAddr;
|
||||||
|
|
||||||
use axum::response::{Html, Redirect};
|
use axum::response::{Html, Redirect};
|
||||||
use axum::routing::post;
|
use axum::routing::post;
|
||||||
use axum::{Json, Router, extract::Form, routing::get};
|
use axum::{Router, extract::Form, routing::get};
|
||||||
use kawari::config::{Config, get_config};
|
use kawari::config::get_config;
|
||||||
use kawari::setup_default_environment;
|
use kawari::setup_default_environment;
|
||||||
use minijinja::{Environment, context};
|
use minijinja::context;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
use axum::{Json, Router, routing::get};
|
use axum::{Json, Router, routing::get};
|
||||||
use kawari::config::{Config, get_config};
|
use kawari::config::get_config;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
|
|
@ -5,8 +5,6 @@ use axum::response::Html;
|
||||||
use axum::routing::post;
|
use axum::routing::post;
|
||||||
use axum::{Form, Router, routing::get};
|
use axum::{Form, Router, routing::get};
|
||||||
use kawari::generate_sid;
|
use kawari::generate_sid;
|
||||||
use rand::Rng;
|
|
||||||
use rand::distributions::Alphanumeric;
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
|
|
@ -3,16 +3,12 @@ use std::fs::read_dir;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
use axum::extract::Path;
|
use axum::extract::Path;
|
||||||
use axum::extract::Query;
|
|
||||||
use axum::http::{HeaderMap, StatusCode};
|
use axum::http::{HeaderMap, StatusCode};
|
||||||
use axum::response::Html;
|
|
||||||
use axum::response::IntoResponse;
|
use axum::response::IntoResponse;
|
||||||
use axum::routing::post;
|
use axum::routing::post;
|
||||||
use axum::{Form, Json, Router, routing::get};
|
use axum::{Router, routing::get};
|
||||||
use kawari::config::{Config, get_config};
|
use kawari::config::get_config;
|
||||||
use kawari::patchlist::{PatchEntry, PatchList, PatchType};
|
use kawari::patchlist::{PatchEntry, PatchList, PatchType};
|
||||||
use minijinja::filters::list;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
fn list_patch_files(dir_path: &str) -> Vec<String> {
|
fn list_patch_files(dir_path: &str) -> Vec<String> {
|
||||||
// If the dir doesn't exist, pretend there is no patch files
|
// If the dir doesn't exist, pretend there is no patch files
|
||||||
|
@ -38,7 +34,7 @@ fn list_patch_files(dir_path: &str) -> Vec<String> {
|
||||||
.collect();
|
.collect();
|
||||||
game_patches.sort_by(|a, b| {
|
game_patches.sort_by(|a, b| {
|
||||||
// Ignore H/D in front of filenames
|
// Ignore H/D in front of filenames
|
||||||
let mut a_path = a
|
let a_path = a
|
||||||
.as_path()
|
.as_path()
|
||||||
.file_name()
|
.file_name()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -48,7 +44,7 @@ fn list_patch_files(dir_path: &str) -> Vec<String> {
|
||||||
if a_path.starts_with("H") {
|
if a_path.starts_with("H") {
|
||||||
return Ordering::Less;
|
return Ordering::Less;
|
||||||
}
|
}
|
||||||
let mut b_path = b
|
let b_path = b
|
||||||
.as_path()
|
.as_path()
|
||||||
.file_name()
|
.file_name()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -117,7 +113,7 @@ async fn verify_boot(Path((platform, boot_version)): Path<(String, String)>) ->
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
let headers = HeaderMap::new();
|
||||||
(headers).into_response()
|
(headers).into_response()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,10 @@ use std::net::SocketAddr;
|
||||||
|
|
||||||
use axum::response::{Html, Redirect};
|
use axum::response::{Html, Redirect};
|
||||||
use axum::routing::post;
|
use axum::routing::post;
|
||||||
use axum::{Json, Router, extract::Form, routing::get};
|
use axum::{Router, extract::Form, routing::get};
|
||||||
use kawari::config::{Config, get_config};
|
use kawari::config::get_config;
|
||||||
use kawari::setup_default_environment;
|
use kawari::setup_default_environment;
|
||||||
use minijinja::{Environment, context};
|
use minijinja::context;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
@ -58,7 +58,7 @@ struct Input {
|
||||||
async fn apply(Form(input): Form<Input>) -> Redirect {
|
async fn apply(Form(input): Form<Input>) -> Redirect {
|
||||||
tracing::info!("Apply config changes...");
|
tracing::info!("Apply config changes...");
|
||||||
|
|
||||||
let mut config = get_config();
|
let config = get_config();
|
||||||
|
|
||||||
serde_json::to_writer(&std::fs::File::create("config.json").unwrap(), &config)
|
serde_json::to_writer(&std::fs::File::create("config.json").unwrap(), &config)
|
||||||
.expect("TODO: panic message");
|
.expect("TODO: panic message");
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use std::fs::write;
|
|
||||||
use std::{io::Cursor, slice};
|
use std::{io::Cursor, slice};
|
||||||
|
|
||||||
use binrw::{BinRead, BinResult, BinWrite};
|
use binrw::{BinRead, BinResult, BinWrite};
|
||||||
|
@ -9,30 +8,14 @@ const GAME_VERSION: u16 = 7000;
|
||||||
|
|
||||||
pub fn generate_encryption_key(key: &[u8], phrase: &str) -> [u8; 16] {
|
pub fn generate_encryption_key(key: &[u8], phrase: &str) -> [u8; 16] {
|
||||||
let mut base_key = vec![0x78, 0x56, 0x34, 0x12];
|
let mut base_key = vec![0x78, 0x56, 0x34, 0x12];
|
||||||
base_key.extend_from_slice(&key);
|
base_key.extend_from_slice(key);
|
||||||
base_key.extend_from_slice(&GAME_VERSION.to_le_bytes());
|
base_key.extend_from_slice(&GAME_VERSION.to_le_bytes());
|
||||||
base_key.extend_from_slice(&[0; 2]); // padding (possibly for game version?)
|
base_key.extend_from_slice(&[0; 2]); // padding (possibly for game version?)
|
||||||
base_key.extend_from_slice(&phrase.as_bytes());
|
base_key.extend_from_slice(phrase.as_bytes());
|
||||||
|
|
||||||
md5::compute(&base_key).0
|
md5::compute(&base_key).0
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_encryption_key() {
|
|
||||||
let key = generate_encryption_key(&[0x00, 0x00, 0x00, 0x00], "foobar");
|
|
||||||
assert_eq!(
|
|
||||||
key,
|
|
||||||
[
|
|
||||||
169, 78, 235, 31, 57, 151, 26, 74, 250, 196, 1, 120, 206, 173, 202, 48
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[binrw::parser(reader, endian)]
|
#[binrw::parser(reader, endian)]
|
||||||
pub(crate) fn decrypt<T>(size: u32, encryption_key: Option<&[u8]>) -> BinResult<T>
|
pub(crate) fn decrypt<T>(size: u32, encryption_key: Option<&[u8]>) -> BinResult<T>
|
||||||
where
|
where
|
||||||
|
@ -87,3 +70,19 @@ where
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_encryption_key() {
|
||||||
|
let key = generate_encryption_key(&[0x00, 0x00, 0x00, 0x00], "foobar");
|
||||||
|
assert_eq!(
|
||||||
|
key,
|
||||||
|
[
|
||||||
|
169, 78, 235, 31, 57, 151, 26, 74, 250, 196, 1, 120, 206, 173, 202, 48
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::{
|
||||||
time::{SystemTime, UNIX_EPOCH},
|
time::{SystemTime, UNIX_EPOCH},
|
||||||
};
|
};
|
||||||
|
|
||||||
use binrw::{BinRead, BinResult, BinWrite, binrw, helpers::until_eof};
|
use binrw::{BinRead, BinWrite, binrw};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
io::{AsyncWriteExt, WriteHalf},
|
io::{AsyncWriteExt, WriteHalf},
|
||||||
net::TcpStream,
|
net::TcpStream,
|
||||||
|
@ -122,11 +122,11 @@ struct IPCSegment {
|
||||||
impl IPCSegment {
|
impl IPCSegment {
|
||||||
fn calc_size(&self) -> u32 {
|
fn calc_size(&self) -> u32 {
|
||||||
let header = 16;
|
let header = 16;
|
||||||
return header
|
header
|
||||||
+ match self.data {
|
+ match self.data {
|
||||||
IPCOpCode::ClientVersionInfo { .. } => todo!(),
|
IPCOpCode::ClientVersionInfo { .. } => todo!(),
|
||||||
IPCOpCode::LobbyServiceAccountList { .. } => 19,
|
IPCOpCode::LobbyServiceAccountList { .. } => 19,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,14 +197,14 @@ struct PacketSegment {
|
||||||
impl PacketSegment {
|
impl PacketSegment {
|
||||||
fn calc_size(&self) -> u32 {
|
fn calc_size(&self) -> u32 {
|
||||||
let header = std::mem::size_of::<u32>() * 4;
|
let header = std::mem::size_of::<u32>() * 4;
|
||||||
return header as u32
|
header as u32
|
||||||
+ match &self.segment_type {
|
+ match &self.segment_type {
|
||||||
SegmentType::InitializeEncryption { .. } => 616,
|
SegmentType::InitializeEncryption { .. } => 616,
|
||||||
SegmentType::InitializationEncryptionResponse { .. } => 640,
|
SegmentType::InitializationEncryptionResponse { .. } => 640,
|
||||||
SegmentType::IPC { data } => data.calc_size(),
|
SegmentType::IPC { data } => data.calc_size(),
|
||||||
SegmentType::KeepAlive { .. } => todo!(),
|
SegmentType::KeepAlive { .. } => todo!(),
|
||||||
SegmentType::KeepAliveResponse { .. } => 0x8,
|
SegmentType::KeepAliveResponse { .. } => 0x8,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,42 +55,42 @@ impl PatchList {
|
||||||
for patch in &self.patches {
|
for patch in &self.patches {
|
||||||
// length
|
// length
|
||||||
str.push_str(&patch.length.to_string());
|
str.push_str(&patch.length.to_string());
|
||||||
str.push_str("\t");
|
str.push('\t');
|
||||||
|
|
||||||
// TODO: unknown value, but i *suspect* is the size of the game on disk once this patch is applied.
|
// TODO: unknown value, but i *suspect* is the size of the game on disk once this patch is applied.
|
||||||
// which would make sense for the launcher to check for
|
// which would make sense for the launcher to check for
|
||||||
str.push_str(&patch.size_on_disk.to_string());
|
str.push_str(&patch.size_on_disk.to_string());
|
||||||
str.push_str("\t");
|
str.push('\t');
|
||||||
|
|
||||||
// TODO: totally unknown
|
// TODO: totally unknown
|
||||||
str.push_str(&patch.unknown_a.to_string());
|
str.push_str(&patch.unknown_a.to_string());
|
||||||
str.push_str("\t");
|
str.push('\t');
|
||||||
|
|
||||||
// TODO: unknown too
|
// TODO: unknown too
|
||||||
str.push_str(&patch.unknown_b.to_string());
|
str.push_str(&patch.unknown_b.to_string());
|
||||||
str.push_str("\t");
|
str.push('\t');
|
||||||
|
|
||||||
// version (e.g. 2023.09.15.0000.0000)
|
// version (e.g. 2023.09.15.0000.0000)
|
||||||
str.push_str(&patch.version);
|
str.push_str(&patch.version);
|
||||||
str.push_str("\t");
|
str.push('\t');
|
||||||
|
|
||||||
if (self.patch_type == PatchType::Game) {
|
if self.patch_type == PatchType::Game {
|
||||||
// hash type
|
// hash type
|
||||||
// TODO: does this need to be configurable?
|
// TODO: does this need to be configurable?
|
||||||
str.push_str("sha1");
|
str.push_str("sha1");
|
||||||
str.push_str("\t");
|
str.push('\t');
|
||||||
|
|
||||||
// hash block size
|
// hash block size
|
||||||
str.push_str(&patch.hash_block_size.to_string());
|
str.push_str(&patch.hash_block_size.to_string());
|
||||||
str.push_str("\t");
|
str.push('\t');
|
||||||
|
|
||||||
// hashes
|
// hashes
|
||||||
str.push_str(&patch.hashes[0]);
|
str.push_str(&patch.hashes[0]);
|
||||||
for hash in &patch.hashes[1..] {
|
for hash in &patch.hashes[1..] {
|
||||||
str.push_str(",");
|
str.push(',');
|
||||||
str.push_str(&hash);
|
str.push_str(hash);
|
||||||
}
|
}
|
||||||
str.push_str("\t");
|
str.push('\t');
|
||||||
}
|
}
|
||||||
|
|
||||||
// url
|
// url
|
||||||
|
@ -108,7 +108,6 @@ impl PatchList {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::fs;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue