Added StartScriptBegin protection. (#2962)
* Refactored Script Event Logging to log to a file that's kept open, but flushed each event instead of spamming the console. * Added Rockstar ID to the Script Event Logger.
This commit is contained in:
parent
ca1e7e6b41
commit
1fa3ef8a45
@ -20,23 +20,23 @@ namespace big
|
||||
|
||||
virtual void execute(player_ptr player, const command_arguments& _args, const std::shared_ptr<command_context> ctx) override
|
||||
{
|
||||
const size_t arg_count = 26;
|
||||
const int arg_count = 26;
|
||||
int64_t args[arg_count] = {(int64_t)eRemoteEvent::StartScriptBegin, (int64_t)self::id, 1 << player->id()};
|
||||
|
||||
args[2] = scriptId;
|
||||
args[3] = scriptId;
|
||||
strcpy((char*)&args[2 + 3], "0");
|
||||
args[2 + 16] = -1;
|
||||
args[2 + 17] = 1337;
|
||||
args[2 + 19] = arg19;
|
||||
args[24] = scr_globals::gpbd_fm_3.as<GPBD_FM_3*>()->Entries[player->id()].ScriptEventReplayProtectionCounter;
|
||||
args[3 + 16] = -1;
|
||||
args[3 + 17] = 1337;
|
||||
args[3 + 19] = arg19;
|
||||
args[25] = scr_globals::gpbd_fm_3.as<GPBD_FM_3*>()->Entries[player->id()].ScriptEventReplayProtectionCounter;
|
||||
|
||||
g_pointers->m_gta.m_trigger_script_event(1, args, arg_count, 1 << player->id(), (int)eRemoteEvent::StartScriptBegin);
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
const size_t arg_count_2 = 26;
|
||||
const int arg_count_2 = 26;
|
||||
int64_t args_2[arg_count_2] = {(int64_t)eRemoteEvent::StartScriptProceed, (int64_t)self::id, 1 << player->id()};
|
||||
args_2[2 + 17] = 1337;
|
||||
args_2[3 + 17] = 1337;
|
||||
g_pointers->m_gta.m_trigger_script_event(1, args_2, arg_count_2, 1 << player->id(), (int)eRemoteEvent::StartScriptProceed);
|
||||
|
||||
script::get_current()->yield(20ms);
|
||||
|
@ -418,10 +418,25 @@ namespace big
|
||||
}
|
||||
break;
|
||||
}
|
||||
case eRemoteEvent::StartScriptBegin:
|
||||
{
|
||||
static const std::unordered_set<int> bad_script_ids = {
|
||||
17 /*AM_PI_MENU*/, 20 /*fm_intro*/, 212 /*golf_mp*/, 214 /*tennis_network_mp*/,
|
||||
215 /*Pilot_School_MP*/, 216 /*FM_Impromptu_DM_Controler*/, 217 /*fm_Bj_race_controler*/, 218 /*fm_deathmatch_controler*/,
|
||||
221 /*FM_Race_Controler*/, 222 /*FM_Horde_Controler*/, 226 /*grid_arcade_cabinet*/, 227 /*scroll_arcade_cabinet*/,
|
||||
229 /*road_arcade*/, 231 /*wizard_arcade*/, 235 /*ggsm_arcade*/, 236 /*puzzle*/, 238 /*SCTV*/ };
|
||||
auto script_id = args[3];
|
||||
if (bad_script_ids.contains(script_id))
|
||||
{
|
||||
g.reactions.start_script.process(plyr);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// detect pasted menus setting args[1] to something other than PLAYER_ID()
|
||||
if (*(int*)&args[1] != player->m_player_id && player->m_player_id != -1)
|
||||
if (*(int*)&args[1] != player->m_player_id && player->m_player_id != -1) [[unlikely]]
|
||||
{
|
||||
LOG(INFO) << "Hash = " << (int)args[0];
|
||||
LOG(INFO) << "Sender = " << args[1];
|
||||
@ -430,24 +445,30 @@ namespace big
|
||||
}
|
||||
|
||||
if (g.debug.logs.script_event.logs
|
||||
&& (!g.debug.logs.script_event.filter_player || g.debug.logs.script_event.player_id == player->m_player_id))
|
||||
&& (!g.debug.logs.script_event.filter_player || g.debug.logs.script_event.player_id == player->m_player_id)) [[unlikely]]
|
||||
{
|
||||
std::string script_args = "{ ";
|
||||
std::stringstream output;
|
||||
output << "Script Event From: " << player->get_name() << " (" << player->get_net_data()->m_gamer_handle.m_rockstar_id << ") Args: { ";
|
||||
for (int i = 0; i < args_count; i++)
|
||||
{
|
||||
if (i)
|
||||
script_args += ", ";
|
||||
output << ", ";
|
||||
|
||||
script_args += std::to_string((int)args[i]);
|
||||
output << (int)args[i];
|
||||
}
|
||||
script_args += " };";
|
||||
output << " }; ";
|
||||
|
||||
LOG(VERBOSE) << "Script Event:\n"
|
||||
<< "\tPlayer: " << player->get_name() << "\n"
|
||||
<< "\tArgs: " << script_args;
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
|
||||
auto timer = std::chrono::system_clock::to_time_t(now);
|
||||
auto local_time = *std::localtime(&timer);
|
||||
|
||||
static std::ofstream log(g_file_manager.get_project_file("./script_events.log").get_path(), std::ios::app);
|
||||
log << "[" << std::put_time(&local_time, "%m/%d/%Y %I:%M:%S") << ":" << std::setfill('0') << std::setw(3) << ms.count() << " " << std::put_time(&local_time, "%p") << "] " << output.str() << std::endl;
|
||||
log.flush();
|
||||
}
|
||||
|
||||
if (g.debug.logs.script_event.block_all)
|
||||
if (g.debug.logs.script_event.block_all) [[unlikely]]
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -54,14 +54,14 @@ namespace big
|
||||
if (m_debug_logging)
|
||||
LOG(VERBOSE) << "Starting " << m_script_name << " using TSEs";
|
||||
|
||||
const size_t arg_count = 26;
|
||||
const size_t arg_count = 26;
|
||||
int64_t args[arg_count] = {(int64_t)eRemoteEvent::StartScriptBegin, (int64_t)self::id, 1 << m_target->get()->id()};
|
||||
|
||||
args[2] = scripts::launcher_index_from_hash(m_script_hash);
|
||||
strcpy((char*)&args[2 + 3], "0");
|
||||
args[2 + 16] = -1;
|
||||
args[2 + 17] = 1337;
|
||||
args[24] = scr_globals::gpbd_fm_3.as<GPBD_FM_3*>()->Entries[m_target->get()->id()].ScriptEventReplayProtectionCounter;
|
||||
args[3] = scripts::launcher_index_from_hash(m_script_hash);
|
||||
strcpy((char*)&args[3 + 3], "0");
|
||||
args[3 + 16] = -1;
|
||||
args[3 + 17] = 1337;
|
||||
args[25] = scr_globals::gpbd_fm_3.as<GPBD_FM_3*>()->Entries[m_target->get()->id()].ScriptEventReplayProtectionCounter;
|
||||
|
||||
g_pointers->m_gta.m_trigger_script_event(1, args, arg_count, 1 << m_target->get()->id(), (int)eRemoteEvent::StartScriptBegin);
|
||||
|
||||
@ -69,7 +69,7 @@ namespace big
|
||||
{
|
||||
const size_t arg_count_2 = 26;
|
||||
int64_t args_2[arg_count_2] = {(int64_t)eRemoteEvent::StartScriptProceed, (int64_t)self::id, 1 << m_target->get()->id()};
|
||||
args_2[2 + 17] = 1337;
|
||||
args_2[3 + 17] = 1337;
|
||||
g_pointers->m_gta.m_trigger_script_event(1, args_2, arg_count_2, 1 << m_target->get()->id(), (int)eRemoteEvent::StartScriptProceed);
|
||||
|
||||
script::get_current()->yield(20ms);
|
||||
|
Reference in New Issue
Block a user