mirror of
https://github.com/celisej567/source-sdk-2013.git
synced 2026-09-17 20:10:21 +03:00
Mapbase v6.0
- Fixed path_track paths saving as pointers instead of handles - Fixed player animations not falling to base class correctly - Fixed logic_externaldata creating garbage in trailing spaces - Added "SetHandModelSkin" input - Added unique colors for various types of console message, adjustable via convars - Added the ability to use map-specific weapon scripts - Added a way to display (placeholder) text entirely from Faceposer scenes - Added "autobreak" keyvalue to game_text, which automatically breaks long text into different lines - Added the ability to change a game_text's font (very limited) - Added LightToggle input to point_spotlight - Added Enable/DisableSprites on npc_manhack - Added ai_goal_police behavior from metrocops to Combine soldiers and citizens - Added func_precipitation particle rain systems from the Alien Swarm SDK - Added new func_precipitation spawnflags for controlling behavior in particle types - Added "mapbase_version" cvar which shows the version of Mapbase a mod might be running on - Fixed an oversight with NPC crouch activities which was causing npc_metropolice to stop firing in standoffs - Added toggleable patches to npc_combine AI which make soldiers less likely to stand around without shooting or rush to melee when not needed - Added key for custom logo font on env_credits scripts - Added SetSpeed and SetPushDir inputs for trigger_push - Added a bunch of I/O/KV to func_fish_pool to allow for more control over the fish - Added OnLostEnemy/Player support for npc_combine_camera - Added enhanced save/restore for the Response System, toggleable via convar - Added a convar which allows users to disable weapon autoswitching when picking up ammo - Split VScript base script into its own file - Added VScript descriptions for NPC squads and the manager class which handles them - Moved several classes, functions, etc. to the VScript library itself for future usage in other projects, like VBSP - Added VScript to VBSP with basic map file interfacing - Made some VScript documentation more clear due to deprecation of online documentation - Added VScript "hook" registration, creating a standardized system which shows up in script_help documentation - Added VScript-driven custom weapons - Added clientside VScript scopes - Added a bunch of weapon-related VScript functions - Split a bunch of cluttered VScript stuff into different files - Added VScript functions for "following" entities/bonemerging - Added VScript functions for grenades - Added a few more VScript trigger functions - Added OnDeath hook for VScript - Fixed documentation for aliased functions in VScript - Fixed $bumpmask not working on SDK_LightmappedGeneric - Made vertex blend swapping in Hammer use a constant instead of a combo (makes it easier to compile the shader, especially for $bumpmask's sake) - Fixed brush phong, etc. causing SDK_WorldVertexTransition to stop working - Added limited support for $envmapmask in the bumpmapping shader - Fixed more issues with parallax corrected cubemaps and instances - Made instance variable recursion consistent with VMFII
This commit is contained in:
@@ -18,6 +18,9 @@
|
||||
#ifdef PARALLAX_CORRECTED_CUBEMAPS
|
||||
#include "matrixinvert.h"
|
||||
#endif
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
#include "vscript_vbsp.h"
|
||||
#endif
|
||||
|
||||
#ifdef VSVMFIO
|
||||
#include "VmfImport.h"
|
||||
@@ -53,6 +56,9 @@ extern qboolean onlyents;
|
||||
extern entity_t *g_ManifestWorldSpawn;
|
||||
|
||||
char g_MainMapPath[ MAX_PATH ];
|
||||
|
||||
// This is done for the instancing fix
|
||||
bool g_pParallaxObbsDone[MAX_MAP_CUBEMAPSAMPLES];
|
||||
#endif
|
||||
|
||||
|
||||
@@ -2568,6 +2574,32 @@ void CMapFile::MergeEntities( entity_t *pInstanceEntity, CMapFile *Instance, Vec
|
||||
Q_snprintf( temp, sizeof( temp ), "%f", vOutNormal.z );
|
||||
SetKeyValue( entity, "normal.z", temp );*/
|
||||
}
|
||||
|
||||
#ifdef MAPBASE
|
||||
else if ( !strcmp( pEntity, "func_instance" ) )
|
||||
{
|
||||
int iNumReplaces = 0;
|
||||
for ( epair_t *epSubInstance = entity->epairs; epSubInstance != NULL; epSubInstance = epSubInstance->next )
|
||||
{
|
||||
if ( strnicmp( epSubInstance->key, INSTANCE_VARIABLE_KEY, strlen( INSTANCE_VARIABLE_KEY ) ) == 0 )
|
||||
{
|
||||
iNumReplaces++;
|
||||
}
|
||||
}
|
||||
|
||||
// Merge this instance's keys
|
||||
for ( epair_t *epInstance = pInstanceEntity->epairs; epInstance != NULL; epInstance = epInstance->next )
|
||||
{
|
||||
if ( strnicmp( epInstance->key, INSTANCE_VARIABLE_KEY, strlen( INSTANCE_VARIABLE_KEY ) ) == 0 )
|
||||
{
|
||||
iNumReplaces++;
|
||||
char szKey[32];
|
||||
Q_snprintf(szKey, sizeof(szKey), "replace%i", iNumReplaces);
|
||||
SetKeyValue( entity, szKey, epInstance->value );
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef MERGE_INSTANCE_DEBUG_INFO
|
||||
@@ -2766,6 +2798,23 @@ bool LoadMapFile( const char *pszFileName )
|
||||
|
||||
if ((eResult == ChunkFile_Ok) || (eResult == ChunkFile_EOF))
|
||||
{
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
if ( g_pScriptVM )
|
||||
{
|
||||
HSCRIPT hFunc = g_pScriptVM->LookupFunction( "OnMapLoaded" );
|
||||
if ( hFunc )
|
||||
{
|
||||
// Use GetLoadingMap()
|
||||
//g_pScriptVM->SetValue( "map", g_LoadingMap->GetScriptInstance() );
|
||||
|
||||
g_pScriptVM->Call( hFunc );
|
||||
g_pScriptVM->ReleaseFunction( hFunc );
|
||||
|
||||
//g_pScriptVM->ClearValue( "map" );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Update the overlay/side list(s).
|
||||
Overlay_UpdateSideLists( g_LoadingMap->m_StartMapOverlays );
|
||||
OverlayTransition_UpdateSideLists( g_LoadingMap->m_StartMapWaterOverlays );
|
||||
@@ -2781,31 +2830,31 @@ bool LoadMapFile( const char *pszFileName )
|
||||
// Fill out parallax obb matrix array
|
||||
// "i" is static so this code could account for
|
||||
// multiple LoadMapFile() calls from instances, etc.
|
||||
for (static int i = 0; i < g_nCubemapSamples; i++)
|
||||
for (int i = 0; i < g_nCubemapSamples; i++)
|
||||
{
|
||||
if (g_pParallaxObbStrs[i][0] != '\0')
|
||||
if (g_pParallaxObbStrs[i][0] != '\0' && g_pParallaxObbsDone[i] == false)
|
||||
{
|
||||
Warning( "Testing OBB string %s\n", g_pParallaxObbStrs[i] );
|
||||
|
||||
entity_t* obbEnt = NULL;
|
||||
for (int i2 = 0; i2 < g_LoadingMap->num_entities; i2++)
|
||||
{
|
||||
entity_t* obbEnt = &g_LoadingMap->entities[i2];
|
||||
if (stricmp( ValueForKey( obbEnt, "targetname" ), g_pParallaxObbStrs[i] ) != 0)
|
||||
if (stricmp( ValueForKey( &g_LoadingMap->entities[i2], "targetname" ), g_pParallaxObbStrs[i] ) != 0)
|
||||
continue;
|
||||
|
||||
if (obbEnt)
|
||||
{
|
||||
g_pParallaxObbStrs[i] = ValueForKey(obbEnt, "transformationmatrix");
|
||||
Warning( "Using OBB transformation matrix \"%s\"\n", g_pParallaxObbStrs[i] );
|
||||
}
|
||||
else
|
||||
{
|
||||
Warning( "Cannot find parallax obb \"%s\"\n", g_pParallaxObbStrs[i] );
|
||||
g_pParallaxObbStrs[i][0] = '\0';
|
||||
}
|
||||
obbEnt = &g_LoadingMap->entities[i2];
|
||||
g_pParallaxObbStrs[i] = ValueForKey(obbEnt, "transformationmatrix");
|
||||
Warning( "Using OBB transformation matrix \"%s\"\n", g_pParallaxObbStrs[i] );
|
||||
g_pParallaxObbsDone[i] = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (!obbEnt)
|
||||
{
|
||||
Warning( "Cannot find parallax obb \"%s\" (num_entities is %i)\n", g_pParallaxObbStrs[i], g_LoadingMap->num_entities );
|
||||
//g_pParallaxObbStrs[i][0] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3320,6 +3369,133 @@ ChunkFileResult_t LoadSolidKeyCallback(const char *szKey, const char *szValue, m
|
||||
}
|
||||
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
HSCRIPT CMapFile::GetScriptInstance()
|
||||
{
|
||||
if (!m_hScriptInstance)
|
||||
m_hScriptInstance = g_pScriptVM->RegisterInstance( this );
|
||||
|
||||
return m_hScriptInstance;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMapFile::ScriptGetEntityKeyValues( int idx, HSCRIPT hKeyTable, HSCRIPT hValTable )
|
||||
{
|
||||
epair_t *curPair = entities[idx].epairs;
|
||||
while (curPair)
|
||||
{
|
||||
g_pScriptVM->ArrayAppend( hKeyTable, curPair->key );
|
||||
g_pScriptVM->ArrayAppend( hValTable, curPair->value );
|
||||
|
||||
curPair = curPair->next;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
int CMapFile::ScriptAddSimpleEntityKV( HSCRIPT hKV )
|
||||
{
|
||||
if (num_entities == MAX_MAP_ENTITIES)
|
||||
{
|
||||
// Exits.
|
||||
g_MapError.ReportError ("num_entities == MAX_MAP_ENTITIES");
|
||||
return -1;
|
||||
}
|
||||
|
||||
entity_t *mapent = NULL;
|
||||
if (::num_entities > 0)
|
||||
{
|
||||
// We're not loading maps anymore. Add this to the central BSP
|
||||
mapent = &::entities[num_entities];
|
||||
::num_entities++;
|
||||
}
|
||||
else
|
||||
{
|
||||
mapent = &entities[num_entities];
|
||||
num_entities++;
|
||||
}
|
||||
|
||||
memset(mapent, 0, sizeof(*mapent));
|
||||
mapent->firstbrush = nummapbrushes;
|
||||
mapent->numbrushes = 0;
|
||||
//mapent->portalareas[0] = -1;
|
||||
//mapent->portalareas[1] = -1;
|
||||
|
||||
LoadEntity_t LoadEntity;
|
||||
LoadEntity.pEntity = mapent;
|
||||
|
||||
// No default flags/contents
|
||||
LoadEntity.nBaseFlags = 0;
|
||||
LoadEntity.nBaseContents = 0;
|
||||
|
||||
int nIterator = -1;
|
||||
ScriptVariant_t varKey, varValue;
|
||||
char szValue[256];
|
||||
while ((nIterator = g_pScriptVM->GetKeyValue( hKV, nIterator, &varKey, &varValue )) != -1)
|
||||
{
|
||||
switch (varValue.m_type)
|
||||
{
|
||||
case FIELD_CSTRING: Q_strncpy( szValue, varValue.m_pszString, sizeof(szValue) ); break;
|
||||
case FIELD_INTEGER: Q_snprintf( szValue, sizeof(szValue), "%i", varValue.m_int ); break;
|
||||
case FIELD_FLOAT: Q_snprintf( szValue, sizeof(szValue), "%f", varValue.m_float ); break;
|
||||
case FIELD_CHARACTER: Q_snprintf( szValue, sizeof( szValue ), "%c", varValue.m_char ); break;
|
||||
case FIELD_BOOLEAN: Q_snprintf( szValue, sizeof(szValue), "%d", varValue.m_bool ); break;
|
||||
case FIELD_VECTOR: Q_snprintf( szValue, sizeof(szValue), "%f %f %f", (*varValue.m_pVector).x, (*varValue.m_pVector).y, (*varValue.m_pVector).z ); break;
|
||||
default: szValue[0] = '\0'; break;
|
||||
}
|
||||
|
||||
LoadEntityKeyCallback( varKey, szValue, &LoadEntity );
|
||||
|
||||
g_pScriptVM->ReleaseValue( varKey );
|
||||
g_pScriptVM->ReleaseValue( varValue );
|
||||
}
|
||||
|
||||
return num_entities - 1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
int CMapFile::ScriptAddInstance( const char *pszVMF, const Vector& vecOrigin, const QAngle& angAngles )
|
||||
{
|
||||
if (num_entities == MAX_MAP_ENTITIES)
|
||||
{
|
||||
// Exits.
|
||||
g_MapError.ReportError ("num_entities == MAX_MAP_ENTITIES");
|
||||
return -1;
|
||||
}
|
||||
|
||||
entity_t *mapent = &entities[num_entities];
|
||||
num_entities++;
|
||||
memset(mapent, 0, sizeof(*mapent));
|
||||
mapent->firstbrush = nummapbrushes;
|
||||
mapent->numbrushes = 0;
|
||||
//mapent->portalareas[0] = -1;
|
||||
//mapent->portalareas[1] = -1;
|
||||
|
||||
SetKeyValue( mapent, "classname", "func_instance" );
|
||||
|
||||
SetKeyValue( mapent, "file", pszVMF );
|
||||
SetKeyValue( mapent, "fixup_style", "2" ); // No fixup
|
||||
|
||||
char szValue[256];
|
||||
Q_snprintf( szValue, sizeof(szValue), "%f %f %f", vecOrigin.x, vecOrigin.y, vecOrigin.z );
|
||||
SetKeyValue( mapent, "origin", szValue );
|
||||
|
||||
Q_snprintf( szValue, sizeof(szValue), "%f %f %f", angAngles.x, angAngles.y, angAngles.z );
|
||||
SetKeyValue( mapent, "angles", szValue );
|
||||
|
||||
return num_entities - 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
================
|
||||
TestExpandBrushes
|
||||
|
||||
@@ -20,6 +20,11 @@
|
||||
#include "byteswap.h"
|
||||
#include "worldvertextransitionfixup.h"
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
#include "vscript/ivscript.h"
|
||||
#include "vscript_vbsp.h"
|
||||
#endif
|
||||
|
||||
extern float g_maxLightmapDimension;
|
||||
|
||||
char source[1024];
|
||||
@@ -66,6 +71,9 @@ bool g_bNoDefaultCubemaps = true;
|
||||
bool g_bSkyboxCubemaps = false;
|
||||
int g_iDefaultCubemapSize = 32;
|
||||
#endif
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
ScriptLanguage_t g_iScripting = SL_NONE;
|
||||
#endif
|
||||
|
||||
float g_defaultLuxelSize = DEFAULT_LUXEL_SIZE;
|
||||
float g_luxelScale = 1.0f;
|
||||
@@ -1185,6 +1193,72 @@ int RunVBSP( int argc, char **argv )
|
||||
Msg( "Default cubemap size = %i\n", g_iDefaultCubemapSize );
|
||||
i++;
|
||||
}
|
||||
#endif
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
else if ( !Q_stricmp( argv[i], "-scripting" ) )
|
||||
{
|
||||
const char *pszScriptLanguage = argv[i + 1];
|
||||
if( pszScriptLanguage[0] == '-')
|
||||
{
|
||||
// It's another command. Just use default
|
||||
g_iScripting = SL_DEFAULT;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use a specific language
|
||||
if( !Q_stricmp(pszScriptLanguage, "gamemonkey") )
|
||||
{
|
||||
g_iScripting = SL_GAMEMONKEY;
|
||||
}
|
||||
else if( !Q_stricmp(pszScriptLanguage, "squirrel") )
|
||||
{
|
||||
g_iScripting = SL_SQUIRREL;
|
||||
}
|
||||
else if( !Q_stricmp(pszScriptLanguage, "python") )
|
||||
{
|
||||
g_iScripting = SL_PYTHON;
|
||||
}
|
||||
else if( !Q_stricmp(pszScriptLanguage, "lua") )
|
||||
{
|
||||
g_iScripting = SL_LUA;
|
||||
}
|
||||
else
|
||||
{
|
||||
DevWarning("-server_script does not recognize a language named '%s'. virtual machine did NOT start.\n", pszScriptLanguage );
|
||||
g_iScripting = SL_NONE;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else if ( !Q_stricmp( argv[i], "-doc" ) )
|
||||
{
|
||||
// Only print the documentation
|
||||
|
||||
if (g_iScripting)
|
||||
{
|
||||
scriptmanager = (IScriptManager*)Sys_GetFactoryThis()(VSCRIPT_INTERFACE_VERSION, NULL);
|
||||
VScriptVBSPInit();
|
||||
|
||||
const char *pszArg1 = argv[i + 1];
|
||||
if (pszArg1[0] == '-')
|
||||
{
|
||||
// It's another command. Just use *
|
||||
pszArg1 = "*";
|
||||
}
|
||||
|
||||
char szCommand[512];
|
||||
_snprintf( szCommand, sizeof( szCommand ), "PrintHelp( \"%s\" );", pszArg1 );
|
||||
g_pScriptVM->Run( szCommand );
|
||||
}
|
||||
else
|
||||
{
|
||||
Warning("Cannot print documentation without scripting enabled!\n");
|
||||
}
|
||||
|
||||
DeleteCmdLine( argc, argv );
|
||||
CmdLib_Cleanup();
|
||||
CmdLib_Exit( 1 );
|
||||
}
|
||||
#endif
|
||||
else if (argv[i][0] == '-')
|
||||
{
|
||||
@@ -1319,6 +1393,15 @@ int RunVBSP( int argc, char **argv )
|
||||
sprintf( materialPath, "%smaterials", gamedir );
|
||||
InitMaterialSystem( materialPath, CmdLib_GetFileSystemFactory() );
|
||||
Msg( "materialPath: %s\n", materialPath );
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
if (g_iScripting)
|
||||
{
|
||||
scriptmanager = (IScriptManager*)Sys_GetFactoryThis()(VSCRIPT_INTERFACE_VERSION, NULL);
|
||||
|
||||
VScriptVBSPInit();
|
||||
}
|
||||
#endif
|
||||
|
||||
// delete portal and line files
|
||||
sprintf (path, "%s.prt", source);
|
||||
@@ -1442,6 +1525,9 @@ int RunVBSP( int argc, char **argv )
|
||||
ReleasePakFileLumps();
|
||||
DeleteMaterialReplacementKeys();
|
||||
ShutdownMaterialSystem();
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
VScriptVBSPTerm();
|
||||
#endif
|
||||
CmdLib_Cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
#include "qfiles.h"
|
||||
#include "utilmatlib.h"
|
||||
#include "ChunkFile.h"
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
#include "vscript/ivscript.h"
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning( disable: 4706 )
|
||||
@@ -340,6 +343,32 @@ public:
|
||||
|
||||
int m_StartMapOverlays;
|
||||
int m_StartMapWaterOverlays;
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
HSCRIPT GetScriptInstance();
|
||||
|
||||
// VScript functions
|
||||
ALLOW_SCRIPT_ACCESS();
|
||||
private:
|
||||
|
||||
const Vector& GetMins() { return map_mins; }
|
||||
const Vector& GetMaxs() { return map_maxs; }
|
||||
|
||||
int GetNumMapBrushes() { return nummapbrushes; }
|
||||
|
||||
const Vector& GetEntityOrigin(int idx) { return (idx < num_entities && idx >= 0) ? entities[idx].origin : vec3_origin; }
|
||||
int GetEntityFirstBrush(int idx) { return (idx < num_entities && idx >= 0) ? entities[idx].firstbrush : 0; }
|
||||
int GetEntityNumBrushes(int idx) { return (idx < num_entities && idx >= 0) ? entities[idx].numbrushes : 0; }
|
||||
|
||||
void ScriptGetEntityKeyValues(int idx, HSCRIPT hKeyTable, HSCRIPT hValTable);
|
||||
|
||||
int ScriptAddSimpleEntityKV(HSCRIPT hKV/*, const Vector& vecOrigin, int iFirstBrush, int iNumBrushes*/);
|
||||
int ScriptAddInstance(const char *pszVMF, const Vector& vecOrigin, const QAngle& angAngles);
|
||||
|
||||
int GetNumEntities() { return num_entities; }
|
||||
|
||||
HSCRIPT m_hScriptInstance;
|
||||
#endif
|
||||
};
|
||||
|
||||
extern CMapFile *g_MainMap;
|
||||
|
||||
@@ -16,6 +16,8 @@ $Configuration
|
||||
{
|
||||
$AdditionalIncludeDirectories "$BASE,..\common,..\vmpi"
|
||||
$PreprocessorDefinitions "$BASE;MACRO_MATHLIB;PROTECTED_THINGS_DISABLE"
|
||||
|
||||
$PreprocessorDefinitions "$BASE;MAPBASE_VSCRIPT" [$MAPBASE_VSCRIPT]
|
||||
}
|
||||
|
||||
$Linker
|
||||
@@ -66,6 +68,14 @@ $Project "Vbsp"
|
||||
$File "worldvertextransitionfixup.cpp"
|
||||
$File "writebsp.cpp"
|
||||
$File "$SRCDIR\public\zip_utils.cpp"
|
||||
|
||||
$File "vscript_vbsp.cpp" [$MAPBASE_VSCRIPT]
|
||||
$File "vscript_vbsp.h" [$MAPBASE_VSCRIPT]
|
||||
$File "vscript_vbsp.nut" [$MAPBASE_VSCRIPT]
|
||||
$File "vscript_funcs_vmfs.cpp" [$MAPBASE_VSCRIPT]
|
||||
$File "vscript_funcs_vmfs.h" [$MAPBASE_VSCRIPT]
|
||||
$File "vscript_funcs_vis.cpp" [$MAPBASE_VSCRIPT]
|
||||
$File "vscript_funcs_vis.h" [$MAPBASE_VSCRIPT]
|
||||
|
||||
$Folder "Common Files"
|
||||
{
|
||||
@@ -179,6 +189,7 @@ $Project "Vbsp"
|
||||
$Lib mathlib
|
||||
$Lib tier2
|
||||
$Lib vtf
|
||||
$Lib vscript [$MAPBASE_VSCRIPT]
|
||||
}
|
||||
|
||||
$File "notes.txt"
|
||||
|
||||
29
sp/src/utils/vbsp/vscript_funcs_vis.cpp
Normal file
29
sp/src/utils/vbsp/vscript_funcs_vis.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "tier1/fmtstr.h"
|
||||
|
||||
#include "vbsp.h"
|
||||
#include "map.h"
|
||||
#include "fgdlib/fgdlib.h"
|
||||
|
||||
#include "vscript_vbsp.h"
|
||||
#include "vscript_funcs_vis.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// There are currently no vis-related functions, but it would be nice to have them in the future.
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void RegisterVisScriptFunctions()
|
||||
{
|
||||
//ScriptRegisterFunction( g_pScriptVM, VMFKV_CreateBlank, "Creates a CScriptKeyValues instance with VMF formatting." );
|
||||
}
|
||||
16
sp/src/utils/vbsp/vscript_funcs_vis.h
Normal file
16
sp/src/utils/vbsp/vscript_funcs_vis.h
Normal file
@@ -0,0 +1,16 @@
|
||||
//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 =================
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
|
||||
#ifndef VSCRIPT_FUNCS_VIS
|
||||
#define VSCRIPT_FUNCS_VIS
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
void RegisterVisScriptFunctions();
|
||||
|
||||
#endif
|
||||
156
sp/src/utils/vbsp/vscript_funcs_vmfs.cpp
Normal file
156
sp/src/utils/vbsp/vscript_funcs_vmfs.cpp
Normal file
@@ -0,0 +1,156 @@
|
||||
//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "tier1/fmtstr.h"
|
||||
|
||||
#include "vbsp.h"
|
||||
#include "map.h"
|
||||
#include "fgdlib/fgdlib.h"
|
||||
|
||||
#include "vscript_vbsp.h"
|
||||
#include "vscript_funcs_vmfs.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static HSCRIPT VMFKV_CreateBlank()
|
||||
{
|
||||
KeyValues *pKV = new KeyValues("VMF");
|
||||
|
||||
KeyValues *pWorld = pKV->FindKey( "world", true );
|
||||
if (pWorld)
|
||||
{
|
||||
pWorld->SetString( "classname", "worldspawn" );
|
||||
}
|
||||
|
||||
return scriptmanager->CreateScriptKeyValues( g_pScriptVM, pKV, true );
|
||||
}
|
||||
|
||||
static bool VMFKV_SaveToFile( const char *szFile, HSCRIPT hKV )
|
||||
{
|
||||
Warning( "Getting keyvalues from thing\n" );
|
||||
|
||||
KeyValues *pKV = scriptmanager->GetKeyValuesFromScriptKV( g_pScriptVM, hKV );
|
||||
if (!pKV)
|
||||
return false;
|
||||
|
||||
CUtlBuffer buf( 0, 0, CUtlBuffer::TEXT_BUFFER );
|
||||
for (KeyValues *pSubKey = pKV->GetFirstSubKey(); pSubKey; pSubKey = pSubKey->GetNextKey())
|
||||
{
|
||||
pSubKey->RecursiveSaveToFile( buf, 0 );
|
||||
}
|
||||
|
||||
char pszFullName[MAX_PATH];
|
||||
Q_ExtractFilePath( source, pszFullName, sizeof(pszFullName) );
|
||||
V_snprintf( pszFullName, sizeof(pszFullName), "%s/vscript_io/%s", pszFullName, szFile );
|
||||
|
||||
if ( !V_RemoveDotSlashes( pszFullName, CORRECT_PATH_SEPARATOR, true ) )
|
||||
{
|
||||
Warning( "Invalid file location : %s\n", szFile );
|
||||
buf.Purge();
|
||||
return false;
|
||||
}
|
||||
|
||||
int nSize = V_strlen(pszFullName) + 1;
|
||||
char *pszDir = (char*)stackalloc(nSize);
|
||||
V_memcpy( pszDir, pszFullName, nSize );
|
||||
V_StripFilename( pszDir );
|
||||
|
||||
//g_pFullFileSystem->RelativePathToFullPath( szFile, NULL, pszFullName, sizeof( pszFullName ) );
|
||||
Warning( "Full path is %s!\n", pszFullName );
|
||||
g_pFullFileSystem->CreateDirHierarchy( pszDir, NULL );
|
||||
bool res = g_pFullFileSystem->WriteFile( pszFullName, NULL, buf );
|
||||
buf.Purge();
|
||||
return res;
|
||||
}
|
||||
|
||||
static HSCRIPT VMFKV_LoadFromFile( const char *szFile )
|
||||
{
|
||||
char pszFullName[MAX_PATH];
|
||||
V_snprintf( pszFullName, sizeof(pszFullName), NULL, szFile );
|
||||
|
||||
if ( !V_RemoveDotSlashes( pszFullName, CORRECT_PATH_SEPARATOR, true ) )
|
||||
{
|
||||
DevWarning( 2, "Invalid file location : %s\n", szFile );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
KeyValues *pKV = new KeyValues( szFile );
|
||||
if ( !pKV->LoadFromFile( g_pFullFileSystem, pszFullName, NULL ) )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
HSCRIPT hScript = scriptmanager->CreateScriptKeyValues( g_pScriptVM, pKV, true ); // bAllowDestruct is supposed to automatically remove the involved KV
|
||||
|
||||
return hScript;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
inline void ScriptVarsToKV( ScriptVariant_t &varKey, ScriptVariant_t &varValue, KeyValues *pKV )
|
||||
{
|
||||
switch (varValue.m_type)
|
||||
{
|
||||
case FIELD_CSTRING: pKV->SetString( varKey.m_pszString, varValue.m_pszString ); break;
|
||||
case FIELD_INTEGER: pKV->SetInt( varKey.m_pszString, varValue.m_int ); break;
|
||||
case FIELD_FLOAT: pKV->SetFloat( varKey.m_pszString, varValue.m_float ); break;
|
||||
case FIELD_BOOLEAN: pKV->SetBool( varKey.m_pszString, varValue.m_bool ); break;
|
||||
case FIELD_VECTOR: pKV->SetString( varKey.m_pszString, CFmtStr( "%f %f %f", varValue.m_pVector->x, varValue.m_pVector->y, varValue.m_pVector->z ) ); break;
|
||||
}
|
||||
}
|
||||
|
||||
static HSCRIPT VMFKV_AddEntityFromTables( HSCRIPT hVMF, HSCRIPT hKV, HSCRIPT hIO )
|
||||
{
|
||||
KeyValues *pVMF = scriptmanager->GetKeyValuesFromScriptKV( g_pScriptVM, hVMF );
|
||||
if (!pVMF)
|
||||
return false;
|
||||
|
||||
KeyValues *pEnt = pVMF->CreateNewKey();
|
||||
if (!pEnt)
|
||||
return false;
|
||||
|
||||
pEnt->SetName( "entity" );
|
||||
|
||||
int nIterator = -1;
|
||||
ScriptVariant_t varKey, varValue;
|
||||
while ((nIterator = g_pScriptVM->GetKeyValue( hKV, nIterator, &varKey, &varValue )) != -1)
|
||||
{
|
||||
ScriptVarsToKV( varKey, varValue, pEnt );
|
||||
|
||||
g_pScriptVM->ReleaseValue( varKey );
|
||||
g_pScriptVM->ReleaseValue( varValue );
|
||||
}
|
||||
|
||||
KeyValues *pConnections = pEnt->FindKey( "connections", true );
|
||||
if (hIO && pConnections)
|
||||
{
|
||||
nIterator = -1;
|
||||
while ((nIterator = g_pScriptVM->GetKeyValue( hIO, nIterator, &varKey, &varValue )) != -1)
|
||||
{
|
||||
ScriptVarsToKV( varKey, varValue, pEnt );
|
||||
|
||||
g_pScriptVM->ReleaseValue( varKey );
|
||||
g_pScriptVM->ReleaseValue( varValue );
|
||||
}
|
||||
}
|
||||
|
||||
return scriptmanager->CreateScriptKeyValues( g_pScriptVM, pEnt, false );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void RegisterVMFScriptFunctions()
|
||||
{
|
||||
ScriptRegisterFunction( g_pScriptVM, VMFKV_CreateBlank, "Creates a CScriptKeyValues instance with VMF formatting." );
|
||||
ScriptRegisterFunction( g_pScriptVM, VMFKV_SaveToFile, "Saves a CScriptKeyValues instance with VMF formatting." );
|
||||
ScriptRegisterFunction( g_pScriptVM, VMFKV_LoadFromFile, "Loads a VMF as a CScriptKeyValues instance with VMF formatting." );
|
||||
ScriptRegisterFunction( g_pScriptVM, VMFKV_AddEntityFromTables, "Adds a VMF-formatted entity to a CScriptKeyValues instance." );
|
||||
}
|
||||
16
sp/src/utils/vbsp/vscript_funcs_vmfs.h
Normal file
16
sp/src/utils/vbsp/vscript_funcs_vmfs.h
Normal file
@@ -0,0 +1,16 @@
|
||||
//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 =================
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
|
||||
#ifndef VSCRIPT_FUNCS_VMFS
|
||||
#define VSCRIPT_FUNCS_VMFS
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
void RegisterVMFScriptFunctions();
|
||||
|
||||
#endif
|
||||
333
sp/src/utils/vbsp/vscript_vbsp.cpp
Normal file
333
sp/src/utils/vbsp/vscript_vbsp.cpp
Normal file
@@ -0,0 +1,333 @@
|
||||
//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 ============//
|
||||
//
|
||||
// Purpose: Mapbase's implementation of VScript in VBSP, allowing users to modify map compilation behavior with scripts.
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "tier1/KeyValues.h"
|
||||
#include "tier1/fmtstr.h"
|
||||
|
||||
#include "vbsp.h"
|
||||
#include "map.h"
|
||||
#include "fgdlib/fgdlib.h"
|
||||
|
||||
#include "vscript_vbsp.h"
|
||||
#include "vscript_vbsp.nut"
|
||||
#include "vscript_funcs_vmfs.h"
|
||||
#include "vscript_funcs_vis.h"
|
||||
|
||||
IScriptVM *g_pScriptVM;
|
||||
IScriptManager *scriptmanager = NULL;
|
||||
|
||||
extern ScriptLanguage_t g_iScripting;
|
||||
|
||||
extern ScriptClassDesc_t * GetScriptDesc( CBaseEntity * );
|
||||
|
||||
// #define VMPROFILE 1
|
||||
|
||||
#ifdef VMPROFILE
|
||||
|
||||
#define VMPROF_START float debugStartTime = Plat_FloatTime();
|
||||
#define VMPROF_SHOW( funcname, funcdesc ) DevMsg("***VSCRIPT PROFILE***: %s %s: %6.4f milliseconds\n", (##funcname), (##funcdesc), (Plat_FloatTime() - debugStartTime)*1000.0 );
|
||||
|
||||
#else // !VMPROFILE
|
||||
|
||||
#define VMPROF_START
|
||||
#define VMPROF_SHOW
|
||||
|
||||
#endif // VMPROFILE
|
||||
|
||||
// This is to ensure a dependency exists between the vscript library and the game DLLs
|
||||
extern int vscript_token;
|
||||
int vscript_token_hack = vscript_token;
|
||||
|
||||
HSCRIPT VScriptCompileScript( const char *pszScriptName, bool bWarnMissing )
|
||||
{
|
||||
if ( !g_pScriptVM )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *pszExtensions[] =
|
||||
{
|
||||
"", // SL_NONE
|
||||
".gm", // SL_GAMEMONKEY
|
||||
".nut", // SL_SQUIRREL
|
||||
".lua", // SL_LUA
|
||||
".py", // SL_PYTHON
|
||||
};
|
||||
|
||||
const char *pszVMExtension = pszExtensions[g_pScriptVM->GetLanguage()];
|
||||
const char *pszIncomingExtension = V_strrchr( pszScriptName , '.' );
|
||||
if ( pszIncomingExtension && V_strcmp( pszIncomingExtension, pszVMExtension ) != 0 )
|
||||
{
|
||||
Warning( "Script file type does not match VM type\n" );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CFmtStr scriptPath;
|
||||
if ( pszIncomingExtension )
|
||||
{
|
||||
scriptPath = pszScriptName;
|
||||
}
|
||||
else
|
||||
{
|
||||
scriptPath.sprintf( "%s%s", pszScriptName, pszVMExtension );
|
||||
}
|
||||
|
||||
const char *pBase;
|
||||
CUtlBuffer bufferScript;
|
||||
|
||||
if ( g_pScriptVM->GetLanguage() == SL_PYTHON )
|
||||
{
|
||||
// python auto-loads raw or precompiled modules - don't load data here
|
||||
pBase = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
FileFindHandle_t handle = NULL;
|
||||
const char *file = g_pFullFileSystem->FindFirst( "*", &handle );
|
||||
while (file)
|
||||
{
|
||||
Msg( "File in this directory: %s\n", file );
|
||||
file = g_pFullFileSystem->FindNext(handle);
|
||||
}
|
||||
|
||||
Msg( "File exists: %d\n", g_pFullFileSystem->FileExists( scriptPath ) );
|
||||
*/
|
||||
|
||||
|
||||
bool bResult = g_pFullFileSystem->ReadFile( scriptPath, NULL, bufferScript );
|
||||
|
||||
if ( !bResult && bWarnMissing )
|
||||
{
|
||||
Warning( "Script not found (%s) \n", scriptPath.operator const char *() );
|
||||
Assert( "Error running script" );
|
||||
}
|
||||
|
||||
pBase = (const char *) bufferScript.Base();
|
||||
|
||||
if ( !pBase || !*pBase )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const char *pszFilename = V_strrchr( scriptPath, '\\' );
|
||||
pszFilename++;
|
||||
HSCRIPT hScript = g_pScriptVM->CompileScript( pBase, pszFilename );
|
||||
if ( !hScript )
|
||||
{
|
||||
Warning( "FAILED to compile and execute script file named %s\n", scriptPath.operator const char *() );
|
||||
Assert( "Error running script" );
|
||||
}
|
||||
return hScript;
|
||||
}
|
||||
|
||||
static int g_ScriptVBSPRunScriptDepth;
|
||||
|
||||
bool VScriptRunScript( const char *pszScriptName, HSCRIPT hScope, bool bWarnMissing )
|
||||
{
|
||||
if ( !g_pScriptVM )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !pszScriptName || !*pszScriptName )
|
||||
{
|
||||
Warning( "Cannot run script: NULL script name\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Prevent infinite recursion in VM
|
||||
if ( g_ScriptVBSPRunScriptDepth > 16 )
|
||||
{
|
||||
Warning( "IncludeScript stack overflow\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
g_ScriptVBSPRunScriptDepth++;
|
||||
HSCRIPT hScript = VScriptCompileScript( pszScriptName, bWarnMissing );
|
||||
bool bSuccess = false;
|
||||
if ( hScript )
|
||||
{
|
||||
bSuccess = ( g_pScriptVM->Run( hScript, hScope ) != SCRIPT_ERROR );
|
||||
if ( !bSuccess )
|
||||
{
|
||||
Warning( "Error running script named %s\n", pszScriptName );
|
||||
Assert( "Error running script" );
|
||||
}
|
||||
}
|
||||
g_ScriptVBSPRunScriptDepth--;
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
BEGIN_SCRIPTDESC_ROOT( CMapFile, "Map file" )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetMins, "Get the map's mins." )
|
||||
DEFINE_SCRIPTFUNC( GetMaxs, "Get the map's maxs." )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetEntityOrigin, "Get the origin of the entity with the specified index." )
|
||||
DEFINE_SCRIPTFUNC( GetEntityFirstBrush, "Get the first brush ID of the entity with the specified index." )
|
||||
DEFINE_SCRIPTFUNC( GetEntityNumBrushes, "Get the number of brushes in the entity with the specified index." )
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetEntityKeyValues, "GetEntityKeyValues", "Export an entity's keyvalues to two arrays." )
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptAddSimpleEntityKV, "AddSimpleEntityKV", "Add a simple entity from a keyvalue table." )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptAddInstance, "AddInstance", "Add an instance to the map." )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetNumEntities, "Get the number of entities in the map." )
|
||||
|
||||
END_SCRIPTDESC();
|
||||
|
||||
static const char *GetSource()
|
||||
{
|
||||
return source;
|
||||
}
|
||||
|
||||
static const char *GetMapBase()
|
||||
{
|
||||
return mapbase;
|
||||
}
|
||||
|
||||
static HSCRIPT GetMainMap()
|
||||
{
|
||||
return g_MainMap ? g_MainMap->GetScriptInstance() : NULL;
|
||||
}
|
||||
|
||||
static HSCRIPT GetLoadingMap()
|
||||
{
|
||||
return g_LoadingMap ? g_LoadingMap->GetScriptInstance() : NULL;
|
||||
}
|
||||
|
||||
static const char *DoUniqueString( const char *pszBase )
|
||||
{
|
||||
static char szBuf[512];
|
||||
g_pScriptVM->GenerateUniqueKey( pszBase, szBuf, ARRAYSIZE(szBuf) );
|
||||
return szBuf;
|
||||
}
|
||||
|
||||
bool DoIncludeScript( const char *pszScript, HSCRIPT hScope )
|
||||
{
|
||||
if ( !VScriptRunScript( pszScript, hScope, true ) )
|
||||
{
|
||||
g_pScriptVM->RaiseException( CFmtStr( "Failed to include script \"%s\"", ( pszScript ) ? pszScript : "unknown" ) );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
extern qboolean glview;
|
||||
extern qboolean onlyents;
|
||||
extern bool onlyprops;
|
||||
extern qboolean noleaktest;
|
||||
extern qboolean verboseentities;
|
||||
extern qboolean g_bLowPriority;
|
||||
extern bool g_bKeepStaleZip;
|
||||
extern bool g_bNoDefaultCubemaps;
|
||||
extern bool g_bSkyboxCubemaps;
|
||||
extern int g_iDefaultCubemapSize;
|
||||
|
||||
bool VScriptVBSPInit()
|
||||
{
|
||||
VMPROF_START
|
||||
|
||||
if( g_iScripting != SL_NONE && scriptmanager != NULL )
|
||||
{
|
||||
if ( g_pScriptVM == NULL )
|
||||
g_pScriptVM = scriptmanager->CreateVM( g_iScripting );
|
||||
|
||||
if( g_pScriptVM )
|
||||
{
|
||||
Log( "VSCRIPT VBSP: Started VScript virtual machine using script language '%s'\n", g_pScriptVM->GetLanguageName() );
|
||||
|
||||
ScriptRegisterFunction( g_pScriptVM, GetSource, "Gets the base directory of the first map loaded." );
|
||||
ScriptRegisterFunction( g_pScriptVM, GetMapBase, "Gets the base name of the first map loaded." );
|
||||
ScriptRegisterFunction( g_pScriptVM, GetMainMap, "Gets the first map loaded." );
|
||||
ScriptRegisterFunction( g_pScriptVM, GetLoadingMap, "Gets the map which is currently loading (e.g. an instance)." );
|
||||
|
||||
ScriptRegisterFunction( g_pScriptVM, DoUniqueString, SCRIPT_ALIAS( "UniqueString", "Generate a string guaranteed to be unique across the life of the script VM, with an optional root string. Useful for adding data to tables when not sure what keys are already in use in that table." ) );
|
||||
ScriptRegisterFunction( g_pScriptVM, DoIncludeScript, "Execute a script (internal)" );
|
||||
|
||||
ScriptRegisterConstantNamed( g_pScriptVM, GameData::NAME_FIXUP_PREFIX, "NAME_FIXUP_PREFIX", "Prefix name fixup" );
|
||||
ScriptRegisterConstantNamed( g_pScriptVM, GameData::NAME_FIXUP_POSTFIX, "NAME_FIXUP_PREFIX", "Postfix name fixup" );
|
||||
ScriptRegisterConstantNamed( g_pScriptVM, GameData::NAME_FIXUP_NONE, "NAME_FIXUP_NONE", "No name fixup" );
|
||||
|
||||
ScriptRegisterConstant( g_pScriptVM, microvolume, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, noprune, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, glview, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, nodetail, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, fulldetail, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, onlyents, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, onlyprops, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, nomerge, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, nomergewater, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, nowater, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, nocsg, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, noweld, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, noshare, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, nosubdiv, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, notjunc, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, noopt, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, noleaktest, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, verboseentities, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, dumpcollide, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, g_bLowPriority, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, g_DumpStaticProps, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, g_bSkyVis, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, g_bLightIfMissing, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, g_snapAxialPlanes, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, g_bKeepStaleZip, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, g_NodrawTriggers, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, g_DisableWaterLighting, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, g_bAllowDetailCracks, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, g_bNoVirtualMesh, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, g_bNoHiddenManifestMaps, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, g_bNoDefaultCubemaps, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, g_bSkyboxCubemaps, "" );
|
||||
ScriptRegisterConstant( g_pScriptVM, g_iDefaultCubemapSize, "" );
|
||||
|
||||
if (g_iScripting == SL_SQUIRREL)
|
||||
{
|
||||
g_pScriptVM->Run( g_Script_vscript_vbsp );
|
||||
}
|
||||
|
||||
RegisterVMFScriptFunctions();
|
||||
|
||||
// Run the map's script
|
||||
char script[96];
|
||||
Q_snprintf( script, sizeof(script), "%s_vbsp", source );
|
||||
//Msg("VBSP script: \"%s\"\n", script);
|
||||
VScriptRunScript( script, true );
|
||||
|
||||
VMPROF_SHOW( g_iScripting, "virtual machine startup" );
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
DevWarning("VM Did not start!\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log( "\nVSCRIPT: Scripting is disabled.\n" );
|
||||
}
|
||||
g_pScriptVM = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
void VScriptVBSPTerm()
|
||||
{
|
||||
if( g_pScriptVM != NULL )
|
||||
{
|
||||
if( g_pScriptVM )
|
||||
{
|
||||
scriptmanager->DestroyVM( g_pScriptVM );
|
||||
g_pScriptVM = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
27
sp/src/utils/vbsp/vscript_vbsp.h
Normal file
27
sp/src/utils/vbsp/vscript_vbsp.h
Normal file
@@ -0,0 +1,27 @@
|
||||
//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 ============//
|
||||
//
|
||||
// Purpose: Mapbase's implementation of VScript in VBSP, allowing users to modify map compilation behavior with scripts.
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef VSCRIPT_VBSP_H
|
||||
#define VSCRIPT_VBSP_H
|
||||
|
||||
#include "vscript/ivscript.h"
|
||||
|
||||
#if defined( _WIN32 )
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
extern IScriptVM *g_pScriptVM;
|
||||
extern IScriptManager *scriptmanager;
|
||||
|
||||
HSCRIPT VScriptCompileScript( const char *pszScriptName, bool bWarnMissing = false );
|
||||
bool VScriptRunScript( const char *pszScriptName, HSCRIPT hScope, bool bWarnMissing = false );
|
||||
inline bool VScriptRunScript( const char *pszScriptName, bool bWarnMissing = false ) { return VScriptRunScript( pszScriptName, NULL, bWarnMissing ); }
|
||||
|
||||
bool VScriptVBSPInit();
|
||||
void VScriptVBSPTerm();
|
||||
|
||||
#endif // VSCRIPT_SERVER_H
|
||||
52
sp/src/utils/vbsp/vscript_vbsp.nut
Normal file
52
sp/src/utils/vbsp/vscript_vbsp.nut
Normal file
@@ -0,0 +1,52 @@
|
||||
static char g_Script_vscript_vbsp[] = R"vscript(
|
||||
//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
function UniqueString( string = "" )
|
||||
{
|
||||
return ::DoUniqueString( string.tostring() );
|
||||
}
|
||||
|
||||
function __ReplaceClosures( script, scope )
|
||||
{
|
||||
if ( !scope )
|
||||
{
|
||||
scope = getroottable();
|
||||
}
|
||||
|
||||
local tempParent = { getroottable = function() { return null; } };
|
||||
local temp = { runscript = script };
|
||||
temp.set_delegate(tempParent);
|
||||
|
||||
temp.runscript()
|
||||
foreach( key,val in temp )
|
||||
{
|
||||
if ( typeof(val) == "function" && key != "runscript" )
|
||||
{
|
||||
printl( " Replacing " + key );
|
||||
scope[key] <- val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function IncludeScript( name, scope = null )
|
||||
{
|
||||
if ( !scope )
|
||||
{
|
||||
scope = this;
|
||||
}
|
||||
return ::DoIncludeScript( name, scope );
|
||||
}
|
||||
|
||||
// VBSP logs don't support ConColorMsg()
|
||||
print <- Msg
|
||||
|
||||
function printdoc( text )
|
||||
{
|
||||
return ::print(text + "\n");
|
||||
}
|
||||
|
||||
)vscript";
|
||||
Reference in New Issue
Block a user