1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/core/ISmmPluginExt.h Fri Nov 14 04:04:02 2008 -0600
1.3 @@ -0,0 +1,158 @@
1.4 +/*
1.5 + * vim: set ts=4 :
1.6 + * ======================================================
1.7 + * Metamod:Source
1.8 + * Copyright (C) 2004-2008 AlliedModders LLC and authors.
1.9 + * All rights reserved.
1.10 + * ======================================================
1.11 + *
1.12 + * This software is provided 'as-is', without any express or implied warranty.
1.13 + * In no event will the authors be held liable for any damages arising from
1.14 + * the use of this software.
1.15 + *
1.16 + * Permission is granted to anyone to use this software for any purpose,
1.17 + * including commercial applications, and to alter it and redistribute it
1.18 + * freely, subject to the following restrictions:
1.19 + *
1.20 + * 1. The origin of this software must not be misrepresented; you must not
1.21 + * claim that you wrote the original software. If you use this software in a
1.22 + * product, an acknowledgment in the product documentation would be
1.23 + * appreciated but is not required.
1.24 + * 2. Altered source versions must be plainly marked as such, and must not be
1.25 + * misrepresented as being the original software.
1.26 + * 3. This notice may not be removed or altered from any source distribution.
1.27 + *
1.28 + * Version: $Id$
1.29 + */
1.30 +
1.31 +#ifndef _INCLUDE_METAMOD_SOURCE_PLUGIN_EXT_H_
1.32 +#define _INCLUDE_METAMOD_SOURCE_PLUGIN_EXT_H_
1.33 +
1.34 +#include <stddef.h>
1.35 +
1.36 +/**
1.37 + * @file ISmmPluginExt.h Provides an alternate method for loading plugins,
1.38 + * without needing to include the default headers and all their Half-Life baggage.
1.39 + *
1.40 + * @brief Definitions for extended plugin loading.
1.41 + */
1.42 +
1.43 +#define SOURCE_ENGINE_UNKNOWN 0 /**< Could not determine the engine version */
1.44 +#define SOURCE_ENGINE_ORIGINAL 1 /**< Original Source Engine (used by The Ship) */
1.45 +#define SOURCE_ENGINE_EPISODEONE 2 /**< Episode 1 Source Engine (second major SDK) */
1.46 +#define SOURCE_ENGINE_ORANGEBOX 3 /**< Orange Box Source Engine (third major SDK) */
1.47 +#define SOURCE_ENGINE_LEFT4DEAD 4 /**< Left 4 Dead */
1.48 +
1.49 +#define METAMOD_PLAPI_VERSION 14 /**< Version of this header file */
1.50 +#define METAMOD_PLAPI_NAME "ISmmPlugin" /**< Name of the plugin interface */
1.51 +
1.52 +namespace SourceMM
1.53 +{
1.54 + class ISmmPlugin;
1.55 + class ISmmAPI;
1.56 +
1.57 + /**
1.58 + * @brief Used to uniquely identify plugins.
1.59 + */
1.60 + typedef int PluginId;
1.61 +
1.62 + #define METAMOD_FAIL_API_V1 7 /**< Minimum API version to detect for V1 */
1.63 + #define METAMOD_FAIL_API_V2 14 /**< Minimum API version to detect for V2 */
1.64 +
1.65 + /**
1.66 + * Use this to instantiate a plugin that will always fail.
1.67 + * This class definition works against major API versions 1 and 2.
1.68 + */
1.69 + class ISmmFailPlugin
1.70 + {
1.71 + public:
1.72 + /**
1.73 + * @brief You must return METAMOD_FAIL_API_V1 or METAMOD_FAIL_API_V2 here,
1.74 + * depending on which Metamod:Source version you detected.
1.75 + */
1.76 + virtual int GetApiVersion() = 0;
1.77 +
1.78 + /**
1.79 + * @brief Do not change.
1.80 + */
1.81 + virtual ~ISmmFailPlugin()
1.82 + {
1.83 + }
1.84 +
1.85 + /**
1.86 + * @brief Return false here -- fill in the error buffer appropriately.
1.87 + *
1.88 + * Do not ever return true. If you do, MM:S will crash because the class layout is
1.89 + * incomplete against ISmmPlugin.
1.90 + *
1.91 + * @param id Ignore.
1.92 + * @param ismm Ignore.
1.93 + * @param error Error buffer (must be filled).
1.94 + * @param maxlength Maximum size of error buffer.
1.95 + * @param late Ignore.
1.96 + * @return Must return false.
1.97 + */
1.98 + virtual bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlength, bool late) =0;
1.99 + };
1.100 +}
1.101 +
1.102 +typedef SourceMM::ISmmPlugin METAMOD_PLUGIN;
1.103 +
1.104 +/**
1.105 + * @brief Contains version information.
1.106 + */
1.107 +struct MetamodVersionInfo
1.108 +{
1.109 + int api_major; /**< ISmmAPI major version */
1.110 + int api_minor; /**< ISmmAPI minor version */
1.111 + int sh_iface; /**< SourceHook interface version */
1.112 + int sh_impl; /**< SourceHook implementation version */
1.113 + int pl_min; /**< Plugin API minimum version */
1.114 + int pl_max; /**< Plugin API maximum version */
1.115 + int source_engine; /**< Source Engine version (SOURCE_* constants) */
1.116 +};
1.117 +
1.118 +/**
1.119 + * @brief Contains information about loading a plugin.
1.120 + */
1.121 +struct MetamodLoaderInfo
1.122 +{
1.123 + const char *pl_file; /**< File path to the plugin being loaded. */
1.124 + const char *pl_path; /**< Folder path containing the plugin. */
1.125 +};
1.126 +
1.127 +/**
1.128 + * @brief If a function of this type is exposed as "CreateInterface_MMS", then
1.129 + * Metamod:Source will attempt to call this function before calling
1.130 + * CreateInterface. If this function returns a valid ISmmPlugin pointer, then
1.131 + * CreateInterface will not be called.
1.132 + *
1.133 + * This is useful for implementing a mini-loader plugin for multiple versions.
1.134 + *
1.135 + * @param mvi MetamodVersionInfo structure.
1.136 + * @param mli MetamodLoaderInfo structure.
1.137 + * @return ISmmAPI pointer, or NULL if none.
1.138 + */
1.139 +typedef METAMOD_PLUGIN *(*METAMOD_FN_LOAD)(const MetamodVersionInfo *mvi,
1.140 + const MetamodLoaderInfo *mli);
1.141 +
1.142 +/**
1.143 + * @brief If a function of this type is exposed as "UnloadInterface_MMS", then
1.144 + * Metamod:Source will attempt to call this function after calling
1.145 + * ISmmAPI::Unload(), and before closing the library. This lets loader plugins
1.146 + * clean up before exiting.
1.147 + *
1.148 + * Note: This function will be ignored unless CreateInterfce_MMS was exposed.
1.149 + * It may be called even if ISmmAPI::Unload() could not be called.
1.150 + */
1.151 +typedef void (*METAMOD_FN_UNLOAD)();
1.152 +
1.153 +/**
1.154 + * @brief Original type of load function. CreateInterfaceFn from Valve.
1.155 + *
1.156 + * Plugins will expose this as "CreateInterface".
1.157 + */
1.158 +typedef void *(*METAMOD_FN_ORIG_LOAD)(const char *, int *);
1.159 +
1.160 +#endif //INCLUDE_METAMOD_SOURCE_PLUGIN_EXT_H_
1.161 +