Merge 03165284b233b1f0c3b9905864b74d7b351dd637 into 5db512287cb735c43eddae6cf57a0053250758c8

This commit is contained in:
Quentin 2024-09-24 14:40:48 +05:30 committed by GitHub
commit 01ed9995d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 49 additions and 38 deletions

View File

@ -70,6 +70,10 @@ namespace big
if (!m_data) if (!m_data)
return false; 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; return m_cache_version == m_cache_header.m_cache_version && file_version == m_cache_header.m_file_version;
} }

View File

@ -152,6 +152,13 @@ namespace big
const auto file_version = memory::module("GTA5.exe").timestamp(); 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); 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);
} }

View File

@ -16,33 +16,22 @@ namespace big
m_wrapper_call_back.push_back(cb); 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; return packfile.OpenPackfile(path.c_str(), true, 0, 0);
__try
{
success = packfile.OpenPackfile(reinterpret_cast<const char*>(path.c_str()), true, 0, 0);
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
return false;
}
return success;
} }
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); std::string mount_path = std::format("temp{}:/", depth);
rage::fiPackfile packfile; rage::fiPackfile packfile;
if (!safe_open_pack_file(packfile, path)) if (!safe_open_pack_file(packfile, path))
{ {
LOG(INFO) << "Failed opening " << reinterpret_cast<const char*>(path.c_str()); LOG(INFO) << "Failed opening " << path;
return; return;
} }
packfile.Mount(mount_path.c_str()); packfile.Mount(mount_path.c_str());
yim_fipackfile rpf_wrapper = yim_fipackfile(&packfile, mount_path); yim_fipackfile rpf_wrapper = yim_fipackfile(&packfile, mount_path);
@ -50,14 +39,15 @@ namespace big
const auto files = rpf_wrapper.get_file_paths(); const auto files = rpf_wrapper.get_file_paths();
for (const auto& file : files) 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<const char*>(file.u8string().c_str()), true)) if (auto handle = ((rage::fiDevice*)&packfile)->Open(file.c_str(), true))
{ {
uint32_t encryption_type{}; uint32_t encryption_type{};
((rage::fiDevice*)&packfile)->Seek(handle, 12, 0); rage::fiDevice* device = &packfile;
((rage::fiDevice*)&packfile)->Read(handle, &encryption_type, 4); device->Seek(handle, 12, 0);
((rage::fiDevice*)&packfile)->Close(handle); device->Read(handle, &encryption_type, 4);
device->Close(handle);
if (encryption_type == 0xFFFFFF9) if (encryption_type == 0xFFFFFF9)
continue; // skip AES encrypted RPFs continue; // skip AES encrypted RPFs
@ -65,12 +55,12 @@ namespace big
// OPEN / CFXP // OPEN / CFXP
if (encryption_type == 0x4E45504F || encryption_type == 0x50584643) if (encryption_type == 0x4E45504F || encryption_type == 0x50584643)
{ {
LOG(INFO) << "Modded RPF, skipping " << reinterpret_cast<const char*>(file.u8string().c_str()); LOG(INFO) << "Modded RPF, skipping " << file;
continue; continue;
} }
traverse_rpf_file(file.u8string(), depth + 1); traverse_rpf_file(file, depth + 1);
} }
} }
else else
@ -99,7 +89,8 @@ namespace big
} }
else else
{ {
LOG(WARNING) << "game_folder variable is not directory " << reinterpret_cast<const char*>(game_folder.u8string().c_str()); LOG(WARNING) << "game_folder variable is not directory "
<< reinterpret_cast<const char*>(game_folder.u8string().c_str());
} }
} }
else else
@ -127,33 +118,42 @@ namespace big
LOG(WARNING) << "Failed printing GTA install directory: " << e.what(); 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()) if (!entry.is_regular_file())
{ {
continue; 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()) if (rel_path.empty())
continue; continue;
const auto utf8_path = string_conversions::utf_16_to_code_page(CP_UTF8, entry.path().native()); if (utf8_rel_path.contains("mods"))
if (utf8_path.empty())
continue;
if (utf8_path.contains("mods"))
continue; continue;
if (rel_path.extension() == ".rpf") if (rel_path.extension() == ".rpf")
traverse_rpf_file(rel_path.u8string()); traverse_rpf_file(utf8_rel_path);
} }
} }
std::vector<std::filesystem::path> yim_fipackfile::get_file_paths(std::string parent) std::vector<std::string> yim_fipackfile::get_file_paths(std::string parent)
{ {
std::vector<std::filesystem::path> file_paths; std::vector<std::string> file_paths;
if (parent.empty()) if (parent.empty())
parent = mount_name; parent = mount_name;

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <pugixml.hpp>
#include <gta/fidevice.hpp> #include <gta/fidevice.hpp>
#include <pugixml.hpp>
namespace big namespace big
{ {
@ -19,10 +19,10 @@ namespace big
static void add_wrapper_call_back(std::function<void(yim_fipackfile& rpf_wrapper, std::filesystem::path path)> cb); static void add_wrapper_call_back(std::function<void(yim_fipackfile& rpf_wrapper, std::filesystem::path path)> 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(); static void for_each_fipackfile();
std::vector<std::filesystem::path> get_file_paths(std::string parent = {}); std::vector<std::string> get_file_paths(std::string parent = {});
const char* get_name(); const char* get_name();