core/GameConfigs.h
author Fyren <fyrenmoo@gmail.com>
Wed Apr 01 05:56:51 2009 -0700 (2009-04-01)
changeset 2692 126e2d41c2b3
parent 2573 9e715ee7389e
child 2726 c96f3fab8211
permissions -rw-r--r--
Disable nextmap in Synergy and Dystopia (bug 3687, bug 3741; r=liam)
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #ifndef _INCLUDE_SOURCEMOD_CGAMECONFIGS_H_
    33 #define _INCLUDE_SOURCEMOD_CGAMECONFIGS_H_
    34 
    35 #include <IGameConfigs.h>
    36 #include <ITextParsers.h>
    37 #include <sh_list.h>
    38 #include "sm_trie.h"
    39 #include "sm_globals.h"
    40 #include "sm_memtable.h"
    41 #include "sm_trie_tpl.h"
    42 #include "ThreadSupport.h"
    43 
    44 using namespace SourceMod;
    45 using namespace SourceHook;
    46 
    47 class SendProp;
    48 
    49 class CGameConfig : 
    50 	public ITextListener_SMC,
    51 	public IGameConfig
    52 {
    53 	friend class GameConfigManager;
    54 public:
    55 	CGameConfig(const char *file);
    56 	~CGameConfig();
    57 public:
    58 	bool Reparse(char *error, size_t maxlength);
    59 	bool EnterFile(const char *file, char *error, size_t maxlength);
    60 public: //ITextListener_SMC
    61 	SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);
    62 	SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
    63 	SMCResult ReadSMC_LeavingSection(const SMCStates *states);
    64 public: //IGameConfig
    65 	const char *GetKeyValue(const char *key);
    66 	bool GetOffset(const char *key, int *value);
    67 	SendProp *GetSendProp(const char *key);
    68 	bool GetMemSig(const char *key, void **addr);
    69 public:
    70 	void IncRefCount();
    71 	unsigned int DecRefCount();
    72 private:
    73 	BaseStringTable *m_pStrings;
    74 	char m_File[PLATFORM_MAX_PATH];
    75 	char m_CurFile[PLATFORM_MAX_PATH];
    76 	Trie *m_pOffsets;
    77 	Trie *m_pProps;
    78 	Trie *m_pKeys;
    79 	Trie *m_pSigs;
    80 	unsigned int m_RefCount;
    81 	/* Parse states */
    82 	int m_ParseState;
    83 	unsigned int m_IgnoreLevel;
    84 	char m_Class[64];
    85 	char m_Prop[64];
    86 	char m_offset[64];
    87 	char m_Game[256];
    88 	bool bShouldBeReadingDefault;
    89 	bool had_game;
    90 	bool matched_game;
    91 	bool had_engine;
    92 	bool matched_engine;
    93 
    94 	/* Custom Sections */
    95 	unsigned int m_CustomLevel;
    96 	ITextListener_SMC *m_CustomHandler;
    97 };
    98 
    99 class GameConfigManager : 
   100 	public IGameConfigManager,
   101 	public SMGlobalClass
   102 {
   103 public:
   104 	GameConfigManager();
   105 	~GameConfigManager();
   106 public: //IGameConfigManager
   107 	bool LoadGameConfigFile(const char *file, IGameConfig **pConfig, char *error, size_t maxlength);
   108 	void CloseGameConfigFile(IGameConfig *cfg);
   109 	IGameConfig *ReadHandle(Handle_t hndl,
   110 		IdentityToken_t *ident,
   111 		HandleError *err);
   112 	void AddUserConfigHook(const char *sectionname, ITextListener_SMC *listener);
   113 	void RemoveUserConfigHook(const char *sectionname, ITextListener_SMC *listener);
   114 	void AcquireLock();
   115 	void ReleaseLock();
   116 public: //SMGlobalClass
   117 	void OnSourceModStartup(bool late);
   118 	void OnSourceModAllInitialized();
   119 	void OnSourceModAllShutdown();
   120 private:
   121 	List<CGameConfig *> m_cfgs;
   122 	Trie *m_pLookup;
   123 public:
   124 	KTrie<ITextListener_SMC *> m_customHandlers;
   125 };
   126 
   127 extern GameConfigManager g_GameConfigs;
   128 extern IGameConfig *g_pGameConf;
   129 
   130 #endif //_INCLUDE_SOURCEMOD_CGAMECONFIGS_H_