Schema

Schema system utilities for accessing and modifying entity fields.

Provides:

  • Runtime field offset resolution (via SchemaSystem)
  • Safe access to entity properties
  • Automatic network state updates
  • Compile-time hashing for fast lookup
This system is similar to Source2 schema/netvar access.

Header source2mod/schema/schema.h

Types

CEntityNameString

typedef void (*CEntityNameString)(void);

CGameSoundEventName

using CGameSoundEventName = CGlobalSymbol;

RotationVector

using RotationVector = void*;

schema_identity_t

template <typename T> using schema_identity_t = typename schema_identity<T>::type;

schema_bits_t

template <typename T> using schema_bits_t = typename schema_bits<T>::type;

CGlobalSymbol

Get

const char* Get() const;

Set

void Set(const char* value);
ParameterType
valueconst char*

SchemaKey

Represents schema offset information.

Fields

FieldTypeDescription
offsetint32Offset of the field
networkedboolTrue if field is networked
manipulatorSchemaCollectionManipulatorFn_tFor an atomic collection field, the engine's own element accessor.
validboolFalse when the field is not in the running game's schema (renamed, removed). Reads then come from zeroed scratch memory and writes go there, so the plugin keeps running with that one field doing nothing -- an error line says which, once.

CStrongHandle

Lightweight wrapper for entity pointers.

Get

T* Get() const;

Set

void Set(void* pPtr);
ParameterType
pPtrvoid*

IsValid

bool IsValid() const;

CStrongHandleCopyable

Get

T* Get() const;

Set

void Set(void* pPtr);
ParameterType
pPtrvoid*

IsValid

bool IsValid() const;

CWeakHandle

Get

T* Get() const;

Set

void Set(void* pPtr);
ParameterType
pPtrvoid*

IsValid

bool IsValid() const;

schema_identity

Puts a parameter in a non-deduced context. * The field setters are templates only so enable_if can pick an overload; T * must stay the field's own type. Deduced from the argument, m_nByte = 1 * made T an int and wrote four bytes over a one-byte field.

type

using type = T;

schema_bits

The integer type a bitwise operator computes in: the underlying type of an enum, otherwise T.

type

using type = T;

Functions

GetGameEventManager

IGameEventManager2* GetGameEventManager();

Global accessors for engine interfaces.

GetGlobalVars

CGlobalVars* GetGlobalVars();

GetCVar

ICvar* GetCVar();

GetSource2Server

ISource2Server* GetSource2Server();

GetEngineServer

IVEngineServer2* GetEngineServer();

GetGameEventSystem

IGameEventSystem* GetGameEventSystem();

GetNetworkMessages

INetworkMessages* GetNetworkMessages();

GetNetworkServerService

INetworkServerService* GetNetworkServerService();

GetEntitySystem

CGameEntitySystem* GetEntitySystem();

GetSchemaSystem

CSchemaSystem* GetSchemaSystem();

EntityNetworkStateChanged

void EntityNetworkStateChanged(uintptr_t pEntity, uint nOffset);
ParameterType
pEntityuintptr_t
nOffsetuint

ChainNetworkStateChanged

void ChainNetworkStateChanged(uintptr_t pNetworkVarChainer, uint nOffset);
ParameterType
pNetworkVarChaineruintptr_t
nOffsetuint

NetworkVarStateChanged

void NetworkVarStateChanged(uintptr_t pNetworkVar, uint32_t nOffset, uint32 nNetworkStateChangedOffset);
ParameterType
pNetworkVaruintptr_t
nOffsetuint32_t
nNetworkStateChangedOffsetuint32

FindChainOffset

int16_t FindChainOffset(const char* className, uint32_t classNameHash);
int16_t FindChainOffset(const char* className);
template <typename T> int16_t FindChainOffset();
template <typename T> int16_t FindChainOffset(const T*);

Finds chain offset for a class.

ParameterType
classNameconst char*
classNameHashuint32_t
—const T*

GetOffset

SchemaKey GetOffset(const char* className, uint32_t classKey, const char* memberName, uint32_t memberKey);
template <typename T> SchemaKey GetOffset(const char* memberName);
template <typename T> SchemaKey GetOffset(const T*, const char* memberName);

Gets schema offset for a field.

ParameterType
classNameconst char*
classKeyuint32_t
memberNameconst char*
memberKeyuint32_t
—const T*

MissingFieldStorage

void* MissingFieldStorage(size_t size);

Scratch memory a missing field reads from and writes to; zeroed, one block for every such field in the plugin.

ParameterType
sizesize_t

MissingField

template <typename T> T& MissingField();

GetServerOffset

int32_t GetServerOffset(const char* pszClassName, const char* pszPropName);
template <typename T> int32_t GetServerOffset(const char* pszPropName);
template <typename T> int32_t GetServerOffset(const T*, const char* pszPropName);

Gets server offset (fallback).

ParameterType
pszClassNameconst char*
pszPropNameconst char*
—const T*

GetClassSize

int32_t GetClassSize(const char* className);
template <typename T> int32_t GetClassSize();
template <typename T> int32_t GetClassSize(const T*);

Gets class size.

ParameterType
classNameconst char*
—const T*

SetStateChanged

void SetStateChanged(CEntityInstance* entity, const char* className, const char* propName);
template <typename T> void SetStateChanged(T* entity, const char* propName);

Marks field as changed (network update).

SetStateChanged(entity, "m_iHealth"), the class taken from the entity's type.

ParameterType
entityCEntityInstance*
classNameconst char*
propNameconst char*
entityT*

hash_32_fnv1a_const

inline constexpr uint32_t hash_32_fnv1a_const(const char* const str, const uint32_t value = 0x811c9dc5) noexcept;

FNV-1a 32-bit hash (constexpr).

ParameterTypeDefault
strconst char* const
valueconst uint32_t0x811c9dc5

hash_64_fnv1a_const

inline constexpr uint64_t hash_64_fnv1a_const(const char* const str, const uint64_t value = 0xcbf29ce484222325) noexcept;

FNV-1a 64-bit hash (constexpr).

ParameterTypeDefault
strconst char* const
valueconst uint64_t0xcbf29ce484222325

ClassName

template <typename T> constexpr std::string_view ClassName();

The C++ name of T at compile time ("CChicken"); schema class names are the C++ ones.

ClassNameCStr

template <typename T> const char* ClassNameCStr();

ClassName<T>() as a null-terminated string.

Macros

SCHEMA_FIELD

#define SCHEMA_FIELD(type, varName) SCHEMA_FIELD_OFFSET(type, varName, 0)

Declares schema field (auto offset + network update).

This macro generates a wrapper class that: * Resolves offset via schema * Provides Get/Set * Automatically updates network state * Use this when you want the member's value itself

SCHEMA_FIELD_POINTER

#define SCHEMA_FIELD_POINTER(type, varName) SCHEMA_FIELD_POINTER_OFFSET(type, varName, 0)

Declares pointer schema field. * Use this when you want a pointer to a member

DECLARE_SCHEMA_CLASS_BASE

#define DECLARE_SCHEMA_CLASS_BASE(ClassName, offset) \
    private:																		
		typedef ClassName ThisClass;												
		static constexpr const char* m_className = #ClassName;						
		static constexpr uint32_t m_classNameHash = hash_32_fnv1a_const(#ClassName);
		static constexpr int m_networkStateChangedOffset = offset;					
	public:

Declares schema-enabled class. * offset != 0 marks a non-entity (embedded) class; the value itself is not used any more

DECLARE_SCHEMA_CLASS_INLINE

#define DECLARE_SCHEMA_CLASS_INLINE(className) DECLARE_SCHEMA_CLASS_BASE(className, 1)

Declares inline schema class (non-entity). * Use this for non-entity classes such as CCollisionProperty or CGlowProperty * Their NetworkStateChanged is a virtual of the NetworkVar_<field> wrapper the engine embeds them in, not CEntityInstance's; * its vtable slot is found at runtime (NetworkVarStateChanged), so no index is kept per class * Though some classes like CGameRules will instead use their CNetworkVarChainer as a link back to the parent entity

Other macros

MacroExpands to
SCHEMA_FIELD_OFFSET(type, varName, extra_offset)class varName##_prop { public: /*The deleted copy ctor below is user-declared, which suppresses the*/ /*imp...
SCHEMA_FIELD_POINTER_OFFSET(type, varName, extra_offset)class varName##_prop { public: /*The deleted copy ctor below is user-declared, which suppresses the*/ /*imp...
SCHEMA_FIELD_OLD(type, className, propName)std::add_lvalue_reference_t<type> propName() { static const int32_t offset = [] { const int32_t nOffset = s...
DECLARE_SCHEMA_CLASS(className)DECLARE_SCHEMA_CLASS_BASE(className, 0)

On this page