mirror of
https://github.com/azalea-rs/azalea-hax.git
synced 2025-08-02 14:26:05 +00:00
Initial commit
This commit is contained in:
commit
933676b7a3
5 changed files with 2913 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
2814
Cargo.lock
generated
Normal file
2814
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "azalea-hax"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
azalea = { git = "https://github.com/mat-1/azalea" }
|
||||
# azalea = { path = "../azalea/azalea" }
|
7
README.md
Normal file
7
README.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
# Azalea Hax
|
||||
|
||||
An [Azalea](https://github.com/azalea-rs/azalea) plugin with useful features that will probably trigger anticheats.
|
||||
|
||||
## Features
|
||||
|
||||
- Anti-knockback
|
81
src/lib.rs
Normal file
81
src/lib.rs
Normal file
|
@ -0,0 +1,81 @@
|
|||
use azalea::{
|
||||
app::{App, Plugin, PreUpdate},
|
||||
ecs::prelude::*,
|
||||
entity::indexing::EntityIdIndex,
|
||||
packet_handling::game::PacketEvent,
|
||||
prelude::*,
|
||||
protocol::packets::game::ClientboundGamePacket,
|
||||
world::MinecraftEntityId,
|
||||
};
|
||||
|
||||
pub struct HaxPlugin;
|
||||
impl Plugin for HaxPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(
|
||||
PreUpdate,
|
||||
anti_knockback
|
||||
.before(azalea::packet_handling::game::process_packet_events)
|
||||
.after(azalea::packet_handling::game::send_packet_events),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub trait HaxClientExt {
|
||||
fn has_anti_knockback(&self) -> bool;
|
||||
/// Enable or disable anti-knockback for this client. If enabled, then the server won't be able
|
||||
/// to change this client's velocity.
|
||||
fn set_anti_knockback(&self, value: bool);
|
||||
}
|
||||
|
||||
impl HaxClientExt for azalea::Client {
|
||||
fn has_anti_knockback(&self) -> bool {
|
||||
self.get_component::<AntiKnockback>().is_some()
|
||||
}
|
||||
|
||||
fn set_anti_knockback(&self, enabled: bool) {
|
||||
let mut ecs = self.ecs.lock();
|
||||
let mut entity_mut = ecs.entity_mut(self.entity);
|
||||
if enabled {
|
||||
entity_mut.insert(AntiKnockback);
|
||||
} else {
|
||||
entity_mut.remove::<AntiKnockback>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The component that controls whether we have anti-knockback or not.
|
||||
#[derive(Component, Clone)]
|
||||
pub struct AntiKnockback;
|
||||
|
||||
fn anti_knockback(
|
||||
events: ResMut<Events<PacketEvent>>,
|
||||
player_query: Query<&EntityIdIndex>,
|
||||
entity_query: Query<(), With<AntiKnockback>>,
|
||||
) {
|
||||
// bevy please merge this https://github.com/bevyengine/bevy/pull/8051
|
||||
// :pleading:
|
||||
#[allow(invalid_reference_casting)]
|
||||
for event in events
|
||||
.iter_current_update_events()
|
||||
// you didn't see anything
|
||||
.map(|e| unsafe { &mut *(e as *const PacketEvent as *mut PacketEvent) })
|
||||
{
|
||||
if let ClientboundGamePacket::SetEntityMotion(p) = &mut event.packet {
|
||||
let Ok(entity_id_index) = player_query.get(event.entity) else {
|
||||
continue;
|
||||
};
|
||||
let Some(ecs_entity) = entity_id_index.get(&MinecraftEntityId(p.id)) else {
|
||||
continue;
|
||||
};
|
||||
// only apply if the entity has the AntiKnockback component
|
||||
if entity_query.get(ecs_entity).is_ok() {
|
||||
(p.xa, p.ya, p.za) = (0, 0, 0);
|
||||
}
|
||||
} else if let ClientboundGamePacket::Explode(p) = &mut event.packet {
|
||||
// only apply if the entity has the AntiKnockback component
|
||||
if entity_query.get(event.entity).is_ok() {
|
||||
(p.knockback_x, p.knockback_y, p.knockback_z) = (0., 0., 0.);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue