From 94f956b50a744dfaf48bf593a53f9a4f2f308ffc Mon Sep 17 00:00:00 2001 From: gir489 <100792176+gir489returns@users.noreply.github.com> Date: Sat, 10 Aug 2024 19:11:56 -0400 Subject: [PATCH 1/7] Better enemy detection for aimbot (#3527) * Added better enemy detection to aimbot and triggerbot. * Fixed aimbot and triggerbot using an unreliable method of determining the target's current vehicle. * Fixed aimbot and triggerbot trying to go after targets that were untargetable. * Refactored is_ped_a_friend function. * Added threat check to aimbot. --- src/backend/looped/weapons/aimbot.cpp | 40 +- src/backend/looped/weapons/triggerbot.cpp | 31 +- src/core/settings.hpp | 1 + src/function_types.hpp | 3 + src/gta/enums.hpp | 1 + src/gta_pointers.hpp | 3 + src/pointers.cpp | 18 + src/util/blip.cpp | 13 + src/util/blip.hpp | 2 + src/util/ped.cpp | 195 ++++ src/util/ped.hpp | 1087 +++++++++------------ src/views/self/view_weapons.cpp | 2 + 12 files changed, 728 insertions(+), 668 deletions(-) create mode 100644 src/util/ped.cpp diff --git a/src/backend/looped/weapons/aimbot.cpp b/src/backend/looped/weapons/aimbot.cpp index cec26286..7b4a8024 100644 --- a/src/backend/looped/weapons/aimbot.cpp +++ b/src/backend/looped/weapons/aimbot.cpp @@ -6,6 +6,7 @@ #include "util/pools.hpp" #include "services/friends/friends_service.hpp" #include "services/player_database/player_database_service.hpp" +#include "util/ped.hpp" namespace big { @@ -15,6 +16,9 @@ namespace big bool_command g_aimbot_only_on_enemy("aimonlyatenemy", "BACKEND_LOOPED_WEAPONS_AIM_ONLY_AT_ENEMY", "BACKEND_LOOPED_WEAPONS_AIM_ONLY_AT_ENEMY_DESC", g.weapons.aimbot.only_on_enemy); + bool_command g_aimbot_only_on_threat("aimonlyatthreats", "BACKEND_LOOPED_WEAPONS_AIM_ONLY_AT_THREATS", "BACKEND_LOOPED_WEAPONS_AIM_ONLY_AT_THREATS_DESC", + g.weapons.aimbot.only_on_enemy); + class aimbot : looped_command { using looped_command::looped_command; @@ -144,12 +148,17 @@ namespace big continue; } + const auto ped_handle = g_pointers->m_gta.m_ptr_to_handle(ped); const bool is_not_a_player_and_we_target_only_players = g_aimbot_only_on_player.is_enabled() && !ped->m_player_info; - const bool we_in_the_same_vehicle = self::veh != 0 && ped->m_vehicle == g_player_service->get_self()->get_current_vehicle(); - if (is_not_a_player_and_we_target_only_players || we_in_the_same_vehicle) + const bool are_we_in_the_same_vehicle = self::veh != 0 && self::veh == PED::GET_VEHICLE_PED_IS_IN(ped_handle, TRUE); + if (is_not_a_player_and_we_target_only_players || are_we_in_the_same_vehicle) { continue; } + + auto weapon_info = g_local_player->m_weapon_manager->m_weapon_info; + if (PED::GET_PED_CONFIG_FLAG(ped_handle, 9, TRUE) || !g_pointers->m_gta.m_can_do_damage_to_ped(g_local_player, weapon_info, ped)) //Can't do damage to them, skip. + continue; if (g.weapons.aimbot.exclude_friends && ped->m_player_info) { @@ -162,29 +171,14 @@ namespace big continue; } - const auto ped_handle = g_pointers->m_gta.m_ptr_to_handle(ped); - - if (g_aimbot_only_on_enemy.is_enabled()) + if (g_aimbot_only_on_enemy.is_enabled() && ped::is_ped_a_friend(ped_handle, ped)) { - bool is_hated_relationship = false; - bool is_in_combat = PED::IS_PED_IN_COMBAT(ped_handle, self::ped); - auto blip_color = HUD::GET_BLIP_HUD_COLOUR(HUD::GET_BLIP_FROM_ENTITY(ped_handle)); - bool is_enemy = ((PED::GET_PED_CONFIG_FLAG(ped_handle, 38, TRUE) == TRUE) || (blip_color == HUD_COLOUR_RED)); + continue; + } - switch (PED::GET_RELATIONSHIP_BETWEEN_PEDS(ped_handle, self::ped)) - { - case Dislike: - case Wanted: - case Hate: is_hated_relationship = blip_color != HUD_COLOUR_BLUE; - } - - if (!is_hated_relationship && !is_in_combat && !is_enemy) - { - continue; - } - - /*if (PED::GET_PED_TYPE(ped_handle) != PED_TYPE_ANIMAL) - LOG(INFO) << " PED_TYPE " << PED::GET_PED_TYPE(ped_handle) << " hated " << is_hated_relationship << " combat " << is_in_combat << " enemy " << is_enemy << " blip_color " << blip_color;*/ + if (g.weapons.aimbot.only_on_threats && WEAPON::HAS_PED_GOT_WEAPON(ped_handle, 1, 1) == FALSE) + { + continue; } if (is_a_ped_type_we_dont_care_about(ped_handle)) diff --git a/src/backend/looped/weapons/triggerbot.cpp b/src/backend/looped/weapons/triggerbot.cpp index 8cc8b6ca..aae76a70 100644 --- a/src/backend/looped/weapons/triggerbot.cpp +++ b/src/backend/looped/weapons/triggerbot.cpp @@ -4,6 +4,7 @@ #include "util/entity.hpp" #include "services/friends/friends_service.hpp" #include "services/player_database/player_database_service.hpp" +#include "util/ped.hpp" namespace big { @@ -31,12 +32,16 @@ namespace big return; const bool trace_hit_non_player = g.weapons.aimbot.only_on_player && !ped_ptr->m_player_info; - const bool we_in_the_same_vehicle = self::veh != 0 && ped_ptr->m_vehicle == g_player_service->get_self()->get_current_vehicle(); - if (trace_hit_non_player || we_in_the_same_vehicle) + const bool are_we_in_the_same_vehicle = self::veh != 0 && self::veh == PED::GET_VEHICLE_PED_IS_IN(ped, TRUE); + if (trace_hit_non_player || are_we_in_the_same_vehicle) { return; } + auto weapon_info = g_local_player->m_weapon_manager->m_weapon_info; + if (PED::GET_PED_CONFIG_FLAG(ped, 9, TRUE) || !g_pointers->m_gta.m_can_do_damage_to_ped(g_local_player, weapon_info, ped_ptr)) //Can't do damage to them, skip. + return; + if (g.weapons.aimbot.exclude_friends && ped_ptr->m_player_info) { auto rockstar_id = ped_ptr->m_player_info->m_net_player_data.m_gamer_handle.m_rockstar_id; @@ -48,24 +53,14 @@ namespace big return; } - if (g.weapons.aimbot.only_on_enemy) + if (g.weapons.aimbot.only_on_enemy && ped::is_ped_a_friend(ped, ped_ptr)) { - bool is_hated_relationship = false; - bool is_in_combat = PED::IS_PED_IN_COMBAT(ped, self::ped); - auto blip_color = HUD::GET_BLIP_HUD_COLOUR(HUD::GET_BLIP_FROM_ENTITY(ped)); - bool is_enemy = ((PED::GET_PED_CONFIG_FLAG(ped, 38, TRUE) == TRUE) || (blip_color == HUD_COLOUR_RED)); + return; + } - switch (PED::GET_RELATIONSHIP_BETWEEN_PEDS(ped, self::ped)) - { - case Dislike: - case Wanted: - case Hate: is_hated_relationship = blip_color != HUD_COLOUR_BLUE; - } - - if (!is_hated_relationship && !is_in_combat && !is_enemy) - { - return; - } + if (g.weapons.aimbot.only_on_threats && WEAPON::HAS_PED_GOT_WEAPON(ped, 1, 1) == FALSE) + { + return; } bool is_a_ped_type_we_dont_care_about; diff --git a/src/core/settings.hpp b/src/core/settings.hpp index 44b16f77..3abcc166 100644 --- a/src/core/settings.hpp +++ b/src/core/settings.hpp @@ -897,6 +897,7 @@ namespace big bool only_on_player = false; bool exclude_friends = false; bool only_on_enemy = false; + bool only_on_threats = false; bool has_target = false; bool use_weapon_range = false; float fov = 60.f; diff --git a/src/function_types.hpp b/src/function_types.hpp index a92fd40c..e628f7d8 100644 --- a/src/function_types.hpp +++ b/src/function_types.hpp @@ -225,4 +225,7 @@ namespace big::functions using create_chat_guid = void (*)(GUID* guid); using begin_scaleform = bool (*)(uint32_t* scaleform, const char* method); + + using is_ped_enemies_with = bool (*)(CPedIntelligence* from, CPed* target, bool check_relationship, bool skip_friend_check, bool skip_combat_task_check); + using can_do_damage_to_ped = bool (*)(CPed* from, CWeaponInfo* current_weapon, CPed* target); } diff --git a/src/gta/enums.hpp b/src/gta/enums.hpp index 4b103404..03251322 100644 --- a/src/gta/enums.hpp +++ b/src/gta/enums.hpp @@ -1469,6 +1469,7 @@ enum class BlipColors enum BlipDisplayBits : uint32_t { + BlipIsFriendly = (1 << 1), BlipIsFlashing = (1 << 2), BlipIsGPSRoute = (1 << 4), BlipShowHeightMarker = (1 << 5), diff --git a/src/gta_pointers.hpp b/src/gta_pointers.hpp index dc0fd00a..2c899f79 100644 --- a/src/gta_pointers.hpp +++ b/src/gta_pointers.hpp @@ -408,6 +408,9 @@ namespace big uint32_t* m_game_lifetime; functions::begin_scaleform m_begin_scaleform; + + functions::is_ped_enemies_with m_is_ped_enemies_with; + functions::can_do_damage_to_ped m_can_do_damage_to_ped; }; #pragma pack(pop) static_assert(sizeof(gta_pointers) % 8 == 0, "Pointers are not properly aligned"); diff --git a/src/pointers.cpp b/src/pointers.cpp index af71707c..a88ce8cd 100644 --- a/src/pointers.cpp +++ b/src/pointers.cpp @@ -1940,6 +1940,24 @@ namespace big { g_pointers->m_gta.m_begin_scaleform = ptr.as(); } + }, + // Is Ped Enemies With + { + "IPEW", + "E8 ? ? ? ? 45 8A FE 84 C0", + [](memory::handle ptr) + { + g_pointers->m_gta.m_is_ped_enemies_with = ptr.add(1).rip().as(); + } + }, + // Can Do Damage + { + "CDD", + "E8 ? ? ? ? 45 8A C4 84 C0", + [](memory::handle ptr) + { + g_pointers->m_gta.m_can_do_damage_to_ped = ptr.add(1).rip().as(); + } } >(); // don't leave a trailing comma at the end diff --git a/src/util/blip.cpp b/src/util/blip.cpp index 4a098a09..1dc4896d 100644 --- a/src/util/blip.cpp +++ b/src/util/blip.cpp @@ -79,4 +79,17 @@ namespace big::blip } return nullptr; } + + rage::CBlip* get_blip_from_blip_id(Blip blip_id) + { + for (int i = 0; i < 1500; i++) + { + auto blip = g_pointers->m_gta.m_blip_list->m_Blips[i].m_pBlip; + if (blip && (blip->m_blip_array_index == blip_id)) + { + return blip; + } + } + return nullptr; + } } \ No newline at end of file diff --git a/src/util/blip.hpp b/src/util/blip.hpp index e26b4bac..bc53b278 100644 --- a/src/util/blip.hpp +++ b/src/util/blip.hpp @@ -16,4 +16,6 @@ namespace big::blip bool get_objective_location(Vector3& location); rage::CBlip* get_selected_blip(); + + rage::CBlip* get_blip_from_blip_id(Blip); } \ No newline at end of file diff --git a/src/util/ped.cpp b/src/util/ped.cpp new file mode 100644 index 00000000..764dfc1d --- /dev/null +++ b/src/util/ped.cpp @@ -0,0 +1,195 @@ +#include "ped.hpp" + +namespace big::ped +{ + bool change_player_model(const Hash hash) + { + if (entity::request_model(hash)) + { + self::ped = PLAYER::PLAYER_PED_ID(); + PLAYER::SET_PLAYER_MODEL(self::id, hash); + script::get_current()->yield(); + STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(hash); + for (int i = 0; i < 12; i++) + { + PED::SET_PED_COMPONENT_VARIATION(self::ped, i, PED::GET_PED_DRAWABLE_VARIATION(self::ped, i), PED::GET_PED_TEXTURE_VARIATION(self::ped, i), PED::GET_PED_PALETTE_VARIATION(self::ped, i)); + } + return true; + } + return false; + } + + bool steal_outfit(const Ped target) + { + Ped ped = self::ped; + + if (ENTITY::GET_ENTITY_MODEL(ped) != ENTITY::GET_ENTITY_MODEL(target)) + { + return false; + } + for (int i = 0; i < 12; i++) + { + PED::SET_PED_COMPONENT_VARIATION(ped, i, PED::GET_PED_DRAWABLE_VARIATION(target, i), PED::GET_PED_TEXTURE_VARIATION(target, i), PED::GET_PED_PALETTE_VARIATION(target, i)); + } + + return true; + } + + void clone_ped(const Ped src, const Ped target) + { + PED::CLONE_PED_TO_TARGET(src, target); + auto src_ptr = g_pointers->m_gta.m_handle_to_ptr(src); + auto dst_ptr = g_pointers->m_gta.m_handle_to_ptr(target); + + if (src_ptr && dst_ptr) + { + for (auto container = src_ptr->m_extension_container; container; container = container->m_next) + { + if (container->m_entry && container->m_entry->get_id() == 0xB) + { + g_pointers->m_gta.m_set_head_blend_data(reinterpret_cast(dst_ptr), + reinterpret_cast(container->m_entry)); + break; + } + } + } + } + + void steal_identity(const Ped target) + { + const int max_health = ENTITY::GET_ENTITY_MAX_HEALTH(self::ped); + const int current_health = ENTITY::GET_ENTITY_HEALTH(self::ped); + const int current_armor = PED::GET_PED_ARMOUR(self::ped); + + if (ENTITY::GET_ENTITY_MODEL(target) != ENTITY::GET_ENTITY_MODEL(self::id)) + { + PLAYER::SET_PLAYER_MODEL(self::id, ENTITY::GET_ENTITY_MODEL(target)); + script::get_current()->yield(); + } + clone_ped(target, self::ped); + ENTITY::SET_ENTITY_MAX_HEALTH(self::ped, max_health); + ENTITY::SET_ENTITY_HEALTH(self::ped, current_health, 0, 0); + PED::SET_PED_ARMOUR(self::ped, current_armor); + } + + void kill_ped(const Ped ped) + { + if (entity::take_control_of(ped, 0)) + ENTITY::SET_ENTITY_HEALTH(ped, 0, self::ped, 0); + else + { + auto ptr = g_pointers->m_gta.m_handle_to_ptr(ped); + if (!ptr) + return; + + g_pointers->m_gta.m_send_network_damage(g_player_service->get_self()->get_ped(), ptr, ptr->get_position(), 0, true, "weapon_explosion"_J, 10000.0f, 2, 0, (1 << 4), 0, 0, 0, false, false, true, true, nullptr); + } + } + + Ped spawn(ePedType pedType, Hash hash, Ped clone, Vector3 location, float heading, bool is_networked) + { + if (entity::request_model(hash)) + { + Ped ped = PED::CREATE_PED(pedType, hash, location.x, location.y, location.z, heading, is_networked, false); + + script::get_current()->yield(); + + if (clone) + { + clone_ped(clone, ped); + } + + STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(hash); + + return ped; + } + return 0; + } + + void set_ped_random_component_variation(Ped ped) + { + constexpr auto range = [](int lower_bound, int upper_bound) -> int { + return std::rand() % (upper_bound - lower_bound + 1) + lower_bound; + }; + + outfit::components_t components; + + for (auto& item : components.items) + { + int drawable_id_max = PED::GET_NUMBER_OF_PED_DRAWABLE_VARIATIONS(ped, item.id) - 1; + if (drawable_id_max == -1) + continue; + int drawable_id = range(0, drawable_id_max); + int texture_id_max = PED::GET_NUMBER_OF_PED_TEXTURE_VARIATIONS(ped, item.id, drawable_id) - 1; + if (texture_id_max == -1) + continue; + int texture_id = range(0, texture_id_max); + PED::SET_PED_COMPONENT_VARIATION(ped, item.id, drawable_id, texture_id, PED::GET_PED_PALETTE_VARIATION(ped, item.id)); + } + } + + player_ptr get_player_from_ped(Ped ped) + { + for (auto& p : g_player_service->players()) + { + if (p.second->get_ped()) + { + if (p.second->get_ped() == g_pointers->m_gta.m_handle_to_ptr(ped)) + return p.second; + } + } + return nullptr; + } + + bool load_animation_dict(const char* dict) + { + if (STREAMING::HAS_ANIM_DICT_LOADED(dict)) + return true; + + for (uint8_t i = 0; !STREAMING::HAS_ANIM_DICT_LOADED(dict) && i < 35; i++) + { + STREAMING::REQUEST_ANIM_DICT(dict); + script::get_current()->yield(); + } + + return STREAMING::HAS_ANIM_DICT_LOADED(dict); + } + + void ped_play_animation(Ped ped, const std::string_view& animDict, const std::string_view& animName, float speed, float speedMultiplier, int duration, int flag, float playbackRate, bool lockPos, Vector3 pos, Vector3 rot, int ik_flags) + { + if (load_animation_dict(animDict.data())) + if (pos.x == 0 && pos.y == 0 && pos.z == 0) + TASK::TASK_PLAY_ANIM(ped, animDict.data(), animName.data(), speed, speedMultiplier, duration, flag, playbackRate, lockPos, lockPos, lockPos); + else + TASK::TASK_PLAY_ANIM_ADVANCED(ped, animDict.data(), animName.data(), pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, speed, speedMultiplier, duration, flag, playbackRate, lockPos, ik_flags); + } + + /* + * Will make the ped enter the vehicle with animation if vehicle is in vicinity + * Param movespeed: 1 = walk, 2 = run, 3 = sprint + */ + void ped_enter_vehicle_animated(Ped ped, Vehicle veh, eVehicleSeats seat, int movespeed) + { + if (entity::take_control_of(ped)) + { + if (ENTITY::DOES_ENTITY_EXIST(veh)) + { + if (math::distance_between_vectors(ENTITY::GET_ENTITY_COORDS(ped, 0), ENTITY::GET_ENTITY_COORDS(veh, 0)) < 15.f) + TASK::TASK_ENTER_VEHICLE(ped, veh, 10000, (int)seat, movespeed, 8, NULL, 0); + else + PED::SET_PED_INTO_VEHICLE(ped, veh, (int)seat); + } + } + } + + bool is_ped_a_friend(Ped ped, CPed* ped_ptr) + { + if (PED::GET_PED_CONFIG_FLAG(ped, 38, TRUE) == TRUE) + return false; + + if (PED::IS_PED_IN_COMBAT(ped, self::ped)) + return false; + + return !g_pointers->m_gta.m_is_ped_enemies_with(ped_ptr->m_ped_intelligence, g_local_player, true, false, false); + } +} \ No newline at end of file diff --git a/src/util/ped.hpp b/src/util/ped.hpp index aaa8431a..ecd15189 100644 --- a/src/util/ped.hpp +++ b/src/util/ped.hpp @@ -1,627 +1,460 @@ -#pragma once -#include "entity.hpp" -#include "gta/enums.hpp" -#include "math.hpp" -#include "natives.hpp" -#include "outfit.hpp" -#include "pointers.hpp" -#include "services/players/player_service.hpp" -#include "script.hpp" - -namespace big::ped -{ - inline const std::map task_names{ - {0, "CTaskHandsUp"}, - {1, "CTaskClimbLadder"}, - {2, "CTaskExitVehicle"}, - {3, "CTaskCombatRoll"}, - {4, "CTaskAimGunOnFoot"}, - {5, "CTaskMovePlayer"}, - {6, "CTaskPlayerOnFoot"}, - {8, "CTaskWeapon"}, - {9, "CTaskPlayerWeapon"}, - {10, "CTaskPlayerIdles"}, - {12, "CTaskAimGun"}, - {12, "CTaskComplex"}, - {12, "CTaskFSMClone"}, - {12, "CTaskMotionBase"}, - {12, "CTaskMove"}, - {12, "CTaskMoveBase"}, - {12, "CTaskNMBehaviour"}, - {12, "CTaskNavBase"}, - {12, "CTaskScenario"}, - {12, "CTaskSearchBase"}, - {12, "CTaskSearchInVehicleBase"}, - {12, "CTaskShockingEvent"}, - {12, "CTaskTrainBase"}, - {12, "CTaskVehicleFSM"}, - {12, "CTaskVehicleGoTo"}, - {12, "CTaskVehicleMissionBase"}, - {12, "CTaskVehicleTempAction"}, - {14, "CTaskPause"}, - {15, "CTaskDoNothing"}, - {16, "CTaskGetUp"}, - {17, "CTaskGetUpAndStandStill"}, - {18, "CTaskFallOver"}, - {19, "CTaskFallAndGetUp"}, - {20, "CTaskCrawl"}, - {25, "CTaskComplexOnFire"}, - {26, "CTaskDamageElectric"}, - {28, "CTaskTriggerLookAt"}, - {29, "CTaskClearLookAt"}, - {30, "CTaskSetCharDecisionMaker"}, - {31, "CTaskSetPedDefensiveArea"}, - {32, "CTaskUseSequence"}, - {34, "CTaskMoveStandStill"}, - {35, "CTaskComplexControlMovement"}, - {36, "CTaskMoveSequence"}, - {38, "CTaskAmbientClips"}, - {39, "CTaskMoveInAir"}, - {40, "CTaskNetworkClone"}, - {41, "CTaskUseClimbOnRoute"}, - {42, "CTaskUseDropDownOnRoute"}, - {43, "CTaskUseLadderOnRoute"}, - {44, "CTaskSetBlockingOfNonTemporaryEvents"}, - {45, "CTaskForceMotionState"}, - {46, "CTaskSlopeScramble"}, - {47, "CTaskGoToAndClimbLadder"}, - {48, "CTaskClimbLadderFully"}, - {49, "CTaskRappel"}, - {50, "CTaskVault"}, - {51, "CTaskDropDown"}, - {52, "CTaskAffectSecondaryBehaviour"}, - {53, "CTaskAmbientLookAtEvent"}, - {54, "CTaskOpenDoor"}, - {55, "CTaskShovePed"}, - {56, "CTaskSwapWeapon"}, - {57, "CTaskGeneralSweep"}, - {58, "CTaskPolice"}, - {59, "CTaskPoliceOrderResponse"}, - {60, "CTaskPursueCriminal"}, - {62, "CTaskArrestPed"}, - {63, "CTaskArrestPed2"}, - {64, "CTaskBusted"}, - {65, "CTaskFirePatrol"}, - {66, "CTaskHeliOrderResponse"}, - {67, "CTaskHeliPassengerRappel"}, - {68, "CTaskAmbulancePatrol"}, - {69, "CTaskPoliceWantedResponse"}, - {70, "CTaskSwat"}, - {72, "CTaskSwatWantedResponse"}, - {73, "CTaskSwatOrderResponse"}, - {74, "CTaskSwatGoToStagingArea"}, - {75, "CTaskSwatFollowInLine"}, - {76, "CTaskWitness"}, - {77, "CTaskGangPatrol"}, - {78, "CTaskArmy"}, - {80, "CTaskShockingEventWatch"}, - {82, "CTaskShockingEventGoto"}, - {83, "CTaskShockingEventHurryAway"}, - {84, "CTaskShockingEventReactToAircraft"}, - {85, "CTaskShockingEventReact"}, - {86, "CTaskShockingEventBackAway"}, - {87, "CTaskShockingPoliceInvestigate"}, - {88, "CTaskShockingEventStopAndStare"}, - {89, "CTaskShockingNiceCarPicture"}, - {90, "CTaskShockingEventThreatResponse"}, - {92, "CTaskTakeOffHelmet"}, - {93, "CTaskCarReactToVehicleCollision"}, - {95, "CTaskCarReactToVehicleCollisionGetOut"}, - {97, "CTaskDyingDead"}, - {100, "CTaskWanderingScenario"}, - {101, "CTaskWanderingInRadiusScenario"}, - {103, "CTaskMoveBetweenPointsScenario"}, - {104, "CTaskChatScenario"}, - {106, "CTaskCowerScenario"}, - {107, "CTaskDeadBodyScenario"}, - {114, "CTaskSayAudio"}, - {116, "CTaskWaitForSteppingOut"}, - {117, "CTaskCoupleScenario"}, - {118, "CTaskUseScenario"}, - {119, "CTaskUseVehicleScenario"}, - {120, "CTaskUnalerted"}, - {121, "CTaskStealVehicle"}, - {122, "CTaskReactToPursuit"}, - {125, "CTaskHitWall"}, - {126, "CTaskCower"}, - {127, "CTaskCrouch"}, - {128, "CTaskMelee"}, - {129, "CTaskMoveMeleeMovement"}, - {130, "CTaskMeleeActionResult"}, - {131, "CTaskMeleeUpperbodyAnims"}, - {133, "CTaskMoVEScripted"}, - {134, "CTaskScriptedAnimation"}, - {135, "CTaskSynchronizedScene"}, - {137, "CTaskComplexEvasiveStep"}, - {138, "CTaskWalkRoundCarWhileWandering"}, - {140, "CTaskComplexStuckInAir"}, - {141, "CTaskWalkRoundEntity"}, - {142, "CTaskMoveWalkRoundVehicle"}, - {144, "CTaskReactToGunAimedAt"}, - {146, "CTaskDuckAndCover"}, - {147, "CTaskAggressiveRubberneck"}, - {150, "CTaskInVehicleBasic"}, - {151, "CTaskCarDriveWander"}, - {152, "CTaskLeaveAnyCar"}, - {153, "CTaskComplexGetOffBoat"}, - {155, "CTaskCarSetTempAction"}, - {156, "CTaskBringVehicleToHalt"}, - {157, "CTaskCarDrive"}, - {159, "CTaskPlayerDrive"}, - {160, "CTaskEnterVehicle"}, - {161, "CTaskEnterVehicleAlign"}, - {162, "CTaskOpenVehicleDoorFromOutside"}, - {163, "CTaskEnterVehicleSeat"}, - {164, "CTaskCloseVehicleDoorFromInside"}, - {165, "CTaskInVehicleSeatShuffle"}, - {167, "CTaskExitVehicleSeat"}, - {168, "CTaskCloseVehicleDoorFromOutside"}, - {169, "CTaskControlVehicle"}, - {170, "CTaskMotionInAutomobile"}, - {171, "CTaskMotionOnBicycle"}, - {172, "CTaskMotionOnBicycleController"}, - {173, "CTaskMotionInVehicle"}, - {174, "CTaskMotionInTurret"}, - {175, "CTaskReactToBeingJacked"}, - {176, "CTaskReactToBeingAskedToLeaveVehicle"}, - {177, "CTaskTryToGrabVehicleDoor"}, - {178, "CTaskGetOnTrain"}, - {179, "CTaskGetOffTrain"}, - {180, "CTaskRideTrain"}, - {190, "CTaskMountThrowProjectile"}, - {195, "CTaskGoToCarDoorAndStandStill"}, - {196, "CTaskMoveGoToVehicleDoor"}, - {197, "CTaskSetPedInVehicle"}, - {198, "CTaskSetPedOutOfVehicle"}, - {199, "CTaskVehicleMountedWeapon"}, - {200, "CTaskVehicleGun"}, - {201, "CTaskVehicleProjectile"}, - {204, "CTaskSmashCarWindow"}, - {205, "CTaskMoveGoToPoint"}, - {206, "CTaskMoveAchieveHeading"}, - {207, "CTaskMoveFaceTarget"}, - {208, "CTaskComplexGoToPointAndStandStillTimed"}, - {208, "CTaskMoveGoToPointAndStandStill"}, - {209, "CTaskMoveFollowPointRoute"}, - {210, "CTaskMoveSeekEntity_CEntitySeekPosCalculatorStandard"}, - {211, "CTaskMoveSeekEntity_CEntitySeekPosCalculatorLastNavMeshIntersection"}, - {212, "CTaskMoveSeekEntity_CEntitySeekPosCalculatorLastNavMeshIntersection2"}, - {213, "CTaskMoveSeekEntity_CEntitySeekPosCalculatorXYOffsetFixed"}, - {214, "CTaskMoveSeekEntity_CEntitySeekPosCalculatorXYOffsetFixed2"}, - {215, "CTaskExhaustedFlee"}, - {216, "CTaskGrowlAndFlee"}, - {217, "CTaskScenarioFlee"}, - {218, "CTaskSmartFlee"}, - {219, "CTaskFlyAway"}, - {220, "CTaskWalkAway"}, - {221, "CTaskWander"}, - {222, "CTaskWanderInArea"}, - {223, "CTaskFollowLeaderInFormation"}, - {224, "CTaskGoToPointAnyMeans"}, - {225, "CTaskTurnToFaceEntityOrCoord"}, - {226, "CTaskFollowLeaderAnyMeans"}, - {228, "CTaskFlyToPoint"}, - {229, "CTaskFlyingWander"}, - {230, "CTaskGoToPointAiming"}, - {231, "CTaskGoToScenario"}, - {233, "CTaskSeekEntityAiming"}, - {234, "CTaskSlideToCoord"}, - {235, "CTaskSwimmingWander"}, - {237, "CTaskMoveTrackingEntity"}, - {238, "CTaskMoveFollowNavMesh"}, - {239, "CTaskMoveGoToPointOnRoute"}, - {240, "CTaskEscapeBlast"}, - {241, "CTaskMoveWander"}, - {242, "CTaskMoveBeInFormation"}, - {243, "CTaskMoveCrowdAroundLocation"}, - {244, "CTaskMoveCrossRoadAtTrafficLights"}, - {245, "CTaskMoveWaitForTraffic"}, - {246, "CTaskMoveGoToPointStandStillAchieveHeading"}, - {251, "CTaskMoveGetOntoMainNavMesh"}, - {252, "CTaskMoveSlideToCoord"}, - {253, "CTaskMoveGoToPointRelativeToEntityAndStandStill"}, - {254, "CTaskHelicopterStrafe"}, - {256, "CTaskGetOutOfWater"}, - {259, "CTaskMoveFollowEntityOffset"}, - {261, "CTaskFollowWaypointRecording"}, - {264, "CTaskMotionPed"}, - {265, "CTaskMotionPedLowLod"}, - {268, "CTaskHumanLocomotion"}, - {269, "CTaskMotionBasicLocomotionLowLod"}, - {270, "CTaskMotionStrafing"}, - {271, "CTaskMotionTennis"}, - {272, "CTaskMotionAiming"}, - {273, "CTaskBirdLocomotion"}, - {274, "CTaskFlightlessBirdLocomotion"}, - {278, "CTaskFishLocomotion"}, - {279, "CTaskQuadLocomotion"}, - {280, "CTaskMotionDiving"}, - {281, "CTaskMotionSwimming"}, - {282, "CTaskMotionParachuting"}, - {283, "CTaskMotionDrunk"}, - {284, "CTaskRepositionMove"}, - {285, "CTaskMotionAimingTransition"}, - {286, "CTaskThrowProjectile"}, - {287, "CTaskCover"}, - {288, "CTaskMotionInCover"}, - {289, "CTaskAimAndThrowProjectile"}, - {290, "CTaskGun"}, - {291, "CTaskAimFromGround"}, - {295, "CTaskAimGunVehicleDriveBy"}, - {296, "CTaskAimGunScripted"}, - {298, "CTaskReloadGun"}, - {299, "CTaskWeaponBlocked"}, - {300, "CTaskEnterCover"}, - {301, "CTaskExitCover"}, - {302, "CTaskAimGunFromCoverIntro"}, - {303, "CTaskAimGunFromCoverOutro"}, - {304, "CTaskAimGunBlindFire"}, - {307, "CTaskCombatClosestTargetInArea"}, - {308, "CTaskCombatAdditionalTask"}, - {309, "CTaskInCover"}, - {313, "CTaskAimSweep"}, - {318, "CTaskSharkCircle"}, - {319, "CTaskSharkAttack"}, - {320, "CTaskAgitated"}, - {321, "CTaskAgitatedAction"}, - {322, "CTaskConfront"}, - {323, "CTaskIntimidate"}, - {324, "CTaskShove"}, - {325, "CTaskShoved"}, - {327, "CTaskCrouchToggle"}, - {328, "CTaskRevive"}, - {334, "CTaskParachute"}, - {335, "CTaskParachuteObject"}, - {336, "CTaskTakeOffPedVariation"}, - {339, "CTaskCombatSeekCover"}, - {341, "CTaskCombatFlank"}, - {342, "CTaskCombat"}, - {343, "CTaskCombatMounted"}, - {344, "CTaskMoveCircle"}, - {345, "CTaskMoveCombatMounted"}, - {346, "CTaskSearch"}, - {347, "CTaskSearchOnFoot"}, - {348, "CTaskSearchInAutomobile"}, - {349, "CTaskSearchInBoat"}, - {350, "CTaskSearchInHeli"}, - {351, "CTaskThreatResponse"}, - {352, "CTaskInvestigate"}, - {353, "CTaskStandGuardFSM"}, - {354, "CTaskPatrol"}, - {355, "CTaskShootAtTarget"}, - {356, "CTaskSetAndGuardArea"}, - {357, "CTaskStandGuard"}, - {358, "CTaskSeparate"}, - {359, "CTaskStayInCover"}, - {360, "CTaskVehicleCombat"}, - {361, "CTaskVehiclePersuit"}, - {362, "CTaskVehicleChase"}, - {363, "CTaskDraggingToSafety"}, - {364, "CTaskDraggedToSafety"}, - {365, "CTaskVariedAimPose"}, - {366, "CTaskMoveWithinAttackWindow"}, - {367, "CTaskMoveWithinDefensiveArea"}, - {368, "CTaskShootOutTire"}, - {369, "CTaskShellShocked"}, - {370, "CTaskBoatChase"}, - {371, "CTaskBoatCombat"}, - {372, "CTaskBoatStrafe"}, - {373, "CTaskHeliChase"}, - {374, "CTaskHeliCombat"}, - {375, "CTaskSubmarineCombat"}, - {376, "CTaskSubmarineChase"}, - {377, "CTaskPlaneChase"}, - {378, "CTaskTargetUnreachable"}, - {379, "CTaskTargetUnreachableInInterior"}, - {380, "CTaskTargetUnreachableInExterior"}, - {381, "CTaskStealthKill"}, - {382, "CTaskWrithe"}, - {383, "CTaskAdvance"}, - {384, "CTaskCharge"}, - {385, "CTaskMoveToTacticalPoint"}, - {386, "CTaskToHurtTransit"}, - {387, "CTaskAnimatedHitByExplosion"}, - {388, "CTaskNMRelax"}, - {390, "CTaskNMPose"}, - {391, "CTaskNMBrace"}, - {392, "CTaskNMBuoyancy"}, - {393, "CTaskNMInjuredOnGround"}, - {394, "CTaskNMShot"}, - {395, "CTaskNMHighFall"}, - {396, "CTaskNMBalance"}, - {397, "CTaskNMElectrocute"}, - {398, "CTaskNMPrototype"}, - {399, "CTaskNMExplosion"}, - {400, "CTaskNMOnFire"}, - {401, "CTaskNMScriptControl"}, - {402, "CTaskNMJumpRollFromRoadVehicle"}, - {403, "CTaskNMFlinch"}, - {404, "CTaskNMSit"}, - {405, "CTaskNMFallDown"}, - {406, "CTaskBlendFromNM"}, - {407, "CTaskNMControl"}, - {408, "CTaskNMDangle"}, - {411, "CTaskNMGenericAttach"}, - {412, "CTaskNMDrunk"}, - {413, "CTaskNMDraggingToSafety"}, - {414, "CTaskNMThroughWindscreen"}, - {415, "CTaskNMRiverRapids"}, - {416, "CTaskNMSimple"}, - {417, "CTaskRageRagdoll"}, - {420, "CTaskJumpVault"}, - {421, "CTaskJump"}, - {422, "CTaskFall"}, - {424, "CTaskReactAimWeapon"}, - {425, "CTaskChat"}, - {426, "CTaskMobilePhone"}, - {427, "CTaskReactToDeadPed"}, - {429, "CTaskSearchForUnknownThreat"}, - {431, "CTaskBomb"}, - {432, "CTaskDetonator"}, - {434, "CTaskAnimatedAttach"}, - {440, "CTaskCutScene"}, - {441, "CTaskReactToExplosion"}, - {442, "CTaskReactToImminentExplosion"}, - {443, "CTaskDiveToGround"}, - {444, "CTaskReactAndFlee"}, - {445, "CTaskSidestep"}, - {446, "CTaskCallPolice"}, - {447, "CTaskReactInDirection"}, - {448, "CTaskReactToBuddyShot"}, - {453, "CTaskVehicleGoToAutomobileNew"}, - {454, "CTaskVehicleGoToPlane"}, - {455, "CTaskVehicleGoToHelicopter"}, - {456, "CTaskVehicleGoToSubmarine"}, - {457, "CTaskVehicleGoToBoat"}, - {458, "CTaskVehicleGoToPointAutomobile"}, - {459, "CTaskVehicleGoToPointWithAvoidanceAutomobile"}, - {460, "CTaskVehiclePursue"}, - {461, "CTaskVehicleRam"}, - {462, "CTaskVehicleSpinOut"}, - {463, "CTaskVehicleApproach"}, - {464, "CTaskVehicleThreePointTurn"}, - {465, "CTaskVehicleDeadDriver"}, - {466, "CTaskVehicleCruiseNew"}, - {467, "CTaskVehicleCruiseBoat"}, - {468, "CTaskVehicleStop"}, - {469, "CTaskVehiclePullOver"}, - {470, "CTaskVehiclePassengerExit"}, - {471, "CTaskVehicleFlee"}, - {472, "CTaskVehicleFleeAirborne"}, - {473, "CTaskVehicleFleeBoat"}, - {474, "CTaskVehicleFollowRecording"}, - {475, "CTaskVehicleFollow"}, - {476, "CTaskVehicleBlock"}, - {477, "CTaskVehicleBlockCruiseInFront"}, - {478, "CTaskVehicleBlockBrakeInFront"}, - {479, "CTaskVehicleBlockBackAndForth"}, - {480, "CTaskVehicleCrash"}, - {481, "CTaskVehicleLand"}, - {482, "CTaskVehicleLandPlane"}, - {483, "CTaskVehicleHover"}, - {484, "CTaskVehicleAttack"}, - {485, "CTaskVehicleAttackTank"}, - {486, "CTaskVehicleCircle"}, - {487, "CTaskVehiclePoliceBehaviour"}, - {488, "CTaskVehiclePoliceBehaviourHelicopter"}, - {489, "CTaskVehiclePoliceBehaviourBoat"}, - {490, "CTaskVehicleEscort"}, - {491, "CTaskVehicleHeliProtect"}, - {493, "CTaskVehiclePlayerDriveAutomobile"}, - {494, "CTaskVehiclePlayerDriveBike"}, - {495, "CTaskVehiclePlayerDriveBoat"}, - {496, "CTaskVehiclePlayerDriveSubmarine"}, - {497, "CTaskVehiclePlayerDriveSubmarineCar"}, - {498, "CTaskVehiclePlayerDrivePlane"}, - {499, "CTaskVehiclePlayerDriveHeli"}, - {500, "CTaskVehiclePlayerDriveAutogyro"}, - {501, "CTaskVehiclePlayerDriveDiggerArm"}, - {502, "CTaskVehiclePlayerDriveTrain"}, - {503, "CTaskVehiclePlaneChase"}, - {504, "CTaskVehicleNoDriver"}, - {505, "CTaskVehicleAnimation"}, - {506, "CTaskVehicleConvertibleRoof"}, - {507, "CTaskVehicleParkNew"}, - {508, "CTaskVehicleFollowWaypointRecording"}, - {509, "CTaskVehicleGoToNavmesh"}, - {510, "CTaskVehicleReactToCopSiren"}, - {511, "CTaskVehicleGotoLongRange"}, - {512, "CTaskVehicleWait"}, - {513, "CTaskVehicleReverse"}, - {514, "CTaskVehicleBrake"}, - {515, "CTaskVehicleHandBrake"}, - {516, "CTaskVehicleTurn"}, - {517, "CTaskVehicleGoForward"}, - {518, "CTaskVehicleSwerve"}, - {519, "CTaskVehicleFlyDirection"}, - {520, "CTaskVehicleHeadonCollision"}, - {521, "CTaskVehicleBoostUseSteeringAngle"}, - {522, "CTaskVehicleShotTire"}, - {523, "CTaskVehicleBurnout"}, - {524, "CTaskVehicleRevEngine"}, - {525, "CTaskVehicleSurfaceInSubmarine"}, - {526, "CTaskVehiclePullAlongside"}, - {527, "CTaskVehicleTransformToSubmarine"}, - {528, "CTaskAnimatedFallback"}, - }; - - inline bool change_player_model(const Hash hash) - { - if (entity::request_model(hash)) - { - self::ped = PLAYER::PLAYER_PED_ID(); - PLAYER::SET_PLAYER_MODEL(self::id, hash); - script::get_current()->yield(); - STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(hash); - for (int i = 0; i < 12; i++) - { - PED::SET_PED_COMPONENT_VARIATION(self::ped, i, PED::GET_PED_DRAWABLE_VARIATION(self::ped, i), PED::GET_PED_TEXTURE_VARIATION(self::ped, i), PED::GET_PED_PALETTE_VARIATION(self::ped, i)); - } - return true; - } - return false; - } - - inline bool steal_outfit(const Ped target) - { - Ped ped = self::ped; - - if (ENTITY::GET_ENTITY_MODEL(ped) != ENTITY::GET_ENTITY_MODEL(target)) - { - return false; - } - for (int i = 0; i < 12; i++) - { - PED::SET_PED_COMPONENT_VARIATION(ped, i, PED::GET_PED_DRAWABLE_VARIATION(target, i), PED::GET_PED_TEXTURE_VARIATION(target, i), PED::GET_PED_PALETTE_VARIATION(target, i)); - } - - return true; - } - - inline void clone_ped(const Ped src, const Ped target) - { - PED::CLONE_PED_TO_TARGET(src, target); - auto src_ptr = g_pointers->m_gta.m_handle_to_ptr(src); - auto dst_ptr = g_pointers->m_gta.m_handle_to_ptr(target); - - if (src_ptr && dst_ptr) - { - for (auto container = src_ptr->m_extension_container; container; container = container->m_next) - { - if (container->m_entry && container->m_entry->get_id() == 0xB) - { - g_pointers->m_gta.m_set_head_blend_data(reinterpret_cast(dst_ptr), reinterpret_cast(container->m_entry)); - break; - } - } - } - } - - inline void steal_identity(const Ped target) - { - const int max_health = ENTITY::GET_ENTITY_MAX_HEALTH(self::ped); - const int current_health = ENTITY::GET_ENTITY_HEALTH(self::ped); - const int current_armor = PED::GET_PED_ARMOUR(self::ped); - - if (ENTITY::GET_ENTITY_MODEL(target) != ENTITY::GET_ENTITY_MODEL(self::id)) - { - PLAYER::SET_PLAYER_MODEL(self::id, ENTITY::GET_ENTITY_MODEL(target)); - script::get_current()->yield(); - } - clone_ped(target, self::ped); - ENTITY::SET_ENTITY_MAX_HEALTH(self::ped, max_health); - ENTITY::SET_ENTITY_HEALTH(self::ped, current_health, 0, 0); - PED::SET_PED_ARMOUR(self::ped, current_armor); - } - - inline void kill_ped(const Ped ped) - { - if (entity::take_control_of(ped, 0)) - ENTITY::SET_ENTITY_HEALTH(ped, 0, self::ped, 0); - else - { - auto ptr = g_pointers->m_gta.m_handle_to_ptr(ped); - if (!ptr) - return; - - g_pointers->m_gta.m_send_network_damage(g_player_service->get_self()->get_ped(), ptr, ptr->get_position(), 0, true, "weapon_explosion"_J, 10000.0f, 2, 0, (1 << 4), 0, 0, 0, false, false, true, true, nullptr); - } - } - - inline Ped spawn(ePedType pedType, Hash hash, Ped clone, Vector3 location, float heading, bool is_networked = true) - { - if (entity::request_model(hash)) - { - Ped ped = PED::CREATE_PED(pedType, hash, location.x, location.y, location.z, heading, is_networked, false); - - script::get_current()->yield(); - - if (clone) - { - clone_ped(clone, ped); - } - - STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(hash); - - return ped; - } - return 0; - } - - inline void set_ped_random_component_variation(Ped ped) - { - constexpr auto range = [](int lower_bound, int upper_bound) -> int { - return std::rand() % (upper_bound - lower_bound + 1) + lower_bound; - }; - - outfit::components_t components; - - for (auto& item : components.items) - { - int drawable_id_max = PED::GET_NUMBER_OF_PED_DRAWABLE_VARIATIONS(ped, item.id) - 1; - if (drawable_id_max == -1) - continue; - int drawable_id = range(0, drawable_id_max); - int texture_id_max = PED::GET_NUMBER_OF_PED_TEXTURE_VARIATIONS(ped, item.id, drawable_id) - 1; - if (texture_id_max == -1) - continue; - int texture_id = range(0, texture_id_max); - PED::SET_PED_COMPONENT_VARIATION(ped, item.id, drawable_id, texture_id, PED::GET_PED_PALETTE_VARIATION(ped, item.id)); - } - } - - inline player_ptr get_player_from_ped(Ped ped) - { - for (auto& p : g_player_service->players()) - { - if (p.second->get_ped()) - { - if (p.second->get_ped() == g_pointers->m_gta.m_handle_to_ptr(ped)) - return p.second; - } - } - return nullptr; - } - - inline bool load_animation_dict(const char* dict) - { - if (STREAMING::HAS_ANIM_DICT_LOADED(dict)) - return true; - - for (uint8_t i = 0; !STREAMING::HAS_ANIM_DICT_LOADED(dict) && i < 35; i++) - { - STREAMING::REQUEST_ANIM_DICT(dict); - script::get_current()->yield(); - } - - return STREAMING::HAS_ANIM_DICT_LOADED(dict); - } - - inline void ped_play_animation(Ped ped, const std::string_view& animDict, const std::string_view& animName, float speed = 4.f, float speedMultiplier = -4.f, int duration = -1, int flag = 0, float playbackRate = 0, bool lockPos = false, Vector3 pos = {}, Vector3 rot = {}, int ik_flags = 0) - { - if (load_animation_dict(animDict.data())) - if(pos.x == 0 && pos.y == 0 && pos.z == 0) - TASK::TASK_PLAY_ANIM(ped, animDict.data(), animName.data(), speed, speedMultiplier, duration, flag, playbackRate, lockPos, lockPos, lockPos); - else - TASK::TASK_PLAY_ANIM_ADVANCED(ped, animDict.data(), animName.data(), pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, speed, speedMultiplier, duration, flag, playbackRate, lockPos, ik_flags); - } - - /* - * Will make the ped enter the vehicle with animation if vehicle is in vicinity - * Param movespeed: 1 = walk, 2 = run, 3 = sprint - */ - inline void ped_enter_vehicle_animated(Ped ped, Vehicle veh, eVehicleSeats seat, int movespeed) - { - if (entity::take_control_of(ped)) - { - if (ENTITY::DOES_ENTITY_EXIST(veh)) - { - if (math::distance_between_vectors(ENTITY::GET_ENTITY_COORDS(ped, 0), ENTITY::GET_ENTITY_COORDS(veh, 0)) < 15.f) - TASK::TASK_ENTER_VEHICLE(ped, veh, 10000, (int)seat, movespeed, 8, NULL, 0); - else - PED::SET_PED_INTO_VEHICLE(ped, veh, (int)seat); - } - } - } - -} +#pragma once +#include "entity.hpp" +#include "gta/enums.hpp" +#include "math.hpp" +#include "natives.hpp" +#include "outfit.hpp" +#include "pointers.hpp" +#include "services/players/player_service.hpp" +#include "script.hpp" + +namespace big::ped +{ + inline const std::map task_names{ + {0, "CTaskHandsUp"}, + {1, "CTaskClimbLadder"}, + {2, "CTaskExitVehicle"}, + {3, "CTaskCombatRoll"}, + {4, "CTaskAimGunOnFoot"}, + {5, "CTaskMovePlayer"}, + {6, "CTaskPlayerOnFoot"}, + {8, "CTaskWeapon"}, + {9, "CTaskPlayerWeapon"}, + {10, "CTaskPlayerIdles"}, + {12, "CTaskAimGun"}, + {12, "CTaskComplex"}, + {12, "CTaskFSMClone"}, + {12, "CTaskMotionBase"}, + {12, "CTaskMove"}, + {12, "CTaskMoveBase"}, + {12, "CTaskNMBehaviour"}, + {12, "CTaskNavBase"}, + {12, "CTaskScenario"}, + {12, "CTaskSearchBase"}, + {12, "CTaskSearchInVehicleBase"}, + {12, "CTaskShockingEvent"}, + {12, "CTaskTrainBase"}, + {12, "CTaskVehicleFSM"}, + {12, "CTaskVehicleGoTo"}, + {12, "CTaskVehicleMissionBase"}, + {12, "CTaskVehicleTempAction"}, + {14, "CTaskPause"}, + {15, "CTaskDoNothing"}, + {16, "CTaskGetUp"}, + {17, "CTaskGetUpAndStandStill"}, + {18, "CTaskFallOver"}, + {19, "CTaskFallAndGetUp"}, + {20, "CTaskCrawl"}, + {25, "CTaskComplexOnFire"}, + {26, "CTaskDamageElectric"}, + {28, "CTaskTriggerLookAt"}, + {29, "CTaskClearLookAt"}, + {30, "CTaskSetCharDecisionMaker"}, + {31, "CTaskSetPedDefensiveArea"}, + {32, "CTaskUseSequence"}, + {34, "CTaskMoveStandStill"}, + {35, "CTaskComplexControlMovement"}, + {36, "CTaskMoveSequence"}, + {38, "CTaskAmbientClips"}, + {39, "CTaskMoveInAir"}, + {40, "CTaskNetworkClone"}, + {41, "CTaskUseClimbOnRoute"}, + {42, "CTaskUseDropDownOnRoute"}, + {43, "CTaskUseLadderOnRoute"}, + {44, "CTaskSetBlockingOfNonTemporaryEvents"}, + {45, "CTaskForceMotionState"}, + {46, "CTaskSlopeScramble"}, + {47, "CTaskGoToAndClimbLadder"}, + {48, "CTaskClimbLadderFully"}, + {49, "CTaskRappel"}, + {50, "CTaskVault"}, + {51, "CTaskDropDown"}, + {52, "CTaskAffectSecondaryBehaviour"}, + {53, "CTaskAmbientLookAtEvent"}, + {54, "CTaskOpenDoor"}, + {55, "CTaskShovePed"}, + {56, "CTaskSwapWeapon"}, + {57, "CTaskGeneralSweep"}, + {58, "CTaskPolice"}, + {59, "CTaskPoliceOrderResponse"}, + {60, "CTaskPursueCriminal"}, + {62, "CTaskArrestPed"}, + {63, "CTaskArrestPed2"}, + {64, "CTaskBusted"}, + {65, "CTaskFirePatrol"}, + {66, "CTaskHeliOrderResponse"}, + {67, "CTaskHeliPassengerRappel"}, + {68, "CTaskAmbulancePatrol"}, + {69, "CTaskPoliceWantedResponse"}, + {70, "CTaskSwat"}, + {72, "CTaskSwatWantedResponse"}, + {73, "CTaskSwatOrderResponse"}, + {74, "CTaskSwatGoToStagingArea"}, + {75, "CTaskSwatFollowInLine"}, + {76, "CTaskWitness"}, + {77, "CTaskGangPatrol"}, + {78, "CTaskArmy"}, + {80, "CTaskShockingEventWatch"}, + {82, "CTaskShockingEventGoto"}, + {83, "CTaskShockingEventHurryAway"}, + {84, "CTaskShockingEventReactToAircraft"}, + {85, "CTaskShockingEventReact"}, + {86, "CTaskShockingEventBackAway"}, + {87, "CTaskShockingPoliceInvestigate"}, + {88, "CTaskShockingEventStopAndStare"}, + {89, "CTaskShockingNiceCarPicture"}, + {90, "CTaskShockingEventThreatResponse"}, + {92, "CTaskTakeOffHelmet"}, + {93, "CTaskCarReactToVehicleCollision"}, + {95, "CTaskCarReactToVehicleCollisionGetOut"}, + {97, "CTaskDyingDead"}, + {100, "CTaskWanderingScenario"}, + {101, "CTaskWanderingInRadiusScenario"}, + {103, "CTaskMoveBetweenPointsScenario"}, + {104, "CTaskChatScenario"}, + {106, "CTaskCowerScenario"}, + {107, "CTaskDeadBodyScenario"}, + {114, "CTaskSayAudio"}, + {116, "CTaskWaitForSteppingOut"}, + {117, "CTaskCoupleScenario"}, + {118, "CTaskUseScenario"}, + {119, "CTaskUseVehicleScenario"}, + {120, "CTaskUnalerted"}, + {121, "CTaskStealVehicle"}, + {122, "CTaskReactToPursuit"}, + {125, "CTaskHitWall"}, + {126, "CTaskCower"}, + {127, "CTaskCrouch"}, + {128, "CTaskMelee"}, + {129, "CTaskMoveMeleeMovement"}, + {130, "CTaskMeleeActionResult"}, + {131, "CTaskMeleeUpperbodyAnims"}, + {133, "CTaskMoVEScripted"}, + {134, "CTaskScriptedAnimation"}, + {135, "CTaskSynchronizedScene"}, + {137, "CTaskComplexEvasiveStep"}, + {138, "CTaskWalkRoundCarWhileWandering"}, + {140, "CTaskComplexStuckInAir"}, + {141, "CTaskWalkRoundEntity"}, + {142, "CTaskMoveWalkRoundVehicle"}, + {144, "CTaskReactToGunAimedAt"}, + {146, "CTaskDuckAndCover"}, + {147, "CTaskAggressiveRubberneck"}, + {150, "CTaskInVehicleBasic"}, + {151, "CTaskCarDriveWander"}, + {152, "CTaskLeaveAnyCar"}, + {153, "CTaskComplexGetOffBoat"}, + {155, "CTaskCarSetTempAction"}, + {156, "CTaskBringVehicleToHalt"}, + {157, "CTaskCarDrive"}, + {159, "CTaskPlayerDrive"}, + {160, "CTaskEnterVehicle"}, + {161, "CTaskEnterVehicleAlign"}, + {162, "CTaskOpenVehicleDoorFromOutside"}, + {163, "CTaskEnterVehicleSeat"}, + {164, "CTaskCloseVehicleDoorFromInside"}, + {165, "CTaskInVehicleSeatShuffle"}, + {167, "CTaskExitVehicleSeat"}, + {168, "CTaskCloseVehicleDoorFromOutside"}, + {169, "CTaskControlVehicle"}, + {170, "CTaskMotionInAutomobile"}, + {171, "CTaskMotionOnBicycle"}, + {172, "CTaskMotionOnBicycleController"}, + {173, "CTaskMotionInVehicle"}, + {174, "CTaskMotionInTurret"}, + {175, "CTaskReactToBeingJacked"}, + {176, "CTaskReactToBeingAskedToLeaveVehicle"}, + {177, "CTaskTryToGrabVehicleDoor"}, + {178, "CTaskGetOnTrain"}, + {179, "CTaskGetOffTrain"}, + {180, "CTaskRideTrain"}, + {190, "CTaskMountThrowProjectile"}, + {195, "CTaskGoToCarDoorAndStandStill"}, + {196, "CTaskMoveGoToVehicleDoor"}, + {197, "CTaskSetPedInVehicle"}, + {198, "CTaskSetPedOutOfVehicle"}, + {199, "CTaskVehicleMountedWeapon"}, + {200, "CTaskVehicleGun"}, + {201, "CTaskVehicleProjectile"}, + {204, "CTaskSmashCarWindow"}, + {205, "CTaskMoveGoToPoint"}, + {206, "CTaskMoveAchieveHeading"}, + {207, "CTaskMoveFaceTarget"}, + {208, "CTaskComplexGoToPointAndStandStillTimed"}, + {208, "CTaskMoveGoToPointAndStandStill"}, + {209, "CTaskMoveFollowPointRoute"}, + {210, "CTaskMoveSeekEntity_CEntitySeekPosCalculatorStandard"}, + {211, "CTaskMoveSeekEntity_CEntitySeekPosCalculatorLastNavMeshIntersection"}, + {212, "CTaskMoveSeekEntity_CEntitySeekPosCalculatorLastNavMeshIntersection2"}, + {213, "CTaskMoveSeekEntity_CEntitySeekPosCalculatorXYOffsetFixed"}, + {214, "CTaskMoveSeekEntity_CEntitySeekPosCalculatorXYOffsetFixed2"}, + {215, "CTaskExhaustedFlee"}, + {216, "CTaskGrowlAndFlee"}, + {217, "CTaskScenarioFlee"}, + {218, "CTaskSmartFlee"}, + {219, "CTaskFlyAway"}, + {220, "CTaskWalkAway"}, + {221, "CTaskWander"}, + {222, "CTaskWanderInArea"}, + {223, "CTaskFollowLeaderInFormation"}, + {224, "CTaskGoToPointAnyMeans"}, + {225, "CTaskTurnToFaceEntityOrCoord"}, + {226, "CTaskFollowLeaderAnyMeans"}, + {228, "CTaskFlyToPoint"}, + {229, "CTaskFlyingWander"}, + {230, "CTaskGoToPointAiming"}, + {231, "CTaskGoToScenario"}, + {233, "CTaskSeekEntityAiming"}, + {234, "CTaskSlideToCoord"}, + {235, "CTaskSwimmingWander"}, + {237, "CTaskMoveTrackingEntity"}, + {238, "CTaskMoveFollowNavMesh"}, + {239, "CTaskMoveGoToPointOnRoute"}, + {240, "CTaskEscapeBlast"}, + {241, "CTaskMoveWander"}, + {242, "CTaskMoveBeInFormation"}, + {243, "CTaskMoveCrowdAroundLocation"}, + {244, "CTaskMoveCrossRoadAtTrafficLights"}, + {245, "CTaskMoveWaitForTraffic"}, + {246, "CTaskMoveGoToPointStandStillAchieveHeading"}, + {251, "CTaskMoveGetOntoMainNavMesh"}, + {252, "CTaskMoveSlideToCoord"}, + {253, "CTaskMoveGoToPointRelativeToEntityAndStandStill"}, + {254, "CTaskHelicopterStrafe"}, + {256, "CTaskGetOutOfWater"}, + {259, "CTaskMoveFollowEntityOffset"}, + {261, "CTaskFollowWaypointRecording"}, + {264, "CTaskMotionPed"}, + {265, "CTaskMotionPedLowLod"}, + {268, "CTaskHumanLocomotion"}, + {269, "CTaskMotionBasicLocomotionLowLod"}, + {270, "CTaskMotionStrafing"}, + {271, "CTaskMotionTennis"}, + {272, "CTaskMotionAiming"}, + {273, "CTaskBirdLocomotion"}, + {274, "CTaskFlightlessBirdLocomotion"}, + {278, "CTaskFishLocomotion"}, + {279, "CTaskQuadLocomotion"}, + {280, "CTaskMotionDiving"}, + {281, "CTaskMotionSwimming"}, + {282, "CTaskMotionParachuting"}, + {283, "CTaskMotionDrunk"}, + {284, "CTaskRepositionMove"}, + {285, "CTaskMotionAimingTransition"}, + {286, "CTaskThrowProjectile"}, + {287, "CTaskCover"}, + {288, "CTaskMotionInCover"}, + {289, "CTaskAimAndThrowProjectile"}, + {290, "CTaskGun"}, + {291, "CTaskAimFromGround"}, + {295, "CTaskAimGunVehicleDriveBy"}, + {296, "CTaskAimGunScripted"}, + {298, "CTaskReloadGun"}, + {299, "CTaskWeaponBlocked"}, + {300, "CTaskEnterCover"}, + {301, "CTaskExitCover"}, + {302, "CTaskAimGunFromCoverIntro"}, + {303, "CTaskAimGunFromCoverOutro"}, + {304, "CTaskAimGunBlindFire"}, + {307, "CTaskCombatClosestTargetInArea"}, + {308, "CTaskCombatAdditionalTask"}, + {309, "CTaskInCover"}, + {313, "CTaskAimSweep"}, + {318, "CTaskSharkCircle"}, + {319, "CTaskSharkAttack"}, + {320, "CTaskAgitated"}, + {321, "CTaskAgitatedAction"}, + {322, "CTaskConfront"}, + {323, "CTaskIntimidate"}, + {324, "CTaskShove"}, + {325, "CTaskShoved"}, + {327, "CTaskCrouchToggle"}, + {328, "CTaskRevive"}, + {334, "CTaskParachute"}, + {335, "CTaskParachuteObject"}, + {336, "CTaskTakeOffPedVariation"}, + {339, "CTaskCombatSeekCover"}, + {341, "CTaskCombatFlank"}, + {342, "CTaskCombat"}, + {343, "CTaskCombatMounted"}, + {344, "CTaskMoveCircle"}, + {345, "CTaskMoveCombatMounted"}, + {346, "CTaskSearch"}, + {347, "CTaskSearchOnFoot"}, + {348, "CTaskSearchInAutomobile"}, + {349, "CTaskSearchInBoat"}, + {350, "CTaskSearchInHeli"}, + {351, "CTaskThreatResponse"}, + {352, "CTaskInvestigate"}, + {353, "CTaskStandGuardFSM"}, + {354, "CTaskPatrol"}, + {355, "CTaskShootAtTarget"}, + {356, "CTaskSetAndGuardArea"}, + {357, "CTaskStandGuard"}, + {358, "CTaskSeparate"}, + {359, "CTaskStayInCover"}, + {360, "CTaskVehicleCombat"}, + {361, "CTaskVehiclePersuit"}, + {362, "CTaskVehicleChase"}, + {363, "CTaskDraggingToSafety"}, + {364, "CTaskDraggedToSafety"}, + {365, "CTaskVariedAimPose"}, + {366, "CTaskMoveWithinAttackWindow"}, + {367, "CTaskMoveWithinDefensiveArea"}, + {368, "CTaskShootOutTire"}, + {369, "CTaskShellShocked"}, + {370, "CTaskBoatChase"}, + {371, "CTaskBoatCombat"}, + {372, "CTaskBoatStrafe"}, + {373, "CTaskHeliChase"}, + {374, "CTaskHeliCombat"}, + {375, "CTaskSubmarineCombat"}, + {376, "CTaskSubmarineChase"}, + {377, "CTaskPlaneChase"}, + {378, "CTaskTargetUnreachable"}, + {379, "CTaskTargetUnreachableInInterior"}, + {380, "CTaskTargetUnreachableInExterior"}, + {381, "CTaskStealthKill"}, + {382, "CTaskWrithe"}, + {383, "CTaskAdvance"}, + {384, "CTaskCharge"}, + {385, "CTaskMoveToTacticalPoint"}, + {386, "CTaskToHurtTransit"}, + {387, "CTaskAnimatedHitByExplosion"}, + {388, "CTaskNMRelax"}, + {390, "CTaskNMPose"}, + {391, "CTaskNMBrace"}, + {392, "CTaskNMBuoyancy"}, + {393, "CTaskNMInjuredOnGround"}, + {394, "CTaskNMShot"}, + {395, "CTaskNMHighFall"}, + {396, "CTaskNMBalance"}, + {397, "CTaskNMElectrocute"}, + {398, "CTaskNMPrototype"}, + {399, "CTaskNMExplosion"}, + {400, "CTaskNMOnFire"}, + {401, "CTaskNMScriptControl"}, + {402, "CTaskNMJumpRollFromRoadVehicle"}, + {403, "CTaskNMFlinch"}, + {404, "CTaskNMSit"}, + {405, "CTaskNMFallDown"}, + {406, "CTaskBlendFromNM"}, + {407, "CTaskNMControl"}, + {408, "CTaskNMDangle"}, + {411, "CTaskNMGenericAttach"}, + {412, "CTaskNMDrunk"}, + {413, "CTaskNMDraggingToSafety"}, + {414, "CTaskNMThroughWindscreen"}, + {415, "CTaskNMRiverRapids"}, + {416, "CTaskNMSimple"}, + {417, "CTaskRageRagdoll"}, + {420, "CTaskJumpVault"}, + {421, "CTaskJump"}, + {422, "CTaskFall"}, + {424, "CTaskReactAimWeapon"}, + {425, "CTaskChat"}, + {426, "CTaskMobilePhone"}, + {427, "CTaskReactToDeadPed"}, + {429, "CTaskSearchForUnknownThreat"}, + {431, "CTaskBomb"}, + {432, "CTaskDetonator"}, + {434, "CTaskAnimatedAttach"}, + {440, "CTaskCutScene"}, + {441, "CTaskReactToExplosion"}, + {442, "CTaskReactToImminentExplosion"}, + {443, "CTaskDiveToGround"}, + {444, "CTaskReactAndFlee"}, + {445, "CTaskSidestep"}, + {446, "CTaskCallPolice"}, + {447, "CTaskReactInDirection"}, + {448, "CTaskReactToBuddyShot"}, + {453, "CTaskVehicleGoToAutomobileNew"}, + {454, "CTaskVehicleGoToPlane"}, + {455, "CTaskVehicleGoToHelicopter"}, + {456, "CTaskVehicleGoToSubmarine"}, + {457, "CTaskVehicleGoToBoat"}, + {458, "CTaskVehicleGoToPointAutomobile"}, + {459, "CTaskVehicleGoToPointWithAvoidanceAutomobile"}, + {460, "CTaskVehiclePursue"}, + {461, "CTaskVehicleRam"}, + {462, "CTaskVehicleSpinOut"}, + {463, "CTaskVehicleApproach"}, + {464, "CTaskVehicleThreePointTurn"}, + {465, "CTaskVehicleDeadDriver"}, + {466, "CTaskVehicleCruiseNew"}, + {467, "CTaskVehicleCruiseBoat"}, + {468, "CTaskVehicleStop"}, + {469, "CTaskVehiclePullOver"}, + {470, "CTaskVehiclePassengerExit"}, + {471, "CTaskVehicleFlee"}, + {472, "CTaskVehicleFleeAirborne"}, + {473, "CTaskVehicleFleeBoat"}, + {474, "CTaskVehicleFollowRecording"}, + {475, "CTaskVehicleFollow"}, + {476, "CTaskVehicleBlock"}, + {477, "CTaskVehicleBlockCruiseInFront"}, + {478, "CTaskVehicleBlockBrakeInFront"}, + {479, "CTaskVehicleBlockBackAndForth"}, + {480, "CTaskVehicleCrash"}, + {481, "CTaskVehicleLand"}, + {482, "CTaskVehicleLandPlane"}, + {483, "CTaskVehicleHover"}, + {484, "CTaskVehicleAttack"}, + {485, "CTaskVehicleAttackTank"}, + {486, "CTaskVehicleCircle"}, + {487, "CTaskVehiclePoliceBehaviour"}, + {488, "CTaskVehiclePoliceBehaviourHelicopter"}, + {489, "CTaskVehiclePoliceBehaviourBoat"}, + {490, "CTaskVehicleEscort"}, + {491, "CTaskVehicleHeliProtect"}, + {493, "CTaskVehiclePlayerDriveAutomobile"}, + {494, "CTaskVehiclePlayerDriveBike"}, + {495, "CTaskVehiclePlayerDriveBoat"}, + {496, "CTaskVehiclePlayerDriveSubmarine"}, + {497, "CTaskVehiclePlayerDriveSubmarineCar"}, + {498, "CTaskVehiclePlayerDrivePlane"}, + {499, "CTaskVehiclePlayerDriveHeli"}, + {500, "CTaskVehiclePlayerDriveAutogyro"}, + {501, "CTaskVehiclePlayerDriveDiggerArm"}, + {502, "CTaskVehiclePlayerDriveTrain"}, + {503, "CTaskVehiclePlaneChase"}, + {504, "CTaskVehicleNoDriver"}, + {505, "CTaskVehicleAnimation"}, + {506, "CTaskVehicleConvertibleRoof"}, + {507, "CTaskVehicleParkNew"}, + {508, "CTaskVehicleFollowWaypointRecording"}, + {509, "CTaskVehicleGoToNavmesh"}, + {510, "CTaskVehicleReactToCopSiren"}, + {511, "CTaskVehicleGotoLongRange"}, + {512, "CTaskVehicleWait"}, + {513, "CTaskVehicleReverse"}, + {514, "CTaskVehicleBrake"}, + {515, "CTaskVehicleHandBrake"}, + {516, "CTaskVehicleTurn"}, + {517, "CTaskVehicleGoForward"}, + {518, "CTaskVehicleSwerve"}, + {519, "CTaskVehicleFlyDirection"}, + {520, "CTaskVehicleHeadonCollision"}, + {521, "CTaskVehicleBoostUseSteeringAngle"}, + {522, "CTaskVehicleShotTire"}, + {523, "CTaskVehicleBurnout"}, + {524, "CTaskVehicleRevEngine"}, + {525, "CTaskVehicleSurfaceInSubmarine"}, + {526, "CTaskVehiclePullAlongside"}, + {527, "CTaskVehicleTransformToSubmarine"}, + {528, "CTaskAnimatedFallback"}, + }; + + bool change_player_model(const Hash hash); + bool steal_outfit(const Ped target); + void clone_ped(const Ped src, const Ped target); + void steal_identity(const Ped target); + void kill_ped(const Ped ped); + Ped spawn(ePedType pedType, Hash hash, Ped clone, Vector3 location, float heading, bool is_networked = true); + void set_ped_random_component_variation(Ped ped); + player_ptr get_player_from_ped(Ped ped); + bool load_animation_dict(const char* dict); + void ped_play_animation(Ped ped, const std::string_view& animDict, const std::string_view& animName, float speed = 4.f, float speedMultiplier = -4.f, int duration = -1, int flag = 0, float playbackRate = 0, bool lockPos = false, Vector3 pos = {}, Vector3 rot = {}, int ik_flags = 0); + void ped_enter_vehicle_animated(Ped ped, Vehicle veh, eVehicleSeats seat, int movespeed); + bool is_ped_a_friend(Ped ped, CPed* ped_ptr); +} diff --git a/src/views/self/view_weapons.cpp b/src/views/self/view_weapons.cpp index 98e185ec..e8e66e78 100644 --- a/src/views/self/view_weapons.cpp +++ b/src/views/self/view_weapons.cpp @@ -194,6 +194,8 @@ namespace big ImGui::Checkbox("TRUST_FRIENDS"_T.data(), &g.weapons.aimbot.exclude_friends); ImGui::SameLine(); components::command_checkbox<"aimonlyatenemy">(); + ImGui::SameLine(); + components::command_checkbox<"aimonlyatthreats">(); ImGui::CheckboxFlags("PLAYERS"_T.data(), &g.weapons.aimbot.only_on_ped_type, (int64_t)ePedTypeFlag::PED_TYPE_NETWORK_PLAYER); ImGui::SameLine(); From 555331ff1d3084b91d19469d4edb469418e5ce32 Mon Sep 17 00:00:00 2001 From: gir489 <100792176+gir489returns@users.noreply.github.com> Date: Sat, 10 Aug 2024 19:12:29 -0400 Subject: [PATCH 2/7] Prevent vehicle looped functions from running on vehicles we are not currently driving. (#3548) --- .../looped/vehicle/keep_vehicle_clean.cpp | 41 ++--- .../looped/vehicle/keep_vehicle_repaired.cpp | 151 +++++++++--------- 2 files changed, 100 insertions(+), 92 deletions(-) diff --git a/src/backend/looped/vehicle/keep_vehicle_clean.cpp b/src/backend/looped/vehicle/keep_vehicle_clean.cpp index 693a9121..283cdc7a 100644 --- a/src/backend/looped/vehicle/keep_vehicle_clean.cpp +++ b/src/backend/looped/vehicle/keep_vehicle_clean.cpp @@ -1,21 +1,22 @@ -#include "backend/looped_command.hpp" -#include "natives.hpp" - -namespace big -{ - class keep_vehicle_clean : looped_command - { - using looped_command::looped_command; - - virtual void on_tick() override - { - if (ENTITY::DOES_ENTITY_EXIST(self::veh)) - { - VEHICLE::SET_VEHICLE_DIRT_LEVEL(self::veh, 0.0f); - } - } - }; - - keep_vehicle_clean - g_keep_vehicle_clean("keepvehicleclean", "KEEP_VEHICLE_CLEAN_CMD", "KEEP_VEHICLE_CLEAN_CMD_DESC", g.vehicle.keep_vehicle_clean); +#include "backend/looped_command.hpp" +#include "natives.hpp" +#include "gta/vehicle_values.hpp" + +namespace big +{ + class keep_vehicle_clean : looped_command + { + using looped_command::looped_command; + + virtual void on_tick() override + { + if (self::veh != 0 && VEHICLE::GET_PED_IN_VEHICLE_SEAT(self::veh, SEAT_DRIVER, FALSE) == self::ped) + { + VEHICLE::SET_VEHICLE_DIRT_LEVEL(self::veh, 0.0f); + } + } + }; + + keep_vehicle_clean + g_keep_vehicle_clean("keepvehicleclean", "KEEP_VEHICLE_CLEAN_CMD", "KEEP_VEHICLE_CLEAN_CMD_DESC", g.vehicle.keep_vehicle_clean); } \ No newline at end of file diff --git a/src/backend/looped/vehicle/keep_vehicle_repaired.cpp b/src/backend/looped/vehicle/keep_vehicle_repaired.cpp index 26cf0ad0..90670ccf 100644 --- a/src/backend/looped/vehicle/keep_vehicle_repaired.cpp +++ b/src/backend/looped/vehicle/keep_vehicle_repaired.cpp @@ -1,72 +1,79 @@ -#include "backend/looped_command.hpp" -#include "natives.hpp" -#include "util/vehicle.hpp" - -namespace big -{ - class keep_vehicle_repaired : looped_command - { - using looped_command::looped_command; - - virtual void on_tick() override - { - const auto veh = self::veh; - if (!ENTITY::IS_ENTITY_A_VEHICLE(veh) || !entity::take_control_of(veh, 0)) - { - return; - } - - if (VEHICLE::GET_DOES_VEHICLE_HAVE_DAMAGE_DECALS(veh)) - { - if (!g.vehicle.keep_vehicle_clean) - { - VEHICLE::SET_VEHICLE_DIRT_LEVEL(veh, 0.f); - } - - // Rear window - constexpr int rear_window_index = 7; - if (!VEHICLE::IS_VEHICLE_WINDOW_INTACT(veh, rear_window_index)) - { - VEHICLE::FIX_VEHICLE_WINDOW(veh, rear_window_index); - } - - g_pointers->m_gta.m_decal_manager_remove(g_pointers->m_gta.m_decal_manager, g_pointers->m_gta.m_handle_to_ptr(veh), -1, 0, 0x00'01'E0'00); - - if (!g.vehicle.god_mode) - { - VEHICLE::SET_VEHICLE_DEFORMATION_FIXED(veh); - } - - vehicle::repair_engine_from_water(veh); - - const auto door_count = VEHICLE::GET_NUMBER_OF_VEHICLE_DOORS(veh); - for (int i = 0; i < door_count; i++) - { - if (VEHICLE::IS_VEHICLE_DOOR_DAMAGED(veh, i)) - { - VEHICLE::SET_VEHICLE_FIXED(veh); - return; - } - } - - for (int i = 0; i <= 14; i++) - { - if (VEHICLE::DOES_EXTRA_EXIST(veh, i) && VEHICLE::IS_VEHICLE_EXTRA_TURNED_ON(veh, i) && VEHICLE::IS_EXTRA_BROKEN_OFF(veh, i)) - { - VEHICLE::SET_VEHICLE_FIXED(veh); - return; - } - } - - if (VEHICLE::IS_VEHICLE_BUMPER_BOUNCING(veh, TRUE) || VEHICLE::IS_VEHICLE_BUMPER_BOUNCING(veh, FALSE) || VEHICLE::GET_VEHICLE_NUM_OF_BROKEN_LOOSEN_PARTS(veh) > 0) - { - VEHICLE::SET_VEHICLE_FIXED(veh); - return; - } - } - } - }; - - keep_vehicle_repaired - g_keep_vehicle_repaired("keepfixed", "KEEP_VEHICLE_FIXED", "KEEP_VEHICLE_FIXED_DESC", g.vehicle.keep_vehicle_repaired); -} +#include "backend/looped_command.hpp" +#include "natives.hpp" +#include "util/vehicle.hpp" +#include "gta/vehicle_values.hpp" + +namespace big +{ + class keep_vehicle_repaired : looped_command + { + using looped_command::looped_command; + + virtual void on_tick() override + { + Vehicle veh = self::veh; + + if (veh == 0 || VEHICLE::GET_PED_IN_VEHICLE_SEAT(self::veh, SEAT_DRIVER, FALSE) != self::ped) + { + return; + } + + if (!entity::take_control_of(veh, 0)) + { + return; + } + + if (VEHICLE::GET_DOES_VEHICLE_HAVE_DAMAGE_DECALS(veh)) + { + if (!g.vehicle.keep_vehicle_clean) + { + VEHICLE::SET_VEHICLE_DIRT_LEVEL(veh, 0.f); + } + + // Rear window + constexpr int rear_window_index = 7; + if (!VEHICLE::IS_VEHICLE_WINDOW_INTACT(veh, rear_window_index)) + { + VEHICLE::FIX_VEHICLE_WINDOW(veh, rear_window_index); + } + + g_pointers->m_gta.m_decal_manager_remove(g_pointers->m_gta.m_decal_manager, g_pointers->m_gta.m_handle_to_ptr(veh), -1, 0, 0x0001E000); + + if (!g.vehicle.god_mode) + { + VEHICLE::SET_VEHICLE_DEFORMATION_FIXED(veh); + } + + vehicle::repair_engine_from_water(veh); + + const auto door_count = VEHICLE::GET_NUMBER_OF_VEHICLE_DOORS(veh); + for (int i = 0; i < door_count; i++) + { + if (VEHICLE::IS_VEHICLE_DOOR_DAMAGED(veh, i)) + { + VEHICLE::SET_VEHICLE_FIXED(veh); + return; + } + } + + for (int i = 0; i <= 14; i++) + { + if (VEHICLE::DOES_EXTRA_EXIST(veh, i) && VEHICLE::IS_VEHICLE_EXTRA_TURNED_ON(veh, i) && VEHICLE::IS_EXTRA_BROKEN_OFF(veh, i)) + { + VEHICLE::SET_VEHICLE_FIXED(veh); + return; + } + } + + if (VEHICLE::IS_VEHICLE_BUMPER_BOUNCING(veh, TRUE) || VEHICLE::IS_VEHICLE_BUMPER_BOUNCING(veh, FALSE) || VEHICLE::GET_VEHICLE_NUM_OF_BROKEN_LOOSEN_PARTS(veh) > 0) + { + VEHICLE::SET_VEHICLE_FIXED(veh); + return; + } + } + } + }; + + keep_vehicle_repaired + g_keep_vehicle_repaired("keepfixed", "KEEP_VEHICLE_FIXED", "KEEP_VEHICLE_FIXED_DESC", g.vehicle.keep_vehicle_repaired); +} From 8c11a1ebb07b18e56cddcf51ada1a2d570c66051 Mon Sep 17 00:00:00 2001 From: gir489 <100792176+gir489returns@users.noreply.github.com> Date: Sat, 10 Aug 2024 19:14:15 -0400 Subject: [PATCH 3/7] Fixed Weapons JSON not properly using the most recent meta file. (#3550) * Added ability to resolve WCT_INVALID attachments at runtime from the achievement_controller script, such as the game does. * Improved component information extraction to also retrieve the descriptions from the scripts. Redesigned Ammunation to now only display proper components. Added a tooltip of the component description to Ammunation. * Refactored script_function::call to fail gracefully if called out of lockstep when the scripts are running. --- src/script_function.hpp | 14 ++++- src/services/gta_data/gta_data_service.cpp | 71 ++++++++++++++++++---- src/views/self/view_weapons.cpp | 5 +- 3 files changed, 74 insertions(+), 16 deletions(-) diff --git a/src/script_function.hpp b/src/script_function.hpp index 35226c22..059d172a 100644 --- a/src/script_function.hpp +++ b/src/script_function.hpp @@ -30,10 +30,18 @@ namespace big { auto thread = gta_util::find_script_thread(m_script); auto program = gta_util::find_script_program(m_script); - auto ip = get_ip(program); - if (!thread || !program || !ip) + if (!thread || !program) + { + LOG(FATAL) << m_name << " failed to find its associated script running."; return Ret(); + } + + auto ip = get_ip(program); + if (!ip) + { + return Ret(); + } auto tls_ctx = rage::tlsContext::get(); auto stack = (uint64_t*)thread->m_stack; @@ -70,5 +78,7 @@ namespace big inline script_function reset_session_data("RSD", "main_persistent"_J, "2D 02 7D 00 00"); inline script_function add_clan_logo_to_vehicle("ACLTV", "main_persistent"_J, "2D 02 04 00 00 5D ? ? ? 61"); inline script_function vehicle_cannot_accept_clan_logo("CVACL", "main_persistent"_J, "2D 01 03 00 00 2C 01 00 A1 06 ? 04"); + inline script_function get_component_name_string("GCNS", "mp_weapons"_J, "2D 02 43 00 00 38 01"); + inline script_function get_component_desc_string("GCDS", "mp_weapons"_J, "2D 02 43 00 00 38 00"); } } \ No newline at end of file diff --git a/src/services/gta_data/gta_data_service.cpp b/src/services/gta_data/gta_data_service.cpp index 53cf1dbb..6d31c432 100644 --- a/src/services/gta_data/gta_data_service.cpp +++ b/src/services/gta_data/gta_data_service.cpp @@ -256,9 +256,12 @@ namespace big hash_array mapped_weapons; hash_array mapped_components; + int mp_weapons_thread_id = 0; + std::vector peds; std::vector vehicles; - std::vector weapons; + //std::vector weapons; + std::unordered_map weapons; std::vector weapon_components; constexpr auto exists = [](const hash_array& arr, uint32_t val) -> bool { @@ -307,7 +310,7 @@ namespace big } else if (const auto file_str = path.string(); file_str.find("weaponcomponents") != std::string::npos && path.extension() == ".meta") { - rpf_wrapper.read_xml_file(path, [&exists, &weapon_components, &mapped_components](pugi::xml_document& doc) { + rpf_wrapper.read_xml_file(path, [&exists, &weapon_components, &mapped_components, &mp_weapons_thread_id](pugi::xml_document& doc) { const auto& items = doc.select_nodes("/CWeaponComponentInfoBlob/Infos/*[self::Item[@type='CWeaponComponentInfo'] or self::Item[@type='CWeaponComponentFlashLightInfo'] or self::Item[@type='CWeaponComponentScopeInfo'] or self::Item[@type='CWeaponComponentSuppressorInfo'] or self::Item[@type='CWeaponComponentVariantModelInfo'] or self::Item[@type='CWeaponComponentClipInfo']]"); for (const auto& item_node : items) { @@ -315,7 +318,7 @@ namespace big const std::string name = item.child("Name").text().as_string(); const auto hash = rage::joaat(name); - if (!name.starts_with("COMPONENT")) + if (!name.starts_with("COMPONENT") || name.ends_with("MK2_UPGRADE")) { continue; } @@ -329,9 +332,49 @@ namespace big std::string LocName = item.child("LocName").text().as_string(); std::string LocDesc = item.child("LocDesc").text().as_string(); - if (LocName.ends_with("INVALID") || LocName.ends_with("RAIL")) - { + if (LocName.ends_with("RAIL")) continue; + + if (LocName.ends_with("INVALID")) + { + constexpr Hash script_hash = "MP_Weapons"_J; + if (!SCRIPT::GET_NUMBER_OF_THREADS_RUNNING_THE_SCRIPT_WITH_THIS_HASH(script_hash)) + { + while (!SCRIPT::HAS_SCRIPT_WITH_NAME_HASH_LOADED(script_hash)) + { + SCRIPT::REQUEST_SCRIPT_WITH_NAME_HASH(script_hash); + script::get_current()->yield(10ms); + } + mp_weapons_thread_id = SYSTEM::START_NEW_SCRIPT_WITH_NAME_HASH(script_hash, 1424); + auto thread = gta_util::find_script_thread_by_id(mp_weapons_thread_id); + if (thread) + thread->m_context.m_state = rage::eThreadState::unk_3; + else + LOG(FATAL) << "Failed to find MP_Weapons script!"; + SCRIPT::SET_SCRIPT_WITH_NAME_HASH_AS_NO_LONGER_NEEDED(script_hash); + } + + Hash weapon_hash = 0; + if (name.starts_with("COMPONENT_KNIFE")) + weapon_hash = "WEAPON_KNIFE"_J; + else if (name.starts_with("COMPONENT_KNUCKLE")) + weapon_hash = "WEAPON_KNUCKLE"_J; + else if (name.starts_with("COMPONENT_BAT")) + weapon_hash = "WEAPON_BAT"_J; + const auto display_string = scr_functions::get_component_name_string.call(hash, weapon_hash); + if (display_string == nullptr) + continue; + LocName = display_string; + } + + if (LocName.ends_with("INVALID")) + continue; + + if (LocDesc.ends_with("INVALID")) + { + const auto display_string = scr_functions::get_component_desc_string.call(hash, 0); + if (display_string != nullptr) + LocDesc = display_string; } weapon_component component; @@ -358,9 +401,8 @@ namespace big if (hash == "WEAPON_BIRD_CRAP"_J) continue; - if (exists(mapped_weapons, hash)) - continue; - mapped_weapons.emplace_back(hash); + if (!exists(mapped_weapons, hash)) + mapped_weapons.emplace_back(hash); const auto human_name_hash = item.child("HumanNameHash").text().as_string(); if (std::strcmp(human_name_hash, "WT_INVALID") == 0 || std::strcmp(human_name_hash, "WT_VEHMINE") == 0) @@ -435,7 +477,7 @@ namespace big weapon.m_hash = hash; - weapons.emplace_back(std::move(weapon)); + weapons[hash] = weapon; skip: continue; } @@ -475,6 +517,11 @@ namespace big yim_fipackfile::for_each_fipackfile(); } + if (mp_weapons_thread_id != 0) + { + SCRIPT::TERMINATE_THREAD(mp_weapons_thread_id); + } + static bool translate_label = false; g_fiber_pool->queue_job([&] { @@ -488,7 +535,7 @@ namespace big } for (auto& item : weapons) { - item.m_display_name = HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(item.m_display_name.c_str()); + item.second.m_display_name = HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(item.second.m_display_name.c_str()); } for (auto& item : weapon_components) { @@ -555,8 +602,8 @@ namespace big m_weapons_cache.weapon_map.clear(); for (auto weapon : weapons) { - add_if_not_exists(m_weapon_types, weapon.m_weapon_type); - m_weapons_cache.weapon_map.insert({weapon.m_name, weapon}); + add_if_not_exists(m_weapon_types, weapon.second.m_weapon_type); + m_weapons_cache.weapon_map.insert({weapon.second.m_name, weapon.second}); } m_weapons_cache.weapon_components.clear(); diff --git a/src/views/self/view_weapons.cpp b/src/views/self/view_weapons.cpp index e8e66e78..b95f2103 100644 --- a/src/views/self/view_weapons.cpp +++ b/src/views/self/view_weapons.cpp @@ -290,8 +290,7 @@ namespace big Hash attachment_hash = attachment_component.m_hash; if (attachment_hash == NULL) { - attachment_name = attachment; - attachment_hash = rage::joaat(attachment); + continue; } bool is_selected = attachment_hash == selected_weapon_attachment_hash; std::string display_name = attachment_name.append("##").append(std::to_string(attachment_hash)); @@ -300,6 +299,8 @@ namespace big selected_weapon_attachment = attachment_name; selected_weapon_attachment_hash = attachment_hash; } + if (ImGui::IsItemHovered()) + ImGui::SetTooltip(attachment_component.m_display_desc.c_str()); if (is_selected) { ImGui::SetItemDefaultFocus(); From d6159d7686a78fcea12c71361ab0efe5409426c6 Mon Sep 17 00:00:00 2001 From: gir489 <100792176+gir489returns@users.noreply.github.com> Date: Mon, 12 Aug 2024 03:13:33 -0400 Subject: [PATCH 4/7] fix(Settings): aimonlyatthreats using only_on_enemy. (#3557) --- src/backend/looped/weapons/aimbot.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/looped/weapons/aimbot.cpp b/src/backend/looped/weapons/aimbot.cpp index 7b4a8024..07e129ee 100644 --- a/src/backend/looped/weapons/aimbot.cpp +++ b/src/backend/looped/weapons/aimbot.cpp @@ -17,7 +17,7 @@ namespace big g.weapons.aimbot.only_on_enemy); bool_command g_aimbot_only_on_threat("aimonlyatthreats", "BACKEND_LOOPED_WEAPONS_AIM_ONLY_AT_THREATS", "BACKEND_LOOPED_WEAPONS_AIM_ONLY_AT_THREATS_DESC", - g.weapons.aimbot.only_on_enemy); + g.weapons.aimbot.only_on_threats); class aimbot : looped_command { From 9f514924b6adb1d4413fe7911492e17c3992e075 Mon Sep 17 00:00:00 2001 From: kikkin_yo_azzez <69381115+USBMenus@users.noreply.github.com> Date: Mon, 12 Aug 2024 02:34:22 -0500 Subject: [PATCH 5/7] feat(Lua): expose imgui separatortext to lua (#3554) --- docs/lua/tables/ImGui.md | 4 ++++ src/lua/bindings/imgui.hpp | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/docs/lua/tables/ImGui.md b/docs/lua/tables/ImGui.md index 82a1c58b..85515a3e 100644 --- a/docs/lua/tables/ImGui.md +++ b/docs/lua/tables/ImGui.md @@ -331,6 +331,10 @@ You can find all the supported functions and overloads below. -- ImGui.Separator() ImGui.Separator + -- ImGui.SeparatorText(...) + -- Parameters: text (text) + ImGui.SeparatorText("some text") + -- ImGui.SameLine(...) -- Parameters: float (offset_from_start_x) [O], float (spacing) [O] -- Overloads diff --git a/src/lua/bindings/imgui.hpp b/src/lua/bindings/imgui.hpp index 92cb52b2..6e35bb76 100644 --- a/src/lua/bindings/imgui.hpp +++ b/src/lua/bindings/imgui.hpp @@ -1,4 +1,5 @@ #pragma once +#include "imgui.h" namespace lua::imgui { @@ -417,6 +418,10 @@ namespace lua::imgui { ImGui::Separator(); } + inline void SeparatorText(const char* label) + { + ImGui::SeparatorText(label); + } inline void SameLine() { ImGui::SameLine(); @@ -3338,6 +3343,7 @@ namespace lua::imgui #pragma region Cursor / Layout ImGui.set_function("Separator", Separator); + ImGui.set_function("SeparatorText", SeparatorText); ImGui.set_function("SameLine", sol::overload(sol::resolve(SameLine), sol::resolve(SameLine))); ImGui.set_function("NewLine", NewLine); ImGui.set_function("Spacing", Spacing); From a1fb2ae6d8e32d754f58981db2501605c68ee82a Mon Sep 17 00:00:00 2001 From: tupoy-ya <72797377+tupoy-ya@users.noreply.github.com> Date: Wed, 14 Aug 2024 06:40:09 +0000 Subject: [PATCH 6/7] feat(Lua)!: New Lua bindings (#3563) * feat(Lua): Make independent imgui independent. feat(Lua): Add a `pointer:set_address` binding. feat(Lua): Added `menu_event.Wndproc` event. fix(Lua): Fix `ImGui.SliderFloat3` binding. fix(Lua Docs): Partially fixed auto generated documentation. * fix(gui.cpp): include `lua_manager.hpp`. * fix(lua_manager.hpp): Added `draw_less_dependent_gui` function. * chore(Lua): Rename `add_independent_imgui` to `add_always_draw_imgui`. * docs(menu_event): Added docs for Wndporc event. * docs: Fixed a few more errors. * add reasoning and use native underlying format Co-authored-by: tupoy-ya Co-authored-by: xiaoxiao921 <837334+xiaoxiao921@users.noreply.github.com> --- docs/lua/classes/pointer.md | 62 ++++++++++++++---------- docs/lua/classes/tab.md | 10 +++- docs/lua/classes/vec3.md | 2 +- docs/lua/tables/gui.md | 60 ++++++++++++++++++++++- docs/lua/tables/menu_event.md | 15 +++++- docs/lua/tables/network.md | 52 ++++++++++---------- docs/lua/tables/scr_function.md | 35 +++++++++----- docs/lua/tables/script.md | 74 ++++++++++++++++++---------- src/core/data/menu_event.hpp | 1 + src/gui.cpp | 11 +++++ src/lua/bindings/event.cpp | 17 ++++++- src/lua/bindings/gui.cpp | 85 +++++++++++++++++++++++++++++---- src/lua/bindings/gui.hpp | 2 + src/lua/bindings/imgui.hpp | 6 +-- src/lua/bindings/memory.cpp | 6 +++ src/lua/bindings/memory.hpp | 19 ++++++++ src/lua/bindings/network.cpp | 11 ++++- src/lua/bindings/script.cpp | 4 +- src/lua/bindings/vector.hpp | 2 +- src/lua/lua_manager.cpp | 17 +++++++ src/lua/lua_manager.hpp | 1 + src/lua/lua_module.hpp | 1 + 22 files changed, 380 insertions(+), 113 deletions(-) diff --git a/docs/lua/classes/pointer.md b/docs/lua/classes/pointer.md index 86ebe206..b30a2da1 100644 --- a/docs/lua/classes/pointer.md +++ b/docs/lua/classes/pointer.md @@ -16,7 +16,7 @@ Returns a memory instance, with the given address. myInstance = pointer:new(address) ``` -## Functions (23) +## Functions (26) ### `add(offset)` @@ -63,18 +63,6 @@ Rips the current memory address and returns a new pointer object. pointer = pointer:rip(offset) ``` -### `get_int()` - -Retrieves the value stored at the memory address as the specified type. - -- **Returns:** - - `number`: the value stored at the memory address as the specified type. - -**Example Usage:** -```lua -number = pointer:get_int() -``` - ### `get_byte()` Retrieves the value stored at the memory address as the specified type. @@ -99,6 +87,18 @@ Retrieves the value stored at the memory address as the specified type. number = pointer:get_word() ``` +### `get_int()` + +Retrieves the value stored at the memory address as the specified type. + +- **Returns:** + - `number`: the value stored at the memory address as the specified type. + +**Example Usage:** +```lua +number = pointer:get_int() +``` + ### `get_dword()` Retrieves the value stored at the memory address as the specified type. @@ -135,18 +135,6 @@ Retrieves the value stored at the memory address as the specified type. number = pointer:get_qword() ``` -### `set_int(value)` - -Sets the value at the memory address to the specified value of the given type. - -- **Parameters:** - - `value` (number): new value. - -**Example Usage:** -```lua -pointer:set_int(value) -``` - ### `set_byte(value)` Sets the value at the memory address to the specified value of the given type. @@ -171,6 +159,18 @@ Sets the value at the memory address to the specified value of the given type. pointer:set_word(value) ``` +### `set_int(value)` + +Sets the value at the memory address to the specified value of the given type. + +- **Parameters:** + - `value` (number): new value. + +**Example Usage:** +```lua +pointer:set_int(value) +``` + ### `set_dword(value)` Sets the value at the memory address to the specified value of the given type. @@ -343,4 +343,16 @@ Retrieves the memory address stored in the pointer object. number = pointer:get_address() ``` +### `set_address(address)` + +Sets the memory address stored in the pointer object. + +- **Parameters:** + - `address` (integer): new address. + +**Example Usage:** +```lua +pointer:set_address(address) +``` + diff --git a/docs/lua/classes/tab.md b/docs/lua/classes/tab.md index d0c1087f..a25cc084 100644 --- a/docs/lua/classes/tab.md +++ b/docs/lua/classes/tab.md @@ -23,13 +23,19 @@ Clear the tab of all its custom lua content that you own. tab:clear() ``` -### `add_tab()` +### `add_tab(tab_name)` Add a sub tab to this tab. +- **Parameters:** + - `tab_name` (string): Name of the tab to add. + +- **Returns:** + - `tab`: A tab instance which corresponds to the new tab in the GUI. + **Example Usage:** ```lua -tab:add_tab() +tab = tab:add_tab(tab_name) ``` ### `add_button(name, callback)` diff --git a/docs/lua/classes/vec3.md b/docs/lua/classes/vec3.md index 2aedf525..aad1820a 100644 --- a/docs/lua/classes/vec3.md +++ b/docs/lua/classes/vec3.md @@ -26,7 +26,7 @@ z component of the vector. ### `new(x, y, z)` -Returns a vector that contains the x, y, and z values. +Returns: vec3: a vector that contains the x, y, and z values. - **Parameters:** - `x` (float): x component of the vector. diff --git a/docs/lua/tables/gui.md b/docs/lua/tables/gui.md index 4197c928..5d931706 100644 --- a/docs/lua/tables/gui.md +++ b/docs/lua/tables/gui.md @@ -2,7 +2,7 @@ Table containing functions for modifying the menu GUI. -## Functions (8) +## Functions (12) ### `get_tab(tab_name)` @@ -92,6 +92,38 @@ gui.show_error(title, message) bool = gui.is_open() ``` +### `toggle(toggle)` + +Opens and closes the gui. + +- **Parameters:** + - `toggle` (boolean) + +**Example Usage:** +```lua +gui.toggle(toggle) +``` + +### `mouse_override()` + +- **Returns:** + - `bool`: Returns true if the mouse is overridden. + +**Example Usage:** +```lua +bool = gui.mouse_override() +``` + +### `override_mouse(override)` + +- **Parameters:** + - `override` (boolean) + +**Example Usage:** +```lua +gui.override_mouse(override) +``` + ### `add_imgui(imgui_rendering)` Registers a function that will be called every rendering frame, you can call ImGui functions in it, please check the ImGui.md documentation file for more info. @@ -118,4 +150,30 @@ end) gui.add_imgui(imgui_rendering) ``` +### `add_always_draw_imgui(imgui_rendering)` + +Registers a function that will be called every rendering frame, you can call ImGui functions in it, please check the ImGui.md documentation file for more info. This function will be called even when the menu is closed. +**Example Usage:** +```lua +gui.add_always_draw_imgui(function() + if ImGui.Begin("My Custom Window") then + if ImGui.Button("Label") then + script.run_in_fiber(function(script) + -- call natives in there + end) + end + + ImGui.End() + end +end) +`` + +- **Parameters:** + - `imgui_rendering` (function): Function that will be called every rendering frame, you can call ImGui functions in it, please check the ImGui.md documentation file for more info. + +**Example Usage:** +```lua +gui.add_always_draw_imgui(imgui_rendering) +``` + diff --git a/docs/lua/tables/menu_event.md b/docs/lua/tables/menu_event.md index f3c6c4cd..97030bbf 100644 --- a/docs/lua/tables/menu_event.md +++ b/docs/lua/tables/menu_event.md @@ -2,7 +2,7 @@ Table containing all possible events to which you can respond. -## Fields (8) +## Fields (9) ### `PlayerLeave` @@ -103,3 +103,16 @@ end) - Type: `integer` +### `Wndproc` + +Event that is triggered when Wndproc is called +**Example Usage:** +```lua +event.register_handler(menu_event.Wndproc, function (hwnd, msg, wparam, lparam) + if msg == 132 then return end + log.debug("hwnd = " .. tostring(hwnd) .. ", msg = " .. tostring(msg) .. ", wparam = " .. tostring(wparam) .. ", lparam = " .. tostring(lparam)) +end) +``` + +- Type: `integer` + diff --git a/docs/lua/tables/network.md b/docs/lua/tables/network.md index 7510e04b..87b1e582 100644 --- a/docs/lua/tables/network.md +++ b/docs/lua/tables/network.md @@ -2,7 +2,7 @@ Table containing helper functions for network related features. -## Functions (17) +## Functions (22) ### `trigger_script_event(bitset, _args)` @@ -146,7 +146,7 @@ string = network.get_flagged_modder_reason(player_idx) Try to force ourself to be host for the given GTA Script. Needs to be called in the fiber pool or a loop. - **Parameters:** - - `script_name` (string): Name of the script + - `script_name` (string): Name of the script. **Example Usage:** ```lua @@ -164,7 +164,7 @@ Forces the given GTA script to be started on a player. Needs to be called in the **Example Usage:** ```lua -network.force_script_on_player(script_name) +network.force_script_on_player(player_idx, script_name, instance_id) ``` ### `send_chat_message(msg, team_only)` @@ -198,14 +198,14 @@ network.send_chat_message_to_player(player_idx, msg) Call get_player_rank(playerID) - **Parameters:** - - `pid` (int) + - `pid` (integer): Index of the player. - **Returns:** - - `int`: Returns an integer which contains the players rank. + - `integer`: An integer which contains the players rank. **Example Usage:** ```lua -network.get_player_rank(pid) +integer = network.get_player_rank(pid) ``` ### `get_player_rp(pid)` @@ -213,14 +213,14 @@ network.get_player_rank(pid) Call get_player_rp(playerID) - **Parameters:** - - `pid` (int) + - `pid` (integer): Index of the player. - **Returns:** - - `int`: Returns an integer which contains the players rp. + - `integer`: An integer which contains the players rp. **Example Usage:** ```lua -network.get_player_rp(pid) +integer = network.get_player_rp(pid) ``` ### `get_player_money(pid)` @@ -228,14 +228,14 @@ network.get_player_rp(pid) Call get_player_money(playerID) - **Parameters:** - - `pid` (int) + - `pid` (integer): Index of the player. - **Returns:** - - `int`: Returns an integer which contains the players money. + - `integer`: An integer which contains the players money. **Example Usage:** ```lua -network.get_player_money(pid) +integer = network.get_player_money(pid) ``` ### `get_player_wallet(pid)` @@ -243,14 +243,14 @@ network.get_player_money(pid) Call get_player_wallet(playerID) - **Parameters:** - - `pid` (int) + - `pid` (integer): Index of the player. - **Returns:** - - `int`: Returns an integer which contains the players wallet. + - `integer`: An integer which contains the players wallet. **Example Usage:** ```lua -network.get_player_wallet(pid) +integer = network.get_player_wallet(pid) ``` ### `get_player_bank(pid)` @@ -258,14 +258,14 @@ network.get_player_wallet(pid) Call get_player_bank(playerID) - **Parameters:** - - `pid` (int) + - `pid` (integer): Index of the player. - **Returns:** - - `int`: Returns an integer which contains the players bank. + - `integer`: An integer which contains the players bank. **Example Usage:** ```lua -network.get_player_bank(pid) +integer = network.get_player_bank(pid) ``` ### `get_player_language_id(pid)` @@ -273,14 +273,14 @@ network.get_player_bank(pid) Call get_player_language_id(playerID) - **Parameters:** - - `pid` (int) + - `pid` (integer): Index of the player. - **Returns:** - - `int`: Returns an integer which contains the players language id. + - `integer`: An integer which contains the players language id. **Example Usage:** ```lua -network.get_player_language_id(pid) +integer = network.get_player_language_id(pid) ``` ### `get_player_language_name(pid)` @@ -288,12 +288,14 @@ network.get_player_language_id(pid) Call get_player_language_name(playerID) - **Parameters:** - - `pid` (int) + - `pid` (integer): Index of the player. - **Returns:** - - `string`: Returns a string which contains the players language name. + - `string`: A string which contains the players language name. **Example Usage:** ```lua -network.get_player_language_name(pid) -``` \ No newline at end of file +string = network.get_player_language_name(pid) +``` + + diff --git a/docs/lua/tables/scr_function.md b/docs/lua/tables/scr_function.md index 10ccaab2..10944e76 100644 --- a/docs/lua/tables/scr_function.md +++ b/docs/lua/tables/scr_function.md @@ -1,43 +1,52 @@ # Table: scr_function -Table for calling GTA script functions. Needs to be called in the fiber pool or a GTA script. Only call the function when necessary. +Table for calling GTA script functions. Needs to be called in the fiber pool. Only call the function when necessary. ## Functions (2) ### `call_script_function(script_name, function_name, pattern, return_type_string, args_)` Calls a script function with the given arguments. Returns the return value as the given type. +**Example Usage:** +```lua +local value = scr_function.call_script_function("freemode", "wear_sunglasses_at_night", "69 42 06 66", "bool", { + { "int", 69 }, + { "float", 4.20 }, + { "int", 666 } +}) +``` - **Parameters:** - `script_name` (string): Name of the script. - `function_name` (string): Name of the function. This parameter needs to be unique. - `pattern` (string): Pattern to scan for within the script. - `return_type_string` (string): Return type of the function. Supported types are **"int"**, **"bool"**, **"const char\*/string"**, **"ptr/pointer/*"**, **"float"**, and **"vector3"**. Anything different will be rejected. - - `_args` (table): Arguments to pass to the function. Supported types are the same as return types. + - `args_` (table): Arguments to pass to the function. Supported types are the same as return types. **Example Usage:** ```lua -local value = scr_function.call_script_function("freemode", "wear_sunglasses_at_night", "69 42 06 66", "bool", { - { "int", 69 }, - { "float", 4.20 }, - { "int", 666 } -}) +scr_function.call_script_function(script_name, function_name, pattern, return_type_string, args_) ``` ### `call_script_function(script_name, instruction_pointer, return_type_string, args_)` Calls a script function directly using the function position with the given arguments. Returns the return value as the given type. +**Example Usage:** +```lua +local value = scr_function.call_script_function("freemode", 0xE792, "string", { + { "int", 191 } +}) +``` - **Parameters:** - `script_name` (string): Name of the script. - - `function_name` (string): Name of the function. - `instruction_pointer` (integer): Position of the function within the script. - `return_type_string` (string): Return type of the function. Supported types are **"int"**, **"bool"**, **"const char\*/string"**, **"ptr/pointer/*"**, **"float"**, and **"vector3"**. Anything different will be rejected. - - `_args` (table): Arguments to pass to the function. Supported types are the same as return types. + - `args_` (table): Arguments to pass to the function. Supported types are the same as return types. **Example Usage:** ```lua -local value = scr_function.call_script_function("freemode", 0xE792, "string", { - { "int", 191 } -}) -``` \ No newline at end of file +scr_function.call_script_function(script_name, instruction_pointer, return_type_string, args_) +``` + + diff --git a/docs/lua/tables/script.md b/docs/lua/tables/script.md index a468166d..be26a423 100644 --- a/docs/lua/tables/script.md +++ b/docs/lua/tables/script.md @@ -2,16 +2,11 @@ Table containing helper functions related to gta scripts. -## Functions (7) +## Functions (6) ### `register_looped(name, func)` Registers a function that will be looped as a gta script. - -- **Parameters:** - - `name` (string): name of your new looped script - - `func` (function): function that will be executed in a forever loop. - **Example Usage:** ```lua script.register_looped("nameOfMyLoopedScript", function (script) @@ -36,13 +31,18 @@ script.register_looped("nameOfMyLoopedScript", function (script) end) ``` +- **Parameters:** + - `name` (string): name of your new looped script + - `func` (function): function that will be executed in a forever loop. + +**Example Usage:** +```lua +script.register_looped(name, func) +``` + ### `run_in_fiber(func)` Executes a function once inside the fiber pool, you can call natives inside it and yield or sleep. - -- **Parameters:** - - `func` (function): function that will be executed once in the fiber pool. - **Example Usage:** ```lua script.run_in_fiber(function (script) @@ -67,16 +67,28 @@ script.run_in_fiber(function (script) end) ``` +- **Parameters:** + - `func` (function): function that will be executed once in the fiber pool. + +**Example Usage:** +```lua +script.run_in_fiber(func) +``` + ### `is_active(script_name)` Returns true if the specified script is currently active/running. +**Example Usage:** +```lua +local is_freemode_active = script.is_active("freemode") +``` - **Parameters:** - `script_name` (string): The name of the script. **Example Usage:** ```lua -local is_freemode_active = script.is_active("freemode") +script.is_active(script_name) ``` ### `execute_as_script(script_name, func)` @@ -93,29 +105,39 @@ script.execute_as_script(script_name, func) ### `add_patch(script_name, name, pattern, offset, _patch)` Adds a patch for the specified script. - -- **Parameters:** - - `script_name` (string): The name of the script. - - `name` (string): The name of the patch. - - `pattern` (string): Pattern to scan for within the script. - - `offset` (integer): The position within the pattern. - - `_patch` (table): The bytes to be written into the script's bytecode. - **Example Usage:** ```lua script.add_patch("fm_content_xmas_truck", "Flickering Fix", "56 ? ? 4F ? ? 40 ? 5D ? ? ? 74", 0, {0x2B, 0x00, 0x00}) ``` -### `start_launcher_script(script_name)` - -Tries to start a launcher script. Needs to be called in the fiber pool or a loop. - - **Parameters:** - - `name` (string): The name of the script. + - `script_name` (string): The name of the script. + - `name` (string): The name of the patch. + - `pattern` (string): The pattern to scan for within the script. + - `offset` (integer): The position within the pattern. + - `_patch` (table): The bytes to be written into the script's bytecode. +**Example Usage:** +```lua +script.add_patch(script_name, name, pattern, offset, _patch) +``` + +### `start_launcher_script(script_name)` + +Tries to start a launcher script. Needs to be called in the fiber pool or a loop. **Example Usage:** ```lua script.run_in_fiber(function() - script.start_launcher_script("am_hunt_the_beast") + script.start_launcher_script("am_hunt_the_beast") end) -``` \ No newline at end of file +``` + +- **Parameters:** + - `script_name` (string): The name of the script. + +**Example Usage:** +```lua +script.start_launcher_script(script_name) +``` + + diff --git a/src/core/data/menu_event.hpp b/src/core/data/menu_event.hpp index e124122b..dd97a276 100644 --- a/src/core/data/menu_event.hpp +++ b/src/core/data/menu_event.hpp @@ -10,4 +10,5 @@ enum class menu_event ScriptedGameEventReceived, MenuUnloaded, ScriptsReloaded, + Wndproc, }; \ No newline at end of file diff --git a/src/gui.cpp b/src/gui.cpp index f3e6df64..6a063daf 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -1,5 +1,6 @@ #include "gui.hpp" +#include "lua/lua_manager.hpp" #include "natives.hpp" #include "renderer/renderer.hpp" #include "script.hpp" @@ -21,6 +22,7 @@ namespace big // medium priority MENU = 0x1000, VEHICLE_CONTROL, + LUA, // high priority INFO_OVERLAY = 0x2000, @@ -53,6 +55,15 @@ namespace big }, eRenderPriority::MENU); + g_renderer.add_dx_callback( + [] { + g_lua_manager->draw_always_draw_gui(); + }, + eRenderPriority::LUA); + + g_renderer.add_wndproc_callback([](HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { + g_lua_manager->trigger_event(hwnd, msg, wparam, lparam); + }); g_renderer.add_wndproc_callback([this](HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { wndproc(hwnd, msg, wparam, lparam); }); diff --git a/src/lua/bindings/event.cpp b/src/lua/bindings/event.cpp index acb12300..87967300 100644 --- a/src/lua/bindings/event.cpp +++ b/src/lua/bindings/event.cpp @@ -98,6 +98,18 @@ namespace lua::event // end) // ``` + // Lua API: Field + // Table: menu_event + // Field: Wndproc: integer + // Event that is triggered when Wndproc is called + // **Example Usage:** + // ```lua + // event.register_handler(menu_event.Wndproc, function (hwnd, msg, wparam, lparam) + // if msg == 132 then return end + // log.debug("hwnd = " .. tostring(hwnd) .. ", msg = " .. tostring(msg) .. ", wparam = " .. tostring(wparam) .. ", lparam = " .. tostring(lparam)) + // end) + // ``` + // Lua API: Table // Name: event // Table for responding to various events. The list of events is available in the menu_event table. @@ -125,8 +137,9 @@ namespace lua::event {"PlayerMgrShutdown", menu_event::PlayerMgrShutdown}, {"ChatMessageReceived", menu_event::ChatMessageReceived}, {"ScriptedGameEventReceived", menu_event::ScriptedGameEventReceived}, - {"MenuUnloaded", menu_event::MenuUnloaded}, - {"ScriptsReloaded", menu_event::ScriptsReloaded}, + {"MenuUnloaded", menu_event::MenuUnloaded}, + {"ScriptsReloaded", menu_event::ScriptsReloaded}, + {"Wndproc", menu_event::Wndproc}, }); diff --git a/src/lua/bindings/gui.cpp b/src/lua/bindings/gui.cpp index d95423f6..873acaaa 100644 --- a/src/lua/bindings/gui.cpp +++ b/src/lua/bindings/gui.cpp @@ -11,6 +11,13 @@ namespace lua::gui module->m_independent_gui.push_back(std::move(element)); } + static void add_always_draw_element(lua_State* state, std::unique_ptr element) + { + big::lua_module* module = sol::state_view(state)["!this"]; + + module->m_always_draw_gui.push_back(std::move(element)); + } + static void add_element(lua_State* state, uint32_t hash, std::unique_ptr element) { big::lua_module* module = sol::state_view(state)["!this"]; @@ -296,6 +303,35 @@ namespace lua::gui return big::g_gui->is_open(); } + // Lua API: Function + // Table: gui + // Name: toggle + // Param: toggle: boolean + // Opens and closes the gui. + static void toggle(bool toggle) + { + big::g_gui->toggle(toggle); + } + + + // Lua API: Function + // Table: gui + // Name: mouse_override + // Returns: bool: Returns true if the mouse is overridden. + static bool mouse_override() + { + return big::g_gui->mouse_override(); + } + + // Lua API: Function + // Table: gui + // Name: override_mouse + // Param: override: boolean + static void override_mouse(bool override) + { + big::g_gui->override_mouse(override); + } + // Lua API: Function // Table: gui // Name: add_imgui @@ -323,17 +359,48 @@ namespace lua::gui return el_ptr; } + // Lua API: Function + // Table: gui + // Name: add_always_draw_imgui + // Param: imgui_rendering: function: Function that will be called every rendering frame, you can call ImGui functions in it, please check the ImGui.md documentation file for more info. + // Registers a function that will be called every rendering frame, you can call ImGui functions in it, please check the ImGui.md documentation file for more info. This function will be called even when the menu is closed. + // **Example Usage:** + // ```lua + // gui.add_always_draw_imgui(function() + // if ImGui.Begin("My Custom Window") then + // if ImGui.Button("Label") then + // script.run_in_fiber(function(script) + // -- call natives in there + // end) + // end + // + // ImGui.End() + // end + // end) + // `` + static lua::gui::raw_imgui_callback* add_always_draw_imgui(sol::protected_function imgui_rendering, sol::this_state state) + { + auto element = std::make_unique(imgui_rendering); + auto el_ptr = element.get(); + add_always_draw_element(state, std::move(element)); + return el_ptr; + } + void bind(sol::state& state) { - auto ns = state["gui"].get_or_create(); - ns["get_tab"] = get_tab; - ns["add_tab"] = add_tab; - ns["show_success"] = show_success; - ns["show_message"] = show_message; - ns["show_warning"] = show_warning; - ns["show_error"] = show_error; - ns["is_open"] = is_open; - ns["add_imgui"] = add_imgui; + auto ns = state["gui"].get_or_create(); + ns["get_tab"] = get_tab; + ns["add_tab"] = add_tab; + ns["show_success"] = show_success; + ns["show_message"] = show_message; + ns["show_warning"] = show_warning; + ns["show_error"] = show_error; + ns["is_open"] = is_open; + ns["toggle"] = toggle; + ns["mouse_override"] = mouse_override; + ns["override_mouse"] = override_mouse; + ns["add_imgui"] = add_imgui; + ns["add_always_draw_imgui"] = add_always_draw_imgui; auto button_ut = ns.new_usertype("button"); button_ut["get_text"] = &lua::gui::button::get_text; diff --git a/src/lua/bindings/gui.hpp b/src/lua/bindings/gui.hpp index d92927d6..38a07113 100644 --- a/src/lua/bindings/gui.hpp +++ b/src/lua/bindings/gui.hpp @@ -50,6 +50,8 @@ namespace lua::gui // Lua API: Function // Class: tab // Name: add_tab + // Param: tab_name: string: Name of the tab to add. + // Returns: tab: A tab instance which corresponds to the new tab in the GUI. // Add a sub tab to this tab. tab add_tab(const std::string& name, sol::this_state state); diff --git a/src/lua/bindings/imgui.hpp b/src/lua/bindings/imgui.hpp index 6e35bb76..c9052a29 100644 --- a/src/lua/bindings/imgui.hpp +++ b/src/lua/bindings/imgui.hpp @@ -1260,7 +1260,7 @@ namespace lua::imgui float value[3] = {static_cast(v1), static_cast(v2), static_cast(v3)}; bool used = ImGui::SliderFloat3(label.c_str(), value, v_min, v_max); - sol::as_table_t float3 = sol::as_table(std::vector{value[0], value[1], value[3]}); + sol::as_table_t float3 = sol::as_table(std::vector{value[0], value[1], value[2]}); return std::make_tuple(float3, used); } @@ -1272,7 +1272,7 @@ namespace lua::imgui float value[3] = {static_cast(v1), static_cast(v2), static_cast(v3)}; bool used = ImGui::SliderFloat3(label.c_str(), value, v_min, v_max, format.c_str()); - sol::as_table_t float3 = sol::as_table(std::vector{value[0], value[1], value[3]}); + sol::as_table_t float3 = sol::as_table(std::vector{value[0], value[1], value[2]}); return std::make_tuple(float3, used); } @@ -1284,7 +1284,7 @@ namespace lua::imgui float value[3] = {static_cast(v1), static_cast(v2), static_cast(v3)}; bool used = ImGui::SliderFloat3(label.c_str(), value, v_min, v_max, format.c_str(), flags); - sol::as_table_t float3 = sol::as_table(std::vector{value[0], value[1], value[3]}); + sol::as_table_t float3 = sol::as_table(std::vector{value[0], value[1], value[2]}); return std::make_tuple(float3, used); } diff --git a/src/lua/bindings/memory.cpp b/src/lua/bindings/memory.cpp index 841209d5..0c25b7e2 100644 --- a/src/lua/bindings/memory.cpp +++ b/src/lua/bindings/memory.cpp @@ -62,6 +62,11 @@ namespace lua::memory return m_address; } + void pointer::set_address(uint64_t address) + { + m_address = address; + } + // Lua API: Table // Name: memory // Table containing helper functions related to process memory. @@ -647,6 +652,7 @@ namespace lua::memory pointer_ut["is_valid"] = &pointer::is_valid; pointer_ut["deref"] = &pointer::deref; pointer_ut["get_address"] = &pointer::get_address; + pointer_ut["set_address"] = &pointer::set_address; auto patch_ut = ns.new_usertype("patch", sol::no_constructor); patch_ut["apply"] = &big::lua_patch::apply; diff --git a/src/lua/bindings/memory.hpp b/src/lua/bindings/memory.hpp index f285b3d2..f10ad9f9 100644 --- a/src/lua/bindings/memory.hpp +++ b/src/lua/bindings/memory.hpp @@ -58,6 +58,12 @@ namespace lua::memory // Returns: number: the value stored at the memory address as the specified type. // Retrieves the value stored at the memory address as the specified type. + // Lua API: Function + // Class: pointer + // Name: get_int + // Returns: number: the value stored at the memory address as the specified type. + // Retrieves the value stored at the memory address as the specified type. + // Lua API: Function // Class: pointer // Name: get_dword @@ -94,6 +100,12 @@ namespace lua::memory // Param: value: number: new value. // Sets the value at the memory address to the specified value of the given type. + // Lua API: Function + // Class: pointer + // Name: set_int + // Param: value: number: new value. + // Sets the value at the memory address to the specified value of the given type. + // Lua API: Function // Class: pointer // Name: set_dword @@ -204,6 +216,13 @@ namespace lua::memory // Returns: number: The memory address stored in the pointer object as a number. // Retrieves the memory address stored in the pointer object. uint64_t get_address() const; + + // Lua API: Function + // Class: pointer + // Name: set_address + // Param: address: integer: new address. + // Sets the memory address stored in the pointer object. + void set_address(uint64_t address); }; // Lua API: Class diff --git a/src/lua/bindings/network.cpp b/src/lua/bindings/network.cpp index ee69ed45..af19287a 100644 --- a/src/lua/bindings/network.cpp +++ b/src/lua/bindings/network.cpp @@ -188,11 +188,11 @@ namespace lua::network } // Lua API: function - // Table: script + // Table: network // Name: force_script_on_player // Param: player_idx: integer: Index of the player. // Param: script_name: string: Name of the script. - // Param: script_name: integer: Instance ID of the script. + // Param: instance_id: integer: Instance ID of the script. // Forces the given GTA script to be started on a player. Needs to be called in the fiber pool or a loop. static void force_script_on_player(int player_idx, const std::string& script_name, int instance_id) { @@ -229,6 +229,7 @@ namespace lua::network // Table: network // Name: get_player_rank // Param: pid: integer: Index of the player. + // Returns: integer: An integer which contains the players rank. // Call get_player_rank(playerID) static int get_player_rank(int pid) { @@ -244,6 +245,7 @@ namespace lua::network // Table: network // Name: get_player_rp // Param: pid: integer: Index of the player. + // Returns: integer: An integer which contains the players rp. // Call get_player_rp(playerID) static int get_player_rp(int pid) { @@ -259,6 +261,7 @@ namespace lua::network // Table: network // Name: get_player_money // Param: pid: integer: Index of the player. + // Returns: integer: An integer which contains the players money. // Call get_player_money(playerID) static int get_player_money(int pid) { @@ -274,6 +277,7 @@ namespace lua::network // Table: network // Name: get_player_wallet // Param: pid: integer: Index of the player. + // Returns: integer: An integer which contains the players wallet. // Call get_player_wallet(playerID) static int get_player_wallet(int pid) { @@ -289,6 +293,7 @@ namespace lua::network // Table: network // Name: get_player_bank // Param: pid: integer: Index of the player. + // Returns: integer: An integer which contains the players bank. // Call get_player_bank(playerID) static int get_player_bank(int pid) { @@ -304,6 +309,7 @@ namespace lua::network // Table: network // Name: get_player_language_id // Param: pid: integer: Index of the player. + // Returns: integer: An integer which contains the players language id. // Call get_player_language_id(playerID) static int get_player_language_id(int pid) { @@ -319,6 +325,7 @@ namespace lua::network // Table: network // Name: get_player_language_name // Param: pid: integer: Index of the player. + // Returns: string: A string which contains the players language name. // Call get_player_language_name(playerID) static std::string get_player_language_name(int pid) { diff --git a/src/lua/bindings/script.cpp b/src/lua/bindings/script.cpp index c56719cb..80ebfa2e 100644 --- a/src/lua/bindings/script.cpp +++ b/src/lua/bindings/script.cpp @@ -188,8 +188,8 @@ namespace lua::script // Param: script_name: string: The name of the script. // Param: name: string: The name of the patch. // Param: pattern: string: The pattern to scan for within the script. - // Param offset: integer: The position within the pattern. - // Param _patch: table: The bytes to be written into the script's bytecode. + // Param: offset: integer: The position within the pattern. + // Param: _patch: table: The bytes to be written into the script's bytecode. // Adds a patch for the specified script. // **Example Usage:** // ```lua diff --git a/src/lua/bindings/vector.hpp b/src/lua/bindings/vector.hpp index 191e53aa..ad297269 100644 --- a/src/lua/bindings/vector.hpp +++ b/src/lua/bindings/vector.hpp @@ -11,7 +11,7 @@ namespace lua::vector // Param: x: float: x component of the vector. // Param: y: float: y component of the vector. // Param: z: float: z component of the vector. - // Returns a vector that contains the x, y, and z values. + // Returns: vec3: a vector that contains the x, y, and z values. // Lua API: Field // Class: vec3 diff --git a/src/lua/lua_manager.cpp b/src/lua/lua_manager.cpp index ecea26fe..756afd93 100644 --- a/src/lua/lua_manager.cpp +++ b/src/lua/lua_manager.cpp @@ -150,6 +150,19 @@ namespace big } } + void lua_manager::draw_always_draw_gui() + { + std::lock_guard guard(m_module_lock); + + for (const auto& module : m_modules) + { + for (const auto& element : module->m_always_draw_gui) + { + element->draw(); + } + } + } + void lua_manager::draw_gui(rage::joaat_t tab_hash) { std::lock_guard guard(m_module_lock); @@ -303,6 +316,10 @@ namespace big return {}; } + // Some scripts are library scripts, they do nothing on their own and are intended to be used with require, they take up space in the script list for no reason. + if (std::filesystem::relative(module_path.parent_path(), m_scripts_folder.get_path()).wstring().contains(L"includes")) + return {}; + const auto module_name = module_path.filename().string(); const auto id = rage::joaat(module_name); diff --git a/src/lua/lua_manager.hpp b/src/lua/lua_manager.hpp index b860893e..998aa651 100644 --- a/src/lua/lua_manager.hpp +++ b/src/lua/lua_manager.hpp @@ -48,6 +48,7 @@ namespace big bool has_gui_to_draw(rage::joaat_t tab_hash); void draw_independent_gui(); + void draw_always_draw_gui(); void draw_gui(rage::joaat_t tab_hash); bool dynamic_hook_pre_callbacks(const uintptr_t target_func_ptr, lua::memory::type_info_t return_type, lua::memory::runtime_func_t::return_value_t* return_value, std::vector param_types, const lua::memory::runtime_func_t::parameters_t* params, const uint8_t param_count); diff --git a/src/lua/lua_module.hpp b/src/lua/lua_module.hpp index 750fd6ef..099b5ab7 100644 --- a/src/lua/lua_module.hpp +++ b/src/lua/lua_module.hpp @@ -34,6 +34,7 @@ namespace big std::unordered_map> m_tab_to_sub_tabs; std::vector> m_independent_gui; + std::vector> m_always_draw_gui; std::unordered_map>> m_gui; std::unordered_map> m_event_callbacks; std::vector m_allocated_memory; From ee69b3b0b918b07a27ebc8603a0101db33ece533 Mon Sep 17 00:00:00 2001 From: gir489 <100792176+gir489returns@users.noreply.github.com> Date: Wed, 14 Aug 2024 02:41:47 -0400 Subject: [PATCH 7/7] Refactor Weapons JSON parser to associate path with recentness (#3565) * Added a RPF parse hierarchy to ensure the latest weapon file is loaded into the Weapons JSON. * Fixed erroneous attachment descriptions being displayed and persisted to the Weapons JSON. * Fix for components that had empty descriptions. --- src/services/gta_data/gta_data_service.cpp | 49 +++++++++++++++++++--- src/services/gta_data/weapon_item.hpp | 17 +++++++- src/views/self/view_weapons.cpp | 7 ++-- 3 files changed, 63 insertions(+), 10 deletions(-) diff --git a/src/services/gta_data/gta_data_service.cpp b/src/services/gta_data/gta_data_service.cpp index 6d31c432..d0c68164 100644 --- a/src/services/gta_data/gta_data_service.cpp +++ b/src/services/gta_data/gta_data_service.cpp @@ -218,6 +218,27 @@ namespace big std::sort(m_weapon_types.begin(), m_weapon_types.end()); } + static RPFDatafileSource determine_file_type(std::string file_path, std::string_view rpf_filename) + { + if (file_path.contains("/dlc_patch/")) + { + return RPFDatafileSource::DLCUPDATE; + } + else if (rpf_filename == "dlc.rpf") + { + return RPFDatafileSource::DLC; + } + else if (rpf_filename == "update.rpf") + { + return RPFDatafileSource::UPDATE; + } + else if (rpf_filename == "common.rpf") + { + return RPFDatafileSource::BASE; + } + return RPFDatafileSource::UNKNOWN; + } + inline void parse_ped(std::vector& peds, std::vector& mapped_peds, pugi::xml_document& doc) { const auto& items = doc.select_nodes("/CPedModelInfo__InitDataList/InitDatas/Item"); @@ -261,7 +282,7 @@ namespace big std::vector peds; std::vector vehicles; //std::vector weapons; - std::unordered_map weapons; + std::unordered_map weapons; std::vector weapon_components; constexpr auto exists = [](const hash_array& arr, uint32_t val) -> bool { @@ -377,6 +398,9 @@ namespace big LocDesc = display_string; } + if (LocDesc.ends_with("INVALID")) + LocDesc.clear(); + weapon_component component; component.m_name = name; @@ -388,9 +412,9 @@ namespace big } }); } - else if (const auto file_str = path.string(); file_str.find("weapon") != std::string::npos && path.extension() == ".meta") + else if (const auto file_str = path.string(); file_str.contains("weapon") && !file_str.contains("vehicle") && path.extension() == ".meta") { - rpf_wrapper.read_xml_file(path, [&exists, &weapons, &mapped_weapons](pugi::xml_document& doc) { + rpf_wrapper.read_xml_file(path, [&exists, &weapons, &mapped_weapons, file_str, &rpf_wrapper](pugi::xml_document& doc) { const auto& items = doc.select_nodes("/CWeaponInfoBlob/Infos/Item/Infos/Item[@type='CWeaponInfo']"); for (const auto& item_node : items) { @@ -408,11 +432,11 @@ namespace big if (std::strcmp(human_name_hash, "WT_INVALID") == 0 || std::strcmp(human_name_hash, "WT_VEHMINE") == 0) continue; - auto weapon = weapon_item{}; + auto weapon = weapon_item_parsed{}; weapon.m_name = name; - weapon.m_display_name = human_name_hash; + weapon.rpf_file_type = determine_file_type(file_str, rpf_wrapper.get_name()); auto weapon_flags = std::string(item.child("WeaponFlags").text().as_string()); @@ -477,6 +501,14 @@ namespace big weapon.m_hash = hash; + if (weapons.contains(hash)) + { + if (weapons[hash].rpf_file_type > weapon.rpf_file_type) + { + continue; + } + } + weapons[hash] = weapon; skip: continue; @@ -540,7 +572,12 @@ namespace big for (auto& item : weapon_components) { item.m_display_name = HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(item.m_display_name.c_str()); - item.m_display_desc = HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(item.m_display_desc.c_str()); + if (!item.m_display_desc.empty()) + { + item.m_display_desc = HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(item.m_display_desc.c_str()); + if (item.m_display_desc == "NULL") + item.m_display_desc.clear(); + } } for (auto it = peds.begin(); it != peds.end();) { diff --git a/src/services/gta_data/weapon_item.hpp b/src/services/gta_data/weapon_item.hpp index c1c16920..4adb76c2 100644 --- a/src/services/gta_data/weapon_item.hpp +++ b/src/services/gta_data/weapon_item.hpp @@ -2,7 +2,16 @@ namespace big { - class weapon_item final + enum RPFDatafileSource : std::uint8_t + { + UNKNOWN, + BASE, + UPDATE, + DLC, + DLCUPDATE + }; + + class weapon_item { public: std::string m_name; @@ -16,4 +25,10 @@ namespace big NLOHMANN_DEFINE_TYPE_INTRUSIVE(weapon_item, m_name, m_display_name, m_weapon_type, m_hash, m_reward_hash, m_reward_ammo_hash, m_attachments, m_throwable) }; + + class weapon_item_parsed : public weapon_item + { + public: + RPFDatafileSource rpf_file_type = RPFDatafileSource::UNKNOWN; + }; } \ No newline at end of file diff --git a/src/views/self/view_weapons.cpp b/src/views/self/view_weapons.cpp index b95f2103..6853c390 100644 --- a/src/views/self/view_weapons.cpp +++ b/src/views/self/view_weapons.cpp @@ -292,19 +292,20 @@ namespace big { continue; } + ImGui::PushID(attachment_hash); bool is_selected = attachment_hash == selected_weapon_attachment_hash; - std::string display_name = attachment_name.append("##").append(std::to_string(attachment_hash)); - if (ImGui::Selectable(display_name.c_str(), is_selected, ImGuiSelectableFlags_None)) + if (ImGui::Selectable(attachment_name.c_str(), is_selected, ImGuiSelectableFlags_None)) { selected_weapon_attachment = attachment_name; selected_weapon_attachment_hash = attachment_hash; } - if (ImGui::IsItemHovered()) + if (ImGui::IsItemHovered() && !attachment_component.m_display_desc.empty()) ImGui::SetTooltip(attachment_component.m_display_desc.c_str()); if (is_selected) { ImGui::SetItemDefaultFocus(); } + ImGui::PopID(); } }