1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-01-19 03:57:14 +01:00

Compare commits

..

No commits in common. "8eb431ea8f9ecf6f36fec66180bf451b0e3d888d" and "131a3f6a62732c3410ececde5281ffdb47402255" have entirely different histories.

12 changed files with 101 additions and 226 deletions

View File

@ -181,7 +181,6 @@ Core::Core() noexcept
, m_LockUnloadSignal(false) , m_LockUnloadSignal(false)
, m_EmptyInit(false) , m_EmptyInit(false)
, m_Verbosity(1) , m_Verbosity(1)
, m_ClientData()
, m_NullBlip() , m_NullBlip()
, m_NullCheckpoint() , m_NullCheckpoint()
, m_NullKeyBind() , m_NullKeyBind()
@ -561,8 +560,6 @@ void Core::Terminate(bool shutdown)
NullObject().Release(); NullObject().Release();
NullLightObj().Release(); NullLightObj().Release();
NullFunction().Release(); NullFunction().Release();
// Release client data buffer, if any
m_ClientData.Release();
// Release null entity instances // Release null entity instances
m_NullBlip.Release(); m_NullBlip.Release();
m_NullCheckpoint.Release(); m_NullCheckpoint.Release();
@ -2849,12 +2846,6 @@ static bool SqDelVehicle(int32_t id, int32_t header, LightObj & payload)
return Core::Get().DelVehicle(id, header, payload); return Core::Get().DelVehicle(id, header, payload);
} }
// ------------------------------------------------------------------------------------------------
static LightObj & SqGetClientDataBuffer()
{
return Core::Get().GetClientDataBuffer();
}
// ================================================================================================ // ================================================================================================
void Register_Core(HSQUIRRELVM vm) void Register_Core(HSQUIRRELVM vm)
{ {
@ -2903,7 +2894,6 @@ void Register_Core(HSQUIRRELVM vm)
.Func(_SC("DestroyObject"), &SqDelObject) .Func(_SC("DestroyObject"), &SqDelObject)
.Func(_SC("DestroyPickup"), &SqDelPickup) .Func(_SC("DestroyPickup"), &SqDelPickup)
.Func(_SC("DestroyVehicle"), &SqDelVehicle) .Func(_SC("DestroyVehicle"), &SqDelVehicle)
.Func(_SC("ClientDataBuffer"), &SqGetClientDataBuffer)
.Func(_SC("OnPreLoad"), &SqGetPreLoadEvent) .Func(_SC("OnPreLoad"), &SqGetPreLoadEvent)
.Func(_SC("OnPostLoad"), &SqGetPostLoadEvent) .Func(_SC("OnPostLoad"), &SqGetPostLoadEvent)
.Func(_SC("OnUnload"), &SqGetUnloadEvent) .Func(_SC("OnUnload"), &SqGetUnloadEvent)

View File

@ -104,9 +104,6 @@ private:
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
int32_t m_Verbosity; // Restrict the amount of outputted information. 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_NullBlip; // Null Blips instance.
LightObj m_NullCheckpoint; // Null Checkpoints instance. LightObj m_NullCheckpoint; // Null Checkpoints instance.
@ -386,14 +383,6 @@ public:
return (!m_IncomingNameBuffer) ? _SC("") : m_IncomingNameBuffer; 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. * Retrieves a line of code from a certain source.
*/ */

View File

@ -2213,25 +2213,18 @@ 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) 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)); 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 // Don't even bother if there's no one listening
if (!(_player.mOnClientScriptData.first->IsEmpty()) || !(mOnClientScriptData.first->IsEmpty())) if (!(_player.mOnClientScriptData.first->IsEmpty()) || !(mOnClientScriptData.first->IsEmpty()))
{ {
#endif
// Allocate a buffer with the received size // Allocate a buffer with the received size
Buffer b(static_cast< Buffer::SzType >(size)); Buffer b(static_cast< Buffer::SzType >(size));
// Replicate the data to the allocated buffer // Replicate the data to the allocated buffer
b.Write(0, reinterpret_cast< Buffer::ConstPtr >(data), static_cast< Buffer::SzType >(size)); b.Write(0, reinterpret_cast< Buffer::ConstPtr >(data), static_cast< Buffer::SzType >(size));
// Prepare an object for the obtained buffer // Prepare an object for the obtained buffer
m_ClientData = LightObj(SqTypeIdentity< SqBuffer >{}, m_VM, std::move(b)); LightObj o(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 // Forward the event call
(*_player.mOnClientScriptData.first)(m_ClientData, size); (*_player.mOnClientScriptData.first)(o, size);
(*mOnClientScriptData.first)(_player.mObj, m_ClientData, size); (*mOnClientScriptData.first)(_player.mObj, o, size);
} }
SQMOD_CO_EV_TRACEBACK("[TRACE>] Core::ClientScriptData") SQMOD_CO_EV_TRACEBACK("[TRACE>] Core::ClientScriptData")
#ifdef VCMP_ENABLE_OFFICIAL #ifdef VCMP_ENABLE_OFFICIAL
@ -2241,8 +2234,6 @@ void Core::EmitClientScriptData(int32_t player_id, const uint8_t * data, size_t
ExecuteLegacyEvent(m_VM, _SC("onClientScriptData"), _player.mLgObj); ExecuteLegacyEvent(m_VM, _SC("onClientScriptData"), _player.mLgObj);
} }
#endif #endif
// Discard the buffer instance, if any
m_ClientData.Release();
} }
#undef NULL_SQOBJ_ // don't need this anymore #undef NULL_SQOBJ_ // don't need this anymore

View File

@ -18,7 +18,6 @@ Routine::Time Routine::s_Last = 0;
Routine::Time Routine::s_Prev = 0; Routine::Time Routine::s_Prev = 0;
Routine::Interval Routine::s_Intervals[SQMOD_MAX_ROUTINES]; Routine::Interval Routine::s_Intervals[SQMOD_MAX_ROUTINES];
Routine::Instance Routine::s_Instances[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_Silenced = false;
bool Routine::s_Persistent = false; bool Routine::s_Persistent = false;
@ -49,14 +48,11 @@ void Routine::Process()
// Have we completed the routine interval? // Have we completed the routine interval?
if ((*itr) <= 0) if ((*itr) <= 0)
{ {
s_Current = static_cast< SQInteger >(itr - s_Intervals);
// Execute and reset the elapsed time // Execute and reset the elapsed time
(*itr) = s_Instances[s_Current].Execute(); (*itr) = s_Instances[itr - s_Intervals].Execute();
} }
} }
} }
// Clear currently executed routine
s_Current = SQMOD_MAX_ROUTINES;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -539,7 +535,6 @@ void Register_Routine(HSQUIRRELVM vm)
.Prop(_SC("Env"), &Routine::GetEnv, &Routine::SetEnv) .Prop(_SC("Env"), &Routine::GetEnv, &Routine::SetEnv)
.Prop(_SC("Func"), &Routine::GetFunc, &Routine::SetFunc) .Prop(_SC("Func"), &Routine::GetFunc, &Routine::SetFunc)
.Prop(_SC("Data"), &Routine::GetData, &Routine::SetData) .Prop(_SC("Data"), &Routine::GetData, &Routine::SetData)
.Prop(_SC("Result"), &Routine::GetResult, &Routine::SetResult)
.Prop(_SC("Interval"), &Routine::GetInterval, &Routine::SetInterval) .Prop(_SC("Interval"), &Routine::GetInterval, &Routine::SetInterval)
.Prop(_SC("Iterations"), &Routine::GetIterations, &Routine::SetIterations) .Prop(_SC("Iterations"), &Routine::GetIterations, &Routine::SetIterations)
.Prop(_SC("Suspended"), &Routine::GetSuspended, &Routine::SetSuspended) .Prop(_SC("Suspended"), &Routine::GetSuspended, &Routine::SetSuspended)
@ -548,7 +543,6 @@ void Register_Routine(HSQUIRRELVM vm)
.Prop(_SC("Endure"), &Routine::GetEndure, &Routine::SetEndure) .Prop(_SC("Endure"), &Routine::GetEndure, &Routine::SetEndure)
.Prop(_SC("Inactive"), &Routine::GetInactive) .Prop(_SC("Inactive"), &Routine::GetInactive)
.Prop(_SC("Persistent"), &Routine::GetPersistent, &Routine::SetPersistent) .Prop(_SC("Persistent"), &Routine::GetPersistent, &Routine::SetPersistent)
.Prop(_SC("Yields"), &Routine::GetYields, &Routine::SetYields)
.Prop(_SC("Terminated"), &Routine::GetTerminated) .Prop(_SC("Terminated"), &Routine::GetTerminated)
.Prop(_SC("Arguments"), &Routine::GetArguments) .Prop(_SC("Arguments"), &Routine::GetArguments)
// Member Methods // Member Methods
@ -560,12 +554,10 @@ void Register_Routine(HSQUIRRELVM vm)
.Func(_SC("SetQuiet"), &Routine::ApplyQuiet) .Func(_SC("SetQuiet"), &Routine::ApplyQuiet)
.Func(_SC("SetEndure"), &Routine::ApplyEndure) .Func(_SC("SetEndure"), &Routine::ApplyEndure)
.Func(_SC("SetPersistent"), &Routine::ApplyPersistent) .Func(_SC("SetPersistent"), &Routine::ApplyPersistent)
.Func(_SC("SetYields"), &Routine::ApplyYields)
.Func(_SC("Terminate"), &Routine::Terminate) .Func(_SC("Terminate"), &Routine::Terminate)
.Func(_SC("GetArgument"), &Routine::GetArgument) .Func(_SC("GetArgument"), &Routine::GetArgument)
.Func(_SC("DropEnv"), &Routine::DropEnv) .Func(_SC("DropEnv"), &Routine::DropEnv)
.Func(_SC("Restart"), &Routine::Restart) .Func(_SC("Restart"), &Routine::Restart)
.StaticFunc(_SC("Current"), &Routine::GetCurrent)
.StaticFunc(_SC("UsedCount"), &Routine::GetUsed) .StaticFunc(_SC("UsedCount"), &Routine::GetUsed)
.StaticFunc(_SC("AreSilenced"), &Routine::GetSilenced) .StaticFunc(_SC("AreSilenced"), &Routine::GetSilenced)
.StaticFunc(_SC("SetSilenced"), &Routine::SetSilenced) .StaticFunc(_SC("SetSilenced"), &Routine::SetSilenced)

View File

@ -37,7 +37,6 @@ private:
LightObj mFunc{}; // A reference to the managed function object. LightObj mFunc{}; // A reference to the managed function object.
LightObj mInst{}; // Reference to the routine associated with this instance. LightObj mInst{}; // Reference to the routine associated with this instance.
LightObj mData{}; // A reference to the arbitrary data 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. String mTag{}; // An arbitrary string which represents the tag.
Iterator mIterations{0}; // Number of iterations before self destruct. Iterator mIterations{0}; // Number of iterations before self destruct.
Interval mInterval{0}; // Interval between routine invocations. Interval mInterval{0}; // Interval between routine invocations.
@ -47,7 +46,6 @@ private:
bool mEndure{false}; // Whether this instance is allowed to terminate itself on errors. bool mEndure{false}; // Whether this instance is allowed to terminate itself on errors.
bool mInactive{true}; // Whether this instance has finished all iterations. bool mInactive{true}; // Whether this instance has finished all iterations.
bool mPersistent{false}; // Whether this instance should not reset when finished. 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. uint8_t mArgc{0}; // The number of arguments that the routine must forward.
Argument mArgv[14]{}; // The arguments that the routine must forward. Argument mArgv[14]{}; // The arguments that the routine must forward.
@ -59,7 +57,6 @@ private:
, mFunc() , mFunc()
, mInst() , mInst()
, mData() , mData()
, mResult()
, mTag() , mTag()
, mIterations(0) , mIterations(0)
, mInterval(0) , mInterval(0)
@ -69,7 +66,6 @@ private:
, mEndure(false) , mEndure(false)
, mInactive(true) , mInactive(true)
, mPersistent(GetPersistency()) , mPersistent(GetPersistency())
, mYields(false)
, mArgc(0) , mArgc(0)
, mArgv() , mArgv()
{ {
@ -132,7 +128,6 @@ private:
mFunc.Release(); mFunc.Release();
mInst.Release(); mInst.Release();
mData.Release(); mData.Release();
mResult.Release();
mIterations = 0; mIterations = 0;
mInterval = 0; mInterval = 0;
mInactive = true; mInactive = true;
@ -173,30 +168,9 @@ private:
// This routine is currently executing // This routine is currently executing
mExecuting = true; mExecuting = true;
// Make the function call and store the result // Make the function call and store the result
const SQRESULT res = sq_call(vm, mArgc + 1, static_cast< SQBool >(mYields), static_cast< SQBool >(!mQuiet)); const SQRESULT res = sq_call(vm, mArgc + 1, static_cast< SQBool >(false), static_cast< SQBool >(!mQuiet));
// This routine has finished executing // This routine has finished executing
mExecuting = false; 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 // Pop the callback object from the stack
sq_pop(vm, 1); sq_pop(vm, 1);
// Validate the result // Validate the result
@ -268,7 +242,6 @@ private:
static Time s_Prev; // Previous time point. static Time s_Prev; // Previous time point.
static Interval s_Intervals[SQMOD_MAX_ROUTINES]; // List of intervals to be processed. 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 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_Silenced; // Error reporting independent from global setting.
static bool s_Persistent; // Whether all routines should be persistent by default. static bool s_Persistent; // Whether all routines should be persistent by default.
@ -589,22 +562,6 @@ public:
return *this; 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. * Retrieve the execution interval.
*/ */
@ -771,31 +728,6 @@ public:
return *this; 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. * See whether the routine was terminated.
*/ */
@ -859,14 +791,6 @@ public:
return *this; 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. * See if error reporting is enabled for all newly created routines.
*/ */

View File

@ -817,7 +817,7 @@ void CPlayer::SetArmor(float amount) const
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
uint32_t CPlayer::GetImmunity() const int32_t CPlayer::GetImmunity() const
{ {
// Validate the managed identifier // Validate the managed identifier
Validate(); Validate();
@ -826,12 +826,12 @@ uint32_t CPlayer::GetImmunity() const
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void CPlayer::SetImmunity(uint32_t flags) void CPlayer::SetImmunity(int32_t flags)
{ {
// Validate the managed identifier // Validate the managed identifier
Validate(); Validate();
// Grab the current value for this property // Grab the current value for this property
const uint32_t current = _Func->GetPlayerImmunityFlags(m_ID); const int32_t current = _Func->GetPlayerImmunityFlags(m_ID);
// Avoid property unwind from a recursive call // Avoid property unwind from a recursive call
_Func->SetPlayerImmunityFlags(m_ID, static_cast< uint32_t >(flags)); _Func->SetPlayerImmunityFlags(m_ID, static_cast< uint32_t >(flags));
// Avoid infinite recursive event loops // Avoid infinite recursive event loops
@ -840,7 +840,7 @@ void CPlayer::SetImmunity(uint32_t flags)
// Prevent this event from triggering while executed // Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, PLAYERCL_EMIT_PLAYER_IMMUNITY); BitGuardU32 bg(m_CircularLocks, PLAYERCL_EMIT_PLAYER_IMMUNITY);
// Now forward the event call // Now forward the event call
Core::Get().EmitPlayerImmunity(m_ID, static_cast< int32_t >(current), static_cast< int32_t >(flags)); Core::Get().EmitPlayerImmunity(m_ID, current, flags);
} }
} }
@ -1035,7 +1035,7 @@ int32_t CPlayer::GetAction() const
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
uint32_t CPlayer::GetGameKeys() const int32_t CPlayer::GetGameKeys() const
{ {
// Validate the managed identifier // Validate the managed identifier
Validate(); Validate();
@ -1845,7 +1845,7 @@ void CPlayer::StartStreamEx(uint32_t size)
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
uint32_t CPlayer::GetBufferCursor() const int32_t CPlayer::GetBufferCursor() const
{ {
return m_Buffer.Position(); return m_Buffer.Position();
} }

View File

@ -488,12 +488,12 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the immunity flags of the managed player entity. * Retrieve the immunity flags of the managed player entity.
*/ */
SQMOD_NODISCARD uint32_t GetImmunity() const; SQMOD_NODISCARD int32_t GetImmunity() const;
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify the immunity flags of the managed player entity. * Modify the immunity flags of the managed player entity.
*/ */
void SetImmunity(uint32_t flags); void SetImmunity(int32_t flags);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the position of the managed player entity. * Retrieve the position of the managed player entity.
@ -588,7 +588,7 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the game keys of the managed player entity. * Retrieve the game keys of the managed player entity.
*/ */
SQMOD_NODISCARD uint32_t GetGameKeys() const; SQMOD_NODISCARD int32_t GetGameKeys() const;
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Embark the managed player entity into the specified vehicle entity. * Embark the managed player entity into the specified vehicle entity.
@ -959,7 +959,7 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the current cursor position of the stream buffer. * Retrieve the current cursor position of the stream buffer.
*/ */
SQMOD_NODISCARD uint32_t GetBufferCursor() const; SQMOD_NODISCARD int32_t GetBufferCursor() const;
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the current cursor position of the stream buffer. * Retrieve the current cursor position of the stream buffer.

View File

@ -306,7 +306,7 @@ void CVehicle::Respawn() const
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
uint32_t CVehicle::GetImmunity() const int32_t CVehicle::GetImmunity() const
{ {
// Validate the managed identifier // Validate the managed identifier
Validate(); Validate();
@ -315,12 +315,12 @@ uint32_t CVehicle::GetImmunity() const
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void CVehicle::SetImmunity(uint32_t flags) void CVehicle::SetImmunity(int32_t flags)
{ {
// Validate the managed identifier // Validate the managed identifier
Validate(); Validate();
// Grab the current value for this property // Grab the current value for this property
const uint32_t current = _Func->GetVehicleImmunityFlags(m_ID); const int32_t current = _Func->GetVehicleImmunityFlags(m_ID);
// Avoid property unwind from a recursive call // Avoid property unwind from a recursive call
_Func->SetVehicleImmunityFlags(m_ID, static_cast< uint32_t >(flags)); _Func->SetVehicleImmunityFlags(m_ID, static_cast< uint32_t >(flags));
// Avoid infinite recursive event loops // Avoid infinite recursive event loops
@ -329,7 +329,7 @@ void CVehicle::SetImmunity(uint32_t flags)
// Prevent this event from triggering while executed // Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, VEHICLECL_EMIT_VEHICLE_IMMUNITY); BitGuardU32 bg(m_CircularLocks, VEHICLECL_EMIT_VEHICLE_IMMUNITY);
// Now forward the event call // Now forward the event call
Core::Get().EmitVehicleImmunity(m_ID, static_cast< int32_t >(current), static_cast< int32_t >(flags)); Core::Get().EmitVehicleImmunity(m_ID, current, flags);
} }
} }
@ -1130,7 +1130,7 @@ void CVehicle::ResetHandlings() const
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
uint32_t CVehicle::GetLightsData() const int32_t CVehicle::GetLightsData() const
{ {
// Validate the managed identifier // Validate the managed identifier
Validate(); Validate();

View File

@ -250,12 +250,12 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the immunity flags of the managed vehicle entity. * Retrieve the immunity flags of the managed vehicle entity.
*/ */
SQMOD_NODISCARD uint32_t GetImmunity() const; SQMOD_NODISCARD int32_t GetImmunity() const;
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify the immunity flags of the managed vehicle entity. * Modify the immunity flags of the managed vehicle entity.
*/ */
void SetImmunity(uint32_t flags); void SetImmunity(int32_t flags);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Explode the managed vehicle entity. * Explode the managed vehicle entity.
@ -605,7 +605,7 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the lights data for the managed vehicle entity. * Retrieve the lights data for the managed vehicle entity.
*/ */
SQMOD_NODISCARD uint32_t GetLightsData() const; SQMOD_NODISCARD int32_t GetLightsData() const;
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify the lights data for the managed vehicle entity. * Modify the lights data for the managed vehicle entity.

View File

@ -622,9 +622,9 @@ void Logger::DebugFv(HSQUIRRELVM vm, const char * fmt, va_list args)
using namespace Sqrat; using namespace Sqrat;
// We want to make sure these messages appear in succession // We want to make sure these messages appear in succession
// So we will push them in bulk after generating them // So we will push them in bulk after generating them
std::array< MsgPtr, 3 > messages{nullptr, nullptr, nullptr}; std::array< MsgPtr, 3 > messages{};
// Create a new message builder // Create a new message builder
MsgPtr message = std::make_unique< Message >(LOGL_ERR, true); MsgPtr message(new Message(LOGL_ERR, true));
// Used to acquire stack information // Used to acquire stack information
SQStackInfos si; SQStackInfos si;
// Write the given error message // Write the given error message
@ -663,7 +663,7 @@ void Logger::DebugFv(HSQUIRRELVM vm, const char * fmt, va_list args)
// Assign the error message // Assign the error message
messages[0] = std::move(message); messages[0] = std::move(message);
// Create a new message builder // Create a new message builder
message = std::make_unique< Message >(LOGL_INF, true); message = std::make_unique<Message>(LOGL_INF, true);
// Trace list (so it can be reused later in locals) // Trace list (so it can be reused later in locals)
std::vector< std::string > locations; std::vector< std::string > locations;
std::vector< std::string > closures; std::vector< std::string > closures;
@ -687,7 +687,7 @@ void Logger::DebugFv(HSQUIRRELVM vm, const char * fmt, va_list args)
// Assign the error message // Assign the error message
messages[1] = std::move(message); messages[1] = std::move(message);
// Create a new message builder // Create a new message builder
message = std::make_unique< Message >(LOGL_INF, true); message = std::make_unique<Message>(LOGL_INF, true);
// Temporary variables to retrieve stack information // Temporary variables to retrieve stack information
const SQChar * s_ = nullptr, * name; const SQChar * s_ = nullptr, * name;
SQInteger i_; SQInteger i_;
@ -697,7 +697,7 @@ void Logger::DebugFv(HSQUIRRELVM vm, const char * fmt, va_list args)
// Begin the local variables information // Begin the local variables information
message->Append("Locals:\n[\n"); message->Append("Locals:\n[\n");
// Indentation string // Indentation string
std::string indent{}; std::string indent;
// Whether current level includes trace // Whether current level includes trace
bool traced = false; bool traced = false;
// Process each stack level // Process each stack level
@ -726,74 +726,74 @@ void Logger::DebugFv(HSQUIRRELVM vm, const char * fmt, va_list args)
// Identify type // Identify type
switch(sq_gettype(vm, -1)) switch(sq_gettype(vm, -1))
{ {
case OT_NULL: { case OT_NULL:
message->AppendF("%s|- %-10s[%s]\n", indent.c_str(), "NULL", name); message->AppendF("%s|- %-10s[%s]\n", indent.c_str(), "NULL", name);
} break; break;
case OT_INTEGER: { case OT_INTEGER:
sq_getinteger(vm, -1, &i_); sq_getinteger(vm, -1, &i_);
message->AppendF("%s|- %-10s[%s] with value: %" PRINT_INT_FMT "\n", indent.c_str(), "INTEGER", name, i_); message->AppendF("%s|- %-10s[%s] with value: %" PRINT_INT_FMT "\n", indent.c_str(), "INTEGER", name, i_);
} break; break;
case OT_FLOAT: { case OT_FLOAT:
sq_getfloat(vm, -1, &f_); sq_getfloat(vm, -1, &f_);
message->AppendF("%s|- %-10s[%s] with value: %f\n", indent.c_str(), "FLOAT", name, f_); message->AppendF("%s|- %-10s[%s] with value: %f\n", indent.c_str(), "FLOAT", name, f_);
} break; break;
case OT_USERPOINTER: { case OT_USERPOINTER:
sq_getuserpointer(vm, -1, &p_); sq_getuserpointer(vm, -1, &p_);
message->AppendF("%s|- %-10s[%s] pointing at: %p\n", indent.c_str(), "POINTER", name, p_); message->AppendF("%s|- %-10s[%s] pointing at: %p\n", indent.c_str(), "POINTER", name, p_);
} break; break;
case OT_STRING: { case OT_STRING:
sq_getstringandsize(vm, -1, &s_, &i_); sq_getstringandsize(vm, -1, &s_, &i_);
if (i_ > 0) { if (i_ > 0) {
message->AppendF("%s|- %-10s[%s] of %" PRINT_INT_FMT " characters: %.*s\n", indent.c_str(), "STRING", name, i_, m_StringTruncate, s_); message->AppendF("%s|- %-10s[%s] of %" PRINT_INT_FMT " characters: %.*s\n", indent.c_str(), "STRING", name, i_, m_StringTruncate, s_);
} else { } else {
message->AppendF("%s|- %-10s[%s] empty\n", indent.c_str(), "STRING", level, name); message->AppendF("%s|- %-10s[%s] empty\n", indent.c_str(), "STRING", level, name);
} }
} break; break;
case OT_TABLE: { case OT_TABLE:
i_ = sq_getsize(vm, -1); i_ = sq_getsize(vm, -1);
message->AppendF("%s|- %-10s[%s] with %" PRINT_INT_FMT " elements\n", indent.c_str(), "TABLE", name, i_); message->AppendF("%s|- %-10s[%s] with %" PRINT_INT_FMT " elements\n", indent.c_str(), "TABLE", name, i_);
} break; break;
case OT_ARRAY: { case OT_ARRAY:
i_ = sq_getsize(vm, -1); i_ = sq_getsize(vm, -1);
message->AppendF("%s|- %-10s[%s] with %" PRINT_INT_FMT " elements\n", indent.c_str(), "ARRAY", name, i_); message->AppendF("%s|- %-10s[%s] with %" PRINT_INT_FMT " elements\n", indent.c_str(), "ARRAY", name, i_);
} break; break;
case OT_CLOSURE: { case OT_CLOSURE:
s_ = _SC("@anonymous"); s_ = _SC("@anonymous");
if (SQ_SUCCEEDED(sq_getclosurename(vm, -1))) { if (SQ_SUCCEEDED(sq_getclosurename(vm, -1))) {
if (sq_gettype(vm, -1) != OT_NULL && SQ_SUCCEEDED(ssf_.Release(vm).Proc(false))) { if (sq_gettype(vm, -1) != OT_NULL && SQ_SUCCEEDED(ssf_.Release(vm).Proc())) {
s_ = ssf_.mPtr; s_ = ssf_.mPtr;
} }
sq_poptop(vm); sq_poptop(vm);
} }
message->AppendF("%s|- %-10s[%s] with name: %s\n", indent.c_str(), "CLOSURE", name, s_); message->AppendF("%s|- %-10s[%s] with name: %s\n", indent.c_str(), "CLOSURE", name, s_);
} break; break;
case OT_NATIVECLOSURE: { case OT_NATIVECLOSURE:
s_ = _SC("@unknown"); s_ = _SC("@unknown");
if (SQ_SUCCEEDED(sq_getclosurename(vm, -1))) { if (SQ_SUCCEEDED(sq_getclosurename(vm, -1))) {
if (sq_gettype(vm, -1) != OT_NULL && SQ_SUCCEEDED(ssf_.Release(vm).Proc(false))) { if (sq_gettype(vm, -1) != OT_NULL && SQ_SUCCEEDED(ssf_.Release(vm).Proc())) {
s_ = ssf_.mPtr; s_ = ssf_.mPtr;
} }
sq_poptop(vm); sq_poptop(vm);
} }
message->AppendF("%s|- %-10s[%s] with name: %s\n", indent.c_str(), "NCLOSURE", name, s_); message->AppendF("%s|- %-10s[%s] with name: %s\n", indent.c_str(), "NCLOSURE", name, s_);
} break; break;
case OT_GENERATOR: { case OT_GENERATOR:
message->AppendF("%s|- %-10s[%s]\n", indent.c_str(), "GENERATOR", name); message->AppendF("%s|- %-10s[%s]\n", indent.c_str(), "GENERATOR", name);
} break; break;
case OT_USERDATA: { case OT_USERDATA:
message->AppendF("%s|- %-10s[%s]\n", indent.c_str(), "USERDATA", name); message->AppendF("%s|- %-10s[%s]\n", indent.c_str(), "USERDATA", name);
} break; break;
case OT_THREAD: { case OT_THREAD:
message->AppendF("%s|- %-10s[%s]\n", indent.c_str(), "THREAD", name); message->AppendF("%s|- %-10s[%s]\n", indent.c_str(), "THREAD", name);
} break; break;
case OT_CLASS: { case OT_CLASS:
// Brute force our way into getting the name of this class without blowing up // Brute force our way into getting the name of this class without blowing up
s_ = _SC("@unknown"); s_ = _SC("@unknown");
// Create a dummy, non-constructed instance and hope `_typeof` doesn't rely on member variables // Create a dummy, non-constructed instance and hope `_typeof` doesn't rely on member variables
if (SQ_SUCCEEDED(sq_createinstance(vm, -1))) { if (SQ_SUCCEEDED(sq_createinstance(vm, -1))) {
// Attempt a `_typeof` on that instance // Attempt a `_typeof` on that instance
if (SQ_SUCCEEDED(sq_typeof(vm, -1))) { if (SQ_SUCCEEDED(sq_typeof(vm, -1))) {
if (SQ_SUCCEEDED(ssf_.Release(vm).Proc(false))) { if (SQ_SUCCEEDED(ssf_.Release(vm).Proc())) {
s_ = ssf_.mPtr; s_ = ssf_.mPtr;
} }
// Pop the name object // Pop the name object
@ -803,24 +803,24 @@ void Logger::DebugFv(HSQUIRRELVM vm, const char * fmt, va_list args)
sq_poptop(vm); sq_poptop(vm);
} }
message->AppendF("%s|- %-10s[%s] of type: %s\n", indent.c_str(), "CLASS", name, s_); message->AppendF("%s|- %-10s[%s] of type: %s\n", indent.c_str(), "CLASS", name, s_);
} break; break;
case OT_INSTANCE: { case OT_INSTANCE:
s_ = _SC("@unknown"); s_ = _SC("@unknown");
if (SQ_SUCCEEDED(sq_typeof(vm, -1))) { if (SQ_SUCCEEDED(sq_typeof(vm, -1))) {
if (SQ_SUCCEEDED(ssf_.Release(vm).Proc(false))) { if (SQ_SUCCEEDED(ssf_.Release(vm).Proc())) {
s_ = ssf_.mPtr; s_ = ssf_.mPtr;
} }
sq_poptop(vm); sq_poptop(vm);
} }
message->AppendF("%s|- %-10s[%s] of type: %s\n", indent.c_str(), "INSTANCE", name, s_); message->AppendF("%s|- %-10s[%s] of type: %s\n", indent.c_str(), "INSTANCE", name, s_);
} break; break;
case OT_WEAKREF: { case OT_WEAKREF:
s_ = _SC("@unknown"); s_ = _SC("@unknown");
// Attempt to grab the value pointed by the weak reference // Attempt to grab the value pointed by the weak reference
if (SQ_SUCCEEDED(sq_getweakrefval(vm, -1))) { if (SQ_SUCCEEDED(sq_getweakrefval(vm, -1))) {
// Attempt a `_typeof` on that instance // Attempt a `_typeof` on that instance
if (SQ_SUCCEEDED(sq_typeof(vm, -1))) { if (SQ_SUCCEEDED(sq_typeof(vm, -1))) {
if (SQ_SUCCEEDED(ssf_.Release(vm).Proc(false))) { if (SQ_SUCCEEDED(ssf_.Release(vm).Proc())) {
s_ = ssf_.mPtr; s_ = ssf_.mPtr;
} }
// Pop the name object // Pop the name object
@ -830,14 +830,14 @@ void Logger::DebugFv(HSQUIRRELVM vm, const char * fmt, va_list args)
sq_poptop(vm); sq_poptop(vm);
} }
message->AppendF("%s|- %-10s[%s] of type: %s\n", indent.c_str(), "WEAKREF", name, s_); message->AppendF("%s|- %-10s[%s] of type: %s\n", indent.c_str(), "WEAKREF", name, s_);
} break; break;
case OT_BOOL: { case OT_BOOL:
sq_getinteger(vm, -1, &i_); sq_getinteger(vm, -1, &i_);
message->AppendF("%s|- %-10s[%s] with value: %s\n", indent.c_str(), "BOOL", name, i_ ? _SC("true") : _SC("false")); message->AppendF("%s|- %-10s[%s] with value: %s\n", indent.c_str(), "BOOL", name, i_ ? _SC("true") : _SC("false"));
} break; break;
default: { default:
message->AppendF("%s|- %-10s[%s]\n", indent.c_str(), "UNKNOWN", name); message->AppendF("%s|- %-10s[%s]\n", indent.c_str(), "UNKNOWN", name);
} break; break;
} }
sq_pop(vm, 1); sq_pop(vm, 1);
} }

View File

@ -2,7 +2,6 @@
#include "Misc/Official.hpp" #include "Misc/Official.hpp"
#include "Base/Vector2.hpp" #include "Base/Vector2.hpp"
#include "Core/Utility.hpp" #include "Core/Utility.hpp"
#include "Library/IO/Buffer.hpp"
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
#include "Core/Entity.hpp" #include "Core/Entity.hpp"
#include "Core.hpp" #include "Core.hpp"
@ -698,7 +697,7 @@ struct LgPlayer
SQMOD_NODISCARD int GetPing() const { return Get().GetPing(); } SQMOD_NODISCARD int GetPing() const { return Get().GetPing(); }
SQMOD_NODISCARD float GetHealth() const { return Get().GetHealth(); } SQMOD_NODISCARD float GetHealth() const { return Get().GetHealth(); }
SQMOD_NODISCARD float GetArmour() const { return Get().GetArmor(); } SQMOD_NODISCARD float GetArmour() const { return Get().GetArmor(); }
SQMOD_NODISCARD uint32_t GetImmunity() const { return Get().GetImmunity(); } SQMOD_NODISCARD int32_t GetImmunity() const { return Get().GetImmunity(); }
SQMOD_NODISCARD float GetHeading() const { return Get().GetHeading(); } SQMOD_NODISCARD float GetHeading() const { return Get().GetHeading(); }
SQMOD_NODISCARD LgVehicle * GetVehicle() const SQMOD_NODISCARD LgVehicle * GetVehicle() const
{ const int id = _Func->GetPlayerVehicleId(GetIdentifier()); return VALID_ENTITYEX(id, SQMOD_VEHICLE_POOL) ? Core::Get().GetVehicle(id).mLgInst : nullptr; } { const int id = _Func->GetPlayerVehicleId(GetIdentifier()); return VALID_ENTITYEX(id, SQMOD_VEHICLE_POOL) ? Core::Get().GetVehicle(id).mLgInst : nullptr; }
@ -719,7 +718,7 @@ struct LgPlayer
SQMOD_NODISCARD bool Typing() const { return Get().IsTyping(); } SQMOD_NODISCARD bool Typing() const { return Get().IsTyping(); }
SQMOD_NODISCARD bool ShowingMarkers() const { return _Func->GetPlayerOption(GetIdentifier(), vcmpPlayerOptionShowMarkers) >= 1; } SQMOD_NODISCARD bool ShowingMarkers() const { return _Func->GetPlayerOption(GetIdentifier(), vcmpPlayerOptionShowMarkers) >= 1; }
SQMOD_NODISCARD bool GetCameraLocked() const { return Get().IsCameraLocked(); } SQMOD_NODISCARD bool GetCameraLocked() const { return Get().IsCameraLocked(); }
SQMOD_NODISCARD uint32_t GetKey() const { return Get().GetKey(); } SQMOD_NODISCARD int GetKey() const { return Get().GetKey(); }
SQMOD_NODISCARD bool GetAwayStatus() const { return Get().IsAway(); } SQMOD_NODISCARD bool GetAwayStatus() const { return Get().IsAway(); }
SQMOD_NODISCARD LgPlayer * GetSpectateTarget() const SQMOD_NODISCARD LgPlayer * GetSpectateTarget() const
{ const int id = _Func->GetPlayerSpectateTarget(GetIdentifier()); return VALID_ENTITYEX(id, SQMOD_PLAYER_POOL) ? Core::Get().GetPlayer(id).mLgInst : nullptr; } { const int id = _Func->GetPlayerSpectateTarget(GetIdentifier()); return VALID_ENTITYEX(id, SQMOD_PLAYER_POOL) ? Core::Get().GetPlayer(id).mLgInst : nullptr; }
@ -734,7 +733,7 @@ struct LgPlayer
SQMOD_NODISCARD bool GetPlayerOnFireStatus() const { return Get().IsBurning(); } SQMOD_NODISCARD bool GetPlayerOnFireStatus() const { return Get().IsBurning(); }
SQMOD_NODISCARD bool GetPlayerCrouchStatus() const { return Get().IsCrouched(); } SQMOD_NODISCARD bool GetPlayerCrouchStatus() const { return Get().IsCrouched(); }
SQMOD_NODISCARD int GetPlayerAction() const { return Get().GetAction(); } SQMOD_NODISCARD int GetPlayerAction() const { return Get().GetAction(); }
SQMOD_NODISCARD uint32_t GetPlayerGameKeys() const { return Get().GetGameKeys(); } SQMOD_NODISCARD int GetPlayerGameKeys() const { return Get().GetGameKeys(); }
SQMOD_NODISCARD LgVector GetPlayerAimPos() const { return LgVector(Get().GetAimPosition()); } SQMOD_NODISCARD LgVector GetPlayerAimPos() const { return LgVector(Get().GetAimPosition()); }
SQMOD_NODISCARD LgVector GetPlayerAimDir() const { return LgVector(Get().GetAimDirection()); } SQMOD_NODISCARD LgVector GetPlayerAimDir() const { return LgVector(Get().GetAimDirection()); }
SQMOD_NODISCARD int GetWantedLevel() const { return Get().GetWantedLevel(); } SQMOD_NODISCARD int GetWantedLevel() const { return Get().GetWantedLevel(); }
@ -826,12 +825,9 @@ struct LgVehicle
} }
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
SQMOD_NODISCARD static int32_t GetDriverID(int32_t id) { SQMOD_NODISCARD static int32_t GetDriverID(int32_t id) {
for(uint32_t i = 0, n = _Func->GetMaxPlayers(); i < n; ++i) { for(int i = 0, n = _Func->GetMaxPlayers(); i < n; ++i) {
if(_Func->IsPlayerConnected(static_cast< int32_t >(i))) { if(_Func->IsPlayerConnected(i)) {
if(_Func->GetPlayerVehicleId(static_cast< int32_t >(i)) == id && if(_Func->GetPlayerVehicleId(i) == id && _Func->GetPlayerInVehicleSlot(i) == 0) return i;
_Func->GetPlayerInVehicleSlot(static_cast< int32_t >(i)) == 0) {
return static_cast< int32_t >(i);
}
} }
} }
return -1; return -1;
@ -849,7 +845,7 @@ struct LgVehicle
void SetColour2(int colour2) const { Get().SetSecondaryColor(colour2); } void SetColour2(int colour2) const { Get().SetSecondaryColor(colour2); }
void SetLocked(bool toggle) const { _Func->SetVehicleOption(GetIdentifier(), vcmpVehicleOptionDoorsLocked, static_cast< uint8_t >(toggle)); } void SetLocked(bool toggle) const { _Func->SetVehicleOption(GetIdentifier(), vcmpVehicleOptionDoorsLocked, static_cast< uint8_t >(toggle)); }
void SetDamage(uint32_t damage) const { Get().SetDamageData(damage); } void SetDamage(uint32_t damage) const { Get().SetDamageData(damage); }
void SetLightFlags(int32_t flags) const { Get().SetLightsData(flags); } void SetLightFlags(uint32_t flags) const { Get().SetLightsData(flags); }
void SetAlarm(bool toggle) const { _Func->SetVehicleOption(GetIdentifier(), vcmpVehicleOptionAlarm, static_cast< uint8_t >(toggle)); } 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 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)); } void SetLights(bool toggle) const { _Func->SetVehicleOption(GetIdentifier(), vcmpVehicleOptionLights, static_cast< uint8_t >(toggle)); }
@ -873,7 +869,7 @@ struct LgVehicle
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
SQMOD_NODISCARD int GetWorld() const { return Get().GetWorld(); } SQMOD_NODISCARD int GetWorld() const { return Get().GetWorld(); }
SQMOD_NODISCARD int GetModel() const { return Get().GetModel(); } SQMOD_NODISCARD int GetModel() const { return Get().GetModel(); }
SQMOD_NODISCARD uint32_t GetImmunity() const { return Get().GetImmunity(); } SQMOD_NODISCARD int GetImmunity() const { return Get().GetImmunity(); }
SQMOD_NODISCARD LgEntityVector GetPosition() const SQMOD_NODISCARD LgEntityVector GetPosition() const
{ return LgEntityVector(mID, LgEntityType::Vehicle, LgVehicleVectorFlag::Pos, Get().GetPosition()); } { return LgEntityVector(mID, LgEntityType::Vehicle, LgVehicleVectorFlag::Pos, Get().GetPosition()); }
SQMOD_NODISCARD LgEntityVector GetSpawnPos() const SQMOD_NODISCARD LgEntityVector GetSpawnPos() const
@ -1263,7 +1259,7 @@ static void LgSetServerName(StackStrF & str) { _Func->SetServerName(str.mPtr); }
static void LgSetMaxPlayers(int newMaxPlayers) { _Func->SetMaxPlayers(static_cast< uint32_t >(newMaxPlayers)); } static void LgSetMaxPlayers(int newMaxPlayers) { _Func->SetMaxPlayers(static_cast< uint32_t >(newMaxPlayers)); }
static void LgSetServerPassword(StackStrF & str) { _Func->SetServerPassword(str.mPtr); } static void LgSetServerPassword(StackStrF & str) { _Func->SetServerPassword(str.mPtr); }
static void LgSetGameModeText(StackStrF & str) { _Func->SetGameModeText(str.mPtr); } static void LgSetGameModeText(StackStrF & str) { _Func->SetGameModeText(str.mPtr); }
static void LgSetTimeRate(int32_t rate) { _Func->SetTimeRate(rate); } static void LgSetTimeRate(uint32_t rate) { _Func->SetTimeRate(rate); }
static void LgSetHour(int hour) { _Func->SetHour( hour ); } static void LgSetHour(int hour) { _Func->SetHour( hour ); }
static void LgSetMinute(int minute) { _Func->SetMinute(minute); } static void LgSetMinute(int minute) { _Func->SetMinute(minute); }
static void LgSetTime(int hour, int minute) { LgSetHour(hour); LgSetMinute(minute); } static void LgSetTime(int hour, int minute) { LgSetHour(hour); LgSetMinute(minute); }
@ -1294,7 +1290,7 @@ SQMOD_NODISCARD static SQInteger LgGetGameModeText(HSQUIRRELVM vm) {
return 1; return 1;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
SQMOD_NODISCARD static uint32_t LgGetMaxPlayers() { return _Func->GetMaxPlayers(); } SQMOD_NODISCARD static int LgGetMaxPlayers() { return _Func->GetMaxPlayers(); }
SQMOD_NODISCARD static uint32_t LgGetTimeRate() { return static_cast< uint32_t >(_Func->GetTimeRate()); } 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 LgGetHour() { return _Func->GetHour(); }
SQMOD_NODISCARD static int LgGetMinute() { return _Func->GetMinute(); } SQMOD_NODISCARD static int LgGetMinute() { return _Func->GetMinute(); }
@ -2249,7 +2245,7 @@ struct LgStream {
length = static_cast< uint16_t >(MAX_SIZE - m_OutputStreamPosition); length = static_cast< uint16_t >(MAX_SIZE - m_OutputStreamPosition);
m_OutputStreamError = true; m_OutputStreamError = true;
} }
auto lengthBE = static_cast< uint16_t >(((length >> 8u) & 0xFFu) | ((length & 0xFFu) << 8u)); uint16_t lengthBE = static_cast< uint16_t >(((length >> 8u) & 0xFFu) | ((length & 0xFFu) << 8u));
Write(&lengthBE, sizeof(lengthBE)); Write(&lengthBE, sizeof(lengthBE));
Write(value.mPtr, length); Write(value.mPtr, length);
} }
@ -2314,17 +2310,6 @@ struct LgStream {
m_InputStreamPosition += length; m_InputStreamPosition += length;
return LightObj(m_Buffer, static_cast< SQInteger >(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: private:
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
static bool CanWrite(size_t size) { return (size <= (MAX_SIZE - m_OutputStreamPosition)); } static bool CanWrite(size_t size) { return (size <= (MAX_SIZE - m_OutputStreamPosition)); }
@ -2346,28 +2331,28 @@ private:
return 0; return 0;
} }
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
static uint8_t m_InputStreamData[MAX_SIZE]; static uint8_t m_InputStreamData[MAX_SIZE];
static size_t m_InputStreamSize; static size_t m_InputStreamSize;
static size_t m_InputStreamPosition; static size_t m_InputStreamPosition;
static bool m_InputStreamError; static bool m_InputStreamError;
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
static uint8_t m_OutputStreamData[MAX_SIZE]; static uint8_t m_OutputStreamData[MAX_SIZE];
static size_t m_OutputStreamPosition; static size_t m_OutputStreamPosition;
static size_t m_OutputStreamEnd; static size_t m_OutputStreamEnd;
static bool m_OutputStreamError; static bool m_OutputStreamError;
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
static SQChar m_Buffer[MAX_SIZE]; static SQChar m_Buffer[MAX_SIZE];
}; };
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
uint8_t LgStream::m_InputStreamData[LgStream::MAX_SIZE]{}; uint8_t LgStream::m_InputStreamData[LgStream::MAX_SIZE];
size_t LgStream::m_InputStreamSize{0}; size_t LgStream::m_InputStreamSize;
size_t LgStream::m_InputStreamPosition{0}; size_t LgStream::m_InputStreamPosition;
bool LgStream::m_InputStreamError{false}; bool LgStream::m_InputStreamError;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
uint8_t LgStream::m_OutputStreamData[LgStream::MAX_SIZE]{}; uint8_t LgStream::m_OutputStreamData[LgStream::MAX_SIZE];
size_t LgStream::m_OutputStreamEnd{0}; size_t LgStream::m_OutputStreamEnd;
size_t LgStream::m_OutputStreamPosition{0}; size_t LgStream::m_OutputStreamPosition;
bool LgStream::m_OutputStreamError{false}; bool LgStream::m_OutputStreamError;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
SQChar LgStream::m_Buffer[LgStream::MAX_SIZE]; SQChar LgStream::m_Buffer[LgStream::MAX_SIZE];
@ -2398,8 +2383,6 @@ void Register_Official_Stream(HSQUIRRELVM vm)
.StaticFunc(_SC("ReadInt"), &LgStream::ReadInt) .StaticFunc(_SC("ReadInt"), &LgStream::ReadInt)
.StaticFunc(_SC("ReadFloat"), &LgStream::ReadFloat) .StaticFunc(_SC("ReadFloat"), &LgStream::ReadFloat)
.StaticFunc(_SC("ReadString"), &LgStream::ReadString) .StaticFunc(_SC("ReadString"), &LgStream::ReadString)
.StaticFunc(_SC("CloneInputToBuffer"), &LgStream::CloneInputToBuffer)
.StaticFunc(_SC("CloneOutputToBuffer"), &LgStream::CloneOutputToBuffer)
); );
} }

View File

@ -1 +1,7 @@
#include <sajson.h> #include <sajson.h>
namespace sajson {
namespace internal {
//template <> const uint8_t globals_struct<void>::parse_flags[256];
}
}