From 4618577ae42ec08c704a200b1caae4395aeea934 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Sat, 23 Jul 2022 22:09:30 +0300 Subject: [PATCH] Implement `.Legacy` member for native entity types. --- module/Entity/Checkpoint.cpp | 13 +++++++++++++ module/Entity/Checkpoint.hpp | 6 ++++++ module/Entity/Object.cpp | 13 +++++++++++++ module/Entity/Object.hpp | 6 ++++++ module/Entity/Pickup.cpp | 13 +++++++++++++ module/Entity/Pickup.hpp | 6 ++++++ module/Entity/Player.cpp | 14 +++++++++++++- module/Entity/Player.hpp | 6 ++++++ module/Entity/Vehicle.cpp | 13 +++++++++++++ module/Entity/Vehicle.hpp | 6 ++++++ 10 files changed, 95 insertions(+), 1 deletion(-) diff --git a/module/Entity/Checkpoint.cpp b/module/Entity/Checkpoint.cpp index 70617a13..e24709b1 100644 --- a/module/Entity/Checkpoint.cpp +++ b/module/Entity/Checkpoint.cpp @@ -468,6 +468,16 @@ void CCheckpoint::SetColorA(int32_t a) const // Perform the requested operation _Func->SetCheckPointColour(m_ID, r, g, b, a); } +#ifdef VCMP_ENABLE_OFFICIAL +// ------------------------------------------------------------------------------------------------ +LightObj & CCheckpoint::GetLegacyObject() const +{ + // Validate the managed identifier + Validate(); + // Return the requested information + return Core::Get().GetCheckpoint(m_ID).mLgObj; +} +#endif // ------------------------------------------------------------------------------------------------ static LightObj & Checkpoint_CreateEx1a(int32_t world, bool sphere, float x, float y, float z, @@ -517,6 +527,9 @@ void Register_CCheckpoint(HSQUIRRELVM vm) .Prop(_SC("Tag"), &CCheckpoint::GetTag, &CCheckpoint::SetTag) .Prop(_SC("Data"), &CCheckpoint::GetData, &CCheckpoint::SetData) .Prop(_SC("Active"), &CCheckpoint::IsActive) +#ifdef VCMP_ENABLE_OFFICIAL + .Prop(_SC("Legacy"), &CCheckpoint::GetLegacyObject) +#endif // Core Methods .FmtFunc(_SC("SetTag"), &CCheckpoint::ApplyTag) .Func(_SC("CustomEvent"), &CCheckpoint::CustomEvent) diff --git a/module/Entity/Checkpoint.hpp b/module/Entity/Checkpoint.hpp index 82eeb0da..71dfb622 100644 --- a/module/Entity/Checkpoint.hpp +++ b/module/Entity/Checkpoint.hpp @@ -320,6 +320,12 @@ public: * Modify the alpha transparency of the managed checkpoint entity. */ void SetColorA(int32_t a) const; +#ifdef VCMP_ENABLE_OFFICIAL + /* -------------------------------------------------------------------------------------------- + * Retrieve legacy object instance for this entity. + */ + LightObj & GetLegacyObject() const; +#endif }; } // Namespace:: SqMod diff --git a/module/Entity/Object.cpp b/module/Entity/Object.cpp index 57026623..e063184b 100644 --- a/module/Entity/Object.cpp +++ b/module/Entity/Object.cpp @@ -833,6 +833,16 @@ void CObject::RotateByEulerZ(float z) const // Perform the requested operation _Func->RotateObjectByEuler(m_ID, 0.0f, 0.0f, z, mRotateByEulerDuration); } +#ifdef VCMP_ENABLE_OFFICIAL +// ------------------------------------------------------------------------------------------------ +LightObj & CObject::GetLegacyObject() const +{ + // Validate the managed identifier + Validate(); + // Return the requested information + return Core::Get().GetObj(m_ID).mLgObj; +} +#endif // ------------------------------------------------------------------------------------------------ static LightObj & Object_CreateEx1a(int32_t model, int32_t world, float x, float y, float z, @@ -883,6 +893,9 @@ void Register_CObject(HSQUIRRELVM vm) .Prop(_SC("Tag"), &CObject::GetTag, &CObject::SetTag) .Prop(_SC("Data"), &CObject::GetData, &CObject::SetData) .Prop(_SC("Active"), &CObject::IsActive) +#ifdef VCMP_ENABLE_OFFICIAL + .Prop(_SC("Legacy"), &CObject::GetLegacyObject) +#endif // Core Methods .FmtFunc(_SC("SetTag"), &CObject::ApplyTag) .Func(_SC("CustomEvent"), &CObject::CustomEvent) diff --git a/module/Entity/Object.hpp b/module/Entity/Object.hpp index 1427a432..c7e4d8fa 100644 --- a/module/Entity/Object.hpp +++ b/module/Entity/Object.hpp @@ -499,6 +499,12 @@ public: * Modify the rotation on the z axis of the managed object entity. */ void RotateByEulerZ(float z) const; +#ifdef VCMP_ENABLE_OFFICIAL + /* -------------------------------------------------------------------------------------------- + * Retrieve legacy object instance for this entity. + */ + LightObj & GetLegacyObject() const; +#endif }; } // Namespace:: SqMod diff --git a/module/Entity/Pickup.cpp b/module/Entity/Pickup.cpp index 6004a714..93cc21b2 100644 --- a/module/Entity/Pickup.cpp +++ b/module/Entity/Pickup.cpp @@ -449,6 +449,16 @@ void CPickup::SetPositionZ(float z) const // Perform the requested operation _Func->SetPickupPosition(m_ID, z, y, z); } +#ifdef VCMP_ENABLE_OFFICIAL +// ------------------------------------------------------------------------------------------------ +LightObj & CPickup::GetLegacyObject() const +{ + // Validate the managed identifier + Validate(); + // Return the requested information + return Core::Get().GetPickup(m_ID).mLgObj; +} +#endif // ------------------------------------------------------------------------------------------------ static LightObj & Pickup_CreateEx1a(int32_t model, int32_t world, int32_t quantity, @@ -496,6 +506,9 @@ void Register_CPickup(HSQUIRRELVM vm) .Prop(_SC("Tag"), &CPickup::GetTag, &CPickup::SetTag) .Prop(_SC("Data"), &CPickup::GetData, &CPickup::SetData) .Prop(_SC("Active"), &CPickup::IsActive) +#ifdef VCMP_ENABLE_OFFICIAL + .Prop(_SC("Legacy"), &CPickup::GetLegacyObject) +#endif // Core Methods .FmtFunc(_SC("SetTag"), &CPickup::ApplyTag) .Func(_SC("CustomEvent"), &CPickup::CustomEvent) diff --git a/module/Entity/Pickup.hpp b/module/Entity/Pickup.hpp index 8b384de0..992ad01e 100644 --- a/module/Entity/Pickup.hpp +++ b/module/Entity/Pickup.hpp @@ -298,6 +298,12 @@ public: * Modify the position on the z axis of the managed pickup entity. */ void SetPositionZ(float z) const; +#ifdef VCMP_ENABLE_OFFICIAL + /* -------------------------------------------------------------------------------------------- + * Retrieve legacy object instance for this entity. + */ + LightObj & GetLegacyObject() const; +#endif }; } // Namespace:: SqMod diff --git a/module/Entity/Player.cpp b/module/Entity/Player.cpp index 30a36cd2..85031e56 100644 --- a/module/Entity/Player.cpp +++ b/module/Entity/Player.cpp @@ -2593,7 +2593,16 @@ SQInteger CPlayer::AnnounceEx(HSQUIRRELVM vm) // This function does not return a value return 0; } - +#ifdef VCMP_ENABLE_OFFICIAL +// ------------------------------------------------------------------------------------------------ +LightObj & CPlayer::GetLegacyObject() const +{ + // Validate the managed identifier + Validate(); + // Return the requested information + return Core::Get().GetPlayer(m_ID).mLgObj; +} +#endif // ------------------------------------------------------------------------------------------------ SQInteger Player_FindAuto(HSQUIRRELVM vm) { @@ -2793,6 +2802,9 @@ void Register_CPlayer(HSQUIRRELVM vm) .Prop(_SC("Tag"), &CPlayer::GetTag, &CPlayer::SetTag) .Prop(_SC("Data"), &CPlayer::GetData, &CPlayer::SetData) .Prop(_SC("Active"), &CPlayer::IsActive) +#ifdef VCMP_ENABLE_OFFICIAL + .Prop(_SC("Legacy"), &CPlayer::GetLegacyObject) +#endif // Core Methods .FmtFunc(_SC("SetTag"), &CPlayer::ApplyTag) .Func(_SC("CustomEvent"), &CPlayer::CustomEvent) diff --git a/module/Entity/Player.hpp b/module/Entity/Player.hpp index 837dbdbf..c10ef971 100644 --- a/module/Entity/Player.hpp +++ b/module/Entity/Player.hpp @@ -1101,6 +1101,12 @@ public: * Send a formatted announcement message to the managed player entity. */ static SQInteger AnnounceEx(HSQUIRRELVM vm); +#ifdef VCMP_ENABLE_OFFICIAL + /* -------------------------------------------------------------------------------------------- + * Retrieve legacy object instance for this entity. + */ + LightObj & GetLegacyObject() const; +#endif }; } // Namespace:: SqMod diff --git a/module/Entity/Vehicle.cpp b/module/Entity/Vehicle.cpp index 5be93117..9d4464ba 100644 --- a/module/Entity/Vehicle.cpp +++ b/module/Entity/Vehicle.cpp @@ -2015,6 +2015,16 @@ void CVehicle::SetRelativeTurnSpeedZ(float z) const // Perform the requested operation _Func->SetVehicleTurnSpeed(m_ID, z, y, z, static_cast< uint8_t >(false), static_cast< uint8_t >(true)); } +#ifdef VCMP_ENABLE_OFFICIAL +// ------------------------------------------------------------------------------------------------ +LightObj & CVehicle::GetLegacyObject() const +{ + // Validate the managed identifier + Validate(); + // Return the requested information + return Core::Get().GetVehicle(m_ID).mLgObj; +} +#endif // ------------------------------------------------------------------------------------------------ static LightObj & Vehicle_CreateEx1a(int32_t model, int32_t world, float x, float y, float z, float angle, @@ -2061,6 +2071,9 @@ void Register_CVehicle(HSQUIRRELVM vm) .Prop(_SC("ID"), &CVehicle::GetID) .Prop(_SC("Tag"), &CVehicle::GetTag, &CVehicle::SetTag) .Prop(_SC("Data"), &CVehicle::GetData, &CVehicle::SetData) +#ifdef VCMP_ENABLE_OFFICIAL + .Prop(_SC("Legacy"), &CVehicle::GetLegacyObject) +#endif .Prop(_SC("Active"), &CVehicle::IsActive) // Core Methods .FmtFunc(_SC("SetTag"), &CVehicle::ApplyTag) diff --git a/module/Entity/Vehicle.hpp b/module/Entity/Vehicle.hpp index 0a00705e..10d5e98d 100644 --- a/module/Entity/Vehicle.hpp +++ b/module/Entity/Vehicle.hpp @@ -942,6 +942,12 @@ public: * Modify the relative turn velocity on the z axis of the managed vehicle entity. */ void SetRelativeTurnSpeedZ(float z) const; +#ifdef VCMP_ENABLE_OFFICIAL + /* -------------------------------------------------------------------------------------------- + * Retrieve legacy object instance for this entity. + */ + LightObj & GetLegacyObject() const; +#endif }; } // Namespace:: SqMod