fix(ContextMenu): Run script function

This commit is contained in:
Yimura 2022-05-22 18:10:51 +02:00
parent 51988fa2e6
commit 5244a4e6b4
4 changed files with 52 additions and 50 deletions

View File

@ -1,48 +0,0 @@
#include "services/context_menu_service.hpp"
#include "backend/looped/looped.hpp"
#include "gta/enums.hpp"
#include "natives.hpp"
namespace big
{
void looped::context_menu()
{
if (PAD::IS_DISABLED_CONTROL_JUST_RELEASED(0, (int)ControllerInputs::INPUT_VEH_DUCK))
{
g_context_menu_service->enabled = !g_context_menu_service->enabled;
}
if (g_context_menu_service->enabled)
{
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_NEXT_WEAPON, true);
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_PREV_WEAPON, true);
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_VEH_NEXT_RADIO, true);
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_VEH_SELECT_NEXT_WEAPON, true);
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_SELECT_NEXT_WEAPON, true);
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_SELECT_PREV_WEAPON, true);
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_WEAPON_WHEEL_NEXT, true);
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_WEAPON_WHEEL_PREV, true);
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_ATTACK, true);
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_SPECIAL_ABILITY, true);
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_VEH_MOUSE_CONTROL_OVERRIDE, true);
g_context_menu_service->get_entity_closest_to_screen_center();
const auto cm = g_context_menu_service->get_context_menu();
if (cm == nullptr)
return;
if (PAD::IS_DISABLED_CONTROL_JUST_PRESSED(0, (int)ControllerInputs::INPUT_WEAPON_WHEEL_NEXT))
cm->current_option = cm->options.size() <= cm->current_option + 1 ? 0 : cm->current_option + 1;
if (PAD::IS_DISABLED_CONTROL_JUST_PRESSED(0, (int)ControllerInputs::INPUT_WEAPON_WHEEL_PREV))
cm->current_option = 0 > cm->current_option - 1 ? static_cast<int>(cm->options.size()) - 1 : cm->current_option - 1;
if (PAD::IS_DISABLED_CONTROL_JUST_PRESSED(0, (int)ControllerInputs::INPUT_ATTACK) ||
PAD::IS_DISABLED_CONTROL_JUST_PRESSED(0, (int)ControllerInputs::INPUT_SPECIAL_ABILITY))
{
if (!g_context_menu_service->m_pointer)
return;
cm->options.at(cm->current_option).command();
}
}
}
}

View File

@ -90,8 +90,7 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
g_script_mgr.add_script(std::make_unique<script>(&backend::lscustoms_loop));
g_script_mgr.add_script(std::make_unique<script>(&backend::vehiclefly_loop));
g_script_mgr.add_script(std::make_unique<script>(&backend::rgbrandomizer_loop));
g_script_mgr.add_script(std::make_unique<script>(&context_menu_service::context_menu));
LOG(INFO) << "Scripts registered.";
auto native_hooks_instance = std::make_unique<native_hooks>();

View File

@ -138,4 +138,53 @@ namespace big
menu.menu_size = { (10.f * static_cast<float>(max_size)) + 10.f , 2 * (10.f * static_cast<float>(menu.options.size())) + 10.f };
}
}
void context_menu_service::context_menu()
{
while (g_running)
{
if (PAD::IS_DISABLED_CONTROL_JUST_RELEASED(0, (int)ControllerInputs::INPUT_VEH_DUCK))
{
g_context_menu_service->enabled = !g_context_menu_service->enabled;
}
if (g_context_menu_service->enabled)
{
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_NEXT_WEAPON, true);
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_PREV_WEAPON, true);
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_VEH_NEXT_RADIO, true);
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_VEH_SELECT_NEXT_WEAPON, true);
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_SELECT_NEXT_WEAPON, true);
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_SELECT_PREV_WEAPON, true);
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_WEAPON_WHEEL_NEXT, true);
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_WEAPON_WHEEL_PREV, true);
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_ATTACK, true);
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_SPECIAL_ABILITY, true);
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_VEH_MOUSE_CONTROL_OVERRIDE, true);
g_context_menu_service->get_entity_closest_to_screen_center();
const auto cm = g_context_menu_service->get_context_menu();
if (cm == nullptr)
{
script::get_current()->yield();
continue;
}
if (PAD::IS_DISABLED_CONTROL_JUST_PRESSED(0, (int)ControllerInputs::INPUT_WEAPON_WHEEL_NEXT))
cm->current_option = cm->options.size() <= cm->current_option + 1 ? 0 : cm->current_option + 1;
if (PAD::IS_DISABLED_CONTROL_JUST_PRESSED(0, (int)ControllerInputs::INPUT_WEAPON_WHEEL_PREV))
cm->current_option = 0 > cm->current_option - 1 ? static_cast<int>(cm->options.size()) - 1 : cm->current_option - 1;
if (PAD::IS_DISABLED_CONTROL_JUST_PRESSED(0, (int)ControllerInputs::INPUT_ATTACK) ||
PAD::IS_DISABLED_CONTROL_JUST_PRESSED(0, (int)ControllerInputs::INPUT_SPECIAL_ABILITY))
{
if (!g_context_menu_service->m_pointer)
return;
cm->options.at(cm->current_option).command();
}
}
script::get_current()->yield();
}
}
}

View File

@ -48,6 +48,8 @@ namespace big
void get_entity_closest_to_screen_center();
void load_shared();
static void context_menu();
Entity m_handle;
rage::fwEntity* m_pointer;