From 610f7e62cbba7c18a4bd01ebffda3eb5d306eb52 Mon Sep 17 00:00:00 2001 From: gir489 <100792176+gir489returns@users.noreply.github.com> Date: Wed, 15 May 2024 13:54:34 -0400 Subject: [PATCH] Added file-based log to debug.packet_logs. (#3127) --- src/core/settings.hpp | 2 +- src/hooks/protections/receive_net_message.cpp | 42 ++++++++++++------- src/views/debug/views_debug_logs.cpp | 3 +- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/core/settings.hpp b/src/core/settings.hpp index 15b9bcad..fbd3d200 100644 --- a/src/core/settings.hpp +++ b/src/core/settings.hpp @@ -95,7 +95,7 @@ namespace big struct logs { bool metric_logs{}; - bool packet_logs{}; + int packet_logs{}; bool script_hook_logs{}; diff --git a/src/hooks/protections/receive_net_message.cpp b/src/hooks/protections/receive_net_message.cpp index a7a4cebf..ef75f05c 100644 --- a/src/hooks/protections/receive_net_message.cpp +++ b/src/hooks/protections/receive_net_message.cpp @@ -256,26 +256,38 @@ namespace big } } - if (g.debug.logs.packet_logs && msgType != rage::eNetMessage::MsgCloneSync && msgType != rage::eNetMessage::MsgPackedCloneSyncACKs && msgType != rage::eNetMessage::MsgPackedEvents && msgType != rage::eNetMessage::MsgPackedReliables && msgType != rage::eNetMessage::MsgPackedEventReliablesMsgs && msgType != rage::eNetMessage::MsgNetArrayMgrUpdate && msgType != rage::eNetMessage::MsgNetArrayMgrSplitUpdateAck && msgType != rage::eNetMessage::MsgNetArrayMgrUpdateAck && msgType != rage::eNetMessage::MsgScriptHandshakeAck && msgType != rage::eNetMessage::MsgScriptHandshake && msgType != rage::eNetMessage::MsgScriptJoin && msgType != rage::eNetMessage::MsgScriptJoinAck && msgType != rage::eNetMessage::MsgScriptJoinHostAck && msgType != rage::eNetMessage::MsgRequestObjectIds && msgType != rage::eNetMessage::MsgInformObjectIds && msgType != rage::eNetMessage::MsgNetTimeSync) + if (g.debug.logs.packet_logs) [[unlikely]] { - const char* packet_type = ""; - for (const auto& p : packet_types) + if (g.debug.logs.packet_logs == 1 || //ALL + (g.debug.logs.packet_logs == 2 && msgType != rage::eNetMessage::MsgCloneSync && msgType != rage::eNetMessage::MsgPackedCloneSyncACKs && msgType != rage::eNetMessage::MsgPackedEvents && msgType != rage::eNetMessage::MsgPackedReliables && msgType != rage::eNetMessage::MsgPackedEventReliablesMsgs && msgType != rage::eNetMessage::MsgNetArrayMgrUpdate && msgType != rage::eNetMessage::MsgNetArrayMgrSplitUpdateAck && msgType != rage::eNetMessage::MsgNetArrayMgrUpdateAck && msgType != rage::eNetMessage::MsgScriptHandshakeAck && msgType != rage::eNetMessage::MsgScriptHandshake && msgType != rage::eNetMessage::MsgScriptJoin && msgType != rage::eNetMessage::MsgScriptJoinAck && msgType != rage::eNetMessage::MsgScriptJoinHostAck && msgType != rage::eNetMessage::MsgRequestObjectIds && msgType != rage::eNetMessage::MsgInformObjectIds && msgType != rage::eNetMessage::MsgNetTimeSync)) //FILTERED { - if (p.second == (int)msgType) + const char* packet_type = ""; + for (const auto& p : packet_types) { - packet_type = p.first; - break; + if (p.second == (int)msgType) + { + packet_type = p.first; + break; + } } - } - LOG(VERBOSE) << "RECEIVED PACKET | Type: " << packet_type << " | Length: " << frame->m_length << " | Sender: " - << (player ? player->get_name() : - std::format(", , ", - (int)frame->m_msg_id, - frame->m_connection_identifier, - frame->m_peer_id) - .c_str()) - << " | " << HEX_TO_UPPER((int)msgType); + auto now = std::chrono::system_clock::now(); + auto ms = std::chrono::duration_cast(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("./packets.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") << "] " + << "RECEIVED PACKET | Type: " << packet_type << " | Length: " << frame->m_length << " | Sender: " + << (player ? player->get_name() : + std::format(", , ", + (int)frame->m_msg_id, + frame->m_connection_identifier, + frame->m_peer_id) + .c_str()) + << " | " << HEX_TO_UPPER((int)msgType) << std::endl; + log.flush(); + } } return g_hooking->get_original()(netConnectionManager, a2, frame); diff --git a/src/views/debug/views_debug_logs.cpp b/src/views/debug/views_debug_logs.cpp index 2ebaa66a..74b91be5 100644 --- a/src/views/debug/views_debug_logs.cpp +++ b/src/views/debug/views_debug_logs.cpp @@ -9,7 +9,8 @@ namespace big if (ImGui::BeginTabItem("DEBUG_TABS_LOGS"_T.data())) { ImGui::Checkbox("DEBUG_LOG_METRICS"_T.data(), &g.debug.logs.metric_logs); - ImGui::Checkbox("VIEW_DEBUG_LOGS_LOG_PACKETS"_T.data(), &g.debug.logs.packet_logs); + static const char* options[]{"OFF"_T.data(), "ALL"_T.data(), "FILTERS"_T.data()}; + ImGui::Combo("VIEW_DEBUG_LOGS_LOG_PACKETS"_T.data(), (int*)&g.debug.logs.packet_logs, options, IM_ARRAYSIZE(options)); ImGui::Checkbox("DEBUG_LOG_NATIVE_SCRIPT_HOOKS"_T.data(), &g.debug.logs.script_hook_logs); if (ImGui::TreeNode("DEBUG_LOG_TREE_SCRIPT_EVENT"_T.data()))