Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ScriptHook_t initialization order #320

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion sp/src/game/shared/baseentity_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ inline HSCRIPT ToHScript(CBaseEntity* pEnt)
return (pEnt) ? pEnt->GetScriptInstance() : NULL;
}

template <> ScriptClassDesc_t* GetScriptDesc<CBaseEntity>(CBaseEntity*);
template <> ScriptClassDesc_t* GetScriptDesc<CBaseEntity>(CBaseEntity*, bool);
inline CBaseEntity* ToEnt(HSCRIPT hScript)
{
return (hScript) ? (CBaseEntity*)g_pScriptVM->GetInstanceValue(hScript, GetScriptDescForClass(CBaseEntity)) : NULL;
Expand Down
2 changes: 1 addition & 1 deletion sp/src/game/shared/vscript_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>( className * ); ScriptClassDesc_t *className::GetScriptDesc() { return ::GetScriptDesc( this ); }
#define _IMPLEMENT_ENT_SCRIPTDESC_ACCESSOR( className ) template <> ScriptClassDesc_t * GetScriptDesc<className>( className *, bool ); ScriptClassDesc_t *className::GetScriptDesc() { return ::GetScriptDesc( this ); }

// Only allow scripts to create entities during map initialization
bool IsEntityCreationAllowedInScripts( void );
Expand Down
37 changes: 20 additions & 17 deletions sp/src/public/vscript/ivscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -697,33 +697,36 @@ static inline int ToConstantVariant(int value)
//
//-----------------------------------------------------------------------------

#define ALLOW_SCRIPT_ACCESS() template <typename T> friend ScriptClassDesc_t *GetScriptDesc(T *);
#define ALLOW_SCRIPT_ACCESS() template <typename T> 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>(baseClass*); \
template <> ScriptClassDesc_t* GetScriptDesc<className>(className*); \
ScriptClassDesc_t & g_##className##_ScriptDesc = *GetScriptDesc<className>(nullptr); \
template <> ScriptClassDesc_t* GetScriptDesc<className>(className*) \
template <> ScriptClassDesc_t* GetScriptDesc<baseClass>(baseClass*, bool); \
template <> ScriptClassDesc_t* GetScriptDesc<className>(className*, bool); \
ScriptClassDesc_t & g_##className##_ScriptDesc = *GetScriptDesc<className>(nullptr, true); \
template <> ScriptClassDesc_t* GetScriptDesc<className>(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 ) \
Expand Down Expand Up @@ -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 <typename T> ScriptClassDesc_t *GetScriptDesc(T *);
template <typename T> ScriptClassDesc_t *GetScriptDesc(T *, bool = false);

struct ScriptNoBase_t;
template <> inline ScriptClassDesc_t *GetScriptDesc<ScriptNoBase_t>( ScriptNoBase_t *) { return NULL; }
template <> inline ScriptClassDesc_t *GetScriptDesc<ScriptNoBase_t>( ScriptNoBase_t *, bool ) { return NULL; }

#define GetScriptDescForClass( className ) GetScriptDesc( ( className *)NULL )

Expand Down
Loading