1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-09-19 20:16:10 +08:00

Update IGameEvent (#155)

Co-authored-by: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com>
This commit is contained in:
Juice
2023-10-09 00:16:21 +03:00
committed by GitHub
parent edef920f90
commit 4c5294550f
2 changed files with 277 additions and 188 deletions

View File

@ -1,187 +1,226 @@
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============// //========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
// //
// Purpose: // Purpose:
// //
// $Workfile: $ // $Workfile: $
// $Date: $ // $Date: $
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// $Log: $ // $Log: $
// //
// $NoKeywords: $ // $NoKeywords: $
//=============================================================================// //=============================================================================//
#if !defined( IGAMEEVENTS_H ) #if !defined( IGAMEEVENTS_H )
#define IGAMEEVENTS_H #define IGAMEEVENTS_H
#ifdef _WIN32 #ifdef _WIN32
#pragma once #pragma once
#endif #endif
#include "interfaces/interfaces.h" #include "interfaces/interfaces.h"
#include "tier1/bitbuf.h" #include "tier1/bitbuf.h"
#include "tier1/generichash.h"
class CMsgSource1LegacyGameEvent; #include "tier1/utlstring.h"
class CPlayerSlot; #include "ihandleentity.h"
class CBasePlayer;
class CEntityIndex; class CMsgSource1LegacyGameEvent;
class CEntityHandle; class CPlayerSlot;
class CBaseEntity; class CBasePlayer;
//----------------------------------------------------------------------------- class CEntityIndex;
// Purpose: Engine interface into global game event management class CEntityHandle;
//----------------------------------------------------------------------------- class CBaseEntity;
class CEntityInstance;
/* class CBasePlayerController;
class CBasePlayerPawn;
The GameEventManager keeps track and fires of all global game events. Game events //-----------------------------------------------------------------------------
are fired by game.dll for events like player death or team wins. Each event has a // Purpose: Engine interface into global game event management
unique name and comes with a KeyValue structure providing informations about this //-----------------------------------------------------------------------------
event. Some events are generated also by the engine.
/*
Events are networked to connected clients and invoked there to. Therefore you
have to specify all data fields and there data types in an public resource The GameEventManager keeps track and fires of all global game events. Game events
file which is parsed by server and broadcasted to it's clients. A typical game are fired by game.dll for events like player death or team wins. Each event has a
event is defined like this: unique name and comes with a KeyValue structure providing informations about this
event. Some events are generated also by the engine.
"game_start" // a new game starts
{ Events are networked to connected clients and invoked there to. Therefore you
"roundslimit" "long" // max round have to specify all data fields and there data types in an public resource
"timelimit" "long" // time limit file which is parsed by server and broadcasted to it's clients. A typical game
"fraglimit" "long" // frag limit event is defined like this:
"objective" "string" // round objective
} "game_start" // a new game starts
{
All events must have unique names (case sensitive) and may have a list "roundslimit" "long" // max round
of data fields. each data field must specify a data type, so the engine "timelimit" "long" // time limit
knows how to serialize/unserialize that event for network transmission. "fraglimit" "long" // frag limit
Valid data types are string, float, long, short, byte & bool. If a "objective" "string" // round objective
data field should not be broadcasted to clients, use the type "local". }
*/
All events must have unique names (case sensitive) and may have a list
of data fields. each data field must specify a data type, so the engine
#define MAX_EVENT_NAME_LENGTH 32 // max game event name length knows how to serialize/unserialize that event for network transmission.
#define MAX_EVENT_BITS 9 // max bits needed for an event index Valid data types are string, float, long, short, byte & bool. If a
#define MAX_EVENT_NUMBER (1<<MAX_EVENT_BITS) // max number of events allowed data field should not be broadcasted to clients, use the type "local".
#define MAX_EVENT_BYTES 1024 // max size in bytes for a serialized event */
class KeyValues; struct GameEventKeySymbol_t
class CGameEvent; {
inline GameEventKeySymbol_t(const char* keyName): m_nHashCode(0), m_pszKeyName(NULL)
abstract_class IToolGameEventAPI {
{ if (!keyName || !keyName[0])
virtual void unk001( void * ) = 0; return;
};
CUtlString buf( keyName );
abstract_class IGameEvent buf.ToLowerFast();
{
public: m_nHashCode = MurmurHash2(buf.Get(), strlen(keyName), 0x31415926);
virtual ~IGameEvent() {}; m_pszKeyName = keyName;
virtual const char *GetName() const = 0; // get event name
virtual int GetID() const = 0; #if 0
if (g_bUpdateStringTokenDatabase)
virtual bool IsReliable() const = 0; // if event handled reliable {
virtual bool IsLocal() const = 0; // if event is never networked RegisterStringToken(m_nHashCode, keyName, 0, true);
virtual bool IsEmpty(const char *keyName = NULL) = 0; // check if data field exists }
#endif
// Data access }
virtual bool GetBool( const char *keyName = NULL, bool defaultValue = false ) = 0;
virtual int GetInt( const char *keyName = NULL, int defaultValue = 0 ) = 0; private:
virtual uint64 GetUint64( const char *keyName = NULL, uint64 defaultValue = 0 ) = 0; unsigned int m_nHashCode;
virtual float GetFloat( const char *keyName = NULL, float defaultValue = 0.0f ) = 0; const char* m_pszKeyName;
virtual const char *GetString( const char *keyName = NULL, const char *defaultValue = "" ) = 0; };
virtual void *GetPtr( const char *keyName = NULL, void *defaultValue = NULL ) = 0;
/* These function prototypes and names are very speculative and might be incorrect */ #define MAX_EVENT_NAME_LENGTH 32 // max game event name length
virtual CEntityHandle GetEHandle( const char *keyName, CEntityHandle defaultValue ) = 0; #define MAX_EVENT_BITS 9 // max bits needed for an event index
virtual CEntityHandle GetStrictEHandle( const char *keyName, CEntityHandle defaultValue ) = 0; #define MAX_EVENT_NUMBER (1<<MAX_EVENT_BITS) // max number of events allowed
virtual CEntityHandle GetEHandle2( const char *keyName, CEntityHandle defaultValue ) = 0; #define MAX_EVENT_BYTES 1024 // max size in bytes for a serialized event
virtual CPlayerSlot *GetPlayerSlot( const char *keyName = NULL ) = 0; class KeyValues;
virtual CBasePlayer *GetPlayer( const char *keyName = NULL ) = 0; class CGameEvent;
virtual void *GetPlayerController( const char *keyName = NULL ) = 0; abstract_class IToolGameEventAPI
virtual CEntityHandle GetPlayerControllerEHandle( const char *keyName = NULL ) = 0; {
virtual CEntityHandle GetPlayerControllerEHandle2( const char *keyName = NULL ) = 0; virtual void unk001( void * ) = 0;
/* ============================================================ */ };
virtual void SetBool( const char *keyName, bool value ) = 0; abstract_class IGameEvent
virtual void SetInt( const char *keyName, int value ) = 0; {
virtual void SetUint64( const char *keyName, uint64 value ) = 0; public:
virtual void SetFloat( const char *keyName, float value ) = 0; virtual ~IGameEvent() {};
virtual void SetString( const char *keyName, const char *value ) = 0; virtual const char *GetName() const = 0; // get event name
virtual void SetPtr( const char *keyName, void *value ) = 0; virtual int GetID() const = 0;
/* These function prototypes and names are very speculative and might be incorrect */ virtual bool IsReliable() const = 0; // if event handled reliable
virtual void SetEHandleStrict( const char *keyName, CEntityHandle handle ) = 0; virtual bool IsLocal() const = 0; // if event is never networked
virtual void SetEHandle( const char *keyName, CEntityHandle handle ) = 0; virtual bool IsEmpty( const GameEventKeySymbol_t &keySymbol ) = 0; // check if data field exists
// Also sets the _pawn key // Data access
virtual void SetPlayerSlot( const char *keyName, CPlayerSlot value ) = 0; virtual bool GetBool( const GameEventKeySymbol_t &keySymbol, bool defaultValue = false ) = 0;
virtual void SetPlayer( const char *keyName, CBasePlayer *value ) = 0; virtual int GetInt( const GameEventKeySymbol_t &keySymbol, int defaultValue = 0 ) = 0;
/* ============================================================ */ virtual uint64 GetUint64( const GameEventKeySymbol_t &keySymbol, uint64 defaultValue = 0 ) = 0;
virtual float GetFloat( const GameEventKeySymbol_t &keySymbol, float defaultValue = 0.0f ) = 0;
virtual bool HasKey( const char *keyName ) = 0; virtual const char *GetString( const GameEventKeySymbol_t &keySymbol, const char *defaultValue = "" ) = 0;
virtual void *GetPtr( const GameEventKeySymbol_t &keySymbol ) = 0;
// Something script vm related
virtual void unk001() = 0; virtual CEntityHandle GetEHandle( const GameEventKeySymbol_t &keySymbol, CEntityHandle defaultValue = CEntityHandle() ) = 0;
virtual KeyValues *GetDataKeys() const = 0; // Returns the entity instance, mostly used for _pawn keys, might return 0 if used on any other key (even on a controller).
}; virtual IHandleEntity *GetEntity( const GameEventKeySymbol_t &keySymbol, IHandleEntity *fallbackInstance = NULL ) = 0;
virtual CEntityIndex GetEntityIndex( const GameEventKeySymbol_t &keySymbol, CEntityIndex defaultValue = CEntityIndex( -1 ) ) = 0;
abstract_class IGameEventListener2
{ virtual CPlayerSlot GetPlayerSlot( const GameEventKeySymbol_t &keySymbol ) = 0;
public:
virtual ~IGameEventListener2( void ) {}; virtual IHandleEntity *GetPlayerController( const GameEventKeySymbol_t &keySymbol ) = 0;
virtual IHandleEntity *GetPlayerPawn( const GameEventKeySymbol_t &keySymbol ) = 0;
// FireEvent is called by EventManager if event just occured
// KeyValue memory will be freed by manager if not needed anymore // Returns the EHandle for the _pawn entity.
virtual void FireGameEvent( IGameEvent *event ) = 0; virtual CEntityHandle GetPawnEHandle( const GameEventKeySymbol_t &keySymbol ) = 0;
}; // Returns the CEntityIndex for the _pawn entity.
virtual CEntityIndex GetPawnEntityIndex( const GameEventKeySymbol_t &keySymbol ) = 0;
abstract_class IGameEventManager2 : public IBaseInterface, public IToolGameEventAPI
{ virtual void SetBool( const GameEventKeySymbol_t &keySymbol, bool value ) = 0;
public: virtual void SetInt( const GameEventKeySymbol_t &keySymbol, int value ) = 0;
virtual ~IGameEventManager2( void ) {}; virtual void SetUint64( const GameEventKeySymbol_t &keySymbol, uint64 value ) = 0;
virtual void SetFloat( const GameEventKeySymbol_t &keySymbol, float value ) = 0;
// load game event descriptions from a file eg "resource\gameevents.res" virtual void SetString( const GameEventKeySymbol_t &keySymbol, const char *value ) = 0;
virtual int LoadEventsFromFile( const char *filename, bool bSearchAll ) = 0; virtual void SetPtr( const GameEventKeySymbol_t &keySymbol, void *value ) = 0;
// removes all and anything virtual void SetEntity( const GameEventKeySymbol_t &keySymbol, CEntityIndex value ) = 0;
virtual void Reset() = 0; virtual void SetEntity( const GameEventKeySymbol_t &keySymbol, IHandleEntity *value ) = 0;
// adds a listener for a particular event // Also sets the _pawn key
virtual bool AddListener( IGameEventListener2 *listener, const char *name, bool bServerSide ) = 0; virtual void SetPlayer( const GameEventKeySymbol_t &keySymbol, CPlayerSlot value ) = 0;
// Also sets the _pawn key (Expects pawn entity to be passed)
// returns true if this listener is listens to given event virtual void SetPlayer( const GameEventKeySymbol_t &keySymbol, IHandleEntity *pawn ) = 0;
virtual bool FindListener( IGameEventListener2 *listener, const char *name ) = 0;
// Expects pawn entity to be passed, will set the controller entity as a controllerKeyName
// removes a listener // and pawn entity as a pawnKeyName.
virtual void RemoveListener( IGameEventListener2 *listener) = 0; virtual void SetPlayerRaw( const GameEventKeySymbol_t &controllerKeySymbol, const GameEventKeySymbol_t &pawnKeySymbol, IHandleEntity *pawn ) = 0;
// create an event by name, but doesn't fire it. returns NULL is event is not virtual bool HasKey( const GameEventKeySymbol_t &keySymbol ) = 0;
// known or no listener is registered for it. bForce forces the creation even if no listener is active
virtual IGameEvent *CreateEvent( const char *name, bool bForce = false, int *pCookie = NULL ) = 0; // Something script vm related
virtual void unk001() = 0;
// fires a server event created earlier, if bDontBroadcast is set, event is not send to clients
virtual bool FireEvent( IGameEvent *event, bool bDontBroadcast = false ) = 0; // Not based on keyvalues anymore as it seems like
virtual void* GetDataKeys() const = 0;
// fires an event for the local client only, should be used only by client code };
virtual bool FireEventClientSide( IGameEvent *event ) = 0;
abstract_class IGameEventListener2
// create a new copy of this event, must be free later {
virtual IGameEvent *DuplicateEvent( IGameEvent *event ) = 0; public:
virtual ~IGameEventListener2( void ) {};
// if an event was created but not fired for some reason, it has to bee freed, same UnserializeEvent
virtual void FreeEvent( IGameEvent *event ) = 0; // FireEvent is called by EventManager if event just occured
// KeyValue memory will be freed by manager if not needed anymore
// write/read event to/from bitbuffer virtual void FireGameEvent( IGameEvent *event ) = 0;
virtual bool SerializeEvent( IGameEvent *event, CMsgSource1LegacyGameEvent *ev ) = 0; };
virtual IGameEvent *UnserializeEvent( const CMsgSource1LegacyGameEvent &ev ) = 0; // create new KeyValues, must be deleted
abstract_class IGameEventManager2 : public IBaseInterface, public IToolGameEventAPI
virtual int LookupEventId( const char *name ) = 0; {
public:
virtual void PrintEventToString( IGameEvent *event, CUtlString &out ) = 0; virtual ~IGameEventManager2( void ) {};
virtual bool HasEventDescriptor( const char *name ) = 0; // load game event descriptions from a file eg "resource\gameevents.res"
}; virtual int LoadEventsFromFile( const char *filename, bool bSearchAll ) = 0;
// removes all and anything
#endif // IGAMEEVENTS_H virtual void Reset() = 0;
// adds a listener for a particular event
virtual bool AddListener( IGameEventListener2 *listener, const char *name, bool bServerSide ) = 0;
// returns true if this listener is listens to given event
virtual bool FindListener( IGameEventListener2 *listener, const char *name ) = 0;
// removes a listener
virtual void RemoveListener( IGameEventListener2 *listener) = 0;
// create an event by name, but doesn't fire it. returns NULL is event is not
// known or no listener is registered for it. bForce forces the creation even if no listener is active
virtual IGameEvent *CreateEvent( const char *name, bool bForce = false, int *pCookie = NULL ) = 0;
// fires a server event created earlier, if bDontBroadcast is set, event is not send to clients
virtual bool FireEvent( IGameEvent *event, bool bDontBroadcast = false ) = 0;
// fires an event for the local client only, should be used only by client code
virtual bool FireEventClientSide( IGameEvent *event ) = 0;
// create a new copy of this event, must be free later
virtual IGameEvent *DuplicateEvent( IGameEvent *event ) = 0;
// if an event was created but not fired for some reason, it has to bee freed, same UnserializeEvent
virtual void FreeEvent( IGameEvent *event ) = 0;
// write/read event to/from bitbuffer
virtual bool SerializeEvent( IGameEvent *event, CMsgSource1LegacyGameEvent *ev ) = 0;
virtual IGameEvent *UnserializeEvent( const CMsgSource1LegacyGameEvent &ev ) = 0; // create new KeyValues, must be deleted
virtual int LookupEventId( const char *name ) = 0;
virtual void PrintEventToString( IGameEvent *event, CUtlString &out ) = 0;
virtual bool HasEventDescriptor( const char *name ) = 0;
};
#endif // IGAMEEVENTS_H

View File

@ -1,4 +1,4 @@
//======= Copyright <20> 2005, , Valve Corporation, All rights reserved. ========= //======= Copyright <20> 2005, , Valve Corporation, All rights reserved. =========
// //
// Purpose: Variant Pearson Hash general purpose hashing algorithm described // Purpose: Variant Pearson Hash general purpose hashing algorithm described
// by Cargill in C++ Report 1994. Generates a 16-bit result. // by Cargill in C++ Report 1994. Generates a 16-bit result.
@ -301,3 +301,53 @@ unsigned FASTCALL HashBlock( const void *pKey, unsigned size )
return (even << 8) | odd; return (even << 8) | odd;
} }
uint32 MurmurHash2( const void *key, int len, uint32 seed )
{
// 'm' and 'r' are mixing constants generated offline.
// They're not really 'magic', they just happen to work well.
const uint32 m = 0x5bd1e995;
const int r = 24;
// Initialize the hash to a 'random' value
uint32 h = seed ^ len;
// Mix 4 bytes at a time into the hash
const unsigned char * data = (const unsigned char *)key;
while(len >= 4)
{
uint32 k = LittleDWord( *(uint32 *)data );
k *= m;
k ^= k >> r;
k *= m;
h *= m;
h ^= k;
data += 4;
len -= 4;
}
// Handle the last few bytes of the input array
switch(len)
{
case 3: h ^= data[2] << 16;
case 2: h ^= data[1] << 8;
case 1: h ^= data[0];
h *= m;
};
// Do a few final mixes of the hash to ensure the last few
// bytes are well-incorporated.
h ^= h >> 13;
h *= m;
h ^= h >> 15;
return h;
}