Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Season and TimeFlow on game ready #85

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(MAFIAMP_CLIENT_FILES
src/core/ui/web/sdk.cpp
src/core/ui/web/view.cpp
src/core/ui/world_debug.cpp
src/core/states/game_ready.cpp
src/core/states/initialize.cpp
src/core/states/main_menu.cpp
src/core/states/session_connected.cpp
Expand All @@ -39,7 +40,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
Expand Down
2 changes: 2 additions & 0 deletions code/client/src/core/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <logging/logger.h>

#include "states/game_ready.h"
#include "states/initialize.h"
#include "states/main_menu.h"
#include "states/session_connected.h"
Expand Down Expand Up @@ -42,6 +43,7 @@ namespace MafiaMP::Core {
// Create the state machine and initialize
_stateMachine = std::make_shared<Framework::Utils::States::Machine>();
_stateMachine->RegisterState<States::InitializeState>();
_stateMachine->RegisterState<States::GameReadyState>();
_stateMachine->RegisterState<States::MainMenuState>();
_stateMachine->RegisterState<States::SessionConnectionState>();
_stateMachine->RegisterState<States::SessionConnectedState>();
Expand Down
13 changes: 0 additions & 13 deletions code/client/src/core/hooks/traffic.cpp

This file was deleted.

66 changes: 66 additions & 0 deletions code/client/src/core/states/game_ready.cpp
Original file line number Diff line number Diff line change
@@ -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 <utils/states/machine.h>

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
19 changes: 19 additions & 0 deletions code/client/src/core/states/game_ready.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <utils/states/state.h>

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
2 changes: 1 addition & 1 deletion code/client/src/core/states/initialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions code/client/src/core/states/states.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace MafiaMP::Core::States {
enum StateIds: int32_t {
Initialize,
GameReady,
MainMenu,
SessionConnection,
SessionConnected,
Expand Down