|
|
|
@ -128,14 +128,20 @@ namespace big
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void gta_data_service::load_from_file(std::string file_path, std::string etag_path, std::string url, void(gta_data_service::* load_func)(file), std::string data_name)
|
|
|
|
|
void gta_data_service::load_from_file(std::string file_path, std::string etag_path, std::string url, bool(gta_data_service::* load_func)(file), std::string data_name)
|
|
|
|
|
{
|
|
|
|
|
file file_to_load(g_file_manager->get_project_file(file_path));
|
|
|
|
|
|
|
|
|
|
if (file_to_load.exists())
|
|
|
|
|
{
|
|
|
|
|
(this->*load_func)(file_to_load);
|
|
|
|
|
LOG(INFO) << "Data loaded: " + data_name;
|
|
|
|
|
if ((this->*load_func)(file_to_load))
|
|
|
|
|
{
|
|
|
|
|
LOG(INFO) << "Data loaded: " + data_name;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG(INFO) << "Data invalid: " + data_name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_thread_pool->push([this, file_path, etag_path, url, load_func, data_name]() {
|
|
|
|
@ -152,8 +158,24 @@ namespace big
|
|
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
|
{
|
|
|
|
|
(this->*load_func)(file_to_load);
|
|
|
|
|
LOG(INFO) << "Data updated: " + data_name;
|
|
|
|
|
if ((this->*load_func)(file_to_load))
|
|
|
|
|
{
|
|
|
|
|
LOG(INFO) << "Data loaded: " + data_name;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG(INFO) << "Data invalid: " + data_name;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
std::ofstream file_ofstream(file_path, std::ios::binary | std::ios::trunc);
|
|
|
|
|
file_ofstream << "";
|
|
|
|
|
|
|
|
|
|
std::ofstream file_etag_ofstream(etag_path, std::ios::binary | std::ios::trunc);
|
|
|
|
|
file_etag_ofstream << "";
|
|
|
|
|
}
|
|
|
|
|
catch (...) { }
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (!file_to_load.exists())
|
|
|
|
@ -164,158 +186,182 @@ namespace big
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gta_data_service::load_vehicles(file file_to_load)
|
|
|
|
|
bool gta_data_service::load_vehicles(file file_to_load)
|
|
|
|
|
{
|
|
|
|
|
m_vehicle_class_arr.clear();
|
|
|
|
|
m_vehicle_hash_idx_map.clear();
|
|
|
|
|
m_vehicle_item_arr.clear();
|
|
|
|
|
|
|
|
|
|
std::ifstream file(file_to_load.get_path());
|
|
|
|
|
nlohmann::json all_vehicles;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
file >> all_vehicles;
|
|
|
|
|
|
|
|
|
|
if (!all_vehicles.is_array())
|
|
|
|
|
{
|
|
|
|
|
throw "Invalid json format.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_vehicle_class_arr.clear();
|
|
|
|
|
m_vehicle_hash_idx_map.clear();
|
|
|
|
|
m_vehicle_item_arr.clear();
|
|
|
|
|
|
|
|
|
|
for (auto& item_json : all_vehicles)
|
|
|
|
|
{
|
|
|
|
|
if (
|
|
|
|
|
item_json["Hash"].is_null() ||
|
|
|
|
|
item_json["Name"].is_null() ||
|
|
|
|
|
!item_json["Bones"].is_array() ||
|
|
|
|
|
item_json["Bones"][0] == "stub"
|
|
|
|
|
) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto item = vehicle_item(item_json);
|
|
|
|
|
|
|
|
|
|
m_vehicle_hash_idx_map[item_json["Hash"]] = (int)m_vehicle_item_arr.size();
|
|
|
|
|
|
|
|
|
|
m_vehicle_item_arr.push_back(item);
|
|
|
|
|
|
|
|
|
|
if (std::find(m_vehicle_class_arr.begin(), m_vehicle_class_arr.end(), item.clazz) == m_vehicle_class_arr.end())
|
|
|
|
|
{
|
|
|
|
|
m_vehicle_class_arr.push_back(item.clazz);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::sort(m_vehicle_class_arr.begin(), m_vehicle_class_arr.end());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
|
{
|
|
|
|
|
LOG(WARNING) << "Failed to load vehicles.json:\n" << ex.what();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (auto& item_json : all_vehicles)
|
|
|
|
|
{
|
|
|
|
|
if (
|
|
|
|
|
item_json["Hash"].is_null() ||
|
|
|
|
|
item_json["Name"].is_null() ||
|
|
|
|
|
!item_json["Bones"].is_array() ||
|
|
|
|
|
item_json["Bones"][0] == "stub"
|
|
|
|
|
) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto item = vehicle_item(item_json);
|
|
|
|
|
|
|
|
|
|
m_vehicle_hash_idx_map[item_json["Hash"]] = (int)m_vehicle_item_arr.size();
|
|
|
|
|
|
|
|
|
|
m_vehicle_item_arr.push_back(item);
|
|
|
|
|
|
|
|
|
|
if (std::find(m_vehicle_class_arr.begin(), m_vehicle_class_arr.end(), item.clazz) == m_vehicle_class_arr.end())
|
|
|
|
|
{
|
|
|
|
|
m_vehicle_class_arr.push_back(item.clazz);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::sort(m_vehicle_class_arr.begin(), m_vehicle_class_arr.end());
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void gta_data_service::load_peds(file file_to_load)
|
|
|
|
|
bool gta_data_service::load_peds(file file_to_load)
|
|
|
|
|
{
|
|
|
|
|
m_ped_type_arr.clear();
|
|
|
|
|
m_ped_hash_idx_map.clear();
|
|
|
|
|
m_ped_item_arr.clear();
|
|
|
|
|
|
|
|
|
|
std::ifstream file(file_to_load.get_path());
|
|
|
|
|
nlohmann::json all_peds;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
file >> all_peds;
|
|
|
|
|
|
|
|
|
|
if (!all_peds.is_array())
|
|
|
|
|
{
|
|
|
|
|
throw "Invalid json format.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_ped_type_arr.clear();
|
|
|
|
|
m_ped_hash_idx_map.clear();
|
|
|
|
|
m_ped_item_arr.clear();
|
|
|
|
|
|
|
|
|
|
for (auto& item_json : all_peds)
|
|
|
|
|
{
|
|
|
|
|
if (
|
|
|
|
|
item_json["Hash"].is_null() ||
|
|
|
|
|
item_json["Name"].is_null()
|
|
|
|
|
) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto item = ped_item(item_json);
|
|
|
|
|
|
|
|
|
|
m_ped_hash_idx_map[item_json["Hash"]] = (int)m_ped_item_arr.size();
|
|
|
|
|
|
|
|
|
|
m_ped_item_arr.push_back(item);
|
|
|
|
|
|
|
|
|
|
if (std::find(m_ped_type_arr.begin(), m_ped_type_arr.end(), item.ped_type) == m_ped_type_arr.end())
|
|
|
|
|
{
|
|
|
|
|
m_ped_type_arr.push_back(item.ped_type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::sort(m_ped_type_arr.begin(), m_ped_type_arr.end());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
|
{
|
|
|
|
|
LOG(WARNING) << "Failed to load peds.json:\n" << ex.what();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto& item_json : all_peds)
|
|
|
|
|
{
|
|
|
|
|
if (
|
|
|
|
|
item_json["Hash"].is_null() ||
|
|
|
|
|
item_json["Name"].is_null()
|
|
|
|
|
) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto item = ped_item(item_json);
|
|
|
|
|
|
|
|
|
|
m_ped_hash_idx_map[item_json["Hash"]] = (int)m_ped_item_arr.size();
|
|
|
|
|
|
|
|
|
|
m_ped_item_arr.push_back(item);
|
|
|
|
|
|
|
|
|
|
if (std::find(m_ped_type_arr.begin(), m_ped_type_arr.end(), item.ped_type) == m_ped_type_arr.end())
|
|
|
|
|
{
|
|
|
|
|
m_ped_type_arr.push_back(item.ped_type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::sort(m_ped_type_arr.begin(), m_ped_type_arr.end());
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void gta_data_service::load_weapons(file file_to_load)
|
|
|
|
|
bool gta_data_service::load_weapons(file file_to_load)
|
|
|
|
|
{
|
|
|
|
|
m_weapon_type_arr.clear();
|
|
|
|
|
m_weapon_hash_idx_map.clear();
|
|
|
|
|
m_weapon_item_arr.clear();
|
|
|
|
|
|
|
|
|
|
std::ifstream file(file_to_load.get_path());
|
|
|
|
|
nlohmann::json all_weapons;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
file >> all_weapons;
|
|
|
|
|
|
|
|
|
|
if (!all_weapons.is_array())
|
|
|
|
|
{
|
|
|
|
|
throw "Invalid json format.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_weapon_type_arr.clear();
|
|
|
|
|
m_weapon_hash_idx_map.clear();
|
|
|
|
|
m_weapon_item_arr.clear();
|
|
|
|
|
|
|
|
|
|
constexpr Hash hash_blacklist_arr[] = {
|
|
|
|
|
RAGE_JOAAT("WEAPON_BIRD_CRAP"),
|
|
|
|
|
RAGE_JOAAT("WEAPON_DIGISCANNER"),
|
|
|
|
|
RAGE_JOAAT("WEAPON_GARBAGEBAG"),
|
|
|
|
|
RAGE_JOAAT("WEAPON_GRENADELAUNCHER_SMOKE"),
|
|
|
|
|
RAGE_JOAAT("WEAPON_HANDCUFFS"),
|
|
|
|
|
RAGE_JOAAT("WEAPON_METALDETECTOR"),
|
|
|
|
|
RAGE_JOAAT("GADGET_NIGHTVISION"),
|
|
|
|
|
RAGE_JOAAT("GADGET_PARACHUTE"),
|
|
|
|
|
RAGE_JOAAT("WEAPON_TRANQUILIZER"),
|
|
|
|
|
RAGE_JOAAT("WEAPON_STINGER")
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (auto& item_json : all_weapons)
|
|
|
|
|
{
|
|
|
|
|
if (
|
|
|
|
|
item_json["Hash"].is_null() ||
|
|
|
|
|
item_json["Name"].is_null() ||
|
|
|
|
|
item_json["IsVehicleWeapon"]
|
|
|
|
|
) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (EXIST_IN_ARRAY(hash_blacklist_arr, item_json["Hash"]))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto item = weapon_item(item_json);
|
|
|
|
|
|
|
|
|
|
if (item.name == "Invalid" || item.name == "Unarmed" || item.weapon_type == "NULL")
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_weapon_hash_idx_map[item_json["Hash"]] = (int)m_weapon_item_arr.size();
|
|
|
|
|
|
|
|
|
|
m_weapon_item_arr.push_back(item);
|
|
|
|
|
|
|
|
|
|
if (std::find(m_weapon_type_arr.begin(), m_weapon_type_arr.end(), item.weapon_type) == m_weapon_type_arr.end())
|
|
|
|
|
{
|
|
|
|
|
m_weapon_type_arr.push_back(item.weapon_type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::sort(m_weapon_type_arr.begin(), m_weapon_type_arr.end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
|
{
|
|
|
|
|
LOG(WARNING) << "Failed to load weapons.json:\n" << ex.what();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constexpr Hash hash_blacklist_arr[] = {
|
|
|
|
|
RAGE_JOAAT("WEAPON_BIRD_CRAP"),
|
|
|
|
|
RAGE_JOAAT("WEAPON_DIGISCANNER"),
|
|
|
|
|
RAGE_JOAAT("WEAPON_GARBAGEBAG"),
|
|
|
|
|
RAGE_JOAAT("WEAPON_GRENADELAUNCHER_SMOKE"),
|
|
|
|
|
RAGE_JOAAT("WEAPON_HANDCUFFS"),
|
|
|
|
|
RAGE_JOAAT("WEAPON_METALDETECTOR"),
|
|
|
|
|
RAGE_JOAAT("GADGET_NIGHTVISION"),
|
|
|
|
|
RAGE_JOAAT("GADGET_PARACHUTE"),
|
|
|
|
|
RAGE_JOAAT("WEAPON_TRANQUILIZER"),
|
|
|
|
|
RAGE_JOAAT("WEAPON_STINGER")
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (auto& item_json : all_weapons)
|
|
|
|
|
{
|
|
|
|
|
if (
|
|
|
|
|
item_json["Hash"].is_null() ||
|
|
|
|
|
item_json["Name"].is_null() ||
|
|
|
|
|
item_json["IsVehicleWeapon"]
|
|
|
|
|
) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (EXIST_IN_ARRAY(hash_blacklist_arr, item_json["Hash"]))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto item = weapon_item(item_json);
|
|
|
|
|
|
|
|
|
|
if (item.name == "Invalid" || item.name == "Unarmed" || item.weapon_type == "NULL")
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_weapon_hash_idx_map[item_json["Hash"]] = (int)m_weapon_item_arr.size();
|
|
|
|
|
|
|
|
|
|
m_weapon_item_arr.push_back(item);
|
|
|
|
|
|
|
|
|
|
if (std::find(m_weapon_type_arr.begin(), m_weapon_type_arr.end(), item.weapon_type) == m_weapon_type_arr.end())
|
|
|
|
|
{
|
|
|
|
|
m_weapon_type_arr.push_back(item.weapon_type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::sort(m_weapon_type_arr.begin(), m_weapon_type_arr.end());
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|