mirror of
https://github.com/Mr-X-GTA/YimMenu.git
synced 2025-06-23 09:02:38 +08:00
Add more spoofing options and added clang-format (#1020)
* feat(Spoofing): add spoofing * feat(Spoofing): prepare code for player attach * remove(PlayerAttach): isn't going to work due to netsync architecture * fix(GUI): fix scaling * feat(Project): add clang-format file * feat(Classes): update classes * fix(BlackHole): remove unnecessary cleanup * fix(Formatting): fix formatting for initializer lists * feat(clang-format): Set tab width and 1 space before comment Co-authored-by: Yimura <24669514+Yimura@users.noreply.github.com>
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
#include "gta_data_service.hpp"
|
||||
#include "file_manager.hpp"
|
||||
|
||||
#include "fiber_pool.hpp"
|
||||
#include "file_manager.hpp"
|
||||
#include "natives.hpp"
|
||||
#include "pointers.hpp"
|
||||
#include "pugixml.hpp"
|
||||
@ -21,10 +22,10 @@ namespace big
|
||||
}
|
||||
|
||||
gta_data_service::gta_data_service() :
|
||||
m_peds_cache(g_file_manager->get_project_file("./cache/peds.bin"), 1),
|
||||
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_update_state(eGtaDataUpdateState::IDLE)
|
||||
m_peds_cache(g_file_manager->get_project_file("./cache/peds.bin"), 1),
|
||||
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_update_state(eGtaDataUpdateState::IDLE)
|
||||
{
|
||||
if (!is_cache_up_to_date())
|
||||
m_update_state = eGtaDataUpdateState::NEEDS_UPDATE;
|
||||
@ -52,8 +53,7 @@ namespace big
|
||||
void gta_data_service::update_in_online()
|
||||
{
|
||||
m_update_state = eGtaDataUpdateState::WAITING_FOR_SINGLE_PLAYER;
|
||||
g_fiber_pool->queue_job([this]
|
||||
{
|
||||
g_fiber_pool->queue_job([this] {
|
||||
while (*g_pointers->m_game_state != eGameState::Playing)
|
||||
{
|
||||
script::get_current()->yield(100ms);
|
||||
@ -74,8 +74,7 @@ namespace big
|
||||
void gta_data_service::update_now()
|
||||
{
|
||||
m_update_state = eGtaDataUpdateState::WAITING_FOR_SINGLE_PLAYER;
|
||||
g_fiber_pool->queue_job([this]
|
||||
{
|
||||
g_fiber_pool->queue_job([this] {
|
||||
rebuild_cache();
|
||||
});
|
||||
}
|
||||
@ -126,13 +125,11 @@ namespace big
|
||||
m_vehicles_cache.load();
|
||||
m_weapons_cache.load();
|
||||
|
||||
const auto game_version = std::strtoul(g_pointers->m_game_version, nullptr, 10);
|
||||
const auto game_version = std::strtoul(g_pointers->m_game_version, nullptr, 10);
|
||||
const auto online_version = std::strtof(g_pointers->m_online_version, nullptr);
|
||||
|
||||
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(game_version, online_version) && m_vehicles_cache.up_to_date(game_version, online_version)
|
||||
&& m_weapons_cache.up_to_date(game_version, online_version);
|
||||
}
|
||||
|
||||
void gta_data_service::load_data()
|
||||
@ -157,7 +154,7 @@ namespace big
|
||||
const auto ped = cached_peds[i];
|
||||
|
||||
add_if_not_exists(m_ped_types, ped.m_ped_type);
|
||||
m_peds.insert({ ped.m_name, ped });
|
||||
m_peds.insert({ped.m_name, ped});
|
||||
}
|
||||
|
||||
std::sort(m_ped_types.begin(), m_ped_types.end());
|
||||
@ -175,7 +172,7 @@ namespace big
|
||||
const auto vehicle = cached_vehicles[i];
|
||||
|
||||
add_if_not_exists(m_vehicle_classes, vehicle.m_vehicle_class);
|
||||
m_vehicles.insert({ vehicle.m_name, vehicle });
|
||||
m_vehicles.insert({vehicle.m_name, vehicle});
|
||||
}
|
||||
|
||||
std::sort(m_vehicle_classes.begin(), m_vehicle_classes.end());
|
||||
@ -193,7 +190,7 @@ namespace big
|
||||
const auto weapon = cached_weapons[i];
|
||||
|
||||
add_if_not_exists(m_weapon_types, weapon.m_weapon_type);
|
||||
m_weapons.insert({ weapon.m_name, weapon });
|
||||
m_weapons.insert({weapon.m_name, weapon});
|
||||
}
|
||||
|
||||
std::sort(m_weapon_types.begin(), m_weapon_types.end());
|
||||
@ -206,8 +203,8 @@ namespace big
|
||||
for (const auto& item_node : items)
|
||||
{
|
||||
const auto& item = item_node.node();
|
||||
const auto name = item.child("Name").text().as_string();
|
||||
const auto hash = rage::joaat(name);
|
||||
const auto name = item.child("Name").text().as_string();
|
||||
const auto hash = rage::joaat(name);
|
||||
|
||||
if (std::find(mapped_peds.begin(), mapped_peds.end(), hash) != mapped_peds.end())
|
||||
continue;
|
||||
@ -240,24 +237,22 @@ namespace big
|
||||
std::vector<vehicle_item> vehicles;
|
||||
std::vector<weapon_item> weapons;
|
||||
|
||||
constexpr auto exists = [](const hash_array& arr, std::uint32_t val) -> bool
|
||||
{
|
||||
constexpr auto exists = [](const hash_array& arr, std::uint32_t val) -> bool {
|
||||
return std::find(arr.begin(), arr.end(), val) != arr.end();
|
||||
};
|
||||
|
||||
LOG(INFO) << "Rebuilding cache started...";
|
||||
yim_fipackfile::for_each_fipackfile([&](yim_fipackfile& rpf_wrapper)
|
||||
{
|
||||
|
||||
yim_fipackfile::for_each_fipackfile([&](yim_fipackfile& rpf_wrapper) {
|
||||
const auto files = rpf_wrapper.get_file_paths();
|
||||
for (const auto& file : files)
|
||||
{
|
||||
if (file.filename() == "setup2.xml")
|
||||
{
|
||||
std::string dlc_name;
|
||||
rpf_wrapper.read_xml_file(file, [&dlc_name](pugi::xml_document& doc)
|
||||
{
|
||||
rpf_wrapper.read_xml_file(file, [&dlc_name](pugi::xml_document& doc) {
|
||||
const auto item = doc.select_node("/SSetupData/nameHash");
|
||||
dlc_name = item.node().text().as_string();
|
||||
dlc_name = item.node().text().as_string();
|
||||
});
|
||||
|
||||
if (dlc_name == "mpG9EC")
|
||||
@ -269,8 +264,7 @@ namespace big
|
||||
}
|
||||
else if (file.filename() == "vehicles.meta")
|
||||
{
|
||||
rpf_wrapper.read_xml_file(file, [&exists, &vehicles, &mapped_vehicles](pugi::xml_document& doc)
|
||||
{
|
||||
rpf_wrapper.read_xml_file(file, [&exists, &vehicles, &mapped_vehicles](pugi::xml_document& doc) {
|
||||
const auto& items = doc.select_nodes("/CVehicleModelInfo__InitDataList/InitDatas/Item");
|
||||
for (const auto& item_node : items)
|
||||
{
|
||||
@ -287,24 +281,15 @@ namespace big
|
||||
std::strncpy(veh.m_name, name, sizeof(veh.m_name));
|
||||
|
||||
const auto manufacturer_display = item.child("vehicleMakeName").text().as_string();
|
||||
std::strncpy(
|
||||
veh.m_display_manufacturer,
|
||||
HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(manufacturer_display),
|
||||
sizeof(veh.m_display_manufacturer));
|
||||
std::strncpy(veh.m_display_manufacturer, HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(manufacturer_display), sizeof(veh.m_display_manufacturer));
|
||||
|
||||
const auto game_name = item.child("gameName").text().as_string();
|
||||
std::strncpy(
|
||||
veh.m_display_name,
|
||||
HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(game_name),
|
||||
sizeof(veh.m_display_name));
|
||||
std::strncpy(veh.m_display_name, HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(game_name), sizeof(veh.m_display_name));
|
||||
|
||||
char vehicle_class[32];
|
||||
std::sprintf(vehicle_class, "VEH_CLASS_%i", VEHICLE::GET_VEHICLE_CLASS_FROM_NAME(hash));
|
||||
std::strncpy(
|
||||
veh.m_vehicle_class,
|
||||
HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(vehicle_class),
|
||||
sizeof(veh.m_vehicle_class));
|
||||
|
||||
std::strncpy(veh.m_vehicle_class, HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(vehicle_class), sizeof(veh.m_vehicle_class));
|
||||
|
||||
veh.m_hash = hash;
|
||||
|
||||
vehicles.emplace_back(std::move(veh));
|
||||
@ -313,8 +298,7 @@ namespace big
|
||||
}
|
||||
else if (const auto file_str = file.string(); file_str.find("weapon") != std::string::npos && file.extension() == ".meta")
|
||||
{
|
||||
rpf_wrapper.read_xml_file(file, [&exists, &weapons, &mapped_weapons](pugi::xml_document& doc)
|
||||
{
|
||||
rpf_wrapper.read_xml_file(file, [&exists, &weapons, &mapped_weapons](pugi::xml_document& doc) {
|
||||
const auto& items = doc.select_nodes("/CWeaponInfoBlob/Infos/Item/Infos/Item[@type='CWeaponInfo']");
|
||||
for (const auto& item_node : items)
|
||||
{
|
||||
@ -340,17 +324,15 @@ namespace big
|
||||
const auto display_name = HUD::GET_FILENAME_FOR_AUDIO_CONVERSATION(human_name_hash);
|
||||
std::strncpy(weapon.m_display_name, display_name, sizeof(weapon.m_name));
|
||||
|
||||
auto weapon_flags = std::string(
|
||||
item.child("WeaponFlags").text().as_string()
|
||||
);
|
||||
auto weapon_flags = std::string(item.child("WeaponFlags").text().as_string());
|
||||
|
||||
bool is_gun = false;
|
||||
bool is_gun = false;
|
||||
bool is_rechargable = false;
|
||||
|
||||
const char* category = "";
|
||||
|
||||
std::size_t pos;
|
||||
while ((pos = weapon_flags.find(' ')) != std::string::npos)
|
||||
while ((pos = weapon_flags.find(' ')) != std::string::npos)
|
||||
{
|
||||
const auto flag = weapon_flags.substr(0, pos);
|
||||
if (flag == "Thrown")
|
||||
@ -386,11 +368,11 @@ namespace big
|
||||
if (is_gun || !std::strcmp(weapon.m_weapon_type, "MELEE") || !std::strcmp(weapon.m_weapon_type, "UNARMED"))
|
||||
{
|
||||
const std::string reward_prefix = "REWARD_";
|
||||
weapon.m_reward_hash = rage::joaat(reward_prefix + name);
|
||||
weapon.m_reward_hash = rage::joaat(reward_prefix + name);
|
||||
|
||||
if (is_gun && !is_rechargable)
|
||||
{
|
||||
std::string weapon_id = name + 7;
|
||||
std::string weapon_id = name + 7;
|
||||
weapon.m_reward_ammo_hash = rage::joaat(reward_prefix + "AMMO_" + weapon_id);
|
||||
}
|
||||
}
|
||||
@ -398,15 +380,14 @@ namespace big
|
||||
weapon.m_hash = hash;
|
||||
|
||||
weapons.emplace_back(std::move(weapon));
|
||||
skip:
|
||||
skip:
|
||||
continue;
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (file.filename() == "peds.meta")
|
||||
{
|
||||
rpf_wrapper.read_xml_file(file, [&exists, &peds, &mapped_peds](pugi::xml_document& doc)
|
||||
{
|
||||
rpf_wrapper.read_xml_file(file, [&exists, &peds, &mapped_peds](pugi::xml_document& doc) {
|
||||
parse_ped(peds, mapped_peds, doc);
|
||||
});
|
||||
}
|
||||
@ -416,12 +397,12 @@ skip:
|
||||
});
|
||||
|
||||
m_update_state = eGtaDataUpdateState::IDLE;
|
||||
LOG(INFO) << "Cache has been rebuilt.\n\tPeds: " << peds.size() << "\n\tVehicles: " << vehicles.size() << "\n\tWeapons: " << weapons.size();
|
||||
LOG(INFO) << "Cache has been rebuilt.\n\tPeds: " << peds.size() << "\n\tVehicles: " << vehicles.size()
|
||||
<< "\n\tWeapons: " << weapons.size();
|
||||
|
||||
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 = std::strtoul(g_pointers->m_game_version, nullptr, 10);
|
||||
g_thread_pool->push([this, peds = std::move(peds), vehicles = std::move(vehicles), weapons = std::move(weapons)] {
|
||||
const auto game_version = std::strtoul(g_pointers->m_game_version, nullptr, 10);
|
||||
const auto online_version = std::strtof(g_pointers->m_online_version, nullptr);
|
||||
|
||||
{
|
||||
|
Reference in New Issue
Block a user