refactor!: Replace premake5 with CMake. (#551)

Co-authored-by: tupoy-ya <tupoy-ya@users.noreply.github.com>
This commit is contained in:
tupoy-ya
2022-11-08 21:08:58 +00:00
committed by GitHub
parent d9d8aa30c1
commit bc05ecd78c
340 changed files with 19298 additions and 19449 deletions

View File

@ -0,0 +1,133 @@
#include "backend/looped/looped.hpp"
#include "gta/enums.hpp"
#include "natives.hpp"
#include "util/blip.hpp"
#include "util/entity.hpp"
#include "util/vehicle.hpp"
namespace big
{
void looped::vehicle_auto_drive()
{
static std::map<AutoDriveStyle, int> driving_style_flags = {
{AutoDriveStyle::LAW_ABIDING, 443},
{AutoDriveStyle::THE_ROAD_IS_YOURS, 787004}
};
static int changing_driving_styles = false;
static AutoDriveDestination current_destination = AutoDriveDestination::STOPPED;
static int current_driving_flag = driving_style_flags[AutoDriveStyle::LAW_ABIDING];
static float current_speed = 8;
static bool started = false;
static Vector3 waypoint;
if (g->vehicle.auto_drive_destination != AutoDriveDestination::STOPPED)
{
current_destination = g->vehicle.auto_drive_destination;
g->vehicle.auto_drive_destination = AutoDriveDestination::STOPPED;
changing_driving_styles = true;
}
if (!self::veh && current_destination != AutoDriveDestination::STOPPED)
{
current_destination = AutoDriveDestination::STOPPED;
changing_driving_styles = false;
g_notification_service->push_warning("Warning", "Please be in a car first then try again.");
}
else if (
current_driving_flag != driving_style_flags[g->vehicle.auto_drive_style] ||
current_speed != g->vehicle.auto_drive_speed
) {
current_driving_flag = driving_style_flags[g->vehicle.auto_drive_style];
current_speed = g->vehicle.auto_drive_speed;
changing_driving_styles = true;
}
if (current_destination != AutoDriveDestination::STOPPED)
{
Vector3 last_waypoint = waypoint;
bool does_waypoint_exist = false;
bool to_waypoint = false;
if (current_destination == AutoDriveDestination::OBJECTITVE)
{
to_waypoint = true;
does_waypoint_exist = blip::get_objective_location(waypoint);
}
else if (current_destination == AutoDriveDestination::WAYPOINT)
{
to_waypoint = true;
does_waypoint_exist = blip::get_blip_location(waypoint, (int)BlipIcons::Waypoint);
}
if (
does_waypoint_exist &&
(
last_waypoint.x != waypoint.x ||
last_waypoint.y != waypoint.y ||
last_waypoint.z != waypoint.z
)
) {
changing_driving_styles = true;
}
bool interupted = (
PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_LEFT_ONLY) ||
PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_RIGHT_ONLY) ||
PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_ACCELERATE) ||
PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_BRAKE) ||
PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_EXIT) ||
PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_HANDBRAKE)
);
if (
current_destination == AutoDriveDestination::EMERGENCY_STOP ||
(to_waypoint && !does_waypoint_exist) ||
interupted
) {
TASK::CLEAR_PRIMARY_VEHICLE_TASK(self::veh);
TASK::CLEAR_PED_TASKS(self::ped);
if (!interupted && started)
{
VEHICLE::SET_VEHICLE_FORWARD_SPEED(self::veh, 0);
}
current_destination = AutoDriveDestination::STOPPED;
if (to_waypoint && !does_waypoint_exist)
{
g_notification_service->push_warning("Warning", "No Waypoint found please set one first.");
}
else
{
g_notification_service->push_warning("Warning", "Auto Drive Stopped");
}
started = false;
}
else if (changing_driving_styles)
{
changing_driving_styles = false;
TASK::CLEAR_PRIMARY_VEHICLE_TASK(self::veh);
TASK::CLEAR_PED_TASKS(self::ped);
if (to_waypoint)
{
TASK::TASK_VEHICLE_DRIVE_TO_COORD_LONGRANGE(
self::ped, self::veh,
waypoint.x, waypoint.y, waypoint.z, current_speed,
current_driving_flag, 20
);
}
else
{
TASK::TASK_VEHICLE_DRIVE_WANDER(self::ped, self::veh, current_speed, current_driving_flag);
}
started = true;
}
}
}
}

View File

@ -0,0 +1,25 @@
#include "backend/looped/looped.hpp"
#include "core/enums.hpp"
#include "natives.hpp"
namespace big
{
void looped::vehicle_boost_behavior()
{
auto* const vehicle = g_local_player->m_vehicle;
if (vehicle && VEHICLE::GET_HAS_ROCKET_BOOST(self::veh))
{
if (g->vehicle.boost_behavior == eBoostBehaviors::INSTANT_REFIL && (vehicle->m_boost == 0.f || !vehicle->m_boost_state)) // Instant Refill
{
vehicle->m_boost_allow_recharge = true;
vehicle->m_boost = 3.f;
}
else if (g->vehicle.boost_behavior == eBoostBehaviors::INFINITE_BOOST) // Infinite Boost
{
vehicle->m_boost_allow_recharge = true;
vehicle->m_boost = 3.f;
}
}
}
}

View File

@ -0,0 +1,11 @@
#include "backend/looped/looped.hpp"
#include "script_global.hpp"
namespace big
{
// allows for spawning unreleased vehicles in online and online vehicles in single player
void looped::vehicle_despawn_bypass()
{
*script_global(4539659).as<bool*>() = true;
}
}

View File

@ -0,0 +1,93 @@
#include "backend/looped/looped.hpp"
#include "natives.hpp"
#include "script.hpp"
#include "util/entity.hpp"
namespace big
{
constexpr auto drive_on_water_surface_hash = RAGE_JOAAT("stt_prop_stunt_bblock_xl3");
static Vector3 drive_on_water_last_loc;
void drive_on_water_hide_surface()
{
Object surface = OBJECT::GET_CLOSEST_OBJECT_OF_TYPE(
drive_on_water_last_loc.x, drive_on_water_last_loc.y, drive_on_water_last_loc.z,
4.0, drive_on_water_surface_hash, 0, 0, 1
);
if (surface)
{
entity::take_control_of(surface);
ENTITY::SET_ENTITY_COORDS(surface, 0, 0, -1000.0f, 0, 0, 0, 1);
script::get_current()->yield(10ms);
ENTITY::SET_ENTITY_AS_NO_LONGER_NEEDED(&surface);
ENTITY::DELETE_ENTITY(&surface);
WATER::RESET_DEEP_OCEAN_SCALER();
}
}
void looped::vehicle_drive_on_water()
{
if (!g->vehicle.drive_on_water || self::veh == 0) {
drive_on_water_hide_surface();
return;
}
Vector3 location = ENTITY::GET_ENTITY_COORDS(self::veh, 1);
float height = 0;
WATER::SET_DEEP_OCEAN_SCALER(0);
if (location.z - height < 10 && WATER::GET_WATER_HEIGHT_NO_WAVES(location.x, location.y, location.z, &height))
{
Object surface = OBJECT::GET_CLOSEST_OBJECT_OF_TYPE(
drive_on_water_last_loc.x, drive_on_water_last_loc.y, drive_on_water_last_loc.z,
4.0, drive_on_water_surface_hash, 0, 0, 1
);
if (ENTITY::DOES_ENTITY_EXIST(surface) && height > -50.0f)
{
entity::take_control_of(surface);
drive_on_water_last_loc = location;
drive_on_water_last_loc.z = height - 0.5f;
ENTITY::SET_ENTITY_COORDS(
surface,
drive_on_water_last_loc.x, drive_on_water_last_loc.y, drive_on_water_last_loc.z,
0, 0, 0, 0
);
if (location.z < height - 2.f)
{
entity::take_control_of(self::veh);
ENTITY::SET_ENTITY_COORDS(self::veh, location.x, location.y, height, 0, 0, 0, 0);
}
}
else
{
STREAMING::REQUEST_MODEL(drive_on_water_surface_hash);
while (!STREAMING::HAS_MODEL_LOADED(drive_on_water_surface_hash))
{
script::get_current()->yield();
}
drive_on_water_last_loc = location;
drive_on_water_last_loc.z = height - 0.5f;
surface = OBJECT::CREATE_OBJECT(
drive_on_water_surface_hash,
drive_on_water_last_loc.x, drive_on_water_last_loc.y, drive_on_water_last_loc.z,
1, 1, 0
);
entity::take_control_of(surface);
ENTITY::FREEZE_ENTITY_POSITION(surface, 1);
ENTITY::SET_ENTITY_ALPHA(surface, 0, 1);
ENTITY::SET_ENTITY_VISIBLE(surface, false, 0);
}
}
else
{
drive_on_water_hide_surface();
}
}
}

View File

@ -0,0 +1,149 @@
#include "backend/looped/looped.hpp"
#include "gta/enums.hpp"
#include "natives.hpp"
#include "util/entity.hpp"
namespace big
{
static bool last_fly_tick = false;
void do_vehicle_fly()
{
Vehicle vehicle = self::veh;
Vector3 cam_pos = CAM::GET_GAMEPLAY_CAM_ROT(0);
ENTITY::SET_ENTITY_ROTATION(vehicle, cam_pos.x, cam_pos.y, cam_pos.z, 1, true);
ENTITY::SET_ENTITY_COLLISION(vehicle, !g->vehicle.fly.no_collision, true);
float locspeed = g->vehicle.fly.speed;
if (PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_UP_ONLY))
{
locspeed *= 2;
}
if (PAD::IS_CONTROL_PRESSED(2, (int)ControllerInputs::INPUT_VEH_ACCELERATE))
{
if (g->vehicle.fly.dont_stop)
{
ENTITY::APPLY_FORCE_TO_ENTITY(vehicle, 1, 0.0, g->vehicle.fly.speed, 0.0, 0.0, 0.0, 0.0, 0, 1, 1, 1, 0, 1);
}
else
{
VEHICLE::SET_VEHICLE_FORWARD_SPEED(vehicle, locspeed);
}
}
if (PAD::IS_CONTROL_PRESSED(2, (int)ControllerInputs::INPUT_VEH_BRAKE))
{
float lsp = g->vehicle.fly.speed;
if (!PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_UP_ONLY))
{
lsp = (g->vehicle.fly.speed * 2);
}
if (g->vehicle.fly.dont_stop)
{
ENTITY::APPLY_FORCE_TO_ENTITY(vehicle, 1, 0.0, 0 - (lsp), 0.0, 0.0, 0.0, 0.0, 0, 1, 1, 1, 0, 1);
}
else
{
VEHICLE::SET_VEHICLE_FORWARD_SPEED(vehicle, (0 - locspeed));
}
}
if (PAD::IS_CONTROL_PRESSED(2, (int)ControllerInputs::INPUT_VEH_MOVE_LEFT_ONLY))
{
float lsp = ((0 - g->vehicle.fly.speed) * 2);
if (!PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_UP_ONLY))
{
lsp = (0 - g->vehicle.fly.speed);
}
if (g->vehicle.fly.dont_stop)
{
ENTITY::APPLY_FORCE_TO_ENTITY(vehicle, 1, (lsp), 0.0, 0.0, 0.0, 0.0, 0.0, 0, 1, 1, 1, 0, 1);
}
else
{
ENTITY::APPLY_FORCE_TO_ENTITY(vehicle, 1, (0 - (locspeed)), 0.0, 0.0, 0.0, 0.0, 0.0, 0, 1, 1, 1, 0, 1);
}
}
if (PAD::IS_CONTROL_PRESSED(2, (int)ControllerInputs::INPUT_VEH_MOVE_RIGHT_ONLY))
{
float lsp = g->vehicle.fly.speed;
if (!PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_UP_ONLY))
{
lsp = (g->vehicle.fly.speed * 2);
}
if (g->vehicle.fly.dont_stop)
{
ENTITY::APPLY_FORCE_TO_ENTITY(vehicle, 1, lsp, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 1, 1, 1, 0, 1);
}
else
{
ENTITY::APPLY_FORCE_TO_ENTITY(vehicle, 1, locspeed, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 1, 1, 1, 0, 1);
}
}
if (!g->vehicle.fly.dont_stop && !PAD::IS_CONTROL_PRESSED(2, (int)ControllerInputs::INPUT_VEH_ACCELERATE) && !PAD::IS_CONTROL_PRESSED(2, (int)ControllerInputs::INPUT_VEH_BRAKE))
{
VEHICLE::SET_VEHICLE_FORWARD_SPEED(vehicle, 0.0);
}
if (TASK::GET_IS_TASK_ACTIVE(self::ped, 2))
{
g->vehicle.fly.enabled = false;
VEHICLE::SET_VEHICLE_GRAVITY(vehicle, true);
ENTITY::SET_ENTITY_COLLISION(vehicle, true, true);
if (g->vehicle.fly.stop_on_exit)
{
VEHICLE::SET_VEHICLE_FORWARD_SPEED(vehicle, 0.0);
}
}
}
void looped::vehicle_fly()
{
Vehicle vehicle = self::veh;
if (g->vehicle.fly.enabled)
{
last_fly_tick = true;
if (!vehicle)
{
g_notification_service->push_warning("Warning", "Please be in a vehicle before enabling vehicle fly.");
g->vehicle.fly.enabled = false;
return;
}
else
{
if (NETWORK::NETWORK_HAS_CONTROL_OF_ENTITY(vehicle))
{
do_vehicle_fly();
VEHICLE::SET_VEHICLE_GRAVITY(vehicle, false);
}
else
{
for (int i = 0; i < 5; i++)
{
entity::take_control_of(vehicle);
g_notification_service->push_warning("Warning", "Failed to take control of the vehicle.");
}
}
}
}
else
{
if (last_fly_tick)
{
ENTITY::SET_ENTITY_COLLISION(vehicle, true, true);
VEHICLE::SET_VEHICLE_GRAVITY(vehicle, true);
last_fly_tick = false;
}
}
}
}

View File

@ -0,0 +1,38 @@
#include "backend/looped/looped.hpp"
#include "gta/enums.hpp"
#include "natives.hpp"
namespace big
{
static constexpr float hornBoostSpeedDefault = 10.f;
static float hornBoostSpeed = hornBoostSpeedDefault;
static constexpr float hostBoostSpeedMax = 200.f;
void looped::vehicle_horn_boost()
{
if (!g->vehicle.horn_boost) return;
Vehicle vehicle = self::veh;
if (vehicle == 0)
{
hornBoostSpeed = hornBoostSpeedDefault;
return;
}
if (PAD::IS_CONTROL_JUST_PRESSED(0, (int)ControllerInputs::INPUT_VEH_HORN))
hornBoostSpeed = ENTITY::GET_ENTITY_SPEED(vehicle);
if (PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_HORN))
{
if (hornBoostSpeed < hostBoostSpeedMax) hornBoostSpeed++;
const auto velocity =
ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(vehicle, 0.f, hornBoostSpeed, 0.f) - ENTITY::GET_ENTITY_COORDS(vehicle, true);
ENTITY::SET_ENTITY_VELOCITY(vehicle, velocity.x, velocity.y, velocity.z);
}
else if (PAD::IS_CONTROL_JUST_RELEASED(0, (int)ControllerInputs::INPUT_VEH_HORN))
hornBoostSpeed = hornBoostSpeedDefault;
}
}

View File

@ -0,0 +1,22 @@
#include "backend/looped/looped.hpp"
#include "gta/enums.hpp"
#include "natives.hpp"
namespace big
{
void looped::vehicle_instant_brake()
{
if (!g->vehicle.instant_brake) return;
Vehicle vehicle = self::veh;
if (vehicle == 0 || ENTITY::GET_ENTITY_SPEED_VECTOR(vehicle, true).y < 1.f || !VEHICLE::IS_VEHICLE_ON_ALL_WHEELS(vehicle))
{
return;
}
if (PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_BRAKE) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_HANDBRAKE))
VEHICLE::SET_VEHICLE_FORWARD_SPEED(vehicle, 0);
}
}

View File

@ -0,0 +1,10 @@
#include "backend/looped/looped.hpp"
namespace big
{
void looped::vehicle_is_targetable()
{
if (g_local_player && g_local_player->m_vehicle)
g_local_player->m_vehicle->m_is_targetable = g->vehicle.is_targetable;
}
}

View File

@ -0,0 +1,12 @@
#include "backend/looped/looped.hpp"
#include "util/vehicle.hpp"
namespace big
{
void looped::vehicle_keep_vehicle_repaired()
{
if (g->vehicle.keep_vehicle_repaired && VEHICLE::GET_DOES_VEHICLE_HAVE_DAMAGE_DECALS(self::veh)) {
vehicle::repair(self::veh);
}
}
}

View File

@ -0,0 +1,69 @@
#include "backend/looped/looped.hpp"
#include "gta_util.hpp"
#include "script_local.hpp"
#include "util/math.hpp"
#include "util/scripts.hpp"
namespace big
{
static bool state = false;
static bool busy = false;
void looped::vehicle_ls_customs()
{
if (busy) return;
busy = true;
constexpr int hash = RAGE_JOAAT("carmod_shop");
if (g->vehicle.ls_customs && g->vehicle.ls_customs == state)
{
if (
auto carmod_shop_thread = gta_util::find_script_thread(hash);
carmod_shop_thread &&
*script_local(carmod_shop_thread, 728).at(11).as<int*>() != 4
)
{
g->vehicle.ls_customs = false;
*script_local(carmod_shop_thread, 728).as<int*>() = 1; // cleanup
}
}
if (g->vehicle.ls_customs && g->vehicle.ls_customs != state)
{
Vehicle veh = self::veh;
if (!ENTITY::DOES_ENTITY_EXIST(veh) || ENTITY::IS_ENTITY_DEAD(veh, false))
{
busy = false;
g->vehicle.ls_customs = false;
g_notification_service->push_warning("LS Customs", "You aren't in a vehicle.");
return;
}
scripts::request_script(hash);
if (scripts::wait_till_loaded(hash))
{
int args[] = { 45, 0, 9 };
scripts::start_script_with_args(hash, args, 3, 3600);
scripts::wait_till_running(hash);
}
if (scripts::is_running(hash))
{
if (auto carmod_shop_thread = gta_util::find_script_thread(hash); carmod_shop_thread)
{
*script_local(carmod_shop_thread, 728).at(406).as<int*>() = veh;
*script_local(carmod_shop_thread, 2149).as<bool*>() = false; // skips cutscene that's invisible
*script_local(carmod_shop_thread, 728).at(11).as<int*>() = 4;
}
}
}
busy = false;
state = g->vehicle.ls_customs;
}
}

View File

@ -0,0 +1,24 @@
#include "backend/looped/looped.hpp"
namespace big
{
static bool bLastVehicleNoWaterCollsion = false;
void looped::vehicle_no_water_collision()
{
if (g_local_player == nullptr || g_local_player->m_vehicle == nullptr) return;
bool bNoWaterCollsion = g->vehicle.no_water_collision;
if (bNoWaterCollsion)
{
g_local_player->m_vehicle->m_navigation->m_damp->m_water_collision = 0;
bLastVehicleNoWaterCollsion = bNoWaterCollsion;
}
else if (bNoWaterCollsion != bLastVehicleNoWaterCollsion)
{
g_local_player->m_vehicle->m_navigation->m_damp->m_water_collision = 1;
bLastVehicleNoWaterCollsion = bNoWaterCollsion;
}
}
}

View File

@ -0,0 +1,124 @@
#include "backend/looped/looped.hpp"
#include "natives.hpp"
#include "script.hpp"
namespace big
{
enum rgb_controller_t
{
rgb_controller_green_up,
rgb_controller_red_down,
rgb_controller_blue_up,
rgb_controller_green_down,
rgb_controller_red_up,
rgb_controller_blue_down,
};
void looped::vehicle_rainbow_paint()
{
static int rgb_controller_v = rgb_controller_green_up;
static int red = 255;
static int green = 0;
static int blue = 0;
if (self::veh && g->vehicle.rainbow_paint.type != RainbowPaintType::Off)
{
int delay_step = 100;
if (g->vehicle.rainbow_paint.type == RainbowPaintType::Spasm)
{
red = rand() % 256;
green = rand() % 256;
blue = rand() % 256;
}
else if (g->vehicle.rainbow_paint.type == RainbowPaintType::Fade)
{
delay_step = 10;
switch (rgb_controller_v)
{
case rgb_controller_green_up:
green += 5;
if (green >= 255)
{
green = 255;
rgb_controller_v = rgb_controller_red_down;
}
break;
case rgb_controller_red_down:
red -= 5;
if (red < 0)
{
red = 0;
rgb_controller_v = rgb_controller_blue_up;
}
break;
case rgb_controller_blue_up:
blue += 5;
if (blue >= 255)
{
blue = 255;
rgb_controller_v = rgb_controller_green_down;
}
break;
case rgb_controller_green_down:
green -= 5;
if (green < 0)
{
green = 0;
rgb_controller_v = rgb_controller_red_up;
}
break;
case rgb_controller_red_up:
red += 5;
if (red >= 255)
{
red = 255;
rgb_controller_v = rgb_controller_blue_down;
}
break;
case rgb_controller_blue_down:
blue -= 5;
if (blue < 0)
{
blue = 0;
rgb_controller_v = rgb_controller_green_up;
}
break;
default:
break;
}
}
Vehicle vehicle = self::veh;
if (g->vehicle.rainbow_paint.primary) {
VEHICLE::SET_VEHICLE_CUSTOM_PRIMARY_COLOUR(vehicle, red, green, blue);
}
if (g->vehicle.rainbow_paint.secondary) {
VEHICLE::SET_VEHICLE_CUSTOM_SECONDARY_COLOUR(vehicle, red, green, blue);
}
if (g->vehicle.rainbow_paint.neon) {
VEHICLE::SET_VEHICLE_NEON_ENABLED(vehicle, 0, 1);
VEHICLE::SET_VEHICLE_NEON_ENABLED(vehicle, 1, 1);
VEHICLE::SET_VEHICLE_NEON_ENABLED(vehicle, 2, 1);
VEHICLE::SET_VEHICLE_NEON_ENABLED(vehicle, 3, 1);
VEHICLE::SET_VEHICLE_NEON_COLOUR(vehicle, red, green, blue);
}
if (g->vehicle.rainbow_paint.smoke) {
VEHICLE::SET_VEHICLE_TYRE_SMOKE_COLOR(vehicle, red, green, blue);
}
auto delay = std::chrono::milliseconds(((delay_step * 10) + 10) - (g->vehicle.rainbow_paint.speed * delay_step));
script::get_current()->yield(delay);
}
}
}

View File

@ -0,0 +1,21 @@
#include "backend/looped/looped.hpp"
#include "natives.hpp"
namespace big
{
static bool b_last_seatbelt = false;
void looped::vehicle_seatbelt()
{
bool b_seatbelt = g->vehicle.seatbelt;
if (b_seatbelt || (!b_seatbelt && b_seatbelt != b_last_seatbelt))
{
PED::SET_PED_CONFIG_FLAG(self::ped, 32, g->vehicle.seatbelt);
PED::SET_PED_CAN_BE_KNOCKED_OFF_VEHICLE(self::ped, g->vehicle.seatbelt);
b_last_seatbelt = g->vehicle.seatbelt;
}
}
}

View File

@ -0,0 +1,61 @@
#include "backend/looped/looped.hpp"
#include "natives.hpp"
#include "util/vehicle.hpp"
namespace big
{
void looped::vehicle_speedo_meter()
{
if (
!g->vehicle.speedo_meter.enabled ||
self::veh == 0 ||
HUD::IS_PAUSE_MENU_ACTIVE() ||
HUD::IS_WARNING_MESSAGE_ACTIVE() ||
CAM::IS_SCREEN_FADED_OUT() ||
CAM::IS_SCREEN_FADING_OUT() ||
CAM::IS_SCREEN_FADING_IN()
) {
return;
}
char speed_type[16], speed[16];
int char_width = 3;
float veh_speed = vehicle::mps_to_speed(
ENTITY::GET_ENTITY_SPEED(self::veh),
g->vehicle.speed_unit
);
switch (g->vehicle.speed_unit)
{
case SpeedUnit::KMPH:
strcpy(speed_type, "kmph");
char_width = 4;
break;
case SpeedUnit::MIPH:
strcpy(speed_type, "mph");
break;
case SpeedUnit::MPS:
strcpy(speed_type, "mps");
break;
}
sprintf(speed, "%*d", g->vehicle.speedo_meter.left_side ? 0 : char_width, (int)veh_speed);
HUD::SET_TEXT_FONT(2);
HUD::SET_TEXT_SCALE(.9f, .9f);
HUD::SET_TEXT_OUTLINE();
HUD::BEGIN_TEXT_COMMAND_DISPLAY_TEXT("STRING");
HUD::ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME(speed_type);
HUD::END_TEXT_COMMAND_DISPLAY_TEXT(g->vehicle.speedo_meter.x, g->vehicle.speedo_meter.y, 1);
HUD::SET_TEXT_FONT(2);
HUD::SET_TEXT_SCALE(.9f, .9f);
HUD::SET_TEXT_OUTLINE();
HUD::BEGIN_TEXT_COMMAND_DISPLAY_TEXT("STRING");
HUD::ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME(speed);
HUD::END_TEXT_COMMAND_DISPLAY_TEXT(g->vehicle.speedo_meter.x + (g->vehicle.speedo_meter.left_side ? 0 : .003f), g->vehicle.speedo_meter.y + .04f, 1);
}
}

View File

@ -0,0 +1,176 @@
#include "backend/looped/looped.hpp"
#include "fiber_pool.hpp"
#include "gta/enums.hpp"
#include "natives.hpp"
#include "script.hpp"
#include "windows.h"
struct key_state
{
key_state(int v_key) : v_key(v_key) {}
enum
{
up,
down,
just_pressed,
just_released,
};
uint8_t state = up;
int v_key;
};
inline key_state right_signal_key{ 'L' };
inline key_state left_signal_key{ 'J' };
inline key_state hazzards_key{ 'K' };
bool is_key_pressed(int const v_key)
{
return GetAsyncKeyState(v_key) & 0x8000;
}
void update_key_state(key_state& key_last_tick)
{
if (is_key_pressed(key_last_tick.v_key))
{
switch (key_last_tick.state)
{
case key_state::up:
key_last_tick.state = key_state::just_pressed;
break;
case key_state::just_pressed:
key_last_tick.state = key_state::down;
break;
}
}
else
{
switch (key_last_tick.state)
{
case key_state::down:
key_last_tick.state = key_state::just_released;
break;
case key_state::just_released:
key_last_tick.state = key_state::up;
break;
}
}
}
void update_key_states()
{
update_key_state(left_signal_key);
update_key_state(hazzards_key);
update_key_state(right_signal_key);
}
struct signal_state {
enum
{
right,
left,
hazzards
};
};
inline void set_turn_signals(int signal_state, bool on)
{
static constexpr int off = 0;
if (self::veh && big::g->vehicle.turn_signals)
{
switch (signal_state)
{
case signal_state::hazzards:
VEHICLE::SET_VEHICLE_INDICATOR_LIGHTS(self::veh, signal_state::left, on);
VEHICLE::SET_VEHICLE_INDICATOR_LIGHTS(self::veh, signal_state::right, on);
break;
case signal_state::right:
VEHICLE::SET_VEHICLE_INDICATOR_LIGHTS(self::veh, signal_state::left, off);
VEHICLE::SET_VEHICLE_INDICATOR_LIGHTS(self::veh, signal_state::right, on);
break;
case signal_state::left:
VEHICLE::SET_VEHICLE_INDICATOR_LIGHTS(self::veh, signal_state::left, on);
VEHICLE::SET_VEHICLE_INDICATOR_LIGHTS(self::veh, signal_state::right, off);
break;
}
}
}
namespace big
{
static bool b_last_turn_signals = false;
void looped::vehicle_turn_signals()
{
static bool hazzards = false;
bool b_turn_signals = g->vehicle.turn_signals;
if (!b_turn_signals && b_turn_signals != b_last_turn_signals)
{
VEHICLE::SET_VEHICLE_INDICATOR_LIGHTS(PED::GET_VEHICLE_PED_IS_IN(PLAYER::PLAYER_PED_ID(), false), 0, 0);
VEHICLE::SET_VEHICLE_INDICATOR_LIGHTS(PED::GET_VEHICLE_PED_IS_IN(PLAYER::PLAYER_PED_ID(), false), 1, 0);
}
if (g->vehicle.turn_signals)
{
static bool ran_once = []
{
g_notification_service->push("Instructions", "Manual: J = Left, L = Right, K = Toggle Hazzards");
return true;
}();
}
update_key_states();
if (left_signal_key.state == key_state::just_pressed || g->vehicle.auto_turn_signals && PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_LEFT_ONLY))
{
set_turn_signals(signal_state::left, true);
}
if (right_signal_key.state == key_state::just_pressed || g->vehicle.auto_turn_signals && PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_RIGHT_ONLY))
{
set_turn_signals(signal_state::right, true);
}
if (hazzards_key.state == key_state::just_pressed && !hazzards)
{
set_turn_signals(signal_state::hazzards, true);
hazzards = true;
}
else if (hazzards_key.state == key_state::just_pressed && hazzards || !g->vehicle.turn_signals)
{
set_turn_signals(signal_state::hazzards, false);
hazzards = false;
}
if (PAD::IS_CONTROL_JUST_RELEASED(0, (int)ControllerInputs::INPUT_VEH_MOVE_LEFT_ONLY))
{
if (g->vehicle.turn_signals)
{
script::get_current()->yield(1500ms);
}
set_turn_signals(signal_state::left, false);
}
if (PAD::IS_CONTROL_JUST_RELEASED(0, (int)ControllerInputs::INPUT_VEH_MOVE_RIGHT_ONLY))
{
if (g->vehicle.turn_signals)
{
script::get_current()->yield(1500ms);
}
set_turn_signals(signal_state::right, false);
}
b_last_turn_signals = g->vehicle.turn_signals;
}
}

View File

@ -0,0 +1,64 @@
#include "backend/looped/looped.hpp"
#include "util/misc.hpp"
#include "util/water.hpp"
namespace big
{
static uint32_t last_bits = 0;
static float last_water_collistion_strength = 0;
void looped::vehicle_god_mode()
{
if (g_local_player == nullptr || g_local_player->m_vehicle == nullptr)
{
return;
}
if (
(g->vehicle.god_mode || g->vehicle.proof_collision) &&
g_local_player->m_ped_task_flag & (int)ePedTask::TASK_DRIVING
) {
g_local_player->m_vehicle->m_deform_god = 0x8C;
}
else
{
g_local_player->m_vehicle->m_deform_god = 0x9C;
}
float* water_collision_ptr = nullptr;
if (g_local_player->m_vehicle->m_navigation != nullptr)
{
water_collision_ptr = water::get_water_collision_ptr(g_local_player->m_vehicle->m_navigation);
}
uint32_t bits = g->vehicle.proof_mask;
uint32_t changed_bits = bits ^ last_bits;
uint32_t changed_or_enabled_bits = bits | changed_bits;
if (changed_or_enabled_bits)
{
uint32_t unchanged_bits = g_local_player->m_vehicle->m_damage_bits & ~changed_or_enabled_bits;
g_local_player->m_vehicle->m_damage_bits = unchanged_bits | bits;
last_bits = bits;
if (changed_or_enabled_bits & (uint32_t)eEntityProofs::WATER)
{
water::reset_ped_oxygen_time(g_local_player);
if (water_collision_ptr != nullptr && *water_collision_ptr != 0.f)
{
last_water_collistion_strength = *water_collision_ptr;
*water_collision_ptr = 0;
}
return;
}
}
if (last_water_collistion_strength != 0 && water_collision_ptr != nullptr)
{
*water_collision_ptr = last_water_collistion_strength;
last_water_collistion_strength = 0;
}
}
}

View File

@ -0,0 +1,23 @@
#include "backend/looped/looped.hpp"
#include "gta/enums.hpp"
#include "natives.hpp"
namespace big
{
void looped::vehicle_jump()
{
if (!g->vehicle.vehicle_jump) return;
const auto vehicle = self::veh;
if (!vehicle || !ENTITY::IS_ENTITY_A_VEHICLE(vehicle))
{
return;
}
if (PAD::IS_CONTROL_JUST_PRESSED(0, (int)ControllerInputs::INPUT_VEH_HANDBRAKE))
{
ENTITY::APPLY_FORCE_TO_ENTITY(vehicle, 1, 0.0, 0.0, 20, 0.0, 0.0, 0.0, 0, 0, 1, 1, 0, 1);
}
}
}