Added sample config #5

Merged
xavo95 merged 2 commits from add-config-samples into master 2024-09-30 19:16:50 +00:00
4 changed files with 139 additions and 69 deletions
Showing only changes of commit 22be65c0e9 - Show all commits

4
Cargo.lock generated
View file

@ -1745,10 +1745,14 @@ version = "0.1.0"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"crc32fast", "crc32fast",
"prettyplease",
"prost", "prost",
"prost-build", "prost-build",
"quote", "quote",
"serde",
"serde_json",
"shorekeeper-protocol-derive", "shorekeeper-protocol-derive",
"syn",
"thiserror", "thiserror",
] ]

View file

@ -8,8 +8,12 @@ byteorder.workspace = true
crc32fast.workspace = true crc32fast.workspace = true
thiserror.workspace = true thiserror.workspace = true
prost.workspace = true prost.workspace = true
serde.workspace = true
serde_json.workspace = true
shorekeeper-protocol-derive.workspace = true shorekeeper-protocol-derive.workspace = true
[build-dependencies] [build-dependencies]
prost-build.workspace = true prost-build.workspace = true
quote = "1.0.35" quote = "1.0.35"
syn = "2.0.76"
prettyplease = "0.2.22"

View file

@ -3,8 +3,9 @@ use std::{
io::{self, BufRead}, io::{self, BufRead},
path::Path, path::Path,
}; };
use std::io::Write;
use quote::quote; use quote::{format_ident, quote};
const CODEGEN_OUT_DIR: &str = "generated/"; const CODEGEN_OUT_DIR: &str = "generated/";
@ -26,9 +27,11 @@ pub fn main() {
prost_build::Config::new() prost_build::Config::new()
.out_dir(CODEGEN_OUT_DIR) .out_dir(CODEGEN_OUT_DIR)
.type_attribute(".", "#[derive(shorekeeper_protocol_derive::MessageID)]") .type_attribute(".", "#[derive(shorekeeper_protocol_derive::MessageID)]")
.type_attribute(".", "#[derive(serde::Serialize,serde::Deserialize)]")
.compile_protos(&[proto_file], &["shorekeeper"]) .compile_protos(&[proto_file], &["shorekeeper"])
.unwrap(); .unwrap();
impl_dumper(Path::new("generated/shorekeeper.rs")).unwrap();
impl_message_id(Path::new("generated/shorekeeper.rs")).unwrap(); impl_message_id(Path::new("generated/shorekeeper.rs")).unwrap();
} }
@ -92,10 +95,11 @@ pub fn impl_proto_config(csv_path: &Path, codegen_path: &Path) -> io::Result<()>
} }
} }
} }
} };
.to_string();
fs::write(codegen_path, generated_code.as_bytes())?; let syntax_tree = syn::parse2(generated_code).unwrap();
let formatted = prettyplease::unparse(&syntax_tree);
fs::write(codegen_path, formatted.as_bytes())?;
Ok(()) Ok(())
} }
@ -126,3 +130,61 @@ fn make_message_id_attr(line: &str) -> Option<String> {
let id = line.trim_start().split(' ').nth(2)?.parse::<u16>().ok()?; let id = line.trim_start().split(' ').nth(2)?.parse::<u16>().ok()?;
Some(format!("#[message_id({id})]")) Some(format!("#[message_id({id})]"))
} }
pub fn impl_dumper(codegen_path: &Path) -> io::Result<()> {
let file = fs::File::open(codegen_path)?;
let reader = io::BufReader::new(file);
let mut match_arms = quote! {};
let mut id = None;
for line in reader.lines() {
let line = line?;
if line.contains("MessageId:") {
id = Some(
line.trim_start().split(' ').nth(2).unwrap().parse::<u16>().ok().unwrap()
);
} else if line.contains("pub struct") {
if let Some(id) = id.take() {
let name = line.trim_start().split(' ').nth(2).unwrap().to_string();
let name_ident = format_ident!("{}", name);
match_arms = quote! {
#match_arms
#id => Ok((#name, serde_json::to_string_pretty(&#name_ident::decode(data)?)?)),
};
}
}
}
let generated_code = quote! {
pub mod proto_dumper {
use prost::Message;
use crate::*;
use crate::ai::*;
use crate::combat_message::*;
use crate::debug::*;
use crate::summon::*;
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("serde_json::Error: {0}")]
Json(#[from] serde_json::Error),
#[error("serde_json::Error: {0}")]
Decode(#[from] prost::DecodeError),
}
pub fn get_debug_info(id: u16, data: &[u8]) -> Result<(&str, String), Error> {
match id {
#match_arms
_ => 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())?;
Ok(())
}

View file

@ -5087,16 +5087,16 @@ message ItemDict {
repeated ItemEntry Items = 1; repeated ItemEntry Items = 1;
} }
message Uih2 { message DragonPoolDropItems {
int32 DragonPoolId = 1; int32 DragonPoolId = 1;
repeated int32 QSs = 2; repeated int32 QSs = 2; // Not used in code, niggers
repeated ItemDict XSs = 3; repeated ItemDict DropItems = 3;
} }
// MessageId: 21983 (Response) // MessageId: 21983 (Response)
message ghs2 { message ghs2 {
ErrorCode ErrorCode = 21; ErrorCode ErrorCode = 21;
Uih2 Uih = 199; DragonPoolDropItems Uih = 199;
} }
// MessageId: 26716 (Request) // MessageId: 26716 (Request)
@ -5112,17 +5112,17 @@ message Mth1 {
} }
// MessageId: 25864 (Request) // MessageId: 25864 (Request)
message Ith1 { message DarkCoastDeliveryRequest {
int32 DragonPoolId = 200; int32 DragonPoolId = 200;
} }
// MessageId: 23120 (Response) // MessageId: 23120 (Response)
message Tth1 { message DarkCoastDeliveryResponse {
ErrorCode ErrorCode = 104; ErrorCode ErrorCode = 104;
Uih2 Uih = 43; DragonPoolDropItems DragonPoolDropItems = 43;
repeated int32 bih1 = 82; repeated int32 DefeatedGuard = 82;
repeated int32 Bih2 = 14; repeated int32 ReceivedGuardReward = 14;
int32 xih1 = 1; int32 LevelGain = 1;
} }
enum BattlePassType { enum BattlePassType {
@ -6885,7 +6885,7 @@ message ApplyGameplayEffectRequest {
// MessageId: 18140 (Response) // MessageId: 18140 (Response)
message ApplyGameplayEffectResponse { message ApplyGameplayEffectResponse {
int32 errCode = 61; ErrorCode ErrorCode = 61;
} }
// MessageId: 26675 (Notify) // MessageId: 26675 (Notify)
@ -6913,7 +6913,7 @@ message RemoveGameplayEffectRequest {
// MessageId: 23319 (Response) // MessageId: 23319 (Response)
message RemoveGameplayEffectResponse { message RemoveGameplayEffectResponse {
int32 errCode = 53; ErrorCode ErrorCode = 53;
int32 Handle = 38; int32 Handle = 38;
} }
@ -7296,15 +7296,15 @@ message t3n {
int32 State = 32; int32 State = 32;
} }
message fFs1 { message DFsm {
int32 FsmId = 1; int32 FsmId = 1;
int32 OTs2 = 2; int32 CurrentState = 2;
int32 Flag = 3; int32 Flag = 3;
int32 kTs = 6; int32 kTs = 6;
} }
message EntityFsmComponentPb { message EntityFsmComponentPb {
repeated fFs1 NTs = 1; repeated DFsm Fsms = 1;
int32 HashCode = 2; int32 HashCode = 2;
int32 CommonHashCode = 3; int32 CommonHashCode = 3;
repeated DFsmBlackBoard BlackBoard = 4; repeated DFsmBlackBoard BlackBoard = 4;
@ -8103,7 +8103,7 @@ message Rca {
} }
message CombatMessage { message CombatMessage {
message CombatMessageTest { message CombatPushData {
CombatCommon CombatCommon = 1; CombatCommon CombatCommon = 1;
oneof Message { oneof Message {
FormationBuffApplyS2cResponsePush FormationBuffApplyS2cResponsePush = 2; FormationBuffApplyS2cResponsePush FormationBuffApplyS2cResponsePush = 2;
@ -8336,8 +8336,8 @@ message CombatMessage {
} }
message CombatSendData { message CombatSendData {
oneof Message { oneof Message {
CombatMessage.CombatMessageTest Push = 2; CombatMessage.CombatPushData Push = 2;
CombatMessage.CombatRequestData request = 3; CombatMessage.CombatRequestData Request = 3;
} }
} }
@ -12497,8 +12497,8 @@ message NormalItemUpdateNotify {
} }
// MessageId: 22716 (Notify) // MessageId: 22716 (Notify)
message pns { message NormalItemRemoveNotify {
repeated int32 Pws = 146; repeated int32 NormalItemIdList = 146;
} }
// MessageId: 28027 (Notify) // MessageId: 28027 (Notify)
@ -12525,8 +12525,8 @@ message WeaponItemAddNotify {
} }
// MessageId: 21270 (Notify) // MessageId: 21270 (Notify)
message Ins1 { message WeaponItemRemoveNotify {
repeated int32 xws = 102; repeated int32 WeaponItemIncrIdList = 102;
} }
// MessageId: 27123 (Request) // MessageId: 27123 (Request)
@ -15819,114 +15819,114 @@ enum SceneStepStatus {
SceneStepStatus_Failed = 2; SceneStepStatus_Failed = 2;
} }
message M8s2 { message SceneStepConditionProgress {
int32 ConditionId = 1; int32 ConditionId = 1;
int32 Oqs = 2; int32 ProgressNum = 2;
} }
message S8s { message SceneStepPlayerProgress {
int32 PlayerId = 1; int32 PlayerId = 1;
repeated M8s2 Progress = 2; repeated SceneStepConditionProgress Progress = 2;
} }
message E8s { message SceneStepInfo {
int32 kqs = 1; int32 StepId = 1;
int32 Status = 2; int32 Status = 2;
repeated M8s2 Progress = 3; repeated SceneStepConditionProgress Progress = 3;
repeated S8s Nqs = 4; repeated SceneStepPlayerProgress MultiPlayerProgress = 4;
} }
message y8s { message SceneStepGroupInfo {
int32 Fqs1 = 1; int32 StepGroupId = 1;
repeated E8s Vqs = 2; repeated SceneStepInfo Vqs = 2;
} }
// MessageId: 23058 (Notify) // MessageId: 23058 (Notify)
message Ims2 { message SceneStepGroupInfoNotify {
repeated y8s DOLLARqs = 165; repeated SceneStepGroupInfo StepGroupInfo = 165;
} }
// MessageId: 21075 (Notify) // MessageId: 21075 (Notify)
message Tms1 { message SceneStepInfoNotify {
int32 Fqs1 = 55; int32 StepGroupId = 55;
E8s Hqs = 129; SceneStepInfo StepInfo = 129;
} }
// MessageId: 16494 (Request) // MessageId: 16494 (Request)
message Lms2 { message TargetGearHitRequest {
int64 EntityId = 81; int64 EntityId = 81;
} }
// MessageId: 19766 (Response) // MessageId: 19766 (Response)
message Rms1 { message TargetGearHitResponse {
ErrorCode ErrorCode = 170; ErrorCode ErrorCode = 170;
} }
// MessageId: 24959 (Request) // MessageId: 24959 (Request)
message Dms3 { message ThrowDamageRequest {
int64 EntityId = 90; int64 EntityId = 90;
int64 I5n1 = 167; int64 CalculateId = 167;
} }
// MessageId: 19365 (Response) // MessageId: 19365 (Response)
message Ams3 { message ThrowDamageResponse {
ErrorCode ErrorCode = 87; ErrorCode ErrorCode = 87;
} }
// MessageId: 18924 (Notify) // MessageId: 18924 (Notify)
message Pms { message ThrowDamageNotify {
int64 EntityId = 211; int64 EntityId = 211;
int32 jqs = 104; int32 Durability = 104;
} }
// MessageId: 17147 (Notify) // MessageId: 17147 (Notify)
message Ums2 { message ThrowDamageRecoveryNotify {
int64 EntityId = 221; int64 EntityId = 221;
int32 jqs = 229; int32 Durability = 229;
} }
// MessageId: 27451 (Request) // MessageId: 27451 (Request)
message wms2 { message GetRewardTreasureBoxRequest {
int64 EntityId = 82; int64 EntityId = 82;
} }
// MessageId: 26500 (Response) // MessageId: 26500 (Response)
message xms1 { message GetRewardTreasureBoxResponse {
ErrorCode ErrorCode = 49; ErrorCode ErrorCode = 49;
} }
message I8s { message MobileButtonSetting {
int32 Flag = 1; int32 Id = 1;
float M8n = 2; float Size = 2;
float S8n = 3; float Transparency = 3;
float E8n = 4; float ScreenX = 4;
float y8n = 5; float ScreenY = 5;
int32 I8n = 6; int32 ButtonLevel = 6;
int32 T8n = 7; int32 PanelLevel = 7;
} }
// MessageId: 23399 (Notify) // MessageId: 23399 (Notify)
message bms1 { message SettingNotify {
repeated I8s v8n = 62; repeated MobileButtonSetting MobileButtonSettings = 62;
} }
// MessageId: 17765 (Request) // MessageId: 17765 (Request)
message Bms2 { message MobileButtonSettingUpdateRequest {
repeated I8s v8n = 113; repeated MobileButtonSetting MobileButtonSettings = 113;
} }
// MessageId: 28703 (Response) // MessageId: 28703 (Response)
message qms1 { message MobileButtonSettingUpdateResponse {
ErrorCode ErrorCode = 146; ErrorCode ErrorCode = 146;
} }
// MessageId: 24990 (Request) // MessageId: 24990 (Request)
message Gms1 { message LanguageSettingUpdateRequest {
int32 Language = 55; int32 Language = 55;
} }
// MessageId: 17062 (Response) // MessageId: 17062 (Response)
message Oms1 { message LanguageSettingUpdateResponse {
ErrorCode ErrorCode = 108; ErrorCode ErrorCode = 108;
} }
@ -16011,7 +16011,7 @@ message InputSettingUpdateRequest {
// MessageId: 29049 (Response) // MessageId: 29049 (Response)
message InputSettingUpdateResponse { message InputSettingUpdateResponse {
int32 ErrorCode = 240; ErrorCode ErrorCode = 240;
} }
// MessageId: 16176 (Notify) // MessageId: 16176 (Notify)