diff --git a/src/services/gta_data/cache_file.cpp b/src/services/gta_data/cache_file.cpp index 46ad6d3c..66f74eb7 100644 --- a/src/services/gta_data/cache_file.cpp +++ b/src/services/gta_data/cache_file.cpp @@ -70,6 +70,10 @@ namespace big if (!m_data) return false; + LOG(VERBOSE) << "Checking if cache is up-to-date for " << m_cache_file.get_path().filename() << "\n\t\t" + << "Cache Version " << (m_cache_version == m_cache_header.m_cache_version ? "match" : "mismatch") << " (file: " << m_cache_header.m_cache_version << ", menu: " << m_cache_version << ")\n\t\t" + << "Game EXE Size " << (file_version == m_cache_header.m_file_version ? "match" : "mismatch") << " (file: " << m_cache_header.m_file_version << ", game: " << file_version << ")"; + return m_cache_version == m_cache_header.m_cache_version && file_version == m_cache_header.m_file_version; } diff --git a/src/services/gta_data/gta_data_service.cpp b/src/services/gta_data/gta_data_service.cpp index ed99eeea..7eee623c 100644 --- a/src/services/gta_data/gta_data_service.cpp +++ b/src/services/gta_data/gta_data_service.cpp @@ -152,6 +152,13 @@ namespace big const auto file_version = memory::module("GTA5.exe").timestamp(); + const auto ped_count = m_peds_cache.data_size() / sizeof(ped_item); + const auto vehicle_count = m_vehicles_cache.data_size() / sizeof(vehicle_item); + if (ped_count == 0 || vehicle_count == 0) + { + return false; + } + return m_peds_cache.up_to_date(file_version) && m_vehicles_cache.up_to_date(file_version) && m_weapons_cache.up_to_date(file_version); } diff --git a/src/services/gta_data/yim_fipackfile.cpp b/src/services/gta_data/yim_fipackfile.cpp index 9d1207c8..cf38a2ff 100644 --- a/src/services/gta_data/yim_fipackfile.cpp +++ b/src/services/gta_data/yim_fipackfile.cpp @@ -16,33 +16,22 @@ namespace big m_wrapper_call_back.push_back(cb); } - static bool safe_open_pack_file(rage::fiPackfile& packfile, const std::u8string& path) + static bool safe_open_pack_file(rage::fiPackfile& packfile, const std::string& path) { - bool success = false; - - __try - { - success = packfile.OpenPackfile(reinterpret_cast(path.c_str()), true, 0, 0); - } - __except (EXCEPTION_EXECUTE_HANDLER) - { - return false; - } - - return success; + return packfile.OpenPackfile(path.c_str(), true, 0, 0); } - void yim_fipackfile::traverse_rpf_file(const std::u8string& path, int depth) + void yim_fipackfile::traverse_rpf_file(const std::string& path, int depth) { std::string mount_path = std::format("temp{}:/", depth); rage::fiPackfile packfile; if (!safe_open_pack_file(packfile, path)) { - LOG(INFO) << "Failed opening " << reinterpret_cast(path.c_str()); + LOG(INFO) << "Failed opening " << path; return; } - + packfile.Mount(mount_path.c_str()); yim_fipackfile rpf_wrapper = yim_fipackfile(&packfile, mount_path); @@ -50,14 +39,15 @@ namespace big const auto files = rpf_wrapper.get_file_paths(); for (const auto& file : files) { - if (file.extension() == ".rpf") + if (std::filesystem::path(file).extension() == ".rpf") { - if (auto handle = ((rage::fiDevice*)&packfile)->Open(reinterpret_cast(file.u8string().c_str()), true)) + if (auto handle = ((rage::fiDevice*)&packfile)->Open(file.c_str(), true)) { uint32_t encryption_type{}; - ((rage::fiDevice*)&packfile)->Seek(handle, 12, 0); - ((rage::fiDevice*)&packfile)->Read(handle, &encryption_type, 4); - ((rage::fiDevice*)&packfile)->Close(handle); + rage::fiDevice* device = &packfile; + device->Seek(handle, 12, 0); + device->Read(handle, &encryption_type, 4); + device->Close(handle); if (encryption_type == 0xFFFFFF9) continue; // skip AES encrypted RPFs @@ -65,12 +55,12 @@ namespace big // OPEN / CFXP if (encryption_type == 0x4E45504F || encryption_type == 0x50584643) { - LOG(INFO) << "Modded RPF, skipping " << reinterpret_cast(file.u8string().c_str()); + LOG(INFO) << "Modded RPF, skipping " << file; continue; } - traverse_rpf_file(file.u8string(), depth + 1); + traverse_rpf_file(file, depth + 1); } } else @@ -99,7 +89,8 @@ namespace big } else { - LOG(WARNING) << "game_folder variable is not directory " << reinterpret_cast(game_folder.u8string().c_str()); + LOG(WARNING) << "game_folder variable is not directory " + << reinterpret_cast(game_folder.u8string().c_str()); } } else @@ -127,33 +118,42 @@ namespace big LOG(WARNING) << "Failed printing GTA install directory: " << e.what(); } - for (const auto& entry : std::filesystem::recursive_directory_iterator(gta_folder, std::filesystem::directory_options::skip_permission_denied)) + // Ensure current_path is gta folder. + std::filesystem::current_path(gta_folder); + + for (const auto& entry : std::filesystem::recursive_directory_iterator(std::filesystem::current_path(), std::filesystem::directory_options::skip_permission_denied)) { if (!entry.is_regular_file()) { continue; } - const auto rel_path = std::filesystem::relative(entry.path()); + const auto utf8_path = string_conversions::utf_16_to_code_page(CP_UTF8, entry.path().wstring()); + + LOG(VERBOSE) << "Game file path: " << utf8_path; + + if (entry.path().empty()) + continue; + + const auto rel_path = std::filesystem::relative(utf8_path); + + const auto utf8_rel_path = string_conversions::utf_16_to_code_page(CP_UTF8, rel_path.wstring()); + LOG(VERBOSE) << "Game file path relative: " << utf8_rel_path; + if (rel_path.empty()) continue; - const auto utf8_path = string_conversions::utf_16_to_code_page(CP_UTF8, entry.path().native()); - - if (utf8_path.empty()) - continue; - - if (utf8_path.contains("mods")) + if (utf8_rel_path.contains("mods")) continue; if (rel_path.extension() == ".rpf") - traverse_rpf_file(rel_path.u8string()); + traverse_rpf_file(utf8_rel_path); } } - std::vector yim_fipackfile::get_file_paths(std::string parent) + std::vector yim_fipackfile::get_file_paths(std::string parent) { - std::vector file_paths; + std::vector file_paths; if (parent.empty()) parent = mount_name; diff --git a/src/services/gta_data/yim_fipackfile.hpp b/src/services/gta_data/yim_fipackfile.hpp index 364c1413..30ef0f59 100644 --- a/src/services/gta_data/yim_fipackfile.hpp +++ b/src/services/gta_data/yim_fipackfile.hpp @@ -1,6 +1,6 @@ #pragma once -#include #include +#include namespace big { @@ -19,10 +19,10 @@ namespace big static void add_wrapper_call_back(std::function cb); - static void traverse_rpf_file(const std::u8string& path, int depth = 0); + static void traverse_rpf_file(const std::string& path, int depth = 0); static void for_each_fipackfile(); - std::vector get_file_paths(std::string parent = {}); + std::vector get_file_paths(std::string parent = {}); const char* get_name();