deadboltmods / Deadbolt-GMS-1.4-Misc

Misc files & info related to Deadbolt in GameMaker 1.4
1 stars 0 forks source link

Crash wi. no error: Infinite while loops in scripts: motion & rotate_arm #7

Open ithinkandicode opened 4 years ago

ithinkandicode commented 4 years ago

Applies to:

The decompiled scripts for motion and rotate_arm have an error in their while loop, which causes them to loop infinitely with no break.

This causes a crash the game if you try to move or aim, letting you progress only as far as your apartment.

motion

To fix this in the script motion, replace this:

while true

With this:

while ( ceil(abs(hsp)) > 0 )

rotate_arm

To fix it in the script rotate_arm:

Before:

while true

After:

while( arm_check_iteration > 0 )
ithinkandicode commented 2 years ago

The fix above doesn't work for rotate_arm. Use this to replace the full script instead.

/// rotate_arm()

var taim_target_dir, tarm_angle, _temp_local_var_1, t_loopfix_current, t_loopfix_max;

// point_direction(x1, y1, x2, y2): Returns the direction, in degrees, of a vector comprised.
taim_target_dir = point_direction((x + (arm_xo * image_xscale)), (y + (arm_yo * image_yscale)), aim_target_x, aim_target_y)

tarm_angle = arm_angle // last arm angle

// arm_check_iteration is set in gml_Script_init_default, and also in each enemy Create eg. oOni3_Create
// For Reaper, it's 30 (the default), and every enemy seems to have their own value set (most use 15)
_temp_local_var_1 = arm_check_iteration

// [BUG_04] Decompiled code causes an infinite while loop, as it has no break (rotate_arm)
t_loopfix_current = 0 // the current number in the loop
t_loopfix_max = 20 // the maximum number of loops

if (arm_check_iteration <= 0)
{
    // ???
}
else
{
    // while (true)
    // while( arm_check_iteration > 0 ) // Seems like a proper fix, but crashes @TODO
    while (t_loopfix_current <= t_loopfix_max)
    {
        t_loopfix_current += 1

        arm_angle = rotate_direction( arm_angle, taim_target_dir, arm_check_angle )

        // Don't let arms pass through walls (pB)
        // Use the last arm angle instead
        if (collision_line((x + (arm_xo * image_xscale)), (y + (arm_yo * image_yscale)), ((x + (arm_xo * image_xscale)) + lengthdir_x(arm_l, arm_angle)), ((y + (arm_yo * image_yscale)) + lengthdir_y(arm_l, arm_angle)), pB, 0, 0) != -4)
        {
            arm_angle = tarm_angle
        }

        if (arm_angle == tarm_angle)
        {
            // ???
        }
        else
        {
            _temp_local_var_1 = (arm_check_iteration - 1)

            if (arm_check_iteration - 1)
            {
                // continue
            }
        }
    }
}

if (lengthdir_x(10, arm_angle) < 0)
{
    arm_yscale = -1
}
else
{
    arm_yscale = 1
}