plugins/include/core.inc
author Nicholas Hastings <skamonkey@gmail.com>
Mon Feb 08 19:57:20 2010 -0800 (2010-02-08)
changeset 2914 bf5f9aa53abe
parent 2841 dde3dd0b4b8b
child 3743 a98686a77974
permissions -rw-r--r--
Fixed FindEntityByClassname crash in Synergy (bug 4235, r=dvander).
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     5  * =============================================================================
     6  *
     7  * This file is part of the SourceMod/SourcePawn SDK.
     8  *
     9  * This program is free software; you can redistribute it and/or modify it under
    10  * the terms of the GNU General Public License, version 3.0, as published by the
    11  * Free Software Foundation.
    12  * 
    13  * This program is distributed in the hope that it will be useful, but WITHOUT
    14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    16  * details.
    17  *
    18  * You should have received a copy of the GNU General Public License along with
    19  * this program.  If not, see <http://www.gnu.org/licenses/>.
    20  *
    21  * As a special exception, AlliedModders LLC gives you permission to link the
    22  * code of this program (as well as its derivative works) to "Half-Life 2," the
    23  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    24  * by the Valve Corporation.  You must obey the GNU General Public License in
    25  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    26  * this exception to all derivative works.  AlliedModders LLC defines further
    27  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    28  * or <http://www.sourcemod.net/license.php>.
    29  *
    30  * Version: $Id$
    31  */
    32 
    33 #if defined _core_included
    34  #endinput
    35 #endif
    36 #define _core_included
    37 
    38 #include <version>
    39 
    40 /** If this gets changed, you need to update Core's check. */
    41 #define SOURCEMOD_PLUGINAPI_VERSION		5
    42 
    43 struct PlVers
    44 {
    45 	version,
    46 	String:filevers[],
    47 	String:date[],
    48 	String:time[]
    49 };
    50 
    51 /**
    52  * Function helper values.
    53  */
    54 enum Function
    55 {
    56      INVALID_FUNCTION = -1,
    57 };
    58 
    59 /**
    60  * Specifies what to do after a hook completes.
    61  */
    62 enum Action
    63 {
    64 	Plugin_Continue = 0,	/**< Continue with the original action */
    65 	Plugin_Changed = 1,		/**< Inputs or outputs have been overridden with new values */
    66 	Plugin_Handled = 3,		/**< Handle the action at the end (don't call it) */
    67 	Plugin_Stop = 4,		/**< Immediately stop the hook chain and handle the original */
    68 };
    69 
    70 /**
    71  * Specifies identity types.
    72  */
    73 enum Identity
    74 {
    75 	Identity_Core = 0,
    76 	Identity_Extension = 1,
    77 	Identity_Plugin = 2
    78 };
    79 
    80 public PlVers:__version = 
    81 {
    82 	version = SOURCEMOD_PLUGINAPI_VERSION,
    83 	filevers = SOURCEMOD_VERSION,
    84 	date = __DATE__,
    85 	time = __TIME__
    86 };
    87 
    88 /**
    89  * Plugin status values.
    90  */
    91 enum PluginStatus
    92 {
    93 	Plugin_Running=0,		/**< Plugin is running */
    94 	/* All states below are "temporarily" unexecutable */
    95 	Plugin_Paused,			/**< Plugin is loaded but paused */
    96 	Plugin_Error,			/**< Plugin is loaded but errored/locked */
    97 	/* All states below do not have all natives */
    98 	Plugin_Loaded,			/**< Plugin has passed loading and can be finalized */
    99 	Plugin_Failed,			/**< Plugin has a fatal failure */
   100 	Plugin_Created,			/**< Plugin is created but not initialized */
   101 	Plugin_Uncompiled,		/**< Plugin is not yet compiled by the JIT */
   102 	Plugin_BadLoad,			/**< Plugin failed to load */
   103 };
   104 
   105 /**
   106  * Plugin information properties.
   107  */
   108 enum PluginInfo
   109 {
   110 	PlInfo_Name,			/**< Plugin name */
   111 	PlInfo_Author,			/**< Plugin author */
   112 	PlInfo_Description,		/**< Plugin description */
   113 	PlInfo_Version,			/**< Plugin verison */
   114 	PlInfo_URL,				/**< Plugin URL */
   115 };
   116 
   117 /**
   118  * Defines how an extension must expose itself for autoloading.
   119  */
   120 struct Extension
   121 {
   122 	const String:name[],	/**< Short name */
   123 	const String:file[],	/**< Default file name */
   124 	bool:autoload,			/**< Whether or not to auto-load */
   125 	bool:required,			/**< Whether or not to require */
   126 };
   127 
   128 /**
   129  * Defines how a plugin must expose itself for native requiring.
   130  */
   131 struct SharedPlugin
   132 {
   133 	const String:name[],	/**< Short name */
   134 	const String:file[],	/**< File name */
   135 	bool:required,			/**< Whether or not to require */
   136 };
   137 
   138 public Float:NULL_VECTOR[3];		/**< Pass this into certain functions to act as a C++ NULL */
   139 public const String:NULL_STRING[1];	/**< pass this into certain functions to act as a C++ NULL */
   140 
   141 /**
   142  * Horrible compatibility shim.
   143  */
   144 public Extension:__ext_core = 
   145 {
   146 	name = "Core",
   147 	file = "core",
   148 	autoload = 0,
   149 	required = 0,
   150 };
   151 
   152 native VerifyCoreVersion();
   153 
   154 /**
   155  * Sets a native as optional, such that if it is unloaded, removed,
   156  * or otherwise non-existent, the plugin will still work.  Calling
   157  * removed natives results in a run-time error.
   158  *
   159  * @param name			Native name.
   160  * @noreturn
   161  */
   162 native MarkNativeAsOptional(const String:name[]);
   163 
   164 public __ext_core_SetNTVOptional()
   165 {
   166 	MarkNativeAsOptional("GetFeatureStatus");
   167 	MarkNativeAsOptional("RequireFeature");
   168 	MarkNativeAsOptional("AddCommandListener");
   169 	MarkNativeAsOptional("RemoveCommandListener");
   170 	VerifyCoreVersion();
   171 }
   172 
   173 
   174 #define AUTOLOAD_EXTENSIONS
   175 #define REQUIRE_EXTENSIONS
   176 #define REQUIRE_PLUGIN