Refactored weapons.bin into weapons.json for extensibility and readability. (#1632)

* Refactored weapons.bin into weapons.json for extensibility and human readability.
Added weapon attachments scraping from the meta files (currently is missing a lot of attachments, more than half, requires RPF reading refactoring to fix.)
Added Ammunation to Self -> Weapons, because it's vital you protect yourself, the patriotic way.

* Fixed weapons.xml not properly populating all the components.
Refactored buttons to use components::button.

* Refactored the Attachments code to implicitly trust that the attachments will be there now.
Added proper versioning to the weapons.json file.
Removed debug logging from gta_data_service.cpp.

* Fixed Ammunation buttons.
Added loading message for the new weapons.json system.
Fixed a bug where two components shared the same name, the user could not select the 2nd component.
Fixed Attachments displaying an attachment from a previous weapon if the user changed weapons.

* Fixed Tint Apply button not using the components::button template.
This commit is contained in:
gir489
2023-07-07 18:52:52 -04:00
committed by GitHub
parent b6fae097aa
commit b8922a9dba
9 changed files with 283 additions and 51 deletions

View File

@ -176,5 +176,93 @@ namespace big
ImGui::SliderFloat("Distance", &g.weapons.aimbot.distance, 1.f, 1000.f, "%.0f");
ImGui::PopItemWidth();
}
ImGui::SeparatorText("Ammunation");
static Hash selected_weapon_hash, selected_weapon_attachment_hash{};
static std::string selected_weapon, selected_weapon_attachment;
ImGui::PushItemWidth(300);
if (ImGui::BeginCombo("Weapons", selected_weapon.c_str()))
{
for (auto& weapon : g_gta_data_service->weapons())
{
bool is_selected = weapon.second.m_hash == selected_weapon_hash;
if (weapon.second.m_display_name != "NULL" && ImGui::Selectable(weapon.second.m_display_name.c_str(), is_selected, ImGuiSelectableFlags_None))
{
selected_weapon = weapon.second.m_display_name;
selected_weapon_hash = weapon.second.m_hash;
selected_weapon_attachment_hash = {};
selected_weapon_attachment.clear();
}
if (is_selected)
ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}
ImGui::PopItemWidth();
ImGui::SameLine();
components::button("Give Weapon", [] {
WEAPON::GIVE_WEAPON_TO_PED(self::ped, selected_weapon_hash, 9999, false, true);
});
ImGui::SameLine();
components::button("Remove Weapon", [] {
WEAPON::REMOVE_WEAPON_FROM_PED(self::ped, selected_weapon_hash);
});
ImGui::PushItemWidth(250);
if (ImGui::BeginCombo("Attachments", selected_weapon_attachment.c_str()))
{
auto weapon = g_gta_data_service->weapon_by_hash(selected_weapon_hash);
if (!weapon.m_attachments.empty())
{
for (std::string attachment : weapon.m_attachments)
{
auto attachment_component = g_gta_data_service->weapon_component_by_name(attachment);
std::string attachment_name = attachment_component.m_display_name;
Hash attachment_hash = attachment_component.m_hash;
if (attachment_hash == NULL)
{
attachment_name = attachment;
attachment_hash = rage::joaat(attachment);
}
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))
{
selected_weapon_attachment = attachment_name;
selected_weapon_attachment_hash = attachment_hash;
}
if (is_selected)
ImGui::SetItemDefaultFocus();
}
}
ImGui::EndCombo();
}
ImGui::SameLine();
components::button("Add to Weapon", [] {
WEAPON::GIVE_WEAPON_COMPONENT_TO_PED(self::ped, selected_weapon_hash, selected_weapon_attachment_hash);
});
ImGui::SameLine();
components::button("Remove from Weapon", [] {
WEAPON::REMOVE_WEAPON_COMPONENT_FROM_PED(self::ped, selected_weapon_hash, selected_weapon_attachment_hash);
});
ImGui::PopItemWidth();
static const char* default_tints[]{"Black tint", "Green tint", "Gold tint", "Pink tint", "Army tint", "LSPD tint", "Orange tint", "Platinum tint"};
static const char* mk2_tints[]{"Classic Black", "Classic Grey", "Classic Two - Tone", "Classic White", "Classic Beige", "Classic Green", "Classic Blue", "Classic Earth", "Classic Brown & Black", "Red Contrast", "Blue Contrast", "Yellow Contrast", "Orange Contrast", "Bold Pink", "Bold Purple & Yellow", "Bold Orange", "Bold Green & Purple", "Bold Red Features", "Bold Green Features", "Bold Cyan Features", "Bold Yellow Features", "Bold Red & White", "Bold Blue & White", "Metallic Gold", "Metallic Platinum", "Metallic Grey & Lilac", "Metallic Purple & Lime", "Metallic Red", "Metallic Green", "Metallic Blue", "Metallic White & Aqua", "Metallic Red & Yellow"};
static int tint;
if (selected_weapon.ends_with("Mk II"))
{
ImGui::Combo("Tints", &tint, mk2_tints, IM_ARRAYSIZE(mk2_tints));
}
else
{
ImGui::Combo("Tints", &tint, default_tints, IM_ARRAYSIZE(default_tints));
}
ImGui::SameLine();
components::button("Apply", [] {
WEAPON::SET_PED_WEAPON_TINT_INDEX(self::ped, selected_weapon_hash, tint);
});
}
}

View File

@ -491,7 +491,7 @@ namespace big
if (ImGui::BeginCombo("##ped_weapon",
selected_ped_weapon_type == SPAWN_PED_NO_WEAPONS ? "NO_WEAPONS"_T.data() :
selected_ped_weapon_hash == 0 ? "ALL"_T.data() :
g_gta_data_service->weapon_by_hash(selected_ped_weapon_hash).m_display_name))
g_gta_data_service->weapon_by_hash(selected_ped_weapon_hash).m_display_name.c_str()))
{
if (selected_ped_weapon_type != SPAWN_PED_NO_WEAPONS)
{
@ -509,7 +509,7 @@ namespace big
{
if (selected_ped_weapon_type == SPAWN_PED_ALL_WEAPONS || weapon.m_weapon_type == weapon_type_arr[selected_ped_weapon_type])
{
if (ImGui::Selectable(weapon.m_display_name, weapon.m_hash == selected_ped_weapon_hash))
if (ImGui::Selectable(weapon.m_display_name.c_str(), weapon.m_hash == selected_ped_weapon_hash))
{
selected_ped_weapon_hash = weapon.m_hash;
}

View File

@ -186,7 +186,7 @@ namespace big
std::string filter = new_template.m_weapon_model;
std::transform(p_model.begin(), p_model.end(), p_model.begin(), ::tolower);
std::transform(filter.begin(), filter.end(), filter.begin(), ::tolower);
if (p_model.find(filter) != std::string::npos && ImGui::Selectable(p.m_name))
if (p_model.find(filter) != std::string::npos && ImGui::Selectable(p.m_name.c_str()))
{
new_template.m_weapon_model = p.m_name;
}