Team Fortress 2 Source Code as on 22/4/2020
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.

254 lines
6.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef GAMECONFIG_H
  7. #define GAMECONFIG_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #pragma warning(push, 1)
  12. #pragma warning(disable:4701 4702 4530)
  13. #include <fstream>
  14. #pragma warning(pop)
  15. #include "fgdlib/HelperInfo.h"
  16. #include "TokenReader.h"
  17. #include "fgdlib/gamedata.h"
  18. #include "GamePalette.h"
  19. #include "IEditorTexture.h"
  20. #include "utlvector.h"
  21. class MDkeyvalue;
  22. class KeyValues;
  23. #define MAX_DIRECTORY_SIZE 32
  24. enum MAPFORMAT
  25. {
  26. mfQuake = 0,
  27. mfHexen2,
  28. mfQuake2,
  29. mfHalfLife,
  30. mfHalfLife2,
  31. };
  32. struct MatExlcusions_s
  33. {
  34. char szDirectory[MAX_PATH]; // Where we store the material exclusion directories
  35. bool bUserGenerated; // If the user specified this ( default: false -- FGD defined )
  36. };
  37. class CGameConfig
  38. {
  39. public:
  40. CGameConfig();
  41. static CGameConfig *GetActiveGame(void);
  42. static void SetActiveGame(CGameConfig *pGame);
  43. inline TEXTUREFORMAT GetTextureFormat(void);
  44. inline void SetTextureFormat(TEXTUREFORMAT eFormat);
  45. inline float GetDefaultTextureScale(void);
  46. inline void SetDefaultTextureScale(float fScale);
  47. inline int GetDefaultLightmapScale(void);
  48. inline void SetDefaultLightmapScale(int nScale);
  49. inline const char *GetCordonTexture(void);
  50. inline void SetCordonTexture(const char *szCordonTexture);
  51. inline void GetSteamExe(CString &str);
  52. inline void GetSteamDir(CString &str);
  53. inline void GetSteamUserDir(CString &str);
  54. inline void GetSteamAppID(CString &str);
  55. inline MAPFORMAT GetMapFormat();
  56. CUtlVector< MatExlcusions_s > m_MaterialExclusions;
  57. DWORD dwID; // assigned on load
  58. char szName[128];
  59. int nGDFiles;
  60. MAPFORMAT mapformat;
  61. char szExecutable[128];
  62. char szDefaultPoint[128];
  63. char szDefaultSolid[128];
  64. char szBSP[128];
  65. char szLIGHT[128];
  66. char szVIS[128];
  67. char m_szGameExeDir[128];
  68. char szMapDir[128];
  69. char szBSPDir[128];
  70. char m_szModDir[128];
  71. int m_MaterialExcludeCount;
  72. CStringArray GDFiles;
  73. GameData GD; // gamedata files loaded
  74. CGamePalette Palette;
  75. BOOL Import(std::fstream &, float fVersion);
  76. bool Load(KeyValues *pkv);
  77. bool Save(KeyValues *pkv);
  78. void Save(std::fstream &);
  79. bool Save(const char *pszFileName, const char *pszSection);
  80. void CopyFrom(CGameConfig *pConfig);
  81. void LoadGDFiles(void);
  82. void ParseGameInfo();
  83. // Accessor methods to get at the mod + the game (*not* full paths)
  84. const char *GetMod();
  85. const char *GetGame();
  86. protected:
  87. TEXTUREFORMAT textureformat;
  88. float m_fDefaultTextureScale;
  89. int m_nDefaultLightmapScale;
  90. char m_szCordonTexture[MAX_PATH];
  91. // These settings are loaded from GameInfo.txt:
  92. char m_szSteamDir[MAX_PATH]; // The full path to steam.exe
  93. char m_szSteamUserDir[MAX_PATH]; // The full path to the users's directory under SteamApps
  94. char m_szSteamAppID[32]; // The app id to add to the command line when launching the game via Steam.
  95. };
  96. //-----------------------------------------------------------------------------
  97. // Purpose:
  98. //-----------------------------------------------------------------------------
  99. MAPFORMAT CGameConfig::GetMapFormat()
  100. {
  101. return mapformat;
  102. }
  103. //-----------------------------------------------------------------------------
  104. // Purpose:
  105. //-----------------------------------------------------------------------------
  106. TEXTUREFORMAT CGameConfig::GetTextureFormat(void)
  107. {
  108. return(textureformat);
  109. }
  110. //-----------------------------------------------------------------------------
  111. // Purpose:
  112. //-----------------------------------------------------------------------------
  113. void CGameConfig::SetTextureFormat(TEXTUREFORMAT eFormat)
  114. {
  115. textureformat = eFormat;
  116. }
  117. //-----------------------------------------------------------------------------
  118. // Purpose:
  119. //-----------------------------------------------------------------------------
  120. const char *CGameConfig::GetCordonTexture(void)
  121. {
  122. return(m_szCordonTexture);
  123. }
  124. //-----------------------------------------------------------------------------
  125. // Purpose:
  126. //-----------------------------------------------------------------------------
  127. void CGameConfig::SetCordonTexture(const char *szCordonTexture)
  128. {
  129. Q_strncpy( m_szCordonTexture, szCordonTexture, sizeof( m_szCordonTexture ) );
  130. }
  131. //-----------------------------------------------------------------------------
  132. // Purpose:
  133. //-----------------------------------------------------------------------------
  134. int CGameConfig::GetDefaultLightmapScale(void)
  135. {
  136. return(m_nDefaultLightmapScale);
  137. }
  138. //-----------------------------------------------------------------------------
  139. // Purpose:
  140. //-----------------------------------------------------------------------------
  141. void CGameConfig::SetDefaultLightmapScale(int nScale)
  142. {
  143. m_nDefaultLightmapScale = nScale;
  144. }
  145. //-----------------------------------------------------------------------------
  146. // Purpose:
  147. //-----------------------------------------------------------------------------
  148. float CGameConfig::GetDefaultTextureScale(void)
  149. {
  150. return(m_fDefaultTextureScale);
  151. }
  152. //-----------------------------------------------------------------------------
  153. // Purpose:
  154. //-----------------------------------------------------------------------------
  155. void CGameConfig::SetDefaultTextureScale(float fScale)
  156. {
  157. m_fDefaultTextureScale = fScale;
  158. }
  159. //-----------------------------------------------------------------------------
  160. // Purpose: Returns the full path to steam.exe, found by searching up from
  161. // whatever directory hammer is in.
  162. //-----------------------------------------------------------------------------
  163. void CGameConfig::GetSteamDir(CString &str)
  164. {
  165. str = m_szSteamDir;
  166. }
  167. //-----------------------------------------------------------------------------
  168. // Purpose: Returns the full path to steam.exe, found by searching up from
  169. // whatever directory hammer is in.
  170. //-----------------------------------------------------------------------------
  171. void CGameConfig::GetSteamExe(CString &str)
  172. {
  173. GetSteamDir(str);
  174. str += "\\steam.exe";
  175. }
  176. //-----------------------------------------------------------------------------
  177. // Purpose: Returns the full path to steam.exe, found by searching up from
  178. // whatever directory hammer is in.
  179. //-----------------------------------------------------------------------------
  180. void CGameConfig::GetSteamUserDir(CString &str)
  181. {
  182. str = m_szSteamUserDir;
  183. }
  184. //-----------------------------------------------------------------------------
  185. // Purpose:
  186. //-----------------------------------------------------------------------------
  187. void CGameConfig::GetSteamAppID(CString &str)
  188. {
  189. str = m_szSteamAppID;
  190. }
  191. extern GameData *pGD;
  192. extern CGameConfig *g_pGameConfig;
  193. extern float g_MAX_MAP_COORD;
  194. extern float g_MIN_MAP_COORD;
  195. #endif // GAMECONFIG_H