diff --git a/code/client/CMakeLists.txt b/code/client/CMakeLists.txt index 8957ca58..a8fb913b 100644 --- a/code/client/CMakeLists.txt +++ b/code/client/CMakeLists.txt @@ -15,6 +15,7 @@ set(MAFIAMP_CLIENT_FILES src/core/ui/web/clipboard.cpp src/core/ui/web/sdk.cpp src/core/ui/web/view.cpp + src/core/states/game_ready.cpp src/core/states/initialize.cpp src/core/states/main_menu.cpp src/core/states/session_connected.cpp @@ -38,7 +39,6 @@ set(MAFIAMP_CLIENT_FILES src/core/hooks/slot_wrapper.cpp src/core/hooks/stream_map.cpp src/core/hooks/tables.cpp - src/core/hooks/traffic.cpp src/core/hooks/translocator.cpp src/core/hooks/vehicle.cpp src/core/hooks/vfs.cpp diff --git a/code/client/src/core/application.cpp b/code/client/src/core/application.cpp index 11a26592..efd0752a 100644 --- a/code/client/src/core/application.cpp +++ b/code/client/src/core/application.cpp @@ -2,6 +2,7 @@ #include +#include "states/game_ready.h" #include "states/initialize.h" #include "states/main_menu.h" #include "states/session_connected.h" @@ -42,6 +43,7 @@ namespace MafiaMP::Core { // Create the state machine and initialize _stateMachine = std::make_shared(); _stateMachine->RegisterState(); + _stateMachine->RegisterState(); _stateMachine->RegisterState(); _stateMachine->RegisterState(); _stateMachine->RegisterState(); diff --git a/code/client/src/core/hooks/traffic.cpp b/code/client/src/core/hooks/traffic.cpp deleted file mode 100644 index ddd3e572..00000000 --- a/code/client/src/core/hooks/traffic.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "sdk/patterns.h" - -#include - -static InitFunction init([]() { - /** - * 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/core/states/game_ready.cpp b/code/client/src/core/states/game_ready.cpp new file mode 100644 index 00000000..b4b959bc --- /dev/null +++ b/code/client/src/core/states/game_ready.cpp @@ -0,0 +1,66 @@ +#include "game_ready.h" + +#include "states.h" + +#include "sdk/ue/game/traffic/c_streaming_traffic_module.h" +#include "sdk/ue/gfx/environmenteffects/c_gfx_environment_effects.h" + +#include + +namespace MafiaMP::Core::States { + GameReadyState::GameReadyState() {} + + GameReadyState::~GameReadyState() {} + + int32_t GameReadyState::GetId() const { + return StateIds::GameReady; + } + + const char *GameReadyState::GetName() const { + return "GameReady"; + } + + bool GameReadyState::OnEnter(Framework::Utils::States::Machine *) { + return true; + } + + bool GameReadyState::OnExit(Framework::Utils::States::Machine *machine) { + machine->RequestNextState(StateIds::MainMenu); + return true; + } + + bool GameReadyState::OnUpdate(Framework::Utils::States::Machine *) { + const auto streamingTrafficModule = SDK::ue::game::traffic::C_StreamingTrafficModule::GetInstance(); + if (!streamingTrafficModule) { + return false; + } + + const auto gfxEnvironmentEffects = SDK::ue::gfx::environmenteffects::C_GfxEnvironmentEffects::GetInstance(); + if (!gfxEnvironmentEffects) { + return false; + } + const auto weatherManager = gfxEnvironmentEffects->GetWeatherManager(); + if (!weatherManager) { + return false; + } + + /** + * Disable traffic + * + * Traffic is automaticaly loaded by the game via C_StreamingTrafficModule::OpenSeason + * after C_StreamMap::OpenPart("freeride") is called. + * + * We close the season here which disable the traffic. + */ + streamingTrafficModule->CloseSeason(true); + + /** + * Disable TimeFlow + * + * We give scripters the option to update the time manually. + */ + weatherManager->SetUserTimeFlowSpeedMult(0); + + return true; + } +} // namespace MafiaMP::Core::States diff --git a/code/client/src/core/states/game_ready.h b/code/client/src/core/states/game_ready.h new file mode 100644 index 00000000..9bbf3771 --- /dev/null +++ b/code/client/src/core/states/game_ready.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +namespace MafiaMP::Core::States { + class GameReadyState: public Framework::Utils::States::IState { + public: + GameReadyState(); + ~GameReadyState(); + + virtual const char *GetName() const override; + virtual int32_t GetId() const override; + + virtual bool OnEnter(Framework::Utils::States::Machine *) override; + virtual bool OnExit(Framework::Utils::States::Machine *) override; + + virtual bool OnUpdate(Framework::Utils::States::Machine *) override; + }; +} // namespace MafiaMP::Core::States diff --git a/code/client/src/core/states/initialize.cpp b/code/client/src/core/states/initialize.cpp index 291f7b33..f0d4c723 100644 --- a/code/client/src/core/states/initialize.cpp +++ b/code/client/src/core/states/initialize.cpp @@ -24,7 +24,7 @@ namespace MafiaMP::Core::States { } bool InitializeState::OnExit(Framework::Utils::States::Machine *machine) { - machine->RequestNextState(StateIds::MainMenu); + machine->RequestNextState(StateIds::GameReady); return true; } diff --git a/code/client/src/core/states/states.h b/code/client/src/core/states/states.h index b33db036..c192955b 100644 --- a/code/client/src/core/states/states.h +++ b/code/client/src/core/states/states.h @@ -3,6 +3,7 @@ namespace MafiaMP::Core::States { enum StateIds: int32_t { Initialize, + GameReady, MainMenu, SessionConnection, SessionConnected,