2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
2016-03-24 08:32:44 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-05-24 18:26:43 +02:00
|
|
|
extern bool GetReloadStatus();
|
|
|
|
extern void SetReloadStatus(bool toggle);
|
2016-03-24 08:32:44 +01:00
|
|
|
|
2017-06-19 15:10:31 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
SQMODE_DECL_TYPENAME(CoreStateTypename, _SC("SqCoreState"))
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-08-18 16:43:54 +02:00
|
|
|
static SQInteger SqLoadScript(HSQUIRRELVM vm)
|
|
|
|
{
|
|
|
|
const Int32 top = sq_gettop(vm);
|
|
|
|
// Was the delay option specified?
|
|
|
|
if (top <= 1)
|
|
|
|
{
|
|
|
|
return sq_throwerror(vm, "Missing delay parameter");
|
|
|
|
}
|
|
|
|
// Was the script path specified?
|
|
|
|
else if (top <= 2)
|
|
|
|
{
|
|
|
|
return sq_throwerror(vm, "Missing script path");
|
|
|
|
}
|
|
|
|
// Whether the script execution is delayed
|
|
|
|
SQBool delay = SQFalse;
|
|
|
|
// Attempt to generate the string value
|
2018-07-29 23:58:27 +02:00
|
|
|
StackStrF val(vm, 3);
|
2016-08-18 16:43:54 +02:00
|
|
|
// Have we failed to retrieve the string?
|
2018-07-29 23:58:27 +02:00
|
|
|
if (SQ_FAILED(val.Proc(true)))
|
2016-08-18 16:43:54 +02:00
|
|
|
{
|
|
|
|
return val.mRes; // Propagate the error!
|
|
|
|
}
|
|
|
|
else if (SQ_FAILED(sq_getbool(vm, 2, &delay)))
|
|
|
|
{
|
|
|
|
return sq_throwerror(vm, "Failed to retrieve the delay parameter");
|
|
|
|
}
|
|
|
|
// Forward the call to the actual implementation
|
|
|
|
sq_pushbool(vm, Core::Get().LoadScript(val.mPtr, static_cast< bool >(delay)));
|
|
|
|
// We have an argument on the stack
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-08-25 02:08:44 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
static SQInteger SqGetEvents(HSQUIRRELVM vm)
|
2016-08-25 02:08:44 +02:00
|
|
|
{
|
2017-02-21 20:24:59 +01:00
|
|
|
// Push the events table object on the stack
|
|
|
|
sq_pushobject(vm, Core::Get().GetEvents().mObj);
|
|
|
|
// Specify that we're returning a value
|
|
|
|
return 1;
|
2016-03-12 21:51:44 +01:00
|
|
|
}
|
|
|
|
|
2020-03-21 12:54:38 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-03-21 12:57:38 +01:00
|
|
|
static SQInteger SqForceEnableNullEntities(HSQUIRRELVM vm)
|
2020-03-21 12:54:38 +01:00
|
|
|
{
|
|
|
|
Core::Get().EnableNullEntities();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-22 17:08:33 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static LightObj & SqGetPreLoadEvent()
|
|
|
|
{
|
|
|
|
return Core::Get().GetPreLoadEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static LightObj & SqGetPostLoadEvent()
|
|
|
|
{
|
|
|
|
return Core::Get().GetPostLoadEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static LightObj & SqGetUnloadEvent()
|
|
|
|
{
|
|
|
|
return Core::Get().GetUnloadEvent();
|
|
|
|
}
|
|
|
|
|
2016-05-24 18:26:43 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static bool SqGetReloadStatus()
|
2016-03-12 21:51:44 +01:00
|
|
|
{
|
2016-05-24 18:26:43 +02:00
|
|
|
return GetReloadStatus();
|
2016-03-12 21:51:44 +01:00
|
|
|
}
|
|
|
|
|
2016-05-24 18:26:43 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static void SqSetReloadStatus(bool toggle)
|
2016-03-12 21:51:44 +01:00
|
|
|
{
|
2016-05-24 18:26:43 +02:00
|
|
|
SetReloadStatus(toggle);
|
2016-03-12 21:51:44 +01:00
|
|
|
}
|
|
|
|
|
2016-05-24 18:26:43 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
static void SqReloadBecause(Int32 header, LightObj & payload)
|
2016-03-12 21:51:44 +01:00
|
|
|
{
|
2016-05-24 18:26:43 +02:00
|
|
|
// Assign the reload info
|
|
|
|
Core::Get().SetReloadInfo(header, payload);
|
|
|
|
// Enable reloading
|
|
|
|
SetReloadStatus(true);
|
2016-03-12 21:51:44 +01:00
|
|
|
}
|
|
|
|
|
2016-05-24 18:26:43 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
static void SqSetReloadInfo(Int32 header, LightObj & payload)
|
2016-03-12 21:51:44 +01:00
|
|
|
{
|
2016-05-24 18:26:43 +02:00
|
|
|
Core::Get().SetReloadInfo(header, payload);
|
2016-03-12 21:51:44 +01:00
|
|
|
}
|
2016-02-20 23:25:00 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-05-24 18:26:43 +02:00
|
|
|
static Int32 SqGetReloadHeader()
|
2016-03-12 21:51:44 +01:00
|
|
|
{
|
2016-05-24 18:26:43 +02:00
|
|
|
return Core::Get().GetReloadHeader();
|
2016-03-12 21:51:44 +01:00
|
|
|
}
|
2016-02-20 23:25:00 +01:00
|
|
|
|
2016-05-23 02:51:44 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
static LightObj & SqGetReloadPayload()
|
2016-05-23 02:51:44 +02:00
|
|
|
{
|
2016-05-24 18:26:43 +02:00
|
|
|
return Core::Get().GetReloadPayload();
|
2016-05-23 02:51:44 +02:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-07-29 11:25:44 +02:00
|
|
|
static Int32 SqGetState()
|
2016-03-12 21:51:44 +01:00
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
return Core::Get().GetState();
|
2016-03-12 21:51:44 +01:00
|
|
|
}
|
|
|
|
|
2016-05-24 18:26:43 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-07-29 11:25:44 +02:00
|
|
|
static void SqSetState(Int32 value)
|
2016-03-12 21:51:44 +01:00
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
return Core::Get().SetState(value);
|
2016-03-12 21:51:44 +01:00
|
|
|
}
|
2016-02-20 23:25:00 +01:00
|
|
|
|
2017-06-19 03:09:35 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-07-29 11:25:44 +02:00
|
|
|
static bool SqGetAreasEnabled()
|
2017-06-19 03:09:35 +02:00
|
|
|
{
|
|
|
|
return Core::Get().AreasEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-07-29 11:25:44 +02:00
|
|
|
static void SqSetAreasEnabled(bool toggle)
|
2017-06-19 03:09:35 +02:00
|
|
|
{
|
|
|
|
Core::Get().AreasEnabled(toggle);
|
|
|
|
}
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-07-29 11:25:44 +02:00
|
|
|
static CSStr SqGetOption(CSStr name)
|
2016-03-12 21:51:44 +01:00
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
return Core::Get().GetOption(name);
|
2016-03-12 21:51:44 +01:00
|
|
|
}
|
|
|
|
|
2016-05-24 18:26:43 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-07-29 11:25:44 +02:00
|
|
|
static CSStr SqGetOptionOr(CSStr name, CSStr value)
|
2016-03-12 21:51:44 +01:00
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
return Core::Get().GetOption(name, value);
|
2016-03-12 21:51:44 +01:00
|
|
|
}
|
|
|
|
|
2016-05-24 18:26:43 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-07-29 11:25:44 +02:00
|
|
|
static void SqSetOption(CSStr name, CSStr value)
|
2016-03-12 21:51:44 +01:00
|
|
|
{
|
2016-05-22 05:20:38 +02:00
|
|
|
return Core::Get().SetOption(name, value);
|
2016-03-12 21:51:44 +01:00
|
|
|
}
|
2016-02-20 23:25:00 +01:00
|
|
|
|
2016-03-24 08:32:44 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-07-29 11:25:44 +02:00
|
|
|
static LightObj & SqGetBlip(Int32 id)
|
2016-05-24 18:26:43 +02:00
|
|
|
{
|
|
|
|
// Validate the identifier first
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Out of range blip identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Return the requested information
|
|
|
|
return Core::Get().GetBlip(id).mObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-07-29 11:25:44 +02:00
|
|
|
static LightObj & SqGetCheckpoint(Int32 id)
|
2016-05-24 18:26:43 +02:00
|
|
|
{
|
|
|
|
// Validate the identifier first
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_CHECKPOINT_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Out of range checkpoint identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Return the requested information
|
|
|
|
return Core::Get().GetCheckpoint(id).mObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-07-29 11:25:44 +02:00
|
|
|
static LightObj & SqGetKeybind(Int32 id)
|
2016-05-24 18:26:43 +02:00
|
|
|
{
|
|
|
|
// Validate the identifier first
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_KEYBIND_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Out of range keybind identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Return the requested information
|
|
|
|
return Core::Get().GetKeybind(id).mObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2020-04-17 16:42:09 +02:00
|
|
|
static LightObj & SqGetObj(Int32 id)
|
2016-05-24 18:26:43 +02:00
|
|
|
{
|
|
|
|
// Validate the identifier first
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Out of range object identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Return the requested information
|
2020-04-17 16:42:09 +02:00
|
|
|
return Core::Get().GetObj(id).mObj;
|
2016-05-24 18:26:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-07-29 11:25:44 +02:00
|
|
|
static LightObj & SqGetPickup(Int32 id)
|
2016-05-24 18:26:43 +02:00
|
|
|
{
|
|
|
|
// Validate the identifier first
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Out of range blip identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Return the requested information
|
|
|
|
return Core::Get().GetPickup(id).mObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-07-29 11:25:44 +02:00
|
|
|
static LightObj & SqGetPlayer(Int32 id)
|
2016-05-24 18:26:43 +02:00
|
|
|
{
|
|
|
|
// Validate the identifier first
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_PLAYER_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Out of range player identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Return the requested information
|
|
|
|
return Core::Get().GetPlayer(id).mObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-07-29 11:25:44 +02:00
|
|
|
static LightObj & SqGetVehicle(Int32 id)
|
2016-05-24 18:26:43 +02:00
|
|
|
{
|
|
|
|
// Validate the identifier first
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Out of range vehicle identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Return the requested information
|
|
|
|
return Core::Get().GetVehicle(id).mObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-07-29 11:25:44 +02:00
|
|
|
static bool SqDelBlip(Int32 id, Int32 header, LightObj & payload)
|
2016-05-24 18:26:43 +02:00
|
|
|
{
|
|
|
|
// Validate the identifier first
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Out of range blip identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Perform the requested operation
|
|
|
|
return Core::Get().DelBlip(id, header, payload);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-07-29 11:25:44 +02:00
|
|
|
static bool SqDelCheckpoint(Int32 id, Int32 header, LightObj & payload)
|
2016-03-24 08:32:44 +01:00
|
|
|
{
|
2016-05-24 18:26:43 +02:00
|
|
|
// Validate the identifier first
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_CHECKPOINT_POOL))
|
2016-03-24 08:32:44 +01:00
|
|
|
{
|
2016-05-24 18:26:43 +02:00
|
|
|
STHROWF("Out of range checkpoint identifier: %d", id);
|
2016-03-24 08:32:44 +01:00
|
|
|
}
|
2016-05-24 18:26:43 +02:00
|
|
|
// Perform the requested operation
|
|
|
|
return Core::Get().DelCheckpoint(id, header, payload);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-07-29 11:25:44 +02:00
|
|
|
static bool SqDelKeybind(Int32 id, Int32 header, LightObj & payload)
|
2016-05-24 18:26:43 +02:00
|
|
|
{
|
|
|
|
// Validate the identifier first
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_KEYBIND_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Out of range keybind identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Perform the requested operation
|
|
|
|
return Core::Get().DelKeybind(id, header, payload);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-07-29 11:25:44 +02:00
|
|
|
static bool SqDelObject(Int32 id, Int32 header, LightObj & payload)
|
2016-05-24 18:26:43 +02:00
|
|
|
{
|
|
|
|
// Validate the identifier first
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
|
2016-03-24 08:32:44 +01:00
|
|
|
{
|
2016-05-24 18:26:43 +02:00
|
|
|
STHROWF("Out of range object identifier: %d", id);
|
2016-03-24 08:32:44 +01:00
|
|
|
}
|
2016-05-24 18:26:43 +02:00
|
|
|
// Perform the requested operation
|
|
|
|
return Core::Get().DelObject(id, header, payload);
|
2016-03-24 08:32:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-07-29 11:25:44 +02:00
|
|
|
static bool SqDelPickup(Int32 id, Int32 header, LightObj & payload)
|
2016-03-24 08:32:44 +01:00
|
|
|
{
|
2016-05-24 18:26:43 +02:00
|
|
|
// Validate the identifier first
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Out of range blip identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Perform the requested operation
|
|
|
|
return Core::Get().DelPickup(id, header, payload);
|
2016-03-24 08:32:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-07-29 11:25:44 +02:00
|
|
|
static bool SqDelVehicle(Int32 id, Int32 header, LightObj & payload)
|
2016-03-24 08:32:44 +01:00
|
|
|
{
|
2016-05-24 18:26:43 +02:00
|
|
|
// Validate the identifier first
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Out of range vehicle identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Perform the requested operation
|
|
|
|
return Core::Get().DelVehicle(id, header, payload);
|
2016-03-24 08:32:44 +01:00
|
|
|
}
|
|
|
|
|
2016-02-20 23:25:00 +01:00
|
|
|
// ================================================================================================
|
|
|
|
void Register_Core(HSQUIRRELVM vm)
|
|
|
|
{
|
2017-06-19 15:10:31 +02:00
|
|
|
Table corens(vm);
|
|
|
|
|
|
|
|
corens.Bind(_SC("State"),
|
|
|
|
Class< CoreState, NoCopy< CoreState > >(vm, CoreStateTypename::Str)
|
|
|
|
// Constructors
|
|
|
|
.Ctor()
|
|
|
|
.Ctor< int >()
|
|
|
|
// Meta-methods
|
|
|
|
.SquirrelFunc(_SC("_typename"), &CoreStateTypename::Fn)
|
|
|
|
// Member Properties
|
|
|
|
.Prop(_SC("Value"), &CoreState::GetValue)
|
|
|
|
);
|
|
|
|
|
|
|
|
corens
|
2016-05-24 18:26:43 +02:00
|
|
|
.Func(_SC("Reload"), &SqSetReloadStatus)
|
|
|
|
.Func(_SC("Reloading"), &SqGetReloadStatus)
|
|
|
|
.Func(_SC("ReloadBecause"), &SqReloadBecause)
|
|
|
|
.Func(_SC("SetReloadInfo"), &SqSetReloadInfo)
|
|
|
|
.Func(_SC("GetReloadHeader"), &SqGetReloadHeader)
|
|
|
|
.Func(_SC("GetReloadPayload"), &SqGetReloadPayload)
|
2018-07-29 11:25:44 +02:00
|
|
|
.Func(_SC("GetState"), &SqGetState)
|
|
|
|
.Func(_SC("SetState"), &SqSetState)
|
|
|
|
.Func(_SC("AreasEnabled"), &SqGetAreasEnabled)
|
|
|
|
.Func(_SC("SetAreasEnabled"), &SqSetAreasEnabled)
|
|
|
|
.Func(_SC("GetOption"), &SqGetOption)
|
|
|
|
.Func(_SC("GetOptionOr"), &SqGetOptionOr)
|
|
|
|
.Func(_SC("SetOption"), &SqSetOption)
|
|
|
|
.Func(_SC("GetBlip"), &SqGetBlip)
|
|
|
|
.Func(_SC("GetCheckpoint"), &SqGetCheckpoint)
|
|
|
|
.Func(_SC("GetKeybind"), &SqGetKeybind)
|
2020-04-17 16:42:09 +02:00
|
|
|
.Func(_SC("GetObj"), &SqGetObj)
|
2018-07-29 11:25:44 +02:00
|
|
|
.Func(_SC("GetPickup"), &SqGetPickup)
|
|
|
|
.Func(_SC("GetPlayer"), &SqGetPlayer)
|
|
|
|
.Func(_SC("GetVehicle"), &SqGetVehicle)
|
|
|
|
.Func(_SC("DestroyBlip"), &SqDelBlip)
|
|
|
|
.Func(_SC("DestroyCheckpoint"), &SqDelCheckpoint)
|
|
|
|
.Func(_SC("DestroyKeybind"), &SqDelKeybind)
|
|
|
|
.Func(_SC("DestroyObject"), &SqDelObject)
|
|
|
|
.Func(_SC("DestroyPickup"), &SqDelPickup)
|
|
|
|
.Func(_SC("DestroyVehicle"), &SqDelVehicle)
|
2017-02-22 17:08:33 +01:00
|
|
|
.Func(_SC("OnPreLoad"), &SqGetPreLoadEvent)
|
|
|
|
.Func(_SC("OnPostLoad"), &SqGetPostLoadEvent)
|
|
|
|
.Func(_SC("OnUnload"), &SqGetUnloadEvent)
|
2020-03-21 12:57:38 +01:00
|
|
|
.SquirrelFunc(_SC("ForceEnableNullEntities"), &SqForceEnableNullEntities)
|
2020-04-17 14:25:58 +02:00
|
|
|
.SquirrelFunc(_SC("LoadScript"), &SqLoadScript, -3, ".b.")
|
2017-06-19 15:10:31 +02:00
|
|
|
.SquirrelFunc(_SC("On"), &SqGetEvents);
|
|
|
|
|
|
|
|
RootTable(vm).Bind(_SC("SqCore"), corens);
|
2016-02-20 23:25:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|