core/GameConfigs.h
author David Anderson <dvander@alliedmods.net>
Tue Jul 03 20:46:17 2007 +0000 (2007-07-03)
changeset 1036 2a073d5b3454
parent 971 d3a94f3f1529
child 1064 726206725da8
permissions -rw-r--r--
added amb505
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  * This file is not open source and may not be copied without explicit
     8  * written permission of AlliedModders LLC.  This file may not be redistributed 
     9  * in whole or significant part.
    10  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #ifndef _INCLUDE_SOURCEMOD_CGAMECONFIGS_H_
    16 #define _INCLUDE_SOURCEMOD_CGAMECONFIGS_H_
    17 
    18 #include <IGameConfigs.h>
    19 #include <ITextParsers.h>
    20 #include <sh_list.h>
    21 #include "sm_trie.h"
    22 #include "sm_globals.h"
    23 #include "sm_memtable.h"
    24 
    25 using namespace SourceMod;
    26 using namespace SourceHook;
    27 
    28 class SendProp;
    29 
    30 class CGameConfig : 
    31 	public ITextListener_SMC,
    32 	public IGameConfig
    33 {
    34 	friend class GameConfigManager;
    35 public:
    36 	CGameConfig(const char *file);
    37 	~CGameConfig();
    38 public:
    39 	bool Reparse(char *error, size_t maxlength);
    40 public: //ITextListener_SMC
    41 	SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes);
    42 	SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes);
    43 	SMCParseResult ReadSMC_LeavingSection();
    44 public: //IGameConfig
    45 	const char *GetKeyValue(const char *key);
    46 	bool GetOffset(const char *key, int *value);
    47 	SendProp *GetSendProp(const char *key);
    48 	bool GetMemSig(const char *key, void **addr);
    49 public:
    50 	void IncRefCount();
    51 	unsigned int DecRefCount();
    52 private:
    53 	BaseStringTable *m_pStrings;
    54 	char *m_pFile;
    55 	Trie *m_pOffsets;
    56 	Trie *m_pProps;
    57 	Trie *m_pKeys;
    58 	Trie *m_pSigs;
    59 	unsigned int m_RefCount;
    60 	/* Parse states */
    61 	int m_ParseState;
    62 	unsigned int m_IgnoreLevel;
    63 	char m_class[64];
    64 	char m_prop[64];
    65 	char m_offset[64];
    66 	char m_mod[255];
    67 	bool bShouldBeReadingDefault;
    68 };
    69 
    70 class GameConfigManager : 
    71 	public IGameConfigManager,
    72 	public SMGlobalClass
    73 {
    74 public:
    75 	GameConfigManager();
    76 	~GameConfigManager();
    77 public: //IGameConfigManager
    78 	bool LoadGameConfigFile(const char *file, IGameConfig **pConfig, char *error, size_t maxlength);
    79 	void CloseGameConfigFile(IGameConfig *cfg);
    80 	IGameConfig *ReadHandle(Handle_t hndl,
    81 		IdentityToken_t *ident,
    82 		HandleError *err);
    83 public: //SMGlobalClass
    84 	void OnSourceModStartup(bool late);
    85 	void OnSourceModAllInitialized();
    86 	void OnSourceModAllShutdown();
    87 private:
    88 	List<CGameConfig *> m_cfgs;
    89 	Trie *m_pLookup;
    90 };
    91 
    92 extern GameConfigManager g_GameConfigs;
    93 extern IGameConfig *g_pGameConf;
    94 
    95 #endif //_INCLUDE_SOURCEMOD_CGAMECONFIGS_H_