Weapon Hotkeys (#1685)
This commit is contained in:
parent
47891cbcae
commit
098b15eca6
@ -73,6 +73,7 @@ namespace big
|
||||
looped::weapons_vehicle_gun();
|
||||
looped::weapons_c4_limit();
|
||||
looped::weapons_do_persist_weapons();
|
||||
looped::weapons_do_weapon_hotkeys();
|
||||
|
||||
script::get_current()->yield();
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ namespace big
|
||||
static void weapons_vehicle_gun();
|
||||
static void weapons_c4_limit();
|
||||
static void weapons_do_persist_weapons();
|
||||
static void weapons_do_weapon_hotkeys();
|
||||
|
||||
static void drive_train();
|
||||
static void derail_train();
|
||||
|
57
src/backend/looped/weapons/weapon_hotkeys.cpp
Normal file
57
src/backend/looped/weapons/weapon_hotkeys.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include "backend/looped/looped.hpp"
|
||||
#include "natives.hpp"
|
||||
#include "services/gta_data/gta_data_service.hpp"
|
||||
#include "gta/enums.hpp"
|
||||
#include "gui.hpp"
|
||||
|
||||
namespace big
|
||||
{
|
||||
const int input_array[6] = {(int)ControllerInputs::INPUT_SELECT_WEAPON_UNARMED, (int)ControllerInputs::INPUT_SELECT_WEAPON_MELEE, (int)ControllerInputs::INPUT_SELECT_WEAPON_HANDGUN, (int)ControllerInputs::INPUT_SELECT_WEAPON_SHOTGUN, (int)ControllerInputs::INPUT_SELECT_WEAPON_SMG, (int)ControllerInputs::INPUT_SELECT_WEAPON_AUTO_RIFLE};
|
||||
|
||||
static void resolve_weapon_hotkey(Hash weapon)
|
||||
{
|
||||
if (g_gta_data_service->weapon_by_hash(weapon).m_name.empty())
|
||||
{
|
||||
WEAPON::SET_CURRENT_PED_VEHICLE_WEAPON(self::ped, weapon);
|
||||
}
|
||||
else
|
||||
{
|
||||
WEAPON::SET_CURRENT_PED_WEAPON(self::ped, weapon, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
void looped::weapons_do_weapon_hotkeys()
|
||||
{
|
||||
Ped player_ped = self::ped;
|
||||
|
||||
if (!g.weapons.enable_weapon_hotkeys || g_gui->is_open() || HUD::IS_PAUSE_MENU_ACTIVE() || PED::IS_PED_DEAD_OR_DYING(player_ped, true) || STREAMING::IS_PLAYER_SWITCH_IN_PROGRESS() || DLC::GET_IS_LOADING_SCREEN_ACTIVE() || HUD::IS_MP_TEXT_CHAT_TYPING())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Hash current_weapon, current_vehicle_weapon;
|
||||
WEAPON::GET_CURRENT_PED_WEAPON(player_ped, ¤t_weapon, -1);
|
||||
WEAPON::GET_CURRENT_PED_VEHICLE_WEAPON(player_ped, ¤t_vehicle_weapon);
|
||||
for (int iterator_keys = 0; iterator_keys < 6; iterator_keys++)
|
||||
{
|
||||
PAD::DISABLE_CONTROL_ACTION(0, input_array[iterator_keys], TRUE);
|
||||
if (PAD::IS_DISABLED_CONTROL_JUST_PRESSED(0, input_array[iterator_keys]))
|
||||
{
|
||||
auto hotkey_vector = g.weapons.weapon_hotkeys[iterator_keys];
|
||||
Hash weapon_hash_to_select = hotkey_vector[0];
|
||||
for (auto vector_iterator = hotkey_vector.begin(); vector_iterator != hotkey_vector.end(); ++vector_iterator)
|
||||
{
|
||||
Hash iteration_hash = *vector_iterator;
|
||||
if (current_weapon == iteration_hash || current_vehicle_weapon == iteration_hash)
|
||||
{
|
||||
if (vector_iterator != hotkey_vector.end() - 1)
|
||||
{
|
||||
weapon_hash_to_select = *std::next(vector_iterator);
|
||||
}
|
||||
}
|
||||
}
|
||||
resolve_weapon_hotkey(weapon_hash_to_select);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -724,8 +724,10 @@ namespace big
|
||||
bool interior_weapon = false;
|
||||
bool triggerbot = false;
|
||||
bool infinite_range = false;
|
||||
bool enable_weapon_hotkeys = false;
|
||||
std::map<int, std::vector<std::uint32_t>> weapon_hotkeys{};
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(weapons, ammo_special, custom_weapon, aimbot, infinite_ammo, always_full_ammo, infinite_mag, increased_damage, increase_damage, no_recoil, no_spread, vehicle_gun_model, increased_c4_limit, increased_flare_limit, rapid_fire, gravity_gun, interior_weapon, triggerbot, infinite_range)
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(weapons, ammo_special, custom_weapon, aimbot, infinite_ammo, always_full_ammo, infinite_mag, increased_damage, increase_damage, no_recoil, no_spread, vehicle_gun_model, increased_c4_limit, increased_flare_limit, rapid_fire, gravity_gun, interior_weapon, triggerbot, infinite_range, enable_weapon_hotkeys, weapon_hotkeys)
|
||||
} weapons{};
|
||||
|
||||
struct window
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "services/gta_data/gta_data_service.hpp"
|
||||
#include "views/view.hpp"
|
||||
#include "services/persist_weapons/persist_weapons.hpp"
|
||||
#include "gta/weapons.hpp"
|
||||
|
||||
namespace big
|
||||
{
|
||||
@ -196,7 +197,9 @@ namespace big
|
||||
selected_weapon_attachment.clear();
|
||||
}
|
||||
if (is_selected)
|
||||
{
|
||||
ImGui::SetItemDefaultFocus();
|
||||
}
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
@ -234,7 +237,9 @@ namespace big
|
||||
selected_weapon_attachment_hash = attachment_hash;
|
||||
}
|
||||
if (is_selected)
|
||||
{
|
||||
ImGui::SetItemDefaultFocus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -304,5 +309,72 @@ namespace big
|
||||
ImGui::EndGroup();
|
||||
ImGui::PopItemWidth();
|
||||
}
|
||||
if (ImGui::CollapsingHeader("Weapon Hotkeys"))
|
||||
{
|
||||
ImGui::Checkbox("Enabled", &g.weapons.enable_weapon_hotkeys);
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::SetTooltip("This will select the next weapon in the hotkey list.\r\nThe first weapon in the list is the first weapon it will select, then the second is the one it will select after and so on.\r\nAfter the end of the list, it will wrap back to the first weapon.");
|
||||
}
|
||||
|
||||
static int selected_key = 0;
|
||||
const char* const keys[]{ "1", "2", "3", "4", "5", "6" };
|
||||
|
||||
ImGui::PushItemWidth(250);
|
||||
ImGui::Combo("Key", &selected_key, keys, IM_ARRAYSIZE(keys));
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
if (!g.weapons.weapon_hotkeys[selected_key].empty())
|
||||
{
|
||||
int counter{};
|
||||
for (auto& weapon_hash : g.weapons.weapon_hotkeys[selected_key])
|
||||
{
|
||||
ImGui::PushID(counter);
|
||||
auto weapon = g_gta_data_service->weapon_by_hash(weapon_hash);
|
||||
ImGui::PushItemWidth(300);
|
||||
if (ImGui::BeginCombo("Weapons", weapon.m_display_name.c_str()))
|
||||
{
|
||||
for (auto& weapon : g_gta_data_service->weapons())
|
||||
{
|
||||
if (weapon.second.m_display_name == "NULL")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
bool is_selected = weapon.second.m_hash == weapon_hash;
|
||||
if (ImGui::Selectable(weapon.second.m_display_name.c_str(), is_selected, ImGuiSelectableFlags_None))
|
||||
{
|
||||
weapon_hash = weapon.second.m_hash;
|
||||
}
|
||||
if (is_selected)
|
||||
{
|
||||
ImGui::SetItemDefaultFocus();
|
||||
}
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
components::button("Set To Current Weapon", [&weapon_hash] {
|
||||
WEAPON::GET_CURRENT_PED_WEAPON(self::ped, &weapon_hash, NULL);
|
||||
if (weapon_hash == NULL)
|
||||
{
|
||||
WEAPON::GET_CURRENT_PED_VEHICLE_WEAPON(self::ped, &weapon_hash);
|
||||
}
|
||||
});
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Remove Weapon"))
|
||||
{
|
||||
g.weapons.weapon_hotkeys[selected_key].erase(g.weapons.weapon_hotkeys[selected_key].begin() + counter);
|
||||
}
|
||||
ImGui::PopID();
|
||||
ImGui::PopItemWidth();
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::Button("Add Weapon"))
|
||||
{
|
||||
g.weapons.weapon_hotkeys[selected_key].push_back(WEAPON_UNARMED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,9 +12,10 @@ namespace big
|
||||
auto ped_count = g_gta_data_service->peds().size();
|
||||
auto veh_count = g_gta_data_service->vehicles().size();
|
||||
auto wep_count = g_gta_data_service->weapons().size();
|
||||
auto wep_comp_count = g_gta_data_service->weapon_components().size();
|
||||
|
||||
components::sub_title("GTA cache stats:");
|
||||
ImGui::Text("Peds Cached: %d\nVehicles Cached: %d\nWeapons Cached: %d", ped_count, veh_count, wep_count);
|
||||
ImGui::Text("Peds Cached: %d\nVehicles Cached: %d\nWeapons Cached: %d\nWeapon Components Cached: %d", ped_count, veh_count, wep_count, wep_comp_count);
|
||||
|
||||
if (components::button("Rebuild Cache"))
|
||||
{
|
||||
|
Reference in New Issue
Block a user