refactor!: Modify command argument handling and move on_ method to bool_command (#1826)

This commit is contained in:
Andreas Maerten 2023-07-26 22:22:40 +02:00 committed by GitHub
parent d590313e4e
commit 4b1fd88f6c
104 changed files with 562 additions and 381 deletions

View File

@ -19,7 +19,7 @@ namespace big
{
void backend::loop()
{
for (auto& command : g_looped_commands)
for (auto& command : g_bool_commands)
command->refresh();
register_script_patches();

View File

@ -1,4 +1,5 @@
#include "bool_command.hpp"
#include "fiber_pool.hpp"
#include "services/translation_service/translation_service.hpp"
namespace big
@ -8,9 +9,10 @@ namespace big
m_toggle(toggle),
m_show_notify(show_notify)
{
g_bool_commands.push_back(this);
}
void bool_command::execute(const std::vector<uint64_t>& args, const std::shared_ptr<command_context> ctx)
void bool_command::execute(const command_arguments& args, const std::shared_ptr<command_context> ctx)
{
if (args.size() == 0)
{
@ -31,15 +33,15 @@ namespace big
}
else
{
m_toggle = args[0];
m_toggle = args.get<bool>(0);
}
this->refresh();
}
std::optional<std::vector<uint64_t>> bool_command::parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx)
std::optional<command_arguments> bool_command::parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx)
{
std::vector<uint64_t> result;
command_arguments result(1);
if (args.size() == 0)
return result;
@ -52,17 +54,59 @@ namespace big
if (args[0] == "yes" || args[0] == "on" || args[0] == "enable" || args[0] == "true")
{
result.push_back(1);
result.push(true);
return result;
}
if (args[0] == "no" || args[0] == "off" || args[0] == "disable" || args[0] == "false")
{
result.push_back(0);
result.push(false);
return result;
}
ctx->report_error(std::format("Cannot convert\"{}\" into a boolean in command {}", args[0], m_name));
return std::nullopt;
}
void bool_command::enable()
{
if (!m_toggle)
{
m_toggle = true;
m_last_enabled = true;
g_fiber_pool->queue_job([this] {
on_enable();
});
}
}
void bool_command::disable()
{
if (m_toggle)
{
m_toggle = false;
m_last_enabled = false;
g_fiber_pool->queue_job([this] {
on_disable();
});
}
}
void bool_command::refresh()
{
if (m_toggle && !m_last_enabled)
{
m_last_enabled = true;
g_fiber_pool->queue_job([this] {
on_enable();
});
}
else if (!m_toggle && m_last_enabled)
{
m_last_enabled = false;
g_fiber_pool->queue_job([this] {
on_disable();
});
}
}
}

View File

@ -5,11 +5,13 @@ namespace big
{
class bool_command : public command
{
bool m_last_enabled = false;
protected:
bool& m_toggle;
bool m_show_notify;
virtual void execute(const std::vector<uint64_t>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
virtual std::optional<std::vector<uint64_t>> parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
virtual void execute(const command_arguments& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
virtual std::optional<command_arguments> parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
public:
bool_command(const std::string& name, const std::string& label, const std::string& description, bool& toggle, bool show_notify = true);
@ -18,14 +20,13 @@ namespace big
return m_toggle;
}
virtual void refresh(){};
virtual void enable()
{
m_toggle = true;
};
virtual void disable()
{
m_toggle = false;
};
virtual void on_enable(){};
virtual void on_disable(){};
virtual void refresh();
virtual void enable();
virtual void disable();
};
inline std::vector<bool_command*> g_bool_commands;
}

View File

@ -51,7 +51,7 @@ namespace big
}
}
void command::call(const std::vector<uint64_t>& args, const std::shared_ptr<command_context> ctx)
void command::call(command_arguments& args, const std::shared_ptr<command_context> ctx)
{
if (m_num_args.has_value() && args.size() != m_num_args.value())
{
@ -68,6 +68,7 @@ namespace big
return;
}
args.reset_idx();
if (m_fiber_pool)
g_fiber_pool->queue_job([this, args, ctx] {
execute(args, ctx);
@ -103,7 +104,7 @@ namespace big
return g_commands[command];
}
void command::call(rage::joaat_t command, const std::vector<uint64_t>& args, const std::shared_ptr<command_context> ctx)
void command::call(rage::joaat_t command, command_arguments& args, const std::shared_ptr<command_context> ctx)
{
g_commands[command]->call(args, ctx);
}

View File

@ -1,4 +1,5 @@
#pragma once
#include "command_arguments.hpp"
#include "context/command_context.hpp"
#include "context/default_command_context.hpp"
#include "core/enums.hpp"
@ -17,10 +18,10 @@ namespace big
std::optional<uint8_t> m_num_args;
bool m_fiber_pool;
virtual void execute(const std::vector<uint64_t>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) = 0;
virtual std::optional<std::vector<uint64_t>> parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>())
virtual void execute(const command_arguments& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) = 0;
virtual std::optional<command_arguments> parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>())
{
return std::vector<uint64_t>();
return {0};
};
virtual CommandAccessLevel get_access_level()
{
@ -54,13 +55,13 @@ namespace big
return m_num_args;
}
void call(const std::vector<uint64_t>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>());
void call(command_arguments& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>());
void call(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>());
static std::vector<command*> get_suggestions(std::string, int limit = 7);
static command* get(rage::joaat_t command);
static void call(rage::joaat_t command, const std::vector<uint64_t>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>());
static void call(rage::joaat_t command, command_arguments& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>());
static void call(rage::joaat_t command, const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>());
static bool process(const std::string& text, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>(), bool use_best_suggestion = false);

View File

@ -0,0 +1,114 @@
#pragma once
#include <concepts>
#include <stdexcept>
#include <type_traits>
namespace big
{
template<typename T>
concept ArgumentLimit = sizeof(T) <= sizeof(uint64_t);
class command_arguments
{
private:
const std::size_t m_argument_count;
std::vector<uint64_t> m_argument_data;
mutable std::size_t m_idx;
public:
command_arguments(std::size_t argument_count = 0) :
m_argument_count(argument_count),
m_argument_data(),
m_idx(0)
{
m_argument_data.reserve(argument_count);
}
command_arguments(std::size_t argument_count, const command_arguments& other) :
command_arguments(argument_count)
{
std::copy_n(other.m_argument_data.begin(), std::min(argument_count, other.m_argument_data.size()), m_argument_data.begin());
}
command_arguments(const std::vector<uint64_t>& vec) :
command_arguments(vec.size())
{
m_argument_data = vec;
}
template<typename T = uint64_t>
requires ArgumentLimit<T>
T get(std::size_t idx) const
{
return reinterpret_cast<const T&>(m_argument_data[idx]);
}
template<typename T = uint64_t>
requires ArgumentLimit<T>
std::enable_if_t<std::is_pointer_v<T>, T> get(std::size_t idx) const
{
return static_cast<T>(m_argument_data[idx]);
}
template<typename T = uint64_t>
requires ArgumentLimit<T>
T shift() const
{
if (m_idx >= m_argument_count)
{
throw std::runtime_error("Attempted to shift argument beyond allocated argument size.");
}
return reinterpret_cast<const T&>(m_argument_data[m_idx++]);
}
template<typename T = uint64_t>
requires ArgumentLimit<T>
std::enable_if_t<std::is_pointer_v<T>, T> shift() const
{
if (m_idx >= m_argument_count)
{
throw std::runtime_error("Attempted to shift argument beyond allocated argument size.");
}
return static_cast<const T>(m_argument_data[m_idx++]);
}
template<typename T = uint64_t>
requires ArgumentLimit<T>
void push(T arg)
{
if (m_idx++ >= m_argument_count)
{
throw std::runtime_error("Attempted to push argument beyond allocated argument size.");
}
m_argument_data.push_back(reinterpret_cast<uint64_t&>(arg));
}
template<typename T = uint64_t>
requires ArgumentLimit<T>
void set(std::size_t idx, T arg)
{
if (idx >= m_argument_count)
{
throw std::runtime_error("Attempted to set argument beyond allocated argument size.");
}
m_argument_data[idx] = reinterpret_cast<uint64_t&>(arg);
}
command_arguments& reset_idx()
{
m_idx = 0;
return *this;
}
std::size_t size() const
{
return m_argument_data.size();
}
};
}

View File

@ -12,7 +12,7 @@ namespace big
return CommandAccessLevel::NONE;
}
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
ctx->report_error("Money and recovery options are not supported in YimMenu to keep Rockstar/Take Two happy. You can try Kiddion's Modest Menu (free) instead, but make sure to only get it from UnknownCheats.me, the rest are scams and may contain malware");
}

View File

@ -16,7 +16,7 @@ namespace big
return CommandAccessLevel::TOXIC;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
const size_t arg_count = 3;
int64_t args[arg_count] = {(int64_t)eRemoteEvent::NetworkBail,

View File

@ -18,7 +18,7 @@ namespace big
return CommandAccessLevel::TOXIC;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
if (!g_player_service->get_self()->is_host() || !player->get_net_data())
return;

View File

@ -17,7 +17,7 @@ namespace big
return CommandAccessLevel::TOXIC;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
if (gta_util::get_network()->m_game_session_ptr->is_host())
{

View File

@ -15,7 +15,7 @@ namespace big
return CommandAccessLevel::TOXIC;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
if (!scripts::force_host(RAGE_JOAAT("freemode")))
{

View File

@ -12,7 +12,7 @@ namespace big
return CommandAccessLevel::TOXIC;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
if (!g_player_service->get_self()->is_host())
{

View File

@ -14,7 +14,7 @@ namespace big
return CommandAccessLevel::TOXIC;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
const size_t arg_count = 15;
int64_t args[arg_count] = {(int64_t)eRemoteEvent::InteriorControl, (int64_t)self::id, (int64_t)(int)-1};

View File

@ -18,7 +18,7 @@ namespace big
return CommandAccessLevel::TOXIC;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
packet msg{};

View File

@ -15,7 +15,7 @@ namespace big
return CommandAccessLevel::TOXIC;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
if (!scripts::force_host(RAGE_JOAAT("freemode")))
{

View File

@ -14,7 +14,7 @@ namespace big
return CommandAccessLevel::FRIENDLY;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
globals::clear_wanted_player(player->id());
}

View File

@ -13,7 +13,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
int id = player->id();
if (scr_globals::gpbd_fm_1.as<GPBD_FM*>()->Entries[id].PropertyData.Index != -1)

View File

@ -15,7 +15,7 @@ namespace big
return CommandAccessLevel::FRIENDLY;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
g_pickup_service->give_player_health(player->id());
}

View File

@ -15,7 +15,7 @@ namespace big
return CommandAccessLevel::FRIENDLY;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
g_pickup_service->give_armour(player->id());
}

View File

@ -15,7 +15,7 @@ namespace big
return CommandAccessLevel::FRIENDLY;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
g_pickup_service->give_player_health(player->id());
}

View File

@ -10,7 +10,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
scr_functions::join_ceo({player->id(), 0, false, false});
}

View File

@ -9,7 +9,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
ped::steal_identity(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id()));
}

View File

@ -9,7 +9,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
ped::steal_outfit(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id()));
}

View File

@ -16,7 +16,7 @@ namespace big
return CommandAccessLevel::AGGRESSIVE;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
auto leader = scr_globals::gpbd_fm_3.as<GPBD_FM_3*>()->Entries[player->id()].BossGoon.Boss;

View File

@ -14,7 +14,7 @@ namespace big
return CommandAccessLevel::AGGRESSIVE;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
toxic::blame_explode_player(player, player, EXP_TAG_SUBMARINE_BIG, 9999.0f, true, false, 9999.0f);
}

View File

@ -14,7 +14,7 @@ namespace big
return CommandAccessLevel::AGGRESSIVE;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
const size_t arg_count = 3;
int64_t args[arg_count] = {(int64_t)eRemoteEvent::ForceMission, (int64_t)self::id, 0};

View File

@ -15,7 +15,7 @@ namespace big
return CommandAccessLevel::FRIENDLY;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
for (auto& weapon : g_gta_data_service->weapons())
WEAPON::GIVE_WEAPON_TO_PED(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id()), weapon.second.m_hash, 9999, FALSE, FALSE);
@ -31,7 +31,7 @@ namespace big
return CommandAccessLevel::FRIENDLY;
}
virtual void execute(const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
g_player_service->iterate([](auto& plyr) {
for (auto& weapon : g_gta_data_service->weapons())

View File

@ -23,7 +23,7 @@ namespace big
return CommandAccessLevel::AGGRESSIVE;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
if (scr_globals::gpbd_fm_1.as<GPBD_FM*>()->Entries[player->id()].PropertyData.Index != -1)
{

View File

@ -14,7 +14,7 @@ namespace big
return CommandAccessLevel::AGGRESSIVE;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
auto vehicle = player->get_current_vehicle();

View File

@ -13,7 +13,7 @@ namespace big
return CommandAccessLevel::AGGRESSIVE;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
if (!player->get_ped())
return;

View File

@ -13,7 +13,7 @@ namespace big
return CommandAccessLevel::AGGRESSIVE;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
if (auto ped = player->get_ped())
if (auto net_object = ped->m_net_object)

View File

@ -14,7 +14,7 @@ namespace big
return CommandAccessLevel::AGGRESSIVE;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
for (auto& [_, weapon] : g_gta_data_service->weapons())
WEAPON::REMOVE_WEAPON_FROM_PED(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id()), weapon.m_hash);

View File

@ -16,7 +16,7 @@ namespace big
return CommandAccessLevel::AGGRESSIVE;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
const size_t arg_count = 8;
int64_t args[arg_count] = {(int64_t)eRemoteEvent::SendTextLabelSMS, self::id};

View File

@ -20,7 +20,7 @@ namespace big
return CommandAccessLevel::AGGRESSIVE;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
const size_t arg_count = 8;
int64_t args[arg_count] = {(int64_t)eRemoteEvent::SendTextLabelSMS, self::id};

View File

@ -9,20 +9,15 @@ namespace big
{
using player_command::player_command;
virtual std::optional<std::vector<uint64_t>> parse_args_p(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx)
{
return std::vector<uint64_t>{(uint64_t)std::atoi(args[0].c_str())};
}
virtual CommandAccessLevel get_access_level()
{
return CommandAccessLevel::AGGRESSIVE;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
const size_t arg_count = 9;
int64_t args[arg_count] = {(int64_t)eRemoteEvent::Teleport, self::id, (int64_t)player->id(), (int64_t)(int)-1, 1, (int64_t)_args[0], 1, 1, 1};
int64_t args[arg_count] = {(int64_t)eRemoteEvent::Teleport, self::id, (int64_t)player->id(), (int64_t)(int)-1, 1, (int64_t)_args.get<int64_t>(0), 1, 1, 1};
g_pointers->m_gta.m_trigger_script_event(1, args, arg_count, 1 << player->id());
}

View File

@ -8,24 +8,19 @@ namespace big
{
using player_command::player_command;
virtual std::optional<std::vector<uint64_t>> parse_args_p(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx)
{
return std::vector<uint64_t>{(uint64_t)std::atoi(args[0].c_str())};
}
virtual CommandAccessLevel get_access_level()
{
return CommandAccessLevel::AGGRESSIVE;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
float max = 1e+38f;
auto coords = ENTITY::GET_ENTITY_COORDS(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id()), FALSE);
const size_t arg_count = 15;
int64_t args[arg_count] = {(int64_t)eRemoteEvent::InteriorControl,
(int64_t)self::id,
(int64_t)(int)_args[0],
(int64_t)_args.get<int>(0),
(int64_t)self::id,
(int64_t) false,
(int64_t) true, // true means enter sender interior

View File

@ -9,20 +9,15 @@ namespace big
{
using player_command::player_command;
virtual std::optional<std::vector<uint64_t>> parse_args_p(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx)
{
return std::vector<uint64_t>{(uint64_t)std::atoi(args[0].c_str())};
}
virtual CommandAccessLevel get_access_level()
{
return CommandAccessLevel::AGGRESSIVE;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
const size_t arg_count = 6;
int64_t args[arg_count] = {(int64_t)eRemoteEvent::TeleportToWarehouse, self::id, (int64_t)player->id(), 1, (int64_t)_args[0]};
int64_t args[arg_count] = {(int64_t)eRemoteEvent::TeleportToWarehouse, self::id, (int64_t)player->id(), 1, (int64_t)_args.get<int>(0)};
g_pointers->m_gta.m_trigger_script_event(1, args, arg_count, 1 << player->id());
}

View File

@ -13,17 +13,19 @@ namespace big
{
using player_command::player_command;
virtual std::optional<std::vector<uint64_t>> parse_args_p(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx)
virtual std::optional<command_arguments> parse_args_p(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx)
{
uint64_t level = std::atoi(args[0].c_str());
const auto level = std::atoi(args[0].c_str());
if (level < 0 || level > 5)
{
ctx->report_error(std::format("Wanted level {} is invalid", level));
ctx->report_error(std::format("Wanted level {} is invalid [0 - 5]", level));
return std::nullopt;
}
return std::vector<uint64_t>{level};
command_arguments result(1);
result.push(level);
return result;
}
virtual CommandAccessLevel get_access_level()
@ -31,33 +33,34 @@ namespace big
return CommandAccessLevel::AGGRESSIVE;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
const auto wanted_level = _args.get<int>(0);
if (player->id() == self::id)
{
PLAYER::SET_PLAYER_WANTED_LEVEL(self::id, _args[0], FALSE);
PLAYER::SET_PLAYER_WANTED_LEVEL(self::id, wanted_level, FALSE);
}
else
{
int id = player->id();
if (PLAYER::GET_PLAYER_WANTED_LEVEL(id) > _args[0])
if (PLAYER::GET_PLAYER_WANTED_LEVEL(id) > wanted_level)
{
// clear existing wanted
globals::clear_wanted_player(id);
for (int i = 0; PLAYER::GET_PLAYER_WANTED_LEVEL(id) > _args[0] && i < 3600; i++)
for (int i = 0; PLAYER::GET_PLAYER_WANTED_LEVEL(id) > wanted_level && i < 3600; i++)
script::get_current()->yield(1ms);
}
if (_args[0] > 0)
if (wanted_level > 0)
{
auto& gpbd = scr_globals::globalplayer_bd.as<GlobalPlayerBD*>()->Entries[self::id];
gpbd.RemoteWantedLevelPlayer = id;
gpbd.RemoteWantedLevelAmount = _args[0];
gpbd.RemoteWantedLevelAmount = wanted_level;
for (int i = 0; PLAYER::GET_PLAYER_WANTED_LEVEL(id) < _args[0] && i < 3600; i++)
for (int i = 0; PLAYER::GET_PLAYER_WANTED_LEVEL(id) < wanted_level && i < 3600; i++)
script::get_current()->yield(1ms);
gpbd.RemoteWantedLevelPlayer = -1;

View File

@ -16,7 +16,7 @@ namespace big
return CommandAccessLevel::AGGRESSIVE;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
const size_t arg_count = 8;
int64_t args[arg_count] = {(int64_t)eRemoteEvent::TransactionError,

View File

@ -18,7 +18,7 @@ namespace big
return CommandAccessLevel::AGGRESSIVE;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
const size_t arg_count = 25;
int64_t args[arg_count] = {(int64_t)eRemoteEvent::StartScriptBegin, (int64_t)self::id};

View File

@ -13,7 +13,7 @@ namespace big
return CommandAccessLevel::AGGRESSIVE;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
const size_t arg_count = 3;
int64_t args[arg_count] = {(int64_t)eRemoteEvent::TriggerCEORaid, (int64_t)self::id, 0};

View File

@ -15,7 +15,7 @@ namespace big
return CommandAccessLevel::AGGRESSIVE;
}
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
auto id = player->id();
@ -81,7 +81,7 @@ namespace big
return CommandAccessLevel::AGGRESSIVE;
}
virtual void execute(const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
scripts::start_launcher_script(47);

View File

@ -10,7 +10,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
teleport::bring_player(player);
}
@ -20,7 +20,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
for (auto& player : g_player_service->players())
g_fiber_pool->queue_job([player]() {

View File

@ -10,7 +10,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
troll::set_bounty_on_player(player, 10000, g.session.anonymous_bounty);
}

View File

@ -10,7 +10,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
teleport::to_player(player->id());
}

View File

@ -9,7 +9,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
Vehicle veh =
PED::GET_VEHICLE_PED_IS_IN(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(g_player_service->get_selected()->id()), false);

View File

@ -9,7 +9,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
Ped ped = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id());
if (!PED::IS_PED_IN_ANY_VEHICLE(ped, true))

View File

@ -9,7 +9,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
Ped ped = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id());

View File

@ -8,7 +8,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
Ped ped = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id());

View File

@ -9,7 +9,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
Ped ped = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id());
Vehicle vehicle = PED::GET_VEHICLE_PED_IS_IN(ped, false);

View File

@ -9,7 +9,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
Ped player_ped = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id());
Vehicle vehicle = PED::GET_VEHICLE_PED_IS_IN(player_ped, false);

View File

@ -9,7 +9,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
Entity ent = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id());

View File

@ -8,7 +8,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
Ped ped = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id());
if (!PED::IS_PED_IN_ANY_VEHICLE(ped, true))

View File

@ -9,7 +9,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
int lockStatus = VEHICLE::GET_VEHICLE_DOOR_LOCK_STATUS(player->id());
Ped ped = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id());

View File

@ -9,7 +9,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
Ped ped = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id());
if (!PED::IS_PED_IN_ANY_VEHICLE(ped, true))

View File

@ -9,7 +9,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
Vehicle veh = PED::GET_VEHICLE_PED_IS_IN(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id()), FALSE);
if (veh == 0)

View File

@ -9,7 +9,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
Ped ped = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id());
if (PED::IS_PED_IN_ANY_VEHICLE(ped, false))

View File

@ -8,7 +8,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
Ped ped = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id());
if (!PED::IS_PED_IN_ANY_VEHICLE(ped, true))

View File

@ -8,7 +8,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
if (PED::IS_PED_IN_ANY_VEHICLE(player->id(), false))
{

View File

@ -10,7 +10,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
Ped ped = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id());
Vehicle vehicle = PED::GET_VEHICLE_PED_IS_IN(ped, false);

View File

@ -10,7 +10,7 @@ namespace big
{
using player_command::player_command;
virtual void execute(player_ptr player, const std::vector<uint64_t>& _args, const std::shared_ptr<command_context> ctx)
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx)
{
Ped ped = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id());

View File

@ -8,7 +8,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
for (const auto& [_, weapon] : g_gta_data_service->weapons())
{

View File

@ -8,7 +8,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
entity::clean_ped(self::ped);
}

View File

@ -7,7 +7,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
if(g_local_player && g_local_player !=nullptr && !g.self.force_wanted_level)
{

View File

@ -8,7 +8,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
std::string mpPrefix = local_player::get_mp_prefix();
STATS::STAT_SET_INT(rage::joaat(mpPrefix + "NO_BOUGHT_YUM_SNACKS"), 30, true);

View File

@ -7,7 +7,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
ENTITY::SET_ENTITY_HEALTH(self::ped, PED::GET_PED_MAX_HEALTH(self::ped), 0);
PED::SET_PED_ARMOUR(self::ped, PLAYER::GET_PLAYER_MAX_ARMOUR(self::id));

View File

@ -7,7 +7,7 @@ namespace big
class repairpv : command
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
vehicle::repair(self::veh);
}

View File

@ -8,7 +8,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
mobile::merry_weather::request_boat_pickup();
}
@ -18,7 +18,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
mobile::ceo_abilities::request_ballistic_armor();
}
@ -28,7 +28,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
mobile::services::request_avenger();
}
@ -38,7 +38,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
mobile::services::request_kosatka();
}
@ -48,7 +48,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
mobile::services::request_mobile_operations_center();
}
@ -58,7 +58,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
mobile::services::request_terrorbyte();
}
@ -68,7 +68,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
mobile::services::request_acidlab();
}
@ -78,7 +78,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
mobile::services::request_acidlab_bike();
}
@ -88,7 +88,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
mobile::mobile_misc::request_taxi();
}

View File

@ -7,7 +7,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
CUTSCENE::STOP_CUTSCENE_IMMEDIATELY();
}

View File

@ -7,7 +7,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
ENTITY::SET_ENTITY_HEALTH(self::ped, 0, 0);
}

View File

@ -8,7 +8,7 @@ namespace big
class empty_session : command
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
g_player_service->iterate([](const player_entry& player) {
auto mgr = *g_pointers->m_gta.m_network_player_mgr;

View File

@ -10,10 +10,12 @@ namespace big
{
using command::command;
virtual std::optional<std::vector<uint64_t>> parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx)
virtual std::optional<command_arguments> parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx)
{
auto hash = rage::joaat(args[0]);
return std::vector<uint64_t>{hash};
command_arguments result(1);
result.push(rage::joaat(args[0]));
return result;
}
virtual CommandAccessLevel get_access_level()
@ -21,9 +23,10 @@ namespace big
return CommandAccessLevel::FRIENDLY;
}
virtual void execute(const std::vector<uint64_t>& args, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments& args, const std::shared_ptr<command_context> ctx)
{
if (!STREAMING::IS_MODEL_IN_CDIMAGE(args[0]) || !STREAMING::IS_MODEL_A_VEHICLE(args[0]))
const auto hash = args.get<rage::joaat_t>(0);
if (!STREAMING::IS_MODEL_IN_CDIMAGE(hash) || !STREAMING::IS_MODEL_A_VEHICLE(hash))
{
ctx->report_error("Specified model is invalid");
return;
@ -31,11 +34,11 @@ namespace big
const auto spawn_location =
vehicle::get_spawn_location(ctx->get_sender()->id() == self::id ? g.spawn_vehicle.spawn_inside : false,
args[0],
hash,
PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(ctx->get_sender()->id()));
const auto spawn_heading = ENTITY::GET_ENTITY_HEADING(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(ctx->get_sender()->id()));
const auto veh = vehicle::spawn(args[0], spawn_location, spawn_heading);
const auto veh = vehicle::spawn(hash, spawn_location, spawn_heading);
if (veh == 0)
{

View File

@ -6,7 +6,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
exit(0);
}

View File

@ -9,7 +9,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
Vehicle veh = mobile::mechanic::get_personal_vehicle();
vehicle::bring(veh, self::pos);

View File

@ -8,7 +8,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<std::uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
teleport::to_highlighted_blip();
}

View File

@ -8,7 +8,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
if (g_local_player && g_local_player->m_vehicle)
{

View File

@ -8,7 +8,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
teleport::to_objective();
}

View File

@ -9,7 +9,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
Vehicle veh = mobile::mechanic::get_personal_vehicle();
teleport::into_vehicle(veh);

View File

@ -8,7 +8,7 @@ namespace big
{
using command::command;
virtual void execute(const std::vector<uint64_t>&, const std::shared_ptr<command_context> ctx)
virtual void execute(const command_arguments&, const std::shared_ptr<command_context> ctx)
{
teleport::to_waypoint();
}

View File

@ -0,0 +1,32 @@
#include "float_command.hpp"
namespace big
{
float_command::float_command(const std::string& name, const std::string& label, const std::string& description, float& value, float lower_bound, float upper_bound) :
command(name, label, description, 1),
m_value(value),
m_lower_bound(lower_bound),
m_upper_bound(upper_bound)
{
}
void float_command::execute(const command_arguments& args, const std::shared_ptr<command_context> ctx)
{
m_value = args.get<float>(0);
}
std::optional<command_arguments> float_command::parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx)
{
command_arguments result(1);
float value = std::atof(args[0].c_str());
if (value < m_lower_bound || value > m_upper_bound)
{
ctx->report_error(std::format("Value {} is not between {} and {} in command {}", value, m_lower_bound, m_upper_bound, m_name));
return std::nullopt;
}
result.push(value);
return result;
}
}

View File

@ -0,0 +1,31 @@
#pragma once
#include "command.hpp"
namespace big
{
class float_command : public command
{
protected:
float& m_value;
const float m_lower_bound;
const float m_upper_bound;
virtual void execute(const command_arguments& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
virtual std::optional<command_arguments> parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
public:
float_command(const std::string& name, const std::string& label, const std::string& description, float& value, float lower_bound, float upper_bound);
inline float& get_value()
{
return m_value;
}
inline float get_lower_bound()
{
return m_lower_bound;
}
inline float get_upper_bound()
{
return m_upper_bound;
}
};
}

View File

@ -10,14 +10,14 @@ namespace big
{
}
void int_command::execute(const std::vector<uint64_t>& args, const std::shared_ptr<command_context> ctx)
void int_command::execute(const command_arguments& args, const std::shared_ptr<command_context> ctx)
{
m_value = args[0];
m_value = args.get<int>(0);
}
std::optional<std::vector<uint64_t>> int_command::parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx)
std::optional<command_arguments> int_command::parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx)
{
std::vector<uint64_t> result;
command_arguments result(1);
int value = std::atoi(args[0].c_str());
if (value < m_lower_bound || value > m_upper_bound)
@ -26,7 +26,7 @@ namespace big
return std::nullopt;
}
result.push_back(value);
result.push(value);
return result;
}
}

View File

@ -10,8 +10,8 @@ namespace big
int m_lower_bound;
int m_upper_bound;
virtual void execute(const std::vector<uint64_t>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
virtual std::optional<std::vector<uint64_t>> parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
virtual void execute(const command_arguments& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
virtual std::optional<command_arguments> parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
public:
int_command(const std::string& name, const std::string& label, const std::string& description, int& value, int lower_bound, int upper_bound);

View File

@ -1,11 +1,11 @@
#include "backend/looped_command.hpp"
#include "backend/bool_command.hpp"
#include "natives.hpp"
namespace big
{
class hudcolor_looped : looped_command
class hudcolor : bool_command
{
using looped_command::looped_command;
using bool_command::bool_command;
virtual void on_enable() override
{
@ -31,10 +31,6 @@ namespace big
}
}
virtual void on_tick() override
{
}
virtual void on_disable() override
{
for (int i = 0; i < hud_colors.size(); i++)
@ -45,5 +41,5 @@ namespace big
}
};
hudcolor_looped g_hudcolor_looped("hudcolor", "Override HUD Color", "Override HUD colors", g.self.hud.color_override);
hudcolor g_hudcolor_looped("hudcolor", "Override HUD Color", "Override HUD colors", g.self.hud.color_override);
}

View File

@ -20,6 +20,11 @@ namespace big
Vector3 position;
Vector3 rotation;
inline bool can_update_location()
{
return !(g.cmd_executor.enabled || g.self.noclip);
}
virtual void on_enable() override
{
camera = CAM::CREATE_CAM("DEFAULT_SCRIPTED_CAMERA", 0);
@ -44,6 +49,8 @@ namespace big
Vector3 vecChange = {0.f, 0.f, 0.f};
if (can_update_location())
{
// Left Shift
if (PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_SPRINT))
vecChange.z += speed / 2;
@ -62,6 +69,7 @@ namespace big
// Right
if (PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_MOVE_RIGHT_ONLY))
vecChange.x += speed;
}
if (vecChange.x == 0.f && vecChange.y == 0.f && vecChange.z == 0.f)
mult = 0.f;

View File

@ -19,6 +19,11 @@ namespace big
Entity m_entity;
float m_speed_multiplier;
inline bool can_update_location()
{
return !(g.cmd_executor.enabled || g.self.free_cam);
}
virtual void on_tick() override
{
if (g_orbital_drone_service.initialized())
@ -41,6 +46,8 @@ namespace big
Vector3 vel{};
if (can_update_location())
{
// Left Shift
if (PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_SPRINT))
vel.z += speed / 2;
@ -59,6 +66,7 @@ namespace big
// Right
if (PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_MOVE_RIGHT_ONLY))
vel.x += speed;
}
auto rot = CAM::GET_GAMEPLAY_CAM_ROT(2);
ENTITY::SET_ENTITY_ROTATION(ent, 0.f, rot.y, rot.z, 2, 0);

View File

@ -1,23 +1,18 @@
#include "backend/looped_command.hpp"
#include "backend/bool_command.hpp"
#include "pointers.hpp"
#include "util/vehicle.hpp"
namespace big
{
class veh_no_collision : looped_command
class veh_no_collision : bool_command
{
using looped_command::looped_command;
using bool_command::bool_command;
virtual void on_enable() override
{
vehicle::disable_collisions::m_patch->apply();
}
virtual void on_tick() override
{
}
virtual void on_disable() override
{
vehicle::disable_collisions::m_patch->restore();

View File

@ -1,4 +1,4 @@
#include "backend/looped_command.hpp"
#include "backend/bool_command.hpp"
#include "pointers.hpp"
namespace big

View File

@ -1,21 +1,17 @@
#include "backend/looped_command.hpp"
#include "backend/bool_command.hpp"
#include "natives.hpp"
namespace big
{
class combative : looped_command
class combative : bool_command
{
using looped_command::looped_command;
using bool_command::bool_command;
virtual void on_enable() override
{
MISC::SET_RIOT_MODE_ENABLED(true);
}
virtual void on_tick() override
{
}
virtual void on_disable() override
{
MISC::SET_RIOT_MODE_ENABLED(false);

View File

@ -1,7 +1,5 @@
#include "looped_command.hpp"
#include "fiber_pool.hpp"
namespace big
{
looped_command::looped_command(const std::string& name, const std::string& label, const std::string& description, bool& toggle) :
@ -9,46 +7,4 @@ namespace big
{
g_looped_commands.push_back(this);
}
void looped_command::enable()
{
if (!m_toggle)
{
m_toggle = true;
m_last_enabled = true;
g_fiber_pool->queue_job([this] {
on_enable();
});
}
}
void looped_command::disable()
{
if (m_toggle)
{
m_toggle = false;
m_last_enabled = false;
g_fiber_pool->queue_job([this] {
disable();
});
}
}
void looped_command::refresh()
{
if (m_toggle && !m_last_enabled)
{
m_last_enabled = true;
g_fiber_pool->queue_job([this] {
on_enable();
});
}
else if (!m_toggle && m_last_enabled)
{
m_last_enabled = false;
g_fiber_pool->queue_job([this] {
on_disable();
});
}
}
}

View File

@ -5,18 +5,10 @@ namespace big
{
class looped_command : public bool_command
{
bool m_last_enabled = false;
public:
looped_command(const std::string& name, const std::string& label, const std::string& description, bool& toggle);
virtual void on_enable(){};
virtual void on_disable(){};
virtual void on_tick() = 0;
virtual void refresh() override;
virtual void enable() override;
virtual void disable() override;
};
inline std::vector<looped_command*> g_looped_commands;

View File

@ -10,7 +10,7 @@ namespace big
{
}
void player_all_component::execute(const std::vector<uint64_t>& args, const std::shared_ptr<command_context> ctx)
void player_all_component::execute(const command_arguments& args, const std::shared_ptr<command_context> ctx)
{
g_fiber_pool->queue_job([this, args, &ctx] {
g_player_service->iterate([this, args, &ctx](const player_entry& player) {
@ -19,7 +19,7 @@ namespace big
});
}
std::optional<std::vector<uint64_t>> player_all_component::parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx)
std::optional<command_arguments> player_all_component::parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx)
{
return m_parent->parse_args_p(args, ctx);
}
@ -31,16 +31,12 @@ namespace big
m_all_component = std::make_unique<player_all_component>(this, name, label, description, num_args);
}
void player_command::execute(const std::vector<uint64_t>& args, const std::shared_ptr<command_context> ctx)
void player_command::execute(const command_arguments& args, const std::shared_ptr<command_context> ctx)
{
g_fiber_pool->queue_job([this, args, ctx] {
std::vector<uint64_t> new_args;
command_arguments new_args(m_num_args.value(), args);
// TODO: This looks ugly and inefficient
for (int i = 1; i < m_num_args; i++)
new_args.push_back(args[i]);
if (g_player_service->get_self()->id() == args[0])
if (g_player_service->get_self()->id() == args.get<int>(0))
{
execute(g_player_service->get_self(), new_args, ctx);
return;
@ -48,25 +44,25 @@ namespace big
for (auto& plyr : g_player_service->players())
{
if (plyr.second->id() == args[0])
if (plyr.second->id() == args.get<uint8_t>(0))
{
execute(plyr.second, new_args, ctx);
return;
}
}
ctx->report_error(std::format("Tried to execute command {}, but a player with index {} was not found", m_name, args[0]));
ctx->report_error(std::format("Tried to execute command {}, but a player with index {} was not found", m_name, args.get<int>(0)));
});
}
std::optional<std::vector<uint64_t>> player_command::parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx)
std::optional<command_arguments> player_command::parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx)
{
std::vector<std::string> new_args;
std::vector<uint64_t> result;
command_arguments result(m_num_args.value());
if (args[0] == "me" || args[0] == "self")
{
result.push_back(ctx->get_sender()->id());
result.push(ctx->get_sender()->id());
}
else
{
@ -93,23 +89,26 @@ namespace big
return std::nullopt;
}
result.push_back(plyr_id);
result.push(plyr_id);
}
for (int i = 1; i < args.size(); i++)
new_args.push_back(args[i]);
std::copy(++args.begin(), args.end(), new_args.begin());
// for (int i = 1; i < args.size(); i++)
// new_args.push_back(args[i]);
auto res = parse_args_p(new_args, ctx);
// no value indicates a failure
if (!res.has_value())
return std::nullopt;
for (auto& p : res.value())
result.push_back(p);
const auto alt_args = res.value();
for (auto i = 0u; i < alt_args.size(); ++i)
result.push(alt_args.get(i));
return result;
}
void player_command::call(player_ptr player, const std::vector<uint64_t>& args, const std::shared_ptr<command_context> ctx)
void player_command::call(player_ptr player, const command_arguments& args, const std::shared_ptr<command_context> ctx)
{
// TODO: Code duplication
if (m_num_args.has_value() && args.size() != (m_num_args.value() - 1))

View File

@ -11,8 +11,8 @@ namespace big
player_command* m_parent;
protected:
virtual void execute(const std::vector<uint64_t>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
virtual std::optional<std::vector<uint64_t>> parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
virtual void execute(const command_arguments& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
virtual std::optional<command_arguments> parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
public:
player_all_component(player_command* parent, const std::string& name, const std::string& label, const std::string& description, std::optional<uint8_t> num_args);
@ -24,16 +24,16 @@ namespace big
std::unique_ptr<player_all_component> m_all_component;
protected:
virtual void execute(const std::vector<uint64_t>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
virtual void execute(player_ptr player, const std::vector<uint64_t>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) = 0;
virtual std::optional<std::vector<uint64_t>> parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
virtual std::optional<std::vector<uint64_t>> parse_args_p(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>())
virtual void execute(const command_arguments& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
virtual void execute(player_ptr player, const command_arguments& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) = 0;
virtual std::optional<command_arguments> parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>()) override;
virtual std::optional<command_arguments> parse_args_p(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>())
{
return std::vector<uint64_t>();
return {0};
};
public:
void call(player_ptr player, const std::vector<uint64_t>& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>());
void call(player_ptr player, const command_arguments& args, const std::shared_ptr<command_context> ctx = std::make_shared<default_command_context>());
player_command(const std::string& name, const std::string& label, const std::string& description, std::optional<uint8_t> num_args, bool make_all_version = true);
};
}

View File

@ -1,5 +1,6 @@
#pragma once
#include "backend/command.hpp"
#include "backend/float_command.hpp"
#include "backend/int_command.hpp"
#include "backend/looped_command.hpp"
#include "backend/player_command.hpp"
@ -22,8 +23,8 @@ namespace big
static void title(const std::string_view);
static void nav_item(std::pair<tabs, navigation_struct>&, int);
static void input_text_with_hint(const std::string_view label, const std::string_view hint, char* buf, size_t buf_size, ImGuiInputTextFlags_ flag = ImGuiInputTextFlags_None, std::function<void()> cb = nullptr);
static void input_text_with_hint(const std::string_view label, const std::string_view hint, std::string* buf, ImGuiInputTextFlags_ flag = ImGuiInputTextFlags_None, std::function<void()> cb = nullptr);
static bool input_text_with_hint(const std::string_view label, const std::string_view hint, char* buf, size_t buf_size, ImGuiInputTextFlags_ flag = ImGuiInputTextFlags_None, std::function<void()> cb = nullptr);
static bool input_text_with_hint(const std::string_view label, const std::string_view hint, std::string& buf, ImGuiInputTextFlags_ flag = ImGuiInputTextFlags_None, std::function<void()> cb = nullptr);
static void input_text(const std::string_view label, char* buf, size_t buf_size, ImGuiInputTextFlags_ flag = ImGuiInputTextFlags_None, std::function<void()> cb = nullptr);
@ -44,7 +45,10 @@ namespace big
return ImGui::Text("INVALID COMMAND");
if (ImGui::Button(label_override.value_or(command->get_label()).data()))
command->call(args);
{
command_arguments _args(args);
command->call(_args);
}
if (ImGui::IsItemHovered())
ImGui::SetTooltip(command->get_description().c_str());
}
@ -97,6 +101,22 @@ namespace big
ImGui::SetTooltip(command->get_description().c_str());
}
template<template_str cmd_str>
static void command_float_slider(std::optional<const std::string_view> label_override = std::nullopt)
{
static float_command* command = (float_command*)command::get(rage::consteval_joaat(cmd_str.value));
if (command == nullptr)
return ImGui::Text("INVALID COMMAND");
ImGui::SliderFloat(label_override.value_or(command->get_label()).data(),
&command->get_value(),
command->get_lower_bound(),
command->get_upper_bound());
if (ImGui::IsItemHovered())
ImGui::SetTooltip(command->get_description().c_str());
}
template<ImVec2 size = ImVec2(0, 0), ImVec4 color = ImVec4(0.24f, 0.23f, 0.29f, 1.00f)>
static bool button(const std::string_view text)
{

View File

@ -5,27 +5,33 @@
namespace big
{
void components::input_text_with_hint(const std::string_view label, const std::string_view hint, char* buf, size_t buf_size, ImGuiInputTextFlags_ flag, std::function<void()> cb)
bool components::input_text_with_hint(const std::string_view label, const std::string_view hint, char* buf, size_t buf_size, ImGuiInputTextFlags_ flag, std::function<void()> cb)
{
if (ImGui::InputTextWithHint(label.data(), hint.data(), buf, buf_size, flag))
if (cb)
bool returned = false;
if (returned = ImGui::InputTextWithHint(label.data(), hint.data(), buf, buf_size, flag); returned && cb)
g_fiber_pool->queue_job(std::move(cb));
if (ImGui::IsItemActive())
{
g_fiber_pool->queue_job([] {
PAD::DISABLE_ALL_CONTROL_ACTIONS(0);
});
}
return returned;
}
void components::input_text_with_hint(const std::string_view label, const std::string_view hint, std::string* buf, ImGuiInputTextFlags_ flag, std::function<void()> cb)
bool components::input_text_with_hint(const std::string_view label, const std::string_view hint, std::string& buf, ImGuiInputTextFlags_ flag, std::function<void()> cb)
{
if (ImGui::InputTextWithHint(label.data(), hint.data(), buf, flag))
if (cb)
bool returned = false;
if (returned = ImGui::InputTextWithHint(label.data(), hint.data(), &buf, flag); returned && cb)
g_fiber_pool->queue_job(std::move(cb));
if (ImGui::IsItemActive())
{
g_fiber_pool->queue_job([] {
PAD::DISABLE_ALL_CONTROL_ACTIONS(0);
});
}
return returned;
}
}

View File

@ -18,7 +18,7 @@ namespace lua::command
// Call a menu command.
static void call(const std::string& command_name, std::optional<sol::table> _args)
{
const auto args = convert_sequence<uint64_t>(_args.value_or(sol::table()));
big::command_arguments args = convert_sequence<uint64_t>(_args.value_or(sol::table()));
const auto command = big::command::get(rage::joaat(command_name));

View File

@ -250,7 +250,7 @@ namespace big
while (g_running)
{
if (g_gui->is_open() || HUD::IS_PAUSE_MENU_ACTIVE()
|| (*g_pointers->m_gta.m_chat_data && (*g_pointers->m_gta.m_chat_data)->m_chat_open))
|| (*g_pointers->m_gta.m_chat_data && (*g_pointers->m_gta.m_chat_data)->m_chat_open) || g.cmd_executor.enabled)
{
script::get_current()->yield();
continue;

View File

@ -21,7 +21,7 @@ namespace big
if (m_cooldown.has_value())
m_wakeup = std::chrono::high_resolution_clock::now() + m_cooldown.value();
command::get(m_command_hash)->call(std::vector<uint64_t>());
command::get(m_command_hash)->call({});
}
rage::joaat_t hotkey::name_hash() const

View File

@ -20,7 +20,7 @@ namespace big
if (ImGui::Begin("cmd_executor", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoMouseInputs))
{
static char command_buffer[255];
static std::string command_buffer;
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {10.f, 15.f});
components::sub_title("CMD_EXECUTOR_TITLE"_T);
@ -28,13 +28,14 @@ namespace big
ImGui::SetKeyboardFocusHere(0);
ImGui::SetNextItemWidth((screen_x * 0.5f) - 30.f);
components::input_text_with_hint("", "CMD_EXECUTOR_TYPE_CMD"_T, command_buffer, sizeof(command_buffer), ImGuiInputTextFlags_EnterReturnsTrue, [] {
if (components::input_text_with_hint("", "CMD_EXECUTOR_TYPE_CMD"_T, command_buffer, ImGuiInputTextFlags_EnterReturnsTrue))
{
if (command::process(command_buffer, std::make_shared<default_command_context>(), true))
{
g.cmd_executor.enabled = false;
command_buffer[0] = 0;
command_buffer = {};
}
}
});
components::small_text("CMD_EXECUTOR_MULTIPLE_CMDS"_T);
ImGui::Spacing();

View File

@ -28,7 +28,7 @@ namespace big
});
ImGui::SetNextItemWidth(400);
components::input_text_with_hint("##dictionaryfilter", "Dictionary", &current_dict);
components::input_text_with_hint("##dictionaryfilter", "Dictionary", current_dict);
if (animations::has_anim_list_been_populated() && ImGui::BeginListBox("##dictionaries", ImVec2(400, 200)))
{

Some files were not shown because too many files have changed in this diff Show More