Port strinova proto debug feature
This commit is contained in:
parent
81073a2a28
commit
316e3ee06f
4 changed files with 84 additions and 46 deletions
19
Cargo.toml
19
Cargo.toml
|
@ -7,4 +7,23 @@ edition = "2024"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
|
byteorder = "1.5.0"
|
||||||
|
crc32fast = "1.4.2"
|
||||||
|
prettyplease = "0.2.32"
|
||||||
|
proc-macro2 = "1.0.95"
|
||||||
|
prost = "0.13.5"
|
||||||
|
prost-build = "0.13.5"
|
||||||
|
quote = "1.0.40" #
|
||||||
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
|
serde_json = "1.0.140"
|
||||||
|
syn = "2.0.101" #
|
||||||
|
thiserror = "2.0.12"
|
||||||
|
|
||||||
|
# Internal
|
||||||
wicked-waifus-protocol-derive = { path = "wicked-waifus-protocol-derive" }
|
wicked-waifus-protocol-derive = { path = "wicked-waifus-protocol-derive" }
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
strip = true # Automatically strip symbols from the binary.
|
||||||
|
lto = true # Link-time optimization.
|
||||||
|
opt-level = 3 # Optimization level 3.
|
||||||
|
codegen-units = 1 # Maximum size reduction optimizations.
|
||||||
|
|
|
@ -4,9 +4,9 @@ edition.workspace = true
|
||||||
version.workspace = true
|
version.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
syn = "2.0.100"
|
syn.workspace = true
|
||||||
quote = "1.0.40"
|
quote.workspace = true
|
||||||
proc-macro2 = "1.0.94"
|
proc-macro2.workspace = true
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
|
|
@ -3,17 +3,20 @@ name = "wicked-waifus-protocol"
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
version.workspace = true
|
version.workspace = true
|
||||||
|
|
||||||
|
[features]
|
||||||
|
debug = ["dep:serde", "dep:serde_json"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
byteorder = "1.5.0"
|
byteorder.workspace = true
|
||||||
crc32fast = "1.4.2"
|
crc32fast.workspace = true
|
||||||
thiserror = "2.0.12"
|
prost.workspace = true
|
||||||
prost = "0.13.5"
|
serde = { workspace = true, optional = true }
|
||||||
serde = { version = "1.0.219", features = ["derive"] }
|
serde_json = { workspace = true, optional = true }
|
||||||
serde_json = "1.0.140"
|
thiserror.workspace = true
|
||||||
wicked-waifus-protocol-derive.workspace = true
|
wicked-waifus-protocol-derive.workspace = true
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
prost-build = "0.13.5"
|
prettyplease.workspace = true
|
||||||
quote = "1.0.40"
|
prost-build.workspace = true
|
||||||
syn = "2.0.100"
|
quote.workspace = true
|
||||||
prettyplease = "0.2.31"
|
syn.workspace = true
|
|
@ -24,15 +24,28 @@ pub fn main() {
|
||||||
if Path::new(&proto_file).exists() {
|
if Path::new(&proto_file).exists() {
|
||||||
println!("cargo:rerun-if-changed={proto_file}");
|
println!("cargo:rerun-if-changed={proto_file}");
|
||||||
|
|
||||||
prost_build::Config::new()
|
#[cfg(feature = "debug")]
|
||||||
.out_dir(CODEGEN_OUT_DIR)
|
{
|
||||||
.default_package_filename("wicked-waifus")
|
prost_build::Config::new()
|
||||||
.type_attribute(".", "#[derive(wicked_waifus_protocol_derive::MessageID)]")
|
.out_dir(CODEGEN_OUT_DIR)
|
||||||
.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")
|
.default_package_filename("wicked-waifus")
|
||||||
.compile_protos(&[proto_file], &["wicked-waifus"])
|
.type_attribute(".", "#[derive(wicked_waifus_protocol_derive::MessageID)]")
|
||||||
.unwrap();
|
.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]")
|
||||||
|
.compile_protos(&[proto_file], &["wicked-waifus"])
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
impl_dumper(Path::new("generated/wicked-waifus.rs")).unwrap();
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "debug"))]
|
||||||
|
{
|
||||||
|
prost_build::Config::new()
|
||||||
|
.out_dir(CODEGEN_OUT_DIR)
|
||||||
|
.default_package_filename("wicked-waifus")
|
||||||
|
.type_attribute(".", "#[derive(wicked_waifus_protocol_derive::MessageID)]")
|
||||||
|
.compile_protos(&[proto_file], &["wicked-waifus"])
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
impl_dumper(Path::new("generated/wicked-waifus.rs")).unwrap();
|
|
||||||
impl_message_id(Path::new("generated/wicked-waifus.rs")).unwrap();
|
impl_message_id(Path::new("generated/wicked-waifus.rs")).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,35 +147,38 @@ pub fn impl_dumper(codegen_path: &Path) -> io::Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let generated_code = quote! {
|
if !match_arms.is_empty() {
|
||||||
pub mod proto_dumper {
|
let generated_code = quote! {
|
||||||
use prost::Message;
|
pub mod proto_dumper {
|
||||||
use crate::*;
|
use prost::Message;
|
||||||
use crate::ai::*;
|
use crate::*;
|
||||||
use crate::combat_message::*;
|
use crate::ai::*;
|
||||||
use crate::debug::*;
|
use crate::combat_message::*;
|
||||||
use crate::summon::*;
|
use crate::debug::*;
|
||||||
|
use crate::summon::*;
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("serde_json::Error: {0}")]
|
#[error("serde_json::Error: {0}")]
|
||||||
Json(#[from] serde_json::Error),
|
Json(#[from] serde_json::Error),
|
||||||
#[error("serde_json::Error: {0}")]
|
#[error("serde_json::Error: {0}")]
|
||||||
Decode(#[from] prost::DecodeError),
|
Decode(#[from] prost::DecodeError),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_debug_info(id: u16, data: &[u8]) -> Result<(&str, String), Error> {
|
pub fn get_debug_info(id: u16, data: &[u8]) -> Result<(&str, String), Error> {
|
||||||
match id {
|
match id {
|
||||||
#match_arms
|
#match_arms
|
||||||
_ => Ok(("UnknownType", "".to_string())),
|
_ => Ok(("UnknownType", "".to_string())),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
|
let syntax_tree = syn::parse2(generated_code).unwrap();
|
||||||
|
let formatted = prettyplease::unparse(&syntax_tree);
|
||||||
|
let mut file = fs::OpenOptions::new().append(true).open(codegen_path)?;
|
||||||
|
file.write(formatted.as_bytes())?;
|
||||||
|
}
|
||||||
|
|
||||||
let syntax_tree = syn::parse2(generated_code).unwrap();
|
|
||||||
let formatted = prettyplease::unparse(&syntax_tree);
|
|
||||||
let mut file = fs::OpenOptions::new().append(true).open(codegen_path)?;
|
|
||||||
file.write(formatted.as_bytes())?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
Loading…
Reference in a new issue