Compare commits

..

1 Commits
main ... update

Author SHA1 Message Date
f01d89b681
build(deps)!: update azalea and fix ecs changes 2025-05-01 18:13:07 -04:00
14 changed files with 455 additions and 349 deletions

635
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -1,15 +1,11 @@
use azalea::{brigadier::prelude::*, chat::ChatPacket, prelude::*}; use azalea::{brigadier::prelude::*, chat::ChatPacket, prelude::*};
use futures::lock::Mutex; use futures::lock::Mutex;
use mlua::{Error, Result, Table, UserDataRef}; use mlua::{Function, Table};
use ncr::{ use ncr::utils::prepend_header;
encoding::{Base64Encoding, Base64rEncoding, NewBase64rEncoding},
encryption::{CaesarEncryption, Cfb8Encryption, EcbEncryption, Encryption, GcmEncryption},
utils::prepend_header,
};
use crate::{ use crate::{
State, crypt, State,
lua::{eval, exec, nochatreports::key::AesKey, reload}, lua::{eval, exec, reload},
}; };
pub type Ctx = CommandContext<Mutex<CommandSource>>; pub type Ctx = CommandContext<Mutex<CommandSource>>;
@ -23,20 +19,15 @@ pub struct CommandSource {
impl CommandSource { impl CommandSource {
pub fn reply(&self, message: &str) { pub fn reply(&self, message: &str) {
fn encrypt(options: &Table, plaintext: &str) -> Result<String> {
Ok(crypt!(encrypt, options, &prepend_header(plaintext)))
}
for mut chunk in message for mut chunk in message
.chars() .chars()
.collect::<Vec<char>>() .collect::<Vec<char>>()
.chunks(if self.ncr_options.is_some() { 150 } else { 236 }) .chunks(if self.ncr_options.is_some() { 150 } else { 236 })
.map(|chars| chars.iter().collect::<String>()) .map(|chars| chars.iter().collect::<String>())
{ {
if let Some(ciphertext) = self if let Some(options) = &self.ncr_options
.ncr_options && let Ok(encrypt) = self.state.lua.globals().get::<Function>("ncr_encrypt")
.as_ref() && let Ok(ciphertext) = encrypt.call::<String>((options, prepend_header(&chunk)))
.and_then(|options| encrypt(options, &chunk).ok())
{ {
chunk = ciphertext; chunk = ciphertext;
} }

@ -35,6 +35,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
let uuid = message.sender_uuid().map(|uuid| uuid.to_string()); let uuid = message.sender_uuid().map(|uuid| uuid.to_string());
let is_whisper = message.is_whisper(); let is_whisper = message.is_whisper();
let text = message.message(); let text = message.message();
let html_text = text.to_html();
let ansi_text = text.to_ansi(); let ansi_text = text.to_ansi();
info!("{ansi_text}"); info!("{ansi_text}");
@ -86,6 +87,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
let table = state.lua.create_table()?; let table = state.lua.create_table()?;
table.set("text", text.to_string())?; table.set("text", text.to_string())?;
table.set("ansi_text", ansi_text)?; table.set("ansi_text", ansi_text)?;
table.set("html_text", html_text)?;
table.set("sender", sender)?; table.set("sender", sender)?;
table.set("content", content)?; table.set("content", content)?;
table.set("uuid", uuid)?; table.set("uuid", uuid)?;
@ -101,6 +103,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
let message_table = state.lua.create_table()?; let message_table = state.lua.create_table()?;
message_table.set("text", packet.message.to_string())?; message_table.set("text", packet.message.to_string())?;
message_table.set("ansi_text", packet.message.to_ansi())?; message_table.set("ansi_text", packet.message.to_ansi())?;
message_table.set("html_text", packet.message.to_html())?;
let table = state.lua.create_table()?; let table = state.lua.create_table()?;
table.set("message", message_table)?; table.set("message", message_table)?;
table.set("player_id", packet.player_id.0)?; table.set("player_id", packet.player_id.0)?;
@ -117,6 +120,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
let table = state.lua.create_table()?; let table = state.lua.create_table()?;
table.set("text", message.to_string())?; table.set("text", message.to_string())?;
table.set("ansi_text", message.to_ansi())?; table.set("ansi_text", message.to_ansi())?;
table.set("html_text", message.to_html())?;
Ok(table) Ok(table)
}) })
.await .await
@ -125,7 +129,6 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
} }
} }
Event::KeepAlive(id) => call_listeners(&state, "keep_alive", || Ok(id)).await, Event::KeepAlive(id) => call_listeners(&state, "keep_alive", || Ok(id)).await,
Event::Login => call_listeners(&state, "login", || Ok(())).await,
Event::RemovePlayer(player_info) => { Event::RemovePlayer(player_info) => {
call_listeners(&state, "remove_player", || Ok(Player::from(player_info))).await call_listeners(&state, "remove_player", || Ok(Player::from(player_info))).await
} }
@ -201,6 +204,12 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
} }
_ => Ok(()), _ => Ok(()),
}, },
Event::Login => {
#[cfg(feature = "matrix")]
matrix_init(&client, state.clone());
call_listeners(&state, "login", || Ok(())).await
}
Event::Init => { Event::Init => {
debug!("received init event"); debug!("received init event");
@ -212,9 +221,6 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
exit(0); exit(0);
})?; })?;
#[cfg(feature = "matrix")]
matrix_init(&client, state.clone());
let globals = state.lua.globals(); let globals = state.lua.globals();
lua_init(client, &state, &globals).await?; lua_init(client, &state, &globals).await?;

@ -3,9 +3,9 @@
pub mod anti_knockback; pub mod anti_knockback;
use anti_knockback::anti_knockback; use anti_knockback::anti_knockback;
use azalea::{movement::handle_knockback, packet::game::process_packet_events}; use azalea::{connection::read_packets, movement::handle_knockback};
use bevy_app::{App, Plugin, PreUpdate}; use bevy_app::{App, Plugin, PreUpdate};
use bevy_ecs::schedule::IntoSystemConfigs; use bevy_ecs::schedule::IntoScheduleConfigs;
pub struct HacksPlugin; pub struct HacksPlugin;
@ -13,9 +13,7 @@ impl Plugin for HacksPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_systems( app.add_systems(
PreUpdate, PreUpdate,
anti_knockback anti_knockback.after(read_packets).before(handle_knockback),
.after(process_packet_events)
.before(handle_knockback),
); );
} }
} }

@ -60,7 +60,7 @@ pub async fn get_block_states(
true true
}) })
{ {
matched.push(block.id); matched.push(block.id());
} }
} }
} }

@ -4,7 +4,6 @@ use azalea::{
prelude::ContainerClientExt, prelude::ContainerClientExt,
protocol::packets::game::ServerboundSetCarriedItem, protocol::packets::game::ServerboundSetCarriedItem,
}; };
use log::error;
use mlua::{Lua, Result, UserDataRef, Value}; use mlua::{Lua, Result, UserDataRef, Value};
use super::{Client, Container, ContainerRef, ItemStack, Vec3}; use super::{Client, Container, ContainerRef, ItemStack, Vec3};
@ -126,11 +125,8 @@ pub fn set_held_slot(_lua: &Lua, client: &Client, slot: u8) -> Result<()> {
inventory.selected_hotbar_slot = slot; inventory.selected_hotbar_slot = slot;
}; };
if let Err(error) = client.write_packet(ServerboundSetCarriedItem { client.write_packet(ServerboundSetCarriedItem {
slot: u16::from(slot), slot: u16::from(slot),
}) { });
error!("failed to send SetCarriedItem packet: {error:?}");
}
Ok(()) Ok(())
} }

@ -3,7 +3,6 @@ use azalea::{
protocol::packets::game::{ServerboundUseItem, s_interact::InteractionHand}, protocol::packets::game::{ServerboundUseItem, s_interact::InteractionHand},
world::MinecraftEntityId, world::MinecraftEntityId,
}; };
use log::error;
use mlua::{Lua, Result, UserDataRef}; use mlua::{Lua, Result, UserDataRef};
use super::{Client, Vec3}; use super::{Client, Vec3};
@ -57,7 +56,7 @@ pub fn start_mining(_lua: &Lua, client: &Client, position: Vec3) -> Result<()> {
pub fn use_item(_lua: &Lua, client: &Client, hand: Option<u8>) -> Result<()> { pub fn use_item(_lua: &Lua, client: &Client, hand: Option<u8>) -> Result<()> {
let direction = client.direction(); let direction = client.direction();
if let Err(error) = client.write_packet(ServerboundUseItem { client.write_packet(ServerboundUseItem {
hand: match hand { hand: match hand {
Some(1) => InteractionHand::OffHand, Some(1) => InteractionHand::OffHand,
_ => InteractionHand::MainHand, _ => InteractionHand::MainHand,
@ -65,8 +64,6 @@ pub fn use_item(_lua: &Lua, client: &Client, hand: Option<u8>) -> Result<()> {
sequence: 0, sequence: 0,
yaw: direction.0, yaw: direction.0,
pitch: direction.1, pitch: direction.1,
}) { });
error!("failed to send UseItem packet: {error:?}");
}
Ok(()) Ok(())
} }

@ -3,13 +3,12 @@ use azalea::{
entity::Position, entity::Position,
interact::HitResultComponent, interact::HitResultComponent,
pathfinder::{ pathfinder::{
ExecutingPath, GotoEvent, Pathfinder, PathfinderClientExt, ExecutingPath, Pathfinder, PathfinderClientExt,
goals::{BlockPosGoal, Goal, InverseGoal, RadiusGoal, ReachBlockPosGoal, XZGoal, YGoal}, goals::{BlockPosGoal, Goal, InverseGoal, RadiusGoal, ReachBlockPosGoal, XZGoal, YGoal},
}, },
protocol::packets::game::{ServerboundPlayerCommand, s_player_command::Action}, protocol::packets::game::{ServerboundPlayerCommand, s_player_command::Action},
world::MinecraftEntityId, world::MinecraftEntityId,
}; };
use log::error;
use mlua::{FromLua, Lua, Result, Table, UserDataRef, Value}; use mlua::{FromLua, Lua, Result, Table, UserDataRef, Value};
use super::{Client, Direction, Vec3}; use super::{Client, Direction, Vec3};
@ -121,11 +120,7 @@ pub async fn start_go_to(
} else { } else {
client.start_goto(goal); client.start_goto(goal);
} }
while client.get_tick_broadcaster().recv().await.is_ok() { let _ = client.get_tick_broadcaster().recv().await;
if client.ecs.lock().get::<GotoEvent>(client.entity).is_none() {
break;
}
}
Ok(()) Ok(())
} }
@ -215,7 +210,7 @@ pub fn set_position(_lua: &Lua, client: &Client, new_position: Vec3) -> Result<(
} }
pub fn set_sneaking(_lua: &Lua, client: &Client, sneaking: bool) -> Result<()> { pub fn set_sneaking(_lua: &Lua, client: &Client, sneaking: bool) -> Result<()> {
if let Err(error) = client.write_packet(ServerboundPlayerCommand { client.write_packet(ServerboundPlayerCommand {
id: client.component::<MinecraftEntityId>(), id: client.component::<MinecraftEntityId>(),
action: if sneaking { action: if sneaking {
Action::PressShiftKey Action::PressShiftKey
@ -223,9 +218,7 @@ pub fn set_sneaking(_lua: &Lua, client: &Client, sneaking: bool) -> Result<()> {
Action::ReleaseShiftKey Action::ReleaseShiftKey
}, },
data: 0, data: 0,
}) { });
error!("failed to send PlayerCommand packet: {error:?}");
}
Ok(()) Ok(())
} }
@ -244,13 +237,11 @@ pub fn stop_pathfinding(_lua: &Lua, client: &Client, (): ()) -> Result<()> {
} }
pub fn stop_sleeping(_lua: &Lua, client: &Client, (): ()) -> Result<()> { pub fn stop_sleeping(_lua: &Lua, client: &Client, (): ()) -> Result<()> {
if let Err(error) = client.write_packet(ServerboundPlayerCommand { client.write_packet(ServerboundPlayerCommand {
id: client.component::<MinecraftEntityId>(), id: client.component::<MinecraftEntityId>(),
action: Action::StopSleeping, action: Action::StopSleeping,
data: 0, data: 0,
}) { });
error!("failed to send PlayerCommand packet: {error:?}");
}
Ok(()) Ok(())
} }

@ -1,7 +1,7 @@
use azalea::{ use azalea::{
ClientInformation, ClientInformation,
entity::metadata::{AirSupply, Score}, entity::metadata::{AirSupply, Score},
pathfinder::PathfinderDebugParticles, pathfinder::debug::PathfinderDebugParticles,
protocol::common::client_information::ModelCustomization, protocol::common::client_information::ModelCustomization,
}; };
use mlua::{Error, Lua, Result, Table, UserDataRef}; use mlua::{Error, Lua, Result, Table, UserDataRef};
@ -40,21 +40,22 @@ pub async fn set_client_information(
allows_listing: info.get("allows_listing")?, allows_listing: info.get("allows_listing")?,
model_customization: info model_customization: info
.get::<Table>("model_customization") .get::<Table>("model_customization")
.as_ref()
.map(|t| ModelCustomization { .map(|t| ModelCustomization {
cape: get_bool(&t, "cape"), cape: get_bool(t, "cape"),
jacket: get_bool(&t, "jacket"), jacket: get_bool(t, "jacket"),
left_sleeve: get_bool(&t, "left_sleeve"), left_sleeve: get_bool(t, "left_sleeve"),
right_sleeve: get_bool(&t, "right_sleeve"), right_sleeve: get_bool(t, "right_sleeve"),
left_pants: get_bool(&t, "left_pants"), left_pants: get_bool(t, "left_pants"),
right_pants: get_bool(&t, "right_pants"), right_pants: get_bool(t, "right_pants"),
hat: get_bool(&t, "hat"), hat: get_bool(t, "hat"),
}) })
.unwrap_or_default(), .unwrap_or_default(),
view_distance: info.get("view_distance").unwrap_or(8), view_distance: info.get("view_distance").unwrap_or(8),
..ClientInformation::default() ..ClientInformation::default()
}) })
.await .await;
.map_err(Error::external) Ok(())
} }
pub fn set_component( pub fn set_component(

@ -28,7 +28,10 @@ pub fn blocks(
nearest_to.z as i32, nearest_to.z as i32,
), ),
&BlockStates { &BlockStates {
set: block_states.iter().map(|&id| BlockState { id }).collect(), set: block_states
.into_iter()
.flat_map(BlockState::try_from)
.collect(),
}, },
) )
.map(Vec3::from) .map(Vec3::from)

@ -3,16 +3,19 @@ mod queries;
pub mod find; pub mod find;
use azalea::{BlockPos, auto_tool::AutoToolClientExt, blocks::BlockState, world::InstanceName}; use azalea::{BlockPos, auto_tool::AutoToolClientExt, blocks::BlockState, world::InstanceName};
use mlua::{Lua, Result, Table}; use mlua::{Lua, Result, Table, Value};
use super::{Client, Direction, Vec3}; use super::{Client, Direction, Vec3};
pub fn best_tool_for_block(lua: &Lua, client: &Client, block_state: u16) -> Result<Table> { pub fn best_tool_for_block(lua: &Lua, client: &Client, block_state: u16) -> Result<Value> {
let result = client.best_tool_in_hotbar_for_block(BlockState { id: block_state }); let Ok(block) = BlockState::try_from(block_state) else {
return Ok(Value::Nil);
};
let result = client.best_tool_in_hotbar_for_block(block);
let table = lua.create_table()?; let table = lua.create_table()?;
table.set("index", result.index)?; table.set("index", result.index)?;
table.set("percentage_per_tick", result.percentage_per_tick)?; table.set("percentage_per_tick", result.percentage_per_tick)?;
Ok(table) Ok(Value::Table(table))
} }
pub fn dimension(_lua: &Lua, client: &Client) -> Result<String> { pub fn dimension(_lua: &Lua, client: &Client) -> Result<String> {
@ -29,7 +32,7 @@ pub fn get_block_state(_lua: &Lua, client: &Client, position: Vec3) -> Result<Op
position.y as i32, position.y as i32,
position.z as i32, position.z as i32,
)) ))
.map(|block| block.id)) .map(|block| block.id()))
} }
#[allow(clippy::cast_possible_truncation)] #[allow(clippy::cast_possible_truncation)]

@ -3,8 +3,9 @@ macro_rules! crypt {
($op:ident, $options:expr, $text:expr) => {{ ($op:ident, $options:expr, $text:expr) => {{
macro_rules! crypt_with { macro_rules! crypt_with {
($algo:ident) => {{ ($algo:ident) => {{
let encoding = $options.get("encoding").unwrap_or_default();
let key = &$options.get::<UserDataRef<AesKey>>("key")?.0; let key = &$options.get::<UserDataRef<AesKey>>("key")?.0;
match $options.get("encoding").unwrap_or_default() { match encoding {
1 => $algo::<Base64Encoding>::$op($text, &key), 1 => $algo::<Base64Encoding>::$op($text, &key),
2 => $algo::<Base64rEncoding>::$op($text, &key), 2 => $algo::<Base64rEncoding>::$op($text, &key),
_ => $algo::<NewBase64rEncoding>::$op($text, &key), _ => $algo::<NewBase64rEncoding>::$op($text, &key),

@ -22,7 +22,7 @@ use std::{
sync::Arc, sync::Arc,
}; };
use anyhow::Context; use anyhow::{Context, Result};
use arguments::Arguments; use arguments::Arguments;
use azalea::{ use azalea::{
DefaultBotPlugins, DefaultPlugins, brigadier::prelude::CommandDispatcher, prelude::*, DefaultBotPlugins, DefaultPlugins, brigadier::prelude::CommandDispatcher, prelude::*,
@ -55,7 +55,7 @@ struct State {
} }
#[tokio::main] #[tokio::main]
async fn main() -> anyhow::Result<()> { async fn main() -> Result<()> {
#[cfg(feature = "console-subscriber")] #[cfg(feature = "console-subscriber")]
console_subscriber::init(); console_subscriber::init();
@ -131,8 +131,7 @@ async fn main() -> anyhow::Result<()> {
} else { } else {
Account::offline(&username) Account::offline(&username)
}; };
let Err(err) = ClientBuilder::new_without_plugins()
let Err(error) = ClientBuilder::new_without_plugins()
.add_plugins(DefaultBotPlugins) .add_plugins(DefaultBotPlugins)
.add_plugins(HacksPlugin) .add_plugins(HacksPlugin)
.add_plugins(default_plugins) .add_plugins(default_plugins)
@ -145,7 +144,7 @@ async fn main() -> anyhow::Result<()> {
}) })
.start(account, server) .start(account, server)
.await; .await;
eprintln!("{error}"); eprintln!("{err}");
Ok(()) Ok(())
} }

@ -3,17 +3,15 @@
use std::sync::Arc; use std::sync::Arc;
use azalea::{ use azalea::{
ecs::{event::EventReader, system::Query}, ecs::event::EventReader,
packet::{ packet::{
config::ReceiveConfigPacketEvent, config::ReceiveConfigPacketEvent, game::ReceiveGamePacketEvent,
game::emit_receive_packet_events, login::ReceiveLoginPacketEvent,
login::{LoginPacketEvent, process_packet_events},
}, },
protocol::packets::login::ClientboundLoginPacket, protocol::packets::login::ClientboundLoginPacket,
raw_connection::RawConnection,
}; };
use bevy_app::{App, First, Plugin}; use bevy_app::{App, First, Plugin};
use bevy_ecs::{schedule::IntoSystemConfigs, system::ResMut}; use bevy_ecs::system::ResMut;
use log::error; use log::error;
use parking_lot::Mutex; use parking_lot::Mutex;
@ -28,19 +26,16 @@ impl Plugin for RecordPlugin {
let recorder = self.recorder.lock().take(); let recorder = self.recorder.lock().take();
if let Some(recorder) = recorder { if let Some(recorder) = recorder {
app.insert_resource(recorder) app.insert_resource(recorder)
.add_systems(First, record_login_packets.before(process_packet_events)) .add_systems(First, record_login_packets)
.add_systems(First, record_configuration_packets) .add_systems(First, record_configuration_packets)
.add_systems( .add_systems(First, record_game_packets);
First,
record_game_packets.before(emit_receive_packet_events),
);
} }
} }
} }
fn record_login_packets( fn record_login_packets(
recorder: Option<ResMut<Recorder>>, recorder: Option<ResMut<Recorder>>,
mut events: EventReader<LoginPacketEvent>, mut events: EventReader<ReceiveLoginPacketEvent>,
) { ) {
if let Some(mut recorder) = recorder { if let Some(mut recorder) = recorder {
for event in events.read() { for event in events.read() {
@ -63,20 +58,20 @@ fn record_configuration_packets(
) { ) {
if let Some(mut recorder) = recorder { if let Some(mut recorder) = recorder {
for event in events.read() { for event in events.read() {
if let Err(error) = recorder.save_packet(&event.packet) { if let Err(error) = recorder.save_packet(event.packet.as_ref()) {
error!("failed to record configuration packet: {error:?}"); error!("failed to record configuration packet: {error:?}");
} }
} }
} }
} }
fn record_game_packets(recorder: Option<ResMut<Recorder>>, query: Query<&RawConnection>) { fn record_game_packets(
if let Some(mut recorder) = recorder recorder: Option<ResMut<Recorder>>,
&& let Ok(raw_conn) = query.get_single() mut events: EventReader<ReceiveGamePacketEvent>,
{ ) {
let queue = raw_conn.incoming_packet_queue(); if let Some(mut recorder) = recorder {
for raw_packet in queue.lock().iter() { for event in events.read() {
if let Err(error) = recorder.save_raw_packet(raw_packet) { if let Err(error) = recorder.save_packet(event.packet.as_ref()) {
error!("failed to record game packet: {error:?}"); error!("failed to record game packet: {error:?}");
} }
} }