From d2b1b505ed5fbda6e79f544658f0fbb17123b36f Mon Sep 17 00:00:00 2001 From: Arthur <121949966+ShinyWasabi@users.noreply.github.com> Date: Tue, 3 Sep 2024 10:22:27 +0300 Subject: [PATCH] Add Description for Weapons (#3649) --- src/script_function.hpp | 1 + src/services/gta_data/gta_data_service.cpp | 44 +++++++++++++--------- src/services/gta_data/weapon_item.hpp | 3 +- src/views/self/view_ammunation.cpp | 10 ++++- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/script_function.hpp b/src/script_function.hpp index 70202352..1c05c409 100644 --- a/src/script_function.hpp +++ b/src/script_function.hpp @@ -81,5 +81,6 @@ namespace big 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"); + inline script_function get_weapon_desc_string("GWDS", "mp_weapons"_J, "2D 02 A0 00 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 eca9c22e..925b3ed7 100644 --- a/src/services/gta_data/gta_data_service.cpp +++ b/src/services/gta_data/gta_data_service.cpp @@ -289,6 +289,23 @@ namespace big return std::find(arr.begin(), arr.end(), val) != arr.end(); }; + 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::paused; + else + LOG(FATAL) << "Failed to find MP_Weapons script!"; + SCRIPT::SET_SCRIPT_WITH_NAME_HASH_AS_NO_LONGER_NEEDED(script_hash); + } + LOG(INFO) << "Rebuilding cache started..."; yim_fipackfile::add_wrapper_call_back([&](yim_fipackfile& rpf_wrapper, std::filesystem::path path) -> void { if (path.filename() == "vehicles.meta") @@ -358,23 +375,6 @@ namespace big 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::paused; - 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; @@ -432,10 +432,15 @@ namespace big if (std::strcmp(human_name_hash, "WT_INVALID") == 0 || std::strcmp(human_name_hash, "WT_VEHMINE") == 0) continue; + std::string desc = scr_functions::get_weapon_desc_string.call(hash, false); + if (desc.ends_with("INVALID")) + desc.clear(); + auto weapon = weapon_item_parsed{}; - weapon.m_name = name; + weapon.m_name = name; weapon.m_display_name = human_name_hash; + weapon.m_display_desc = desc; weapon.rpf_file_type = determine_file_type(file_str, rpf_wrapper.get_name()); auto weapon_flags = std::string(item.child("WeaponFlags").text().as_string()); @@ -568,6 +573,9 @@ namespace big for (auto& item : weapons) { item.second.m_display_name = HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(item.second.m_display_name.c_str()); + item.second.m_display_desc = HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(item.second.m_display_desc.c_str()); + if (item.second.m_display_desc == "NULL") + item.second.m_display_desc.clear(); } for (auto& item : weapon_components) { diff --git a/src/services/gta_data/weapon_item.hpp b/src/services/gta_data/weapon_item.hpp index 4adb76c2..d2de439c 100644 --- a/src/services/gta_data/weapon_item.hpp +++ b/src/services/gta_data/weapon_item.hpp @@ -16,6 +16,7 @@ namespace big public: std::string m_name; std::string m_display_name; + std::string m_display_desc; std::string m_weapon_type; uint32_t m_hash; uint32_t m_reward_hash; @@ -23,7 +24,7 @@ namespace big std::vector m_attachments; bool m_throwable; - 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) + NLOHMANN_DEFINE_TYPE_INTRUSIVE(weapon_item, m_name, m_display_name, m_display_desc, m_weapon_type, m_hash, m_reward_hash, m_reward_ammo_hash, m_attachments, m_throwable) }; class weapon_item_parsed : public weapon_item diff --git a/src/views/self/view_ammunation.cpp b/src/views/self/view_ammunation.cpp index aa3f8304..c265e348 100644 --- a/src/views/self/view_ammunation.cpp +++ b/src/views/self/view_ammunation.cpp @@ -106,6 +106,14 @@ namespace big selected_attachment_hash = 0; selected_tint = 0; } + if (ImGui::IsItemHovered() && !weapon.second.m_display_desc.empty()) + { + ImGui::BeginTooltip(); + ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35); + ImGui::TextUnformatted(weapon.second.m_display_desc.c_str()); + ImGui::PopTextWrapPos(); + ImGui::EndTooltip(); + } } } if (!found_match) @@ -141,7 +149,7 @@ namespace big selected_attachment = attachment_name; selected_attachment_hash = attachment_hash; } - if (ImGui::IsItemHovered() && attachment_component.m_display_desc != "NULL") + if (ImGui::IsItemHovered() && !attachment_component.m_display_desc.empty()) { ImGui::SetTooltip(attachment_component.m_display_desc.c_str()); }