feat(cache): expand ped (#1156)

This commit is contained in:
Aure7138
2023-04-02 00:37:26 +08:00
committed by GitHub
parent 4922e60d89
commit 205836dd74
14 changed files with 215 additions and 62 deletions

View File

@ -9,6 +9,9 @@
#include "thread_pool.hpp"
#include "util/session.hpp"
#include "yim_fipackfile.hpp"
#include "util/vehicle.hpp"
#include "util/misc.hpp"
#include "util/model_info.hpp"
namespace big
{
@ -50,6 +53,11 @@ namespace big
return m_update_state;
}
void gta_data_service::set_state(eGtaDataUpdateState state)
{
m_update_state = state;
}
void gta_data_service::update_in_online()
{
m_update_state = eGtaDataUpdateState::WAITING_FOR_SINGLE_PLAYER;
@ -66,7 +74,7 @@ namespace big
{
script::get_current()->yield(100ms);
}
m_update_state = eGtaDataUpdateState::UPDATING;
rebuild_cache();
});
}
@ -75,6 +83,15 @@ namespace big
{
m_update_state = eGtaDataUpdateState::WAITING_FOR_SINGLE_PLAYER;
g_fiber_pool->queue_job([this] {
m_update_state = eGtaDataUpdateState::UPDATING;
rebuild_cache();
});
}
void gta_data_service::update_on_init()
{
m_update_state = eGtaDataUpdateState::ON_INIT_WAITING;
g_thread_pool->push([this] {
rebuild_cache();
});
}
@ -226,8 +243,6 @@ namespace big
void gta_data_service::rebuild_cache()
{
m_update_state = eGtaDataUpdateState::UPDATING;
using hash_array = std::vector<std::uint32_t>;
hash_array mapped_peds;
hash_array mapped_vehicles;
@ -243,7 +258,7 @@ namespace big
LOG(INFO) << "Rebuilding cache started...";
yim_fipackfile::for_each_fipackfile([&](yim_fipackfile& rpf_wrapper) {
yim_fipackfile::add_wrapper_call_back([&](yim_fipackfile& rpf_wrapper) {
const auto files = rpf_wrapper.get_file_paths();
for (const auto& file : files)
{
@ -281,14 +296,15 @@ namespace big
std::strncpy(veh.m_name, name, sizeof(veh.m_name));
const auto manufacturer_display = item.child("vehicleMakeName").text().as_string();
std::strncpy(veh.m_display_manufacturer, HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(manufacturer_display), sizeof(veh.m_display_manufacturer));
std::strncpy(veh.m_display_manufacturer, manufacturer_display, sizeof(veh.m_display_manufacturer));
const auto game_name = item.child("gameName").text().as_string();
std::strncpy(veh.m_display_name, HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(game_name), sizeof(veh.m_display_name));
std::strncpy(veh.m_display_name, game_name, sizeof(veh.m_display_name));
char vehicle_class[32];
std::sprintf(vehicle_class, "VEH_CLASS_%i", VEHICLE::GET_VEHICLE_CLASS_FROM_NAME(hash));
std::strncpy(veh.m_vehicle_class, HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(vehicle_class), sizeof(veh.m_vehicle_class));
const auto vehicle_class = item.child("vehicleClass").text().as_string();
constexpr auto enum_prefix_len = 3;
if (std::strlen(vehicle_class) > enum_prefix_len)
std::strncpy(veh.m_vehicle_class, vehicle_class + enum_prefix_len, sizeof(veh.m_vehicle_class));
veh.m_hash = hash;
@ -321,8 +337,7 @@ namespace big
std::strncpy(weapon.m_name, name, sizeof(weapon.m_name));
const auto display_name = HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(human_name_hash);
std::strncpy(weapon.m_display_name, display_name, sizeof(weapon.m_name));
std::strncpy(weapon.m_display_name, human_name_hash, sizeof(weapon.m_display_name));
auto weapon_flags = std::string(item.child("WeaponFlags").text().as_string());
@ -391,11 +406,78 @@ namespace big
parse_ped(peds, mapped_peds, doc);
});
}
else if (std::string str = rpf_wrapper.get_name(); (str.find("componentpeds") != std::string::npos || str.find("streamedpeds") != std::string::npos || str.find("mppatches") != std::string::npos || str.find("cutspeds") != std::string::npos) && file.extension() == ".yft")
{
const auto name = file.stem().string();
const auto hash = rage::joaat(name);
if (std::find(mapped_peds.begin(), mapped_peds.end(), hash) != mapped_peds.end())
continue;
mapped_peds.emplace_back(hash);
auto ped = ped_item{};
std::strncpy(ped.m_name, name.c_str(), sizeof(ped.m_name));
ped.m_hash = hash;
peds.emplace_back(std::move(ped));
}
}
return files.size();
});
if (state() == eGtaDataUpdateState::UPDATING)
{
yim_fipackfile::for_each_fipackfile();
}
else
{
while (state() != eGtaDataUpdateState::ON_INIT_UPDATE_END)
std::this_thread::sleep_for(100ms);
}
static bool translate_lebel = false;
g_fiber_pool->queue_job([&] {
for (auto& item : vehicles)
{
std::strncpy(item.m_display_manufacturer, HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(item.m_display_manufacturer), sizeof(item.m_display_manufacturer));
std::strncpy(item.m_display_name, HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(item.m_display_name), sizeof(item.m_display_name));
char vehicle_class[32];
std::sprintf(vehicle_class, "VEH_CLASS_%i", VEHICLE::GET_VEHICLE_CLASS_FROM_NAME(item.m_hash));
std::strncpy(item.m_vehicle_class, HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(vehicle_class), sizeof(item.m_vehicle_class));
}
for (auto& item : weapons)
{
std::strncpy(item.m_display_name, HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(item.m_display_name), sizeof(item.m_display_name));
}
for (auto it = peds.begin(); it != peds.end();)
{
if (CPedModelInfo* info = model_info::get_model<CPedModelInfo*>(it->m_hash))
{
static std::array<std::string, 30> ped_types = {"PLAYER_0", "PLAYER_1", "NETWORK_PLAYER", "PLAYER_2", "CIVMALE", "CIVFEMALE", "COP", "GANG_ALBANIAN", "GANG_BIKER_1", "GANG_BIKER_2", "GANG_BIKER_2", "GANG_RUSSIAN", "GANG_RUSSIAN_2", "GANG_RUSSIAN_2", "GANG_JAMAICAN", "GANG_AFRICAN_AMERICAN", "GANG_KOREAN", "GANG_CHINESE_JAPANESE", "GANG_PUERTO_RICAN", "DEALER", "MEDIC", "FIREMAN", "CRIMINAL", "BUM", "PROSTITUTE", "SPECIAL", "MISSION", "SWAT", "ANIMAL", "ARMY"};
std::strncpy(it->m_ped_type, ped_types[info->ped_type].c_str(), sizeof(it->m_ped_type));
++it;
}
else
{
peds.erase(it);
}
}
translate_lebel = true;
});
while (!translate_lebel)
{
if (state() == eGtaDataUpdateState::UPDATING)
script::get_current()->yield();
else
std::this_thread::sleep_for(100ms);
}
m_update_state = eGtaDataUpdateState::IDLE;
LOG(INFO) << "Cache has been rebuilt.\n\tPeds: " << peds.size() << "\n\tVehicles: " << vehicles.size()
<< "\n\tWeapons: " << weapons.size();