2004-03-06 00:03:14 +03:00
|
|
|
/* AMX Mod X
|
|
|
|
*
|
|
|
|
* by the AMX Mod X Development Team
|
|
|
|
* originally developed by OLO
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the author gives permission to
|
|
|
|
* link the code of this program with the Half-Life Game Engine ("HL
|
|
|
|
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
|
|
|
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
|
|
|
* respects for all of the code used other than the HL Engine and MODs
|
|
|
|
* from Valve. If you modify this file, you may extend this exception
|
|
|
|
* to your version of the file, but you are not obligated to do so. If
|
|
|
|
* you do not wish to do so, delete this exception statement from your
|
|
|
|
* version.
|
|
|
|
*/
|
|
|
|
|
2004-01-31 23:56:22 +03:00
|
|
|
#ifndef PLUGIN_H
|
|
|
|
#define PLUGIN_H
|
|
|
|
|
2006-05-08 01:16:00 +04:00
|
|
|
#include "CString.h"
|
|
|
|
#include "sh_list.h"
|
|
|
|
#include "amx.h"
|
|
|
|
#include "amxxfile.h"
|
|
|
|
|
2004-01-31 23:56:22 +03:00
|
|
|
// *****************************************************
|
|
|
|
// class CPluginMngr
|
|
|
|
// *****************************************************
|
|
|
|
|
2005-09-10 04:38:42 +04:00
|
|
|
enum
|
|
|
|
{
|
2005-12-01 16:42:28 +03:00
|
|
|
ps_bad_load, //Load failed
|
|
|
|
ps_error, //Erroneous state
|
|
|
|
ps_locked, //UNUSED
|
|
|
|
ps_paused, //Plugin is temporarily paused
|
|
|
|
ps_stopped, //Plugin is ... more temporarily paused
|
|
|
|
ps_running, //Plugin is running
|
2004-01-31 23:56:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class CPluginMngr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
class iterator;
|
|
|
|
|
|
|
|
class CPlugin
|
|
|
|
{
|
|
|
|
friend class iterator;
|
|
|
|
friend class CPluginMngr;
|
|
|
|
|
|
|
|
AMX amx;
|
|
|
|
void* code;
|
2005-09-17 03:48:51 +04:00
|
|
|
|
2004-08-15 14:53:48 +04:00
|
|
|
String name;
|
|
|
|
String version;
|
|
|
|
String title;
|
|
|
|
String author;
|
2004-09-10 19:52:48 +04:00
|
|
|
String errorMsg;
|
2005-09-17 03:48:51 +04:00
|
|
|
|
2005-07-25 10:03:43 +04:00
|
|
|
int m_PauseFwd;
|
|
|
|
int m_UnpauseFwd;
|
2004-01-31 23:56:22 +03:00
|
|
|
int paused_fun;
|
|
|
|
int status;
|
|
|
|
CPlugin* next;
|
|
|
|
int id;
|
2005-09-17 03:48:51 +04:00
|
|
|
|
2005-09-10 04:38:42 +04:00
|
|
|
CPlugin(int i, const char* p, const char* n, char* e, int d);
|
|
|
|
~CPlugin();
|
2005-09-17 03:48:51 +04:00
|
|
|
|
2005-07-27 01:31:21 +04:00
|
|
|
bool m_Debug;
|
2004-01-31 23:56:22 +03:00
|
|
|
public:
|
2004-08-13 12:46:04 +04:00
|
|
|
inline const char* getName() { return name.c_str();}
|
|
|
|
inline const char* getVersion() { return version.c_str();}
|
|
|
|
inline const char* getTitle() { return title.c_str();}
|
|
|
|
inline const char* getAuthor() { return author.c_str();}
|
2004-09-10 19:52:48 +04:00
|
|
|
inline const char* getError() { return errorMsg.c_str();}
|
|
|
|
inline int getStatusCode() { return status; }
|
2004-01-31 23:56:22 +03:00
|
|
|
inline int getId() const { return id; }
|
|
|
|
inline AMX* getAMX() { return &amx; }
|
2004-09-17 04:27:28 +04:00
|
|
|
inline const AMX* getAMX() const { return &amx; }
|
2005-09-10 04:38:42 +04:00
|
|
|
inline void setTitle(const char* n) { title.assign(n); }
|
|
|
|
inline void setAuthor(const char* n) { author.assign(n); }
|
|
|
|
inline void setVersion(const char* n) { version.assign(n); }
|
|
|
|
inline void setError(const char* n) { errorMsg.assign(n); }
|
2005-08-30 11:18:47 +04:00
|
|
|
inline bool isValid() const { return (status >= ps_paused); }
|
2005-09-10 04:38:42 +04:00
|
|
|
inline bool isPaused() const { return ((status == ps_paused) || (status == ps_stopped)); }
|
2005-07-25 10:03:43 +04:00
|
|
|
inline bool isExecutable(int id) const { return (isValid() && !isPaused()); }
|
2005-09-17 03:48:51 +04:00
|
|
|
|
2005-08-01 00:11:58 +04:00
|
|
|
void Finalize();
|
2004-04-22 11:47:55 +04:00
|
|
|
void pausePlugin();
|
|
|
|
void unpausePlugin();
|
2005-09-10 04:38:42 +04:00
|
|
|
void pauseFunction(int id);
|
|
|
|
void unpauseFunction(int id);
|
|
|
|
void setStatus(int a);
|
2005-09-17 03:48:51 +04:00
|
|
|
|
2004-01-31 23:56:22 +03:00
|
|
|
const char* getStatus() const;
|
2005-07-27 01:31:21 +04:00
|
|
|
inline bool isDebug() const { return m_Debug; }
|
2004-01-31 23:56:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
CPlugin *head;
|
|
|
|
int pCounter;
|
|
|
|
public:
|
2005-08-01 00:11:58 +04:00
|
|
|
CPluginMngr() { head = 0; pCounter = 0; pNatives = NULL; m_Finalized=false;}
|
2006-05-08 01:16:00 +04:00
|
|
|
~CPluginMngr() { clear(); InvalidateCache(); }
|
2004-01-31 23:56:22 +03:00
|
|
|
|
2005-08-01 00:11:58 +04:00
|
|
|
bool m_Finalized;
|
|
|
|
AMX_NATIVE_INFO *pNatives;
|
|
|
|
|
2004-01-31 23:56:22 +03:00
|
|
|
// Interface
|
|
|
|
|
2004-09-08 11:05:16 +04:00
|
|
|
CPlugin* loadPlugin(const char* path, const char* name, char* error, int debug);
|
2005-09-10 04:38:42 +04:00
|
|
|
void unloadPlugin(CPlugin** a);
|
2006-08-17 23:34:34 +04:00
|
|
|
int loadPluginsFromFile(const char* filename, bool warn=true);
|
2005-09-17 03:48:51 +04:00
|
|
|
|
2006-02-01 15:10:52 +03:00
|
|
|
inline CPlugin* findPluginFast(AMX *amx) { return (CPlugin*)(amx->userdata[UD_FINDPLUGIN]); }
|
2004-01-31 23:56:22 +03:00
|
|
|
CPlugin* findPlugin(AMX *amx);
|
|
|
|
CPlugin* findPlugin(int index);
|
|
|
|
CPlugin* findPlugin(const char* name);
|
2005-09-17 03:48:51 +04:00
|
|
|
|
2004-01-31 23:56:22 +03:00
|
|
|
inline int getPluginsNum() const { return pCounter; }
|
2005-08-01 00:11:58 +04:00
|
|
|
void Finalize();
|
2004-01-31 23:56:22 +03:00
|
|
|
void clear();
|
|
|
|
|
2005-09-10 04:38:42 +04:00
|
|
|
class iterator
|
|
|
|
{
|
2004-01-31 23:56:22 +03:00
|
|
|
CPlugin *a;
|
|
|
|
public:
|
|
|
|
iterator(CPlugin*aa) : a(aa) {}
|
|
|
|
iterator& operator++() { a = a->next; return *this; }
|
|
|
|
bool operator==(const iterator& b) const { return a == b.a; }
|
|
|
|
bool operator!=(const iterator& b) const { return !operator==(b); }
|
|
|
|
operator bool () const { return a ? true : false; }
|
|
|
|
CPlugin& operator*() { return *a; }
|
|
|
|
};
|
2005-09-10 04:38:42 +04:00
|
|
|
|
2004-01-31 23:56:22 +03:00
|
|
|
inline iterator begin() const { return iterator(head); }
|
|
|
|
inline iterator end() const { return iterator(0); }
|
2006-05-08 01:16:00 +04:00
|
|
|
public:
|
|
|
|
struct plcache_entry
|
|
|
|
{
|
|
|
|
CAmxxReader *file;
|
|
|
|
size_t bufsize;
|
|
|
|
char *buffer;
|
|
|
|
String path;
|
|
|
|
};
|
|
|
|
char *ReadIntoOrFromCache(const char *file, size_t &bufsize);
|
|
|
|
void InvalidateCache();
|
|
|
|
void InvalidateFileInCache(const char *file, bool freebuf);
|
2006-05-10 06:32:34 +04:00
|
|
|
void CacheAndLoadModules(const char *plugin);
|
|
|
|
void CALMFromFile(const char *file);
|
2006-05-08 01:16:00 +04:00
|
|
|
private:
|
|
|
|
List<plcache_entry *> m_plcache;
|
2006-08-17 22:25:23 +04:00
|
|
|
List<String *> m_BlockList;
|
2004-01-31 23:56:22 +03:00
|
|
|
};
|
|
|
|
|
2005-09-10 04:38:42 +04:00
|
|
|
#endif //PLUGIN_H
|