core/GameConfigs.h
author David Anderson <dvander@alliedmods.net>
Thu Oct 29 01:33:57 2009 -0700 (2009-10-29)
changeset 2846 5e176efe7927
parent 2726 c96f3fab8211
child 2901 f5a1cf24f505
permissions -rw-r--r--
Use GetSourceEngineBuild() from MM:S 1.8 legacy API (bug 4083, r=ds).
     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 	bool EnterFile(const char *file, char *error, size_t maxlength);
    59 public: //ITextListener_SMC
    60 	SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);
    61 	SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
    62 	SMCResult ReadSMC_LeavingSection(const SMCStates *states);
    63 public: //IGameConfig
    64 	const char *GetKeyValue(const char *key);
    65 	bool GetOffset(const char *key, int *value);
    66 	SendProp *GetSendProp(const char *key);
    67 	bool GetMemSig(const char *key, void **addr);
    68 public:
    69 	void IncRefCount();
    70 	unsigned int DecRefCount();
    71 private:
    72 	BaseStringTable *m_pStrings;
    73 	char m_File[PLATFORM_MAX_PATH];
    74 	char m_CurFile[PLATFORM_MAX_PATH];
    75 	Trie *m_pOffsets;
    76 	Trie *m_pProps;
    77 	Trie *m_pKeys;
    78 	Trie *m_pSigs;
    79 	unsigned int m_RefCount;
    80 	/* Parse states */
    81 	int m_ParseState;
    82 	unsigned int m_IgnoreLevel;
    83 	char m_Class[64];
    84 	char m_Prop[64];
    85 	char m_offset[64];
    86 	char m_Game[256];
    87 	bool bShouldBeReadingDefault;
    88 	bool had_game;
    89 	bool matched_game;
    90 	bool had_engine;
    91 	bool matched_engine;
    92 
    93 	/* Custom Sections */
    94 	unsigned int m_CustomLevel;
    95 	ITextListener_SMC *m_CustomHandler;
    96 };
    97 
    98 class GameConfigManager : 
    99 	public IGameConfigManager,
   100 	public SMGlobalClass
   101 {
   102 public:
   103 	GameConfigManager();
   104 	~GameConfigManager();
   105 public: //IGameConfigManager
   106 	bool LoadGameConfigFile(const char *file, IGameConfig **pConfig, char *error, size_t maxlength);
   107 	void CloseGameConfigFile(IGameConfig *cfg);
   108 	IGameConfig *ReadHandle(Handle_t hndl,
   109 		IdentityToken_t *ident,
   110 		HandleError *err);
   111 	void AddUserConfigHook(const char *sectionname, ITextListener_SMC *listener);
   112 	void RemoveUserConfigHook(const char *sectionname, ITextListener_SMC *listener);
   113 	void AcquireLock();
   114 	void ReleaseLock();
   115 public: //SMGlobalClass
   116 	void OnSourceModStartup(bool late);
   117 	void OnSourceModAllInitialized();
   118 	void OnSourceModAllShutdown();
   119 private:
   120 	List<CGameConfig *> m_cfgs;
   121 	Trie *m_pLookup;
   122 public:
   123 	KTrie<ITextListener_SMC *> m_customHandlers;
   124 };
   125 
   126 extern GameConfigManager g_GameConfigs;
   127 extern IGameConfig *g_pGameConf;
   128 
   129 #endif //_INCLUDE_SOURCEMOD_CGAMECONFIGS_H_