diff --git a/code/client/CMakeLists.txt b/code/client/CMakeLists.txt index e86e1388..8957ca58 100644 --- a/code/client/CMakeLists.txt +++ b/code/client/CMakeLists.txt @@ -97,6 +97,7 @@ set(MAFIAMP_SDK_FILES src/sdk/ue/game/shotmanager/c_shot_manager.cpp src/sdk/ue/game/traffic/c_human_spawner.cpp src/sdk/ue/game/traffic/c_profile_spawner.cpp + src/sdk/ue/game/traffic/c_streaming_traffic_module.cpp src/sdk/ue/gfx/environmenteffects/c_gfx_environment_effects.cpp src/sdk/ue/gfx/environmenteffects/c_weather_manager_2.cpp src/sdk/ue/sys/core/c_scene_object.cpp diff --git a/code/client/src/core/hooks/traffic.cpp b/code/client/src/core/hooks/traffic.cpp index 8bf1ec7d..ddd3e572 100644 --- a/code/client/src/core/hooks/traffic.cpp +++ b/code/client/src/core/hooks/traffic.cpp @@ -1,8 +1,13 @@ -#include +#include "sdk/patterns.h" + #include static InitFunction init([]() { - //Disable traffic - const auto OpenSeasonAddr = hook::pattern("40 55 41 56 48 83 EC 48 83 B9 ? ? ? ? ?").get_first(); - hook::return_function(OpenSeasonAddr); + /** + * Disable traffic + * + * Traffic is automaticaly loaded by the game via C_StreamingTrafficModule::OpenSeason + * after C_StreamMap::OpenPart("freeride") is called. + */ + hook::return_function(SDK::gPatterns.C_StreamingTrafficModule__OpenSeason); }); diff --git a/code/client/src/sdk/mafia/traffic/traffic_defines.h b/code/client/src/sdk/mafia/traffic/traffic_defines.h index 3b7a3108..5463df58 100644 --- a/code/client/src/sdk/mafia/traffic/traffic_defines.h +++ b/code/client/src/sdk/mafia/traffic/traffic_defines.h @@ -5,15 +5,15 @@ namespace SDK { namespace mafia::traffic { enum class E_TrafficCommonFlags : uint32_t { - // Time Periods - E_TCF_TIME_1930 = 0x1, - E_TCF_TIME_1932 = 0x2, - E_TCF_TIME_1933 = 0x4, - E_TCF_TIME_1935 = 0x8, - E_TCF_TIME_1938 = 0x10, + // Time Periods (also called Seasons) + E_TCF_TIME_1930 = 0x1, + E_TCF_TIME_1932 = 0x2, + E_TCF_TIME_1933 = 0x4, + E_TCF_TIME_1935 = 0x8, + E_TCF_TIME_1938 = 0x10, + E_TCF_TIME_FREERIDE = 0x1000, // Locations - E_TCF_TIME_FREERIDE = 0x1000, E_TCF_LOC_LOSTHEAVEN = 0x10000 }; @@ -44,11 +44,11 @@ namespace SDK { E_TVF_SIZE_BIG = 0x80000, // special - E_TVF_BOAT = 0x100000, - E_TVF_CIVILIAN = 0x200000, - E_TVF_CAR = 0x400000, - E_TVF_POLICE_STATE = 0x800000, - E_TVF_TRAIN = 0x1000000, + E_TVF_BOAT = 0x100000, + E_TVF_CIVILIAN = 0x200000, + E_TVF_CAR = 0x400000, + E_TVF_MOTORCYCLE = 0x800000, + E_TVF_TRAIN = 0x1000000, }; enum class E_TrafficVehicleLookFlags : uint32_t { @@ -76,5 +76,5 @@ namespace SDK { E_TVFL_SPORTS = 0x200000, E_TVFL_RACING = 0x400000, }; - } // mafia::traffic + } // namespace mafia::traffic } // namespace SDK diff --git a/code/client/src/sdk/patterns.cpp b/code/client/src/sdk/patterns.cpp index 6b392db7..336529ed 100644 --- a/code/client/src/sdk/patterns.cpp +++ b/code/client/src/sdk/patterns.cpp @@ -323,6 +323,13 @@ namespace SDK { // C_StreamingModule gPatterns.C_StreamingModule__SetStreamingPosSource = reinterpret_cast(hook::get_pattern("33 C0 89 91 ? ? ? ? 48 89 81 ? ? ? ?")); + // C_StreamingTrafficModule + gPatterns.C_StreamingTrafficModule__CloseSeason = reinterpret_cast(hook::get_pattern("48 89 6C 24 ? 41 56 48 83 EC 20 83 B9 ? ? ? ? ? 44 0F B6 F2")); + gPatterns.C_StreamingTrafficModule__GetSeasonOpened = hook::get_opcode_address("E8 ? ? ? ? 33 D2 84 C0 74 0B "); + gPatterns.C_StreamingTrafficModule__GetInstance = hook::get_opcode_address("E8 ? ? ? ? 4C 8B 44 F3 ?"); + gPatterns.C_StreamingTrafficModule__OpenSeason = hook::get_opcode_address("E8 ? ? ? ? 48 8B 76 08 48 8B CE"); + gPatterns.C_StreamingTrafficModule__SetMaxHumanElements = reinterpret_cast(hook::get_pattern("48 83 EC 28 3B 91 ? ? ? ? 74 25")); + // C_StreamMap gPatterns.C_StreamMap__CloseGame = reinterpret_cast( hook::get_pattern("48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 41 56 48 83 EC 30 48 8B A9 ? ? ? ? 4C 8B F1 48 C7 44 24 ? ? ? ? ? B9 ? ? ? ? C7 44 24 ? ? ? ? ? 48 8B 75 08 E8 ? ? ? ? 48 8B D8 48 85 C0 75 07 FF 15 ? ? ? ? CC 48 89 7C 24 ? 48 8D 78 08 48 89 28 " diff --git a/code/client/src/sdk/patterns.h b/code/client/src/sdk/patterns.h index 0b700e39..42981e1a 100644 --- a/code/client/src/sdk/patterns.h +++ b/code/client/src/sdk/patterns.h @@ -288,6 +288,13 @@ namespace SDK { // C_StreamingModule uint64_t C_StreamingModule__SetStreamingPosSource = 0x0; + // C_StreamingTrafficModule + uint64_t C_StreamingTrafficModule__CloseSeason = 0x0; + uint64_t C_StreamingTrafficModule__GetSeasonOpened = 0x0; + uint64_t C_StreamingTrafficModule__GetInstance = 0x0; + uint64_t C_StreamingTrafficModule__OpenSeason = 0x0; + uint64_t C_StreamingTrafficModule__SetMaxHumanElements = 0x0; + // C_StreamMap uint64_t C_StreamMap__CloseGame = 0x0; uint64_t C_StreamMap__CloseMission = 0x0; diff --git a/code/client/src/sdk/ue/game/traffic/c_streaming_traffic_module.cpp b/code/client/src/sdk/ue/game/traffic/c_streaming_traffic_module.cpp new file mode 100644 index 00000000..7bd0667a --- /dev/null +++ b/code/client/src/sdk/ue/game/traffic/c_streaming_traffic_module.cpp @@ -0,0 +1,33 @@ +#include "c_streaming_traffic_module.h" + +namespace SDK { + namespace ue::game::traffic { + void C_StreamingTrafficModule::CloseSeason(bool destroyActorItems) { + hook::this_call(gPatterns.C_StreamingTrafficModule__CloseSeason, this, destroyActorItems); + } + + int C_StreamingTrafficModule::GetCurrentSeasonID() { + return m_iSeasonID; + } + + int C_StreamingTrafficModule::GetMaxHumanElements() { + return m_iMaxHumanElements; + } + + int C_StreamingTrafficModule::GetPreviousSeasonID() { + return m_iPrevSeasonID; + } + + bool C_StreamingTrafficModule::GetSeasonOpened() { + return m_iSeasonID != -1; + } + + void C_StreamingTrafficModule::OpenSeason(unsigned int seasonID, bool unk2) { + hook::this_call(gPatterns.C_StreamingTrafficModule__OpenSeason, this, seasonID, unk2); + } + + void C_StreamingTrafficModule::SetMaxHumanElements(int maxHumanElements) { + hook::this_call(gPatterns.C_StreamingTrafficModule__SetMaxHumanElements, this, maxHumanElements); + } + } // namespace ue::game::traffic +} // namespace SDK diff --git a/code/client/src/sdk/ue/game/traffic/c_streaming_traffic_module.h b/code/client/src/sdk/ue/game/traffic/c_streaming_traffic_module.h new file mode 100644 index 00000000..95c539d2 --- /dev/null +++ b/code/client/src/sdk/ue/game/traffic/c_streaming_traffic_module.h @@ -0,0 +1,56 @@ +#pragma once + +#include "../../../c_ticked_module.h" + +#include "../../../patterns.h" + +namespace SDK { + namespace ue::game::traffic { + class C_StreamingTrafficModule: public C_TickedModule { + public: + char pad0[0x8C]; // 0008 - 0094 + int m_iSeasonID; // 0094 - 0098 + int m_iPrevSeasonID; // 0098 - 009C + char pad1[0x64]; // 009C - 0100 + int m_iMaxHumanElements; // 0100 - 0104 + + public: + /** + * @param destroyActorItems see mafia::streaming::C_ActorsSlotWrapper::Close + */ + void CloseSeason(bool destroyActorItems); + + /** + * Custom method + */ + int GetCurrentSeasonID(); + + /** + * Custom method + */ + int GetMaxHumanElements(); + + /** + * Custom method + */ + int GetPreviousSeasonID(); + + /** + * Check if any season is opened (seasonID != -1) + */ + bool GetSeasonOpened(); + + /** + * If the current season is not -1, you must close the current season + * with C_StreamingTrafficModule::CloseSeason before using it. + */ + void OpenSeason(unsigned int seasonID, bool unk2); + + void SetMaxHumanElements(int maxHumanElements); + + static C_StreamingTrafficModule *GetInstance() { + return hook::call(gPatterns.C_StreamingTrafficModule__GetInstance); + } + }; + } // namespace ue::game::traffic +} // namespace SDK