core/GameConfigs.h
author David Anderson <dvander@alliedmods.net>
Fri Jul 11 06:51:21 2008 +0000 (2008-07-11)
branchrefac-jit
changeset 2192 7602d7fb60d9
parent 2168 c24a6fa957db
child 2217 eca7057167a0
permissions -rw-r--r--
fixed a compat regression, forgot msvc does funky things with overloaded virtual calls
     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 
    42 using namespace SourceMod;
    43 using namespace SourceHook;
    44 
    45 class SendProp;
    46 
    47 class CGameConfig : 
    48 	public ITextListener_SMC,
    49 	public IGameConfig
    50 {
    51 	friend class GameConfigManager;
    52 public:
    53 	CGameConfig(const char *file);
    54 	~CGameConfig();
    55 public:
    56 	bool Reparse(char *error, size_t maxlength);
    57 public: //ITextListener_SMC
    58 	SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);
    59 	SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
    60 	SMCResult ReadSMC_LeavingSection(const SMCStates *states);
    61 public: //IGameConfig
    62 	const char *GetKeyValue(const char *key);
    63 	bool GetOffset(const char *key, int *value);
    64 	SendProp *GetSendProp(const char *key);
    65 	bool GetMemSig(const char *key, void **addr);
    66 public:
    67 	void IncRefCount();
    68 	unsigned int DecRefCount();
    69 private:
    70 	BaseStringTable *m_pStrings;
    71 	char *m_pFile;
    72 	Trie *m_pOffsets;
    73 	Trie *m_pProps;
    74 	Trie *m_pKeys;
    75 	Trie *m_pSigs;
    76 	unsigned int m_RefCount;
    77 	/* Parse states */
    78 	int m_ParseState;
    79 	unsigned int m_IgnoreLevel;
    80 	char m_Class[64];
    81 	char m_Prop[64];
    82 	char m_offset[64];
    83 	char m_Game[256];
    84 	bool bShouldBeReadingDefault;
    85 };
    86 
    87 class GameConfigManager : 
    88 	public IGameConfigManager,
    89 	public SMGlobalClass
    90 {
    91 public:
    92 	GameConfigManager();
    93 	~GameConfigManager();
    94 public: //IGameConfigManager
    95 	bool LoadGameConfigFile(const char *file, IGameConfig **pConfig, char *error, size_t maxlength);
    96 	void CloseGameConfigFile(IGameConfig *cfg);
    97 	IGameConfig *ReadHandle(Handle_t hndl,
    98 		IdentityToken_t *ident,
    99 		HandleError *err);
   100 public: //SMGlobalClass
   101 	void OnSourceModStartup(bool late);
   102 	void OnSourceModAllInitialized();
   103 	void OnSourceModAllShutdown();
   104 private:
   105 	List<CGameConfig *> m_cfgs;
   106 	Trie *m_pLookup;
   107 };
   108 
   109 extern GameConfigManager g_GameConfigs;
   110 extern IGameConfig *g_pGameConf;
   111 
   112 #endif //_INCLUDE_SOURCEMOD_CGAMECONFIGS_H_