Skip to content

Commit

Permalink
fix: artifactarium not returning most packets
Browse files Browse the repository at this point in the history
  • Loading branch information
Yumeo0 committed Nov 10, 2024
1 parent ff8d277 commit 9567483
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 41 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "artifactarium"]
path = artifactarium
url = https://github.com/Yumeo0/artifactarium
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"

anyhow = "1.0.93"
artifactarium = { git = "https://github.com/juliuskreutz/artifactarium" }
artifactarium = { path = "../artifactarium" }
pcap = "2.2.0"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
Expand Down
7 changes: 6 additions & 1 deletion src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
// lib.rs

mod settings;
mod sniffer;
mod state;
Expand All @@ -12,6 +13,10 @@ use tauri::Manager;

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tracing_subscriber::fmt()
.with_env_filter("mualani_guide=debug,artifactarium=warn")
.init();

tauri::Builder::default()
.plugin(tauri_plugin_shell::init())
.setup(|app| {
Expand Down
17 changes: 0 additions & 17 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use pcap::Device;
use tracing::info;

fn main() {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
.with_env_filter("mualani_guide=info")
.init();

info!("Starting up...");

info!("Available devices:");
let mut index = 0;
for device in Device::list().unwrap() {
info!("{}: {} <{}>", index, device.name, device.desc.unwrap());
index += 1;
}

mualani_guide_lib::run();
}
151 changes: 135 additions & 16 deletions src-tauri/src/sniffer.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
// sniffer.rs

use std::{
collections::HashMap,
sync::{Arc, Mutex},
thread,
};

use artifactarium::{GamePacket, GameSniffer};
use artifactarium::{GameCommand, GamePacket, GameSniffer};
use base64::prelude::*;
use pcap::{Capture, Device};
use proto_gen::generated::{pack_ids, PlayerInfo::PlayerInfo, PlayerTokenRsp::PlayerTokenRsp};
use proto_gen::generated::{
pack_ids,
APIKeyInfo::APIKeyNotify,
AchievementNotify::{AchievementNotify, AchievementUpdateNotify},
AvatarNotify::{
AvatarFightPropUpdate, AvatarNotify, AvatarPropertyUpdate, AvatarSkillUpdate,
TeamSwapNotify,
},
FriendInit::FriendInit,
PlayerInfo::PlayerInfo,
PlayerTokenRsp::PlayerTokenRsp,
PlayerUpdate::PlayerUpdate,
QuestNotify::QuestNotify,
SceneUpdate::{SceneEntityDieUpdate, SceneUpdate},
StoreNotify::StoreNotify,
StoreUpdate::StoreUpdate,
WorldPlayerLocationNotify::WorldNotify,
};
use protobuf_json_mapping::print_to_string;
use std::result::Result::Ok;
use tauri::{AppHandle, Emitter};
Expand All @@ -18,6 +37,19 @@ pub struct PacketSniffer {
capture_thread: Mutex<Option<std::thread::JoinHandle<()>>>,
}

pub fn handle_packet<T: protobuf::MessageFull>(
event_name: &str,
command: GameCommand,
app_handle: AppHandle,
) {
debug!("Handling packet: {:?}", command.command_id);
if let Ok(data) = command.parse_proto::<T>() {
app_handle
.emit(event_name, print_to_string(&data).unwrap())
.unwrap();
}
}

impl PacketSniffer {
pub fn new() -> Self {
PacketSniffer {
Expand All @@ -30,6 +62,7 @@ impl PacketSniffer {
let keys = load_keys()?;
let mut sniffer = GameSniffer::new().set_initial_keys(keys);
let shutdown_hook = Arc::clone(&self.shutdown_hook);
*shutdown_hook.lock().unwrap() = false;

let handle = thread::spawn(move || {
let mut capturer = Capture::from_device(device)
Expand All @@ -47,23 +80,109 @@ impl PacketSniffer {
else {
continue;
};

for command in commands {
if command.command_id == pack_ids::PLAYERTOKENRSP_ID {
if let Ok(data) = command.parse_proto::<PlayerTokenRsp>() {
info!("PlayerTokenRsp: {:?}", data);
app_handle
.emit("player_token_rsp", print_to_string(&data).unwrap())
.unwrap();
// debug!("Received command: {:?}", command.command_id);
match command.command_id {
pack_ids::ACHIEVEMENTNOTIFY_ID => {
handle_packet::<AchievementNotify>(
"achievement_notify",
command,
app_handle.clone(),
)
}
pack_ids::ACHIEVEMENTUPDATE_ID => {
handle_packet::<AchievementUpdateNotify>(
"achievement_update_notify",
command,
app_handle.clone(),
)
}
pack_ids::APIKEYINFO_ID => handle_packet::<APIKeyNotify>(
"api_key_notify",
command,
app_handle.clone(),
),
pack_ids::AVATARFIGHTPROP_ID => {
handle_packet::<AvatarFightPropUpdate>(
"avatar_fight_prop_update",
command,
app_handle.clone(),
)
}
} else if command.command_id == pack_ids::PLAYERINFO_ID {
if let Ok(data) = command.parse_proto::<PlayerInfo>() {
info!("PlayerInfo: {}", data);
app_handle
.emit("player_info", print_to_string(&data).unwrap())
.unwrap();
pack_ids::AVATARNOTIFY_ID => handle_packet::<AvatarNotify>(
"avatar_notify",
command,
app_handle.clone(),
),
pack_ids::AVATARPROP_ID => handle_packet::<AvatarPropertyUpdate>(
"avatar_property_update",
command,
app_handle.clone(),
),
pack_ids::FRIENDINIT_ID => handle_packet::<FriendInit>(
"friend_init",
command,
app_handle.clone(),
),
pack_ids::PLAYERINFO_ID => handle_packet::<PlayerInfo>(
"player_info",
command,
app_handle.clone(),
),
pack_ids::PLAYERTOKENRSP_ID => handle_packet::<PlayerTokenRsp>(
"player_token_rsp",
command,
app_handle.clone(),
),
pack_ids::PLAYERUPDATE_ID => handle_packet::<PlayerUpdate>(
"player_update",
command,
app_handle.clone(),
),
pack_ids::QUESTNOTIFY_ID => handle_packet::<QuestNotify>(
"quest_notify",
command,
app_handle.clone(),
),
pack_ids::SCENEENTITYDIE_ID => {
handle_packet::<SceneEntityDieUpdate>(
"scene_entity_die_update",
command,
app_handle.clone(),
)
}
}
pack_ids::SCENEUPDATE_ID => handle_packet::<SceneUpdate>(
"scene_update",
command,
app_handle.clone(),
),
pack_ids::SKILLUPDATE_ID => handle_packet::<AvatarSkillUpdate>(
"avatar_skill_update",
command,
app_handle.clone(),
),
pack_ids::STORENOTIFY_ID => handle_packet::<StoreNotify>(
"store_notify",
command,
app_handle.clone(),
),
pack_ids::STOREUPDATE_ID => handle_packet::<StoreUpdate>(
"store_update",
command,
app_handle.clone(),
),
pack_ids::TEAMSWAP_ID => handle_packet::<TeamSwapNotify>(
"team_swap_notify",
command,
app_handle.clone(),
),
pack_ids::WORLDNOTIFY_ID => handle_packet::<WorldNotify>(
"world_notify",
command,
app_handle.clone(),
),
_ => continue, //warn!("Packet not handled yet: {:?}", command.command_id),
};
}
}
Err(pcap::Error::TimeoutExpired) => {
Expand Down
30 changes: 25 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,32 @@ import { Event, listen } from '@tauri-apps/api/event';

function App() {

listen('player_token_rsp', (event: Event<string>) => {
console.log('Received PlayerTokenRsp:', event.payload);
});
const events = [
'achievement_notify',
//'achievement_update_notify',
'api_key_notify',
'avatar_fight_prop_update',
'avatar_notify',
'avatar_property_update',
'friend_init',
'player_info',
'player_token_rsp',
'player_update',
'quest_notify',
'scene_entity_die_update',
'scene_update',
'avatar_skill_update',
'store_notify',
'store_update',
'team_swap_notify',
'world_notify',
];

listen('player_info', (event: Event<string>) => {
console.log('Received PlayerInfo:', event.payload);
events.forEach((event) => {
console.debug('Listening for', event);
listen(event, (event: Event<string>) => {
console.log('Received', event.event, ':', JSON.parse(event.payload));
});
});

return (
Expand Down

0 comments on commit 9567483

Please sign in to comment.