2021-08-05 01:26:23 +02:00
|
|
|
#pragma once
|
2023-10-13 00:11:37 +02:00
|
|
|
#include "core/data/infractions.hpp"
|
2021-08-05 01:26:23 +02:00
|
|
|
#include "core/data/session_types.hpp"
|
2023-03-01 21:27:15 +00:00
|
|
|
#include "fiber_pool.hpp"
|
2022-10-26 14:12:29 +02:00
|
|
|
#include "gta/joaat.hpp"
|
2023-03-01 21:27:15 +00:00
|
|
|
#include "gta_util.hpp"
|
|
|
|
#include "natives.hpp"
|
|
|
|
#include "packet.hpp"
|
2022-10-26 14:12:29 +02:00
|
|
|
#include "pointers.hpp"
|
2023-03-01 21:27:15 +00:00
|
|
|
#include "rage/rlSessionByGamerTaskResult.hpp"
|
|
|
|
#include "script.hpp"
|
2023-07-12 17:03:29 +00:00
|
|
|
#include "script_function.hpp"
|
2022-12-17 17:24:45 +01:00
|
|
|
#include "services/api/api_service.hpp"
|
2023-03-01 21:27:15 +00:00
|
|
|
#include "services/player_database/player_database_service.hpp"
|
|
|
|
#include "services/players/player_service.hpp"
|
2022-12-17 17:24:45 +01:00
|
|
|
#include "thread_pool.hpp"
|
2023-03-01 21:27:15 +00:00
|
|
|
#include "util/globals.hpp"
|
|
|
|
#include "util/misc.hpp"
|
2023-01-03 16:48:32 +00:00
|
|
|
|
|
|
|
#include <network/Network.hpp>
|
|
|
|
#include <network/snConnectToPeerTask.hpp>
|
|
|
|
#include <rage/rlQueryPresenceAttributesContext.hpp>
|
2023-03-01 21:27:15 +00:00
|
|
|
#include <rage/rlScHandle.hpp>
|
2023-06-14 21:29:25 +00:00
|
|
|
#include <script/globals/GPBD_FM_3.hpp>
|
2021-08-05 01:26:23 +02:00
|
|
|
|
|
|
|
namespace big::session
|
|
|
|
{
|
2023-01-03 16:48:32 +00:00
|
|
|
static void gamer_handle_serialize(rage::rlGamerHandle& hnd, rage::datBitBuffer& buf)
|
|
|
|
{
|
|
|
|
buf.Write<uint8_t>(*reinterpret_cast<uint8_t*>(&hnd.m_platform), 8);
|
|
|
|
if (*reinterpret_cast<uint8_t*>(&hnd.m_platform) == 3)
|
|
|
|
{
|
|
|
|
buf.WriteInt64(*(int64_t*)&hnd.m_rockstar_id, 64);
|
|
|
|
buf.Write<uint8_t>(*reinterpret_cast<uint8_t*>(reinterpret_cast<__int64>(&hnd) + 9), 8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-10 23:06:08 +02:00
|
|
|
inline bool join_type(eSessionType session)
|
2021-08-05 01:26:23 +02:00
|
|
|
{
|
2023-07-12 17:03:29 +00:00
|
|
|
SCRIPT::REQUEST_SCRIPT_WITH_NAME_HASH(RAGE_JOAAT("pausemenu_multiplayer"));
|
2023-07-10 23:06:08 +02:00
|
|
|
|
2023-07-12 17:03:29 +00:00
|
|
|
while (!SCRIPT::HAS_SCRIPT_WITH_NAME_HASH_LOADED(RAGE_JOAAT("pausemenu_multiplayer")))
|
|
|
|
script::get_current()->yield();
|
|
|
|
|
2023-07-30 01:08:07 +02:00
|
|
|
*scr_globals::sctv_spectator.as<int*>() = (session == eSessionType::SC_TV ? 1 : 0); // If SCTV then enable spectator mode
|
2022-08-14 18:19:15 +08:00
|
|
|
|
2022-10-19 00:30:32 +02:00
|
|
|
if (session == eSessionType::LEAVE_ONLINE)
|
2023-08-24 16:06:50 -04:00
|
|
|
*scr_globals::session.at(2).as<int*>() = -1;
|
2021-08-05 01:26:23 +02:00
|
|
|
else
|
2023-07-12 17:03:29 +00:00
|
|
|
{
|
2023-08-24 16:06:50 -04:00
|
|
|
*scr_globals::session.at(2).as<int*>() = 0;
|
2023-10-13 00:11:37 +02:00
|
|
|
*scr_globals::session2.as<int*>() = (int)session;
|
2023-07-12 17:03:29 +00:00
|
|
|
}
|
2021-08-05 01:26:23 +02:00
|
|
|
|
2023-08-24 16:06:50 -04:00
|
|
|
*scr_globals::session.as<int*>() = 1;
|
2023-07-10 23:06:08 +02:00
|
|
|
|
2023-07-12 17:03:29 +00:00
|
|
|
if (*g_pointers->m_gta.m_is_session_started && session != eSessionType::LEAVE_ONLINE)
|
|
|
|
{
|
|
|
|
*scr_globals::transition_state.as<eTransitionState*>() = eTransitionState::TRANSITION_STATE_LOOK_TO_JOIN_ANOTHER_SESSION_FM;
|
|
|
|
}
|
2023-07-15 20:37:20 +00:00
|
|
|
else if (session == eSessionType::LEAVE_ONLINE)
|
|
|
|
{
|
|
|
|
*scr_globals::transition_state.as<eTransitionState*>() = eTransitionState::TRANSITION_STATE_RETURN_TO_SINGLEPLAYER;
|
|
|
|
}
|
2023-07-12 17:03:29 +00:00
|
|
|
|
|
|
|
scr_functions::reset_session_data({true, true});
|
2023-10-13 00:11:37 +02:00
|
|
|
*scr_globals::session3.as<int*>() = 0;
|
2023-08-24 16:06:50 -04:00
|
|
|
*scr_globals::session4.as<int*>() = 1;
|
|
|
|
*scr_globals::session5.as<int*>() = 32;
|
2023-07-12 17:03:29 +00:00
|
|
|
|
|
|
|
if (SCRIPT::GET_NUMBER_OF_THREADS_RUNNING_THE_SCRIPT_WITH_THIS_HASH(RAGE_JOAAT("maintransition")) == 0)
|
|
|
|
{
|
2023-08-24 16:06:50 -04:00
|
|
|
*scr_globals::session6.as<int*>() = 1;
|
2023-07-12 17:03:29 +00:00
|
|
|
script::get_current()->yield(200ms);
|
2023-08-24 16:06:50 -04:00
|
|
|
*scr_globals::session.as<int*>() = 0;
|
2023-07-12 17:03:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SCRIPT::SET_SCRIPT_WITH_NAME_HASH_AS_NO_LONGER_NEEDED(RAGE_JOAAT("pausemenu_multiplayer"));
|
2023-07-10 23:06:08 +02:00
|
|
|
return true;
|
2021-08-05 01:26:23 +02:00
|
|
|
}
|
2022-03-21 17:06:16 -04:00
|
|
|
|
2022-10-26 20:27:15 +02:00
|
|
|
inline void set_fm_event_index(int index)
|
|
|
|
{
|
|
|
|
int idx = index / 32;
|
|
|
|
int bit = index % 32;
|
2023-06-14 21:29:25 +00:00
|
|
|
misc::set_bit(scr_globals::gsbd_fm_events.at(11).at(361).at(idx, 1).as<int*>(), bit);
|
|
|
|
misc::set_bit(scr_globals::gsbd_fm_events.at(11).at(353).at(idx, 1).as<int*>(), bit);
|
|
|
|
misc::set_bit((int*)&scr_globals::gpbd_fm_3.as<GPBD_FM_3*>()->Entries[self::id].BossGoon.ActiveFreemodeEvents[idx], bit);
|
2022-10-26 20:27:15 +02:00
|
|
|
}
|
|
|
|
|
2022-12-06 16:12:02 +00:00
|
|
|
inline void clear_fm_event_index(int index)
|
2022-10-26 20:27:15 +02:00
|
|
|
{
|
2022-12-06 16:12:02 +00:00
|
|
|
int idx = index / 32;
|
|
|
|
int bit = index % 32;
|
2023-06-14 21:29:25 +00:00
|
|
|
misc::clear_bit(scr_globals::gsbd_fm_events.at(11).at(361).at(idx, 1).as<int*>(), bit);
|
|
|
|
misc::clear_bit(scr_globals::gsbd_fm_events.at(11).at(353).at(idx, 1).as<int*>(), bit);
|
|
|
|
misc::clear_bit((int*)&scr_globals::gpbd_fm_3.as<GPBD_FM_3*>()->Entries[self::id].BossGoon.ActiveFreemodeEvents[idx], bit);
|
2022-11-24 21:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void join_session(const rage::rlSessionInfo& info)
|
|
|
|
{
|
2023-07-12 17:03:29 +00:00
|
|
|
if (SCRIPT::GET_NUMBER_OF_THREADS_RUNNING_THE_SCRIPT_WITH_THIS_HASH(RAGE_JOAAT("maintransition")) != 0 || STREAMING::IS_PLAYER_SWITCH_IN_PROGRESS())
|
|
|
|
{
|
|
|
|
g_notification_service->push_error("RID Joiner", "Player switch in progress, wait a bit.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-18 23:15:52 +01:00
|
|
|
g.session.join_queued = true;
|
2023-03-01 21:27:15 +00:00
|
|
|
g.session.info = info;
|
|
|
|
session::join_type({eSessionType::NEW_PUBLIC});
|
2022-11-24 21:49:05 +00:00
|
|
|
if (SCRIPT::GET_NUMBER_OF_THREADS_RUNNING_THE_SCRIPT_WITH_THIS_HASH(RAGE_JOAAT("maintransition")) == 0)
|
|
|
|
{
|
2022-12-18 23:15:52 +01:00
|
|
|
g.session.join_queued = false;
|
2022-11-24 21:49:05 +00:00
|
|
|
g_notification_service->push_error("RID Joiner", "Unable to launch maintransition");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2022-12-17 17:24:45 +01:00
|
|
|
|
2022-10-26 14:12:29 +02:00
|
|
|
inline void join_by_rockstar_id(uint64_t rid)
|
|
|
|
{
|
2023-03-01 21:27:15 +00:00
|
|
|
if (SCRIPT::GET_NUMBER_OF_THREADS_RUNNING_THE_SCRIPT_WITH_THIS_HASH(RAGE_JOAAT("maintransition")) != 0 || STREAMING::IS_PLAYER_SWITCH_IN_PROGRESS())
|
2022-10-26 14:12:29 +02:00
|
|
|
{
|
|
|
|
g_notification_service->push_error("RID Joiner", "Player switch in progress, wait a bit.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rage::rlGamerHandle player_handle(rid);
|
|
|
|
rage::rlSessionByGamerTaskResult result;
|
|
|
|
bool success = false;
|
2023-01-03 16:48:32 +00:00
|
|
|
rage::rlTaskStatus state{};
|
|
|
|
|
2023-04-14 18:54:07 +02:00
|
|
|
if (g_pointers->m_gta.m_start_get_session_by_gamer_handle(0, &player_handle, 1, &result, 1, &success, &state))
|
2022-10-26 14:12:29 +02:00
|
|
|
{
|
2023-01-03 16:48:32 +00:00
|
|
|
while (state.status == 1)
|
2022-10-26 14:12:29 +02:00
|
|
|
script::get_current()->yield();
|
|
|
|
|
2023-01-03 16:48:32 +00:00
|
|
|
if (state.status == 3 && success)
|
2022-10-26 14:12:29 +02:00
|
|
|
{
|
2022-11-24 21:49:05 +00:00
|
|
|
join_session(result.m_session_info);
|
2022-10-26 14:12:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-21 15:42:12 +00:00
|
|
|
g_notification_service->push_error("RID Joiner", "Target player is offline?");
|
2022-10-26 14:12:29 +02:00
|
|
|
}
|
2022-11-19 01:49:36 +00:00
|
|
|
|
2022-12-17 17:24:45 +01:00
|
|
|
inline void join_by_username(std::string username)
|
|
|
|
{
|
2023-03-01 21:27:15 +00:00
|
|
|
g_thread_pool->push([username] {
|
2022-12-17 17:24:45 +01:00
|
|
|
uint64_t rid;
|
|
|
|
if (g_api_service->get_rid_from_username(username, rid))
|
|
|
|
{
|
2023-03-01 21:27:15 +00:00
|
|
|
g_fiber_pool->queue_job([rid] {
|
2022-12-17 17:24:45 +01:00
|
|
|
join_by_rockstar_id(rid);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
g_notification_service->push_error("RID Joiner", "Target player is offline?");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-10-13 00:11:37 +02:00
|
|
|
inline void add_infraction(player_ptr player, Infraction infraction, const std::string& custom_reason = "")
|
2022-11-19 01:49:36 +00:00
|
|
|
{
|
2023-08-19 11:01:08 +00:00
|
|
|
if (g.debug.fuzzer.enabled)
|
|
|
|
return;
|
|
|
|
|
2022-11-19 01:49:36 +00:00
|
|
|
auto plyr = g_player_database_service->get_or_create_player(player);
|
2022-11-21 15:42:12 +00:00
|
|
|
if (!plyr->infractions.contains((int)infraction))
|
|
|
|
{
|
2023-03-01 21:27:15 +00:00
|
|
|
plyr->is_modder = true;
|
2022-11-21 15:42:12 +00:00
|
|
|
player->is_modder = true;
|
2023-10-13 00:11:37 +02:00
|
|
|
|
2022-11-21 15:42:12 +00:00
|
|
|
plyr->infractions.insert((int)infraction);
|
2023-10-13 00:11:37 +02:00
|
|
|
if (infraction == Infraction::CUSTOM_REASON)
|
|
|
|
{
|
|
|
|
plyr->custom_infraction_reason += plyr->custom_infraction_reason.size() ? (std::string(", ") + custom_reason) : custom_reason;
|
|
|
|
}
|
|
|
|
|
2022-11-21 15:42:12 +00:00
|
|
|
g_player_database_service->save();
|
2023-10-13 00:11:37 +02:00
|
|
|
|
2023-07-22 22:44:38 +03:00
|
|
|
g.reactions.modder_detection.process(player);
|
2022-11-21 15:42:12 +00:00
|
|
|
}
|
2022-11-19 01:49:36 +00:00
|
|
|
}
|
2022-12-06 16:12:02 +00:00
|
|
|
|
|
|
|
inline void give_collectible(Player target, eCollectibleType col, int index = 0, bool uncomplete = false)
|
|
|
|
{
|
2023-03-01 21:27:15 +00:00
|
|
|
const size_t arg_count = 7;
|
2022-12-06 16:12:02 +00:00
|
|
|
int64_t args[arg_count] = {
|
2023-03-01 21:27:15 +00:00
|
|
|
(int64_t)eRemoteEvent::GiveCollectible,
|
|
|
|
(int64_t)self::id,
|
2023-06-06 07:40:40 +00:00
|
|
|
(int64_t)col, // iParam0
|
|
|
|
(int64_t)index, // iParam1
|
|
|
|
!uncomplete, // bParam2
|
2023-03-01 21:27:15 +00:00
|
|
|
true,
|
2023-06-06 07:40:40 +00:00
|
|
|
0 // bParam3
|
2022-12-06 16:12:02 +00:00
|
|
|
};
|
|
|
|
|
2023-04-14 18:54:07 +02:00
|
|
|
g_pointers->m_gta.m_trigger_script_event(1, args, arg_count, 1 << target);
|
2022-12-06 16:12:02 +00:00
|
|
|
}
|
2022-10-26 14:12:29 +02:00
|
|
|
}
|