Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

318 lines
10 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //-----------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #if !defined( CLIENT_H )
  14. #define CLIENT_H
  15. #ifdef _WIN32
  16. #pragma once
  17. #endif
  18. #include <qlimits.h>
  19. #include <utllinkedlist.h>
  20. #include <convar.h>
  21. #include <checksum_crc.h>
  22. #include <protocol.h>
  23. #include <cdll_int.h>
  24. #include <globalvars_base.h>
  25. #include <soundflags.h>
  26. #include <utlvector.h>
  27. #include "host.h"
  28. #include "event_system.h"
  29. #include "precache.h"
  30. #include "baseclientstate.h"
  31. #include "clientframe.h"
  32. #include "netmessages.h"
  33. struct model_t;
  34. class ClientClass;
  35. class CSfxTable;
  36. class CPureServerWhitelist;
  37. #define MAX_DEMOS 32
  38. #define MAX_DEMONAME 32
  39. struct AddAngle
  40. {
  41. float total;
  42. float starttime;
  43. };
  44. class CQueuedEntityMessage
  45. {
  46. public:
  47. bool operator==( const CQueuedEntityMessage &val ) const
  48. {
  49. return this->m_msg.ent_index() == val.m_msg.ent_index();
  50. }
  51. CSVCMsg_EntityMsg m_msg;
  52. };
  53. //-----------------------------------------------------------------------------
  54. // Purpose: CClientState should hold all pieces of the client state
  55. // The client_state_t structure is wiped completely at every server signon
  56. //-----------------------------------------------------------------------------
  57. class CClientState : public CBaseClientState, public CClientFrameManager
  58. {
  59. typedef CBaseClientState BaseClass;
  60. typedef struct CustomFile_s
  61. {
  62. CRC32_t crc; //file CRC
  63. unsigned int reqID; // download request ID
  64. } CustomFile_t;
  65. public:
  66. CClientState();
  67. void ResetHltvReplayState();
  68. ~CClientState();
  69. public: // IConnectionlessPacketHandler interface:
  70. bool ProcessConnectionlessPacket(struct netpacket_s *packet);
  71. public: // CBaseClientState overrides:
  72. void Disconnect(bool bShowMainMenu);
  73. virtual void ConnectionStart( INetChannel *chan ) OVERRIDE;
  74. virtual void ConnectionStop() OVERRIDE;
  75. virtual void FullConnect( const ns_address &adr, int nEncryptionKey ) OVERRIDE;
  76. bool SetSignonState ( int state, int count, const CNETMsg_SignonState *msg );
  77. void PacketStart(int incoming_sequence, int outgoing_acknowledged);
  78. void PacketEnd( void );
  79. void FileReceived( const char *fileName, unsigned int transferID, bool isReplayDemoFile );
  80. void FileRequested(const char *fileName, unsigned int transferID, bool isReplayDemoFile );
  81. void FileDenied(const char *fileName, unsigned int transferID, bool isReplayDemoFile );
  82. void ConnectionCrashed( const char * reason );
  83. void ConnectionClosing( const char * reason );
  84. const char *GetCDKeyHash( void );
  85. void SetFriendsID( uint friendsID, const char *friendsName );
  86. void SendClientInfo( void );
  87. void SendLoadingProgress( int nProgress );
  88. void SendServerCmdKeyValues( KeyValues *pKeyValues );
  89. bool SendNetMsg( INetMessage &msg, bool bForceReliable = false, bool bVoice = false );
  90. void InstallStringTableCallback( char const *tableName );
  91. bool HookClientStringTable( char const *tableName );
  92. bool InstallEngineStringTableCallback( char const *tableName );
  93. void StartUpdatingSteamResources();
  94. void CheckUpdatingSteamResources();
  95. void CheckFileCRCsWithServer();
  96. void FinishSignonState_New();
  97. void ConsistencyCheck(bool bForce);
  98. void RunFrame();
  99. void ReadDeletions( CEntityReadInfo &u );
  100. void ReadPacketEntities( CEntityReadInfo &u );
  101. void SendQueuedEntityMessage( int iEntity );
  102. void RemoveQueuedMessageForEntity( int iEntity );
  103. // In case the client DLL is using the old interface to set area bits,
  104. // copy what they've passed to us into the m_chAreaBits array (and 0xFF-out the m_chAreaPortalBits array).
  105. void UpdateAreaBits_BackwardsCompatible();
  106. // Used to be pAreaBits.
  107. unsigned char** GetAreaBits_BackwardCompatibility();
  108. int GetHltvReplayDelay()const { return m_nHltvReplayDelay; }
  109. float GetHltvReplayTimeScale()const;
  110. void StopHltvReplay();
  111. public: // IServerMessageHandlers
  112. virtual bool NETMsg_Tick( const CNETMsg_Tick& msg ) OVERRIDE;
  113. virtual bool NETMsg_StringCmd( const CNETMsg_StringCmd& msg ) OVERRIDE;
  114. virtual bool SVCMsg_ServerInfo( const CSVCMsg_ServerInfo& msg ) OVERRIDE;
  115. virtual bool SVCMsg_ClassInfo( const CSVCMsg_ClassInfo& msg ) OVERRIDE;
  116. virtual bool SVCMsg_SetPause( const CSVCMsg_SetPause& msg ) OVERRIDE;
  117. virtual bool SVCMsg_VoiceInit( const CSVCMsg_VoiceInit& msg ) OVERRIDE;
  118. virtual bool SVCMsg_VoiceData( const CSVCMsg_VoiceData& msg ) OVERRIDE;
  119. virtual bool SVCMsg_FixAngle( const CSVCMsg_FixAngle& msg ) OVERRIDE;
  120. virtual bool SVCMsg_Prefetch( const CSVCMsg_Prefetch& msg ) OVERRIDE;
  121. virtual bool SVCMsg_CrosshairAngle( const CSVCMsg_CrosshairAngle& msg ) OVERRIDE;
  122. virtual bool SVCMsg_BSPDecal( const CSVCMsg_BSPDecal& msg ) OVERRIDE;
  123. virtual bool SVCMsg_UserMessage( const CSVCMsg_UserMessage& msg ) OVERRIDE;
  124. virtual bool SVCMsg_PaintmapData( const CSVCMsg_PaintmapData& msg ) OVERRIDE;
  125. virtual bool SVCMsg_GameEvent( const CSVCMsg_GameEvent& msg ) OVERRIDE;
  126. virtual bool SVCMsg_TempEntities( const CSVCMsg_TempEntities& msg ) OVERRIDE;
  127. virtual bool SVCMsg_PacketEntities( const CSVCMsg_PacketEntities &msg ) OVERRIDE;
  128. virtual bool SVCMsg_Sounds( const CSVCMsg_Sounds& msg ) OVERRIDE;
  129. virtual bool SVCMsg_EntityMsg( const CSVCMsg_EntityMsg& msg ) OVERRIDE;
  130. virtual bool SVCMsg_HltvReplay( const CSVCMsg_HltvReplay &msg );
  131. CNetMessageBinder m_SVCMsgHltvReplay;
  132. public:
  133. float m_flLastServerTickTime; // the timestamp of last message
  134. bool insimulation;
  135. int oldtickcount; // previous tick
  136. float m_tickRemainder; // client copy of tick remainder
  137. float m_frameTime; // dt of the current frame
  138. int lastoutgoingcommand;// Sequence number of last outgoing command
  139. int chokedcommands; // number of choked commands
  140. int last_command_ack; // last command sequence number acknowledged by server
  141. int last_server_tick; // same update pattern as last_command_ack, but with server ticks
  142. int command_ack; // current command sequence acknowledged by server
  143. int m_nSoundSequence; // current processed reliable sound sequence number
  144. int m_nLastProgressPercent; // last progress percent sent to server
  145. //
  146. // information that is static for the entire time connected to a server
  147. //
  148. bool ishltv; // true if HLTV server/demo
  149. #if defined( REPLAY_ENABLED )
  150. bool isreplay; // true if Replay server/demo
  151. #endif
  152. CRC32_t serverCRC; // To determine if client is playing hacked .map. (entities lump is skipped)
  153. CRC32_t serverClientSideDllCRC; // To determine if client is playing on a hacked client dll.
  154. unsigned char m_chAreaBits[MAX_AREA_STATE_BYTES];
  155. unsigned char m_chAreaPortalBits[MAX_AREA_PORTAL_STATE_BYTES];
  156. bool m_bAreaBitsValid; // Have the area bits been set for this level yet?
  157. // refresh related state
  158. QAngle viewangles;
  159. CUtlVector< AddAngle > addangle;
  160. float addangletotal;
  161. float prevaddangletotal;
  162. int cdtrack; // cd audio
  163. CustomFile_t m_nCustomFiles[MAX_CUSTOM_FILES]; // own custom files CRCs
  164. uint m_nFriendsID;
  165. char m_FriendsName[MAX_PLAYER_NAME_LENGTH];
  166. CUtlFixedLinkedList< CEventInfo > events; // list of received events
  167. // demo loop control
  168. int demonum; // -1 = don't play demos
  169. char demos[MAX_DEMOS][MAX_DEMONAME]; // when not playing
  170. CUtlVector< CQueuedEntityMessage > queuedmessage;
  171. public:
  172. // If 'insimulation', returns the time (in seconds) at the client's current tick.
  173. // Otherwise, returns the exact client clock.
  174. float GetTime() const;
  175. bool IsPaused() const;
  176. float GetFrameTime( void ) const;
  177. void SetFrameTime( float dt ) { m_frameTime = dt; }
  178. float GetClientInterpAmount(); // Formerly cl_interp, now based on cl_interp_ratio and cl_updaterate.
  179. void Clear( void );
  180. void DumpPrecacheStats( const char * name );
  181. // Public API to models
  182. model_t *GetModel( int index );
  183. void SetModel( int tableIndex );
  184. int LookupModelIndex( char const *name );
  185. // Public API to generic
  186. char const *GetGeneric( int index );
  187. void SetGeneric( int tableIndex );
  188. int LookupGenericIndex( char const *name );
  189. // Public API to sounds
  190. CSfxTable *GetSound( int index );
  191. char const *GetSoundName( int index );
  192. void SetSound( int tableIndex );
  193. int LookupSoundIndex( char const *name );
  194. void ClearSounds();
  195. // Public API to decals
  196. char const *GetDecalName( int index );
  197. void SetDecal( int tableIndex );
  198. // customization files code
  199. void CheckOwnCustomFiles(); // load own custom file
  200. void CheckOthersCustomFile(CRC32_t crc); // check if we have to download custom files from server
  201. void AddCustomFile( int slot, const char *resourceFile);
  202. public:
  203. INetworkStringTable *m_pModelPrecacheTable;
  204. INetworkStringTable *m_pDynamicModelTable;
  205. INetworkStringTable *m_pGenericPrecacheTable;
  206. INetworkStringTable *m_pSoundPrecacheTable;
  207. INetworkStringTable *m_pDecalPrecacheTable;
  208. INetworkStringTable *m_pInstanceBaselineTable;
  209. INetworkStringTable *m_pLightStyleTable;
  210. INetworkStringTable *m_pUserInfoTable;
  211. INetworkStringTable *m_pServerStartupTable;
  212. INetworkStringTable *m_pDownloadableFileTable;
  213. CPrecacheItem model_precache[ MAX_MODELS ];
  214. CPrecacheItem generic_precache[ MAX_GENERIC ];
  215. CPrecacheItem sound_precache[ MAX_SOUNDS ];
  216. CPrecacheItem decal_precache[ MAX_BASE_DECALS ];
  217. WaitForResourcesHandle_t m_hWaitForResourcesHandle;
  218. bool m_bUpdateSteamResources;
  219. bool m_bShownSteamResourceUpdateProgress;
  220. bool m_bDownloadResources;
  221. bool m_bDownloadingUGCMap;
  222. bool m_bCheckCRCsWithServer;
  223. float m_flLastCRCBatchTime;
  224. int m_modelIndexLoaded;
  225. int m_lastModelPercent;
  226. // This is only kept around to print out the whitelist info if sv_pure is used.
  227. CPureServerWhitelist *m_pPureServerWhitelist;
  228. int m_nHltvReplayDelay;
  229. int m_nHltvReplayStopAt;
  230. int m_nHltvReplayStartAt;
  231. int m_nHltvReplaySlowdownBeginAt;
  232. int m_nHltvReplaySlowdownEndAt;
  233. float m_flHltvReplaySlowdownRate;
  234. private:
  235. // Note: This is only here for backwards compatibility. If it is set to something other than NULL,
  236. // then we'll copy its contents into m_chAreaBits in UpdateAreaBits_BackwardsCompatible.
  237. byte *m_pAreaBits;
  238. // Set to false when we first connect to a server and true later on before we
  239. // respond to a new whitelist.
  240. bool m_bMarkedCRCsUnverified;
  241. }; //CClientState
  242. #ifndef DEDICATED
  243. extern CClientState &GetLocalClient( int nSlot = -1 );
  244. extern CClientState &GetBaseLocalClient(); // The player in the first slot (all split users depend on this one)
  245. #endif
  246. #ifndef DEDICATED
  247. extern CGlobalVarsBase g_ClientGlobalVariables;
  248. #endif
  249. extern bool g_bClientGameDLLGreaterThanV13;
  250. #endif // CLIENT_H