From 3eacc0998cc54500026bb616b5355922df167665 Mon Sep 17 00:00:00 2001 From: TheGreenBandit <106003542+TheGreenBandit@users.noreply.github.com> Date: Sun, 23 Jul 2023 12:51:57 -0400 Subject: [PATCH] Rework rgb for fun vehicle and paintgun (#1783) Closes #1819 --- CMakeLists.txt | 3 +- src/backend/backend.cpp | 1 - src/backend/looped/looped.hpp | 1 - src/backend/looped/system/rgb.cpp | 101 ------------------ src/backend/looped/vehicle/rgb_paint.cpp | 55 ++++++---- src/backend/looped/weapons/paintgun.cpp | 37 +++++-- src/core/data/color.hpp | 10 -- src/core/settings.hpp | 8 +- .../misc/update_timecycle_keyframe_data.cpp | 1 - src/views/self/view_weapons.cpp | 1 + src/views/settings/view_settings.cpp | 5 - src/views/world/view_vfx.cpp | 3 - 12 files changed, 65 insertions(+), 161 deletions(-) delete mode 100644 src/backend/looped/system/rgb.cpp delete mode 100644 src/core/data/color.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 6af3c642..6d8e8feb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,9 +16,8 @@ include(scripts/json.cmake) include(scripts/cpr.cmake) include(scripts/zydis.cmake) include(scripts/lua.cmake) - -message("\nFetching custom modules") include(scripts/imgui.cmake) +message("\nFetching custom modules") include(scripts/gtav-classes.cmake) diff --git a/src/backend/backend.cpp b/src/backend/backend.cpp index f1536e1f..57812bb5 100644 --- a/src/backend/backend.cpp +++ b/src/backend/backend.cpp @@ -35,7 +35,6 @@ namespace big looped::system_desync_kick_protection(); looped::system_spoofing(); looped::system_mission_creator(); - looped::system_rainbow(); for (auto command : g_looped_commands) if (command->is_enabled()) diff --git a/src/backend/looped/looped.hpp b/src/backend/looped/looped.hpp index 6d3e35ae..4c70337d 100644 --- a/src/backend/looped/looped.hpp +++ b/src/backend/looped/looped.hpp @@ -40,7 +40,6 @@ namespace big static void system_desync_kick_protection(); static void system_spoofing(); static void system_mission_creator(); - static void system_rainbow(); static void vehicle_auto_drive(); static void vehicle_allow_all_weapons(); diff --git a/src/backend/looped/system/rgb.cpp b/src/backend/looped/system/rgb.cpp deleted file mode 100644 index 9ad0f387..00000000 --- a/src/backend/looped/system/rgb.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include "backend/looped/looped.hpp" -#include "core/data/color.hpp" - -namespace big -{ - void looped::system_rainbow() - { - static std::chrono::system_clock::time_point last_rgb_run_time; - static std::chrono::milliseconds delay = 0s; - - 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, - }; - - - if (last_rgb_run_time + delay < std::chrono::system_clock::now()) - { - int delay_step = 100; - if (g.settings.rainbow.spasm) - { - rgb.red = rand() % 256; - rgb.green = rand() % 256; - rgb.blue = rand() % 256; - } - else if (g.settings.rainbow.fade) - { - int delay_step = 10; - - static int rgb_controller_v = rgb_controller_green_up; - - switch (rgb_controller_v) - { - case rgb_controller_green_up: - rgb.green += 5; - if (rgb.green >= 255) - { - rgb.green = 255; - rgb_controller_v = rgb_controller_red_down; - } - break; - - case rgb_controller_red_down: - rgb.red -= 5; - if (rgb.red < 0) - { - rgb.red = 0; - rgb_controller_v = rgb_controller_blue_up; - } - break; - - case rgb_controller_blue_up: - rgb.blue += 5; - if (rgb.blue >= 255) - { - rgb.blue = 255; - rgb_controller_v = rgb_controller_green_down; - } - break; - - case rgb_controller_green_down: - rgb.green -= 5; - if (rgb.green < 0) - { - rgb.green = 0; - rgb_controller_v = rgb_controller_red_up; - } - break; - - case rgb_controller_red_up: - rgb.red += 5; - if (rgb.red >= 255) - { - rgb.red = 255; - rgb_controller_v = rgb_controller_blue_down; - } - break; - - case rgb_controller_blue_down: - rgb.blue -= 5; - if (rgb.blue < 0) - { - rgb.blue = 0; - rgb_controller_v = rgb_controller_green_up; - } - break; - - default: break; - } - } - - delay = std::chrono::milliseconds(((delay_step * 10) + 10) - (g.settings.rainbow.speed * delay_step)); - last_rgb_run_time = std::chrono::system_clock::now(); - } - } -} \ No newline at end of file diff --git a/src/backend/looped/vehicle/rgb_paint.cpp b/src/backend/looped/vehicle/rgb_paint.cpp index ce20a15c..d73a3741 100644 --- a/src/backend/looped/vehicle/rgb_paint.cpp +++ b/src/backend/looped/vehicle/rgb_paint.cpp @@ -3,34 +3,50 @@ #include "backend/looped/looped.hpp" #include "natives.hpp" #include "script.hpp" -#include "core/data/color.hpp" namespace big { + float red = 255.f, green = 0.f, blue = 0.f; void looped::vehicle_rainbow_paint() { static std::chrono::system_clock::time_point last_rgb_run_time; static std::chrono::milliseconds delay = 0s; + static bool ran = false; - static int red = 255; - static int green = 0; - static int blue = 0; - - if (self::veh && g.vehicle.rainbow_paint.type != RainbowPaintType::Off && last_rgb_run_time + delay < std::chrono::system_clock::now()) + if (self::veh && g.vehicle.rainbow_paint.type != RainbowPaintType::Off) { - int delay_step = 100; - - if (g.vehicle.rainbow_paint.type == RainbowPaintType::Spasm) + if (g.vehicle.rainbow_paint.type == RainbowPaintType::Spasm && last_rgb_run_time + delay < std::chrono::system_clock::now()) { - red = rand() % 256; - green = rand() % 256; - blue = rand() % 256; + red = rand() % 255; + green = rand() % 255; + blue = rand() % 255; + delay = std::chrono::milliseconds((110) - (g.vehicle.rainbow_paint.speed * 10)); + last_rgb_run_time = std::chrono::system_clock::now(); + ran = true; } - else if (g.vehicle.rainbow_paint.type == RainbowPaintType::Fade) + + if (g.vehicle.rainbow_paint.type == RainbowPaintType::Fade) //messy but gets job done { - red = rgb.red; - blue = rgb.blue; - green = rgb.green; + if (ran) { red = 255; green = 0; blue = 0; ran = false; } + + if (red > 0 && blue == 0) + { + green += g.vehicle.rainbow_paint.speed; + red -= g.vehicle.rainbow_paint.speed; + } + if (green > 0 && red == 0) + { + blue += g.vehicle.rainbow_paint.speed; + green -= g.vehicle.rainbow_paint.speed; + } + if (blue > 0 && green == 0) + { + red += g.vehicle.rainbow_paint.speed; + blue -= g.vehicle.rainbow_paint.speed; + } + red = std::clamp(red, 0.f, 255.f); + green = std::clamp(green, 0.f, 255.f); + blue = std::clamp(blue, 0.f, 255.f); } if (g.vehicle.rainbow_paint.primary) @@ -43,19 +59,12 @@ namespace big } if (g.vehicle.rainbow_paint.neon) { - VEHICLE::SET_VEHICLE_NEON_ENABLED(self::veh, 0, 1); - VEHICLE::SET_VEHICLE_NEON_ENABLED(self::veh, 1, 1); - VEHICLE::SET_VEHICLE_NEON_ENABLED(self::veh, 2, 1); - VEHICLE::SET_VEHICLE_NEON_ENABLED(self::veh, 3, 1); VEHICLE::SET_VEHICLE_NEON_COLOUR(self::veh, red, green, blue); } if (g.vehicle.rainbow_paint.smoke) { VEHICLE::SET_VEHICLE_TYRE_SMOKE_COLOR(self::veh, red, green, blue); } - - delay = std::chrono::milliseconds(((delay_step * 10) + 10) - (g.vehicle.rainbow_paint.speed * delay_step)); - last_rgb_run_time = std::chrono::system_clock::now(); } } diff --git a/src/backend/looped/weapons/paintgun.cpp b/src/backend/looped/weapons/paintgun.cpp index 187d44ef..918b7fc0 100644 --- a/src/backend/looped/weapons/paintgun.cpp +++ b/src/backend/looped/weapons/paintgun.cpp @@ -2,19 +2,42 @@ #include "core/enums.hpp" #include "gta/enums.hpp" #include "util/entity.hpp" -#include "core/data/color.hpp" namespace big { void looped::weapons_paint_gun() { + static Vector3 col = {0, 0, 0}; + static float red = 255.f, green = 0.f, blue = 0.f; + if (g.weapons.paintgun.rainbow) { - g.weapons.paintgun.col[0] = rgb.red; - g.weapons.paintgun.col[1] = rgb.green; - g.weapons.paintgun.col[2] = rgb.blue; + if (red > 0 && blue == 0) + { + green += red; + red -= g.weapons.paintgun.speed; + } + if (green > 0 && red == 0) + { + blue += g.weapons.paintgun.speed; + green -= g.weapons.paintgun.speed; + } + if (blue > 0 && green == 0) + { + red += g.weapons.paintgun.speed; + blue -= g.weapons.paintgun.speed; + } + red = std::clamp(red, 0.f, 255.f); + green = std::clamp(green, 0.f, 255.f); + blue = std::clamp(blue, 0.f, 255.f); + } + if (g.weapons.paintgun.rainbow) + col = {red, green, blue}; + else + col = {g.weapons.paintgun.col[0], g.weapons.paintgun.col[1], g.weapons.paintgun.col[2]}; + if (g.weapons.custom_weapon == CustomWeapon::PAINT_GUN && (!g.self.custom_weapon_stop || WEAPON::IS_PED_ARMED(self::ped, 4 | 2))) { Vector3 c; entity::raycast(&c); @@ -35,9 +58,9 @@ namespace big 0.f, // always 0 0.5f, //size x 0.4f, //size y - g.weapons.paintgun.col[0], - g.weapons.paintgun.col[1], - g.weapons.paintgun.col[2], + col.x, + col.y, + col.z, g.weapons.paintgun.col[3], -1, true, diff --git a/src/core/data/color.hpp b/src/core/data/color.hpp deleted file mode 100644 index 83f29dbe..00000000 --- a/src/core/data/color.hpp +++ /dev/null @@ -1,10 +0,0 @@ -namespace big -{ - inline class rgb - { - public: - float red = 255.f; - float green = 0; - float blue = 0; - } rgb{}; -} \ No newline at end of file diff --git a/src/core/settings.hpp b/src/core/settings.hpp index d348158c..501ec340 100644 --- a/src/core/settings.hpp +++ b/src/core/settings.hpp @@ -422,13 +422,6 @@ namespace big { bool dev_dlc = false; - struct rainbow - { - bool fade = false; - bool spasm = false; - int speed = 1; - } rainbow{}; - struct hotkeys { bool editing_menu_toggle = false; @@ -732,6 +725,7 @@ namespace big struct paintgun { bool rainbow = false; + float speed = 1.f; float col[4] = {0.f, 0.f, 1.f, 1.f}; NLOHMANN_DEFINE_TYPE_INTRUSIVE(paintgun, rainbow, col) } paintgun{}; diff --git a/src/hooks/misc/update_timecycle_keyframe_data.cpp b/src/hooks/misc/update_timecycle_keyframe_data.cpp index 0a0934d6..a5798e77 100644 --- a/src/hooks/misc/update_timecycle_keyframe_data.cpp +++ b/src/hooks/misc/update_timecycle_keyframe_data.cpp @@ -1,5 +1,4 @@ #include "hooking.hpp" -#include "core/data/color.hpp" #include diff --git a/src/views/self/view_weapons.cpp b/src/views/self/view_weapons.cpp index e55166b1..2613c8ac 100644 --- a/src/views/self/view_weapons.cpp +++ b/src/views/self/view_weapons.cpp @@ -150,6 +150,7 @@ namespace big break; case CustomWeapon::PAINT_GUN: ImGui::Checkbox("Rainbow Color", &g.weapons.paintgun.rainbow); + ImGui::SliderFloat("Rainbow Speed", &g.weapons.paintgun.speed, 0.f, 10.f); if (!g.weapons.paintgun.rainbow) { ImGui::ColorEdit4("Paint Gun Color", g.weapons.paintgun.col); } } diff --git a/src/views/settings/view_settings.cpp b/src/views/settings/view_settings.cpp index b6ecedd7..cf7fd7ca 100644 --- a/src/views/settings/view_settings.cpp +++ b/src/views/settings/view_settings.cpp @@ -58,11 +58,6 @@ namespace big }); } - ImGui::SeparatorText("Rainbow"); - ImGui::Checkbox("Spasm", &g.settings.rainbow.spasm); - ImGui::Checkbox("Fade", &g.settings.rainbow.fade); - ImGui::SliderInt("Speed", &g.settings.rainbow.speed, 0, 10); // TODO: THIS SPEED DOESNT MAKE SENSE - ImGui::SeparatorText("SETTINGS_MISC"_T.data()); ImGui::Checkbox("SETTINGS_MISC_DEV_DLC"_T.data(), &g.settings.dev_dlc); diff --git a/src/views/world/view_vfx.cpp b/src/views/world/view_vfx.cpp index a7e2f3be..3a04c5f9 100644 --- a/src/views/world/view_vfx.cpp +++ b/src/views/world/view_vfx.cpp @@ -1,8 +1,5 @@ #include "views/view.hpp" -#include - - namespace big { void view::vfx()