QMM Plugin API
QMM
API version 1:0
 
Contents

  1. Overview

 
Overview

This document explains the API for QMM plugins. If you are looking for QMM installation instructions, please go here.
All plugins must include the qmmapi.h header file from the QMM source. This contains all the type definitions, global externs, and macros used by plugins.
In this document, you will see the following colored boxes:
	Green blocks like this contain code samples
	Blue blocks like this contain notes
	Red blocks like this contain warnings

Top
 
Data Types

plugininfo_t
This struct contains information about a plugin and is created by the plugin and given to QMM in QMM_Query().

typedef struct plugininfo_s {
	char* name;
	char* version;
	char* desc;
	char* author;
	char* url;
	int canpause;
	int loadcmd;
	int unloadcmd;

	int pifv_major;
	int pifv_minor;
} plugininfo_t;
  • name is the name of the plugin.
  • version is the version of the plugin.
  • desc is a short description of the plugin.
  • author is the author of the plugin.
  • url is the homepage URL for the plugin.
  • canpause is a boolean flag that determines whether the plugin can be paused; 0=no, 1=yes
  • loadcmd is a boolean flag that determines whether the plugin can be loaded by the "qmm load" server console command; 0=no, 1=yes
  • unloadcmd is a boolean flag that determines whether the plugin can be unloaded by the "qmm unload" server console command; 0=no, 1=yes
    (the "qmm force_unload" command overrides this flag)
  • pifv_major is the major API version this plugin was compiled with, just set this to QMM_PIFV_MAJOR
  • pifv_minor is the minor API version this plugin was compiled with, just set this to QMM_PIFV_MINOR

Top

pluginfuncs_t
This struct contains function pointers for helper functions provided by QMM.
See the QMM Plugin Functions section for more information.

typedef struct pluginfuncs_s {
	int (*pfnWriteGameLog)(const char*, int);
	char* (*pfnVarArgs)(char*, ...);
	int (*pfnIsVM)();
	const char* (*pfnEngMsgName)(int);
	const char* (*pfnModMsgName)(int);
	int (*pfnGetIntCvar)(const char*);
	const char* (*pfnGetStrCvar)(const char*);
} pluginfuncs_t;

Top

pluginres_t
This enumeration contains constants used to tell QMM how to handle the function return value and function routing.
See QMM_RETURN for more information.

typedef enum pluginres_e {
	QMM_UNUSED = -2,
	QMM_ERROR = -1,
	QMM_IGNORED = 0,
	QMM_OVERRIDE,
	QMM_SUPERCEDE
} pluginres_t;
  • QMM_UNUSED is used internally by QMM, do not use this constant.
  • QMM_ERROR signals that an error happened during the function.
  • QMM_IGNORED signals that nothing special needs to be done with this function.
  • QMM_OVERRIDE signals that the final destination function should be called, but that this function's return value should be used as the return value to the caller.
  • QMM_SUPERCEDE signals that the final destination function should not be called, and this function's return value should be used as the return value to the caller.
For more information on these, see QMM_RETURN, QMM_SET_RESULT, and QMM_RET_*.

Top

eng_syscall_t
This is a function pointer prototype for the engine's syscall function.
See g_syscall for more information.

typedef int (*eng_syscall_t)(int, ...);

Top

mod_vmMain_t
This is a function pointer prototype for the mod's vmMain function.
See g_vmMain for more information.

typedef int (*mod_vmMain_t)(int, int, int, int, int, int, int, int, int, int, int, int, int);

Top
 
Globals

plugininfo_t g_plugininfo
This is created by the plugin and given to QMM in QMM_Query().

Top


pluginfuncs_t* g_pluginfuncs
This is stored in QMM_Attach() and is used to access QMM-provided helper functions. See the QMM Plugin Functions section for more information.

Top


pluginres_t* g_result
This is stored in QMM_Attach() and is used by the QMM_RETURN, QMM_SET_RESULT, and QMM_RET_* macros to tell QMM how to handle the function return value and function routing.
See QMM_RETURN, QMM_SET_RESULT, and QMM_RET_* for more information.

Top


eng_syscall_t g_syscall
This is stored in QMM_Attach() and is a function pointer used to call the engine's syscall function.

Top


mod_vmMain_t g_vmMain
This is stored in QMM_Attach() and is a function pointer used to call the mod's vmMain() function.

Top


int g_vmbase
This is stored in QMM_Attach() and is a magic number used by GETPTR and SETPTR to handle QVM pointers.

WARNING: g_vmbase should not be used by anything other than the GETPTR and SETPTR macros.


Top
 
Exported Functions

C_DLLEXPORT void QMM_Query(pluginfuncs_t** pinfo)
This function is the first function called in a QMM plugin and its sole purpose is to give information about the plugin via a pluginfuncs_t struct. To pass plugin info to QMM, simply use the QMM_GIVE_PINFO macro.

C_DLLEXPORT void QMM_Query(plugininfo_t** pinfo) {
	QMM_GIVE_PINFO();
}

WARNING: Nothing that requires deinitialization should be done within QMM_Query() since there is no corresponding unload function.


Top

C_DLLEXPORT int QMM_Attach(eng_syscall_t engfunc, mod_vmMain_t modfunc, pluginres_t* presult, pluginfuncs_t* pluginfuncs, int vmbase, int iscmd)
This function is the second function called in a QMM plugin. It is used to give pointers and other important information to the plugin.

  • engfunc is a function pointer for the engine's syscall function.
  • modfunc is a function pointer for the mod's vmMain() function.
  • presult is a pointer to the result flag in QMM that holds information about how to handle function return values and function routing.
  • pluginfuncs is a pointer to a struct containing helper functions for plugins. See the QMM Plugin Functions section for more information.
  • vmbase is a magic number used by GETPTR and SETPTR to handle QVM pointers.
To easily save all these variables, simply use the QMM_SAVE_VARS macro:
C_DLLEXPORT int QMM_Attach(/* ... */) {
	QMM_SAVE_VARS();
	//...
The last argument, iscmd is a boolean flag that is 0 if the plugin is being loaded on map startup from the QMM configuration file. It is 1 if the plugin is being loaded from the server console during a map.
To signal to QMM that this function completed successfully, it should return 1. If this function returns 0, it will be unloaded immediately upon return.
Non-game-related initializations should be done here.

Top

C_DLLEXPORT void QMM_Detach(int iscmd)
This function is the last function called in a QMM plugin, provided QMM_Attach() was called.
The single argument, iscmd, behaves the same as it's QMM_Attach() counterpart. However, if the plugin was unloaded forcefully, this will always be 0 as if the plugin was unloaded at the end of a map.
Non-game-related deinitializations should be done here.

Top


C_DLLEXPORT int QMM_vmMain(int cmd, int arg0, /* ... */, int arg11)
This function is called before the mod's vmMain() function is called and the parameters behave the same way.

Top


C_DLLEXPORT int QMM_vmMain_Post(int cmd, int arg0, /* ... */, int arg11)
This function is called after the mod's vmMain() function is called and the parameters behave the same way.

Top


C_DLLEXPORT int QMM_syscall(int cmd, int arg0, /* ... */, int arg12)
This function is called before the engine's syscall function is called and the parameters behave the same way.

Note: In the mod SDK, the engine's syscall function is called behind-the-scenes by the trap_* functions. Look at g_syscalls.c in the mod SDK for more information.


Top

C_DLLEXPORT int QMM_syscall_Post(int cmd, int arg0, /* ... */, int arg12)
This function is called after the engine's syscall function is called and the parameters behave the same way.

Note: In the mod SDK, the engine's syscall function is called behind-the-scenes by the trap_* functions. Look at g_syscalls.c in the mod SDK for more information.


Top
 
QMM Plugin Functions

int QMM_ISVM()
This function simply returns 0 if the mod is a native DLL/SO binary, or 1 if the mod is a QVM.

Top


char* QMM_VARARGS(char* fmt, ...)
This function takes printf-style formatting arguments and returns the resulting string.

Note: The returned char* points to 1 of 8 cycling static string buffers, so you do not have to copy the string to a local buffer as is typical with functions returning statically-stored strings.


Top

int QMM_WRITEGAMELOG(char* str, int len)
QMM detects the file handle for the mod's game log. This function allows you to write a string to the log.

Note: If len is -1, it will default to the length of str.


Top

const char* QMM_ENGMSGNAME(int msg)
This will return the name of the given engine syscall message constant.

Top


const char* QMM_MODMSGNAME(int msg)
This will return the name of the given mod vmMain() message constant.

Top


int QMM_GETINTCVAR(const char* cvar)
This will return the integer value of the given cvar.

Top


const char* QMM_GETSTRCVAR(const char* cvar)
This will return the string value of the given cvar.

Note: The returned char* points to 1 of 8 cycling static string buffers, so you do not have to copy the string to a local buffer as is typical with functions returning statically-stored strings.


Top
 
Miscellaneous

QMM_GIVE_PINFO()
This macro properly passes g_plugininfo to QMM in QMM_Query().

C_DLLEXPORT void QMM_Query(plugininfo_t** pinfo) {
	QMM_GIVE_PINFO();
}

Top

QMM_SAVE_VARS()
This macro properly stores the arguments to QMM_Attach() in global variables.

C_DLLEXPORT int QMM_Attach(/* ... */) {
	QMM_SAVE_VARS();
	//...

Top

QMM_PIFV_MAJOR
This macro contains the major QMM plugin API version number. This should be assigned to the pifv_major field of g_plugininfo.
The current QMM plugin API version (both major and minor) can be found at the top of this document on the right (in the form major:minor).

Note: If the plugin's major API version does not match QMM's major API version, the plugin will not load and an error will appear in the console.


Top

QMM_PIFV_MINOR
This macro contains the minor QMM plugin API version number. This should be assigned to the pifv_minor field of g_plugininfo.
The current QMM plugin API version (both major and minor) can be found at the top of this document on the right (in the form major:minor).

Note: If the plugin's minor API version is greater than QMM's minor API version, the plugin will not load and an error will appear in the console. If the plugin's is less than QMM's, the plugin will load, but a warning will appear in console.


Top

QMM_RETURN(result, return)
This macro sets the plugin result flag (g_result) to the given result value, and will also return from the function with the given return value.
The result value should be a pluginres_t enumeration constant.

Top


QMM_SET_RESULT(result)
This macro sets the plugin result flag (g_result) to the given result value.
The result value should be a pluginres_t enumeration constant.

Top


QMM_RET_*(return)
This is actually 4 macros:

  • QMM_RET_ERROR(return)
  • QMM_RET_IGNORED(return)
  • QMM_RET_OVERRIDE(return)
  • QMM_RET_SUPERCEDE(return)
Each one sets the plugin result flag (g_result) to the corresponding pluginres_t enumeration constant, and also returns from the function with the given return value.

Top

GETPTR(pointer,type)
This macro converts the given QVM-based pointer into a real pointer and casts it to the given type.

gentity_t* entity = /* ... */;
gclient_t* client = GETPTR(entity->client, gclient_t*);

Top

SETPTR(pointer,type)
This macro converts the given real pointer into a QVM-based pointer and casts to the given type.

gentity_t* entity = /* ... */;
entity->classname = SETPTR("someclass", char*);

Top
 
QMM was written by Kevin Masterson (CyberMind)
   <kevinm -AT- planetquake -DOT- com>
   <cybermind -AT- users -DOT- sourceforge -DOT- net>
QMM is released under the GPL

Copyright 2005 Kevin Masterson, all rights reserved.