parent
11073bd80d
commit
c0e1ab6a24
@ -122,6 +122,14 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
|
|||||||
g_script_mgr.remove_all_scripts();
|
g_script_mgr.remove_all_scripts();
|
||||||
LOG(INFO) << "Scripts unregistered.";
|
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();
|
gui_service_instance.reset();
|
||||||
LOG(INFO) << "Gui Service reset.";
|
LOG(INFO) << "Gui Service reset.";
|
||||||
gta_data_service_instance.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) << "Context Service reset.";
|
||||||
LOG(INFO) << "Services uninitialized.";
|
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();
|
hooking_instance.reset();
|
||||||
LOG(INFO) << "Hooking uninitialized.";
|
LOG(INFO) << "Hooking uninitialized.";
|
||||||
|
|
||||||
|
@ -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));
|
file file_to_load(g_file_manager->get_project_file(file_path));
|
||||||
|
|
||||||
if (file_to_load.exists())
|
if (file_to_load.exists())
|
||||||
{
|
{
|
||||||
(this->*load_func)(file_to_load);
|
if ((this->*load_func)(file_to_load))
|
||||||
LOG(INFO) << "Data loaded: " + data_name;
|
{
|
||||||
|
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]() {
|
g_thread_pool->push([this, file_path, etag_path, url, load_func, data_name]() {
|
||||||
@ -152,8 +158,24 @@ namespace big
|
|||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
(this->*load_func)(file_to_load);
|
if ((this->*load_func)(file_to_load))
|
||||||
LOG(INFO) << "Data updated: " + data_name;
|
{
|
||||||
|
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;
|
break;
|
||||||
}
|
}
|
||||||
else if (!file_to_load.exists())
|
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());
|
std::ifstream file(file_to_load.get_path());
|
||||||
nlohmann::json all_vehicles;
|
nlohmann::json all_vehicles;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
file >> all_vehicles;
|
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)
|
catch (const std::exception& ex)
|
||||||
{
|
{
|
||||||
LOG(WARNING) << "Failed to load vehicles.json:\n" << ex.what();
|
LOG(WARNING) << "Failed to load vehicles.json:\n" << ex.what();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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());
|
std::ifstream file(file_to_load.get_path());
|
||||||
nlohmann::json all_peds;
|
nlohmann::json all_peds;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
file >> all_peds;
|
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)
|
catch (const std::exception& ex)
|
||||||
{
|
{
|
||||||
LOG(WARNING) << "Failed to load peds.json:\n" << ex.what();
|
LOG(WARNING) << "Failed to load peds.json:\n" << ex.what();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& item_json : all_peds)
|
return true;
|
||||||
{
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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());
|
std::ifstream file(file_to_load.get_path());
|
||||||
nlohmann::json all_weapons;
|
nlohmann::json all_weapons;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
file >> all_weapons;
|
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)
|
catch (const std::exception& ex)
|
||||||
{
|
{
|
||||||
LOG(WARNING) << "Failed to load weapons.json:\n" << ex.what();
|
LOG(WARNING) << "Failed to load weapons.json:\n" << ex.what();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Hash hash_blacklist_arr[] = {
|
return true;
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,11 +41,11 @@ namespace big
|
|||||||
const std::vector<weapon_item>& get_weapon_arr();
|
const std::vector<weapon_item>& get_weapon_arr();
|
||||||
|
|
||||||
private:
|
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);
|
bool load_vehicles(file file_to_load);
|
||||||
void load_peds(file file_to_load);
|
bool load_peds(file file_to_load);
|
||||||
void load_weapons(file file_to_load);
|
bool load_weapons(file file_to_load);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline gta_data_service* g_gta_data_service{};
|
inline gta_data_service* g_gta_data_service{};
|
||||||
|
@ -28,7 +28,6 @@ namespace big
|
|||||||
void thread_pool::destroy()
|
void thread_pool::destroy()
|
||||||
{
|
{
|
||||||
this->m_managing_thread.join();
|
this->m_managing_thread.join();
|
||||||
|
|
||||||
{
|
{
|
||||||
std::unique_lock lock(m_lock);
|
std::unique_lock lock(m_lock);
|
||||||
this->m_accept_jobs = false;
|
this->m_accept_jobs = false;
|
||||||
|
2
vendor/json
vendored
2
vendor/json
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 350ff4f7ced7c4117eae2fb93df02823c8021fcb
|
Subproject commit 5d550374f8ef362cfb4dfb5b689b23218546b1e7
|
Reference in New Issue
Block a user