2022-11-27 01:29:14 +08:00
|
|
|
#include "hotkey_service.hpp"
|
2023-03-26 13:45:46 -04:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
#include "fiber_pool.hpp"
|
|
|
|
#include "gui.hpp"
|
2022-11-29 20:48:58 +01:00
|
|
|
#include "network/ChatData.hpp"
|
|
|
|
#include "pointers.hpp"
|
2023-03-01 21:27:15 +00:00
|
|
|
#include "renderer.hpp"
|
|
|
|
#include "util/teleport.hpp"
|
2022-11-29 20:48:58 +01:00
|
|
|
|
2022-11-27 01:29:14 +08:00
|
|
|
namespace big
|
|
|
|
{
|
2023-03-01 21:27:15 +00:00
|
|
|
hotkey_service::hotkey_service()
|
|
|
|
{
|
2023-04-15 22:34:39 +02:00
|
|
|
// ordered alphabetically to more easily see if a certain hotkey is present
|
|
|
|
register_hotkey("beastjump", g.settings.hotkeys.beastjump, RAGE_JOAAT("beastjump"));
|
2023-03-01 21:27:15 +00:00
|
|
|
register_hotkey("bringpv", g.settings.hotkeys.bringvehicle, RAGE_JOAAT("bringpv"));
|
2023-04-17 20:24:41 +02:00
|
|
|
register_hotkey("cmdexecutor", g.settings.hotkeys.cmd_excecutor, RAGE_JOAAT("cmdexecutor"));
|
2023-04-16 18:28:49 +00:00
|
|
|
register_hotkey("fastrun", g.settings.hotkeys.superrun, RAGE_JOAAT("fastrun"));
|
2023-04-15 22:34:39 +02:00
|
|
|
register_hotkey("fastquit", g.settings.hotkeys.fast_quit, RAGE_JOAAT("fastquit"));
|
|
|
|
register_hotkey("fillammo", g.settings.hotkeys.fill_ammo, RAGE_JOAAT("fillammo"));
|
2023-03-01 21:27:15 +00:00
|
|
|
register_hotkey("fillsnacks", g.settings.hotkeys.fill_inventory, RAGE_JOAAT("fillsnacks"));
|
2023-04-16 18:28:49 +00:00
|
|
|
register_hotkey("freecam", g.settings.hotkeys.freecam, RAGE_JOAAT("freecam"));
|
2023-04-15 22:34:39 +02:00
|
|
|
register_hotkey("heal", g.settings.hotkeys.heal, RAGE_JOAAT("heal"));
|
|
|
|
register_hotkey("invis", g.settings.hotkeys.invis, RAGE_JOAAT("invis"));
|
2023-03-01 21:27:15 +00:00
|
|
|
register_hotkey("invisveh", g.settings.hotkeys.invisveh, RAGE_JOAAT("invisveh"));
|
|
|
|
register_hotkey("localinvisveh", g.settings.hotkeys.localinvisveh, RAGE_JOAAT("localinvisveh"));
|
2023-04-15 22:34:39 +02:00
|
|
|
register_hotkey("noclip", g.settings.hotkeys.noclip, RAGE_JOAAT("noclip"));
|
|
|
|
register_hotkey("objective", g.settings.hotkeys.teleport_objective, RAGE_JOAAT("objectivetp"));
|
2023-03-26 13:45:46 -04:00
|
|
|
register_hotkey("repairpv", g.settings.hotkeys.repairpv, RAGE_JOAAT("repairpv"));
|
2023-04-15 22:34:39 +02:00
|
|
|
register_hotkey("skipcutscene", g.settings.hotkeys.skip_cutscene, RAGE_JOAAT("skipcutscene"));
|
|
|
|
register_hotkey("superjump", g.settings.hotkeys.superjump, RAGE_JOAAT("superjump"));
|
2023-04-05 19:54:29 +02:00
|
|
|
register_hotkey("vehiclecontroller", g.settings.hotkeys.open_vehicle_controller, RAGE_JOAAT("vehiclecontrol"));
|
2023-04-15 22:34:39 +02:00
|
|
|
register_hotkey("waypoint", g.settings.hotkeys.teleport_waypoint, RAGE_JOAAT("waypointtp"));
|
2023-06-27 14:05:44 +02:00
|
|
|
register_hotkey("clearwantedlvl", g.settings.hotkeys.clear_wanted, RAGE_JOAAT("clearwantedlvl"));
|
2023-03-11 00:06:09 +01:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
g_renderer->add_wndproc_callback([this](HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
|
|
|
wndproc(static_cast<eKeyState>(msg), wparam);
|
|
|
|
});
|
2022-12-16 18:55:55 +01:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
g_hotkey_service = this;
|
|
|
|
}
|
2022-11-27 01:29:14 +08:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
hotkey_service::~hotkey_service()
|
|
|
|
{
|
|
|
|
g_hotkey_service = nullptr;
|
|
|
|
}
|
2022-11-27 01:29:14 +08:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
void hotkey_service::register_hotkey(const std::string_view name, key_t key, rage::joaat_t command_hash, eKeyState state, std::optional<std::chrono::high_resolution_clock::duration> cooldown)
|
|
|
|
{
|
|
|
|
m_hotkeys[state == eKeyState::RELEASE].emplace(key, hotkey(rage::joaat(name), key, command_hash, cooldown));
|
|
|
|
}
|
2022-11-27 01:29:14 +08:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
bool hotkey_service::update_hotkey(const std::string_view name, const key_t key)
|
|
|
|
{
|
|
|
|
static auto update_hotkey_map = [](hotkey_map& hotkey_map, rage::joaat_t name_hash, key_t new_key) -> bool {
|
|
|
|
for (auto it = hotkey_map.begin(); it != hotkey_map.end(); ++it)
|
|
|
|
{
|
|
|
|
auto hotkey = it->second;
|
|
|
|
if (hotkey.name_hash() != name_hash)
|
|
|
|
continue;
|
2022-11-27 01:29:14 +08:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
hotkey_map.erase(it);
|
|
|
|
hotkey.set_key(new_key);
|
|
|
|
hotkey_map.emplace(new_key, hotkey);
|
2022-11-27 01:29:14 +08:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
2022-11-27 01:29:14 +08:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
const auto name_hash = rage::joaat(name);
|
2023-03-11 00:06:09 +01:00
|
|
|
return update_hotkey_map(m_hotkeys[1], name_hash, key) // released
|
|
|
|
&& update_hotkey_map(m_hotkeys[0], name_hash, key); // down
|
2023-03-01 21:27:15 +00:00
|
|
|
}
|
2022-11-27 01:29:14 +08:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
void hotkey_service::wndproc(eKeyState state, key_t key)
|
|
|
|
{
|
2023-04-14 18:54:07 +02:00
|
|
|
if (const auto chat_data = *g_pointers->m_gta.m_chat_data; chat_data && (chat_data->m_chat_open || chat_data->m_timer_two))
|
2023-03-01 21:27:15 +00:00
|
|
|
return;
|
2022-11-29 20:48:58 +01:00
|
|
|
|
2023-03-11 00:06:09 +01:00
|
|
|
//command executer is opened
|
|
|
|
if (g.cmd_executor.enabled)
|
|
|
|
return;
|
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
if (g_gui->is_open())
|
|
|
|
return;
|
2023-01-22 21:57:32 +00:00
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
if (state == eKeyState::RELEASE || state == eKeyState::DOWN)
|
|
|
|
{
|
|
|
|
auto& hotkey_map = m_hotkeys[state == eKeyState::RELEASE];
|
|
|
|
if (const auto& it = hotkey_map.find(key); it != hotkey_map.end())
|
|
|
|
{
|
|
|
|
if (auto& hotkey = it->second; hotkey.can_exec())
|
|
|
|
{
|
|
|
|
g_fiber_pool->queue_job([&hotkey] {
|
|
|
|
hotkey.exec();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-27 01:29:14 +08:00
|
|
|
}
|