-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from MafiaHub/racing-ui
Racing UI API
- Loading branch information
Showing
12 changed files
with
321 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "c_ui_database.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#pragma once | ||
|
||
#include "../../ue/sys/sodb/c_database_interface.h" | ||
|
||
namespace SDK { | ||
namespace mafia::database { | ||
class C_UIDatabase: public ue::sys::sodb::C_DatabaseInterface { | ||
public: | ||
class C_HUDTable { | ||
public: | ||
uint8_t pad0[0x1E]; // 0000 - 001E | ||
bool m_bRacingVisible = false; // 001E - 001F | ||
uint8_t pad1[0x3]; // 001F - 0022 | ||
uint8_t pad2[0x346]; // 0022 - 0368 | ||
float m_fElapsedTime = 0.0f; // 0368 - 036C | ||
float m_fTargetTime = 0.0f; // 036C - 0370 | ||
uint16_t m_uCurCheckpoint = 0; // 0370 - 0372 | ||
uint16_t m_uTotalCheckpoints = 0; // 0372 - 0374 | ||
uint16_t m_uCurPosition = 0; // 0374 - 0376 | ||
uint16_t m_uTotalPositions = 0; // 0376 - 0378 | ||
uint16_t m_uUnknown1 = 0; // 0378 - 037C | ||
uint16_t m_uUnknown2 = 0; // 0378 - 037C | ||
uint16_t m_uCurLap = 0; // 037C - 037E | ||
uint16_t m_uTotalLaps = 0; // 037E - 0380 | ||
uint8_t m_uCountdown = 0; // 0380 - 0381 | ||
}; | ||
|
||
C_HUDTable *GetHUDTable() const { | ||
return m_pHUDTable; | ||
} | ||
|
||
private: | ||
// NB: Atleast 0x38 is part of C_DatabaseInterface | ||
// Since m_pHUDTable is at 0x20, that could actually be part of base class | ||
uint8_t pad0[0x20]; // 0000 - 0020 | ||
C_HUDTable *m_pHUDTable = nullptr; // 0020 - 0028 | ||
}; | ||
}; // namespace mafia::database | ||
}; // namespace SDK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,42 @@ | ||
#pragma once | ||
|
||
#include "../../../patterns.h" | ||
|
||
namespace SDK { | ||
namespace mafia::ui::hud { | ||
|
||
class C_RaceTimer { | ||
public: | ||
|
||
// This starts C_RaceManager! | ||
// If you do not wish to use C_RaceManager, use mafia::ui::hud::RaceXBin instead! | ||
void SetVisible(const bool visible) { | ||
hook::this_call(gPatterns.C_RaceTimer_SetVisible, this, visible); | ||
} | ||
|
||
// This starts C_RaceManager! | ||
// If you do not wish to use C_RaceManager, Use mafia::ui::hud::RaceXBin instead! | ||
void StartRace(const uint32_t numCheckpoints, const float targetTime, const uint32_t numLaps) { | ||
hook::this_call(gPatterns.C_RaceTimer_StartRace, this, numCheckpoints, targetTime, numLaps); | ||
} | ||
|
||
private: | ||
void *m_pVtable = nullptr; // 0000 - 0008 | ||
void *m_pUnk0 = nullptr; // 0008 - 0010 | ||
float m_fTimer = 0.0f; // 0010 - 0014 | ||
uint32_t m_uCurrentCheckpoint = 0; // 0014 - 0018 | ||
uint32_t m_uCurrentLap = 0; // 0018 - 001C | ||
}; | ||
|
||
class C_HudController { | ||
public: | ||
C_RaceTimer *GetRacingTimer() { | ||
return m_pRaceTimer; | ||
} | ||
|
||
private: | ||
char pad0[0x5A8]; // 0000 - 05A8 | ||
C_RaceTimer *m_pRaceTimer = nullptr; // 05A8 - 05B0 | ||
}; | ||
} // namespace mafia::ui::hud | ||
} // namespace SDK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include "race_xbin.h" | ||
|
||
#include "../../database/c_ui_database.h" | ||
#include "../c_game_gui_2_module.h" | ||
|
||
namespace RaceXBinUtils | ||
{ | ||
// Handy little utility function to fetch the HUDTable, for the Racing XBin. | ||
SDK::mafia::database::C_UIDatabase::C_HUDTable *GetHUDTable() { | ||
|
||
// Fetch database | ||
SDK::mafia::ui::C_GameGUI2Module *GameGuiModule = SDK::mafia::ui::GetGameGui2Module(); | ||
SDK::ue::C_WeakPtr<SDK::ue::sys::sodb::C_DatabaseInterface> result = GameGuiModule->GetDatabase(); | ||
|
||
// need to cast to C_UIDatabase | ||
// TODO: Feels like this should be dynamic_cast, rather than reinterpret_cast | ||
if (SDK::mafia::database::C_UIDatabase *database = reinterpret_cast<SDK::mafia::database::C_UIDatabase *>(result.Get())) { | ||
return database->GetHUDTable(); | ||
} | ||
|
||
return nullptr; | ||
} | ||
} | ||
|
||
namespace SDK { | ||
namespace mafia::ui::hud { | ||
|
||
void RaceXBin::SetVisible(const bool visibility) { | ||
if (SDK::mafia::database::C_UIDatabase::C_HUDTable *hudTable = RaceXBinUtils::GetHUDTable()) { | ||
hudTable->m_bRacingVisible = visibility; | ||
} | ||
} | ||
|
||
void RaceXBin::SetTargetTime(const float targetTime) { | ||
if (SDK::mafia::database::C_UIDatabase::C_HUDTable *hudTable = RaceXBinUtils::GetHUDTable()) { | ||
hudTable->m_fTargetTime = targetTime; | ||
} | ||
} | ||
|
||
void RaceXBin::SetPosition(const uint16_t currentPosition) { | ||
if (SDK::mafia::database::C_UIDatabase::C_HUDTable *hudTable = RaceXBinUtils::GetHUDTable()) { | ||
hudTable->m_uCurPosition = currentPosition; | ||
} | ||
} | ||
|
||
void RaceXBin::SetPositionTotal(const uint16_t totalPositions) { | ||
if (SDK::mafia::database::C_UIDatabase::C_HUDTable *hudTable = RaceXBinUtils::GetHUDTable()) { | ||
hudTable->m_uTotalPositions = totalPositions; | ||
} | ||
} | ||
|
||
void RaceXBin::SetLaps(const uint16_t currentLap) { | ||
if (SDK::mafia::database::C_UIDatabase::C_HUDTable *hudTable = RaceXBinUtils::GetHUDTable()) { | ||
hudTable->m_uCurLap = currentLap; | ||
} | ||
} | ||
|
||
void RaceXBin::SetLapsTotal(const uint16_t totalLaps) { | ||
if (SDK::mafia::database::C_UIDatabase::C_HUDTable *hudTable = RaceXBinUtils::GetHUDTable()) { | ||
hudTable->m_uTotalLaps = totalLaps; | ||
} | ||
} | ||
|
||
void RaceXBin::SetCheckpoints(const uint16_t currentCheckpoint) { | ||
if (SDK::mafia::database::C_UIDatabase::C_HUDTable *hudTable = RaceXBinUtils::GetHUDTable()) { | ||
hudTable->m_uCurCheckpoint = currentCheckpoint; | ||
} | ||
} | ||
|
||
void RaceXBin::SetCheckpointsTotal(const uint16_t totalCheckpoint) { | ||
if (SDK::mafia::database::C_UIDatabase::C_HUDTable *hudTable = RaceXBinUtils::GetHUDTable()) { | ||
hudTable->m_uTotalCheckpoints = totalCheckpoint; | ||
} | ||
} | ||
|
||
void RaceXBin::SetCountdown(const uint8_t countdown) { | ||
if (SDK::mafia::database::C_UIDatabase::C_HUDTable *hudTable = RaceXBinUtils::GetHUDTable()) { | ||
hudTable->m_uCountdown = countdown; | ||
} | ||
} | ||
} // namespace mafia::ui::hud | ||
} // namespace SDK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
|
||
namespace SDK { | ||
namespace mafia::ui::hud { | ||
|
||
/** | ||
* Handy structure which provides an API to update the Racing HUD Element. | ||
* Note that there are some discrepancies with the executable code however | ||
* all functionality should be the same. | ||
*/ | ||
class RaceXBin { | ||
public: | ||
|
||
/** | ||
* Set the visibility of the Racing HUD Element. | ||
* @param bVisibility - Should the HUD Element be visible | ||
*/ | ||
static void SetVisible(const bool visiblity); | ||
|
||
/** | ||
* Set the Target Time on the Racing HUD Element. | ||
* Note that this may not have an effect (eg. appear on the HUD) | ||
* @param InTargetTime - Target Time to show on the HUD | ||
*/ | ||
static void SetTargetTime(const float targetTime); | ||
|
||
/** | ||
* Set the current Position on the Racing HUD Element. | ||
* Note that 'Total Positions' may need to be set before this to have an effect. | ||
* @param InPosition - The current position out of Total Positions | ||
*/ | ||
static void SetPosition(const uint16_t currentPosition); | ||
|
||
/** | ||
* Set the max amount of Positions on the Racing HUD Element | ||
* @param InTotalPosition - Max number of positions | ||
*/ | ||
static void SetPositionTotal(const uint16_t totalPositions); | ||
|
||
/** | ||
* Set the current Lap on the Racing HUD Element. | ||
* Note that 'Total Laps' may need to be set before this to have an effect. | ||
* @param InLaps - The current Lap out of Total Laps | ||
*/ | ||
static void SetLaps(const uint16_t currentLap); | ||
|
||
/** | ||
* Set the number of Laps on the Racing HUD Element | ||
* @param InTotalPosition - Number of Laps | ||
*/ | ||
static void SetLapsTotal(const uint16_t totalLaps); | ||
|
||
/** | ||
* Set the current Checkpoint on the Racing HUD Element. | ||
* Note that 'Total Checkpoints' may need to be set before this to have an effect. | ||
* @param InPosition - The current Checkpoint out of Total Checkpoints | ||
*/ | ||
static void SetCheckpoints(const uint16_t currentCheckpoint); | ||
|
||
/** | ||
* Set the max amount of Checkpoints on the Racing HUD Element | ||
* @param InTotalPosition - Max number of checkpoints | ||
*/ | ||
static void SetCheckpointsTotal(const uint16_t totalCheckpoints); | ||
|
||
/** | ||
* Set the countdown. Max is 3, Minimum is 0. | ||
* The HUD automatically plays the noise when the countdown is updated. | ||
* The caller will have to manage a timer for the countdown. | ||
* @param InCountdown - Current step in the Countdown | ||
*/ | ||
static void SetCountdown(const uint8_t countdown); | ||
}; | ||
} // namespace mafia::ui::hud | ||
} // namespace SDK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.