diff --git a/sp/src/game/shared/baseentity_shared.h b/sp/src/game/shared/baseentity_shared.h index 85a0ffd89a..4891b0bc23 100644 --- a/sp/src/game/shared/baseentity_shared.h +++ b/sp/src/game/shared/baseentity_shared.h @@ -255,7 +255,7 @@ inline HSCRIPT ToHScript(CBaseEntity* pEnt) return (pEnt) ? pEnt->GetScriptInstance() : NULL; } -template <> ScriptClassDesc_t* GetScriptDesc(CBaseEntity*); +template <> ScriptClassDesc_t* GetScriptDesc(CBaseEntity*, bool); inline CBaseEntity* ToEnt(HSCRIPT hScript) { return (hScript) ? (CBaseEntity*)g_pScriptVM->GetInstanceValue(hScript, GetScriptDescForClass(CBaseEntity)) : NULL; diff --git a/sp/src/game/shared/vscript_shared.h b/sp/src/game/shared/vscript_shared.h index 508342208d..2145825b03 100644 --- a/sp/src/game/shared/vscript_shared.h +++ b/sp/src/game/shared/vscript_shared.h @@ -26,7 +26,7 @@ inline bool VScriptRunScript( const char *pszScriptName, bool bWarnMissing = fal #define BEGIN_ENT_SCRIPTDESC_NAMED( className, baseClass, scriptName, description ) _IMPLEMENT_ENT_SCRIPTDESC_ACCESSOR( className ); BEGIN_SCRIPTDESC_NAMED( className, baseClass, scriptName, description ) #define BEGIN_ENT_SCRIPTDESC_ROOT_NAMED( className, scriptName, description ) _IMPLEMENT_ENT_SCRIPTDESC_ACCESSOR( className ); BEGIN_SCRIPTDESC_ROOT_NAMED( className, scriptName, description ) -#define _IMPLEMENT_ENT_SCRIPTDESC_ACCESSOR( className ) template <> ScriptClassDesc_t * GetScriptDesc( className * ); ScriptClassDesc_t *className::GetScriptDesc() { return ::GetScriptDesc( this ); } +#define _IMPLEMENT_ENT_SCRIPTDESC_ACCESSOR( className ) template <> ScriptClassDesc_t * GetScriptDesc( className *, bool ); ScriptClassDesc_t *className::GetScriptDesc() { return ::GetScriptDesc( this ); } // Only allow scripts to create entities during map initialization bool IsEntityCreationAllowedInScripts( void ); diff --git a/sp/src/public/vscript/ivscript.h b/sp/src/public/vscript/ivscript.h index 58f981e037..3c553ff1b5 100644 --- a/sp/src/public/vscript/ivscript.h +++ b/sp/src/public/vscript/ivscript.h @@ -697,33 +697,36 @@ static inline int ToConstantVariant(int value) // //----------------------------------------------------------------------------- -#define ALLOW_SCRIPT_ACCESS() template friend ScriptClassDesc_t *GetScriptDesc(T *); +#define ALLOW_SCRIPT_ACCESS() template friend ScriptClassDesc_t *GetScriptDesc(T *, bool); #define BEGIN_SCRIPTDESC( className, baseClass, description ) BEGIN_SCRIPTDESC_NAMED( className, baseClass, #className, description ) #define BEGIN_SCRIPTDESC_ROOT( className, description ) BEGIN_SCRIPTDESC_ROOT_NAMED( className, #className, description ) #define BEGIN_SCRIPTDESC_NAMED( className, baseClass, scriptName, description ) \ - template <> ScriptClassDesc_t* GetScriptDesc(baseClass*); \ - template <> ScriptClassDesc_t* GetScriptDesc(className*); \ - ScriptClassDesc_t & g_##className##_ScriptDesc = *GetScriptDesc(nullptr); \ - template <> ScriptClassDesc_t* GetScriptDesc(className*) \ + template <> ScriptClassDesc_t* GetScriptDesc(baseClass*, bool); \ + template <> ScriptClassDesc_t* GetScriptDesc(className*, bool); \ + ScriptClassDesc_t & g_##className##_ScriptDesc = *GetScriptDesc(nullptr, true); \ + template <> ScriptClassDesc_t* GetScriptDesc(className*, bool init) \ { \ static ScriptClassDesc_t g_##className##_ScriptDesc; \ typedef className _className; \ ScriptClassDesc_t *pDesc = &g_##className##_ScriptDesc; \ - if (pDesc->m_pszClassname) return pDesc; \ - pDesc->m_pszDescription = description; \ - ScriptInitClassDescNamed( pDesc, className, GetScriptDescForClass( baseClass ), scriptName ); \ - ScriptClassDesc_t *pInstanceHelperBase = pDesc->m_pBaseDesc; \ - while ( pInstanceHelperBase ) \ + if (!pDesc->m_pszClassname) \ { \ - if ( pInstanceHelperBase->pHelper ) \ + pDesc->m_pszDescription = description; \ + ScriptInitClassDescNamed( pDesc, className, GetScriptDescForClass( baseClass ), scriptName ); \ + ScriptClassDesc_t *pInstanceHelperBase = pDesc->m_pBaseDesc; \ + while ( pInstanceHelperBase ) \ { \ - pDesc->pHelper = pInstanceHelperBase->pHelper; \ - break; \ + if ( pInstanceHelperBase->pHelper ) \ + { \ + pDesc->pHelper = pInstanceHelperBase->pHelper; \ + break; \ + } \ + pInstanceHelperBase = pInstanceHelperBase->m_pBaseDesc; \ } \ - pInstanceHelperBase = pInstanceHelperBase->m_pBaseDesc; \ - } + } \ + if (!init) return pDesc; #define BEGIN_SCRIPTDESC_ROOT_NAMED( className, scriptName, description ) \ @@ -781,10 +784,10 @@ static inline int ToConstantVariant(int value) do { ScriptMemberDesc_t *pBinding = &((pDesc)->m_Members[(pDesc)->m_Members.AddToTail()]); pBinding->m_pszScriptName = varName; pBinding->m_pszDescription = description; pBinding->m_ReturnType = returnType; } while (0); #endif -template ScriptClassDesc_t *GetScriptDesc(T *); +template ScriptClassDesc_t *GetScriptDesc(T *, bool = false); struct ScriptNoBase_t; -template <> inline ScriptClassDesc_t *GetScriptDesc( ScriptNoBase_t *) { return NULL; } +template <> inline ScriptClassDesc_t *GetScriptDesc( ScriptNoBase_t *, bool ) { return NULL; } #define GetScriptDescForClass( className ) GetScriptDesc( ( className *)NULL )