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

+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);
}