mirror of
https://github.com/Mr-X-GTA/YimMenu.git
synced 2025-06-23 09:02:38 +08:00
General fixes (#1251)
This commit is contained in:
@ -65,13 +65,12 @@ namespace big
|
||||
return m_cache_header.m_data_size;
|
||||
}
|
||||
|
||||
bool cache_file::up_to_date(std::uint32_t game_version, float online_version) const
|
||||
bool cache_file::up_to_date(std::uint32_t file_version) const
|
||||
{
|
||||
if (!m_data)
|
||||
return false;
|
||||
|
||||
return m_cache_version == m_cache_header.m_cache_version && game_version == m_cache_header.m_game_version
|
||||
&& online_version == m_cache_header.m_online_version;
|
||||
return m_cache_version == m_cache_header.m_cache_version && file_version == m_cache_header.m_file_version;
|
||||
}
|
||||
|
||||
void cache_file::set_data(cache_data&& data, std::uint64_t data_size)
|
||||
@ -80,11 +79,10 @@ namespace big
|
||||
m_cache_header.m_data_size = data_size;
|
||||
}
|
||||
|
||||
void cache_file::set_header_version(std::uint32_t game_version, float online_version)
|
||||
void cache_file::set_header_version(std::uint32_t file_version)
|
||||
{
|
||||
m_cache_header.m_cache_version = m_cache_version;
|
||||
m_cache_header.m_game_version = game_version;
|
||||
m_cache_header.m_online_version = online_version;
|
||||
m_cache_header.m_cache_version = m_cache_version;
|
||||
m_cache_header.m_file_version = file_version;
|
||||
}
|
||||
|
||||
void cache_file::set_cache_version(std::uint32_t cache_version)
|
||||
|
@ -7,8 +7,7 @@ namespace big
|
||||
{
|
||||
public:
|
||||
std::uint32_t m_cache_version;
|
||||
std::uint32_t m_game_version;
|
||||
float m_online_version;
|
||||
std::uint32_t m_file_version;
|
||||
std::uint64_t m_data_size;
|
||||
};
|
||||
|
||||
@ -55,7 +54,7 @@ namespace big
|
||||
/// <param name="game_version">Current Game version</param>
|
||||
/// <param name="online_version">Current Online version</param>
|
||||
/// <returns>True if cache is up to date, false otherwise.</returns>
|
||||
bool up_to_date(std::uint32_t game_version, float online_version) const;
|
||||
bool up_to_date(std::uint32_t file_version) const;
|
||||
|
||||
|
||||
void set_data(cache_data&& data, std::uint64_t data_size);
|
||||
@ -64,7 +63,7 @@ namespace big
|
||||
/// </summary>
|
||||
/// <param name="game_version">Game Build</param>
|
||||
/// <param name="online_version">Online Version</param>
|
||||
void set_header_version(std::uint32_t game_version, float online_version);
|
||||
void set_header_version(std::uint32_t file_version);
|
||||
|
||||
void set_cache_version(std::uint32_t cache_version);
|
||||
|
||||
|
@ -15,6 +15,11 @@
|
||||
|
||||
namespace big
|
||||
{
|
||||
inline bool is_crash_ped(rage::joaat_t hash)
|
||||
{
|
||||
return hash == RAGE_JOAAT("slod_human") || hash == RAGE_JOAAT("slod_small_quadped") || hash == RAGE_JOAAT("slod_large_quadped");
|
||||
}
|
||||
|
||||
bool add_if_not_exists(string_vec& vec, std::string str)
|
||||
{
|
||||
if (std::find(vec.begin(), vec.end(), str) != vec.end())
|
||||
@ -25,9 +30,9 @@ namespace big
|
||||
}
|
||||
|
||||
gta_data_service::gta_data_service() :
|
||||
m_peds_cache(g_file_manager->get_project_file("./cache/peds.bin"), 2),
|
||||
m_vehicles_cache(g_file_manager->get_project_file("./cache/vehicles.bin"), 1),
|
||||
m_weapons_cache(g_file_manager->get_project_file("./cache/weapons.bin"), 2),
|
||||
m_peds_cache(g_file_manager->get_project_file("./cache/peds.bin"), 3),
|
||||
m_vehicles_cache(g_file_manager->get_project_file("./cache/vehicles.bin"), 2),
|
||||
m_weapons_cache(g_file_manager->get_project_file("./cache/weapons.bin"), 3),
|
||||
m_update_state(eGtaDataUpdateState::IDLE)
|
||||
{
|
||||
if (!is_cache_up_to_date())
|
||||
@ -142,11 +147,9 @@ namespace big
|
||||
m_vehicles_cache.load();
|
||||
m_weapons_cache.load();
|
||||
|
||||
const auto game_version = g_pointers->m_game_version_uint32_t;
|
||||
const auto online_version = g_pointers->m_online_version_float;
|
||||
const auto file_version = memory::module("GTA5.exe").size();
|
||||
|
||||
return m_peds_cache.up_to_date(game_version, online_version) && m_vehicles_cache.up_to_date(game_version, online_version)
|
||||
&& m_weapons_cache.up_to_date(game_version, online_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);
|
||||
}
|
||||
|
||||
void gta_data_service::load_data()
|
||||
@ -223,6 +226,9 @@ namespace big
|
||||
const auto name = item.child("Name").text().as_string();
|
||||
const auto hash = rage::joaat(name);
|
||||
|
||||
if (is_crash_ped(hash))
|
||||
continue;
|
||||
|
||||
if (std::find(mapped_peds.begin(), mapped_peds.end(), hash) != mapped_peds.end())
|
||||
continue;
|
||||
|
||||
@ -411,6 +417,9 @@ namespace big
|
||||
const auto name = file.stem().string();
|
||||
const auto hash = rage::joaat(name);
|
||||
|
||||
if (is_crash_ped(hash))
|
||||
continue;
|
||||
|
||||
if (std::find(mapped_peds.begin(), mapped_peds.end(), hash) != mapped_peds.end())
|
||||
continue;
|
||||
|
||||
@ -484,15 +493,14 @@ namespace big
|
||||
|
||||
LOG(VERBOSE) << "Starting cache saving procedure...";
|
||||
g_thread_pool->push([this, peds = std::move(peds), vehicles = std::move(vehicles), weapons = std::move(weapons)] {
|
||||
const auto game_version = g_pointers->m_game_version_uint32_t;
|
||||
const auto online_version = g_pointers->m_online_version_float;
|
||||
const auto file_version = memory::module("GTA5.exe").size();
|
||||
|
||||
{
|
||||
const auto data_size = sizeof(ped_item) * peds.size();
|
||||
m_peds_cache.set_data(std::make_unique<std::uint8_t[]>(data_size), data_size);
|
||||
std::memcpy(m_peds_cache.data(), peds.data(), data_size);
|
||||
|
||||
m_peds_cache.set_header_version(game_version, online_version);
|
||||
m_peds_cache.set_header_version(file_version);
|
||||
m_peds_cache.write();
|
||||
}
|
||||
|
||||
@ -501,7 +509,7 @@ namespace big
|
||||
m_vehicles_cache.set_data(std::make_unique<std::uint8_t[]>(data_size), data_size);
|
||||
std::memcpy(m_vehicles_cache.data(), vehicles.data(), data_size);
|
||||
|
||||
m_vehicles_cache.set_header_version(game_version, online_version);
|
||||
m_vehicles_cache.set_header_version(file_version);
|
||||
m_vehicles_cache.write();
|
||||
}
|
||||
|
||||
@ -510,7 +518,7 @@ namespace big
|
||||
m_weapons_cache.set_data(std::make_unique<std::uint8_t[]>(data_size), data_size);
|
||||
std::memcpy(m_weapons_cache.data(), weapons.data(), data_size);
|
||||
|
||||
m_weapons_cache.set_header_version(game_version, online_version);
|
||||
m_weapons_cache.set_header_version(file_version);
|
||||
m_weapons_cache.write();
|
||||
}
|
||||
|
||||
|
@ -6,35 +6,9 @@
|
||||
|
||||
namespace big
|
||||
{
|
||||
yim_fipackfile::yim_fipackfile(rage::fiPackfile* rpf, const std::string& mount_name)
|
||||
yim_fipackfile::yim_fipackfile(rage::fiPackfile* rpf)
|
||||
{
|
||||
this->rpf = rpf;
|
||||
this->mount_name = mount_name;
|
||||
}
|
||||
|
||||
std::vector<std::string> yim_fipackfile::get_non_dlc_mounted_devices_names()
|
||||
{
|
||||
std::vector<std::string> non_dlc_mounted_devices_names;
|
||||
|
||||
uint16_t mounted_devices_len = *g_pointers->m_gta.m_fidevices_len;
|
||||
if (mounted_devices_len)
|
||||
{
|
||||
auto devices_arr = *(uint64_t*)g_pointers->m_gta.m_fidevices;
|
||||
uint8_t** current_device_mount_name_ptr = *(unsigned __int8***)g_pointers->m_gta.m_fidevices;
|
||||
auto device_i = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
non_dlc_mounted_devices_names.push_back(*(const char**)current_device_mount_name_ptr);
|
||||
|
||||
++device_i;
|
||||
current_device_mount_name_ptr += 4;
|
||||
if (device_i >= mounted_devices_len)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return non_dlc_mounted_devices_names;
|
||||
this->rpf = rpf;
|
||||
}
|
||||
|
||||
void yim_fipackfile::add_wrapper_call_back(std::function<size_t(yim_fipackfile& rpf_wrapper)> cb)
|
||||
@ -44,14 +18,6 @@ namespace big
|
||||
|
||||
void yim_fipackfile::for_each_fipackfile()
|
||||
{
|
||||
// the idea is to reuse existing mount points as much as possible because
|
||||
// even when mounting / unmounting properly you'll get file errors
|
||||
// and crashes if the rpf file was already mounted
|
||||
|
||||
// iterate the fidevice array which contains devices that are currently mounted
|
||||
// the dlc devices are in another array
|
||||
const auto non_dlc_mounted_devices_names = get_non_dlc_mounted_devices_names();
|
||||
|
||||
// for not hanging the game too much
|
||||
constexpr auto yield_increment = 80;
|
||||
|
||||
@ -66,57 +32,11 @@ namespace big
|
||||
break;
|
||||
}
|
||||
|
||||
yim_fipackfile rpf_wrapper = yim_fipackfile(rpf, default_mount_name);
|
||||
yim_fipackfile rpf_wrapper = yim_fipackfile(rpf);
|
||||
|
||||
auto already_mounted = false;
|
||||
for (const auto& non_dlc_mounted_device_name : non_dlc_mounted_devices_names)
|
||||
{
|
||||
auto* non_dlc_mounted_device = rage::fiDevice::GetDevice(non_dlc_mounted_device_name.c_str(), true);
|
||||
|
||||
if (rpf == non_dlc_mounted_device)
|
||||
{
|
||||
rpf_wrapper.mount_name = non_dlc_mounted_device_name;
|
||||
already_mounted = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!already_mounted)
|
||||
{
|
||||
size_t acc = 0;
|
||||
|
||||
static std::vector<std::string> mount_names = {"memory:/", "memory:", "dlc", "dlc:", "dlc:/", "dlcpacks:/", "common:/", "commoncrc:/", "update:/", "update2:/", "platform:/", "platformcrc:/", "gamecache:/"};
|
||||
|
||||
for (auto& mount_name : mount_names)
|
||||
{
|
||||
rpf_wrapper.mount_name = mount_name;
|
||||
if (auto count = rpf_wrapper.get_file_paths().size())
|
||||
{
|
||||
acc += count;
|
||||
std::for_each(m_wrapper_call_back.begin(), m_wrapper_call_back.end(), [&rpf_wrapper](std::function<size_t(yim_fipackfile & rpf_wrapper)> cb) {
|
||||
cb(rpf_wrapper);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// if we got nothing with those mount points for this rpf, mount it
|
||||
if (!acc)
|
||||
{
|
||||
rpf_wrapper.mount_name = default_mount_name;
|
||||
rpf->Mount(default_mount_name);
|
||||
|
||||
std::for_each(m_wrapper_call_back.begin(), m_wrapper_call_back.end(), [&rpf_wrapper](std::function<size_t(yim_fipackfile & rpf_wrapper)> cb) {
|
||||
cb(rpf_wrapper);
|
||||
});
|
||||
|
||||
g_pointers->m_gta.m_fipackfile_unmount(default_mount_name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::for_each(m_wrapper_call_back.begin(), m_wrapper_call_back.end(), [&rpf_wrapper](std::function<size_t(yim_fipackfile & rpf_wrapper)> cb) {
|
||||
cb(rpf_wrapper);
|
||||
});
|
||||
}
|
||||
std::for_each(m_wrapper_call_back.begin(), m_wrapper_call_back.end(), [&rpf_wrapper](std::function<size_t(yim_fipackfile & rpf_wrapper)> cb) {
|
||||
cb(rpf_wrapper);
|
||||
});
|
||||
|
||||
if (i % yield_increment == 0)
|
||||
script::get_current()->yield();
|
||||
@ -127,7 +47,7 @@ namespace big
|
||||
{
|
||||
std::vector<std::filesystem::path> file_paths;
|
||||
if (parent.empty())
|
||||
parent = mount_name;
|
||||
parent = "/";
|
||||
|
||||
std::vector<std::string> directories;
|
||||
|
||||
@ -137,7 +57,12 @@ namespace big
|
||||
{
|
||||
do
|
||||
{
|
||||
std::string fn = std::string(parent.c_str()) + std::string("/") + std::string(findData.fileName);
|
||||
std::string fn;
|
||||
|
||||
if (parent == "/")
|
||||
fn = std::string(parent.c_str()) + std::string(findData.fileName);
|
||||
else
|
||||
fn = std::string(parent.c_str()) + std::string("/") + std::string(findData.fileName);
|
||||
|
||||
if (findData.fileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
{
|
||||
|
@ -4,15 +4,13 @@
|
||||
namespace big
|
||||
{
|
||||
using file_contents_callback = std::function<void(const std::unique_ptr<std::uint8_t[]>& file_content, const int data_size)>;
|
||||
|
||||
class yim_fipackfile
|
||||
{
|
||||
static constexpr auto default_mount_name = "yimM:/";
|
||||
|
||||
rage::fiPackfile* rpf;
|
||||
std::string mount_name;
|
||||
|
||||
public:
|
||||
explicit yim_fipackfile(rage::fiPackfile* rpf, const std::string& mount_name);
|
||||
explicit yim_fipackfile(rage::fiPackfile* rpf);
|
||||
|
||||
static std::vector<std::string> get_non_dlc_mounted_devices_names();
|
||||
|
||||
@ -29,7 +27,5 @@ namespace big
|
||||
void read_file(const std::filesystem::path& path, file_contents_callback&& cb);
|
||||
|
||||
void read_xml_file(const std::filesystem::path& path, std::function<void(pugi::xml_document& doc)> cb);
|
||||
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user