tools/gdc-psyfork/GameConfigs.h
author Nicholas Hastings <skamonkey@gmail.com>
Sun May 27 11:39:50 2012 -0400 (2012-05-27)
changeset 3514 377c7da70d7c
parent 3513 50b5b98b3400
child 3574 b51285ca203f
permissions -rw-r--r--
Added example scripts missing from last commit (NPOTB).
     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 #include <list>
    44 #include <map>
    45 #include "gdc.h"
    46 #include <limits.h>
    47 #include <string>
    48 #include <cstring>
    49 #include <cstdio>
    50 
    51 #define PLATFORM_MAX_PATH PATH_MAX
    52 
    53 using std::map;
    54 using std::list;
    55 using namespace SourceMod;
    56 //using namespace SourceHook;
    57 
    58 extern char *game;
    59 extern char *engine;
    60 
    61 #define PARSE_ERROR -1
    62 struct cmp_str 
    63 {
    64 	bool operator()(char const *a, char const *b) 
    65 	{
    66 		return std::strcmp(a, b) < 0;
    67 	}
    68 };
    69 
    70 struct Offset
    71 {
    72 	char *name;
    73 	char *symbol;
    74 	int lin;
    75 	int win;
    76 
    77 	Offset()
    78 	{
    79 		name = symbol = NULL;
    80 		lin = win = -1;
    81 	}
    82 
    83 	~Offset()
    84 	{
    85 		delete name;
    86 		delete symbol;
    87 	}
    88 
    89 	void reset()
    90 	{
    91 		delete name;
    92 		delete symbol;
    93 		lin = win = -1;
    94 	}
    95 
    96 	void setName(const char *src)
    97 	{
    98 		delete name;
    99 		name = new char[strlen(src)+1];
   100 		strcpy(name, src);
   101 	}
   102 
   103 	void setSymbol(const char *src)
   104 	{
   105 		delete symbol;
   106 		symbol = new char[strlen(src)+1];
   107 		strcpy(symbol, src);
   108 	}
   109 
   110 	void setLin(int offs)
   111 	{
   112 		lin = offs;
   113 	}
   114 
   115 	void setWin(int offs)
   116 	{
   117 		win = offs;
   118 	}
   119 };
   120 
   121 enum Library
   122 {
   123 	Engine,
   124 	Server
   125 };
   126 
   127 struct Sig
   128 {
   129 	char *name;
   130 	char *win;
   131 	char *lin;
   132 	Library lib;
   133 
   134 	Sig()
   135 	{
   136 		name = win = lin = NULL;
   137 		lib = (Library) -1;
   138 	}
   139 
   140 	~Sig()
   141 	{
   142 		delete name;
   143 		delete win;
   144 		delete lin;
   145 	}
   146 
   147 	void reset()
   148 	{
   149 		delete name;
   150 		delete win;
   151 		delete lin;
   152 		lib = (Library) -1;
   153 	}
   154 
   155 	void setName(const char *src)
   156 	{
   157 		delete name;
   158 		name = new char[strlen(src)+1];
   159 		strcpy(name, src);
   160 	}
   161 
   162 	void setWin(const char *src)
   163 	{
   164 		delete win;
   165 		win = new char[strlen(src)+1];
   166 		strcpy(win, src);
   167 	}
   168 
   169 	void setLin(const char *src)
   170 	{
   171 		delete lin;
   172 		lin = new char[strlen(src)+1];
   173 		strcpy(lin, src);
   174 	}
   175 
   176 	void setLib(const char *src)
   177 	{
   178 		if (stricmp(src, "server") == 0) lib = Server;
   179 		else if (stricmp(src, "engine") == 0) lib = Engine;
   180 		else lib = (Library)-1;
   181 	}
   182 };
   183 
   184 class SendProp;
   185 
   186 class CGameConfig : 
   187 	public ITextListener_SMC//,
   188 //	public IGameConfig
   189 {
   190 public:
   191 	CGameConfig();//const char *file);//, const char *game, const char *engine);
   192 	~CGameConfig();
   193 public:
   194 	bool Reparse(char *error, size_t maxlength);
   195 	bool EnterFile(const char *file, char *error, size_t maxlength);
   196 	list<Offset> GetOffsets();
   197 	list<Sig> GetSigs();
   198 public: //ITextListener_SMC
   199 	SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);
   200 	SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
   201 	SMCResult ReadSMC_LeavingSection(const SMCStates *states);
   202 public: //IGameConfig
   203 	const char *GetKeyValue(const char *key);
   204 	bool GetOffset(const char *key, int *value);
   205 	SendProp *GetSendProp(const char *key);
   206 	bool GetMemSig(const char *key, void **addr);
   207 public:
   208 //	void IncRefCount();
   209 //	unsigned int DecRefCount();
   210 private:
   211 //	bool DoesGameMatch(const char *value);
   212 //	bool DoesEngineMatch(const char *value);
   213 public:
   214 	BaseStringTable *m_pStrings;
   215 	char m_File[PLATFORM_MAX_PATH];
   216 	char m_CurFile[PLATFORM_MAX_PATH];
   217 	list<Offset> m_Offsets;
   218 	list<Sig> m_Sigs;
   219 //	map<const char*,const char*,cmp_str> m_Keys;
   220 	KTrie<int> m_Keys;
   221 	unsigned int m_RefCount;
   222 	/* Parse states */
   223 	int m_ParseState;
   224 	unsigned int m_IgnoreLevel;
   225 	char m_Class[64];
   226 	char m_Prop[64];
   227 	char m_offset[64];
   228 	char m_Game[256];
   229 	char m_gdcGame[256];
   230 	char m_gdcEngine[256];
   231 	bool bShouldBeReadingDefault;
   232 	bool had_game;
   233 	bool matched_game;
   234 	bool had_engine;
   235 	bool matched_engine;
   236 
   237 	/* Custom Sections */
   238 	unsigned int m_CustomLevel;
   239 	ITextListener_SMC *m_CustomHandler;
   240 };
   241 
   242 #endif //_INCLUDE_SOURCEMOD_CGAMECONFIGS_H_