1
0
mirror of https://github.com/alliedmodders/metamod-source.git synced 2025-02-18 11:54:14 +01:00

initial import of 1.2 api changes

--HG--
extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/trunk%40167
This commit is contained in:
David Anderson 2005-12-23 23:38:38 +00:00
parent 7711afa7a8
commit 00322f8833
9 changed files with 81 additions and 38 deletions

View File

@ -32,9 +32,11 @@
* 4: Added AllPluginsLoaded() callback (2005-04-18)
* 5: Bumped version for SourceHook V4 (2005-05-01)
* 6: Added functions for console printing (2005-05-26)
* MC 7: Changed template libraries (2005-08-11)
* M 7: Changed template libraries (2005-08-11)
* New loading structure mechanism
* New SourceHook version
* C 8: New SourceHook version (2005-12-23)
* New ISmmAPI additions
*/
#define PLAPI_MIN_VERSION 7

View File

@ -316,3 +316,45 @@ int CSmmAPI::FormatIface(char iface[], unsigned int maxlength)
return num;
}
void *CSmmAPI::InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret)
{
size_t len = strlen(iface);
int num = 0;
void *pf = NULL;
char *_if = new char[len + 2];
if (max > 999)
max = 999;
strcpy(_if, iface);
do
{
if ( (pf = (fn)(_if, NULL)) != NULL )
break;
if (num > max)
break;
} while ( num = FormatIface(_if, len) );
return pf;
}
const char *CSmmAPI::GetBaseDir()
{
return g_ModPath.c_str();
}
void CSmmAPI::PathFormat(char *buffer, size_t len, const char *fmt, ...)
{
va_list ap;
va_start(ap,fmt);
size_t mylen = vsnprintf(buffer, len, fmt, ap);
va_end(ap);
for (size_t i=0; i<mylen; i++)
{
if (buffer[i] == ALT_SEP_CHAR)
buffer[i] = PATH_SEP_CHAR;
}
}

View File

@ -51,6 +51,9 @@ namespace SourceMM
virtual void AddListener(ISmmPlugin *plugin, IMetamodListener *pListener);
virtual void *MetaFactory(const char *iface, int *ret, PluginId *id);
virtual int FormatIface(char buffer[], unsigned int maxlength);
virtual void *InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret);
virtual const char *GetBaseDir();
virtual void PathFormat(char *buffer, size_t len, const char *fmt, ...);
public:
bool CacheCmds();
private:

View File

@ -83,6 +83,21 @@ public: //Added in 1.1.2 (1:1)
* reformats the string to increase the number, then returns the new number.
*/
virtual int FormatIface(char iface[], unsigned int maxlength) =0;
public: //Added in 1.2 (1:2)
/**
* @brief Searches for an interface for you.
*/
virtual void *InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret) =0;
/**
* @brief Returns the base directory of the game/server, equivalent to IVEngineServer::GetGameDir
*/
virtual const char *GetBaseDir() =0;
/**
* @brief Formats a file path to the local OS. Does not include any base directories.
*/
virtual void PathFormat(char *buffer, size_t len, const char *fmt, ...) =0;
};

View File

@ -20,7 +20,7 @@
#include <sourcehook/sourcehook.h>
#include "ISmmAPI.h"
#define PLAPI_VERSION 7
#define PLAPI_VERSION 8
#define PLAPI_NAME "ISmmPlugin"
class ISmmAPI;
@ -143,7 +143,7 @@ public:
};
/**
* @brief Added in 1.2 so plugins could listen to specific events
* @brief Added in 1.1 so plugins could listen to specific events
*/
class IMetamodListener
{

View File

@ -92,7 +92,7 @@ void InitMainStates()
GetFileOfAddress(g_GameDll.factory, full_path, sizeof(full_path)-1);
g_BinPath.assign(full_path);
UTIL_PathFmt(full_path, sizeof(full_path)-1, "%s/%s", g_ModPath.c_str(), GetPluginsFile());
g_SmmAPI.PathFormat(full_path, sizeof(full_path)-1, "%s/%s", g_ModPath.c_str(), GetPluginsFile());
//Like metamod, reload plugins at the end of the map.
//This is so plugins can hook everything on load, BUT, new plugins will be reloaded
@ -138,7 +138,7 @@ bool DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory,
}
char full_path[260];
UTIL_PathFmt(full_path, sizeof(full_path)-1, "%s/%s", g_ModPath.c_str(), GetPluginsFile());
g_SmmAPI.PathFormat(full_path, sizeof(full_path)-1, "%s/%s", g_ModPath.c_str(), GetPluginsFile());
LoadPluginsFromFile(full_path);
@ -304,9 +304,9 @@ SMM_API void *CreateInterface(const char *iface, int *ret)
//no need to append "bin"
if (gamebin)
{
UTIL_PathFmt(temp_path, sizeof(temp_path)-1, "%s/%s/%s", lptr, ptr, SERVER_DLL);
g_SmmAPI.PathFormat(temp_path, sizeof(temp_path)-1, "%s/%s/%s", lptr, ptr, SERVER_DLL);
} else {
UTIL_PathFmt(temp_path, sizeof(temp_path)-1, "%s/%s/%s/%s", lptr, ptr, "bin", SERVER_DLL);
g_SmmAPI.PathFormat(temp_path, sizeof(temp_path)-1, "%s/%s/%s/%s", lptr, ptr, "bin", SERVER_DLL);
}
if (!UTIL_PathCmp(s_dllpath.c_str(), temp_path))
{
@ -504,7 +504,7 @@ int LoadPluginsFromFile(const char *file)
ext = "";
}
//Format the new path
UTIL_PathFmt(full_path, sizeof(full_path)-1, "%s/%s%s", g_ModPath.c_str(), buffer, ext);
g_SmmAPI.PathFormat(full_path, sizeof(full_path)-1, "%s/%s%s", g_ModPath.c_str(), buffer, ext);
id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error)-1);
if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
{
@ -598,6 +598,10 @@ bool LevelInit_handler(char const *pMapName, char const *pMapEntities, char cons
LogMessage("[META] Warning: Console messages will not be redirected to rcon console.");
}
#if (defined _DEBUG || defined DEBUG) && (defined WIN32 || defined _WIN32)
SetUnhandledExceptionFilter(NULL);
#endif
ITER_EVENT(OnLevelInit, (pMapName, pMapEntities, pOldLevel, pLandmarkName, loadGame, background));
RETURN_META_VALUE(MRES_IGNORED, false);

View File

@ -28,22 +28,17 @@
/**
* Versioning
* First grouping is major release version (1)
* Second grouping is minor release version.
* Third grouping is release change version.
* For an entire code rehaul, we would change major.
* For a simple bug-fix release, we would change the third grouping.
* For an API change, we would increase the second grouping by one.
* For a breaking API change, we would increase the second group up to the next bracket.
* (example: 1.45 -> 1.50. 1.12 -> 1.20. 1.19 -> 1.20)
* minor changes can also roll over, but a big change should ALWAYS roll over.
* Increasing one grouping should make the lesser ones reset back to zero.
* ?what the hell was I smoking when I wrote this
* increase api_major when API breaks
* increase api_minor when new functions are added (non-breaking)
* increase vers_release when bug fix releases are made
* never increase major
*/
#define SOURCEMM_VERSION "1.1.2"
#define SOURCEMM_VERSION "1.2"
#define SOURCEMM_DATE __DATE__
#define SM_MAJOR_VERSION 1 //never need to increase this
#define SM_VERS_API_MAJOR 1 //increase this on a breaking change
#define SM_VERS_API_MINOR 1 //increase this on a non-breaking API change
#define SM_VERS_API_MINOR 2 //increase this on a non-breaking API change
#define SM_VERS_RELEASE 0 //increase this on a bug-fix release.
//We need a good CServerGameDLL version to work properly. We support these inclusively.

View File

@ -159,23 +159,6 @@ void UTIL_KeySplit(const char *str, char *buf1, size_t len1, char *buf2, size_t
buf2[c] = '\0';
}
/**
* Formats a path name for an OS
*/
void UTIL_PathFmt(char *buffer, size_t len, const char *fmt, ...)
{
va_list ap;
va_start(ap,fmt);
size_t mylen = vsnprintf(buffer, len, fmt, ap);
va_end(ap);
for (size_t i=0; i<mylen; i++)
{
if (buffer[i] == ALT_SEP_CHAR)
buffer[i] = PATH_SEP_CHAR;
}
}
bool UTIL_PathCmp(const char *path1, const char *path2)
{
size_t len1=strlen(path1);

View File

@ -21,7 +21,6 @@ void UTIL_TrimComments(char *buffer);
void UTIL_TrimLeft(char *buffer);
void UTIL_TrimRight(char *buffer);
void UTIL_KeySplit(const char *str, char *buf1, size_t len1, char *buf2, size_t len2);
void UTIL_PathFmt(char *buffer, size_t len, const char *fmt, ...);
bool UTIL_PathCmp(const char *path1, const char *path2);
#endif //_INCLUDE_UTIL_H