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 f10c698396
commit 6f40a38045
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);
});
}
}