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

Reverse traffic / seasons stuffs #78

Merged
merged 9 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions code/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions code/client/src/core/hooks/traffic.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#include <utils/hooking/hooking.h>
#include "sdk/patterns.h"

#include <utils/hooking/hook_function.h>

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);
});
26 changes: 13 additions & 13 deletions code/client/src/sdk/mafia/traffic/traffic_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -76,5 +76,5 @@ namespace SDK {
E_TVFL_SPORTS = 0x200000,
E_TVFL_RACING = 0x400000,
};
} // mafia::traffic
} // namespace mafia::traffic
} // namespace SDK
7 changes: 7 additions & 0 deletions code/client/src/sdk/patterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@ namespace SDK {
// C_StreamingModule
gPatterns.C_StreamingModule__SetStreamingPosSource = reinterpret_cast<uint64_t>(hook::get_pattern("33 C0 89 91 ? ? ? ? 48 89 81 ? ? ? ?"));

// C_StreamingTrafficModule
gPatterns.C_StreamingTrafficModule__CloseSeason = reinterpret_cast<uint64_t>(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<uint64_t>(hook::get_pattern("48 83 EC 28 3B 91 ? ? ? ? 74 25"));

// C_StreamMap
gPatterns.C_StreamMap__CloseGame = reinterpret_cast<uint64_t>(
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 "
Expand Down
7 changes: 7 additions & 0 deletions code/client/src/sdk/patterns.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 33 additions & 0 deletions code/client/src/sdk/ue/game/traffic/c_streaming_traffic_module.cpp
Original file line number Diff line number Diff line change
@@ -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<void>(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<void>(gPatterns.C_StreamingTrafficModule__OpenSeason, this, seasonID, unk2);
}

void C_StreamingTrafficModule::SetMaxHumanElements(int maxHumanElements) {
hook::this_call<void>(gPatterns.C_StreamingTrafficModule__SetMaxHumanElements, this, maxHumanElements);
}
} // namespace ue::game::traffic
} // namespace SDK
56 changes: 56 additions & 0 deletions code/client/src/sdk/ue/game/traffic/c_streaming_traffic_module.h
Original file line number Diff line number Diff line change
@@ -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<C_StreamingTrafficModule *>(gPatterns.C_StreamingTrafficModule__GetInstance);
}
};
} // namespace ue::game::traffic
} // namespace SDK