COM_AddCommand("simplequickstep", function(player, arg)
	if arg
		if arg == "1" or arg == "true" or arg == "on"
			if io and player == consoleplayer
				local file = io.openlocal("client/quickstep.dat", "w+")
				file:write(arg)
				file:close()
			end
			player.simplequickstep = true
			CONS_Printf(player, "You can now press Fire or Fire normal to quickstep!")
		elseif arg == "0" or arg == "false" or arg == "off"
			if io and player == consoleplayer
				local file = io.openlocal("client/quickstep.dat", "w+")
				file:write(arg)
				file:close()
			end	
			player.simplequickstep = false
			CONS_Printf(player, "You can now hold Fire and press strafe to quickstep!")
		elseif player.simplequickstep
			CONS_Printf(player, "simplequickstep [on/off] - Changes the input method for the quickstep. Currently on.")
		else
			CONS_Printf(player, "simplequickstep [on/off] - Changes the input method for the quickstep. Currently off.")
		end
	elseif player.simplequickstep
		CONS_Printf(player, "simplequickstep [on/off] - Changes the input method for the quickstep. Currently on.")
	else
		CONS_Printf(player, "simplequickstep [on/off] - Changes the input method for the quickstep. Currently off.")
	end
end, 0)

addHook("ThinkFrame", do
	for player in players.iterate

		if player.simplequickstep == nil
			player.simplequickstep = false
		end
    end
end)
		
addHook("PlayerSpawn", function(p)
	if io and p == consoleplayer and p.simplequickstep == nil
		local file = io.openlocal("client/quickstep.dat")
		if file
			local string = file:read("*a")
			if string == "1" or string == "true" or string == "on"
				COM_BufInsertText(p, "simplequickstep on")
			elseif string == "0" or string == "false" or string == "off" or string == nil
				COM_BufInsertText(p, "simplequickstep off")
			end
			file:close()
		end
	end
end)

//quickstep from Modern Abilities for 2.1, by MotdSpork
freeslot("sfx_sonicd")
addHook("PlayerThink", function(player)
		if player.mo
			if player.pflags & PF_JUMPED
				player.pflags = $1 & ~PF_SPINNING
			end
			if not (player.mo.sidestepping)
				player.mo.sidestepping = 0
			end
			if not (player.mo.sidetimer)
				player.mo.sidetimer = 0
			end
			if not (player.mo.sidestep)
				player.mo.sidestep = 0
			end
			if not (player.mo.prevspeed)
				player.mo.prevspeed = 0
			end
			if player.mo.sidestepping == 0
				player.prevspeed = player.speed
			end
			if (player.mo and player.mo.skin == "rangersonic")
			//I HATE WHAT I'M ABOUT TO DO!!
				if player.simplequickstep == true
					if P_IsObjectOnGround(player.mo)
					and player.mo and player.mo.valid //and player.health
					//and player.cmd.sidemove < 0
					and player.mo.sidestepping == 0
					and player.cmd.buttons & BT_ATTACK
						if not (player.mo.eflags & MFE_UNDERWATER)
							P_InstaThrust(player.mo, player.mo.angle + ANGLE_90, (FixedMul(64*FRACUNIT, player.mo.scale)+5*FRACUNIT)+cos(player.aiming))
						else
							P_InstaThrust(player.mo, player.mo.angle + ANGLE_90, (FixedMul(28*FRACUNIT, player.mo.scale)+5*FRACUNIT)+cos(player.aiming))
						end
						S_StartSound(player.mo, sfx_sonicd)
						player.mo.sidestepping = 1
						player.mo.sidetimer = 2
						player.mo.sidestep = 1
					else
						if P_IsObjectOnGround(player.mo)
						and player.mo and player.mo.valid //and player.health
						//and player.cmd.sidemove > 0
						and player.mo.sidestepping == 0
						and player.cmd.buttons & BT_CUSTOM3
							if not (player.mo.eflags & MFE_UNDERWATER)
								P_InstaThrust(player.mo, player.mo.angle - ANGLE_90, (FixedMul(64*FRACUNIT, player.mo.scale)+5*FRACUNIT)+cos(player.aiming))
							else
								P_InstaThrust(player.mo, player.mo.angle - ANGLE_90,  (FixedMul(28*FRACUNIT, player.mo.scale)+5*FRACUNIT)+cos(player.aiming))
							end
							S_StartSound(player.mo, sfx_sonicd)
							player.mo.sidestepping = 1
							player.mo.sidetimer = 2
							player.mo.sidestep = 1
						end
						if not (player.cmd.buttons & BT_ATTACK)
						and not (player.cmd.buttons & BT_CUSTOM3)
						and player.mo.sidestepping == 1
							player.mo.sidestepping = 0
						end
						if player.mo.sidestep == 1
						and player.mo.sidetimer == 0
							player.mo.sidestep = 0
							P_InstaThrust(player.mo, player.mo.angle - ANGLE_90, (FixedMul(0*FRACUNIT, player.mo.scale)+0*FRACUNIT)+cos(player.aiming))
							P_InstaThrust(player.mo, player.mo.angle + ANGLE_90, (FixedMul(0*FRACUNIT, player.mo.scale)+0*FRACUNIT)+cos(player.aiming))
							P_InstaThrust(player.mo, player.mo.angle, player.prevspeed)
							if player.prevspeed <= 1*FRACUNIT
								player.mo.state = S_PLAY_STND
							end
						end	
					end
					if player.mo.sidetimer > 0
						P_SpawnGhostMobj(player.mo)
						player.mo.sidetimer = $1 - 1
					end
			//If anyone reading this has tips, please let me know :)
				elseif player.simplequickstep == false
					if player.cmd.buttons & BT_ATTACK
					or player.cmd.buttons & BT_CUSTOM3
						player.drawangle = player.mo.angle
					end
					
					if P_IsObjectOnGround(player.mo)
					and player.mo and player.mo.valid //and player.health
					and player.cmd.sidemove < 0
					and player.mo.sidestepping == 0
						if player.cmd.buttons & BT_ATTACK
						or player.cmd.buttons & BT_CUSTOM3
							if not (player.mo.eflags & MFE_UNDERWATER)
								P_InstaThrust(player.mo, player.mo.angle + ANGLE_90, (FixedMul(64*FRACUNIT, player.mo.scale)+5*FRACUNIT)+cos(player.aiming))
							else
								P_InstaThrust(player.mo, player.mo.angle + ANGLE_90, (FixedMul(28*FRACUNIT, player.mo.scale)+5*FRACUNIT)+cos(player.aiming))
							end
							S_StartSound(player.mo, sfx_sonicd)
							player.mo.sidestepping = 1
							player.mo.sidetimer = 2
							player.mo.sidestep = 1
						end
					else
						if player.cmd.sidemove > 0
						and player.mo and player.mo.valid //and player.health
						and player.mo.sidestepping == 0
						and P_IsObjectOnGround(player.mo)
							if player.cmd.buttons & BT_ATTACK
							or player.cmd.buttons & BT_CUSTOM3
								if not (player.mo.eflags & MFE_UNDERWATER)
									P_InstaThrust(player.mo, player.mo.angle - ANGLE_90, (FixedMul(64*FRACUNIT, player.mo.scale)+5*FRACUNIT)+cos(player.aiming))
								else
									P_InstaThrust(player.mo, player.mo.angle - ANGLE_90,  (FixedMul(28*FRACUNIT, player.mo.scale)+5*FRACUNIT)+cos(player.aiming))
								end
								S_StartSound(player.mo, sfx_sonicd)
								player.mo.sidestepping = 1
								player.mo.sidetimer = 2
								player.mo.sidestep = 1
							end
						end
						if (player.cmd.sidemove == 0)
						and player.mo.sidestepping == 1
							player.mo.sidestepping = 0
						end
						if player.mo.sidestep == 1
						and player.mo.sidetimer == 0
							player.mo.sidestep = 0
							P_InstaThrust(player.mo, player.mo.angle - ANGLE_90, (FixedMul(0*FRACUNIT, player.mo.scale)+0*FRACUNIT)+cos(player.aiming))
							P_InstaThrust(player.mo, player.mo.angle + ANGLE_90, (FixedMul(0*FRACUNIT, player.mo.scale)+0*FRACUNIT)+cos(player.aiming))
							P_InstaThrust(player.mo, player.mo.angle, player.prevspeed)
							if player.prevspeed <= 1*FRACUNIT
								player.mo.state = S_PLAY_STND
							end
						end	
					end
					if player.mo.sidetimer > 0
						P_SpawnGhostMobj(player.mo)
						player.mo.sidetimer = $1 - 1
					end
				end
			end
	end
end)

sfxinfo[sfx_sonicd].caption = "Quickstep"