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:
maybegreat48
2023-03-01 21:27:15 +00:00
committed by GitHub
parent 92aea20cd6
commit 97a8c5d60b
466 changed files with 55224 additions and 35596 deletions

View File

@ -3,12 +3,11 @@
namespace big
{
cache_file::cache_file(file cache_file, std::uint32_t cache_version) :
m_cache_file(cache_file),
m_data(nullptr),
m_cache_version(cache_version),
m_cache_header()
m_cache_file(cache_file),
m_data(nullptr),
m_cache_version(cache_version),
m_cache_header()
{
}
void cache_file::free()
@ -39,7 +38,7 @@ namespace big
if (!m_data)
return false;
auto file = std::ofstream(m_cache_file.get_path(), std::ios::binary);
auto file = std::ofstream(m_cache_file.get_path(), std::ios::binary);
file.write(reinterpret_cast<const char*>(&m_cache_header), sizeof(m_cache_header));
file.write(reinterpret_cast<const char*>(m_data.get()), m_cache_header.m_data_size);
@ -63,10 +62,8 @@ namespace big
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 && game_version == m_cache_header.m_game_version
&& online_version == m_cache_header.m_online_version;
}
void cache_file::set_data(cache_data&& data, std::uint64_t data_size)
@ -77,8 +74,8 @@ namespace big
void cache_file::set_header_version(std::uint32_t game_version, float online_version)
{
m_cache_header.m_cache_version = m_cache_version;
m_cache_header.m_game_version = game_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;
}
}

View File

@ -17,7 +17,7 @@ namespace big
{
public:
/// <summary>
///
///
/// </summary>
/// <param name="cache_file">FileMgr file object</param>
/// <param name="cache_version">Internal version, use this to invalidate the cache when changing the structure of the data</param>

View File

@ -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);
{

View File

@ -15,10 +15,10 @@ namespace big
UPDATING
};
using ped_map = std::map<std::string, ped_item>;
using ped_map = std::map<std::string, ped_item>;
using vehicle_map = std::map<std::string, vehicle_item>;
using weapon_map = std::map<std::string, weapon_item>;
using string_vec = std::vector<std::string>;
using weapon_map = std::map<std::string, weapon_item>;
using string_vec = std::vector<std::string>;
class gta_data_service final
{
@ -40,15 +40,21 @@ namespace big
string_vec& weapon_types();
ped_map& peds()
{ return m_peds; }
{
return m_peds;
}
vehicle_map& vehicles()
{ return m_vehicles; }
{
return m_vehicles;
}
weapon_map& weapons()
{ return m_weapons; }
{
return m_weapons;
}
private:
bool is_cache_up_to_date();
void load_data();
void load_peds();
void load_vehicles();
@ -73,10 +79,9 @@ namespace big
eGtaDataUpdateState m_update_state;
private:
static constexpr ped_item empty_ped {};
static constexpr vehicle_item empty_vehicle {};
static constexpr weapon_item empty_weapon {};
static constexpr ped_item empty_ped{};
static constexpr vehicle_item empty_vehicle{};
static constexpr weapon_item empty_weapon{};
};
inline gta_data_service* g_gta_data_service{};

View File

@ -1,13 +1,14 @@
#include "yim_fipackfile.hpp"
#include "pointers.hpp"
#include "gta/fidevice.hpp"
#include "pointers.hpp"
#include "script.hpp"
namespace big
{
yim_fipackfile::yim_fipackfile(rage::fiPackfile* rpf, const std::string& mount_name)
{
this->rpf = rpf;
this->rpf = rpf;
this->mount_name = mount_name;
}
@ -18,9 +19,9 @@ namespace big
uint16_t mounted_devices_len = *g_pointers->m_fidevices_len;
if (mounted_devices_len)
{
auto devices_arr = *(uint64_t*)g_pointers->m_fidevices;
auto devices_arr = *(uint64_t*)g_pointers->m_fidevices;
uint8_t** current_device_mount_name_ptr = *(unsigned __int8***)g_pointers->m_fidevices;
auto device_i = 0;
auto device_i = 0;
while (true)
{
@ -36,17 +37,6 @@ namespace big
return non_dlc_mounted_devices_names;
}
static int ends_with(const char* str, const char* suffix)
{
if (!str || !suffix)
return 0;
size_t lenstr = strlen(str);
size_t lensuffix = strlen(suffix);
if (lensuffix > lenstr)
return 0;
return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0;
}
void yim_fipackfile::for_each_fipackfile(std::function<size_t(yim_fipackfile& rpf_wrapper)> cb)
{
// the idea is to reuse existing mount points as much as possible because
@ -81,7 +71,7 @@ namespace big
if (rpf == non_dlc_mounted_device)
{
rpf_wrapper.mount_name = non_dlc_mounted_device_name;
already_mounted = true;
already_mounted = true;
}
}
@ -157,8 +147,8 @@ namespace big
std::vector<std::string> directories;
rage::fiFindData findData = { 0 };
auto handlef = rpf->FindFirst(parent.c_str(), &findData);
rage::fiFindData findData = {0};
auto handlef = rpf->FindFirst(parent.c_str(), &findData);
if (handlef != -1)
{
do
@ -192,7 +182,7 @@ namespace big
{
if (const auto handle = rpf->Open(path.string().c_str(), true); handle != -1)
{
const auto data_length = rpf->GetFileLength(handle);
const auto data_length = rpf->GetFileLength(handle);
const auto file_content = std::make_unique<std::uint8_t[]>(data_length);
rpf->ReadFull(handle, file_content.get(), data_length);
@ -205,8 +195,7 @@ namespace big
void yim_fipackfile::read_xml_file(const std::filesystem::path& path, std::function<void(pugi::xml_document& doc)> cb)
{
read_file(path, [&cb](const std::unique_ptr<std::uint8_t[]>& file_content, const int data_size)
{
read_file(path, [&cb](const std::unique_ptr<std::uint8_t[]>& file_content, const int data_size) {
if (pugi::xml_document doc; doc.load_buffer(file_content.get(), data_size).status == pugi::xml_parse_status::status_ok)
{
cb(doc);

View File

@ -22,6 +22,5 @@ namespace big
void read_xml_file(const std::filesystem::path& path, std::function<void(pugi::xml_document& doc)> cb);
private:
};
}