· 9 years ago · Jan 22, 2017, 12:24 PM
1#pragma once
2
3#include "types.h"
4#include "basetypes.h"
5#include "button.h"
6#include "color.h"
7#include "const.h"
8#include "bspflags.h"
9#include "string.h"
10#include "vector.h"
11#include "mathlib.h"
12#include "dt_recv.h"
13#include "crc.h"
14#include "cinput.h"
15
16#include "../main.h"
17#include "../client.h"
18
19#pragma region OFFSET
20
21//current game version at 22.01.2k17 tijesef ugami nomin ai lav u
22/*Protocol version 13565 [431/431]
23Exe version 1.35.6.5 (csgo)
24Exe build: 18:12:55 Jan 12 2017 (6641) (730)*/
25
26#define CSGO_VERSION XorStr("1.35.6.5")
27#define CSGO_CLIENT_VERSION 431
28
29#define m_vecOrigin 0x134
30#define m_hMyWeapons 0x2DE8
31#define m_hViewModel 0x32FC
32#define m_fEffects 0xEC
33#define m_iTeamNum 0xF0
34#define m_angEyeAngles 0xAA08
35#define m_iHealth 0xFC
36#define m_ArmorValue 0xAA04
37#define m_iShotsFired 0xA2C0
38#define m_iCrossHairID 0xAA70
39#define m_lifeState 0x25B
40#define m_fFlags 0x100
41#define m_vecViewOffset 0x104
42#define m_aimPunchAngle 0x301C
43#define m_hActiveWeapon 0x2EE8
44#define m_iFOVStart 0x31D8
45#define m_MoveType 0x258
46#define m_iClip1 0x3204
47#define m_iItemDefinitionIndex 0x2F88
48#define m_nFallbackPaintKit 0x3170
49#define m_flFallbackWear 0x3178
50#define m_iItemIDHigh 0x2FA0
51#define m_OriginalOwnerXuidHigh 0x316C
52#define m_OriginalOwnerXuidLow 0x3168
53#define m_iAccountID 0x2FA8
54#define m_iEntityQuality 0x2F8C
55#define m_nModelIndex 0x254
56#define m_hOwner 0x31D0
57#define m_hWeapon 0x29B8
58#define m_hOwnerEntity 0x148
59
60#define m_nTickBase 0x3424
61#define m_flNextPrimaryAttack 0x31D8
62
63#define m_dwGlowObject 0x4FE38C4
64#define m_iGlowIndex 0xA320
65
66#define CSPlayerResource 0x2F07464
67#define m_iCompetitiveRanking 0x1A44
68
69#pragma endregion
70
71#pragma region SDK
72
73class IVEngineClient;
74class IBaseClientDLL;
75class IEngineSound;
76class ISurface;
77class IPanel;
78class IPlayerInfoManager;
79class CGlobalVarsBase;
80class IClientMode;
81class IClientEntity;
82class IClientEntityList;
83class IVModelInfoClient;
84class IGameEventManager2;
85class IModelRender;
86class IRenderView;
87class IMaterialSystem;
88
89extern IVEngineClient* g_pEngine;
90extern IBaseClientDLL* g_pClient;
91extern IEngineSound* g_pSound;
92extern ISurface* g_pSurface;
93extern IPanel* g_pPanel;
94extern IPlayerInfoManager* g_pPlayerInfoManager;
95extern CGlobalVarsBase* g_pGlobalVarsBase;
96extern IClientMode* g_pClientMode;
97extern IClientEntityList* g_pClientEntList;
98extern IVModelInfoClient* g_pModelInfo;
99extern IGameEventManager2* g_pGameEventMgr;
100extern IModelRender* g_pModelRender;
101extern IRenderView* g_pRenderView;
102extern IMaterialSystem* g_pMaterialSystem;
103extern CInput* g_pInput;
104
105#define VirtualFn( cast ) typedef cast( __thiscall* OriginalFn )
106
107#pragma endregion
108
109#pragma region Defines
110
111#define RandomInt(nMin, nMax) (rand() % (nMax - nMin + 1) + nMin);
112
113struct GlowObjectDefinition_t
114{
115 IClientEntity* pEntity;
116 float r;
117 float g;
118 float b;
119 float a;
120 uint8_t unk1[16];
121 bool m_bRenderWhenOccluded;
122 bool m_bRenderWhenUnoccluded;
123 bool m_bFullBloom;
124 uint8_t unk2[14];
125};
126
127#pragma endregion
128
129#pragma region Interface
130
131#define VENGINE_CLIENT_INTERFACE_VERSION "VEngineClient014"
132#define CLIENT_DLL_INTERFACE_VERSION "VClient018"
133#define VCLIENTENTITYLIST_INTERFACE_VERSION "VClientEntityList003"
134#define VGUI_SURFACE_INTERFACE_VERSION "VGUI_Surface031"
135#define VGUI_PANEL_INTERFACE_VERSION "VGUI_Panel009"
136#define INTERFACEVERSION_PLAYERINFOMANAGER "PlayerInfoManager002"
137#define IENGINESOUND_CLIENT_INTERFACE_VERSION "IEngineSoundClient003"
138#define VMODELINFO_CLIENT_INTERACE_VERSION "VModelInfoClient004"
139#define GAMEEVENTMANAGER_INTERFACE_VERSION "GAMEEVENTSMANAGER002"
140#define VENGINE_HUDMODEL_INTERFACE_VERSION "VEngineModel016"
141#define VENGINE_RENDERVIEW_INTERFACE_VERSION "VEngineRenderView014"
142#define MATERIAL_SYSTEM_INTERFACE_VERSION "VMaterialSystem080"
143#define CREATEINTERFACE_PROCNAME "CreateInterface"
144
145class IBaseInterface
146{
147public:
148 virtual ~IBaseInterface() { }
149};
150
151typedef void* ( *CreateInterfaceFn )( const char *pName , int *pReturnCode );
152
153#pragma endregion
154
155#pragma region WorldSize
156
157#define MAX_COORD_INTEGER (16384)
158#define MIN_COORD_INTEGER (-MAX_COORD_INTEGER)
159#define MAX_COORD_FRACTION (1.0-(1.0/16.0))
160#define MIN_COORD_FRACTION (-1.0+(1.0/16.0))
161
162#define MAX_COORD_FLOAT (16384.0f)
163#define MIN_COORD_FLOAT (-MAX_COORD_FLOAT)
164
165// Width of the coord system, which is TOO BIG to send as a client/server coordinate value
166#define COORD_EXTENT (2*MAX_COORD_INTEGER)
167
168// Maximum traceable distance ( assumes cubic world and trace from one corner to opposite )
169// COORD_EXTENT * sqrt(3)
170#define MAX_TRACE_LENGTH ( 1.732050807569 * COORD_EXTENT )
171
172// This value is the LONGEST possible range (limited by max valid coordinate number, not 2x)
173#define MAX_COORD_RANGE (MAX_COORD_INTEGER)
174
175#pragma endregion
176
177#pragma region Studio
178
179#define MAXSTUDIOTRIANGLES 25000
180#define MAXSTUDIOVERTS 10000
181#define MAXSTUDIOFLEXVERTS 1000
182
183#define MAXSTUDIOSKINS 32 // total textures
184#define MAXSTUDIOBONES 128 // total bones actually used
185#define MAXSTUDIOFLEXDESC 1024 // maximum number of low level flexes (actual morph targets)
186#define MAXSTUDIOFLEXCTRL 96 // maximum number of flexcontrollers (input sliders)
187#define MAXSTUDIOPOSEPARAM 24
188#define MAXSTUDIOBONECTRLS 4
189#define MAXSTUDIOANIMBLOCKS 256
190
191#define MAXSTUDIOBONEBITS 7 // NOTE: MUST MATCH MAXSTUDIOBONES
192
193// NOTE!!! : Changing this number also changes the vtx file format!!!!!
194#define MAX_NUM_BONES_PER_VERT 3
195
196//Adrian - Remove this when we completely phase out the old event system.
197#define NEW_EVENT_STYLE ( 1 << 10 )
198
199#define BONE_CALCULATE_MASK 0x1F
200#define BONE_PHYSICALLY_SIMULATED 0x01 // bone is physically simulated when physics are active
201#define BONE_PHYSICS_PROCEDURAL 0x02 // procedural when physics is active
202#define BONE_ALWAYS_PROCEDURAL 0x04 // bone is always procedurally animated
203#define BONE_SCREEN_ALIGN_SPHERE 0x08 // bone aligns to the screen, not constrained in motion.
204#define BONE_SCREEN_ALIGN_CYLINDER 0x10 // bone aligns to the screen, constrained by it's own axis.
205
206#define BONE_USED_MASK 0x0007FF00
207#define BONE_USED_BY_ANYTHING 0x0007FF00
208#define BONE_USED_BY_HITBOX 0x00000100 // bone (or child) is used by a hit box
209#define BONE_USED_BY_ATTACHMENT 0x00000200 // bone (or child) is used by an attachment point
210#define BONE_USED_BY_VERTEX_MASK 0x0003FC00
211#define BONE_USED_BY_VERTEX_LOD0 0x00000400 // bone (or child) is used by the toplevel model via skinned vertex
212#define BONE_USED_BY_VERTEX_LOD1 0x00000800
213#define BONE_USED_BY_VERTEX_LOD2 0x00001000
214#define BONE_USED_BY_VERTEX_LOD3 0x00002000
215#define BONE_USED_BY_VERTEX_LOD4 0x00004000
216#define BONE_USED_BY_VERTEX_LOD5 0x00008000
217#define BONE_USED_BY_VERTEX_LOD6 0x00010000
218#define BONE_USED_BY_VERTEX_LOD7 0x00020000
219#define BONE_USED_BY_BONE_MERGE 0x00040000 // bone is available for bone merge to occur against it
220
221#define BONE_USED_BY_VERTEX_AT_LOD(lod) ( BONE_USED_BY_VERTEX_LOD0 << (lod) )
222#define BONE_USED_BY_ANYTHING_AT_LOD(lod) ( ( BONE_USED_BY_ANYTHING & ~BONE_USED_BY_VERTEX_MASK ) | BONE_USED_BY_VERTEX_AT_LOD(lod) )
223
224#define MAX_NUM_LODS 8
225
226#define BONE_TYPE_MASK 0x00F00000
227#define BONE_FIXED_ALIGNMENT 0x00100000 // bone can't spin 360 degrees, all interpolation is normalized around a fixed orientation
228
229#define BONE_HAS_SAVEFRAME_POS 0x00200000 // Vector48
230#define BONE_HAS_SAVEFRAME_ROT 0x00400000 // Quaternion64
231
232#pragma endregion
233
234#pragma region IVEngineClient
235
236typedef struct player_info_s {
237private:
238 DWORD __pad0[2];
239public:
240 int m_nXuidLow;
241 int m_nXuidHigh;
242 char m_szPlayerName[128];
243 int m_nUserID;
244 char m_szSteamID[33];
245 UINT m_nSteam3ID;
246 char m_szFriendsName[128];
247 bool m_bIsFakePlayer;
248 bool m_bIsHLTV;
249 DWORD m_dwCustomFiles[4];
250 BYTE m_FilesDownloaded;
251private:
252 int __pad1;
253} player_info_t;
254
255struct client_textmessage_t
256{
257 int effect;
258 byte r1 , g1 , b1 , a1; // 2 colors for effects
259 byte r2 , g2 , b2 , a2;
260 float x;
261 float y;
262 float fadein;
263 float fadeout;
264 float holdtime;
265 float fxtime;
266 const char *pVGuiSchemeFontName; // If null, use default font for messages
267 const char *pName;
268 const char *pMessage;
269 bool bRoundedRectBackdropBox;
270 float flBoxSize; // as a function of font height
271 byte boxcolor[4];
272 char const *pClearMessage; // message to clear
273};
274
275struct OcclusionParams_t
276{
277 float m_flMaxOccludeeArea;
278 float m_flMinOccluderArea;
279};
280
281enum SkyboxVisibility_t
282{
283 SKYBOX_NOT_VISIBLE = 0 ,
284 SKYBOX_3DSKYBOX_VISIBLE ,
285 SKYBOX_2DSKYBOX_VISIBLE ,
286};
287
288enum EngineInputContextId_t
289{
290 ENGINE_INPUT_CONTEXT_GAME = 0 ,
291 ENGINE_INPUT_CONTEXT_GAMEUI ,
292};
293
294typedef struct con_nprint_s
295{
296 int index; // Row #
297 float time_to_live; // # of seconds before it disappears. -1 means to display for 1 frame then go away.
298 float color[3]; // RGB colors ( 0.0 -> 1.0 scale )
299 bool fixed_width_font;
300} con_nprint_t;
301
302struct model_t;
303class SurfInfo;
304class IMaterial;
305class CSentence;
306class CAudioSource;
307class ISpatialQuery;
308class IMaterialSystem;
309class Frustum_t;
310struct AudioState_t;
311class INetChannelInfo;
312class CPhysCollide;
313class IAchievementMgr;
314class ISPSharedMemory;
315class CGamestatsData;
316class CSteamAPIContext;
317class KeyValues;
318
319#define FORWARD_DECLARE_HANDLE(name) typedef struct name##__ *name
320typedef void( *pfnDemoCustomDataCallback )( uint8 *pData , size_t iSize );
321FORWARD_DECLARE_HANDLE( InputContextHandle_t );
322
323template< class T , class A > class CUtlVector;
324template< class T , class I > class CUtlMemory;
325
326template< class T , class I = int >
327class CUtlMemory { };
328
329template< class T , class A = CUtlMemory<T> >
330class CUtlVector { };
331
332class IVEngineClient
333{
334public:
335 // Find the model's surfaces that intersect the given sphere.
336 // Returns the number of surfaces filled in.
337 virtual int GetIntersectingSurfaces(
338 const model_t *model ,
339 const Vector &vCenter ,
340 const float radius ,
341 const bool bOnlyVisibleSurfaces , // Only return surfaces visible to vCenter.
342 SurfInfo *pInfos ,
343 const int nMaxInfos ) = 0;
344
345 // Get the lighting intensivty for a specified point
346 // If bClamp is specified, the resulting Vector is restricted to the 0.0 to 1.0 for each element
347 virtual Vector GetLightForPoint( const Vector &pos , bool bClamp ) = 0;
348
349 // Traces the line and reports the material impacted as well as the lighting information for the impact point
350 virtual IMaterial *TraceLineMaterialAndLighting( const Vector &start , const Vector &end ,
351 Vector &diffuseLightColor , Vector& baseColor ) = 0;
352
353 // Given an input text buffer data pointer, parses a single token into the variable token and returns the new
354 // reading position
355 virtual const char *ParseFile( const char *data , char *token , int maxlen ) = 0;
356 virtual bool CopyFile( const char *source , const char *destination ) = 0;
357
358 // Gets the dimensions of the game window
359 virtual void GetScreenSize( int& width , int& height ) = 0;
360
361 // Forwards szCmdString to the server, sent reliably if bReliable is set
362 virtual void ServerCmd( const char *szCmdString , bool bReliable = true ) = 0;
363 // Inserts szCmdString into the command buffer as if it was typed by the client to his/her console.
364 // Note: Calls to this are checked against FCVAR_CLIENTCMD_CAN_EXECUTE (if that bit is not set, then this function can't change it).
365 // Call ClientCmd_Unrestricted to have access to FCVAR_CLIENTCMD_CAN_EXECUTE vars.
366 virtual void ClientCmd( const char *szCmdString ) = 0;
367
368 // Fill in the player info structure for the specified player index (name, model, etc.)
369 virtual bool GetPlayerInfo( int ent_num , player_info_t *pinfo ) = 0;
370
371 // Retrieve the player entity number for a specified userID
372 virtual int GetPlayerForUserID( int userID ) = 0;
373
374 // Retrieves text message system information for the specified message by name
375 virtual client_textmessage_t *TextMessageGet( const char *pName ) = 0; // 10
376
377 // Returns true if the console is visible
378 virtual bool Con_IsVisible( void ) = 0;
379
380 // Get the entity index of the local player
381 virtual int GetLocalPlayer( void ) = 0;
382
383 // Client DLL is hooking a model, loads the model into memory and returns pointer to the model_t
384 virtual const model_t *LoadModel( const char *pName , bool bProp = false ) = 0;
385
386 // Get the exact server timesstamp ( server time ) from the last message received from the server
387 virtual float GetLastTimeStamp( void ) = 0;
388
389 // Given a CAudioSource (opaque pointer), retrieve the underlying CSentence object ( stores the words, phonemes, and close
390 // captioning data )
391 virtual CSentence *GetSentence( CAudioSource *pAudioSource ) = 0; // 15
392 // Given a CAudioSource, determines the length of the underlying audio file (.wav, .mp3, etc.)
393 virtual float GetSentenceLength( CAudioSource *pAudioSource ) = 0;
394 // Returns true if the sound is streaming off of the hard disk (instead of being memory resident)
395 virtual bool IsStreaming( CAudioSource *pAudioSource ) const = 0;
396
397 // Copy current view orientation into va
398 virtual void GetViewAngles( QAngle& va ) = 0;
399 // Set current view orientation from va
400 virtual void SetViewAngles( QAngle& va ) = 0;
401
402 // Retrieve the current game's maxclients setting
403 virtual int GetMaxClients( void ) = 0; // 20
404
405 // Given the string pBinding which may be bound to a key,
406 // returns the string name of the key to which this string is bound. Returns NULL if no such binding exists
407 virtual const char *Key_LookupBinding( const char *pBinding ) = 0;
408
409 // Given the name of the key "mouse1", "e", "tab", etc., return the string it is bound to "+jump", "impulse 50", etc.
410 virtual const char *Key_BindingForKey( ButtonCode_t &code ) = 0;
411 virtual void Key_SetBinding( ButtonCode_t , char const* ) = 0;
412
413 // key trapping (for binding keys)
414 virtual void StartKeyTrapMode( void ) = 0;
415 virtual bool CheckDoneKeyTrapping( ButtonCode_t &code ) = 0;
416
417 // Returns true if the player is fully connected and active in game (i.e, not still loading)
418 virtual bool IsInGame( void ) = 0;
419 // Returns true if the player is connected, but not necessarily active in game (could still be loading)
420 virtual bool IsConnected( void ) = 0;
421 // Returns true if the loading plaque should be drawn
422 virtual bool IsDrawingLoadingImage( void ) = 0;
423 virtual void HideLoadingPlaque( void ) = 0;
424
425 // Prints the formatted string to the notification area of the screen ( down the right hand edge
426 // numbered lines starting at position 0
427 virtual void Con_NPrintf( int pos , const char *fmt , ... ) = 0; // 30
428 // Similar to Con_NPrintf, but allows specifying custom text color and duration information
429 virtual void Con_NXPrintf( const struct con_nprint_s *info , const char *fmt , ... ) = 0;
430
431 // Is the specified world-space bounding box inside the view frustum?
432 virtual int IsBoxVisible( const Vector& mins , const Vector& maxs ) = 0;
433
434 // Is the specified world-space boudning box in the same PVS cluster as the view origin?
435 virtual int IsBoxInViewCluster( const Vector& mins , const Vector& maxs ) = 0;
436
437 // Returns true if the specified box is outside of the view frustum and should be culled
438 virtual bool CullBox( const Vector& mins , const Vector& maxs ) = 0;
439
440 // Allow the sound system to paint additional data (during lengthy rendering operations) to prevent stuttering sound.
441 virtual void Sound_ExtraUpdate( void ) = 0;
442
443 // Get the current game directory ( e.g., hl2, tf2, cstrike, hl1 )
444 virtual const char *GetGameDirectory( void ) = 0;
445
446 // Get access to the world to screen transformation matrix
447 virtual const D3DMATRIX& WorldToScreenMatrix() = 0;
448
449 // Get the matrix to move a point from world space into view space
450 // (translate and rotate so the camera is at the origin looking down X).
451 virtual const D3DMATRIX& WorldToViewMatrix() = 0;
452
453 // The .bsp file can have mod-specified data lumps. These APIs are for working with such game lumps.
454
455 // Get mod-specified lump version id for the specified game data lump
456 virtual int GameLumpVersion( int lumpId ) const = 0;
457 // Get the raw size of the specified game data lump.
458 virtual int GameLumpSize( int lumpId ) const = 0; // 40
459 // Loads a game lump off disk, writing the data into the buffer pointed to by pBuffer
460 // Returns false if the data can't be read or the destination buffer is too small
461 virtual bool LoadGameLump( int lumpId , void* pBuffer , int size ) = 0;
462
463 // Returns the number of leaves in the level
464 virtual int LevelLeafCount() const = 0;
465
466 // Gets a way to perform spatial queries on the BSP tree
467 virtual ISpatialQuery* GetBSPTreeQuery() = 0;
468
469 // Convert texlight to gamma...
470 virtual void LinearToGamma( float* linear , float* gamma ) = 0;
471
472 // Get the lightstyle value
473 virtual float LightStyleValue( int style ) = 0; // 45
474
475 // Computes light due to dynamic lighting at a point
476 // If the normal isn't specified, then it'll return the maximum lighting
477 virtual void ComputeDynamicLighting( const Vector& pt , const Vector* pNormal , Vector& color ) = 0;
478
479 // Returns the color of the ambient light
480 virtual void GetAmbientLightColor( Vector& color ) = 0;
481
482 // Returns the dx support level
483 virtual int GetDXSupportLevel() = 0;
484
485 // GR - returns the HDR support status
486 virtual bool SupportsHDR() = 0;
487
488 // Replace the engine's material system pointer.
489 virtual void Mat_Stub( IMaterialSystem *pMatSys ) = 0; // 50
490
491 // Get the name of the current map
492 virtual void GetChapterName( char *pchBuff , int iMaxLength ) = 0;
493 virtual char const *GetLevelName( void ) = 0;
494 virtual char const *GetLevelNameShort( void ) = 0;
495 virtual char const *GetMapGroupName( void ) = 0;
496
497 // Obtain access to the voice tweaking API
498 virtual struct IVoiceTweak_s *GetVoiceTweakAPI( void ) = 0;
499
500 ///// new virtual added on 14\08\2014 /////
501 virtual void SetVoiceCasterID( unsigned int someint ) = 0; // 56
502
503 // Tell engine stats gathering system that the rendering frame is beginning/ending
504 virtual void EngineStats_BeginFrame( void ) = 0;
505 virtual void EngineStats_EndFrame( void ) = 0;
506
507 // This tells the engine to fire any events (temp entity messages) that it has queued up this frame.
508 // It should only be called once per frame.
509 virtual void FireEvents() = 0;
510
511 // Returns an area index if all the leaves are in the same area. If they span multple areas, then it returns -1.
512 virtual int GetLeavesArea( unsigned short *pLeaves , int nLeaves ) = 0;
513
514 // Returns true if the box touches the specified area's frustum.
515 virtual bool DoesBoxTouchAreaFrustum( const Vector &mins , const Vector &maxs , int iArea ) = 0; // 60
516 virtual int GetFrustumList( Frustum_t **pList , int listMax ) = 0;
517 virtual bool ShouldUseAreaFrustum( int i ) = 0;
518
519 // Sets the hearing origin (i.e., the origin and orientation of the listener so that the sound system can spatialize
520 // sound appropriately ).
521 virtual void SetAudioState( const AudioState_t& state ) = 0;
522
523 // Sentences / sentence groups
524 virtual int SentenceGroupPick( int groupIndex , char *name , int nameBufLen ) = 0;
525 virtual int SentenceGroupPickSequential( int groupIndex , char *name , int nameBufLen , int sentenceIndex , int reset ) = 0;
526 virtual int SentenceIndexFromName( const char *pSentenceName ) = 0;
527 virtual const char *SentenceNameFromIndex( int sentenceIndex ) = 0;
528 virtual int SentenceGroupIndexFromName( const char *pGroupName ) = 0;
529 virtual const char *SentenceGroupNameFromIndex( int groupIndex ) = 0;
530 virtual float SentenceLength( int sentenceIndex ) = 0;
531
532 // Computes light due to dynamic lighting at a point
533 // If the normal isn't specified, then it'll return the maximum lighting
534 // If pBoxColors is specified (it's an array of 6), then it'll copy the light contribution at each box side.
535 virtual void ComputeLighting( const Vector& pt , const Vector* pNormal , bool bClamp , Vector& color , Vector *pBoxColors = NULL ) = 0;
536
537 // Activates/deactivates an occluder...
538 virtual void ActivateOccluder( int nOccluderIndex , bool bActive ) = 0;
539 virtual bool IsOccluded( const Vector &vecAbsMins , const Vector &vecAbsMaxs ) = 0; // 74
540 virtual int GetOcclusionViewId( void ) = 0;
541
542 // The save restore system allocates memory from a shared memory pool, use this allocator to allocate/free saverestore
543 // memory.
544 virtual void *SaveAllocMemory( size_t num , size_t size ) = 0;
545 virtual void SaveFreeMemory( void *pSaveMem ) = 0;
546
547 // returns info interface for client netchannel
548 virtual INetChannelInfo *GetNetChannelInfo( void ) = 0;
549
550 // Debugging functionality:
551 // Very slow routine to draw a physics model
552 virtual void DebugDrawPhysCollide( const CPhysCollide *pCollide , IMaterial *pMaterial , const matrix3x4_t& transform , const color32 &color ) = 0; //79
553 // This can be used to notify test scripts that we're at a particular spot in the code.
554 virtual void CheckPoint( const char *pName ) = 0; // 80
555 // Draw portals if r_DrawPortals is set (Debugging only)
556 virtual void DrawPortals() = 0;
557 // Determine whether the client is playing back or recording a demo
558 virtual bool IsPlayingDemo( void ) = 0;
559 virtual bool IsRecordingDemo( void ) = 0;
560 virtual bool IsPlayingTimeDemo( void ) = 0;
561 virtual int GetDemoRecordingTick( void ) = 0;
562 virtual int GetDemoPlaybackTick( void ) = 0;
563 virtual int GetDemoPlaybackStartTick( void ) = 0;
564 virtual float GetDemoPlaybackTimeScale( void ) = 0;
565 virtual int GetDemoPlaybackTotalTicks( void ) = 0;
566 // Is the game paused?
567 virtual bool IsPaused( void ) = 0; // 90
568
569 // What is the game timescale multiplied with the host_timescale?
570 virtual float GetTimescale( void ) const = 0;
571
572 // Is the game currently taking a screenshot?
573 virtual bool IsTakingScreenshot( void ) = 0;
574 // Is this a HLTV broadcast ?
575 virtual bool IsHLTV( void ) = 0;
576 // Is this a Replay demo?
577 //virtual bool IsReplay( void ) = 0;
578 // is this level loaded as just the background to the main menu? (active, but unplayable)
579 virtual bool IsLevelMainMenuBackground( void ) = 0;
580 // returns the name of the background level
581 virtual void GetMainMenuBackgroundName( char *dest , int destlen ) = 0;
582
583 // Occlusion system control
584 virtual void SetOcclusionParameters( const OcclusionParams_t ¶ms ) = 0; // 96
585
586 // What language is the user expecting to hear .wavs in, "english" or another...
587 virtual void GetUILanguage( char *dest , int destlen ) = 0;
588
589 // Can skybox be seen from a particular point?
590 virtual SkyboxVisibility_t IsSkyboxVisibleFromPoint( const Vector &vecPoint ) = 0;
591
592 // Get the pristine map entity lump string. (e.g., used by CS to reload the map entities when restarting a round.)
593 virtual const char* GetMapEntitiesString() = 0;
594
595 // Is the engine in map edit mode ?
596 virtual bool IsInEditMode( void ) = 0; // 100
597
598 // current screen aspect ratio (eg. 4.0f/3.0f, 16.0f/9.0f)
599 virtual float GetScreenAspectRatio( int viewportWidth , int viewportHeight ) = 0;
600
601 // allow the game UI to login a user
602 virtual bool REMOVED_SteamRefreshLogin( const char *password , bool isSecure ) = 0; // 100
603 virtual bool REMOVED_SteamProcessCall( bool & finished ) = 0;
604
605 // allow other modules to know about engine versioning (one use is a proxy for network compatability)
606 virtual unsigned int GetEngineBuildNumber() = 0; // engines build
607 virtual const char * GetProductVersionString() = 0; // mods version number (steam.inf)
608
609 // Communicates to the color correction editor that it's time to grab the pre-color corrected frame
610 // Passes in the actual size of the viewport
611 virtual void GrabPreColorCorrectedFrame( int x , int y , int width , int height ) = 0;
612
613 virtual bool IsHammerRunning() const = 0;
614
615 // Inserts szCmdString into the command buffer as if it was typed by the client to his/her console.
616 // And then executes the command string immediately (vs ClientCmd() which executes in the next frame)
617 //
618 // Note: this is NOT checked against the FCVAR_CLIENTCMD_CAN_EXECUTE vars.
619 virtual void ExecuteClientCmd( const char *szCmdString ) = 0; //108
620
621 // returns if the loaded map was processed with HDR info. This will be set regardless
622 // of what HDR mode the player is in.
623 virtual bool MapHasHDRLighting( void ) = 0;
624 virtual bool MapHasLightMapAlphaData( void ) = 0;
625
626 virtual int GetAppID() = 0;
627
628 // Just get the leaf ambient light - no caching, no samples
629 virtual Vector GetLightForPointFast( const Vector &pos , bool bClamp ) = 0;
630
631 // This version does NOT check against FCVAR_CLIENTCMD_CAN_EXECUTE.
632 virtual void ClientCmd_Unrestricted( char const* , int , bool ) = 0;
633 virtual void ClientCmd_Unrestricted( const char *szCmdString ) = 0; // 114
634
635 // This used to be accessible through the cl_restrict_server_commands cvar.
636 // By default, Valve games restrict the server to only being able to execute commands marked with FCVAR_SERVER_CAN_EXECUTE.
637 // By default, mods are allowed to execute any server commands, and they can restrict the server's ability to execute client
638 // commands with this function.
639 virtual void SetRestrictServerCommands( bool bRestrict ) = 0;
640
641 // If set to true (defaults to true for Valve games and false for others), then IVEngineClient::ClientCmd
642 // can only execute things marked with FCVAR_CLIENTCMD_CAN_EXECUTE.
643 virtual void SetRestrictClientCommands( bool bRestrict ) = 0;
644
645 // Sets the client renderable for an overlay's material proxy to bind to
646 virtual void SetOverlayBindProxy( int iOverlayID , void *pBindProxy ) = 0;
647
648 virtual bool CopyFrameBufferToMaterial( const char *pMaterialName ) = 0;
649
650 // Causes the engine to read in the user's configuration on disk
651 virtual void ReadConfiguration( const int iController , const bool readDefault ) = 0;
652
653 virtual void SetAchievementMgr( IAchievementMgr *pAchievementMgr ) = 0;
654 virtual IAchievementMgr*GetAchievementMgr() = 0;
655 virtual bool MapLoadFailed( void ) = 0;
656 virtual void SetMapLoadFailed( bool bState ) = 0;
657 virtual bool IsLowViolence() = 0;
658 virtual const char *GetMostRecentSaveGame( void ) = 0;
659 virtual void SetMostRecentSaveGame( const char *lpszFilename ) = 0;
660 virtual void StartXboxExitingProcess() = 0;
661 virtual bool IsSaveInProgress() = 0;
662 virtual bool IsAutoSaveDangerousInProgress( void ) = 0;
663 virtual uint OnStorageDeviceAttached( int iController ) = 0;
664 virtual void OnStorageDeviceDetached( int iController ) = 0;
665 virtual char* const GetSaveDirName( void ) = 0;
666 // generic screenshot writing
667 virtual void WriteScreenshot( const char *pFilename ) = 0;
668 virtual void ResetDemoInterpolation( void ) = 0;
669 // For non-split screen games this will always be zero
670 virtual int GetActiveSplitScreenPlayerSlot() = 0;
671 virtual int SetActiveSplitScreenPlayerSlot( int slot ) = 0;
672 // This is the current # of players on the local host
673 virtual bool SetLocalPlayerIsResolvable( char const *pchContext , int nLine , bool bResolvable ) = 0;
674 virtual bool IsLocalPlayerResolvable() = 0;
675 virtual int GetSplitScreenPlayer( int nSlot ) = 0;
676 virtual bool IsSplitScreenActive() = 0;
677 virtual bool IsValidSplitScreenSlot( int nSlot ) = 0;
678 virtual int FirstValidSplitScreenSlot() = 0; // -1 == invalid
679 virtual int NextValidSplitScreenSlot( int nPreviousSlot ) = 0; // -1 == invalid
680 //Finds or Creates a shared memory space, the returned pointer will automatically be AddRef()ed
681 virtual ISPSharedMemory *GetSinglePlayerSharedMemorySpace( const char *szName , int ent_num = MAX_EDICTS ) = 0;
682 // Computes an ambient cube that includes ALL dynamic lights
683 virtual void ComputeLightingCube( const Vector& pt , bool bClamp , Vector *pBoxColors ) = 0;
684 //All callbacks have to be registered before demo recording begins. TODO: Macro'ize a way to do it at startup
685 virtual void RegisterDemoCustomDataCallback( string_t szCallbackSaveID , pfnDemoCustomDataCallback pCallback ) = 0;
686 virtual void RecordDemoCustomData( pfnDemoCustomDataCallback pCallback , const void *pData , size_t iDataLength ) = 0;
687 // global sound pitch scaling
688 virtual void SetPitchScale( float flPitchScale ) = 0;
689 virtual float GetPitchScale( void ) = 0;
690 // Load/unload the SFM - used by Replay
691 virtual bool LoadFilmmaker() = 0;
692 virtual void UnloadFilmmaker() = 0;
693 // leaf flag management. Allows fast leaf enumeration of leaves that have a flag set
694 // set a bit in a leaf flag
695 virtual void SetLeafFlag( int nLeafIndex , int nFlagBits ) = 0;
696 // you must call this once done modifying flags. Not super fast.
697 virtual void RecalculateBSPLeafFlags( void ) = 0;
698 virtual bool DSPGetCurrentDASRoomNew( void ) = 0;
699 virtual bool DSPGetCurrentDASRoomChanged( void ) = 0;
700 virtual bool DSPGetCurrentDASRoomSkyAbove( void ) = 0;
701 virtual float DSPGetCurrentDASRoomSkyPercent( void ) = 0;
702 virtual void SetMixGroupOfCurrentMixer( const char *szgroupname , const char *szparam , float val , int setMixerType ) = 0;
703 virtual int GetMixLayerIndex( const char *szmixlayername ) = 0;
704 virtual void SetMixLayerLevel( int index , float level ) = 0;
705 virtual int GetMixGroupIndex( char const* groupname ) = 0;
706 virtual void SetMixLayerTriggerFactor( int i1 , int i2 , float fl ) = 0;
707 virtual void SetMixLayerTriggerFactor( char const* char1 , char const* char2 , float fl ) = 0;
708 virtual bool IsCreatingReslist() = 0;
709 virtual bool IsCreatingXboxReslist() = 0;
710 virtual void SetTimescale( float flTimescale ) = 0;
711 // Methods to set/get a gamestats data container so client & server running in same process can send combined data
712 virtual void SetGamestatsData( CGamestatsData *pGamestatsData ) = 0;
713 virtual CGamestatsData *GetGamestatsData() = 0;
714 virtual void GetMouseDelta( int &dx , int &dy , bool b ) = 0; // unknown
715 // Given the string pBinding which may be bound to a key,
716 // returns the string name of the key to which this string is bound. Returns NULL if no such binding exists
717 // Increment start count to iterate through multiple keys bound to the same binding
718 // iAllowJoystick defaults to -1 witch returns joystick and non-joystick binds, 0 returns only non-joystick, 1 returns only joystick
719 virtual const char *Key_LookupBindingEx( const char *pBinding , int iUserId = -1 , int iStartCount = 0 , int iAllowJoystick = -1 ) = 0;
720 virtual int Key_CodeForBinding( char const* , int , int , int ) = 0;
721 // Updates dynamic light state. Necessary for light cache to work properly for d- and elights
722 virtual void UpdateDAndELights( void ) = 0;
723 // Methods to get bug count for internal dev work stat tracking.
724 // Will get the bug count and clear it every map transition
725 virtual int GetBugSubmissionCount() const = 0;
726 virtual void ClearBugSubmissionCount() = 0;
727 // Is there water anywhere in the level?
728 virtual bool DoesLevelContainWater() const = 0;
729 // How much time was spent in server simulation?
730 virtual float GetServerSimulationFrameTime() const = 0;
731 virtual void SolidMoved( class IClientEntity *pSolidEnt , class ICollideable *pSolidCollide , const Vector* pPrevAbsOrigin , bool accurateBboxTriggerChecks ) = 0;
732 virtual void TriggerMoved( class IClientEntity *pTriggerEnt , bool accurateBboxTriggerChecks ) = 0;
733 // Using area bits, check whether the area of the specified point flows into the other areas
734 virtual void ComputeLeavesConnected( const Vector &vecOrigin , int nCount , const int *pLeafIndices , bool *pIsConnected ) = 0;
735 // Is the engine in Commentary mode?
736 virtual bool IsInCommentaryMode( void ) = 0;
737 virtual void SetBlurFade( float amount ) = 0;
738 virtual bool IsTransitioningToLoad() = 0;
739 virtual void SearchPathsChangedAfterInstall() = 0;
740 virtual void ConfigureSystemLevel( int nCPULevel , int nGPULevel ) = 0;
741 virtual void SetConnectionPassword( char const *pchCurrentPW ) = 0;
742 virtual CSteamAPIContext* GetSteamAPIContext() = 0;
743 virtual void SubmitStatRecord( char const *szMapName , uint uiBlobVersion , uint uiBlobSize , const void *pvBlob ) = 0;
744 // Sends a key values server command, not allowed from scripts execution
745 // Params:
746 // pKeyValues - key values to be serialized and sent to server
747 // the pointer is deleted inside the function: pKeyValues->deleteThis()
748 virtual void ServerCmdKeyValues( KeyValues *pKeyValues ) = 0; // 203
749 // Tells the engine what and where to paint
750 virtual void SpherePaintSurface( const model_t* model , const Vector& location , unsigned char chr , float fl1 , float fl2 ) = 0;
751 virtual bool HasPaintmap( void ) = 0;
752 // Enable paint in the engine for project Paint
753 virtual void EnablePaintmapRender() = 0;
754 //virtual void TracePaintSurface( const model_t *model, const Vector& position, float radius, CUtlVector<Color>& surfColors ) = 0;
755 virtual void SphereTracePaintSurface( const model_t* model , const Vector& position , const Vector &vec2 , float radius , CUtlVector<unsigned char , CUtlMemory<unsigned char , int>> & utilVecShit ) = 0;
756 virtual void RemoveAllPaint() = 0;
757 virtual void PaintAllSurfaces( unsigned char uchr ) = 0;
758 virtual void RemovePaint( const model_t* model ) = 0;
759
760 virtual bool IsActiveApp() = 0;
761
762 // is this client running inside the same process as an active server?
763 virtual bool IsClientLocalToActiveServer() = 0;
764
765 // Callback for LevelInit to tick the progress bar during time consuming operations
766 virtual void TickProgressBar() = 0;
767
768 // Returns the requested input context
769 virtual InputContextHandle_t GetInputContext( EngineInputContextId_t id ) = 0;
770 virtual void GetStartupImage( char* filename , int size ) = 0;
771 virtual bool IsUsingLocalNetworkBackdoor( void ) = 0;
772 virtual void SaveGame( const char* , bool , char* , int , char* , int ) = 0;
773 virtual void GetGenericMemoryStats(/* GenericMemoryStat_t */ void ** ) = 0;
774 virtual bool GameHasShutdownAndFlushedMemory( void ) = 0;
775 virtual int GetLastAcknowledgedCommand( void ) = 0;
776 virtual void FinishContainerWrites( int i ) = 0;
777 virtual void FinishAsyncSave( void ) = 0;
778 virtual int GetServerTick( void ) = 0;
779 virtual const char* GetModDirectory( void ) = 0;
780 virtual bool AudioLanguageChanged( void ) = 0;
781 virtual bool IsAutoSaveInProgress( void ) = 0;
782 virtual void StartLoadingScreenForCommand( const char* command ) = 0;
783 virtual void StartLoadingScreenForKeyValues( KeyValues* values ) = 0;
784 virtual void SOSSetOpvarFloat( const char* , float ) = 0;
785 virtual void SOSGetOpvarFloat( const char* , float & ) = 0;
786 virtual bool IsSubscribedMap( const char* , bool ) = 0;
787 virtual bool IsFeaturedMap( const char* , bool ) = 0;
788 virtual void GetDemoPlaybackParameters( void ) = 0;
789 virtual int GetClientVersion( void ) = 0;
790 virtual bool IsDemoSkipping( void ) = 0;
791 virtual void SetDemoImportantEventData( const KeyValues* values ) = 0;
792 virtual void ClearEvents( void ) = 0;
793 virtual int GetSafeZoneXMin( void ) = 0;
794 virtual bool IsVoiceRecording( void ) = 0;
795 virtual void ForceVoiceRecordOn( void ) = 0;
796 virtual bool IsReplay( void ) = 0;
797};
798
799#pragma endregion
800
801#pragma region IBaseClientDLL
802
803class CGlobalVarsBase;
804class IClientNetworkable;
805
806typedef IClientNetworkable* ( *CreateClientClassFn )( int entnum , int serialNum );
807typedef IClientNetworkable* ( *CreateEventFn )( );
808
809class ClientClass
810{
811public:
812 const char* GetName() { return m_pNetworkName; }
813
814public:
815 CreateClientClassFn m_pCreateFn;
816 CreateEventFn m_pCreateEventFn; // Only called for event objects.
817 char *m_pNetworkName;
818 RecvTable *m_pRecvTable;
819 ClientClass *m_pNext;
820 int m_ClassID; // Managed by the engine.
821};
822
823class CViewSetup;
824class CEngineSprite;
825
826#define FFADE_IN 0x0001 // Just here so we don't pass 0 into the function
827#define FFADE_OUT 0x0002 // Fade out (not in)
828#define FFADE_MODULATE 0x0004 // Modulate (don't blend)
829#define FFADE_STAYOUT 0x0008 // ignores the duration, stays faded out until new ScreenFade message received
830#define FFADE_PURGE 0x0010 // Purges all other fades, replacing them with this one
831
832#define SCREENFADE_FRACBITS 9 // which leaves 16-this for the integer part
833// This structure is sent over the net to describe a screen fade event
834struct ScreenFade_t
835{
836 unsigned short duration; // FIXED 16 bit, with SCREENFADE_FRACBITS fractional, seconds duration
837 unsigned short holdTime; // FIXED 16 bit, with SCREENFADE_FRACBITS fractional, seconds duration until reset (fade & hold)
838 short fadeFlags; // flags
839 byte r , g , b , a; // fade to color ( max alpha )
840};
841
842enum ClientFrameStage_t
843{
844 FRAME_UNDEFINED = -1 , // (haven't run any frames yet)
845 FRAME_START ,
846
847 // A network packet is being recieved
848 FRAME_NET_UPDATE_START ,
849 // Data has been received and we're going to start calling PostDataUpdate
850 FRAME_NET_UPDATE_POSTDATAUPDATE_START ,
851 // Data has been received and we've called PostDataUpdate on all data recipients
852 FRAME_NET_UPDATE_POSTDATAUPDATE_END ,
853 // We've received all packets, we can now do interpolation, prediction, etc..
854 FRAME_NET_UPDATE_END ,
855
856 // We're about to start rendering the scene
857 FRAME_RENDER_START ,
858 // We've finished rendering the scene.
859 FRAME_RENDER_END
860};
861
862struct bf_write;
863struct bf_read;
864
865class IBaseClientDLL
866{
867public:
868 virtual int Connect( CreateInterfaceFn appSystemFactory , CGlobalVarsBase *pGlobals ) = 0;
869 virtual int Disconnect( void ) = 0;
870 virtual int Init( CreateInterfaceFn appSystemFactory , CGlobalVarsBase *pGlobals ) = 0;
871 virtual void PostInit() = 0;
872 virtual void Shutdown( void ) = 0;
873 virtual void LevelInitPreEntity( char const* pMapName ) = 0;
874 virtual void LevelInitPostEntity() = 0;
875 virtual void LevelShutdown( void ) = 0;
876 virtual ClientClass *GetAllClasses( void ) = 0;
877 virtual int HudVidInit( void ) = 0;
878 virtual void HudProcessInput( bool bActive ) = 0;
879 virtual void HudUpdate( bool bActive ) = 0;
880 virtual void HudReset( void ) = 0;
881 virtual void HudText( const char * message ) = 0;
882 virtual void ShouldDrawDropdownConsole( void ) = 0;
883 virtual void IN_ActivateMouse( void ) = 0;
884 virtual void IN_DeactivateMouse( void ) = 0;
885 virtual void IN_Accumulate( void ) = 0;
886 virtual void IN_ClearStates( void ) = 0;
887 virtual bool IN_IsKeyDown( const char *name , bool& isdown ) = 0;
888 virtual int IN_KeyEvent( int eventcode , ButtonCode_t keynum , const char *pszCurrentBinding ) = 0;
889 virtual void CreateMove( int sequence_number , float input_sample_frametime , bool active ) = 0;
890 virtual void ExtraMouseSample( float frametime , bool active ) = 0;
891 virtual bool WriteUsercmdDeltaToBuffer( int nSlot , bf_write *buf , int from , int to , bool isnewcommand ) = 0;
892 virtual void EncodeUserCmdToBuffer( int nSlot , bf_write& buf , int slot ) = 0;
893 virtual void DecodeUserCmdFromBuffer( int nSlot , bf_read& buf , int slot ) = 0;
894 virtual void View_Render( vrect_t *rect ) = 0;
895 virtual void RenderView( const CViewSetup &view , int nClearFlags , int whatToDraw ) = 0;
896 virtual void View_Fade( ScreenFade_t *pSF ) = 0;
897 virtual void SetCrosshairAngle( const QAngle& angle ) = 0;
898 virtual void InitSprite( CEngineSprite *pSprite , const char *loadname ) = 0;
899 virtual void ShutdownSprite( CEngineSprite *pSprite ) = 0;
900 virtual int GetSpriteSize( void ) const = 0;
901 virtual void VoiceStatus( int entindex , int iSsSlot , qboolean bTalking ) = 0;
902 virtual int PlayerAudible( int audible ) = 0;
903 virtual void InstallStringTableCallback( char const *tableName ) = 0;
904 virtual void FrameStageNotify( ClientFrameStage_t curStage ) = 0;
905 virtual bool DispatchUserMessage( int msg_type , int unk1 , int unk2 , bf_read &msg_data ) = 0;
906};
907
908#pragma endregion
909
910#pragma region IClientEntity
911
912class CBaseHandle;
913class ICollideable;
914class IClientUnknown;
915class IClientRenderable;
916class IClientNetworkable;
917class IClientThinkable;
918class IClientEntity;
919class IClientEntityList;
920class CBaseViewModel;
921
922class IClientUnknown
923{
924public:
925 virtual ICollideable* GetCollideable() = 0;
926 virtual IClientNetworkable* GetClientNetworkable() = 0;
927 virtual IClientRenderable* GetClientRenderable() = 0;
928 virtual IClientEntity* GetIClientEntity() = 0;
929 virtual IClientEntity* GetBaseEntity() = 0;
930 virtual IClientThinkable* GetClientThinkable() = 0;
931};
932
933struct model_t;
934
935typedef unsigned short ClientShadowHandle_t;
936
937enum
938{
939 CLIENTSHADOW_INVALID_HANDLE = (ClientShadowHandle_t)~0
940};
941
942typedef unsigned short ClientRenderHandle_t;
943
944enum
945{
946 INVALID_CLIENT_RENDER_HANDLE = (ClientRenderHandle_t)0xffff ,
947};
948
949struct RenderableInstance_t
950{
951 uint8 m_nAlpha;
952};
953
954class IClientRenderable
955{
956public:
957 virtual IClientUnknown* GetIClientUnknown() = 0;
958 virtual Vector const& GetRenderOrigin() = 0;
959 virtual QAngle const& GetRenderAngles() = 0;
960 virtual bool ShouldDraw() = 0;
961 virtual bool IsTransparent() = 0;
962 virtual void Unused();
963 virtual ClientShadowHandle_t GetShadowHandle() const = 0;
964 virtual ClientRenderHandle_t& RenderHandle() = 0;
965 virtual const model_t* GetModel() const = 0;
966 virtual int DrawModel( int flags , const RenderableInstance_t &instance ) = 0;
967 virtual int GetBody() = 0;
968 virtual void GetColorModulation( float* color ) = 0;
969 virtual bool LODTest() = 0;
970 virtual bool SetupBones( matrix3x4_t *pBoneToWorldOut , int nMaxBones , int boneMask , float currentTime ) = 0;
971};
972
973enum ShouldTransmitState_t
974{
975 SHOULDTRANSMIT_START = 0 ,
976 SHOULDTRANSMIT_END
977};
978
979enum DataUpdateType_t
980{
981 DATA_UPDATE_CREATED = 0 ,
982 DATA_UPDATE_DATATABLE_CHANGED ,
983};
984
985class IClientNetworkable
986{
987public:
988 virtual IClientUnknown* GetIClientUnknown() = 0;
989 virtual void Release() = 0;
990 virtual ClientClass* GetClientClass() = 0;
991 virtual void NotifyShouldTransmit( ShouldTransmitState_t state ) = 0;
992 virtual void OnPreDataChanged( DataUpdateType_t updateType ) = 0;
993 virtual void OnDataChanged( DataUpdateType_t updateType ) = 0;
994 virtual void PreDataUpdate( DataUpdateType_t updateType ) = 0;
995 virtual void PostDataUpdate( DataUpdateType_t updateType ) = 0;
996 virtual void unknown() = 0;
997 virtual bool IsDormant() = 0;
998 virtual int Index() const = 0;
999 virtual void ReceiveMessage( int classID , bf_read &msg ) = 0;
1000 virtual void* GetDataTableBasePtr() = 0;
1001 virtual void SetDestroyedOnRecreateEntities() = 0;
1002};
1003
1004class CClientThinkHandlePtr;
1005typedef CClientThinkHandlePtr* ClientThinkHandle_t;
1006
1007class IClientThinkable
1008{
1009public:
1010 virtual IClientUnknown* GetIClientUnknown() = 0;
1011 virtual void ClientThink() = 0;
1012 virtual ClientThinkHandle_t GetThinkHandle() = 0;
1013 virtual void SetThinkHandle( ClientThinkHandle_t* hThink ) = 0;
1014 virtual void Release() = 0;
1015};
1016
1017class IClientEntityList
1018{
1019public:
1020 virtual IClientNetworkable* GetClientNetworkable( int entnum ) = 0;
1021 virtual IClientNetworkable* GetClientNetworkableFromHandle( CBaseHandle hEnt ) = 0;
1022 virtual IClientUnknown* GetClientUnknownFromHandle( CBaseHandle hEnt ) = 0;
1023 virtual IClientEntity* GetClientEntity( int entnum ) = 0;
1024 virtual IClientEntity* GetClientEntityFromHandle( DWORD hEnt ) = 0;
1025 virtual int NumberOfEntities( bool bIncludeNonNetworkable ) = 0;
1026 virtual int GetHighestEntityIndex( void ) = 0;
1027 virtual void SetMaxEntities( int maxents ) = 0;
1028 virtual int GetMaxEntities() = 0;
1029};
1030
1031class __declspec ( novtable ) IClientEntity : public IClientUnknown , public IClientRenderable , public IClientNetworkable , public IClientThinkable
1032{
1033public:
1034
1035 const Vector& GetAbsOrigin()
1036 {
1037 typedef const Vector&( __thiscall* oGetAbsOrigin )( PVOID );
1038 return call_func< oGetAbsOrigin >( this , 10 )( this );
1039 }
1040
1041 const QAngle& GetAbsAngles()
1042 {
1043 typedef const QAngle&( __thiscall* oGetAbsAngles )( PVOID );
1044 return call_func< oGetAbsAngles >( this , 11 )( this );
1045 }
1046
1047 char* GetWeaponName( DWORD pWeapon )
1048 {
1049 typedef char*( __thiscall* GetWeaponNameFn )( PVOID );
1050 GetWeaponNameFn WeaponName = (GetWeaponNameFn)( ( *( PDWORD* )this )[378] );
1051 return WeaponName( (PVOID)pWeapon );
1052 }
1053
1054 Vector GetOrigin()
1055 {
1056 return *reinterpret_cast<Vector*>( ( DWORD )this + (DWORD)m_vecOrigin );
1057 }
1058
1059 int GetLocalFovStart()
1060 {
1061 return *reinterpret_cast<int*>( ( DWORD )this + (DWORD)m_iFOVStart );
1062 }
1063
1064 int GetEffects()
1065 {
1066 return *reinterpret_cast<int*>( ( DWORD )this + (DWORD)m_fEffects );
1067 }
1068
1069 int GetTeamNum()
1070 {
1071 return *reinterpret_cast<int*>( ( DWORD )this + (DWORD)m_iTeamNum );
1072 }
1073
1074 QAngle GetEyeAngles()
1075 {
1076 return *reinterpret_cast<QAngle*>( ( DWORD )this + (DWORD)m_angEyeAngles );
1077 }
1078
1079 int GetHealth()
1080 {
1081 return *reinterpret_cast<int*>( ( DWORD )this + (DWORD)m_iHealth );
1082 }
1083
1084 int GetArmorValue()
1085 {
1086 return *reinterpret_cast<int*>( ( DWORD )this + (DWORD)m_ArmorValue );
1087 }
1088
1089 int GetShotsFired()
1090 {
1091 return *reinterpret_cast<int*>( ( DWORD )this + (DWORD)m_iShotsFired );
1092 }
1093
1094 BYTE GetMoveType()
1095 {
1096 return *reinterpret_cast<BYTE*>( ( DWORD )this + (DWORD)m_MoveType );
1097 }
1098
1099 BYTE GetlifeState()
1100 {
1101 return *reinterpret_cast<BYTE*>( ( DWORD )this + (DWORD)m_lifeState );
1102 }
1103
1104 int GetFlags()
1105 {
1106 return *reinterpret_cast<int*>( ( DWORD )this + (DWORD)m_fFlags );
1107 }
1108
1109 Vector GetViewOffset()
1110 {
1111 return *reinterpret_cast<Vector*>( ( DWORD )this + (DWORD)m_vecViewOffset );
1112 }
1113
1114 Vector GetAimPunch()
1115 {
1116 return *reinterpret_cast<Vector*>( ( DWORD )this + (DWORD)m_aimPunchAngle );
1117 }
1118
1119 DWORD GetAcitveWeapon()
1120 {
1121 return *reinterpret_cast<DWORD*>( ( DWORD )this + (DWORD)m_hActiveWeapon );
1122 }
1123
1124 int GetIndex() {
1125 return *(int*)( ( DWORD )this + 0x64 );
1126 }
1127
1128 int GetGlowIndex() {
1129 return *(int*)( ( DWORD )this + m_iGlowIndex );
1130 }
1131
1132 UINT* GetWeapons() {
1133 // DT_BasePlayer -> m_hMyWeapons
1134 return (UINT*)( ( DWORD )this + m_hMyWeapons );
1135 }
1136
1137 CBaseViewModel* GetViewModel()
1138 {
1139 // DT_BasePlayer -> m_hViewModel
1140 return (CBaseViewModel*)g_pClientEntList->GetClientEntityFromHandle( *(PDWORD)( (DWORD)this + m_hViewModel ) );
1141 }
1142};
1143
1144#pragma endregion
1145
1146#pragma region ISurface
1147
1148enum FontDrawType_t
1149{
1150 FONT_DRAW_DEFAULT = 0 ,
1151 FONT_DRAW_NONADDITIVE ,
1152 FONT_DRAW_ADDITIVE ,
1153 FONT_DRAW_TYPE_COUNT = 2 ,
1154};
1155
1156enum EFontFlags
1157{
1158 FONTFLAG_NONE ,
1159 FONTFLAG_ITALIC = 0x001 ,
1160 FONTFLAG_UNDERLINE = 0x002 ,
1161 FONTFLAG_STRIKEOUT = 0x004 ,
1162 FONTFLAG_SYMBOL = 0x008 ,
1163 FONTFLAG_ANTIALIAS = 0x010 ,
1164 FONTFLAG_GAUSSIANBLUR = 0x020 ,
1165 FONTFLAG_ROTARY = 0x040 ,
1166 FONTFLAG_DROPSHADOW = 0x080 ,
1167 FONTFLAG_ADDITIVE = 0x100 ,
1168 FONTFLAG_OUTLINE = 0x200 ,
1169 FONTFLAG_CUSTOM = 0x400 ,
1170 FONTFLAG_BITMAP = 0x800 ,
1171};
1172
1173class ISurface
1174{
1175public:
1176 void DrawSetColor( Color col )
1177 {
1178 typedef void( __thiscall* oDrawSetColor )( PVOID , Color );
1179 call_func< oDrawSetColor >( this , HookIndexSDK::ISurface::DrawSetColor1 )( this , col );
1180 }
1181 void DrawSetColor( int r , int g , int b , int a )
1182 {
1183 typedef void( __thiscall* oDrawSetColor )( PVOID , int , int , int , int );
1184 call_func< oDrawSetColor >( this , HookIndexSDK::ISurface::DrawSetColor2 )( this , r , g , b , a );
1185 }
1186 void DrawFilledRect( int x0 , int y0 , int x1 , int y1 )
1187 {
1188 typedef void( __thiscall* oDrawFilledRect )( PVOID , int , int , int , int );
1189 call_func< oDrawFilledRect >( this , HookIndexSDK::ISurface::DrawFilledRect )( this , x0 , y0 , x1 , y1 );
1190 }
1191 void DrawOutlinedRect( int x0 , int y0 , int x1 , int y1 )
1192 {
1193 typedef void( __thiscall* oDrawOutlinedRect )( PVOID , int , int , int , int );
1194 call_func< oDrawOutlinedRect >( this , HookIndexSDK::ISurface::DrawOutlinedRect )( this , x0 , y0 , x1 , y1 );
1195 }
1196 void DrawLine( int x0 , int y0 , int x1 , int y1 )
1197 {
1198 typedef void( __thiscall* oDrawLine )( PVOID , int , int , int , int );
1199 call_func< oDrawLine >( this , HookIndexSDK::ISurface::DrawLine )( this , x0 , y0 , x1 , y1 );
1200 }
1201 void DrawSetTextFont( unsigned long hFont )
1202 {
1203 typedef void( __thiscall* oDrawSetTextFont )( PVOID , unsigned long );
1204 call_func< oDrawSetTextFont >( this , HookIndexSDK::ISurface::DrawSetTextFont )( this , hFont );
1205 }
1206 void DrawSetTextColor( Color col )
1207 {
1208 typedef void( __thiscall* oDrawSetTextColor )( PVOID , Color );
1209 call_func< oDrawSetTextColor >( this , HookIndexSDK::ISurface::DrawSetTextColor )( this , col );
1210 }
1211 void DrawSetTextPos( int x , int y )
1212 {
1213 typedef void( __thiscall* oDrawSetTextPos )( PVOID , int , int );
1214 call_func< oDrawSetTextPos >( this , HookIndexSDK::ISurface::DrawSetTextPos )( this , x , y );
1215 }
1216 void DrawPrintText( wchar_t *text , int textLen , FontDrawType_t drawType = FONT_DRAW_DEFAULT )
1217 {
1218 typedef void( __thiscall* oDrawPrintText )( PVOID , wchar_t* , int , FontDrawType_t );
1219 call_func< oDrawPrintText >( this , HookIndexSDK::ISurface::DrawPrintText )( this , text , textLen , drawType );
1220 }
1221 DWORD FontCreate()
1222 {
1223 typedef DWORD( __thiscall* oCreateFont )( PVOID );
1224 return call_func< oCreateFont >( this , HookIndexSDK::ISurface::FontCreate )( this );
1225 }
1226 void SetFontGlyphSet( unsigned long font , const char *windowsFontName , int tall , int weight , int blur , int scanlines , int flags , int nRangeMin = 0 , int nRangeMax = 0 )
1227 {
1228 typedef void( __thiscall* oSetFontGlyphSet )( PVOID , unsigned long , const char * , int , int , int , int , int , int , int );
1229 call_func< oSetFontGlyphSet >( this , HookIndexSDK::ISurface::SetFontGlyphSet )( this , font , windowsFontName , tall , weight , blur , scanlines , flags , nRangeMin , nRangeMax );
1230 }
1231 void GetTextSize( unsigned long font , const wchar_t *text , int &wide , int &tall )
1232 {
1233 typedef void( __thiscall* oGetTextSize )( PVOID , unsigned long , const wchar_t* , int& , int& );
1234 call_func< oGetTextSize >( this , HookIndexSDK::ISurface::GetTextSize )( this , font , text , wide , tall );
1235 }
1236};
1237
1238#pragma endregion
1239
1240#pragma region IPanel
1241
1242class IPanel
1243{
1244public:
1245 bool IsVisible( unsigned int vguiPanel )
1246 {
1247 typedef bool( __thiscall* oIsVisible )( PVOID , unsigned int );
1248 return call_func< oIsVisible >( this , HookIndexSDK::IPanel::IsVisible )( this , vguiPanel );
1249 }
1250 const char* GetName( unsigned int vguiPanel )
1251 {
1252 typedef const char*( __thiscall* oGetName )( PVOID , unsigned int );
1253 return call_func< oGetName >( this , HookIndexSDK::IPanel::GetName )( this , vguiPanel );
1254 }
1255 void PaintTraverse( unsigned int vguiPanel , bool forceRepaint , bool allowForce = true )
1256 {
1257 typedef void( __thiscall* oPaintTraverse )( PVOID , unsigned int , bool , bool );
1258 return call_func< oPaintTraverse >( this , HookIndexSDK::IPanel::PaintTraverse )( this , vguiPanel , forceRepaint , allowForce );
1259 }
1260};
1261
1262#pragma endregion
1263
1264#pragma region CGameTrace
1265
1266#define DISPSURF_FLAG_SURFACE (1<<0)
1267#define DISPSURF_FLAG_WALKABLE (1<<1)
1268#define DISPSURF_FLAG_BUILDABLE (1<<2)
1269#define DISPSURF_FLAG_SURFPROP1 (1<<3)
1270#define DISPSURF_FLAG_SURFPROP2 (1<<4)
1271
1272#define PlayerVisibleMask (CONTENTS_HITBOX | CONTENTS_CURRENT_UP | CONTENTS_CURRENT_DOWN | CONTENTS_CURRENT_270 | CONTENTS_CURRENT_180 | CONTENTS_MOVEABLE | CONTENTS_SOLID | CONTENTS_WINDOW | CONTENTS_GRATE)
1273
1274struct cplane_t
1275{
1276 Vector normal;
1277 float dist;
1278 byte type; // for fast side tests
1279 byte signbits; // signx + (signy<<1) + (signz<<1)
1280 byte pad[2];
1281};
1282
1283struct csurface_t
1284{
1285 const char *name;
1286 short surfaceProps;
1287 unsigned short flags; // BUGBUG: These are declared per surface, not per material, but this database is per-material now
1288};
1289
1290class CBaseTrace
1291{
1292public:
1293 // Displacement flags tests.
1294 bool IsDispSurface( void ) { return ( ( dispFlags & DISPSURF_FLAG_SURFACE ) != 0 ); }
1295 bool IsDispSurfaceWalkable( void ) { return ( ( dispFlags & DISPSURF_FLAG_WALKABLE ) != 0 ); }
1296 bool IsDispSurfaceBuildable( void ) { return ( ( dispFlags & DISPSURF_FLAG_BUILDABLE ) != 0 ); }
1297 bool IsDispSurfaceProp1( void ) { return ( ( dispFlags & DISPSURF_FLAG_SURFPROP1 ) != 0 ); }
1298 bool IsDispSurfaceProp2( void ) { return ( ( dispFlags & DISPSURF_FLAG_SURFPROP2 ) != 0 ); }
1299public:
1300 // these members are aligned!!
1301 Vector startpos; // start position
1302 Vector endpos; // final position
1303 cplane_t plane; // surface normal at impact
1304 float fraction; // time completed, 1.0 = didn't hit anything
1305 int contents; // contents on other side of surface hit
1306 unsigned short dispFlags; // displacement flags for marking surfaces with data
1307 bool allsolid; // if true, plane is not valid
1308 bool startsolid; // if true, the initial point was in a solid area
1309 CBaseTrace() { }
1310};
1311
1312class CGameTrace : public CBaseTrace
1313{
1314public:
1315
1316 bool IsVisible() const
1317 {
1318 return fraction > 0.97f;
1319 }
1320
1321public:
1322 float fractionleftsolid; // time we left a solid, only valid if we started in solid
1323 csurface_t surface; // surface hit (impact surface)
1324 int hitgroup; // 0 == generic, non-zero is specific body part
1325 short physicsbone; // physics bone hit by trace in studio
1326 unsigned short worldSurfaceIndex; // Index of the msurface2_t, if applicable
1327 IClientEntity *m_pEnt;
1328 int hitbox; // box hit by trace in studio
1329 CGameTrace() { }
1330};
1331
1332typedef CGameTrace trace_t;
1333
1334#pragma endregion
1335
1336#pragma region CGlobalVarsBase
1337
1338class CGlobalVarsBase
1339{
1340public:
1341 float realtime;
1342 int framecount;
1343 float absolute_frametime;
1344 float absolute_framestarttimestddev;
1345 float curtime;
1346 float frameTime;
1347 int maxClients;
1348 int tickcount;
1349 float interval_per_tick;
1350 float interpolation_amount;
1351 int simThicksThisFrame;
1352 int network_protocol;
1353};
1354
1355#pragma endregion
1356
1357#pragma region IPlayerInfoManager
1358
1359class IPlayerInfo;
1360struct edict_t;
1361
1362class IPlayerInfoManager
1363{
1364public:
1365 virtual IPlayerInfo* GetPlayerInfo( edict_t *pEdict ) = 0;
1366 virtual CGlobalVarsBase* GetGlobalVars() = 0;
1367};
1368
1369#pragma endregion
1370
1371#pragma region IClientMode
1372
1373class IClientMode
1374{
1375public:
1376 bool CL_CreateMove( float flInputSampleTime , CUserCmd* cmd )
1377 {
1378 typedef bool( __thiscall* oCreateMove )( PVOID , float , CUserCmd* );
1379 return call_func< oCreateMove >( this , HookIndexSDK::IClientMode::CL_CreateMove )( this , flInputSampleTime , cmd );
1380 }
1381};
1382
1383#pragma endregion
1384
1385#pragma region IEngineSound
1386
1387class IRecipientFilter
1388{
1389public:
1390 virtual ~IRecipientFilter() {}
1391
1392 virtual bool IsReliable( void ) const = 0;
1393 virtual bool IsInitMessage( void ) const = 0;
1394
1395 virtual int GetRecipientCount( void ) const = 0;
1396 virtual int GetRecipientIndex( int slot ) const = 0;
1397};
1398
1399//-----------------------------------------------------------------------------
1400// channels
1401//-----------------------------------------------------------------------------
1402enum
1403{
1404 CHAN_REPLACE = -1 ,
1405 CHAN_AUTO = 0 ,
1406 CHAN_WEAPON = 1 ,
1407 CHAN_VOICE = 2 ,
1408 CHAN_ITEM = 3 ,
1409 CHAN_BODY = 4 ,
1410 CHAN_STREAM = 5 , // allocate stream channel from the static or dynamic area
1411 CHAN_STATIC = 6 , // allocate channel from the static area
1412 CHAN_VOICE2 = 7 ,
1413 CHAN_VOICE_BASE = 8 , // allocate channel for network voice data
1414 CHAN_USER_BASE = ( CHAN_VOICE_BASE + 128 ) // Anything >= this number is allocated to game code.
1415};
1416
1417//-----------------------------------------------------------------------------
1418// common volume values
1419//-----------------------------------------------------------------------------
1420#define VOL_NORM 1.0f
1421
1422
1423//-----------------------------------------------------------------------------
1424// common attenuation values
1425//-----------------------------------------------------------------------------
1426#define ATTN_NONE 0.0f
1427#define ATTN_NORM 0.8f
1428#define ATTN_IDLE 2.0f
1429#define ATTN_STATIC 1.25f
1430#define ATTN_RICOCHET 1.5f
1431
1432// HL2 world is 8x bigger now! We want to hear gunfire from farther.
1433// Don't change this without consulting Kelly or Wedge (sjb).
1434#define ATTN_GUNFIRE 0.27f
1435
1436enum soundlevel_t
1437{
1438 SNDLVL_NONE = 0 ,
1439
1440 SNDLVL_20dB = 20 , // rustling leaves
1441 SNDLVL_25dB = 25 , // whispering
1442 SNDLVL_30dB = 30 , // library
1443 SNDLVL_35dB = 35 ,
1444 SNDLVL_40dB = 40 ,
1445 SNDLVL_45dB = 45 , // refrigerator
1446
1447 SNDLVL_50dB = 50 , // 3.9 // average home
1448 SNDLVL_55dB = 55 , // 3.0
1449
1450 SNDLVL_IDLE = 60 , // 2.0
1451 SNDLVL_60dB = 60 , // 2.0 // normal conversation, clothes dryer
1452
1453 SNDLVL_65dB = 65 , // 1.5 // washing machine, dishwasher
1454 SNDLVL_STATIC = 66 , // 1.25
1455
1456 SNDLVL_70dB = 70 , // 1.0 // car, vacuum cleaner, mixer, electric sewing machine
1457
1458 SNDLVL_NORM = 75 ,
1459 SNDLVL_75dB = 75 , // 0.8 // busy traffic
1460
1461 SNDLVL_80dB = 80 , // 0.7 // mini-bike, alarm clock, noisy restaurant, office tabulator, outboard motor, passing snowmobile
1462 SNDLVL_TALKING = 80 , // 0.7
1463 SNDLVL_85dB = 85 , // 0.6 // average factory, electric shaver
1464 SNDLVL_90dB = 90 , // 0.5 // screaming child, passing motorcycle, convertible ride on frw
1465 SNDLVL_95dB = 95 ,
1466 SNDLVL_100dB = 100 , // 0.4 // subway train, diesel truck, woodworking shop, pneumatic drill, boiler shop, jackhammer
1467 SNDLVL_105dB = 105 , // helicopter, power mower
1468 SNDLVL_110dB = 110 , // snowmobile drvrs seat, inboard motorboat, sandblasting
1469 SNDLVL_120dB = 120 , // auto horn, propeller aircraft
1470 SNDLVL_130dB = 130 , // air raid siren
1471
1472 SNDLVL_GUNFIRE = 140 , // 0.27 // THRESHOLD OF PAIN, gunshot, jet engine
1473 SNDLVL_140dB = 140 , // 0.2
1474
1475 SNDLVL_150dB = 150 , // 0.2
1476
1477 SNDLVL_180dB = 180 , // rocket launching
1478
1479 // NOTE: Valid soundlevel_t values are 0-255.
1480 // 256-511 are reserved for sounds using goldsrc compatibility attenuation.
1481};
1482
1483#define MAX_SNDLVL_BITS 9 // Used to encode 0-255 for regular soundlevel_t's and 256-511 for goldsrc-compatible ones.
1484#define MIN_SNDLVL_VALUE 0
1485#define MAX_SNDLVL_VALUE ((1<<MAX_SNDLVL_BITS)-1)
1486
1487
1488#define ATTN_TO_SNDLVL( a ) (soundlevel_t)(int)((a) ? (50 + 20 / ((float)a)) : 0 )
1489#define SNDLVL_TO_ATTN( a ) ((a > 50) ? (20.0f / (float)(a - 50)) : 4.0 )
1490
1491// This is a limit due to network encoding.
1492// It encodes attenuation * 64 in 8 bits, so the maximum is (255 / 64)
1493#define MAX_ATTENUATION 3.98f
1494
1495//-----------------------------------------------------------------------------
1496// Flags to be or-ed together for the iFlags field
1497//-----------------------------------------------------------------------------
1498enum SoundFlags_t
1499{
1500 SND_NOFLAGS = 0 , // to keep the compiler happy
1501 SND_CHANGE_VOL = ( 1 << 0 ) , // change sound vol
1502 SND_CHANGE_PITCH = ( 1 << 1 ) , // change sound pitch
1503 SND_STOP = ( 1 << 2 ) , // stop the sound
1504 SND_SPAWNING = ( 1 << 3 ) , // we're spawning, used in some cases for ambients
1505 // not sent over net, only a param between dll and server.
1506 SND_DELAY = ( 1 << 4 ) , // sound has an initial delay
1507 SND_STOP_LOOPING = ( 1 << 5 ) , // stop all looping sounds on the entity.
1508 SND_SPEAKER = ( 1 << 6 ) , // being played again by a microphone through a speaker
1509
1510 SND_SHOULDPAUSE = ( 1 << 7 ) , // this sound should be paused if the game is paused
1511 SND_IGNORE_PHONEMES = ( 1 << 8 ) ,
1512 SND_IGNORE_NAME = ( 1 << 9 ) , // used to change all sounds emitted by an entity, regardless of scriptname
1513
1514 SND_DO_NOT_OVERWRITE_EXISTING_ON_CHANNEL = ( 1 << 10 ) ,
1515};
1516
1517#define SND_FLAG_BITS_ENCODE 11
1518
1519#define MAX_SOUND_INDEX_BITS 14
1520#define MAX_SOUNDS (1<<MAX_SOUND_INDEX_BITS)
1521
1522#define MAX_SOUND_DELAY_MSEC_ENCODE_BITS (13)
1523
1524// Subtract one to leave room for the sign bit
1525#define MAX_SOUND_DELAY_MSEC (1<<(MAX_SOUND_DELAY_MSEC_ENCODE_BITS-1)) // 4096 msec or about 4 seconds
1526
1527//-----------------------------------------------------------------------------
1528// common pitch values
1529//-----------------------------------------------------------------------------
1530#define PITCH_NORM 100 // non-pitch shifted
1531#define PITCH_LOW 95 // other values are possible - 0-255, where 255 is very high
1532#define PITCH_HIGH 120
1533
1534#define DEFAULT_SOUND_PACKET_VOLUME 1.0f
1535#define DEFAULT_SOUND_PACKET_PITCH 100
1536#define DEFAULT_SOUND_PACKET_DELAY 0.0f
1537
1538// Handy defines for EmitSound
1539#define SOUND_FROM_UI_PANEL -2 // Sound being played inside a UI panel on the client
1540#define SOUND_FROM_LOCAL_PLAYER -1
1541#define SOUND_FROM_WORLD 0
1542
1543// These are used to feed a soundlevel to the sound system and have it use
1544// goldsrc-type attenuation. We should use this as little as possible and
1545// phase it out as soon as possible.
1546
1547// Take a regular sndlevel and convert it to compatibility mode.
1548#define SNDLEVEL_TO_COMPATIBILITY_MODE( x ) ((soundlevel_t)(int)( (x) + 256 ))
1549
1550// Take a compatibility-mode sndlevel and get the REAL sndlevel out of it.
1551#define SNDLEVEL_FROM_COMPATIBILITY_MODE( x ) ((soundlevel_t)(int)( (x) - 256 ))
1552
1553// Tells if the given sndlevel is marked as compatibility mode.
1554#define SNDLEVEL_IS_COMPATIBILITY_MODE( x ) ( (x) >= 256 )
1555
1556//-----------------------------------------------------------------------------
1557// Client-server neutral effects interface
1558//-----------------------------------------------------------------------------
1559
1560typedef void* FileNameHandle_t;
1561
1562struct SndInfo_t
1563{
1564 // Sound Guid
1565 int m_nGuid;
1566 FileNameHandle_t m_filenameHandle; // filesystem filename handle - call IFilesystem to conver this to a string
1567 int m_nSoundSource;
1568 int m_nChannel;
1569 // If a sound is being played through a speaker entity (e.g., on a monitor,), this is the
1570 // entity upon which to show the lips moving, if the sound has sentence data
1571 int m_nSpeakerEntity;
1572 float m_flVolume;
1573 float m_flLastSpatializedVolume;
1574 // Radius of this sound effect (spatialization is different within the radius)
1575 float m_flRadius;
1576 int m_nPitch;
1577 Vector *m_pOrigin;
1578 Vector *m_pDirection;
1579
1580 // if true, assume sound source can move and update according to entity
1581 bool m_bUpdatePositions;
1582 // true if playing linked sentence
1583 bool m_bIsSentence;
1584 // if true, bypass all dsp processing for this sound (ie: music)
1585 bool m_bDryMix;
1586 // true if sound is playing through in-game speaker entity.
1587 bool m_bSpeaker;
1588 // for snd_show, networked sounds get colored differently than local sounds
1589 bool m_bFromServer;
1590};
1591
1592//-----------------------------------------------------------------------------
1593// Hearing info
1594//-----------------------------------------------------------------------------
1595struct AudioState_t
1596{
1597 Vector m_Origin;
1598 QAngle m_Angles;
1599 bool m_bIsUnderwater;
1600};
1601
1602class IEngineSound
1603{
1604public:
1605 // Precache a particular sample
1606 virtual bool PrecacheSound( const char *pSample , bool bPreload = false , bool bIsUISound = false ) = 0;
1607 virtual bool IsSoundPrecached( const char *pSample ) = 0;
1608 virtual void PrefetchSound( const char *pSample ) = 0;
1609 virtual bool IsLoopingSound( const char *pSample ) = 0;
1610
1611 // Just loads the file header and checks for duration (not hooked up for .mp3's yet)
1612 // Is accessible to server and client though
1613 virtual float GetSoundDuration( const char *pSample ) = 0;
1614
1615 // Pitch of 100 is no pitch shift. Pitch > 100 up to 255 is a higher pitch, pitch < 100
1616 // down to 1 is a lower pitch. 150 to 70 is the realistic range.
1617 // EmitSound with pitch != 100 should be used sparingly, as it's not quite as
1618 // fast (the pitchshift mixer is not native coded).
1619
1620 // NOTE: setting iEntIndex to -1 will cause the sound to be emitted from the local
1621 // player (client-side only)
1622 virtual int EmitSound1( IRecipientFilter& filter , int iEntIndex , int iChannel , const char *pSoundEntry , unsigned int nSoundEntryHash , const char *pSample ,
1623 float flVolume , soundlevel_t iSoundlevel , int nSeed , int iFlags = 0 , int iPitch = PITCH_NORM ,
1624 const Vector *pOrigin = NULL , const Vector *pDirection = NULL , CUtlVector< Vector >* pUtlVecOrigins = NULL , bool bUpdatePositions = true , float soundtime = 0.0f , int speakerentity = -1 ) = 0;
1625
1626 virtual int EmitSound2( IRecipientFilter& filter , int iEntIndex , int iChannel , const char *pSoundEntry , unsigned int nSoundEntryHash , const char *pSample ,
1627 float flVolume , float flAttenuation , int nSeed , int iFlags = 0 , int iPitch = PITCH_NORM ,
1628 const Vector *pOrigin = NULL , const Vector *pDirection = NULL , CUtlVector< Vector >* pUtlVecOrigins = NULL , bool bUpdatePositions = true , float soundtime = 0.0f , int speakerentity = -1 ) = 0;
1629
1630 virtual void EmitSentenceByIndex( IRecipientFilter& filter , int iEntIndex , int iChannel , int iSentenceIndex ,
1631 float flVolume , soundlevel_t iSoundlevel , int nSeed , int iFlags = 0 , int iPitch = PITCH_NORM ,
1632 const Vector *pOrigin = NULL , const Vector *pDirection = NULL , CUtlVector< Vector >* pUtlVecOrigins = NULL , bool bUpdatePositions = true , float soundtime = 0.0f , int speakerentity = -1 ) = 0;
1633
1634 virtual void StopSound( int iEntIndex , int iChannel , const char *pSample , unsigned int nSoundEntryHash ) = 0;
1635};
1636
1637#pragma endregion
1638
1639#pragma region IGameEventManager2
1640
1641class IGameEvent {
1642public:
1643 const char* GetName() {
1644 return call_func<const char*( __thiscall * )( void* )>( this , 1 )( this );
1645 }
1646
1647 int GetInt( const char* szKeyName , int nDefault = 0 ) {
1648 return call_func<int( __thiscall * )( void* , const char* , int )>( this , 6 )( this , szKeyName , nDefault );
1649 }
1650
1651 const char* GetString( const char* szKeyName ) {
1652 return call_func<const char*( __thiscall * )( void* , const char* , int )>( this , 9 )( this , szKeyName , 0 );
1653 }
1654
1655 void SetString( const char* szKeyName , const char* szValue ) {
1656 return call_func<void( __thiscall * )( void* , const char* , const char* )>( this , 16 )( this , szKeyName , szValue );
1657 }
1658};
1659
1660class IGameEventManager2 {
1661public:
1662 bool FireEventClientSide( IGameEvent* pEvent ) {
1663 return call_func<bool( __thiscall * )( void* , IGameEvent* )>( this , 9 )( this , pEvent );
1664 }
1665};
1666
1667#pragma endregion
1668
1669#pragma region CBaseViewModel
1670
1671class CBaseViewModel : public IClientEntity {
1672public:
1673 int GetModelIndex() {
1674 // DT_BaseViewModel -> m_nModelIndex
1675 return *(int*)( ( DWORD )this + m_nModelIndex );
1676 }
1677
1678 DWORD GetOwner() {
1679 // DT_BaseViewModel -> m_hOwner
1680 return *(PDWORD)( ( DWORD )this + m_hOwner );
1681 }
1682
1683 DWORD GetWeapon() {
1684 // DT_BaseViewModel -> m_hWeapon
1685 return *(PDWORD)( ( DWORD )this + m_hWeapon );
1686 }
1687
1688 void SetWeaponModel( const char* Filename , IClientEntity* Weapon ) {
1689 return call_func<void( __thiscall* )( void* , const char* , IClientEntity* )>( this , 242 )( this , Filename , Weapon );
1690 }
1691};
1692
1693#pragma endregion
1694
1695#pragma region CBaseAttributableItem
1696
1697class CBaseAttributableItem : public IClientEntity {
1698public:
1699 int* GetItemDefinitionIndex() {
1700 // DT_BaseAttributableItem -> m_AttributeManager -> m_Item -> m_iItemDefinitionIndex
1701 return (int*)( ( DWORD )this + m_iItemDefinitionIndex );
1702 }
1703
1704 int* GetItemIDHigh() {
1705 // DT_BaseAttributableItem -> m_AttributeManager -> m_Item -> m_iItemIDHigh
1706 return (int*)( ( DWORD )this + m_iItemIDHigh );
1707 }
1708
1709 int* GetAccountID() {
1710 // DT_BaseAttributableItem -> m_AttributeManager -> m_Item -> m_iAccountID
1711 return (int*)( ( DWORD )this + m_iAccountID );
1712 }
1713
1714 int* GetEntityQuality() {
1715 // DT_BaseAttributableItem -> m_AttributeManager -> m_Item -> m_iEntityQuality
1716 return (int*)( ( DWORD )this + m_iEntityQuality );
1717 }
1718
1719 int* GetOriginalOwnerXuidLow() {
1720 // DT_BaseAttributableItem -> m_OriginalOwnerXuidLow
1721 return (int*)( ( DWORD )this + m_OriginalOwnerXuidLow );
1722 }
1723
1724 int* GetOriginalOwnerXuidHigh() {
1725 // DT_BaseAttributableItem -> m_OriginalOwnerXuidHigh
1726 return (int*)( ( DWORD )this + m_OriginalOwnerXuidHigh );
1727 }
1728
1729 int* GetFallbackPaintKit() {
1730 // DT_BaseAttributableItem -> m_nFallbackPaintKit
1731 return (int*)( ( DWORD )this + m_nFallbackPaintKit );
1732 }
1733
1734 float* GetFallbackWear() {
1735 // DT_BaseAttributableItem -> m_flFallbackWear
1736 return (float*)( ( DWORD )this + m_flFallbackWear );
1737 }
1738
1739 int* GetOwnerEntity() {
1740 // DT_BaseAttributableItem -> m_hOwnerEntity
1741 return (int*)( ( DWORD )this + m_hOwnerEntity );
1742 }
1743};
1744
1745#pragma endregion
1746
1747#pragma region IModelRender
1748
1749#ifndef CONCAT_IMPL
1750#define CONCAT_IMPL(x, y) x##y
1751#ifndef MACRO_CONCAT
1752#define MACRO_CONCAT(x, y) CONCAT_IMPL(x, y)
1753#ifndef PAD
1754#define PAD(SIZE) BYTE MACRO_CONCAT(_pad, __COUNTER__)[SIZE];
1755#endif
1756#endif
1757#endif
1758
1759struct mstudiobbox_t
1760{
1761 int bone; // 0x0
1762 int group; // 0x4
1763 Vector bbmin; // 0x8
1764 Vector bbmax; // 0x14
1765 int szhitboxnameindex; // 0x18
1766 PAD( 0x8 );
1767 float m_flRadius;// 0x1C
1768 char* GetHitboxName( void )
1769 {
1770 if ( szhitboxnameindex == 0 )
1771 return "";
1772
1773 return ( ( char* )this ) + szhitboxnameindex;
1774 } // 0x28
1775 PAD( 0x18 );
1776};
1777
1778struct mstudiohitboxset_t
1779{
1780 int sznameindex;
1781 inline char* const GetName( void ) const { return ( ( char* )this ) + sznameindex; }
1782 int numhitboxes;
1783 int hitboxindex;
1784 float m_flRadius;
1785 inline mstudiobbox_t* pHitbox( int i ) const { return (mstudiobbox_t*)( ( ( BYTE* )this ) + hitboxindex ) + i; };
1786};
1787
1788struct mstudiobone_t
1789{
1790 int sznameindex;
1791 inline char * const GetName( void ) const { return ( ( char * )this ) + sznameindex; }
1792 int parent;
1793 int bonecontroller[6];
1794
1795 Vector pos;
1796 float quat[4];
1797 Vector rot;
1798 Vector posscale;
1799 Vector rotscale;
1800
1801 matrix3x4_t poseToBone;
1802 float qAlignment[4];
1803 int flags;
1804 int proctype;
1805 int procindex; // procedural rule
1806 mutable int physicsbone; // index into physically simulated bone
1807 inline void * GetProcedure() const { if ( procindex == 0 ) return NULL; else return (void *)( ( ( BYTE * )this ) + procindex ); };
1808 int surfacepropidx; // index into string tablefor property name
1809 inline char * const GetSurfaceProps( void ) const { return ( ( char * )this ) + surfacepropidx; }
1810 int contents; // See BSPFlags.h for the contents flags
1811
1812 int unused[8]; // remove as appropriate
1813};
1814
1815struct studiohdr_t
1816{
1817 int id;
1818 int version;
1819 int checksum;
1820 char name[64];
1821 int length;
1822 Vector eyeposition;
1823 Vector illumposition;
1824 Vector hull_min;
1825 Vector hull_max;
1826 Vector view_bbmin;
1827 Vector view_bbmax;
1828 int flags;
1829 int numbones;
1830 int boneindex;
1831
1832 inline mstudiobone_t *pBone( int i ) const { return (mstudiobone_t *)( ( ( BYTE * )this ) + boneindex ) + i; };
1833
1834 int numbonecontrollers;
1835 int bonecontrollerindex;
1836 int numhitboxsets;
1837 int hitboxsetindex;
1838
1839 mstudiohitboxset_t* pHitboxSet( int i ) const
1840 {
1841 return (mstudiohitboxset_t*)( ( ( BYTE* )this ) + hitboxsetindex ) + i;
1842 }
1843
1844 inline mstudiobbox_t* pHitbox( int i , int set ) const
1845 {
1846 mstudiohitboxset_t const* s = pHitboxSet( set );
1847
1848 if ( !s )
1849 return NULL;
1850
1851 return s->pHitbox( i );
1852 }
1853
1854 inline int GetHitboxCount( int set ) const
1855 {
1856 mstudiohitboxset_t const* s = pHitboxSet( set );
1857
1858 if ( !s )
1859 return 0;
1860
1861 return s->numhitboxes;
1862 }
1863
1864 int numlocalanim;
1865 int localanimindex;
1866 int numlocalseq;
1867 int localseqindex;
1868 mutable int activitylistversion;
1869 mutable int eventsindexed;
1870 int numtextures;
1871 int textureindex;
1872 int numcdtextures;
1873 int cdtextureindex;
1874 int numskinref;
1875 int numskinfamilies;
1876 int skinindex;
1877 int numbodyparts;
1878 int bodypartindex;
1879 int numlocalattachments;
1880 int localattachmentindex;
1881 int numlocalnodes;
1882 int localnodeindex;
1883 int localnodenameindex;
1884 int numflexdesc;
1885 int flexdescindex;
1886 int numflexcontrollers;
1887 int flexcontrollerindex;
1888 int numflexrules;
1889 int flexruleindex;
1890 int numikchains;
1891 int ikchainindex;
1892 int nummouths;
1893 int mouthindex;
1894 int numlocalposeparameters;
1895 int localposeparamindex;
1896 int surfacepropindex;
1897 int keyvalueindex;
1898 int keyvaluesize;
1899 int numlocalikautoplaylocks;
1900 int localikautoplaylockindex;
1901 float mass;
1902 int contents;
1903 int numincludemodels;
1904 int includemodelindex;
1905 mutable void *virtualModel;
1906 int szanimblocknameindex;
1907 int numanimblocks;
1908 int animblockindex;
1909 mutable void *animblockModel;
1910 int bonetablebynameindex;
1911 void *pVertexBase;
1912 void *pIndexBase;
1913 BYTE constdirectionallightdot;
1914 BYTE rootLOD;
1915 BYTE numAllowedRootLODs;
1916 PAD( 0x5 );
1917 int numflexcontrollerui;
1918 int flexcontrolleruiindex;
1919 float flVertAnimFixedPointScale;
1920 PAD( 0x4 );
1921 int studiohdr2index;
1922 PAD( 0x4 );
1923};
1924
1925struct DrawModelState_t
1926{
1927 struct studiohdr_t* m_pStudioHdr;
1928 unsigned long m_pStudioHWData;
1929 IClientEntity* m_pRenderable;
1930 const matrix3x4_t* m_pModelToWorld;
1931 unsigned long m_decals;
1932 int m_drawFlags;
1933 int m_lod;
1934};
1935
1936struct ModelRenderInfo_t
1937{
1938 Vector origin;
1939 QAngle angles;
1940 IClientEntity* pRenderable;
1941 const model_t* pModel;
1942 const matrix3x4_t* pModelToWorld;
1943 const matrix3x4_t* pLightingOffset;
1944 const Vector* pLightingOrigin;
1945 int flags;
1946 int entity_index;
1947 int skin;
1948 int body;
1949 int hitboxset;
1950 unsigned short instance;
1951 ModelRenderInfo_t( void )
1952 {
1953 pModelToWorld = NULL;
1954 pLightingOffset = NULL;
1955 pLightingOrigin = NULL;
1956 }
1957};
1958
1959class IModelRender
1960{
1961public:
1962 void DrawModelExecute( PVOID pContext , const DrawModelState_t& pState , const ModelRenderInfo_t& pInfo , matrix3x4_t* pCustomBoneToWorld )
1963 {
1964 VirtualFn( void )( PVOID , PVOID , const DrawModelState_t& , const ModelRenderInfo_t& , matrix3x4_t* );
1965 call_func< OriginalFn >( this , 21 )( this , pContext , pState , pInfo , pCustomBoneToWorld );
1966 }
1967 void ForcedMaterialOverride( IMaterial *newMaterial , int nOverrideType = 0 , int iUnknown = 0 )
1968 {
1969 VirtualFn( void )( PVOID , IMaterial* , int , int );
1970 call_func< OriginalFn >( this , 1 )( this , newMaterial , nOverrideType , iUnknown );
1971 }
1972};
1973
1974#pragma endregion
1975
1976#pragma region IVModelInfoClient
1977
1978class IVModelInfoClient {
1979public:
1980 void* GetModel( int Index ) {
1981 return call_func<void*( __thiscall * )( void* , int )>( this , 1 )( this , Index );
1982 }
1983
1984 int GetModelIndex( const char* Filename ) {
1985 return call_func<int( __thiscall * )( void* , const char* )>( this , 2 )( this , Filename );
1986 }
1987
1988 std::string GetModelName( const void* Model ) {
1989 return call_func<const char*( __thiscall * )( void* , const void* )>( this , 3 )( this , Model );
1990 }
1991
1992 void GetModelMaterials( const model_t *model , int count , IMaterial** ppMaterial )
1993 {
1994 call_func<void*( __thiscall * )( void* , const model_t* , int , IMaterial** )>( this , 17 )( this , model , count , ppMaterial );
1995 }
1996 studiohdr_t* GetStudioModel( const model_t *mod )
1997 {
1998 return call_func<studiohdr_t*( __thiscall * )( void* , const model_t* )>( this , 30 )( this , mod );
1999 }
2000};
2001
2002#pragma endregion
2003
2004#pragma region IMaterial
2005
2006enum MaterialVarFlags_t
2007{
2008 MATERIAL_VAR_DEBUG = ( 1 << 0 ) ,
2009 MATERIAL_VAR_NO_DEBUG_OVERRIDE = ( 1 << 1 ) ,
2010 MATERIAL_VAR_NO_DRAW = ( 1 << 2 ) ,
2011 MATERIAL_VAR_USE_IN_FILLRATE_MODE = ( 1 << 3 ) ,
2012 MATERIAL_VAR_VERTEXCOLOR = ( 1 << 4 ) ,
2013 MATERIAL_VAR_VERTEXALPHA = ( 1 << 5 ) ,
2014 MATERIAL_VAR_SELFILLUM = ( 1 << 6 ) ,
2015 MATERIAL_VAR_ADDITIVE = ( 1 << 7 ) ,
2016 MATERIAL_VAR_ALPHATEST = ( 1 << 8 ) ,
2017 MATERIAL_VAR_ZNEARER = ( 1 << 10 ) ,
2018 MATERIAL_VAR_MODEL = ( 1 << 11 ) ,
2019 MATERIAL_VAR_FLAT = ( 1 << 12 ) ,
2020 MATERIAL_VAR_NOCULL = ( 1 << 13 ) ,
2021 MATERIAL_VAR_NOFOG = ( 1 << 14 ) ,
2022 MATERIAL_VAR_IGNOREZ = ( 1 << 15 ) ,
2023 MATERIAL_VAR_DECAL = ( 1 << 16 ) ,
2024 MATERIAL_VAR_ENVMAPSPHERE = ( 1 << 17 ) , // OBSOLETE
2025 MATERIAL_VAR_ENVMAPCAMERASPACE = ( 1 << 19 ) , // OBSOLETE
2026 MATERIAL_VAR_BASEALPHAENVMAPMASK = ( 1 << 20 ) ,
2027 MATERIAL_VAR_TRANSLUCENT = ( 1 << 21 ) ,
2028 MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK = ( 1 << 22 ) ,
2029 MATERIAL_VAR_NEEDS_SOFTWARE_SKINNING = ( 1 << 23 ) , // OBSOLETE
2030 MATERIAL_VAR_OPAQUETEXTURE = ( 1 << 24 ) ,
2031 MATERIAL_VAR_ENVMAPMODE = ( 1 << 25 ) , // OBSOLETE
2032 MATERIAL_VAR_SUPPRESS_DECALS = ( 1 << 26 ) ,
2033 MATERIAL_VAR_HALFLAMBERT = ( 1 << 27 ) ,
2034 MATERIAL_VAR_WIREFRAME = ( 1 << 28 ) ,
2035 MATERIAL_VAR_ALLOWALPHATOCOVERAGE = ( 1 << 29 ) ,
2036 MATERIAL_VAR_ALPHA_MODIFIED_BY_PROXY = ( 1 << 30 ) ,
2037 MATERIAL_VAR_VERTEXFOG = ( 1 << 31 ) ,
2038};
2039
2040class IMaterial
2041{
2042public:
2043 std::string GetName( void )
2044 {
2045 VirtualFn( const char* )( PVOID );
2046 return std::string( call_func< OriginalFn >( this , 0 )( this ) );
2047 }
2048 std::string GetTextureGroupName( void )
2049 {
2050 VirtualFn( const char* )( PVOID );
2051 return std::string( call_func< OriginalFn >( this , 1 )( this ) );
2052 }
2053 void IncrementReferenceCount( void )
2054 {
2055 VirtualFn( void )( PVOID );
2056 call_func< OriginalFn >( this , 12 )( this );
2057 }
2058 void AlphaModulate( float alpha )
2059 {
2060 VirtualFn( void )( PVOID , float );
2061 call_func< OriginalFn >( this , 27 )( this , alpha );
2062 }
2063 void ColorModulate( float r , float g , float b )
2064 {
2065 VirtualFn( void )( PVOID , float , float , float );
2066 call_func< OriginalFn >( this , 28 )( this , r , g , b );
2067 }
2068 void SetMaterialVarFlag( MaterialVarFlags_t flag , bool on )
2069 {
2070 VirtualFn( void )( PVOID , MaterialVarFlags_t , bool );
2071 call_func< OriginalFn >( this , 29 )( this , flag , on );
2072 }
2073};
2074
2075#pragma endregion
2076
2077#pragma region IRenderView
2078
2079class IRenderView
2080{
2081public:
2082 void SetBlend( float blend )
2083 {
2084 VirtualFn( void )( PVOID , float );
2085 call_func< OriginalFn >( this , 4 )( this , blend );
2086 }
2087 void SetColorModulation( float const* blend )
2088 {
2089 VirtualFn( void )( PVOID , float const* );
2090 call_func< OriginalFn >( this , 6 )( this , blend );
2091 }
2092};
2093
2094#pragma endregion
2095
2096#pragma region IMaterialSystem
2097
2098class IMaterialSystem
2099{
2100public:
2101 IMaterial* CreateMaterial( const char* pMaterialName , KeyValues* pVMTKeyValues )
2102 {
2103 VirtualFn( IMaterial* )( PVOID , const char* , KeyValues* );
2104 return call_func< OriginalFn >( this , 83 )( this , pMaterialName , pVMTKeyValues );
2105 }
2106 IMaterial* FindMaterial( const char* pMaterialName , const char* pTextureGroupName , bool complain = true , const char* pComplainPrefix = 0 )
2107 {
2108 VirtualFn( IMaterial* )( PVOID , const char* , const char* , bool , const char* );
2109 return call_func< OriginalFn >( this , 84 )( this , pMaterialName , pTextureGroupName , complain , pComplainPrefix );
2110 }
2111};
2112
2113#pragma endregion
2114
2115#pragma region KeyValues
2116
2117class KeyValues
2118{
2119public:
2120 static void SetUseGrowableStringTable( bool bUseGrowableTable );
2121
2122 KeyValues( const char *setName )
2123 {
2124 Init();
2125 SetName( setName );
2126 }
2127
2128 class AutoDelete
2129 {
2130 public:
2131 explicit inline AutoDelete( KeyValues *pKeyValues ) : m_pKeyValues( pKeyValues ) {}
2132 explicit inline AutoDelete( const char *pchKVName ) : m_pKeyValues( new KeyValues( pchKVName ) ) {}
2133 inline ~AutoDelete( void ) { if ( m_pKeyValues ) m_pKeyValues->deleteThis(); }
2134 inline void Assign( KeyValues *pKeyValues ) { m_pKeyValues = pKeyValues; }
2135 KeyValues *operator->() { return m_pKeyValues; }
2136 operator KeyValues *( ) { return m_pKeyValues; }
2137 private:
2138 AutoDelete( AutoDelete const &x ); // forbid
2139 AutoDelete & operator= ( AutoDelete const &x ); // forbid
2140 KeyValues *m_pKeyValues;
2141 };
2142
2143 const char *GetName() const;
2144 void SetName( const char *setName )
2145 {
2146 m_iKeyName = 2;
2147 }
2148
2149 int GetNameSymbol() const { return m_iKeyName; }
2150
2151 void UsesEscapeSequences( bool state ); // default false
2152 void UsesConditionals( bool state ); // default true
2153
2154 KeyValues *FindKey( const char *keyName , bool bCreate = false );
2155 KeyValues *FindKey( int keySymbol ) const;
2156 KeyValues *CreateNewKey(); // creates a new key, with an autogenerated name. name is guaranteed to be an integer, of value 1 higher than the highest other integer key name
2157 void AddSubKey( KeyValues *pSubkey ); // Adds a subkey. Make sure the subkey isn't a child of some other keyvalues
2158 void RemoveSubKey( KeyValues *subKey ); // removes a subkey from the list, DOES NOT DELETE IT
2159
2160 KeyValues *GetFirstSubKey() { return m_pSub; } // returns the first subkey in the list
2161 KeyValues *GetNextKey() { return m_pPeer; } // returns the next subkey
2162 void SetNextKey( KeyValues * pDat );
2163 KeyValues *FindLastSubKey(); // returns the LAST subkey in the list. This requires a linked list iteration to find the key. Returns NULL if we don't have any children
2164
2165 KeyValues* GetFirstTrueSubKey();
2166 KeyValues* GetNextTrueSubKey();
2167
2168 KeyValues* GetFirstValue(); // When you get a value back, you can use GetX and pass in NULL to get the value.
2169 KeyValues* GetNextValue();
2170
2171 // Data access
2172 int GetInt( const char *keyName = NULL , int defaultValue = 0 );
2173 float GetFloat( const char *keyName = NULL , float defaultValue = 0.0f );
2174 const char *GetString( const char *keyName = NULL , const char *defaultValue = "" );
2175 const wchar_t *GetWString( const char *keyName = NULL , const wchar_t *defaultValue = L"" );
2176 void *GetPtr( const char *keyName = NULL , void *defaultValue = (void*)0 );
2177 bool GetBool( const char *keyName = NULL , bool defaultValue = false );
2178 bool IsEmpty( const char *keyName = NULL );
2179
2180 // Data access
2181 int GetInt( int keySymbol , int defaultValue = 0 );
2182 float GetFloat( int keySymbol , float defaultValue = 0.0f );
2183 const char *GetString( int keySymbol , const char *defaultValue = "" );
2184 const wchar_t *GetWString( int keySymbol , const wchar_t *defaultValue = L"" );
2185 void *GetPtr( int keySymbol , void *defaultValue = (void*)0 );
2186 bool IsEmpty( int keySymbol );
2187
2188 // Key writing
2189 void SetWString( const char *keyName , const wchar_t *value );
2190 void SetString( const char *keyName , const char *value );
2191 void SetInt( const char *keyName , int value );
2192 void SetUint64( const char *keyName , UINT value );
2193 void SetFloat( const char *keyName , float value );
2194 void SetPtr( const char *keyName , void *value );
2195 void SetBool( const char *keyName , bool value ) { SetInt( keyName , value ? 1 : 0 ); }
2196
2197 KeyValues& operator=( KeyValues& src );
2198
2199 // Adds a chain... if we don't find stuff in this keyvalue, we'll look
2200 // in the one we're chained to.
2201 void ChainKeyValue( KeyValues* pChain );
2202
2203 // Allocate & create a new copy of the keys
2204 KeyValues *MakeCopy( void ) const;
2205
2206 // Make a new copy of all subkeys, add them all to the passed-in keyvalues
2207 void CopySubkeys( KeyValues *pParent ) const;
2208
2209 // Clear out all subkeys, and the current value
2210 void Clear( void );
2211
2212 // Data type
2213 enum types_t
2214 {
2215 TYPE_NONE = 0 ,
2216 TYPE_STRING ,
2217 TYPE_INT ,
2218 TYPE_FLOAT ,
2219 TYPE_PTR ,
2220 TYPE_WSTRING ,
2221 TYPE_COLOR ,
2222 TYPE_UINT64 ,
2223 TYPE_NUMTYPES ,
2224 };
2225 types_t GetDataType( const char *keyName = NULL );
2226
2227 // Virtual deletion function - ensures that KeyValues object is deleted from correct heap
2228 void deleteThis();
2229
2230 void SetStringValue( char const *strValue );
2231
2232 // unpack a key values list into a structure
2233 void UnpackIntoStructure( struct KeyValuesUnpackStructure const *pUnpackTable , void *pDest , size_t DestSizeInBytes );
2234
2235 // Process conditional keys for widescreen support.
2236 bool ProcessResolutionKeys( const char *pResString );
2237
2238 // Dump keyvalues recursively into a dump context
2239 bool Dump( class IKeyValuesDumpContext *pDump , int nIndentLevel = 0 );
2240
2241 // Merge in another KeyValues, keeping "our" settings
2242 void RecursiveMergeKeyValues( KeyValues *baseKV );
2243
2244public:
2245 KeyValues( KeyValues& ); // prevent copy constructor being used
2246
2247 // prevent delete being called except through deleteThis()
2248 ~KeyValues();
2249
2250 KeyValues* CreateKey( const char *keyName );
2251
2252 KeyValues* CreateKeyUsingKnownLastChild( const char *keyName , KeyValues *pLastChild );
2253 void AddSubkeyUsingKnownLastChild( KeyValues *pSubKey , KeyValues *pLastChild );
2254
2255 void RecursiveCopyKeyValues( KeyValues& src );
2256 void RemoveEverything();
2257
2258 void Init()
2259 {
2260 m_iKeyName = -1;
2261 m_iDataType = TYPE_NONE;
2262
2263 m_pSub = NULL;
2264 m_pPeer = NULL;
2265 m_pChain = NULL;
2266
2267 m_sValue = NULL;
2268 m_wsValue = NULL;
2269 m_pValue = NULL;
2270
2271 m_bHasEscapeSequences = false;
2272
2273 // for future proof
2274 memset( unused , 0 , sizeof( unused ) );
2275 }
2276
2277 void FreeAllocatedValue();
2278 void AllocateValueBlock( int size );
2279
2280 int m_iKeyName; // keyname is a symbol defined in KeyValuesSystem
2281
2282 // These are needed out of the union because the API returns string pointers
2283 char *m_sValue;
2284 wchar_t *m_wsValue;
2285
2286 // we don't delete these
2287 union
2288 {
2289 int m_iValue;
2290 float m_flValue;
2291 void *m_pValue;
2292 unsigned char m_Color[4];
2293 };
2294
2295 char m_iDataType;
2296 char m_bHasEscapeSequences; // true, if while parsing this KeyValue, Escape Sequences are used (default false)
2297 char m_bEvaluateConditionals; // true, if while parsing this KeyValue, conditionals blocks are evaluated (default true)
2298 char unused[1];
2299
2300 KeyValues *m_pPeer; // pointer to next key in list
2301 KeyValues *m_pSub; // pointer to Start of a new sub key list
2302 KeyValues *m_pChain;// Search here if it's not in our list
2303
2304private:
2305 // Statics to implement the optional growable string table
2306 // Function pointers that will determine which mode we are in
2307 static int( *s_pfGetSymbolForString )( const char *name , bool bCreate );
2308 static const char *( *s_pfGetStringForSymbol )( int symbol );
2309
2310public:
2311 // Functions that invoke the default behavior
2312 static int GetSymbolForStringClassic( const char *name , bool bCreate = true );
2313 static const char *GetStringForSymbolClassic( int symbol );
2314
2315 // Functions that use the growable string table
2316 static int GetSymbolForStringGrowable( const char *name , bool bCreate = true );
2317 static const char *GetStringForSymbolGrowable( int symbol );
2318
2319 // Functions to get external access to whichever of the above functions we're going to call.
2320 static int CallGetSymbolForString( const char *name , bool bCreate = true ) { return s_pfGetSymbolForString( name , bCreate ); }
2321 static const char *CallGetStringForSymbol( int symbol ) { return s_pfGetStringForSymbol( symbol ); }
2322
2323 bool LoadFromBuffer( KeyValues *pThis , const char *pszFirst , const char *pszSecond , PVOID pSomething = 0 , PVOID pAnother = 0 , PVOID pLast = 0 );
2324};
2325
2326#pragma endregion