diff --git a/BigBaseV2/src/features/functions.cpp b/BigBaseV2/src/features/functions.cpp index 1a7eb122..daa89b56 100644 --- a/BigBaseV2/src/features/functions.cpp +++ b/BigBaseV2/src/features/functions.cpp @@ -120,4 +120,67 @@ namespace big::features::functions g_settings.save(); } + + bool take_control_of_entity(Entity ent) + { + for (uint8_t i = 0; !NETWORK::NETWORK_HAS_CONTROL_OF_ENTITY(ent) && i < 3; i++) + { + NETWORK::NETWORK_REQUEST_CONTROL_OF_ENTITY(ent); + + script::get_current()->yield(); + } + if (!NETWORK::NETWORK_HAS_CONTROL_OF_ENTITY(ent)) return false; + + int netHandle = NETWORK::NETWORK_GET_NETWORK_ID_FROM_ENTITY(ent); + NETWORK::SET_NETWORK_ID_CAN_MIGRATE(netHandle, true); + + return true; + } + + BOOL raycast_entity(Entity* ent) + { + BOOL hit; + Vector3 endCoords; + Vector3 surfaceNormal; + + Vector3 camCoords = CAM::GET_GAMEPLAY_CAM_COORD(); + Vector3 rot = CAM::GET_GAMEPLAY_CAM_ROT(2); + Vector3 dir = rotation_to_direction(rot); + Vector3 farCoords; + + farCoords.x = camCoords.x + dir.x * 1000; + farCoords.y = camCoords.y + dir.y * 1000; + farCoords.z = camCoords.z + dir.z * 1000; + + int ray = SHAPETEST::_START_SHAPE_TEST_RAY(camCoords.x, camCoords.y, camCoords.z, farCoords.x, farCoords.y, farCoords.z, -1, 0, 7); + SHAPETEST::GET_SHAPE_TEST_RESULT(ray, &hit, &endCoords, &surfaceNormal, ent); + + return hit; + } + + float deg_to_rad(float deg) + { + double radian = (3.14159265359 / 180) * deg; + return (float)radian; + } + + Vector3 rotation_to_direction(Vector3 rotation) + { + float x = deg_to_rad(rotation.x); + float z = deg_to_rad(rotation.z); + + float num = abs(cos(x)); + + return Vector3 + { + -sin(z) * num, + cos(z) * num, + sin(x) + }; + } + + double distance_between_vectors(Vector3 a, Vector3 b) + { + return sqrt(pow((a.x - b.x), 2) + pow((a.y - b.y), 2) + pow((a.z - b.z), 2)); + } } \ No newline at end of file diff --git a/BigBaseV2/src/features/functions.hpp b/BigBaseV2/src/features/functions.hpp index 3c34a8ba..67aaf485 100644 --- a/BigBaseV2/src/features/functions.hpp +++ b/BigBaseV2/src/features/functions.hpp @@ -12,4 +12,11 @@ namespace big::features::functions void set_player_level(int level); void spoof_rank(int rank); void toggle_protections(bool toggle); + + bool take_control_of_entity(Entity ent); + + BOOL raycast_entity(Entity* ent); + float deg_to_rad(float deg); + Vector3 rotation_to_direction(Vector3 rotation); + double distance_between_vectors(Vector3 a, Vector3 b); } \ No newline at end of file diff --git a/BigBaseV2/src/features/looped/gravity_gun.cpp b/BigBaseV2/src/features/looped/gravity_gun.cpp new file mode 100644 index 00000000..8aac047a --- /dev/null +++ b/BigBaseV2/src/features/looped/gravity_gun.cpp @@ -0,0 +1,172 @@ +#include "features.hpp" + +namespace big +{ + static Entity entity = -1; + static Vector3 location; + static Vector3 other; + static double dist; + + static const float multiplier = 3; + static const int scroll = 2; + static const int controls[] = { 14, 15, 24 }; + + void features::gravity_gun() + { + bool bGravityGun = g_settings.options["gravity_gun"]; + + if (bGravityGun) + { + // ZOOMED IN + if (PAD::IS_DISABLED_CONTROL_PRESSED(0, 25)) + { + for (int control : controls) + PAD::DISABLE_CONTROL_ACTION(0, control, true); + + location = ENTITY::GET_ENTITY_COORDS(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(g_playerId), true); + + // Attack RELEASED + if (PAD::IS_DISABLED_CONTROL_JUST_RELEASED(0, 24)) + { + if (functions::raycast_entity(&entity)) + { + other = ENTITY::GET_ENTITY_COORDS(entity, true); + dist = functions::distance_between_vectors(location, other); + + if (dist > 50) + { + entity = -1; + + notify::above_map("Entity is too far."); + } + else + { + functions::take_control_of_entity(entity); + + features::notify::above_map("Selected entity at crosshair."); + } + } + else + { + entity = -1; + + features::notify::above_map("No entity found."); + } + } + + if (ENTITY::DOES_ENTITY_EXIST(entity)) + { + // Scroll Away + if (PAD::IS_DISABLED_CONTROL_PRESSED(0, 14)) + dist -= 5; + if (PAD::IS_DISABLED_CONTROL_PRESSED(0, 15)) + dist += 5; + + functions::take_control_of_entity(entity); + + ENTITY::SET_ENTITY_COLLISION(entity, false, false); + + other = ENTITY::GET_ENTITY_COORDS(entity, true); + + Vector3 rot = CAM::GET_GAMEPLAY_CAM_ROT(2); + float pitch = functions::deg_to_rad(rot.x - 0); // vertical + // float roll = rot.y; + float yaw = functions::deg_to_rad(rot.z + 90); // horizontal + + Vector3 zRot; + + zRot.x = location.x + (dist * cos(pitch) * cos(yaw)); + zRot.y = location.y + (dist * sin(yaw) * cos(pitch)); + zRot.z = location.z + (dist * sin(pitch)); + + ENTITY::SET_ENTITY_VELOCITY(entity, (zRot.x - other.x) * multiplier, (zRot.y - other.y) * multiplier, (zRot.z - other.z) * multiplier); + } + } + else if (entity != -1) + { + ENTITY::SET_ENTITY_COLLISION(entity, true, true); + + entity = -1; + + features::notify::above_map("Released entity."); + } + } + } + + float deg_to_rad(float deg) + { + double radian = (3.14159265359 / 180) * deg; + return (float)radian; + } + + Vector3 rotation_to_direction(Vector3 rotation) + { + float x = deg_to_rad(rotation.x); + float z = deg_to_rad(rotation.z); + + float num = abs(cos(x)); + + return Vector3 + { + -sin(z) * num, + cos(z) * num, + sin(x) + }; + } + + Vector3 screen_to_world(Vector3 position, Vector3 rotation, float mouseX, float mouseY, Vector3 &out) + { + Vector3 direction = rotation_to_direction(rotation); + + Vector3 rotUp = rotation; + Vector3 rotDown = rotation; + Vector3 rotLeft = rotation; + Vector3 rotRight = rotation; + + rotUp.x += 1; + rotDown.x -= 1; + rotLeft.z -= 1; + rotRight.z += 1; + + Vector3 camRight = rotation_to_direction(rotRight) - rotation_to_direction(rotLeft); + Vector3 camUp = rotation_to_direction(rotUp) - rotation_to_direction(rotDown); + + float rollRad = -deg_to_rad(rotation.y); + + Vector3 camRightRoll = camRight * cos(rollRad) - camUp * sin(rollRad); + Vector3 camUpRoll = camRight * sin(rollRad) + camUp * cos(rollRad); + + Vector3 point3d = position + direction * 1.f + camRightRoll + camUpRoll; + float x, y; + if (!GRAPHICS::GET_SCREEN_COORD_FROM_WORLD_COORD(point3d.x, point3d.y, point3d.z, &x, &y)) + { + out = direction; + + return position + direction * 1.f; + } + + Vector3 point3d_zero = position + direction * 1.f; + float x_zero, y_zero; + if (!GRAPHICS::GET_SCREEN_COORD_FROM_WORLD_COORD(point3d_zero.x, point3d_zero.y, point3d_zero.z, &x_zero, &y_zero)) + { + out = direction; + + return position + direction * 1.f; + } + + const double eps = .001; + if (abs(x - x_zero) < eps || abs(y - y_zero) < eps) + { + out = direction; + + return position + direction * 1.f; + } + + float scaleX = (mouseX - x_zero) / (x - x_zero); + float scaleY = (mouseY - y_zero) / (y - y_zero); + + Vector3 point3d_ret = position + direction * 1.f + camRightRoll * scaleX + camUpRoll * scaleY; + out = direction + camRightRoll * scaleX + camUpRoll * scaleY; + return point3d_ret; + } +} \ No newline at end of file diff --git a/BigBaseV2/src/gta/vector.hpp b/BigBaseV2/src/gta/vector.hpp index 9ec39766..523f7495 100644 --- a/BigBaseV2/src/gta/vector.hpp +++ b/BigBaseV2/src/gta/vector.hpp @@ -32,6 +32,42 @@ namespace rage scrVector(float x, float y, float z) : x(x), y(y), z(z) {} + + scrVector operator+(const scrVector& other) + { + scrVector vec; + vec.x = this->x + other.x; + vec.y = this->y + other.y; + vec.z = this->z + other.z; + return vec; + } + + scrVector operator-(const scrVector& other) + { + scrVector vec; + vec.x = this->x - other.x; + vec.y = this->y - other.y; + vec.z = this->z - other.z; + return vec; + } + + scrVector operator*(const scrVector& other) + { + scrVector vec; + vec.x = this->x * other.x; + vec.y = this->y * other.y; + vec.z = this->z * other.z; + return vec; + } + + scrVector operator*(const float& other) + { + scrVector vec; + vec.x = this->x * other; + vec.y = this->y * other; + vec.z = this->z * other; + return vec; + } public: float x{}; private: