2021-12-25 22:36:38 +01:00
|
|
|
//=============================================================================//
|
|
|
|
//
|
2022-01-16 00:35:39 +01:00
|
|
|
// Purpose: Expose native code to VScript API
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Create functions here under the target VM namespace. If the function has to
|
|
|
|
// be registered for 2 or more VM's, put them under the 'SHARED' namespace.
|
2023-07-18 00:17:49 +02:00
|
|
|
// Ifdef them out for 'SERVER_DLL' / 'CLIENT_DLL' if the target VM's do not
|
2022-03-28 12:02:11 +02:00
|
|
|
// include 'SERVER' / 'CLIENT'.
|
2021-12-25 22:36:38 +01:00
|
|
|
//
|
|
|
|
//=============================================================================//
|
|
|
|
|
|
|
|
#include "core/stdafx.h"
|
2022-05-29 02:08:07 +02:00
|
|
|
#include "vpc/keyvalues.h"
|
2023-07-19 18:52:00 +02:00
|
|
|
#include "engine/client/cl_main.h"
|
2022-05-27 02:08:51 +02:00
|
|
|
#include "engine/cmodel_bsp.h"
|
2023-05-06 16:23:56 +02:00
|
|
|
#include "vscript/languages/squirrel_re/include/sqvm.h"
|
2023-07-19 18:52:00 +02:00
|
|
|
#include "vscript_shared.h"
|
2022-01-16 00:35:39 +01:00
|
|
|
|
2023-05-06 16:23:56 +02:00
|
|
|
namespace VScriptCode
|
2022-01-16 00:35:39 +01:00
|
|
|
{
|
2023-07-18 21:05:29 +02:00
|
|
|
namespace Shared
|
2022-01-16 00:35:39 +01:00
|
|
|
{
|
2022-03-28 19:34:51 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: expose SDK version to the VScript API
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-03-30 22:54:33 +02:00
|
|
|
SQRESULT GetSDKVersion(HSQUIRRELVM v)
|
2022-03-28 19:34:51 +02:00
|
|
|
{
|
2022-07-01 02:20:47 +02:00
|
|
|
sq_pushstring(v, SDK_VERSION, -1);
|
2022-03-28 19:34:51 +02:00
|
|
|
return SQ_OK;
|
|
|
|
}
|
2022-05-27 02:08:51 +02:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: return all available maps
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
SQRESULT GetAvailableMaps(HSQUIRRELVM v)
|
|
|
|
{
|
2023-03-31 00:35:01 +02:00
|
|
|
std::lock_guard<std::mutex> l(g_InstalledMapsMutex);
|
2022-08-29 11:55:58 +02:00
|
|
|
|
2023-09-05 17:34:22 +02:00
|
|
|
if (g_InstalledMaps.IsEmpty())
|
2022-05-27 02:08:51 +02:00
|
|
|
return SQ_OK;
|
|
|
|
|
|
|
|
sq_newarray(v, 0);
|
2023-09-05 17:34:22 +02:00
|
|
|
|
|
|
|
FOR_EACH_VEC(g_InstalledMaps, i)
|
2022-05-27 02:08:51 +02:00
|
|
|
{
|
2023-09-05 17:34:22 +02:00
|
|
|
const CUtlString& mapName = g_InstalledMaps[i];
|
|
|
|
|
|
|
|
sq_pushstring(v, mapName.String(), -1);
|
2022-05-27 02:08:51 +02:00
|
|
|
sq_arrayappend(v, -2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SQ_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: return all available playlists
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
SQRESULT GetAvailablePlaylists(HSQUIRRELVM v)
|
|
|
|
{
|
2022-08-29 11:55:58 +02:00
|
|
|
std::lock_guard<std::mutex> l(g_PlaylistsVecMutex);
|
|
|
|
|
2022-05-27 02:08:51 +02:00
|
|
|
if (g_vAllPlaylists.empty())
|
|
|
|
return SQ_OK;
|
|
|
|
|
|
|
|
sq_newarray(v, 0);
|
2022-07-01 23:33:47 +02:00
|
|
|
for (const string& it : g_vAllPlaylists)
|
2022-05-27 02:08:51 +02:00
|
|
|
{
|
|
|
|
sq_pushstring(v, it.c_str(), -1);
|
|
|
|
sq_arrayappend(v, -2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SQ_OK;
|
|
|
|
}
|
2023-08-12 22:41:48 +01:00
|
|
|
|
|
|
|
SQRESULT ScriptError(HSQUIRRELVM v)
|
|
|
|
{
|
|
|
|
SQChar* pString = NULL;
|
|
|
|
SQInteger a4 = 0;
|
|
|
|
|
|
|
|
if (SQVM_sprintf(v, 0, 1, &a4, &pString) < 0)
|
|
|
|
return SQ_ERROR;
|
|
|
|
|
|
|
|
v_SQVM_ScriptError("%s", pString);
|
|
|
|
|
|
|
|
// this should be moved to a wrapper for all script funcs
|
|
|
|
if (*reinterpret_cast<DWORD*>(&v->_sharedstate->gap43b9[127]))
|
|
|
|
{
|
|
|
|
v_SQVM_ThrowError(*reinterpret_cast<QWORD*>(&v->_sharedstate->gap43b9[111]), v);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SQ_ERROR;
|
|
|
|
}
|
2023-07-19 02:12:56 +02:00
|
|
|
}
|
|
|
|
}
|
2022-09-16 01:40:17 +02:00
|
|
|
|
2023-07-19 02:12:56 +02:00
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: common script abstractions
|
|
|
|
// Input : *s -
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
void Script_RegisterCommonAbstractions(CSquirrelVM* s)
|
|
|
|
{
|
2023-07-19 12:09:42 +02:00
|
|
|
DEFINE_SHARED_SCRIPTFUNC_NAMED(s, GetSDKVersion, "Gets the SDK version as a string", "string", "");
|
2023-07-18 00:17:49 +02:00
|
|
|
|
2023-07-19 12:09:42 +02:00
|
|
|
DEFINE_SHARED_SCRIPTFUNC_NAMED(s, GetAvailableMaps, "Gets an array of all available maps", "array< string >", "");
|
|
|
|
DEFINE_SHARED_SCRIPTFUNC_NAMED(s, GetAvailablePlaylists, "Gets an array of all available playlists", "array< string >", "");
|
2023-08-12 22:41:48 +01:00
|
|
|
|
|
|
|
DEFINE_SHARED_SCRIPTFUNC_NAMED(s, ScriptError, "", "void", "string format, ...")
|
2023-07-18 00:17:49 +02:00
|
|
|
}
|
2023-07-19 18:52:00 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: listen server constants (!!! only call on builds containing a listen server !!!)
|
|
|
|
// Input : *s -
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
void Script_RegisterListenServerConstants(CSquirrelVM* s)
|
|
|
|
{
|
|
|
|
const SQBool hasListenServer = !IsClientDLL();
|
|
|
|
s->RegisterConstant("LISTEN_SERVER", hasListenServer);
|
|
|
|
}
|