From ec19493aedc48e3fe0860342484058e48204dda2 Mon Sep 17 00:00:00 2001 From: Ryan <80224521+Rxann@users.noreply.github.com> Date: Sat, 27 Jul 2024 22:24:50 -0400 Subject: [PATCH] Session Events (#32) --- CMakeLists.txt | 6 +- classes.cpp | 1 + network/rlScSession.hpp | 1 + network/rlScSessionEvent.hpp | 126 ++++++++++++++++++++++++ rage/atUri.hpp | 4 +- script/globals/NetCampHostData.hpp | 35 +++---- script/globals/PlayerStatusSyncData.hpp | 9 +- 7 files changed, 157 insertions(+), 25 deletions(-) create mode 100644 network/rlScSessionEvent.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 94f44c1..d931702 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.11) -project(RDR-Classes) +project(RDR-Classes LANGUAGES CXX VERSION 0.0.1 DESCRIPTION "Reversed structures for Red Dead Redemption 2 PC") include(CheckIncludeFileCXX) @@ -15,8 +15,8 @@ set(OK TRUE) file(GLOB_RECURSE HEADERS "**.hpp") file(GLOB_RECURSE SRC_MAIN "**.cpp") source_group(FILES "${SRC_MAIN}") -add_library(RDR-Classes MODULE "${SRC_MAIN}") - +add_library(RDR-Classes STATIC "${SRC_MAIN}" "${HEADERS}") +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 20) add_compile_definitions(_CRT_SECURE_NO_WARNINGS) message(STATUS "") diff --git a/classes.cpp b/classes.cpp index 0bc11a8..39d25dd 100644 --- a/classes.cpp +++ b/classes.cpp @@ -27,6 +27,7 @@ #include "network/rlGamerInfoBase.hpp" #include "network/rlScPeerConnection.hpp" #include "network/rlScSession.hpp" +#include "network/rlScSessionEvent.hpp" #include "network/rlScSessionManagerImpl.hpp" #include "network/rlScSessionMultiplayer.hpp" #include "network/rlScSessionPeer.hpp" diff --git a/network/rlScSession.hpp b/network/rlScSession.hpp index 8f4f80f..6c956d8 100644 --- a/network/rlScSession.hpp +++ b/network/rlScSession.hpp @@ -16,6 +16,7 @@ namespace rage } }; static_assert(sizeof(rlScSessionId) == 0x10); + using rlScSessionRequestId = rlScSessionId; // for now class rlScSessionPeerPoolEntry { diff --git a/network/rlScSessionEvent.hpp b/network/rlScSessionEvent.hpp new file mode 100644 index 0000000..6a9f3ac --- /dev/null +++ b/network/rlScSessionEvent.hpp @@ -0,0 +1,126 @@ +#pragma once +#include "rlGamerHandle.hpp" +#include "rlGamerInfoBase.hpp" +#include "rlScSession.hpp" +#include "rage/atUri.hpp" + +#pragma pack(push, 8) +namespace rage +{ + enum class SessionEvent : std::uint32_t + { + LEAVE_SESSION = 6, + ADD_PLAYER = 7, + REMOVE_PLAYER = 8, + HOST_CHANGED = 9, + QUEUE_ERROR = 17, + LOCALIZED_MESSAGE = 19, + CONFIG_PARAM = 20, + COMPLAINT_RECEIVED = 31, + QUEUE_ENTERED = 32, + ADMIN_SECURITY_INVITE = 38 + }; + + class rlScSessionEvent + { + public: + virtual ~rlScSessionEvent() = default; + + SessionEvent m_EventType; + + template + inline T* As() + { + return T*(this); + } + }; + static_assert(sizeof(rage::rlScSessionEvent) == 0x10); + + class rlScLeaveSessionEvent : public rlScSessionEvent + { + public: + rage::rlScSessionId m_SessionId; + int m_Reason; + int m_Reason2; + int m_PlayerCount; + }; + static_assert(sizeof(rage::rlScLeaveSessionEvent) == 0x30); + + class rlScAddPlayerEvent : public rlScSessionEvent + { + public: + rage::rlScSessionId m_SessionId; + rage::rlScSessionPeerIdentifier m_Identifier; + rage::rlGamerInfoBase m_PeerAddress; + }; + static_assert(sizeof(rage::rlScAddPlayerEvent) == 0xD0); + + class rlScRemovePlayerEvent : public rlScSessionEvent + { + public: + rage::rlScSessionId m_SessionId; + rage::rlScSessionPeerIdentifier m_Identifier; + }; + static_assert(sizeof(rage::rlScRemovePlayerEvent) == 0x38); + + class rlScHostChangedEvent : public rlScSessionEvent + { + public: + rage::rlScSessionId m_SessionId; + int m_OldIndex; + int m_NewIndex; + }; + static_assert(sizeof(rage::rlScHostChangedEvent) == 0x28); + + class rlScComplaintReceivedEvent : public rlScSessionEvent + { + public: + rage::rlGamerHandle m_Complainer; + }; + static_assert(sizeof(rage::rlScComplaintReceivedEvent) == 0x20); + + class rlScQueueEnteredEvent : public rlScSessionEvent + { + public: + rage::rlScSessionRequestId m_RequestId; + int m_QueueGroup; + int m_OptionFlags; + }; + static_assert(sizeof(rage::rlScQueueEnteredEvent) == 0x28); + + class rlScQueueErrorEvent : public rlScSessionEvent + { + public: + rage::rlScSessionRequestId m_RequestId; + int m_Reason; + }; + static_assert(sizeof(rage::rlScQueueErrorEvent) == 0x28); + + // not rlScLocalizedMessageEvent + class rlScLocalizedMessage : public rlScSessionEvent + { + public: + char m_Key[128]; + }; + static_assert(sizeof(rage::rlScLocalizedMessage) == 0x90); + + class rlScConfigParamEvent : public rlScSessionEvent + { + public: + int m_NameHash; // TODO: reverse this + char m_Value[32]; + }; + static_assert(sizeof(rage::rlScConfigParamEvent) == 0x38); + + class rlScAdminSecurityInviteEvent : public rlScSessionEvent + { + public: + rage::rlGamerHandle m_Handle; + int m_InviteId; + int m_Flags; + rage::atUri m_ServerUri; + int m_SessionType; + }; + static_assert(sizeof(rage::rlScAdminSecurityInviteEvent) == 0x4B8); +} +#pragma pack(pop) \ No newline at end of file diff --git a/rage/atUri.hpp b/rage/atUri.hpp index 429821c..acf0337 100644 --- a/rage/atUri.hpp +++ b/rage/atUri.hpp @@ -1,6 +1,7 @@ #pragma once #include +#pragma pack(push, 8) namespace rage { class atUri @@ -21,4 +22,5 @@ namespace rage char m_QueryString[512]; }; static_assert(sizeof(atUri) == 0x488); -} \ No newline at end of file +} +#pragma pack(pop) \ No newline at end of file diff --git a/script/globals/NetCampHostData.hpp b/script/globals/NetCampHostData.hpp index 8ed5a3b..1387456 100644 --- a/script/globals/NetCampHostData.hpp +++ b/script/globals/NetCampHostData.hpp @@ -1,6 +1,7 @@ #pragma once #include "script/types.hpp" #include "rage/joaat.hpp" +#include // TODO: remove! enum class CampState { @@ -10,7 +11,7 @@ enum class CampState CLEANUP }; -inline std::map g_CampStateMap = { +inline std::unordered_map g_CampStateMap = { {CampState::INVALID, "Invalid"}, {CampState::WAITING, "Waiting"}, {CampState::RUNNING, "Running"}, @@ -19,22 +20,22 @@ inline std::map g_CampStateMap = { enum class CampLocationIndex : std::uint32_t { - GRIZZLIES_CAMP = rage::joaat("GRIZZLIES_CAMP"), - BAYOU_NAWAS_CAMP = rage::joaat("BAYOU_NAWAS_CAMP"), - BIG_VALLEY_CAMP = rage::joaat("BIG_VALLEY_CAMP"), - CHOLLA_SPRINGS_CAMP = rage::joaat("CHOLLA_SPRINGS_CAMP"), - CUMBERLAND_FOREST_CAMP = rage::joaat("CUMBERLAND_FOREST_CAMP"), - GAPTOOTH_RIDGE_CAMP = rage::joaat("GAPTOOTH_RIDGE_CAMP"), - GREAT_PLAINS_CAMP = rage::joaat("GREAT_PLAINS_CAMP"), - HEARTLAND_CAMP = rage::joaat("HEARTLAND_CAMP"), - HENNIGANS_STEAD_CAMP = rage::joaat("HENNIGANS_STEAD_CAMP"), - RIO_BRAVO_CAMP = rage::joaat("RIO_BRAVO_CAMP"), - ROANOKE_RIDGE_CAMP = rage::joaat("ROANOKE_RIDGE_CAMP"), - SCARLETT_MEADOWS_CAMP = rage::joaat("SCARLETT_MEADOWS_CAMP"), - TALL_TREES_CAMP = rage::joaat("TALL_TREES_CAMP"), + GRIZZLIES_CAMP = rage::Joaat("GRIZZLIES_CAMP"), + BAYOU_NAWAS_CAMP = rage::Joaat("BAYOU_NAWAS_CAMP"), + BIG_VALLEY_CAMP = rage::Joaat("BIG_VALLEY_CAMP"), + CHOLLA_SPRINGS_CAMP = rage::Joaat("CHOLLA_SPRINGS_CAMP"), + CUMBERLAND_FOREST_CAMP = rage::Joaat("CUMBERLAND_FOREST_CAMP"), + GAPTOOTH_RIDGE_CAMP = rage::Joaat("GAPTOOTH_RIDGE_CAMP"), + GREAT_PLAINS_CAMP = rage::Joaat("GREAT_PLAINS_CAMP"), + HEARTLAND_CAMP = rage::Joaat("HEARTLAND_CAMP"), + HENNIGANS_STEAD_CAMP = rage::Joaat("HENNIGANS_STEAD_CAMP"), + RIO_BRAVO_CAMP = rage::Joaat("RIO_BRAVO_CAMP"), + ROANOKE_RIDGE_CAMP = rage::Joaat("ROANOKE_RIDGE_CAMP"), + SCARLETT_MEADOWS_CAMP = rage::Joaat("SCARLETT_MEADOWS_CAMP"), + TALL_TREES_CAMP = rage::Joaat("TALL_TREES_CAMP"), }; -inline std::map g_CampLocationMap = { +inline std::unordered_map g_CampLocationMap = { {CampLocationIndex::GRIZZLIES_CAMP, "Grizzlies"}, {CampLocationIndex::BAYOU_NAWAS_CAMP, "Bayou Nawas"}, {CampLocationIndex::BIG_VALLEY_CAMP, "Big Valley"}, @@ -67,7 +68,7 @@ enum class CampBit WHITE_FLAG_LOCKED_FOR_CONTENT }; -inline std::map g_CampBitMap = { +inline std::unordered_map g_CampBitMap = { {CampBit::IS_LAUNCHED, "Is Launched"}, {CampBit::IS_ATTACKING, "Is Attacking"}, {CampBit::IS_ACTIVE, "Is Active"}, @@ -92,7 +93,7 @@ enum class CampContentType CAMP_RAID }; -inline std::map g_CampContentTypeMap = { +inline std::unordered_map g_CampContentTypeMap = { {CampContentType::NONE, "None"}, {CampContentType::NET_BEAT, "Net Beat"}, {CampContentType::DYNAMIC_MISSION, "Dynamic Mission"}, diff --git a/script/globals/PlayerStatusSyncData.hpp b/script/globals/PlayerStatusSyncData.hpp index ed37301..dfc1510 100644 --- a/script/globals/PlayerStatusSyncData.hpp +++ b/script/globals/PlayerStatusSyncData.hpp @@ -1,5 +1,6 @@ #pragma once #include "script/types.hpp" +#include "unordered_map" enum class PlayerStatus { @@ -355,7 +356,7 @@ enum class Region MAX }; -inline std::map g_RegionMap = { +inline std::unordered_map g_RegionMap = { { Region::INVALID, "Invalid" }, { Region::BAY_CRAWDADWILLIES, "Crawdad Willies" }, { Region::BAY_MACOMBS_END, "Macomb's End" }, @@ -522,7 +523,7 @@ enum class District HENNIGANS_STEAD }; -inline std::map g_DistrictMap = { +inline std::unordered_map g_DistrictMap = { { District::INVALID, "Invalid" }, { District::BAYOU_NWA, "Bayou Nwa" }, { District::BIG_VALLEY, "Big Valley" }, @@ -562,7 +563,7 @@ enum class Language CHINESE_SIMP }; -inline std::map g_LanguageMap = { +inline std::unordered_map g_LanguageMap = { { Language::UNDEFINED, "Undefined" }, { Language::ENGLISH, "English" }, { Language::FRENCH, "French" }, @@ -588,7 +589,7 @@ enum class PassiveState FORCED_FROM_PASSIVE }; -inline std::map g_PassiveStateMap = { +inline std::unordered_map g_PassiveStateMap = { {PassiveState::NOT_PASSIVE, "Not Passive"}, {PassiveState::WAITING_FOR_PASSIVE, "Waiting for Passive"}, {PassiveState::PASSIVE, "Passive"},