-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Was working on some stuff I forgot about, anyways I made it use a uni…
…que ID in the user agent
- Loading branch information
Showing
18 changed files
with
446 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
Very very incomplete notes, the ramblings of an insane girl who wants to make her own patcher for some godsforsaken reason | ||
|
||
# Patch file | ||
|
||
# HIST Entry | ||
|
||
# APLY Entry | ||
Entry length : 4 bytes (big endian) | ||
Signature : 4 bytes "APLY" | ||
??? : 4 bytes (big endian) | ||
Entry data : [Entry length] bytes | ||
|
||
# SQPK Entry | ||
Container length : 4 bytes (big endian) | ||
Signature : 4 bytes "SQPK" | ||
Container length : 4 bytes (big endian) (yes it seems to be duplicated; data integrity reasons?) | ||
Container data : [Container length] bytes | ||
|
||
All containers seem to start with a 2 byte magic marker that determines | ||
what kind of data is stored in there. | ||
|
||
Types: | ||
- "T" (TBD) | ||
- "X" (TBD) | ||
- "FA" (Raw file record?) | ||
|
||
# Raw file record? | ||
|
||
Type marker? : 2 bytes "FA" | ||
??? : 14 bytes (usually all 0 but not always? has nothing to do with padding len) | ||
Output file len : 4 bytes (big endian) | ||
File name len : 4 bytes (big endian) | ||
??? : 4 bytes (always 0?) | ||
File name : [File name len] bytes | ||
??? : 4 bytes (little endian?) (appears to always be 0x10) | ||
??? : 4 bytes (always 0?) | ||
Data len 1 : 4 bytes (little endian) (is the array len if compressed, ??? when uncompressed) | ||
Data len 2 : 4 bytes (little endian) (output length, and array len if compressed) | ||
Patch data : [File data len] bytes | ||
Padding : ??????? bytes (whyyyyy) | ||
|
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "sqpatch" | ||
version = "0.1.0" | ||
authors = ["Connie Hilarides <[email protected]>"] | ||
edition = "2018" | ||
|
||
[dependencies] | ||
byteorder = "1.3.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::{Parse, Stream}; | ||
|
||
use std::io; | ||
|
||
use byteorder::{ReadBytesExt, BE}; | ||
|
||
pub const SQPK_SIG: u32 = 0x53_51_50_4B; // SQPK | ||
|
||
#[derive(Copy, Clone, Debug)] | ||
pub struct Aply { | ||
pub data: [u32; 4], | ||
} | ||
|
||
impl Parse for Aply { | ||
fn parse(stream: &mut impl Stream) -> io::Result<Aply> { | ||
let data = [ | ||
stream.read_u32::<BE>()?, | ||
stream.read_u32::<BE>()?, | ||
stream.read_u32::<BE>()?, | ||
stream.read_u32::<BE>()?, | ||
]; | ||
|
||
Ok(Aply { data }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use crate::{Parse, Position, Stream}; | ||
|
||
use byteorder::{ReadBytesExt, BE}; | ||
|
||
#[derive(Copy, Clone)] | ||
pub struct Container { | ||
/// Does not include the 4 bytes at the beginning of the data | ||
pub length: u32, | ||
pub signature: [u8; 4], | ||
pub data: Position, | ||
} | ||
|
||
impl Container { | ||
pub fn read_contents<D>(&self, stream: &mut impl Stream) -> std::io::Result<D> | ||
where | ||
D: Parse, | ||
{ | ||
stream.seek_to(self.data)?; | ||
D::parse(stream) | ||
} | ||
} | ||
|
||
impl Parse for Container { | ||
fn parse(stream: &mut impl Stream) -> std::io::Result<Self> { | ||
let length = stream.read_u32::<BE>()?; | ||
let mut signature = [0; 4]; | ||
stream.read_exact(&mut signature)?; | ||
let data = stream.pos()?; | ||
stream.seek_by(length as i64 + 4)?; | ||
|
||
Ok(Container { | ||
length, | ||
signature, | ||
data, | ||
}) | ||
} | ||
} | ||
|
||
impl std::fmt::Debug for Container { | ||
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
let sig = String::from_utf8_lossy(&self.signature); | ||
fmt.debug_struct("Container") | ||
.field("length", &self.length) | ||
.field("signature", &sig) | ||
.field("data", &self.data) | ||
.finish() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
use crate::{Parse, Position, Stream}; | ||
|
||
use std::cmp::min; | ||
|
||
use byteorder::{ReadBytesExt, BE, LE}; | ||
|
||
pub struct FileRecord { | ||
pub header: [u8; 4], | ||
pub unk0: u32, | ||
pub file_offset: u32, | ||
pub unk1: u32, | ||
pub file_length: u32, | ||
pub unk2: u32, | ||
pub file_name: String, | ||
pub chunks: Vec<FileChunk>, | ||
pub hash: [u8; 4], | ||
} | ||
|
||
impl Parse for FileRecord { | ||
fn parse(stream: &mut impl Stream) -> std::io::Result<FileRecord> { | ||
let mut header = [0; 4]; | ||
stream.read_exact(&mut header)?; | ||
|
||
let unk0 = stream.read_u32::<BE>()?; | ||
let file_offset = stream.read_u32::<BE>()?; | ||
let unk1 = stream.read_u32::<BE>()?; | ||
|
||
let file_length = stream.read_u32::<BE>()?; | ||
let file_name_len = stream.read_u32::<BE>()?; | ||
let unk2 = stream.read_u32::<BE>()?; | ||
|
||
let mut file_name = vec![0; file_name_len as usize]; | ||
stream.read_exact(&mut file_name)?; | ||
file_name.pop(); | ||
let file_name = String::from_utf8_lossy(&file_name).into_owned(); | ||
|
||
let mut chunks = vec![]; | ||
loop { | ||
if stream.peek_u32_le()? != 16 { | ||
break; | ||
} | ||
|
||
chunks.push(FileChunk::parse(stream)?); | ||
} | ||
|
||
let mut hash = [0; 4]; | ||
stream.read_exact(&mut hash)?; | ||
|
||
Ok(FileRecord { | ||
header, | ||
unk0, | ||
file_offset, | ||
unk1, | ||
file_length, | ||
unk2, | ||
file_name, | ||
chunks, | ||
hash, | ||
}) | ||
} | ||
} | ||
|
||
pub struct FileChunk { | ||
pub unk0: u32, | ||
pub unk1: u32, | ||
pub data_len: u32, | ||
pub expanded_len: u32, | ||
pub data: Position, | ||
} | ||
|
||
impl Parse for FileChunk { | ||
fn parse(stream: &mut impl Stream) -> std::io::Result<FileChunk> { | ||
let begin = stream.pos()?; | ||
|
||
let unk0 = stream.read_u32::<LE>()?; | ||
let unk1 = stream.read_u32::<LE>()?; | ||
|
||
let data_len = stream.read_u32::<LE>()?; | ||
let expanded_len = stream.read_u32::<LE>()?; | ||
|
||
let data = stream.pos()?; | ||
|
||
stream.seek_by(min(data_len, expanded_len) as i64)?; | ||
stream.align_up_from(begin, 0x80)?; | ||
|
||
Ok(FileChunk { | ||
unk0, | ||
unk1, | ||
data_len, | ||
expanded_len, | ||
data, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use std::fmt::UpperHex; | ||
|
||
pub struct HexFmt<'a, T: UpperHex>(pub &'a T); | ||
|
||
impl<T: UpperHex> std::fmt::Debug for HexFmt<'_, T> { | ||
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
self.0.fmt(fmt) | ||
} | ||
} |
Oops, something went wrong.