2021-05-19 14:35:30 +02:00
|
|
|
#include "backend/looped/looped.hpp"
|
|
|
|
#include "fiber_pool.hpp"
|
2022-05-23 06:38:45 +08:00
|
|
|
#include "gta/enums.hpp"
|
2021-05-19 14:35:30 +02:00
|
|
|
#include "natives.hpp"
|
|
|
|
#include "util/entity.hpp"
|
|
|
|
|
|
|
|
namespace big
|
|
|
|
{
|
2022-06-25 21:17:35 +02:00
|
|
|
static const ControllerInputs controls[] =
|
|
|
|
{
|
|
|
|
ControllerInputs::INPUT_SPRINT,
|
|
|
|
ControllerInputs::INPUT_MOVE_UP_ONLY,
|
|
|
|
ControllerInputs::INPUT_MOVE_DOWN_ONLY,
|
|
|
|
ControllerInputs::INPUT_MOVE_LEFT_ONLY,
|
|
|
|
ControllerInputs::INPUT_MOVE_RIGHT_ONLY,
|
|
|
|
ControllerInputs::INPUT_DUCK
|
2022-05-23 06:38:45 +08:00
|
|
|
};
|
|
|
|
|
2021-08-03 20:26:43 +02:00
|
|
|
static float speed = 20.f;
|
|
|
|
static float mult = 0.f;
|
2021-05-19 14:35:30 +02:00
|
|
|
|
|
|
|
static bool bLastNoclip = false;
|
|
|
|
|
|
|
|
static Entity prev = -1;
|
|
|
|
static Vector3 rot{};
|
|
|
|
|
2022-06-25 21:17:35 +02:00
|
|
|
void looped::self_noclip_disable_control_action()
|
|
|
|
{
|
2022-12-18 23:15:52 +01:00
|
|
|
if (g.self.noclip)
|
2022-06-25 21:17:35 +02:00
|
|
|
{
|
|
|
|
for (const auto& control : controls)
|
|
|
|
PAD::DISABLE_CONTROL_ACTION(0, static_cast<int>(control), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void looped::self_noclip()
|
|
|
|
{
|
2022-12-18 23:15:52 +01:00
|
|
|
const auto bNoclip = g.self.noclip;
|
2021-05-19 14:35:30 +02:00
|
|
|
|
2022-07-27 14:39:22 +02:00
|
|
|
const auto location = self::pos;
|
|
|
|
const Entity ent = (self::veh != 0 && g_local_player->m_ped_task_flag & (int)ePedTask::TASK_DRIVING) ? self::veh : self::ped;
|
2021-05-19 14:35:30 +02:00
|
|
|
|
|
|
|
// cleanup when changing entities
|
|
|
|
if (prev != ent)
|
|
|
|
{
|
2021-10-14 00:09:56 +02:00
|
|
|
ENTITY::FREEZE_ENTITY_POSITION(prev, false);
|
2021-05-19 14:35:30 +02:00
|
|
|
ENTITY::SET_ENTITY_COLLISION(prev, true, true);
|
|
|
|
|
|
|
|
prev = ent;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bNoclip)
|
|
|
|
{
|
|
|
|
Vector3 vel = { 0.f, 0.f, 0.f };
|
|
|
|
|
|
|
|
// Left Shift
|
2022-05-23 06:38:45 +08:00
|
|
|
if (PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_SPRINT))
|
2021-05-19 14:35:30 +02:00
|
|
|
vel.z += speed / 2;
|
|
|
|
// Left Control
|
2022-05-23 06:38:45 +08:00
|
|
|
if (PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_DUCK))
|
2021-05-19 14:35:30 +02:00
|
|
|
vel.z -= speed / 2;
|
|
|
|
// Forward
|
2022-05-23 06:38:45 +08:00
|
|
|
if (PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_MOVE_UP_ONLY))
|
2021-05-19 14:35:30 +02:00
|
|
|
vel.y += speed;
|
|
|
|
// Backward
|
2022-05-23 06:38:45 +08:00
|
|
|
if (PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_MOVE_DOWN_ONLY))
|
2021-05-19 14:35:30 +02:00
|
|
|
vel.y -= speed;
|
|
|
|
// Left
|
2022-05-23 06:38:45 +08:00
|
|
|
if (PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_MOVE_LEFT_ONLY))
|
2021-05-19 14:35:30 +02:00
|
|
|
vel.x -= speed;
|
|
|
|
// Right
|
2022-05-23 06:38:45 +08:00
|
|
|
if (PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_MOVE_RIGHT_ONLY))
|
2021-05-19 14:35:30 +02:00
|
|
|
vel.x += speed;
|
|
|
|
|
|
|
|
rot = CAM::GET_GAMEPLAY_CAM_ROT(2);
|
|
|
|
ENTITY::SET_ENTITY_ROTATION(ent, 0.f, rot.y, rot.z, 2, 0);
|
|
|
|
ENTITY::SET_ENTITY_COLLISION(ent, false, false);
|
|
|
|
if (vel.x == 0.f && vel.y == 0.f && vel.z == 0.f)
|
|
|
|
{
|
|
|
|
// freeze entity to prevent drifting when standing still
|
|
|
|
ENTITY::FREEZE_ENTITY_POSITION(ent, true);
|
2021-08-03 20:26:43 +02:00
|
|
|
|
|
|
|
mult = 0.f;
|
2021-05-19 14:35:30 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-03 20:26:43 +02:00
|
|
|
if (mult < 20.f)
|
|
|
|
mult += 0.15f;
|
|
|
|
|
2021-05-19 14:35:30 +02:00
|
|
|
ENTITY::FREEZE_ENTITY_POSITION(ent, false);
|
|
|
|
|
2022-07-27 14:39:22 +02:00
|
|
|
const auto offset = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(ent, vel.x, vel.y, 0.f);
|
2022-05-23 06:38:45 +08:00
|
|
|
vel.x = offset.x - location.x;
|
|
|
|
vel.y = offset.y - location.y;
|
2021-05-19 14:35:30 +02:00
|
|
|
|
2021-08-03 20:26:43 +02:00
|
|
|
ENTITY::SET_ENTITY_VELOCITY(ent, vel.x * mult, vel.y * mult, vel.z * mult);
|
2021-05-19 14:35:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (bNoclip != bLastNoclip)
|
|
|
|
{
|
2022-01-07 17:00:42 +01:00
|
|
|
if (entity::take_control_of(ent))
|
|
|
|
{
|
|
|
|
ENTITY::FREEZE_ENTITY_POSITION(ent, false);
|
|
|
|
ENTITY::SET_ENTITY_COLLISION(ent, true, false);
|
|
|
|
}
|
2021-05-19 14:35:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bLastNoclip = bNoclip;
|
|
|
|
}
|
2022-06-25 21:17:35 +02:00
|
|
|
}
|