diff --git a/src/backend/commands/player/toxic/give_all_weapons.cpp b/src/backend/commands/player/toxic/give_all_weapons.cpp index a39d4059..39c9574e 100644 --- a/src/backend/commands/player/toxic/give_all_weapons.cpp +++ b/src/backend/commands/player/toxic/give_all_weapons.cpp @@ -16,7 +16,7 @@ namespace big virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr ctx) override { - for (auto& weapon : g_gta_data_service->weapons()) + for (auto& weapon : g_gta_data_service.weapons()) WEAPON::GIVE_WEAPON_TO_PED(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id()), weapon.second.m_hash, 9999, FALSE, FALSE); } }; @@ -33,7 +33,7 @@ namespace big virtual void execute(const command_arguments& _args, const std::shared_ptr ctx) override { g_player_service->iterate([](auto& plyr) { - for (auto& weapon : g_gta_data_service->weapons()) + for (auto& weapon : g_gta_data_service.weapons()) WEAPON::GIVE_WEAPON_TO_PED(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(plyr.second->id()), weapon.second.m_hash, 9999, FALSE, FALSE); script::get_current()->yield(500ms); }); @@ -42,4 +42,4 @@ namespace big give_all_weapons g_give_all_weapons("giveweaps", "GIVE_WEAPONS", "GIVE_WEAPONS_DESC", 0, false); give_all_weapons_all g_give_all_weapons_all("giveweapsall", "GIVE_WEAPONS", "GIVE_WEAPONS_ALL_DESC", 0); -} \ No newline at end of file +} diff --git a/src/backend/commands/player/toxic/kamikaze.cpp b/src/backend/commands/player/toxic/kamikaze.cpp index bcdca206..0667af60 100644 --- a/src/backend/commands/player/toxic/kamikaze.cpp +++ b/src/backend/commands/player/toxic/kamikaze.cpp @@ -42,7 +42,7 @@ namespace big } else if (arg == 3) { - for (auto& item : g_gta_data_service->vehicles()) + for (auto& item : g_gta_data_service.vehicles()) { suggestions.push_back(item.second.m_name); } @@ -92,7 +92,7 @@ namespace big std::string item_name_lower, args_lower; args_lower = args[2]; string::operations::to_lower(args_lower); - for (auto& item : g_gta_data_service->vehicles()) + for (auto& item : g_gta_data_service.vehicles()) { item_name_lower = item.second.m_name; string::operations::to_lower(item_name_lower); diff --git a/src/backend/commands/player/toxic/remove_all_weapons.cpp b/src/backend/commands/player/toxic/remove_all_weapons.cpp index ec2459be..5c5c333f 100644 --- a/src/backend/commands/player/toxic/remove_all_weapons.cpp +++ b/src/backend/commands/player/toxic/remove_all_weapons.cpp @@ -15,10 +15,10 @@ namespace big virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr ctx) override { - for (auto& [_, weapon] : g_gta_data_service->weapons()) + for (auto& [_, weapon] : g_gta_data_service.weapons()) WEAPON::REMOVE_WEAPON_FROM_PED(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id()), weapon.m_hash); } }; remove_all_weapons g_remove_all_weapons("remweaps", "REMOVE_ALL_WEAPONS", "REMOVE_ALL_WEAPONS_DESC", 0); -} \ No newline at end of file +} diff --git a/src/backend/commands/self/ammo.cpp b/src/backend/commands/self/ammo.cpp index 11a0d4ad..78310a9a 100644 --- a/src/backend/commands/self/ammo.cpp +++ b/src/backend/commands/self/ammo.cpp @@ -10,7 +10,7 @@ namespace big virtual void execute(const command_arguments&, const std::shared_ptr ctx) override { - for (const auto& [_, weapon] : g_gta_data_service->weapons()) + for (const auto& [_, weapon] : g_gta_data_service.weapons()) { int ammo_in; WEAPON::GET_MAX_AMMO(self::ped, weapon.m_hash, &ammo_in); @@ -19,4 +19,4 @@ namespace big } }; fill_ammo g_fill_ammo("fillammo", "FILL_AMMO", "FILL_AMMO_DESC", 0); -} \ No newline at end of file +} diff --git a/src/backend/commands/spawn/spawn_vehicle.cpp b/src/backend/commands/spawn/spawn_vehicle.cpp index ff01cc1b..7d3722eb 100644 --- a/src/backend/commands/spawn/spawn_vehicle.cpp +++ b/src/backend/commands/spawn/spawn_vehicle.cpp @@ -17,7 +17,7 @@ namespace big if (arg == 1) { std::vector suggestions; - for (auto& item : g_gta_data_service->vehicles()) + for (auto& item : g_gta_data_service.vehicles()) { suggestions.push_back(item.second.m_name); } @@ -31,13 +31,13 @@ namespace big { command_arguments result(1); - if (g_gta_data_service->vehicle_by_hash(rage::joaat(args[0])).m_hash != 0) + if (g_gta_data_service.vehicle_by_hash(rage::joaat(args[0])).m_hash != 0) { result.push(rage::joaat(args[0])); return result; } - for (auto& item : g_gta_data_service->vehicles()) + for (auto& item : g_gta_data_service.vehicles()) { std::string item_name_lower, args_lower; item_name_lower = item.second.m_name; @@ -70,8 +70,7 @@ namespace big auto id = ctx->get_sender()->id(); - const auto spawn_location = vehicle::get_spawn_location(id == self::id ? g.spawn_vehicle.spawn_inside : false, - hash, PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(id)); + const auto spawn_location = vehicle::get_spawn_location(id == self::id ? g.spawn_vehicle.spawn_inside : false, hash, PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(id)); const auto spawn_heading = ENTITY::GET_ENTITY_HEADING(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(id)); auto veh = vehicle::spawn(hash, spawn_location, spawn_heading); diff --git a/src/backend/looped/weapons/weapon_hotkeys.cpp b/src/backend/looped/weapons/weapon_hotkeys.cpp index 5c18b577..3d7e8e3c 100644 --- a/src/backend/looped/weapons/weapon_hotkeys.cpp +++ b/src/backend/looped/weapons/weapon_hotkeys.cpp @@ -10,7 +10,7 @@ namespace big static void resolve_weapon_hotkey(Hash weapon) { - if (g_gta_data_service->weapon_by_hash(weapon).m_name.empty()) + if (g_gta_data_service.weapon_by_hash(weapon).m_name.empty()) { WEAPON::SET_CURRENT_PED_VEHICLE_WEAPON(self::ped, weapon); } @@ -61,4 +61,4 @@ namespace big } } } -} \ No newline at end of file +} diff --git a/src/hooks/protections/received_event.cpp b/src/hooks/protections/received_event.cpp index 9db335bc..1d05a709 100644 --- a/src/hooks/protections/received_event.cpp +++ b/src/hooks/protections/received_event.cpp @@ -52,7 +52,7 @@ namespace big return false; } - + // Returns true if bad event bool scan_weapon_damage_event(rage::netEventMgr* event_manager, CNetGamePlayer* player, CNetGamePlayer* target_player, int event_index, int event_handled_bitset, rage::datBitBuffer* buffer) { @@ -103,7 +103,11 @@ namespace big if (!is_valid_weapon(weaponType)) { notify::crash_blocked(player, "invalid weapon type"); - LOGF(stream::net_events, WARNING, "Blocked WEAPON_DAMAGE_EVENT from {} with invalid weapon hash {:X}", player->get_name(), weaponType); + LOGF(stream::net_events, + WARNING, + "Blocked WEAPON_DAMAGE_EVENT from {} with invalid weapon hash {:X}", + player->get_name(), + weaponType); g_pointers->m_gta.m_send_event_ack(event_manager, player, target_player, event_index, event_handled_bitset); return true; } @@ -424,7 +428,8 @@ namespace big static const std::unordered_set blocked_script_hashes = {"main_persistent"_J, "shop_controller"_J}; bool should_block = [&] { - if (blocked_ref_hashes.contains(ref_hash) || blocked_sound_hashes.contains(sound_hash) || blocked_script_hashes.contains(script_hash)) + if (blocked_ref_hashes.contains(ref_hash) || blocked_sound_hashes.contains(sound_hash) + || blocked_script_hashes.contains(script_hash)) return true; switch (sound_hash) @@ -551,7 +556,7 @@ namespace big else if (type == ScriptEntityChangeType::SetVehicleLockState) { if (g_local_player && g_local_player->m_vehicle && g_local_player->m_vehicle->m_net_object - && g_local_player->m_vehicle->m_net_object->m_object_id == entity) + && g_local_player->m_vehicle->m_net_object->m_object_id == entity) { g_pointers->m_gta.m_send_event_ack(event_manager, source_player, target_player, event_index, event_handled_bitset); LOGF(stream::net_events, WARNING, "Blocked SCRIPT_ENTITY_STATE_CHANGE_EVENT of type SetVehicleLockState from {} on our local vehicle", plyr->get_name()); @@ -673,8 +678,8 @@ namespace big { Vehicle personal_vehicle = mobile::mechanic::get_personal_vehicle(); Vehicle veh = g_pointers->m_gta.m_ptr_to_handle(g_local_player->m_vehicle); - if (!NETWORK::NETWORK_IS_ACTIVITY_SESSION() //If we're in Freemode. - || personal_vehicle == veh //Or we're in our personal vehicle. + if (!NETWORK::NETWORK_IS_ACTIVITY_SESSION() //If we're in Freemode. + || personal_vehicle == veh //Or we're in our personal vehicle. || self::spawned_vehicles.contains(net_id)) // Or it's a vehicle we spawned. { // Let trusted friends and players request control (e.g., they want to hook us to their tow-truck or something) @@ -769,9 +774,9 @@ namespace big if (g_local_player && g_local_player->m_net_object && g_local_player->m_net_object->m_object_id == net_id) { - weapon_item weapon = g_gta_data_service->weapon_by_hash(hash); + weapon_item weapon = g_gta_data_service.weapon_by_hash(hash); g_notification_service.push_warning("PROTECTIONS"_T.data(), - std::format("{} {} {}.", source_player->get_name(), "REMOVE_WEAPON_ATTEMPT_MESSAGE"_T, weapon.m_display_name)); + std::format("{} {} {}.", source_player->get_name(), "REMOVE_WEAPON_ATTEMPT_MESSAGE"_T, weapon.m_display_name)); g_pointers->m_gta.m_send_event_ack(event_manager, source_player, target_player, event_index, event_handled_bitset); return; } @@ -786,7 +791,7 @@ namespace big if (g_local_player && g_local_player->m_net_object && g_local_player->m_net_object->m_object_id == net_id) { - weapon_item weapon = g_gta_data_service->weapon_by_hash(hash); + weapon_item weapon = g_gta_data_service.weapon_by_hash(hash); g_notification_service.push_warning("PROTECTIONS"_T.data(), std::format("{} {} {}.", source_player->get_name(), "GIVE_WEAPON_ATTEMPT_MESSAGE"_T, weapon.m_display_name)); g_pointers->m_gta.m_send_event_ack(event_manager, source_player, target_player, event_index, event_handled_bitset); diff --git a/src/lua/bindings/vehicles.cpp b/src/lua/bindings/vehicles.cpp index 9875774b..af36d940 100644 --- a/src/lua/bindings/vehicles.cpp +++ b/src/lua/bindings/vehicles.cpp @@ -18,7 +18,7 @@ namespace lua::vehicles //``` static std::string get_vehicle_display_name(Hash vehicle_hash) { - return big::g_gta_data_service->vehicle_by_hash(vehicle_hash).m_display_name; + return big::g_gta_data_service.vehicle_by_hash(vehicle_hash).m_display_name; } // Lua API: Function @@ -32,7 +32,7 @@ namespace lua::vehicles //``` static std::string get_vehicle_display_name_string(std::string vehicle_name) { - return big::g_gta_data_service->vehicle_by_hash(rage::joaat(vehicle_name)).m_display_name; + return big::g_gta_data_service.vehicle_by_hash(rage::joaat(vehicle_name)).m_display_name; } // Lua API: Function @@ -50,7 +50,7 @@ namespace lua::vehicles static std::vector get_all_vehicles_by_class(std::string vehicle_class) { std::vector return_value; - for (auto& [name, vehicle] : big::g_gta_data_service->vehicles()) + for (auto& [name, vehicle] : big::g_gta_data_service.vehicles()) { if (vehicle.m_vehicle_class == vehicle_class) { @@ -76,7 +76,7 @@ namespace lua::vehicles static std::vector get_all_vehicles_by_mfr(std::string manufacturer) { std::vector return_value; - for (auto& [name, vehicle] : big::g_gta_data_service->vehicles()) + for (auto& [name, vehicle] : big::g_gta_data_service.vehicles()) { if (vehicle.m_display_manufacturer == manufacturer) { @@ -88,9 +88,9 @@ namespace lua::vehicles void bind(sol::state& state) { - auto ns = state["vehicles"].get_or_create(); - ns["get_vehicle_display_name"] = sol::overload(get_vehicle_display_name, get_vehicle_display_name_string); - ns["get_all_vehicles_by_class"] = get_all_vehicles_by_class; - ns["get_all_vehicles_by_mfr"] = get_all_vehicles_by_mfr; + auto ns = state["vehicles"].get_or_create(); + ns["get_vehicle_display_name"] = sol::overload(get_vehicle_display_name, get_vehicle_display_name_string); + ns["get_all_vehicles_by_class"] = get_all_vehicles_by_class; + ns["get_all_vehicles_by_mfr"] = get_all_vehicles_by_mfr; } -} \ No newline at end of file +} diff --git a/src/lua/bindings/weapons.cpp b/src/lua/bindings/weapons.cpp index c267b6fb..59aaef84 100644 --- a/src/lua/bindings/weapons.cpp +++ b/src/lua/bindings/weapons.cpp @@ -18,7 +18,7 @@ namespace lua::weapons //``` static std::string get_weapon_display_name(Hash weapon_hash) { - return big::g_gta_data_service->weapon_by_hash(weapon_hash).m_display_name; + return big::g_gta_data_service.weapon_by_hash(weapon_hash).m_display_name; } // Lua API: Function @@ -32,7 +32,7 @@ namespace lua::weapons //``` static std::string get_weapon_display_name_string(std::string weapon_name) { - return big::g_gta_data_service->weapon_by_hash(rage::joaat(weapon_name)).m_display_name; + return big::g_gta_data_service.weapon_by_hash(rage::joaat(weapon_name)).m_display_name; } // Lua API: Function @@ -50,7 +50,7 @@ namespace lua::weapons static std::vector get_all_weapons_of_group_type(Hash group_hash) { std::vector return_value; - for (auto& [name, weapon] : big::g_gta_data_service->weapons()) + for (auto& [name, weapon] : big::g_gta_data_service.weapons()) { if (rage::joaat("GROUP_" + weapon.m_weapon_type) == group_hash) { @@ -85,7 +85,7 @@ namespace lua::weapons group_name.erase(0, 6); } std::vector return_value; - for (auto& [name, weapon] : big::g_gta_data_service->weapons()) + for (auto& [name, weapon] : big::g_gta_data_service.weapons()) { if (weapon.m_weapon_type == group_name) { @@ -109,7 +109,7 @@ namespace lua::weapons //``` static std::vector get_all_weapon_components(Hash weapon_hash) { - return big::g_gta_data_service->weapon_by_hash(weapon_hash).m_attachments; + return big::g_gta_data_service.weapon_by_hash(weapon_hash).m_attachments; } // Lua API: Function @@ -126,7 +126,7 @@ namespace lua::weapons //``` static std::vector get_all_weapon_components_string(std::string weapon_name) { - return big::g_gta_data_service->weapon_by_hash(rage::joaat(weapon_name)).m_attachments; + return big::g_gta_data_service.weapon_by_hash(rage::joaat(weapon_name)).m_attachments; } // Lua API: Function @@ -140,7 +140,7 @@ namespace lua::weapons //``` static std::string get_weapon_component_display_name(Hash weapon_component_hash) { - return big::g_gta_data_service->weapon_component_by_hash(weapon_component_hash).m_display_name; + return big::g_gta_data_service.weapon_component_by_hash(weapon_component_hash).m_display_name; } // Lua API: Function @@ -154,7 +154,7 @@ namespace lua::weapons //``` static std::string get_weapon_component_display_name_string(std::string weapon_component) { - return big::g_gta_data_service->weapon_component_by_hash(rage::joaat(weapon_component)).m_display_name; + return big::g_gta_data_service.weapon_component_by_hash(rage::joaat(weapon_component)).m_display_name; } // Lua API: Function @@ -168,7 +168,7 @@ namespace lua::weapons //``` static std::string get_weapon_component_display_desc(Hash weapon_component_hash) { - return big::g_gta_data_service->weapon_component_by_hash(weapon_component_hash).m_display_desc; + return big::g_gta_data_service.weapon_component_by_hash(weapon_component_hash).m_display_desc; } // Lua API: Function @@ -182,16 +182,16 @@ namespace lua::weapons //``` static std::string get_weapon_component_display_desc_string(std::string weapon_component) { - return big::g_gta_data_service->weapon_component_by_hash(rage::joaat(weapon_component)).m_display_desc; + return big::g_gta_data_service.weapon_component_by_hash(rage::joaat(weapon_component)).m_display_desc; } void bind(sol::state& state) { - auto ns = state["weapons"].get_or_create(); - ns["get_weapon_display_name"] = sol::overload(get_weapon_display_name, get_weapon_display_name_string); - ns["get_all_weapons_of_group_type"] = sol::overload(get_all_weapons_of_group_type, get_all_weapons_of_group_type_string); - ns["get_all_weapon_components"] = sol::overload(get_all_weapon_components, get_all_weapon_components_string); + auto ns = state["weapons"].get_or_create(); + ns["get_weapon_display_name"] = sol::overload(get_weapon_display_name, get_weapon_display_name_string); + ns["get_all_weapons_of_group_type"] = sol::overload(get_all_weapons_of_group_type, get_all_weapons_of_group_type_string); + ns["get_all_weapon_components"] = sol::overload(get_all_weapon_components, get_all_weapon_components_string); ns["get_weapon_component_display_name"] = sol::overload(get_weapon_component_display_name, get_weapon_component_display_name_string); ns["get_weapon_component_display_desc"] = sol::overload(get_weapon_component_display_desc, get_weapon_component_display_desc_string); } -} \ No newline at end of file +} diff --git a/src/main.cpp b/src/main.cpp index dd4ebe60..35c1ac12 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -204,12 +204,13 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID) auto hooking_instance = std::make_unique(); LOG(INFO) << "Hooking initialized."; + g_gta_data_service.init(); + auto context_menu_service_instance = std::make_unique(); auto custom_text_service_instance = std::make_unique(); auto mobile_service_instance = std::make_unique(); auto pickup_service_instance = std::make_unique(); auto player_service_instance = std::make_unique(); - auto gta_data_service_instance = std::make_unique(); auto model_preview_service_instance = std::make_unique(); auto handling_service_instance = std::make_unique(); auto gui_service_instance = std::make_unique(); @@ -224,8 +225,8 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID) auto xml_maps_service_instance = std::make_unique(); LOG(INFO) << "Registered service instances..."; - g_notification_service.initialise(); - LOG(INFO) << "Finished initialising services."; + g_notification_service.initialise(); + LOG(INFO) << "Finished initialising services."; g_script_mgr.add_script(std::make_unique