PDA

View Full Version : Being version independent


devicenull
11-16-2005, 19:06
CreateInterfaceFn* findValidInterface(CreateInterfaceFn fac,const char * inter,unsigned int offset) {
if (fac==NULL || inter==NULL || offset ==0) return NULL;
CreateInterfaceFn *temp;

temp = (CreateInterfaceFn*)fac(inter,NULL);
if (!temp) {
int sLenName=strlen(inter);
char intName[256], newVer[256];
memcpy(intName,inter,(sLenName>256?256:sLenName));
unsigned int cVersion;
cVersion = intName[sLenName-1]+(intName[sLenName-2]*10)+(intName[sLenName-3]*100);
cVersion = atoi(&intName[sLenName-3]);
intName[sLenName-3] = 0;
for (cVersion=cVersion+offset;(cVersion>cVersion-offset && cVersion>0);cVersion--) {
_snprintf(newVer,256,"%s%03d",intName,cVersion);
temp = (CreateInterfaceFn *)fac(newVer,NULL);
if (temp) break;
}
}
return temp;
}

You use this as so.
To replace
m_ServerDll = (IServerGameDLL *)((ismm->serverFactory())(INTERFACEVERSION_SERVERGAMED LL, NULL));

You would use
m_ServerDll = (IServerGameDLL *)findValidInterface(ismm->serverFactory(),INTERFACEVERSION_SERVERGAMEDL L,2);

In that way, as long as the interface available is either 2 above or below the one it was compiled against, you will get a valid interface pointer. It's still possible to get null's, if for example the interface was totally removed.

BAILOPAN
11-17-2005, 01:48
Perhaps it would be best to have some sort of table of version compatibilities so you knew what was available or not.

I know it sounds like work but it'd be neat to have like interfaces.xml which you could parse and the user could modify, to adapt to a game.

devicenull
11-17-2005, 14:45
It would be but, its a lot more code :P
This is the simplest thing to do at the moment, requiring no user action.