An interface isn't anything fancy. Check this out, this is the file you would distribute:
IMyInterface.h
Code:
#define MYINTERFACE_VERSION "MYINTERFACE001" // Increment the version number any time you a) add a function or b) remove a function. If you neglect to do this, the virtual table will not match.
class IMyInterface
{
public:
// I forget if you need constructor/destructor, consider this my warning that you might need this:
// virtual ~IMyInterface() = 0;
virtual void FunctionA() = 0; // The "= 0" means the function is purely virtual. It MUST be overriden. Don't worry, this is shown later.
virtual int FunctionB(int Param1, int Param2) = 0;
virtual bool FunctionC() = 0;
};
Now in your plugin, you have to define the interface's true functionality.
MyInterface.h
Code:
class CMyInterface : public IMyInterface
{
public:
CInterface() {}
~CInterface() {}
void FunctionA()
{
// Do something fancy.
}
int FunctionB(int P1, int P2)
{
return P1 + P2; // Just an example to show return value.
}
bool FunctionC()
{
// Do something fancy.
return true; // or false, :P
}
};
extern CMyInterface g_MyInterface;
You're also going to need to put this in a CPP file:
Code:
CMyInteface g_MyInterface;
Then you need to implement the QueryInterface, I think it is an optional member for the metamod plugin class:
Code:
void *MyPlugin::QueryInterface(const char *version_string)
{
if(FStrEq(version_string, MYINTERFACE_VERSION))
{
return (void*)g_MyInterface;
}
return (void*)0;
}
The MetaFactory function actually calls every QueryInterface and uses the non-null result.
Something like this for any plugin that tries to use MyInterface...
Code:
#include "IMyInterface.h"
...
IMyInterface *theInterface = (IMyInterface*)MetaFactory(MYINTERFACE_VERSION);
if(theInterface)
{
theInterface->FunctionA();
int result 1 = theInterface->FunctionB(1, 2);
bool result2 = theInterface->FunctionC();
}
else
{
Msg("Failed to find interface!\n");
}
Good luck.
__________________