2004-10-15 00:35:53 +00:00
|
|
|
//contains generic plugin code for dll/qvm
|
|
|
|
//it's this one or the engine...
|
|
|
|
#include "plugin.h"
|
2019-09-04 07:59:40 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
2016-07-12 00:40:13 +00:00
|
|
|
|
2004-10-15 00:35:53 +00:00
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
plugcorefuncs_t *plugfuncs;
|
|
|
|
plugcmdfuncs_t *cmdfuncs;
|
|
|
|
plugcvarfuncs_t *cvarfuncs;
|
|
|
|
//plugclientfuncs_t *clientfuncs;
|
2007-10-05 10:50:13 +00:00
|
|
|
|
2015-06-29 23:46:31 +00:00
|
|
|
|
2004-10-15 00:35:53 +00:00
|
|
|
|
2005-12-15 18:52:03 +00:00
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
/* An implementation of some 'standard' functions */
|
|
|
|
void Q_strlncpy(char *d, const char *s, int sizeofd, int lenofs)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
sizeofd--;
|
|
|
|
if (sizeofd < 0)
|
|
|
|
return; //this could be an error
|
2004-10-15 00:35:53 +00:00
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
for (i=0; lenofs-- > 0; i++)
|
|
|
|
{
|
|
|
|
if (i == sizeofd)
|
|
|
|
break;
|
|
|
|
*d++ = *s++;
|
|
|
|
}
|
|
|
|
*d='\0';
|
|
|
|
}
|
|
|
|
void Q_strlcpy(char *d, const char *s, int n)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
n--;
|
|
|
|
if (n < 0)
|
|
|
|
return; //this could be an error
|
2005-11-27 01:12:16 +00:00
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
for (i=0; *s; i++)
|
|
|
|
{
|
|
|
|
if (i == n)
|
|
|
|
break;
|
|
|
|
*d++ = *s++;
|
|
|
|
}
|
|
|
|
*d='\0';
|
|
|
|
}
|
|
|
|
void Q_strlcat(char *d, const char *s, int n)
|
|
|
|
{
|
|
|
|
if (n)
|
|
|
|
{
|
|
|
|
int dlen = strlen(d);
|
|
|
|
int slen = strlen(s)+1;
|
|
|
|
if (slen > (n-1)-dlen)
|
|
|
|
slen = (n-1)-dlen;
|
|
|
|
memcpy(d+dlen, s, slen);
|
|
|
|
d[n - 1] = 0;
|
|
|
|
}
|
|
|
|
}
|
2004-10-15 00:35:53 +00:00
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
char *Plug_Info_ValueForKey (const char *s, const char *key, char *out, size_t outsize)
|
|
|
|
{
|
|
|
|
int isvalue = 0;
|
|
|
|
const char *start;
|
|
|
|
char *oout = out;
|
|
|
|
*out = 0;
|
|
|
|
if (*s != '\\')
|
|
|
|
return out; //gah, get lost with your corrupt infostrings.
|
|
|
|
|
|
|
|
start = ++s;
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
while(s[0] == '\\' && s[1] == '\\')
|
|
|
|
s+=2;
|
|
|
|
if (s[0] != '\\' && *s)
|
|
|
|
{
|
|
|
|
s++;
|
|
|
|
continue;
|
|
|
|
}
|
2004-10-15 00:35:53 +00:00
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
//okay, it terminates here
|
|
|
|
isvalue = !isvalue;
|
|
|
|
if (isvalue)
|
|
|
|
{
|
|
|
|
if (strlen(key) == (size_t)(s - start) && !strncmp(start, key, s - start))
|
|
|
|
{
|
|
|
|
s++;
|
|
|
|
while (outsize --> 1)
|
|
|
|
{
|
|
|
|
if (s[0] == '\\' && s[1] == '\\')
|
|
|
|
s++;
|
|
|
|
else if (s[0] == '\\' || !s[0])
|
|
|
|
break;
|
|
|
|
*out++ = *s++;
|
|
|
|
}
|
|
|
|
*out++ = 0;
|
|
|
|
return oout;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*s)
|
|
|
|
start = ++s;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return oout;
|
|
|
|
}
|
2005-11-30 00:48:29 +00:00
|
|
|
|
2019-12-17 17:41:12 +00:00
|
|
|
#if defined(_MSC_VER) && _MSC_VER < 1900
|
2019-09-04 07:59:40 +00:00
|
|
|
int Q_vsnprintf(char *buffer, size_t maxlen, const char *format, va_list argptr)
|
|
|
|
{
|
|
|
|
int r = _vsnprintf (buffer, maxlen-1, format, argptr);
|
|
|
|
buffer[maxlen-1] = 0; //make sure its null terminated
|
|
|
|
if (r < 0) //work around dodgy return value. we can't use this to check required length but can check for truncation
|
|
|
|
r = maxlen;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
int Q_snprintf(char *buffer, size_t maxlen, const char *format, ...)
|
|
|
|
{
|
|
|
|
int p;
|
|
|
|
va_list argptr;
|
2005-07-20 11:50:00 +00:00
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
va_start (argptr, format);
|
|
|
|
p = Q_vsnprintf (buffer, maxlen, format,argptr);
|
|
|
|
va_end (argptr);
|
2009-04-19 01:46:52 +00:00
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
return p;
|
|
|
|
}
|
2005-07-20 11:50:00 +00:00
|
|
|
#endif
|
|
|
|
|
2013-11-29 14:36:47 +00:00
|
|
|
char *va(const char *format, ...) //Identical in function to the one in Quake, though I can assure you that I wrote it...
|
2004-10-15 00:35:53 +00:00
|
|
|
{ //It's not exactly hard, just easy to use, so gets duplicated lots.
|
|
|
|
va_list argptr;
|
|
|
|
static char string[1024];
|
|
|
|
|
|
|
|
va_start (argptr, format);
|
2013-06-23 18:43:59 +00:00
|
|
|
Q_vsnprintf (string, sizeof(string), format,argptr);
|
2004-10-15 00:35:53 +00:00
|
|
|
va_end (argptr);
|
|
|
|
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
2019-09-04 23:39:39 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
// don't use these functions in MSVC8
|
|
|
|
#if (_MSC_VER < 1400)
|
|
|
|
int QDECL linuxlike_snprintf(char *buffer, int size, const char *format, ...)
|
|
|
|
{
|
|
|
|
#undef _vsnprintf
|
|
|
|
int ret;
|
|
|
|
va_list argptr;
|
|
|
|
|
|
|
|
if (size <= 0)
|
|
|
|
return 0;
|
|
|
|
size--;
|
|
|
|
|
|
|
|
va_start (argptr, format);
|
|
|
|
ret = _vsnprintf (buffer,size, format,argptr);
|
|
|
|
va_end (argptr);
|
|
|
|
|
|
|
|
buffer[size] = '\0';
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
int QDECL linuxlike_vsnprintf(char *buffer, int size, const char *format, va_list argptr)
|
|
|
|
{
|
|
|
|
#undef _vsnprintf
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (size <= 0)
|
|
|
|
return 0;
|
|
|
|
size--;
|
|
|
|
|
|
|
|
ret = _vsnprintf (buffer,size, format,argptr);
|
|
|
|
|
|
|
|
buffer[size] = '\0';
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2019-12-17 17:41:12 +00:00
|
|
|
#elif (_MSC_VER < 1900)
|
2019-09-04 23:39:39 +00:00
|
|
|
int VARGS linuxlike_snprintf_vc8(char *buffer, int size, const char *format, ...)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
va_list argptr;
|
|
|
|
|
|
|
|
va_start (argptr, format);
|
|
|
|
ret = vsnprintf_s (buffer,size, _TRUNCATE, format,argptr);
|
|
|
|
va_end (argptr);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2012-10-08 05:29:52 +00:00
|
|
|
void Con_Printf(const char *format, ...)
|
2004-10-15 00:35:53 +00:00
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
static char string[1024];
|
|
|
|
|
|
|
|
va_start (argptr, format);
|
2013-06-23 18:43:59 +00:00
|
|
|
Q_vsnprintf (string, sizeof(string), format,argptr);
|
2004-10-15 00:35:53 +00:00
|
|
|
va_end (argptr);
|
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
plugfuncs->Print(string);
|
2004-10-15 00:35:53 +00:00
|
|
|
}
|
2012-11-27 03:23:19 +00:00
|
|
|
void Con_DPrintf(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
static char string[1024];
|
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
if (!cvarfuncs->GetFloat("developer"))
|
2012-11-27 03:23:19 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
va_start (argptr, format);
|
2013-06-23 18:43:59 +00:00
|
|
|
Q_vsnprintf (string, sizeof(string), format,argptr);
|
2012-11-27 03:23:19 +00:00
|
|
|
va_end (argptr);
|
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
plugfuncs->Print(string);
|
2012-11-27 03:23:19 +00:00
|
|
|
}
|
2012-10-08 05:29:52 +00:00
|
|
|
void Sys_Errorf(const char *format, ...)
|
2004-10-15 00:35:53 +00:00
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
static char string[1024];
|
|
|
|
|
|
|
|
va_start (argptr, format);
|
2013-06-23 18:43:59 +00:00
|
|
|
Q_vsnprintf (string, sizeof(string), format,argptr);
|
2004-10-15 00:35:53 +00:00
|
|
|
va_end (argptr);
|
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
plugfuncs->Error(string);
|
2004-10-15 00:35:53 +00:00
|
|
|
}
|
|
|
|
|
2019-10-01 22:32:06 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
#endif
|
2019-09-04 07:59:40 +00:00
|
|
|
qboolean NATIVEEXPORT FTEPlug_Init(plugcorefuncs_t *corefuncs)
|
2005-05-17 22:05:45 +00:00
|
|
|
{
|
2019-09-04 07:59:40 +00:00
|
|
|
plugfuncs = corefuncs;
|
2019-10-01 22:32:06 +00:00
|
|
|
cmdfuncs = (plugcmdfuncs_t*)plugfuncs->GetEngineInterface(plugcmdfuncs_name, sizeof(*cmdfuncs));
|
|
|
|
cvarfuncs = (plugcvarfuncs_t*)plugfuncs->GetEngineInterface(plugcvarfuncs_name, sizeof(*cvarfuncs));
|
2021-07-19 22:47:29 +00:00
|
|
|
if (!plugfuncs || !cmdfuncs || !cvarfuncs)
|
|
|
|
return false; //erk
|
2004-10-15 00:35:53 +00:00
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
return Plug_Init();
|
2004-10-15 00:35:53 +00:00
|
|
|
}
|
|
|
|
|