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

Add support for currently spectated ghost #7

Open
wants to merge 3 commits into
base: main
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Export.as
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ namespace VehicleState
// Get vehicle vis from a given player.
import CSceneVehicleVis@ GetVis(ISceneVis@ sceneVis, CSmPlayer@ player) from "VehicleState";

// Get vehicle vis with a given entity ID.
import CSceneVehicleVis@ GetVis(ISceneVis@ sceneVis, uint vehicleEntityId) from "VehicleState";

// Get the only existing vehicle vis state, if there is only one. Otherwise, this returns null.
import CSceneVehicleVis@ GetSingularVis(ISceneVis@ sceneVis) from "VehicleState";

Expand Down
30 changes: 28 additions & 2 deletions Internal/Impl.as
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
namespace VehicleState
{
#if TMNEXT
CSmPlayer@ GetViewingPlayer()
CGameTerminal@ GetGameTerminal()
{
auto playground = GetApp().CurrentPlayground;
if (playground is null || playground.GameTerminals.Length != 1) {
return null;
}
return cast<CSmPlayer>(playground.GameTerminals[0].GUIPlayer);
return playground.GameTerminals[0];
}

CSmPlayer@ GetViewingPlayer()
{
auto gameTerminal = GetGameTerminal();
if (gameTerminal is null) {
return null;
}
return cast<CSmPlayer>(gameTerminal.GUIPlayer);
}
#elif TURBO
CGameMobil@ GetViewingPlayer()
Expand Down Expand Up @@ -62,6 +71,23 @@ namespace VehicleState
}
#endif

#if TMNEXT
if (vis is null) {
auto gameTerminal = GetGameTerminal();
if (gameTerminal !is null) {
auto type = Reflection::GetType("CGameTerminal");
if (type !is null) {
auto offset = type.GetMember("MediaAmbianceClipPlayer").Offset + 0x68;
bool isWatchingGhost = Dev::GetOffsetUint8(gameTerminal, offset) == 1;
auto ghostVisEntId = Dev::GetOffsetUint32(gameTerminal, offset + 0x4);
if (isWatchingGhost && ghostVisEntId & 0x04000000 > 0) {
@vis = GetVis(sceneVis, ghostVisEntId);
}
}
}
}
#endif

return vis;
}

Expand Down
2 changes: 1 addition & 1 deletion Internal/SceneVis.as
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace SceneVis
CMwNod@ GetManager(ISceneVis@ sceneVis, uint index)
{
uint managerCount = Dev::GetOffsetUint32(sceneVis, 0x8);
if (index > managerCount) {
if (index >= managerCount) {
error("Index out of range: there are only " + managerCount + " managers");
return null;
}
Expand Down
6 changes: 5 additions & 1 deletion Internal/Vehicle/VehicleNext.as
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ namespace VehicleState
// Get vehicle vis from a given player.
CSceneVehicleVis@ GetVis(ISceneVis@ sceneVis, CSmPlayer@ player)
{
uint vehicleEntityId = GetPlayerVehicleID(player);
return GetVis(sceneVis, GetPlayerVehicleID(player));
}

// Get vehicle vis with a given entity ID.
CSceneVehicleVis@ GetVis(ISceneVis@ sceneVis, uint vehicleEntityId)
{
auto vehicleVisMgr = SceneVis::GetManager(sceneVis, VehiclesManagerIndex); // NSceneVehicleVis_SMgr
if (vehicleVisMgr is null) {
return null;
Expand Down