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.

212 lines
7.0 KiB

  1. //========= Copyright � 1996-2005, 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. return (stricmp(m_pModData->GetString("type", ""), "singleplayer_only") == 0);
  61. }
  62. //-----------------------------------------------------------------------------
  63. // Purpose: data accessor
  64. //-----------------------------------------------------------------------------
  65. const char *CModInfo::GetFallbackDir()
  66. {
  67. return m_pModData->GetString("fallback_dir", "");
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Purpose: data accessor
  71. //-----------------------------------------------------------------------------
  72. const wchar_t *CModInfo::GetGameTitle()
  73. {
  74. if (!m_wcsGameTitle[0])
  75. {
  76. // for some reason, the standard ILocalize::ConvertANSIToUnicode() strips off
  77. // the '�' character in 'HALF-LIFE�' - so just do a straight upconvert to unicode
  78. const char *title = m_pModData->GetString("title", "");
  79. int i = 0;
  80. for (; title[i] != 0; ++i)
  81. {
  82. m_wcsGameTitle[i] = (wchar_t)title[i];
  83. }
  84. m_wcsGameTitle[i] = 0;
  85. }
  86. return m_wcsGameTitle;
  87. }
  88. //-----------------------------------------------------------------------------
  89. // Purpose: data accessor
  90. //-----------------------------------------------------------------------------
  91. const wchar_t *CModInfo::GetGameTitle2()
  92. {
  93. if (!m_wcsGameTitle2[0])
  94. {
  95. // for some reason, the standard ILocalize::ConvertANSIToUnicode() strips off
  96. // the '�' character in 'HALF-LIFE�' - so just do a straight upconvert to unicode
  97. const char *title2 = m_pModData->GetString("title2", "");
  98. int i = 0;
  99. for (; title2[i] != 0; ++i)
  100. {
  101. m_wcsGameTitle2[i] = (wchar_t)title2[i];
  102. }
  103. m_wcsGameTitle2[i] = 0;
  104. }
  105. return m_wcsGameTitle2;
  106. }
  107. //-----------------------------------------------------------------------------
  108. // Purpose: data accessor
  109. //-----------------------------------------------------------------------------
  110. const char *CModInfo::GetGameName()
  111. {
  112. return m_pModData->GetString("game", "");
  113. }
  114. //-----------------------------------------------------------------------------
  115. // Purpose: data accessor
  116. //-----------------------------------------------------------------------------
  117. KeyValues *CModInfo::GetHiddenMaps()
  118. {
  119. return m_pModData->FindKey( "hidden_maps" );
  120. }
  121. //-----------------------------------------------------------------------------
  122. // Purpose: data accessor
  123. //-----------------------------------------------------------------------------
  124. bool CModInfo::HasPortals()
  125. {
  126. return (stricmp(m_pModData->GetString("hasportals", "0"), "1") == 0);
  127. }
  128. //-----------------------------------------------------------------------------
  129. // Purpose: data accessor
  130. //-----------------------------------------------------------------------------
  131. bool CModInfo::NoDifficulty()
  132. {
  133. return (stricmp(m_pModData->GetString("nodifficulty", "0"), "1") == 0);
  134. }
  135. //-----------------------------------------------------------------------------
  136. // Purpose: data accessor
  137. //-----------------------------------------------------------------------------
  138. bool CModInfo::NoModels()
  139. {
  140. return (stricmp(m_pModData->GetString("nomodels", "0"), "1") == 0);
  141. }
  142. //-----------------------------------------------------------------------------
  143. // Purpose: data accessor
  144. //-----------------------------------------------------------------------------
  145. bool CModInfo::NoHiModel()
  146. {
  147. return (stricmp(m_pModData->GetString("nohimodel", "0"), "1") == 0);
  148. }
  149. //-----------------------------------------------------------------------------
  150. // Purpose: data accessor
  151. //-----------------------------------------------------------------------------
  152. bool CModInfo::NoCrosshair()
  153. {
  154. return (stricmp(m_pModData->GetString("nocrosshair", "1"), "1") == 0);
  155. }
  156. //-----------------------------------------------------------------------------
  157. // Purpose: data accessor
  158. //-----------------------------------------------------------------------------
  159. bool CModInfo::AdvCrosshair()
  160. {
  161. return (stricmp(m_pModData->GetString("advcrosshair", "0"), "1") == 0);
  162. }
  163. //-----------------------------------------------------------------------------
  164. // Purpose:
  165. //-----------------------------------------------------------------------------
  166. void CModInfo::LoadCurrentGameInfo()
  167. {
  168. // Load up gameinfo for the current mod
  169. char const *filename = "gameinfo.txt";
  170. m_pModData->LoadFromFile( g_pFullFileSystem, filename );
  171. }
  172. //-----------------------------------------------------------------------------
  173. // Purpose: loads file from null-terminated buffer
  174. //-----------------------------------------------------------------------------
  175. void CModInfo::LoadGameInfoFromBuffer( const char *buffer )
  176. {
  177. // Load up gameinfo.txt for the current mod
  178. m_pModData->LoadFromBuffer( "", buffer );
  179. }
  180. //-----------------------------------------------------------------------------
  181. // Purpose: data accessor
  182. //-----------------------------------------------------------------------------
  183. bool CModInfo::UseGameLogo()
  184. {
  185. return ( Q_stricmp( m_pModData->GetString( "gamelogo", "0" ), "1" ) == 0 );
  186. }