Give optimisation hints to compiler (#2929)

feat(invoker): add compiler hints
chore(get network event data): added translation TODO
feat(native hooks): add compiler hint to crashes
feat(render): add likely compiler hint to on_present
feat(thread pool): add compiler hints
Added hook likely/unlikely switches to debug/crash scenarios.
Added HEX_TO_UPPER call on the AC verifier offsets.
Added more fuzzer unlikely attributes.
Replaced some hard coded numbers with their unhashed _J variants.
Added more unlikely attributes to singleton initializer checks.
Added more likely/unlikely attributes to certain scenarios.
This commit is contained in:
Andreas Maerten 2024-04-22 19:48:22 +02:00 committed by GitHub
parent b1bf477d1f
commit ca1e7e6b41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
41 changed files with 114 additions and 112 deletions

View File

@ -12,7 +12,7 @@ namespace big
virtual void on_tick() override
{
if (g_local_player == nullptr)
if (g_local_player == nullptr) [[unlikely]]
{
return;
}
@ -21,7 +21,7 @@ namespace big
uint32_t changed_bits = bits ^ last_bits;
uint32_t changed_or_enabled_bits = bits | changed_bits;
if (changed_or_enabled_bits)
if (changed_or_enabled_bits) [[unlikely]]
{
uint32_t unchanged_bits = g_local_player->m_damage_bits & ~changed_or_enabled_bits;
g_local_player->m_damage_bits = unchanged_bits | bits;

View File

@ -14,7 +14,7 @@ namespace big
virtual void on_tick() override
{
if (g_local_player)
if (g_local_player) [[likely]]
((rage::phBoundComposite*)g_local_player->m_navigation->m_damp->m_bound)
->m_bounds[0]
->m_bounding_box_max_xyz_margin_w.w = -1;
@ -22,7 +22,7 @@ namespace big
virtual void on_disable() override
{
if (g_local_player)
if (g_local_player) [[likely]]
((rage::phBoundComposite*)g_local_player->m_navigation->m_damp->m_bound)
->m_bounds[0]
->m_bounding_box_max_xyz_margin_w.w = 0.25;

View File

@ -11,13 +11,13 @@ namespace big
virtual void on_tick() override
{
if (g_local_player)
if (g_local_player) [[likely]]
g_local_player->m_navigation->m_damp->m_water_collision = 0;
}
virtual void on_disable() override
{
if (g_local_player)
if (g_local_player) [[likely]]
g_local_player->m_navigation->m_damp->m_water_collision = 1;
}
};

View File

@ -15,13 +15,13 @@ namespace big
int offset = 0;
switch (model)
{
case "mp_m_freemode_01"_J: break;
case "mp_f_freemode_01"_J:
case "mp_m_freemode_01"_J: [[likely]] break;
case "mp_f_freemode_01"_J: [[likely]]
{
offset = 1;
break;
}
default: return false; //For non-normal models
default:[[unlikely]] return false; //For non-normal models
}
return PED::GET_PED_DRAWABLE_VARIATION(self::ped, ComponentId::AUXILIARY) == 15 && PED::GET_PED_DRAWABLE_VARIATION(self::ped, ComponentId::TORSO) == 15 && PED::GET_PED_DRAWABLE_VARIATION(self::ped, ComponentId::LEGS) == (14 + offset);
@ -31,17 +31,17 @@ namespace big
{
//Disable clothing validation
*scr_globals::reset_clothing.as<PBOOL>() = FALSE;
if (auto tunable = g_tunables_service->get_tunable<PBOOL>("DISABLE_CLOTHING_SAVE_SLOT_VALIDATION"_J))
if (auto tunable = g_tunables_service->get_tunable<PBOOL>("DISABLE_CLOTHING_SAVE_SLOT_VALIDATION"_J)) [[likely]]
*tunable = TRUE;
if (g.self.persist_outfit.empty())
return; //Off
if (g_local_player == nullptr || PED::IS_PED_DEAD_OR_DYING(self::ped, TRUE) || STREAMING::IS_PLAYER_SWITCH_IN_PROGRESS() || DLC::GET_IS_LOADING_SCREEN_ACTIVE())
if (g_local_player == nullptr || PED::IS_PED_DEAD_OR_DYING(self::ped, TRUE) || STREAMING::IS_PLAYER_SWITCH_IN_PROGRESS() || DLC::GET_IS_LOADING_SCREEN_ACTIVE()) [[unlikely]]
return; //Dead or Loading
auto model = ENTITY::GET_ENTITY_MODEL(self::ped);
if (is_taking_shower(model))
if (is_taking_shower(model)) [[unlikely]]
return; //Showering
if (g.self.persist_outfits_mis && NETWORK::NETWORK_IS_ACTIVITY_SESSION())
@ -55,10 +55,10 @@ namespace big
persisting_outfit = g.self.persist_outfit;
folder saved_outfit_path = g_file_manager.get_project_folder("saved_outfits");
const auto persist_outfit_file_path = saved_outfit_path.get_file(persisting_outfit).get_path();
if (std::filesystem::exists(persist_outfit_file_path))
if (std::filesystem::exists(persist_outfit_file_path)) [[likely]]
{
std::ifstream i(persist_outfit_file_path);
if (i.is_open())
if (i.is_open()) [[likely]]
{
outfit.clear();
try

View File

@ -6,7 +6,7 @@ namespace big
{
void looped::self_police()
{
if (g_local_player == nullptr || g_local_player->m_player_info == nullptr)
if (g_local_player == nullptr || g_local_player->m_player_info == nullptr) [[unlikely]]
return;
static bool bLast = false;

View File

@ -15,14 +15,14 @@ namespace big
virtual void on_tick() override
{
if (scr_globals::gpbd_fm_3.as<GPBD_FM_3*>()->Entries[self::id].BossGoon.Boss != -1 || gta_util::find_script_thread("fm_mission_controller"_J) || gta_util::find_script_thread("fm_mission_controller_2020"_J))
if (scr_globals::gpbd_fm_3.as<GPBD_FM_3*>()->Entries[self::id].BossGoon.Boss != -1 || gta_util::find_script_thread("fm_mission_controller"_J) || gta_util::find_script_thread("fm_mission_controller_2020"_J)) [[unlikely]]
{
on_disable();
g.self.passive = false;
g_notification_service.push_warning("PASSIVE"_T.data(), "BACKEND_LOOPED_SELF_TOGGLE_PASSIVE_DISABLED_PASSIVE_MODE_MESSAGE"_T.data());
return;
}
*g_tunables_service->get_tunable<int*>(-29732167) = 0; // End Passive Time = 0s
*g_tunables_service->get_tunable<int*>("VC_PASSIVE_TIME_AFTER_DISABLE"_J) = 0; // End Passive Time = 0s
*scr_globals::passive.as<PBOOL>() = TRUE;
}
@ -30,7 +30,7 @@ namespace big
{
*scr_globals::passive.as<PBOOL>() = FALSE;
NETWORK::SET_LOCAL_PLAYER_AS_GHOST(false, false);
*g_tunables_service->get_tunable<int*>(-29732167) = 30000;
*g_tunables_service->get_tunable<int*>("VC_PASSIVE_TIME_AFTER_DISABLE"_J) = 30000;
PED::SET_PED_CONFIG_FLAG(self::ped, 342, false); // Disable NotAllowedToJackAnyPlayers
PED::SET_PED_CONFIG_FLAG(self::ped, 122, false); // Disable DisableMelee
PLAYER::SET_PLAYER_VEHICLE_DEFENSE_MODIFIER(self::ped, 1.f);

View File

@ -11,7 +11,7 @@ namespace big
virtual void on_tick() override
{
if (g_local_player)
if (g_local_player) [[likely]]
g_local_player->m_ped_intelligence->m_oxygen_time = 0;
}
};

View File

@ -9,9 +9,9 @@ namespace big
void looped::system_self_globals()
{
if (!*g_pointers->m_gta.m_network_player_mgr || !(*g_pointers->m_gta.m_network_player_mgr)->m_local_net_player
|| (*g_pointers->m_gta.m_network_player_mgr)->m_local_net_player->m_player_id == -1)
|| (*g_pointers->m_gta.m_network_player_mgr)->m_local_net_player->m_player_id == -1) [[unlikely]]
self::id = 0;
else
else [[likely]]
self::id = (*g_pointers->m_gta.m_network_player_mgr)->m_local_net_player->m_player_id;
self::ped = PLAYER::PLAYER_PED_ID();

View File

@ -9,15 +9,16 @@ namespace big
virtual void on_tick() override
{
if (auto tunable = g_tunables_service->get_tunable<PBOOL>(-298441869))
if (auto tunable = g_tunables_service->get_tunable<PBOOL>("KICK_OUT_OF_NIGHTCLUB_WITH_WEAPON"_J)) [[likely]]
{
if (*tunable == TRUE) [[unlikely]]
*tunable = FALSE;
}
}
virtual void on_disable() override
{
if (auto tunable = g_tunables_service->get_tunable<PBOOL>(-298441869))
if (auto tunable = g_tunables_service->get_tunable<PBOOL>("KICK_OUT_OF_NIGHTCLUB_WITH_WEAPON"_J)) [[likely]]
{
*tunable = TRUE;
}

View File

@ -16,7 +16,7 @@ namespace big
{
for (Hash tunable_hash : list_of_hashes)
{
if (auto tunable_ptr = g_tunables_service->get_tunable<PBOOL>(tunable_hash))
if (auto tunable_ptr = g_tunables_service->get_tunable<PBOOL>(tunable_hash)) [[likely]]
{
if (*tunable_ptr != FALSE)
{

View File

@ -12,21 +12,20 @@ namespace big
{
void looped::vehicle_allow_all_weapons()
{
if (g_local_player == nullptr || g_local_player->m_vehicle == nullptr)
if (g_local_player == nullptr || g_local_player->m_vehicle == nullptr) [[unlikely]]
return;
auto seat_info = g_pointers->m_gta.m_get_ped_seat(g_local_player->m_seat_info, g_local_player);
if (seat_info == nullptr)
if (seat_info == nullptr) [[unlikely]]
return;
if (g.vehicle.unlimited_weapons == false)
{
if (seat_info->anim_info)
if (seat_info->anim_info) [[likely]]
{
for (auto drive_by_anim_info : seat_info->anim_info->m_drive_by_anim_infos)
{
if (drive_by_anim_info->m_weapon_groups->m_groups.size() == 7 && drive_by_anim_info->m_weapon_groups->m_groups.contains(GROUP_PISTOL))
if (drive_by_anim_info->m_weapon_groups->m_groups.size() == 7 && drive_by_anim_info->m_weapon_groups->m_groups.contains(GROUP_PISTOL)) [[unlikely]]
{
drive_by_anim_info->m_weapon_groups->m_groups.clear();
drive_by_anim_info->m_weapon_groups->m_groups.append({GROUP_PISTOL});
@ -36,21 +35,21 @@ namespace big
return;
}
if (seat_info->anim_info == nullptr) //Should only occur in the R-88 and similar formula cars, so assume the user is in the driver's seat. Fix later, if other edge cases occur.
if (seat_info->anim_info == nullptr) [[unlikely]] //Should only occur in the R-88 and similar formula cars, so assume the user is in the driver's seat. Fix later, if other edge cases occur.
{
seat_info->anim_info = g_pointers->m_gta.m_vehicle_layout_metadata_mgr->m_drive_by_seat_defaults->m_driveby_standard_front_left;
}
for (auto drive_by_anim_info : seat_info->anim_info->m_drive_by_anim_infos)
{
if (drive_by_anim_info->m_weapon_groups->m_groups.size() != 7 && drive_by_anim_info->m_weapon_groups->m_groups.contains(GROUP_PISTOL))
if (drive_by_anim_info->m_weapon_groups->m_groups.size() != 7 && drive_by_anim_info->m_weapon_groups->m_groups.contains(GROUP_PISTOL)) [[unlikely]]
{
drive_by_anim_info->m_weapon_groups->m_groups.clear();
drive_by_anim_info->m_weapon_groups->m_groups.append({GROUP_PISTOL, GROUP_MG, GROUP_RIFLE, GROUP_SHOTGUN, GROUP_HEAVY, GROUP_SNIPER, GROUP_SMG});
}
}
if (auto vehicle_model_info = static_cast<CVehicleModelInfo*>(g_local_player->m_vehicle->m_model_info))
if (auto vehicle_model_info = static_cast<CVehicleModelInfo*>(g_local_player->m_vehicle->m_model_info)) [[likely]]
{
vehicle_model_info->set_vehicle_model_flag(CVehicleModelInfoFlags::DRIVER_NO_DRIVE_BY, false);
if (PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_AIM))

View File

@ -11,7 +11,7 @@ namespace big
const auto elapsed_time_in_ms = std::chrono::duration_cast<std::chrono::milliseconds>(time_now - last_time);
if (elapsed_time_in_ms >= 500ms)
if (elapsed_time_in_ms >= 500ms) [[unlikely]]
{
last_time = time_now;

View File

@ -8,7 +8,7 @@ namespace big
{
auto orig = g_hooking->get_original<hooks::read_bits_single>()(data, out_value, size, offset);
if (fuzzer::is_fuzzer_enabled())
if (fuzzer::is_fuzzer_enabled()) [[unlikely]]
{
fuzzer::handle_vtable_write(out_value, sizeof(int), __FUNCTION__);
*out_value = fuzzer::fuzz_bits(*out_value, size);

View File

@ -7,7 +7,7 @@ namespace big
{
auto orig = g_hooking->m_sync_data_reader_hook.get_original<decltype(&hooks::sync_reader_serialize_dword)>(1)(_this, dword, size);
if (fuzzer::is_fuzzer_enabled())
if (fuzzer::is_fuzzer_enabled()) [[unlikely]]
{
fuzzer::handle_vtable_write(dword, sizeof(uint32_t), __FUNCTION__);
*dword = fuzzer::fuzz_bits(*dword, size);
@ -21,7 +21,7 @@ namespace big
{
auto orig = g_hooking->m_sync_data_reader_hook.get_original<decltype(&hooks::sync_reader_serialize_word)>(2)(_this, word, size);
if (fuzzer::is_fuzzer_enabled())
if (fuzzer::is_fuzzer_enabled()) [[unlikely]]
{
fuzzer::handle_vtable_write(word, sizeof(uint16_t), __FUNCTION__);
*word = fuzzer::fuzz_bits(*word, size);
@ -35,7 +35,7 @@ namespace big
{
auto orig = g_hooking->m_sync_data_reader_hook.get_original<decltype(&hooks::sync_reader_serialize_byte)>(3)(_this, byte, size);
if (fuzzer::is_fuzzer_enabled())
if (fuzzer::is_fuzzer_enabled()) [[unlikely]]
{
fuzzer::handle_vtable_write(byte, sizeof(uint8_t), __FUNCTION__);
*byte = fuzzer::fuzz_bits(*byte, size);
@ -49,7 +49,7 @@ namespace big
{
auto orig = g_hooking->m_sync_data_reader_hook.get_original<decltype(&hooks::sync_reader_serialize_int32)>(4)(_this, i, size);
if (fuzzer::is_fuzzer_enabled())
if (fuzzer::is_fuzzer_enabled()) [[unlikely]]
{
fuzzer::handle_vtable_write(i, sizeof(int32_t), __FUNCTION__);
*i = fuzzer::fuzz_signed_bits(*i, size);
@ -63,7 +63,7 @@ namespace big
{
auto orig = g_hooking->m_sync_data_reader_hook.get_original<decltype(&hooks::sync_reader_serialize_int16)>(5)(_this, i, size);
if (fuzzer::is_fuzzer_enabled())
if (fuzzer::is_fuzzer_enabled()) [[unlikely]]
{
fuzzer::handle_vtable_write(i, sizeof(int16_t), __FUNCTION__);
*i = fuzzer::fuzz_signed_bits(*i, size);
@ -77,7 +77,7 @@ namespace big
{
auto orig = g_hooking->m_sync_data_reader_hook.get_original<decltype(&hooks::sync_reader_serialize_signed_byte)>(6)(_this, i, size);
if (fuzzer::is_fuzzer_enabled())
if (fuzzer::is_fuzzer_enabled()) [[unlikely]]
{
fuzzer::handle_vtable_write(i, sizeof(int8_t), __FUNCTION__);
*i = fuzzer::fuzz_signed_bits(*i, size);
@ -91,7 +91,7 @@ namespace big
{
auto orig = g_hooking->m_sync_data_reader_hook.get_original<decltype(&hooks::sync_reader_serialize_bool)>(7)(_this, flag, size);
if (fuzzer::is_fuzzer_enabled())
if (fuzzer::is_fuzzer_enabled()) [[unlikely]]
{
fuzzer::handle_vtable_write(flag, sizeof(bool), __FUNCTION__);
*flag = fuzzer::fuzz_bool(*flag);
@ -105,7 +105,7 @@ namespace big
{
auto orig = g_hooking->m_sync_data_reader_hook.get_original<decltype(&hooks::sync_reader_serialize_signed_float)>(16)(_this, flt, divisor, size);
if (fuzzer::is_fuzzer_enabled())
if (fuzzer::is_fuzzer_enabled()) [[unlikely]]
{
fuzzer::handle_vtable_write(flt, sizeof(float), __FUNCTION__);
*flt = fuzzer::fuzz_float(*flt, size, divisor, true);
@ -119,7 +119,7 @@ namespace big
{
auto orig = g_hooking->m_sync_data_reader_hook.get_original<decltype(&hooks::sync_reader_serialize_float)>(17)(_this, flt, divisor, size);
if (fuzzer::is_fuzzer_enabled())
if (fuzzer::is_fuzzer_enabled()) [[unlikely]]
{
fuzzer::handle_vtable_write(flt, sizeof(float), __FUNCTION__);
*flt = fuzzer::fuzz_float(*flt, size, divisor, false);
@ -133,7 +133,7 @@ namespace big
{
auto orig = g_hooking->m_sync_data_reader_hook.get_original<decltype(&hooks::sync_reader_serialize_net_id)>(18)(_this, id);
if (fuzzer::is_fuzzer_enabled())
if (fuzzer::is_fuzzer_enabled()) [[unlikely]]
{
fuzzer::handle_vtable_write(id, sizeof(uint16_t), __FUNCTION__);
*id = fuzzer::fuzz_network_id(*id);
@ -147,7 +147,7 @@ namespace big
{
auto orig = g_hooking->m_sync_data_reader_hook.get_original<decltype(&hooks::sync_reader_serialize_vec3)>(19)(_this, vec, divisor, size);
if (fuzzer::is_fuzzer_enabled())
if (fuzzer::is_fuzzer_enabled()) [[unlikely]]
{
fuzzer::handle_vtable_write(vec, sizeof(rage::fvector3), __FUNCTION__);
*vec = fuzzer::fuzz_vector(*vec, size, divisor, false);
@ -161,7 +161,7 @@ namespace big
{
auto orig = g_hooking->m_sync_data_reader_hook.get_original<decltype(&hooks::sync_reader_serialize_vec3_signed)>(21)(_this, vec, divisor, size);
if (fuzzer::is_fuzzer_enabled())
if (fuzzer::is_fuzzer_enabled()) [[unlikely]]
{
fuzzer::handle_vtable_write(vec, sizeof(rage::fvector3), __FUNCTION__);
*vec = fuzzer::fuzz_vector(*vec, size, divisor, true);
@ -175,7 +175,7 @@ namespace big
{
auto orig = g_hooking->m_sync_data_reader_hook.get_original<decltype(&hooks::sync_reader_serialize_array)>(23)(_this, array, size);
if (fuzzer::is_fuzzer_enabled())
if (fuzzer::is_fuzzer_enabled()) [[unlikely]]
{
fuzzer::handle_vtable_write(array, size / 8, __FUNCTION__);
fuzzer::fuzz_data(array, size / 8);

View File

@ -6,7 +6,7 @@ namespace big
{
LRESULT hooks::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
if (g_running)
if (g_running) [[likely]]
{
g_renderer.wndproc(hwnd, msg, wparam, lparam);
}

View File

@ -64,7 +64,7 @@ namespace big
g_fiber_pool->queue_job([] {
session::join_session(gta_util::get_network()->m_last_joined_session.m_session_info);
});
g_notification_service.push_warning("KICKED"_T.data(), "You have been desync kicked. Rejoining previous session...");
g_notification_service.push_warning("KICKED"_T.data(), "You have been desync kicked. Rejoining previous session..."); // TODO: add to translations
}
else
{

View File

@ -7,7 +7,7 @@ namespace big
{
bool hooks::http_start_request(void* request, const char* uri)
{
if (strstr(uri, "Bonus"))
if (strstr(uri, "Bonus")) [[unlikely]]
{
// This is for worst case scenario where a report does slip through the cracks...
// Lets make it go somewhere it doesn't matter -- don't let the reports reach their servers!

View File

@ -7,11 +7,11 @@ namespace big
{
bool inline is_address_in_game_region(int64_t address)
{
if(!address)
if(!address) [[unlikely]]
return false;
static int64_t moduleBase = NULL;
static int64_t moduleSize = NULL;
if (!moduleBase || !moduleSize)
if (!moduleBase || !moduleSize) [[unlikely]]
{
MODULEINFO info;
if (!GetModuleInformation(GetCurrentProcess(), GetModuleHandle(0), &info, sizeof(info)))
@ -42,10 +42,10 @@ namespace big
int64_t f2 = *reinterpret_cast<int64_t*>(cb + 0x100);
int64_t f3 = *reinterpret_cast<int64_t*>(cb + 0x1A0);
if (!is_address_in_game_region(f1) || !is_address_in_game_region(f2) || !is_address_in_game_region(f3))
if (!is_address_in_game_region(f1) || !is_address_in_game_region(f2) || !is_address_in_game_region(f3)) [[likely]]
return false;
if(*reinterpret_cast<uint8_t*>(f1) != 0xE9)
if(*reinterpret_cast<uint8_t*>(f1) != 0xE9) [[likely]]
return false;
return true;
@ -58,9 +58,9 @@ namespace big
int hooks::queue_dependency(void* a1, int a2, int64_t dependency)
{
if (is_unwanted_dependency(dependency))
if (is_unwanted_dependency(dependency)) [[unlikely]]
{
LOG(INFO) << "Blocking AC Verifier " << std::hex << *reinterpret_cast<int64_t*>(dependency + 0x60) - reinterpret_cast<int64_t>(GetModuleHandleA(0));
LOG(INFO) << "Blocking AC Verifier " << HEX_TO_UPPER(*reinterpret_cast<int64_t*>(dependency + 0x60) - reinterpret_cast<int64_t>(GetModuleHandle(NULL)));
ac_verifier* verifier = reinterpret_cast<ac_verifier*>(dependency - 0x30);
verifier->m_delay = INT_MAX; // makes it so these won't queue in the future
*reinterpret_cast<void**>(dependency + 0x60) = nullsub;

View File

@ -24,12 +24,12 @@ namespace big
void* hooks::allocate_memory_reliable(rage::netConnection* cxn, int required_memory)
{
if (!cxn || !required_memory)
if (!cxn || !required_memory) [[unlikely]]
return nullptr;
auto memory = reinterpret_cast<rage::sysMemAllocator*>(cxn->m_allocator)->Allocate(required_memory, 0, 0);
if (memory)
if (memory) [[likely]]
return memory;
LOG(WARNING) << "Failed to allocate " << required_memory << " bytes for reliable message, free space: "

View File

@ -1667,7 +1667,7 @@ namespace big
static bool init = ([] { sync_node_finder::init(); }(), true);
veh_creation_model = std::nullopt;
if (tree->m_child_node_count && tree->m_next_sync_node && check_node(tree->m_next_sync_node, g.m_syncing_player, object))
if (tree->m_child_node_count && tree->m_next_sync_node && check_node(tree->m_next_sync_node, g.m_syncing_player, object)) [[unlikely]]
{
return false;
}

View File

@ -4,7 +4,7 @@ namespace big
{
bool hooks::fragment_physics_crash_2(float* a1, float* a2)
{
if (!a1 || !a2)
if (!a1 || !a2) [[unlikely]]
return false;
return g_hooking->get_original<hooks::fragment_physics_crash_2>()(a1, a2);

View File

@ -11,7 +11,7 @@ namespace big
bool hooks::handle_join_request(Network* network, rage::snSession* session, rage::rlGamerInfo* player_info, CJoinRequestContext* ctx, BOOL is_transition_session)
{
if (auto player = g_player_database_service->get_player_by_rockstar_id(player_info->m_gamer_handle.m_rockstar_id);
player && player->block_join)
player && player->block_join) [[unlikely]]
{
CMsgJoinResponse response{};
response.m_status_code = player->block_join_reason;
@ -20,7 +20,7 @@ namespace big
std::vformat("BLOCK_JOIN_INFO"_T, std::make_format_args(player->name)));
return false;
}
else
else [[likely]]
{
return g_hooking->get_original<hooks::handle_join_request>()(network, session, player_info, ctx, is_transition_session);
}

View File

@ -4,11 +4,11 @@ namespace big
{
void hooks::invalid_decal(uintptr_t a1, int a2)
{
if (a1 && a2 == 2)
if (a1 && a2 == 2) [[unlikely]]
//*(*(*(a1 + 0x48) + 0x30) + 0x2C8)
if (const auto ptr = *reinterpret_cast<uintptr_t*>((a1 + 0x48)); ptr)
if (const auto ptr2 = *reinterpret_cast<uintptr_t*>((ptr + 0x30)); ptr2)
if (*reinterpret_cast<uintptr_t*>(ptr2 + 0x2C8) == 0)
if (const auto ptr = *reinterpret_cast<uintptr_t*>((a1 + 0x48)); ptr) [[unlikely]]
if (const auto ptr2 = *reinterpret_cast<uintptr_t*>((ptr + 0x30)); ptr2) [[unlikely]]
if (*reinterpret_cast<uintptr_t*>(ptr2 + 0x2C8) == 0) [[unlikely]]
return;
g_hooking->get_original<hooks::invalid_decal>()(a1, a2);

View File

@ -4,7 +4,7 @@ namespace big
{
void hooks::invalid_mods_crash_detour(int64_t a1, int64_t a2, int a3, char a4)
{
if (!*(int64_t*)(a1 + 0xD8))
if (!*(int64_t*)(a1 + 0xD8)) [[unlikely]]
return;
g_hooking->get_original<hooks::invalid_mods_crash_detour>()(a1, a2, a3, a4);
}

View File

@ -6,7 +6,7 @@ namespace big
{
void hooks::received_clone_create(CNetworkObjectMgr* mgr, CNetGamePlayer* src, CNetGamePlayer* dst, eNetObjType object_type, int32_t object_id, int32_t object_flag, rage::datBitBuffer* buffer, int32_t timestamp)
{
if (object_type < eNetObjType::NET_OBJ_TYPE_AUTOMOBILE || object_type > eNetObjType::NET_OBJ_TYPE_TRAIN)
if (object_type < eNetObjType::NET_OBJ_TYPE_AUTOMOBILE || object_type > eNetObjType::NET_OBJ_TYPE_TRAIN) [[unlikely]]
{
notify::crash_blocked(src, "out of bounds object type");
return;
@ -14,14 +14,14 @@ namespace big
auto plyr = g_player_service->get_by_id(src->m_player_id);
if (plyr && plyr->block_clone_create)
if (plyr && plyr->block_clone_create) [[unlikely]]
return;
g.m_syncing_player = src;
g.m_syncing_object_type = object_type;
g.debug.fuzzer.thread_id = GetCurrentThreadId();
if (g.debug.fuzzer.enabled_object_types[(int)object_type])
if (g.debug.fuzzer.enabled_object_types[(int)object_type]) [[unlikely]]
g.debug.fuzzer.active = true;
g.debug.fuzzer.syncing_object_id = object_id;
g_hooking->get_original<hooks::received_clone_create>()(mgr, src, dst, object_type, object_id, object_flag, buffer, timestamp);

View File

@ -5,7 +5,7 @@ namespace big
{
void hooks::received_clone_remove(CNetworkObjectMgr* mgr, CNetGamePlayer* src, CNetGamePlayer* dst, int16_t object_id, uint32_t ownership_token)
{
if (dst->m_player_info->m_ped->m_net_object->m_object_id == object_id)
if (dst->m_player_info->m_ped->m_net_object->m_object_id == object_id) [[unlikely]]
{
notify::crash_blocked(src, "player ped removal");
return;

View File

@ -6,13 +6,13 @@ namespace big
{
eAckCode hooks::received_clone_sync(CNetworkObjectMgr* mgr, CNetGamePlayer* src, CNetGamePlayer* dst, eNetObjType object_type, uint16_t object_id, rage::datBitBuffer* buffer, uint16_t unk, uint32_t timestamp)
{
if (object_type < eNetObjType::NET_OBJ_TYPE_AUTOMOBILE || object_type > eNetObjType::NET_OBJ_TYPE_TRAIN)
if (object_type < eNetObjType::NET_OBJ_TYPE_AUTOMOBILE || object_type > eNetObjType::NET_OBJ_TYPE_TRAIN) [[unlikely]]
{
notify::crash_blocked(src, "out of bounds object type");
return eAckCode::ACKCODE_FAIL;
}
if (auto net_obj = g_pointers->m_gta.m_get_net_object(mgr, object_id, true); net_obj && net_obj->m_object_type != (int16_t)object_type)
if (auto net_obj = g_pointers->m_gta.m_get_net_object(mgr, object_id, true); net_obj && net_obj->m_object_type != (int16_t)object_type) [[unlikely]]
{
notify::crash_blocked(src, "incorrect object type");
return eAckCode::ACKCODE_FAIL;
@ -20,14 +20,14 @@ namespace big
auto plyr = g_player_service->get_by_id(src->m_player_id);
if (plyr && plyr->block_clone_sync)
if (plyr && plyr->block_clone_sync) [[unlikely]]
return eAckCode::ACKCODE_FAIL;
g.m_syncing_player = src;
g.m_syncing_object_type = object_type;
g.debug.fuzzer.thread_id = GetCurrentThreadId();
if (g.debug.fuzzer.enabled_object_types[(int)object_type])
if (g.debug.fuzzer.enabled_object_types[(int)object_type]) [[unlikely]]
g.debug.fuzzer.active = true;
g.debug.fuzzer.syncing_object_id = object_id;
auto ret = g_hooking->get_original<received_clone_sync>()(mgr, src, dst, object_type, object_id, buffer, unk, timestamp);

View File

@ -378,14 +378,14 @@ namespace big
void hooks::received_event(rage::netEventMgr* event_manager, CNetGamePlayer* source_player, CNetGamePlayer* target_player, uint16_t event_id, int event_index, int event_handled_bitset, int buffer_size, rage::datBitBuffer* buffer)
{
if (event_id > 91u)
if (event_id > 91u) [[unlikely]]
{
g_pointers->m_gta.m_send_event_ack(event_manager, source_player, target_player, event_index, event_handled_bitset);
return;
}
const auto event_name = *(char**)((DWORD64)event_manager + 8i64 * event_id + 243376);
if (event_name == nullptr || source_player == nullptr || source_player->m_player_id < 0 || source_player->m_player_id >= 32)
if (event_name == nullptr || source_player == nullptr || source_player->m_player_id < 0 || source_player->m_player_id >= 32) [[unlikely]]
{
g_pointers->m_gta.m_send_event_ack(event_manager, source_player, target_player, event_index, event_handled_bitset);
return;
@ -393,7 +393,7 @@ namespace big
auto plyr = g_player_service->get_by_id(source_player->m_player_id);
if (plyr && plyr->block_net_events)
if (plyr && plyr->block_net_events) [[unlikely]]
{
g_pointers->m_gta.m_send_event_ack(event_manager, source_player, target_player, event_index, event_handled_bitset);
return;

View File

@ -5,12 +5,12 @@ namespace big
{
__int64 hooks::render_big_ped(__int64 renderer, CPed* ped, __int64 a3, __int64 a4)
{
if (*(int*)(((__int64)(*g_pointers->m_gta.m_draw_handler_mgr) + 0x14730)) >= 512)
if (*(int*)(((__int64)(*g_pointers->m_gta.m_draw_handler_mgr) + 0x14730)) >= 512) [[unlikely]]
{
*(int*)(a4 + 4) = -2;
return a4 + 0x14;
}
else
else [[likely]]
{
return g_hooking->get_original<hooks::render_big_ped>()(renderer, ped, a3, a4);
}

View File

@ -5,14 +5,14 @@ namespace big
{
void hooks::render_entity(__int64 renderer, rage::fwEntity* entity, int unk, bool a4)
{
if (*(int*)(((__int64)(*g_pointers->m_gta.m_draw_handler_mgr) + 0x14730)) >= 512)
if (*(int*)(((__int64)(*g_pointers->m_gta.m_draw_handler_mgr) + 0x14730)) >= 512) [[unlikely]]
{
*(int*)(renderer + 4) &= ~0x80000000;
*(int*)(renderer + 4) &= ~0x40000000;
*(int*)(renderer + 4) |= (a4 & 1) << 30;
*(int*)renderer = -2;
}
else
else [[likely]]
{
g_hooking->get_original<hooks::render_entity>()(renderer, entity, unk, a4);
}

View File

@ -5,11 +5,11 @@ namespace big
{
void* hooks::render_ped(__int64 renderer, CPed* ped, __int64 a3, __int64 a4)
{
if (*(int*)(((__int64)(*g_pointers->m_gta.m_draw_handler_mgr) + 0x14730)) >= 499)
if (*(int*)(((__int64)(*g_pointers->m_gta.m_draw_handler_mgr) + 0x14730)) >= 499) [[unlikely]]
{
return nullptr;
}
else
else [[likely]]
{
return g_hooking->get_original<hooks::render_ped>()(renderer, ped, a3, a4);
}

View File

@ -18,7 +18,7 @@ namespace big
auto object = reinterpret_cast<TaskObject*>(info + 0x30);
g_hooking->get_original<hooks::serialize_parachute_task>()(info, serializer);
if (object->m_entity && object->m_entity->m_entity_type != 5)
if (object->m_entity && object->m_entity->m_entity_type != 5) [[unlikely]]
{
g_pointers->m_gta.m_remove_reference(object->m_entity, &object->m_entity);
notify::crash_blocked(g.m_syncing_player, "invalid parachute object type");

View File

@ -28,7 +28,7 @@ namespace big
void hooks::serialize_take_off_ped_variation_task(ClonedTakeOffPedVariationInfo* info, rage::CSyncDataBase* serializer)
{
g_hooking->get_original<hooks::serialize_take_off_ped_variation_task>()(info, serializer);
if (!is_valid_parachute_model(info->m_prop_hash))
if (!is_valid_parachute_model(info->m_prop_hash)) [[unlikely]]
{
notify::crash_blocked(g.m_syncing_player, "invalid parachute model");
info->m_prop_hash = 0;

View File

@ -7,7 +7,7 @@ namespace big
// enter crash func
// TODO: this doesn't block the crash completely
if (*(uint64_t*)(_this + 0x100))
if (*(uint64_t*)(_this + 0x100)) [[likely]]
return g_hooking->get_original<hooks::task_ambient_clips>()(_this, a2, a3);
return 0;

View File

@ -6,9 +6,9 @@ namespace big
{
if (a2 == 1 && a3 == 1) // enter crash func
{
if (auto ptr = *(uint64_t*)(_this + 16))
if (auto ptr2 = *(uint64_t*)(ptr + 80))
if (auto ptr3 = *(uint64_t*)(ptr2 + 64))
if (auto ptr = *(uint64_t*)(_this + 16)) [[likely]]
if (auto ptr2 = *(uint64_t*)(ptr + 80)) [[likely]]
if (auto ptr3 = *(uint64_t*)(ptr2 + 64)) [[likely]]
return g_hooking->get_original<hooks::task_parachute_object>()(_this, a2, a3);
return 0;
}

View File

@ -5,7 +5,7 @@ namespace big
{
bool hooks::run_script_threads(uint32_t ops_to_execute)
{
if (g_running)
if (g_running) [[likely]]
{
g_script_mgr.tick();
}

View File

@ -33,16 +33,17 @@ namespace big
m_call_context.reset();
}
template<int index, bool fix_vectors>
template<int index, bool should_fix_vectors>
constexpr void end_call()
{
// TODO: try to get rid of this
if (!m_are_handlers_cached)
[[assume((cache_handlers(), m_are_handlers_cached == true))]];
if (!m_are_handlers_cached) [[unlikely]]
cache_handlers();
m_handlers[index](&m_call_context);
if constexpr (fix_vectors)
this->fix_vectors();
if constexpr (should_fix_vectors)
fix_vectors();
}
template<typename T>
@ -64,7 +65,8 @@ namespace big
static rage::scrNativeHandler* get_handlers()
{
if (!m_are_handlers_cached)
[[assume((cache_handlers(), m_are_handlers_cached == true))]];
if (!m_are_handlers_cached) [[unlikely]]
cache_handlers();
return m_handlers;

View File

@ -26,7 +26,7 @@ namespace big
void NETWORK_SET_THIS_SCRIPT_IS_NETWORK_SCRIPT(rage::scrNativeCallContext* src)
{
if (src->get_arg<int>(2) != -1 && src->get_arg<uint32_t>(2) >= 0x100)
if (src->get_arg<int>(2) != -1 && src->get_arg<uint32_t>(2) >= 0x100) [[unlikely]]
{
notify::crash_blocked(nullptr, "out of bounds instance id");
return;
@ -37,7 +37,7 @@ namespace big
void NETWORK_TRY_TO_SET_THIS_SCRIPT_IS_NETWORK_SCRIPT(rage::scrNativeCallContext* src)
{
if (src->get_arg<int>(2) != -1 && src->get_arg<uint32_t>(2) >= 0x100)
if (src->get_arg<int>(2) != -1 && src->get_arg<uint32_t>(2) >= 0x100) [[unlikely]]
{
notify::crash_blocked(nullptr, "out of bounds instance id");
src->set_return_value<BOOL>(FALSE);

View File

@ -75,7 +75,7 @@ namespace big
void renderer::on_present()
{
if (m_font_mgr.can_use())
if (m_font_mgr.can_use()) [[likely]]
{
new_frame();
for (const auto& cb : m_dx_callbacks | std::views::values)

View File

@ -83,7 +83,7 @@ namespace big
persist_weapon_loadout = get_loadout(g.persist_weapons.weapon_loadout_file);
}
if (g_local_player == nullptr || g_local_player->m_player_info == nullptr || g_local_player->m_player_info->m_game_state == eGameState::InMPCutscene || STREAMING::IS_PLAYER_SWITCH_IN_PROGRESS() || DLC::GET_IS_LOADING_SCREEN_ACTIVE())
if (g_local_player == nullptr || g_local_player->m_player_info == nullptr || g_local_player->m_player_info->m_game_state == eGameState::InMPCutscene || STREAMING::IS_PLAYER_SWITCH_IN_PROGRESS() || DLC::GET_IS_LOADING_SCREEN_ACTIVE()) [[unlikely]]
{
return;
}
@ -150,7 +150,7 @@ namespace big
{
Player player = self::id;
Ped player_ped = self::ped;
if (PED::IS_PED_DEAD_OR_DYING(player_ped, true))
if (PED::IS_PED_DEAD_OR_DYING(player_ped, true)) [[unlikely]]
return;
for (auto weapon : loadout.weapons)

View File

@ -51,7 +51,7 @@ namespace big
std::unique_lock lock(m_lock);
m_job_stack.push({func, location});
if (m_allocated_thread_count - m_busy_threads < m_job_stack.size())
if (m_allocated_thread_count - m_busy_threads < m_job_stack.size()) [[unlikely]]
{
LOG(WARNING) << "Thread pool potentially starved, resizing to accommodate for load.";
@ -79,9 +79,9 @@ namespace big
return !m_job_stack.empty() || !m_accept_jobs;
});
if (!m_accept_jobs)
if (!m_accept_jobs) [[unlikely]]
break;
if (m_job_stack.empty())
if (m_job_stack.empty()) [[likely]]
continue;
thread_pool_job job = m_job_stack.top();