1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-07-06 08:57:11 +02:00

Migrated the host module to C++ exceptions as well.

Also enabled the latest C++ revision in the project.
Replaced the Random library with the one provided by C++11.
Implemented a simple AES256 encryption class.
Various other fixes and improvements.
This commit is contained in:
Sandu Liviu Catalin
2016-03-10 05:57:13 +02:00
parent 3162221e7f
commit 70e5f0ba21
124 changed files with 14873 additions and 14062 deletions

View File

@ -11,15 +11,20 @@ namespace SqMod {
Vector3 CPickup::s_Vector3;
// ------------------------------------------------------------------------------------------------
SQChar CPickup::s_StrID[SQMOD_PICKUP_POOL][8];
const Int32 CPickup::Max = SQMOD_PICKUP_POOL;
// ------------------------------------------------------------------------------------------------
const Int32 CPickup::Max = SQMOD_PICKUP_POOL;
SQInteger CPickup::Typename(HSQUIRRELVM vm)
{
static SQChar name[] = _SC("SqPickup");
sq_pushstring(vm, name, sizeof(name));
return 1;
}
// ------------------------------------------------------------------------------------------------
CPickup::CPickup(Int32 id)
: m_ID(VALID_ENTITYGETEX(id, SQMOD_PICKUP_POOL))
, m_Tag(VALID_ENTITY(m_ID) ? s_StrID[m_ID] : _SC("-1"))
, m_Tag(ToStrF("%d", id))
{
/* ... */
}
@ -41,221 +46,289 @@ Int32 CPickup::Cmp(const CPickup & o) const
return -1;
}
CSStr CPickup::ToString() const
// ------------------------------------------------------------------------------------------------
const String & CPickup::ToString() const
{
return VALID_ENTITYEX(m_ID, SQMOD_PICKUP_POOL) ? s_StrID[m_ID] : _SC("-1");
return m_Tag;
}
// ------------------------------------------------------------------------------------------------
CSStr CPickup::GetTag() const
const String & CPickup::GetTag() const
{
return m_Tag.c_str();
return m_Tag;
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetTag(CSStr tag)
{
m_Tag.assign(tag);
}
// ------------------------------------------------------------------------------------------------
Object & CPickup::GetData()
{
if (Validate())
return m_Data;
return NullObject();
// Validate the managed identifier
Validate();
// Return the requested information
return m_Data;
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetData(Object & data)
{
if (Validate())
m_Data = data;
// Validate the managed identifier
Validate();
// Apply the specified value
m_Data = data;
}
// ------------------------------------------------------------------------------------------------
bool CPickup::Destroy(Int32 header, Object & payload)
{
// Validate the managed identifier
Validate();
// Perform the requested operation
return _Core->DelPickup(m_ID, header, payload);
}
// ------------------------------------------------------------------------------------------------
bool CPickup::BindEvent(Int32 evid, Object & env, Function & func) const
void CPickup::BindEvent(Int32 evid, Object & env, Function & func) const
{
if (!Validate())
return false;
// Validate the managed identifier
Validate();
// Obtain the function instance called for this event
Function & event = _Core->GetPickupEvent(m_ID, evid);
// Is the specified callback function null?
if (func.IsNull())
event.Release();
event.Release(); // Then release the current callback
// Assign the specified environment and function
else
event = Function(env.GetVM(), env, func.GetFunc());
return true;
}
// ------------------------------------------------------------------------------------------------
bool CPickup::IsStreamedFor(CPlayer & player) const
{
// Is the specified player even valid?
if (!player.IsActive())
SqThrow("Invalid player argument: null");
else if (Validate())
return _Func->IsPickupStreamedForPlayer(m_ID, player.GetID());
return false;
SqThrowF("Invalid player argument: null");
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->IsPickupStreamedForPlayer(m_ID, player.GetID());
}
// ------------------------------------------------------------------------------------------------
Int32 CPickup::GetModel() const
{
if (Validate())
return _Func->PickupGetModel(m_ID);
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->PickupGetModel(m_ID);
}
// ------------------------------------------------------------------------------------------------
Int32 CPickup::GetWorld() const
{
if (Validate())
return _Func->GetPickupWorld(m_ID);
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->GetPickupWorld(m_ID);
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetWorld(Int32 world) const
{
if (Validate())
_Func->SetPickupWorld(m_ID, world);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetPickupWorld(m_ID, world);
}
// ------------------------------------------------------------------------------------------------
Int32 CPickup::GetAlpha() const
{
if (Validate())
return _Func->GetVehicleModel(m_ID);
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->GetVehicleModel(m_ID);
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetAlpha(Int32 alpha) const
{
if (Validate())
_Func->PickupSetAlpha(m_ID, alpha);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->PickupSetAlpha(m_ID, alpha);
}
// ------------------------------------------------------------------------------------------------
bool CPickup::GetAutomatic() const
{
if (Validate())
return _Func->PickupIsAutomatic(m_ID);
return false;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->PickupIsAutomatic(m_ID);
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetAutomatic(bool toggle) const
{
if (Validate())
_Func->PickupSetAutomatic(m_ID, toggle);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->PickupSetAutomatic(m_ID, toggle);
}
// ------------------------------------------------------------------------------------------------
Int32 CPickup::GetAutoTimer() const
{
if (Validate())
return _Func->GetPickupAutoTimer(m_ID);
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->GetPickupAutoTimer(m_ID);
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetAutoTimer(Int32 timer) const
{
if (Validate())
_Func->SetPickupAutoTimer(m_ID, timer);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->SetPickupAutoTimer(m_ID, timer);
}
// ------------------------------------------------------------------------------------------------
void CPickup::Refresh() const
{
if (Validate())
_Func->PickupRefresh(m_ID);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->PickupRefresh(m_ID);
}
// ------------------------------------------------------------------------------------------------
const Vector3 & CPickup::GetPosition()
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
s_Vector3.Clear();
if (Validate())
_Func->PickupGetPos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
// Query the server for the position values
_Func->PickupGetPos(m_ID, &s_Vector3.x, &s_Vector3.y, &s_Vector3.z);
// Return the requested information
return s_Vector3;
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetPosition(const Vector3 & pos) const
{
if (Validate())
_Func->PickupSetPos(m_ID, pos.x, pos.y, pos.z);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->PickupSetPos(m_ID, pos.x, pos.y, pos.z);
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetPositionEx(Float32 x, Float32 y, Float32 z) const
{
if (Validate())
_Func->PickupSetPos(m_ID, x, y, z);
// Validate the managed identifier
Validate();
// Perform the requested operation
_Func->PickupSetPos(m_ID, x, y, z);
}
// ------------------------------------------------------------------------------------------------
Int32 CPickup::GetQuantity() const
{
if (Validate())
return _Func->PickupGetQuantity(m_ID);
return -1;
// Validate the managed identifier
Validate();
// Return the requested information
return _Func->PickupGetQuantity(m_ID);
}
// ------------------------------------------------------------------------------------------------
Float32 CPickup::GetPosX() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
s_Vector3.x = 0;
if (Validate())
_Func->PickupGetPos(m_ID, &s_Vector3.x, NULL, NULL);
// Query the server for the requested component value
_Func->PickupGetPos(m_ID, &s_Vector3.x, NULL, NULL);
// Return the requested information
return s_Vector3.x;
}
// ------------------------------------------------------------------------------------------------
Float32 CPickup::GetPosY() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
s_Vector3.y = 0;
if (Validate())
_Func->PickupGetPos(m_ID, NULL, &s_Vector3.y, NULL);
// Query the server for the requested component value
_Func->PickupGetPos(m_ID, NULL, &s_Vector3.y, NULL);
// Return the requested information
return s_Vector3.y;
}
// ------------------------------------------------------------------------------------------------
Float32 CPickup::GetPosZ() const
{
// Validate the managed identifier
Validate();
// Clear previous position information, if any
s_Vector3.z = 0;
if (Validate())
_Func->PickupGetPos(m_ID, NULL, NULL, &s_Vector3.z);
// Query the server for the requested component value
_Func->PickupGetPos(m_ID, NULL, NULL, &s_Vector3.z);
// Return the requested information
return s_Vector3.z;
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetPosX(Float32 x) const
{
if (Validate())
{
_Func->PickupGetPos(m_ID, NULL, &s_Vector3.y, &s_Vector3.z);
_Func->PickupSetPos(m_ID, x, s_Vector3.y, s_Vector3.z);
}
}
void CPickup::SetPosY(Float32 y) const
{
if (Validate())
{
_Func->PickupGetPos(m_ID, &s_Vector3.x, NULL, &s_Vector3.z);
_Func->PickupSetPos(m_ID, s_Vector3.x, y, s_Vector3.z);
}
}
void CPickup::SetPosZ(Float32 z) const
{
if (Validate())
{
_Func->PickupGetPos(m_ID, &s_Vector3.x, &s_Vector3.y, NULL);
_Func->PickupSetPos(m_ID, s_Vector3.z, s_Vector3.y, z);
}
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->PickupGetPos(m_ID, NULL, &s_Vector3.y, &s_Vector3.z);
// Perform the requested operation
_Func->PickupSetPos(m_ID, x, s_Vector3.y, s_Vector3.z);
}
// ------------------------------------------------------------------------------------------------
static Object & CreatePickupEx(Int32 model, Int32 world, Int32 quantity,
void CPickup::SetPosY(Float32 y) const
{
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->PickupGetPos(m_ID, &s_Vector3.x, NULL, &s_Vector3.z);
// Perform the requested operation
_Func->PickupSetPos(m_ID, s_Vector3.x, y, s_Vector3.z);
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetPosZ(Float32 z) const
{
// Validate the managed identifier
Validate();
// Retrieve the current values for unchanged components
_Func->PickupGetPos(m_ID, &s_Vector3.x, &s_Vector3.y, NULL);
// Perform the requested operation
_Func->PickupSetPos(m_ID, s_Vector3.z, s_Vector3.y, z);
}
// ------------------------------------------------------------------------------------------------
static Object & Pickup_CreateEx(Int32 model, Int32 world, Int32 quantity,
Float32 x, Float32 y, Float32 z, Int32 alpha, bool automatic)
{
return _Core->NewPickup(model, world, quantity, x, y, z, alpha, automatic,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreatePickupEx(Int32 model, Int32 world, Int32 quantity,
static Object & Pickup_CreateEx(Int32 model, Int32 world, Int32 quantity,
Float32 x, Float32 y, Float32 z, Int32 alpha, bool automatic,
Int32 header, Object & payload)
{
@ -263,14 +336,14 @@ static Object & CreatePickupEx(Int32 model, Int32 world, Int32 quantity,
}
// ------------------------------------------------------------------------------------------------
static Object & CreatePickup(Int32 model, Int32 world, Int32 quantity, const Vector3 & pos,
static Object & Pickup_Create(Int32 model, Int32 world, Int32 quantity, const Vector3 & pos,
Int32 alpha, bool automatic)
{
return _Core->NewPickup(model, world, quantity, pos.x, pos.y, pos.z, alpha, automatic,
SQMOD_CREATE_DEFAULT, NullObject());
}
static Object & CreatePickup(Int32 model, Int32 world, Int32 quantity, const Vector3 & pos,
static Object & Pickup_Create(Int32 model, Int32 world, Int32 quantity, const Vector3 & pos,
Int32 alpha, bool automatic, Int32 header, Object & payload)
{
return _Core->NewPickup(model, world, quantity, pos.x, pos.y, pos.z, alpha, automatic,
@ -282,22 +355,24 @@ void Register_CPickup(HSQUIRRELVM vm)
{
RootTable(vm).Bind(_SC("SqPickup"),
Class< CPickup, NoConstructor< CPickup > >(vm, _SC("SqPickup"))
/* Metamethods */
// Metamethods
.Func(_SC("_cmp"), &CPickup::Cmp)
.SquirrelFunc(_SC("_typename"), &CPickup::Typename)
.Func(_SC("_tostring"), &CPickup::ToString)
/* Core Properties */
// Static values
.SetStaticValue(_SC("MaxID"), CPickup::Max)
// Core Properties
.Prop(_SC("ID"), &CPickup::GetID)
.Prop(_SC("Tag"), &CPickup::GetTag, &CPickup::SetTag)
.Prop(_SC("Data"), &CPickup::GetData, &CPickup::SetData)
.Prop(_SC("MaxID"), &CPickup::GetMaxID)
.Prop(_SC("Active"), &CPickup::IsActive)
/* Core Functions */
// Core Functions
.Func(_SC("Bind"), &CPickup::BindEvent)
/* Core Overloads */
// Core Overloads
.Overload< bool (CPickup::*)(void) >(_SC("Destroy"), &CPickup::Destroy)
.Overload< bool (CPickup::*)(Int32) >(_SC("Destroy"), &CPickup::Destroy)
.Overload< bool (CPickup::*)(Int32, Object &) >(_SC("Destroy"), &CPickup::Destroy)
/* Properties */
// Properties
.Prop(_SC("Model"), &CPickup::GetModel)
.Prop(_SC("World"), &CPickup::GetWorld, &CPickup::SetWorld)
.Prop(_SC("Alpha"), &CPickup::GetAlpha, &CPickup::SetAlpha)
@ -311,22 +386,21 @@ void Register_CPickup(HSQUIRRELVM vm)
.Prop(_SC("X"), &CPickup::GetPosX, &CPickup::SetPosX)
.Prop(_SC("Y"), &CPickup::GetPosY, &CPickup::SetPosY)
.Prop(_SC("Z"), &CPickup::GetPosZ, &CPickup::SetPosZ)
/* Functions */
// Functions
.Func(_SC("StreamedFor"), &CPickup::IsStreamedFor)
.Func(_SC("Refresh"), &CPickup::Refresh)
.Func(_SC("SetPos"), &CPickup::SetPositionEx)
.Func(_SC("SetPosition"), &CPickup::SetPositionEx)
// Static Overloads
.StaticOverload< Object & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool) >
(_SC("CreateEx"), &Pickup_CreateEx)
.StaticOverload< Object & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool, Int32, Object &) >
(_SC("CreateEx"), &Pickup_CreateEx)
.StaticOverload< Object & (*)(Int32, Int32, Int32, const Vector3 &, Int32, bool) >
(_SC("Create"), &Pickup_Create)
.StaticOverload< Object & (*)(Int32, Int32, Int32, const Vector3 &, Int32, bool, Int32, Object &) >
(_SC("Create"), &Pickup_Create)
);
RootTable(vm)
.Overload< Object & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool) >
(_SC("CreatePickupEx"), &CreatePickupEx)
.Overload< Object & (*)(Int32, Int32, Int32, Float32, Float32, Float32, Int32, bool, Int32, Object &) >
(_SC("CreatePickupEx"), &CreatePickupEx)
.Overload< Object & (*)(Int32, Int32, Int32, const Vector3 &, Int32, bool) >
(_SC("CreatePickup"), &CreatePickup)
.Overload< Object & (*)(Int32, Int32, Int32, const Vector3 &, Int32, bool, Int32, Object &) >
(_SC("CreatePickup"), &CreatePickup);
}
} // Namespace:: SqMod