diff --git a/BigBaseV2/src/main.cpp b/BigBaseV2/src/main.cpp index 312214f1..d6504863 100644 --- a/BigBaseV2/src/main.cpp +++ b/BigBaseV2/src/main.cpp @@ -122,6 +122,14 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID) g_script_mgr.remove_all_scripts(); LOG(INFO) << "Scripts unregistered."; + // Make sure that all threads created don't have any blocking loops + // otherwise make sure that they have stopped executing + thread_pool_instance->destroy(); + LOG(INFO) << "Destroyed thread pool."; + + thread_pool_instance.reset(); + LOG(INFO) << "Thread pool uninitialized."; + gui_service_instance.reset(); LOG(INFO) << "Gui Service reset."; gta_data_service_instance.reset(); @@ -144,14 +152,6 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID) LOG(INFO) << "Context Service reset."; LOG(INFO) << "Services uninitialized."; - // Make sure that all threads created don't have any blocking loops - // otherwise make sure that they have stopped executing - thread_pool_instance->destroy(); - LOG(INFO) << "Destroyed thread pool."; - - thread_pool_instance.reset(); - LOG(INFO) << "Thread pool uninitialized."; - hooking_instance.reset(); LOG(INFO) << "Hooking uninitialized."; diff --git a/BigBaseV2/src/services/gta_data/gta_data_service.cpp b/BigBaseV2/src/services/gta_data/gta_data_service.cpp index 7b5ecdde..85a118bf 100644 --- a/BigBaseV2/src/services/gta_data/gta_data_service.cpp +++ b/BigBaseV2/src/services/gta_data/gta_data_service.cpp @@ -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; } } diff --git a/BigBaseV2/src/services/gta_data/gta_data_service.hpp b/BigBaseV2/src/services/gta_data/gta_data_service.hpp index 13c208d9..55ed6b05 100644 --- a/BigBaseV2/src/services/gta_data/gta_data_service.hpp +++ b/BigBaseV2/src/services/gta_data/gta_data_service.hpp @@ -41,11 +41,11 @@ namespace big const std::vector& get_weapon_arr(); private: - void 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 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); - void load_vehicles(file file_to_load); - void load_peds(file file_to_load); - void load_weapons(file file_to_load); + bool load_vehicles(file file_to_load); + bool load_peds(file file_to_load); + bool load_weapons(file file_to_load); }; inline gta_data_service* g_gta_data_service{}; diff --git a/BigBaseV2/src/thread_pool.cpp b/BigBaseV2/src/thread_pool.cpp index 4a64b571..2473bee4 100644 --- a/BigBaseV2/src/thread_pool.cpp +++ b/BigBaseV2/src/thread_pool.cpp @@ -28,7 +28,6 @@ namespace big void thread_pool::destroy() { this->m_managing_thread.join(); - { std::unique_lock lock(m_lock); this->m_accept_jobs = false; diff --git a/vendor/json b/vendor/json index 350ff4f7..5d550374 160000 --- a/vendor/json +++ b/vendor/json @@ -1 +1 @@ -Subproject commit 350ff4f7ced7c4117eae2fb93df02823c8021fcb +Subproject commit 5d550374f8ef362cfb4dfb5b689b23218546b1e7