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

+168
View File
@@ -0,0 +1,168 @@
// Auto Tool - switch to the best tool for the block you are mining.
//
// While you hold the attack key on a block, the hotbar slot that mines it fastest is
// selected. With "switch_back" on, your old slot is selected again when you stop.
//
// Callbacks (descriptor slots +0x1d8 / +0x1e8):
// auto_tool_on_inventory_tick every tick
// auto_tool_on_shutdown module unloaded: free the allowed-block list
#include "slinky/engine.h"
struct Vec3 { double x, y, z; };
// ---- settings ----
extern "C" float auto_tool_activation_time_value; // "activation_time": ticks to wait before switching
extern "C" unsigned char auto_tool_allow_using_fists_value; // "allow_using_fists": may switch away from an empty hand
extern "C" unsigned char auto_tool_allow_using_sword_value; // "allow_using_sword": may switch away from a sword
extern "C" unsigned char auto_tool_allow_using_tools_value; // "allow_using_tools": may switch away from a tool
extern "C" unsigned char auto_tool_allow_using_other_value; // "allow_using_other": may switch away from anything else
extern "C" unsigned char auto_tool_require_sneak_value; // "require_sneak"
extern "C" unsigned char auto_tool_restrict_allowed_blocks; // "restrict_allowed_blocks": only for blocks in the list
extern "C" unsigned char auto_tool_switch_back_value; // "switch_back"
extern "C" void *auto_tool_allowed_block_set[2]; // the block list (start, end of a vector of ids)
// ---- module state ----
extern "C" char auto_tool_module_descriptor[];
extern "C" int auto_tool_slot_switch_back; // slot to go back to afterwards, -1 = none
extern "C" int auto_tool_slot_we_switched; // slot we selected
extern "C" int auto_tool_activation_countdown; // ticks left before we may switch
// ---- game / engine functions ----
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)); // selected hotbar slot
FN(void, java_set_inventory_player_current_item, (void *jvm, void *inventory_player, 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(void *, get_game_settings, (void *jvm, void *object));
FN(unsigned char, java_call_entity_player_is_using_item, (void *jvm, void *entity_player));
FN(void *, java_get_game_settings_attack_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_get_game_settings_sneak_key, (void *jvm, void *game_settings));
FN(unsigned char, is_key_down, (void *jvm, void *k));
FN(void *, java_get_minecraft_object_mouse_over, (void *jvm, void *minecraft)); // what the crosshair points at
FN(int, java_get_moving_object_position_type_ordinal, (void *jvm, void *moving_object_position)); // 1 = a block
FN(Vec3, java_get_moving_object_position_block_x, (void *jvm, void *moving_object_position));
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(unsigned char, id_vector_contains, (void *set, int id));
FN(void *, java_call_iinventory_get_stack_in_slot, (void *jvm, void *object, int slot));
FN(float, java_call_item_stack_get_str_vs_block, (void *jvm, void *item_stack, void *blk)); // mining speed of the item on the block
FN(unsigned char, claim_release_hotbar_module, (void *timer)); // ask for control of the hotbar (one module at a time)
FN(void, release_owner, (void *timer)); // give control of the hotbar back
FN(void, libc_free, (void *ptr));
// Is the module allowed to switch away from the item in your hand?
static bool may_switch_from_held_item(Ctx *ctx) {
void *held = item_held_hotbar_slot(ctx->jvm, ctx->player);
if (!held)
return auto_tool_allow_using_fists_value == 1;
switch (java_call_static_item_get_id_from_item(ctx->jvm, held)) {
// shovels, pickaxes, axes (iron, wood, stone, diamond, gold) and shears
case 256: case 257: case 258:
case 269: case 270: case 271:
case 273: case 274: case 275:
case 277: case 278: case 279:
case 284: case 285: case 286:
case 359:
return auto_tool_allow_using_tools_value == 1;
// swords (iron, wood, stone, diamond, gold)
case 267: case 268: case 272: case 276: case 283:
return auto_tool_allow_using_sword_value == 1;
default:
return auto_tool_allow_using_other_value == 1;
}
}
// Give the hotbar back, and select the old slot again if we remembered one.
static void stop_and_switch_back(Ctx *ctx, void *inventory) {
release_owner(auto_tool_module_descriptor);
if (auto_tool_slot_switch_back != -1) {
java_set_inventory_player_current_item(ctx->jvm, inventory, auto_tool_slot_switch_back);
auto_tool_slot_switch_back = -1;
}
}
extern "C" void auto_tool_on_inventory_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
if (ctx->in_game != 1)
return;
void *inventory = java_get_entity_player_inventory(ctx->jvm, ctx->player);
int current_slot = java_get_inventory_player_current_item(ctx->jvm, inventory);
// The player picked another slot themselves: forget the slot to switch back to.
if (auto_tool_slot_switch_back != -1 && auto_tool_slot_we_switched != current_slot) {
auto_tool_slot_switch_back = -1;
stop_and_switch_back(ctx, inventory);
return;
}
// Check that we should be active. If not, restart the wait and switch back.
bool active = true;
void *block = nullptr;
if (auto_tool_slot_switch_back == -1 && !may_switch_from_held_item(ctx))
active = false;
if (active) {
void *settings = get_game_settings(ctx->jvm, ctx->minecraft);
if (java_call_entity_player_is_using_item(ctx->jvm, ctx->player)) {
active = false;
} else if (!java_get_key_binding_key_code(ctx->jvm, java_get_game_settings_attack_key(ctx->jvm, settings))) {
active = false; // not mining
} else if (auto_tool_require_sneak_value == 1 && !is_key_down(ctx->jvm, java_get_game_settings_sneak_key(ctx->jvm, settings))) {
active = false;
} else {
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) {
active = false; // not looking at a block
} else {
Vec3 pos = java_get_moving_object_position_block_x(ctx->jvm, hit);
block = java_call_variant(ctx->jvm, ctx->world, (int)pos.x, (int)pos.y, (int)pos.z);
if (!block)
active = false;
else if (auto_tool_restrict_allowed_blocks == 1 && !id_vector_contains(auto_tool_allowed_block_set, get_block_id(ctx->jvm, block)))
active = false;
}
}
}
if (!active) {
auto_tool_activation_countdown = (int)auto_tool_activation_time_value;
stop_and_switch_back(ctx, inventory);
return;
}
// Still waiting for "activation_time".
if (auto_tool_activation_countdown > 0) {
auto_tool_activation_countdown = auto_tool_activation_countdown - 1;
stop_and_switch_back(ctx, inventory);
return;
}
// Find the hotbar slot that mines this block fastest (starting from the current slot,
// so on a tie the current one wins). Speed 1.0 is the bare hand.
int best_slot = current_slot;
float best_speed = 1.0f;
for (int i = 0; i < 9; i++) {
int slot = (current_slot + i) % 9;
void *stack = java_call_iinventory_get_stack_in_slot(ctx->jvm, inventory, slot);
if (!stack)
continue;
float speed = java_call_item_stack_get_str_vs_block(ctx->jvm, stack, block);
if (speed > best_speed)
best_slot = slot;
best_speed = speed > best_speed ? speed : best_speed;
}
if (best_slot == current_slot)
return;
// Switch, if no other module is using the hotbar right now.
if (claim_release_hotbar_module(auto_tool_module_descriptor)) {
java_set_inventory_player_current_item(ctx->jvm, inventory, best_slot);
auto_tool_slot_we_switched = best_slot;
if (auto_tool_slot_switch_back == -1 && auto_tool_switch_back_value)
auto_tool_slot_switch_back = current_slot;
}
}
extern "C" void auto_tool_on_shutdown(Hook *hook) {
libc_free(auto_tool_allowed_block_set[0]);
auto_tool_allowed_block_set[0] = auto_tool_allowed_block_set[1] = nullptr;
}
+61
View File
@@ -0,0 +1,61 @@
// Auto Tool — Selects the best tool when digging.
// category: block descriptor: 0x2ee158 settings block: 0x2ee350
// functions: gui auto_tool_gui, register auto_tool_register
// implementation: src/logic/block/auto_tool.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_auto_tool); // "Main"
S(str_allow_while_using); // "Allow while using"
S(str_conditions_in_auto_tool); // "Conditions"
S(str_activation_time_in_auto_tool); // "activation_time"
S(str_switch_back); // "switch_back"
S(str_allow_using_sword); // "allow_using_sword"
S(str_allow_using_tools); // "allow_using_tools"
S(str_allow_using_fists); // "allow_using_fists"
S(str_allow_using_other); // "allow_using_other"
S(str_require_sneak_in_auto_tool); // "require_sneak"
S(str_restrict_allowed_blocks_in_auto_tool); // "restrict_allowed_blocks"
S(str_allowed_blocks_in_auto_tool); // "allowed_blocks"
D(auto_tool_activation_time_setting); // setting num "activation_time"
D(auto_tool_allow_using_fists_setting); // setting bool "allow_using_fists"
D(auto_tool_allow_using_sword_setting); // setting bool "allow_using_sword"
D(auto_tool_allow_using_tools_setting); // setting bool "allow_using_tools"
D(auto_tool_allow_using_other_setting); // setting bool "allow_using_other"
D(auto_tool_require_sneak_setting); // setting bool "require_sneak"
D(auto_tool_restrict_allowed_blocks_setting); // setting bool "restrict_allowed_blocks"
D(auto_tool_restrict_allowed_blocks); // current value of setting "restrict_allowed_blocks" (+0x18)
D(auto_tool_switch_back_setting); // setting bool "switch_back"
D(auto_tool_allowed_blocks_setting); // setting kind2 "allowed_blocks"
extern "C" void auto_tool_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_auto_tool);
W_slider(window, gui, auto_tool_activation_time_setting);
W_bool(window, gui, auto_tool_switch_back_setting);
W_label(gui, window, str_allow_while_using);
W_bool(window, gui, auto_tool_allow_using_sword_setting);
W_bool(window, gui, auto_tool_allow_using_tools_setting);
W_bool(window, gui, auto_tool_allow_using_fists_setting);
W_bool(window, gui, auto_tool_allow_using_other_setting);
W_label(gui, window, str_conditions_in_auto_tool);
W_bool(window, gui, auto_tool_require_sneak_setting);
W_bool(window, gui, auto_tool_restrict_allowed_blocks_setting);
if (*(unsigned char *)auto_tool_restrict_allowed_blocks == 1) {
W_items(window, gui, auto_tool_allowed_blocks_setting);
} else {
EPILOG_NOP();
}
}
extern "C" void auto_tool_register(void *module) {
R_num(module, str_activation_time_in_auto_tool, auto_tool_activation_time_setting);
R_bool(module, str_switch_back, auto_tool_switch_back_setting);
R_bool(module, str_allow_using_sword, auto_tool_allow_using_sword_setting);
R_bool(module, str_allow_using_tools, auto_tool_allow_using_tools_setting);
R_bool(module, str_allow_using_fists, auto_tool_allow_using_fists_setting);
R_bool(module, str_allow_using_other, auto_tool_allow_using_other_setting);
R_bool(module, str_require_sneak_in_auto_tool, auto_tool_require_sneak_setting);
R_bool(module, str_restrict_allowed_blocks_in_auto_tool, auto_tool_restrict_allowed_blocks_setting);
R_kind2(module, str_allowed_blocks_in_auto_tool, auto_tool_allowed_blocks_setting);
}
+361
View File
@@ -0,0 +1,361 @@
// Block In - build a box of blocks around yourself (roof first, then the walls).
//
// Every tick the module looks for the next free spot around the player, aims at it with
// smooth, slightly random head movement, and presses "use item" once the aim is on it.
// When nothing is left to place and you stand in the middle of your block, it turns itself off.
//
// Callbacks:
// block_in_on_tick (unused, empty)
// block_in_rotation_override_placement the rotation sent to the server when placing
// block_in_tick_while_placing every tick: walk to the middle of the block / stand still
// block_in_enable_remember_facing module switched on/off
// block_in_tick every tick: pick the next spot, aim, place
#include "slinky/engine.h"
struct Vec3 { double x, y, z; };
struct Box { Vec3 lo, hi; };
struct Range { float lo, hi; };
struct Pair { float x, y; }; // yaw, pitch difference
struct Offset3 { signed char dx, dy, dz; };
struct Offset2 { signed char dx, dz; };
struct Rot { float yaw, pitch; };
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 RotHook {
char padding_00[8];
unsigned char override_yaw, override_pitch; // +0x08 / +0x09 set to 1 to replace the rotation
char padding_0a[2];
Rot rot; // +0x0c rotation to send
};
// ---- settings ----
extern "C" unsigned char block_in_require_ground; // only while standing on the ground
extern "C" float block_in_aim_speed; // how fast to turn the head
// ---- module state ----
extern "C" char block_in_module_descriptor[];
extern "C" unsigned char block_in_active; // 1 while aiming/placing this tick
// 0 = not placing, 1 = walk to the middle of the block first, 2 = in the middle, stand still
extern "C" int block_in_rotation_mode;
extern "C" Rot block_in_placement_rotation; // where to look while walking to the middle
// Spots already placed (a 64-bit mask): bits 0..11 the walls (3 heights x 4 sides), bits 32..41 the roof.
extern "C" void *block_in_placed_count;
extern "C" int block_in_facing_quadrant; // which side to start the walls on (0..3, from the yaw)
extern "C" double block_in_last_y; // player height last tick (moving up or down resets the mask)
// States of the random walks that make the aim look human.
extern "C" char block_in_rng_states[], block_in_rng_states_second[], block_in_rng_states_third[], block_in_rng_states_fourth[], block_in_rng_states_fifth[], block_in_rng_states_in_block_in_d[];
// The 10 roof spots, relative to the block below the feet, and the 4 wall directions.
extern "C" const Offset3 block_in_roof_spots_relative_block_below[10];
extern "C" const Offset2 block_in_side_directions[4];
// Bounds of the random ranges used for aim points (the name says the value: 3_6 = 3.6, neg_0_25 = -0.25).
extern "C" const float random_range_bound_neg_0_25, random_range_bound_neg_0_4, random_range_bound_0_25_in_block_in, random_range_bound_0_4_in_block_in,
random_range_bound_0_6_in_block_in, random_range_bound_neg_0_1_in_block_in, random_range_bound_neg_0_2, random_range_bound_3_6,
random_range_bound_3_8, random_range_bound_1_1_in_block_in, random_range_bound_1_2_in_block_in, random_range_bound_0_8_in_block_in;
// ---- game / engine functions ----
FN(Rot, get_entity_rotation, (void *jvm, void *entity));
FN(float, libc_roundf, (float v));
FN(unsigned char, java_get_key_binding_key_code, (void *jvm, void *key_binding)); // key physically held down
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_back_key, (void *jvm, void *game_settings));
FN(void *, java_get_game_settings_left_key, (void *jvm, void *game_settings));
FN(void *, java_get_game_settings_right_key, (void *jvm, void *game_settings));
FN(void, java_set_key_binding_pressed, (void *jvm, void *key_binding, unsigned char on));
FN(unsigned char, java_get_entity_on_ground, (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 x));
FN(double, libc_fmod, (double x, double y));
FN(void *, java_block_pos_init, (void *jvm, void *object, int y, int z));
FN(void *, java_call_world_get_block_state, (void *jvm, void *world, void *pos, int x, int y, int z));
FN(int, get_block_id, (void *jvm, void *block));
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(Vec3, vec3_add, (Vec3 a, Vec3 b));
FN(Box, aabb_make, (Vec3 lo, Vec3 hi));
FN(unsigned char, aabb_intersects, (Box a, Box b));
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 inside the range
FN(unsigned char, update_rotation_priority_peak, (int ms)); // may this module control the rotation?
FN(void, switch_best_hotbar_slot, (Ctx *ctx, void *mod, unsigned char on, void (*cb)(void *)));
FN(void, key_category, (void *));
FN(void *, item_held_hotbar_slot, (void *jvm, void *slot));
FN(unsigned char, block_entity_id, (void *jvm, void *entity)); // 1 if the item is a block
FN(Rot, get_silent_rotation_offset, ());
FN(Rot, rot_add, (Rot a, Rot b));
FN(void *, java_call_entity_living_base_get_position, (void *jvm, void *entity_living_base)); // eye position
FN(Vec3, java_get_vec3_x_coord, (void *jvm, void *bp));
FN(Rot, rot_look_at, (Vec3 from, Vec3 to));
FN(Pair, rot_sub, (Rot a, Rot b));
FN(float, wrap_angle, (float deg)); // to -180..180
FN(Pair, rot_scale, (Pair p, float k));
FN(float, limit_rotation_delta, (float lo, float hi, float v)); // clamp
FN(Pair, rot_lerp, (Pair a, Pair b, float k));
FN(void, apply_silent_rotation, (Pair r));
FN(void *, java_get_game_settings_use_item_key, (void *jvm, void *game_settings));
FN(void, java_increment_key_binding_press_time, (void *jvm, void *key_binding)); // = one right click
FN(void, queue_module_toggle, (void *module_manager, void *module, unsigned char enabled));
static unsigned long long &placed_mask() { return *(unsigned long long *)&block_in_placed_count; }
extern "C" void block_in_on_tick(void *) {
}
// When placing: send our aim to the server, and in "walk to the middle" mode the walking direction.
extern "C" void block_in_rotation_override_placement(RotHook *hook) {
if (block_in_active != 1)
return;
hook->override_yaw = 1;
hook->override_pitch = 1;
if (block_in_rotation_mode == 1)
hook->rot = block_in_placement_rotation;
}
// While placing: hold forward to walk to the middle of the block (mode 1), never walk otherwise.
extern "C" void block_in_tick_while_placing(Hook *hook) {
if (block_in_rotation_mode == 0)
return;
Ctx *ctx = hook->ctx;
void *settings = get_game_settings(ctx->jvm, ctx->minecraft);
void *forward_key = java_get_game_settings_forward_key(ctx->jvm, settings);
void *back_key = java_get_game_settings_back_key(ctx->jvm, settings);
void *left_key = java_get_game_settings_left_key(ctx->jvm, settings);
void *right_key = java_get_game_settings_right_key(ctx->jvm, settings);
java_set_key_binding_pressed(ctx->jvm, forward_key, block_in_rotation_mode == 1);
java_set_key_binding_pressed(ctx->jvm, back_key, 0);
java_set_key_binding_pressed(ctx->jvm, left_key, 0);
java_set_key_binding_pressed(ctx->jvm, right_key, 0);
}
// On enable: start fresh and remember which way we face. On disable: give the movement keys back.
extern "C" void block_in_enable_remember_facing(EvHook *hook) {
if (hook->ev != block_in_module_descriptor)
return;
Ctx *ctx = hook->ctx;
if (hook->on == 1) {
block_in_placed_count = nullptr;
int quadrant = (int)libc_roundf(get_entity_rotation(ctx->jvm, ctx->player).yaw / 90.0f);
block_in_facing_quadrant = quadrant % 4;
return;
}
void *settings = get_game_settings(ctx->jvm, ctx->minecraft);
void *forward_key = java_get_game_settings_forward_key(ctx->jvm, settings);
void *back_key = java_get_game_settings_back_key(ctx->jvm, settings);
void *left_key = java_get_game_settings_left_key(ctx->jvm, settings);
void *right_key = java_get_game_settings_right_key(ctx->jvm, settings);
java_set_key_binding_pressed(ctx->jvm, forward_key, java_get_key_binding_key_code(ctx->jvm, forward_key));
java_set_key_binding_pressed(ctx->jvm, back_key, java_get_key_binding_key_code(ctx->jvm, back_key));
java_set_key_binding_pressed(ctx->jvm, left_key, java_get_key_binding_key_code(ctx->jvm, left_key));
java_set_key_binding_pressed(ctx->jvm, right_key, java_get_key_binding_key_code(ctx->jvm, right_key));
}
// Can a block be placed here? True for air, water and tall grass.
static bool is_open(Ctx *ctx, void *pos, int x, int y, int z) {
unsigned block_id = get_block_id(ctx->jvm, java_call_world_get_block_state(ctx->jvm, ctx->world, pos, x, y, z));
return block_id <= 31 && (0x80000301u >> block_id & 1); // ids 0 (air), 8, 9 (water), 31 (tall grass)
}
static double abs_d(double x) { return __builtin_fabs(x); }
static float abs_f(float x) { return __builtin_fabsf(x); }
// Is the position in the middle part of its block (0.31 .. 0.69 on both x and z)?
static bool in_block_middle(double frac_x, double frac_z) {
return 0.69 >= frac_x && frac_x >= 0.31 && frac_z >= 0.31 && 0.69 >= frac_z;
}
// Roof: look for the next roof spot. Returns false when the walls should be done first
// (or the roof is complete). bx/by/bz is the block below the feet.
static bool find_roof_spot(Ctx *ctx, void *pos, int bx, int by, int bz, Vec3 *target, unsigned char *bit) {
unsigned long long placed = placed_mask();
for (int i = 0; i < 10; i++) {
const Offset3 &spot = block_in_roof_spots_relative_block_below[i];
// Skip spots that are still open (and not placed by us yet).
if (!(placed >> 32 >> i & 1) && is_open(ctx, pos, bx + spot.dx, by + spot.dy, bz + spot.dz))
continue;
if (i == 0)
return false; // already standing under a roof: do the walls
*bit = (unsigned char)(32 + i);
// Aim at a random point on the side of the block that is there.
float fx = (float)bx, fy = (float)by, fz = (float)bz;
Range height = rot_make_floats(random_range_bound_3_6, random_range_bound_3_8);
switch (i == 9 ? 4 : (i - 1) & 3) {
case 0:
target->x = bx;
target->y = fy + walk_update(block_in_rng_states, height, 0.5);
target->z = fz + walk_update(block_in_rng_states_second, rot_make_floats(random_range_bound_neg_0_1_in_block_in, random_range_bound_neg_0_2), 0.5);
break;
case 1:
target->x = fx + walk_update(block_in_rng_states, rot_make_floats(random_range_bound_1_1_in_block_in, random_range_bound_1_2_in_block_in), 0.5);
target->y = fy + walk_update(block_in_rng_states_second, height, 0.5);
target->z = bz;
break;
case 2:
target->x = bx + 1;
target->y = fy + walk_update(block_in_rng_states, height, 0.5);
target->z = fz + walk_update(block_in_rng_states_second, rot_make_floats(random_range_bound_1_1_in_block_in, random_range_bound_1_2_in_block_in), 0.5);
break;
case 3:
target->x = fx + walk_update(block_in_rng_states, rot_make_floats(random_range_bound_neg_0_1_in_block_in, random_range_bound_neg_0_2), 0.5);
target->y = fy + walk_update(block_in_rng_states_second, height, 0.5);
target->z = bz + 1;
break;
default: // the last spot: aim at the underside, straight above
target->x = fx + walk_update(block_in_rng_states, rot_make_floats(random_range_bound_0_4_in_block_in, random_range_bound_0_6_in_block_in), 0.5);
target->y = by + 4;
target->z = fz + walk_update(block_in_rng_states_second, rot_make_floats(random_range_bound_0_4_in_block_in, random_range_bound_0_6_in_block_in), 0.5);
break;
}
return true;
}
return false;
}
// Walls: one column on each of the 4 sides, filled from the bottom (feet, head, above head).
static bool find_wall_spot(Ctx *ctx, void *pos, int bx, int by, int bz, Vec3 *target, unsigned char *bit) {
unsigned long long placed = placed_mask();
for (int d = 0; d < 4; d++) {
int dir = (block_in_facing_quadrant + d) & 3;
int dx = block_in_side_directions[dir].dx, dz = block_in_side_directions[dir].dz;
int nx = bx + dx, nz = bz + dz;
// Skip a side the player is standing in.
Box player_box = java_get_axis_aligned_bb_min_x(ctx->jvm, java_get_entity_bounding_box(ctx->jvm, ctx->player));
Vec3 lo = {(double)nx, (double)by, (double)nz};
Box column = aabb_make(lo, vec3_add(lo, Vec3{1.0, 3.0, 1.0}));
if (aabb_intersects(player_box, column))
continue;
// The lowest open spot that has a block under it to place against.
int base = dir * 3;
int level;
Range r;
if (!(placed >> base & 1) && is_open(ctx, pos, nx, by, nz) && !is_open(ctx, pos, nx, by - 1, nz)) {
level = 0;
r = rot_make_floats(random_range_bound_neg_0_25, random_range_bound_neg_0_4);
} else if (!(placed >> (base + 1) & 1) && is_open(ctx, pos, nx, by + 1, nz) && !is_open(ctx, pos, nx, by, nz)) {
level = 1;
r = rot_make_floats(random_range_bound_0_25_in_block_in, random_range_bound_0_4_in_block_in);
} else if (!(placed >> (base + 2) & 1) && is_open(ctx, pos, nx, by + 2, nz) && !is_open(ctx, pos, nx, by + 1, nz)) {
level = 2;
r = rot_make_floats(random_range_bound_0_25_in_block_in, random_range_bound_0_4_in_block_in);
} else {
continue;
}
// Aim at a random point on the top of the block below that spot.
target->x = (0.5 - (double)(walk_update(block_in_rng_states_third, r, 0.5) * (float)dx)) + nx;
target->z = (0.5 - (double)(walk_update(block_in_rng_states_fourth, r, 0.5) * (float)dz)) + nz;
target->y = by + level;
*bit = (unsigned char)(base + level);
return true;
}
return false;
}
// Turn the head a step towards the target, and place when the aim is on it.
// Returns false if the module should turn itself off.
static bool aim_and_place(Ctx *ctx, Vec3 me, Vec3 target, unsigned char bit) {
if (!update_rotation_priority_peak(500))
return false;
switch_best_hotbar_slot(ctx, block_in_module_descriptor, 1, key_category);
if (!block_entity_id(ctx->jvm, item_held_hotbar_slot(ctx->jvm, ctx->player)))
return false; // no blocks in the hotbar
// How far the head still has to turn.
Rot current = rot_add(get_entity_rotation(ctx->jvm, ctx->player), get_silent_rotation_offset());
Vec3 eye = java_get_vec3_x_coord(ctx->jvm, java_call_entity_living_base_get_position(ctx->jvm, ctx->player));
Pair diff = rot_sub(rot_look_at(eye, target), current);
float diff_yaw = wrap_angle(diff.x);
float diff_pitch = diff.y;
// Turn part of the way (by aim speed), limited to a random maximum per tick.
Pair step = rot_scale(Pair{diff_yaw, diff_pitch}, (float)((double)block_in_aim_speed * 0.5 + 0.5));
float jitter_yaw = walk_update(block_in_rng_states_fifth, rot_make_floats(random_range_bound_0_8_in_block_in, random_range_bound_1_2_in_block_in), 0.2);
float jitter_pitch = walk_update(block_in_rng_states_in_block_in_d, rot_make_floats(random_range_bound_0_8_in_block_in, random_range_bound_1_2_in_block_in), 0.2);
float max_yaw = jitter_yaw * 180.0f * block_in_aim_speed;
float max_pitch = 180.0f * jitter_pitch * block_in_aim_speed;
Pair limited = {limit_rotation_delta(-max_yaw, max_yaw, diff_yaw), limit_rotation_delta(-max_pitch, max_pitch, diff_pitch)};
Pair turn = rot_lerp(step, limited, 0.5f);
apply_silent_rotation(turn);
// Within 1 degree after this step: right click.
float error_yaw = abs_f(diff_yaw - turn.x);
float error_pitch = abs_f(diff_pitch - turn.y);
if (1.0f > error_pitch + error_yaw) {
java_increment_key_binding_press_time(ctx->jvm, java_get_game_settings_use_item_key(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft)));
placed_mask() |= 1ull << (bit & 63);
}
block_in_active = 1;
// Not in the middle of the block yet: walk there first.
double frac_x = abs_d(libc_fmod(me.x, 1.0));
double frac_z = libc_fmod(me.z, 1.0);
if (in_block_middle(frac_x, abs_d(frac_z))) {
block_in_rotation_mode = 2;
return true;
}
block_in_rotation_mode = 1;
Vec3 middle = {libc_floor(me.x) + 0.5, me.y, libc_floor(me.z) + 0.5};
block_in_placement_rotation = rot_look_at(me, middle);
return true;
}
extern "C" void block_in_tick(Hook *hook) {
block_in_active = 0;
block_in_rotation_mode = 0;
Ctx *ctx = hook->ctx;
bool turn_off = false;
if (ctx->in_game != 1) {
turn_off = true;
} else {
unsigned char on_ground = java_get_entity_on_ground(ctx->jvm, ctx->player);
if (block_in_require_ground && !on_ground) {
turn_off = true;
} else {
Vec3 me = java_get_entity_pos_x(ctx->jvm, ctx->player);
if (java_variant(ctx->jvm))
me = vec3_add_eye_height_sneak(me);
// The block below the feet.
int bx = (int)libc_floor(me.x);
int by = (int)(libc_floor(me.y) + -1.0);
int bz = (int)libc_floor(me.z);
// Moved up or down: start over.
if (abs_d(me.y - block_in_last_y) > 0.01)
placed_mask() = 0;
block_in_last_y = me.y;
// A BlockPos object reused for the block lookups (only once the JVM handle is ready).
void *pos = **(int **)ctx->jvm ? java_block_pos_init(ctx->jvm, nullptr, 0, 0) : nullptr;
Vec3 target;
unsigned char bit;
if (find_roof_spot(ctx, pos, bx, by, bz, &target, &bit) || find_wall_spot(ctx, pos, bx, by, bz, &target, &bit)) {
turn_off = !aim_and_place(ctx, me, target, bit);
} else {
// Nothing left to place: done once we stand in the middle of the block.
if (!on_ground)
return;
double frac_x = abs_d(libc_fmod(me.x, 1.0));
double frac_z = abs_d(libc_fmod(me.z, 1.0));
turn_off = in_block_middle(frac_x, frac_z);
}
}
}
if (turn_off)
queue_module_toggle(ctx->module_manager, block_in_module_descriptor, 0);
}
+26
View File
@@ -0,0 +1,26 @@
// Block In — Places blocks around you.
// category: block descriptor: 0x2f6108 settings block: 0x2f6300
// functions: gui block_in_gui, register block_in_register
// implementation: src/logic/block/block_in.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_block_in); // "Main"
S(str_conditions_in_block_in); // "Conditions"
S(str_speed_in_block_in); // "speed"
S(str_require_ground); // "require_ground"
D(block_in_require_ground_setting); // setting bool "require_ground"
D(block_in_speed_setting); // setting num "speed"
extern "C" void block_in_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_block_in);
W_slider(window, gui, block_in_speed_setting);
W_label(gui, window, str_conditions_in_block_in);
W_bool(window, gui, block_in_require_ground_setting);
}
extern "C" void block_in_register(void *module) {
R_num(module, str_speed_in_block_in, block_in_speed_setting);
R_bool(module, str_require_ground, block_in_require_ground_setting);
}
+323
View File
@@ -0,0 +1,323 @@
// Bridge Assist - sneak automatically at block edges while bridging backwards.
//
// While you walk backwards placing blocks, this module holds sneak just before you would
// step off the edge, and lets go again a moment later. It can also restrict placing to
// clicks that hit the edge of the block below you.
//
// Callbacks:
// bridge_assist_disable module switched off: give the sneak key back
// bridge_assist_on_late_tick every tick: keep the module's keybind state in sync
// bridge_assist_tick every tick: hold / release sneak
// bridge_assist_place right click: decide if placing is allowed
// bridge_assist_edge_check helper: is the ground under our next position air?
#include "slinky/engine.h"
struct Vec3 { double x, y, z; };
struct Rot { float yaw, pitch; };
struct Range { float lo, hi; };
struct Box { double x0, y0, z0, x1, y1, z1; };
struct PlaceEvt {
char padding_00[8];
Ctx *ctx; // +0x08 game context
unsigned char cancelled; // +0x10 placing already cancelled
unsigned char allow; // +0x11 set to 1 to allow placing
};
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 bridge_assist_activation_mode; // 0 = off, 1 = on, 2 = toggle with the keybind
extern "C" unsigned char bridge_assist_only_while_sneak_held; // only while you hold sneak yourself
extern "C" unsigned char bridge_assist_only_when_looking_down; // only with pitch >= 65
extern "C" unsigned char bridge_assist_only_while_not_rising; // not while walking forwards
extern "C" unsigned char bridge_assist_only_few_ticks_after_landing; // only shortly after holding blocks
extern "C" unsigned char bridge_assist_also_air_while_falling; // also in the air while not falling
extern "C" unsigned char bridge_assist_randomise; // randomise margin and release delay
extern "C" unsigned char bridge_assist_edge_only_placing; // only allow placing on the edge
extern "C" float bridge_assist_edge_margin; // how close to the edge before sneaking (blocks)
extern "C" float bridge_assist_release_delay; // ticks to keep sneaking after the edge is safe
// ---- module state ----
extern "C" char bridge_assist_module_descriptor[];
extern "C" unsigned char bridge_assist_sneak_held_by_us; // we are controlling the sneak key
extern "C" unsigned char bridge_assist_placing; // active this tick
extern "C" unsigned char bridge_assist_restrict_placing_edge; // placing is restricted to the edge this tick
extern "C" int bridge_assist_cooldown_after_sneaking_ticks; // 20 after placing a block, counts down
extern "C" int bridge_assist_ticks_left_hold; // "only_few_ticks_after_landing" countdown
extern "C" float bridge_assist_release_timer; // ticks left before sneak is released
extern "C" char bridge_assist_rng_states[], bridge_assist_rng_states_second[], bridge_assist_rng_states_third[]; // random walk states
// Bounds of random ranges (the name says the value: neg_0_5 = -0.5, 0_04 = 0.04).
extern "C" const float random_range_bound_neg_0_5, random_range_bound_0_5_in_bridge_assist, random_range_bound_0_04_in_bridge_assist,
random_range_bound_0_08_in_bridge_assist, random_range_bound_3_in_bridge_assist, random_range_bound_0_15_in_bridge_assist;
// ---- game / engine functions ----
FN(void *, get_game_settings, (void *jvm, void *object));
FN(void *, java_get_game_settings_sneak_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, track_owner, (void *ctx, void *mod, unsigned char toggle));
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, java_get_variant, (void *jvm, void *hit)); // side of the block that was hit (>= 2: a vertical side)
FN(unsigned char, java_get_entity_on_ground, (void *jvm, void *entity));
FN(void *, java_get_game_settings_forward_key, (void *jvm, void *game_settings));
FN(void *, java_get_game_settings_back_key, (void *jvm, void *game_settings));
FN(void *, java_get_game_settings_left_key, (void *jvm, void *game_settings));
FN(void *, java_get_game_settings_right_key, (void *jvm, void *game_settings));
FN(unsigned char, is_key_down, (void *jvm, void *k));
FN(void *, item_held_hotbar_slot, (void *jvm, void *slot));
FN(unsigned char, block_entity_id, (void *jvm, void *entity)); // 1 if the item is a block
FN(Rot, get_entity_rotation, (void *jvm, void *entity));
FN(double, libc_fmod, (double x, double y));
FN(double, libc_floor, (double x));
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(void *, java_get_moving_object_position_hit_vec, (void *jvm, void *hit));
FN(Vec3, java_get_vec3_x_coord, (void *jvm, void *bp));
FN(Vec3, java_get_adjacent_block_position, (void *jvm, void *hit));
FN(float, java_get_entity_living_base_move_forward, (void *jvm, void *entity_living_base));
FN(Vec3, java_get_entity_motion_x, (void *jvm, void *entity));
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(Vec3, vec3_make, (double x, double y, double z));
FN(Vec3, vec3_add, (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));
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 *block));
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 inside the range
FN(unsigned char, walk_should_change, (void *state, Range r, double d));
FN(float, random_rotation, (Range r)); // random value in the range
static double abs_d(double x) { return __builtin_fabs(x); }
static float abs_f(float x) { return __builtin_fabsf(x); }
// On disable: give the sneak key back to the player.
extern "C" void bridge_assist_disable(EvHook *hook) {
if (hook->ev != bridge_assist_module_descriptor || hook->on || !(bridge_assist_sneak_held_by_us & 1))
return;
Ctx *ctx = hook->ctx;
void *sneak_key = java_get_game_settings_sneak_key(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft));
java_set_key_binding_pressed(ctx->jvm, sneak_key, java_get_key_binding_key_code(ctx->jvm, sneak_key));
bridge_assist_sneak_held_by_us = 0;
}
extern "C" void bridge_assist_on_late_tick(Hook *hook) {
if (bridge_assist_placing == 1)
track_owner(hook->ctx, bridge_assist_module_descriptor, bridge_assist_activation_mode == 2);
}
// Where will the player be next tick, and is there no block under any corner of that spot
// (shrunk by the edge margin)? Returns 1 when we would walk off an edge.
extern "C" unsigned char bridge_assist_edge_check(void *jvm, void *game_settings, void *world, void *player) {
// Middle of the feet, just below them.
Box box = java_get_axis_aligned_bb_min_x(jvm, java_get_entity_bounding_box(jvm, player));
Vec3 feet = vec3_make((box.x0 + box.x1) * 0.5, box.y0 + -0.01, (box.z0 + box.z1) * 0.5);
Vec3 motion = java_get_entity_motion_x(jvm, player);
double margin = bridge_assist_edge_margin;
if (bridge_assist_randomise == 1) {
margin -= walk_update(bridge_assist_rng_states, rot_make_floats(0.0f, random_range_bound_0_15_in_bridge_assist), 5.0);
if (0.0 > margin)
margin = 0.0;
}
// The movement keys held, as input values.
void *forward_key = java_get_game_settings_forward_key(jvm, game_settings);
void *back_key = java_get_game_settings_back_key(jvm, game_settings);
void *left_key = java_get_game_settings_left_key(jvm, game_settings);
void *right_key = java_get_game_settings_right_key(jvm, game_settings);
float forward = is_key_down(jvm, forward_key) ? 1.0f : 0.0f;
if (is_key_down(jvm, back_key))
forward += -1.0f;
float strafe = is_key_down(jvm, left_key) ? 1.0f : 0.0f;
if (is_key_down(jvm, right_key))
strafe += -1.0f;
// Next position = feet + motion + what the keys add.
Rot rotation = get_entity_rotation(jvm, player);
Vec3 push = horizontal_motion(rotation, forward, strafe, java_get_entity_living_base_land_movement_factor(jvm, player));
Vec3 next = vec3_add(feet, vec3_add(motion, push));
// The (up to 4) blocks under the spot, shrunk by the margin. Any solid one = safe.
int x0 = (int)libc_floor(next.x - margin);
int z0 = (int)libc_floor(next.z - margin);
int y = (int)libc_floor(next.y);
double x1_floor = libc_floor(next.x + margin);
double z1_floor = libc_floor(margin + next.z);
if (get_block_id(jvm, java_call_variant(jvm, world, x0, y, z0)))
return 0;
int z1 = (int)z1_floor;
if (z0 != z1 && get_block_id(jvm, java_call_variant(jvm, world, x0, y, z1)))
return 0;
int x1 = (int)x1_floor;
if (x0 == x1)
return 1;
if (get_block_id(jvm, java_call_variant(jvm, world, x1, y, z0)))
return 0;
if (z0 == z1)
return 1;
return !get_block_id(jvm, java_call_variant(jvm, world, x1, y, z1));
}
extern "C" void bridge_assist_tick(Hook *hook) {
bridge_assist_restrict_placing_edge = 0;
bridge_assist_placing = 0;
Ctx *ctx = hook->ctx;
if (ctx->in_game != 1)
return;
void *game_settings = get_game_settings(ctx->jvm, ctx->minecraft);
if (bridge_assist_cooldown_after_sneaking_ticks > 0)
bridge_assist_cooldown_after_sneaking_ticks -= 1;
void *sneak_key = java_get_game_settings_sneak_key(ctx->jvm, game_settings);
unsigned char sneak_held = java_get_key_binding_key_code(ctx->jvm, sneak_key);
// Conditions. If one fails, give the sneak key back.
bool conditions_ok = true;
if (bridge_assist_only_while_sneak_held != sneak_held)
conditions_ok = false;
else if (bridge_assist_only_when_looking_down == 1 && 65.0f > get_entity_rotation(ctx->jvm, ctx->player).pitch)
conditions_ok = false;
else if (bridge_assist_only_while_not_rising == 1 && java_get_entity_living_base_move_forward(ctx->jvm, ctx->player) > 0.0f)
conditions_ok = false;
if (conditions_ok) {
bridge_assist_placing = bridge_assist_activation_mode != 0;
if (bridge_assist_only_few_ticks_after_landing == 1) {
// Holding blocks keeps the countdown at 2; otherwise it runs out.
int ticks_left;
if (block_entity_id(ctx->jvm, item_held_hotbar_slot(ctx->jvm, ctx->player))) {
ticks_left = 2;
} else {
ticks_left = bridge_assist_ticks_left_hold;
if (ticks_left <= 0)
conditions_ok = false;
ticks_left -= 1;
}
if (conditions_ok)
bridge_assist_ticks_left_hold = ticks_left;
}
}
if (!conditions_ok) {
if (bridge_assist_sneak_held_by_us == 1)
java_set_key_binding_pressed(ctx->jvm, sneak_key, sneak_held);
bridge_assist_sneak_held_by_us = 0;
return;
}
bridge_assist_sneak_held_by_us = 1;
// What to do with the sneak key this tick.
enum { KEEP, CHECK_EDGE, COUNT_DOWN } action;
if (is_key_down(ctx->jvm, sneak_key)) {
// Sneaking now: release once the edge is safe (after the release delay).
if (bridge_assist_only_while_sneak_held == 1) {
if (java_get_entity_living_base_move_forward(ctx->jvm, ctx->player) >= 0.0f || bridge_assist_cooldown_after_sneaking_ticks <= 0)
action = KEEP;
else
action = CHECK_EDGE;
} else if (java_get_entity_on_ground(ctx->jvm, ctx->player)) {
action = CHECK_EDGE;
} else if (bridge_assist_also_air_while_falling == 1 && !(0.0 > java_get_entity_motion_x(ctx->jvm, ctx->player).y)) {
action = CHECK_EDGE;
} else {
action = COUNT_DOWN;
}
} else {
// Not sneaking: press sneak if we are about to walk off the edge.
if (!java_get_entity_on_ground(ctx->jvm, ctx->player)) {
if (bridge_assist_also_air_while_falling != 1 || 0.0 > java_get_entity_motion_x(ctx->jvm, ctx->player).y)
return;
}
if (!bridge_assist_edge_check(ctx->jvm, game_settings, ctx->world, ctx->player))
return;
java_set_key_binding_pressed(ctx->jvm, sneak_key, 1);
action = KEEP;
}
// Still at the edge: keep sneaking.
if (action == CHECK_EDGE && bridge_assist_edge_check(ctx->jvm, game_settings, ctx->world, ctx->player))
action = KEEP;
if (action != KEEP) {
// Count the release timer down; at 0 release sneak and start a new (random) delay.
bridge_assist_release_timer += -1.0f;
if (!(bridge_assist_release_timer > 0.0f)) {
java_set_key_binding_pressed(ctx->jvm, sneak_key, 0);
float delay = bridge_assist_release_delay;
if (bridge_assist_randomise == 1) {
delay += walk_update(bridge_assist_rng_states_second, rot_make_floats(random_range_bound_neg_0_5, random_range_bound_0_5_in_bridge_assist), 30.0);
if (walk_should_change(bridge_assist_rng_states_third, rot_make_floats(random_range_bound_0_04_in_bridge_assist, random_range_bound_0_08_in_bridge_assist), 60.0))
delay += random_rotation(rot_make_floats(0.0f, random_range_bound_3_in_bridge_assist));
}
bridge_assist_release_timer = delay + bridge_assist_release_timer;
return;
}
}
bridge_assist_restrict_placing_edge = bridge_assist_edge_only_placing;
}
// Is the crosshair on the outer edge of the side of the block we are standing on,
// while walking straight backwards at a diagonal angle?
static bool aimed_at_edge_below(Ctx *ctx) {
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 || java_get_variant(ctx->jvm, hit) < 2 ||
!java_get_entity_on_ground(ctx->jvm, ctx->player))
return false;
// Only back held (no left/right).
void *game_settings = get_game_settings(ctx->jvm, ctx->minecraft);
void *back_key = java_get_game_settings_back_key(ctx->jvm, game_settings);
void *left_key = java_get_game_settings_left_key(ctx->jvm, game_settings);
void *right_key = java_get_game_settings_right_key(ctx->jvm, game_settings);
if (!is_key_down(ctx->jvm, back_key) || is_key_down(ctx->jvm, left_key) || is_key_down(ctx->jvm, right_key))
return false;
// Facing diagonally (30..60 degrees within each quarter turn).
float yaw = abs_f((float)libc_fmod(get_entity_rotation(ctx->jvm, ctx->player).yaw, 90.0));
if (30.0f > yaw || yaw > 60.0f)
return false;
// The point hit must be within 1 block sideways and up to 1 block below the feet.
Vec3 pos = java_get_entity_pos_x(ctx->jvm, ctx->player);
if (java_variant(ctx->jvm))
pos = vec3_add_eye_height_sneak(pos);
Vec3 hit_pos = java_get_vec3_x_coord(ctx->jvm, java_get_moving_object_position_hit_vec(ctx->jvm, hit));
double dy = hit_pos.y - pos.y;
if (abs_d(hit_pos.x - pos.x) > 1.0 || -1.0 > dy || dy > 0.0 || abs_d(hit_pos.z - pos.z) > 1.0)
return false;
// The point hit must not be near a corner of the face. Standing right on the new block
// the band is wider (0.25) than otherwise (0.15).
Vec3 new_block = java_get_adjacent_block_position(ctx->jvm, hit);
bool inside_z = new_block.z < pos.z && pos.z < new_block.z + 1.0;
bool inside_x = new_block.x < pos.x && pos.x < new_block.x + 1.0;
double frac_x = abs_d(libc_fmod(hit_pos.x, 1.0));
double frac_z = libc_fmod(hit_pos.z, 1.0);
double edge = inside_x && inside_z ? 0.25 : 0.15;
double far = 1.0 - edge;
if (!(far < frac_x) && !(frac_x < edge))
return true;
frac_z = abs_d(frac_z);
return !(far < frac_z) && !(frac_z < edge);
}
// Right click: with "edge_only_placing", only allow clicks on the edge below us.
extern "C" void bridge_assist_place(PlaceEvt *h) {
if (h->cancelled || bridge_assist_cooldown_after_sneaking_ticks == 20)
return;
Ctx *ctx = h->ctx;
if (bridge_assist_restrict_placing_edge == 1 && aimed_at_edge_below(ctx)) {
h->allow = 1;
return;
}
if (block_entity_id(ctx->jvm, item_held_hotbar_slot(ctx->jvm, ctx->player)))
bridge_assist_cooldown_after_sneaking_ticks = 20;
}
+58
View File
@@ -0,0 +1,58 @@
// Bridge Assist — Sneaks and unsneaks for you while bridging.
// category: block descriptor: 0x2e9ac0 settings block: 0x2e9cb8
// functions: gui bridge_assist_gui, register bridge_assist_register
// implementation: src/logic/block/bridge_assist.cpp
#pragma once
#include "slinky/api.h"
S(str_main); // "Main"
S(str_conditions_in_bridge_assist); // "Conditions"
S(str_edge_offset_in_bridge_assist); // "edge_offset"
S(str_unsneak_delay_in_bridge_assist); // "unsneak_delay"
S(str_select_blocks_in_bridge_assist); // "select_blocks"
S(str_randomize_in_bridge_assist); // "randomize"
S(str_sneak_on_jump_in_bridge_assist); // "sneak_on_jump"
S(str_avoid_double_sneak); // "avoid_double_sneak"
S(str_require_sneak); // "require_sneak"
S(str_require_holding_blocks); // "require_holding_blocks"
S(str_require_looking_down); // "require_looking_down"
S(str_require_not_forward); // "require_not_forward"
D(bridge_assist_require_sneak_setting); // setting bool "require_sneak"
D(bridge_assist_require_looking_down_setting); // setting bool "require_looking_down"
D(bridge_assist_require_not_forward_setting); // setting bool "require_not_forward"
D(bridge_assist_select_blocks_setting); // setting enum "select_blocks"
D(bridge_assist_require_holding_blocks_setting); // setting bool "require_holding_blocks"
D(bridge_assist_sneak_on_jump_setting); // setting bool "sneak_on_jump"
D(bridge_assist_edge_offset_setting); // setting num "edge_offset"
D(bridge_assist_randomize_setting); // setting bool "randomize"
D(bridge_assist_avoid_double_sneak_setting); // setting bool "avoid_double_sneak"
D(bridge_assist_unsneak_delay_setting); // setting num "unsneak_delay"
extern "C" void bridge_assist_gui(void *gui, void *window) {
W_label(gui, window, str_main);
W_slider(window, gui, bridge_assist_edge_offset_setting);
W_slider(window, gui, bridge_assist_unsneak_delay_setting);
W_enumw(window, gui, bridge_assist_select_blocks_setting);
W_bool(window, gui, bridge_assist_randomize_setting);
W_bool(window, gui, bridge_assist_sneak_on_jump_setting);
W_bool(window, gui, bridge_assist_avoid_double_sneak_setting);
W_label(gui, window, str_conditions_in_bridge_assist);
W_bool(window, gui, bridge_assist_require_sneak_setting);
W_bool(window, gui, bridge_assist_require_holding_blocks_setting);
W_bool(window, gui, bridge_assist_require_looking_down_setting);
W_bool(window, gui, bridge_assist_require_not_forward_setting);
}
extern "C" void bridge_assist_register(void *module) {
R_num(module, str_edge_offset_in_bridge_assist, bridge_assist_edge_offset_setting);
R_num(module, str_unsneak_delay_in_bridge_assist, bridge_assist_unsneak_delay_setting);
R_enum(module, str_select_blocks_in_bridge_assist, bridge_assist_select_blocks_setting);
R_bool(module, str_randomize_in_bridge_assist, bridge_assist_randomize_setting);
R_bool(module, str_sneak_on_jump_in_bridge_assist, bridge_assist_sneak_on_jump_setting);
R_bool(module, str_avoid_double_sneak, bridge_assist_avoid_double_sneak_setting);
R_bool(module, str_require_sneak, bridge_assist_require_sneak_setting);
R_bool(module, str_require_holding_blocks, bridge_assist_require_holding_blocks_setting);
R_bool(module, str_require_looking_down, bridge_assist_require_looking_down_setting);
R_bool(module, str_require_not_forward, bridge_assist_require_not_forward_setting);
}
+462
View File
@@ -0,0 +1,462 @@
// Clutch - save yourself from falling by placing a block.
//
// When you are about to fall (knocked off an edge, walking backwards into the void, ...),
// the module picks the best nearby block to place against, turns your head to it with
// smooth, slightly random movement, and right clicks once the crosshair is on it.
// Afterwards it turns your head back to where you were really looking ("snap back").
//
// Callbacks:
// clutch_tick every tick: right click when the crosshair is on the planned block
// clutch_rotation_override_flag tells the engine we control the rotation this tick
// clutch_on_late_tick every tick: pick a block, aim at it, snap back afterwards
// clutch_pick_aim_target helper: aim point on one candidate block and how far we must turn
#include "slinky/engine.h"
struct Vec3 { double x, y, z; };
struct BlockPos { int x, y, z; };
struct Rot { float yaw, pitch; };
struct Box { Vec3 lo, hi; };
struct Range { float lo, hi; };
// ---- settings ----
extern "C" float clutch_clicks_per_second;
extern "C" float clutch_snapback_duration; // ticks to turn back to the real rotation
extern "C" float clutch_snapback_delay; // ticks to wait before turning back
extern "C" float clutch_randomisation; // 0 = no randomness, 1 = full
extern "C" float clutch_aim_speed; // max degrees per tick
extern "C" float clutch_aim_multiplier; // fraction of the remaining angle to turn per tick
extern "C" float clutch_aim_multiplier_strength; // how much the multiplier is used vs. the max speed
extern "C" unsigned char clutch_snapback_instantly_on_jump;
extern "C" unsigned char clutch_require_air; // only while in the air
extern "C" unsigned char clutch_require_damage; // only within 10 ticks of being hit
extern "C" unsigned char clutch_require_moving_backwards;
extern "C" float clutch_min_height; // only when the ground is at least this far below
extern "C" float clutch_range; // how far away a block may be (index into the candidate table)
extern "C" float clutch_max_aim_distance; // give up when the head would have to turn more than this
extern "C" unsigned char clutch_sideways_only; // never place on the block straight below
extern "C" unsigned char clutch_multipoint_aim;
extern "C" int clutch_select_blocks_1_switch_2; // 1 = switch to blocks, 2 = switch to blocks and back
extern "C" unsigned char clutch_disable_after; // turn the module off after one clutch
// ---- module state ----
extern "C" char clutch_module_descriptor[];
extern "C" float clutch_click_cooldown; // ticks until the next right click
extern "C" unsigned char clutch_planned; // a block is planned and we hold blocks
extern "C" BlockPos clutch_planned_block; // block to place against
extern "C" unsigned char clutch_planned_face_up; // place on its top (1) or on a side (0)
extern "C" unsigned char clutch_rotating; // we control the rotation this tick
extern "C" Vec3 clutch_aim_point; // point on the block we aim at
extern "C" int clutch_ticks_since_last_hurt;
extern "C" int clutch_ticks_left_jump_snapback; // window after a clutch in which jumping snaps back at once
extern "C" int clutch_snapback_delay_second; // ticks left before the snap back starts
extern "C" int clutch_snapback_ticks_left; // ticks left of the snap back
extern "C" unsigned char clutch_disable_module_after_snapback;
extern "C" double clutch_jump_wiggle_direction; // sum of the random yaw wiggles on jump
extern "C" char clutch_random_walk_1[], clutch_random_walk_2[], clutch_random_walk_3[], clutch_random_walk_4[],
clutch_random_walk_5[], clutch_random_walk_6[], clutch_random_walk_7[], clutch_random_walk_8[]; // random walk states
// Candidate blocks around the player, nearest first. Each entry packs an offset as three
// 4-bit numbers (x, y, z, each + 8). The first table says how many entries are within a distance.
extern "C" const unsigned short clutch_candidates_within_distance_n[8];
extern "C" const unsigned short clutch_candidate_offsets_4_bits_each[];
// Bounds of random ranges (the name says the value: neg_0_1 = -0.1, 0_05 = 0.05).
extern "C" const float random_range_bound_0_05_in_clutch, random_range_bound_neg_0_1_in_clutch, random_range_bound_0_1_in_clutch, random_range_bound_neg_20_in_clutch,
random_range_bound_20_in_clutch_a, random_range_bound_neg_0_05_in_clutch, random_range_bound_5_in_clutch, random_range_bound_15_in_clutch,
random_range_bound_0_05_in_clutch_a, random_range_bound_neg_0_01, random_range_bound_0_01_in_clutch;
// ---- 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)); // 1 = a block
FN(BlockPos, java_get_moving_object_position_block_pos, (void *jvm, void *hit));
FN(int, java_get_variant, (void *jvm, void *hit)); // face hit, 1 = top
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_increment_key_binding_press_time, (void *jvm, void *key_binding)); // = one right click
FN(Vec3, java_get_adjacent_block_position, (void *jvm, void *hit)); // where the new block goes
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, is_silent_rotation_active, ());
FN(void *, get_held_item, (void *jvm, void *game_settings)); // here: the jump key
FN(unsigned char, java_get_key_binding_key_code, (void *jvm, void *key_binding));
FN(Rot, get_entity_rotation, (void *jvm, void *entity));
FN(Rot, get_silent_rotation_offset, ());
FN(Rot, get_render_rotation, ()); // where the player really looks
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, wrap_angle, (float deg)); // to -180..180
FN(void, apply_silent_rotation, (Rot rotation));
FN(Range, rot_make_floats, (float lo, float hi));
FN(float, random_rotation, (Range r)); // random value in the range
FN(float, walk_update, (void *state, Range r, double d)); // next value of a random walk
FN(float, walk_update_timed, (void *state, Range r, double a, double b));
FN(float, limit_rotation_delta, (float lo, float hi, float v)); // clamp
FN(float, lerp_unclamped_float, (float a, float b, float t));
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(void *, java_call_entity_living_base_get_position, (void *jvm, void *entity_living_base)); // eye position
FN(Vec3, java_get_vec3_x_coord, (void *jvm, void *vec3));
FN(void *, java_get_entity_riding_entity, (void *jvm, void *entity));
FN(Vec3, java_get_entity_motion_x, (void *jvm, void *entity));
FN(double, libc_hypot, (double x, double y));
FN(double, libc_acos, (double x));
FN(float, libc_sinf, (float x));
FN(float, libc_cosf, (float x));
FN(double, libc_floor, (double x));
FN(double, libc_fmod, (double x, double y));
FN(void *, java_block_pos_init, (void *jvm, void *object, int y, int z));
FN(void *, java_call_world_get_block_state, (void *jvm, void *world, void *pos, int x, int y, int z));
FN(int, get_block_id, (void *jvm, void *block));
FN(double, vec3_distance_sq, (Vec3 a, Vec3 b));
FN(void *, java_new_vec3_init, (void *jvm, Vec3 v));
FN(void *, java_world_ray_trace_blocks, (void *jvm, void *world, void *from, void *to, unsigned char liquids, unsigned char ignore_no_box, unsigned char last));
FN(Vec3, vec3_make, (double x, double y, double z));
FN(Rot, rot_look_at, (Vec3 from, Vec3 to));
FN(void, track_owner, (Ctx *ctx, void *mod, unsigned char back));
FN(void *, item_held_hotbar_slot, (void *jvm, void *slot));
FN(unsigned char, block_entity_id, (void *jvm, void *entity)); // 1 if the item is a block
FN(void, queue_module_toggle, (void *module_manager, void *module, unsigned char enabled));
FN(unsigned char, update_rotation_priority_peak, (int ms)); // may this module control the rotation?
FN(Vec3, java_get_entity_rotation_pitch, (void *jvm, void *entity)); // look direction (unit vector)
FN(Vec3, vec3_scale, (Vec3 v, double k));
FN(unsigned char, aabb_ray_hit, (Box b, Vec3 origin, Vec3 dir, Vec3 *hit));
static const float BIGGEST_FLOAT = 3.40282347e+38f;
static const double MAX_REACH_SQUARED = 4.49 * 4.49;
static int abs_i(int v) { return v < 0 ? -v : v; }
static double abs_d(double x) { return __builtin_fabs(x); }
static float abs_f(float x) { return __builtin_fabsf(x); }
static bool same_block(BlockPos a, BlockPos b) { return a.x == b.x && a.y == b.y && a.z == b.z; }
// Every tick: right click when the crosshair is on the planned block, at "clicks_per_second".
extern "C" void clutch_tick(Hook *hook) {
float cooldown = clutch_click_cooldown;
if (cooldown > 0.0f) {
cooldown += -1.0f;
clutch_click_cooldown = cooldown;
if (cooldown > 0.0f)
return;
}
clutch_click_cooldown = 20.0f / clutch_clicks_per_second + cooldown;
Ctx *ctx = hook->ctx;
if (ctx->in_game != 1 || !clutch_planned)
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) != 1)
return;
if (!same_block(java_get_moving_object_position_block_pos(ctx->jvm, hit), clutch_planned_block))
return;
// Must be the planned face: the top, or a side.
bool hit_top = java_get_variant(ctx->jvm, hit) == 1;
if (hit_top != (clutch_planned_face_up != 0))
return;
java_increment_key_binding_press_time(ctx->jvm, java_get_game_settings_use_item_key(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft)));
// Next time, place against the block we just placed.
Vec3 placed = java_get_adjacent_block_position(ctx->jvm, hit);
clutch_planned_block.x = (int)placed.x;
clutch_planned_block.y = (int)placed.y;
clutch_planned_block.z = (int)placed.z;
}
extern "C" void clutch_rotation_override_flag(char *h) {
if (clutch_rotating == 1) {
h[8] = 1; // override yaw
h[9] = 1; // override pitch
}
}
// Pick a point on the side of a candidate block (at base + rel) that faces the player.
// Writes it to *out and returns how many degrees the head has to turn to look at it.
extern "C" float clutch_pick_aim_target(Vec3 *eye, Rot cur, Vec3 *center, BlockPos *base, BlockPos *rel, Vec3 *out) {
int rx = rel->x, ry = rel->y, rz = rel->z;
float jitter_inset = walk_update(clutch_random_walk_1, rot_make_floats(0.0f, random_range_bound_0_05_in_clutch_a), 1.0);
float randomness = clutch_randomisation;
float jitter_x = walk_update(clutch_random_walk_2, rot_make_floats(random_range_bound_neg_0_01, random_range_bound_0_01_in_clutch), 0.5);
float jitter_z = walk_update(clutch_random_walk_3, rot_make_floats(random_range_bound_neg_0_01, random_range_bound_0_01_in_clutch), 0.5);
double shift_x = (double)(jitter_x * randomness), shift_z = (double)(jitter_z * randomness);
if (!clutch_multipoint_aim) {
// Lean towards the side of the block the previous aim point was on.
double frac_x = abs_d(libc_fmod(center->x, 1.0));
double frac_z = abs_d(libc_fmod(center->z, 1.0));
frac_x = 0.5 < frac_x ? abs_d(frac_x + -1.0) : frac_x;
frac_z = 0.5 < frac_z ? abs_d(frac_z + -1.0) : frac_z;
shift_z += frac_x * (clutch_aim_point.z < center->z ? -1.0 : 1.0);
shift_x += frac_z * (clutch_aim_point.x < center->x ? -1.0 : 1.0);
}
// The face pointing at us: on the x side if the block is further away in x, else on the z side.
// Stay a little away from the face's edges.
double inset = (double)(randomness * jitter_inset) + 0.1;
double far = 1.0 - inset;
double x_lo, x_hi, z_lo, z_hi;
if ((unsigned)abs_i(rx) > (unsigned)abs_i(rz)) {
x_lo = x_hi = (double)((unsigned)rx >> 31); // 1 if the block is at -x (aim at its +x face), else 0
z_lo = inset;
z_hi = far;
} else {
x_lo = inset;
x_hi = far;
z_lo = z_hi = (double)((unsigned)rz >> 31);
}
// Aim point: as close to our position as the face allows; higher for blocks further away.
int bx = rx + base->x, by = ry + base->y, bz = rz + base->z;
double distance = (double)(abs_i(rel->x) + abs_i(rel->z));
double aim_x = limit_rotation_delta((float)(x_lo + bx), (float)(x_hi + bx), (float)(shift_x + center->x));
double aim_y = (double)limit_rotation_delta(0.0f, 0.65f, (float)(distance * 0.25)) + ((double)by + 0.25);
double aim_z = limit_rotation_delta((float)(z_lo + bz), (float)(z_hi + bz), (float)(shift_z + center->z));
Vec3 aim = vec3_make(aim_x, aim_y, aim_z);
Rot diff = rot_sub(rot_look_at(*eye, aim), cur);
*out = aim;
return abs_f(wrap_angle(diff.yaw)) + abs_f(diff.pitch);
}
// Should we try to clutch right now?
static bool should_clutch(Ctx *ctx, unsigned char on_ground) {
if (clutch_require_air & on_ground)
return false;
if (clutch_ticks_since_last_hurt >= 11 && clutch_require_damage)
return false;
if (java_get_entity_riding_entity(ctx->jvm, ctx->player))
return false;
if (clutch_require_moving_backwards == 1) {
Vec3 motion = java_get_entity_motion_x(ctx->jvm, ctx->player);
double speed = libc_hypot(motion.x, motion.z);
if (speed == 0.0)
return false;
// Angle between the facing direction and the motion: under 90 degrees = moving forwards.
float facing = (float)((double)get_entity_rotation(ctx->jvm, ctx->player).yaw * -3.141592653589793 / 180.0 + -3.141592653589793);
float sin_facing = libc_sinf(facing), cos_facing = libc_cosf(facing);
if (1.5707963267948966 > libc_acos(((double)sin_facing * motion.x + (double)cos_facing * motion.z) / speed))
return false;
}
return true;
}
// Find the best block to place against. Sets clutch_aim_point / clutch_planned_block.
// Returns false when there is nothing to do.
static bool plan_block(Ctx *ctx, Box player_box, Vec3 eye, Rot cur) {
// Middle of the feet, just inside the block below.
Vec3 center = {(player_box.lo.x + player_box.hi.x) * 0.5, player_box.lo.y + -0.99, (player_box.lo.z + player_box.hi.z) * 0.5};
clutch_planned_face_up = 0;
void *pos = **(int **)ctx->jvm ? java_block_pos_init(ctx->jvm, nullptr, 0, 0) : nullptr;
BlockPos base = {(int)libc_floor(center.x), (int)libc_floor(center.y), (int)libc_floor(center.z)};
// Ground closer than "min_height": nothing to do.
if (clutch_min_height > 0.0f) {
int y = base.y;
for (int depth = 1;; depth++, y--) {
if (get_block_id(ctx->jvm, java_call_world_get_block_state(ctx->jvm, ctx->world, pos, base.x, y, base.z)))
return false;
if (!(clutch_min_height > (float)depth))
break;
}
}
unsigned long long candidates = clutch_candidates_within_distance_n[(int)clutch_range];
long long best_rank = -3;
float best_cost = BIGGEST_FLOAT;
Vec3 best_aim = {};
BlockPos best_block = {};
Vec3 aim;
// Keep the previously planned block while it is still there, reachable and visible.
if (!((double)clutch_planned_block.y > center.y) &&
get_block_id(ctx->jvm, java_call_world_get_block_state(ctx->jvm, ctx->world, pos, clutch_planned_block.x, clutch_planned_block.y, clutch_planned_block.z))) {
BlockPos rel = {clutch_planned_block.x - base.x, clutch_planned_block.y - base.y, clutch_planned_block.z - base.z};
float cost = clutch_pick_aim_target(&eye, cur, &center, &base, &rel, &aim);
if (!(cost > clutch_max_aim_distance) && MAX_REACH_SQUARED > vec3_distance_sq(eye, aim)) {
void *hit = java_world_ray_trace_blocks(ctx->jvm, ctx->world, java_new_vec3_init(ctx->jvm, eye), java_new_vec3_init(ctx->jvm, aim), 0, 1, 0);
BlockPos hit_block = clutch_planned_block;
if (hit)
hit_block = java_get_moving_object_position_block_pos(ctx->jvm, hit);
if (same_block(hit_block, clutch_planned_block)) {
best_aim = aim;
best_block = hit_block;
best_cost = BIGGEST_FLOAT;
if (cost != BIGGEST_FLOAT) {
best_rank = abs_i(hit_block.x - base.x) + abs_i(hit_block.y - base.y) + abs_i(hit_block.z - base.z) - 2;
best_cost = cost;
}
}
}
}
// Try the candidate blocks, nearest first.
for (unsigned long long i = 0; i < candidates; i++) {
unsigned packed = clutch_candidate_offsets_4_bits_each[i];
int ox = (packed & 0xf) - 8, oy = (packed >> 4 & 0xf) - 8, oz = (packed >> 8 & 0xf) - 8;
int x = base.x + ox, y = base.y + oy, z = base.z + oz;
if (!get_block_id(ctx->jvm, java_call_world_get_block_state(ctx->jvm, ctx->world, pos, x, y, z)))
continue; // air, nothing to place against
if (!ox && !oz) {
// A block straight below: aim at a random point on its top. That always wins.
if (clutch_sideways_only)
return false;
double inset = (double)(walk_update(clutch_random_walk_1, rot_make_floats(0.0f, random_range_bound_0_05_in_clutch), 1.0) * clutch_randomisation) + 0.1;
double shift_x = walk_update(clutch_random_walk_4, rot_make_floats(random_range_bound_neg_0_1_in_clutch, random_range_bound_0_1_in_clutch), 1.0) * clutch_randomisation;
double shift_z = walk_update(clutch_random_walk_5, rot_make_floats(random_range_bound_neg_0_1_in_clutch, random_range_bound_0_1_in_clutch), 1.0) * clutch_randomisation;
double aim_x = limit_rotation_delta((float)((double)x + inset), (float)((double)(x + 1) - inset), (float)(center.x + shift_x));
double aim_z = limit_rotation_delta((float)((double)z + inset), (float)((double)(z + 1) - inset), (float)(center.z + shift_z));
clutch_aim_point = vec3_make(aim_x, (double)y + 1.0, aim_z);
clutch_planned_block = BlockPos{x, y, z};
clutch_planned_face_up = 1;
return true;
}
// Once a block is found, only blocks at the same distance are still worth checking.
long long rank = abs_i(ox) + abs_i(oy) + abs_i(oz);
candidates = clutch_candidates_within_distance_n[rank];
BlockPos rel = {ox, oy, oz};
float cost = clutch_pick_aim_target(&eye, cur, &center, &base, &rel, &aim);
if (cost > best_cost && best_rank <= rank)
continue;
if (!(MAX_REACH_SQUARED > vec3_distance_sq(eye, aim)))
continue;
best_aim = aim;
best_block = BlockPos{x, y, z};
best_cost = cost;
}
if (best_cost > clutch_max_aim_distance)
return false;
clutch_aim_point = best_aim;
clutch_planned_block = best_block;
return true;
}
// Turn the head a step towards the aim point.
static void aim_at_planned_block(Ctx *ctx, Vec3 eye, Rot cur) {
// Already looking at the top of the planned block: nothing to do.
int bx = clutch_planned_block.x, by = clutch_planned_block.y, bz = clutch_planned_block.z;
Vec3 look = vec3_scale(java_get_entity_rotation_pitch(ctx->jvm, ctx->player), 4.4);
Box top = {{bx + 0.02, by + 0.02, bz + 0.02}, {bx + 0.98, (double)(by + 1), 0.98 + bz}};
Vec3 hit;
if (aabb_ray_hit(top, eye, look, &hit) && (double)by + 0.99 > hit.y)
return;
Rot want = rot_look_at(eye, clutch_aim_point);
Rot diff = rot_sub(want, cur);
float yaw_diff;
if ((double)want.pitch > 89.999)
yaw_diff = walk_update(clutch_random_walk_6, rot_make_floats(random_range_bound_neg_20_in_clutch, random_range_bound_20_in_clutch_a), 0.5) * clutch_randomisation; // straight down: yaw does not matter, wiggle it
else
yaw_diff = wrap_angle(diff.yaw);
// Turn at most "aim_speed" (randomly a bit less) per tick...
float speed = clutch_aim_speed;
Range speed_range = rot_make_floats((float)((double)clutch_randomisation * -0.25 + 1.0), 1.0f);
float max_yaw = walk_update_timed(clutch_random_walk_7, speed_range, 10.0, 1.0) * speed;
speed_range = rot_make_floats((float)((double)clutch_randomisation * -0.25 + 1.0), 1.0f);
float max_pitch = speed * walk_update_timed(clutch_random_walk_8, speed_range, 10.0, 1.0);
float capped_yaw = limit_rotation_delta(-max_yaw, max_yaw, yaw_diff);
float capped_pitch = limit_rotation_delta(-max_pitch, max_pitch, diff.pitch);
// ...mixed with turning a fraction ("aim_multiplier") of the remaining angle.
float mult_yaw = clutch_aim_multiplier + walk_update_timed(clutch_random_walk_7, rot_make_floats(random_range_bound_neg_0_05_in_clutch, random_range_bound_0_05_in_clutch), 10.0, 1.0);
float mult_pitch = clutch_aim_multiplier + walk_update_timed(clutch_random_walk_8, rot_make_floats(random_range_bound_neg_0_05_in_clutch, random_range_bound_0_05_in_clutch), 10.0, 1.0);
float turn_yaw = lerp_unclamped_float(capped_yaw, mult_yaw * yaw_diff, clutch_aim_multiplier_strength);
float turn_pitch = lerp_unclamped_float(capped_pitch, mult_pitch * diff.pitch, clutch_aim_multiplier_strength);
apply_silent_rotation(Rot{turn_yaw, turn_pitch});
}
// Turn back to the real rotation, evenly over the remaining snap-back ticks.
static void snap_back(Ctx *ctx) {
if (clutch_snapback_delay_second > 0)
return;
int ticks_left = clutch_snapback_ticks_left;
if (ticks_left <= 0 || !is_silent_rotation_active())
return;
Rot now = rot_add(get_entity_rotation(ctx->jvm, ctx->player), get_silent_rotation_offset());
Rot diff = rot_sub(get_render_rotation(), now);
diff.yaw = wrap_angle(diff.yaw);
apply_silent_rotation(rot_scale(diff, 1.0f / (float)ticks_left));
}
extern "C" void clutch_on_late_tick(Hook *hook) {
clutch_planned = 0;
clutch_rotating = 0;
Ctx *ctx = hook->ctx;
if (ctx->in_game != 1)
return;
unsigned char on_ground = java_get_entity_on_ground(ctx->jvm, ctx->player);
clutch_ticks_since_last_hurt = java_get_entity_living_base_hurt_time(ctx->jvm, ctx->player) == 0 ? clutch_ticks_since_last_hurt + 1 : 0;
// Shortly after a clutch, jumping turns the head back at once (with a small random wiggle).
if (clutch_ticks_left_jump_snapback > 0) {
clutch_ticks_left_jump_snapback -= 1;
if (on_ground && is_silent_rotation_active() && clutch_snapback_instantly_on_jump &&
java_get_key_binding_key_code(ctx->jvm, get_held_item(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft)))) {
Rot cur = rot_add(get_entity_rotation(ctx->jvm, ctx->player), get_silent_rotation_offset());
Rot real = get_render_rotation();
double sign = 0.0 > clutch_jump_wiggle_direction ? 1.0 : -1.0; // wiggle the other way than last time
float wiggle_yaw = (float)((double)random_rotation(rot_make_floats(random_range_bound_5_in_clutch, random_range_bound_15_in_clutch)) * sign);
float wiggle_pitch = (float)((double)random_rotation(rot_make_floats(random_range_bound_5_in_clutch, random_range_bound_15_in_clutch)) * sign);
clutch_jump_wiggle_direction += wiggle_yaw;
Rot diff = rot_sub(rot_add(real, rot_scale(Rot{wiggle_yaw, wiggle_pitch}, clutch_randomisation)), cur);
diff.yaw = wrap_angle(diff.yaw);
apply_silent_rotation(diff);
clutch_rotating = 1;
clutch_snapback_delay_second = (int)clutch_snapback_duration;
return;
}
}
Box player_box = java_get_axis_aligned_bb_min_x(ctx->jvm, java_get_entity_bounding_box(ctx->jvm, ctx->player));
Vec3 eye = java_get_vec3_x_coord(ctx->jvm, java_call_entity_living_base_get_position(ctx->jvm, ctx->player));
Rot cur = rot_add(get_entity_rotation(ctx->jvm, ctx->player), get_silent_rotation_offset());
bool start_aiming = false;
if (should_clutch(ctx, on_ground) && plan_block(ctx, player_box, eye, cur)) {
if (clutch_select_blocks_1_switch_2 == 1)
track_owner(ctx, clutch_module_descriptor, 0);
else if (clutch_select_blocks_1_switch_2 == 2)
track_owner(ctx, clutch_module_descriptor, 1);
clutch_planned = block_entity_id(ctx->jvm, item_held_hotbar_slot(ctx->jvm, ctx->player));
if (clutch_planned) {
// Plan the snap back for after the clutch.
float delay_scale = random_rotation(rot_make_floats(1.0f, (float)((double)clutch_randomisation * 0.5 + 1.0)));
clutch_snapback_delay_second = (int)(delay_scale * clutch_snapback_delay);
clutch_ticks_left_jump_snapback = 10;
clutch_disable_module_after_snapback = clutch_disable_after;
start_aiming = true;
}
} else {
clutch_planned = 0;
}
if (!start_aiming) {
// Not clutching: run the snap-back timers.
if (clutch_snapback_delay_second > 0) {
clutch_snapback_delay_second -= 1;
clutch_snapback_ticks_left = (int)clutch_snapback_duration;
} else if (clutch_snapback_ticks_left > 0) {
clutch_snapback_ticks_left -= 1;
clutch_planned = 0;
} else {
// Snap back finished.
if (clutch_disable_module_after_snapback == 1) {
queue_module_toggle(ctx->module_manager, clutch_module_descriptor, 0);
clutch_disable_module_after_snapback = 0;
}
return;
}
}
if (!update_rotation_priority_peak(1000))
return;
clutch_rotating = 1;
if (clutch_planned)
aim_at_planned_block(ctx, eye, cur);
else
snap_back(ctx);
}
+94
View File
@@ -0,0 +1,94 @@
// Clutch — Clutches for you when falling.
// category: block descriptor: 0x2f5580 settings block: 0x2f5778
// functions: gui clutch_gui, register clutch_register
// implementation: src/logic/block/clutch.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_clutch); // "Main"
S(str_aim_in_clutch); // "Aim"
S(str_snap_back); // "Snap-back"
S(str_conditions_in_clutch); // "Conditions"
S(str_range_in_clutch); // "range"
S(str_max_aim_dist); // "max_aim_dist"
S(str_min_height); // "min_height"
S(str_click_speed_in_clutch); // "click_speed"
S(str_randomization_in_clutch); // "randomization"
S(str_select_blocks_in_clutch); // "select_blocks"
S(str_sideways_only); // "sideways_only"
S(str_aim_speed); // "aim_speed"
S(str_aim_mult); // "aim_mult"
S(str_aim_mult_strength); // "aim_mult_strength"
S(str_aim_multipoint); // "aim_multipoint"
S(str_snapback_delay); // "snapback_delay"
S(str_snapback_duration); // "snapback_duration"
S(str_snapback_instant_on_jump); // "snapback_instant_on_jump"
S(str_snapback_disable_after); // "snapback_disable_after"
S(str_require_air_in_clutch); // "require_air"
S(str_require_damage_in_clutch); // "require_damage"
S(str_require_backwards); // "require_backwards"
D(clutch_click_speed_setting); // setting num "click_speed"
D(clutch_snapback_duration_setting); // setting num "snapback_duration"
D(clutch_snapback_delay_setting); // setting num "snapback_delay"
D(clutch_randomization_setting); // setting num "randomization"
D(clutch_aim_speed_setting); // setting num "aim_speed"
D(clutch_aim_mult_setting); // setting num "aim_mult"
D(clutch_aim_mult_strength_setting); // setting num "aim_mult_strength"
D(clutch_snapback_instant_on_jump_setting); // setting bool "snapback_instant_on_jump"
D(clutch_require_air_setting); // setting bool "require_air"
D(clutch_require_damage_setting); // setting bool "require_damage"
D(clutch_require_backwards_setting); // setting bool "require_backwards"
D(clutch_min_height_setting); // setting num "min_height"
D(clutch_range_setting); // setting num "range"
D(clutch_max_aim_dist_setting); // setting num "max_aim_dist"
D(clutch_sideways_only_setting); // setting bool "sideways_only"
D(clutch_aim_multipoint_setting); // setting bool "aim_multipoint"
D(clutch_select_blocks_setting); // setting enum "select_blocks"
D(clutch_snapback_disable_after_setting); // setting bool "snapback_disable_after"
extern "C" void clutch_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_clutch);
W_slider(window, gui, clutch_range_setting);
W_slider(window, gui, clutch_max_aim_dist_setting);
W_slider(window, gui, clutch_min_height_setting);
W_slider(window, gui, clutch_click_speed_setting);
W_slider(window, gui, clutch_randomization_setting);
W_enumw(window, gui, clutch_select_blocks_setting);
W_bool(window, gui, clutch_sideways_only_setting);
W_label(gui, window, str_aim_in_clutch);
W_slider(window, gui, clutch_aim_speed_setting);
W_slider(window, gui, clutch_aim_mult_setting);
W_slider(window, gui, clutch_aim_mult_strength_setting);
W_bool(window, gui, clutch_aim_multipoint_setting);
W_label(gui, window, str_snap_back);
W_slider(window, gui, clutch_snapback_delay_setting);
W_slider(window, gui, clutch_snapback_duration_setting);
W_bool(window, gui, clutch_snapback_instant_on_jump_setting);
W_bool(window, gui, clutch_snapback_disable_after_setting);
W_label(gui, window, str_conditions_in_clutch);
W_bool(window, gui, clutch_require_air_setting);
W_bool(window, gui, clutch_require_damage_setting);
W_bool(window, gui, clutch_require_backwards_setting);
}
extern "C" void clutch_register(void *module) {
R_num(module, str_range_in_clutch, clutch_range_setting);
R_num(module, str_max_aim_dist, clutch_max_aim_dist_setting);
R_num(module, str_min_height, clutch_min_height_setting);
R_num(module, str_click_speed_in_clutch, clutch_click_speed_setting);
R_num(module, str_randomization_in_clutch, clutch_randomization_setting);
R_enum(module, str_select_blocks_in_clutch, clutch_select_blocks_setting);
R_bool(module, str_sideways_only, clutch_sideways_only_setting);
R_num(module, str_aim_speed, clutch_aim_speed_setting);
R_num(module, str_aim_mult, clutch_aim_mult_setting);
R_num(module, str_aim_mult_strength, clutch_aim_mult_strength_setting);
R_bool(module, str_aim_multipoint, clutch_aim_multipoint_setting);
R_num(module, str_snapback_delay, clutch_snapback_delay_setting);
R_num(module, str_snapback_duration, clutch_snapback_duration_setting);
R_bool(module, str_snapback_instant_on_jump, clutch_snapback_instant_on_jump_setting);
R_bool(module, str_snapback_disable_after, clutch_snapback_disable_after_setting);
R_bool(module, str_require_air_in_clutch, clutch_require_air_setting);
R_bool(module, str_require_damage_in_clutch, clutch_require_damage_setting);
R_bool(module, str_require_backwards, clutch_require_backwards_setting);
}
+68
View File
@@ -0,0 +1,68 @@
// Fast Mine - break blocks faster.
//
// Two tricks:
// - the pause between breaking one block and starting the next ("block hit delay") is
// capped at "break_delay", and can count down faster;
// - on the first tick of mining a block, the progress is jumped ahead so the block
// breaks in 1/"speed" of the normal number of ticks.
//
// Callbacks (descriptor slots +0x48 / +0x168):
// fast_mine_on_tick every tick: shorten the block hit delay
// fast_mine_on_late_tick every tick, after mining progress was updated: skip ahead
#include "slinky/engine.h"
// ---- settings ----
extern "C" float fast_mine_break_delay_value; // "break_delay": longest delay allowed (ticks)
extern "C" unsigned char fast_mine_decr_block_hit_delay_value; // "decr_block_hit_delay": count the delay down twice as fast
extern "C" float fast_mine_speed; // "speed": 2 = blocks break in half the ticks
// ---- module state ----
extern "C" int fast_mine_last_block_hit_delay; // block hit delay seen last tick
extern "C" float fast_mine_last_progress_value; // mining progress seen last tick (0 = not mining)
// ---- game / engine functions ----
FN(void *, java_get_minecraft_player_controller, (void *jvm, void *minecraft));
FN(float, java_get_player_controller_mp_cur_block_damage_mp, (void *jvm, void *blk)); // mining progress, 0..1
FN(void, java_set_player_controller_mp_cur_block_damage_mp, (void *jvm, void *blk, float value));
FN(int, java_get_player_controller_mp_block_hit_delay, (void *jvm, void *blk));
FN(void, java_set_player_controller_mp_block_hit_delay, (void *jvm, void *blk, int value));
FN(float, libc_ceilf, (float v));
extern "C" void fast_mine_on_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
int delay = 0;
void *controller = java_get_minecraft_player_controller(ctx->jvm, ctx->minecraft);
if (controller) {
fast_mine_last_progress_value = java_get_player_controller_mp_cur_block_damage_mp(ctx->jvm, controller);
delay = java_get_player_controller_mp_block_hit_delay(ctx->jvm, controller);
if ((float)delay > fast_mine_break_delay_value) {
// Longer than allowed: cap it.
java_set_player_controller_mp_block_hit_delay(ctx->jvm, controller, (int)fast_mine_break_delay_value);
} else if (delay > 0 && fast_mine_decr_block_hit_delay_value && delay == fast_mine_last_block_hit_delay) {
// The game did not count it down this tick yet: take one off ourselves.
java_set_player_controller_mp_block_hit_delay(ctx->jvm, controller, delay - 1);
}
}
fast_mine_last_block_hit_delay = delay;
}
extern "C" void fast_mine_on_late_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
void *controller = java_get_minecraft_player_controller(ctx->jvm, ctx->minecraft);
if (!controller)
return;
// Only on the first tick of mining a block (progress went from 0 to something).
float progress_per_tick = java_get_player_controller_mp_cur_block_damage_mp(ctx->jvm, controller);
if (progress_per_tick == 0.0f || fast_mine_last_progress_value != 0.0f)
return;
// Ticks the block normally takes, and ticks we want it to take.
long long normal_ticks = (long long)libc_ceilf(1.0f / progress_per_tick);
double wanted = 1.0 / (double)fast_mine_speed / (double)progress_per_tick;
long long wanted_ticks = (long long)libc_ceilf((float)wanted);
// Jump ahead by the difference.
unsigned int ticks_done = (unsigned int)((int)normal_ticks - (int)wanted_ticks + 1);
java_set_player_controller_mp_cur_block_damage_mp(ctx->jvm, controller, (float)(long long)ticks_done * progress_per_tick);
}
+35
View File
@@ -0,0 +1,35 @@
// Fast Mine — Increases block mining speed.
// category: block descriptor: 0x2f1d90 settings block: 0x2f1f88
// functions: gui fast_mine_gui, register fast_mine_register, status fast_mine_status
// implementation: src/logic/block/fast_mine.cpp
#pragma once
#include "slinky/api.h"
S(str_2fx_in_fast_mine); // "%.2fx"
S(str_main_in_fast_mine); // "Main"
S(str_speed_in_fast_mine); // "speed"
S(str_break_delay_in_fast_mine); // "break_delay"
S(str_decr_block_hit_delay); // "decr_block_hit_delay"
D(fast_mine_break_delay_setting); // setting num "break_delay"
D(fast_mine_decr_block_hit_delay_setting); // setting bool "decr_block_hit_delay"
D(fast_mine_speed_setting); // setting num "speed"
extern "C" float fast_mine_speed; // current value of setting "speed" (+0x30)
extern "C" void fast_mine_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_fast_mine);
W_slider(window, gui, fast_mine_speed_setting);
W_slider(window, gui, fast_mine_break_delay_setting);
W_bool(window, gui, fast_mine_decr_block_hit_delay_setting);
}
extern "C" void fast_mine_register(void *module) {
R_num(module, str_speed_in_fast_mine, fast_mine_speed_setting);
R_num(module, str_break_delay_in_fast_mine, fast_mine_break_delay_setting);
R_bool(module, str_decr_block_hit_delay, fast_mine_decr_block_hit_delay_setting);
}
extern "C" void fast_mine_status(void *self) {
log_fmt(self, 0x20, str_2fx_in_fast_mine, (double)fast_mine_speed);
}
+120
View File
@@ -0,0 +1,120 @@
// Fast Place - place blocks quickly while holding right click.
//
// Minecraft repeats right click only every 4 ticks. While you hold the use key, this
// module clicks at "max_cps" clicks per second instead (after "activation_delay" ticks).
// It skips clicks that would put a block inside yourself, except now and then at random.
//
// Callback:
// fast_place_tick every tick
#include "slinky/engine.h"
struct Vec3 { double x, y, z; };
struct Box { Vec3 lo, hi; };
struct Range { float lo, hi; };
// ---- settings ----
extern "C" float fast_place_max_cps; // clicks per second
extern "C" float fast_place_activation_delay; // ticks to hold before clicking starts
// ---- module state ----
extern "C" float fast_place_click_timer; // ticks until the next click
extern "C" unsigned char fast_place_use_key_held_last_tick;
extern "C" int fast_place_activation_delay_left;
extern "C" char fast_place_random_walk_1[]; // random walk state
// Bounds of the random range used to sometimes click anyway (0.02 .. 0.08).
extern "C" const float random_range_bound_0_02, random_range_bound_0_08_in_fast_place;
// ---- game / engine functions ----
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(int, java_get_key_binding_press_time, (void *jvm, void *key_binding)); // clicks waiting to be handled
FN(void, java_increment_key_binding_press_time, (void *jvm, void *key_binding)); // = one right click
FN(void *, item_held_hotbar_slot, (void *jvm, void *slot));
FN(unsigned char, block_entity_id, (void *jvm, void *entity)); // 1 if the item is a block
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(int, java_call_static_item_get_id_from_item, (void *jvm, void *item));
FN(Vec3, java_get_adjacent_block_position, (void *jvm, void *hit)); // where the new block would go
FN(Vec3, vec3_make, (double x, double y, double z));
FN(Vec3, vec3_add, (Vec3 a, Vec3 b));
FN(Box, aabb_make, (Vec3 lo, Vec3 hi));
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(unsigned char, aabb_intersects, (Box a, Box b));
FN(Range, rot_make_floats, (float lo, float hi));
FN(unsigned char, walk_should_change, (void *state, Range r, double d)); // random yes/no
enum { ITEM_LADDER = 65 };
// Would a click right now be useful?
static bool should_click(Ctx *ctx) {
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)
return walk_should_change(fast_place_random_walk_1, rot_make_floats(random_range_bound_0_02, random_range_bound_0_08_in_fast_place), 20.0);
// Ladders can always be placed.
void *stack = item_held_hotbar_slot(ctx->jvm, ctx->player);
if (stack && java_call_static_item_get_id_from_item(ctx->jvm, stack) == ITEM_LADDER)
return true;
// Only when the new block would not overlap the player (or now and then at random).
Vec3 cell_pos = java_get_adjacent_block_position(ctx->jvm, hit);
Box cell = aabb_make(cell_pos, vec3_add(cell_pos, vec3_make(1.0, 1.0, 1.0)));
Box player_box = java_get_axis_aligned_bb_min_x(ctx->jvm, java_get_entity_bounding_box(ctx->jvm, ctx->player));
return !aabb_intersects(cell, player_box) ||
walk_should_change(fast_place_random_walk_1, rot_make_floats(random_range_bound_0_02, random_range_bound_0_08_in_fast_place), 20.0);
}
extern "C" void fast_place_tick(Hook *hook) {
// Count the click timer down.
float timer = fast_place_click_timer;
if (timer > 0.0f) {
timer += -1.0f;
fast_place_click_timer = timer;
if (timer > 0.0f)
return;
}
Ctx *ctx = hook->ctx;
if (ctx->in_game != 1)
return;
void *use_key = java_get_game_settings_use_item_key(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft));
unsigned char was_held = fast_place_use_key_held_last_tick;
unsigned char held = java_get_key_binding_key_code(ctx->jvm, use_key);
fast_place_use_key_held_last_tick = held;
// Not holding right click: reset the activation delay.
if (!held) {
fast_place_activation_delay_left = (int)fast_place_activation_delay;
return;
}
if (fast_place_activation_delay_left > 0) {
fast_place_activation_delay_left -= 1;
return;
}
// A click is already waiting.
if (java_get_key_binding_press_time(ctx->jvm, use_key) > 0)
return;
timer = fast_place_click_timer;
if (!(0.0f >= timer))
return;
// Click as many times as fit in this tick (more than one at a high cps).
// The very first press clicks by itself, so that one is not repeated.
bool first_press = !was_held;
for (;;) {
timer = (float)((double)timer + 20.0 / (double)fast_place_max_cps); // 20 ticks per second
fast_place_click_timer = timer;
if (!first_press && block_entity_id(ctx->jvm, item_held_hotbar_slot(ctx->jvm, ctx->player))) {
if (should_click(ctx))
java_increment_key_binding_press_time(ctx->jvm, use_key);
timer = fast_place_click_timer;
}
first_press = false;
if (!(0.0f >= timer))
return;
}
}
+31
View File
@@ -0,0 +1,31 @@
// Fast Place — Allows placing blocks faster.
// category: block descriptor: 0x2ea2d0 settings block: 0x2ea4c8
// functions: gui fast_place_gui, register fast_place_register, status fast_place_status
// implementation: src/logic/block/fast_place.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_fast_place); // "Main"
S(str_max_cps); // "max_cps"
S(str_activate_delay_in_fast_place); // "activate_delay"
S(str_1f_in_fast_place); // "%.1f"
D(fast_place_max_cps_setting); // setting num "max_cps"
extern "C" float fast_place_max_cps; // current value of setting "max_cps" (+0x30)
D(fast_place_activate_delay_setting); // setting num "activate_delay"
extern "C" void fast_place_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_fast_place);
W_slider(window, gui, fast_place_max_cps_setting);
W_slider(window, gui, fast_place_activate_delay_setting);
}
extern "C" void fast_place_register(void *module) {
R_num(module, str_max_cps, fast_place_max_cps_setting);
R_num(module, str_activate_delay_in_fast_place, fast_place_activate_delay_setting);
}
extern "C" void fast_place_status(void *self) {
log_fmt(self, 0x20, str_1f_in_fast_place, (double)fast_place_max_cps);
}
+89
View File
@@ -0,0 +1,89 @@
// Ghost Hand - click through entities (hit/use the block behind them).
//
// When the crosshair is on an entity, the engine asks ghost_hand_should_ignore_entity.
// If it returns 1, the entity is ignored and the click goes to whatever is behind it.
// The settings choose which held items and which kinds of entities this applies to.
//
// Callbacks:
// ghost_hand_should_ignore_entity engine query for one entity
// ghost_hand_on_reach_query descriptor slot +0xc8: mark the module as active
#include "slinky/engine.h"
// A boolean setting stored as a full setting record; the value is at +0x18.
struct Setting { char padding_00[0x18]; unsigned char on; };
// ---- settings ----
extern "C" unsigned char ghost_hand_module_enabled;
extern "C" unsigned char ghost_hand_require_mouse_setting; // "require_mouse_pressed"
extern "C" unsigned char ghost_hand_allow_with_fists; // "allow_using_fists"
extern "C" unsigned char ghost_hand_swords; // "allow_using_sword"
extern "C" unsigned char ghost_hand_tools; // "allow_using_tools"
extern "C" unsigned char ghost_hand_bows; // "allow_using_buckets"
extern "C" unsigned char ghost_hand_flint_steel; // "allow_using_fns" (flint and steel)
extern "C" unsigned char ghost_hand_cobweb; // "allow_using_cobweb"
extern "C" unsigned char ghost_hand_other_items; // "allow_using_other"
extern "C" unsigned char ghost_hand_non_living_entities; // "non_players": ignore entities that are not players
extern "C" Setting ghost_hand_bots_setting; // "bots": ignore players marked as bots
extern "C" Setting ghost_hand_friendlies_setting; // "friendlies": ignore friends and teammates
extern "C" Setting ghost_hand_enemies_setting; // "enemies": ignore everyone else
// ---- game / engine functions ----
FN(unsigned char, vertex_pointer_current, (Ctx *ctx)); // a mouse button is held
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(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
// Is the item in your hand allowed by the settings?
static bool held_item_allowed(Ctx *ctx) {
void *held = item_held_hotbar_slot(ctx->jvm, ctx->player);
if (!held)
return ghost_hand_allow_with_fists == 1;
switch (java_call_static_item_get_id_from_item(ctx->jvm, held)) {
// shovels, pickaxes, axes (iron, wood, stone, diamond, gold) and shears
case 256: case 257: case 258:
case 269: case 270: case 271:
case 273: case 274: case 275:
case 277: case 278: case 279:
case 284: case 285: case 286:
case 359:
return ghost_hand_tools == 1;
// swords (iron, wood, stone, diamond, gold)
case 267: case 268: case 272: case 276: case 283:
return ghost_hand_swords == 1;
// bucket, water bucket, lava bucket
case 325: case 326: case 327:
return ghost_hand_bows == 1;
case 259: // flint and steel
return ghost_hand_flint_steel == 1;
case 30: // cobweb
return ghost_hand_cobweb == 1;
default:
return ghost_hand_other_items == 1;
}
}
extern "C" unsigned char ghost_hand_should_ignore_entity(Ctx *ctx, void *entity) {
if (ghost_hand_module_enabled != 1)
return 0;
if (ghost_hand_require_mouse_setting == 1 && !vertex_pointer_current(ctx))
return 0;
if (!held_item_allowed(ctx))
return 0;
void *player = java_jni_is_instance_of_entity_other_player_mp(ctx->jvm, entity);
if (!player)
return ghost_hand_non_living_entities;
// Bots first, then friends/teammates, then everyone else.
unsigned flags = entity_flags_get(ctx->jvm, player);
if (flags & 2)
return ghost_hand_bots_setting.on;
if (flags & 5)
return ghost_hand_friendlies_setting.on;
return ghost_hand_enemies_setting.on;
}
extern "C" void ghost_hand_on_reach_query(char *s) {
s[0x10] = 1;
}
+68
View File
@@ -0,0 +1,68 @@
// Ghost Hand — Allows interacting with blocks through entities.
// category: block descriptor: 0x2f48b0 settings block: 0x2f4aa8
// functions: gui ghost_hand_gui, register ghost_hand_register
// implementation: src/logic/block/ghost_hand.cpp
#pragma once
#include "slinky/api.h"
S(str_interact_through); // "Interact through"
S(str_allow_while_using_in_ghost_hand); // "Allow while using"
S(str_conditions_in_ghost_hand); // "Conditions"
S(str_non_players_in_ghost_hand); // "non_players"
S(str_friendlies_in_ghost_hand); // "friendlies"
S(str_bots_in_ghost_hand); // "bots"
S(str_enemies_in_ghost_hand); // "enemies"
S(str_allow_using_sword_in_ghost_hand); // "allow_using_sword"
S(str_allow_using_tools_in_ghost_hand); // "allow_using_tools"
S(str_allow_using_fists_in_ghost_hand); // "allow_using_fists"
S(str_allow_using_buckets); // "allow_using_buckets"
S(str_allow_using_fns); // "allow_using_fns"
S(str_allow_using_cobweb); // "allow_using_cobweb"
S(str_allow_using_other_in_ghost_hand); // "allow_using_other"
S(str_require_mouse_pressed_in_ghost_hand); // "require_mouse_pressed"
D(ghost_hand_require_mouse_pressed_setting); // setting bool "require_mouse_pressed"
D(ghost_hand_allow_using_fists_setting); // setting bool "allow_using_fists"
D(ghost_hand_allow_using_sword_setting); // setting bool "allow_using_sword"
D(ghost_hand_allow_using_tools_setting); // setting bool "allow_using_tools"
D(ghost_hand_allow_using_buckets_setting); // setting bool "allow_using_buckets"
D(ghost_hand_allow_using_fns_setting); // setting bool "allow_using_fns"
D(ghost_hand_allow_using_cobweb_setting); // setting bool "allow_using_cobweb"
D(ghost_hand_allow_using_other_setting); // setting bool "allow_using_other"
D(ghost_hand_non_players_setting); // setting bool "non_players"
D(ghost_hand_bots_setting); // setting bool "bots"
D(ghost_hand_friendlies_setting); // setting bool "friendlies"
D(ghost_hand_enemies_setting); // setting bool "enemies"
extern "C" void ghost_hand_gui(void *gui, void *window) {
W_label(gui, window, str_interact_through);
W_bool(window, gui, ghost_hand_non_players_setting);
W_bool(window, gui, ghost_hand_friendlies_setting);
W_bool(window, gui, ghost_hand_bots_setting);
W_bool(window, gui, ghost_hand_enemies_setting);
W_label(gui, window, str_allow_while_using_in_ghost_hand);
W_bool(window, gui, ghost_hand_allow_using_sword_setting);
W_bool(window, gui, ghost_hand_allow_using_tools_setting);
W_bool(window, gui, ghost_hand_allow_using_fists_setting);
W_bool(window, gui, ghost_hand_allow_using_buckets_setting);
W_bool(window, gui, ghost_hand_allow_using_fns_setting);
W_bool(window, gui, ghost_hand_allow_using_cobweb_setting);
W_bool(window, gui, ghost_hand_allow_using_other_setting);
W_label(gui, window, str_conditions_in_ghost_hand);
W_bool(window, gui, ghost_hand_require_mouse_pressed_setting);
}
extern "C" void ghost_hand_register(void *module) {
R_bool(module, str_non_players_in_ghost_hand, ghost_hand_non_players_setting);
R_bool(module, str_friendlies_in_ghost_hand, ghost_hand_friendlies_setting);
R_bool(module, str_bots_in_ghost_hand, ghost_hand_bots_setting);
R_bool(module, str_enemies_in_ghost_hand, ghost_hand_enemies_setting);
R_bool(module, str_allow_using_sword_in_ghost_hand, ghost_hand_allow_using_sword_setting);
R_bool(module, str_allow_using_tools_in_ghost_hand, ghost_hand_allow_using_tools_setting);
R_bool(module, str_allow_using_fists_in_ghost_hand, ghost_hand_allow_using_fists_setting);
R_bool(module, str_allow_using_buckets, ghost_hand_allow_using_buckets_setting);
R_bool(module, str_allow_using_fns, ghost_hand_allow_using_fns_setting);
R_bool(module, str_allow_using_cobweb, ghost_hand_allow_using_cobweb_setting);
R_bool(module, str_allow_using_other_in_ghost_hand, ghost_hand_allow_using_other_setting);
R_bool(module, str_require_mouse_pressed_in_ghost_hand, ghost_hand_require_mouse_pressed_setting);
}
+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);
}
+89
View File
@@ -0,0 +1,89 @@
// Fast Accel - reach full walking speed faster on the ground.
//
// Normally Minecraft needs several ticks to speed up from standing to full speed.
// This module works out the top speed the current keys would eventually reach, and
// moves the player's horizontal speed part of the way there ("acceleration" = how far).
//
// Callback (descriptor slot +0x1a8):
// fast_accel_on_move_flying every movement update, before the game applies the input
#include "slinky/engine.h"
struct Vec3 { double x, y, z; };
// What the engine hands to the callback.
struct MoveHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
float strafe; // +0x10 sideways input
float forward; // +0x14 forwards input
float speed; // +0x18 movement speed for this tick
unsigned char sprint; // +0x1c 1 when the game treats this tick as sprinting
};
// ---- settings ----
extern "C" float fast_accel_acceleration_value; // "acceleration": 0 = no change, 1 = jump straight to top speed
extern "C" unsigned char fast_accel_require_weapon_value; // "require_weapon": only while holding a weapon
extern "C" unsigned char fast_accel_require_not_damaged_value; // "require_not_damaged": not while taking knockback
// ---- game / engine functions ----
FN(unsigned char, is_holding_accepted_weapon, (void *jvm, void *object));
FN(int, java_get_entity_living_base_hurt_time, (void *jvm, void *entity_living_base));
FN(Vec3, java_get_entity_motion_x, (void *jvm, void *entity)); // the player's motion (x, y, z)
FN(void, java_set_entity_motion_x, (void *jvm, void *entity, Vec3 value));
FN(unsigned char, java_get_entity_on_ground, (void *jvm, void *entity));
FN(unsigned char, java_call_entity_is_sprinting, (void *jvm, void *entity));
FN(double, libc_hypot, (double x, double z)); // sqrt(x*x + z*z)
FN(float, libc_hypotf_alt, (float x, float y)); // same, in float
FN(double, lerp_double, (double a, double b, double c)); // a + (b - a) * c
// Minecraft's slow-down per tick on the ground (block slipperiness 0.6 * air drag 0.91).
static const double GROUND_FRICTION = 0.546;
extern "C" void fast_accel_on_move_flying(MoveHook *hook) {
// Not pressing any movement key.
if (hook->forward == 0.0f && hook->strafe == 0.0f)
return;
Ctx *ctx = hook->ctx;
if (fast_accel_require_weapon_value == 1 && !is_holding_accepted_weapon(ctx->jvm, ctx->player))
return;
if (fast_accel_require_not_damaged_value == 1 && java_get_entity_living_base_hurt_time(ctx->jvm, ctx->player) > 0)
return;
// Current horizontal speed.
Vec3 motion = java_get_entity_motion_x(ctx->jvm, ctx->player);
double current_speed = libc_hypot(motion.x, motion.z);
if (current_speed == 0.0)
return;
if (!java_get_entity_on_ground(ctx->jvm, ctx->player))
return;
// How much speed the keys add each tick (same maths as Minecraft's moveFlying):
// the input direction, normalised so diagonals are not faster, times the speed.
float input_length = libc_hypotf_alt(hook->strafe, hook->forward);
float scale = hook->speed / (input_length > 1.0f ? input_length : 1.0f);
float push_strafe = hook->strafe * scale;
float push_forward = scale * hook->forward;
double push_per_tick = libc_hypotf_alt(push_strafe, push_forward);
// Speed after 20 ticks of: speed = speed * friction + push.
double top_speed = 0.0;
top_speed += push_per_tick;
for (int tick = 0; tick < 19; tick++) {
top_speed *= GROUND_FRICTION;
top_speed += push_per_tick;
}
if (hook->sprint == 1 && java_call_entity_is_sprinting(ctx->jvm, ctx->player))
top_speed += 0.2; // sprint-jump bonus
// Already at (or above) top speed: leave it alone.
if (current_speed > top_speed)
return;
// Keep the direction, change only the speed.
double new_speed = lerp_double(current_speed, top_speed, fast_accel_acceleration_value);
motion.x = motion.x / current_speed * new_speed;
motion.z = motion.z / current_speed * new_speed;
java_set_entity_motion_x(ctx->jvm, ctx->player, motion);
}
+30
View File
@@ -0,0 +1,30 @@
// Fast Accel — Speeds up acceleration.
// category: move descriptor: 0x2f27f8 settings block: 0x2f29f0
// functions: gui fast_accel_gui, register fast_accel_register
// implementation: src/logic/move/fast_accel.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_fast_accel); // "Main"
S(str_conditions_in_fast_accel); // "Conditions"
S(str_acceleration); // "acceleration"
S(str_require_not_damaged); // "require_not_damaged"
S(str_require_weapon_in_fast_accel); // "require_weapon"
D(fast_accel_acceleration_setting); // setting num "acceleration"
D(fast_accel_require_weapon_setting); // setting bool "require_weapon"
D(fast_accel_require_not_damaged_setting); // setting bool "require_not_damaged"
extern "C" void fast_accel_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_fast_accel);
W_slider(window, gui, fast_accel_acceleration_setting);
W_label(gui, window, str_conditions_in_fast_accel);
W_bool(window, gui, fast_accel_require_not_damaged_setting);
W_bool(window, gui, fast_accel_require_weapon_setting);
}
extern "C" void fast_accel_register(void *module) {
R_num(module, str_acceleration, fast_accel_acceleration_setting);
R_bool(module, str_require_not_damaged, fast_accel_require_not_damaged_setting);
R_bool(module, str_require_weapon_in_fast_accel, fast_accel_require_weapon_setting);
}
+108
View File
@@ -0,0 +1,108 @@
// Instant Stop - stop dead when you let go of the forward key.
//
// When forward is released on the ground the player normally slides a little.
// For one tick this module presses back (plus left or right if that cancels the slide
// better), then gives the keys back to the player.
//
// Callback (descriptor slot +0x148):
// instant_stop_on_tick every client tick
#include "slinky/engine.h"
struct Vec3 { double x, y, z; };
struct Rot { float yaw, pitch; };
// What the module is doing right now (kept between ticks).
enum InstantStopState {
IDLE = 0, // forward not held
FORWARD_HELD = 1, // forward held last tick, watch for it being released
COUNTER_PRESSED = 2, // counter keys pressed this tick, restore them next tick
};
extern "C" int instant_stop_state;
// ---- game / engine functions ----
FN(unsigned char, is_in_game, (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_back_key, (void *jvm, void *game_settings));
FN(void *, java_get_game_settings_left_key, (void *jvm, void *game_settings));
FN(void *, java_get_game_settings_right_key, (void *jvm, void *game_settings));
FN(unsigned char, is_key_down, (void *jvm, void *k)); // key binding pressed (by the game)
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(unsigned char, java_get_entity_on_ground, (void *jvm, void *entity));
FN(Vec3, java_get_entity_motion_x, (void *jvm, void *entity));
FN(Rot, get_entity_rotation, (void *jvm, void *entity));
FN(float, java_get_entity_living_base_land_movement_factor, (void *jvm, void *entity_living_base));
FN(unsigned char, java_call_entity_is_sprinting, (void *jvm, void *entity));
FN(Vec3, horizontal_motion, (Rot rotation, float fwd, float strafe, float speed)); // motion one tick of input adds
FN(Vec3, vec3_add, (Vec3 a, Vec3 b));
static double horizontal_speed_squared(Vec3 v) { return v.x * v.x + v.z * v.z; }
extern "C" void instant_stop_on_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
int next_state = IDLE;
if (is_in_game(ctx->jvm, ctx->minecraft)) {
void *settings = get_game_settings(ctx->jvm, ctx->minecraft);
void *forward_key = java_get_game_settings_forward_key(ctx->jvm, settings);
void *back_key = java_get_game_settings_back_key(ctx->jvm, settings);
void *left_key = java_get_game_settings_left_key(ctx->jvm, settings);
void *right_key = java_get_game_settings_right_key(ctx->jvm, settings);
int state = instant_stop_state;
if (state == COUNTER_PRESSED) {
// Last tick we pressed counter keys: put them back to what the player is really holding.
java_set_key_binding_pressed(ctx->jvm, back_key, java_get_key_binding_key_code(ctx->jvm, back_key));
java_set_key_binding_pressed(ctx->jvm, left_key, java_get_key_binding_key_code(ctx->jvm, left_key));
java_set_key_binding_pressed(ctx->jvm, right_key, java_get_key_binding_key_code(ctx->jvm, right_key));
} else if (state == FORWARD_HELD) {
// Still holding forward, or in the air: keep waiting (state unchanged).
if (is_key_down(ctx->jvm, forward_key))
return;
if (!java_get_entity_on_ground(ctx->jvm, ctx->player))
return;
// Forward was just released on the ground. Try the possible counter inputs and
// pick the one that leaves the least speed.
Vec3 motion = java_get_entity_motion_x(ctx->jvm, ctx->player);
Rot rotation = get_entity_rotation(ctx->jvm, ctx->player);
float speed = java_get_entity_living_base_land_movement_factor(ctx->jvm, ctx->player);
if (java_call_entity_is_sprinting(ctx->jvm, ctx->player))
speed = (float)((double)speed / 1.3); // remove the sprint bonus
enum { BACK_AND_RIGHT = -1, BACK_ONLY = 0, BACK_AND_LEFT = 1, NOTHING = 999 };
// Doing nothing vs. back + right.
double speed_nothing = horizontal_speed_squared(motion);
double speed_back_right = horizontal_speed_squared(vec3_add(motion, horizontal_motion(rotation, -1.0f, -1.0f, speed)));
int best_choice = speed_nothing > speed_back_right ? BACK_AND_RIGHT : NOTHING;
double best_speed = speed_back_right < speed_nothing ? speed_back_right : speed_nothing;
// Back only.
double speed_back = horizontal_speed_squared(vec3_add(motion, horizontal_motion(rotation, -1.0f, 0.0f, speed)));
if (best_speed > speed_back)
best_choice = BACK_ONLY;
best_speed = speed_back < best_speed ? speed_back : best_speed;
// Back + left.
double speed_back_left = horizontal_speed_squared(vec3_add(motion, horizontal_motion(rotation, -1.0f, 1.0f, speed)));
bool left_is_best = best_speed > speed_back_left;
if (left_is_best)
best_choice = BACK_AND_LEFT;
if (best_choice != NOTHING) {
java_set_key_binding_pressed(ctx->jvm, back_key, 1);
java_set_key_binding_pressed(ctx->jvm, left_key, left_is_best);
java_set_key_binding_pressed(ctx->jvm, right_key, best_choice == BACK_AND_RIGHT);
next_state = COUNTER_PRESSED;
}
} else {
// Idle: start watching once forward is held.
if (!is_key_down(ctx->jvm, forward_key))
return;
next_state = FORWARD_HELD;
}
}
instant_stop_state = next_state;
}
+6
View File
@@ -0,0 +1,6 @@
// Instant Stop — Instantly stops moving when move keys are released.
// category: move descriptor: 0x2f2a80 settings block: none
// implementation: src/logic/move/instant_stop.cpp
// no GUI callback: this module is engine-side and has no settings pane.
#pragma once
#include "slinky/api.h"
+329
View File
@@ -0,0 +1,329 @@
// Inv Walk - keep walking while an inventory or container screen is open.
//
// Minecraft releases all movement keys when a screen opens. Every tick this module
// presses them again to match the keys the player is really holding.
//
// In "silent" mode the server is never told that the inventory is open while you are
// moving: the "open inventory" packet is held back, and inventory clicks are queued
// until the player stands still. Moving while clicking is what anticheats look for.
//
// Callbacks:
// inv_walk_on_toggle module switched on/off: on disable, give the keys back
// inv_walk_on_gui_screen every outgoing packet (silent mode): hold back / queue packets
// inv_walk_on_inventory_tick every tick: drain keyboard input while queued clicks are replayed
// inv_walk_tick_keep_movement every tick: press the movement keys while a screen is open
#include "slinky/engine.h"
#include "slinky/jids.h"
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, 0 = switched off
};
struct GuiHook {
char padding_00[8];
void *a; // +0x08 JVM handle
void *screen_obj; // +0x10 network manager the packet is sent through
void *screen; // +0x18 the packet being sent
unsigned char handled; // +0x20 set to 1 to cancel sending it
};
// ---- settings ----
enum InvWalkMode { MODE_VANILLA = 0, MODE_SILENT = 1 };
extern "C" unsigned inv_walk_mode; // "mode"
enum StopOnClick { STOP_ALWAYS = 0, STOP_SPRINT_ONLY = 1, STOP_NEVER = 2 };
extern "C" unsigned inv_walk_stop_on_click; // "stop_on_click": what to do while clicks are pending
extern "C" float inv_walk_stop_duration_value; // "stop_duration": ticks to keep stopping after a click
extern "C" unsigned inv_walk_stop_non_inv_value; // "stop_non_inv": same as stop_on_click, for chests and other screens
// ---- module state ----
extern "C" char inv_walk_module_descriptor[];
extern "C" void *inv_walk_queued_clicks[0x20]; // click packets waiting to be sent (JNI global refs)
extern "C" unsigned long long inv_walk_queued_count; // how many are queued
extern "C" int inv_walk_tick_counter; // ticks since start
extern "C" int inv_walk_tick_last_screen_activity; // tick of the last inventory click
// What the server has been told about the player's inventory (silent mode).
enum InvWalkPhase {
PHASE_NO_SCREEN = 0, // no screen open
PHASE_OTHER_SCREEN = 1, // a non-inventory screen (chest, furnace, ...) is open
PHASE_SERVER_CLOSED = 2, // inventory open, but the server thinks it is closed
PHASE_SERVER_OPEN = 3, // inventory open, and the server knows
};
extern "C" int inv_walk_phase;
extern "C" unsigned char inv_walk_replaying_queued_clicks; // 1 while queued clicks are being sent
extern "C" unsigned char inv_walk_keys_released_last_tick; // 1 if we forced the movement keys up last tick
// ---- game / engine functions ----
FN(void *, get_current_screen, (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_back_key, (void *jvm, void *game_settings));
FN(void *, java_get_game_settings_left_key, (void *jvm, void *game_settings));
FN(void *, java_get_game_settings_right_key, (void *jvm, void *game_settings));
FN(void *, get_held_item, (void *jvm, void *item)); // here: the jump key
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(unsigned char, java_jni_is_instance_of_gui_inventory, (void *jvm, void *screen));
FN(void *, java_get_entity_player_inventory, (void *jvm, void *entity_player));
FN(void *, java_call_minecraft_get_net_handler, (void *jvm, void *minecraft));
FN(void *, java_get_net_handler_play_client_net_manager, (void *jvm, void *net_handler_play_client));
FN(void *, java_get_inventory_player_item_stack, (void *jvm, void *inv)); // item held on the mouse cursor
FN(void *, java_get_entity_player_inventory_container, (void *jvm, void *entity_player));
FN(void *, java_get_container_player_craft_matrix, (void *jvm, void *container_player));
FN(void *, java_call_iinventory_get_stack_in_slot, (void *jvm, void *inv, int slot));
FN(void *, java_new_c_init, (void *jvm, int x)); // new C0D "close window" packet
FN(void, java_call_entity_set_sprinting, (void *jvm, void *entity, bool on));
FN(unsigned char, release_global_refs, (void *jvm, void *object)); // send the queued clicks; 1 if any were sent
FN(void *, java_jni_is_instance_of_c16_packet_client_status, (void *jvm, void *screen));
FN(int, java_get_c16_packet_client_status_status, (void *jvm, void *c16_packet_client_status));
FN(void *, java_jni_is_instance_of_c0_epacket_click_window, (void *jvm, void *screen));
FN(void *, java_get_c16_enum_state_open_inventory, (void *jvm));
FN(void *, java_new_c16_packet_client_status, (void *jvm, void *object)); // new C16 "open inventory" packet
FN(void, java_call_generic_future_listener, (void *jvm, void *generic_future_listener, void *other_object)); // send a packet
FN(void *, java_jni_is_instance_of_c, (void *jvm, void *screen)); // is it a C0D "close window" packet
FN(unsigned char, keyboard_has_events, (void *jvm));
FN(unsigned char, keyboard_has_next, (void *jvm));
// On disable: give the movement keys back to the player.
extern "C" void inv_walk_on_toggle(EvHook *hook) {
if (hook->on || hook->ev != inv_walk_module_descriptor)
return;
Ctx *ctx = hook->ctx;
release_global_refs(ctx->jvm, ctx->minecraft);
}
// Keep a reference to the packet so it can be sent later (at most 32 are kept).
static void queue_packet(void *jvm, void *packet) {
if (inv_walk_queued_count == 0x20)
return;
JNIEnv *env = ((Jvm *)jvm)->env;
void *ref = (*env)->NewGlobalRef(env, packet);
if (ref) {
unsigned long long index = inv_walk_queued_count;
inv_walk_queued_clicks[index] = ref;
inv_walk_queued_count = index + 1;
}
}
// Every outgoing packet (silent mode only).
extern "C" void inv_walk_on_gui_screen(GuiHook *hook) {
if (inv_walk_mode != MODE_SILENT)
return;
void *packet = hook->screen;
void *status_packet = java_jni_is_instance_of_c16_packet_client_status(hook->a, packet);
void *jvm = hook->a;
// "Open inventory" (status 2): hold it back. The server keeps thinking the inventory is closed.
if (status_packet) {
if (java_get_c16_packet_client_status_status(jvm, status_packet) == 2) {
hook->handled = 1;
inv_walk_phase = PHASE_SERVER_CLOSED;
}
return;
}
// Inventory click.
if (java_jni_is_instance_of_c0_epacket_click_window(jvm, packet)) {
if (inv_walk_phase == PHASE_SERVER_CLOSED) {
// First click: open the inventory on the server now, and queue the click after it.
java_call_generic_future_listener(hook->a, hook->screen_obj,
java_new_c16_packet_client_status(hook->a, java_get_c16_enum_state_open_inventory(hook->a)));
inv_walk_phase = PHASE_SERVER_OPEN;
inv_walk_replaying_queued_clicks = 1;
queue_packet(hook->a, packet);
hook->handled = 1;
return;
}
if (inv_walk_queued_count == 0 && !(inv_walk_replaying_queued_clicks & 1)) {
// Nothing queued: let it through, and remember when it happened.
inv_walk_tick_last_screen_activity = inv_walk_tick_counter;
return;
}
// Other clicks are queued: keep the order and queue this one too.
queue_packet(hook->a, packet);
hook->handled = 1;
return;
}
// "Close window".
if (!java_jni_is_instance_of_c(hook->a, packet))
return;
if (inv_walk_phase == PHASE_SERVER_CLOSED) {
// The server never saw the inventory open, so it does not need to see it close.
hook->handled = 1;
return;
}
if (inv_walk_queued_count) {
// Must arrive after the queued clicks.
queue_packet(hook->a, packet);
hook->handled = 1;
}
}
// Every tick: once the queued clicks have been sent, throw away the keyboard input
// that piled up meanwhile.
extern "C" void inv_walk_on_inventory_tick(Hook *hook) {
if (inv_walk_replaying_queued_clicks)
return;
Ctx *ctx = hook->ctx;
if (!release_global_refs(ctx->jvm, ctx->minecraft))
return;
inv_walk_tick_last_screen_activity = inv_walk_tick_counter;
if (ctx->in_game != 1)
return;
while (keyboard_has_events(ctx->jvm))
;
while (keyboard_has_next(ctx->jvm))
;
}
// True for "stop_duration" ticks after the last inventory click.
static bool clicked_recently() {
return (unsigned)(inv_walk_tick_counter - inv_walk_tick_last_screen_activity) < (unsigned)(long long)inv_walk_stop_duration_value;
}
// Every tick: keep the movement keys pressed while a screen is open.
extern "C" void inv_walk_tick_keep_movement(Hook *hook) {
Ctx *ctx = hook->ctx;
void *screen = get_current_screen(ctx->jvm, ctx->minecraft);
void *settings = get_game_settings(ctx->jvm, ctx->minecraft);
void *back_key = java_get_game_settings_back_key(ctx->jvm, settings);
void *left_key = java_get_game_settings_left_key(ctx->jvm, settings);
void *right_key = java_get_game_settings_right_key(ctx->jvm, settings);
void *forward_key = java_get_game_settings_forward_key(ctx->jvm, settings);
void *jump_key = get_held_item(ctx->jvm, settings);
// Which keys the player is physically holding.
unsigned char back_held = java_get_key_binding_key_code(ctx->jvm, back_key);
unsigned char left_held = java_get_key_binding_key_code(ctx->jvm, left_key);
unsigned char right_held = java_get_key_binding_key_code(ctx->jvm, right_key);
unsigned char forward_held = java_get_key_binding_key_code(ctx->jvm, forward_key);
unsigned char jump_held = java_get_key_binding_key_code(ctx->jvm, jump_key);
unsigned stop_on_click = inv_walk_stop_on_click;
// cancel_sprint: stop sprinting this tick. release_keys: force all movement keys up this tick.
unsigned char cancel_sprint = (inv_walk_mode == MODE_SILENT && stop_on_click != STOP_NEVER) ? inv_walk_queued_count != 0 : 0;
unsigned char release_keys = (stop_on_click == STOP_ALWAYS) & cancel_sprint;
unsigned char update_keys;
inv_walk_tick_counter += 1;
if (!screen) {
// No screen open: if one was open, give the keys back once.
if (inv_walk_phase != PHASE_NO_SCREEN) {
java_set_key_binding_pressed(ctx->jvm, back_key, back_held);
java_set_key_binding_pressed(ctx->jvm, left_key, left_held);
java_set_key_binding_pressed(ctx->jvm, right_key, right_held);
java_set_key_binding_pressed(ctx->jvm, forward_key, forward_held);
java_set_key_binding_pressed(ctx->jvm, jump_key, jump_held);
}
inv_walk_phase = PHASE_NO_SCREEN;
if (!ctx->in_game)
return;
update_keys = 0;
} else {
unsigned char moving = back_held | left_held | right_held | forward_held | jump_held;
unsigned char inventory_busy;
if (!java_jni_is_instance_of_gui_inventory(ctx->jvm, screen)) {
// A chest, furnace or other non-inventory screen.
inv_walk_phase = PHASE_OTHER_SCREEN;
if (inv_walk_mode == MODE_SILENT) {
cancel_sprint |= moving ^ 1;
unsigned char recent = 0;
if (stop_on_click != STOP_NEVER)
recent = clicked_recently();
unsigned char stop = cancel_sprint | recent;
unsigned char stop_non_inv = (inv_walk_stop_non_inv_value != STOP_NEVER) | stop;
cancel_sprint = stop_non_inv;
if (((stop_on_click == STOP_ALWAYS) & stop) || ((inv_walk_stop_non_inv_value == STOP_ALWAYS) & stop_non_inv))
goto release_all;
} else if (release_keys) {
goto release_all;
}
goto press_held_keys;
}
// The player's own inventory.
if (inv_walk_mode != MODE_SILENT) {
inv_walk_phase = PHASE_SERVER_OPEN;
update_keys = 1;
inventory_busy = 0;
} else {
void *inventory = java_get_entity_player_inventory(ctx->jvm, ctx->player);
void *net_manager = java_get_net_handler_play_client_net_manager(ctx->jvm, java_call_minecraft_get_net_handler(ctx->jvm, ctx->minecraft));
// The inventory is "busy" when an item is on the cursor or in the crafting grid.
inventory_busy = 1;
if (!java_get_inventory_player_item_stack(ctx->jvm, inventory)) {
if (inv_walk_phase == PHASE_OTHER_SCREEN) {
inventory_busy = cancel_sprint;
} else {
void *grid = java_get_container_player_craft_matrix(ctx->jvm, java_get_entity_player_inventory_container(ctx->jvm, ctx->player));
if (!java_call_iinventory_get_stack_in_slot(ctx->jvm, grid, 0) && !java_call_iinventory_get_stack_in_slot(ctx->jvm, grid, 1) &&
!java_call_iinventory_get_stack_in_slot(ctx->jvm, grid, 2) && !java_call_iinventory_get_stack_in_slot(ctx->jvm, grid, 3))
inventory_busy = cancel_sprint;
}
}
moving &= inventory_busy ^ 1;
int phase = inv_walk_phase;
if (phase == PHASE_SERVER_CLOSED && !moving) {
// Standing still now: tell the server the inventory is open.
void *open_packet = java_new_c16_packet_client_status(ctx->jvm, java_get_c16_enum_state_open_inventory(ctx->jvm));
java_call_generic_future_listener(ctx->jvm, net_manager, open_packet);
inv_walk_phase = phase = PHASE_SERVER_OPEN;
} else if (moving & (inv_walk_queued_count == 0) & (phase == PHASE_SERVER_OPEN)) {
// Moving again and nothing queued: tell the server the inventory closed.
if (stop_on_click == STOP_NEVER || !clicked_recently()) {
void *close_packet = java_new_c_init(ctx->jvm, 0);
java_call_generic_future_listener(ctx->jvm, net_manager, close_packet);
inv_walk_phase = phase = PHASE_SERVER_CLOSED;
}
}
inventory_busy |= phase == PHASE_SERVER_OPEN;
update_keys = phase != PHASE_NO_SCREEN;
}
cancel_sprint |= (stop_on_click != STOP_NEVER) & inventory_busy;
release_keys = (stop_on_click == STOP_ALWAYS) & cancel_sprint;
}
// Nothing to do unless keys need updating or were forced up last tick.
if (!((update_keys | inv_walk_keys_released_last_tick | release_keys) & 1))
goto finish;
if (!release_keys)
goto press_held_keys;
release_all:
java_set_key_binding_pressed(ctx->jvm, back_key, 0);
java_set_key_binding_pressed(ctx->jvm, left_key, 0);
java_set_key_binding_pressed(ctx->jvm, right_key, 0);
java_set_key_binding_pressed(ctx->jvm, forward_key, 0);
java_set_key_binding_pressed(ctx->jvm, jump_key, 0);
release_keys = 1;
goto finish;
press_held_keys:
java_set_key_binding_pressed(ctx->jvm, back_key, back_held);
java_set_key_binding_pressed(ctx->jvm, left_key, left_held);
java_set_key_binding_pressed(ctx->jvm, right_key, right_held);
java_set_key_binding_pressed(ctx->jvm, forward_key, forward_held);
java_set_key_binding_pressed(ctx->jvm, jump_key, jump_held);
release_keys = 0;
finish:
if (cancel_sprint) {
java_call_entity_set_sprinting(ctx->jvm, ctx->player, false);
void *jvm = ctx->jvm;
java_set_key_binding_pressed(jvm, java_get_game_settings_key_17_or_8(jvm, settings), 0);
}
inv_walk_keys_released_last_tick = release_keys;
inv_walk_replaying_queued_clicks = 0;
}
+48
View File
@@ -0,0 +1,48 @@
// Inv Walk — Allows moving in inventory.
// category: move descriptor: 0x2ef3d0 settings block: 0x2ef5c8
// functions: gui inv_walk_gui, register inv_walk_register, status inv_walk_status
// implementation: src/logic/move/inv_walk.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_inv_walk); // "Main"
S(str_other_containers); // "Other containers"
S(str_mode_in_inv_walk); // "mode"
S(str_stop_on_click); // "stop_on_click"
S(str_stop_duration_in_inv_walk); // "stop_duration"
S(str_stop_non_inv); // "stop_non_inv"
S(str_s_in_inv_walk); // "%s"
D(inv_walk_enum_option_labels_1); // enum option labels (const char *[])
D(inv_walk_mode_setting); // setting enum "mode"
extern "C" unsigned inv_walk_mode; // current value of setting "mode" (+0x30)
D(inv_walk_stop_on_click_setting); // setting enum "stop_on_click"
extern "C" unsigned inv_walk_stop_on_click; // current value of setting "stop_on_click" (+0x30)
D(inv_walk_stop_duration_setting); // setting num "stop_duration"
D(inv_walk_stop_non_inv_setting); // setting enum "stop_non_inv"
extern "C" void inv_walk_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_inv_walk);
W_enumw(window, gui, inv_walk_mode_setting);
if (inv_walk_mode != 0) {
W_enumw(window, gui, inv_walk_stop_on_click_setting);
if (inv_walk_stop_on_click != 2)
W_slider(window, gui, inv_walk_stop_duration_setting);
W_label(gui, window, str_other_containers);
W_enumw(window, gui, inv_walk_stop_non_inv_setting);
} else {
EPILOG_NOP();
}
}
extern "C" void inv_walk_register(void *module) {
R_enum(module, str_mode_in_inv_walk, inv_walk_mode_setting);
R_enum(module, str_stop_on_click, inv_walk_stop_on_click_setting);
R_num(module, str_stop_duration_in_inv_walk, inv_walk_stop_duration_setting);
R_enum(module, str_stop_non_inv, inv_walk_stop_non_inv_setting);
}
extern "C" void inv_walk_status(void *self) {
log_fmt(self, 0x20, str_s_in_inv_walk, ((const char **)inv_walk_enum_option_labels_1)[inv_walk_mode]);
}
+84
View File
@@ -0,0 +1,84 @@
// Keep Sprint - don't lose speed when you hit someone while sprinting.
//
// Hitting a player while sprinting normally slows you down and stops your sprint.
// This module saves your motion just before the hit and puts (part of) it back after.
//
// Callbacks (descriptor slots +0x128 / +0x138 / +0x158):
// keep_sprint_on_attack just before an attack: roll "chance", save the motion
// keep_sprint_on_attack_post just after the attack: restore the saved motion
// keep_sprint_on_player_update next player tick: turn sprint back on
#include "slinky/engine.h"
struct Vec3 { double x, y, z; };
struct PhaseHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
unsigned char phase; // +0x10 1 = the hit actually happens
};
// ---- settings ----
extern "C" float keep_sprint_chance_value; // "chance": how often it works
extern "C" float keep_sprint_motion_mult; // "motion_mult": how much of the saved speed to give back
extern "C" unsigned char keep_sprint_require_on_ground_value; // "require_on_ground"
extern "C" unsigned char keep_sprint_allow_reduce_value; // "allow_reduce": let the hit slow you when you have a target
// ---- module state ----
extern "C" Vec3 keep_sprint_saved_motion; // motion saved before the hit
extern "C" unsigned char keep_sprint_roll_succeeded; // the "chance" roll succeeded for this hit
extern "C" unsigned char keep_sprint_motion_pending_re_apply; // motion restored, sprint needs turning back on
// ---- game / engine functions ----
FN(unsigned char, java_call_entity_is_sprinting, (void *jvm, void *entity));
FN(unsigned char, random_chance, (float chance));
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(unsigned char, java_get_entity_on_ground, (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
FN(void, java_call_entity_set_sprinting, (void *jvm, void *entity, bool on));
// Before the hit: save the motion if we are sprinting and the roll succeeds.
extern "C" void keep_sprint_on_attack(PhaseHook *hook) {
if (hook->phase != 1)
return;
Ctx *ctx = hook->ctx;
unsigned char success = 0;
if (ctx->in_game == 1 && java_call_entity_is_sprinting(ctx->jvm, ctx->player) && random_chance(keep_sprint_chance_value)) {
keep_sprint_saved_motion = java_get_entity_motion_x(ctx->jvm, ctx->player);
success = 1;
}
keep_sprint_roll_succeeded = success;
}
// After the hit: put the saved motion back.
extern "C" void keep_sprint_on_attack_post(PhaseHook *hook) {
if (keep_sprint_roll_succeeded != 1 || hook->phase != 1)
return;
Ctx *ctx = hook->ctx;
if (!ctx->player)
return;
if (keep_sprint_require_on_ground_value == 1 && !java_get_entity_on_ground(ctx->jvm, ctx->player))
return;
// Only if the attack really landed this tick.
if (java_get_entity_ticks_existed(ctx->jvm, ctx->player) != java_get_entity_living_base_last_attacker_time(ctx->jvm, ctx->player))
return;
if (keep_sprint_allow_reduce_value == 1 && ((CombatTarget *)ctx->target)->valid)
return;
double mult = keep_sprint_motion_mult;
keep_sprint_saved_motion.x *= mult;
keep_sprint_saved_motion.z *= mult;
java_set_entity_motion_x(ctx->jvm, ctx->player, keep_sprint_saved_motion);
keep_sprint_motion_pending_re_apply = 1;
}
// Next player tick: the hit turned sprint off, turn it back on.
extern "C" void keep_sprint_on_player_update(Hook *hook) {
if (keep_sprint_motion_pending_re_apply != 1)
return;
keep_sprint_motion_pending_re_apply = 0;
Ctx *ctx = hook->ctx;
if (ctx->player)
java_call_entity_set_sprinting(ctx->jvm, ctx->player, true);
}
+42
View File
@@ -0,0 +1,42 @@
// Keep Sprint — Keeps your sprint speed when attacking players.
// category: move descriptor: 0x2ef700 settings block: 0x2ef8f8
// functions: gui keep_sprint_gui, register keep_sprint_register, status keep_sprint_status
// implementation: src/logic/move/keep_sprint.cpp
#pragma once
#include "slinky/api.h"
extern "C" float factor_100_in_keep_sprint; // 100
S(str_0f_in_keep_sprint); // "%.0f%%"
S(str_main_in_keep_sprint); // "Main"
S(str_conditions_in_keep_sprint); // "Conditions"
S(str_chance_in_keep_sprint); // "chance"
S(str_motion_mult); // "motion_mult"
S(str_allow_reduce); // "allow_reduce"
S(str_require_on_ground); // "require_on_ground"
D(keep_sprint_chance_setting); // setting num "chance"
D(keep_sprint_motion_mult_setting); // setting num "motion_mult"
extern "C" float keep_sprint_motion_mult; // current value of setting "motion_mult" (+0x30)
D(keep_sprint_require_on_ground_setting); // setting bool "require_on_ground"
D(keep_sprint_allow_reduce_setting); // setting bool "allow_reduce"
extern "C" void keep_sprint_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_keep_sprint);
W_slider(window, gui, keep_sprint_chance_setting);
W_slider(window, gui, keep_sprint_motion_mult_setting);
W_bool(window, gui, keep_sprint_allow_reduce_setting);
W_label(gui, window, str_conditions_in_keep_sprint);
W_bool(window, gui, keep_sprint_require_on_ground_setting);
}
extern "C" void keep_sprint_register(void *module) {
R_num(module, str_chance_in_keep_sprint, keep_sprint_chance_setting);
R_num(module, str_motion_mult, keep_sprint_motion_mult_setting);
R_bool(module, str_allow_reduce, keep_sprint_allow_reduce_setting);
R_bool(module, str_require_on_ground, keep_sprint_require_on_ground_setting);
}
extern "C" void keep_sprint_status(void *self) {
log_fmt(self, 0x20, str_0f_in_keep_sprint, (double)(keep_sprint_motion_mult * factor_100_in_keep_sprint));
}
+16
View File
@@ -0,0 +1,16 @@
// No Jump Delay - jump again straight away when holding space.
//
// Minecraft waits 10 ticks between jumps while the jump key is held. This module
// resets that wait to 0 every tick.
//
// Callback (descriptor slot +0x158):
// no_jump_delay_on_tick every player tick
#include "slinky/engine.h"
FN(void, java_set_entity_living_base_jump_ticks, (void *jvm, void *entity_living_base, int value));
extern "C" void no_jump_delay_on_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
if (ctx->in_game == 1)
java_set_entity_living_base_jump_ticks(ctx->jvm, ctx->player, 0);
}
+6
View File
@@ -0,0 +1,6 @@
// No Jump Delay — Removes cooldown when holding jump key.
// category: move descriptor: 0x2ed630 settings block: none
// implementation: src/logic/move/no_jump_delay.cpp
// no GUI callback: this module is engine-side and has no settings pane.
#pragma once
#include "slinky/api.h"
+66
View File
@@ -0,0 +1,66 @@
// No Slow - walk faster while using an item (bow, sword block, eating/drinking).
//
// Minecraft multiplies your movement input by 0.2 while you use an item. This module
// replaces that 0.2 with the multiplier from the settings for that kind of item.
//
// Callback (descriptor slot +0x198):
// no_slow_on_movement_input every movement update, after the game has slowed the input
#include "slinky/engine.h"
// ---- settings ----
extern "C" float no_slow_mult_bow_value; // "mult_bow"
extern "C" float no_slow_mult_sword_value; // "mult_sword"
extern "C" float no_slow_mult_consumables_value; // "mult_consumables": food, potions, everything else
struct SlowState {
char padding_00[8];
Ctx *ctx; // +0x08 game context
float move[2]; // +0x10 strafe and forward input (already multiplied by 0.2)
};
// ---- game / engine functions ----
FN(bool, java_call_entity_player_is_using_item, (void *jvm, void *entity_player));
FN(void *, item_held_hotbar_slot, (void *jvm, void *slot));
FN(int, java_call_static_item_get_id_from_item, (void *jvm, void *item));
// Item ids (Minecraft 1.8).
enum {
ITEM_BOW = 261,
ITEM_IRON_SWORD = 267,
ITEM_WOODEN_SWORD = 268,
ITEM_STONE_SWORD = 272,
ITEM_DIAMOND_SWORD = 276,
ITEM_GOLDEN_SWORD = 283,
};
extern "C" void no_slow_on_movement_input(SlowState *s) {
Ctx *ctx = s->ctx;
if (!java_call_entity_player_is_using_item(ctx->jvm, ctx->player))
return;
void *item = item_held_hotbar_slot(ctx->jvm, ctx->player);
if (!item)
return;
// Pick the multiplier for this item.
const float *mult;
switch (java_call_static_item_get_id_from_item(ctx->jvm, item)) {
case ITEM_BOW:
mult = &no_slow_mult_bow_value;
break;
case ITEM_IRON_SWORD:
case ITEM_WOODEN_SWORD:
case ITEM_STONE_SWORD:
case ITEM_DIAMOND_SWORD:
case ITEM_GOLDEN_SWORD:
mult = &no_slow_mult_sword_value;
break;
default:
mult = &no_slow_mult_consumables_value;
break;
}
// Undo the game's 0.2 and apply ours instead.
double factor = *mult / 0.2;
s->move[0] = (float)(s->move[0] * factor);
s->move[1] = (float)(s->move[1] * factor);
}
+28
View File
@@ -0,0 +1,28 @@
// No Slow — Removes slowdown while using items.
// category: move descriptor: 0x2f2c90 settings block: 0x2f2e88
// functions: gui no_slow_gui, register no_slow_register
// implementation: src/logic/move/no_slow.cpp
#pragma once
#include "slinky/api.h"
S(str_retained_speed_in_no_slow); // "Retained speed"
S(str_mult_sword); // "mult_sword"
S(str_mult_bow); // "mult_bow"
S(str_mult_consumables); // "mult_consumables"
D(no_slow_mult_bow_setting); // setting num "mult_bow"
D(no_slow_mult_sword_setting); // setting num "mult_sword"
D(no_slow_mult_consumables_setting); // setting num "mult_consumables"
extern "C" void no_slow_gui(void *gui, void *window) {
W_label(gui, window, str_retained_speed_in_no_slow);
W_slider(window, gui, no_slow_mult_sword_setting);
W_slider(window, gui, no_slow_mult_bow_setting);
W_slider(window, gui, no_slow_mult_consumables_setting);
}
extern "C" void no_slow_register(void *module) {
R_num(module, str_mult_sword, no_slow_mult_sword_setting);
R_num(module, str_mult_bow, no_slow_mult_bow_setting);
R_num(module, str_mult_consumables, no_slow_mult_consumables_setting);
}
+68
View File
@@ -0,0 +1,68 @@
// Null Move - pressing a movement key overrides the opposite one.
//
// Normally holding A and D together cancels out and you stand still. With this module the
// key you pressed last wins: when you press a key while its opposite is held, the opposite
// key is released. When you let go again, the opposite key is restored if you still hold it.
//
// Callback (descriptor slot +0x148):
// null_move_on_tick every client tick
#include "slinky/engine.h"
// One value per key (forward, left, back, right): the tick the key was pressed, or 0 when not held.
extern "C" int null_move_key_state_0; // forward
extern "C" int null_move_key_state_1; // left
extern "C" int null_move_key_state_2; // back
extern "C" int null_move_key_state_3; // right
// ---- game / engine functions ----
FN(unsigned char, is_in_game, (void *jvm, void *object));
FN(int, java_get_entity_ticks_existed, (void *jvm, void *entity));
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_left_key, (void *jvm, void *game_settings));
FN(void *, java_get_game_settings_back_key, (void *jvm, void *game_settings));
FN(void *, java_get_game_settings_right_key, (void *jvm, void *game_settings));
FN(unsigned char, is_key_down, (void *jvm, void *k)); // key binding pressed (by the game)
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));
// Handle one key and its opposite.
static void handle_key(Ctx *ctx, int *state, void *key, void *opposite_key, int now) {
int pressed_at = *state;
bool key_down = is_key_down(ctx->jvm, key);
bool opposite_down = is_key_down(ctx->jvm, opposite_key);
if (key_down) {
// Just pressed while the opposite is held: release the opposite.
bool just_pressed = pressed_at == 0;
if (just_pressed && opposite_down)
java_set_key_binding_pressed(ctx->jvm, opposite_key, 0);
*state = now;
} else if (pressed_at == 0) {
*state = 0;
} else {
// Just let go: give the opposite key back if it is still physically held.
unsigned char opposite_held = java_get_key_binding_key_code(ctx->jvm, opposite_key);
*state = 0;
if (opposite_held)
java_set_key_binding_pressed(ctx->jvm, opposite_key, 1);
}
}
extern "C" void null_move_on_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
if (!is_in_game(ctx->jvm, ctx->minecraft))
return;
int now = java_get_entity_ticks_existed(ctx->jvm, ctx->player);
void *settings = get_game_settings(ctx->jvm, ctx->minecraft);
void *forward_key = java_get_game_settings_forward_key(ctx->jvm, settings);
void *left_key = java_get_game_settings_left_key(ctx->jvm, settings);
void *back_key = java_get_game_settings_back_key(ctx->jvm, settings);
void *right_key = java_get_game_settings_right_key(ctx->jvm, settings);
handle_key(ctx, &null_move_key_state_0, forward_key, back_key, now);
handle_key(ctx, &null_move_key_state_1, left_key, right_key, now);
handle_key(ctx, &null_move_key_state_2, back_key, forward_key, now);
handle_key(ctx, &null_move_key_state_3, right_key, left_key, now);
}
+6
View File
@@ -0,0 +1,6 @@
// Null Move — Makes it easier to switch move direction instantly.
// category: move descriptor: 0x2f46a0 settings block: none
// implementation: src/logic/move/null_move.cpp
// no GUI callback: this module is engine-side and has no settings pane.
#pragma once
#include "slinky/api.h"
+65
View File
@@ -0,0 +1,65 @@
// Safe Walk - don't fall off block edges (like sneaking, without sneaking).
//
// The edge check itself is done by the engine while safe_walk_safe_walk_active is 1.
// This callback decides whether it should be active, and can slow you down while it is.
//
// Callback (descriptor slot +0x48):
// safe_walk_on_tick every player tick
#include "slinky/engine.h"
// ---- settings ----
extern "C" float safe_walk_motion_multiplier_value; // "motion_multiplier": speed while active (1 = normal)
extern "C" unsigned char safe_walk_require_looking_down_value; // "require_looking_down": only when pitch >= 65
extern "C" unsigned char safe_walk_require_not_forward_value; // "require_not_forward": not while walking forwards
extern "C" unsigned char safe_walk_require_holding_blocks_value; // "require_holding_blocks"
// 1 = the engine stops the player at block edges.
extern "C" unsigned char safe_walk_safe_walk_active;
struct Vec3 { double x, y, z; };
struct Rot { float yaw, pitch; };
struct WalkState { char padding_00[8]; Ctx *ctx; }; // +0x08 game context
// ---- game / engine functions ----
FN(Rot, get_entity_rotation, (void *jvm, void *entity));
FN(float, java_get_entity_living_base_move_forward, (void *jvm, void *entity_living_base));
FN(void *, item_held_hotbar_slot, (void *jvm, void *slot));
FN(unsigned char, block_entity_id, (void *jvm, void *item)); // 1 if the item is a block
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));
extern "C" void safe_walk_on_tick(WalkState *s) {
Ctx *ctx = s->ctx;
if (ctx->in_game != 1)
return;
// Turn off when a requirement is not met.
if (safe_walk_require_looking_down_value == 1 && get_entity_rotation(ctx->jvm, ctx->player).pitch < 65.0f) {
safe_walk_safe_walk_active = 0;
return;
}
if (safe_walk_require_not_forward_value == 1 && java_get_entity_living_base_move_forward(ctx->jvm, ctx->player) > 0.0f) {
safe_walk_safe_walk_active = 0;
return;
}
if (safe_walk_require_holding_blocks_value == 1) {
void *item = item_held_hotbar_slot(ctx->jvm, ctx->player);
if (!block_entity_id(ctx->jvm, item)) {
safe_walk_safe_walk_active = 0;
return;
}
}
safe_walk_safe_walk_active = 1;
// Optionally slow down while on the ground.
if (!java_get_entity_on_ground(ctx->jvm, ctx->player))
return;
if (safe_walk_motion_multiplier_value == 1.0f)
return;
Vec3 motion = java_get_entity_motion_x(ctx->jvm, ctx->player);
double mult = safe_walk_motion_multiplier_value;
motion.x *= mult;
motion.z *= mult;
java_set_entity_motion_x(ctx->jvm, ctx->player, motion);
}
+34
View File
@@ -0,0 +1,34 @@
// Safe Walk — Prevents you from walking off ledges.
// category: move descriptor: 0x2f2030 settings block: 0x2f2228
// functions: gui safe_walk_gui, register safe_walk_register
// implementation: src/logic/move/safe_walk.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_safe_walk); // "Main"
S(str_conditions_in_safe_walk); // "Conditions"
S(str_motion_multiplier); // "motion_multiplier"
S(str_require_holding_blocks_in_safe_walk); // "require_holding_blocks"
S(str_require_looking_down_in_safe_walk); // "require_looking_down"
S(str_require_not_forward_in_safe_walk); // "require_not_forward"
D(safe_walk_motion_multiplier_setting); // setting num "motion_multiplier"
D(safe_walk_require_looking_down_setting); // setting bool "require_looking_down"
D(safe_walk_require_not_forward_setting); // setting bool "require_not_forward"
D(safe_walk_require_holding_blocks_setting); // setting bool "require_holding_blocks"
extern "C" void safe_walk_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_safe_walk);
W_slider(window, gui, safe_walk_motion_multiplier_setting);
W_label(gui, window, str_conditions_in_safe_walk);
W_bool(window, gui, safe_walk_require_holding_blocks_setting);
W_bool(window, gui, safe_walk_require_looking_down_setting);
W_bool(window, gui, safe_walk_require_not_forward_setting);
}
extern "C" void safe_walk_register(void *module) {
R_num(module, str_motion_multiplier, safe_walk_motion_multiplier_setting);
R_bool(module, str_require_holding_blocks_in_safe_walk, safe_walk_require_holding_blocks_setting);
R_bool(module, str_require_looking_down_in_safe_walk, safe_walk_require_looking_down_setting);
R_bool(module, str_require_not_forward_in_safe_walk, safe_walk_require_not_forward_setting);
}
+98
View File
@@ -0,0 +1,98 @@
// Sprint - sprints for you, and keeps you sprinting in the directions the settings allow.
//
// The module has two callbacks (descriptor slots +0x158 and +0x198):
// sprint_on_player_update every player tick: holds the sprint key down for you
// sprint_on_movement_input every movement update: boosts speed when sprinting sideways/backwards/while eating
#include "slinky/engine.h"
// ---- settings (defined in sprint.h, values live in the original data section) ----
extern "C" unsigned char sprint_while_in_gui_value; // "while_in_gui": keep sprinting while a menu is open
extern "C" unsigned char sprint_while_using_item_value; // "while_using_item": sprint while eating/blocking/drawing a bow
extern "C" unsigned char sprint_while_backwards_value; // "while_backwards": sprint when walking backwards
extern "C" unsigned char sprint_while_sideways_value; // "while_sideways": sprint when only strafing
// 1 while this module is the reason the sprint key is held down.
extern "C" unsigned char sprint_sprint_currently_forced;
// ---- what the engine hands to each callback ----
struct SprintState {
char padding_00[8];
Ctx *ctx; // +0x08 game context (JVM, Minecraft instance, local player)
};
struct MoveState {
char padding_00[8];
Ctx *ctx; // +0x08 game context
float strafe; // +0x10 sideways input (-1 right .. +1 left, 0 = none)
float forward; // +0x14 forwards input (-1 back .. +1 forward, 0 = none)
float speed; // +0x18 movement speed for this tick, can be changed
};
// ---- game functions used (implemented in the engine, they call into Minecraft over JNI) ----
FN(void *, get_current_screen, (void *jvm, void *object)); // open menu, or null
FN(void *, get_game_settings, (void *jvm, void *object)); // Minecraft's GameSettings
FN(void *, java_get_game_settings_key_17_or_8, (void *jvm, void *game_settings)); // the sprint key binding
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_call_entity_set_sprinting, (void *jvm, void *entity, bool on));
FN(unsigned char, java_call_entity_player_is_using_item, (void *jvm, void *entity_player));
// Every player tick: hold the sprint key down whenever sprinting is allowed.
extern "C" void sprint_on_player_update(SprintState *s) {
Ctx *ctx = s->ctx;
// Sprinting is allowed when no menu is open, or when "while_in_gui" is on.
bool menu_open = get_current_screen(ctx->jvm, ctx->minecraft) != nullptr;
bool allowed = !menu_open || (sprint_while_in_gui_value & 1);
// Press (or release) the sprint key to match.
void *game_settings = get_game_settings(ctx->jvm, ctx->minecraft);
void *sprint_key = java_get_game_settings_key_17_or_8(ctx->jvm, game_settings);
java_set_key_binding_pressed(ctx->jvm, sprint_key, allowed);
void *player = ctx->player;
if (player) {
if (!allowed) {
// A menu just opened: stop the sprint we were forcing.
// (The "forced" flag stays set until sprinting is allowed again.)
if (sprint_sprint_currently_forced == 1)
java_call_entity_set_sprinting(ctx->jvm, player, false);
return;
}
// Already sprinting: set it again so the game does not drop it.
if (java_call_entity_is_sprinting(ctx->jvm, player))
java_call_entity_set_sprinting(ctx->jvm, ctx->player, true);
}
sprint_sprint_currently_forced = allowed;
}
// Every movement update: Minecraft only sprints forwards and not while using an item.
// For the extra directions the settings allow, sprint anyway and add the sprint speed boost (x1.3).
extern "C" void sprint_on_movement_input(MoveState *s) {
Ctx *ctx = s->ctx;
// Standing still: nothing to do.
if (s->forward == 0.0f && s->strafe == 0.0f)
return;
bool using_item = java_call_entity_player_is_using_item(ctx->jvm, ctx->player);
if (using_item && !sprint_while_using_item_value)
return;
if (s->forward < 0.0f) {
// Walking backwards.
if (!sprint_while_backwards_value)
return;
} else if (s->forward == 0.0f) {
// Only strafing (we know strafe != 0 here).
if (!sprint_while_sideways_value)
return;
} else {
// Walking forwards: the game already sprints by itself, unless an item is being used.
if (!using_item)
return;
}
s->speed = (float)(s->speed * 1.3);
java_call_entity_set_sprinting(ctx->jvm, ctx->player, true);
}
+32
View File
@@ -0,0 +1,32 @@
// Sprint — Automatically sprints for you.
// category: move descriptor: 0x2ed840 settings block: 0x2eda38
// functions: gui sprint_gui, register sprint_register
// implementation: src/logic/move/sprint.cpp
#pragma once
#include "slinky/api.h"
S(str_allow_while); // "Allow while"
S(str_while_using_item); // "while_using_item"
S(str_while_backwards); // "while_backwards"
S(str_while_sideways); // "while_sideways"
S(str_while_in_gui); // "while_in_gui"
D(sprint_while_in_gui_setting); // setting bool "while_in_gui"
D(sprint_while_using_item_setting); // setting bool "while_using_item"
D(sprint_while_backwards_setting); // setting bool "while_backwards"
D(sprint_while_sideways_setting); // setting bool "while_sideways"
extern "C" void sprint_gui(void *gui, void *window) {
W_label(gui, window, str_allow_while);
W_bool(window, gui, sprint_while_using_item_setting);
W_bool(window, gui, sprint_while_backwards_setting);
W_bool(window, gui, sprint_while_sideways_setting);
W_bool(window, gui, sprint_while_in_gui_setting);
}
extern "C" void sprint_register(void *module) {
R_bool(module, str_while_using_item, sprint_while_using_item_setting);
R_bool(module, str_while_backwards, sprint_while_backwards_setting);
R_bool(module, str_while_sideways, sprint_while_sideways_setting);
R_bool(module, str_while_in_gui, sprint_while_in_gui_setting);
}
+107
View File
@@ -0,0 +1,107 @@
// Strafe - change direction instantly, even in the air.
//
// Minecraft keeps your momentum: in the air you can barely steer. This module turns your
// horizontal motion towards the direction your keys point, keeping the same speed.
// "strength_*" sets how far it turns (0 = not at all, 1 = fully) on the ground, in the air,
// and on the tick you jump.
//
// Callbacks (descriptor slots +0x198 / +0x1a8):
// strafe_on_movement_input every movement update: remember whether we were sprinting
// strafe_on_move_flying every movement update: steer the motion
#include "slinky/engine.h"
struct Vec3 { double x, y, z; };
struct Rot { float yaw, pitch; };
struct MoveHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
float strafe; // +0x10 sideways input (+ = left, - = right)
float forward; // +0x14 forwards input (+ = forward, - = back)
float speed; // +0x18
unsigned char sprint; // +0x1c 1 on the tick the player jumps
};
// ---- settings ----
extern "C" float strafe_max_hurt_time_value; // "max_hurt_time": don't steer while taking knockback
extern "C" float strafe_strength_air_value; // "strength_air"
extern "C" float strafe_strength_jump_value; // "strength_jump"
extern "C" float strafe_strength_ground_value; // "strength_ground"
extern "C" unsigned char strafe_require_weapon_value; // "require_weapon"
// Sprinting state at the last movement input (despite the name).
extern "C" unsigned char strafe_was_on_ground_last_tick;
// ---- game / engine functions ----
FN(unsigned char, java_call_entity_is_sprinting, (void *jvm, void *entity));
FN(unsigned char, is_holding_accepted_weapon, (void *jvm, void *object));
FN(int, java_get_entity_living_base_hurt_time, (void *jvm, void *entity_living_base));
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(double, libc_hypot, (double x, double z));
FN(Rot, get_entity_rotation, (void *jvm, void *entity));
FN(float, libc_sinf, (float v));
FN(float, libc_cosf, (float v));
FN(double, lerp_double, (double a, double b, double c)); // a + (b - a) * c
extern "C" void strafe_on_movement_input(Hook *hook) {
Ctx *ctx = hook->ctx;
strafe_was_on_ground_last_tick = java_call_entity_is_sprinting(ctx->jvm, ctx->player);
}
extern "C" void strafe_on_move_flying(MoveHook *hook) {
if (hook->forward == 0.0f && hook->strafe == 0.0f)
return;
Ctx *ctx = hook->ctx;
if (strafe_require_weapon_value == 1 && !is_holding_accepted_weapon(ctx->jvm, ctx->player))
return;
if ((float)java_get_entity_living_base_hurt_time(ctx->jvm, ctx->player) > strafe_max_hurt_time_value)
return;
// Pick the strength for this tick. Jumping without sprint gets the sprint-jump boost added.
float strength;
bool add_jump_boost = false;
if (java_get_entity_on_ground(ctx->jvm, ctx->player)) {
if (hook->sprint == 1) {
add_jump_boost = strafe_was_on_ground_last_tick ^ 1;
strength = strafe_strength_jump_value;
} else {
strength = strafe_strength_ground_value;
}
} else {
strength = strafe_strength_air_value;
}
if (strength == 0.0f)
return;
// Keep the current speed.
Vec3 motion = java_get_entity_motion_x(ctx->jvm, ctx->player);
double speed = libc_hypot(motion.x, motion.z);
if (add_jump_boost)
speed += 0.2;
// Direction the keys point, in degrees: the camera yaw, turned for the keys held.
float yaw = get_entity_rotation(ctx->jvm, ctx->player).yaw;
double side = 0.0; // -1 = right, +1 = left
if (0.0f > hook->strafe)
side = -1.0;
if (hook->strafe > 0.0f)
side = 1.0;
double direction = yaw;
if (hook->forward > 0.0f) {
side *= -45.0; // diagonal forward
} else if (0.0f > hook->forward) {
direction += 180.0; // walking backwards
side *= 45.0; // diagonal backward
} else {
side *= -90.0; // straight sideways
}
direction += side;
float radians = (float)(direction * 3.141592653589793 / 180.0);
// Turn the motion towards that direction.
motion.x = lerp_double(motion.x, (double)-libc_sinf(radians) * speed, strength);
motion.z = lerp_double(motion.z, (double)libc_cosf(radians) * speed, strength);
java_set_entity_motion_x(ctx->jvm, ctx->player, motion);
}
+38
View File
@@ -0,0 +1,38 @@
// Strafe — Allows faster strafing.
// category: move descriptor: 0x2f24e8 settings block: 0x2f26e0
// functions: gui strafe_gui, register strafe_register
// implementation: src/logic/move/strafe.cpp
#pragma once
#include "slinky/api.h"
S(str_strength); // "Strength"
S(str_conditions_in_strafe); // "Conditions"
S(str_strength_jump); // "strength_jump"
S(str_strength_ground); // "strength_ground"
S(str_strength_air); // "strength_air"
S(str_max_hurt_time_in_strafe); // "max_hurt_time"
S(str_require_weapon_in_strafe); // "require_weapon"
D(strafe_max_hurt_time_setting); // setting num "max_hurt_time"
D(strafe_strength_air_setting); // setting num "strength_air"
D(strafe_strength_jump_setting); // setting num "strength_jump"
D(strafe_strength_ground_setting); // setting num "strength_ground"
D(strafe_require_weapon_setting); // setting bool "require_weapon"
extern "C" void strafe_gui(void *gui, void *window) {
W_label(gui, window, str_strength);
W_slider(window, gui, strafe_strength_jump_setting);
W_slider(window, gui, strafe_strength_ground_setting);
W_slider(window, gui, strafe_strength_air_setting);
W_label(gui, window, str_conditions_in_strafe);
W_slider(window, gui, strafe_max_hurt_time_setting);
W_bool(window, gui, strafe_require_weapon_setting);
}
extern "C" void strafe_register(void *module) {
R_num(module, str_strength_jump, strafe_strength_jump_setting);
R_num(module, str_strength_ground, strafe_strength_ground_setting);
R_num(module, str_strength_air, strafe_strength_air_setting);
R_num(module, str_max_hurt_time_in_strafe, strafe_max_hurt_time_setting);
R_bool(module, str_require_weapon_in_strafe, strafe_require_weapon_setting);
}
+215
View File
@@ -0,0 +1,215 @@
// Anti Bot - spot fake players (server-side bots) so the combat modules ignore them.
//
// Every tick each player is checked; a player that looks like a bot is tagged (entity flag 2).
// A player counts as a bot when (each check has its own setting):
// "always_stationary": it has never moved (less than 1 block in total)
// "invalid_uuid": it has a version-2 UUID (1: only while stationary, 2: always)
// "sleeping": it is in a bed
// "always_invis": it was invisible and without armour since it appeared
// "min_age": it has existed for fewer ticks than this
// "invalid_username": its name has no letter, digit or "_"
// What we learn about each player is kept in a table by UUID (cleared on a new world).
//
// Callbacks (descriptor slots +0x48 / +0x98):
// anti_bot_on_tick every tick: check every player
// anti_bot_on_toggle module switched off: clear the table, untag everyone
#include "slinky/engine.h"
#include "slinky/jids.h"
struct Vec3 { double x, y, z; };
struct Key { unsigned long long hi, lo, padding_10, padding_18; }; // UUID
// What we know about one player.
struct Info {
unsigned long long hi, lo; // UUID
double moved; // +0x10 total horizontal movement (squared distances summed)
unsigned char aged; // +0x18 has passed "min_age"
unsigned char visible; // +0x19 has been seen not "always invisible"
unsigned char name_ok; // +0x1a its name has a valid character
};
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" float anti_bot_min_age_value; // "min_age" (ticks)
extern "C" unsigned char anti_bot_always_stationary_value; // "always_stationary"
extern "C" int anti_bot_invalid_uuid_value; // "invalid_uuid": 0 off, 1 while stationary, 2 always
extern "C" unsigned char anti_bot_sleeping_value; // "sleeping"
extern "C" unsigned char anti_bot_always_invis_value; // "always_invis"
extern "C" unsigned char anti_bot_invalid_username_value; // "invalid_username"
// ---- module state ----
extern "C" char anti_bot_module_descriptor[];
extern "C" int anti_bot_world_id_table_belongs; // which world the table is for
extern "C" void *anti_bot_info_table[1]; // the table's entries
extern "C" char anti_bot_table_meta[]; // the table's capacity and count
// ---- game / engine functions ----
FN(int, java_call_object_hash_code, (void *jvm, void *world));
FN(void, libc_free, (void *ptr));
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(void *, java_get_entity_uuid, (void *jvm, void *entity));
FN(unsigned long long, java_jni_call_long_method_uuid_get_most_significant_bits, (void *jvm, void *uuid));
FN(unsigned long long, java_jni_call_long_method_uuid_get_least_significant_bits, (void *jvm, void *uuid));
FN(Info *, vector_find_insert, (void *table, int keysz, void *meta, void *key, void *hash)); // find, or add a zeroed entry
FN(void, compare_u128, ());
FN(Vec3, java_get_entity_prev_pos_x, (void *jvm, void *entity));
FN(Vec3, java_get_entity_pos_x, (void *jvm, void *entity));
FN(unsigned char, java_get_entity_player_sleeping, (void *jvm, void *entity_player));
FN(int, java_get_entity_ticks_existed, (void *jvm, void *entity));
FN(unsigned char, java_call_entity_player_is_invisible_to_player, (void *jvm, void *entity_player, void *viewer));
FN(void *, java_get_entity_player_inventory, (void *jvm, void *entity_player));
FN(void *, java_call_iinventory_get_stack_in_slot, (void *jvm, void *inv, int slot));
FN(void *, java_call_item_stack_get_item, (void *jvm, void *stack));
FN(int, java_call_static_item_get_id_from_item, (void *jvm, void *item));
FN(void *, java_call_entity_get_command_sender_name, (void *jvm, void *entity));
FN(void, entity_flags_set, (void *jvm, void *entity, int tag));
FN(void, entity_flags_clear, (void *jvm, void *entity, int tag));
enum { FLAG_BOT = 2 };
enum { SLOT_BOOTS = 36, SLOT_LEGGINGS = 37, SLOT_CHESTPLATE = 38, SLOT_HELMET = 39 };
static bool is_ourselves(Ctx *ctx, void *entity) {
JNIEnv *env = ((Jvm *)ctx->jvm)->env;
return (*env)->IsSameObject(env, ctx->player, entity);
}
static void clear_table() {
libc_free(anti_bot_info_table[0]);
anti_bot_info_table[0] = nullptr;
__builtin_memset(anti_bot_table_meta, 0, 8); // capacity + count
}
// Is there an item in this inventory slot?
static bool has_item(void *jvm, void *inventory, int slot) {
void *stack = java_call_iinventory_get_stack_in_slot(jvm, inventory, slot);
if (!stack)
return false;
void *item = java_call_item_stack_get_item(jvm, stack);
return item && java_call_static_item_get_id_from_item(jvm, item) != 0;
}
// Does the name have at least one letter, digit or "_"? (Colour codes "§x" are skipped.)
static bool name_has_valid_character(Ctx *ctx, void *player) {
JNIEnv *env = ((Jvm *)ctx->jvm)->env;
void *name = java_call_entity_get_command_sender_name(ctx->jvm, player);
int length = (*env)->GetStringLength(env, name);
unsigned short *chars = (unsigned short *)(*env)->GetStringCritical(env, name, nullptr);
bool valid = false;
for (int j = 0; j < length; j++) {
unsigned c = chars[j];
if (c == 0xa7) { // "§": skip the colour code character too
j++;
continue;
}
bool letter = (unsigned short)((c & 0xffdf) - 'A') < 26; // A-Z or a-z
if (letter || c == '_' || (unsigned short)(c - '0') <= 9) {
valid = true;
break;
}
}
(*env)->ReleaseStringCritical(env, name, chars);
return valid;
}
// The checks for one player. Updates what we know about it in `info`.
static bool looks_like_bot(Ctx *ctx, void *player, Info *info) {
// Movement since last tick, added up.
Vec3 previous = java_get_entity_prev_pos_x(ctx->jvm, player);
Vec3 current = java_get_entity_pos_x(ctx->jvm, player);
double dx = previous.x - current.x, dz = previous.z - current.z;
double moved = dx * dx + dz * dz + info->moved;
info->moved = moved;
bool stationary = 1.0 > moved;
if (anti_bot_always_stationary_value == 1 && stationary)
return true;
if (anti_bot_invalid_uuid_value != 0) {
bool version_2_uuid = ((unsigned)info->hi & 0xf000) == 0x2000;
if (version_2_uuid && ((anti_bot_invalid_uuid_value == 2) | stationary))
return true;
}
if (anti_bot_sleeping_value == 1 && java_get_entity_player_sleeping(ctx->jvm, player))
return true;
int age = java_get_entity_ticks_existed(ctx->jvm, player);
if (anti_bot_always_invis_value == 1 && !info->visible) {
// Invisible and no armour at all.
void *jvm = ctx->jvm;
if (java_call_entity_player_is_invisible_to_player(jvm, player, ctx->player)) {
void *inventory = java_get_entity_player_inventory(jvm, player);
if (!has_item(jvm, inventory, SLOT_BOOTS) && !has_item(jvm, inventory, SLOT_LEGGINGS) &&
!has_item(jvm, inventory, SLOT_CHESTPLATE) && !has_item(jvm, inventory, SLOT_HELMET))
return true;
}
if (age >= 21)
info->visible = 1; // passed the check for a second: stop checking
}
float min_age = anti_bot_min_age_value;
if (min_age > 0.0f && !info->aged) {
if (min_age > (float)age)
return true;
info->aged = 1;
}
if (anti_bot_invalid_username_value == 1 && !info->name_ok) {
if (name_has_valid_character(ctx, player))
info->name_ok = 1;
if (!info->name_ok)
return true;
}
return false;
}
extern "C" void anti_bot_on_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
// A different world: start a new table.
int world_id = ctx->world ? java_call_object_hash_code(ctx->jvm, ctx->world) : 0;
if (world_id != anti_bot_world_id_table_belongs) {
clear_table();
anti_bot_world_id_table_belongs = world_id;
}
if (!ctx->world)
return;
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);
if (is_ourselves(ctx, other))
continue;
void *uuid = java_get_entity_uuid(ctx->jvm, other);
alignas(16) Key key;
key.hi = java_jni_call_long_method_uuid_get_most_significant_bits(ctx->jvm, uuid);
key.lo = java_jni_call_long_method_uuid_get_least_significant_bits(ctx->jvm, uuid);
key.padding_10 = key.padding_18 = 0;
Info *info = vector_find_insert(anti_bot_info_table, 0x20, anti_bot_table_meta, &key, (void *)compare_u128);
if (looks_like_bot(ctx, other, info))
entity_flags_set(ctx->jvm, other, FLAG_BOT);
else
entity_flags_clear(ctx->jvm, other, FLAG_BOT);
}
}
// On disable: clear the table and untag everyone.
extern "C" void anti_bot_on_toggle(EvHook *hook) {
if (hook->ev != anti_bot_module_descriptor || hook->on)
return;
clear_table();
Ctx *ctx = hook->ctx;
if (!ctx->world)
return;
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);
if (!is_ourselves(ctx, other))
entity_flags_clear(ctx->jvm, other, FLAG_BOT);
}
}
+40
View File
@@ -0,0 +1,40 @@
// Anti Bot — Ignores NPCs for specific modules.
// category: utility descriptor: 0x2eacd0 settings block: 0x2eaec8
// functions: gui anti_bot_gui, register anti_bot_register
// implementation: src/logic/utility/anti_bot.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_anti_bot); // "Main"
S(str_invalid_uuid_in_anti_bot); // "invalid_uuid"
S(str_invalid_username_in_anti_bot); // "invalid_username"
S(str_always_invis); // "always_invis"
S(str_always_stationary_in_anti_bot); // "always_stationary"
S(str_sleeping_in_anti_bot); // "sleeping"
S(str_min_age); // "min_age"
D(anti_bot_min_age_setting); // setting num "min_age"
D(anti_bot_always_stationary_setting); // setting bool "always_stationary"
D(anti_bot_invalid_uuid_setting); // setting enum "invalid_uuid"
D(anti_bot_sleeping_setting); // setting bool "sleeping"
D(anti_bot_always_invis_setting); // setting bool "always_invis"
D(anti_bot_invalid_username_setting); // setting bool "invalid_username"
extern "C" void anti_bot_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_anti_bot);
W_enumw(window, gui, anti_bot_invalid_uuid_setting);
W_bool(window, gui, anti_bot_invalid_username_setting);
W_bool(window, gui, anti_bot_always_invis_setting);
W_bool(window, gui, anti_bot_always_stationary_setting);
W_bool(window, gui, anti_bot_sleeping_setting);
W_slider(window, gui, anti_bot_min_age_setting);
}
extern "C" void anti_bot_register(void *module) {
R_enum(module, str_invalid_uuid_in_anti_bot, anti_bot_invalid_uuid_setting);
R_bool(module, str_invalid_username_in_anti_bot, anti_bot_invalid_username_setting);
R_bool(module, str_always_invis, anti_bot_always_invis_setting);
R_bool(module, str_always_stationary_in_anti_bot, anti_bot_always_stationary_setting);
R_bool(module, str_sleeping_in_anti_bot, anti_bot_sleeping_setting);
R_num(module, str_min_age, anti_bot_min_age_setting);
}
+241
View File
@@ -0,0 +1,241 @@
// Auto Pot - throw splash healing potions.
//
// When switched on (usually by its keybind when you are low), the module works out how many
// potions you need (each heals 8 health), switches to a splash potion in the hotbar, throws
// it, repeats, switches back and switches itself off. With "double_splash" all of them are
// thrown at once; otherwise pressing the keybind again throws another one.
//
// Callbacks (descriptor slots +0x48 / +0x88 / +0x98):
// auto_pot_on_tick every tick: the next step
// auto_pot_on_input keybind pressed again: one more potion
// auto_pot_on_toggle switched on: how many potions to throw
// auto_pot_asm_r_pins helper: a random delay between steps
#include "slinky/engine.h"
struct Range { float lo, hi; };
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 InHook {
char padding_00[8];
void *mod; // +0x08 module whose keybind was pressed
unsigned char use; // +0x10 set to 1: we used the key press
};
// ---- settings ----
extern "C" unsigned char auto_pot_use_non_health_value; // "use_non_health": throw other splash potions too
extern "C" float auto_pot_delay_value; // "delay": ticks between steps
extern "C" unsigned char auto_pot_prevent_waste_value; // "prevent_waste": not when at full health
extern "C" unsigned char auto_pot_double_splash_value; // "double_splash": throw all needed at once
// ---- module state ----
extern "C" char auto_pot_module_descriptor[];
enum PotStage {
STAGE_FIND_POTION = 0,
STAGE_SWITCH = 1,
STAGE_THROW = 2,
STAGE_NEXT = 3, // next potion, or switch back
STAGE_DONE = 4, // switch off
};
extern "C" int auto_pot_stage;
extern "C" int auto_pot_potion_slot;
extern "C" int auto_pot_original_slot;
extern "C" unsigned char auto_pot_keep_original_slot; // throwing another one: remember the slot from the first
extern "C" float auto_pot_step_delay; // ticks until the next step
extern "C" int auto_pot_potions_left_throw;
extern "C" int auto_pot_extra_throws; // extra potions the keybind may still ask for
extern "C" char auto_pot_rng_states[], auto_pot_initial_stage[]; // random walk states
// ---- game / engine functions ----
FN(void *, java_get_entity_player_inventory, (void *jvm, void *entity_player));
FN(void *, java_call_iinventory_get_stack_in_slot, (void *jvm, void *object, int slot));
FN(void *, java_call_item_stack_get_item, (void *jvm, void *item_stack));
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(int, java_get_inventory_player_current_item, (void *jvm, void *inventory_player));
FN(void, java_set_inventory_player_current_item, (void *jvm, void *inventory_player, int slot));
FN(unsigned char, claim_release_hotbar_module, (void *timer)); // ask for control of the hotbar
FN(void, release_owner, (void *timer)); // give control of the hotbar back
FN(unsigned char, java_call_entity_player_is_using_item, (void *jvm, void *entity_player));
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_increment_key_binding_press_time, (void *jvm, void *key_binding)); // = one right click
FN(void, queue_module_toggle, (void *module_manager, void *module, int enabled));
FN(float, java_call_entity_living_base_get_health, (void *jvm, void *entity_living_base));
FN(float, java_call_entity_living_base_get_max_health, (void *jvm, void *entity_living_base));
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)); // random yes/no
FN(float, random_rotation, (Range r)); // random value in the range
extern "C" float auto_pot_asm_r_pins();
enum { ITEM_POTION = 373, POTION_SPLASH_FLAG = 0x4000, POTION_EFFECT_HEALING = 5 };
// The first hotbar slot with a splash potion we may throw, or 9 when there is none.
static int find_potion(Ctx *ctx, void *inventory) {
int slot = 0;
for (; slot < 9; slot++) {
void *stack = java_call_iinventory_get_stack_in_slot(ctx->jvm, inventory, slot);
if (!stack)
continue;
void *item = java_call_item_stack_get_item(ctx->jvm, stack);
if (!item || java_call_static_item_get_id_from_item(ctx->jvm, item) != ITEM_POTION)
continue;
unsigned damage = java_get_item_stack_metadata(ctx->jvm, stack);
if (!(damage & POTION_SPLASH_FLAG))
continue;
if ((damage & 0xf) != POTION_EFFECT_HEALING && !auto_pot_use_non_health_value)
continue;
break;
}
return slot;
}
// Give up: switch off.
static void stop(Ctx *ctx) {
auto_pot_stage = STAGE_DONE;
queue_module_toggle(ctx->module_manager, auto_pot_module_descriptor, 0);
}
extern "C" void auto_pot_on_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
// Up to 4 steps per tick, while there is no delay.
for (int step = 0; step < 4; step++) {
float delay = auto_pot_step_delay;
if (delay > 0.0f) {
auto_pot_step_delay = delay + -1.0f;
break;
}
if (!ctx->in_game) {
auto_pot_keep_original_slot = 0;
stop(ctx);
return;
}
switch (auto_pot_stage) {
case STAGE_FIND_POTION: {
void *inventory = java_get_entity_player_inventory(ctx->jvm, ctx->player);
int slot = find_potion(ctx, inventory);
if (slot == 9) {
// None (left): switch back if this was another throw, else switch off.
auto_pot_potions_left_throw = 0;
int next = STAGE_DONE - auto_pot_keep_original_slot;
auto_pot_stage = next;
auto_pot_keep_original_slot = 0;
if (next == STAGE_DONE)
queue_module_toggle(ctx->module_manager, auto_pot_module_descriptor, 0);
return;
}
auto_pot_potion_slot = slot;
int original;
if (auto_pot_keep_original_slot == 1) {
original = auto_pot_original_slot;
} else {
original = java_get_inventory_player_current_item(ctx->jvm, inventory);
auto_pot_original_slot = original;
slot = auto_pot_potion_slot;
}
auto_pot_keep_original_slot = 0;
// Already holding it: throw straight away, else switch first.
auto_pot_stage = (slot == original) + STAGE_SWITCH;
continue;
}
case STAGE_SWITCH:
if (!claim_release_hotbar_module(auto_pot_module_descriptor)) {
stop(ctx);
return;
}
java_set_inventory_player_current_item(ctx->jvm, java_get_entity_player_inventory(ctx->jvm, ctx->player), auto_pot_potion_slot);
auto_pot_stage = STAGE_THROW;
auto_pot_step_delay = auto_pot_asm_r_pins() + auto_pot_step_delay;
continue;
case STAGE_THROW:
if (java_call_entity_player_is_using_item(ctx->jvm, ctx->player))
goto finished; // wait for the next tick
java_increment_key_binding_press_time(ctx->jvm, java_get_game_settings_use_item_key(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft)));
auto_pot_potions_left_throw += -1;
auto_pot_stage = STAGE_NEXT;
if (auto_pot_potion_slot != auto_pot_original_slot)
auto_pot_step_delay = (auto_pot_asm_r_pins() + 1.0f) + auto_pot_step_delay;
continue;
case STAGE_NEXT:
if (auto_pot_potions_left_throw > 0) {
auto_pot_keep_original_slot = 1;
auto_pot_stage = STAGE_FIND_POTION;
} else {
java_set_inventory_player_current_item(ctx->jvm, java_get_entity_player_inventory(ctx->jvm, ctx->player), auto_pot_original_slot);
auto_pot_stage = STAGE_DONE;
}
continue;
case STAGE_DONE:
release_owner(auto_pot_module_descriptor);
goto finished;
default:
__builtin_unreachable();
}
}
finished:
if (auto_pot_stage == STAGE_DONE)
queue_module_toggle(ctx->module_manager, auto_pot_module_descriptor, 0);
}
// The keybind was pressed again: throw one more (if allowed).
extern "C" void auto_pot_on_input(InHook *hook) {
if (hook->mod != auto_pot_module_descriptor || auto_pot_stage == STAGE_DONE)
return;
int extra = auto_pot_extra_throws;
if (extra <= 0)
return;
hook->use = 1;
auto_pot_potions_left_throw += 1;
auto_pot_extra_throws = extra - 1;
}
// Switched on: how many potions? Switched off: reset.
extern "C" void auto_pot_on_toggle(EvHook *hook) {
if (hook->ev != auto_pot_module_descriptor)
return;
if (hook->on != 1) {
auto_pot_stage = STAGE_FIND_POTION;
auto_pot_potions_left_throw = 0;
return;
}
Ctx *ctx = hook->ctx;
if (ctx->in_game != 1)
return;
// One potion heals 8 health.
float health = java_call_entity_living_base_get_health(ctx->jvm, ctx->player);
int needed = (int)(((double)(java_call_entity_living_base_get_max_health(ctx->jvm, ctx->player) - health) + 0.5) * 0.125);
if (needed == 0) {
needed = 1;
if (auto_pot_prevent_waste_value == 1) {
auto_pot_stage = STAGE_DONE; // nearly full health: don't waste one
return;
}
}
if (auto_pot_double_splash_value == 1) {
auto_pot_potions_left_throw = needed;
auto_pot_extra_throws = 0;
} else {
auto_pot_potions_left_throw = 1;
auto_pot_extra_throws = auto_pot_prevent_waste_value ? needed - 1 : 5;
}
}
// "delay" minus up to 0.5 ticks at random (not below 0); now and then (1-3%) 0.5-1 tick more.
extern "C" float auto_pot_asm_r_pins() {
float delay = 0.0f;
float shorter = auto_pot_delay_value - walk_update(auto_pot_rng_states, rot_make_floats(0.0f, 0.5f), 5.0);
delay = delay > shorter ? delay : shorter;
if (walk_should_change(auto_pot_initial_stage, rot_make_floats(0.01f, 0.03f), 30.0))
delay += random_rotation(rot_make_floats(0.5f, 1.0f));
return delay;
}
+32
View File
@@ -0,0 +1,32 @@
// Auto Pot — Uses healing potions for you.
// category: utility descriptor: 0x2ef128 settings block: 0x2ef320
// functions: gui auto_pot_gui, register auto_pot_register
// implementation: src/logic/utility/auto_pot.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_auto_pot); // "Main"
S(str_delay_in_auto_pot); // "delay"
S(str_prevent_waste); // "prevent_waste"
S(str_double_splash); // "double_splash"
S(str_use_non_health); // "use_non_health"
D(auto_pot_use_non_health_setting); // setting bool "use_non_health"
D(auto_pot_delay_setting); // setting num "delay"
D(auto_pot_prevent_waste_setting); // setting bool "prevent_waste"
D(auto_pot_double_splash_setting); // setting bool "double_splash"
extern "C" void auto_pot_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_auto_pot);
W_slider(window, gui, auto_pot_delay_setting);
W_bool(window, gui, auto_pot_prevent_waste_setting);
W_bool(window, gui, auto_pot_double_splash_setting);
W_bool(window, gui, auto_pot_use_non_health_setting);
}
extern "C" void auto_pot_register(void *module) {
R_num(module, str_delay_in_auto_pot, auto_pot_delay_setting);
R_bool(module, str_prevent_waste, auto_pot_prevent_waste_setting);
R_bool(module, str_double_splash, auto_pot_double_splash_setting);
R_bool(module, str_use_non_health, auto_pot_use_non_health_setting);
}
+372
View File
@@ -0,0 +1,372 @@
// Auto Rod - throw your fishing rod (or snowballs / eggs) at your target, then switch back.
//
// When switched on (by its keybind), the module switches to the rod, throws it, waits until
// the bobber should have reached the target, reels it in by switching back to your weapon,
// and switches itself off. With "allow_throwables" snowballs and eggs are preferred.
// Delays are randomised with "randomize_delays".
//
// Callbacks:
// auto_rod_on_input keybind pressed while running: cancel
// auto_rod_on_toggle switched on: start over
// auto_rod_on_attack left click with the rod: don't swing twice
// auto_rod_randomised_throw_delay helper: delay between steps
// auto_rod_randomised_rod_pull helper: delay between throws (repeat mode)
// auto_rod_ticks_bobber_needs helper: ticks until the bobber reaches the target
// auto_rod_on_tick every tick: the next step
#include "slinky/engine.h"
struct Vec3 { double x, y, z; };
struct AABB { Vec3 lo, hi; };
struct Range { float lo, hi; };
struct InHook {
char padding_00[8];
void *mod; // +0x08 module whose keybind was pressed
unsigned char use; // +0x10 set to 1: we used the key press
};
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 AttackHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
unsigned char phase; // +0x10 0 = before the click
unsigned char cancel; // +0x11 set to 1 to cancel it
};
// ---- settings ----
extern "C" float auto_rod_throw_delay; // "delay": ticks between steps
extern "C" unsigned char auto_rod_randomise; // "randomize_delays"
extern "C" float auto_rod_pull_speed; // "retract_speed": throws per second (repeat mode)
extern "C" float auto_rod_projectile_speed; // "throw_speed": blocks per tick
extern "C" unsigned char auto_rod_abort_when_aiming_at_entity; // "require_not_mouse_over"
extern "C" unsigned char auto_rod_prefer_snowballs_eggs; // "allow_throwables"
extern "C" unsigned char auto_rod_switch_best_weapon_afterwards; // "always_switch_to_weapon"
// Engine flag: 1 = keep repeating until the keybind is pressed again.
extern "C" unsigned char timer_range_min_dist_setting_field_0x58;
// ---- module state ----
extern "C" char auto_rod_module_descriptor[];
enum RodStage {
STAGE_START = 0, // find the rod and take the hotbar
STAGE_SWITCH = 1, // switch to it
STAGE_THROW = 2,
STAGE_WAIT = 3, // wait for the bobber to reach the target
STAGE_REEL = 4, // (same slot to go back to) switch away for a moment to reel in
STAGE_SWITCH_BACK = 5,
STAGE_DONE = 6,
STAGE_CANCEL = 7,
};
extern "C" int auto_rod_stage;
extern "C" unsigned char auto_rod_input_taken; // the keybind was pressed (repeat mode): stop
extern "C" unsigned char auto_rod_rod_swing_seen;
extern "C" int auto_rod_slot_switch_back; // slot to go back to, -1 = none
extern "C" int auto_rod_rod_slot;
extern "C" float auto_rod_step_delay; // ticks until the next step
extern "C" int auto_rod_wait_ticks;
extern "C" unsigned char auto_rod_using_fishing_rod; // 1 = rod, 0 = snowball / egg
extern "C" char auto_rod_rng_states[], auto_rod_rng_states_second[], auto_rod_rng_states_third[], auto_rod_rng_states_fourth[]; // random walk states
// ---- game / engine functions ----
FN(void *, java_get_entity_player_inventory, (void *jvm, void *entity_player));
FN(void, java_set_inventory_player_current_item, (void *jvm, void *inventory_player, int slot));
FN(int, java_get_inventory_player_current_item, (void *jvm, void *inventory_player));
FN(void, release_owner, (void *timer)); // give control of the hotbar back
FN(unsigned char, claim_release_hotbar_module, (void *timer)); // ask for control of the hotbar
FN(void, queue_module_toggle, (void *module_manager, void *module, int enabled));
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_call_iinventory_get_stack_in_slot, (void *jvm, void *object, int slot));
FN(void *, java_call_item_stack_get_item, (void *jvm, void *stack));
FN(int, weapons_find_first_weapon_slot_entry, (Ctx *ctx, void *slot)); // see weapons.cpp
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_press_time, (void *jvm, void *key_binding, int n)); // 1 = one right click
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)); // server position
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(AABB, aabb_make, (Vec3 lo, Vec3 hi));
FN(Vec3, aabb_clamp_point, (AABB box, Vec3 p)); // closest point of the box
FN(double, vec3_distance, (Vec3 a, Vec3 b));
FN(float, libc_ceilf, (float 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(unsigned char, walk_should_change, (void *state, Range r, double p)); // random yes/no
FN(float, random_rotation, (Range r)); // random value in the range
FN(void *, item_held_hotbar_slot, (void *jvm, void *slot));
FN(int, java_call_static_item_get_id_from_item, (void *jvm, void *item));
enum { ITEM_SNOWBALL = 332, ITEM_EGG = 344, ITEM_FISHING_ROD = 346 };
static bool repeat_mode() { return timer_range_min_dist_setting_field_0x58 == 1; }
extern "C" void auto_rod_on_input(InHook *hook) {
if (auto_rod_input_taken != 0 || hook->mod != auto_rod_module_descriptor)
return;
if (repeat_mode()) {
auto_rod_input_taken = 1; // stop repeating
} else {
int stage = auto_rod_stage;
if (stage == STAGE_DONE)
return;
if (stage == STAGE_WAIT)
auto_rod_stage = STAGE_CANCEL;
}
hook->use = 1;
}
extern "C" void auto_rod_on_toggle(EvHook *hook) {
if (hook->ev != auto_rod_module_descriptor || hook->on != 1)
return;
auto_rod_stage = STAGE_START;
}
// Clicking with the rod: let the first swing through, cancel the others.
extern "C" void auto_rod_on_attack(AttackHook *hook) {
if (hook->phase != 0)
return;
Ctx *ctx = hook->ctx;
void *held = item_held_hotbar_slot(ctx->jvm, ctx->player);
if (held && java_call_static_item_get_id_from_item(ctx->jvm, held) == ITEM_FISHING_ROD) {
if (auto_rod_rod_swing_seen)
hook->cancel = 1;
else
auto_rod_rod_swing_seen = 1;
}
}
// "delay", randomly up to 0.5 ticks shorter, and now and then (1-3%) 0.5-1 tick longer.
extern "C" float auto_rod_randomised_throw_delay() {
float delay = auto_rod_throw_delay;
if (auto_rod_randomise == 1) {
float shorter = delay - walk_update(auto_rod_rng_states, rot_make_floats(0.0f, 0.5f), 5.0);
delay = 0.0f;
delay = delay > shorter ? delay : shorter;
if (walk_should_change(auto_rod_rng_states_second, rot_make_floats(0.01f, 0.03f), 30.0))
delay += random_rotation(rot_make_floats(0.5f, 1.0f));
}
return delay;
}
// Ticks between throws: 20 / "retract_speed", randomly up to 2x longer, now and then 1-2 ticks more.
extern "C" float auto_rod_randomised_rod_pull() {
float speed = auto_rod_pull_speed;
if (!auto_rod_randomise)
return 20.0f / speed;
float factor = walk_update(auto_rod_rng_states_third, rot_make_floats(0.5f, 1.0f), 1.0);
float ticks = 20.0f / (speed * factor);
if (walk_should_change(auto_rod_rng_states_fourth, rot_make_floats(0.01f, 0.03f), 30.0))
ticks += random_rotation(rot_make_floats(1.0f, 2.0f));
return ticks;
}
// Ticks the bobber needs to reach the target's hitbox (10 blocks without a target).
extern "C" int auto_rod_ticks_bobber_needs(Ctx *ctx) {
void *target = ((CombatTarget *)ctx->target)->ent;
float ticks;
if (!target) {
ticks = 10.0f / auto_rod_projectile_speed;
} else {
Vec3 eye = java_get_entity_pos_x(ctx->jvm, ctx->player);
if (!java_variant(ctx->jvm))
eye = vec3_add_eye_height(eye);
// The target's hitbox: 0.6 wide, 1.8 tall.
Vec3 pos = java_get_entity_other_player_mp_other_player_mpx(ctx->jvm, target);
Vec3 lo = vec3_sub(pos, vec3_make(0.3, 0.0, 0.3));
Vec3 hi = vec3_add(pos, vec3_make(0.3, 1.8, 0.3));
Vec3 nearest = aabb_clamp_point(aabb_make(lo, hi), eye);
ticks = (float)(vec3_distance(eye, nearest) / (double)auto_rod_projectile_speed);
}
return (int)libc_ceilf(ticks);
}
static void restore_slot(Ctx *ctx) {
if (auto_rod_slot_switch_back != -1) {
java_set_inventory_player_current_item(ctx->jvm, java_get_entity_player_inventory(ctx->jvm, ctx->player), auto_rod_slot_switch_back);
auto_rod_slot_switch_back = -1;
}
}
// The hotbar slot with the rod (or, with "allow_throwables", a snowball / egg), or -1.
// Sets auto_rod_using_fishing_rod.
static int find_throwable(Ctx *ctx, void *inventory) {
auto_rod_using_fishing_rod = 0;
int found = -1;
for (int i = 0; i < 9; i++) {
void *stack = java_call_iinventory_get_stack_in_slot(ctx->jvm, inventory, i);
if (!stack)
continue;
void *item = java_call_item_stack_get_item(ctx->jvm, stack);
if (!item)
continue;
int item_id = java_call_static_item_get_id_from_item(ctx->jvm, item);
if (item_id == ITEM_SNOWBALL || item_id == ITEM_EGG) {
if (auto_rod_prefer_snowballs_eggs == 1) {
auto_rod_using_fishing_rod = 0;
return i;
}
continue;
}
if (item_id != ITEM_FISHING_ROD)
continue;
auto_rod_using_fishing_rod = 1;
found = i;
if (!auto_rod_prefer_snowballs_eggs)
return i; // (with throwables allowed, keep looking for one; the rod is the fallback)
}
return found;
}
// Done: in repeat mode start again, otherwise switch off.
static void finished(Ctx *ctx) {
if (repeat_mode()) {
auto_rod_stage = STAGE_START;
return;
}
queue_module_toggle(ctx->module_manager, auto_rod_module_descriptor, 0);
}
// Throw: right click, then wait for the bobber (rod), the next throw (repeat mode), or switch back.
static void throw_item(Ctx *ctx) {
java_set_key_binding_press_time(ctx->jvm, java_get_game_settings_use_item_key(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft)), 1);
if (auto_rod_using_fishing_rod == 1) {
auto_rod_stage = STAGE_WAIT;
auto_rod_wait_ticks = auto_rod_ticks_bobber_needs(ctx);
auto_rod_step_delay += auto_rod_randomised_throw_delay();
} else if (repeat_mode()) {
auto_rod_step_delay += auto_rod_randomised_rod_pull();
} else {
auto_rod_stage = STAGE_SWITCH_BACK;
auto_rod_step_delay += auto_rod_randomised_throw_delay();
}
}
extern "C" void auto_rod_on_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
if (ctx->in_game != 1)
return;
if (auto_rod_input_taken) {
restore_slot(ctx);
release_owner(auto_rod_module_descriptor);
queue_module_toggle(ctx->module_manager, auto_rod_module_descriptor, 0);
auto_rod_input_taken = 0;
return;
}
// Up to 3 steps per tick, while there is no delay.
for (int step = 0; step < 3; step++) {
if (auto_rod_abort_when_aiming_at_entity == 1) {
// Aiming at an entity: just hit it instead.
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) {
restore_slot(ctx);
release_owner(auto_rod_module_descriptor);
auto_rod_stage = STAGE_DONE;
finished(ctx);
return;
}
}
if (auto_rod_stage == STAGE_CANCEL) {
restore_slot(ctx);
release_owner(auto_rod_module_descriptor);
auto_rod_stage = STAGE_START;
return;
}
if (auto_rod_wait_ticks)
auto_rod_wait_ticks -= 1;
float delay = auto_rod_step_delay;
if (delay > 0.0f) {
delay += -1.0f;
auto_rod_step_delay = delay;
if (delay > 0.0f)
break;
}
void *inventory = java_get_entity_player_inventory(ctx->jvm, ctx->player);
int current_slot = java_get_inventory_player_current_item(ctx->jvm, inventory);
unsigned stage = auto_rod_stage;
int rod_slot = auto_rod_rod_slot;
if (stage >= STAGE_THROW && current_slot != rod_slot) {
// The player switched slot: stop.
release_owner(auto_rod_module_descriptor);
auto_rod_stage = STAGE_DONE;
finished(ctx);
return;
}
switch (stage) {
case STAGE_START: {
int found = find_throwable(ctx, inventory);
if (found == -1 || !claim_release_hotbar_module(auto_rod_module_descriptor)) {
auto_rod_stage = STAGE_DONE;
finished(ctx);
return;
}
auto_rod_rod_slot = found;
auto_rod_slot_switch_back = current_slot;
if (auto_rod_switch_best_weapon_afterwards == 1) {
int weapon_slot = weapons_find_first_weapon_slot_entry(ctx, inventory);
if (weapon_slot != -1)
auto_rod_slot_switch_back = weapon_slot;
current_slot = auto_rod_slot_switch_back;
}
// Already holding it: throw straight away, else switch first.
auto_rod_stage = (auto_rod_rod_slot == current_slot) + STAGE_SWITCH;
continue;
}
case STAGE_THROW: {
int found = find_throwable(ctx, inventory);
if (found == -1) {
auto_rod_stage = STAGE_SWITCH_BACK; // nothing left to throw
return;
}
if (found == current_slot) {
throw_item(ctx);
goto check_done;
}
auto_rod_rod_slot = found;
auto_rod_stage = STAGE_SWITCH;
auto_rod_step_delay += auto_rod_randomised_throw_delay();
continue;
}
case STAGE_SWITCH:
java_set_inventory_player_current_item(ctx->jvm, inventory, rod_slot);
auto_rod_stage = STAGE_THROW;
auto_rod_rod_swing_seen = 0;
auto_rod_step_delay += auto_rod_randomised_throw_delay();
continue;
case STAGE_WAIT:
if (auto_rod_wait_ticks != 0)
goto check_done;
// Reel in: switching slot does that. Going back to the same slot needs a detour.
auto_rod_stage = auto_rod_slot_switch_back == rod_slot ? STAGE_REEL : STAGE_SWITCH_BACK;
auto_rod_step_delay += auto_rod_randomised_throw_delay();
continue;
case STAGE_REEL:
java_set_inventory_player_current_item(ctx->jvm, inventory, (auto_rod_slot_switch_back + 1) % 9);
auto_rod_stage = STAGE_SWITCH_BACK;
return;
case STAGE_SWITCH_BACK:
auto_rod_stage = STAGE_DONE;
restore_slot(ctx);
release_owner(auto_rod_module_descriptor);
auto_rod_step_delay += auto_rod_randomised_throw_delay();
goto check_done;
default:
goto check_done;
}
}
check_done:
if (auto_rod_stage == STAGE_DONE)
finished(ctx);
}
+47
View File
@@ -0,0 +1,47 @@
// Auto Rod — Throws your fishing rod for you.
// category: utility descriptor: 0x2f3520 settings block: 0x2f3718
// functions: gui auto_rod_gui, register auto_rod_register
// implementation: src/logic/utility/auto_rod.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_auto_rod); // "Main"
S(str_throwables); // "Throwables"
S(str_retract_speed_in_auto_rod); // "retract_speed"
S(str_delay_in_auto_rod); // "delay"
S(str_randomize_delays_in_auto_rod); // "randomize_delays"
S(str_always_switch_to_weapon); // "always_switch_to_weapon"
S(str_allow_throwables); // "allow_throwables"
S(str_throw_speed_in_auto_rod); // "throw_speed"
S(str_require_not_mouse_over); // "require_not_mouse_over"
D(auto_rod_require_not_mouse_over_setting); // setting bool "require_not_mouse_over"
D(auto_rod_allow_throwables_setting); // setting bool "allow_throwables"
D(auto_rod_always_switch_to_weapon_setting); // setting bool "always_switch_to_weapon"
D(auto_rod_delay_setting); // setting num "delay"
D(auto_rod_randomize_delays_setting); // setting bool "randomize_delays"
D(auto_rod_retract_speed_setting); // setting num "retract_speed"
D(auto_rod_throw_speed_setting); // setting num "throw_speed"
extern "C" void auto_rod_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_auto_rod);
W_slider(window, gui, auto_rod_retract_speed_setting);
W_slider(window, gui, auto_rod_delay_setting);
W_bool(window, gui, auto_rod_randomize_delays_setting);
W_bool(window, gui, auto_rod_always_switch_to_weapon_setting);
W_label(gui, window, str_throwables);
W_bool(window, gui, auto_rod_allow_throwables_setting);
W_slider(window, gui, auto_rod_throw_speed_setting);
W_label(gui, window, str_main_in_auto_rod);
W_bool(window, gui, auto_rod_require_not_mouse_over_setting);
}
extern "C" void auto_rod_register(void *module) {
R_num(module, str_retract_speed_in_auto_rod, auto_rod_retract_speed_setting);
R_num(module, str_delay_in_auto_rod, auto_rod_delay_setting);
R_bool(module, str_randomize_delays_in_auto_rod, auto_rod_randomize_delays_setting);
R_bool(module, str_always_switch_to_weapon, auto_rod_always_switch_to_weapon_setting);
R_bool(module, str_allow_throwables, auto_rod_allow_throwables_setting);
R_num(module, str_throw_speed_in_auto_rod, auto_rod_throw_speed_setting);
R_bool(module, str_require_not_mouse_over, auto_rod_require_not_mouse_over_setting);
}
+255
View File
@@ -0,0 +1,255 @@
// Auto Soup - eat soup automatically when your health is low.
//
// When health drops to "single_soup_max_hp", the module switches to a soup in the hotbar,
// eats it (soup is eaten instantly), optionally drops the empty bowl, and switches back.
// At "double_soup_max_hp" or lower it eats a second soup straight away. Every step waits a
// random delay ("delay_before" / "delay_between" / "delay_after", scaled by "randomization").
//
// Callbacks:
// auto_soup_input_hook blocks the player's own hotbar input while eating
// auto_soup_enable switched on: start over
// auto_soup_asm_pins_keep helper: one random delay
// auto_soup_on_tick every tick: the next step
#include "slinky/engine.h"
#include "slinky/jids.h"
struct Range { float lo, hi; };
struct InHook {
char padding_00[8];
void *mod; // +0x08 module asking for the hotbar
unsigned char use; // +0x10 set to 1: block the player's input
};
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" float auto_soup_single_soup_max_hp; // "single_soup_max_hp": eat at this health or lower
extern "C" float auto_soup_double_soup_max_hp; // "double_soup_max_hp": eat two at this health or lower
extern "C" float auto_soup_delay_scale; // "randomization"
extern "C" float auto_soup_delays_refill_health; // "delay_before"
extern "C" float auto_soup_delays_refill_health_second; // "delay_between"
extern "C" float auto_soup_delays_refill_health_third; // "delay_after"
extern "C" unsigned char auto_soup_drop_bowls_value; // "drop_bowls"
extern "C" unsigned char auto_soup_override_item; // "override_item": use "allowed_items" instead of soup
extern "C" char auto_soup_custom_item_set[]; // "allowed_items"
// ---- module state ----
extern "C" char auto_soup_module_descriptor[];
enum SoupStage {
STAGE_CHECK_HEALTH = 0,
STAGE_FIND_SOUP = 1,
STAGE_SWITCH = 2,
STAGE_EAT = 3,
STAGE_DROP_BOWL = 4,
STAGE_SWITCH_BACK = 5, // (or eat a second one)
STAGE_COOL_DOWN = 6,
};
extern "C" int auto_soup_stage;
extern "C" unsigned char auto_soup_busy; // eating the second soup
extern "C" unsigned char auto_soup_input_consumed; // the player pressed a hotbar key while we were eating
extern "C" float auto_soup_step_delay; // ticks until the next step
extern "C" int auto_soup_soup_slot;
extern "C" int auto_soup_original_slot;
extern "C" unsigned char auto_soup_eat_another_one;
extern "C" unsigned char auto_soup_item_leaves_bowl;
extern "C" char auto_soup_rng_states[], auto_soup_random_walk_1[], auto_soup_random_walk_2[]; // random states
// ---- game / engine functions ----
FN(void, queue_module_toggle, (void *module_manager, void *module, int enabled));
FN(float, java_call_entity_living_base_get_health, (void *jvm, void *entity_living_base));
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_get_inventory_player_main_inventory, (void *jvm, void *inv)); // the item array
FN(void *, java_call_item_stack_get_item, (void *jvm, void *stack));
FN(int, java_call_static_item_get_id_from_item, (void *jvm, void *item));
FN(unsigned char, id_vector_contains, (void *set, int id));
FN(unsigned char, claim_release_hotbar_module, (void *timer)); // ask for control of the hotbar
FN(void, release_owner, (void *timer)); // give control of the hotbar back
FN(void, java_set_inventory_player_current_item, (void *jvm, void *inventory_player, int slot));
FN(unsigned char, java_call_entity_player_is_using_item, (void *jvm, void *entity_player));
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_get_game_settings_key_8_or_9, (void *jvm, void *game_settings)); // the drop key
FN(void, java_increment_key_binding_press_time, (void *jvm, void *key_binding));
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)); // random yes/no
FN(float, random_rotation, (Range r)); // random value in the range
enum { ITEM_MUSHROOM_STEW = 282, ITEM_RABBIT_STEW = 413 };
extern "C" void auto_soup_input_hook(InHook *hook) {
if (hook->mod != auto_soup_module_descriptor)
return;
int stage = auto_soup_stage;
if (stage == STAGE_CHECK_HEALTH || stage == STAGE_COOL_DOWN)
return;
hook->use = 1;
auto_soup_input_consumed = 1;
}
extern "C" void auto_soup_enable(EvHook *hook) {
if (hook->ev != auto_soup_module_descriptor || hook->on != 1)
return;
auto_soup_stage = STAGE_CHECK_HEALTH;
auto_soup_busy = 0;
auto_soup_step_delay = 0.0f;
auto_soup_input_consumed = 0;
}
// A delay: `base` ticks plus a random 0-1 tick (now and then 0.5-2.5 more), scaled by "randomization".
extern "C" float auto_soup_asm_pins_keep(float base) {
float slow = walk_update(auto_soup_rng_states, rot_make_floats(0.0f, 0.5f), 60.0);
float extra = walk_update(auto_soup_rng_states, rot_make_floats(0.0f, 0.5f), 5.0) + slow;
if (walk_should_change(auto_soup_random_walk_1, rot_make_floats(0.03f, 0.06f), 60.0))
extra += random_rotation(rot_make_floats(0.5f, 2.5f));
return extra * auto_soup_delay_scale + base;
}
// Wait a random delay of about `base` ticks.
static void add_delay(float base) {
auto_soup_step_delay = auto_soup_asm_pins_keep(base) + auto_soup_step_delay;
}
// Find a soup in the hotbar (starting from the selected slot). Returns the slot, or -1.
static int find_soup(Ctx *ctx, void *inventory) {
unsigned char skip_current = auto_soup_busy; // second soup: the current slot holds the bowl
int current = java_get_inventory_player_current_item(ctx->jvm, inventory);
void *hotbar = java_get_inventory_player_main_inventory(ctx->jvm, inventory);
int found = -1;
for (int i = 0; i < 9; i++) {
int slot = (current + i) % 9;
if (skip_current & (slot == current))
continue;
void *jvm = ctx->jvm;
JNIEnv *env = ((Jvm *)jvm)->env;
void *stack = (*env)->GetObjectArrayElement(env, hotbar, slot);
int item_id = stack ? java_call_static_item_get_id_from_item(jvm, java_call_item_stack_get_item(jvm, stack)) : 0;
if (auto_soup_override_item == 1) {
if (!id_vector_contains(auto_soup_custom_item_set, item_id))
continue;
} else if (item_id != ITEM_RABBIT_STEW && item_id != ITEM_MUSHROOM_STEW) {
continue;
}
auto_soup_item_leaves_bowl = (item_id == ITEM_MUSHROOM_STEW) | (item_id == ITEM_RABBIT_STEW);
found = slot;
// Usually take the first one; now and then (1-8%) keep looking.
if (!walk_should_change(auto_soup_random_walk_2, rot_make_floats(0.01f, 0.08f), 30.0))
break;
}
return found;
}
extern "C" void auto_soup_on_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
// The player used the hotbar themselves while we were eating: switch off.
if (auto_soup_input_consumed == 1 && (auto_soup_stage == STAGE_COOL_DOWN || auto_soup_stage == STAGE_CHECK_HEALTH)) {
queue_module_toggle(ctx->module_manager, auto_soup_module_descriptor, 0);
return;
}
if (ctx->in_game != 1) {
auto_soup_busy = 0;
auto_soup_stage = STAGE_CHECK_HEALTH;
return;
}
// Up to 3 steps per tick, while there is no delay.
for (int step = 0; step < 3; step++) {
float delay = auto_soup_step_delay;
if (delay > 0.0f) {
auto_soup_step_delay = delay + -1.0f;
return;
}
switch (auto_soup_stage) {
case STAGE_CHECK_HEALTH: {
float health = java_call_entity_living_base_get_health(ctx->jvm, ctx->player);
if (health > auto_soup_single_soup_max_hp)
return;
add_delay(auto_soup_delays_refill_health);
auto_soup_eat_another_one = auto_soup_double_soup_max_hp >= health;
auto_soup_stage = STAGE_FIND_SOUP;
break;
}
case STAGE_FIND_SOUP: {
void *inventory = java_get_entity_player_inventory(ctx->jvm, ctx->player);
int found = find_soup(ctx, inventory);
if (found == -1) {
// No soup (left): switch back if we were eating the second one, else cool down.
auto_soup_stage = STAGE_COOL_DOWN - auto_soup_busy;
auto_soup_busy = 0;
return;
}
auto_soup_soup_slot = found;
int original;
if (auto_soup_busy == 1) {
original = auto_soup_original_slot;
} else {
original = java_get_inventory_player_current_item(ctx->jvm, inventory);
auto_soup_original_slot = original;
found = auto_soup_soup_slot;
}
auto_soup_busy = 0;
// Already holding it: eat straight away, else switch first.
auto_soup_stage = (found == original) | STAGE_SWITCH;
break;
}
case STAGE_SWITCH:
if (!claim_release_hotbar_module(auto_soup_module_descriptor)) {
auto_soup_stage = STAGE_CHECK_HEALTH;
return;
}
java_set_inventory_player_current_item(ctx->jvm, java_get_entity_player_inventory(ctx->jvm, ctx->player), auto_soup_soup_slot);
auto_soup_stage = STAGE_EAT;
add_delay(auto_soup_delays_refill_health_second);
if (java_call_entity_player_is_using_item(ctx->jvm, ctx->player)) {
float x = auto_soup_step_delay;
if (0.0f >= x)
auto_soup_step_delay = x + 1.0f;
}
break;
case STAGE_EAT:
java_increment_key_binding_press_time(ctx->jvm, java_get_game_settings_use_item_key(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft)));
if (auto_soup_drop_bowls_value == 1 && auto_soup_item_leaves_bowl) {
auto_soup_stage = STAGE_DROP_BOWL;
float x = auto_soup_asm_pins_keep(auto_soup_delays_refill_health_second) + auto_soup_step_delay;
auto_soup_step_delay = x > 0.0f ? x : x + 1.0f;
break;
}
goto eaten;
case STAGE_DROP_BOWL:
java_increment_key_binding_press_time(ctx->jvm, java_get_game_settings_key_8_or_9(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft)));
eaten:
auto_soup_stage = STAGE_SWITCH_BACK;
if (auto_soup_soup_slot != auto_soup_original_slot) {
float x = auto_soup_asm_pins_keep(auto_soup_delays_refill_health_second) + auto_soup_step_delay;
auto_soup_step_delay = x;
if (0.0f >= x)
auto_soup_step_delay = x + 1.0f;
}
break;
case STAGE_SWITCH_BACK:
release_owner(auto_soup_module_descriptor);
if (auto_soup_eat_another_one == 1) {
auto_soup_eat_another_one = 0;
auto_soup_busy = 1;
auto_soup_stage = STAGE_FIND_SOUP;
break;
}
java_set_inventory_player_current_item(ctx->jvm, java_get_entity_player_inventory(ctx->jvm, ctx->player), auto_soup_original_slot);
auto_soup_stage = STAGE_COOL_DOWN;
break;
case STAGE_COOL_DOWN:
auto_soup_busy = 0;
add_delay(auto_soup_delays_refill_health_third);
auto_soup_stage = STAGE_CHECK_HEALTH;
break;
}
}
}
+66
View File
@@ -0,0 +1,66 @@
// Auto Soup — Uses soups for you.
// category: utility descriptor: 0x2e96b0 settings block: 0x2e98a8
// functions: gui auto_soup_gui, register auto_soup_register
// implementation: src/logic/utility/auto_soup.cpp
#pragma once
#include "slinky/api.h"
S(str_maximum_health); // "Maximum health"
S(str_delays); // "Delays"
S(str_extra); // "Extra"
S(str_single_soup_max_hp); // "single_soup_max_hp"
S(str_double_soup_max_hp); // "double_soup_max_hp"
S(str_randomization_in_auto_soup); // "randomization"
S(str_delay_before); // "delay_before"
S(str_delay_between); // "delay_between"
S(str_delay_after); // "delay_after"
S(str_drop_bowls_in_auto_soup); // "drop_bowls"
S(str_override_item); // "override_item"
S(str_allowed_items); // "allowed_items"
D(auto_soup_single_soup_max_hp_setting); // setting num "single_soup_max_hp"
extern "C" float auto_soup_single_soup_max_hp; // current value of setting "single_soup_max_hp" (+0x30)
D(auto_soup_delay_before_setting); // setting num "delay_before"
D(auto_soup_double_soup_max_hp_setting); // setting num "double_soup_max_hp"
extern "C" float auto_soup_double_soup_max_hp; // current value of setting "double_soup_max_hp" (+0x30)
D(auto_soup_delay_between_setting); // setting num "delay_between"
D(auto_soup_delay_after_setting); // setting num "delay_after"
D(auto_soup_randomization_setting); // setting num "randomization"
D(auto_soup_override_item_setting); // setting bool "override_item"
extern "C" unsigned char auto_soup_override_item; // current value of setting "override_item" (+0x18)
D(auto_soup_drop_bowls_setting); // setting bool "drop_bowls"
D(auto_soup_allowed_items_setting); // setting kind2 "allowed_items"
extern "C" void auto_soup_gui(void *gui, void *window) {
W_label(gui, window, str_maximum_health);
W_slider(window, gui, auto_soup_single_soup_max_hp_setting);
float lo = auto_soup_single_soup_max_hp;
if (auto_soup_double_soup_max_hp > lo)
auto_soup_double_soup_max_hp = lo;
W_slider(window, gui, auto_soup_double_soup_max_hp_setting);
W_label(gui, window, str_delays);
W_slider(window, gui, auto_soup_randomization_setting);
W_slider(window, gui, auto_soup_delay_before_setting);
W_slider(window, gui, auto_soup_delay_between_setting);
W_slider(window, gui, auto_soup_delay_after_setting);
W_label(gui, window, str_extra);
W_bool(window, gui, auto_soup_drop_bowls_setting);
W_bool(window, gui, auto_soup_override_item_setting);
if (auto_soup_override_item == 1)
W_items(window, gui, auto_soup_allowed_items_setting);
else
EPILOG_NOP();
}
extern "C" void auto_soup_register(void *module) {
R_num(module, str_single_soup_max_hp, auto_soup_single_soup_max_hp_setting);
R_num(module, str_double_soup_max_hp, auto_soup_double_soup_max_hp_setting);
R_num(module, str_randomization_in_auto_soup, auto_soup_randomization_setting);
R_num(module, str_delay_before, auto_soup_delay_before_setting);
R_num(module, str_delay_between, auto_soup_delay_between_setting);
R_num(module, str_delay_after, auto_soup_delay_after_setting);
R_bool(module, str_drop_bowls_in_auto_soup, auto_soup_drop_bowls_setting);
R_bool(module, str_override_item, auto_soup_override_item_setting);
R_kind2(module, str_allowed_items, auto_soup_allowed_items_setting);
}
+105
View File
@@ -0,0 +1,105 @@
// Blink - hold back network packets, then send them all at once.
//
// While enabled, packets are held ("direction": 0 = incoming, 1 = outgoing, 2 = both).
// To everyone else you freeze, then teleport when Blink is switched off. It switches off by
// itself after "max_duration" ticks, and optionally when you attack, dig or use a block.
//
// Callbacks (descriptor slots +0x48 / +0x68 / +0x78 / +0x98 / +0x128):
// blink_on_tick every tick: switch off when time is up / on attack
// blink_on_packet_received every incoming packet: hold it (except hit feedback)
// blink_on_packet_sent every outgoing packet: hold it
// blink_on_toggle switched on: start the timer
// blink_on_attack left / right click: switch off when clicking a block
#include "slinky/engine.h"
// ---- settings ----
extern "C" float blink_max_duration_value; // "max_duration" (ticks)
extern "C" unsigned char blink_direction; // "direction"
extern "C" unsigned char blink_disable_on_attack_value; // "disable_on_attack"
extern "C" unsigned char blink_disable_on_block_dig_value; // "disable_on_block_dig"
extern "C" unsigned char blink_disable_on_block_interact_value; // "disable_on_block_interact"
// ---- module state ----
extern "C" char blink_module_descriptor[];
extern "C" int blink_last_hurt_time; // tick of our last attack, last tick
extern "C" int blink_ticks_left;
extern "C" volatile unsigned char blink_active_direction; // "direction" while active (read by the network thread)
struct PktHook {
char padding_00[8];
Ctx *ctx; // +0x08 JVM handle
void *ev; // +0x10 the packet
char padding_18[12];
int verdict; // +0x24 1 = hold, 3 = let through
};
struct PhaseHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
unsigned char phase; // +0x10 1 = left click (dig), else right click (use)
};
struct StateHook {
char padding_00[16];
void *ev; // +0x10 module descriptor that was toggled
unsigned char on; // +0x18 1 = switched on
};
// ---- game / engine functions ----
FN(int, java_get_entity_living_base_last_attacker_time, (void *jvm, void *entity_living_base)); // tick of our last attack
FN(void, queue_module_toggle, (void *module_manager, void *module, int enabled));
FN(void *, java_jni_is_instance_of_s19_packet_entity_status, (void *jvm, void *event));
FN(void *, java_jni_is_instance_of_s06_packet_update_health, (void *jvm, void *event));
FN(void *, java_jni_is_instance_of_s29_packet_sound_effect, (void *jvm, void *event));
FN(void *, java_jni_is_instance_of_s2_apacket_particles, (void *jvm, void *event));
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)); // 1 = a block
enum { DIRECTION_INCOMING = 0, DIRECTION_OUTGOING = 1, DIRECTION_BOTH = 2 };
extern "C" void blink_on_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
if (ctx->in_game != 1)
return;
int last_attack = java_get_entity_living_base_last_attacker_time(ctx->jvm, ctx->player);
unsigned char attacked = last_attack > blink_last_hurt_time;
unsigned char disable_on_attack = blink_disable_on_attack_value;
blink_last_hurt_time = last_attack;
if (--blink_ticks_left <= 0 || (attacked & disable_on_attack))
queue_module_toggle(ctx->module_manager, blink_module_descriptor, 0);
}
extern "C" void blink_on_packet_received(PktHook *hook) {
if (blink_active_direction == DIRECTION_OUTGOING)
return;
// Hold everything except hurt / health / sound (hit feedback) and particles.
int verdict = 3;
if (!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))
verdict = java_jni_is_instance_of_s2_apacket_particles(hook->ctx, hook->ev) ? 3 : 1;
hook->verdict = verdict;
}
extern "C" void blink_on_packet_sent(PktHook *hook) {
if (blink_active_direction != DIRECTION_INCOMING)
hook->verdict = 1;
}
extern "C" void blink_on_toggle(StateHook *hook) {
if (hook->ev != blink_module_descriptor || hook->on != 1)
return;
blink_ticks_left = (int)(long long)blink_max_duration_value;
blink_last_hurt_time = 0x7fffffff;
__atomic_exchange_n(&blink_active_direction, blink_direction, __ATOMIC_SEQ_CST);
}
extern "C" void blink_on_attack(PhaseHook *hook) {
Ctx *ctx = hook->ctx;
bool watch = hook->phase == 1 ? blink_disable_on_block_dig_value == 1 : blink_disable_on_block_interact_value == 1;
if (!watch)
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) == 1)
queue_module_toggle(ctx->module_manager, blink_module_descriptor, 0);
}
+46
View File
@@ -0,0 +1,46 @@
// Blink — Simulates teleporting using lag.
// category: utility descriptor: 0x2ec600 settings block: 0x2ec7f8
// functions: gui blink_gui, register blink_register, status blink_status
// implementation: src/logic/utility/blink.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_blink); // "Main"
S(str_disable_on); // "Disable on"
S(str_direction_in_blink); // "direction"
S(str_max_duration); // "max_duration"
S(str_disable_on_attack); // "disable_on_attack"
S(str_disable_on_block_interact); // "disable_on_block_interact"
S(str_disable_on_block_dig); // "disable_on_block_dig"
S(str_s_in_blink); // "%s"
D(blink_disable_on_attack_setting); // setting bool "disable_on_attack"
D(blink_max_duration_setting); // setting num "max_duration"
D(blink_enum_option_labels_1); // enum option labels (const char *[])
D(blink_direction_setting); // setting enum "direction"
extern "C" unsigned blink_direction; // current value of setting "direction" (+0x30)
D(blink_disable_on_block_dig_setting); // setting bool "disable_on_block_dig"
D(blink_disable_on_block_interact_setting); // setting bool "disable_on_block_interact"
extern "C" void blink_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_blink);
W_enumw(window, gui, blink_direction_setting);
W_slider(window, gui, blink_max_duration_setting);
W_label(gui, window, str_disable_on);
W_bool(window, gui, blink_disable_on_attack_setting);
W_bool(window, gui, blink_disable_on_block_interact_setting);
W_bool(window, gui, blink_disable_on_block_dig_setting);
}
extern "C" void blink_register(void *module) {
R_enum(module, str_direction_in_blink, blink_direction_setting);
R_num(module, str_max_duration, blink_max_duration_setting);
R_bool(module, str_disable_on_attack, blink_disable_on_attack_setting);
R_bool(module, str_disable_on_block_interact, blink_disable_on_block_interact_setting);
R_bool(module, str_disable_on_block_dig, blink_disable_on_block_dig_setting);
}
extern "C" void blink_status(void *self) {
log_fmt(self, 0x20, str_s_in_blink, ((const char **)blink_enum_option_labels_1)[blink_direction]);
}
+299
View File
@@ -0,0 +1,299 @@
// Chest Stealer - take the useful items out of a chest.
//
// While a chest is open, the module shift-clicks the items worth taking, one per click
// ("speed" clicks per 50 ms), after "delay_after_open" ms:
// - tools, weapons and armour that are better than what you have,
// - golden apples ("Golden apples") and useful potions ("Good potions"),
// - building blocks, up to "Max blocks" in your inventory.
// With "require_vanilla_title", only chests with the normal "Chest" / "Large Chest" title.
//
// Callback (descriptor slot +0x1d8):
// chest_stealer_on_tick every tick
#include "slinky/engine.h"
#include "slinky/jids.h"
S(str_container_chest); // "container.chest"
S(str_container_chestdouble); // "container.chestDouble"
extern "C" float chest_stealer_delay_after_open_value; // "delay_after_open" current value
extern "C" unsigned char chest_stealer_require_vanilla_title_value; // "require_vanilla_title"
extern "C" float chest_stealer_steal_delay; // steal delay (ms)
extern "C" unsigned char chest_stealer_speed_setting[]; // slider; current value at +0x30
extern "C" unsigned char chest_stealer_max_blocks_setting[]; // slider; current value at +0x30
extern "C" unsigned char chest_stealer_golden_apples_value; // take golden apples
extern "C" unsigned char chest_stealer_good_potions_value; // take useful potions
struct ToolInfo { int kind, tier; };
FN(void *, get_current_screen, (void *jvm, void *object));
FN(unsigned char, java_jni_is_instance_of_gui_chest, (void *jvm, void *scr));
FN(void *, java_get_gui_chest_lower_chest_inventory, (void *jvm, void *scr));
FN(void *, java_jni_is_instance_of_inventory_basic, (void *jvm, void *candidate));
FN(void *, java_get_inventory_basic, (void *jvm, void *inventory_basic));
FN(unsigned char, java_string_equal_translation_key, (void *jvm, void *title, const char *name));
FN(void *, java_call_iinventory_get_stack_in_slot, (void *jvm, void *inventory, int slot));
FN(void, java_gui_container_handle_mouse_click, (void *jvm, void *screen, int slot, int button, int mode));
FN(void *, java_get_entity_player_inventory, (void *jvm, void *entity_player));
FN(void *, java_call_item_stack_get_item, (void *jvm, void *stack));
FN(int, java_call_static_item_get_id_from_item, (void *jvm, void *item));
FN(int, java_get_item_stack_metadata, (void *jvm, void *stack));
FN(int, java_get_item_stack_stack_size, (void *jvm, void *stack));
FN(void *, java_call_item_stack_get_enchantment_tag_list, (void *jvm, void *stack));
FN(unsigned char, java_call_item_stack_has_display_name, (void *jvm, void *stack));
FN(int, score_item_inventory_sorter_category, (Ctx *ctx, int category, int id, unsigned meta, void *nbt, unsigned char display_name));
FN(ToolInfo, chest_gui_title_id, (int id));
FN(unsigned, swap_delay, (Ctx *ctx, void *stack, unsigned kind));
FN(double, time_now, ());
static void *chest_stealer_screen; // screen whose slots are being processed
static int chest_stealer_slot; // next chest slot to inspect
static int chest_stealer_size; // number of slots in the lower chest inventory
static double chest_stealer_next_click; // time of the next click
static jmethodID chest_stealer_size_method; // IInventory.getSizeInventory
static jmethodID inventory_size_method(Jvm *jvm) {
if (chest_stealer_size_method) return chest_stealer_size_method;
JNIEnv *env = jvm->env;
jclass cls = (jclass)jvm->ids->IInventory;
static const char *const names[] = {"getSizeInventory", "func_70302_i_", "a"};
for (int i = 0; i < 3; i++) {
jmethodID id = (*env)->GetMethodID(env, cls, names[i], "()I");
if (id) {
chest_stealer_size_method = id;
return id;
}
(*env)->ExceptionClear(env);
}
return 0;
}
static float speed_value() {
float s = *(float *)(chest_stealer_speed_setting + 0x30);
if (!(s > 0.1f) || s > 10.0f) s = 1.0f;
return s;
}
// Score a tool against the sorter's tool category. kind is 0 for non-tools.
static int tool_score(Ctx *ctx, void *stack, int *kind) {
Jvm *jvm = (Jvm *)ctx->jvm;
JNIEnv *env = jvm->env;
jobject item = java_call_item_stack_get_item(jvm, stack);
if (!item) return -1;
int id = java_call_static_item_get_id_from_item(jvm, item);
ToolInfo info = chest_gui_title_id(id);
if (!info.kind) {
(*env)->DeleteLocalRef(env, item);
return -1;
}
unsigned meta = (unsigned)java_get_item_stack_metadata(jvm, stack);
void *nbt = java_call_item_stack_get_enchantment_tag_list(jvm, stack);
unsigned char display_name = java_call_item_stack_has_display_name(jvm, stack);
int score = score_item_inventory_sorter_category(ctx, info.kind, id, meta, nbt, display_name);
if (nbt) (*env)->DeleteLocalRef(env, nbt);
(*env)->DeleteLocalRef(env, item);
*kind = info.kind;
return score;
}
static int max_block_count() {
float value = *(float *)(chest_stealer_max_blocks_setting + 0x30);
if (!(value > 0.0f)) return 0;
if (value > 2304.0f) value = 2304.0f; // 36 inventory slots * 64
return (int)value;
}
static bool is_block_item(int id) {
return id > 0 && id < 0x100;
}
// 1.8 potion damage values: the low nibble is the base potion, bit 0x20 is
// level II, bit 0x40 is extended, and bit 0x4000 marks a splash potion.
static bool is_good_potion(unsigned meta) {
switch (meta & 0xf) {
case 1: // regeneration
case 2: // swiftness
case 3: // fire resistance
case 5: // instant health
case 6: // night vision
case 8: // strength
case 10: // jump boost
case 12: // water breathing
case 13: // invisibility
return true;
default:
return false;
}
}
static int player_block_count(Ctx *ctx) {
Jvm *jvm = (Jvm *)ctx->jvm;
JNIEnv *env = jvm->env;
void *inventory = java_get_entity_player_inventory(jvm, ctx->player);
if (!inventory) return 0;
int total = 0;
for (int slot = 0; slot < 36 && total < 2304; slot++) {
void *current = java_call_iinventory_get_stack_in_slot(jvm, inventory, slot);
if ((*env)->ExceptionCheck(env)) {
(*env)->ExceptionClear(env);
break;
}
if (!current) continue;
jobject item = java_call_item_stack_get_item(jvm, current);
if (item) {
int id = java_call_static_item_get_id_from_item(jvm, item);
if (is_block_item(id)) {
int n = java_get_item_stack_stack_size(jvm, current);
if (n > 0) total += n;
}
(*env)->DeleteLocalRef(env, item);
}
(*env)->DeleteLocalRef(env, current);
}
(*env)->DeleteLocalRef(env, inventory);
return total;
}
static bool chest_block_is_wanted(Ctx *ctx, void *stack, int current_blocks) {
int limit = max_block_count();
if (limit <= 0) return false;
Jvm *jvm = (Jvm *)ctx->jvm;
int n = java_get_item_stack_stack_size(jvm, stack);
if (n <= 0) return false;
return current_blocks + n <= limit;
}
// Golden apples, useful potions, and a configurable number of building blocks.
static bool chest_item_is_special(Ctx *ctx, void *stack, int blocks_in_inventory) {
Jvm *jvm = (Jvm *)ctx->jvm;
JNIEnv *env = jvm->env;
jobject item = java_call_item_stack_get_item(jvm, stack);
if (!item) return false;
int id = java_call_static_item_get_id_from_item(jvm, item);
bool wanted = false;
if (id == 0x142 || id == 0x1d2) { // golden / enchanted golden apple
wanted = chest_stealer_golden_apples_value == 1;
} else if (id == 0x175) { // potion
wanted = chest_stealer_good_potions_value == 1 &&
is_good_potion((unsigned)java_get_item_stack_metadata(jvm, stack));
} else if (is_block_item(id)) {
wanted = chest_block_is_wanted(ctx, stack, blocks_in_inventory);
}
(*env)->DeleteLocalRef(env, item);
return wanted;
}
// True only when the chest stack is an upgrade over the player's current gear.
static bool chest_item_is_upgrade(Ctx *ctx, void *stack) {
Jvm *jvm = (Jvm *)ctx->jvm;
JNIEnv *env = jvm->env;
int kind = 0;
int chest_score = tool_score(ctx, stack, &kind);
void *inventory = java_get_entity_player_inventory(jvm, ctx->player);
if (inventory && kind) {
int best = 0;
for (int slot = 0; slot < 36; slot++) {
void *current = java_call_iinventory_get_stack_in_slot(jvm, inventory, slot);
if (!current) continue;
int current_kind = 0;
int current_score = tool_score(ctx, current, &current_kind);
if (current_kind == kind && current_score > best) best = current_score;
(*env)->DeleteLocalRef(env, current);
}
(*env)->DeleteLocalRef(env, inventory);
return chest_score > best;
}
if (inventory) {
// Armor: kind 0 helmet, 1 chestplate, 2 leggings, 3 boots. swap_delay returns
// armour points plus protection enchantments for the matching piece.
for (int armor_kind = 0; armor_kind < 4; armor_kind++) {
unsigned upgrade_score = swap_delay(ctx, stack, (unsigned)armor_kind);
if (!upgrade_score) continue;
void *current = java_call_iinventory_get_stack_in_slot(jvm, inventory, 39 - armor_kind);
unsigned current_score = current ? swap_delay(ctx, current, (unsigned)armor_kind) : 0;
if (current) (*env)->DeleteLocalRef(env, current);
if (upgrade_score > current_score) {
(*env)->DeleteLocalRef(env, inventory);
return true;
}
}
(*env)->DeleteLocalRef(env, inventory);
}
return false;
}
extern "C" void chest_stealer_on_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
Jvm *jvm = (Jvm *)ctx->jvm;
void *screen = get_current_screen(ctx->jvm, ctx->minecraft);
if (!screen || !java_jni_is_instance_of_gui_chest(ctx->jvm, screen)) {
chest_stealer_screen = 0;
chest_stealer_slot = 0;
return;
}
void *lower = java_get_gui_chest_lower_chest_inventory(ctx->jvm, screen);
if (!lower) return;
// "require_vanilla_title" means: only click chests whose localized title is the
// vanilla chest title.
if (chest_stealer_require_vanilla_title_value == 1) {
void *inventory_basic = java_jni_is_instance_of_inventory_basic(jvm, lower);
if (inventory_basic) {
void *title = java_get_inventory_basic(jvm, inventory_basic);
if (!java_string_equal_translation_key(jvm, title, str_container_chest) &&
!java_string_equal_translation_key(jvm, title, str_container_chestdouble))
return;
}
}
double now = time_now();
if (screen != chest_stealer_screen) {
chest_stealer_screen = screen;
chest_stealer_slot = 0;
chest_stealer_size = 0;
chest_stealer_next_click = now + (double)chest_stealer_delay_after_open_value / 1000.0;
}
if (now < chest_stealer_next_click) return;
if (chest_stealer_size <= 0) {
jmethodID size_method = inventory_size_method(jvm);
if (size_method) {
chest_stealer_size = (*jvm->env)->CallIntMethod(jvm->env, lower, size_method);
if ((*jvm->env)->ExceptionCheck(jvm->env)) {
(*jvm->env)->ExceptionClear(jvm->env);
chest_stealer_size = 0;
}
}
// If the size lookup is unavailable, use the single-chest size. Never probe
// past it, or a single chest would start moving the player's own items into it.
if (chest_stealer_size <= 0 || chest_stealer_size > 54) chest_stealer_size = 27;
}
int blocks_in_inventory = max_block_count() > 0 ? player_block_count(ctx) : 0;
for (; chest_stealer_slot < chest_stealer_size; chest_stealer_slot++) {
void *stack = java_call_iinventory_get_stack_in_slot(jvm, lower, chest_stealer_slot);
if ((*jvm->env)->ExceptionCheck(jvm->env)) {
(*jvm->env)->ExceptionClear(jvm->env);
return;
}
if (!stack) continue;
bool take = chest_item_is_special(ctx, stack, blocks_in_inventory);
if (!take) take = chest_item_is_upgrade(ctx, stack);
(*jvm->env)->DeleteLocalRef(jvm->env, stack);
if (!take) continue;
java_gui_container_handle_mouse_click(jvm, screen, chest_stealer_slot, 0, 1); // shift-click
if ((*jvm->env)->ExceptionCheck(jvm->env)) {
(*jvm->env)->ExceptionClear(jvm->env);
return;
}
chest_stealer_steal_delay = (float)(0.05 / (double)speed_value() * 1000.0);
chest_stealer_slot++;
chest_stealer_next_click = now + 0.05 / (double)speed_value();
return;
}
// Everything useful has been handled. Re-scan later if the chest remains open.
chest_stealer_slot = 0;
chest_stealer_next_click = now + 0.2;
}
+49
View File
@@ -0,0 +1,49 @@
// Chest Stealer — Automatically loots chests for you.
// category: utility descriptor: 0x2f5288 settings block: 0x2f5480
// functions: gui chest_stealer_gui, register chest_stealer_register
// implementation: src/logic/utility/chest_stealer.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_chest_stealer); // "Main"
S(str_delay_after_open_in_chest_stealer); // "delay_after_open"
S(str_delay_before_close_in_chest_stealer); // "delay_before_close"
S(str_speed_in_chest_stealer); // "speed"
S(str_smart_speed_in_chest_stealer); // "smart_speed"
S(str_require_vanilla_title); // "require_vanilla_title"
S(str_max_blocks_in_chest_stealer); // "Max blocks"
S(str_golden_apples_in_chest_stealer); // "Golden apples"
S(str_good_potions_in_chest_stealer); // "Good potions"
D(chest_stealer_delay_after_open_setting); // setting num "delay_after_open"
D(chest_stealer_require_vanilla_title_setting); // setting bool "require_vanilla_title"
D(chest_stealer_delay_before_close_setting); // setting num "delay_before_close"
D(chest_stealer_speed_setting); // setting num "speed"
D(chest_stealer_smart_speed_setting); // setting bool "smart_speed"
D(chest_stealer_max_blocks_setting); // setting num "Max blocks"
D(chest_stealer_golden_apples_setting); // setting bool "Golden apples"
D(chest_stealer_good_potions_setting); // setting bool "Good potions"
extern "C" void chest_stealer_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_chest_stealer);
W_slider(window, gui, chest_stealer_delay_after_open_setting);
W_slider(window, gui, chest_stealer_delay_before_close_setting);
W_slider(window, gui, chest_stealer_speed_setting);
W_bool(window, gui, chest_stealer_smart_speed_setting);
W_slider(window, gui, chest_stealer_max_blocks_setting);
W_bool(window, gui, chest_stealer_golden_apples_setting);
W_bool(window, gui, chest_stealer_good_potions_setting);
W_label(gui, window, str_main_in_chest_stealer);
W_bool(window, gui, chest_stealer_require_vanilla_title_setting);
}
extern "C" void chest_stealer_register(void *module) {
R_num(module, str_delay_after_open_in_chest_stealer, chest_stealer_delay_after_open_setting);
R_num(module, str_delay_before_close_in_chest_stealer, chest_stealer_delay_before_close_setting);
R_num(module, str_speed_in_chest_stealer, chest_stealer_speed_setting);
R_bool(module, str_smart_speed_in_chest_stealer, chest_stealer_smart_speed_setting);
R_bool(module, str_require_vanilla_title, chest_stealer_require_vanilla_title_setting);
R_num(module, str_max_blocks_in_chest_stealer, chest_stealer_max_blocks_setting);
R_bool(module, str_golden_apples_in_chest_stealer, chest_stealer_golden_apples_setting);
R_bool(module, str_good_potions_in_chest_stealer, chest_stealer_good_potions_setting);
}
+156
View File
@@ -0,0 +1,156 @@
// Debug - print diagnostics into the chat.
//
// "hurt_time": when you get hit, the hurt time and whether you sprint / use an item
// "item_use_state": when the server is told you start / stop using an item
// "clicks": left and right clicks per tick
// Each line starts with the tick count (last 3 digits). Colours are Minecraft "§" codes.
//
// Callbacks:
// debug_on_tick every tick: hurt time and item use lines
// debug_on_packet_sent every outgoing packet: track item use start / stop
// debug_on_attack_post after a click: count it
// debug_on_late_tick every tick: click line
#include "slinky/engine.h"
// Chat line formats.
S(str_sect_7_03d_debug_hurt_time_sec); // hurt time line
S(str_sect_7_03d_debug_item_use_sect); // item use line
S(str_astart); // "aStart" (the format puts "§" before it: green "Start")
S(str_cstop); // "cStop" (red "Stop")
S(str_sect_7_03d_debug_click_sect_cl); // click line
extern "C" const int debug_hurt_time_code_table[]; // colour code for hurt time 7, 8, 9, 10: 'a', 'e', 'c', '4'
// ---- settings ----
extern "C" unsigned char debug_hurt_time_value; // "hurt_time"
extern "C" unsigned char debug_item_use_state_value; // "item_use_state"
extern "C" unsigned char debug_clicks_value; // "clicks"
// ---- module state ----
extern "C" unsigned char debug_last_item_use_state;
extern "C" unsigned char debug_current_item_use_state; // written by the network thread
extern "C" int debug_left_clicks_this_window;
extern "C" int debug_right_clicks_this_window;
extern "C" int debug_ticks_window; // ticks since the last click
struct EvHook {
char padding_00[8];
void *ctx; // +0x08 JVM handle
void *ev; // +0x10 the packet
char padding_18[12];
int type; // +0x24
};
// ---- game / engine functions ----
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(unsigned char, java_call_entity_is_sprinting, (void *jvm, void *entity));
FN(unsigned char, java_call_entity_player_is_using_item, (void *jvm, void *entity_player));
FN(void, jni_throw_format, (void *jvm, const char *fmt, ...)); // print a line into the chat
FN(void *, java_jni_is_instance_of_c08_packet_player_block_placement, (void *ctx, void *event)); // "use item" packet
FN(void *, java_jni_is_instance_of_c07_packet_player_digging, (void *ctx, void *event));
FN(int, java_c07_packet_player_digging_status, (void *ctx, void *object)); // 5 = release use item
// Minecraft colour codes.
enum { GREEN = 'a', AQUA = 'b', RED = 'c', WHITE = 'f', DARK_GREEN = '2', DARK_AQUA = '3', DARK_GRAY = '8' };
// The tick count, last 3 digits.
static unsigned tick_stamp(void *jvm, void *player) {
unsigned ticks = java_get_entity_ticks_existed(jvm, player);
return ticks - ticks / 1000 * 1000;
}
extern "C" void debug_on_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
if (ctx->in_game != 1)
return;
if (debug_hurt_time_value == 1) {
int hurt_time = java_get_entity_living_base_hurt_time(ctx->jvm, ctx->player);
if (hurt_time >= 7) {
void *jvm = ctx->jvm;
unsigned stamp = tick_stamp(jvm, ctx->player);
int hurt_colour = WHITE;
unsigned index = hurt_time - 7;
if (index <= 3)
hurt_colour = debug_hurt_time_code_table[index];
int sprint_colour = RED;
if (java_call_entity_is_sprinting(ctx->jvm, ctx->player))
sprint_colour = DARK_GRAY;
int item_colour = DARK_GRAY;
if (java_call_entity_player_is_using_item(ctx->jvm, ctx->player))
item_colour = RED;
jni_throw_format(jvm, str_sect_7_03d_debug_hurt_time_sec, stamp, hurt_colour, hurt_time, sprint_colour, item_colour);
}
}
if (debug_item_use_state_value == 1) {
unsigned state = debug_current_item_use_state;
unsigned char using_item = state & 1;
if (using_item != debug_last_item_use_state) {
debug_last_item_use_state = using_item;
void *jvm = ctx->jvm;
unsigned stamp = tick_stamp(jvm, ctx->player);
jni_throw_format(jvm, str_sect_7_03d_debug_item_use_sect, stamp, (state & 1) ? str_astart : str_cstop);
}
}
}
// Every outgoing packet: "use item" = start, "release use item" = stop.
extern "C" void debug_on_packet_sent(EvHook *hook) {
int type = hook->type;
if (type != 3 && type != 0)
return;
unsigned char using_item = 1;
if (!java_jni_is_instance_of_c08_packet_player_block_placement(hook->ctx, hook->ev)) {
void *dig = java_jni_is_instance_of_c07_packet_player_digging(hook->ctx, hook->ev);
if (!dig)
return;
if (java_c07_packet_player_digging_status(hook->ctx, dig) != 5)
return;
using_item = 0;
}
__atomic_exchange_n(&debug_current_item_use_state, using_item, __ATOMIC_SEQ_CST);
}
// After a click (h[0x10]: 1 = left, 0 = right).
extern "C" void debug_on_attack_post(unsigned char *h) {
if (debug_clicks_value != 1)
return;
if (h[0x10])
debug_left_clicks_this_window += 1;
else
debug_right_clicks_this_window += 1;
debug_ticks_window = 0;
}
// Every tick: print the clicks of this tick (for up to 10 ticks after the last click).
extern "C" void debug_on_late_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
if (ctx->in_game != 1)
return;
unsigned ticks = debug_ticks_window;
if (debug_clicks_value == 1) {
if (ticks <= 9) {
// Colour: grey for 0, light for 1, dark for 2+.
int left = debug_left_clicks_this_window;
int left_colour = DARK_GREEN;
if (left == 1)
left_colour = GREEN;
if (left == 0)
left_colour = DARK_GRAY;
int right = debug_right_clicks_this_window;
int right_colour = DARK_AQUA;
if (right == 1)
right_colour = AQUA;
if (right == 0)
right_colour = DARK_GRAY;
void *jvm = ctx->jvm;
unsigned stamp = tick_stamp(jvm, ctx->player);
jni_throw_format(jvm, str_sect_7_03d_debug_click_sect_cl, stamp, left_colour, debug_left_clicks_this_window, right_colour, debug_right_clicks_this_window);
ticks = debug_ticks_window;
}
debug_left_clicks_this_window = 0;
debug_right_clicks_this_window = 0;
}
debug_ticks_window = ticks + 1;
}
+28
View File
@@ -0,0 +1,28 @@
// Debug — Prints debug information in chat.
// category: utility descriptor: 0x2f4430 settings block: 0x2f4628
// functions: gui debug_gui, register debug_register
// implementation: src/logic/utility/debug.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_debug); // "Main"
S(str_clicks_in_debug); // "clicks"
S(str_hurt_time_in_debug); // "hurt_time"
S(str_item_use_state); // "item_use_state"
D(debug_hurt_time_setting); // setting bool "hurt_time"
D(debug_item_use_state_setting); // setting bool "item_use_state"
D(debug_clicks_setting); // setting bool "clicks"
extern "C" void debug_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_debug);
W_bool(window, gui, debug_clicks_setting);
W_bool(window, gui, debug_hurt_time_setting);
W_bool(window, gui, debug_item_use_state_setting);
}
extern "C" void debug_register(void *module) {
R_bool(module, str_clicks_in_debug, debug_clicks_setting);
R_bool(module, str_hurt_time_in_debug, debug_hurt_time_setting);
R_bool(module, str_item_use_state, debug_item_use_state_setting);
}
+133
View File
@@ -0,0 +1,133 @@
// Fake Lag - make your connection look laggy on purpose.
//
// Packets are held for up to "inbound" / "outbound" ms before they go through, so others
// see you move in jumps and react later. "require_attack" only lags for 20 ticks after you
// attack. In "mode" 1 (pulse) the lag comes in waves: held, then released every few ticks.
// With "realtime_damage", hit feedback (hurt / health / sound) always arrives at once.
//
// Callbacks (descriptor slots +0x48 / +0x78):
// fake_lag_on_tick every tick: decide how long packets may be held
// fake_lag_on_packet_sent every packet (both directions): hold or release
#include "slinky/engine.h"
// ---- settings ----
extern "C" float fake_lag_inbound_value; // "inbound" (ms)
extern "C" float fake_lag_outbound_value; // "outbound" (ms)
extern "C" bool fake_lag_realtime_damage_value; // "realtime_damage"
extern "C" unsigned fake_lag_mode; // "mode": 0 = constant, 1 = pulse
extern "C" unsigned char fake_lag_require_ingame_value; // "require_ingame"
extern "C" unsigned char fake_lag_require_weapon_value; // "require_weapon"
extern "C" unsigned char fake_lag_require_attack_value; // "require_attack"
// ---- module state ----
extern "C" int fake_lag_last_hurt_time; // tick of our last attack, last tick
extern "C" int fake_lag_cooldown; // ticks of lag left after an attack
extern "C" int fake_lag_inbound_counter; // pulse mode: ms until the next release
extern "C" int fake_lag_outbound_counter;
// Shared with the network thread:
extern "C" unsigned char fake_lag_realtime_damage_flag;
extern "C" unsigned char fake_lag_inbound_window_open; // pulse mode: release now
extern "C" unsigned char fake_lag_outbound_window_open;
extern "C" volatile unsigned short fake_lag_inbound_budget; // ms a packet may be held (0 = no lag)
extern "C" volatile unsigned short fake_lag_outbound_budget;
struct PktHook {
int type; // +0x00 2 = incoming
char padding_04[4];
Ctx *ctx; // +0x08 JVM handle
void *ev; // +0x10 the packet
long long budget; // +0x18 ms the packet has been held so far
char padding_20[4];
int verdict; // +0x24 1 = hold, 3 = let through
};
// ---- game / engine functions ----
FN(int, java_get_entity_living_base_last_attacker_time, (void *jvm, void *entity_living_base)); // tick of our last attack
FN(unsigned char, is_holding_accepted_weapon, (void *jvm, void *object));
FN(void *, java_jni_is_instance_of_s19_packet_entity_status, (void *jvm, void *event));
FN(void *, java_jni_is_instance_of_s06_packet_update_health, (void *jvm, void *event));
FN(void *, java_jni_is_instance_of_s29_packet_sound_effect, (void *jvm, void *event));
// Pulse mode, one direction: count 50 ms per tick down; at the end release and start again.
static bool pulse_step(int *counter, float length) {
int ms_left = *counter;
if (ms_left > 0) {
*counter = ms_left - 50;
return (unsigned)ms_left < 51; // the last tick of the wave: release
}
*counter = (int)((float)ms_left + length);
return false;
}
static void set_budgets(unsigned short inbound, unsigned short outbound) {
__atomic_exchange_n(&fake_lag_inbound_budget, inbound, __ATOMIC_SEQ_CST);
__atomic_exchange_n(&fake_lag_outbound_budget, outbound, __ATOMIC_SEQ_CST);
}
extern "C" void fake_lag_on_tick(Hook *hook) {
if (fake_lag_cooldown > 0)
fake_lag_cooldown--;
__atomic_exchange_n(&fake_lag_realtime_damage_flag, fake_lag_realtime_damage_value, __ATOMIC_SEQ_CST);
if (fake_lag_mode == 1) {
__atomic_exchange_n(&fake_lag_inbound_window_open, pulse_step(&fake_lag_inbound_counter, fake_lag_inbound_value), __ATOMIC_SEQ_CST);
__atomic_exchange_n(&fake_lag_outbound_window_open, pulse_step(&fake_lag_outbound_counter, fake_lag_outbound_value), __ATOMIC_SEQ_CST);
}
Ctx *ctx = hook->ctx;
if (!ctx->world || (fake_lag_require_ingame_value == 1 && !ctx->in_game)) {
fake_lag_cooldown = 0;
__atomic_exchange_n(&fake_lag_outbound_budget, (unsigned short)0, __ATOMIC_SEQ_CST);
__atomic_exchange_n(&fake_lag_inbound_budget, (unsigned short)0, __ATOMIC_SEQ_CST);
return;
}
int last_attack = java_get_entity_living_base_last_attacker_time(ctx->jvm, ctx->player);
unsigned char lag;
if (fake_lag_require_weapon_value == 1 && !is_holding_accepted_weapon(ctx->jvm, ctx->player)) {
fake_lag_cooldown = 0;
lag = false;
} else {
// With "require_attack": only in the 20 ticks after an attack.
lag = (fake_lag_require_attack_value ^ 1) | (fake_lag_cooldown != 0);
}
if (last_attack != fake_lag_last_hurt_time)
fake_lag_cooldown = 20; // we attacked
fake_lag_last_hurt_time = last_attack;
if (lag) {
set_budgets((unsigned short)(int)fake_lag_inbound_value, (unsigned short)(int)fake_lag_outbound_value);
return;
}
__atomic_exchange_n(&fake_lag_outbound_budget, (unsigned short)0, __ATOMIC_SEQ_CST);
__atomic_exchange_n(&fake_lag_inbound_budget, (unsigned short)0, __ATOMIC_SEQ_CST);
}
// Every packet (network thread).
extern "C" void fake_lag_on_packet_sent(PktHook *hook) {
unsigned short allowed_ms;
if (hook->type == 2) {
// Incoming.
if (__atomic_load_n(&fake_lag_realtime_damage_flag, __ATOMIC_SEQ_CST) & 1) {
if (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 = 3;
return;
}
}
if (__atomic_load_n(&fake_lag_inbound_window_open, __ATOMIC_SEQ_CST) & 1)
return;
allowed_ms = fake_lag_inbound_budget;
} else {
// Outgoing.
if (__atomic_load_n(&fake_lag_outbound_window_open, __ATOMIC_SEQ_CST) & 1)
return;
allowed_ms = fake_lag_outbound_budget;
}
// Held for less than the allowed time: keep holding.
hook->budget -= allowed_ms;
if (hook->budget < 0) {
hook->budget = 0;
hook->verdict = 1;
}
}
+54
View File
@@ -0,0 +1,54 @@
// Fake Lag — Adds an artificial delay to your packets.
// category: utility descriptor: 0x2ebcc0 settings block: 0x2ebeb8
// functions: gui fake_lag_gui, register fake_lag_register, status fake_lag_status
// implementation: src/logic/utility/fake_lag.cpp
#pragma once
#include "slinky/api.h"
S(str_delay); // "Delay"
S(str_conditions_in_fake_lag); // "Conditions"
S(str_mode_in_fake_lag); // "mode"
S(str_inbound_in_fake_lag); // "inbound"
S(str_outbound_in_fake_lag); // "outbound"
S(str_realtime_damage_in_fake_lag); // "realtime_damage"
S(str_require_weapon_in_fake_lag); // "require_weapon"
S(str_require_attack); // "require_attack"
S(str_require_ingame); // "require_ingame"
S(str_s_in_fake_lag); // "%s"
D(fake_lag_inbound_setting); // setting num "inbound"
D(fake_lag_outbound_setting); // setting num "outbound"
D(fake_lag_realtime_damage_setting); // setting bool "realtime_damage"
D(fake_lag_enum_option_labels_1); // enum option labels (const char *[])
D(fake_lag_mode_setting); // setting enum "mode"
extern "C" unsigned fake_lag_mode; // current value of setting "mode" (+0x30)
D(fake_lag_require_ingame_setting); // setting bool "require_ingame"
D(fake_lag_require_weapon_setting); // setting bool "require_weapon"
D(fake_lag_require_attack_setting); // setting bool "require_attack"
extern "C" void fake_lag_gui(void *gui, void *window) {
W_label(gui, window, str_delay);
W_enumw(window, gui, fake_lag_mode_setting);
W_slider(window, gui, fake_lag_inbound_setting);
W_slider(window, gui, fake_lag_outbound_setting);
W_bool(window, gui, fake_lag_realtime_damage_setting);
W_label(gui, window, str_conditions_in_fake_lag);
W_bool(window, gui, fake_lag_require_weapon_setting);
W_bool(window, gui, fake_lag_require_attack_setting);
W_bool(window, gui, fake_lag_require_ingame_setting);
}
extern "C" void fake_lag_register(void *module) {
R_enum(module, str_mode_in_fake_lag, fake_lag_mode_setting);
R_num(module, str_inbound_in_fake_lag, fake_lag_inbound_setting);
R_num(module, str_outbound_in_fake_lag, fake_lag_outbound_setting);
R_bool(module, str_realtime_damage_in_fake_lag, fake_lag_realtime_damage_setting);
R_bool(module, str_require_weapon_in_fake_lag, fake_lag_require_weapon_setting);
R_bool(module, str_require_attack, fake_lag_require_attack_setting);
R_bool(module, str_require_ingame, fake_lag_require_ingame_setting);
}
extern "C" void fake_lag_status(void *self) {
log_fmt(self, 0x20, str_s_in_fake_lag, ((const char **)fake_lag_enum_option_labels_1)[fake_lag_mode]);
}
+152
View File
@@ -0,0 +1,152 @@
// Friends - your friend list. Other modules leave friends alone.
//
// Friends are stored by player UUID in a sorted table. Every tick each player in the world
// is tagged (entity flag 4) when it is a friend; the combat modules check that tag.
// With "middle_click_add", middle-clicking a player adds or removes them.
//
// Callbacks:
// friends_on_middle_click_add middle click: add / remove the player under the crosshair
// friends_on_tick every tick: tag friends in the world (and update "last seen")
// friends_on_toggle module switched off: untag everyone
// friends_on_shutdown module unloaded: free the table
#include "slinky/engine.h"
#include "slinky/jids.h"
// A table key: the UUID (two 64-bit halves) and when we last saw them.
struct Key { unsigned long long hi, lo, seen, padding_18; }; // 0x20 bytes
struct Entry { char padding_00[0x10]; long long seen; }; // a table entry (same layout)
// A notification for the GUI ("friend added" / "friend removed").
struct Notice { int kind; int padding_04; unsigned char added; char rest[0x3f]; }; // 0x48 bytes
enum { NOTICE_FRIEND = 0x13 };
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" unsigned char friends_middle_click_add_value; // "middle_click_add"
// ---- module state ----
extern "C" char friends_module_descriptor[];
extern "C" void *friend_set_friend_table; // the sorted table (begin, end pointers)
extern "C" char friend_set_table_meta[];
// ---- game / engine functions ----
FN(void *, get_minecraft, (void *jvm));
FN(void *, java_get_minecraft_object_mouse_over, (void *jvm, void *minecraft));
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(void *, java_get_entity_uuid, (void *jvm, void *entity));
FN(unsigned long long, java_jni_call_long_method_uuid_get_most_significant_bits, (void *jvm, void *uuid));
FN(unsigned long long, java_jni_call_long_method_uuid_get_least_significant_bits, (void *jvm, void *uuid));
FN(long long, libc_time64, (void *t)); // current time (seconds)
FN(Entry *, binary_search, (void *table, int keysz, void *meta, void *key, void *hash)); // find an entry, or null
FN(void, sorted_insert, (void *table, int keysz, void *meta, void *key, void *hash));
FN(void, vector_erase_value, (void *table, int keysz, void *meta, void *entry));
FN(unsigned char, entity_flags_has, (void *jvm, void *entity, int mode)); // flag 2: bot
FN(void, dispatch_event, (void *ui, Notice *n));
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(void, entity_flags_set, (void *jvm, void *entity, int tag));
FN(void, entity_flags_clear, (void *jvm, void *entity, int tag));
FN(void, compare_friend_key, ()); // compares the UUID part of two keys
FN(void, libc_free, (void *ptr));
enum { FLAG_BOT = 2, FLAG_FRIEND = 4 };
static bool is_ourselves(Ctx *ctx, void *entity) {
JNIEnv *env = ((Jvm *)ctx->jvm)->env;
return (*env)->IsSameObject(env, ctx->player, entity);
}
// Middle click: add or remove the player under the crosshair.
extern "C" void friends_on_middle_click_add(void *jvm, void *mgr) {
if (friends_middle_click_add_value != 1)
return;
void *hit = java_get_minecraft_object_mouse_over(jvm, get_minecraft(jvm));
if (!hit)
return;
void *entity = java_get_moving_object_position_entity_hit(jvm, hit);
if (!entity)
return;
void *player = java_jni_is_instance_of_entity_other_player_mp(jvm, entity);
if (!player)
return;
void *uuid = java_get_entity_uuid(jvm, player);
Key key;
key.hi = java_jni_call_long_method_uuid_get_most_significant_bits(jvm, uuid);
key.lo = java_jni_call_long_method_uuid_get_least_significant_bits(jvm, uuid);
key.seen = libc_time64(nullptr);
key.padding_18 = 0;
Notice notice = {};
Entry *entry = binary_search(friend_set_friend_table, 0x20, friend_set_table_meta, &key, (void *)compare_friend_key);
if (entry) {
// Already a friend: remove.
notice.kind = NOTICE_FRIEND;
notice.added = 0;
vector_erase_value(friend_set_friend_table, 0x20, friend_set_table_meta, entry);
} else {
// Bots can't be friends.
if (entity_flags_has(jvm, player, FLAG_BOT))
return;
notice.kind = NOTICE_FRIEND;
notice.added = 1;
sorted_insert(&friend_set_friend_table, 0x20, friend_set_table_meta, &key, (void *)compare_friend_key);
}
dispatch_event(mgr, &notice);
}
// Every tick: tag the friends in the world.
extern "C" void friends_on_tick(Hook *hook) {
Ctx *ctx = hook->ctx;
if (!ctx->player)
return;
long long now = libc_time64(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);
if (is_ourselves(ctx, other))
continue;
void *uuid = java_get_entity_uuid(ctx->jvm, other);
alignas(16) Key key;
key.hi = java_jni_call_long_method_uuid_get_most_significant_bits(ctx->jvm, uuid);
key.lo = java_jni_call_long_method_uuid_get_least_significant_bits(ctx->jvm, uuid);
key.seen = 0;
key.padding_18 = 0;
Entry *entry = binary_search(friend_set_friend_table, 0x20, friend_set_table_meta, &key, (void *)compare_friend_key);
if (entry) {
entity_flags_set(ctx->jvm, other, FLAG_FRIEND);
entry->seen = now;
} else {
entity_flags_clear(ctx->jvm, other, FLAG_FRIEND);
}
}
}
// On disable: untag everyone.
extern "C" void friends_on_toggle(EvHook *hook) {
if (hook->ev != friends_module_descriptor || hook->on)
return;
Ctx *ctx = hook->ctx;
if (!ctx->world)
return;
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);
if (!is_ourselves(ctx, other))
entity_flags_clear(ctx->jvm, other, FLAG_FRIEND);
}
}
extern "C" void friends_on_shutdown(Hook *hook) {
libc_free(friend_set_friend_table);
// Clear the table's begin and end pointers.
*(__int128 *)&friend_set_friend_table = 0;
}
+23
View File
@@ -0,0 +1,23 @@
// Friends — Lets you mark other players as friendly.
// category: utility descriptor: 0x2f0038 settings block: 0x2f0230
// functions: gui friends_gui, register friends_register
// implementation: src/logic/utility/friends.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_friends); // "Main"
S(str_middle_click_add); // "middle_click_add"
S(str_friends_second); // "friends"
D(friends_middle_click_add_setting); // setting bool "middle_click_add"
D(friends_friends_setting); // setting kind2 "friends"
extern "C" void friends_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_friends);
W_bool(window, gui, friends_middle_click_add_setting);
}
extern "C" void friends_register(void *module) {
R_bool(module, str_middle_click_add, friends_middle_click_add_setting);
R_kind2(module, str_friends_second, friends_friends_setting);
}
+307
View File
@@ -0,0 +1,307 @@
// Inv Manager - sort your inventory automatically while it is open.
//
// For each armour slot and each hotbar slot, the settings say which kind of item belongs
// there (sword, blocks, bow, ...). While the inventory is open, the module finds the best
// such item, and clicks it into place: shift-click for armour, "number key" swaps for the
// hotbar, and pick-up / put-down for merging stacks. Clicks are spaced by "click_delay",
// longer for longer mouse moves ("scale_by_mouse_distance") and at random ("randomise").
//
// Functions:
// inv_manager_score_item_stack how good an item is for a slot
// inv_manager_tick every tick: the next click
// inv_manager_plan_step helper: find the best item for one hotbar slot
#include "slinky/engine.h"
#include "slinky/jids.h"
// ---- settings ----
extern "C" unsigned char inv_manager_try_paired_slot; // "swap_sides": also try the other hand's / side's kind
extern "C" char inv_manager_enum_slot_1[]; // per hotbar slot settings, 0x40 bytes each (+0x30 wanted kind)
extern "C" float inv_manager_start_delay; // ticks after opening the inventory
extern "C" float inv_manager_click_delay_b, inv_manager_click_delay_b_second; // click delay = first / second
extern "C" unsigned char inv_manager_randomise;
extern "C" unsigned char inv_manager_scale_by_mouse_distance;
// ---- game / engine functions ----
FN(void *, java_call_item_stack_get_item, (void *jvm, void *stack));
FN(int, java_call_static_item_get_id_from_item, (void *jvm, void *item));
FN(int, java_get_item_stack_metadata, (void *jvm, void *stack));
FN(void *, java_call_item_stack_get_enchantment_tag_list, (void *jvm, void *stack));
FN(unsigned char, java_call_item_stack_has_display_name, (void *jvm, void *stack));
FN(unsigned short, score_item_inventory_sorter_category, (void **s, int slot, int id, int dmg, void *nbt, unsigned char flag)); // score for a kind (0 = does not fit)
// How good the item stack is as kind `kind`. With "swap_sides", an item that does not fit
// may still score (lower) as the paired kind.
extern "C" unsigned inv_manager_score_item_stack(void **s, void *stack, int kind) {
void *item = java_call_item_stack_get_item(*s, stack);
if (!item)
return 0;
int item_id = java_call_static_item_get_id_from_item(*s, item);
int damage = java_get_item_stack_metadata(*s, stack);
void *enchantments = java_call_item_stack_get_enchantment_tag_list(*s, stack);
unsigned char named = java_call_item_stack_has_display_name(*s, stack);
unsigned score = score_item_inventory_sorter_category(s, kind, item_id, damage, enchantments, named);
if (inv_manager_try_paired_slot != 1)
return score;
if (score)
return score << 16; // a real fit always beats a paired one
int paired;
switch (kind) {
case 22: paired = 25; break;
case 17: paired = 7; break;
case 7: paired = 17; break;
default: return 0;
}
return score_item_inventory_sorter_category(s, paired, item_id, damage, enchantments, named);
}
struct Pair { float x, y; };
struct Range { float lo, hi; };
// The module's progress (all in one block of memory).
struct InvState {
int state; // what we are doing (see below)
int padding_04;
unsigned long long mask; // targets already handled
int action; // the planned click: 0 shift-click, 1 swap with hotbar `slot`, 2 pick up and put in `slot`
unsigned char slot, padding_15, padding_16, padding_17;
int saved; // state to go back to after the click
unsigned char sub; // current target within the state
unsigned char window; // window slot to click
unsigned char advance; // go to the next target after the click
unsigned char padding_1f;
float delay; // ticks until the next click
int padding_24;
Pair pos; // where the "mouse" is (for the delay)
};
enum InvStep {
STEP_ARMOUR = 0, // plan the armour slots
STEP_HOTBAR = 1, // plan the hotbar slots
STEP_DONE = 2,
STEP_CLICK = 3, // do the planned click
STEP_PUT_DOWN = 4, // (pick up action) put the stack down
STEP_DROP_REST = 5, // drop what is left on the cursor
};
struct InvHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
unsigned char busy; // +0x10 set to 1: we use the inventory this tick
};
// A planning function for one target: true when it planned a click.
typedef unsigned char (*Step)(Ctx *c, InvState *st);
extern "C" InvState inv_manager_rotation_walk; // the progress
extern "C" unsigned char *const inv_manager_slot_setting_ptrs[2]; // armour / hotbar part enabled
extern "C" const unsigned char inv_manager_targets_per_state[2]; // number of targets: armour, hotbar
extern "C" const Step ptr_to_plan_inventory_swap[2]; // planning function: armour, hotbar (inv_manager_plan_step)
FN(void *, get_current_screen, (void *jvm, void *object));
FN(unsigned char, java_jni_is_instance_of_gui_inventory, (void *jvm, void *g));
FN(void, java_gui_container_handle_mouse_click, (void *jvm, void *g, int slot, int button, int mode));
FN(Pair, slot_index, (int slot)); // screen position of a window slot
FN(float, rot_delta_length, (Pair a, Pair b)); // distance between two positions
FN(Range, rot_make_floats, (float lo, float hi));
FN(float, random_rotation, (Range r)); // random value in the range
FN(void *, java_get_entity_player_inventory, (void *jvm, void *entity_player));
FN(void *, java_get_inventory_player_main_inventory, (void *jvm, void *inventory_player));
FN(int, java_get_item_stack_stack_size, (void *jvm, void *stack));
FN(int, java_call_item_stack_get_max_stack_size, (void *jvm, void *stack));
FN(unsigned char, java_call_static_item_stack_are_item_stack_tags_equal, (void *jvm, void *item_stack, void *other_object));
// Move the "mouse" to `target`: wait the click delay (scaled by the distance / randomly).
static void move_to(Pair target) {
float delay = inv_manager_click_delay_b / inv_manager_click_delay_b_second;
if (inv_manager_scale_by_mouse_distance == 1) {
float distance = rot_delta_length(target, inv_manager_rotation_walk.pos) * 0.5f;
delay *= distance > 1.0f ? distance : 1.0f;
}
if (inv_manager_randomise == 1)
delay *= random_rotation(rot_make_floats(1.0f, 1.25f));
inv_manager_rotation_walk.delay = delay + inv_manager_rotation_walk.delay;
inv_manager_rotation_walk.pos = target;
}
extern "C" void inv_manager_tick(InvHook *hook) {
InvState &st = inv_manager_rotation_walk;
Ctx *ctx = hook->ctx;
// Inventory not open: get ready for next time (start delay, mouse in the middle).
void *screen = get_current_screen(ctx->jvm, ctx->minecraft);
if (!screen || !java_jni_is_instance_of_gui_inventory(ctx->jvm, screen)) {
__builtin_memset(&st, 0, 0x20);
st.delay = inv_manager_start_delay;
if (inv_manager_randomise == 1)
st.delay = random_rotation(rot_make_floats(1.0f, 1.5f)) * st.delay;
st.pos = slot_index(13);
return;
}
int state = st.state;
if (state == STEP_DONE)
return;
if (st.delay > 0.0f) {
st.delay += -1.0f;
if (st.delay > 0.0f)
return;
}
hook->busy = 1;
int button = 0, mode = 0;
for (;;) {
switch (state) {
case STEP_ARMOUR:
case STEP_HOTBAR:
// Plan the next target that needs a click.
if (*inv_manager_slot_setting_ptrs[state]) {
for (unsigned char targets = inv_manager_targets_per_state[state]; st.sub < targets; st.sub++) {
if (ptr_to_plan_inventory_swap[state](ctx, &st)) {
move_to(slot_index(st.window));
st.state = STEP_CLICK;
st.saved = state;
st.advance = state != STEP_HOTBAR;
return;
}
}
}
// All done here: next part (clear everything but the state).
st.state = ++state;
__builtin_memset((char *)&st + 4, 0, 0x1c);
continue;
case STEP_CLICK: {
int action = st.action;
unsigned char slot = st.slot;
if (action == 2) { // pick up
button = 0;
mode = 0;
} else if (action == 1) { // swap with hotbar slot (like pressing its number key)
button = slot;
mode = 2;
} else if (action == 0) { // shift-click
button = 0;
mode = 1;
}
java_gui_container_handle_mouse_click(ctx->jvm, screen, st.window, button, mode);
st.mask |= (long long)(1 << (st.sub & 31));
if (st.advance == 1)
st.sub++;
if (action == 2) {
// Then put it down in `slot`.
move_to(slot_index(slot));
st.state = STEP_PUT_DOWN;
st.window = slot;
return;
}
state = st.state = st.saved;
continue;
}
case STEP_PUT_DOWN: {
java_gui_container_handle_mouse_click(ctx->jvm, screen, st.window, 0, 0);
// Then move the mouse out of the window, to drop what did not fit.
Pair outside = st.pos;
outside.x += -2.0f;
move_to(outside);
st.state = STEP_DROP_REST;
return;
}
case STEP_DROP_REST:
java_gui_container_handle_mouse_click(ctx->jvm, screen, -999, 0, 0); // click outside the window
state = st.state = st.saved;
continue;
default:
return;
}
}
}
// An item's id and metadata as one number (0 for no item).
static unsigned long long item_key(Ctx *ctx, void *stack) {
void *item = java_call_item_stack_get_item(ctx->jvm, stack);
if (!item)
return 0;
unsigned item_id = java_call_static_item_get_id_from_item(ctx->jvm, item);
return ((unsigned long long)item_id << 32) | (unsigned long long)(long long)java_get_item_stack_metadata(ctx->jvm, stack);
}
// Plan hotbar slot `st->sub`: find the stack that is best there (score x count), or one that
// can be merged into the current stack. True when a click was planned.
extern "C" unsigned char inv_manager_plan_step(Ctx *ctx, InvState *st) {
unsigned target = st->sub;
int wanted_kind = *(int *)(inv_manager_enum_slot_1 + target * 0x40 + 0x30);
if (!wanted_kind)
return 0; // "any": leave it alone
void *items = java_get_inventory_player_main_inventory(ctx->jvm, java_get_entity_player_inventory(ctx->jvm, ctx->player));
JNIEnv *env = ((Jvm *)ctx->jvm)->env;
auto get = (*env)->GetObjectArrayElement;
// What is there now.
void *current = get(env, items, target);
int count = 0, max_count = 0;
unsigned long long key = 0;
unsigned score = 0;
if (current) {
count = java_get_item_stack_stack_size(ctx->jvm, current);
max_count = java_call_item_stack_get_max_stack_size(ctx->jvm, current);
key = item_key(ctx, current);
score = inv_manager_score_item_stack((void **)ctx, current, wanted_kind);
}
// Is there an empty slot in the main inventory (9..35)? (empty_slot == null)
void *empty_slot;
int i = 9;
for (;;) {
empty_slot = get(env, items, i);
if (!empty_slot || i == 35)
break;
i++;
}
if (count <= 0)
count = 0;
unsigned best = count * score;
unsigned best_slot = target;
unsigned char merge = 0;
for (unsigned j = 0; j < 36; j++) {
if (j == target || (st->mask >> j & 1))
continue;
void *stack = get(env, items, j);
if (!stack)
continue;
int n = java_get_item_stack_stack_size(ctx->jvm, stack);
unsigned long long other_key = item_key(ctx, stack);
// Value when merged into the current stack (same item, both not full).
unsigned merged = 0;
if (count < max_count && n < max_count && other_key == key && java_call_static_item_stack_are_item_stack_tags_equal(ctx->jvm, current, stack)) {
int total = count + n;
merged = (total < max_count ? total : max_count) * score;
}
unsigned value = inv_manager_score_item_stack((void **)ctx, stack, wanted_kind) * n;
bool use_merge = value - 1 < merged; // (value > 0 and merging is worth at least as much)
if (use_merge)
value = merged;
// Merging from the hotbar only when there is room for the rest.
if (value > best && (!empty_slot || j >= 9 || !use_merge)) {
best = value;
best_slot = j;
merge = use_merge;
}
}
if (best_slot != target) {
st->padding_15 = st->padding_16 = st->padding_17 = 0;
st->action = !merge; // merge: shift-click (0), else swap into the hotbar slot (1)
st->slot = merge ? 0 : target;
st->window = (int)best_slot >= 9 ? best_slot : best_slot + 36; // hotbar slots are 36..44 in the window
st->mask |= (long long)(1 << (target & 31));
return 1;
}
if (best)
st->mask |= (long long)(1 << (target & 31));
return 0;
}
+90
View File
@@ -0,0 +1,90 @@
// Inv Manager — Organises your inventory for you.
// category: utility descriptor: 0x2f4c40 settings block: 0x2f4e38
// functions: gui inv_manager_gui, register inv_manager_register
// implementation: src/logic/utility/inv_manager.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_inv_manager); // "Main"
S(str_equip_armor); // "Equip armor"
S(str_sort_hotbar); // "Sort hotbar"
S(str_delay_after_open_in_inv_manager); // "delay_after_open"
S(str_speed_in_inv_manager); // "speed"
S(str_smart_speed_in_inv_manager); // "smart_speed"
S(str_randomize_in_inv_manager); // "randomize"
S(str_equip_armor_in_inv_manager); // "equip_armor"
S(str_sort_hotbar_in_inv_manager); // "sort_hotbar"
S(str_sort_hotbar_fallback); // "sort_hotbar_fallback"
D(inv_manager_delay_after_open_setting); // setting num "delay_after_open"
D(inv_manager_equip_armor_setting); // setting bool "equip_armor"
D(inv_manager_sort_hotbar_setting); // setting bool "sort_hotbar"
D(inv_manager_sort_hotbar); // current value of setting "sort_hotbar" (+0x18)
D(inv_manager_enum_slot_1); // setting enum (slot)
D(inv_manager_enum_slot_2); // setting enum (slot)
D(inv_manager_enum_slot_3); // setting enum (slot)
D(inv_manager_enum_slot_4); // setting enum (slot)
D(inv_manager_enum_slot_5); // setting enum (slot)
D(inv_manager_enum_slot_6); // setting enum (slot)
D(inv_manager_enum_slot_7); // setting enum (slot)
D(inv_manager_enum_slot_8); // setting enum (slot)
D(inv_manager_enum_slot_9); // setting enum (slot)
D(inv_manager_sort_hotbar_fallback_setting); // setting bool "sort_hotbar_fallback"
D(inv_manager_randomize_setting); // setting bool "randomize"
D(inv_manager_speed_setting); // setting num "speed"
D(inv_manager_smart_speed_setting); // setting bool "smart_speed"
extern "C" void inv_manager_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_inv_manager);
W_slider(window, gui, inv_manager_delay_after_open_setting);
W_slider(window, gui, inv_manager_speed_setting);
W_bool(window, gui, inv_manager_smart_speed_setting);
W_bool(window, gui, inv_manager_randomize_setting);
W_label(gui, window, str_equip_armor);
W_bool(window, gui, inv_manager_equip_armor_setting);
W_label(gui, window, str_sort_hotbar);
W_bool(window, gui, inv_manager_sort_hotbar_setting);
if (*(unsigned char *)inv_manager_sort_hotbar == 1) {
W_bool(window, gui, inv_manager_sort_hotbar_fallback_setting);
W_enumw(window, gui, inv_manager_enum_slot_1);
W_enumw(window, gui, inv_manager_enum_slot_2);
W_enumw(window, gui, inv_manager_enum_slot_3);
W_enumw(window, gui, inv_manager_enum_slot_4);
W_enumw(window, gui, inv_manager_enum_slot_5);
W_enumw(window, gui, inv_manager_enum_slot_6);
W_enumw(window, gui, inv_manager_enum_slot_7);
W_enumw(window, gui, inv_manager_enum_slot_8);
W_enumw(window, gui, inv_manager_enum_slot_9);
} else {
EPILOG_NOP();
}
}
extern "C" void inv_manager_register(void *module) {
char slot[2];
R_num(module, str_delay_after_open_in_inv_manager, inv_manager_delay_after_open_setting);
R_num(module, str_speed_in_inv_manager, inv_manager_speed_setting);
R_bool(module, str_smart_speed_in_inv_manager, inv_manager_smart_speed_setting);
R_bool(module, str_randomize_in_inv_manager, inv_manager_randomize_setting);
R_bool(module, str_equip_armor_in_inv_manager, inv_manager_equip_armor_setting);
R_bool(module, str_sort_hotbar_in_inv_manager, inv_manager_sort_hotbar_setting);
R_bool(module, str_sort_hotbar_fallback, inv_manager_sort_hotbar_fallback_setting);
*(__int16 *)slot = 0x31;
R_enum(module, slot, inv_manager_enum_slot_1);
*(__int16 *)slot = 0x32;
R_enum(module, slot, inv_manager_enum_slot_2);
*(__int16 *)slot = 0x33;
R_enum(module, slot, inv_manager_enum_slot_3);
*(__int16 *)slot = 0x34;
R_enum(module, slot, inv_manager_enum_slot_4);
*(__int16 *)slot = 0x35;
R_enum(module, slot, inv_manager_enum_slot_5);
*(__int16 *)slot = 0x36;
R_enum(module, slot, inv_manager_enum_slot_6);
*(__int16 *)slot = 0x37;
R_enum(module, slot, inv_manager_enum_slot_7);
*(__int16 *)slot = 0x38;
R_enum(module, slot, inv_manager_enum_slot_8);
*(__int16 *)slot = 0x39;
R_enum(module, slot, inv_manager_enum_slot_9);
}
+43
View File
@@ -0,0 +1,43 @@
// Item Use Fix - let you use an item while mining.
//
// Minecraft won't use an item (right click) while you are hitting a block. Just before the
// right click is handled, this module clears the "hitting a block" flag, and puts it back
// right after.
//
// Callbacks (descriptor slots +0x128 / +0x138):
// item_use_fix_clear_hitting_block before the right click
// item_use_fix_restore_hitting_block after the right click
#include "slinky/engine.h"
// ---- module state ----
extern "C" unsigned char item_use_fix_item_use_flag; // 1: we cleared the flag and must restore it
struct UseState {
char padding_00[8];
Ctx *ctx; // +0x08 game context
unsigned char skip; // +0x10 non-zero: not a real click
};
// ---- game / engine functions ----
FN(void *, java_get_minecraft_player_controller, (void *jvm, void *minecraft));
FN(unsigned char, java_get_player_controller_mp_is_hitting_block, (void *jvm, void *player_controller_mp));
FN(void, java_set_player_controller_mp_is_hitting_block, (void *jvm, void *player_controller_mp, int on));
extern "C" void item_use_fix_clear_hitting_block(UseState *s) {
if (s->skip != 0)
return;
Ctx *ctx = s->ctx;
void *controller = java_get_minecraft_player_controller(ctx->jvm, ctx->minecraft);
unsigned char hitting = java_get_player_controller_mp_is_hitting_block(ctx->jvm, controller);
item_use_fix_item_use_flag = hitting != 0;
if (hitting)
java_set_player_controller_mp_is_hitting_block(ctx->jvm, controller, 0);
}
extern "C" void item_use_fix_restore_hitting_block(UseState *s) {
if (item_use_fix_item_use_flag != 1 || s->skip != 0)
return;
Ctx *ctx = s->ctx;
void *controller = java_get_minecraft_player_controller(ctx->jvm, ctx->minecraft);
java_set_player_controller_mp_is_hitting_block(ctx->jvm, controller, item_use_fix_item_use_flag);
}
+6
View File
@@ -0,0 +1,6 @@
// Item Use Fix — Allows using items while breaking blocks.
// category: utility descriptor: 0x2f2f48 settings block: none
// implementation: src/logic/utility/item_use_fix.cpp
// no GUI callback: this module is engine-side and has no settings pane.
#pragma once
#include "slinky/api.h"
+48
View File
@@ -0,0 +1,48 @@
// No Hit Delay - remove the wait after a missed click.
//
// When you click at nothing, Minecraft blocks attacks for 10 ticks. This module resets that
// wait, so every click counts.
// mode 0: always
// mode 1: only when the crosshair is on something; clicks at nothing just swing the arm
//
// Callback (descriptor slot +0x128):
// no_hit_delay_on_attack before an attack
#include "slinky/engine.h"
// ---- settings ----
extern "C" unsigned no_hit_delay_mode; // "mode"
struct HitState {
char padding_00[8];
Ctx *ctx; // +0x08 game context
unsigned char on; // +0x10 1 = an attack click
};
// ---- game / engine functions ----
FN(int, java_get_minecraft_left_click_counter, (void *jvm, void *minecraft)); // ticks attacks are blocked
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
FN(void, java_set_minecraft_left_click_counter, (void *jvm, void *minecraft, int value));
FN(bool, 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));
extern "C" void no_hit_delay_on_attack(HitState *s) {
if (s->on != 1)
return;
Ctx *ctx = s->ctx;
if (**(int **)ctx->jvm == 0)
return; // the JVM handle is not ready
if (java_get_minecraft_left_click_counter(ctx->jvm, ctx->minecraft) <= 0)
return; // not blocked
if (no_hit_delay_mode == 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) == 0) {
// Clicking at nothing: only swing the arm.
if (!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);
return;
}
}
java_set_minecraft_left_click_counter(ctx->jvm, ctx->minecraft, 0);
}
+28
View File
@@ -0,0 +1,28 @@
// No Hit Delay — Removes 1.8 swing delay.
// category: utility descriptor: 0x2f0b70 settings block: 0x2f0d68
// functions: gui no_hit_delay_gui, register no_hit_delay_register, status no_hit_delay_status
// implementation: src/logic/utility/no_hit_delay.cpp
#pragma once
#include "slinky/api.h"
S(str_in_game_in_no_hit_delay); // "In-game"
S(str_mode_in_no_hit_delay); // "mode"
S(str_s_in_no_hit_delay); // "%s"
D(no_hit_delay_enum_option_labels_1); // enum option labels (const char *[])
D(no_hit_delay_mode_setting); // setting enum "mode"
extern "C" unsigned no_hit_delay_mode; // current value of setting "mode" (+0x30)
extern "C" void no_hit_delay_gui(void *gui, void *window) {
W_label(gui, window, str_in_game_in_no_hit_delay);
W_enumw(window, gui, no_hit_delay_mode_setting);
}
extern "C" void no_hit_delay_register(void *module) {
R_enum(module, str_mode_in_no_hit_delay, no_hit_delay_mode_setting);
}
extern "C" void no_hit_delay_status(void *self) {
log_fmt(self, 0x20, str_s_in_no_hit_delay, ((const char **)no_hit_delay_enum_option_labels_1)[no_hit_delay_mode]);
}
+79
View File
@@ -0,0 +1,79 @@
// No Item Release - keep using an item (eating, blocking, ...) on the server after you let go.
//
// When you stop using an item, the game sends a "release use item" packet. This module
// cancels that packet for the items chosen by "mode", so the server thinks you are still
// eating / blocking.
// mode 0: swords only mode 1: everything except swords other: everything
// Bows and fishing rods are never affected (releasing is how they work).
//
// Callback (descriptor slot +0x78):
// no_item_release_on_packet_sent every outgoing packet
#include "slinky/engine.h"
// ---- settings ----
extern "C" unsigned no_item_release_mode; // "mode"
// ---- module state ----
// 1 after a "use item" packet for an affected item: cancel the next release.
extern "C" unsigned char no_item_release_release_lock_flag;
struct RelState {
char padding_00[8];
void *w; // +0x08 JVM handle
void *x; // +0x10 the packet
char padding_18[0xc];
int state; // +0x24 set to 2 to cancel the packet
};
// ---- game / engine functions ----
FN(void *, java_jni_is_instance_of_c08_packet_player_block_placement, (void *w, void *candidate)); // "use item" packet, or null
FN(void *, java_get_c08_packet_player_block_placement_stack, (void *w, void *c08_packet_player_block_placement));
FN(void *, java_call_item_stack_get_item, (void *w, void *item_stack));
FN(int, java_call_static_item_get_id_from_item, (void *w, void *item));
FN(void *, java_jni_is_instance_of_c07_packet_player_digging, (void *w, void *candidate)); // dig / release packet, or null
FN(int, java_c07_packet_player_digging_status, (void *w, void *object)); // 5 = release use item
enum { ITEM_BOW = 261, ITEM_FISHING_ROD = 346 };
extern "C" void no_item_release_on_packet_sent(RelState *s) {
void *use_packet = java_jni_is_instance_of_c08_packet_player_block_placement(s->w, s->x);
void *jvm = s->w;
if (use_packet) {
// Starting to use an item: should its release be cancelled?
unsigned char lock = 0;
void *stack = java_get_c08_packet_player_block_placement_stack(jvm, use_packet);
if (stack) {
void *item = java_call_item_stack_get_item(jvm, stack);
if (item) {
bool affected;
switch (java_call_static_item_get_id_from_item(jvm, item)) {
case 267: case 268: case 272: case 276: case 283: // swords
affected = no_item_release_mode != 1;
break;
case ITEM_BOW:
case ITEM_FISHING_ROD:
affected = false;
break;
default:
affected = no_item_release_mode != 0;
break;
}
if (affected) {
int id = java_call_static_item_get_id_from_item(jvm, item);
lock = (id != ITEM_FISHING_ROD) & (id != ITEM_BOW);
}
}
}
no_item_release_release_lock_flag = lock;
return;
}
// The release: cancel it once.
void *dig_packet = java_jni_is_instance_of_c07_packet_player_digging(jvm, s->x);
if (!dig_packet || no_item_release_release_lock_flag == 0)
return;
if (java_c07_packet_player_digging_status(s->w, dig_packet) == 5)
s->state = 2;
no_item_release_release_lock_flag = 0;
}
+28
View File
@@ -0,0 +1,28 @@
// No Item Release — Hides item release from server.
// category: utility descriptor: 0x2ec390 settings block: 0x2ec588
// functions: gui no_item_release_gui, register no_item_release_register, status no_item_release_status
// implementation: src/logic/utility/no_item_release.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_no_item_release); // "Main"
S(str_mode_in_no_item_release); // "mode"
S(str_s_in_no_item_release); // "%s"
D(no_item_release_enum_option_labels_1); // enum option labels (const char *[])
D(no_item_release_mode_setting); // setting enum "mode"
extern "C" unsigned no_item_release_mode; // current value of setting "mode" (+0x30)
extern "C" void no_item_release_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_no_item_release);
W_enumw(window, gui, no_item_release_mode_setting);
}
extern "C" void no_item_release_register(void *module) {
R_enum(module, str_mode_in_no_item_release, no_item_release_mode_setting);
}
extern "C" void no_item_release_status(void *self) {
log_fmt(self, 0x20, str_s_in_no_item_release, ((const char **)no_item_release_enum_option_labels_1)[no_item_release_mode]);
}
+63
View File
@@ -0,0 +1,63 @@
// No Use Delay - stop using an item as soon as it is done.
//
// While you hold right click, Minecraft starts using the item again right after it finished
// (eating the next piece of food, ...). This module lets go of the use key for a tick once the
// item use is complete, so you can do something else straight away. With "allow_desync" it
// also lets go as soon as the client says the use is over.
//
// Callback (descriptor slot +0x168):
// no_use_delay_on_late_tick every tick
#include "slinky/engine.h"
// ---- settings ----
extern "C" unsigned char no_use_delay_allow_desync_value; // "allow_desync"
// ---- module state ----
extern "C" int no_use_delay_remaining_ticks; // ticks left of the current item use
extern "C" int no_use_delay_last_seen_slot_state; // hotbar slot last tick
struct DelayState { char padding_00[8]; Ctx *ctx; }; // +0x08 game context
// ---- game / engine functions ----
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, is_key_down, (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, 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, int value));
FN(int, java_get_entity_player_item_in_use_count, (void *jvm, void *entity_player)); // ticks left of the item use
extern "C" void no_use_delay_on_late_tick(DelayState *s) {
Ctx *ctx = s->ctx;
if (ctx->in_game == 0) {
no_use_delay_remaining_ticks = 0;
return;
}
void *use_key = java_get_game_settings_use_item_key(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft));
unsigned char using_key = is_key_down(ctx->jvm, use_key);
// Switched slot: start over and give the key back.
int slot = java_get_inventory_player_current_item(ctx->jvm, java_get_entity_player_inventory(ctx->jvm, ctx->player));
if (slot != no_use_delay_last_seen_slot_state) {
no_use_delay_remaining_ticks = 0;
no_use_delay_last_seen_slot_state = slot;
java_set_key_binding_pressed(ctx->jvm, use_key, java_get_key_binding_key_code(ctx->jvm, use_key));
}
if (!using_key)
return;
int use_ticks_left = java_get_entity_player_item_in_use_count(ctx->jvm, ctx->player);
int countdown = no_use_delay_remaining_ticks;
if (countdown <= 0) {
// A new use started: count its length.
no_use_delay_remaining_ticks = use_ticks_left;
return;
}
countdown--;
no_use_delay_remaining_ticks = countdown;
// Done (or, with "allow_desync", done on the client): let go of the use key.
if (countdown != 0 && !((use_ticks_left == 0) & no_use_delay_allow_desync_value))
return;
java_set_key_binding_pressed(ctx->jvm, use_key, 0);
}
+20
View File
@@ -0,0 +1,20 @@
// No Use Delay — Removes vanilla delay when consuming items.
// category: utility descriptor: 0x2f1210 settings block: 0x2f1408
// functions: gui no_use_delay_gui, register no_use_delay_register
// implementation: src/logic/utility/no_use_delay.cpp
#pragma once
#include "slinky/api.h"
S(str_main_in_no_use_delay); // "Main"
S(str_allow_desync); // "allow_desync"
D(no_use_delay_allow_desync_setting); // setting bool "allow_desync"
extern "C" void no_use_delay_gui(void *gui, void *window) {
W_label(gui, window, str_main_in_no_use_delay);
W_bool(window, gui, no_use_delay_allow_desync_setting);
}
extern "C" void no_use_delay_register(void *module) {
R_bool(module, str_allow_desync, no_use_delay_allow_desync_setting);
}
+30
View File
@@ -0,0 +1,30 @@
// Ping Fix - drop keep-alive packets in both directions.
//
// The server measures your ping with keep-alive packets. Dropping them stops it from
// measuring (and from seeing the delays other modules add).
//
// Callbacks (descriptor slots +0x68 / +0x78):
// ping_fix_drop_incoming_keepalive every incoming packet
// ping_fix_drop_outgoing_keepalive every outgoing packet
#include "slinky/engine.h"
struct PingState {
char padding_00[8];
void *jvm; // +0x08 JVM handle
void *packet; // +0x10 the packet
char padding_18[0xc];
int state; // +0x24 set to 3 to drop the packet
};
FN(void *, java_jni_is_instance_of_s00_packet_keep_alive, (void *jvm, void *candidate));
FN(void *, java_jni_is_instance_of_c00_packet_keep_alive, (void *jvm, void *candidate));
extern "C" void ping_fix_drop_incoming_keepalive(PingState *s) {
if (java_jni_is_instance_of_s00_packet_keep_alive(s->jvm, s->packet))
s->state = 3;
}
extern "C" void ping_fix_drop_outgoing_keepalive(PingState *s) {
if (java_jni_is_instance_of_c00_packet_keep_alive(s->jvm, s->packet))
s->state = 3;
}
+6
View File
@@ -0,0 +1,6 @@
// Ping Fix — Shows your real ping while using lag mods.
// category: utility descriptor: 0x2f0dd0 settings block: none
// implementation: src/logic/utility/ping_fix.cpp
// no GUI callback: this module is engine-side and has no settings pane.
#pragma once
#include "slinky/api.h"
+255
View File
@@ -0,0 +1,255 @@
// Refill - fill the empty hotbar slots with soup / healing potions from the inventory.
//
// The module opens your inventory, shift-clicks soups (and with "refill_potion" splash
// potions) from the inventory into the hotbar until it is full, then closes the inventory
// and switches itself off. Clicks are spaced like a human's: slower for slots further away
// on screen ("distance_based_delay"), with random variation.
//
// Callbacks:
// refill_enable switched on: start over
// refill_classify_27_main helper: sort the 27 inventory slots by what they hold
// refill_on_inventory_tick every tick: the next step
#include "slinky/engine.h"
struct Range { float lo, hi; };
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 InvHook {
char padding_00[8];
Ctx *ctx; // +0x08 game context
unsigned char handled; // +0x10 set to 1: we use the inventory screen this tick
};
// ---- settings ----
extern "C" unsigned char refill_refill_potion; // also move splash potions
extern "C" float refill_open_delay_setting; // "open_delay": ticks after opening
extern "C" float refill_close_delay_setting; // "close_delay": ticks before closing
extern "C" float refill_speed_value; // "speed"
extern "C" unsigned char refill_distance_based_delay; // slower for slots further away
extern "C" unsigned refill_click_button_mode; // mouse button: 0 left, 1 right, 2 random
// ---- module state ----
extern "C" char refill_module_descriptor[];
// Slot class numbers (see refill_classify_27_main).
extern "C" unsigned char refill_soup_class_offset;
extern "C" unsigned char refill_non_health_potion_class_offset;
extern "C" unsigned char refill_slot_classes[27]; // class of each inventory slot (9..35)
// What to do next.
enum RefillStep {
STEP_OPEN = 0, // open the inventory
STEP_START = 1, // inventory open: pick where the "mouse" starts
STEP_CHOOSE_SLOT = 2, // pick the next slot to move
STEP_CLICK = 3, // shift-click it
STEP_DONE = 4, // close the inventory and switch off
};
extern "C" int refill_pending_action;
extern "C" float refill_step_delay; // ticks until the next step
extern "C" int refill_last_slot; // the slot the "mouse" is on
extern "C" float refill_cell_angle; // preferred direction to the next slot
extern "C" int refill_slot_being_moved;
extern "C" int refill_random_button;
extern "C" char refill_open_delay_timer[], refill_close_delay_timer[], refill_random_walk_1[], refill_random_walk_2[], refill_gauss_rng_state[], refill_random_walk_3[]; // random states
// ---- game / engine functions ----
FN(void *, get_current_screen, (void *jvm, void *object));
FN(unsigned char, java_jni_is_instance_of_gui_inventory, (void *jvm, void *screen));
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)); // random yes/no
FN(float, random_rotation, (Range r)); // random value in the range
FN(float, gauss_random, (void *st)); // normally distributed random number
FN(int, refill_pick_inventory_cell, (int last, float bias, float *dist)); // next slot to move (or -1), and its distance
FN(void, refill_disable_and_close_screen, (Ctx *ctx));
FN(void *, get_game_settings, (void *jvm, void *object));
FN(void *, get_game_screen, (void *jvm, void *object)); // here: the inventory key
FN(void, java_increment_key_binding_press_time, (void *jvm, void *key_binding));
FN(void, java_gui_container_handle_mouse_click, (void *jvm, void *screen, int slot, int button, int mode)); // mode 1 = shift-click
FN(void, queue_module_toggle, (void *module_manager, void *module, int enabled));
FN(void, keyboard_send_key, (void *jvm, void *screen, int x, int y)); // (0, 1) = escape: close the screen
FN(void *, java_get_entity_player_inventory, (void *jvm, void *entity_player));
FN(void *, java_call_iinventory_get_stack_in_slot, (void *jvm, void *inv, int slot));
FN(void *, java_call_item_stack_get_item, (void *jvm, void *stack));
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));
enum { ITEM_MUSHROOM_STEW = 282, ITEM_POTION = 373, POTION_SPLASH_FLAG = 0x4000, POTION_EFFECT_HEALING = 5 };
extern "C" void refill_enable(EvHook *hook) {
if (hook->ev != refill_module_descriptor || hook->on != 1)
return;
refill_pending_action = STEP_OPEN;
}
// Sort the 27 inventory slots (9..35) by what they hold:
// 0 = empty, 1 = something else, 2 = splash healing potion,
// refill_non_health_potion_class_offset + 1 = another splash potion, refill_soup_class_offset + 1 = soup
extern "C" void refill_classify_27_main(Ctx *ctx) {
void *inventory = java_get_entity_player_inventory(ctx->jvm, ctx->player);
for (long i = 0; i != 27; i++) {
unsigned char slot_class = 0;
void *stack = java_call_iinventory_get_stack_in_slot(ctx->jvm, inventory, (int)i + 9);
if (stack) {
void *jvm = ctx->jvm;
void *item = java_call_item_stack_get_item(jvm, stack);
int item_id = item ? java_call_static_item_get_id_from_item(jvm, item) : 0;
if (item_id) {
switch (item_id) {
case ITEM_POTION:
slot_class = 1;
if (refill_refill_potion == 1) {
unsigned damage = java_get_item_stack_metadata(jvm, stack);
if (damage & POTION_SPLASH_FLAG) {
slot_class = 2;
if ((damage & 0xf) != POTION_EFFECT_HEALING)
slot_class = refill_non_health_potion_class_offset + 1;
}
}
break;
case ITEM_MUSHROOM_STEW:
slot_class = refill_soup_class_offset + 1;
break;
default:
slot_class = 1;
break;
}
}
}
refill_slot_classes[i] = slot_class;
}
}
// Wait `base` ticks, minus up to 2 at random.
static void add_delay(float base, char *random_state) {
double delay = (double)base - (double)walk_update(random_state, rot_make_floats(0.0f, 2.0f), 30.0);
delay = delay > 0.0 ? delay : 0.0;
refill_step_delay = (float)((double)refill_step_delay + delay);
}
// Is there an empty slot in the hotbar?
static bool hotbar_has_space(Ctx *ctx) {
void *inventory = java_get_entity_player_inventory(ctx->jvm, ctx->player);
for (int i = 0; i < 9; i++) {
void *stack = java_call_iinventory_get_stack_in_slot(ctx->jvm, inventory, i);
if (!stack)
return true;
void *item = java_call_item_stack_get_item(ctx->jvm, stack);
if (!item || !java_call_static_item_get_id_from_item(ctx->jvm, item))
return true;
}
return false;
}
// Switch off and close the screen.
static void finish(Ctx *ctx) {
queue_module_toggle(ctx->module_manager, refill_module_descriptor, 0);
void *screen = get_current_screen(ctx->jvm, ctx->minecraft);
if (screen)
keyboard_send_key(ctx->jvm, screen, 0, 1);
}
extern "C" void refill_on_inventory_tick(InvHook *hook) {
Ctx *ctx = hook->ctx;
void *screen = get_current_screen(ctx->jvm, ctx->minecraft);
if (refill_pending_action != STEP_OPEN) {
// The player closed the inventory: stop.
if (!screen || !java_jni_is_instance_of_gui_inventory(ctx->jvm, screen)) {
finish(ctx);
return;
}
hook->handled = 1;
}
// Wait for the delay.
float delay = refill_step_delay;
if (delay > 0.0f) {
refill_step_delay = delay + -1.0f;
return;
}
if (!(0.0f >= delay))
return;
// Do steps until one needs a delay.
int button = 0;
for (;;) {
if (refill_pending_action == STEP_DONE) {
finish(ctx);
return;
}
if (!ctx->player || !hotbar_has_space(ctx))
break; // hotbar full: done
switch (refill_pending_action) {
case STEP_OPEN: {
refill_pending_action = STEP_START;
if (screen)
return;
refill_classify_27_main(ctx);
float distance;
if (refill_pick_inventory_cell(refill_last_slot, refill_cell_angle, &distance) == -1) {
refill_disable_and_close_screen(ctx); // nothing to move
return;
}
java_increment_key_binding_press_time(ctx->jvm, get_game_screen(ctx->jvm, get_game_settings(ctx->jvm, ctx->minecraft))); // open the inventory
return;
}
case STEP_START:
refill_last_slot = (int)random_rotation(rot_make_floats(0.0f, 27.0f));
refill_cell_angle = random_rotation(rot_make_floats(0.0f, 3.14159265f));
refill_pending_action = STEP_CHOOSE_SLOT;
add_delay(refill_open_delay_setting, refill_open_delay_timer);
break;
case STEP_CHOOSE_SLOT: {
float distance;
int slot = refill_pick_inventory_cell(refill_last_slot, refill_cell_angle, &distance);
refill_slot_being_moved = slot;
if (slot == -1) {
add_delay(refill_close_delay_setting, refill_close_delay_timer);
refill_pending_action = STEP_DONE;
return;
}
// Time to move the mouse there: distance / speed, with random variation
// (+-20% drift, gaussian 30%, now and then 1.4-1.8x slower).
float speed = walk_update(refill_random_walk_1, rot_make_floats(0.8f, 1.2f), 30.0) * refill_speed_value;
speed = (float)((double)speed * ((double)gauss_random(refill_gauss_rng_state) * 0.3 + 1.0));
if (walk_should_change(refill_random_walk_2, rot_make_floats(0.04f, 0.08f), 30.0))
speed /= random_rotation(rot_make_floats(1.4f, 1.8f));
float how_far = refill_distance_based_delay ? distance : 1.0f;
refill_step_delay = how_far / speed + refill_step_delay;
refill_last_slot = refill_slot_being_moved;
refill_pending_action = STEP_CLICK;
break;
}
case STEP_CLICK: {
unsigned mode = refill_click_button_mode;
if (mode < 2) {
button = (int)mode;
} else if (mode == 2) {
button = refill_random_button;
if (walk_should_change(refill_random_walk_3, rot_make_floats(0.9f, 1.0f), 10.0))
refill_random_button = refill_random_button == 0;
}
java_gui_container_handle_mouse_click(ctx->jvm, screen, refill_slot_being_moved + 9, button, 1);
refill_slot_classes[refill_slot_being_moved] = 0;
refill_pending_action = STEP_CHOOSE_SLOT;
break;
}
}
if (!(0.0f >= refill_step_delay))
return;
}
// Hotbar full: close after "close_delay".
add_delay(refill_close_delay_setting, refill_close_delay_timer);
refill_pending_action = STEP_DONE;
if (!(0.0f >= refill_step_delay))
return;
finish(ctx);
}
+53
View File
@@ -0,0 +1,53 @@
// Refill — Automatically moves items into your hotbar.
// category: utility descriptor: 0x2eed90 settings block: 0x2eef88
// functions: gui refill_gui, register refill_register
// implementation: src/logic/utility/refill.cpp
#pragma once
#include "slinky/api.h"
S(str_items_in_refill); // "Items"
S(str_clicks); // "Clicks"
S(str_refill_potion); // "refill_potion"
S(str_refill_potion_non_health); // "refill_potion_non_health"
S(str_refill_soup); // "refill_soup"
S(str_simulate_button_in_refill); // "simulate_button"
S(str_delay_after_open_in_refill); // "delay_after_open"
S(str_delay_before_close_in_refill); // "delay_before_close"
S(str_speed_in_refill); // "speed"
S(str_smart_speed_in_refill); // "smart_speed"
D(refill_delay_before_close_setting); // setting num "delay_before_close"
D(refill_delay_after_open_setting); // setting num "delay_after_open"
D(refill_speed_setting); // setting num "speed"
D(refill_refill_soup_setting); // setting bool "refill_soup"
D(refill_refill_potion_setting); // setting bool "refill_potion"
D(refill_refill_potion); // current value of setting "refill_potion" (+0x18)
D(refill_refill_potion_non_health_setting); // setting bool "refill_potion_non_health"
D(refill_smart_speed_setting); // setting bool "smart_speed"
D(refill_simulate_button_setting); // setting enum "simulate_button"
extern "C" void refill_gui(void *gui, void *window) {
W_label(gui, window, str_items_in_refill);
W_bool(window, gui, refill_refill_potion_setting);
if (*(unsigned char *)refill_refill_potion == 1) {
W_bool(window, gui, refill_refill_potion_non_health_setting);
}
W_bool(window, gui, refill_refill_soup_setting);
W_label(gui, window, str_clicks);
W_enumw(window, gui, refill_simulate_button_setting);
W_slider(window, gui, refill_delay_after_open_setting);
W_slider(window, gui, refill_delay_before_close_setting);
W_slider(window, gui, refill_speed_setting);
W_bool(window, gui, refill_smart_speed_setting);
}
extern "C" void refill_register(void *module) {
R_bool(module, str_refill_potion, refill_refill_potion_setting);
R_bool(module, str_refill_potion_non_health, refill_refill_potion_non_health_setting);
R_bool(module, str_refill_soup, refill_refill_soup_setting);
R_enum(module, str_simulate_button_in_refill, refill_simulate_button_setting);
R_num(module, str_delay_after_open_in_refill, refill_delay_after_open_setting);
R_num(module, str_delay_before_close_in_refill, refill_delay_before_close_setting);
R_num(module, str_speed_in_refill, refill_speed_setting);
R_bool(module, str_smart_speed_in_refill, refill_smart_speed_setting);
}
Loaded 100 of 621 files, more files were not shown because too many files have changed in this diff. Show more