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.

251 lines
7.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "ModInfo.h"
  8. #include "KeyValues.h"
  9. #include "vgui_controls/Controls.h"
  10. #include "filesystem.h"
  11. #include "EngineInterface.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include <tier0/memdbgon.h>
  14. //-----------------------------------------------------------------------------
  15. // Purpose: singleton accessor
  16. //-----------------------------------------------------------------------------
  17. CModInfo &ModInfo()
  18. {
  19. static CModInfo s_ModInfo;
  20. return s_ModInfo;
  21. }
  22. //-----------------------------------------------------------------------------
  23. // Purpose: Constructor
  24. //-----------------------------------------------------------------------------
  25. CModInfo::CModInfo()
  26. {
  27. m_pModData = new KeyValues("ModData");
  28. m_wcsGameTitle[0] = 0;
  29. }
  30. //-----------------------------------------------------------------------------
  31. // Purpose: Destructor
  32. //-----------------------------------------------------------------------------
  33. CModInfo::~CModInfo()
  34. {
  35. FreeModInfo();
  36. }
  37. //-----------------------------------------------------------------------------
  38. // Purpose:
  39. //-----------------------------------------------------------------------------
  40. void CModInfo::FreeModInfo()
  41. {
  42. if (m_pModData)
  43. {
  44. m_pModData->deleteThis();
  45. m_pModData = NULL;
  46. }
  47. }
  48. //-----------------------------------------------------------------------------
  49. // Purpose: data accessor
  50. //-----------------------------------------------------------------------------
  51. bool CModInfo::IsMultiplayerOnly()
  52. {
  53. return (stricmp(m_pModData->GetString("type", ""), "multiplayer_only") == 0);
  54. }
  55. //-----------------------------------------------------------------------------
  56. // Purpose: data accessor
  57. //-----------------------------------------------------------------------------
  58. bool CModInfo::IsSinglePlayerOnly()
  59. {
  60. #ifndef _XBOX
  61. return (stricmp(m_pModData->GetString("type", ""), "singleplayer_only") == 0);
  62. #else
  63. // xboxissue - no support for disparate mounted content
  64. return true;
  65. #endif
  66. }
  67. //-----------------------------------------------------------------------------
  68. // Purpose: data accessor
  69. //-----------------------------------------------------------------------------
  70. const char *CModInfo::GetFallbackDir()
  71. {
  72. return m_pModData->GetString("fallback_dir", "");
  73. }
  74. //-----------------------------------------------------------------------------
  75. // Purpose: data accessor
  76. //-----------------------------------------------------------------------------
  77. const wchar_t *CModInfo::GetGameTitle()
  78. {
  79. if (!m_wcsGameTitle[0])
  80. {
  81. // for some reason, the standard ILocalize::ConvertANSIToUnicode() strips off
  82. // the '�' character in 'HALF-LIFE�' - so just do a straight upconvert to unicode
  83. const char *title = m_pModData->GetString("title", "");
  84. int i = 0;
  85. for (; title[i] != 0; ++i)
  86. {
  87. m_wcsGameTitle[i] = (wchar_t)title[i];
  88. }
  89. m_wcsGameTitle[i] = 0;
  90. }
  91. return m_wcsGameTitle;
  92. }
  93. //-----------------------------------------------------------------------------
  94. // Purpose: data accessor
  95. //-----------------------------------------------------------------------------
  96. const wchar_t *CModInfo::GetGameTitle2()
  97. {
  98. if (!m_wcsGameTitle2[0])
  99. {
  100. // for some reason, the standard ILocalize::ConvertANSIToUnicode() strips off
  101. // the '�' character in 'HALF-LIFE�' - so just do a straight upconvert to unicode
  102. const char *title2 = m_pModData->GetString("title2", "");
  103. int i = 0;
  104. for (; title2[i] != 0; ++i)
  105. {
  106. m_wcsGameTitle2[i] = (wchar_t)title2[i];
  107. }
  108. m_wcsGameTitle2[i] = 0;
  109. }
  110. return m_wcsGameTitle2;
  111. }
  112. //-----------------------------------------------------------------------------
  113. // Purpose: data accessor
  114. //-----------------------------------------------------------------------------
  115. const char *CModInfo::GetGameName()
  116. {
  117. return m_pModData->GetString("game", "");
  118. }
  119. //-----------------------------------------------------------------------------
  120. // Purpose: data accessor
  121. //-----------------------------------------------------------------------------
  122. KeyValues *CModInfo::GetHiddenMaps()
  123. {
  124. return m_pModData->FindKey( "hidden_maps" );
  125. }
  126. //-----------------------------------------------------------------------------
  127. // Purpose: data accessor
  128. //-----------------------------------------------------------------------------
  129. bool CModInfo::HasPortals()
  130. {
  131. return (stricmp(m_pModData->GetString("hasportals", "0"), "1") == 0);
  132. }
  133. //-----------------------------------------------------------------------------
  134. // Purpose: data accessor
  135. //-----------------------------------------------------------------------------
  136. bool CModInfo::HasHDContent()
  137. {
  138. return (stricmp(m_pModData->GetString("hashdcontent", "0"), "1") == 0);
  139. }
  140. //-----------------------------------------------------------------------------
  141. // Purpose: data accessor
  142. //-----------------------------------------------------------------------------
  143. bool CModInfo::NoDifficulty()
  144. {
  145. return (stricmp(m_pModData->GetString("nodifficulty", "0"), "1") == 0);
  146. }
  147. //-----------------------------------------------------------------------------
  148. // Purpose: data accessor
  149. //-----------------------------------------------------------------------------
  150. bool CModInfo::NoModels()
  151. {
  152. return (stricmp(m_pModData->GetString("nomodels", "0"), "1") == 0);
  153. }
  154. //-----------------------------------------------------------------------------
  155. // Purpose: data accessor
  156. //-----------------------------------------------------------------------------
  157. bool CModInfo::NoHiModel()
  158. {
  159. return (stricmp(m_pModData->GetString("nohimodel", "0"), "1") == 0);
  160. }
  161. //-----------------------------------------------------------------------------
  162. // Purpose: data accessor
  163. //-----------------------------------------------------------------------------
  164. bool CModInfo::NoCrosshair()
  165. {
  166. return (stricmp(m_pModData->GetString("nocrosshair", "1"), "1") == 0);
  167. }
  168. //-----------------------------------------------------------------------------
  169. // Purpose: data accessor
  170. //-----------------------------------------------------------------------------
  171. bool CModInfo::AdvCrosshair()
  172. {
  173. return ( m_pModData->GetInt( "advcrosshair" ) > 0 );
  174. }
  175. //-----------------------------------------------------------------------------
  176. // Purpose: data accessor
  177. //-----------------------------------------------------------------------------
  178. int CModInfo::AdvCrosshairLevel()
  179. {
  180. return m_pModData->GetInt( "advcrosshair" );
  181. }
  182. //-----------------------------------------------------------------------------
  183. // Purpose:
  184. //-----------------------------------------------------------------------------
  185. void CModInfo::LoadCurrentGameInfo()
  186. {
  187. // Load up gameinfo for the current mod
  188. char const *filename = "gameinfo.txt";
  189. m_pModData->LoadFromFile( g_pFullFileSystem, filename );
  190. }
  191. //-----------------------------------------------------------------------------
  192. // Purpose: loads file from null-terminated buffer
  193. //-----------------------------------------------------------------------------
  194. void CModInfo::LoadGameInfoFromBuffer( const char *buffer )
  195. {
  196. // Load up gameinfo.txt for the current mod
  197. m_pModData->LoadFromBuffer( "", buffer );
  198. }
  199. //-----------------------------------------------------------------------------
  200. // Purpose: data accessor
  201. //-----------------------------------------------------------------------------
  202. bool CModInfo::UseGameLogo()
  203. {
  204. return ( Q_stricmp( m_pModData->GetString( "gamelogo", "0" ), "1" ) == 0 );
  205. }
  206. //-----------------------------------------------------------------------------
  207. // Purpose: data accessor
  208. //-----------------------------------------------------------------------------
  209. bool CModInfo::UseBots()
  210. {
  211. return ( Q_stricmp( m_pModData->GetString( "bots", "0" ), "1" ) == 0 );
  212. }
  213. //-----------------------------------------------------------------------------
  214. // Purpose: data accessor
  215. //-----------------------------------------------------------------------------
  216. bool CModInfo::SupportsVR()
  217. {
  218. return (m_pModData->GetInt( "supportsvr" ) > 0);
  219. }