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