Skip to content

Commit 60bffb8

Browse files
committed
Add various missing functions from TF2 SDK
1 parent 09cc11f commit 60bffb8

7 files changed

Lines changed: 261 additions & 10 deletions

File tree

src/game/server/netpropmanager.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
// memdbgon must be the last include file in a .cpp file!!!
1717
#include "tier0/memdbgon.h"
1818

19-
#ifndef MAPBASE_VSCRIPT
20-
2119
extern void SendProxy_StringT_To_String( const SendProp *pProp, const void *pStruct, const void *pVarData, DVariant *pOut, int iElement, int objectID );
2220
extern ISaveRestoreOps* ActivityDataOps();
2321

@@ -27,6 +25,7 @@ const char *ArrayElementNameForIdx( size_t i )
2725
return DT_ArrayElementNameForIdx( i );
2826
}
2927

28+
#ifndef MAPBASE_VSCRIPT
3029
//-----------------------------------------------------------------------------
3130
CNetPropManager::~CNetPropManager()
3231
{
@@ -1076,6 +1075,7 @@ bool CNetPropManager::GetPropInfo( HSCRIPT hEnt, const char *pszProperty, int el
10761075

10771076
return true;
10781077
}
1078+
#endif
10791079

10801080

10811081
//-----------------------------------------------------------------------------
@@ -1390,4 +1390,3 @@ void CNetPropManager::GetTable( HSCRIPT hEnt, int iPropType, HSCRIPT hTable )
13901390
CollectNestedDataMaps( pDataMap, pBaseEntity, 0, hTable );
13911391
}
13921392
}
1393-
#endif

src/game/server/netpropmanager.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
#pragma once
1414
#endif
1515

16-
#ifndef MAPBASE_VSCRIPT
1716
#include "dt_send.h"
1817
#include "datamap.h"
1918

2019
// Gets and sets SendTable/DataMap netprops and caches results
2120
class CNetPropManager
2221
{
22+
#ifndef MAPBASE_VSCRIPT
2323
public:
2424
~CNetPropManager();
2525

@@ -72,6 +72,7 @@ class CNetPropManager
7272

7373
// Searches a ServerClass's SendTable and datamap and returns pertinent prop info
7474
inline PropInfo_t GetEntityPropInfo( CBaseEntity *pBaseEntity, const char *pstrProperty, int element );
75+
#endif
7576

7677
// Gets the value of a SendProp and stores it in a table
7778
inline void StoreSendPropValue( SendProp *pSendProp, CBaseEntity *pBaseEntity, int iOffset, int iElement, HSCRIPT hTable );
@@ -85,6 +86,13 @@ class CNetPropManager
8586
// Iterates through the DataMap and stores prop names in a table
8687
inline void CollectNestedDataMaps( datamap_t *pMap, CBaseEntity *pBaseEntity, int iOffset, HSCRIPT hTable );
8788

89+
#ifdef MAPBASE_VSCRIPT
90+
91+
public:
92+
// Fills in a passed table with all SendProps or DataMaps for the provided entity
93+
void GetTable( HSCRIPT hEnt, int iPropType, HSCRIPT hTable );
94+
95+
#else
8896

8997
private:
9098

@@ -184,8 +192,8 @@ class CNetPropManager
184192

185193
// Fills in a passed table with property info for the provided entity
186194
bool GetPropInfo( HSCRIPT hEnt, const char *pstrProperty, int element, HSCRIPT hTable );
187-
};
188195
#endif
196+
};
189197

190198

191199
#endif // NETPROPMANAGER_H

src/game/server/vscript_server.nut

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ function PrecacheOther( a, b = "" )
8383
return PrecacheOther( a, b )
8484
}
8585

86+
function PrecacheEntityFromTable( a, b = null )
87+
{
88+
if ( b == null )
89+
{
90+
// Table only
91+
return DoPrecacheEntityFromTable( a.classname, a )
92+
}
93+
else
94+
{
95+
// Classname + table
96+
return DoPrecacheEntityFromTable( a, b )
97+
}
98+
}
99+
86100
function __ReplaceClosures( script, scope )
87101
{
88102
if ( !scope )

src/game/shared/basecombatweapon_shared.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3200,8 +3200,8 @@ BEGIN_ENT_SCRIPTDESC( CBaseCombatWeapon, BASECOMBATWEAPON_DERIVED_FROM, "The bas
32003200
DEFINE_SCRIPTFUNC( GetWeight, "Get the weapon's weight." )
32013201
DEFINE_SCRIPTFUNC( GetPrintName, "" )
32023202

3203-
DEFINE_SCRIPTFUNC_CL( GetSlot, "" )
3204-
DEFINE_SCRIPTFUNC_CL( GetPosition, "" )
3203+
DEFINE_SCRIPTFUNC( GetSlot, "" )
3204+
DEFINE_SCRIPTFUNC( GetPosition, "" )
32053205

32063206
DEFINE_SCRIPTFUNC( CanBePickedUpByNPCs, "Check if the weapon can be picked up by NPCs." )
32073207

src/game/shared/mapbase/vscript_funcs_shared.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ void RegisterSharedScriptFunctions()
975975

976976
#ifndef CLIENT_DLL
977977
ScriptRegisterFunction( g_pScriptVM, AddThinkToEnt, "This will put a think function onto an entity, or pass null to remove it. This is NOT chained, so be careful." );
978-
ScriptRegisterFunction( g_pScriptVM, PrecacheEntityFromTable, "Precache an entity from KeyValues in a table." );
978+
ScriptRegisterFunctionNamed( g_pScriptVM, PrecacheEntityFromTable, "DoPrecacheEntityFromTable", SCRIPT_ALIAS( "PrecacheEntityFromTable", "Precache an entity from KeyValues in a table." ) );
979979
ScriptRegisterFunction( g_pScriptVM, SpawnEntityFromTable, "Native function for entity spawning." );
980980
#endif // !CLIENT_DLL
981981
ScriptRegisterFunction( g_pScriptVM, EntIndexToHScript, "Returns the script handle for the given entity index." );

src/game/shared/mapbase/vscript_singletons.cpp

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#if !defined(NO_STEAM)
4242
#include "steam/steam_api.h"
4343
#endif
44+
#else
45+
#include "netpropmanager.h"
4446
#endif
4547

4648
#include "vscript_singletons.h"
@@ -103,6 +105,18 @@ extern ISaveRestoreOps* GetStdStringDataOps();
103105
#endif
104106
#endif
105107

108+
#ifndef CLIENT_DLL
109+
// This is a smaller version of the stock net prop manager which has functions we need
110+
CNetPropManager g_ScriptNetPropManagerStub;
111+
#endif
112+
113+
// Copied from netpropmanager.cpp
114+
const char *s_pszBannedNetProps[]
115+
{
116+
"EntityQuality",
117+
"AccountID",
118+
};
119+
106120
//=============================================================================
107121
// Net Prop Manager
108122
// Based on L4D2 API
@@ -461,6 +475,16 @@ class CScriptNetPropManager
461475
// CPlayerResource::m_iHealth and CBaseEntity::m_iHealth
462476
varinfo_t *GetVarInfo( CBaseEntity *pEnt, const char *szProp, int index )
463477
{
478+
// Copied from netpropmanager.cpp
479+
for ( int i = 0; i < ARRAYSIZE( s_pszBannedNetProps ); i++ )
480+
{
481+
if ( V_stristr( szProp, s_pszBannedNetProps[ i ] ) != NULL)
482+
{
483+
// Replace any banned properties with a dummy string.
484+
szProp = "Y6WP5EH4I45F2LMKSDY2";
485+
}
486+
}
487+
464488
int offset = 0;
465489
NetTable *pTable = GetNetTable( GetNetworkClass( pEnt ) );
466490
NetProp *pProp = FindInNetTable( (char*)pEnt, pTable, szProp, &offset );
@@ -1615,6 +1639,16 @@ class CScriptNetPropManager
16151639
}
16161640
}
16171641

1642+
bool GetPropBoolArray( HSCRIPT hEnt, const char *szProp, int index )
1643+
{
1644+
return (bool)GetPropIntArray( hEnt, szProp, index );
1645+
}
1646+
1647+
void SetPropBoolArray( HSCRIPT hEnt, const char *szProp, bool value, int index )
1648+
{
1649+
SetPropIntArray( hEnt, szProp, (int)value, index );
1650+
}
1651+
16181652
#define GetProp( type, name )\
16191653
type GetProp##name( HSCRIPT hEnt, const char* szProp )\
16201654
{\
@@ -1629,6 +1663,8 @@ class CScriptNetPropManager
16291663

16301664
GetProp( int, Int );
16311665
SetProp( int, Int );
1666+
GetProp( bool, Bool );
1667+
SetProp( bool, Bool );
16321668
GetProp( float, Float );
16331669
SetProp( float, Float );
16341670
GetProp( HSCRIPT, Entity );
@@ -1641,6 +1677,62 @@ class CScriptNetPropManager
16411677
#undef GetProp
16421678
#undef SetProp
16431679

1680+
//-----------------------------------------------------------------------------
1681+
// Adapted from netpropmanager.cpp
1682+
//-----------------------------------------------------------------------------
1683+
bool GetPropInfo( HSCRIPT hEnt, const char *szProp, int index, HSCRIPT hTable )
1684+
{
1685+
CBaseEntity *pEnt = ToEnt( hEnt );
1686+
if ( !pEnt )
1687+
return false;
1688+
1689+
varinfo_t *pInfo = CacheFetch( pEnt, szProp );
1690+
if ( !pInfo )
1691+
{
1692+
pInfo = GetVarInfo( pEnt, szProp, INDEX_GET_TYPE );
1693+
1694+
if ( !pInfo )
1695+
return false;
1696+
}
1697+
1698+
g_pScriptVM->SetValue( hTable, "is_sendprop", !pInfo->isNotNetworked );
1699+
g_pScriptVM->SetValue( hTable, "type", pInfo->datatype );
1700+
1701+
int size = 0;
1702+
if ( pInfo->datatype == types::_STRING_T || pInfo->datatype == types::_CSTRING || pInfo->datatype == types::_INT8 )
1703+
{
1704+
size = pInfo->stringsize;
1705+
}
1706+
else
1707+
{
1708+
// Revert MASK_INT_SIZE to get original size
1709+
int bits = pInfo->mask;
1710+
while (bits > 0)
1711+
{
1712+
bits >>= 1;
1713+
size++;
1714+
}
1715+
}
1716+
1717+
// TODO: pInfo->arraysize stores both GetNumElements() and GetNumProps()
1718+
g_pScriptVM->SetValue( hTable, "bits", size );
1719+
g_pScriptVM->SetValue( hTable, "elements", pInfo->arraysize );
1720+
g_pScriptVM->SetValue( hTable, "offset", pInfo->GetOffset( index ) );
1721+
g_pScriptVM->SetValue( hTable, "length", pInfo->arraysize );
1722+
g_pScriptVM->SetValue( hTable, "array_props", pInfo->elemsize );
1723+
g_pScriptVM->SetValue( hTable, "flags", pInfo->isUnsigned ? SPROP_UNSIGNED : 0 ); // TODO: Proper flag storage?
1724+
1725+
return true;
1726+
}
1727+
1728+
#ifndef CLIENT_DLL
1729+
void GetTable( HSCRIPT hEnt, int iPropType, HSCRIPT hTable )
1730+
{
1731+
// To avoid copying a bunch of code, we keep a piece of the original net prop manager around for this
1732+
g_ScriptNetPropManagerStub.GetTable( hEnt, iPropType, hTable );
1733+
}
1734+
#endif
1735+
16441736
#ifdef _DEBUG
16451737
private:
16461738
CUtlBuffer m_output;
@@ -2541,9 +2633,19 @@ BEGIN_SCRIPTDESC_ROOT_NAMED( CScriptNetPropManager, "CNetPropManager", SCRIPT_SI
25412633
DEFINE_SCRIPTFUNC( SetPropStringArray, "Sets a string in an array." )
25422634
DEFINE_SCRIPTFUNC( SetPropVector, "Sets to the specified vector." )
25432635
DEFINE_SCRIPTFUNC( SetPropVectorArray, "Sets a 3D vector in an array." )
2636+
DEFINE_SCRIPTFUNC( GetPropInfo, "Fills in a passed table with property info for the provided entity." )
2637+
#ifndef CLIENT_DLL
2638+
DEFINE_SCRIPTFUNC( GetTable, "Fills in a passed table with all props of a specified type for the provided entity (set prop_type to 0 for SendTable or 1 for DataMap)." )
2639+
#endif
25442640
#ifdef _DEBUG
25452641
DEFINE_SCRIPTFUNC( Dump, "Dump all readable netprop and datafield values of this entity. Pass in file name to write into." );
25462642
#endif
2643+
2644+
// TF2 SDK compatibility
2645+
DEFINE_SCRIPTFUNC( GetPropBool, SCRIPT_HIDE )
2646+
DEFINE_SCRIPTFUNC( GetPropBoolArray, SCRIPT_HIDE )
2647+
DEFINE_SCRIPTFUNC( SetPropBool, SCRIPT_HIDE )
2648+
DEFINE_SCRIPTFUNC( SetPropBoolArray, SCRIPT_HIDE )
25472649
END_SCRIPTDESC();
25482650

25492651
//=============================================================================
@@ -5016,6 +5118,11 @@ class CScriptConvarAccessor : public CAutoGameSystem
50165118
GameRules()->SaveConvar( cvar );
50175119
}
50185120

5121+
bool IsConVarOnAllowList( const char *pszConVar )
5122+
{
5123+
return !IsBlockedConvar( pszConVar );
5124+
}
5125+
50195126
} g_ScriptConvarAccessor;
50205127

50215128

@@ -5233,6 +5340,7 @@ BEGIN_SCRIPTDESC_ROOT_NAMED( CScriptConvarAccessor, "CConvars", SCRIPT_SINGLETON
52335340
DEFINE_SCRIPTFUNC( SetBool, "Sets the value of the convar as a bool." )
52345341
DEFINE_SCRIPTFUNC( SetStr, "Sets the value of the convar as a string." )
52355342
DEFINE_SCRIPTFUNC_NAMED( SetVariant, "SetValue", "Sets the value of the convar with any applicable type." )
5343+
DEFINE_SCRIPTFUNC( IsConVarOnAllowList, "Checks if the cvar is allowed to be changed." )
52365344
END_SCRIPTDESC();
52375345

52385346

0 commit comments

Comments
 (0)