refactor(ContextMenu): improve code (#1173)
* chore: remove unused classes from replay * feat(ContextMenu): keep drawing even if menu is open
This commit is contained in:
parent
ea33c09e8c
commit
06a215b90c
@ -18,8 +18,8 @@ namespace big
|
||||
if (!player->get_ped())
|
||||
return;
|
||||
|
||||
g_pointers->m_send_network_damage((CEntity*)g_player_service->get_self()->get_ped(),
|
||||
(CEntity*)player->get_ped(),
|
||||
g_pointers->m_send_network_damage(g_player_service->get_self()->get_ped(),
|
||||
player->get_ped(),
|
||||
player->get_ped()->m_navigation->get_position(),
|
||||
0,
|
||||
true,
|
||||
|
@ -18,8 +18,8 @@ namespace big
|
||||
if (g_player_service->get_self()->get_ped() && entry.second->get_ped() && entry.second->get_ped()->m_health > 0)
|
||||
{
|
||||
if (entry.second->kill_loop && !(entry.second->get_ped()->m_damage_bits & (1 << 8)))
|
||||
g_pointers->m_send_network_damage((CEntity*)g_player_service->get_self()->get_ped(),
|
||||
(CEntity*)entry.second->get_ped(),
|
||||
g_pointers->m_send_network_damage(g_player_service->get_self()->get_ped(),
|
||||
entry.second->get_ped(),
|
||||
entry.second->get_ped()->m_navigation->get_position(),
|
||||
0,
|
||||
true,
|
||||
|
@ -108,7 +108,7 @@ namespace big::functions
|
||||
|
||||
using send_chat_message = bool (*)(int64_t* send_chat_ptr, rage::rlGamerInfo* gamer_info, char* message, bool is_team);
|
||||
|
||||
using send_network_damage = void (*)(CEntity* source, CEntity* target, rage::fvector3* position, int hit_component, bool override_default_damage, int weapon_type, float override_damage, int tire_index, int suspension_index, int flags, std::uint32_t action_result_hash, std::int16_t action_result_id, int action_unk, bool hit_weapon, bool hit_weapon_ammo_attachment, bool silenced, bool unk, rage::fvector3* impact_direction);
|
||||
using send_network_damage = void (*)(rage::CEntity* source, rage::CEntity* target, rage::fvector3* position, int hit_component, bool override_default_damage, int weapon_type, float override_damage, int tire_index, int suspension_index, int flags, std::uint32_t action_result_hash, std::int16_t action_result_id, int action_unk, bool hit_weapon, bool hit_weapon_ammo_attachment, bool silenced, bool unk, rage::fvector3* impact_direction);
|
||||
using request_ragdoll = void (*)(uint16_t object_id);
|
||||
using request_control = void (*)(rage::netObject* net_object);
|
||||
|
||||
|
@ -5,6 +5,8 @@ namespace rage
|
||||
template<typename T>
|
||||
class atArray;
|
||||
|
||||
class CEntity;
|
||||
|
||||
class datBitBuffer;
|
||||
class sysMemAllocator;
|
||||
|
||||
@ -58,7 +60,6 @@ class CGameScriptHandler;
|
||||
class CGameScriptHandlerNetwork;
|
||||
class CGameScriptHandlerMgr;
|
||||
|
||||
class CEntity;
|
||||
class CPhysical;
|
||||
|
||||
class CObject;
|
||||
|
@ -3,138 +3,92 @@
|
||||
|
||||
#include "common.hpp"
|
||||
#include "fwddec.hpp"
|
||||
#include "base/CObject.hpp"
|
||||
|
||||
namespace rage
|
||||
{
|
||||
class CObject : public fwEntity
|
||||
template<typename T = CDynamicEntity>
|
||||
class CEntityEntry
|
||||
{
|
||||
public:
|
||||
};//Size: 0x018C
|
||||
T* m_entity_ptr; //0x0000
|
||||
int32_t m_handle; //0x0008
|
||||
char pad_000C[4]; //0x000C
|
||||
}; //Size: 0x0010
|
||||
static_assert(sizeof(CEntityEntry<CDynamicEntity>) == 0x10, "CEntityHandle is not properly sized");
|
||||
|
||||
class CPedFactory
|
||||
class CObjectEntry : public CEntityEntry<CObject>
|
||||
{
|
||||
public:
|
||||
virtual ~CPedFactory() = default;
|
||||
class CPed* m_local_ped;//0x0008
|
||||
}; //Size: 0x0010
|
||||
};
|
||||
|
||||
//CUSTOM CLASS TO IMPROVE R* SHIT CLASS STRUCTURE
|
||||
class CEntityHandle
|
||||
class CPedEntry : public CEntityEntry<CPed>
|
||||
{
|
||||
public:
|
||||
class fwEntity* m_entity_ptr;//0x0000
|
||||
int32_t m_handle; //0x0008
|
||||
char pad_000C[4]; //0x000C
|
||||
}; //Size: 0x0010
|
||||
static_assert(sizeof(CEntityHandle) == 0x10, "CEntityHandle is not properly sized");
|
||||
};
|
||||
|
||||
class CObjectHandle
|
||||
class CVehicleEntry : public CEntityEntry<CVehicle>
|
||||
{
|
||||
public:
|
||||
class CObject* m_object;//0x0000
|
||||
int32_t m_handle; //0x0008
|
||||
char pad_000C[4]; //0x000C
|
||||
}; //Size: 0x0010
|
||||
static_assert(sizeof(CObjectHandle) == 0x10, "CObjectHandle is not properly sized");
|
||||
|
||||
class CObjectList
|
||||
{
|
||||
public:
|
||||
class CEntityHandle m_objects[2300];//0x0000
|
||||
}; //Size: 0x8FC0
|
||||
}; //Size: 0x8FC0
|
||||
|
||||
class CObjectInterface
|
||||
{
|
||||
public:
|
||||
char pad_0000[344]; //0x0000
|
||||
class CObjectList* m_object_list;//0x0158
|
||||
int32_t m_max_objects; //0x0160
|
||||
char pad_0164[4]; //0x0164
|
||||
int32_t m_cur_objects; //0x0168
|
||||
char pad_0000[344]; //0x0000
|
||||
std::array<CObjectEntry, 2300>* m_object_list; //0x0158
|
||||
int32_t m_max_objects; //0x0160
|
||||
char pad_0164[4]; //0x0164
|
||||
int32_t m_cur_objects; //0x0168
|
||||
|
||||
rage::fwEntity* get_object(const int& index)
|
||||
CObject* get_object(const int& index)
|
||||
{
|
||||
if (index < m_max_objects)
|
||||
return m_object_list->m_objects[index].m_entity_ptr;
|
||||
return (*m_object_list)[index].m_entity_ptr;
|
||||
return nullptr;
|
||||
}
|
||||
};//Size: 0x016C
|
||||
|
||||
class CPedHandle
|
||||
{
|
||||
public:
|
||||
class CPed* m_ped;//0x0000
|
||||
int32_t m_handle; //0x0008
|
||||
char pad_000C[4]; //0x000C
|
||||
}; //Size: 0x0010
|
||||
static_assert(sizeof(CPedHandle) == 0x10, "CPedHandle is not properly sized");
|
||||
|
||||
class CPedList
|
||||
{
|
||||
public:
|
||||
//CHANGED FROM CPedHandle
|
||||
class CEntityHandle m_peds[256];//0x0000
|
||||
}; //Size: 0x1000
|
||||
}; //Size: 0x016C
|
||||
|
||||
class CPedInterface
|
||||
{
|
||||
public:
|
||||
char pad_0000[256]; //0x0000
|
||||
class CPedList* m_ped_list;//0x0100
|
||||
int32_t m_max_peds; //0x0108
|
||||
char pad_010C[4]; //0x010C
|
||||
int32_t m_cur_peds; //0x0110
|
||||
char pad_0000[256]; //0x0000
|
||||
std::array<CPedEntry, 256>* m_ped_list; //0x0100
|
||||
int32_t m_max_peds; //0x0108
|
||||
char pad_010C[4]; //0x010C
|
||||
int32_t m_cur_peds; //0x0110
|
||||
|
||||
fwEntity* get_ped(const int& index)
|
||||
CPed* get_ped(const int& index)
|
||||
{
|
||||
if (index < m_max_peds)
|
||||
return m_ped_list->m_peds[index].m_entity_ptr;
|
||||
return (*m_ped_list)[index].m_entity_ptr;
|
||||
return nullptr;
|
||||
}
|
||||
};//Size: 0x0114
|
||||
|
||||
class CVehicleHandle
|
||||
{
|
||||
public:
|
||||
class CAutomobile* m_vehicle;//0x0000
|
||||
int32_t m_handle; //0x0008
|
||||
char pad_000C[4]; //0x000C
|
||||
}; //Size: 0x0010
|
||||
static_assert(sizeof(CVehicleHandle) == 0x10, "CVehicleHandle is not properly sized");
|
||||
|
||||
class CVehicleList
|
||||
{
|
||||
public:
|
||||
//CHANGED FROM CVehicleHandle
|
||||
class CEntityHandle m_vehicles[300];//0x0000
|
||||
}; //Size: 0x12C0
|
||||
}; //Size: 0x0114
|
||||
|
||||
class CVehicleInterface
|
||||
{
|
||||
public:
|
||||
char pad_0000[384]; //0x0000
|
||||
class CVehicleList* m_vehicle_list;//0x0180
|
||||
int32_t m_max_vehicles; //0x0188
|
||||
char pad_018C[4]; //0x018C
|
||||
int32_t m_cur_vehicles; //0x0190
|
||||
char pad_0000[384]; //0x0000
|
||||
std::array<CVehicleEntry, 300>* m_vehicle_list; //0x0180
|
||||
int32_t m_max_vehicles; //0x0188
|
||||
char pad_018C[4]; //0x018C
|
||||
int32_t m_cur_vehicles; //0x0190
|
||||
|
||||
fwEntity* get_vehicle(const int& index)
|
||||
CVehicle* get_vehicle(const int& index)
|
||||
{
|
||||
if (index < m_max_vehicles)
|
||||
return m_vehicle_list->m_vehicles[index].m_entity_ptr;
|
||||
return (*m_vehicle_list)[index].m_entity_ptr;
|
||||
return nullptr;
|
||||
}
|
||||
};//Size: 0x0194
|
||||
}; //Size: 0x0194
|
||||
|
||||
|
||||
class CReplayInterface
|
||||
{
|
||||
public:
|
||||
char pad_0000[16]; //0x0000
|
||||
class CVehicleInterface* m_vehicle_interface;//0x0010
|
||||
class CPedInterface* m_ped_interface; //0x0018
|
||||
char pad_0020[8]; //0x0020
|
||||
class CObjectInterface* m_object_interface; //0x0028
|
||||
}; //Size: 0x0030
|
||||
char pad_0000[16]; //0x0000
|
||||
class CVehicleInterface* m_vehicle_interface; //0x0010
|
||||
class CPedInterface* m_ped_interface; //0x0018
|
||||
char pad_0020[8]; //0x0020
|
||||
class CObjectInterface* m_object_interface; //0x0028
|
||||
}; //Size: 0x0030
|
||||
}
|
||||
#pragma pack(pop)
|
@ -193,8 +193,8 @@ namespace big
|
||||
if (!player->is_valid() || !player->get_ped())
|
||||
return;
|
||||
|
||||
g_pointers->m_send_network_damage((CEntity*)g_player_service->get_self()->get_ped(),
|
||||
(CEntity*)player->get_ped(),
|
||||
g_pointers->m_send_network_damage(g_player_service->get_self()->get_ped(),
|
||||
player->get_ped(),
|
||||
(rage::fvector3*)&localPos,
|
||||
hitComponent,
|
||||
overrideDefaultDamage,
|
||||
|
@ -1,11 +1,11 @@
|
||||
#include "context_menu_service.hpp"
|
||||
|
||||
#include "fiber_pool.hpp"
|
||||
#include "gta/replay.hpp"
|
||||
#include "gui.hpp"
|
||||
#include "natives.hpp"
|
||||
#include "pointers.hpp"
|
||||
#include "util/misc.hpp"
|
||||
#include "fiber_pool.hpp"
|
||||
|
||||
namespace big
|
||||
{
|
||||
@ -113,19 +113,19 @@ namespace big
|
||||
|
||||
double context_menu_service::distance_to_middle_of_screen(const rage::fvector2& screen_pos)
|
||||
{
|
||||
double cumulative_distance{};
|
||||
double cum_dist{};
|
||||
|
||||
if (screen_pos.x > 0.5)
|
||||
cumulative_distance += screen_pos.x - 0.5;
|
||||
cum_dist += screen_pos.x - 0.5;
|
||||
else
|
||||
cumulative_distance += 0.5 - screen_pos.x;
|
||||
cum_dist += 0.5 - screen_pos.x;
|
||||
|
||||
if (screen_pos.y > 0.5)
|
||||
cumulative_distance += screen_pos.y - 0.5;
|
||||
cum_dist += screen_pos.y - 0.5;
|
||||
else
|
||||
cumulative_distance += 0.5 - screen_pos.y;
|
||||
cum_dist += 0.5 - screen_pos.y;
|
||||
|
||||
return cumulative_distance;
|
||||
return cum_dist;
|
||||
}
|
||||
|
||||
s_context_menu* context_menu_service::get_context_menu()
|
||||
@ -142,6 +142,7 @@ namespace big
|
||||
}
|
||||
return &options.at(ContextEntityType::OBJECT);
|
||||
}
|
||||
case eModelType::OnlineOnlyPed:
|
||||
case eModelType::Ped:
|
||||
{
|
||||
if (const auto ped = reinterpret_cast<CPed*>(m_pointer); ped)
|
||||
@ -200,48 +201,52 @@ namespace big
|
||||
|
||||
if (veh_interface && ped_interface && obj_interface)
|
||||
{
|
||||
const auto veh_interface_size = veh_interface->m_max_vehicles;
|
||||
const auto ped_interface_size = ped_interface->m_max_peds;
|
||||
const auto obj_interface_size = obj_interface->m_max_objects;
|
||||
const auto all_entities = std::make_unique<rage::CEntityHandle[]>(veh_interface_size + ped_interface_size + obj_interface_size);
|
||||
double distance = 1;
|
||||
|
||||
const auto ptr = all_entities.get();
|
||||
std::uint32_t offset = 0;
|
||||
std::copy(ped_interface->m_ped_list->m_peds, ped_interface->m_ped_list->m_peds + ped_interface_size, ptr);
|
||||
offset += ped_interface_size;
|
||||
|
||||
std::copy(veh_interface->m_vehicle_list->m_vehicles, veh_interface->m_vehicle_list->m_vehicles + veh_interface_size, ptr + offset);
|
||||
offset += veh_interface_size;
|
||||
|
||||
std::copy(obj_interface->m_object_list->m_objects, obj_interface->m_object_list->m_objects + obj_interface_size, ptr + offset);
|
||||
offset += obj_interface_size;
|
||||
|
||||
double distance = 1;
|
||||
bool got_an_entity = false;
|
||||
rage::fvector2 screen_pos{};
|
||||
for (std::uint32_t i = 0; i < offset; i++)
|
||||
const auto get_closest_to_center = [this, &distance](auto entity_list) -> auto
|
||||
{
|
||||
if (!all_entities[i].m_entity_ptr)
|
||||
continue;
|
||||
|
||||
const auto temp_pointer = all_entities[i].m_entity_ptr;
|
||||
const auto temp_handle = g_pointers->m_ptr_to_handle(temp_pointer);
|
||||
if (!temp_pointer->m_navigation)
|
||||
continue;
|
||||
|
||||
const auto pos = *temp_pointer->m_navigation->get_position();
|
||||
HUD::GET_HUD_SCREEN_POSITION_FROM_WORLD_POSITION(pos.x, pos.y, pos.z, &screen_pos.x, &screen_pos.y);
|
||||
if (distance_to_middle_of_screen(screen_pos) < distance && ENTITY::HAS_ENTITY_CLEAR_LOS_TO_ENTITY(PLAYER::PLAYER_PED_ID(), temp_handle, 17) && temp_handle != PLAYER::PLAYER_PED_ID())
|
||||
rage::fvector2 screen_pos{};
|
||||
bool got_an_entity = false;
|
||||
for (const auto entity : *entity_list)
|
||||
{
|
||||
m_handle = temp_handle;
|
||||
m_pointer = temp_pointer;
|
||||
distance = distance_to_middle_of_screen(screen_pos);
|
||||
got_an_entity = true;
|
||||
const auto temp_pointer = entity.m_entity_ptr;
|
||||
if (!temp_pointer || !temp_pointer->m_navigation)
|
||||
continue;
|
||||
const auto temp_handle = g_pointers->m_ptr_to_handle(temp_pointer);
|
||||
|
||||
const auto pos = temp_pointer->m_navigation->get_position();
|
||||
HUD::GET_HUD_SCREEN_POSITION_FROM_WORLD_POSITION(pos->x,
|
||||
pos->y,
|
||||
pos->z,
|
||||
&screen_pos.x,
|
||||
&screen_pos.y);
|
||||
|
||||
const auto distance_from_middle = distance_to_middle_of_screen(screen_pos);
|
||||
if (distance_from_middle < distance && ENTITY::HAS_ENTITY_CLEAR_LOS_TO_ENTITY(self::ped, temp_handle, 17) && temp_handle != self::ped)
|
||||
{
|
||||
m_handle = temp_handle;
|
||||
m_pointer = temp_pointer;
|
||||
distance = distance_from_middle;
|
||||
got_an_entity = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return got_an_entity;
|
||||
};
|
||||
|
||||
// I'm using bitwise OR instead or || to avoid compiler optimisation, all functions HAVE to execute
|
||||
auto got_an_entity = get_closest_to_center(veh_interface->m_vehicle_list);
|
||||
got_an_entity |= get_closest_to_center(ped_interface->m_ped_list);
|
||||
got_an_entity |= get_closest_to_center(obj_interface->m_object_list);
|
||||
|
||||
if (got_an_entity)
|
||||
{
|
||||
// if the ped is driving a vehicle take their vehicle instead of the ped (aka. prevent jank)
|
||||
if ((m_pointer->m_model_info->m_model_type == eModelType::Ped || m_pointer->m_model_info->m_model_type == eModelType::OnlineOnlyPed)
|
||||
&& reinterpret_cast<CPed*>(m_pointer)->m_vehicle)
|
||||
{
|
||||
m_pointer = reinterpret_cast<CPed*>(m_pointer)->m_vehicle;
|
||||
m_handle = g_pointers->m_ptr_to_handle(m_pointer);
|
||||
}
|
||||
fill_model_bounding_box_screen_space();
|
||||
}
|
||||
}
|
||||
@ -303,12 +308,6 @@ namespace big
|
||||
continue;
|
||||
}
|
||||
|
||||
if (g_gui->is_open())
|
||||
{
|
||||
script::get_current()->yield();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (PAD::IS_DISABLED_CONTROL_JUST_RELEASED(0, (int)ControllerInputs::INPUT_VEH_DUCK))
|
||||
{
|
||||
g_context_menu_service->enabled = !g_context_menu_service->enabled;
|
||||
@ -326,25 +325,23 @@ namespace big
|
||||
script::get_current()->yield();
|
||||
continue;
|
||||
}
|
||||
else
|
||||
|
||||
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 (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)
|
||||
{
|
||||
if (!g_context_menu_service->m_pointer)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
g_fiber_pool->queue_job([cm] {
|
||||
cm->options.at(cm->current_option).command();
|
||||
});
|
||||
|
||||
script::get_current()->yield();
|
||||
continue;
|
||||
}
|
||||
|
||||
g_fiber_pool->queue_job([cm] {
|
||||
cm->options.at(cm->current_option).command();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -209,14 +209,11 @@ namespace big::entity
|
||||
Entity closest_entity{};
|
||||
float distance = 1;
|
||||
|
||||
//if (!vehicleInterface || !pedInterface)
|
||||
// return 0;
|
||||
|
||||
auto replayInterface = *g_pointers->m_replay_interface;
|
||||
auto vehicleInterface = replayInterface->m_vehicle_interface;
|
||||
auto pedInterface = replayInterface->m_ped_interface;
|
||||
|
||||
for (auto veh : vehicleInterface->m_vehicle_list->m_vehicles)
|
||||
for (const auto veh : (*vehicleInterface->m_vehicle_list))
|
||||
{
|
||||
if (veh.m_entity_ptr)
|
||||
{
|
||||
@ -233,7 +230,7 @@ namespace big::entity
|
||||
}
|
||||
}
|
||||
|
||||
for (auto ped : pedInterface->m_ped_list->m_peds)
|
||||
for (auto ped : *pedInterface->m_ped_list)
|
||||
{
|
||||
if (ped.m_entity_ptr)
|
||||
{
|
||||
|
@ -108,15 +108,11 @@ namespace big::vehicle
|
||||
float min_dist = FLT_MAX;
|
||||
int32_t m_handle = 0;
|
||||
|
||||
for (int32_t i = 0; i < veh_interface_size; i++)
|
||||
for (const auto veh_entity : *veh_interface->m_vehicle_list)
|
||||
{
|
||||
auto veh_entity = veh_interface->m_vehicle_list->m_vehicles[i];
|
||||
auto veh_ptr = veh_entity.m_entity_ptr;
|
||||
|
||||
const auto veh_ptr = veh_entity.m_entity_ptr;
|
||||
if (!veh_ptr || !veh_ptr->m_navigation)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
auto veh_pos_arr = *veh_ptr->m_navigation->get_position();
|
||||
Vector3 veh_pos(veh_pos_arr.x, veh_pos_arr.y, veh_pos_arr.z);
|
||||
|
Reference in New Issue
Block a user