core/GameConfigs.h
author Matt Woodrow <pred@alliedmods.net>
Fri Aug 08 00:17:37 2008 +0000 (2008-08-08)
changeset 2224 676c3b826f13
parent 2217 eca7057167a0
child 2289 44045ead61cd
permissions -rw-r--r--
Initial Import of beta structs extension.
     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 
    43 using namespace SourceMod;
    44 using namespace SourceHook;
    45 
    46 class SendProp;
    47 
    48 class CGameConfig : 
    49 	public ITextListener_SMC,
    50 	public IGameConfig
    51 {
    52 	friend class GameConfigManager;
    53 public:
    54 	CGameConfig(const char *file);
    55 	~CGameConfig();
    56 public:
    57 	bool Reparse(char *error, size_t maxlength);
    58 public: //ITextListener_SMC
    59 	SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);
    60 	SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
    61 	SMCResult ReadSMC_LeavingSection(const SMCStates *states);
    62 public: //IGameConfig
    63 	const char *GetKeyValue(const char *key);
    64 	bool GetOffset(const char *key, int *value);
    65 	SendProp *GetSendProp(const char *key);
    66 	bool GetMemSig(const char *key, void **addr);
    67 public:
    68 	void IncRefCount();
    69 	unsigned int DecRefCount();
    70 private:
    71 	BaseStringTable *m_pStrings;
    72 	char *m_pFile;
    73 	Trie *m_pOffsets;
    74 	Trie *m_pProps;
    75 	Trie *m_pKeys;
    76 	Trie *m_pSigs;
    77 	unsigned int m_RefCount;
    78 	/* Parse states */
    79 	int m_ParseState;
    80 	unsigned int m_IgnoreLevel;
    81 	char m_Class[64];
    82 	char m_Prop[64];
    83 	char m_offset[64];
    84 	char m_Game[256];
    85 	bool bShouldBeReadingDefault;
    86 
    87 	/* Custom Sections */
    88 	unsigned int m_CustomLevel;
    89 	ITextListener_SMC *m_CustomHandler;
    90 };
    91 
    92 class GameConfigManager : 
    93 	public IGameConfigManager,
    94 	public SMGlobalClass
    95 {
    96 public:
    97 	GameConfigManager();
    98 	~GameConfigManager();
    99 public: //IGameConfigManager
   100 	bool LoadGameConfigFile(const char *file, IGameConfig **pConfig, char *error, size_t maxlength);
   101 	void CloseGameConfigFile(IGameConfig *cfg);
   102 	IGameConfig *ReadHandle(Handle_t hndl,
   103 		IdentityToken_t *ident,
   104 		HandleError *err);
   105 	void AddUserConfigHook(const char *sectionname, ITextListener_SMC *listener);
   106 	void RemoveUserConfigHook(const char *sectionname, ITextListener_SMC *listener);
   107 public: //SMGlobalClass
   108 	void OnSourceModStartup(bool late);
   109 	void OnSourceModAllInitialized();
   110 	void OnSourceModAllShutdown();
   111 private:
   112 	List<CGameConfig *> m_cfgs;
   113 	Trie *m_pLookup;
   114 public:
   115 	KTrie<ITextListener_SMC *> m_customHandlers;
   116 };
   117 
   118 extern GameConfigManager g_GameConfigs;
   119 extern IGameConfig *g_pGameConf;
   120 
   121 #endif //_INCLUDE_SOURCEMOD_CGAMECONFIGS_H_