Skip to content

Commit

Permalink
Updated cheat_jetpack
Browse files Browse the repository at this point in the history
Fixed unintended behavior on initial jump
Added freeze in midair while crouching
  • Loading branch information
twist84 committed Sep 24, 2024
1 parent 3552896 commit dad1c7e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 59 deletions.
37 changes: 19 additions & 18 deletions game/source/game/player_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,27 +437,28 @@ void __cdecl player_control_get_controller_input_for_jetpack(e_input_user_index
{
player_control_get_controller_input(input_user_index, controller_index, world_seconds_elapsed, game_seconds_elapsed, input_states, input);

if (cheat.jetpack)
{
TLS_DATA_GET_VALUE_REFERENCE(player_control_globals);
if (!cheat.jetpack)
return;

long unit_index = player_control_globals->input_states[controller_index].unit_index;
if (biped_datum* biped = (biped_datum*)object_get_and_verify_type(unit_index, _object_mask_biped))
{
bool v0 = false;
if (input_states[controller_index]->get_button(_button_action_jump).down_frames() && mover_get_motor_program(unit_index) == 1)
{
bool v1 = TEST_BIT(biped->unit.unit_control_flags, 1);
real jump_control_ticks = (real)biped->biped.jump_control_ticks;
real v2 = (real)game_tick_rate() / 15.0f;
bool v3 = v2 > jump_control_ticks;
if ((v1 && v3) || TEST_BIT(biped->unit.unit_control_flags, 15))
v0 = true;
}
TLS_DATA_GET_VALUE_REFERENCE(player_control_globals);

SET_BIT(input->control_flags, 15, v0);
}
long unit_index = player_control_globals->input_states[controller_index].unit_index;
biped_datum* biped = biped_get(unit_index);
if (!biped)
return;

bool v0 = false;
if (input_states[controller_index]->get_button(_button_action_jump).down_frames() && mover_get_motor_program(unit_index) == 1)
{
bool v1 = TEST_BIT(biped->unit.unit_control_flags, _unit_control_jump_bit);
real jump_control_ticks = (real)biped->biped.jump_control_ticks;
real v2 = (real)game_tick_rate() / 15.0f;
bool v3 = v2 > jump_control_ticks;
if ((v1 && v3) || TEST_BIT(biped->unit.unit_control_flags, _unit_control_jetpack_bit))
v0 = true;
}

SET_BIT(input->control_flags, _unit_control_jetpack_bit, v0);
}
HOOK_DECLARE_CALL(0x005D4C66, player_control_get_controller_input_for_jetpack);

88 changes: 47 additions & 41 deletions game/source/units/bipeds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,49 +431,55 @@ biped_datum* biped_get(long biped_index)

void biped_update_jetpack(long biped_index)
{
biped_datum* biped = (biped_datum*)object_get_and_verify_type(biped_index, _object_mask_biped);
if (cheat.jetpack && biped->unit.player_index != NONE)
if (!cheat.jetpack)
return;

biped_datum* biped = biped_get(biped_index);
if (!biped || biped->unit.player_index == NONE)
return;

if (!biped_in_airborne_state(biped_index))
return;

if (!TEST_BIT(biped->unit.unit_control_flags, _unit_control_jetpack_bit))
return;

vector3d linear_velocity{};
if (TEST_BIT(biped->unit.unit_control_flags, _unit_control_crouch_bit))
{
if (TEST_BIT(biped->unit.unit_control_flags, 15) || TEST_BIT(biped->unit.unit_control_flags, 1) && biped_in_airborne_state(biped_index))
{
vector3d linear_velocity{};
object_get_velocities(biped_index, &linear_velocity, NULL);
if (TEST_BIT(biped->unit.unit_control_flags, 15))
{
real v7 = dot_product3d(&biped->unit.aiming_vector, &linear_velocity);
if (v7 < 0.0f)
v7 = 0.0f;

real v8 = fminf(1.0f, fmaxf(v7 * 0.0625f, 0.0f));
if (v8 >= 1.0f)
v8 = 1.0f;

real v9 = -v7;
linear_velocity.i -= (0.2f * (linear_velocity.i + (v9 * biped->unit.aiming_vector.i)));
linear_velocity.j -= (0.2f * (linear_velocity.j + (v9 * biped->unit.aiming_vector.j)));
linear_velocity.k -= (0.2f * (linear_velocity.k + (v9 * biped->unit.aiming_vector.k)));

real v10 = game_tick_length();
real v11 = v10 * (9.0f + ((9.0f * v8) - (18.0f * (v8 * v8))));
linear_velocity.i += v11 * biped->unit.aiming_vector.i;
linear_velocity.j += v11 * biped->unit.aiming_vector.j;
linear_velocity.k += v11 * biped->unit.aiming_vector.k;

c_motor_request motor_request{};
motor_request.setup_force_airborne(_action_none);
motor_system_submit(biped_index, &motor_request);
}
else
{
linear_velocity.i *= 0.9f;
linear_velocity.j *= 0.9f;
linear_velocity.k *= 0.9f;
printf("");
}
// freeze velocity and adjust for gravity
linear_velocity.i = 0.0f;
linear_velocity.j = 0.0f;
linear_velocity.k = global_gravity_get() * game_tick_length();
}
else
{
object_get_velocities(biped_index, &linear_velocity, NULL);

linear_velocity.k += global_gravity_get() * game_tick_length();
object_set_velocities(biped_index, &linear_velocity, NULL);
}
real velocity_dot = dot_product3d(&biped->unit.aiming_vector, &linear_velocity);
if (velocity_dot < 0.0f)
velocity_dot = 0.0f;

real clamped_velocity_dot = fminf(1.0f, fmaxf(velocity_dot * 0.0625f, 0.0f));
if (clamped_velocity_dot >= 1.0f)
clamped_velocity_dot = 1.0f;

real negative_velocity_dot = -velocity_dot;
linear_velocity.i -= (0.2f * (linear_velocity.i + (negative_velocity_dot * biped->unit.aiming_vector.i)));
linear_velocity.j -= (0.2f * (linear_velocity.j + (negative_velocity_dot * biped->unit.aiming_vector.j)));
linear_velocity.k -= (0.2f * (linear_velocity.k + (negative_velocity_dot * biped->unit.aiming_vector.k)));

real v11 = game_tick_length() * (9.0f + ((9.0f * clamped_velocity_dot) - (18.0f * (clamped_velocity_dot * clamped_velocity_dot))));
linear_velocity.i += v11 * biped->unit.aiming_vector.i;
linear_velocity.j += v11 * biped->unit.aiming_vector.j;
linear_velocity.k += v11 * biped->unit.aiming_vector.k;

c_motor_request motor_request{};
motor_request.setup_force_airborne(_action_none);
motor_system_submit(biped_index, &motor_request);

linear_velocity.k += global_gravity_get() * game_tick_length();
}
object_set_velocities(biped_index, &linear_velocity, NULL);
}

0 comments on commit dad1c7e

Please sign in to comment.