mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 08:47:17 +01:00
Compare commits
8 Commits
131a3f6a62
...
8eb431ea8f
Author | SHA1 | Date | |
---|---|---|---|
|
8eb431ea8f | ||
|
7b7f974e42 | ||
|
0641de7920 | ||
|
e2e9d2c83f | ||
|
47519cb3f4 | ||
|
79b5641b9f | ||
|
2088a825e3 | ||
|
747586ecf3 |
@ -181,6 +181,7 @@ Core::Core() noexcept
|
||||
, m_LockUnloadSignal(false)
|
||||
, m_EmptyInit(false)
|
||||
, m_Verbosity(1)
|
||||
, m_ClientData()
|
||||
, m_NullBlip()
|
||||
, m_NullCheckpoint()
|
||||
, m_NullKeyBind()
|
||||
@ -560,6 +561,8 @@ void Core::Terminate(bool shutdown)
|
||||
NullObject().Release();
|
||||
NullLightObj().Release();
|
||||
NullFunction().Release();
|
||||
// Release client data buffer, if any
|
||||
m_ClientData.Release();
|
||||
// Release null entity instances
|
||||
m_NullBlip.Release();
|
||||
m_NullCheckpoint.Release();
|
||||
@ -2846,6 +2849,12 @@ static bool SqDelVehicle(int32_t id, int32_t header, LightObj & payload)
|
||||
return Core::Get().DelVehicle(id, header, payload);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static LightObj & SqGetClientDataBuffer()
|
||||
{
|
||||
return Core::Get().GetClientDataBuffer();
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Core(HSQUIRRELVM vm)
|
||||
{
|
||||
@ -2894,6 +2903,7 @@ void Register_Core(HSQUIRRELVM vm)
|
||||
.Func(_SC("DestroyObject"), &SqDelObject)
|
||||
.Func(_SC("DestroyPickup"), &SqDelPickup)
|
||||
.Func(_SC("DestroyVehicle"), &SqDelVehicle)
|
||||
.Func(_SC("ClientDataBuffer"), &SqGetClientDataBuffer)
|
||||
.Func(_SC("OnPreLoad"), &SqGetPreLoadEvent)
|
||||
.Func(_SC("OnPostLoad"), &SqGetPostLoadEvent)
|
||||
.Func(_SC("OnUnload"), &SqGetUnloadEvent)
|
||||
|
@ -104,6 +104,9 @@ private:
|
||||
// --------------------------------------------------------------------------------------------
|
||||
int32_t m_Verbosity; // Restrict the amount of outputted information.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
LightObj m_ClientData; // Currently processed client data buffer.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
LightObj m_NullBlip; // Null Blips instance.
|
||||
LightObj m_NullCheckpoint; // Null Checkpoints instance.
|
||||
@ -383,6 +386,14 @@ public:
|
||||
return (!m_IncomingNameBuffer) ? _SC("") : m_IncomingNameBuffer;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the current client data buffer, if any.
|
||||
*/
|
||||
SQMOD_NODISCARD LightObj & GetClientDataBuffer()
|
||||
{
|
||||
return m_ClientData;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieves a line of code from a certain source.
|
||||
*/
|
||||
|
@ -2213,18 +2213,25 @@ void Core::EmitClientScriptData(int32_t player_id, const uint8_t * data, size_t
|
||||
{
|
||||
SQMOD_CO_EV_TRACEBACK("[TRACE<] Core::ClientScriptData(%d, [byte stream], %" PRINT_SZ_FMT ")", player_id, size)
|
||||
PlayerInst & _player = m_Players.at(static_cast< size_t >(player_id));
|
||||
#ifndef VCMP_ENABLE_OFFICIAL
|
||||
// Don't even bother if there's no one listening
|
||||
if (!(_player.mOnClientScriptData.first->IsEmpty()) || !(mOnClientScriptData.first->IsEmpty()))
|
||||
{
|
||||
#endif
|
||||
// Allocate a buffer with the received size
|
||||
Buffer b(static_cast< Buffer::SzType >(size));
|
||||
// Replicate the data to the allocated buffer
|
||||
b.Write(0, reinterpret_cast< Buffer::ConstPtr >(data), static_cast< Buffer::SzType >(size));
|
||||
// Prepare an object for the obtained buffer
|
||||
LightObj o(SqTypeIdentity< SqBuffer >{}, m_VM, std::move(b));
|
||||
m_ClientData = LightObj(SqTypeIdentity< SqBuffer >{}, m_VM, std::move(b));
|
||||
#ifdef VCMP_ENABLE_OFFICIAL
|
||||
// Don't even bother if there's no one listening
|
||||
if (!(_player.mOnClientScriptData.first->IsEmpty()) || !(mOnClientScriptData.first->IsEmpty()))
|
||||
{
|
||||
#endif
|
||||
// Forward the event call
|
||||
(*_player.mOnClientScriptData.first)(o, size);
|
||||
(*mOnClientScriptData.first)(_player.mObj, o, size);
|
||||
(*_player.mOnClientScriptData.first)(m_ClientData, size);
|
||||
(*mOnClientScriptData.first)(_player.mObj, m_ClientData, size);
|
||||
}
|
||||
SQMOD_CO_EV_TRACEBACK("[TRACE>] Core::ClientScriptData")
|
||||
#ifdef VCMP_ENABLE_OFFICIAL
|
||||
@ -2234,6 +2241,8 @@ void Core::EmitClientScriptData(int32_t player_id, const uint8_t * data, size_t
|
||||
ExecuteLegacyEvent(m_VM, _SC("onClientScriptData"), _player.mLgObj);
|
||||
}
|
||||
#endif
|
||||
// Discard the buffer instance, if any
|
||||
m_ClientData.Release();
|
||||
}
|
||||
|
||||
#undef NULL_SQOBJ_ // don't need this anymore
|
||||
|
@ -18,6 +18,7 @@ Routine::Time Routine::s_Last = 0;
|
||||
Routine::Time Routine::s_Prev = 0;
|
||||
Routine::Interval Routine::s_Intervals[SQMOD_MAX_ROUTINES];
|
||||
Routine::Instance Routine::s_Instances[SQMOD_MAX_ROUTINES];
|
||||
SQInteger Routine::s_Current = SQMOD_MAX_ROUTINES;
|
||||
bool Routine::s_Silenced = false;
|
||||
bool Routine::s_Persistent = false;
|
||||
|
||||
@ -48,11 +49,14 @@ void Routine::Process()
|
||||
// Have we completed the routine interval?
|
||||
if ((*itr) <= 0)
|
||||
{
|
||||
s_Current = static_cast< SQInteger >(itr - s_Intervals);
|
||||
// Execute and reset the elapsed time
|
||||
(*itr) = s_Instances[itr - s_Intervals].Execute();
|
||||
(*itr) = s_Instances[s_Current].Execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Clear currently executed routine
|
||||
s_Current = SQMOD_MAX_ROUTINES;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -535,6 +539,7 @@ void Register_Routine(HSQUIRRELVM vm)
|
||||
.Prop(_SC("Env"), &Routine::GetEnv, &Routine::SetEnv)
|
||||
.Prop(_SC("Func"), &Routine::GetFunc, &Routine::SetFunc)
|
||||
.Prop(_SC("Data"), &Routine::GetData, &Routine::SetData)
|
||||
.Prop(_SC("Result"), &Routine::GetResult, &Routine::SetResult)
|
||||
.Prop(_SC("Interval"), &Routine::GetInterval, &Routine::SetInterval)
|
||||
.Prop(_SC("Iterations"), &Routine::GetIterations, &Routine::SetIterations)
|
||||
.Prop(_SC("Suspended"), &Routine::GetSuspended, &Routine::SetSuspended)
|
||||
@ -543,6 +548,7 @@ void Register_Routine(HSQUIRRELVM vm)
|
||||
.Prop(_SC("Endure"), &Routine::GetEndure, &Routine::SetEndure)
|
||||
.Prop(_SC("Inactive"), &Routine::GetInactive)
|
||||
.Prop(_SC("Persistent"), &Routine::GetPersistent, &Routine::SetPersistent)
|
||||
.Prop(_SC("Yields"), &Routine::GetYields, &Routine::SetYields)
|
||||
.Prop(_SC("Terminated"), &Routine::GetTerminated)
|
||||
.Prop(_SC("Arguments"), &Routine::GetArguments)
|
||||
// Member Methods
|
||||
@ -554,10 +560,12 @@ void Register_Routine(HSQUIRRELVM vm)
|
||||
.Func(_SC("SetQuiet"), &Routine::ApplyQuiet)
|
||||
.Func(_SC("SetEndure"), &Routine::ApplyEndure)
|
||||
.Func(_SC("SetPersistent"), &Routine::ApplyPersistent)
|
||||
.Func(_SC("SetYields"), &Routine::ApplyYields)
|
||||
.Func(_SC("Terminate"), &Routine::Terminate)
|
||||
.Func(_SC("GetArgument"), &Routine::GetArgument)
|
||||
.Func(_SC("DropEnv"), &Routine::DropEnv)
|
||||
.Func(_SC("Restart"), &Routine::Restart)
|
||||
.StaticFunc(_SC("Current"), &Routine::GetCurrent)
|
||||
.StaticFunc(_SC("UsedCount"), &Routine::GetUsed)
|
||||
.StaticFunc(_SC("AreSilenced"), &Routine::GetSilenced)
|
||||
.StaticFunc(_SC("SetSilenced"), &Routine::SetSilenced)
|
||||
|
@ -37,6 +37,7 @@ private:
|
||||
LightObj mFunc{}; // A reference to the managed function object.
|
||||
LightObj mInst{}; // Reference to the routine associated with this instance.
|
||||
LightObj mData{}; // A reference to the arbitrary data associated with this instance.
|
||||
LightObj mResult{}; // A reference to the value returned by the callback on last invocation.
|
||||
String mTag{}; // An arbitrary string which represents the tag.
|
||||
Iterator mIterations{0}; // Number of iterations before self destruct.
|
||||
Interval mInterval{0}; // Interval between routine invocations.
|
||||
@ -46,6 +47,7 @@ private:
|
||||
bool mEndure{false}; // Whether this instance is allowed to terminate itself on errors.
|
||||
bool mInactive{true}; // Whether this instance has finished all iterations.
|
||||
bool mPersistent{false}; // Whether this instance should not reset when finished.
|
||||
bool mYields{false}; // Whether this instance may yield a value when callback is invoked.
|
||||
uint8_t mArgc{0}; // The number of arguments that the routine must forward.
|
||||
Argument mArgv[14]{}; // The arguments that the routine must forward.
|
||||
|
||||
@ -57,6 +59,7 @@ private:
|
||||
, mFunc()
|
||||
, mInst()
|
||||
, mData()
|
||||
, mResult()
|
||||
, mTag()
|
||||
, mIterations(0)
|
||||
, mInterval(0)
|
||||
@ -66,6 +69,7 @@ private:
|
||||
, mEndure(false)
|
||||
, mInactive(true)
|
||||
, mPersistent(GetPersistency())
|
||||
, mYields(false)
|
||||
, mArgc(0)
|
||||
, mArgv()
|
||||
{
|
||||
@ -128,6 +132,7 @@ private:
|
||||
mFunc.Release();
|
||||
mInst.Release();
|
||||
mData.Release();
|
||||
mResult.Release();
|
||||
mIterations = 0;
|
||||
mInterval = 0;
|
||||
mInactive = true;
|
||||
@ -168,9 +173,30 @@ private:
|
||||
// This routine is currently executing
|
||||
mExecuting = true;
|
||||
// Make the function call and store the result
|
||||
const SQRESULT res = sq_call(vm, mArgc + 1, static_cast< SQBool >(false), static_cast< SQBool >(!mQuiet));
|
||||
const SQRESULT res = sq_call(vm, mArgc + 1, static_cast< SQBool >(mYields), static_cast< SQBool >(!mQuiet));
|
||||
// This routine has finished executing
|
||||
mExecuting = false;
|
||||
// Should we look for a yielded value?
|
||||
if (mYields)
|
||||
{
|
||||
// Release previous value, if any
|
||||
if (!sq_isnull(mResult.mObj))
|
||||
{
|
||||
sq_release(vm, &(mResult.mObj));
|
||||
}
|
||||
// Attempt to retrieve the new value if possible
|
||||
if (SQ_SUCCEEDED(res) && SQ_SUCCEEDED(sq_getstackobj(vm, -1, &(mResult.mObj))))
|
||||
{
|
||||
sq_addref(vm, &(mResult.mObj)); // Don't destroy once popped
|
||||
}
|
||||
else
|
||||
{
|
||||
sq_resetobject(&(mResult.mObj)); // Discard anything so far
|
||||
}
|
||||
// Pop the returned value from the stack
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
|
||||
// Pop the callback object from the stack
|
||||
sq_pop(vm, 1);
|
||||
// Validate the result
|
||||
@ -242,6 +268,7 @@ private:
|
||||
static Time s_Prev; // Previous time point.
|
||||
static Interval s_Intervals[SQMOD_MAX_ROUTINES]; // List of intervals to be processed.
|
||||
static Instance s_Instances[SQMOD_MAX_ROUTINES]; // List of routines to be executed.
|
||||
static SQInteger s_Current; // Currently executed routine index (SQMOD_MAX_ROUTINES if none).
|
||||
static bool s_Silenced; // Error reporting independent from global setting.
|
||||
static bool s_Persistent; // Whether all routines should be persistent by default.
|
||||
|
||||
@ -562,6 +589,22 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the value that the callback has yielded last invocation.
|
||||
*/
|
||||
SQMOD_NODISCARD const LightObj & GetResult() const
|
||||
{
|
||||
return GetValid().mResult;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the value that the callback has yielded last invocation.
|
||||
*/
|
||||
void SetResult(const LightObj & value)
|
||||
{
|
||||
GetValid().mResult = value;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the execution interval.
|
||||
*/
|
||||
@ -728,6 +771,31 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the routine is yielding a value.
|
||||
*/
|
||||
SQMOD_NODISCARD bool GetYields() const
|
||||
{
|
||||
return GetValid().mYields;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set whether the routine should be yielding values.
|
||||
*/
|
||||
void SetYields(bool toggle)
|
||||
{
|
||||
GetValid().mYields = toggle;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set whether the routine should be yielding values.
|
||||
*/
|
||||
Routine & ApplyYields(bool toggle)
|
||||
{
|
||||
SetYields(toggle);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See whether the routine was terminated.
|
||||
*/
|
||||
@ -791,6 +859,14 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the currently executed routine, if any.
|
||||
*/
|
||||
static LightObj & GetCurrent()
|
||||
{
|
||||
return (s_Current != SQMOD_MAX_ROUTINES) ? s_Instances[s_Current].mInst : NullLightObj();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See if error reporting is enabled for all newly created routines.
|
||||
*/
|
||||
|
@ -817,7 +817,7 @@ void CPlayer::SetArmor(float amount) const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
int32_t CPlayer::GetImmunity() const
|
||||
uint32_t CPlayer::GetImmunity() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
@ -826,12 +826,12 @@ int32_t CPlayer::GetImmunity() const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CPlayer::SetImmunity(int32_t flags)
|
||||
void CPlayer::SetImmunity(uint32_t flags)
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Grab the current value for this property
|
||||
const int32_t current = _Func->GetPlayerImmunityFlags(m_ID);
|
||||
const uint32_t current = _Func->GetPlayerImmunityFlags(m_ID);
|
||||
// Avoid property unwind from a recursive call
|
||||
_Func->SetPlayerImmunityFlags(m_ID, static_cast< uint32_t >(flags));
|
||||
// Avoid infinite recursive event loops
|
||||
@ -840,7 +840,7 @@ void CPlayer::SetImmunity(int32_t flags)
|
||||
// Prevent this event from triggering while executed
|
||||
BitGuardU32 bg(m_CircularLocks, PLAYERCL_EMIT_PLAYER_IMMUNITY);
|
||||
// Now forward the event call
|
||||
Core::Get().EmitPlayerImmunity(m_ID, current, flags);
|
||||
Core::Get().EmitPlayerImmunity(m_ID, static_cast< int32_t >(current), static_cast< int32_t >(flags));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1035,7 +1035,7 @@ int32_t CPlayer::GetAction() const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
int32_t CPlayer::GetGameKeys() const
|
||||
uint32_t CPlayer::GetGameKeys() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
@ -1845,7 +1845,7 @@ void CPlayer::StartStreamEx(uint32_t size)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
int32_t CPlayer::GetBufferCursor() const
|
||||
uint32_t CPlayer::GetBufferCursor() const
|
||||
{
|
||||
return m_Buffer.Position();
|
||||
}
|
||||
|
@ -488,12 +488,12 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the immunity flags of the managed player entity.
|
||||
*/
|
||||
SQMOD_NODISCARD int32_t GetImmunity() const;
|
||||
SQMOD_NODISCARD uint32_t GetImmunity() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the immunity flags of the managed player entity.
|
||||
*/
|
||||
void SetImmunity(int32_t flags);
|
||||
void SetImmunity(uint32_t flags);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position of the managed player entity.
|
||||
@ -588,7 +588,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the game keys of the managed player entity.
|
||||
*/
|
||||
SQMOD_NODISCARD int32_t GetGameKeys() const;
|
||||
SQMOD_NODISCARD uint32_t GetGameKeys() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Embark the managed player entity into the specified vehicle entity.
|
||||
@ -959,7 +959,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the current cursor position of the stream buffer.
|
||||
*/
|
||||
SQMOD_NODISCARD int32_t GetBufferCursor() const;
|
||||
SQMOD_NODISCARD uint32_t GetBufferCursor() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the current cursor position of the stream buffer.
|
||||
|
@ -306,7 +306,7 @@ void CVehicle::Respawn() const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
int32_t CVehicle::GetImmunity() const
|
||||
uint32_t CVehicle::GetImmunity() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
@ -315,12 +315,12 @@ int32_t CVehicle::GetImmunity() const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CVehicle::SetImmunity(int32_t flags)
|
||||
void CVehicle::SetImmunity(uint32_t flags)
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Grab the current value for this property
|
||||
const int32_t current = _Func->GetVehicleImmunityFlags(m_ID);
|
||||
const uint32_t current = _Func->GetVehicleImmunityFlags(m_ID);
|
||||
// Avoid property unwind from a recursive call
|
||||
_Func->SetVehicleImmunityFlags(m_ID, static_cast< uint32_t >(flags));
|
||||
// Avoid infinite recursive event loops
|
||||
@ -329,7 +329,7 @@ void CVehicle::SetImmunity(int32_t flags)
|
||||
// Prevent this event from triggering while executed
|
||||
BitGuardU32 bg(m_CircularLocks, VEHICLECL_EMIT_VEHICLE_IMMUNITY);
|
||||
// Now forward the event call
|
||||
Core::Get().EmitVehicleImmunity(m_ID, current, flags);
|
||||
Core::Get().EmitVehicleImmunity(m_ID, static_cast< int32_t >(current), static_cast< int32_t >(flags));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1130,7 +1130,7 @@ void CVehicle::ResetHandlings() const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
int32_t CVehicle::GetLightsData() const
|
||||
uint32_t CVehicle::GetLightsData() const
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
|
@ -250,12 +250,12 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the immunity flags of the managed vehicle entity.
|
||||
*/
|
||||
SQMOD_NODISCARD int32_t GetImmunity() const;
|
||||
SQMOD_NODISCARD uint32_t GetImmunity() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the immunity flags of the managed vehicle entity.
|
||||
*/
|
||||
void SetImmunity(int32_t flags);
|
||||
void SetImmunity(uint32_t flags);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explode the managed vehicle entity.
|
||||
@ -605,7 +605,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the lights data for the managed vehicle entity.
|
||||
*/
|
||||
SQMOD_NODISCARD int32_t GetLightsData() const;
|
||||
SQMOD_NODISCARD uint32_t GetLightsData() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the lights data for the managed vehicle entity.
|
||||
|
@ -622,9 +622,9 @@ void Logger::DebugFv(HSQUIRRELVM vm, const char * fmt, va_list args)
|
||||
using namespace Sqrat;
|
||||
// We want to make sure these messages appear in succession
|
||||
// So we will push them in bulk after generating them
|
||||
std::array< MsgPtr, 3 > messages{};
|
||||
std::array< MsgPtr, 3 > messages{nullptr, nullptr, nullptr};
|
||||
// Create a new message builder
|
||||
MsgPtr message(new Message(LOGL_ERR, true));
|
||||
MsgPtr message = std::make_unique< Message >(LOGL_ERR, true);
|
||||
// Used to acquire stack information
|
||||
SQStackInfos si;
|
||||
// Write the given error message
|
||||
@ -697,7 +697,7 @@ void Logger::DebugFv(HSQUIRRELVM vm, const char * fmt, va_list args)
|
||||
// Begin the local variables information
|
||||
message->Append("Locals:\n[\n");
|
||||
// Indentation string
|
||||
std::string indent;
|
||||
std::string indent{};
|
||||
// Whether current level includes trace
|
||||
bool traced = false;
|
||||
// Process each stack level
|
||||
@ -726,74 +726,74 @@ void Logger::DebugFv(HSQUIRRELVM vm, const char * fmt, va_list args)
|
||||
// Identify type
|
||||
switch(sq_gettype(vm, -1))
|
||||
{
|
||||
case OT_NULL:
|
||||
case OT_NULL: {
|
||||
message->AppendF("%s|- %-10s[%s]\n", indent.c_str(), "NULL", name);
|
||||
break;
|
||||
case OT_INTEGER:
|
||||
} break;
|
||||
case OT_INTEGER: {
|
||||
sq_getinteger(vm, -1, &i_);
|
||||
message->AppendF("%s|- %-10s[%s] with value: %" PRINT_INT_FMT "\n", indent.c_str(), "INTEGER", name, i_);
|
||||
break;
|
||||
case OT_FLOAT:
|
||||
} break;
|
||||
case OT_FLOAT: {
|
||||
sq_getfloat(vm, -1, &f_);
|
||||
message->AppendF("%s|- %-10s[%s] with value: %f\n", indent.c_str(), "FLOAT", name, f_);
|
||||
break;
|
||||
case OT_USERPOINTER:
|
||||
} break;
|
||||
case OT_USERPOINTER: {
|
||||
sq_getuserpointer(vm, -1, &p_);
|
||||
message->AppendF("%s|- %-10s[%s] pointing at: %p\n", indent.c_str(), "POINTER", name, p_);
|
||||
break;
|
||||
case OT_STRING:
|
||||
} break;
|
||||
case OT_STRING: {
|
||||
sq_getstringandsize(vm, -1, &s_, &i_);
|
||||
if (i_ > 0) {
|
||||
message->AppendF("%s|- %-10s[%s] of %" PRINT_INT_FMT " characters: %.*s\n", indent.c_str(), "STRING", name, i_, m_StringTruncate, s_);
|
||||
} else {
|
||||
message->AppendF("%s|- %-10s[%s] empty\n", indent.c_str(), "STRING", level, name);
|
||||
}
|
||||
break;
|
||||
case OT_TABLE:
|
||||
} break;
|
||||
case OT_TABLE: {
|
||||
i_ = sq_getsize(vm, -1);
|
||||
message->AppendF("%s|- %-10s[%s] with %" PRINT_INT_FMT " elements\n", indent.c_str(), "TABLE", name, i_);
|
||||
break;
|
||||
case OT_ARRAY:
|
||||
} break;
|
||||
case OT_ARRAY: {
|
||||
i_ = sq_getsize(vm, -1);
|
||||
message->AppendF("%s|- %-10s[%s] with %" PRINT_INT_FMT " elements\n", indent.c_str(), "ARRAY", name, i_);
|
||||
break;
|
||||
case OT_CLOSURE:
|
||||
} break;
|
||||
case OT_CLOSURE: {
|
||||
s_ = _SC("@anonymous");
|
||||
if (SQ_SUCCEEDED(sq_getclosurename(vm, -1))) {
|
||||
if (sq_gettype(vm, -1) != OT_NULL && SQ_SUCCEEDED(ssf_.Release(vm).Proc())) {
|
||||
if (sq_gettype(vm, -1) != OT_NULL && SQ_SUCCEEDED(ssf_.Release(vm).Proc(false))) {
|
||||
s_ = ssf_.mPtr;
|
||||
}
|
||||
sq_poptop(vm);
|
||||
}
|
||||
message->AppendF("%s|- %-10s[%s] with name: %s\n", indent.c_str(), "CLOSURE", name, s_);
|
||||
break;
|
||||
case OT_NATIVECLOSURE:
|
||||
} break;
|
||||
case OT_NATIVECLOSURE: {
|
||||
s_ = _SC("@unknown");
|
||||
if (SQ_SUCCEEDED(sq_getclosurename(vm, -1))) {
|
||||
if (sq_gettype(vm, -1) != OT_NULL && SQ_SUCCEEDED(ssf_.Release(vm).Proc())) {
|
||||
if (sq_gettype(vm, -1) != OT_NULL && SQ_SUCCEEDED(ssf_.Release(vm).Proc(false))) {
|
||||
s_ = ssf_.mPtr;
|
||||
}
|
||||
sq_poptop(vm);
|
||||
}
|
||||
message->AppendF("%s|- %-10s[%s] with name: %s\n", indent.c_str(), "NCLOSURE", name, s_);
|
||||
break;
|
||||
case OT_GENERATOR:
|
||||
} break;
|
||||
case OT_GENERATOR: {
|
||||
message->AppendF("%s|- %-10s[%s]\n", indent.c_str(), "GENERATOR", name);
|
||||
break;
|
||||
case OT_USERDATA:
|
||||
} break;
|
||||
case OT_USERDATA: {
|
||||
message->AppendF("%s|- %-10s[%s]\n", indent.c_str(), "USERDATA", name);
|
||||
break;
|
||||
case OT_THREAD:
|
||||
} break;
|
||||
case OT_THREAD: {
|
||||
message->AppendF("%s|- %-10s[%s]\n", indent.c_str(), "THREAD", name);
|
||||
break;
|
||||
case OT_CLASS:
|
||||
} break;
|
||||
case OT_CLASS: {
|
||||
// Brute force our way into getting the name of this class without blowing up
|
||||
s_ = _SC("@unknown");
|
||||
// Create a dummy, non-constructed instance and hope `_typeof` doesn't rely on member variables
|
||||
if (SQ_SUCCEEDED(sq_createinstance(vm, -1))) {
|
||||
// Attempt a `_typeof` on that instance
|
||||
if (SQ_SUCCEEDED(sq_typeof(vm, -1))) {
|
||||
if (SQ_SUCCEEDED(ssf_.Release(vm).Proc())) {
|
||||
if (SQ_SUCCEEDED(ssf_.Release(vm).Proc(false))) {
|
||||
s_ = ssf_.mPtr;
|
||||
}
|
||||
// Pop the name object
|
||||
@ -803,24 +803,24 @@ void Logger::DebugFv(HSQUIRRELVM vm, const char * fmt, va_list args)
|
||||
sq_poptop(vm);
|
||||
}
|
||||
message->AppendF("%s|- %-10s[%s] of type: %s\n", indent.c_str(), "CLASS", name, s_);
|
||||
break;
|
||||
case OT_INSTANCE:
|
||||
} break;
|
||||
case OT_INSTANCE: {
|
||||
s_ = _SC("@unknown");
|
||||
if (SQ_SUCCEEDED(sq_typeof(vm, -1))) {
|
||||
if (SQ_SUCCEEDED(ssf_.Release(vm).Proc())) {
|
||||
if (SQ_SUCCEEDED(ssf_.Release(vm).Proc(false))) {
|
||||
s_ = ssf_.mPtr;
|
||||
}
|
||||
sq_poptop(vm);
|
||||
}
|
||||
message->AppendF("%s|- %-10s[%s] of type: %s\n", indent.c_str(), "INSTANCE", name, s_);
|
||||
break;
|
||||
case OT_WEAKREF:
|
||||
} break;
|
||||
case OT_WEAKREF: {
|
||||
s_ = _SC("@unknown");
|
||||
// Attempt to grab the value pointed by the weak reference
|
||||
if (SQ_SUCCEEDED(sq_getweakrefval(vm, -1))) {
|
||||
// Attempt a `_typeof` on that instance
|
||||
if (SQ_SUCCEEDED(sq_typeof(vm, -1))) {
|
||||
if (SQ_SUCCEEDED(ssf_.Release(vm).Proc())) {
|
||||
if (SQ_SUCCEEDED(ssf_.Release(vm).Proc(false))) {
|
||||
s_ = ssf_.mPtr;
|
||||
}
|
||||
// Pop the name object
|
||||
@ -830,14 +830,14 @@ void Logger::DebugFv(HSQUIRRELVM vm, const char * fmt, va_list args)
|
||||
sq_poptop(vm);
|
||||
}
|
||||
message->AppendF("%s|- %-10s[%s] of type: %s\n", indent.c_str(), "WEAKREF", name, s_);
|
||||
break;
|
||||
case OT_BOOL:
|
||||
} break;
|
||||
case OT_BOOL: {
|
||||
sq_getinteger(vm, -1, &i_);
|
||||
message->AppendF("%s|- %-10s[%s] with value: %s\n", indent.c_str(), "BOOL", name, i_ ? _SC("true") : _SC("false"));
|
||||
break;
|
||||
default:
|
||||
} break;
|
||||
default: {
|
||||
message->AppendF("%s|- %-10s[%s]\n", indent.c_str(), "UNKNOWN", name);
|
||||
break;
|
||||
} break;
|
||||
}
|
||||
sq_pop(vm, 1);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "Misc/Official.hpp"
|
||||
#include "Base/Vector2.hpp"
|
||||
#include "Core/Utility.hpp"
|
||||
#include "Library/IO/Buffer.hpp"
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Entity.hpp"
|
||||
#include "Core.hpp"
|
||||
@ -697,7 +698,7 @@ struct LgPlayer
|
||||
SQMOD_NODISCARD int GetPing() const { return Get().GetPing(); }
|
||||
SQMOD_NODISCARD float GetHealth() const { return Get().GetHealth(); }
|
||||
SQMOD_NODISCARD float GetArmour() const { return Get().GetArmor(); }
|
||||
SQMOD_NODISCARD int32_t GetImmunity() const { return Get().GetImmunity(); }
|
||||
SQMOD_NODISCARD uint32_t GetImmunity() const { return Get().GetImmunity(); }
|
||||
SQMOD_NODISCARD float GetHeading() const { return Get().GetHeading(); }
|
||||
SQMOD_NODISCARD LgVehicle * GetVehicle() const
|
||||
{ const int id = _Func->GetPlayerVehicleId(GetIdentifier()); return VALID_ENTITYEX(id, SQMOD_VEHICLE_POOL) ? Core::Get().GetVehicle(id).mLgInst : nullptr; }
|
||||
@ -718,7 +719,7 @@ struct LgPlayer
|
||||
SQMOD_NODISCARD bool Typing() const { return Get().IsTyping(); }
|
||||
SQMOD_NODISCARD bool ShowingMarkers() const { return _Func->GetPlayerOption(GetIdentifier(), vcmpPlayerOptionShowMarkers) >= 1; }
|
||||
SQMOD_NODISCARD bool GetCameraLocked() const { return Get().IsCameraLocked(); }
|
||||
SQMOD_NODISCARD int GetKey() const { return Get().GetKey(); }
|
||||
SQMOD_NODISCARD uint32_t GetKey() const { return Get().GetKey(); }
|
||||
SQMOD_NODISCARD bool GetAwayStatus() const { return Get().IsAway(); }
|
||||
SQMOD_NODISCARD LgPlayer * GetSpectateTarget() const
|
||||
{ const int id = _Func->GetPlayerSpectateTarget(GetIdentifier()); return VALID_ENTITYEX(id, SQMOD_PLAYER_POOL) ? Core::Get().GetPlayer(id).mLgInst : nullptr; }
|
||||
@ -733,7 +734,7 @@ struct LgPlayer
|
||||
SQMOD_NODISCARD bool GetPlayerOnFireStatus() const { return Get().IsBurning(); }
|
||||
SQMOD_NODISCARD bool GetPlayerCrouchStatus() const { return Get().IsCrouched(); }
|
||||
SQMOD_NODISCARD int GetPlayerAction() const { return Get().GetAction(); }
|
||||
SQMOD_NODISCARD int GetPlayerGameKeys() const { return Get().GetGameKeys(); }
|
||||
SQMOD_NODISCARD uint32_t GetPlayerGameKeys() const { return Get().GetGameKeys(); }
|
||||
SQMOD_NODISCARD LgVector GetPlayerAimPos() const { return LgVector(Get().GetAimPosition()); }
|
||||
SQMOD_NODISCARD LgVector GetPlayerAimDir() const { return LgVector(Get().GetAimDirection()); }
|
||||
SQMOD_NODISCARD int GetWantedLevel() const { return Get().GetWantedLevel(); }
|
||||
@ -825,9 +826,12 @@ struct LgVehicle
|
||||
}
|
||||
// --------------------------------------------------------------------------------------------
|
||||
SQMOD_NODISCARD static int32_t GetDriverID(int32_t id) {
|
||||
for(int i = 0, n = _Func->GetMaxPlayers(); i < n; ++i) {
|
||||
if(_Func->IsPlayerConnected(i)) {
|
||||
if(_Func->GetPlayerVehicleId(i) == id && _Func->GetPlayerInVehicleSlot(i) == 0) return i;
|
||||
for(uint32_t i = 0, n = _Func->GetMaxPlayers(); i < n; ++i) {
|
||||
if(_Func->IsPlayerConnected(static_cast< int32_t >(i))) {
|
||||
if(_Func->GetPlayerVehicleId(static_cast< int32_t >(i)) == id &&
|
||||
_Func->GetPlayerInVehicleSlot(static_cast< int32_t >(i)) == 0) {
|
||||
return static_cast< int32_t >(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
@ -845,7 +849,7 @@ struct LgVehicle
|
||||
void SetColour2(int colour2) const { Get().SetSecondaryColor(colour2); }
|
||||
void SetLocked(bool toggle) const { _Func->SetVehicleOption(GetIdentifier(), vcmpVehicleOptionDoorsLocked, static_cast< uint8_t >(toggle)); }
|
||||
void SetDamage(uint32_t damage) const { Get().SetDamageData(damage); }
|
||||
void SetLightFlags(uint32_t flags) const { Get().SetLightsData(flags); }
|
||||
void SetLightFlags(int32_t flags) const { Get().SetLightsData(flags); }
|
||||
void SetAlarm(bool toggle) const { _Func->SetVehicleOption(GetIdentifier(), vcmpVehicleOptionAlarm, static_cast< uint8_t >(toggle)); }
|
||||
void SetSiren(bool toggle) const { _Func->SetVehicleOption(GetIdentifier(), vcmpVehicleOptionSiren, static_cast< uint8_t >(toggle)); }
|
||||
void SetLights(bool toggle) const { _Func->SetVehicleOption(GetIdentifier(), vcmpVehicleOptionLights, static_cast< uint8_t >(toggle)); }
|
||||
@ -869,7 +873,7 @@ struct LgVehicle
|
||||
// --------------------------------------------------------------------------------------------
|
||||
SQMOD_NODISCARD int GetWorld() const { return Get().GetWorld(); }
|
||||
SQMOD_NODISCARD int GetModel() const { return Get().GetModel(); }
|
||||
SQMOD_NODISCARD int GetImmunity() const { return Get().GetImmunity(); }
|
||||
SQMOD_NODISCARD uint32_t GetImmunity() const { return Get().GetImmunity(); }
|
||||
SQMOD_NODISCARD LgEntityVector GetPosition() const
|
||||
{ return LgEntityVector(mID, LgEntityType::Vehicle, LgVehicleVectorFlag::Pos, Get().GetPosition()); }
|
||||
SQMOD_NODISCARD LgEntityVector GetSpawnPos() const
|
||||
@ -1259,7 +1263,7 @@ static void LgSetServerName(StackStrF & str) { _Func->SetServerName(str.mPtr); }
|
||||
static void LgSetMaxPlayers(int newMaxPlayers) { _Func->SetMaxPlayers(static_cast< uint32_t >(newMaxPlayers)); }
|
||||
static void LgSetServerPassword(StackStrF & str) { _Func->SetServerPassword(str.mPtr); }
|
||||
static void LgSetGameModeText(StackStrF & str) { _Func->SetGameModeText(str.mPtr); }
|
||||
static void LgSetTimeRate(uint32_t rate) { _Func->SetTimeRate(rate); }
|
||||
static void LgSetTimeRate(int32_t rate) { _Func->SetTimeRate(rate); }
|
||||
static void LgSetHour(int hour) { _Func->SetHour( hour ); }
|
||||
static void LgSetMinute(int minute) { _Func->SetMinute(minute); }
|
||||
static void LgSetTime(int hour, int minute) { LgSetHour(hour); LgSetMinute(minute); }
|
||||
@ -1290,7 +1294,7 @@ SQMOD_NODISCARD static SQInteger LgGetGameModeText(HSQUIRRELVM vm) {
|
||||
return 1;
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_NODISCARD static int LgGetMaxPlayers() { return _Func->GetMaxPlayers(); }
|
||||
SQMOD_NODISCARD static uint32_t LgGetMaxPlayers() { return _Func->GetMaxPlayers(); }
|
||||
SQMOD_NODISCARD static uint32_t LgGetTimeRate() { return static_cast< uint32_t >(_Func->GetTimeRate()); }
|
||||
SQMOD_NODISCARD static int LgGetHour() { return _Func->GetHour(); }
|
||||
SQMOD_NODISCARD static int LgGetMinute() { return _Func->GetMinute(); }
|
||||
@ -2245,7 +2249,7 @@ struct LgStream {
|
||||
length = static_cast< uint16_t >(MAX_SIZE - m_OutputStreamPosition);
|
||||
m_OutputStreamError = true;
|
||||
}
|
||||
uint16_t lengthBE = static_cast< uint16_t >(((length >> 8u) & 0xFFu) | ((length & 0xFFu) << 8u));
|
||||
auto lengthBE = static_cast< uint16_t >(((length >> 8u) & 0xFFu) | ((length & 0xFFu) << 8u));
|
||||
Write(&lengthBE, sizeof(lengthBE));
|
||||
Write(value.mPtr, length);
|
||||
}
|
||||
@ -2310,6 +2314,17 @@ struct LgStream {
|
||||
m_InputStreamPosition += length;
|
||||
return LightObj(m_Buffer, static_cast< SQInteger >(length));
|
||||
}
|
||||
// --------------------------------------------------------------------------------------------
|
||||
static LightObj CloneInputToBuffer() {
|
||||
return LightObj(SqTypeIdentity< SqBuffer >{}, SqVM(), Buffer(m_Buffer,
|
||||
static_cast< Buffer::SzType >(m_InputStreamSize),
|
||||
static_cast< Buffer::SzType >(m_InputStreamPosition)));
|
||||
}
|
||||
static LightObj CloneOutputToBuffer() {
|
||||
return LightObj(SqTypeIdentity< SqBuffer >{}, SqVM(), Buffer(m_Buffer,
|
||||
static_cast< Buffer::SzType >(m_OutputStreamEnd),
|
||||
static_cast< Buffer::SzType >(m_OutputStreamPosition)));
|
||||
}
|
||||
private:
|
||||
// --------------------------------------------------------------------------------------------
|
||||
static bool CanWrite(size_t size) { return (size <= (MAX_SIZE - m_OutputStreamPosition)); }
|
||||
@ -2344,15 +2359,15 @@ private:
|
||||
static SQChar m_Buffer[MAX_SIZE];
|
||||
};
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
uint8_t LgStream::m_InputStreamData[LgStream::MAX_SIZE];
|
||||
size_t LgStream::m_InputStreamSize;
|
||||
size_t LgStream::m_InputStreamPosition;
|
||||
bool LgStream::m_InputStreamError;
|
||||
uint8_t LgStream::m_InputStreamData[LgStream::MAX_SIZE]{};
|
||||
size_t LgStream::m_InputStreamSize{0};
|
||||
size_t LgStream::m_InputStreamPosition{0};
|
||||
bool LgStream::m_InputStreamError{false};
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
uint8_t LgStream::m_OutputStreamData[LgStream::MAX_SIZE];
|
||||
size_t LgStream::m_OutputStreamEnd;
|
||||
size_t LgStream::m_OutputStreamPosition;
|
||||
bool LgStream::m_OutputStreamError;
|
||||
uint8_t LgStream::m_OutputStreamData[LgStream::MAX_SIZE]{};
|
||||
size_t LgStream::m_OutputStreamEnd{0};
|
||||
size_t LgStream::m_OutputStreamPosition{0};
|
||||
bool LgStream::m_OutputStreamError{false};
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQChar LgStream::m_Buffer[LgStream::MAX_SIZE];
|
||||
|
||||
@ -2383,6 +2398,8 @@ void Register_Official_Stream(HSQUIRRELVM vm)
|
||||
.StaticFunc(_SC("ReadInt"), &LgStream::ReadInt)
|
||||
.StaticFunc(_SC("ReadFloat"), &LgStream::ReadFloat)
|
||||
.StaticFunc(_SC("ReadString"), &LgStream::ReadString)
|
||||
.StaticFunc(_SC("CloneInputToBuffer"), &LgStream::CloneInputToBuffer)
|
||||
.StaticFunc(_SC("CloneOutputToBuffer"), &LgStream::CloneOutputToBuffer)
|
||||
);
|
||||
}
|
||||
|
||||
|
6
vendor/SAJSON/sajson.cpp
vendored
6
vendor/SAJSON/sajson.cpp
vendored
@ -1,7 +1 @@
|
||||
#include <sajson.h>
|
||||
|
||||
namespace sajson {
|
||||
namespace internal {
|
||||
//template <> const uint8_t globals_struct<void>::parse_flags[256];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user