Skip to content

Commit

Permalink
Reverse traffic / seasons stuffs (#78)
Browse files Browse the repository at this point in the history
* Reverse traffic / seasons stuffs

* Fix E_TrafficVehicleFlags 0x800000

* fix pad name

* fix pads

* Return void for C_StreamingTrafficModule::SetMaxHumanElements

* Set fields as public

* Fixed used notation

---------

Co-authored-by: Segfault <5221072+Segfaultd@users.noreply.github.com>
  • Loading branch information
Deewarz and Segfaultd authored Feb 3, 2024
1 parent abd9f1b commit e260bf4
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 17 deletions.
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 @@ -322,6 +322,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 48 85 FF 74 03 48 89 37 48 8D 48 10 48 85 C9 74 34 8B 44 24 20 48 8D 71 08 89 01 48 8D 54 24 ? 48 8B 44 24 ? 48 8B CE 48 89 06 E8 ? ? ? ? 84 C0 75 11 48 83 3E 00 74 0B 48 8B CE E8 ? ? ? ? F0 FF 00 49 8B 8E ? ? ? ? 48 B8 ? ? ? ? ? ? ? ? 48 2B C1 48 83 F8 01 73 0E 48 8D 0D ? ? ? ? FF 15 ? ? ? ? CC 48 8D 41 01 49 89 86 ? ? ? ? 48 89 5D 08 48 8B 07 48 89 18 48 83 7C 24 ? ? 74 1E 48 8D 4C 24 ? E8 ? ? ? ? 83 C9 FF F0 0F C1 08 83 F9 01 75 08 48 8B C8 E8 ? ? ? ? 48 8B 7C 24 ? 48 8B 5C 24 ? 48 8B 6C 24 ? 48 8B 74 24 ? 48 83 C4 30 41 5E C3 CC CC CC CC 40 53 48 83 EC 20 44 8B 41 10 48 8D 81 ? ? ? ? 48 89 81 ? ? ? ? 32 DB 41 8D 40 FF"));
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 @@ -290,6 +290,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

0 comments on commit e260bf4

Please sign in to comment.