Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/game/server/netpropmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

#ifndef MAPBASE_VSCRIPT

extern void SendProxy_StringT_To_String( const SendProp *pProp, const void *pStruct, const void *pVarData, DVariant *pOut, int iElement, int objectID );
extern ISaveRestoreOps* ActivityDataOps();

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

#ifndef MAPBASE_VSCRIPT
//-----------------------------------------------------------------------------
CNetPropManager::~CNetPropManager()
{
Expand Down Expand Up @@ -1076,6 +1075,7 @@ bool CNetPropManager::GetPropInfo( HSCRIPT hEnt, const char *pszProperty, int el

return true;
}
#endif


//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1390,4 +1390,3 @@ void CNetPropManager::GetTable( HSCRIPT hEnt, int iPropType, HSCRIPT hTable )
CollectNestedDataMaps( pDataMap, pBaseEntity, 0, hTable );
}
}
#endif
12 changes: 10 additions & 2 deletions src/game/server/netpropmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
#pragma once
#endif

#ifndef MAPBASE_VSCRIPT
#include "dt_send.h"
#include "datamap.h"

// Gets and sets SendTable/DataMap netprops and caches results
class CNetPropManager
{
#ifndef MAPBASE_VSCRIPT
public:
~CNetPropManager();

Expand Down Expand Up @@ -72,6 +72,7 @@ class CNetPropManager

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

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

#ifdef MAPBASE_VSCRIPT

public:
// Fills in a passed table with all SendProps or DataMaps for the provided entity
void GetTable( HSCRIPT hEnt, int iPropType, HSCRIPT hTable );

#else

private:

Expand Down Expand Up @@ -184,8 +192,8 @@ class CNetPropManager

// Fills in a passed table with property info for the provided entity
bool GetPropInfo( HSCRIPT hEnt, const char *pstrProperty, int element, HSCRIPT hTable );
};
#endif
};


#endif // NETPROPMANAGER_H
14 changes: 14 additions & 0 deletions src/game/server/vscript_server.nut
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ function PrecacheOther( a, b = "" )
return PrecacheOther( a, b )
}

function PrecacheEntityFromTable( a, b = null )
{
if ( b == null )
{
// Table only
return DoPrecacheEntityFromTable( a.classname, a )
}
else
{
// Classname + table
return DoPrecacheEntityFromTable( a, b )
}
}

function __ReplaceClosures( script, scope )
{
if ( !scope )
Expand Down
4 changes: 2 additions & 2 deletions src/game/shared/basecombatweapon_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3200,8 +3200,8 @@ BEGIN_ENT_SCRIPTDESC( CBaseCombatWeapon, BASECOMBATWEAPON_DERIVED_FROM, "The bas
DEFINE_SCRIPTFUNC( GetWeight, "Get the weapon's weight." )
DEFINE_SCRIPTFUNC( GetPrintName, "" )

DEFINE_SCRIPTFUNC_CL( GetSlot, "" )
DEFINE_SCRIPTFUNC_CL( GetPosition, "" )
DEFINE_SCRIPTFUNC( GetSlot, "" )
DEFINE_SCRIPTFUNC( GetPosition, "" )

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

Expand Down
2 changes: 1 addition & 1 deletion src/game/shared/mapbase/vscript_funcs_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ void RegisterSharedScriptFunctions()

#ifndef CLIENT_DLL
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." );
ScriptRegisterFunction( g_pScriptVM, PrecacheEntityFromTable, "Precache an entity from KeyValues in a table." );
ScriptRegisterFunctionNamed( g_pScriptVM, PrecacheEntityFromTable, "DoPrecacheEntityFromTable", SCRIPT_ALIAS( "PrecacheEntityFromTable", "Precache an entity from KeyValues in a table." ) );
ScriptRegisterFunction( g_pScriptVM, SpawnEntityFromTable, "Native function for entity spawning." );
#endif // !CLIENT_DLL
ScriptRegisterFunction( g_pScriptVM, EntIndexToHScript, "Returns the script handle for the given entity index." );
Expand Down
108 changes: 108 additions & 0 deletions src/game/shared/mapbase/vscript_singletons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#if !defined(NO_STEAM)
#include "steam/steam_api.h"
#endif
#else
#include "netpropmanager.h"
#endif

#include "vscript_singletons.h"
Expand Down Expand Up @@ -103,6 +105,18 @@ extern ISaveRestoreOps* GetStdStringDataOps();
#endif
#endif

#ifndef CLIENT_DLL
// This is a smaller version of the stock net prop manager which has functions we need
CNetPropManager g_ScriptNetPropManagerStub;
#endif

// Copied from netpropmanager.cpp
const char *s_pszBannedNetProps[]
{
"EntityQuality",
"AccountID",
Comment on lines +116 to +117

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be within #ifdef TF so that other games don't unnecessarily check for them.

And I'm wondering, why are these partial lookups? Why not just m_iEntityQuality, m_iAccountID and strcmp == 0?

};

//=============================================================================
// Net Prop Manager
// Based on L4D2 API
Expand Down Expand Up @@ -461,6 +475,16 @@ class CScriptNetPropManager
// CPlayerResource::m_iHealth and CBaseEntity::m_iHealth
varinfo_t *GetVarInfo( CBaseEntity *pEnt, const char *szProp, int index )
{
// Copied from netpropmanager.cpp
for ( int i = 0; i < ARRAYSIZE( s_pszBannedNetProps ); i++ )
{
if ( V_stristr( szProp, s_pszBannedNetProps[ i ] ) != NULL)
{
// Replace any banned properties with a dummy string.
szProp = "Y6WP5EH4I45F2LMKSDY2";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What even is the point of this? Looks like a convoluted way to return null. Just return null

}
}

int offset = 0;
NetTable *pTable = GetNetTable( GetNetworkClass( pEnt ) );
NetProp *pProp = FindInNetTable( (char*)pEnt, pTable, szProp, &offset );
Expand Down Expand Up @@ -1615,6 +1639,16 @@ class CScriptNetPropManager
}
}

bool GetPropBoolArray( HSCRIPT hEnt, const char *szProp, int index )
{
return (bool)GetPropIntArray( hEnt, szProp, index );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should return GetPropIntArray == 1. In netpropmanager.cpp, it returns false for invalid props, which would return true here. They also check int size but I don't think that's necessary.

}

void SetPropBoolArray( HSCRIPT hEnt, const char *szProp, bool value, int index )
{
SetPropIntArray( hEnt, szProp, (int)value, index );
}

#define GetProp( type, name )\
type GetProp##name( HSCRIPT hEnt, const char* szProp )\
{\
Expand All @@ -1629,6 +1663,8 @@ class CScriptNetPropManager

GetProp( int, Int );
SetProp( int, Int );
GetProp( bool, Bool );
SetProp( bool, Bool );
GetProp( float, Float );
SetProp( float, Float );
GetProp( HSCRIPT, Entity );
Expand All @@ -1641,6 +1677,62 @@ class CScriptNetPropManager
#undef GetProp
#undef SetProp

//-----------------------------------------------------------------------------
// Adapted from netpropmanager.cpp
//-----------------------------------------------------------------------------
bool GetPropInfo( HSCRIPT hEnt, const char *szProp, int index, HSCRIPT hTable )
{
CBaseEntity *pEnt = ToEnt( hEnt );
if ( !pEnt )
return false;

varinfo_t *pInfo = CacheFetch( pEnt, szProp );
if ( !pInfo )
{
pInfo = GetVarInfo( pEnt, szProp, INDEX_GET_TYPE );

if ( !pInfo )
return false;
}

g_pScriptVM->SetValue( hTable, "is_sendprop", !pInfo->isNotNetworked );
g_pScriptVM->SetValue( hTable, "type", pInfo->datatype );

int size = 0;
if ( pInfo->datatype == types::_STRING_T || pInfo->datatype == types::_CSTRING || pInfo->datatype == types::_INT8 )
{
size = pInfo->stringsize;
}
else
{
// Revert MASK_INT_SIZE to get original size
int bits = pInfo->mask;
while (bits > 0)
{
bits >>= 1;
size++;
}
}

// TODO: pInfo->arraysize stores both GetNumElements() and GetNumProps()
g_pScriptVM->SetValue( hTable, "bits", size );
g_pScriptVM->SetValue( hTable, "elements", pInfo->arraysize );
g_pScriptVM->SetValue( hTable, "offset", pInfo->GetOffset( index ) );
g_pScriptVM->SetValue( hTable, "length", pInfo->arraysize );
g_pScriptVM->SetValue( hTable, "array_props", pInfo->elemsize );
g_pScriptVM->SetValue( hTable, "flags", pInfo->isUnsigned ? SPROP_UNSIGNED : 0 ); // TODO: Proper flag storage?

return true;
}

#ifndef CLIENT_DLL
void GetTable( HSCRIPT hEnt, int iPropType, HSCRIPT hTable )
{
// To avoid copying a bunch of code, we keep a piece of the original net prop manager around for this
g_ScriptNetPropManagerStub.GetTable( hEnt, iPropType, hTable );
}
#endif

#ifdef _DEBUG
private:
CUtlBuffer m_output;
Expand Down Expand Up @@ -2541,9 +2633,19 @@ BEGIN_SCRIPTDESC_ROOT_NAMED( CScriptNetPropManager, "CNetPropManager", SCRIPT_SI
DEFINE_SCRIPTFUNC( SetPropStringArray, "Sets a string in an array." )
DEFINE_SCRIPTFUNC( SetPropVector, "Sets to the specified vector." )
DEFINE_SCRIPTFUNC( SetPropVectorArray, "Sets a 3D vector in an array." )
DEFINE_SCRIPTFUNC( GetPropInfo, "Fills in a passed table with property info for the provided entity." )
#ifndef CLIENT_DLL
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)." )
#endif
#ifdef _DEBUG
DEFINE_SCRIPTFUNC( Dump, "Dump all readable netprop and datafield values of this entity. Pass in file name to write into." );
#endif

// TF2 SDK compatibility
DEFINE_SCRIPTFUNC( GetPropBool, SCRIPT_HIDE )
DEFINE_SCRIPTFUNC( GetPropBoolArray, SCRIPT_HIDE )
DEFINE_SCRIPTFUNC( SetPropBool, SCRIPT_HIDE )
DEFINE_SCRIPTFUNC( SetPropBoolArray, SCRIPT_HIDE )
END_SCRIPTDESC();

//=============================================================================
Expand Down Expand Up @@ -5016,6 +5118,11 @@ class CScriptConvarAccessor : public CAutoGameSystem
GameRules()->SaveConvar( cvar );
}

bool IsConVarOnAllowList( const char *pszConVar )
{
return !IsBlockedConvar( pszConVar );
}

} g_ScriptConvarAccessor;


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


Expand Down
Loading
Loading