Replace repository content with Codeberg version

This commit is contained in:
nitrogenoliquido committed 2026-11-08 10:50:20 -05:00
1 parent 9c1430df6e
commit fd9c5922da
621 files changed
+197975 -130605

No files matched your search

+504
View File
@@ -0,0 +1,504 @@
// Aim Assist - turn your view towards the nearest suitable player.
//
// Every tick the module picks a target (a player in range, inside the "fov", not a friend,
// sorted by "sort_by") and a point on it, moved around a little with smooth noise so the
// aim does not sit on one spot. Every frame it turns the view a step towards that point.
// mode 0: smooth turn mode 1: turn at most a fixed speed
// mode 2: instant (yaw only, unless "lock_on_vertical") mode 3: silent (only the server sees it)
//
// Callbacks:
// aim_assist_disable module switched off: forget the target
// aim_assist_on_rotation_update rotation hook: tell the engine we control the rotation
// aim_assist_tick every tick: choose / keep the target and its aim point
// aim_assist_frame every frame: turn towards the aim point
// aim_assist_apply_frame_rotation helper: one frame of turning (deadzone, speed, randomness)
// aim_assist_test_entity_updating helper: check one player, and keep it if it is the best so far
#include "slinky/engine.h"
#include "slinky/jids.h"
struct Vec3 { double x, y, z; };
struct Rot { float yaw, pitch; };
struct Box { Vec3 lo, hi; };
struct Range { float lo, hi; };
struct FrameEvt {
char padding_00[8];
Ctx *ctx; // +0x08 game context
float partial; // +0x10 how far we are between two ticks (0..1)
int padding_14;
double dt; // +0x18 seconds since the last frame
};
struct EvHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
void *ev; // +0x10 module descriptor that was toggled
unsigned char on; // +0x18 1 = switched on
};
// ---- settings ----
extern "C" int aim_assist_mode; // see above (0..3)
extern "C" unsigned char aim_assist_lock_on_vertical; // mode 2: turn the pitch too
extern "C" unsigned char aim_assist_require_mouse_moved; // never turn faster than the mouse moves
extern "C" unsigned char aim_assist_silent_ignore_manual_aim; // mode 3
extern "C" unsigned char aim_assist_silent_move_correct_value; // mode 3: move in the direction the server sees
extern "C" unsigned char aim_assist_require_sprint;
extern "C" unsigned char aim_assist_require_mouse_pressed;
extern "C" unsigned char aim_assist_disable_on_block_break; // not while mining
extern "C" unsigned char aim_assist_require_weapon;
extern "C" int aim_assist_mode_target; // 0 = keep the target while valid, else re-pick every tick
extern "C" unsigned char aim_assist_ignore_invisible;
extern "C" unsigned char aim_assist_allow_exceeding_fov; // keep aiming at a kept target that left the fov
extern "C" unsigned char aim_assist_require_line_sight;
extern "C" int aim_assist_sort_by_distance_health_hurt; // "sort_by": 0 distance, 1 health, 2 hurt time, 3 fov
extern "C" float aim_assist_deadzone; // degrees close enough not to turn
extern "C" float aim_assist_fov; // degrees
extern "C" float aim_assist_horizontal_vertical_speed, aim_assist_horizontal_vertical_speed_second; // horizontal / vertical speed
extern "C" float aim_assist_near_distance; // don't aim at targets closer than this
extern "C" float aim_assist_range;
extern "C" float aim_assist_predict; // 0..1: aim between the shown and the server position
extern "C" float aim_assist_horizontal_vertical_hitbox_correction, aim_assist_horizontal_vertical_hitbox_correction_second; // aim at the near side of the hitbox (h / v)
extern "C" float aim_assist_aim_randomisation; // size of the aim point noise
// ---- module state ----
extern "C" char aim_assist_module_descriptor[];
extern "C" unsigned char aim_assist_has_target; // there is a target to aim at
extern "C" void *aim_assist_cached_target_ref; // the current target (JNI global ref)
extern "C" unsigned char aim_assist_aiming; // we control the rotation (until handed back)
extern "C" Vec3 aim_assist_previous_current_aim_point; // aim point last tick
extern "C" Vec3 aim_assist_previous_current_aim_point_second; // aim point this tick
extern "C" Rot aim_assist_mouse_movement_since_last_tick; // how far the player moved the mouse (yaw, pitch)
extern "C" int aim_assist_clicks_wait_before_aiming;
extern "C" unsigned long long aim_assist_tie_break_counter;
extern "C" char aim_assist_rng_states[], aim_assist_rng_states_second[], aim_assist_rng_states_third[], aim_assist_rng_states_fourth[], aim_assist_rng_states_fifth[]; // random walk states
// ---- game / engine functions ----
FN(unsigned char, update_rotation_priority_peak, (int ms)); // may this module control the rotation?
FN(unsigned char, is_silent_rotation_active, ());
FN(Rot, get_render_rotation, ()); // where the player really looks
FN(Rot, get_silent_rotation_offset, ());
FN(Rot, get_entity_rotation, (void *jvm, void *entity));
FN(Rot, rot_add, (Rot a, Rot b));
FN(Rot, rot_sub, (Rot a, Rot b));
FN(Rot, rot_scale, (Rot rotation, float k));
FN(float, rot_length, (Rot rotation));
FN(float, wrap_angle, (float deg)); // to -180..180
FN(void, apply_silent_rotation, (Rot rotation)); // turn by this much
FN(Vec3, java_get_entity_pos_x, (void *jvm, void *entity));
FN(Vec3, java_get_entity_prev_pos_x, (void *jvm, void *entity));
FN(unsigned char, java_variant, (void *jvm));
FN(Vec3, vec3_add_eye_height, (Vec3 v));
FN(Vec3, vec3_sub, (Vec3 a, Vec3 b));
FN(Vec3, vec3_add, (Vec3 a, Vec3 b));
FN(Vec3, vec3_scale, (Vec3 v, double k));
FN(Vec3, vec3_lerp, (Vec3 a, Vec3 b, double t));
FN(Rot, rot_look_at, (Vec3 from, Vec3 to));
FN(Range, rot_make_floats, (float lo, float hi));
FN(float, walk_update, (void *state, Range r, double d)); // next value of a random walk
FN(float, limit_rotation_delta, (float lo, float hi, float v)); // clamp
FN(unsigned char, random_chance, (float chance));
FN(unsigned char, java_call_entity_is_sprinting, (void *jvm, void *entity));
FN(unsigned char, vertex_pointer_current, (Ctx *ctx)); // a mouse button is held
FN(void *, java_get_minecraft_object_mouse_over, (void *jvm, void *minecraft));
FN(int, java_get_moving_object_position_type_ordinal, (void *jvm, void *hit)); // 1 = a block
FN(unsigned char, is_holding_accepted_weapon, (void *jvm, void *object));
FN(void *, java_get_world_player_entities, (void *jvm, void *world));
FN(int, java_call_list_size, (void *jvm, void *list));
FN(void *, java_call_list_get, (void *jvm, void *list, int i));
FN(unsigned char, java_get_entity_is_dead, (void *jvm, void *entity));
FN(unsigned char, java_get_entity_player_sleeping, (void *jvm, void *entity_player));
FN(unsigned char, java_call_entity_player_is_invisible_to_player, (void *jvm, void *entity_player, void *viewer));
FN(unsigned char, entity_flags_has, (void *jvm, void *entity, int checks)); // 7: friend, teammate or bot
FN(Vec3, java_get_entity_other_player_mp_other_player_mpx, (void *jvm, void *entity_other_player_mp)); // server position
FN(void *, java_get_entity_bounding_box, (void *jvm, void *entity));
FN(Box, java_get_axis_aligned_bb_min_x, (void *jvm, void *bounding_box));
FN(Box, aabb_expand, (Box b, double grow));
FN(Vec3, aabb_clamp_point, (Box b, Vec3 p)); // closest point of the box
FN(double, vec3_distance, (Vec3 a, Vec3 b));
FN(double, lerp_double, (double a, double b, double t));
FN(float, noise_1d, (float x)); // smooth noise, -1..1
FN(float, java_call_entity_living_base_get_health, (void *jvm, void *entity_living_base));
FN(int, java_get_entity_living_base_hurt_time, (void *jvm, void *entity_living_base));
FN(unsigned char, set_vertex_pointer, (void *jvm, void *world, Vec3 from, Vec3 to)); // clear line of sight
FN(int, java_get_entity_entity_id, (void *jvm, void *entity));
static const float BIGGEST_FLOAT = 3.40282347e+38f;
static Rot wrap(Rot rotation) {
rotation.yaw = wrap_angle(rotation.yaw);
return rotation;
}
static void delete_global_ref(void *jvm, void *ref) {
JNIEnv *env = ((Jvm *)jvm)->env;
(*env)->DeleteGlobalRef(env, ref);
}
// On disable: forget the target.
extern "C" void aim_assist_disable(EvHook *hook) {
if (hook->ev != aim_assist_module_descriptor || hook->on)
return;
void *ref = aim_assist_cached_target_ref;
if (ref)
delete_global_ref(hook->ctx->jvm, ref);
aim_assist_cached_target_ref = nullptr;
aim_assist_has_target = 0;
}
extern "C" void aim_assist_on_rotation_update(char *h) {
if (aim_assist_aiming == 1) {
h[8] = 1; // we control the yaw
if (aim_assist_silent_move_correct_value == 1)
h[9] = 1;
}
}
// Check one player as a target. If it is better than the best so far (by the "sort_by" score),
// update the scores and write its aim point; returns 1. `sticky`: it is the kept target.
// *should_aim_out: 0 when the target is closer than "near_distance" (no need to aim).
extern "C" unsigned char aim_assist_test_entity_updating(Ctx *c, void *e, Vec3 *eye, Rot rot, unsigned char sticky, double *range,
float *best_hp, int *best_hurt, unsigned *best_tie, float *fov,
Vec3 *aim_out, unsigned char *should_aim_out) {
if (java_get_entity_is_dead(c->jvm, e) || java_get_entity_player_sleeping(c->jvm, e))
return 0;
if (aim_assist_ignore_invisible == 1 && java_call_entity_player_is_invisible_to_player(c->jvm, e, c->player))
return 0;
if (entity_flags_has(c->jvm, e, 7))
return 0;
// Distance to the nearest point of its hitbox (grown by 0.1).
Vec3 pos = java_get_entity_pos_x(c->jvm, e);
if (aim_assist_predict > 0.0f)
pos = vec3_lerp(pos, java_get_entity_other_player_mp_other_player_mpx(c->jvm, e), aim_assist_predict);
Box hitbox = aabb_expand(java_get_axis_aligned_bb_min_x(c->jvm, java_get_entity_bounding_box(c->jvm, e)), (double)0.1f);
Vec3 nearest = aabb_clamp_point(hitbox, *eye);
double distance = vec3_distance(*eye, nearest);
unsigned char should_aim = !((double)aim_assist_near_distance > distance);
if (distance > *range)
return 0;
// Aim point: its eyes, pulled towards the nearest hitbox point by the hitbox correction
// (less correction closer than 3.5 blocks).
Vec3 head = vec3_add_eye_height(pos);
double aim_x, aim_z;
float correction = aim_assist_horizontal_vertical_hitbox_correction;
if (correction > 0.0f) {
if (3.5 > distance)
correction = (float)(correction * (distance / 3.5));
Vec3 pulled = vec3_lerp(head, nearest, correction);
aim_x = pulled.x;
aim_z = pulled.z;
} else {
aim_x = head.x;
aim_z = head.z;
}
double aim_y = lerp_double(head.y, nearest.y, aim_assist_horizontal_vertical_hitbox_correction_second);
// Move it around with smooth noise (seeded by the positions, so it drifts as things move).
float seed = (float)((eye->x + eye->y + eye->z + aim_x + aim_y + aim_z) * 0.1);
float seed_2 = 10000.0f + seed, seed_3 = 20000.0f + seed;
float noise_x = noise_1d(seed), noise_y = noise_1d(seed_2);
double noise_z = (double)noise_1d(seed_3) * 0.5;
float randomness = aim_assist_aim_randomisation;
if (3.5 > distance)
randomness = (float)(randomness * (distance / 3.5 * 0.9 + 0.1));
Vec3 jitter = vec3_scale(Vec3{(double)noise_x * 0.5, (double)noise_y * 0.5, noise_z}, randomness);
Vec3 aim = vec3_add(Vec3{aim_x, aim_y, aim_z}, jitter);
// How far off our view it is (yaw).
float off_angle = __builtin_fabsf(wrap_angle(rot_sub(rot_look_at(*eye, aim), rot).yaw));
if (off_angle > *fov) {
if (!sticky)
return 0;
should_aim = aim_assist_allow_exceeding_fov;
}
float health = java_call_entity_living_base_get_health(c->jvm, e);
if (health > *best_hp)
return 0;
int hurt = java_get_entity_living_base_hurt_time(c->jvm, e);
if (hurt > *best_hurt)
return 0;
if (aim_assist_require_line_sight == 1 && !set_vertex_pointer(c->jvm, c->world, *eye, aim))
return 0;
// Better than the best so far: store its score.
if (!aim_assist_mode_target) {
*fov = off_angle;
} else {
switch (aim_assist_sort_by_distance_health_hurt) {
case 0:
*range = distance;
break;
case 1:
*best_hp = health;
break;
case 2: {
// Same hurt time: break the tie with a hash of the id.
unsigned hash = java_get_entity_entity_id(c->jvm, e) + (unsigned)aim_assist_tie_break_counter;
hash = (hash >> 16 ^ hash) * 0x45d9f3b;
hash = (hash >> 16 ^ hash) * 0x45d9f3b;
hash = hash >> 16 ^ hash;
aim_assist_tie_break_counter += 1;
if (hurt == *best_hurt && hash < *best_tie)
return 0;
*best_hurt = hurt;
*best_tie = hash;
break;
}
case 3:
*fov = off_angle;
break;
}
}
*aim_out = aim;
*should_aim_out = should_aim;
return 1;
}
// One frame of turning by (at most) `diff`, `dt` seconds long.
extern "C" void aim_assist_apply_frame_rotation(Rot diff, float dt) {
float yaw = diff.yaw, pitch = diff.pitch;
// Deadzone: close enough does not need turning.
const float deadzone = aim_assist_deadzone;
if (yaw > 0.0f) {
yaw -= deadzone;
yaw = yaw > 0.0f ? yaw : 0.0f;
} else {
yaw += deadzone;
yaw = yaw < 0.0f ? yaw : 0.0f;
}
if (pitch > 0.0f) {
pitch -= deadzone;
pitch = pitch > 0.0f ? pitch : 0.0f;
} else {
pitch += deadzone;
pitch = pitch < 0.0f ? pitch : 0.0f;
}
if (aim_assist_mode == 2) {
// Instant.
if (!aim_assist_lock_on_vertical)
pitch = 0.0f;
} else {
// The pitch follows less while the yaw is still far off (fully off at 40-120 degrees).
float full_off_at = walk_update(aim_assist_rng_states, rot_make_floats(40.0f, 120.0f), 5.0);
float pitch_factor = (float)(-1.0 / (double)full_off_at * (double)__builtin_fabsf(yaw) + 1.0);
pitch *= pitch_factor > 0.0f ? pitch_factor : 0.0f;
float speed_h = aim_assist_horizontal_vertical_speed, speed_v = aim_assist_horizontal_vertical_speed_second;
if (aim_assist_mode == 3) {
// Silent: at least 5.
speed_h = 5.0f > speed_h ? 5.0f : speed_h;
speed_v = 5.0f > speed_v ? 5.0f : speed_v;
}
speed_h *= 0.5f;
speed_v *= 0.5f;
// Speeds squared, randomly +-10%, and a slow +-5% drift.
float rate_yaw = walk_update(aim_assist_rng_states_third, rot_make_floats(0.9f, 1.1f), 1.0) * (speed_h * speed_h);
float rate_pitch = walk_update(aim_assist_rng_states_fourth, rot_make_floats(0.9f, 1.1f), 1.0) * (speed_v * speed_v);
float drift = walk_update(aim_assist_rng_states_fifth, Range{0.95f, 1.05f}, 60.0);
if (aim_assist_mode == 1) {
// At most rate * 5 degrees per second.
float max_yaw = rate_yaw * 5.0f * drift * dt;
yaw = limit_rotation_delta(-max_yaw, max_yaw, yaw);
float max_pitch = rate_pitch * 5.0f * drift * dt;
pitch = limit_rotation_delta(-max_pitch, max_pitch, pitch);
} else {
// A fraction of the remaining angle (never overshooting).
Rot step = rot_scale(rot_scale(Rot{rate_yaw * yaw, rate_pitch * pitch}, drift), dt);
if (!(__builtin_fabsf(step.yaw) > __builtin_fabsf(yaw)))
yaw = step.yaw;
if (!(__builtin_fabsf(step.pitch) > __builtin_fabsf(pitch)))
pitch = step.pitch;
}
// A little vertical wobble while turning sideways.
if (aim_assist_mode != 2) {
float wobble = (float)((double)__builtin_fabsf(yaw) * 0.1);
pitch += walk_update(aim_assist_rng_states_second, rot_make_floats(-wobble, wobble), 1.0);
}
}
if (aim_assist_require_mouse_moved == 1) {
// Never turn more than the player moved the mouse since last tick.
float abs_yaw = __builtin_fabsf(yaw), abs_pitch = __builtin_fabsf(pitch);
float mouse_yaw = __builtin_fabsf(aim_assist_mouse_movement_since_last_tick.yaw);
float mouse_pitch = __builtin_fabsf(aim_assist_mouse_movement_since_last_tick.pitch);
bool cut_yaw = mouse_yaw < abs_yaw && yaw != 0.0f;
float cut_yaw_value = mouse_yaw / abs_yaw * yaw;
if (mouse_pitch < abs_pitch && pitch != 0.0f)
pitch *= mouse_pitch / abs_pitch;
aim_assist_mouse_movement_since_last_tick.yaw = 0.0f;
aim_assist_mouse_movement_since_last_tick.pitch = 0.0f;
if (cut_yaw)
yaw = cut_yaw_value;
}
apply_silent_rotation(Rot{yaw, pitch});
}
// Every frame: turn towards the aim point (or, without a target, back to the real view).
extern "C" void aim_assist_frame(FrameEvt *h) {
Ctx *ctx = h->ctx;
if (ctx->in_game != 1)
return;
if (!aim_assist_has_target) {
if (aim_assist_aiming != 1)
return;
// No target any more: hand the rotation back by turning to where the player looks.
if (!is_silent_rotation_active() || !update_rotation_priority_peak(100)) {
aim_assist_aiming = 0;
return;
}
Rot current = rot_add(get_entity_rotation(ctx->jvm, ctx->player), get_silent_rotation_offset());
Rot back = wrap(rot_sub(get_render_rotation(), current));
if (10.0f > rot_length(back))
aim_assist_aiming = 0; // close enough: done after this frame
aim_assist_apply_frame_rotation(back, (float)h->dt);
return;
}
if (!update_rotation_priority_peak(100))
return;
if (!aim_assist_aiming && aim_assist_mode == 3)
aim_assist_aiming = 1;
if (aim_assist_aiming && !is_silent_rotation_active())
return;
// Our eye position this frame, and the aim point between last tick's and this tick's.
float partial = h->partial;
Vec3 prev = java_get_entity_prev_pos_x(ctx->jvm, ctx->player);
Vec3 pos = java_get_entity_pos_x(ctx->jvm, ctx->player);
Vec3 eye = vec3_add(prev, vec3_scale(vec3_sub(pos, prev), partial));
if (!java_variant(ctx->jvm))
eye = vec3_add_eye_height(eye);
Vec3 aim = vec3_lerp(aim_assist_previous_current_aim_point, aim_assist_previous_current_aim_point_second, h->partial);
Rot want = rot_look_at(eye, aim);
Rot current = rot_add(get_entity_rotation(ctx->jvm, ctx->player), get_silent_rotation_offset());
Rot diff = wrap(rot_sub(want, current));
if (aim_assist_mode == 3 && !aim_assist_silent_ignore_manual_aim) {
// Silent: if the player is aiming at it themselves (closer than we are), follow them.
Rot back = wrap(rot_sub(get_render_rotation(), current));
Rot from_player = wrap(rot_sub(want, get_render_rotation()));
if (10.0f > rot_length(back) && rot_length(diff) > rot_length(from_player)) {
apply_silent_rotation(back);
return;
}
}
aim_assist_apply_frame_rotation(diff, (float)h->dt);
}
// Forget the target.
static void clear_target(Ctx *ctx) {
if (aim_assist_cached_target_ref)
delete_global_ref(ctx->jvm, aim_assist_cached_target_ref);
aim_assist_cached_target_ref = nullptr;
aim_assist_has_target = 0;
}
// Should we aim at all this tick? Clears or pauses the target when not.
static bool conditions_ok(Ctx *ctx) {
if (ctx->in_game != 1) {
clear_target(ctx);
return false;
}
if (aim_assist_require_sprint == 1 && aim_assist_mode != 3 && !java_call_entity_is_sprinting(ctx->jvm, ctx->player)) {
aim_assist_has_target = 0; // pause, keep the target
return false;
}
unsigned char mouse_pressed = vertex_pointer_current(ctx);
if (aim_assist_require_mouse_pressed == 1) {
if (!mouse_pressed) {
// Start aiming only after 1-2 clicks next time.
aim_assist_clicks_wait_before_aiming = random_chance(0.5f) + 1;
clear_target(ctx);
return false;
}
if ((unsigned)aim_assist_mode < 2 && aim_assist_clicks_wait_before_aiming) {
aim_assist_clicks_wait_before_aiming -= 1;
clear_target(ctx);
return false;
}
}
if ((mouse_pressed & aim_assist_disable_on_block_break) == 1) {
void *hit = java_get_minecraft_object_mouse_over(ctx->jvm, ctx->minecraft);
if (hit && java_get_moving_object_position_type_ordinal(ctx->jvm, hit) == 1) {
aim_assist_has_target = 0; // mining a block: pause
return false;
}
}
if (aim_assist_require_weapon == 1 && !is_holding_accepted_weapon(ctx->jvm, ctx->player)) {
clear_target(ctx);
return false;
}
return true;
}
// Every tick: choose (or keep) the target and its aim point.
extern "C" void aim_assist_tick(Hook *hook) {
aim_assist_mouse_movement_since_last_tick = Rot{0.0f, 0.0f};
Ctx *ctx = hook->ctx;
if (!conditions_ok(ctx))
return;
Vec3 eye = java_get_entity_pos_x(ctx->jvm, ctx->player);
if (!java_variant(ctx->jvm))
eye = vec3_add_eye_height(eye);
Rot view = is_silent_rotation_active() ? get_render_rotation() : get_entity_rotation(ctx->jvm, ctx->player);
Vec3 aim;
// Keep the current target while it stays valid ("mode_target" 0).
if (!aim_assist_mode_target && aim_assist_cached_target_ref) {
double range = aim_assist_range;
float fov = aim_assist_fov, best_hp = BIGGEST_FLOAT;
int best_hurt = 0x7fffffff;
unsigned best_tie = 0;
if (aim_assist_test_entity_updating(ctx, aim_assist_cached_target_ref, &eye, view, 1, &range, &best_hp, &best_hurt, &best_tie, &fov, &aim, &aim_assist_has_target)) {
aim_assist_previous_current_aim_point = aim_assist_previous_current_aim_point_second;
aim_assist_previous_current_aim_point_second = aim;
return;
}
delete_global_ref(ctx->jvm, aim_assist_cached_target_ref);
aim_assist_cached_target_ref = nullptr;
aim_assist_has_target = 0;
}
// Find the best player.
double range = aim_assist_range;
float fov = aim_assist_fov, best_hp = BIGGEST_FLOAT;
int best_hurt = 0x7fffffff;
unsigned best_tie = 0;
unsigned char should_aim;
void *best = nullptr;
void *players = java_get_world_player_entities(ctx->jvm, ctx->world);
for (int i = 0; i < java_call_list_size(ctx->jvm, players); i++) {
void *other = java_call_list_get(ctx->jvm, players, i);
JNIEnv *env = ((Jvm *)ctx->jvm)->env;
if ((*env)->IsSameObject(env, ctx->player, other))
continue; // ourselves
if (aim_assist_test_entity_updating(ctx, other, &eye, view, 0, &range, &best_hp, &best_hurt, &best_tie, &fov, &aim, &should_aim))
best = other;
}
if (!best) {
clear_target(ctx);
return;
}
// Same target as before: move the aim point on; a new one: jump to its point.
JNIEnv *env = ((Jvm *)ctx->jvm)->env;
if ((*env)->IsSameObject(env, aim_assist_cached_target_ref, best)) {
aim_assist_previous_current_aim_point = aim_assist_previous_current_aim_point_second;
aim_assist_previous_current_aim_point_second = aim;
} else {
aim_assist_previous_current_aim_point_second = aim;
aim_assist_previous_current_aim_point = aim;
}
aim_assist_has_target = should_aim;
if (aim_assist_cached_target_ref)
(*env)->DeleteGlobalRef(env, aim_assist_cached_target_ref);
if (void *ref = (*env)->NewGlobalRef(env, best))
aim_assist_cached_target_ref = ref;
}
+129
View File
@@ -0,0 +1,129 @@
// Aim Assist — Pulls your crosshair towards other players.
// category: combat descriptor: 0x2e8cc0 settings block: 0x2e8eb8
// functions: gui aim_assist_gui, register aim_assist_register, status aim_assist_status
// implementation: src/logic/combat/aim_assist.cpp
#pragma once
#include "slinky/api.h"
S(str_aim); // "Aim"
S(str_multi_point); // "Multi-point"
S(str_target); // "Target"
S(str_conditions); // "Conditions"
S(str_mode_in_aim_assist); // "mode"
S(str_hor_speed); // "hor_speed"
S(str_ver_speed); // "ver_speed"
S(str_lock_on_vertical); // "lock_on_vertical"
S(str_silent_move_correct); // "silent_move_correct"
S(str_silent_ignore_manual_aim); // "silent_ignore_manual_aim"
S(str_predict_in_aim_assist); // "predict"
S(str_aim_randomization); // "aim_randomization"
S(str_hor_hitbox_correct); // "hor_hitbox_correct"
S(str_ver_hitbox_correct); // "ver_hitbox_correct"
S(str_mode_target); // "mode_target"
S(str_sort_by_in_aim_assist); // "sort_by"
S(str_allow_exceed_fov); // "allow_exceed_fov"
S(str_range_in_aim_assist); // "range"
S(str_fov_in_aim_assist); // "fov"
S(str_require_sprint); // "require_sprint"
S(str_require_mouse_pressed); // "require_mouse_pressed"
S(str_require_mouse_moved); // "require_mouse_moved"
S(str_disable_on_block_break); // "disable_on_block_break"
S(str_require_weapon); // "require_weapon"
S(str_ignore_invis); // "ignore_invis"
S(str_require_line_of_sight); // "require_line_of_sight"
S(str_s_in_aim_assist); // "%s"
D(aim_assist_fov_setting); // setting rng "fov"
D(aim_assist_hor_speed_setting); // setting num "hor_speed"
D(aim_assist_ver_speed_setting); // setting num "ver_speed"
D(aim_assist_lock_on_vertical_setting); // setting bool "lock_on_vertical"
D(aim_assist_require_mouse_moved_setting); // setting bool "require_mouse_moved"
D(aim_assist_enum_option_labels_1); // enum option labels (const char *[])
D(aim_assist_mode_setting); // setting enum "mode"
extern "C" unsigned aim_assist_mode; // current value of setting "mode" (+0x30)
D(aim_assist_silent_ignore_manual_aim_setting); // setting bool "silent_ignore_manual_aim"
D(aim_assist_silent_move_correct_setting); // setting bool "silent_move_correct"
D(aim_assist_range_setting); // setting rng "range"
D(aim_assist_require_sprint_setting); // setting bool "require_sprint"
D(aim_assist_require_mouse_pressed_setting); // setting bool "require_mouse_pressed"
D(aim_assist_disable_on_block_break_setting); // setting bool "disable_on_block_break"
D(aim_assist_require_weapon_setting); // setting bool "require_weapon"
D(aim_assist_mode_target_setting); // setting enum "mode_target"
extern "C" int aim_assist_mode_target; // current value of setting "mode_target" (+0x30)
D(aim_assist_predict_setting); // setting num "predict"
D(aim_assist_hor_hitbox_correct_setting); // setting num "hor_hitbox_correct"
D(aim_assist_ver_hitbox_correct_setting); // setting num "ver_hitbox_correct"
D(aim_assist_aim_randomization_setting); // setting num "aim_randomization"
D(aim_assist_ignore_invis_setting); // setting bool "ignore_invis"
D(aim_assist_allow_exceed_fov_setting); // setting bool "allow_exceed_fov"
D(aim_assist_require_line_of_sight_setting); // setting bool "require_line_of_sight"
D(aim_assist_sort_by_setting); // setting enum "sort_by"
extern "C" void aim_assist_gui(void *gui, void *window) {
W_label(gui, window, str_aim);
W_enumw(window, gui, aim_assist_mode_setting);
if (aim_assist_mode == 2) {
W_bool(window, gui, aim_assist_lock_on_vertical_setting);
} else if (aim_assist_mode == 3) {
W_bool(window, gui, aim_assist_silent_move_correct_setting);
W_bool(window, gui, aim_assist_silent_ignore_manual_aim_setting);
W_slider(window, gui, aim_assist_hor_speed_setting);
W_slider(window, gui, aim_assist_ver_speed_setting);
} else {
W_slider(window, gui, aim_assist_hor_speed_setting);
W_slider(window, gui, aim_assist_ver_speed_setting);
}
W_slider(window, gui, aim_assist_predict_setting);
W_slider(window, gui, aim_assist_aim_randomization_setting);
W_label(gui, window, str_multi_point);
W_slider(window, gui, aim_assist_hor_hitbox_correct_setting);
W_slider(window, gui, aim_assist_ver_hitbox_correct_setting);
W_label(gui, window, str_target);
W_enumw(window, gui, aim_assist_mode_target_setting);
if (aim_assist_mode_target == 0) {
W_bool(window, gui, aim_assist_allow_exceed_fov_setting);
} else if (aim_assist_mode_target == 1) {
W_enumw(window, gui, aim_assist_sort_by_setting);
}
W_range(window, gui, aim_assist_range_setting);
W_range(window, gui, aim_assist_fov_setting);
W_label(gui, window, str_conditions);
if (aim_assist_mode != 3)
W_bool(window, gui, aim_assist_require_sprint_setting);
W_bool(window, gui, aim_assist_require_mouse_pressed_setting);
W_bool(window, gui, aim_assist_require_mouse_moved_setting);
W_bool(window, gui, aim_assist_disable_on_block_break_setting);
W_bool(window, gui, aim_assist_require_weapon_setting);
W_bool(window, gui, aim_assist_ignore_invis_setting);
W_bool(window, gui, aim_assist_require_line_of_sight_setting);
}
extern "C" void aim_assist_register(void *module) {
R_enum(module, str_mode_in_aim_assist, aim_assist_mode_setting);
R_num(module, str_hor_speed, aim_assist_hor_speed_setting);
R_num(module, str_ver_speed, aim_assist_ver_speed_setting);
R_bool(module, str_lock_on_vertical, aim_assist_lock_on_vertical_setting);
R_bool(module, str_silent_move_correct, aim_assist_silent_move_correct_setting);
R_bool(module, str_silent_ignore_manual_aim, aim_assist_silent_ignore_manual_aim_setting);
R_num(module, str_predict_in_aim_assist, aim_assist_predict_setting);
R_num(module, str_aim_randomization, aim_assist_aim_randomization_setting);
R_num(module, str_hor_hitbox_correct, aim_assist_hor_hitbox_correct_setting);
R_num(module, str_ver_hitbox_correct, aim_assist_ver_hitbox_correct_setting);
R_enum(module, str_mode_target, aim_assist_mode_target_setting);
R_enum(module, str_sort_by_in_aim_assist, aim_assist_sort_by_setting);
R_bool(module, str_allow_exceed_fov, aim_assist_allow_exceed_fov_setting);
R_rng(module, str_range_in_aim_assist, aim_assist_range_setting);
R_rng(module, str_fov_in_aim_assist, aim_assist_fov_setting);
R_bool(module, str_require_sprint, aim_assist_require_sprint_setting);
R_bool(module, str_require_mouse_pressed, aim_assist_require_mouse_pressed_setting);
R_bool(module, str_require_mouse_moved, aim_assist_require_mouse_moved_setting);
R_bool(module, str_disable_on_block_break, aim_assist_disable_on_block_break_setting);
R_bool(module, str_require_weapon, aim_assist_require_weapon_setting);
R_bool(module, str_ignore_invis, aim_assist_ignore_invis_setting);
R_bool(module, str_require_line_of_sight, aim_assist_require_line_of_sight_setting);
}
extern "C" void aim_assist_status(void *self) {
log_fmt(self, 0x20, str_s_in_aim_assist, ((const char **)aim_assist_enum_option_labels_1)[aim_assist_mode]);
}
+285
View File
@@ -0,0 +1,285 @@
// Auto Block - block with your sword automatically while fighting.
//
// While you hold a sword and the conditions are met, the module holds the use key so you
// block, lets go after "max_hold_time" ticks so you can hit, and blocks again when a target
// is in range. After letting go it can "lag" (hold outgoing packets) for "lag_duration"
// ticks, with "lag_chance". "fake_block_animation" makes the sword look blocked on your
// screen even when it is not.
//
// Callbacks (descriptor slots +0x48 / +0x78 / +0x98 / +0x128 / +0x168):
// auto_block_on_tick every tick: block / unblock
// auto_block_on_packet_sent every outgoing packet: hold it while lagging
// auto_block_on_toggle module switched off: give the use key back
// auto_block_on_attack before an attack
// auto_block_on_late_tick every tick: the fake block animation
#include "slinky/engine.h"
struct AttackHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
unsigned char phase; // +0x10
unsigned char cancel; // +0x11 set to 1 to cancel the attack
};
struct EvHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
void *ev; // +0x10 module descriptor that was toggled
unsigned char on; // +0x18 1 = switched on
};
struct PktHook { char padding_00[0x24]; int verdict; }; // +0x24 set to 1 to hold the packet
struct Mouse { unsigned char padding_00, lmb, rmb; }; // Ctx::key_state_table: +1 left, +2 right button held
// ---- settings ----
extern "C" float auto_block_max_hold_time_value; // "max_hold_time": ticks to block before letting go
extern "C" float auto_block_lag_chance_value; // "lag_chance"
extern "C" float auto_block_lag_duration_value; // "lag_duration": ticks
extern "C" float auto_block_max_hurt_time_value; // "max_hurt_time": don't block later than this after being hit
extern "C" unsigned char auto_block_require_left_mouse_pressed_value; // "require_left_mouse_pressed"
extern "C" unsigned char auto_block_require_right_mouse_pressed_value; // "require_right_mouse_pressed"
extern "C" unsigned char auto_block_require_damage_value; // "require_damage": only after being hit
extern "C" unsigned char auto_block_fake_block_animation; // "fake_block_animation"
extern "C" unsigned char auto_block_fake_block_animation_require_target_value; // "fake_block_animation_require_target"
extern "C" float auto_block_range_value; // "range": target distance to block at
extern "C" unsigned char auto_block_lag_flush_attack_value; // "lag_flush_attack": stop lagging when we hit
extern "C" unsigned char auto_block_lag_reblock_value; // "lag_reblock": block again right after lagging
// ---- module state ----
extern "C" char auto_block_module_descriptor[];
extern "C" unsigned char auto_block_blocking; // we are blocking
extern "C" unsigned char auto_block_use_key_forced; // we control the use key
extern "C" int auto_block_re_block_cooldown; // ticks before blocking again
extern "C" int auto_block_ticks_held; // ticks blocked so far
extern "C" unsigned auto_block_ticks_since_target_hit;
extern "C" int auto_block_last_target_id;
extern "C" unsigned char auto_block_right_mouse_required; // "require_right_mouse_pressed" is on (this tick)
extern "C" int auto_block_lag_ticks_left; // > 0 while lagging (read by the network thread)
extern "C" unsigned char auto_block_fake_animation_this_tick;
extern "C" unsigned char auto_block_animation_started;
extern "C" int auto_block_animation_counter; // item use count shown for the fake animation
// ---- game / engine functions ----
FN(unsigned char, java_call_entity_player_is_using_item, (void *jvm, void *entity_player));
FN(void, java_set_entity_player_item_in_use_count, (void *jvm, void *entity_player, int n));
FN(int, java_get_entity_living_base_hurt_time, (void *jvm, void *entity_living_base)); // 10 on the tick of being hit
FN(void *, item_held_hotbar_slot, (void *jvm, void *slot));
FN(unsigned char, item_sword, (void *jvm, void *item)); // is it a sword?
FN(unsigned char, timer_range_is_delay_pending, ()); // Timer Range is busy
FN(unsigned char, random_chance, (float chance));
FN(void *, get_game_settings, (void *jvm, void *object));
FN(void *, java_get_game_settings_use_item_key, (void *jvm, void *game_settings));
FN(unsigned char, java_get_key_binding_key_code, (void *jvm, void *key_binding)); // key physically held down
FN(void, java_set_key_binding_pressed, (void *jvm, void *key_binding, unsigned char on));
FN(void, java_increment_key_binding_press_time, (void *jvm, void *key_binding)); // = one right click
FN(int, java_get_entity_ticks_existed, (void *jvm, void *entity));
FN(int, java_get_entity_living_base_last_attacker_time, (void *jvm, void *entity_living_base)); // tick of our last attack
FN(int, java_get_entity_entity_id, (void *jvm, void *entity));
// Round a tick count randomly: 2.3 gives 3 with a 30% chance, else 2.
static int random_round(float value) {
int whole = (int)value;
return random_chance(value - (float)(int)value) + whole;
}
static void *use_key(Ctx *ctx) {
return java_get_game_settings_use_item_key(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft));
}
static void stop_lagging() {
__atomic_exchange_n(&auto_block_lag_ticks_left, 0, __ATOMIC_SEQ_CST);
}
static bool target_in_range(Ctx *ctx) {
CombatTarget *target = (CombatTarget *)ctx->target;
return target->ent && (double)(auto_block_range_value * auto_block_range_value) > target->dist2;
}
extern "C" void auto_block_on_tick(Hook *hook) {
auto_block_fake_animation_this_tick = 0;
Ctx *ctx = hook->ctx;
// End last tick's fake animation.
if (auto_block_animation_started == 1) {
if (ctx->player && !java_call_entity_player_is_using_item(ctx->jvm, ctx->player))
java_set_entity_player_item_in_use_count(ctx->jvm, ctx->player, 0);
auto_block_animation_started = 0;
}
if (auto_block_re_block_cooldown != 0)
auto_block_re_block_cooldown -= 1;
if (!ctx->in_game) {
if (auto_block_use_key_forced == 1) {
void *key = use_key(ctx);
java_set_key_binding_pressed(ctx->jvm, key, java_get_key_binding_key_code(ctx->jvm, key));
auto_block_use_key_forced = 0;
}
auto_block_right_mouse_required = 0;
stop_lagging();
return;
}
int hurt_time = java_get_entity_living_base_hurt_time(ctx->jvm, ctx->player);
unsigned char holding_sword = item_sword(ctx->jvm, item_held_hotbar_slot(ctx->jvm, ctx->player));
auto_block_right_mouse_required = 0;
// Should the use key be ours this tick?
unsigned char conditions_ok = 0; // sword + mouse conditions (for the fake animation)
unsigned char key_forced = 0; // we press the use key this tick
unsigned char fake_animation = 0;
bool give_key_back;
if (!holding_sword) {
give_key_back = auto_block_use_key_forced == 1; // only if we had it
if (!give_key_back)
goto bookkeeping;
} else if (auto_block_require_left_mouse_pressed_value == 1 && !((Mouse *)ctx->key_state_table)->lmb) {
give_key_back = true;
} else if (timer_range_is_delay_pending()) {
give_key_back = true;
} else {
unsigned char need_rmb = auto_block_require_right_mouse_pressed_value;
auto_block_right_mouse_required = need_rmb;
if (need_rmb != ((Mouse *)ctx->key_state_table)->rmb) {
give_key_back = true;
} else {
conditions_ok = 1;
// Blocking only right after being hit, and not too late.
if (hurt_time == 0 && auto_block_require_damage_value)
give_key_back = true;
else if (hurt_time > random_round(auto_block_max_hurt_time_value))
give_key_back = true;
else
give_key_back = false;
}
}
if (give_key_back) {
// The use key goes back to the player (or stays up while right mouse is required).
void *key = use_key(ctx);
java_set_key_binding_pressed(ctx->jvm, key, auto_block_right_mouse_required ? 0 : java_get_key_binding_key_code(ctx->jvm, key));
key_forced = 0;
} else {
// Ours: pressed while blocking, up otherwise.
unsigned char blocking = auto_block_blocking;
void *key = use_key(ctx);
java_set_key_binding_pressed(ctx->jvm, key, blocking);
key_forced = 1;
if (blocking == 1)
java_increment_key_binding_press_time(ctx->jvm, key);
}
auto_block_use_key_forced = key_forced;
if (conditions_ok && auto_block_fake_block_animation) {
fake_animation = 1;
if (auto_block_fake_block_animation_require_target_value == 1)
fake_animation = target_in_range(ctx);
}
bookkeeping:
auto_block_fake_animation_this_tick = fake_animation;
if (hurt_time == 10)
auto_block_re_block_cooldown = 0; // just got hit: may block again at once
// Did we hit the target (or get a new one)?
unsigned ticks = auto_block_ticks_since_target_hit + 1;
auto_block_ticks_since_target_hit = ticks;
unsigned char hit_target = 0;
if (ticks >= 10) {
hit_target = java_get_entity_ticks_existed(ctx->jvm, ctx->player) == java_get_entity_living_base_last_attacker_time(ctx->jvm, ctx->player) + 1;
if (hit_target)
auto_block_ticks_since_target_hit = 0;
}
void *target = ((CombatTarget *)ctx->target)->ent;
int target_id = target ? java_get_entity_entity_id(ctx->jvm, target) : 0;
if (target_id != auto_block_last_target_id) {
auto_block_last_target_id = target_id;
auto_block_ticks_since_target_hit = 0;
hit_target = 1;
}
// Count the lag down (or end it on a hit with "lag_flush_attack").
if (__atomic_load_n(&auto_block_lag_ticks_left, __ATOMIC_SEQ_CST) != 0) {
if ((hit_target & auto_block_lag_flush_attack_value) == 1)
__atomic_exchange_n(&auto_block_lag_ticks_left, 0, __ATOMIC_SEQ_CST);
else
__atomic_fetch_sub(&auto_block_lag_ticks_left, 1, __ATOMIC_SEQ_CST);
if (auto_block_lag_reblock_value == 1 && __atomic_load_n(&auto_block_lag_ticks_left, __ATOMIC_SEQ_CST) == 0)
auto_block_re_block_cooldown = 0; // lag over: block again at once
}
if (auto_block_blocking) {
// Blocking: let go after "max_hold_time" ticks (randomly rounded).
int held = auto_block_ticks_held + 1;
float max_hold = auto_block_max_hold_time_value;
int whole = (int)max_hold;
auto_block_ticks_held = held;
int limit = random_chance(max_hold - (float)(int)max_hold) + whole;
unsigned char keep_holding = held < limit;
if (key_forced & keep_holding)
return;
java_set_key_binding_pressed(ctx->jvm, use_key(ctx), 0);
auto_block_use_key_forced = 1;
if (random_chance(auto_block_lag_chance_value))
__atomic_exchange_n(&auto_block_lag_ticks_left, random_round(auto_block_lag_duration_value), __ATOMIC_SEQ_CST);
auto_block_blocking = 0;
return;
}
// Not blocking: block again when allowed and a target is in range.
if (!(key_forced & (auto_block_re_block_cooldown == 0)))
return;
if (!target_in_range(ctx))
return;
void *key = use_key(ctx);
java_set_key_binding_pressed(ctx->jvm, key, 1);
java_increment_key_binding_press_time(ctx->jvm, key);
auto_block_use_key_forced = 1;
auto_block_blocking = 1;
auto_block_re_block_cooldown = 10;
auto_block_ticks_held = 0;
stop_lagging();
}
extern "C" void auto_block_on_packet_sent(PktHook *hook) {
if (__atomic_load_n(&auto_block_lag_ticks_left, __ATOMIC_SEQ_CST) != 0)
hook->verdict = 1;
}
// On disable: stop blocking and give the use key back.
extern "C" void auto_block_on_toggle(EvHook *hook) {
if (hook->ev != auto_block_module_descriptor || hook->on || !(auto_block_blocking & 1))
return;
if (auto_block_use_key_forced == 1) {
Ctx *ctx = hook->ctx;
void *key = use_key(ctx);
java_set_key_binding_pressed(ctx->jvm, key, java_get_key_binding_key_code(ctx->jvm, key));
auto_block_use_key_forced = 0;
}
auto_block_blocking = 0;
stop_lagging();
}
extern "C" void auto_block_on_attack(AttackHook *hook) {
if (hook->phase != 0)
return;
void *jvm = hook->ctx->jvm;
if (!item_sword(jvm, item_held_hotbar_slot(jvm, hook->ctx->player)))
stop_lagging();
// With "require_right_mouse_pressed", don't attack while not blocking.
if (auto_block_right_mouse_required == 1 && !(auto_block_blocking & 1))
hook->cancel = 1;
}
// Fake block animation: count the item use counter down so the sword is drawn blocking.
extern "C" void auto_block_on_late_tick(Hook *hook) {
if (!auto_block_fake_animation_this_tick) {
auto_block_animation_counter = 72000; // a sword's full use duration
return;
}
Ctx *ctx = hook->ctx;
if (ctx->player) {
auto_block_animation_started = 1;
int count = auto_block_animation_counter - 1;
auto_block_animation_counter = count;
java_set_entity_player_item_in_use_count(ctx->jvm, ctx->player, count);
}
}
+73
View File
@@ -0,0 +1,73 @@
// Auto Block — Blocks your sword for you in combat.
// category: combat descriptor: 0x2eaff8 settings block: 0x2eb1f0
// functions: gui auto_block_gui, register auto_block_register
// implementation: src/logic/combat/auto_block.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_auto_block); // "Main"
S(str_force_block_animation); // "Force block animation"
S(str_lag); // "Lag"
S(str_conditions_in_auto_block); // "Conditions"
S(str_range_in_auto_block); // "range"
S(str_max_hurt_time); // "max_hurt_time"
S(str_max_hold_time); // "max_hold_time"
S(str_fake_block_animation); // "fake_block_animation"
S(str_fake_block_animation_require_t); // "fake_block_animation_require_target"
S(str_lag_chance); // "lag_chance"
S(str_lag_duration); // "lag_duration"
S(str_lag_flush_attack); // "lag_flush_attack"
S(str_lag_reblock); // "lag_reblock"
S(str_require_left_mouse_pressed); // "require_left_mouse_pressed"
S(str_require_right_mouse_pressed); // "require_right_mouse_pressed"
S(str_require_damage); // "require_damage"
D(auto_block_max_hold_time_setting); // setting num "max_hold_time"
D(auto_block_lag_chance_setting); // setting num "lag_chance"
D(auto_block_lag_duration_setting); // setting num "lag_duration"
D(auto_block_max_hurt_time_setting); // setting num "max_hurt_time"
D(auto_block_require_left_mouse_pressed_setting); // setting bool "require_left_mouse_pressed"
D(auto_block_require_right_mouse_pressed_setting); // setting bool "require_right_mouse_pressed"
D(auto_block_require_damage_setting); // setting bool "require_damage"
D(auto_block_fake_block_animation_setting); // setting bool "fake_block_animation"
D(auto_block_fake_block_animation); // current value of setting "fake_block_animation" (+0x18)
D(auto_block_fake_block_animation_require_target_setting); // setting bool "fake_block_animation_require_target"
D(auto_block_range_setting); // setting num "range"
D(auto_block_lag_flush_attack_setting); // setting bool "lag_flush_attack"
D(auto_block_lag_reblock_setting); // setting bool "lag_reblock"
extern "C" void auto_block_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_auto_block);
W_slider(window, gui, auto_block_range_setting);
W_slider(window, gui, auto_block_max_hurt_time_setting);
W_slider(window, gui, auto_block_max_hold_time_setting);
W_label(gui, window, str_force_block_animation);
W_bool(window, gui, auto_block_fake_block_animation_setting);
if (*(unsigned char *)auto_block_fake_block_animation == 1) {
W_bool(window, gui, auto_block_fake_block_animation_require_target_setting);
}
W_label(gui, window, str_lag);
W_slider(window, gui, auto_block_lag_chance_setting);
W_slider(window, gui, auto_block_lag_duration_setting);
W_bool(window, gui, auto_block_lag_flush_attack_setting);
W_bool(window, gui, auto_block_lag_reblock_setting);
W_label(gui, window, str_conditions_in_auto_block);
W_bool(window, gui, auto_block_require_left_mouse_pressed_setting);
W_bool(window, gui, auto_block_require_right_mouse_pressed_setting);
W_bool(window, gui, auto_block_require_damage_setting);
}
extern "C" void auto_block_register(void *module) {
R_num(module, str_range_in_auto_block, auto_block_range_setting);
R_num(module, str_max_hurt_time, auto_block_max_hurt_time_setting);
R_num(module, str_max_hold_time, auto_block_max_hold_time_setting);
R_bool(module, str_fake_block_animation, auto_block_fake_block_animation_setting);
R_bool(module, str_fake_block_animation_require_t, auto_block_fake_block_animation_require_target_setting);
R_num(module, str_lag_chance, auto_block_lag_chance_setting);
R_num(module, str_lag_duration, auto_block_lag_duration_setting);
R_bool(module, str_lag_flush_attack, auto_block_lag_flush_attack_setting);
R_bool(module, str_lag_reblock, auto_block_lag_reblock_setting);
R_bool(module, str_require_left_mouse_pressed, auto_block_require_left_mouse_pressed_setting);
R_bool(module, str_require_right_mouse_pressed, auto_block_require_right_mouse_pressed_setting);
R_bool(module, str_require_damage, auto_block_require_damage_setting);
}
+290
View File
@@ -0,0 +1,290 @@
// Auto Clicker - click for you while you hold the attack button.
//
// While the attack mouse button is held, the module sends its own button presses and
// releases at "cps" clicks per second, with human-like randomness ("randomize"): slow drifts
// in speed, occasional bursts of fast clicks, and in "mode" 1 occasional double clicks.
// In inventories ("inventory_fill"), holding shift and dragging over slots shift-clicks them.
//
// Callbacks:
// auto_clicker_tick every tick: find the attack button, reset the click delay
// auto_clicker_on_player_update every player tick: what is under the crosshair
// auto_clicker_on_frame every frame: send presses / releases when they are due
// auto_clicker_extra_burst_clicks helper: occasional bursts of faster clicks
#include "slinky/engine.h"
struct Rot { float yaw, pitch; };
struct Range { float lo, hi; };
struct TickHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
char padding_10[8];
double dt; // +0x18 seconds since the last frame
};
// ---- settings ----
extern "C" float auto_clicker_cps_setting; // "cps"
extern "C" unsigned char auto_clicker_randomize_setting; // "randomize"
extern "C" unsigned auto_clicker_pattern; // "mode": 0 = even clicks, 1 = with double clicks
extern "C" unsigned char auto_clicker_burst_setting; // "burst"
extern "C" unsigned char auto_clicker_break_blocks_setting; // "break_blocks": don't click on blocks (so they can be mined)
extern "C" unsigned char auto_clicker_require_weapon_value; // "require_weapon"
extern "C" unsigned char auto_clicker_pause_when_using_setting; // "pause_when_using"
extern "C" unsigned char auto_clicker_allow_inventory; // "inventory_fill"
extern "C" unsigned char auto_clicker_inventory_random_delay_setting; // "inventory_random_delay"
// ---- module state ----
extern "C" Rot auto_clicker_rotation_at_last_tick;
extern "C" unsigned char auto_clicker_attack_bound_mouse; // 0 = attack is the left button, 1 = the right button
extern "C" int auto_clicker_hit_type_under_crosshair; // 0 = nothing, 1 = block, 2 = entity
extern "C" unsigned char *const ptr_to_no_hit_delay_module_descriptor; // client state; +0x14 = a screen is open
extern "C" double auto_clicker_time_until_next_click_edge; // seconds until the next press/release
extern "C" double auto_clicker_last_edge_delay;
extern "C" int auto_clicker_burst_clicks_left;
extern "C" unsigned char auto_clicker_double_click_pending;
extern "C" unsigned char auto_clicker_lmb_was_down_gui;
extern "C" int auto_clicker_last_inventory_slot_clicked;
// Random walk / random number states.
extern "C" char auto_clicker_rng_states[], auto_clicker_rng_states_second[], auto_clicker_rng_states_third[];
extern "C" char auto_clicker_random_walk_1[], auto_clicker_random_walk_2[], auto_clicker_random_walk_3[], auto_clicker_random_walk_4[],
auto_clicker_random_walk_5[], auto_clicker_random_walk_6[], auto_clicker_random_walk_7[], auto_clicker_gauss_rng_state[];
// ---- game / engine functions ----
FN(float, gauss_random, (void *st)); // normally distributed random number
FN(Range, rot_make_floats, (float lo, float hi));
FN(unsigned char, walk_should_change, (void *state, Range r, double p)); // random yes/no
FN(float, walk_update, (void *state, Range r, double p)); // next value of a random walk
FN(float, random_rotation, (Range r)); // random value in the range
FN(void *, get_timer, (void *jvm, void *timer));
FN(float, java_get_timer_timer_speed, (void *jvm, void *timer));
FN(void, post_synthetic_click, (int button, unsigned char down)); // press / release a mouse button
FN(float, rot_delta_length, (Rot a, Rot b)); // how far the view turned
FN(unsigned char, is_holding_accepted_weapon, (void *jvm, void *object));
FN(unsigned char, java_call_entity_player_is_using_item, (void *jvm, void *entity_player));
FN(void *, get_current_screen, (void *jvm, void *object));
FN(void *, java_get_entity_player_inventory, (void *jvm, void *entity_player));
FN(void *, java_get_gui_container_the_slot, (void *jvm, void *screen)); // slot under the mouse
FN(void *, java_get_inventory_player_item_stack, (void *jvm, void *inv)); // item on the mouse cursor
FN(int, java_get_slot_slot_number, (void *jvm, void *slot));
FN(void *, java_call_slot_get_stack, (void *jvm, void *slot));
FN(unsigned char, random_chance, (float chance));
FN(void *, get_game_settings, (void *jvm, void *object));
FN(void *, java_get_game_settings_attack_key, (void *jvm, void *game_settings));
FN(int, get_event_key, (void *jvm, void *k)); // key code; -100 = left mouse, -99 = right mouse
FN(Rot, get_entity_rotation, (void *jvm, void *entity));
FN(void, java_set_minecraft_left_click_counter, (void *jvm, void *minecraft, int y));
FN(void *, java_get_minecraft_object_mouse_over, (void *jvm, void *minecraft));
FN(int, java_get_moving_object_position_type_ordinal, (void *jvm, void *moving_object_position));
enum { KEY_LEFT_MOUSE = -100, KEY_RIGHT_MOUSE = -99 };
static int auto_clicker_attack_key;
extern "C" void auto_clicker_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
auto_clicker_attack_key = get_event_key(ctx->jvm, java_get_game_settings_attack_key(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft)));
auto_clicker_attack_bound_mouse = auto_clicker_attack_key == KEY_RIGHT_MOUSE;
if (ctx->in_game != 1)
return;
auto_clicker_rotation_at_last_tick = get_entity_rotation(ctx->jvm, ctx->player);
if (ptr_to_no_hit_delay_module_descriptor[0x14])
return;
// Remove Minecraft's 10-tick wait after a missed click.
java_set_minecraft_left_click_counter(ctx->jvm, ctx->minecraft, 0);
}
extern "C" void auto_clicker_on_player_update(Hook *hook) {
Ctx *ctx = hook->ctx;
if (ctx->in_game == 1) {
void *hit = java_get_minecraft_object_mouse_over(ctx->jvm, ctx->minecraft);
auto_clicker_hit_type_under_crosshair = hit ? java_get_moving_object_position_type_ordinal(ctx->jvm, hit) : 0;
}
}
// Now and then, a burst of 1-3 quicker clicks. Returns 1 (and makes *delay a bit longer
// ...the burst clicks are spaced 0.02 s + noise apart) while a burst is running.
extern "C" unsigned char auto_clicker_extra_burst_clicks(float *delay, float base) {
int clicks = auto_clicker_burst_clicks_left;
if (clicks <= 0) {
// Start a new burst? More likely while aiming around ("base").
if (auto_clicker_burst_setting != 1)
return 0;
double chance = base;
Range start_chance = {(float)(0.02 + chance), (float)(chance + 0.04)};
if (!walk_should_change(auto_clicker_rng_states, start_chance, 300.0))
return 0;
// How long: usually 1 click, sometimes 2 or 3.
float roll = random_rotation(rot_make_floats(0.0f, 1.0f));
clicks = 3;
if (!(walk_update(auto_clicker_rng_states_second, rot_make_floats(0.03f, 0.06f), 120.0) > roll))
clicks = (walk_update(auto_clicker_rng_states_second, rot_make_floats(0.12f, 0.15f), 120.0) > roll) + 1;
}
auto_clicker_burst_clicks_left = clicks - 1;
double extra = (double)gauss_random(auto_clicker_rng_states_third) * 0.01 + 0.02;
*delay = (float)((double)*delay + extra);
return 1;
}
// Burst chance bonus: higher while the view turns fast, and with no target within 5 blocks.
static float aim_bonus(Ctx *ctx) {
float bonus = rot_delta_length(get_entity_rotation(ctx->jvm, ctx->player), auto_clicker_rotation_at_last_tick) / 20.0f + 0.0f;
CombatTarget *target = (CombatTarget *)ctx->target;
if (!target->ent || target->dist2 > 25.0)
bonus = (float)((double)bonus + 0.08);
return bonus;
}
// Seconds the button stays down after a press (the release takes the same time).
static float press_duration(Ctx *ctx) {
float cps = auto_clicker_cps_setting;
if (auto_clicker_randomize_setting == 1) {
// Slow drifts of +-10% and quick wobbles of +-5%, then gaussian noise of 20-30%.
float noise_size = walk_update(auto_clicker_random_walk_1, rot_make_floats(0.2f, 0.3f), 30.0);
float slow_drift = walk_update(auto_clicker_random_walk_2, rot_make_floats(-0.1f, 0.1f), 120.0);
float drift = walk_update(auto_clicker_random_walk_3, rot_make_floats(-0.1f, 0.1f), 30.0);
float wobble = walk_update(auto_clicker_random_walk_4, rot_make_floats(-0.05f, 0.05f), 5.0);
cps *= slow_drift + 1.0f + drift + wobble;
cps *= gauss_random(auto_clicker_gauss_rng_state) * noise_size + 1.0f;
}
float delay;
if (auto_clicker_pattern == 1) {
if (auto_clicker_double_click_pending == 1) {
delay = 0.014f; // the second click of a double click
auto_clicker_double_click_pending = 0;
} else {
delay = (float)(1.0 / (double)cps + -(double)0.014f);
if (!auto_clicker_extra_burst_clicks(&delay, aim_bonus(ctx)))
auto_clicker_double_click_pending = random_chance((float)walk_should_change(auto_clicker_random_walk_5, rot_make_floats(0.94f, 0.97f), 30.0));
}
} else {
delay = 0.5f / cps; // half a click down, half up
auto_clicker_extra_burst_clicks(&delay, aim_bonus(ctx));
}
return delay;
}
// In an inventory: holding shift and dragging with the left button shift-clicks each slot.
static void inventory_fill(Ctx *ctx) {
unsigned char *keys = (unsigned char *)ctx->key_state_table;
unsigned char left_down = keys[1];
double wait;
if (left_down == 1 && auto_clicker_lmb_was_down_gui == 1) {
bool shift_held = (keys[0x62] & 1) || (keys[0x63] & 1);
if (auto_clicker_allow_inventory == 1 && shift_held) {
void *jvm = ctx->jvm;
void *screen = get_current_screen(jvm, ctx->minecraft);
void *inventory = java_get_entity_player_inventory(jvm, ctx->player);
void *slot = java_get_gui_container_the_slot(jvm, screen);
if (slot && !java_get_inventory_player_item_stack(jvm, inventory)) {
int slot_number = java_get_slot_slot_number(jvm, slot);
if (slot_number != auto_clicker_last_inventory_slot_clicked) {
auto_clicker_last_inventory_slot_clicked = slot_number;
// Empty slots are clicked only now and then (like a human dragging over them).
if (java_call_slot_get_stack(jvm, slot) ||
!walk_should_change(auto_clicker_random_walk_6, rot_make_floats(0.6f, 0.8f), 10.0)) {
post_synthetic_click(1, 1);
if (auto_clicker_inventory_random_delay_setting != 1) {
wait = 0.001;
} else {
Range r = walk_should_change(auto_clicker_random_walk_7, rot_make_floats(0.04f, 0.08f), 10.0)
? rot_make_floats(0.15f, 0.25f) : rot_make_floats(0.06f, 0.075f);
wait = random_rotation(r);
}
auto_clicker_time_until_next_click_edge = wait + auto_clicker_time_until_next_click_edge;
return;
}
}
}
}
} else {
auto_clicker_lmb_was_down_gui = left_down == 1;
}
wait = auto_clicker_inventory_random_delay_setting ? 0.05 : 0.001;
auto_clicker_time_until_next_click_edge = wait + auto_clicker_time_until_next_click_edge;
}
// Every frame: send the next press or release when it is due.
extern "C" void auto_clicker_on_frame(TickHook *hook) {
if (auto_clicker_attack_key != KEY_LEFT_MOUSE && auto_clicker_attack_key != KEY_RIGHT_MOUSE)
return; // attack is not on a mouse button: nothing to click
Ctx *ctx = hook->ctx;
// Count down by the frame time (scaled with the game speed), not below -0.2 s.
double time_left = auto_clicker_time_until_next_click_edge - (double)java_get_timer_timer_speed(ctx->jvm, get_timer(ctx->jvm, ctx->minecraft)) * hook->dt;
time_left = -0.2 > time_left ? -0.2 : time_left;
auto_clicker_time_until_next_click_edge = time_left;
if (!(0.0 >= time_left))
return;
// The attack button's state: bit 0 = down, bit 1 = held down by us.
unsigned char *mouse = (unsigned char *)ctx->key_state_table;
unsigned char down = mouse[auto_clicker_attack_bound_mouse + 1];
unsigned char ours = (down & 2) >> 1;
int button = auto_clicker_attack_bound_mouse ^ 1;
double reset_to = 0.01;
if (ctx->in_game == 0) {
// In a menu: let go of our press, then the inventory feature.
if (ours & 1)
post_synthetic_click(button, (~down) & 1);
if (get_current_screen(ctx->jvm, ctx->minecraft)) {
inventory_fill(ctx);
return;
}
} else {
for (;;) {
if (ctx->in_game == 0) {
// (left the world during the loop)
if (ours & 1)
post_synthetic_click(button, (~down) & 1);
if (get_current_screen(ctx->jvm, ctx->minecraft)) {
inventory_fill(ctx);
return;
}
break;
}
if (!((down | ours) & 1))
break; // the player let go of the button
// Reasons to stop clicking: release our press, if any.
bool cancel = false;
if (auto_clicker_hit_type_under_crosshair == 1 && auto_clicker_break_blocks_setting)
cancel = true;
else if (auto_clicker_require_weapon_value == 1 && !is_holding_accepted_weapon(ctx->jvm, ctx->player))
cancel = true;
else if (auto_clicker_pause_when_using_setting == 1)
cancel = java_call_entity_player_is_using_item(ctx->jvm, ctx->player) || ((down & ours) & 1);
else if ((down & ours) & 1) {
post_synthetic_click(button, 0); // release (the player is still holding it)
reset_to = 0.0;
break;
}
if (cancel) {
reset_to = 0.0;
if (ours & 1)
post_synthetic_click(button, (~down) & 1);
break;
}
if (down & 1) {
// Down now: release, after the same time it was down.
post_synthetic_click(button, 0);
auto_clicker_time_until_next_click_edge = auto_clicker_last_edge_delay + auto_clicker_time_until_next_click_edge;
} else {
// Up now: press, and decide how long it stays down.
post_synthetic_click(button, 1);
double delay = press_duration(ctx);
auto_clicker_time_until_next_click_edge = auto_clicker_time_until_next_click_edge + delay;
auto_clicker_last_edge_delay = delay;
}
down ^= 1;
ours ^= 1;
if (0.0 < auto_clicker_time_until_next_click_edge)
return;
}
}
auto_clicker_time_until_next_click_edge = reset_to;
auto_clicker_last_inventory_slot_clicked = -1;
}
+67
View File
@@ -0,0 +1,67 @@
// Auto Clicker — Clicks for you when holding down left-click.
// category: combat descriptor: 0x2e9330 settings block: 0x2e9528
// functions: gui auto_clicker_gui, register auto_clicker_register, status auto_clicker_status
// implementation: src/logic/combat/auto_clicker.cpp
#pragma once
#include "slinky/api.h"
S(str_in_game); // "In-game"
S(str_inventory_in_auto_clicker); // "Inventory"
S(str_conditions_in_auto_clicker); // "Conditions"
S(str_pattern); // "pattern"
S(str_target_cps_in_auto_clicker); // "target_cps"
S(str_randomize_cps); // "randomize_cps"
S(str_exhaust); // "exhaust"
S(str_allow_block_break); // "allow_block_break"
S(str_allow_inventory); // "allow_inventory"
S(str_inventory_randomize); // "inventory_randomize"
S(str_require_weapon_in_auto_clicker); // "require_weapon"
S(str_require_not_using_item); // "require_not_using_item"
S(str_s_in_auto_clicker); // "%s"
D(auto_clicker_allow_inventory_setting); // setting bool "allow_inventory"
D(auto_clicker_allow_inventory); // current value of setting "allow_inventory" (+0x18)
D(auto_clicker_inventory_randomize_setting); // setting bool "inventory_randomize"
D(auto_clicker_allow_block_break_setting); // setting bool "allow_block_break"
D(auto_clicker_require_weapon_setting); // setting bool "require_weapon"
D(auto_clicker_require_not_using_item_setting); // setting bool "require_not_using_item"
D(auto_clicker_target_cps_setting); // setting num "target_cps"
D(auto_clicker_randomize_cps_setting); // setting bool "randomize_cps"
D(auto_clicker_enum_option_labels_1); // enum option labels (const char *[])
D(auto_clicker_pattern_setting); // setting enum "pattern"
extern "C" unsigned auto_clicker_pattern; // current value of setting "pattern" (+0x30)
D(auto_clicker_exhaust_setting); // setting bool "exhaust"
extern "C" void auto_clicker_gui(void *gui, void *window) {
W_label(gui, window, str_in_game);
W_enumw(window, gui, auto_clicker_pattern_setting);
W_slider(window, gui, auto_clicker_target_cps_setting);
W_bool(window, gui, auto_clicker_randomize_cps_setting);
W_bool(window, gui, auto_clicker_exhaust_setting);
W_bool(window, gui, auto_clicker_allow_block_break_setting);
W_label(gui, window, str_inventory_in_auto_clicker);
W_bool(window, gui, auto_clicker_allow_inventory_setting);
if (*(unsigned char *)auto_clicker_allow_inventory == 1) {
W_bool(window, gui, auto_clicker_inventory_randomize_setting);
}
W_label(gui, window, str_conditions_in_auto_clicker);
W_bool(window, gui, auto_clicker_require_weapon_setting);
W_bool(window, gui, auto_clicker_require_not_using_item_setting);
}
extern "C" void auto_clicker_register(void *module) {
R_enum(module, str_pattern, auto_clicker_pattern_setting);
R_num(module, str_target_cps_in_auto_clicker, auto_clicker_target_cps_setting);
R_bool(module, str_randomize_cps, auto_clicker_randomize_cps_setting);
R_bool(module, str_exhaust, auto_clicker_exhaust_setting);
R_bool(module, str_allow_block_break, auto_clicker_allow_block_break_setting);
R_bool(module, str_allow_inventory, auto_clicker_allow_inventory_setting);
R_bool(module, str_inventory_randomize, auto_clicker_inventory_randomize_setting);
R_bool(module, str_require_weapon_in_auto_clicker, auto_clicker_require_weapon_setting);
R_bool(module, str_require_not_using_item, auto_clicker_require_not_using_item_setting);
}
extern "C" void auto_clicker_status(void *self) {
log_fmt(self, 0x20, str_s_in_auto_clicker, ((const char **)auto_clicker_enum_option_labels_1)[auto_clicker_pattern]);
}
+83
View File
@@ -0,0 +1,83 @@
// Auto Weapon - switch to your weapon when you aim at a player.
//
// When the crosshair is on a player you may fight (not a friend/teammate/bot) and you are
// not holding a weapon, the first weapon slot in the hotbar is selected, after the crosshair
// has been on players for "activation_time" ticks. "Weapon" is decided by the Weapons module.
//
// Callback (descriptor slot +0x1d8):
// auto_weapon_on_inventory_tick every tick
#include "slinky/engine.h"
// ---- settings ----
extern "C" float auto_weapon_activation_time_value; // "activation_time"
extern "C" unsigned char auto_weapon_require_mouse_pressed_value; // "require_mouse_pressed"
// ---- module state ----
extern "C" int auto_weapon_ticks_since_target_acquired;
extern "C" char auto_weapon_module_descriptor[];
struct WState { char padding_00[8]; Ctx *ctx; }; // +0x08 game context
// ---- game / engine functions ----
FN(unsigned char, java_call_entity_player_is_using_item, (void *jvm, void *entity_player));
FN(unsigned char, vertex_pointer_current, (Ctx *ctx)); // a mouse button is held
FN(void *, java_get_minecraft_object_mouse_over, (void *jvm, void *minecraft));
FN(int, java_get_moving_object_position_type_ordinal, (void *jvm, void *moving_object_position)); // 2 = an entity
FN(void *, java_get_moving_object_position_entity_hit, (void *jvm, void *moving_object_position));
FN(void *, java_jni_is_instance_of_entity_player, (void *jvm, void *candidate)); // the entity as a player, or null
FN(unsigned char, entity_flags_has, (void *jvm, void *entity, int mode)); // mode 7: friend, teammate or bot
FN(unsigned char, is_holding_accepted_weapon, (void *jvm, void *object));
FN(void *, java_get_entity_player_inventory, (void *jvm, void *entity_player));
FN(int, java_get_inventory_player_current_item, (void *jvm, void *inventory_player));
FN(int, weapons_find_first_weapon_slot_entry, (Ctx *ctx, void *player)); // see weapons.cpp
FN(unsigned char, claim_release_hotbar_module, (void *timer)); // ask for control of the hotbar
FN(void, java_set_inventory_player_current_item, (void *jvm, void *player, int slot));
FN(void, release_owner, (void *timer)); // give control of the hotbar back
// Is the crosshair on a player we may fight, while we are not holding a weapon?
static bool should_switch(Ctx *ctx) {
if (ctx->in_game != 1)
return false;
if (java_call_entity_player_is_using_item(ctx->jvm, ctx->player))
return false;
if (auto_weapon_require_mouse_pressed_value == 1 && !vertex_pointer_current(ctx))
return false;
void *hit = java_get_minecraft_object_mouse_over(ctx->jvm, ctx->minecraft);
if (!hit || java_get_moving_object_position_type_ordinal(ctx->jvm, hit) != 2)
return false;
void *target = java_jni_is_instance_of_entity_player(ctx->jvm, java_get_moving_object_position_entity_hit(ctx->jvm, hit));
if (!target || entity_flags_has(ctx->jvm, target, 7))
return false;
if (is_holding_accepted_weapon(ctx->jvm, ctx->player))
return false;
return true;
}
extern "C" void auto_weapon_on_inventory_tick(WState *s) {
Ctx *ctx = s->ctx;
if (!should_switch(ctx)) {
auto_weapon_ticks_since_target_acquired = 0;
return;
}
void *inventory = java_get_entity_player_inventory(ctx->jvm, ctx->player);
int current_slot = java_get_inventory_player_current_item(ctx->jvm, inventory);
int weapon_slot = weapons_find_first_weapon_slot_entry(ctx, inventory);
if (weapon_slot == -1 || current_slot == weapon_slot) {
auto_weapon_ticks_since_target_acquired = 0;
return;
}
// Wait "activation_time" ticks first.
int ticks = auto_weapon_ticks_since_target_acquired;
if (auto_weapon_activation_time_value > (float)ticks) {
auto_weapon_ticks_since_target_acquired = ticks + 1;
return;
}
// Switch, if no other module is using the hotbar right now.
if (!claim_release_hotbar_module(auto_weapon_module_descriptor))
return;
java_set_inventory_player_current_item(ctx->jvm, inventory, weapon_slot);
release_owner(auto_weapon_module_descriptor);
}
+26
View File
@@ -0,0 +1,26 @@
// Auto Weapon — Selects your weapon when aiming on players.
// category: combat descriptor: 0x2f5af8 settings block: 0x2f5cf0
// functions: gui auto_weapon_gui, register auto_weapon_register
// implementation: src/logic/combat/auto_weapon.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_auto_weapon); // "Main"
S(str_conditions_in_auto_weapon); // "Conditions"
S(str_activation_time_in_auto_weapon); // "activation_time"
S(str_require_mouse_pressed_in_auto_weapon); // "require_mouse_pressed"
D(auto_weapon_activation_time_setting); // setting num "activation_time"
D(auto_weapon_require_mouse_pressed_setting); // setting bool "require_mouse_pressed"
extern "C" void auto_weapon_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_auto_weapon);
W_slider(window, gui, auto_weapon_activation_time_setting);
W_label(gui, window, str_conditions_in_auto_weapon);
W_bool(window, gui, auto_weapon_require_mouse_pressed_setting);
}
extern "C" void auto_weapon_register(void *module) {
R_num(module, str_activation_time_in_auto_weapon, auto_weapon_activation_time_setting);
R_bool(module, str_require_mouse_pressed_in_auto_weapon, auto_weapon_require_mouse_pressed_setting);
}
+293
View File
@@ -0,0 +1,293 @@
// Backtrack - hit your target where it was a moment ago.
//
// While you fight a target in range, the movement packets the server sends about that
// target are held back for up to "delay" ms. On your screen the target stays where it was,
// which makes it easier to hit when it moves away. Packets are released once the hold time
// is up, when the target would be closer if released, or when you take knockback
// ("disable_on_hit"). A box can show where the target really is.
//
// Callbacks:
// backtrack_packet_hook_under every incoming packet (network thread): hold or release
// backtrack_render_box_held every frame: draw the box at the target's real position
// backtrack_tick_decide_whether every tick: start / keep / stop backtracking
#include "slinky/engine.h"
struct Vec3 { double x, y, z; };
struct Rot { float yaw, pitch; };
struct RenderHook {
char padding_00[8];
Vec3 cam; // +0x08 camera position
char padding_20[8];
float partial; // +0x28 how far we are between two ticks (0..1)
};
struct PktHook {
char padding_00[8];
void *ctx; // +0x08 JVM handle
void *ev; // +0x10 the packet
long long budget; // +0x18 ms the packet has been held so far
int seq; // +0x20 packet sequence number
int verdict; // +0x24 0 = let through, 1 = hold, 3 = let through even while holding
};
// ---- settings ----
extern "C" float backtrack_delay; // "delay": max hold (ms)
extern "C" float backtrack_cooldown; // "cooldown": ticks to wait after stopping
extern "C" float backtrack_max_target_hurt_time; // only while the target's hurt time is at most this
extern "C" float backtrack_min_max_range, backtrack_min_max_range_second; // target distance range (min, max)
extern "C" unsigned char backtrack_require_mouse_pressed_value; // "require_mouse_pressed"
extern "C" unsigned char backtrack_require_weapon_value; // "require_weapon"
extern "C" unsigned char backtrack_disable_on_hit_value; // "disable_on_hit": stop when we take knockback
extern "C" unsigned char backtrack_render_remote_pos; // "render_remote_pos": draw the box
extern "C" unsigned char backtrack_rotate_box; // turn the box with the target's yaw
extern "C" float backtrack_line_width_setting; // "line_width"
extern "C" float backtrack_color_setting[3]; // "color" (r, g, b)
extern "C" unsigned char backtrack_filled_setting; // "filled"
// ---- module state (shared with the network thread, guarded by the spin lock) ----
extern "C" unsigned char backtrack_spin_lock;
extern "C" unsigned char backtrack_active; // holding the target's packets
extern "C" long long backtrack_max_hold_budget; // "delay" as a whole number
extern "C" int backtrack_target_entity_id;
extern "C" int backtrack_own_entity_id;
extern "C" unsigned char backtrack_stop_on_velocity_setting; // copy of "disable_on_hit" for the network thread
extern "C" int backtrack_last_released_sequence;
extern "C" int backtrack_last_held_sequence;
extern "C" int backtrack_cooldown_ticks;
// The target's real (server-side) position, built from the held packets (see reach_distance_checks.cpp):
extern "C" Vec3 backtrack_accumulated_offset; // movement in the held packets (or an absolute position, see below)
extern "C" unsigned char backtrack_stop_on_velocity_setting_field_0x1f; // 1: the offset is an absolute position (a teleport was held)
extern "C" float backtrack_stop_on_velocity_setting_field_0x23; // yaw from the held packets
extern "C" unsigned char backtrack_stop_on_velocity_setting_field_0x27; // 1: that yaw is set
// For the box: real position and yaw, last tick / this tick / latest.
extern "C" unsigned char backtrack_render_box;
extern "C" Vec3 backtrack_previous_current_server_position; // last tick
extern "C" Vec3 backtrack_previous_current_server_position_in_reach_distance_checks_a; // this tick
extern "C" Vec3 backtrack_previous_current_server_position_in_reach_distance_checks; // latest
extern "C" float backtrack_yaws, backtrack_yaws_in_reach_distance_checks_a, backtrack_yaws_in_reach_distance_checks;
// ---- OpenGL ----
extern "C" void (**ptr_to_pGlLineWidth)(float);
extern "C" void (**ptr_to_pGlPushMatrix)();
extern "C" void (**ptr_to_pGlPopMatrix)();
extern "C" void (**ptr_to_pGlTranslatef)(float, float, float);
extern "C" void (**ptr_to_pGlScalef)(float, float, float);
extern "C" void (**ptr_to_pGlRotatef)(float, float, float, float);
extern "C" void (**ptr_to_pGlColor3f)(float, float, float);
extern "C" void (**ptr_to_pGlColor4f)(float, float, float, float);
FN(void, gl_array_xyz_float, ()); // set up the unit box vertex array
FN(void, gl_array_color1, ()); // draw it filled
FN(void, gl_array_color2, ()); // draw its outline
FN(void, disable_vertex_array_state, ());
// ---- game / engine functions ----
FN(Vec3, vec3_lerp, (Vec3 a, Vec3 b, double t));
FN(Vec3, vec3_sub, (Vec3 a, Vec3 b));
FN(Vec3, vec3_add, (Vec3 a, Vec3 b));
FN(Vec3, vec3_make, (double x, double y, double z));
FN(Vec3, vec3_add_eye_height_sneak, (Vec3 v));
FN(float, lerp_unclamped_float, (float a, float b, float t));
FN(unsigned char, vertex_pointer_current, (Ctx *ctx)); // a mouse button is held
FN(unsigned char, is_holding_accepted_weapon, (void *jvm, void *object));
FN(int, java_get_entity_living_base_last_attacker_time, (void *jvm, void *entity_living_base)); // tick of our last attack
FN(int, java_get_entity_ticks_existed, (void *jvm, void *entity));
FN(int, java_get_entity_living_base_hurt_time, (void *jvm, void *entity_living_base));
FN(Vec3, java_get_entity_pos_x, (void *jvm, void *entity));
FN(unsigned char, java_variant, (void *jvm));
FN(Vec3, java_get_entity_other_player_mp_other_player_mpx, (void *jvm, void *entity_other_player_mp)); // position the client shows
FN(Rot, get_entity_rotation, (void *jvm, void *entity));
FN(int, java_get_entity_entity_id, (void *jvm, void *entity));
FN(unsigned char, entity_reach_check, (Ctx *ctx, void *entity, Vec3 eye)); // worth starting? (see reach_distance_checks.cpp)
FN(double, segment_distance, (Vec3 eye, Vec3 pos, Vec3 off)); // how much further away the real position is
FN(void, backtrack_record_server_position, (Vec3 off, float yaw));
FN(void *, java_jni_is_instance_of_s19_packet_entity_status, (void *ctx, void *event));
FN(int, java_get_s19_packet_entity_status_entity_id, (void *ctx, void *s19_packet_entity_status));
FN(void *, java_jni_is_instance_of_s06_packet_update_health, (void *ctx, void *event));
FN(void *, java_jni_is_instance_of_s29_packet_sound_effect, (void *ctx, void *event));
FN(void *, java_jni_is_instance_of_s12_packet_entity_velocity, (void *ctx, void *event));
FN(int, java_get_s12_packet_entity_velocity_entity_id, (void *ctx, void *s12_packet_entity_velocity));
FN(void *, java_jni_is_instance_of_s08_packet_player_pos_look, (void *ctx, void *event)); // server teleported us
FN(void, check_entity_distance, (void **hook_ctx, unsigned char hold)); // track the target's movement in a packet
static void lock() {
while (__atomic_exchange_n(&backtrack_spin_lock, (unsigned char)1, __ATOMIC_SEQ_CST))
__builtin_ia32_pause();
}
static void unlock() { backtrack_spin_lock = 0; }
// Forget the tracked movement.
static void clear_tracked_offset() {
backtrack_accumulated_offset = vec3_make(0.0, 0.0, 0.0);
backtrack_stop_on_velocity_setting_field_0x1f = 0;
backtrack_stop_on_velocity_setting_field_0x27 = 0;
}
// Every incoming packet (network thread).
extern "C" void backtrack_packet_hook_under(PktHook *hook) {
lock();
if (backtrack_active == 1) {
// Hurt / health / sound packets about the target go through at once (hit feedback).
bool pass = false;
void *status = java_jni_is_instance_of_s19_packet_entity_status(hook->ctx, hook->ev);
if (status)
pass = java_get_s19_packet_entity_status_entity_id(hook->ctx, status) == backtrack_target_entity_id;
else
pass = java_jni_is_instance_of_s06_packet_update_health(hook->ctx, hook->ev) || java_jni_is_instance_of_s29_packet_sound_effect(hook->ctx, hook->ev);
if (pass) {
hook->verdict = 3;
unlock();
return;
}
// We were teleported, or took knockback with "disable_on_hit": stop.
bool stop = false;
void *velocity = java_jni_is_instance_of_s12_packet_entity_velocity(hook->ctx, hook->ev);
if (!velocity)
stop = java_jni_is_instance_of_s08_packet_player_pos_look(hook->ctx, hook->ev) != nullptr;
else
stop = backtrack_stop_on_velocity_setting && java_get_s12_packet_entity_velocity_entity_id(hook->ctx, velocity) == backtrack_own_entity_id;
if (stop) {
backtrack_active = 0;
unlock();
return;
}
if (hook->budget <= backtrack_max_hold_budget) {
// Hold it, and add its movement to the tracked offset (once per packet).
hook->verdict = 1;
int seq = hook->seq;
if (seq > backtrack_last_released_sequence) {
backtrack_last_released_sequence = seq;
check_entity_distance(&hook->ctx, 0);
}
} else if (hook->verdict == 0 && hook->seq > backtrack_last_held_sequence) {
// Held long enough: released now, take its movement back out of the offset.
check_entity_distance(&hook->ctx, 1);
backtrack_last_held_sequence = hook->seq;
}
}
unlock();
}
// Every frame: a box (0.6 wide, 2 tall) at the target's real position.
extern "C" void backtrack_render_box_held(RenderHook *hook) {
if (backtrack_render_box != 1)
return;
Vec3 pos = vec3_sub(vec3_lerp(backtrack_previous_current_server_position, backtrack_previous_current_server_position_in_reach_distance_checks_a, (double)hook->partial), hook->cam);
gl_array_xyz_float();
(*ptr_to_pGlLineWidth)(backtrack_line_width_setting);
(*ptr_to_pGlPushMatrix)();
(*ptr_to_pGlTranslatef)((float)pos.x, (float)(pos.y + 1.0), (float)pos.z);
(*ptr_to_pGlScalef)(0.3f, 1.0f, 0.3f);
if (backtrack_rotate_box == 1) {
float yaw = lerp_unclamped_float(backtrack_yaws, backtrack_yaws_in_reach_distance_checks_a, hook->partial);
(*ptr_to_pGlRotatef)(180.0f - yaw, 0.0f, 1.0f, 0.0f);
}
if (backtrack_filled_setting == 1) {
(*ptr_to_pGlColor4f)(backtrack_color_setting[0], backtrack_color_setting[1], backtrack_color_setting[2], 0.4f);
gl_array_color1();
}
(*ptr_to_pGlColor3f)(backtrack_color_setting[0], backtrack_color_setting[1], backtrack_color_setting[2]);
gl_array_color2();
(*ptr_to_pGlPopMatrix)();
disable_vertex_array_state();
}
// Are we fighting a target that is in range?
static bool should_backtrack(Ctx *ctx) {
if (ctx->in_game != 1)
return false;
if (backtrack_require_mouse_pressed_value == 1 && !vertex_pointer_current(ctx))
return false;
if (backtrack_require_weapon_value == 1 && !is_holding_accepted_weapon(ctx->jvm, ctx->player))
return false;
// We attacked in the last second.
int last_attack = java_get_entity_living_base_last_attacker_time(ctx->jvm, ctx->player);
if (java_get_entity_ticks_existed(ctx->jvm, ctx->player) - last_attack > 20)
return false;
CombatTarget *target = (CombatTarget *)ctx->target;
if (!target->ent)
return false;
if ((float)java_get_entity_living_base_hurt_time(ctx->jvm, target->ent) > backtrack_max_target_hurt_time)
return false;
double distance_sq = target->dist2;
if ((double)(backtrack_min_max_range * backtrack_min_max_range) > distance_sq ||
distance_sq > (double)(backtrack_min_max_range_second * backtrack_min_max_range_second))
return false;
return true;
}
// Every tick: start, keep or stop backtracking.
extern "C" void backtrack_tick_decide_whether(Hook *hook) {
Ctx *ctx = hook->ctx;
int cooldown = backtrack_cooldown_ticks;
if (cooldown > 0) {
backtrack_cooldown_ticks = cooldown - 1;
if (cooldown != 1)
return;
}
if (!should_backtrack(ctx)) {
lock();
if (backtrack_active == 1) {
backtrack_cooldown_ticks = (int)backtrack_cooldown;
backtrack_active = 0;
}
unlock();
backtrack_render_box = 0;
return;
}
void *target = ((CombatTarget *)ctx->target)->ent;
Vec3 eye = java_get_entity_pos_x(ctx->jvm, ctx->player);
if (java_variant(ctx->jvm))
eye = vec3_add_eye_height_sneak(eye);
Vec3 shown_pos = java_get_entity_other_player_mp_other_player_mpx(ctx->jvm, target);
float yaw = get_entity_rotation(ctx->jvm, target).yaw;
int target_id = java_get_entity_entity_id(ctx->jvm, target);
int own_id = java_get_entity_entity_id(ctx->jvm, ctx->player);
lock();
backtrack_max_hold_budget = (long long)backtrack_delay;
int old_target_id = backtrack_target_entity_id;
backtrack_target_entity_id = target_id;
backtrack_own_entity_id = own_id;
backtrack_stop_on_velocity_setting = backtrack_disable_on_hit_value;
if (backtrack_active != 1) {
// Not active yet: start if it is worth it, with the box at the target's current position.
if (!entity_reach_check(ctx, target, eye)) {
backtrack_render_box = 0;
unlock();
return;
}
backtrack_active = 1;
clear_tracked_offset();
Vec3 position = java_get_entity_pos_x(ctx->jvm, target);
backtrack_previous_current_server_position = position;
backtrack_previous_current_server_position_in_reach_distance_checks_a = position;
backtrack_previous_current_server_position_in_reach_distance_checks = position;
backtrack_yaws = yaw;
backtrack_yaws_in_reach_distance_checks_a = yaw;
backtrack_yaws_in_reach_distance_checks = yaw;
backtrack_render_box = backtrack_render_remote_pos;
unlock();
return;
}
// Active: where is the target really?
Vec3 real_offset = backtrack_stop_on_velocity_setting_field_0x1f == 1 ? backtrack_accumulated_offset : vec3_add(backtrack_accumulated_offset, shown_pos);
double further = segment_distance(eye, shown_pos, real_offset);
if (-0.05 > further || old_target_id != target_id) {
// Releasing would bring the target closer (or a new target): stop and cool down.
clear_tracked_offset();
backtrack_render_box = 0;
backtrack_active = 0;
backtrack_cooldown_ticks = (int)backtrack_cooldown;
unlock();
return;
}
backtrack_record_server_position(real_offset, backtrack_stop_on_velocity_setting_field_0x27 ? backtrack_stop_on_velocity_setting_field_0x23 : yaw);
unlock();
}
+78
View File
@@ -0,0 +1,78 @@
// Backtrack — Uses lag to make players easier to hit.
// category: combat descriptor: 0x2edad0 settings block: 0x2edcc8
// functions: gui backtrack_gui, register backtrack_register, status backtrack_status
// implementation: src/logic/combat/backtrack.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_backtrack); // "Main"
S(str_real_position_indicator); // "Real position indicator"
S(str_conditions_in_backtrack); // "Conditions"
S(str_target_dist); // "target_dist"
S(str_delay_in_backtrack); // "delay"
S(str_max_hurt_time_in_backtrack); // "max_hurt_time"
S(str_cooldown_in_backtrack); // "cooldown"
S(str_disable_on_hit); // "disable_on_hit"
S(str_render_remote_pos); // "render_remote_pos"
S(str_indicator_color); // "indicator_color"
S(str_indicator_line_width); // "indicator_line_width"
S(str_indicator_filled); // "indicator_filled"
S(str_indicator_rotate); // "indicator_rotate"
S(str_require_mouse_pressed_in_backtrack); // "require_mouse_pressed"
S(str_require_weapon_in_backtrack); // "require_weapon"
S(str_0fms); // "%.0fms"
D(backtrack_indicator_line_width_setting); // setting num "indicator_line_width"
D(backtrack_indicator_color_setting); // setting key "indicator_color"
D(backtrack_indicator_rotate_setting); // setting bool "indicator_rotate"
D(backtrack_indicator_filled_setting); // setting bool "indicator_filled"
D(backtrack_max_hurt_time_setting); // setting num "max_hurt_time"
D(backtrack_target_dist_setting); // setting rng "target_dist"
D(backtrack_delay_setting); // setting num "delay"
extern "C" float backtrack_delay; // current value of setting "delay" (+0x30)
D(backtrack_cooldown_setting); // setting num "cooldown"
D(backtrack_require_mouse_pressed_setting); // setting bool "require_mouse_pressed"
D(backtrack_require_weapon_setting); // setting bool "require_weapon"
D(backtrack_disable_on_hit_setting); // setting bool "disable_on_hit"
D(backtrack_render_remote_pos_setting); // setting bool "render_remote_pos"
D(backtrack_render_remote_pos); // current value of setting "render_remote_pos" (+0x18)
extern "C" void backtrack_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_backtrack);
W_range(window, gui, backtrack_target_dist_setting);
W_slider(window, gui, backtrack_delay_setting);
W_slider(window, gui, backtrack_max_hurt_time_setting);
W_slider(window, gui, backtrack_cooldown_setting);
W_bool(window, gui, backtrack_disable_on_hit_setting);
W_label(gui, window, str_real_position_indicator);
W_bool(window, gui, backtrack_render_remote_pos_setting);
if (*(unsigned char *)backtrack_render_remote_pos == 1) {
W_color(window, gui, backtrack_indicator_color_setting);
W_slider(window, gui, backtrack_indicator_line_width_setting);
W_bool(window, gui, backtrack_indicator_filled_setting);
W_bool(window, gui, backtrack_indicator_rotate_setting);
}
W_label(gui, window, str_conditions_in_backtrack);
W_bool(window, gui, backtrack_require_mouse_pressed_setting);
W_bool(window, gui, backtrack_require_weapon_setting);
}
extern "C" void backtrack_register(void *module) {
R_rng(module, str_target_dist, backtrack_target_dist_setting);
R_num(module, str_delay_in_backtrack, backtrack_delay_setting);
R_num(module, str_max_hurt_time_in_backtrack, backtrack_max_hurt_time_setting);
R_num(module, str_cooldown_in_backtrack, backtrack_cooldown_setting);
R_bool(module, str_disable_on_hit, backtrack_disable_on_hit_setting);
R_bool(module, str_render_remote_pos, backtrack_render_remote_pos_setting);
R_key(module, str_indicator_color, backtrack_indicator_color_setting);
R_num(module, str_indicator_line_width, backtrack_indicator_line_width_setting);
R_bool(module, str_indicator_filled, backtrack_indicator_filled_setting);
R_bool(module, str_indicator_rotate, backtrack_indicator_rotate_setting);
R_bool(module, str_require_mouse_pressed_in_backtrack, backtrack_require_mouse_pressed_setting);
R_bool(module, str_require_weapon_in_backtrack, backtrack_require_weapon_setting);
}
extern "C" void backtrack_status(void *self) {
log_fmt(self, 0x20, str_0fms, (double)backtrack_delay);
}
+208
View File
@@ -0,0 +1,208 @@
// Criticals - land critical hits more often.
//
// A hit is critical when you are falling. Two ways to get there ("mode"):
// 0 "packet": hold your movement packets back for up to "max_delay" ms while you fall,
// so the server still sees you falling when the hit arrives.
// 1 "timer": slow the game down while you fall onto the player under your crosshair,
// then speed it up again afterwards ("boost") to catch up.
// Each 10 ticks, "chance" decides whether the module helps for the next 10 ticks.
//
// Callbacks (descriptor slots +0x48 / +0x58 / +0x78 / +0x98):
// criticals_on_tick every tick: decide whether to act
// criticals_on_frame every frame: change the game speed (timer mode)
// criticals_on_packet_sent every movement packet: hold it back (packet mode)
// criticals_on_toggle module switched off: restore the game speed
#include "slinky/engine.h"
struct Vec3 { double x, y, z; };
struct PktHook {
char padding_00[8];
void *ctx; // +0x08 JVM handle
void *ev; // +0x10 the packet
long long budget; // +0x18 ms the packet has been held so far
int seq; // +0x20 packet sequence number
int verdict; // +0x24 set to 1 to keep holding it
};
struct EvHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
void *ev; // +0x10 module descriptor that was toggled
unsigned char on; // +0x18 1 = switched on
};
struct TimerHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
char padding_10[8];
double dt; // +0x18 seconds since the last frame
};
// ---- settings ----
enum CriticalsMode { MODE_PACKET = 0, MODE_TIMER = 1 };
extern "C" unsigned criticals_mode; // "mode"
extern "C" float criticals_max_delay_value; // "max_delay" (ms, packet mode)
extern "C" float criticals_chance_value; // "chance"
extern "C" unsigned char criticals_require_mouse_pressed_value; // "require_mouse_pressed"
extern "C" unsigned char criticals_require_weapon_value; // "require_weapon"
extern "C" float criticals_timer_speed_value; // "timer_speed": game speed while falling (timer mode)
extern "C" float criticals_boost_value; // "boost": max ticks to catch up afterwards
// ---- module state ----
extern "C" char criticals_module_descriptor[];
// Shared with the network thread, so read/written atomically.
extern "C" unsigned char criticals_packet_mode_armed; // packet mode is active
extern "C" unsigned short criticals_packet_delay; // max hold time (ms)
extern "C" unsigned char criticals_timer_mode_armed; // timer mode is slowing the game this tick
extern "C" int criticals_roll_cooldown; // ticks until the next "chance" roll
extern "C" unsigned char criticals_last_roll; // result of the last roll
extern "C" unsigned char criticals_timer_modified; // we changed the game speed
extern "C" double criticals_accumulated_boost; // ticks to catch up on
extern "C" int criticals_current_hold_budget; // how long packets may be held (ms)
extern "C" double criticals_last_y; // y in the last movement packet
extern "C" int criticals_last_sequence; // sequence number of the last packet seen
extern "C" unsigned char criticals_falling; // the last packets show us falling
// ---- game / engine functions ----
FN(unsigned char, random_chance, (float chance));
FN(unsigned char, vertex_pointer_current, (Ctx *ctx)); // a mouse button is held
FN(unsigned char, is_holding_accepted_weapon, (void *jvm, void *object));
FN(int, java_get_entity_living_base_last_attacker_time, (void *jvm, void *entity_living_base)); // tick of our last attack
FN(int, java_get_entity_ticks_existed, (void *jvm, void *entity));
FN(unsigned char, java_get_entity_on_ground, (void *jvm, void *entity));
FN(Vec3, java_get_entity_motion_x, (void *jvm, void *entity));
FN(int, java_get_entity_living_base_hurt_time, (void *jvm, void *entity_living_base));
FN(void *, java_get_minecraft_object_mouse_over, (void *jvm, void *minecraft));
FN(int, java_get_moving_object_position_type_ordinal, (void *jvm, void *moving_object_position)); // 2 = an entity
FN(void *, get_timer, (void *jvm, void *timer)); // the game's tick timer
FN(void, java_set_timer_timer_speed, (void *jvm, void *timer, float speed));
FN(float, java_get_timer_elapsed_partial_ticks, (void *jvm, void *timer));
FN(void, java_set_timer_elapsed_partial_ticks, (void *jvm, void *timer, float value));
FN(void *, java_jni_is_instance_of_c03_packet_player, (void *ctx, void *event)); // movement packet, or null
FN(unsigned char, java_get_c03_packet_player_moving, (void *ctx, void *c03_packet_player)); // contains a position
FN(double, java_get_c03_packet_player_b, (void *ctx, void *c03_packet_player)); // its y
FN(unsigned char, java_get_c03_packet_player_on_ground, (void *ctx, void *c03_packet_player));
// Every tick: should the module help right now?
static bool should_act(Ctx *ctx) {
if (ctx->in_game != 1)
return false;
// Roll "chance" once every 10 ticks.
int cooldown = criticals_roll_cooldown;
if (cooldown != 0) {
unsigned char last_roll = criticals_last_roll;
criticals_roll_cooldown = cooldown - 1;
if (last_roll != 1)
return false;
} else {
criticals_roll_cooldown = 10;
unsigned char roll = random_chance(criticals_chance_value);
criticals_last_roll = roll;
criticals_roll_cooldown += -1;
if (!roll)
return false;
}
if (criticals_require_mouse_pressed_value == 1 && !vertex_pointer_current(ctx))
return false;
if (criticals_require_weapon_value == 1 && !is_holding_accepted_weapon(ctx->jvm, ctx->player))
return false;
// Only while fighting: we attacked in the last 10 ticks.
int last_attack = java_get_entity_living_base_last_attacker_time(ctx->jvm, ctx->player);
return java_get_entity_ticks_existed(ctx->jvm, ctx->player) - last_attack < 11;
}
extern "C" void criticals_on_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
bool act = should_act(ctx);
if (criticals_mode == MODE_PACKET) {
__atomic_exchange_n(&criticals_packet_mode_armed, (unsigned char)act, __ATOMIC_SEQ_CST);
__atomic_exchange_n(&criticals_packet_delay, (unsigned short)(int)criticals_max_delay_value, __ATOMIC_SEQ_CST);
criticals_timer_mode_armed = 0;
return;
}
if (criticals_mode != MODE_TIMER)
return;
__atomic_exchange_n(&criticals_packet_mode_armed, (unsigned char)0, __ATOMIC_SEQ_CST);
// Timer mode: slow down while falling (not just hit) onto the entity under the crosshair.
unsigned char slow_down = 0;
if (act && !java_get_entity_on_ground(ctx->jvm, ctx->player) &&
java_get_entity_motion_x(ctx->jvm, ctx->player).y < 0.0 &&
java_get_entity_living_base_hurt_time(ctx->jvm, ctx->player) != 10) {
void *hit = java_get_minecraft_object_mouse_over(ctx->jvm, ctx->minecraft);
if (hit)
slow_down = java_get_moving_object_position_type_ordinal(ctx->jvm, hit) == 2;
}
criticals_timer_mode_armed = slow_down;
}
// Every frame (timer mode).
extern "C" void criticals_on_frame(TimerHook *hook) {
Ctx *ctx = hook->ctx;
void *timer = get_timer(ctx->jvm, ctx->minecraft);
if (criticals_timer_mode_armed == 1) {
// Slow the game down, and remember how many ticks we lose (up to "boost").
java_set_timer_timer_speed(ctx->jvm, timer, criticals_timer_speed_value);
criticals_timer_modified = 1;
double ticks_this_frame = hook->dt * 20.0;
double lost = (double)(1.0f - criticals_timer_speed_value) * ticks_this_frame + criticals_accumulated_boost;
criticals_accumulated_boost = lost;
if (lost > (double)criticals_boost_value)
criticals_accumulated_boost = criticals_boost_value;
return;
}
// Not slowing down: catch up on the lost ticks, whole ticks at a time.
double lost = criticals_accumulated_boost;
if (lost > 1.0) {
float partial = java_get_timer_elapsed_partial_ticks(ctx->jvm, timer);
int whole_ticks = (int)lost;
java_set_timer_elapsed_partial_ticks(ctx->jvm, timer, (float)whole_ticks + partial);
criticals_accumulated_boost -= (double)whole_ticks;
}
if (criticals_timer_modified == 1) {
java_set_timer_timer_speed(ctx->jvm, timer, 1.0f);
criticals_timer_modified = 0;
}
}
// Every outgoing packet (packet mode, runs on the network thread).
extern "C" void criticals_on_packet_sent(PktHook *hook) {
void *packet = java_jni_is_instance_of_c03_packet_player(hook->ctx, hook->ev);
if (packet && java_get_c03_packet_player_moving(hook->ctx, packet) && hook->seq > criticals_last_sequence) {
// A new movement packet: are we falling?
double y = java_get_c03_packet_player_b(hook->ctx, packet);
unsigned char on_ground = java_get_c03_packet_player_on_ground(hook->ctx, packet);
if (on_ground || criticals_last_y > y)
criticals_falling = on_ground ^ 1;
// While falling, allow holding packets a bit longer each time (1/5 of the max), up to the max.
int hold = 0;
if ((__atomic_load_n(&criticals_packet_mode_armed, __ATOMIC_SEQ_CST) & 1) && (criticals_falling & 1)) {
hold = __atomic_load_n(&criticals_packet_delay, __ATOMIC_SEQ_CST) / 5 + criticals_current_hold_budget;
if (hold > (int)__atomic_load_n(&criticals_packet_delay, __ATOMIC_SEQ_CST))
hold = __atomic_load_n(&criticals_packet_delay, __ATOMIC_SEQ_CST);
}
criticals_current_hold_budget = hold;
criticals_last_y = y;
criticals_last_sequence = hook->seq;
}
// Keep holding the packet while it has been held for less than the budget.
if (hook->budget < (long long)criticals_current_hold_budget)
hook->verdict = 1;
}
// On disable: restore normal game speed.
extern "C" void criticals_on_toggle(EvHook *hook) {
if (hook->ev != criticals_module_descriptor || hook->on || !(criticals_timer_modified & 1))
return;
Ctx *ctx = hook->ctx;
void *timer = get_timer(ctx->jvm, ctx->minecraft);
java_set_timer_timer_speed(ctx->jvm, timer, 1.0f);
criticals_timer_modified = 0;
}
+57
View File
@@ -0,0 +1,57 @@
// Criticals — Increases chance of landing critical hits.
// category: combat descriptor: 0x2ec010 settings block: 0x2ec208
// functions: gui criticals_gui, register criticals_register, status criticals_status
// implementation: src/logic/combat/criticals.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_criticals); // "Main"
S(str_conditions_in_criticals); // "Conditions"
S(str_mode_in_criticals); // "mode"
S(str_chance_in_criticals); // "chance"
S(str_max_delay); // "max_delay"
S(str_timer_speed_in_criticals); // "timer_speed"
S(str_boost_in_criticals); // "boost"
S(str_require_weapon_in_criticals); // "require_weapon"
S(str_require_mouse_pressed_in_criticals); // "require_mouse_pressed"
S(str_s_in_criticals); // "%s"
D(criticals_max_delay_setting); // setting num "max_delay"
D(criticals_chance_setting); // setting num "chance"
D(criticals_require_mouse_pressed_setting); // setting bool "require_mouse_pressed"
D(criticals_require_weapon_setting); // setting bool "require_weapon"
D(criticals_enum_option_labels_1); // enum option labels (const char *[])
D(criticals_mode_setting); // setting enum "mode"
extern "C" unsigned criticals_mode; // current value of setting "mode" (+0x30)
D(criticals_timer_speed_setting); // setting num "timer_speed"
D(criticals_boost_setting); // setting num "boost"
extern "C" void criticals_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_criticals);
W_enumw(window, gui, criticals_mode_setting);
W_slider(window, gui, criticals_chance_setting);
if (criticals_mode != 0) {
W_slider(window, gui, criticals_timer_speed_setting);
W_slider(window, gui, criticals_boost_setting);
} else {
W_slider(window, gui, criticals_max_delay_setting);
}
W_label(gui, window, str_conditions_in_criticals);
W_bool(window, gui, criticals_require_weapon_setting);
W_bool(window, gui, criticals_require_mouse_pressed_setting);
}
extern "C" void criticals_register(void *module) {
R_enum(module, str_mode_in_criticals, criticals_mode_setting);
R_num(module, str_chance_in_criticals, criticals_chance_setting);
R_num(module, str_max_delay, criticals_max_delay_setting);
R_num(module, str_timer_speed_in_criticals, criticals_timer_speed_setting);
R_num(module, str_boost_in_criticals, criticals_boost_setting);
R_bool(module, str_require_weapon_in_criticals, criticals_require_weapon_setting);
R_bool(module, str_require_mouse_pressed_in_criticals, criticals_require_mouse_pressed_setting);
}
extern "C" void criticals_status(void *self) {
log_fmt(self, 0x20, str_s_in_criticals, ((const char **)criticals_enum_option_labels_1)[criticals_mode]);
}
+253
View File
@@ -0,0 +1,253 @@
// Hit Select - skip bad hits so you win more trades.
//
// Not every click should hit: hitting at the wrong moment gives the other player the
// first hit back, or wastes a combo. This module cancels some of your attacks, based on
// timing ("pause_dur", "trades_delay", ...) and "cancel_rate".
//
// Two modes:
// 0: wait until the target can take damage again, and don't trade hits while being comboed
// 1: prefer hits while falling (critical hits), cancel ones that would reduce your knockback
//
// Callbacks (descriptor slots +0x48 / +0x128 / +0x158):
// hit_select_on_tick every tick: count calm ticks (not hurt)
// hit_select_on_attack every attack: allow or cancel it (decided once per tick)
// hit_select_on_player_update every player tick: track when the target was last hit
#include "slinky/engine.h"
struct Vec3 { double x, y, z; };
struct AttackHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
unsigned char phase; // +0x10 1 = the attack is about to happen
unsigned char cancel; // +0x11 set to 1 to cancel it
};
// ---- settings ----
extern "C" unsigned hit_select_mode; // "mode"
extern "C" float hit_select_cancel_rate_value; // "cancel_rate": chance to cancel a bad hit
extern "C" float hit_select_cancel_rate_air_value; // "cancel_rate_air": chance to cancel a click on nothing
extern "C" float hit_select_pause_dur_value; // "pause_dur": ticks to wait after the target was hit
extern "C" float hit_select_wait_for_damage_dur_value; // "wait_for_damage_dur"
extern "C" float hit_select_trades_delay_value; // "trades_delay": extra wait while we are being hit
extern "C" unsigned char hit_select_use_server_time_value; // "use_server_time": use the target's hurt time
extern "C" unsigned char hit_select_fake_swing_value; // "fake_swing": swing the arm on cancelled hits
extern "C" unsigned char hit_select_crits_allow_reduce_value; // "crits_allow_reduce"
extern "C" unsigned char hit_select_require_damage_value; // "require_damage"
extern "C" unsigned char hit_select_require_sprint_value; // "require_sprint"
extern "C" unsigned char hit_select_require_weapon_value; // "require_weapon"
// ---- module state ----
extern "C" unsigned char hit_select_decided_this_tick;
extern "C" unsigned char hit_select_cancel; // decision for this tick
extern "C" int hit_select_calm_ticks; // ticks since we were last hurt (on the ground)
extern "C" unsigned hit_select_ticks_since_target_was_hit;
extern "C" unsigned hit_select_wait_damage_counter;
extern "C" unsigned char hit_select_target_just_got_hit;
extern "C" int hit_select_last_target_id;
// ---- game / engine functions ----
FN(int, java_get_entity_living_base_hurt_time, (void *jvm, void *entity_living_base)); // 10 on the tick of being hit
FN(unsigned char, java_call_entity_player_is_using_item, (void *jvm, void *entity_player));
FN(void, java_jni_call_nonvirtual_void_method_entity_living_base_swing_item, (void *jvm, void *object));
FN(unsigned char, java_call_entity_is_sprinting, (void *jvm, void *entity));
FN(unsigned char, is_holding_accepted_weapon, (void *jvm, void *object));
FN(void *, java_get_minecraft_object_mouse_over, (void *jvm, void *minecraft));
FN(int, java_get_moving_object_position_type_ordinal, (void *jvm, void *moving_object_position)); // 0 = nothing, 1 = block, 2 = entity
FN(void *, java_get_moving_object_position_entity_hit, (void *jvm, void *moving_object_position));
FN(unsigned char, random_chance, (float chance));
FN(unsigned char, java_get_entity_on_ground, (void *jvm, void *entity));
FN(Vec3, java_get_entity_motion_x, (void *jvm, void *entity));
FN(float, java_get_entity_fall_distance, (void *jvm, void *entity));
FN(Vec3, java_get_entity_pos_x, (void *jvm, void *entity));
FN(unsigned char, java_variant, (void *jvm));
FN(Vec3, vec3_add_eye_height_sneak, (Vec3 v));
FN(double, libc_floor, (double v));
FN(void *, java_call_variant, (void *jvm, void *world, int x, int y, int z)); // block at x, y, z
FN(int, get_block_id, (void *jvm, void *blk));
FN(int, java_get_entity_entity_id, (void *jvm, void *entity));
FN(int, java_get_entity_ticks_existed, (void *jvm, void *entity));
FN(int, java_get_entity_living_base_last_attacker_time, (void *jvm, void *entity_living_base)); // tick of our last attack
// Round a tick count randomly: 2.3 gives 3 with a 30% chance, else 2.
static unsigned random_round(float value) {
unsigned whole = (unsigned)(long long)value;
return random_chance(value - (float)(unsigned long long)whole) + whole;
}
extern "C" void hit_select_on_tick(Hook *hook) {
hit_select_decided_this_tick = 0;
Ctx *ctx = hook->ctx;
int calm = 0;
if (ctx->in_game == 1 && java_get_entity_living_base_hurt_time(ctx->jvm, ctx->player) == 0)
calm = hit_select_calm_ticks + 1;
hit_select_calm_ticks = calm;
}
enum Decision {
ALLOW, // let the hit through
CANCEL, // cancel it
ROLL, // too early: cancel with "cancel_rate" chance, unless the pause is over
};
// Decide about this attack. For ROLL, *pause_ticks is how long to wait after the target was hit.
static Decision decide(Ctx *ctx, unsigned *pause_ticks) {
if (hit_select_require_sprint_value == 1 && !java_call_entity_is_sprinting(ctx->jvm, ctx->player))
return ALLOW;
if (hit_select_require_weapon_value == 1 && !is_holding_accepted_weapon(ctx->jvm, ctx->player))
return ALLOW;
// What is under the crosshair?
bool no_entity = true;
void *hit = java_get_minecraft_object_mouse_over(ctx->jvm, ctx->minecraft);
if (hit) {
switch (java_get_moving_object_position_type_ordinal(ctx->jvm, hit)) {
case 2: // an entity
no_entity = java_get_moving_object_position_entity_hit(ctx->jvm, hit) == nullptr;
break;
case 1: // a block: always allow (mining)
return ALLOW;
case 0: // nothing
if (random_chance(hit_select_cancel_rate_air_value))
return CANCEL;
break;
}
}
unsigned pause = random_round(hit_select_pause_dur_value);
*pause_ticks = pause;
// Going up (jumping) while having a target.
unsigned char rising = 1;
unsigned char on_ground = java_get_entity_on_ground(ctx->jvm, ctx->player);
if (on_ground)
rising = java_get_entity_motion_x(ctx->jvm, ctx->player).y > 0.0;
rising &= ((CombatTarget *)ctx->target)->valid;
if (hit_select_mode == 1) {
// Outside the 2..8 tick window after the target was hit (or using server time).
unsigned char outside_window = (hit_select_ticks_since_target_was_hit - 9 < (unsigned)-7) | hit_select_use_server_time_value;
unsigned char falling;
if (on_ground) {
falling = 0;
} else {
falling = java_get_entity_fall_distance(ctx->jvm, ctx->player) > 0.0f;
if (falling & outside_window)
return ALLOW; // a critical hit
}
if (rising && (!outside_window || hit_select_crits_allow_reduce_value))
return ALLOW;
// A block at head height (we can't jump): allow.
Vec3 pos = java_get_entity_pos_x(ctx->jvm, ctx->player);
if (java_variant(ctx->jvm))
pos = vec3_add_eye_height_sneak(pos);
int x = (int)libc_floor(pos.x);
int y = (int)libc_floor(pos.y);
int z = (int)libc_floor(pos.z);
if (get_block_id(ctx->jvm, java_call_variant(ctx->jvm, ctx->world, x, y, z)) != 0)
return ALLOW;
if (on_ground | falling)
return ROLL;
if (hit_select_require_damage_value != 1 || java_get_entity_living_base_hurt_time(ctx->jvm, ctx->player) != 0)
return CANCEL; // rising in the air: wait for the fall
return ROLL;
}
if (hit_select_mode != 0 || rising)
return ALLOW;
// Mode 0. Right after the target was hit, wait "wait_for_damage_dur" ticks.
if (hit_select_ticks_since_target_was_hit < 15) {
hit_select_wait_damage_counter = 0;
} else if (!no_entity) {
unsigned waited = hit_select_wait_damage_counter + 1;
hit_select_wait_damage_counter = waited;
if (waited <= random_round(hit_select_wait_for_damage_dur_value))
return CANCEL;
}
// Being hit ourselves recently: wait longer before trading.
if ((unsigned)hit_select_calm_ticks <= 9)
*pause_ticks = pause + random_round(hit_select_trades_delay_value);
if (hit_select_target_just_got_hit == 1) {
hit_select_target_just_got_hit = 0;
return ALLOW;
}
return ROLL;
}
// Cancel the attack (and optionally swing the arm anyway, so it looks normal).
static void cancel_attack(AttackHook *hook, Ctx *ctx) {
hook->cancel = 1;
if (hit_select_fake_swing_value == 1 && ctx->player && !java_call_entity_player_is_using_item(ctx->jvm, ctx->player))
java_jni_call_nonvirtual_void_method_entity_living_base_swing_item(ctx->jvm, ctx->player);
}
extern "C" void hit_select_on_attack(AttackHook *hook) {
if (hook->phase != 1)
return;
Ctx *ctx = hook->ctx;
// Already decided this tick: do the same again.
if (hit_select_decided_this_tick == 1) {
if (hit_select_cancel)
cancel_attack(hook, ctx);
return;
}
unsigned pause_ticks = 0;
Decision decision = decide(ctx, &pause_ticks);
if (decision == ROLL) {
if (pause_ticks <= hit_select_ticks_since_target_was_hit + 1) {
decision = ALLOW; // the pause is over
} else {
unsigned char cancel = random_chance(hit_select_cancel_rate_value);
hit_select_cancel = cancel;
hit_select_decided_this_tick = 1;
if (cancel)
cancel_attack(hook, ctx);
return;
}
}
hit_select_decided_this_tick = 1;
if (decision == ALLOW) {
hit_select_cancel = 0;
return;
}
hit_select_cancel = 1;
cancel_attack(hook, ctx);
}
// Every player tick: count the ticks since the target was last hit.
extern "C" void hit_select_on_player_update(Hook *hook) {
Ctx *ctx = hook->ctx;
void *target = ((CombatTarget *)ctx->target)->ent;
if (hit_select_use_server_time_value == 1) {
// Server time: the target's hurt time is 10 on the tick it was hit.
if (target && java_get_entity_living_base_hurt_time(ctx->jvm, target) == 10) {
hit_select_ticks_since_target_was_hit = 0;
hit_select_target_just_got_hit = 1;
return;
}
hit_select_ticks_since_target_was_hit += 1;
return;
}
// Our own time: the tick we last attacked.
int target_id = target ? java_get_entity_entity_id(ctx->jvm, target) : 0;
if (target_id == hit_select_last_target_id) {
unsigned ticks = hit_select_ticks_since_target_was_hit + 1;
hit_select_ticks_since_target_was_hit = ticks;
if (ticks < 10)
return;
} else {
// New target: "long ago".
hit_select_last_target_id = target_id;
hit_select_ticks_since_target_was_hit = 1001;
}
if (java_get_entity_ticks_existed(ctx->jvm, ctx->player) == java_get_entity_living_base_last_attacker_time(ctx->jvm, ctx->player))
hit_select_ticks_since_target_was_hit = 0;
}
+80
View File
@@ -0,0 +1,80 @@
// Hit Select — Perfectly times your hits.
// category: combat descriptor: 0x2ee4f0 settings block: 0x2ee6e8
// functions: gui hit_select_gui, register hit_select_register, status hit_select_status
// implementation: src/logic/combat/hit_select.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_hit_select); // "Main"
S(str_cancel_rate); // "Cancel rate"
S(str_conditions_in_hit_select); // "Conditions"
S(str_mode_in_hit_select); // "mode"
S(str_cancel_rate_in_hit_select); // "cancel_rate"
S(str_cancel_rate_air); // "cancel_rate_air"
S(str_pause_dur); // "pause_dur"
S(str_wait_for_damage_dur); // "wait_for_damage_dur"
S(str_trades_delay); // "trades_delay"
S(str_use_server_time); // "use_server_time"
S(str_fake_swing_in_hit_select); // "fake_swing"
S(str_crits_allow_reduce); // "crits_allow_reduce"
S(str_require_damage_in_hit_select); // "require_damage"
S(str_require_sprint_in_hit_select); // "require_sprint"
S(str_require_weapon_in_hit_select); // "require_weapon"
S(str_s_in_hit_select); // "%s"
D(hit_select_cancel_rate_air_setting); // setting num "cancel_rate_air"
D(hit_select_pause_dur_setting); // setting num "pause_dur"
D(hit_select_wait_for_damage_dur_setting); // setting num "wait_for_damage_dur"
D(hit_select_trades_delay_setting); // setting num "trades_delay"
D(hit_select_cancel_rate_setting); // setting num "cancel_rate"
D(hit_select_require_sprint_setting); // setting bool "require_sprint"
D(hit_select_require_weapon_setting); // setting bool "require_weapon"
D(hit_select_enum_option_labels_1); // enum option labels (const char *[])
D(hit_select_mode_setting); // setting enum "mode"
extern "C" unsigned hit_select_mode; // current value of setting "mode" (+0x30)
D(hit_select_use_server_time_setting); // setting bool "use_server_time"
D(hit_select_crits_allow_reduce_setting); // setting bool "crits_allow_reduce"
D(hit_select_require_damage_setting); // setting bool "require_damage"
D(hit_select_fake_swing_setting); // setting bool "fake_swing"
extern "C" void hit_select_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_hit_select);
W_enumw(window, gui, hit_select_mode_setting);
W_slider(window, gui, hit_select_pause_dur_setting);
if (hit_select_mode == 0) {
W_slider(window, gui, hit_select_wait_for_damage_dur_setting);
W_slider(window, gui, hit_select_trades_delay_setting);
}
W_bool(window, gui, hit_select_use_server_time_setting);
W_bool(window, gui, hit_select_fake_swing_setting);
if (hit_select_mode == 1) {
W_bool(window, gui, hit_select_crits_allow_reduce_setting);
W_bool(window, gui, hit_select_require_damage_setting);
}
W_label(gui, window, str_cancel_rate);
W_slider(window, gui, hit_select_cancel_rate_setting);
W_slider(window, gui, hit_select_cancel_rate_air_setting);
W_label(gui, window, str_conditions_in_hit_select);
W_bool(window, gui, hit_select_require_sprint_setting);
W_bool(window, gui, hit_select_require_weapon_setting);
}
extern "C" void hit_select_register(void *module) {
R_enum(module, str_mode_in_hit_select, hit_select_mode_setting);
R_num(module, str_cancel_rate_in_hit_select, hit_select_cancel_rate_setting);
R_num(module, str_cancel_rate_air, hit_select_cancel_rate_air_setting);
R_num(module, str_pause_dur, hit_select_pause_dur_setting);
R_num(module, str_wait_for_damage_dur, hit_select_wait_for_damage_dur_setting);
R_num(module, str_trades_delay, hit_select_trades_delay_setting);
R_bool(module, str_use_server_time, hit_select_use_server_time_setting);
R_bool(module, str_fake_swing_in_hit_select, hit_select_fake_swing_setting);
R_bool(module, str_crits_allow_reduce, hit_select_crits_allow_reduce_setting);
R_bool(module, str_require_damage_in_hit_select, hit_select_require_damage_setting);
R_bool(module, str_require_sprint_in_hit_select, hit_select_require_sprint_setting);
R_bool(module, str_require_weapon_in_hit_select, hit_select_require_weapon_setting);
}
extern "C" void hit_select_status(void *self) {
log_fmt(self, 0x20, str_s_in_hit_select, ((const char **)hit_select_enum_option_labels_1)[hit_select_mode]);
}
+23
View File
@@ -0,0 +1,23 @@
// Hitboxes - make other players' hitboxes bigger, so they are easier to hit.
//
// The engine asks every tick how much to grow hitboxes by; this answers with "expand".
//
// Callback (descriptor slot +0xc8):
// hitboxes_on_reach_query every tick
#include "slinky/engine.h"
// ---- settings ----
extern "C" float hitboxes_expand; // "expand": blocks added on each side
// The engine's question, filled in by the callback.
struct HitboxState {
char padding_00[0x10];
bool active; // +0x10 set to true to expand hitboxes
char padding_11[0xf];
double expand; // +0x20 how much
};
extern "C" void hitboxes_on_reach_query(HitboxState *s) {
s->active = true;
s->expand = (double)hitboxes_expand;
}
+27
View File
@@ -0,0 +1,27 @@
// Hitboxes — Expands hitboxes of other players.
// category: combat descriptor: 0x2ecca8 settings block: 0x2ecea0
// functions: gui hitboxes_gui, register hitboxes_register, status hitboxes_status
// implementation: src/logic/combat/hitboxes.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_hitboxes); // "Main"
S(str_expand_in_hitboxes); // "expand"
S(str_2f_in_hitboxes); // "%.2f"
D(hitboxes_expand_setting); // setting num "expand"
extern "C" float hitboxes_expand; // current value of setting "expand" (+0x30)
extern "C" void hitboxes_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_hitboxes);
W_slider(window, gui, hitboxes_expand_setting);
}
extern "C" void hitboxes_register(void *module) {
R_num(module, str_expand_in_hitboxes, hitboxes_expand_setting);
}
extern "C" void hitboxes_status(void *self) {
log_fmt(self, 0x20, str_2f_in_hitboxes, (double)hitboxes_expand);
}
+188
View File
@@ -0,0 +1,188 @@
// Knockback Delay - take knockback later than you should.
//
// When the server sends you knockback, this module holds that packet (and everything that
// arrives after it) for up to "max_delay" ms before the game sees it. That keeps you in
// place a little longer during a fight. Only when the conditions allow: in the air, holding
// a weapon, a target in range, ..., and "chance".
//
// Callbacks (descriptor slots +0x68 / +0x168):
// knockback_delay_on_packet_received every incoming packet (network thread): hold or release
// knockback_delay_on_late_tick every tick: decide whether delaying is allowed
#include "slinky/engine.h"
#include "slinky/jids.h"
struct Vec3 { double x, y, z; };
struct Rot { float yaw, pitch; };
struct Range { float lo, hi; };
struct PktHook {
char padding_00[8];
void *ctx; // +0x08 JVM handle
void *ev; // +0x10 the packet
long long budget; // +0x18 ms the packet has been held so far
int id; // +0x20 id of the batch of packets it arrived in
int verdict; // +0x24 0 = let through, 1 = hold, 3 = hold (and it is a hurt/health/sound packet)
};
// ---- settings ----
extern "C" float knockback_delay_max_delay; // "max_delay" (ms)
extern "C" unsigned char knockback_delay_require_air_value; // "require_air"
extern "C" float knockback_delay_range_value; // "range": target must be this close
extern "C" unsigned char knockback_delay_require_weapon_value; // "require_weapon"
extern "C" unsigned char knockback_delay_require_mouse_value; // "require_mouse"
extern "C" unsigned char knockback_delay_require_target_value; // "require_target": a player within 6 blocks in front of us
extern "C" float knockback_delay_chance_value; // "chance"
// ---- module state (shared with the network thread) ----
extern "C" unsigned char knockback_delay_holding; // packets are being held
extern "C" int knockback_delay_held_transaction_id; // batch id of the held knockback packet
extern "C" unsigned char knockback_delay_air; // "require_air" is on and we are in the air
extern "C" unsigned char knockback_delay_allowed; // conditions say delaying is allowed
extern "C" unsigned short knockback_delay_max_delay_second; // "max_delay" as a whole number
extern "C" int knockback_delay_own_entity_id;
extern "C" char knockback_delay_random_walk_1[]; // random walk state
// ---- game / engine functions ----
FN(void *, java_jni_is_instance_of_s12_packet_entity_velocity, (void *ctx, void *event)); // knockback packet, or null
FN(int, java_get_s12_packet_entity_velocity_entity_id, (void *ctx, void *pkt));
FN(void *, java_jni_is_instance_of_s19_packet_entity_status, (void *ctx, void *event));
FN(void *, java_jni_is_instance_of_s06_packet_update_health, (void *ctx, void *event));
FN(void *, java_jni_is_instance_of_s29_packet_sound_effect, (void *ctx, void *event));
FN(int, java_get_entity_entity_id, (void *jvm, void *entity));
FN(unsigned char, java_get_entity_on_ground, (void *jvm, void *entity));
FN(unsigned char, is_holding_accepted_weapon, (void *jvm, void *object));
FN(unsigned char, vertex_pointer_current, (Ctx *ctx)); // a mouse button is held
FN(Vec3, java_get_entity_pos_x, (void *jvm, void *entity));
FN(Rot, get_entity_rotation, (void *jvm, void *entity));
FN(void *, java_get_world_player_entities, (void *jvm, void *world));
FN(int, java_call_list_size, (void *jvm, void *list));
FN(void *, java_call_list_get, (void *jvm, void *list, int i));
FN(double, vec3_distance_sq, (Vec3 a, Vec3 b));
FN(Rot, rot_look_at, (Vec3 from, Vec3 to));
FN(float, wrap_angle, (float a)); // to -180..180
FN(Range, rot_make_floats, (float lo, float hi));
FN(unsigned char, walk_should_change, (void *state, Range r, double p)); // random yes/no
// Stop holding and forget the held packet.
static void stop_holding() {
knockback_delay_holding = 0;
__atomic_exchange_n(&knockback_delay_allowed, (unsigned char)0, __ATOMIC_SEQ_CST);
knockback_delay_held_transaction_id = 0;
}
// Every incoming packet (network thread).
extern "C" void knockback_delay_on_packet_received(PktHook *hook) {
if (hook->verdict != 0)
return;
// Is it knockback for us?
bool our_knockback = false;
void *velocity = java_jni_is_instance_of_s12_packet_entity_velocity(hook->ctx, hook->ev);
if (velocity)
our_knockback = java_get_s12_packet_entity_velocity_entity_id(hook->ctx, velocity) == __atomic_load_n(&knockback_delay_own_entity_id, __ATOMIC_SEQ_CST);
// Should this packet be held?
unsigned char hold;
if (__atomic_load_n(&knockback_delay_air, __ATOMIC_SEQ_CST) & 1) {
// In the air: start holding with the first packet of a batch.
hold = hook->budget == 0 ? (__atomic_load_n(&knockback_delay_allowed, __ATOMIC_SEQ_CST) & 1) : 0;
knockback_delay_holding = hold;
} else if ((__atomic_load_n(&knockback_delay_allowed, __ATOMIC_SEQ_CST) & our_knockback) & 1) {
// Our knockback arrived: start holding.
knockback_delay_holding = 1;
hold = 1;
} else {
hold = knockback_delay_holding;
}
if ((our_knockback & hold) == 1) {
// Remember which batch the knockback came in. A second knockback in another batch: give up.
int held_id = knockback_delay_held_transaction_id;
int id = hook->id;
if (held_id == 0) {
knockback_delay_held_transaction_id = id;
} else if (held_id != id) {
stop_holding();
return;
}
} else if (!hold) {
return;
}
// Held long enough: let everything through.
if (hook->budget > (long long)__atomic_load_n(&knockback_delay_max_delay_second, __ATOMIC_SEQ_CST)) {
stop_holding();
return;
}
bool hurt_related = java_jni_is_instance_of_s19_packet_entity_status(hook->ctx, hook->ev) ||
java_jni_is_instance_of_s06_packet_update_health(hook->ctx, hook->ev) ||
java_jni_is_instance_of_s29_packet_sound_effect(hook->ctx, hook->ev);
hook->verdict = hurt_related ? 3 : 1;
}
// Is another player within 6 blocks and within 90 degrees of where we look?
static bool player_in_front(Ctx *ctx) {
Vec3 my_pos = java_get_entity_pos_x(ctx->jvm, ctx->player);
Rot rotation = get_entity_rotation(ctx->jvm, ctx->player);
void *players = java_get_world_player_entities(ctx->jvm, ctx->world);
for (int i = 0; i < java_call_list_size(ctx->jvm, players); i++) {
void *other = java_call_list_get(ctx->jvm, players, i);
JNIEnv *env = ((Jvm *)ctx->jvm)->env;
if ((*env)->IsSameObject(env, ctx->player, other))
continue; // ourselves
Vec3 other_pos = java_get_entity_pos_x(ctx->jvm, other);
if (vec3_distance_sq(my_pos, other_pos) > 36.0)
continue;
float angle = __builtin_fabsf(wrap_angle(rot_look_at(my_pos, other_pos).yaw - rotation.yaw));
if (angle > 90.0f)
continue;
return true;
}
return false;
}
// Target in range, weapon, mouse and "require_target" conditions.
static bool conditions_met(Ctx *ctx) {
CombatTarget *target = (CombatTarget *)ctx->target;
if (!target->ent || target->dist2 > (double)(knockback_delay_range_value * knockback_delay_range_value))
return false;
if (knockback_delay_require_weapon_value == 1 && !is_holding_accepted_weapon(ctx->jvm, ctx->player))
return false;
if (knockback_delay_require_mouse_value == 1 && !vertex_pointer_current(ctx))
return false;
if (knockback_delay_require_target_value == 1 && !player_in_front(ctx))
return false;
return true;
}
// "chance": always yes above 0.999, otherwise a random walk around the chance.
static unsigned char roll_chance() {
double chance = knockback_delay_chance_value;
if (chance > 0.999)
return 1;
return walk_should_change(knockback_delay_random_walk_1, rot_make_floats((float)(-0.025 + chance), (float)(chance + 0.025)), 60.0);
}
// Every tick: is delaying allowed right now?
extern "C" void knockback_delay_on_late_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
if (!ctx->player)
return;
__atomic_exchange_n(&knockback_delay_own_entity_id, java_get_entity_entity_id(ctx->jvm, ctx->player), __ATOMIC_SEQ_CST);
unsigned char in_air;
if (knockback_delay_require_air_value == 1)
in_air = !java_get_entity_on_ground(ctx->jvm, ctx->player);
else
in_air = 0;
__atomic_exchange_n(&knockback_delay_air, in_air, __ATOMIC_SEQ_CST);
unsigned char allowed = 0;
if (knockback_delay_require_air_value == 1 && !in_air)
knockback_delay_holding = 0;
else if (conditions_met(ctx))
allowed = roll_chance();
__atomic_exchange_n(&knockback_delay_allowed, allowed, __ATOMIC_SEQ_CST);
__atomic_exchange_n(&knockback_delay_max_delay_second, (unsigned short)(int)knockback_delay_max_delay, __ATOMIC_SEQ_CST);
}
+53
View File
@@ -0,0 +1,53 @@
// Knockback Delay — Delays your knockback in certain scenarios.
// category: combat descriptor: 0x2f40f8 settings block: 0x2f42f0
// functions: gui knockback_delay_gui, register knockback_delay_register, status knockback_delay_status
// implementation: src/logic/combat/knockback_delay.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_knockback_delay); // "Main"
S(str_conditions_in_knockback_delay); // "Conditions"
S(str_range_in_knockback_delay); // "range"
S(str_chance_in_knockback_delay); // "chance"
S(str_max_delay_in_knockback_delay); // "max_delay"
S(str_require_air); // "require_air"
S(str_require_target_in_knockback_delay); // "require_target"
S(str_require_mouse_in_knockback_delay); // "require_mouse"
S(str_require_weapon_in_knockback_delay); // "require_weapon"
S(str_0fms_in_knockback_delay); // "%.0fms"
D(knockback_delay_max_delay_setting); // setting num "max_delay"
extern "C" float knockback_delay_max_delay; // current value of setting "max_delay" (+0x30)
D(knockback_delay_require_air_setting); // setting bool "require_air"
D(knockback_delay_range_setting); // setting num "range"
D(knockback_delay_require_weapon_setting); // setting bool "require_weapon"
D(knockback_delay_require_mouse_setting); // setting bool "require_mouse"
D(knockback_delay_require_target_setting); // setting bool "require_target"
D(knockback_delay_chance_setting); // setting num "chance"
extern "C" void knockback_delay_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_knockback_delay);
W_slider(window, gui, knockback_delay_range_setting);
W_slider(window, gui, knockback_delay_chance_setting);
W_slider(window, gui, knockback_delay_max_delay_setting);
W_label(gui, window, str_conditions_in_knockback_delay);
W_bool(window, gui, knockback_delay_require_air_setting);
W_bool(window, gui, knockback_delay_require_target_setting);
W_bool(window, gui, knockback_delay_require_mouse_setting);
W_bool(window, gui, knockback_delay_require_weapon_setting);
}
extern "C" void knockback_delay_register(void *module) {
R_num(module, str_range_in_knockback_delay, knockback_delay_range_setting);
R_num(module, str_chance_in_knockback_delay, knockback_delay_chance_setting);
R_num(module, str_max_delay_in_knockback_delay, knockback_delay_max_delay_setting);
R_bool(module, str_require_air, knockback_delay_require_air_setting);
R_bool(module, str_require_target_in_knockback_delay, knockback_delay_require_target_setting);
R_bool(module, str_require_mouse_in_knockback_delay, knockback_delay_require_mouse_setting);
R_bool(module, str_require_weapon_in_knockback_delay, knockback_delay_require_weapon_setting);
}
extern "C" void knockback_delay_status(void *self) {
log_fmt(self, 0x20, str_0fms_in_knockback_delay, (double)knockback_delay_max_delay);
}
+201
View File
@@ -0,0 +1,201 @@
// Knockback Displace - push your target sideways instead of straight back.
//
// Knockback goes the way you are facing. On a hit, this module turns your head sideways by
// "angle" degrees (with a little randomness) for that one tick, so the target flies off to
// the side. Next tick it turns back and clicks again. "hide_rotation" holds outgoing packets
// during that tick so the turn is not sent separately.
//
// Callbacks (descriptor slots +0x78 / +0x118 / +0x128 / +0x138 / +0x168):
// knockback_displace_on_packet_sent every outgoing packet: hold it while hiding the turn
// knockback_displace_on_rotation_update rotation hook: see below
// knockback_displace_on_attack before an attack: start the sideways turn
// knockback_displace_on_attack_post after an attack
// knockback_displace_on_late_tick every tick: turn back, bookkeeping
// knockback_displace_direction helper: -1 = left, +1 = right
#include "slinky/engine.h"
struct Rot { float yaw, pitch; };
struct Range { float lo, hi; };
struct AttackHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
unsigned char phase; // +0x10 1 = the attack is about to happen
unsigned char handled; // +0x11 set to 1 to cancel the attack (we click again next tick)
};
struct PktHook { char padding_00[0x24]; int verdict; }; // +0x24 set to 1 to hold the packet
// ---- settings ----
extern "C" float knockback_displace_cooldown_value; // "cooldown": ticks between displacements
extern "C" float knockback_displace_angle; // "angle": degrees to turn
extern "C" unsigned knockback_displace_direction_value; // "direction": 0 left, 1 right, 2 random, 3 strafe, 4 against strafe
extern "C" unsigned char knockback_displace_use_last_strafe_value; // "use_last_strafe": remember the strafe direction after letting go
extern "C" unsigned char knockback_displace_hide_rotation_value; // "hide_rotation"
extern "C" unsigned char knockback_displace_require_no_kb_value; // "require_no_kb"
extern "C" unsigned char knockback_displace_require_weapon_value; // "require_weapon"
extern "C" unsigned char knockback_displace_require_kb_enchant_value; // "require_kb_enchant"
extern "C" unsigned char knockback_displace_require_facing_away_value; // "require_facing_away"
// ---- module state ----
extern "C" unsigned char knockback_displace_rotation_hidden; // holding packets (read by the network thread)
extern "C" unsigned char knockback_displace_displacing_this_tick;
extern "C" unsigned char knockback_displace_displaced_last_tick;
extern "C" unsigned char knockback_displace_hit_seen_this_tick;
extern "C" unsigned knockback_displace_ticks_since_reset;
extern "C" unsigned knockback_displace_ticks_since_displacement;
extern "C" Rot knockback_displace_rotation_before_displacement; // rotation to turn back to
extern "C" int knockback_displace_last_strafe_sign; // -1 right, 0 none, +1 left
// ---- game / engine functions ----
FN(void *, java_get_minecraft_object_mouse_over, (void *jvm, void *minecraft));
FN(int, java_get_moving_object_position_type_ordinal, (void *jvm, void *moving_object_position)); // 2 = an entity
FN(void *, java_get_moving_object_position_entity_hit, (void *jvm, void *moving_object_position));
FN(void *, java_jni_is_instance_of_entity_other_player_mp, (void *jvm, void *candidate)); // the entity as a player, or null
FN(unsigned char, entity_flags_has, (void *jvm, void *entity, int mode)); // mode 7: friend, teammate or bot
FN(unsigned char, timer_range_is_delay_pending, ()); // Timer Range is busy
FN(unsigned char, is_held_item_accepted_weapon, (void *jvm, void *item, unsigned *flags)); // flags & 2: knockback enchant
FN(unsigned char, java_call_entity_is_sprinting, (void *jvm, void *entity));
FN(Rot, get_entity_rotation, (void *jvm, void *entity));
FN(unsigned char, yaw_diff_check, (Ctx *ctx, Rot rotation, void *target)); // facing away from the target
FN(unsigned char, update_rotation_priority_peak, (int ms)); // may this module control the rotation?
FN(void, apply_player_rotation, (Ctx *ctx, unsigned char a, int b, int d, Rot rotation));
FN(unsigned char, random_chance, (float chance));
FN(Range, rot_make_floats, (float lo, float hi));
FN(float, random_rotation, (Range r)); // random value in the range
FN(void, apply_silent_rotation, (Rot rotation));
FN(void, set_rotation_active, (void *jvm, void *object, int x));
FN(float, java_get_entity_living_base_move_strafing, (void *jvm, void *entity_living_base));
FN(Rot, get_silent_rotation_offset, ());
FN(Rot, rot_add, (Rot a, Rot b));
FN(Rot, rot_sub, (Rot a, Rot b));
FN(void *, get_game_settings, (void *jvm, void *object));
FN(void, java_set_minecraft_left_click_counter, (void *jvm, void *minecraft, int y));
FN(void *, java_get_game_settings_attack_key, (void *jvm, void *game_settings));
FN(void, java_increment_key_binding_press_time, (void *jvm, void *key_binding)); // = one click
extern "C" int knockback_displace_direction();
extern "C" void knockback_displace_on_packet_sent(PktHook *hook) {
if (__atomic_load_n(&knockback_displace_rotation_hidden, __ATOMIC_SEQ_CST) & 1)
hook->verdict = 1;
}
// While displacing (this tick or last tick): clear the engine's pitch-override flag (+0x09).
extern "C" void knockback_displace_on_rotation_update(char *h) {
if (knockback_displace_displacing_this_tick != 0 || knockback_displace_displaced_last_tick != 0)
h[9] = 0;
}
extern "C" void knockback_displace_on_attack(AttackHook *hook) {
// Already turned this tick: cancel further attacks until we turn back.
if (knockback_displace_displacing_this_tick == 1) {
hook->handled = 1;
return;
}
if (hook->phase != 1)
return;
Ctx *ctx = hook->ctx;
// Attacking a player we may fight?
void *hit = java_get_minecraft_object_mouse_over(ctx->jvm, ctx->minecraft);
if (!hit || java_get_moving_object_position_type_ordinal(ctx->jvm, hit) != 2)
return;
void *target = java_jni_is_instance_of_entity_other_player_mp(ctx->jvm, java_get_moving_object_position_entity_hit(ctx->jvm, hit));
if (!target || entity_flags_has(ctx->jvm, target, 7))
return;
knockback_displace_hit_seen_this_tick = 1;
// Conditions.
if (knockback_displace_displaced_last_tick || knockback_displace_ticks_since_reset < 9)
return;
if (knockback_displace_cooldown_value > (float)knockback_displace_ticks_since_displacement)
return;
if (timer_range_is_delay_pending())
return;
if (knockback_displace_require_no_kb_value == 1 && ((CombatTarget *)ctx->target)->valid)
return;
unsigned flags;
unsigned char weapon = is_held_item_accepted_weapon(ctx->jvm, ctx->player, &flags);
if (knockback_displace_require_weapon_value == 1 && !weapon)
return;
// The hit must deal extra knockback: a knockback enchant, or sprinting.
if (!(flags & 2) && (knockback_displace_require_kb_enchant_value || !java_call_entity_is_sprinting(ctx->jvm, ctx->player)))
return;
Rot rotation = get_entity_rotation(ctx->jvm, ctx->player);
knockback_displace_rotation_before_displacement = rotation;
if (knockback_displace_require_facing_away_value == 1 && !yaw_diff_check(ctx, rotation, target))
return;
int direction = knockback_displace_direction();
if (!direction || !update_rotation_priority_peak(200))
return;
// Turn sideways: "angle" minus 0..10 degrees, and pitch 10..20 degrees up or down at random.
apply_player_rotation(ctx, 1, 0, 0, knockback_displace_rotation_before_displacement);
knockback_displace_displacing_this_tick = 1;
unsigned char pitch_down = random_chance(0.5f);
float yaw = (knockback_displace_angle - random_rotation(rot_make_floats(0.0f, 10.0f))) * (float)direction;
float pitch = random_rotation(rot_make_floats(10.0f, 20.0f));
if (!pitch_down)
pitch = -pitch;
apply_silent_rotation(Rot{yaw, pitch});
set_rotation_active(ctx->jvm, ctx->player, 0);
if (knockback_displace_hide_rotation_value == 1)
__atomic_exchange_n(&knockback_displace_rotation_hidden, (unsigned char)1, __ATOMIC_SEQ_CST);
// Cancel this attack; the click is repeated next tick, after the turn was sent.
hook->handled = 1;
knockback_displace_ticks_since_displacement = 0;
}
extern "C" void knockback_displace_on_attack_post(AttackHook *hook) {
if (hook->phase == 1 && knockback_displace_ticks_since_reset >= 10 && (knockback_displace_hit_seen_this_tick & 1))
knockback_displace_ticks_since_reset = 0;
}
extern "C" void knockback_displace_on_late_tick(Hook *hook) {
knockback_displace_ticks_since_reset += 1;
knockback_displace_ticks_since_displacement += 1;
knockback_displace_displaced_last_tick = knockback_displace_displacing_this_tick;
knockback_displace_hit_seen_this_tick = 0;
Ctx *ctx = hook->ctx;
if (ctx->in_game == 1) {
// Remember which way we strafe (for "direction" 3 and 4).
float strafe = java_get_entity_living_base_move_strafing(ctx->jvm, ctx->player);
int sign = (strafe > 0.0f) - (0.0f > strafe);
if (knockback_displace_use_last_strafe_value != 1 || sign != 0)
knockback_displace_last_strafe_sign = sign;
// We turned last tick: turn back, and click again (the attack that was cancelled).
if (knockback_displace_displacing_this_tick == 1 && update_rotation_priority_peak(200)) {
Rot now = rot_add(get_entity_rotation(ctx->jvm, ctx->player), get_silent_rotation_offset());
apply_silent_rotation(rot_sub(knockback_displace_rotation_before_displacement, now));
set_rotation_active(ctx->jvm, ctx->player, 0);
void *settings = get_game_settings(ctx->jvm, ctx->minecraft);
java_set_minecraft_left_click_counter(ctx->jvm, ctx->minecraft, 0);
java_increment_key_binding_press_time(ctx->jvm, java_get_game_settings_attack_key(ctx->jvm, settings));
}
}
knockback_displace_displacing_this_tick = 0;
// Keep holding packets for the tick after the turn, if "hide_rotation".
unsigned char hide = knockback_displace_displaced_last_tick ? knockback_displace_hide_rotation_value : 0;
__atomic_exchange_n(&knockback_displace_rotation_hidden, hide, __ATOMIC_SEQ_CST);
}
// -1 = turn left, +1 = turn right, 0 = don't.
extern "C" int knockback_displace_direction() {
switch (knockback_displace_direction_value) {
case 0:
return -1;
case 1:
return 1;
case 2:
return (random_chance(0.5f) - 1) | 1; // -1 or +1 at random
case 3:
return knockback_displace_last_strafe_sign;
case 4:
return -knockback_displace_last_strafe_sign;
default:
__builtin_unreachable(); // the setting only has 5 options
}
}
+67
View File
@@ -0,0 +1,67 @@
// Knockback Displace — Allows dealing knockback at a different angle.
// category: combat descriptor: 0x2f5d60 settings block: 0x2f5f58
// functions: gui knockback_displace_gui, register knockback_displace_register, status knockback_displace_status
// implementation: src/logic/combat/knockback_displace.cpp
#pragma once
#include "slinky/api.h"
S(str_0f_in_knockback_displace); // "%.0f°"
S(str_main_in_knockback_displace); // "Main"
S(str_condition); // "Condition"
S(str_direction_in_knockback_displace); // "direction"
S(str_use_last_strafe); // "use_last_strafe"
S(str_angle_in_knockback_displace); // "angle"
S(str_cooldown_in_knockback_displace); // "cooldown"
S(str_hide_rotation); // "hide_rotation"
S(str_require_no_kb); // "require_no_kb"
S(str_require_weapon_in_knockback_displace); // "require_weapon"
S(str_require_kb_enchant); // "require_kb_enchant"
S(str_require_facing_away); // "require_facing_away"
D(knockback_displace_cooldown_setting); // setting num "cooldown"
D(knockback_displace_angle_setting); // setting num "angle"
extern "C" float knockback_displace_angle; // current value of setting "angle" (+0x30)
D(knockback_displace_require_no_kb_setting); // setting bool "require_no_kb"
D(knockback_displace_require_weapon_setting); // setting bool "require_weapon"
D(knockback_displace_require_kb_enchant_setting); // setting bool "require_kb_enchant"
D(knockback_displace_require_facing_away_setting); // setting bool "require_facing_away"
D(knockback_displace_direction_setting); // setting enum "direction"
extern "C" unsigned knockback_displace_direction_value; // current value of setting "direction" (+0x30)
D(knockback_displace_hide_rotation_setting); // setting bool "hide_rotation"
D(knockback_displace_use_last_strafe_setting); // setting bool "use_last_strafe"
extern "C" void knockback_displace_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_knockback_displace);
W_enumw(window, gui, knockback_displace_direction_setting);
switch (knockback_displace_direction_value) {
case 3:
case 4:
W_bool(window, gui, knockback_displace_use_last_strafe_setting);
break;
}
W_slider(window, gui, knockback_displace_cooldown_setting);
W_slider(window, gui, knockback_displace_angle_setting);
W_bool(window, gui, knockback_displace_hide_rotation_setting);
W_label(gui, window, str_condition);
W_bool(window, gui, knockback_displace_require_no_kb_setting);
W_bool(window, gui, knockback_displace_require_weapon_setting);
W_bool(window, gui, knockback_displace_require_kb_enchant_setting);
W_bool(window, gui, knockback_displace_require_facing_away_setting);
}
extern "C" void knockback_displace_register(void *module) {
R_enum(module, str_direction_in_knockback_displace, knockback_displace_direction_setting);
R_bool(module, str_use_last_strafe, knockback_displace_use_last_strafe_setting);
R_num(module, str_angle_in_knockback_displace, knockback_displace_angle_setting);
R_num(module, str_cooldown_in_knockback_displace, knockback_displace_cooldown_setting);
R_bool(module, str_hide_rotation, knockback_displace_hide_rotation_setting);
R_bool(module, str_require_no_kb, knockback_displace_require_no_kb_setting);
R_bool(module, str_require_weapon_in_knockback_displace, knockback_displace_require_weapon_setting);
R_bool(module, str_require_kb_enchant, knockback_displace_require_kb_enchant_setting);
R_bool(module, str_require_facing_away, knockback_displace_require_facing_away_setting);
}
extern "C" void knockback_displace_status(void *self) {
log_fmt(self, 0x20, str_0f_in_knockback_displace, (double)knockback_displace_angle);
}
+286
View File
@@ -0,0 +1,286 @@
// Lag Range - fake lag while walking up to your target, so you reach them before they see you coming.
//
// While a target is within 10-15 blocks and you are moving closer to it, your outgoing
// movement packets are held back for up to "delay" ms. The server (and the target) see you
// further away than you are, then you "teleport" in when the packets are released.
// Packets are released at once when you attack, stop sprinting ("flush_sprint_reset") or
// throw a splash potion ("flush_splash_potion").
//
// The symbol names "lag_range_target_position*" / "..._from_packets" are historical: they hold
// OUR position as last sent to the server (see the comments below).
//
// Callbacks:
// lag_range_attack_hook every attack: did the hit land this tick?
// lag_range_render_box_interpolated every frame: draw a box where the server thinks we are
// lag_range_packet_hook_hold every outgoing packet (network thread): hold or release
// lag_range_tick_decide_whether every tick: may we hold packets now?
#include "slinky/engine.h"
struct Vec3 { double x, y, z; };
struct Range { float lo, hi; };
struct RenderHook {
char padding_00[8];
Vec3 cam; // +0x08 camera position
char padding_20[8];
float partial; // +0x28 how far we are between two ticks (0..1)
};
struct PktHook {
char padding_00[8];
void *ctx; // +0x08 JVM handle
void *ev; // +0x10 the packet
long long budget; // +0x18 ms the packet has been held so far
int seq; // +0x20 packet sequence number
int verdict; // +0x24 set to 1 to hold the packet
};
struct PhaseHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
unsigned char phase; // +0x10 1 = the attack happens
};
// ---- settings ----
extern "C" float lag_range_delay; // "delay": max hold (ms)
extern "C" unsigned char lag_range_require_weapon_value; // "require_weapon"
extern "C" unsigned char lag_range_flush_splash_potion_value; // "flush_splash_potion"
extern "C" unsigned char lag_range_flush_sprint_reset_value; // "flush_sprint_reset"
extern "C" unsigned char lag_range_render_remote_pos; // "render_remote_pos": draw the box (third person)
extern "C" float lag_range_line_width_setting; // "line_width"
extern "C" float lag_range_color_setting[3]; // "color" (r, g, b)
extern "C" unsigned char lag_range_filled_setting; // "filled"
// ---- module state (shared with the network thread, guarded by the spin lock) ----
extern "C" unsigned char lag_range_spin_lock;
extern "C" unsigned char lag_range_active; // holding is allowed this tick
extern "C" long long lag_range_max_hold_budget; // "delay" as a whole number
extern "C" int lag_range_last_packet_sequence;
extern "C" unsigned char lag_range_target_moved_closer; // our last movement packet brought us closer to the target
extern "C" unsigned char lag_range_hold_active; // release on our next attack packet
extern "C" unsigned char lag_range_track_entity_action; // release on our next "stop sprinting" packet
extern "C" unsigned char lag_range_hold_just_released; // released, don't hold again until the next movement packet
extern "C" Vec3 lag_range_target_position_when_window_started; // the target's position this tick
extern "C" Vec3 lag_range_latest_target_position_from_packets; // OUR position in the last movement packet sent
extern "C" unsigned char lag_range_hit_time_unchanged; // we landed a hit this tick
extern "C" unsigned char lag_range_sprinting_last_tick;
extern "C" int lag_range_pause_ticks; // ticks to pause after a splash potion
extern "C" char lag_range_random_walk_1[]; // random walk state
// For the box: our server-side position last tick and this tick.
extern "C" unsigned char lag_range_have_target_position;
extern "C" Vec3 lag_range_target_position;
extern "C" Vec3 lag_range_target_position_second;
// ---- OpenGL ----
extern "C" void (**ptr_to_pGlLineWidth)(float);
extern "C" void (**ptr_to_pGlPushMatrix)();
extern "C" void (**ptr_to_pGlPopMatrix)();
extern "C" void (**ptr_to_pGlTranslatef)(float, float, float);
extern "C" void (**ptr_to_pGlScalef)(float, float, float);
extern "C" void (**ptr_to_pGlColor3f)(float, float, float);
extern "C" void (**ptr_to_pGlColor4f)(float, float, float, float);
FN(void, gl_array_xyz_float, ()); // set up the unit box vertex array
FN(void, gl_array_color1, ()); // draw it filled
FN(void, gl_array_color2, ()); // draw its outline
FN(void, disable_vertex_array_state, ());
// ---- game / engine functions ----
FN(void *, java_jni_is_instance_of_c03_packet_player, (void *ctx, void *event)); // movement packet, or null
FN(unsigned char, java_get_c03_packet_player_moving, (void *ctx, void *c03_packet_player)); // contains a position
FN(Vec3, java_get_c03_packet_player_a, (void *ctx, void *c03_packet_player)); // its position
FN(void *, java_jni_is_instance_of_c02_packet_use_entity, (void *ctx, void *event)); // attack packet, or null
FN(void *, java_jni_is_instance_of_c0_bpacket_entity_action, (void *ctx, void *event)); // sprint/sneak packet, or null
FN(int, java_c0_bpacket_entity_action, (void *ctx, void *object)); // its action, 4 = stop sprinting
FN(double, vec3_distance_sq, (Vec3 a, Vec3 b));
FN(unsigned char, is_holding_accepted_weapon, (void *jvm, void *object));
FN(void *, java_get_entity_player_inventory, (void *jvm, void *entity_player));
FN(int, java_get_inventory_player_current_item, (void *jvm, void *inventory_player));
FN(void *, java_call_iinventory_get_stack_in_slot, (void *jvm, void *object, int slot));
FN(void *, item_held_hotbar_slot, (void *jvm, void *slot));
FN(int, java_call_static_item_get_id_from_item, (void *jvm, void *item));
FN(unsigned, java_get_item_stack_metadata, (void *jvm, void *stack));
FN(unsigned char, java_call_entity_is_sprinting, (void *jvm, void *entity));
FN(Vec3, java_get_entity_pos_x, (void *jvm, void *entity));
FN(unsigned char, java_variant, (void *jvm));
FN(Vec3, vec3_add_eye_height_sneak, (Vec3 v));
FN(Range, rot_make_floats, (float lo, float hi));
FN(float, walk_update, (void *state, Range r, double p)); // next value of a random walk
FN(int, java_get_entity_living_base_hurt_time, (void *jvm, void *entity_living_base));
FN(void *, get_game_settings, (void *jvm, void *object));
FN(int, java_get_game_settings_third_person_view, (void *jvm, void *game_settings));
FN(Vec3, java_get_entity_other_player_mp_other_player_mpx, (void *jvm, void *entity_other_player_mp)); // server-side position
FN(Vec3, vec3_lerp, (Vec3 a, Vec3 b, double t));
FN(Vec3, vec3_sub, (Vec3 a, Vec3 b));
FN(int, java_get_entity_ticks_existed, (void *jvm, void *entity));
FN(int, java_get_entity_living_base_last_attacker_time, (void *jvm, void *entity_living_base)); // tick of our last attack
enum { ITEM_POTION = 373, POTION_SPLASH_FLAG = 0x4000 };
static void lock() {
while (__atomic_exchange_n(&lag_range_spin_lock, (unsigned char)1, __ATOMIC_SEQ_CST))
__builtin_ia32_pause();
}
static void unlock() { lag_range_spin_lock = 0; }
extern "C" void lag_range_attack_hook(PhaseHook *hook) {
if (hook->phase != 1)
return;
Ctx *ctx = hook->ctx;
int now = java_get_entity_ticks_existed(ctx->jvm, ctx->player);
lag_range_hit_time_unchanged = now == java_get_entity_living_base_last_attacker_time(ctx->jvm, ctx->player);
}
// Every frame: a box (0.6 wide, 2 tall) where the server thinks we are.
extern "C" void lag_range_render_box_interpolated(RenderHook *hook) {
if (lag_range_have_target_position != 1)
return;
Vec3 pos = vec3_sub(vec3_lerp(lag_range_target_position, lag_range_target_position_second, (double)hook->partial), hook->cam);
gl_array_xyz_float();
(*ptr_to_pGlLineWidth)(lag_range_line_width_setting);
(*ptr_to_pGlPushMatrix)();
(*ptr_to_pGlTranslatef)((float)pos.x, (float)(pos.y + 1.0), (float)pos.z);
(*ptr_to_pGlScalef)(0.3f, 1.0f, 0.3f);
if (lag_range_filled_setting == 1) {
(*ptr_to_pGlColor4f)(lag_range_color_setting[0], lag_range_color_setting[1], lag_range_color_setting[2], 0.4f);
gl_array_color1();
}
(*ptr_to_pGlColor3f)(lag_range_color_setting[0], lag_range_color_setting[1], lag_range_color_setting[2]);
gl_array_color2();
(*ptr_to_pGlPopMatrix)();
disable_vertex_array_state();
}
// Every outgoing packet (network thread).
extern "C" void lag_range_packet_hook_hold(PktHook *hook) {
lock();
unsigned char active = lag_range_active;
// A new packet: if it is a movement packet, are we moving closer to the target?
if (hook->seq > lag_range_last_packet_sequence) {
if (active) {
void *movement = java_jni_is_instance_of_c03_packet_player(hook->ctx, hook->ev);
if (movement && java_get_c03_packet_player_moving(hook->ctx, movement)) {
Vec3 new_pos = java_get_c03_packet_player_a(hook->ctx, movement);
double old_distance = vec3_distance_sq(lag_range_target_position_when_window_started, lag_range_latest_target_position_from_packets);
lag_range_target_moved_closer = old_distance > vec3_distance_sq(lag_range_target_position_when_window_started, new_pos);
}
}
lag_range_last_packet_sequence = hook->seq;
active = lag_range_active;
}
if (active && lag_range_target_moved_closer && !lag_range_hold_active && !lag_range_hold_just_released &&
!lag_range_track_entity_action && hook->budget < lag_range_max_hold_budget) {
hook->verdict = 1; // hold it
} else if (hook->verdict == 0) {
// The packet goes out now. Watch for the packets that release the hold.
void *movement = java_jni_is_instance_of_c03_packet_player(hook->ctx, hook->ev);
if (movement) {
lag_range_hold_just_released = 0;
if (java_get_c03_packet_player_moving(hook->ctx, movement))
lag_range_latest_target_position_from_packets = java_get_c03_packet_player_a(hook->ctx, movement);
} else if (java_jni_is_instance_of_c02_packet_use_entity(hook->ctx, hook->ev)) {
// Attack: release.
if (lag_range_hold_active) {
lag_range_hold_active = 0;
lag_range_hold_just_released = 1;
}
} else {
// Stop sprinting: release.
void *action = java_jni_is_instance_of_c0_bpacket_entity_action(hook->ctx, hook->ev);
if (action && lag_range_track_entity_action && java_c0_bpacket_entity_action(hook->ctx, action) == 4) {
lag_range_track_entity_action = 0;
lag_range_hold_just_released = 1;
}
}
}
unlock();
}
// Should holding be off this tick? (updates the splash potion pause)
static bool paused_or_not_ready(Ctx *ctx) {
if (ctx->in_game != 1)
return true;
if (lag_range_require_weapon_value == 1 && !is_holding_accepted_weapon(ctx->jvm, ctx->player))
return true;
if (lag_range_flush_splash_potion_value == 1) {
// Holding a splash potion: pause for 15 ticks.
void *inventory = java_get_entity_player_inventory(ctx->jvm, ctx->player);
void *stack = java_call_iinventory_get_stack_in_slot(ctx->jvm, inventory, java_get_inventory_player_current_item(ctx->jvm, inventory));
if (stack) {
void *held = item_held_hotbar_slot(ctx->jvm, ctx->player);
if (held && java_call_static_item_get_id_from_item(ctx->jvm, held) == ITEM_POTION && (java_get_item_stack_metadata(ctx->jvm, stack) & POTION_SPLASH_FLAG)) {
lag_range_pause_ticks = 15;
return true;
}
}
int pause = lag_range_pause_ticks;
if (pause > 0) {
lag_range_pause_ticks = pause - 1;
return true;
}
}
return false;
}
// Every tick: may we hold packets now?
extern "C" void lag_range_tick_decide_whether(Hook *hook) {
unsigned char hit_this_tick = lag_range_hit_time_unchanged;
lag_range_hit_time_unchanged = 0;
Ctx *ctx = hook->ctx;
bool on = false;
if (!paused_or_not_ready(ctx)) {
// Stopped sprinting since last tick: release on the "stop sprinting" packet.
unsigned char sprinting = java_call_entity_is_sprinting(ctx->jvm, ctx->player);
unsigned char stopped_sprinting = (lag_range_sprinting_last_tick & 1) ? lag_range_flush_sprint_reset_value : 0;
if (sprinting)
stopped_sprinting = 0;
lag_range_sprinting_last_tick = sprinting;
// (eye position, not used)
Vec3 eye = java_get_entity_pos_x(ctx->jvm, ctx->player);
if (java_variant(ctx->jvm))
eye = vec3_add_eye_height_sneak(eye);
(void)eye;
// Target within a random 10-15 blocks.
CombatTarget *target = (CombatTarget *)ctx->target;
if (target->ent) {
double distance_sq = target->dist2;
double max_range = walk_update(lag_range_random_walk_1, rot_make_floats(10.0f, 15.0f), 10.0);
if (!(distance_sq > max_range * max_range)) {
// Release on our next attack only when the target can take damage again.
unsigned char target_can_be_hurt = java_get_entity_living_base_hurt_time(ctx->jvm, target->ent) < 5;
unsigned char show_box = 0;
if (lag_range_render_remote_pos == 1)
show_box = java_get_game_settings_third_person_view(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft)) != 0;
hit_this_tick &= target_can_be_hurt;
Vec3 target_pos = java_get_entity_other_player_mp_other_player_mpx(ctx->jvm, target->ent);
lock();
lag_range_max_hold_budget = (long long)lag_range_delay;
lag_range_hold_active = hit_this_tick;
lag_range_track_entity_action = stopped_sprinting;
lag_range_active = 1;
lag_range_target_position_when_window_started = target_pos;
// For the box: last tick's and this tick's server-side position.
lag_range_target_position = lag_range_have_target_position == 1 ? lag_range_target_position_second : lag_range_latest_target_position_from_packets;
lag_range_target_position_second = lag_range_latest_target_position_from_packets;
lag_range_have_target_position = show_box ? lag_range_target_moved_closer : 0;
unlock();
on = true;
}
}
}
if (on)
return;
lock();
lag_range_hold_just_released = 0;
lag_range_hold_active = 0;
lag_range_track_entity_action = 0;
lag_range_active = 0;
unlock();
lag_range_have_target_position = 0;
}
+64
View File
@@ -0,0 +1,64 @@
// Lag Range — Uses lag to stay out of target range.
// category: combat descriptor: 0x2ef9c0 settings block: 0x2efbb8
// functions: gui lag_range_gui, register lag_range_register, status lag_range_status
// implementation: src/logic/combat/lag_range.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_lag_range); // "Main"
S(str_flush_if); // "Flush if"
S(str_real_position_indicator_in_lag_range); // "Real position indicator"
S(str_conditions_in_lag_range); // "Conditions"
S(str_delay_in_lag_range); // "delay"
S(str_flush_sprint_reset); // "flush_sprint_reset"
S(str_flush_splash_potion); // "flush_splash_potion"
S(str_render_remote_pos_in_lag_range); // "render_remote_pos"
S(str_indicator_color_in_lag_range); // "indicator_color"
S(str_indicator_line_width_in_lag_range); // "indicator_line_width"
S(str_indicator_filled_in_lag_range); // "indicator_filled"
S(str_require_weapon_in_lag_range); // "require_weapon"
S(str_0fms_in_lag_range); // "%.0fms"
D(lag_range_indicator_line_width_setting); // setting num "indicator_line_width"
D(lag_range_indicator_color_setting); // setting key "indicator_color"
D(lag_range_indicator_filled_setting); // setting bool "indicator_filled"
D(lag_range_delay_setting); // setting num "delay"
extern "C" float lag_range_delay; // current value of setting "delay" (+0x30)
D(lag_range_require_weapon_setting); // setting bool "require_weapon"
D(lag_range_flush_splash_potion_setting); // setting bool "flush_splash_potion"
D(lag_range_flush_sprint_reset_setting); // setting bool "flush_sprint_reset"
D(lag_range_render_remote_pos_setting); // setting bool "render_remote_pos"
D(lag_range_render_remote_pos); // current value of setting "render_remote_pos" (+0x18)
extern "C" void lag_range_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_lag_range);
W_slider(window, gui, lag_range_delay_setting);
W_label(gui, window, str_flush_if);
W_bool(window, gui, lag_range_flush_sprint_reset_setting);
W_bool(window, gui, lag_range_flush_splash_potion_setting);
W_label(gui, window, str_real_position_indicator_in_lag_range);
W_bool(window, gui, lag_range_render_remote_pos_setting);
if (*(unsigned char *)lag_range_render_remote_pos == 1) {
W_color(window, gui, lag_range_indicator_color_setting);
W_slider(window, gui, lag_range_indicator_line_width_setting);
W_bool(window, gui, lag_range_indicator_filled_setting);
}
W_label(gui, window, str_conditions_in_lag_range);
W_bool(window, gui, lag_range_require_weapon_setting);
}
extern "C" void lag_range_register(void *module) {
R_num(module, str_delay_in_lag_range, lag_range_delay_setting);
R_bool(module, str_flush_sprint_reset, lag_range_flush_sprint_reset_setting);
R_bool(module, str_flush_splash_potion, lag_range_flush_splash_potion_setting);
R_bool(module, str_render_remote_pos_in_lag_range, lag_range_render_remote_pos_setting);
R_key(module, str_indicator_color_in_lag_range, lag_range_indicator_color_setting);
R_num(module, str_indicator_line_width_in_lag_range, lag_range_indicator_line_width_setting);
R_bool(module, str_indicator_filled_in_lag_range, lag_range_indicator_filled_setting);
R_bool(module, str_require_weapon_in_lag_range, lag_range_require_weapon_setting);
}
extern "C" void lag_range_status(void *self) {
log_fmt(self, 0x20, str_0fms_in_lag_range, (double)lag_range_delay);
}
+98
View File
@@ -0,0 +1,98 @@
// Piercing - hit through entities and blocks.
//
// When two entities are under the crosshair, the engine asks which one the attack should hit.
// With this module the attack can go through friends, bots and non-players to reach an
// enemy behind them, and (with "blocks") through blocks too.
//
// Functions:
// piercing_decide_which_entity 0 = hit the first entity, 1 = hit the second, 2 = no preference
// piercing_should_pierce_blocks true while block piercing is active
// piercing_on_reach_query mark the module as active
#include "slinky/engine.h"
// ---- settings ----
extern "C" unsigned char piercing_module_enabled;
extern "C" unsigned char piercing_require_inside_bb_value; // "require_inside_bb": only when standing inside the first entity's hitbox
extern "C" unsigned char piercing_require_weapon_value; // "require_weapon"
extern "C" unsigned char piercing_non_players_value; // "non_players": hit through non-players
extern "C" bool piercing_friendlies_value; // "friendlies": hit through friends and teammates
extern "C" bool piercing_bots_value; // "bots": hit through bots
extern "C" unsigned char piercing_enemies_value; // "enemies": choose between two enemies
extern "C" int piercing_sort_by_value; // "sort_by": 0 = hurt time, 1 = health
extern "C" unsigned char piercing_blocks_value; // "blocks": hit through blocks
// ---- game / engine functions ----
FN(unsigned char, is_holding_accepted_weapon, (void *jvm, void *object));
FN(void *, java_jni_is_instance_of_entity_other_player_mp, (void *jvm, void *candidate)); // the entity as a player, or null
FN(unsigned, entity_flags_get, (void *jvm, void *t)); // bit 1/4: friend/teammate, bit 2: bot
FN(float, java_call_entity_living_base_get_health, (void *jvm, void *entity_living_base));
FN(int, java_get_entity_living_base_hurt_time, (void *jvm, void *entity_living_base));
FN(int, java_get_entity_ticks_existed, (void *jvm, void *entity));
FN(int, java_get_entity_entity_id, (void *jvm, void *entity));
// Scrambles a number (a simple hash), used to break ties in a stable but random-looking way.
static unsigned mix(unsigned x) {
x = (x ^ (x >> 16)) * 0x45d9f3b;
x = (x ^ (x >> 16)) * 0x45d9f3b;
return x ^ (x >> 16);
}
enum { HIT_FIRST = 0, HIT_SECOND = 1, NO_PREFERENCE = 2 };
extern "C" int piercing_decide_which_entity(Ctx *ctx, void *first, void *second, unsigned char inside_bb) {
if (piercing_module_enabled != 1)
return NO_PREFERENCE;
if (!inside_bb && piercing_require_inside_bb_value)
return NO_PREFERENCE;
if (piercing_require_weapon_value == 1 && !is_holding_accepted_weapon(ctx->jvm, ctx->player))
return NO_PREFERENCE;
void *second_player = java_jni_is_instance_of_entity_other_player_mp(ctx->jvm, second);
if (!second_player)
return 2 - piercing_non_players_value; // "non_players" on: HIT_SECOND, else NO_PREFERENCE
// The second one is a friend or a bot we may hit through.
unsigned flags = entity_flags_get(ctx->jvm, second_player);
if ((piercing_friendlies_value & ((flags & 5) != 0)) || (piercing_bots_value & ((flags & 2) >> 1)))
return HIT_SECOND;
void *first_player = java_jni_is_instance_of_entity_other_player_mp(ctx->jvm, first);
if (!first_player)
return HIT_FIRST;
if (piercing_enemies_value != 1)
return NO_PREFERENCE;
// Two enemies: pick by the "sort_by" setting.
if (piercing_sort_by_value == 1) {
float first_health = java_call_entity_living_base_get_health(ctx->jvm, first_player);
float second_health = java_call_entity_living_base_get_health(ctx->jvm, second_player);
if (second_health > first_health)
return HIT_SECOND;
if (first_health > second_health)
return HIT_FIRST;
} else if (piercing_sort_by_value == 0) {
int first_hurt = java_get_entity_living_base_hurt_time(ctx->jvm, first_player);
int second_hurt = java_get_entity_living_base_hurt_time(ctx->jvm, second_player);
if (second_hurt > first_hurt)
return HIT_SECOND;
if (second_hurt < first_hurt)
return HIT_FIRST;
}
// Still a tie: pick one by a hash of age + id.
unsigned first_hash = mix(java_get_entity_ticks_existed(ctx->jvm, first_player) + java_get_entity_entity_id(ctx->jvm, first_player));
unsigned second_hash = mix(java_get_entity_ticks_existed(ctx->jvm, second_player) + java_get_entity_entity_id(ctx->jvm, second_player));
return (int)second_hash <= (int)first_hash;
}
extern "C" unsigned char piercing_should_pierce_blocks(Ctx *ctx) {
if (piercing_module_enabled != 1 || !piercing_blocks_value)
return 0;
if (piercing_require_weapon_value == 1 && !is_holding_accepted_weapon(ctx->jvm, ctx->player))
return 0;
return 1;
}
extern "C" void piercing_on_reach_query(unsigned char *h) {
h[0x10] = 1;
}
+50
View File
@@ -0,0 +1,50 @@
// Piercing — Allows hitting entities through obstructions.
// category: combat descriptor: 0x2f3ab0 settings block: 0x2f3ca8
// functions: gui piercing_gui, register piercing_register
// implementation: src/logic/combat/piercing.cpp
#pragma once
#include "slinky/api.h"
S(str_always_hit_through); // "Always hit through"
S(str_conditions_in_piercing); // "Conditions"
S(str_sort_by_in_piercing); // "sort_by"
S(str_non_players); // "non_players"
S(str_friendlies_in_piercing); // "friendlies"
S(str_bots_in_piercing); // "bots"
S(str_enemies_in_piercing); // "enemies"
S(str_blocks_in_piercing); // "blocks"
S(str_require_weapon_in_piercing); // "require_weapon"
S(str_require_inside_bb); // "require_inside_bb"
D(piercing_require_inside_bb_setting); // setting bool "require_inside_bb"
D(piercing_require_weapon_setting); // setting bool "require_weapon"
D(piercing_non_players_setting); // setting bool "non_players"
D(piercing_friendlies_setting); // setting bool "friendlies"
D(piercing_bots_setting); // setting bool "bots"
D(piercing_enemies_setting); // setting bool "enemies"
D(piercing_sort_by_setting); // setting enum "sort_by"
D(piercing_blocks_setting); // setting bool "blocks"
extern "C" void piercing_gui(void *gui, void *window) {
W_label(gui, window, str_always_hit_through);
W_enumw(window, gui, piercing_sort_by_setting);
W_bool(window, gui, piercing_non_players_setting);
W_bool(window, gui, piercing_friendlies_setting);
W_bool(window, gui, piercing_bots_setting);
W_bool(window, gui, piercing_enemies_setting);
W_bool(window, gui, piercing_blocks_setting);
W_label(gui, window, str_conditions_in_piercing);
W_bool(window, gui, piercing_require_weapon_setting);
W_bool(window, gui, piercing_require_inside_bb_setting);
}
extern "C" void piercing_register(void *module) {
R_enum(module, str_sort_by_in_piercing, piercing_sort_by_setting);
R_bool(module, str_non_players, piercing_non_players_setting);
R_bool(module, str_friendlies_in_piercing, piercing_friendlies_setting);
R_bool(module, str_bots_in_piercing, piercing_bots_setting);
R_bool(module, str_enemies_in_piercing, piercing_enemies_setting);
R_bool(module, str_blocks_in_piercing, piercing_blocks_setting);
R_bool(module, str_require_weapon_in_piercing, piercing_require_weapon_setting);
R_bool(module, str_require_inside_bb, piercing_require_inside_bb_setting);
}
+65
View File
@@ -0,0 +1,65 @@
// Reach - hit players from further away.
//
// The engine asks every tick how far attacks may reach, and gets "distance" back.
// Each hit you land starts a 9-tick cooldown; the longer reach is only given once the
// cooldown is below "activate_time" (so right after a hit it is off for a few ticks).
// Optionally only while sprinting.
//
// Callback (descriptor slot +0xc8):
// reach_on_reach_query every tick
#include "slinky/engine.h"
// ---- settings ----
extern "C" float reach_distance; // "distance": reach in blocks
extern "C" float reach_activate_time; // "activate_time": ticks after a hit with the longer reach
extern "C" unsigned char reach_require_sprint; // "require_sprint"
// ---- module state ----
extern "C" int reach_last_value_seen_from_java; // tick of our last attack, as seen last time
extern "C" int reach_cooldown_ticks; // counts down from 9 after each attack
// ---- game / engine functions ----
FN(bool, java_call_entity_is_sprinting, (void *jvm, void *entity));
FN(int, java_get_entity_living_base_last_attacker_time, (void *jvm, void *entity_living_base)); // tick of our last attack
// The engine's question, filled in by the callback.
struct ReachState {
char padding_00[8];
Ctx *ctx; // +0x08 game context
bool active; // +0x10 set to true to change the reach
char padding_11[7];
double reach; // +0x18 the reach to use
};
extern "C" void reach_on_reach_query(ReachState *s) {
int cooldown = reach_cooldown_ticks;
if (cooldown > 0) {
cooldown--;
reach_cooldown_ticks = cooldown;
}
Ctx *ctx = s->ctx;
if (reach_require_sprint == 1) {
if (!java_call_entity_is_sprinting(ctx->jvm, ctx->player))
return;
cooldown = reach_cooldown_ticks;
}
// Cooldown over: a new attack starts it again.
if (cooldown == 0) {
int last_attack = java_get_entity_living_base_last_attacker_time(ctx->jvm, ctx->player);
if (last_attack == reach_last_value_seen_from_java) {
cooldown = reach_cooldown_ticks;
} else {
reach_last_value_seen_from_java = last_attack;
reach_cooldown_ticks = 9;
cooldown = 9;
}
}
// The cooldown counts down from 9: the longer reach is on once it is below "activate_time".
if (reach_activate_time > (float)cooldown) {
s->active = true;
s->reach = (double)reach_distance;
}
}
+39
View File
@@ -0,0 +1,39 @@
// Reach — Increases your melee range.
// category: combat descriptor: 0x2ea550 settings block: 0x2ea748
// functions: gui reach_gui, register reach_register, status reach_status
// implementation: src/logic/combat/reach.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_reach); // "Main"
S(str_advanced); // "Advanced"
S(str_conditions_in_reach); // "Conditions"
S(str_distance_in_reach); // "distance"
S(str_activate_time); // "activate_time"
S(str_require_sprint_in_reach); // "require_sprint"
S(fmt_float_2dp_b); // "%.2f"
D(reach_distance_setting); // setting num "distance"
extern "C" float reach_distance; // current value of setting "distance" (+0x30)
D(reach_activate_time_setting); // setting num "activate_time"
D(reach_require_sprint_setting); // setting bool "require_sprint"
extern "C" void reach_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_reach);
W_slider(window, gui, reach_distance_setting);
W_label(gui, window, str_advanced);
W_slider(window, gui, reach_activate_time_setting);
W_label(gui, window, str_conditions_in_reach);
W_bool(window, gui, reach_require_sprint_setting);
}
extern "C" void reach_register(void *module) {
R_num(module, str_distance_in_reach, reach_distance_setting);
R_num(module, str_activate_time, reach_activate_time_setting);
R_bool(module, str_require_sprint_in_reach, reach_require_sprint_setting);
}
extern "C" void reach_status(void *self) {
log_fmt(self, 0x20, fmt_float_2dp_b, (double)reach_distance);
}
+146
View File
@@ -0,0 +1,146 @@
// Sprint Reset - stop sprinting for a moment after each hit, so the next hit deals full knockback.
//
// Knockback is extra strong on the first hit after you start sprinting. After you land a hit,
// this module waits "delay" ticks, then lets go of a key for "duration" ticks (which stops the
// sprint), then gives the key back. Which key depends on "mode":
// 0 = release forward, 1 = press sneak, 2 = release the sprint key (and stop sprinting)
//
// Callback (descriptor slot +0x158):
// sprint_reset_on_player_update every player tick
#include "slinky/engine.h"
struct Range { float lo, hi; };
// ---- settings ----
extern "C" unsigned sprint_reset_mode; // "mode"
extern "C" float sprint_reset_delay_value; // "delay": ticks after the hit
extern "C" float sprint_reset_duration_value; // "duration": ticks the key is let go
extern "C" unsigned char sprint_reset_randomize_value; // "randomize"
extern "C" unsigned char sprint_reset_wait_for_damage_value; // "wait_for_damage": only on the tick we take damage
extern "C" unsigned char sprint_reset_require_weapon_value; // "require_weapon"
// ---- module state ----
enum SprintResetStage {
STAGE_IDLE = 0, // waiting for a hit
STAGE_WAITING = 1, // hit seen, waiting "delay"
STAGE_KEY_RELEASED = 2, // key let go, waiting "duration"
};
extern "C" int sprint_reset_stage;
extern "C" float sprint_reset_countdown; // ticks left in the current stage
extern "C" double sprint_reset_time_last_own_hit; // time of our last hit (seconds)
extern "C" unsigned char sprint_reset_hit_seen; // a hit was seen and not handled yet
extern "C" int sprint_reset_ticks_since_hurt;
extern "C" char sprint_reset_rng_states[], sprint_reset_random_walk_1[], sprint_reset_random_walk_2[]; // random walk states
// ---- game / engine functions ----
FN(double, time_now, ());
FN(int, java_get_entity_ticks_existed, (void *jvm, void *entity));
FN(int, java_get_entity_living_base_last_attacker_time, (void *jvm, void *entity_living_base)); // tick of our last attack
FN(int, java_get_entity_living_base_hurt_time, (void *jvm, void *entity_living_base)); // 10 on the tick we are hit
FN(unsigned char, is_holding_accepted_weapon, (void *jvm, void *object));
FN(void *, get_game_settings, (void *jvm, void *object));
FN(void *, java_get_game_settings_forward_key, (void *jvm, void *game_settings));
FN(void *, java_get_game_settings_sneak_key, (void *jvm, void *game_settings));
FN(void *, java_get_game_settings_key_17_or_8, (void *jvm, void *game_settings)); // the sprint key
FN(unsigned char, java_get_key_binding_key_code, (void *jvm, void *key_binding)); // key physically held down
FN(void, java_set_key_binding_pressed, (void *jvm, void *key_binding, unsigned char on));
FN(void, java_call_entity_set_sprinting, (void *jvm, void *entity, bool on));
FN(Range, rot_make_floats, (float lo, float hi));
FN(float, walk_update, (void *state, Range r, double p)); // next value of a random walk
FN(unsigned char, walk_should_change, (void *state, Range r, double p));
FN(float, random_rotation, (Range r)); // random value in the range
extern "C" void sprint_reset_press_key(Ctx *ctx, unsigned char on);
extern "C" void sprint_reset_on_player_update(Hook *hook) {
Ctx *ctx = hook->ctx;
if (ctx->in_game != 1) {
// Left the world: reset everything.
if (sprint_reset_stage == STAGE_KEY_RELEASED)
sprint_reset_press_key(ctx, 0);
sprint_reset_stage = STAGE_IDLE;
sprint_reset_hit_seen = 0;
sprint_reset_countdown = 0.0f;
return;
}
// Did we land a hit this tick? (at most one every half second)
double now = time_now();
if (!(now - sprint_reset_time_last_own_hit < 0.5) &&
java_get_entity_ticks_existed(ctx->jvm, ctx->player) == java_get_entity_living_base_last_attacker_time(ctx->jvm, ctx->player)) {
sprint_reset_time_last_own_hit = now;
sprint_reset_hit_seen = 1;
}
sprint_reset_ticks_since_hurt += 1;
if (java_get_entity_living_base_hurt_time(ctx->jvm, ctx->player) == 10)
sprint_reset_ticks_since_hurt = 0;
// Count down the current stage.
float countdown = sprint_reset_countdown;
if (countdown > 0.0f) {
countdown += -1.0f;
sprint_reset_countdown = countdown;
if (countdown > 0.0f) {
if (sprint_reset_stage == STAGE_KEY_RELEASED)
sprint_reset_press_key(ctx, 1); // keep the key let go
return;
}
}
if (sprint_reset_stage == STAGE_KEY_RELEASED) {
// "duration" is over: give the key back.
sprint_reset_press_key(ctx, 0);
sprint_reset_stage = STAGE_IDLE;
return;
}
if (sprint_reset_stage == STAGE_WAITING) {
// "delay" is over: let go of the key for "duration" ticks.
sprint_reset_press_key(ctx, 1);
sprint_reset_stage = STAGE_KEY_RELEASED;
sprint_reset_hit_seen = 0;
float duration = sprint_reset_duration_value;
if (sprint_reset_randomize_value == 1) {
float shorter = walk_update(sprint_reset_random_walk_1, rot_make_floats(0.0f, 1.0f), 30.0);
float reduced = duration - shorter;
duration = 0.0f > reduced ? 0.0f : reduced;
// Now and then (5-10% of the time), 1-2 ticks longer.
if (walk_should_change(sprint_reset_random_walk_2, rot_make_floats(0.05f, 0.1f), 30.0))
duration += random_rotation(rot_make_floats(1.0f, 2.0f));
}
sprint_reset_countdown = duration + sprint_reset_countdown;
return;
}
// Idle: after a hit, start waiting "delay" ticks.
float delay = sprint_reset_delay_value;
if (sprint_reset_randomize_value == 1)
delay += walk_update(sprint_reset_rng_states, rot_make_floats(0.0f, 2.0f), 5.0);
if (sprint_reset_hit_seen == 1) {
if (sprint_reset_wait_for_damage_value == 1 && sprint_reset_ticks_since_hurt != 0)
return;
if (sprint_reset_require_weapon_value == 1 && !is_holding_accepted_weapon(ctx->jvm, ctx->player))
return;
sprint_reset_countdown = delay + sprint_reset_countdown;
sprint_reset_stage = STAGE_WAITING;
}
}
// on = 1: do the reset (let go of the key / press sneak). on = 0: give the key back.
extern "C" void sprint_reset_press_key(Ctx *c, unsigned char on) {
void *settings = get_game_settings(c->jvm, c->minecraft);
void *key;
if (sprint_reset_mode == 2)
key = java_get_game_settings_key_17_or_8(c->jvm, settings); // sprint key
else if (sprint_reset_mode == 1)
key = java_get_game_settings_sneak_key(c->jvm, settings);
else
key = java_get_game_settings_forward_key(c->jvm, settings);
if (sprint_reset_mode == 2)
java_call_entity_set_sprinting(c->jvm, c->player, on != 1);
// Doing the reset: sneak is pressed, the other keys are let go.
// Giving it back: the key goes back to what the player physically holds.
unsigned char pressed = on ? (sprint_reset_mode == 1) : java_get_key_binding_key_code(c->jvm, key);
java_set_key_binding_pressed(c->jvm, key, pressed);
}
+50
View File
@@ -0,0 +1,50 @@
// Sprint Reset — Resets your sprint state to deal more knockback.
// category: combat descriptor: 0x2efd00 settings block: 0x2efef8
// functions: gui sprint_reset_gui, register sprint_reset_register, status sprint_reset_status
// implementation: src/logic/combat/sprint_reset.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_sprint_reset); // "Main"
S(str_conditions_in_sprint_reset); // "Conditions"
S(str_mode_in_sprint_reset); // "mode"
S(str_delay_in_sprint_reset); // "delay"
S(str_duration_in_sprint_reset); // "duration"
S(str_randomize_in_sprint_reset); // "randomize"
S(str_wait_for_damage); // "wait_for_damage"
S(str_require_weapon_in_sprint_reset); // "require_weapon"
S(str_s_in_sprint_reset); // "%s"
D(sprint_reset_enum_option_labels_1); // enum option labels (const char *[])
D(sprint_reset_mode_setting); // setting enum "mode"
extern "C" unsigned sprint_reset_mode; // current value of setting "mode" (+0x30)
D(sprint_reset_delay_setting); // setting num "delay"
D(sprint_reset_randomize_setting); // setting bool "randomize"
D(sprint_reset_wait_for_damage_setting); // setting bool "wait_for_damage"
D(sprint_reset_require_weapon_setting); // setting bool "require_weapon"
D(sprint_reset_duration_setting); // setting num "duration"
extern "C" void sprint_reset_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_sprint_reset);
W_enumw(window, gui, sprint_reset_mode_setting);
W_slider(window, gui, sprint_reset_delay_setting);
W_slider(window, gui, sprint_reset_duration_setting);
W_bool(window, gui, sprint_reset_randomize_setting);
W_label(gui, window, str_conditions_in_sprint_reset);
W_bool(window, gui, sprint_reset_wait_for_damage_setting);
W_bool(window, gui, sprint_reset_require_weapon_setting);
}
extern "C" void sprint_reset_register(void *module) {
R_enum(module, str_mode_in_sprint_reset, sprint_reset_mode_setting);
R_num(module, str_delay_in_sprint_reset, sprint_reset_delay_setting);
R_num(module, str_duration_in_sprint_reset, sprint_reset_duration_setting);
R_bool(module, str_randomize_in_sprint_reset, sprint_reset_randomize_setting);
R_bool(module, str_wait_for_damage, sprint_reset_wait_for_damage_setting);
R_bool(module, str_require_weapon_in_sprint_reset, sprint_reset_require_weapon_setting);
}
extern "C" void sprint_reset_status(void *self) {
log_fmt(self, 0x20, str_s_in_sprint_reset, ((const char **)sprint_reset_enum_option_labels_1)[sprint_reset_mode]);
}
+290
View File
@@ -0,0 +1,290 @@
// Timer Range - freeze the game for a moment, then catch up in a burst that carries you into hit range.
//
// When a target is a few ticks of walking away, the module works out how many ticks of
// walking forwards would bring it into reach. It then freezes the game timer for that many
// ticks' worth of time and plays them all at once, so you arrive in range (and attack)
// before the target can react.
// mode 0: freeze first, then play the ticks quickly
// mode 1: play the ticks at once, then freeze (holding packets) to even out the time
//
// Callbacks:
// timer_range_on_packet_sent every outgoing packet: hold it during a mode 1 freeze
// timer_range_on_timer_phase module switched off: restore the timer
// timer_range_hypot helper: start the freeze
// timer_range_tick every tick: during a burst attack; otherwise check if a burst is possible
// timer_range_render_tick every frame: end the freeze; simulate ticks ahead to plan a burst
#include "slinky/engine.h"
struct Vec3 { double x, y, z; };
struct Rot { float yaw, pitch; };
struct Box { Vec3 lo, hi; };
struct FrameEvt {
char padding_00[8];
Ctx *ctx; // +0x08 game context
float partial; // +0x10 how far we are between two ticks (0..1)
int padding_14;
double dt; // +0x18 seconds since the last frame
};
struct PktHook { char padding_00[0x24]; int verdict; }; // +0x24 set to 1 to hold the packet
struct EvHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
void *ev; // +0x10 module descriptor that was toggled
unsigned char on; // +0x18 1 = switched on
};
// ---- settings ----
extern "C" int timer_range_mode; // see above
extern "C" unsigned char timer_range_block_while_charging; // block with the sword while frozen (mode 0)
extern "C" unsigned char timer_range_require_mouse_pressed;
extern "C" unsigned char timer_range_require_weapon;
extern "C" unsigned char timer_range_require_not_using_item;
extern "C" float timer_range_max_ticks, timer_range_max_ticks_second; // max ticks to skip (mode 0 / mode 1)
extern "C" float timer_range_min_range; // don't burst when this close already
extern "C" float timer_range_cooldown_after_burst; // seconds between bursts
// ---- module state ----
extern "C" char timer_range_module_descriptor[];
extern "C" int timer_range_delay_ticks; // ticks left in the burst
extern "C" unsigned char timer_range_timer_modified; // the timer is frozen
extern "C" unsigned char timer_range_holding_packets; // read by the network thread
extern "C" unsigned char timer_range_burst_would_reach_target; // a burst is possible this tick
extern "C" float timer_range_last_forward_input, timer_range_last_strafe_input;
extern "C" double timer_range_cooldown; // seconds before the next burst
extern "C" double timer_range_freeze_time_left; // seconds
// ---- game / engine functions ----
FN(void *, get_timer, (void *jvm, void *timer)); // the game's tick timer
FN(void, java_set_timer_timer_speed, (void *jvm, void *timer, float speed));
FN(void, java_set_timer_elapsed_partial_ticks, (void *jvm, void *timer, float ticks)); // ticks to run on the next frame
FN(void *, item_held_hotbar_slot, (void *jvm, void *slot));
FN(unsigned char, item_sword, (void *jvm, void *item));
FN(void *, get_game_settings, (void *jvm, void *object));
FN(void *, java_get_game_settings_use_item_key, (void *jvm, void *game_settings));
FN(void, java_set_key_binding_pressed, (void *jvm, void *key_binding, unsigned char on));
FN(void, java_increment_key_binding_press_time, (void *jvm, void *key_binding)); // = one click
FN(void *, java_get_minecraft_object_mouse_over, (void *jvm, void *minecraft));
FN(int, java_get_moving_object_position_type_ordinal, (void *jvm, void *hit)); // 2 = an entity
FN(void, java_set_minecraft_left_click_counter, (void *jvm, void *minecraft, int n));
FN(void *, java_get_game_settings_attack_key, (void *jvm, void *game_settings));
FN(unsigned char, java_get_entity_on_ground, (void *jvm, void *entity));
FN(int, java_get_entity_living_base_hurt_time, (void *jvm, void *entity_living_base));
FN(unsigned char, vertex_pointer_current, (Ctx *ctx)); // a mouse button is held
FN(unsigned char, is_holding_accepted_weapon, (void *jvm, void *object));
FN(unsigned char, java_call_entity_player_is_using_item, (void *jvm, void *entity_player));
FN(Vec3, java_get_entity_motion_x, (void *jvm, void *entity));
FN(void *, get_held_item, (void *jvm, void *game_settings)); // here: the jump key
FN(unsigned char, is_key_down, (void *jvm, void *k));
FN(Vec3, java_get_entity_pos_x, (void *jvm, void *entity));
FN(unsigned char, java_variant, (void *jvm));
FN(Vec3, vec3_add_eye_height, (Vec3 v));
FN(Vec3, java_get_entity_other_player_mp_other_player_mpx, (void *jvm, void *entity_other_player_mp)); // target's server position
FN(unsigned char, set_vertex_pointer, (void *jvm, void *world, Vec3 from, Vec3 to)); // clear line of sight between two points
FN(void, timer_range_read_movement_axes, (void *jvm, void *game_settings)); // fills timer_range_last_*_input
FN(int, java_get_entity_other_player_mp_other_player_mppos_rotation_increments, (void *jvm, void *entity_other_player_mp)); // interpolation steps left
FN(Rot, get_entity_rotation, (void *jvm, void *entity));
FN(float, libc_cosf, (float x));
FN(float, libc_sinf, (float x));
FN(Vec3, vec3_make, (double x, double y, double z));
FN(Vec3, vec3_sub, (Vec3 a, Vec3 b));
FN(Vec3, vec3_add, (Vec3 a, Vec3 b));
FN(Vec3, vec3_scale, (Vec3 v, double k));
FN(Vec3, vec3_reciprocal, (Vec3 v));
FN(unsigned char, aabb_ray_slab_test, (Box b, Vec3 origin, Vec3 dir)); // does the ray hit the box?
FN(Vec3, aabb_clamp_point, (Box b, Vec3 p)); // closest point of the box
FN(double, vec3_distance_sq, (Vec3 a, Vec3 b));
FN(float, java_get_entity_living_base_land_movement_factor, (void *jvm, void *entity_living_base));
FN(Vec3, horizontal_motion, (Rot rotation, float fwd, float strafe, float speed)); // motion one tick of input adds
FN(double, libc_hypot, (double x, double y));
static const double DEGREES_TO_RADIANS = 0.017453292519943295;
extern "C" void timer_range_hypot(Ctx *ctx);
extern "C" void timer_range_on_packet_sent(PktHook *hook) {
if (__atomic_load_n(&timer_range_holding_packets, __ATOMIC_SEQ_CST) & 1)
hook->verdict = 1;
}
// On disable: normal timer speed, no burst.
extern "C" void timer_range_on_timer_phase(EvHook *hook) {
if (hook->ev != timer_range_module_descriptor || hook->on)
return;
Ctx *ctx = hook->ctx;
void *timer = get_timer(ctx->jvm, ctx->minecraft);
java_set_timer_timer_speed(ctx->jvm, timer, 1.0f);
timer_range_timer_modified = 0;
timer_range_delay_ticks = 0;
__atomic_exchange_n(&timer_range_holding_packets, (unsigned char)0, __ATOMIC_SEQ_CST);
}
// Start the freeze (the timer stops; mode 1 also holds packets; mode 0 can block meanwhile).
extern "C" void timer_range_hypot(Ctx *c) {
void *timer = get_timer(c->jvm, c->minecraft);
java_set_timer_timer_speed(c->jvm, timer, 0.0f);
timer_range_timer_modified = 1;
if (timer_range_mode == 1) {
__atomic_exchange_n(&timer_range_holding_packets, (unsigned char)1, __ATOMIC_SEQ_CST);
} else if (timer_range_block_while_charging == 1 && item_sword(c->jvm, item_held_hotbar_slot(c->jvm, c->player))) {
void *use_key = java_get_game_settings_use_item_key(c->jvm, get_game_settings(c->jvm, c->minecraft));
java_set_key_binding_pressed(c->jvm, use_key, 1);
java_increment_key_binding_press_time(c->jvm, use_key);
}
}
extern "C" void timer_range_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
CombatTarget *target = (CombatTarget *)ctx->target;
if (timer_range_delay_ticks > 0) {
// In a burst: count it down (mode 0 freezes at the end), and attack when on the target.
void *settings = get_game_settings(ctx->jvm, ctx->minecraft);
int ticks_left = --timer_range_delay_ticks;
if (ticks_left == 0 && timer_range_mode == 0)
timer_range_hypot(ctx);
if (ctx->in_game != 1 || !target->ent)
return;
void *hit = java_get_minecraft_object_mouse_over(ctx->jvm, ctx->minecraft);
if (!hit || java_get_moving_object_position_type_ordinal(ctx->jvm, hit) != 2)
return;
java_set_minecraft_left_click_counter(ctx->jvm, ctx->minecraft, 0);
java_increment_key_binding_press_time(ctx->jvm, java_get_game_settings_attack_key(ctx->jvm, settings));
return;
}
// Is a burst possible? Target further than sqrt(3) blocks, we stand on the ground walking
// forwards (not jumping), the target can be hurt, and we can see it.
timer_range_burst_would_reach_target = 0;
if (ctx->in_game != 1)
return;
if (!target->ent || 3.0 > target->dist2)
return;
if (!java_get_entity_on_ground(ctx->jvm, ctx->player) || java_get_entity_living_base_hurt_time(ctx->jvm, target->ent) > 1)
return;
if (timer_range_require_mouse_pressed == 1 && !vertex_pointer_current(ctx))
return;
if (timer_range_require_weapon == 1 && !is_holding_accepted_weapon(ctx->jvm, ctx->player))
return;
if (timer_range_require_not_using_item == 1 && java_call_entity_player_is_using_item(ctx->jvm, ctx->player))
return;
if (java_get_entity_motion_x(ctx->jvm, ctx->player).y > 0.0)
return;
void *settings = get_game_settings(ctx->jvm, ctx->minecraft);
if (is_key_down(ctx->jvm, get_held_item(ctx->jvm, settings)))
return; // jumping
Vec3 my_eye = java_get_entity_pos_x(ctx->jvm, ctx->player);
if (!java_variant(ctx->jvm))
my_eye = vec3_add_eye_height(my_eye);
Vec3 target_eye = java_get_entity_other_player_mp_other_player_mpx(ctx->jvm, target->ent);
if (!java_variant(ctx->jvm))
target_eye = vec3_add_eye_height(target_eye);
if (!set_vertex_pointer(ctx->jvm, ctx->world, my_eye, target_eye))
return;
timer_range_read_movement_axes(ctx->jvm, settings);
timer_range_burst_would_reach_target = timer_range_last_forward_input > 0.0f;
}
// End of the freeze: normal speed again.
static void end_freeze(Ctx *ctx, void *timer) {
java_set_timer_timer_speed(ctx->jvm, get_timer(ctx->jvm, ctx->minecraft), 1.0f);
timer_range_timer_modified = 0;
__atomic_exchange_n(&timer_range_holding_packets, (unsigned char)0, __ATOMIC_SEQ_CST);
int mode = timer_range_mode;
if (mode != 1 && timer_range_block_while_charging == 1) {
if (item_sword(ctx->jvm, item_held_hotbar_slot(ctx->jvm, ctx->player)))
java_set_key_binding_pressed(ctx->jvm, java_get_game_settings_use_item_key(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft)), 0);
mode = timer_range_mode;
}
// Mode 1: now play the burst's ticks at once.
if (mode == 1)
java_set_timer_elapsed_partial_ticks(ctx->jvm, timer, (float)timer_range_delay_ticks);
}
// Every frame.
extern "C" void timer_range_render_tick(FrameEvt *h) {
Ctx *ctx = h->ctx;
void *timer = get_timer(ctx->jvm, ctx->minecraft);
if (timer_range_timer_modified == 1) {
timer_range_freeze_time_left -= h->dt;
if (timer_range_freeze_time_left > 0.0) {
java_set_timer_timer_speed(ctx->jvm, timer, 0.0f);
return;
}
end_freeze(ctx, timer);
}
if (timer_range_cooldown > 0.0) {
timer_range_cooldown -= h->dt;
return;
}
if (timer_range_burst_would_reach_target != 1 || ctx->in_game != 1)
return;
CombatTarget *target = (CombatTarget *)ctx->target;
if (!target->ent)
return;
// Simulate the next ticks: us walking forwards, the target moving to its server position.
Vec3 motion = java_get_entity_motion_x(ctx->jvm, ctx->player);
Vec3 my_eye = java_get_entity_pos_x(ctx->jvm, ctx->player);
if (!java_variant(ctx->jvm))
my_eye = vec3_add_eye_height(my_eye);
Vec3 target_pos = java_get_entity_pos_x(ctx->jvm, target->ent);
Vec3 target_server_pos = java_get_entity_other_player_mp_other_player_mpx(ctx->jvm, target->ent);
int interpolation_steps = java_get_entity_other_player_mp_other_player_mppos_rotation_increments(ctx->jvm, target->ent);
// Our look direction (unit vector, as Minecraft computes it).
Rot rotation = get_entity_rotation(ctx->jvm, ctx->player);
float yaw_radians = (float)((double)-3.14159265f - (double)rotation.yaw * DEGREES_TO_RADIANS);
float cos_yaw = libc_cosf(yaw_radians), sin_yaw = libc_sinf(yaw_radians);
float pitch_radians = (float)((double)-rotation.pitch * DEGREES_TO_RADIANS);
float minus_cos_pitch = -libc_cosf(pitch_radians), sin_pitch = libc_sinf(pitch_radians);
Vec3 look = {(double)(sin_yaw * minus_cos_pitch), (double)sin_pitch, (double)(cos_yaw * minus_cos_pitch)};
int max_ticks = (int)(timer_range_mode == 0 ? timer_range_max_ticks : timer_range_max_ticks_second);
for (int ticks = 1; ticks <= max_ticks; ticks++) {
// Would we hit the target's hitbox from here (looking 3 blocks ahead)?
Box hitbox;
hitbox.lo = vec3_sub(target_pos, vec3_make(0.4, 0.1, 0.4));
hitbox.hi = vec3_add(target_pos, vec3_make(0.4, 1.9, 0.4));
Vec3 inverse_ray = vec3_reciprocal(vec3_scale(look, 3.0));
if (aabb_ray_slab_test(hitbox, my_eye, inverse_ray)) {
double distance_sq = vec3_distance_sq(my_eye, aabb_clamp_point(hitbox, my_eye));
if (distance_sq > 0.0) {
if ((double)(timer_range_min_range * timer_range_min_range) > distance_sq)
return; // already close enough
// Plan the burst of `ticks` ticks.
if (timer_range_mode == 1)
timer_range_hypot(ctx);
else
java_set_timer_elapsed_partial_ticks(ctx->jvm, timer, (float)ticks);
timer_range_delay_ticks = ticks;
timer_range_freeze_time_left = (double)((float)ticks - h->partial) * 0.05; // 0.05 s per tick
timer_range_cooldown = timer_range_cooldown_after_burst;
return;
}
}
// One tick of our movement (ground friction 0.546)...
Vec3 push = horizontal_motion(rotation, timer_range_last_forward_input, timer_range_last_strafe_input, java_get_entity_living_base_land_movement_factor(ctx->jvm, ctx->player));
motion = vec3_add(motion, push);
my_eye = vec3_add(my_eye, motion);
motion = vec3_scale(motion, 0.546);
if (timer_range_mode == 1) {
// (mode 1: assume the target walks towards us at our speed)
double speed = libc_hypot(motion.x, motion.z);
Vec3 towards_us = vec3_sub(my_eye, target_server_pos);
Vec3 step = vec3_scale(towards_us, speed / libc_hypot(towards_us.x, towards_us.z));
step.y = 0.0;
target_server_pos = vec3_add(target_server_pos, step);
}
// ...and the target sliding towards its server position.
if (interpolation_steps > 0) {
Vec3 remaining = vec3_sub(target_server_pos, target_pos);
target_pos = vec3_add(target_pos, vec3_scale(remaining, 1.0 / (double)interpolation_steps));
interpolation_steps -= 1;
}
}
}
+62
View File
@@ -0,0 +1,62 @@
// Timer Range — Abuses timer lag to teleport you.
// category: combat descriptor: 0x2f3160 settings block: 0x2f3358
// functions: gui timer_range_gui, register timer_range_register, status timer_range_status
// implementation: src/logic/combat/timer_range.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_timer_range); // "Main"
S(str_conditions_in_timer_range); // "Conditions"
S(str_mode_in_timer_range); // "mode"
S(str_min_dist); // "min_dist"
S(str_duration_in_timer_range); // "duration"
S(str_duration_legit); // "duration_legit"
S(str_cooldown_in_timer_range); // "cooldown"
S(str_block_while_frozen_in_timer_range); // "block_while_frozen"
S(str_require_mouse_pressed_in_timer_range); // "require_mouse_pressed"
S(str_require_weapon_in_timer_range); // "require_weapon"
S(str_require_not_using_item_in_timer_range); // "require_not_using_item"
S(str_s_in_timer_range); // "%s"
D(timer_range_require_mouse_pressed_setting); // setting bool "require_mouse_pressed"
D(timer_range_require_weapon_setting); // setting bool "require_weapon"
D(timer_range_require_not_using_item_setting); // setting bool "require_not_using_item"
D(timer_range_enum_option_labels_1); // enum option labels (const char *[])
D(timer_range_mode_setting); // setting enum "mode"
extern "C" unsigned timer_range_mode; // current value of setting "mode" (+0x30)
D(timer_range_block_while_frozen_setting); // setting bool "block_while_frozen"
D(timer_range_cooldown_setting); // setting num "cooldown"
D(timer_range_duration_setting); // setting num "duration"
D(timer_range_duration_legit_setting); // setting num "duration_legit"
D(timer_range_min_dist_setting); // setting num "min_dist"
extern "C" void timer_range_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_timer_range);
W_enumw(window, gui, timer_range_mode_setting);
W_slider(window, gui, timer_range_min_dist_setting);
W_slider(window, gui, timer_range_mode == 0 ? timer_range_duration_setting : timer_range_duration_legit_setting);
W_slider(window, gui, timer_range_cooldown_setting);
if (timer_range_mode == 0)
W_bool(window, gui, timer_range_block_while_frozen_setting);
W_label(gui, window, str_conditions_in_timer_range);
W_bool(window, gui, timer_range_require_mouse_pressed_setting);
W_bool(window, gui, timer_range_require_weapon_setting);
W_bool(window, gui, timer_range_require_not_using_item_setting);
}
extern "C" void timer_range_register(void *module) {
R_enum(module, str_mode_in_timer_range, timer_range_mode_setting);
R_num(module, str_min_dist, timer_range_min_dist_setting);
R_num(module, str_duration_in_timer_range, timer_range_duration_setting);
R_num(module, str_duration_legit, timer_range_duration_legit_setting);
R_num(module, str_cooldown_in_timer_range, timer_range_cooldown_setting);
R_bool(module, str_block_while_frozen_in_timer_range, timer_range_block_while_frozen_setting);
R_bool(module, str_require_mouse_pressed_in_timer_range, timer_range_require_mouse_pressed_setting);
R_bool(module, str_require_weapon_in_timer_range, timer_range_require_weapon_setting);
R_bool(module, str_require_not_using_item_in_timer_range, timer_range_require_not_using_item_setting);
}
extern "C" void timer_range_status(void *self) {
log_fmt(self, 0x20, str_s_in_timer_range, ((const char **)timer_range_enum_option_labels_1)[timer_range_mode]);
}
+343
View File
@@ -0,0 +1,343 @@
// Velocity - take less knockback.
//
// Four ways ("mode"):
// 0 "reduce": when hit from the front, multiply the sideways knockback by "reduce_amount"
// (after "reduce_delay" ticks)
// 1 "jump": jump the moment you get knocked back (a "jump reset"), which cancels most of it
// 2 "hit": when you hit the target back, keep only 60% of your own motion (like a sprint hit)
// 3 "delayed": ignore the knockback and keep the motion you had the tick before
// "chance", "require_*" and the target conditions decide when it works.
//
// Callbacks:
// velocity_disable module switched off
// velocity_attack before our attack: save our motion
// velocity_tick every tick: save our motion
// velocity_mode_3_delayed every tick (mode 3)
// velocity_packet_hook_watch every incoming packet: notice knockback / explosions / teleports
// velocity_mode_2_reduce after our attack (mode 2)
// velocity_shared_conditions the "require_*" and target conditions
// velocity_tick_mode_0 every tick (modes 0 and 1)
#include "slinky/engine.h"
#include "slinky/jids.h"
struct Vec3 { double x, y, z; };
struct Rot { float yaw, pitch; };
struct Range { float lo, hi; };
struct PhaseHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
unsigned char phase; // +0x10 1 = the attack happens
};
struct EvHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
void *ev; // +0x10 module descriptor that was toggled
unsigned char on; // +0x18 1 = switched on
};
struct PktHook {
char padding_00[8];
void *ctx; // +0x08 JVM handle
void *ev; // +0x10 the packet
char padding_18[12];
int verdict; // +0x24 non-zero: another module is holding it
};
// ---- settings ----
extern "C" unsigned velocity_mode; // "mode"
extern "C" float velocity_chance_setting; // "chance" (mode 3), in percent
extern "C" unsigned velocity_keep_vertical_1_air_2; // mode 3: keep the old vertical motion too: 1 = in the air, 2 = always
extern "C" unsigned char velocity_require_moving_setting; // "require_moving": only while walking forwards
extern "C" unsigned char velocity_require_weapon_value; // "require_weapon"
extern "C" unsigned char velocity_require_mouse_value; // "require_mouse"
extern "C" unsigned char velocity_require_target_value; // "require_target": a player within 6 blocks in front of us
extern "C" unsigned char velocity_require_sprinting_jump_value; // mode 1: only while sprinting
extern "C" unsigned char velocity_every_hit_setting; // mode 2: on every hit, not only the first of a combo
extern "C" float velocity_reduce_chance_value; // mode 0 chance, in percent
extern "C" float velocity_reduce_delay_value; // mode 0 delay, ticks
extern "C" float velocity_reduce_amount; // mode 0 multiplier
extern "C" float velocity_fov_value; // mode 0: only when hit from within this angle (radians) of the front
extern "C" float velocity_jump_chance_value; // mode 1 chance, in percent
// ---- module state ----
extern "C" char velocity_module_descriptor[];
extern "C" unsigned char velocity_tick_motion_saved;
extern "C" Vec3 velocity_motion_at_last_tick;
extern "C" Vec3 velocity_motion_at_our_last_hit;
extern "C" unsigned char velocity_reduced_this_combo;
extern "C" int velocity_delay_ticks;
extern "C" unsigned char velocity_jump_key_pressed_by_us;
extern "C" char velocity_random_walk_1[];
// Shared with the network thread:
extern "C" int velocity_own_entity_id;
extern "C" unsigned char velocity_strong_knockback; // we just got knocked back (or a strong explosion)
extern "C" unsigned char velocity_own_velocity_packet_seen; // we were just teleported by the server
// ---- game / engine functions ----
FN(unsigned char, velocity_shared_conditions_entry, (Ctx *ctx)); // = velocity_shared_conditions
FN(unsigned char, vertex_pointer_current, (Ctx *ctx)); // a mouse button is held
FN(Vec3, java_get_entity_pos_x, (void *jvm, void *entity));
FN(Rot, get_entity_rotation, (void *jvm, void *entity));
FN(void *, java_get_world_player_entities, (void *jvm, void *world));
FN(int, java_call_list_size, (void *jvm, void *list));
FN(void *, java_call_list_get, (void *jvm, void *list, int i));
FN(double, vec3_distance_sq, (Vec3 a, Vec3 b));
FN(Rot, rot_look_at, (Vec3 from, Vec3 to));
FN(float, wrap_angle, (float a)); // to -180..180
FN(int, java_get_entity_entity_id, (void *jvm, void *entity));
FN(void *, get_game_settings, (void *jvm, void *object));
FN(void *, get_held_item, (void *jvm, void *item)); // here: the jump key
FN(unsigned char, java_get_key_binding_key_code, (void *jvm, void *key_binding)); // key physically held down
FN(unsigned char, is_key_down, (void *jvm, void *k));
FN(void, java_set_key_binding_pressed, (void *jvm, void *key_binding, unsigned char on));
FN(unsigned char, java_call_entity_is_sprinting, (void *jvm, void *entity));
FN(void *, java_potion_potion_types, (void *jvm, int id));
FN(void *, java_call_entity_living_base_get_active_potion_effect, (void *jvm, void *entity_living_base, void *effect));
FN(double, libc_hypot, (double x, double z));
FN(float, libc_sinf, (float v));
FN(float, libc_cosf, (float v));
FN(double, libc_acos, (double v));
FN(float, java_get_entity_living_base_move_forward, (void *jvm, void *entity_living_base));
FN(unsigned char, is_holding_accepted_weapon, (void *jvm, void *object));
FN(int, java_get_entity_ticks_existed, (void *jvm, void *entity));
FN(int, java_get_entity_living_base_last_attacker_time, (void *jvm, void *entity_living_base)); // tick of our last attack
FN(Range, rot_make_floats, (float lo, float hi));
FN(unsigned char, walk_should_change, (void *state, Range r, double p)); // random yes/no
FN(unsigned char, java_get_entity_on_ground, (void *jvm, void *entity));
FN(Vec3, java_get_entity_motion_x, (void *jvm, void *entity));
FN(void, java_set_entity_motion_x, (void *jvm, void *entity, Vec3 value));
FN(void *, java_jni_is_instance_of_s12_packet_entity_velocity, (void *ctx, void *event)); // knockback packet, or null
FN(int, java_get_s12_packet_entity_velocity_entity_id, (void *ctx, void *s12_packet_entity_velocity));
FN(void *, java_jni_is_instance_of_s27_packet_explosion, (void *ctx, void *event));
FN(float, java_get_s27_packet_explosion_f, (void *ctx, void *s27_packet_explosion)); // push x
FN(float, java_get_s27_packet_explosion_h, (void *ctx, void *s27_packet_explosion)); // push z
FN(void *, java_jni_is_instance_of_s08_packet_player_pos_look, (void *ctx, void *event)); // server teleported us
enum VelocityMode { MODE_REDUCE = 0, MODE_JUMP = 1, MODE_HIT = 2, MODE_DELAYED = 3 };
enum { POTION_JUMP_BOOST = 8 };
// A chance in percent: always yes above 99, otherwise a random walk around it.
static bool roll(float percent) {
if (percent > 99.0f)
return true;
double p = (float)((double)percent * 0.01);
return walk_should_change(velocity_random_walk_1, rot_make_floats((float)(-0.05 + p), (float)(p + 0.05)), 60.0);
}
// Did the knockback flag get raised? (and clear it)
static bool take_knockback_flag() {
unsigned char expected = 1;
return __atomic_compare_exchange_n(&velocity_strong_knockback, &expected, 0, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
}
extern "C" void velocity_disable(EvHook *hook) {
if (hook->ev == velocity_module_descriptor)
velocity_tick_motion_saved = 0;
}
extern "C" void velocity_attack(PhaseHook *hook) {
if (hook->phase != 1)
return;
Ctx *ctx = hook->ctx;
if (ctx->player)
velocity_motion_at_our_last_hit = java_get_entity_motion_x(ctx->jvm, ctx->player);
}
extern "C" void velocity_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
if (ctx->player) {
velocity_motion_at_last_tick = java_get_entity_motion_x(ctx->jvm, ctx->player);
velocity_tick_motion_saved = 1;
}
}
// Mode 3: put back the motion of the tick before.
extern "C" void velocity_mode_3_delayed(Hook *hook) {
if (velocity_mode != MODE_DELAYED)
return;
Ctx *ctx = hook->ctx;
if (ctx->in_game != 1)
return;
// Not right after a teleport.
if (__atomic_load_n(&velocity_own_velocity_packet_seen, __ATOMIC_SEQ_CST) & 1) {
__atomic_exchange_n(&velocity_own_velocity_packet_seen, (unsigned char)0, __ATOMIC_SEQ_CST);
return;
}
if (velocity_tick_motion_saved != 1 || !velocity_shared_conditions_entry(ctx))
return;
if (!roll(velocity_chance_setting))
return;
Vec3 motion = java_get_entity_motion_x(ctx->jvm, ctx->player);
motion.x = velocity_motion_at_last_tick.x;
unsigned keep_vertical = velocity_keep_vertical_1_air_2;
if (keep_vertical == 2 || (keep_vertical == 1 && !java_get_entity_on_ground(ctx->jvm, ctx->player)))
motion.y = velocity_motion_at_last_tick.y;
motion.z = velocity_motion_at_last_tick.z;
java_set_entity_motion_x(ctx->jvm, ctx->player, motion);
velocity_tick_motion_saved = 0;
}
// Every incoming packet (network thread).
extern "C" void velocity_packet_hook_watch(PktHook *hook) {
if (hook->verdict != 0)
return;
// Knockback for us.
void *knockback = java_jni_is_instance_of_s12_packet_entity_velocity(hook->ctx, hook->ev);
if (knockback) {
if (java_get_s12_packet_entity_velocity_entity_id(hook->ctx, knockback) == velocity_own_entity_id)
__atomic_exchange_n(&velocity_strong_knockback, (unsigned char)1, __ATOMIC_SEQ_CST);
return;
}
// An explosion pushing us noticeably.
void *explosion = java_jni_is_instance_of_s27_packet_explosion(hook->ctx, hook->ev);
if (explosion) {
float push_x = java_get_s27_packet_explosion_f(hook->ctx, explosion);
float push_z = java_get_s27_packet_explosion_h(hook->ctx, explosion);
unsigned char strong = (double)(push_x * push_x + push_z * push_z) > 0.05;
__atomic_exchange_n(&velocity_strong_knockback, strong, __ATOMIC_SEQ_CST);
return;
}
if (java_jni_is_instance_of_s08_packet_player_pos_look(hook->ctx, hook->ev))
__atomic_exchange_n(&velocity_own_velocity_packet_seen, (unsigned char)1, __ATOMIC_SEQ_CST);
}
// Mode 2: when our hit lands on a target, slow our own motion to 60% (as a sprint hit would).
extern "C" void velocity_mode_2_reduce(PhaseHook *hook) {
if (velocity_mode != MODE_HIT)
return;
if (velocity_reduced_this_combo == 1 && !velocity_every_hit_setting)
return;
if (hook->phase != 1)
return;
Ctx *ctx = hook->ctx;
if (!ctx->player || ((CombatTarget *)ctx->target)->valid != 1)
return;
if (velocity_require_moving_setting == 1 && 0.0f >= java_get_entity_living_base_move_forward(ctx->jvm, ctx->player))
return;
if (velocity_require_weapon_value == 1 && !is_holding_accepted_weapon(ctx->jvm, ctx->player))
return;
if (java_get_entity_ticks_existed(ctx->jvm, ctx->player) != java_get_entity_living_base_last_attacker_time(ctx->jvm, ctx->player))
return; // the hit did not land
velocity_motion_at_our_last_hit.x *= 0.6;
velocity_motion_at_our_last_hit.z *= 0.6;
java_set_entity_motion_x(ctx->jvm, ctx->player, velocity_motion_at_our_last_hit);
velocity_reduced_this_combo = 1;
}
// The "require_*" conditions, and "require_target": another player within 6 blocks
// and within 90 degrees of where we look.
extern "C" unsigned char velocity_shared_conditions(Ctx *ctx) {
if (velocity_require_moving_setting == 1 && 0.0f >= java_get_entity_living_base_move_forward(ctx->jvm, ctx->player))
return 0;
if (velocity_require_mouse_value == 1 && !vertex_pointer_current(ctx))
return 0;
if (velocity_require_weapon_value == 1 && !is_holding_accepted_weapon(ctx->jvm, ctx->player))
return 0;
if (velocity_require_target_value != 1)
return 1;
Vec3 my_pos = java_get_entity_pos_x(ctx->jvm, ctx->player);
Rot rotation = get_entity_rotation(ctx->jvm, ctx->player);
void *players = java_get_world_player_entities(ctx->jvm, ctx->world);
for (int i = 0; i < java_call_list_size(ctx->jvm, players); i++) {
void *other = java_call_list_get(ctx->jvm, players, i);
JNIEnv *env = ((Jvm *)ctx->jvm)->env;
if ((*env)->IsSameObject(env, ctx->player, other))
continue; // ourselves
Vec3 other_pos = java_get_entity_pos_x(ctx->jvm, other);
if (vec3_distance_sq(my_pos, other_pos) > 36.0)
continue;
float angle = __builtin_fabsf(wrap_angle(rot_look_at(my_pos, other_pos).yaw - rotation.yaw));
if (angle > 90.0f)
continue;
return 1;
}
return 0;
}
// Mode 1: jump on knockback.
static void jump_reset(Ctx *ctx) {
// We pressed jump last tick: give the key back.
if (velocity_jump_key_pressed_by_us == 1) {
void *jump_key = get_held_item(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft));
java_set_key_binding_pressed(ctx->jvm, jump_key, java_get_key_binding_key_code(ctx->jvm, jump_key));
velocity_jump_key_pressed_by_us = 0;
return;
}
// Only as a reaction to knockback (the packet hook raises the flag).
if (!take_knockback_flag())
return;
if (!velocity_shared_conditions(ctx) || !roll(velocity_jump_chance_value))
return;
if (velocity_require_sprinting_jump_value == 1 && !java_call_entity_is_sprinting(ctx->jvm, ctx->player))
return;
if (!java_get_entity_on_ground(ctx->jvm, ctx->player))
return;
if (0.0 < java_get_entity_motion_x(ctx->jvm, ctx->player).y)
return;
if (java_call_entity_living_base_get_active_potion_effect(ctx->jvm, ctx->player, java_potion_potion_types(ctx->jvm, POTION_JUMP_BOOST)))
return;
void *jump_key = get_held_item(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft));
if (is_key_down(ctx->jvm, jump_key))
return;
java_set_key_binding_pressed(ctx->jvm, jump_key, 1);
velocity_jump_key_pressed_by_us = 1;
}
// Mode 0: after knockback from the front, reduce the sideways motion after "reduce_delay" ticks.
static void reduce_after_delay(Ctx *ctx) {
int ticks = velocity_delay_ticks;
bool apply_now = false;
if (ticks <= 0) {
// Not waiting: start on new knockback.
if (!take_knockback_flag())
return;
if (!velocity_shared_conditions(ctx) || !roll(velocity_reduce_chance_value))
return;
Vec3 motion = java_get_entity_motion_x(ctx->jvm, ctx->player);
double speed = libc_hypot(motion.x, motion.z);
if (speed == 0.0)
return;
// Angle between where we look and where we are pushed: must be within "fov".
float yaw = get_entity_rotation(ctx->jvm, ctx->player).yaw;
float facing = (float)((double)yaw * -3.141592653589793 / 180.0 + -3.141592653589793);
float sin_facing = libc_sinf(facing);
float cos_facing = libc_cosf(facing);
double angle = libc_acos(((double)sin_facing * motion.x + (double)cos_facing * motion.z) / speed);
if (!((double)velocity_fov_value >= angle))
return;
ticks = (int)velocity_reduce_delay_value;
velocity_delay_ticks = ticks;
apply_now = ticks <= 0;
}
if (!apply_now) {
velocity_delay_ticks = ticks - 1;
if (ticks - 1 != 0)
return;
}
Vec3 motion = java_get_entity_motion_x(ctx->jvm, ctx->player);
double amount = velocity_reduce_amount;
motion.x *= amount;
motion.z *= amount;
java_set_entity_motion_x(ctx->jvm, ctx->player, motion);
}
// Every tick (modes 0 and 1).
extern "C" void velocity_tick_mode_0(Hook *hook) {
velocity_reduced_this_combo = 0;
if (velocity_mode == MODE_HIT)
return;
Ctx *ctx = hook->ctx;
if (ctx->in_game != 1)
return;
__atomic_exchange_n(&velocity_own_entity_id, java_get_entity_entity_id(ctx->jvm, ctx->player), __ATOMIC_SEQ_CST);
unsigned mode = velocity_mode;
if (mode == MODE_JUMP)
jump_reset(ctx);
else if (mode == MODE_REDUCE)
reduce_after_delay(ctx);
}
+104
View File
@@ -0,0 +1,104 @@
// Velocity — Reduces the amount of knockback you take.
// category: combat descriptor: 0x2ea7f0 settings block: 0x2ea9e8
// functions: gui velocity_gui, register velocity_register, status velocity_status
// implementation: src/logic/combat/velocity.cpp
#pragma once
#include "slinky/api.h"
extern "C" float factor_100; // 100
S(str_0f_in_velocity); // "%.0f%%"
S(str_main_in_velocity); // "Main"
S(str_conditions_in_velocity); // "Conditions"
S(str_mode_in_velocity); // "mode"
S(str_reduce_chance); // "reduce_chance"
S(str_fov_in_velocity); // "fov"
S(str_reduce_amount); // "reduce_amount"
S(str_reduce_delay_in_velocity); // "reduce_delay"
S(str_jump_chance); // "jump_chance"
S(str_reduce_multiple_per_tick); // "reduce_multiple_per_tick"
S(str_ignore_vertical_in_velocity); // "ignore_vertical"
S(str_ignore_chance); // "ignore_chance"
S(str_require_target); // "require_target"
S(str_require_mouse); // "require_mouse"
S(str_require_forward); // "require_forward"
S(str_require_weapon_in_velocity); // "require_weapon"
S(str_require_sprinting_jump); // "require_sprinting_jump"
S(str_s_in_velocity); // "%s"
D(velocity_enum_option_labels_1); // enum option labels (const char *[])
D(velocity_mode_setting); // setting enum "mode"
extern "C" unsigned velocity_mode; // current value of setting "mode" (+0x30)
D(velocity_ignore_chance_setting); // setting num "ignore_chance"
D(velocity_require_forward_setting); // setting bool "require_forward"
D(velocity_require_mouse_setting); // setting bool "require_mouse"
D(velocity_require_weapon_setting); // setting bool "require_weapon"
D(velocity_require_target_setting); // setting bool "require_target"
D(velocity_ignore_vertical_setting); // setting enum "ignore_vertical"
D(velocity_reduce_multiple_per_tick_setting); // setting bool "reduce_multiple_per_tick"
D(velocity_reduce_chance_setting); // setting num "reduce_chance"
D(velocity_reduce_delay_setting); // setting num "reduce_delay"
D(velocity_reduce_amount_setting); // setting num "reduce_amount"
extern "C" float velocity_reduce_amount; // current value of setting "reduce_amount" (+0x30)
D(velocity_fov_setting); // setting num "fov"
D(velocity_jump_chance_setting); // setting num "jump_chance"
D(velocity_require_sprinting_jump_setting); // setting bool "require_sprinting_jump"
extern "C" void velocity_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_velocity);
W_enumw(window, gui, velocity_mode_setting);
switch (velocity_mode) {
case 0:
W_slider(window, gui, velocity_reduce_chance_setting);
W_slider(window, gui, velocity_fov_setting);
W_slider(window, gui, velocity_reduce_amount_setting);
W_slider(window, gui, velocity_reduce_delay_setting);
break;
case 1:
W_slider(window, gui, velocity_jump_chance_setting);
break;
case 2:
W_bool(window, gui, velocity_reduce_multiple_per_tick_setting);
break;
case 3:
W_enumw(window, gui, velocity_ignore_vertical_setting);
W_slider(window, gui, velocity_ignore_chance_setting);
break;
}
W_label(gui, window, str_conditions_in_velocity);
if (velocity_mode != 2) {
W_bool(window, gui, velocity_require_target_setting);
W_bool(window, gui, velocity_require_mouse_setting);
}
W_bool(window, gui, velocity_require_forward_setting);
W_bool(window, gui, velocity_require_weapon_setting);
if (velocity_mode == 1)
W_bool(window, gui, velocity_require_sprinting_jump_setting);
else
EPILOG_NOP();
}
extern "C" void velocity_register(void *module) {
R_enum(module, str_mode_in_velocity, velocity_mode_setting);
R_num(module, str_reduce_chance, velocity_reduce_chance_setting);
R_num(module, str_fov_in_velocity, velocity_fov_setting);
R_num(module, str_reduce_amount, velocity_reduce_amount_setting);
R_num(module, str_reduce_delay_in_velocity, velocity_reduce_delay_setting);
R_num(module, str_jump_chance, velocity_jump_chance_setting);
R_bool(module, str_reduce_multiple_per_tick, velocity_reduce_multiple_per_tick_setting);
R_enum(module, str_ignore_vertical_in_velocity, velocity_ignore_vertical_setting);
R_num(module, str_ignore_chance, velocity_ignore_chance_setting);
R_bool(module, str_require_target, velocity_require_target_setting);
R_bool(module, str_require_mouse, velocity_require_mouse_setting);
R_bool(module, str_require_forward, velocity_require_forward_setting);
R_bool(module, str_require_weapon_in_velocity, velocity_require_weapon_setting);
R_bool(module, str_require_sprinting_jump, velocity_require_sprinting_jump_setting);
}
extern "C" void velocity_status(void *self) {
if (velocity_mode)
log_fmt(self, 0x20, str_s_in_velocity, ((const char **)velocity_enum_option_labels_1)[velocity_mode]);
else
log_fmt(self, 0x20, str_0f_in_velocity, (double)(velocity_reduce_amount * factor_100));
}
+123
View File
@@ -0,0 +1,123 @@
// Weapons - decides which items count as a "weapon" for the other combat modules.
//
// Modules with "require_weapon" (and Auto Weapon) ask here. An item is a weapon when:
// - its hotbar slot is ticked in the settings, or
// - it has an enchantment that is ticked (sharpness, knockback, fire aspect), or
// - it is a sword / axe and that class is ticked, or
// - its id is in the user's custom item list.
// An empty hand counts when "fist" is ticked.
//
// Functions:
// weapons_check_held_item_cached is the held item a weapon? (cached for one tick)
// weapons_is_item_allowed_by_class sword / axe / custom list check for one item
// weapons_find_first_weapon_slot first hotbar slot with a weapon, or -1
// weapons_on_shutdown free the custom item list
#include "slinky/engine.h"
// A per-slot checkbox setting (32 bytes each); the value is at +0x18.
struct SlotSetting { char padding_00[0x18]; unsigned char on; char padding_19[7]; };
// A list of item ids (start / end pointers).
struct IdCache { void *p, *q; };
// ---- settings ----
extern "C" unsigned char weapons_fist_value; // "fist"
extern "C" SlotSetting weapons_bool_slot_1[]; // "slot 1" .. "slot 9"
extern "C" unsigned char weapons_enchant_sharpness_value; // "enchant_sharpness"
extern "C" unsigned char weapons_enchant_knockback_value; // "enchant_knockback"
extern "C" unsigned char weapons_enchant_fire_aspect_value; // "enchant_fire_aspect"
extern "C" unsigned char weapons_axes_value; // "axes"
extern "C" unsigned char weapons_swords_value; // "swords"
extern "C" IdCache weapons_slot_id_vector; // custom item ids
// ---- cache: the answer for the current tick ----
extern "C" int weapons_cached_key; // tick the answer is for
extern "C" unsigned char weapons_cached_verdict; // the answer
extern "C" unsigned weapons_cached_enchant_flags; // enchantments of the held item
// ---- game / engine functions ----
FN(int, java_get_entity_ticks_existed, (void *jvm, void *entity));
FN(void *, java_get_entity_player_inventory, (void *jvm, void *entity_player));
FN(int, java_get_inventory_player_current_item, (void *jvm, void *inventory_player));
FN(void *, java_call_iinventory_get_stack_in_slot, (void *jvm, void *object, int slot));
FN(unsigned, get_weapon_enchant_flags, (void *jvm, void *item)); // 1 = sharpness, 2 = knockback, 4+ = fire aspect
FN(void *, java_call_item_stack_get_item, (void *jvm, void *item_stack));
FN(unsigned char, weapons_is_item_allowed_by_class_entry, (void *jvm, void *item)); // = weapons_is_item_allowed_by_class
FN(int, java_call_static_item_get_id_from_item, (void *jvm, void *item));
FN(unsigned char, id_vector_contains, (IdCache *cache, int id));
FN(void, libc_free, (void *ptr));
// Is an enchantment on the item one of the ticked ones?
static bool has_allowed_enchant(unsigned flags) {
if ((flags & 1) && weapons_enchant_sharpness_value)
return true;
if ((flags & 2) && weapons_enchant_knockback_value)
return true;
if (flags >= 4 && weapons_enchant_fire_aspect_value)
return true;
return false;
}
extern "C" unsigned char weapons_check_held_item_cached(void *jvm, void *entity_player, unsigned *out) {
int tick = java_get_entity_ticks_existed(jvm, entity_player);
if (tick != weapons_cached_key) {
// New tick: work the answer out again.
weapons_cached_key = tick;
weapons_cached_enchant_flags = 0;
void *inventory = java_get_entity_player_inventory(jvm, entity_player);
int slot = java_get_inventory_player_current_item(jvm, inventory);
void *stack = java_call_iinventory_get_stack_in_slot(jvm, inventory, slot);
unsigned char is_weapon;
if (!stack) {
is_weapon = weapons_fist_value;
} else {
unsigned enchants = get_weapon_enchant_flags(jvm, stack);
weapons_cached_enchant_flags = enchants;
if (weapons_bool_slot_1[slot].on || has_allowed_enchant(enchants))
is_weapon = 1;
else
is_weapon = weapons_is_item_allowed_by_class_entry(jvm, java_call_item_stack_get_item(jvm, stack));
}
weapons_cached_verdict = is_weapon;
}
if (out)
*out = weapons_cached_enchant_flags;
return weapons_cached_verdict;
}
extern "C" unsigned char weapons_is_item_allowed_by_class(void *jvm, void *item) {
if (item) {
int item_id = java_call_static_item_get_id_from_item(jvm, item);
switch (item_id) {
case 267: case 268: case 272: case 276: case 283: // swords (iron, wood, stone, diamond, gold)
return weapons_swords_value;
case 258: case 271: case 275: case 279: case 286: // axes (iron, wood, stone, diamond, gold)
return weapons_axes_value;
default:
if (item_id)
return id_vector_contains(&weapons_slot_id_vector, item_id);
}
}
return weapons_fist_value;
}
// ctx points at the Ctx (its first field is the JVM handle).
extern "C" int weapons_find_first_weapon_slot(void **ctx, void *player) {
for (long slot = 0; slot < 9; slot++) {
if (weapons_bool_slot_1[slot].on)
return (int)slot;
void *stack = java_call_iinventory_get_stack_in_slot(*ctx, player, (int)slot);
if (!stack)
continue;
void *jvm = *ctx;
if (has_allowed_enchant(get_weapon_enchant_flags(jvm, stack)))
return (int)slot;
if (weapons_is_item_allowed_by_class_entry(jvm, java_call_item_stack_get_item(jvm, stack)))
return (int)slot;
}
return -1;
}
extern "C" void weapons_on_shutdown(Hook *hook) {
libc_free(weapons_slot_id_vector.p);
weapons_slot_id_vector = IdCache{};
}
+85
View File
@@ -0,0 +1,85 @@
// Weapons — Configure which items are considered weapons.
// category: combat descriptor: 0x2ee930 settings block: 0x2eeb28
// functions: gui weapons_gui, register weapons_register
// implementation: src/logic/combat/weapons.cpp
#pragma once
#include "slinky/api.h"
S(str_item_types); // "Item types"
S(str_any_item_with); // "Any item with"
S(str_any_item_in); // "Any item in"
S(str_fist_in_weapons); // "fist"
S(str_swords_in_weapons); // "swords"
S(str_axes_in_weapons); // "axes"
S(str_extra_items); // "extra_items"
S(str_enchant_sharpness); // "enchant_sharpness"
S(str_enchant_knockback); // "enchant_knockback"
S(str_enchant_fire_aspect); // "enchant_fire_aspect"
D(weapons_fist_setting); // setting bool "fist"
D(weapons_bool_slot_1); // setting bool (slot)
D(weapons_bool_slot_2); // setting bool (slot)
D(weapons_bool_slot_3); // setting bool (slot)
D(weapons_bool_slot_4); // setting bool (slot)
D(weapons_bool_slot_5); // setting bool (slot)
D(weapons_bool_slot_6); // setting bool (slot)
D(weapons_bool_slot_7); // setting bool (slot)
D(weapons_bool_slot_8); // setting bool (slot)
D(weapons_bool_slot_9); // setting bool (slot)
D(weapons_enchant_sharpness_setting); // setting bool "enchant_sharpness"
D(weapons_enchant_knockback_setting); // setting bool "enchant_knockback"
D(weapons_enchant_fire_aspect_setting); // setting bool "enchant_fire_aspect"
D(weapons_axes_setting); // setting bool "axes"
D(weapons_swords_setting); // setting bool "swords"
D(weapons_extra_items_setting); // setting kind2 "extra_items"
extern "C" void weapons_gui(void *gui, void *window) {
W_label(gui, window, str_item_types);
W_bool(window, gui, weapons_fist_setting);
W_bool(window, gui, weapons_swords_setting);
W_bool(window, gui, weapons_axes_setting);
W_items(window, gui, weapons_extra_items_setting);
W_label(gui, window, str_any_item_with);
W_bool(window, gui, weapons_enchant_sharpness_setting);
W_bool(window, gui, weapons_enchant_knockback_setting);
W_bool(window, gui, weapons_enchant_fire_aspect_setting);
W_label(gui, window, str_any_item_in);
W_bool(window, gui, weapons_bool_slot_1);
W_bool(window, gui, weapons_bool_slot_2);
W_bool(window, gui, weapons_bool_slot_3);
W_bool(window, gui, weapons_bool_slot_4);
W_bool(window, gui, weapons_bool_slot_5);
W_bool(window, gui, weapons_bool_slot_6);
W_bool(window, gui, weapons_bool_slot_7);
W_bool(window, gui, weapons_bool_slot_8);
W_bool(window, gui, weapons_bool_slot_9);
}
extern "C" void weapons_register(void *module) {
char slot[2];
R_bool(module, str_fist_in_weapons, weapons_fist_setting);
R_bool(module, str_swords_in_weapons, weapons_swords_setting);
R_bool(module, str_axes_in_weapons, weapons_axes_setting);
R_kind2(module, str_extra_items, weapons_extra_items_setting);
R_bool(module, str_enchant_sharpness, weapons_enchant_sharpness_setting);
R_bool(module, str_enchant_knockback, weapons_enchant_knockback_setting);
R_bool(module, str_enchant_fire_aspect, weapons_enchant_fire_aspect_setting);
*(__int16 *)slot = 0x31;
R_bool(module, slot, weapons_bool_slot_1);
*(__int16 *)slot = 0x32;
R_bool(module, slot, weapons_bool_slot_2);
*(__int16 *)slot = 0x33;
R_bool(module, slot, weapons_bool_slot_3);
*(__int16 *)slot = 0x34;
R_bool(module, slot, weapons_bool_slot_4);
*(__int16 *)slot = 0x35;
R_bool(module, slot, weapons_bool_slot_5);
*(__int16 *)slot = 0x36;
R_bool(module, slot, weapons_bool_slot_6);
*(__int16 *)slot = 0x37;
R_bool(module, slot, weapons_bool_slot_7);
*(__int16 *)slot = 0x38;
R_bool(module, slot, weapons_bool_slot_8);
*(__int16 *)slot = 0x39;
R_bool(module, slot, weapons_bool_slot_9);
}