2022-03-08 05:31:34 +00:00
|
|
|
#include "q3common.h"
|
2005-09-09 23:40:55 +00:00
|
|
|
#ifdef VM_UI
|
2008-12-23 02:55:20 +00:00
|
|
|
#include "clq3defs.h"
|
2004-08-23 00:15:46 +00:00
|
|
|
#include "ui_public.h"
|
|
|
|
#include "cl_master.h"
|
2006-02-11 14:51:36 +00:00
|
|
|
#include "shader.h"
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
static int keycatcher;
|
2005-09-08 22:52:46 +00:00
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
#include "botlib.h"
|
|
|
|
void SV_InitBotLib(void);
|
|
|
|
extern botlib_export_t *botlib;
|
|
|
|
qboolean CG_GetLimboString(int index, char *outbuf);
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
#define TT_STRING 1 // string
|
|
|
|
#define TT_LITERAL 2 // literal
|
|
|
|
#define TT_NUMBER 3 // number
|
|
|
|
#define TT_NAME 4 // name
|
|
|
|
#define TT_PUNCTUATION 5 // punctuation
|
|
|
|
|
|
|
|
#define SCRIPT_MAXDEPTH 64
|
|
|
|
#define SCRIPT_DEFINELENGTH 256
|
|
|
|
typedef struct {
|
|
|
|
char *filestack[SCRIPT_MAXDEPTH];
|
|
|
|
char *originalfilestack[SCRIPT_MAXDEPTH];
|
2006-03-12 05:21:15 +00:00
|
|
|
char *lastreadptr;
|
|
|
|
int lastreaddepth;
|
2005-08-26 22:56:51 +00:00
|
|
|
char filename[MAX_QPATH][SCRIPT_MAXDEPTH];
|
|
|
|
int stackdepth;
|
|
|
|
|
|
|
|
char *defines;
|
|
|
|
int numdefines;
|
|
|
|
} script_t;
|
2009-11-04 21:16:50 +00:00
|
|
|
static script_t *scripts;
|
|
|
|
static int maxscripts;
|
2022-03-08 05:31:34 +00:00
|
|
|
static float ui_size[2]; //to track when it needs to be restarted (the api has no video mode changed event)
|
2019-09-04 07:59:40 +00:00
|
|
|
static menu_t uimenu;
|
|
|
|
|
|
|
|
void Q3_SetKeyCatcher(int newcatcher)
|
|
|
|
{
|
|
|
|
int delta = newcatcher^keycatcher;
|
|
|
|
keycatcher = newcatcher;
|
|
|
|
if (delta & 2)
|
|
|
|
{
|
|
|
|
uimenu.isopaque = false; //no surprises.
|
|
|
|
if (newcatcher&2)
|
2022-03-08 05:31:34 +00:00
|
|
|
inputfuncs->Menu_Push(&uimenu, false);
|
2019-09-04 07:59:40 +00:00
|
|
|
else
|
2022-03-08 05:31:34 +00:00
|
|
|
inputfuncs->Menu_Unlink(&uimenu, false);
|
2019-09-04 07:59:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
int Q3_GetKeyCatcher(void)
|
|
|
|
{
|
|
|
|
return keycatcher;
|
|
|
|
}
|
2006-03-12 05:21:15 +00:00
|
|
|
#define Q3SCRIPTPUNCTUATION "(,{})(\':;=!><&|+-\""
|
|
|
|
void StripCSyntax (char *s)
|
|
|
|
{
|
|
|
|
while(*s)
|
|
|
|
{
|
|
|
|
if (*s == '\\')
|
|
|
|
{
|
|
|
|
memmove(s, s+1, strlen(s+1)+1);
|
|
|
|
switch (*s)
|
|
|
|
{
|
|
|
|
case 'r':
|
|
|
|
*s = '\r';
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
*s = '\n';
|
|
|
|
break;
|
|
|
|
case '\\':
|
|
|
|
*s = '\\';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*s = '?';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|
2006-02-12 00:01:42 +00:00
|
|
|
int Script_Read(int handle, struct pc_token_s *token)
|
2005-08-26 22:56:51 +00:00
|
|
|
{
|
2006-03-12 05:21:15 +00:00
|
|
|
char *s;
|
|
|
|
char readstring[8192];
|
2005-08-26 22:56:51 +00:00
|
|
|
int i;
|
|
|
|
script_t *sc = scripts+handle-1;
|
2022-03-08 05:31:34 +00:00
|
|
|
char thetoken[1024];
|
|
|
|
com_tokentype_t tokentype;
|
2005-08-26 22:56:51 +00:00
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
if (!sc->stackdepth)
|
2006-03-12 05:21:15 +00:00
|
|
|
{
|
|
|
|
memset(token, 0, sizeof(*token));
|
2005-08-26 22:56:51 +00:00
|
|
|
return 0;
|
2006-03-12 05:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s = sc->filestack[sc->stackdepth-1];
|
|
|
|
sc->lastreadptr = s;
|
|
|
|
sc->lastreaddepth = sc->stackdepth;
|
2005-08-26 22:56:51 +00:00
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
s = (char *)cmdfuncs->ParsePunctuation(s, Q3SCRIPTPUNCTUATION, thetoken, sizeof(thetoken), &tokentype);
|
|
|
|
Q_strncpyz(readstring, thetoken, sizeof(readstring));
|
|
|
|
if (tokentype == TTP_STRING)
|
2006-03-12 05:21:15 +00:00
|
|
|
{
|
|
|
|
while(s)
|
|
|
|
{
|
|
|
|
while (*s > '\0' && *s <= ' ')
|
|
|
|
s++;
|
|
|
|
if (*s == '/' && s[1] == '/')
|
|
|
|
{
|
|
|
|
while(*s && *s != '\n')
|
|
|
|
s++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
while (*s > '\0' && *s <= ' ')
|
|
|
|
s++;
|
|
|
|
if (*s == '\"')
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
s = (char*)cmdfuncs->ParsePunctuation(s, Q3SCRIPTPUNCTUATION, thetoken, sizeof(thetoken), &tokentype);
|
|
|
|
Q_strncatz(readstring, thetoken, sizeof(readstring));
|
2006-03-12 05:21:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sc->filestack[sc->stackdepth-1] = s;
|
2022-03-08 05:31:34 +00:00
|
|
|
if (tokentype == TTP_LINEENDING)
|
2019-07-02 04:12:20 +00:00
|
|
|
continue; //apparently we shouldn't stop on linebreaks
|
2005-08-26 22:56:51 +00:00
|
|
|
|
2006-03-12 05:21:15 +00:00
|
|
|
if (!strcmp(readstring, "#include"))
|
2005-08-26 22:56:51 +00:00
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
sc->filestack[sc->stackdepth-1] = (char *)cmdfuncs->ParsePunctuation(sc->filestack[sc->stackdepth-1], Q3SCRIPTPUNCTUATION, thetoken, sizeof(thetoken), &tokentype);
|
2005-08-26 22:56:51 +00:00
|
|
|
|
|
|
|
if (sc->stackdepth == SCRIPT_MAXDEPTH) //just don't enter it
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (sc->originalfilestack[sc->stackdepth])
|
2022-03-08 05:31:34 +00:00
|
|
|
plugfuncs->Free(sc->originalfilestack[sc->stackdepth]);
|
|
|
|
sc->filestack[sc->stackdepth] = sc->originalfilestack[sc->stackdepth] = fsfuncs->LoadFile(thetoken, NULL);
|
|
|
|
Q_strncpyz(sc->filename[sc->stackdepth], thetoken, MAX_QPATH);
|
2005-08-26 22:56:51 +00:00
|
|
|
sc->stackdepth++;
|
|
|
|
continue;
|
|
|
|
}
|
2006-03-12 05:21:15 +00:00
|
|
|
if (!strcmp(readstring, "#define"))
|
2005-08-26 22:56:51 +00:00
|
|
|
{
|
|
|
|
sc->numdefines++;
|
2022-03-08 05:31:34 +00:00
|
|
|
sc->defines = plugfuncs->Realloc(sc->defines, sc->numdefines*SCRIPT_DEFINELENGTH*2);
|
|
|
|
sc->filestack[sc->stackdepth-1] = (char *)cmdfuncs->ParsePunctuation(sc->filestack[sc->stackdepth-1], Q3SCRIPTPUNCTUATION, thetoken, sizeof(thetoken), &tokentype);
|
|
|
|
Q_strncpyz(sc->defines+SCRIPT_DEFINELENGTH*2*(sc->numdefines-1), thetoken, SCRIPT_DEFINELENGTH);
|
|
|
|
sc->filestack[sc->stackdepth-1] = (char *)cmdfuncs->ParsePunctuation(sc->filestack[sc->stackdepth-1], Q3SCRIPTPUNCTUATION, thetoken, sizeof(thetoken), &tokentype);
|
|
|
|
Q_strncpyz(sc->defines+SCRIPT_DEFINELENGTH*2*(sc->numdefines-1)+SCRIPT_DEFINELENGTH, thetoken, SCRIPT_DEFINELENGTH);
|
2005-08-26 22:56:51 +00:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2022-03-08 05:31:34 +00:00
|
|
|
if (!*readstring && tokentype != TTP_STRING)
|
2005-08-26 22:56:51 +00:00
|
|
|
{
|
|
|
|
if (sc->stackdepth==0)
|
2006-03-12 05:21:15 +00:00
|
|
|
{
|
|
|
|
memset(token, 0, sizeof(*token));
|
2005-08-26 22:56:51 +00:00
|
|
|
return 0;
|
2006-03-12 05:21:15 +00:00
|
|
|
}
|
2005-08-26 22:56:51 +00:00
|
|
|
|
|
|
|
sc->stackdepth--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-03-08 05:31:34 +00:00
|
|
|
if (tokentype == TTP_STRING)
|
2005-08-26 22:56:51 +00:00
|
|
|
{
|
2006-03-12 05:21:15 +00:00
|
|
|
i = sc->numdefines;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < sc->numdefines; i++)
|
2005-08-26 22:56:51 +00:00
|
|
|
{
|
2006-03-12 05:21:15 +00:00
|
|
|
if (!strcmp(readstring, sc->defines+SCRIPT_DEFINELENGTH*2*i))
|
|
|
|
{
|
|
|
|
Q_strncpyz(token->string, sc->defines+SCRIPT_DEFINELENGTH*2*i+SCRIPT_DEFINELENGTH, sizeof(token->string));
|
|
|
|
break;
|
|
|
|
}
|
2005-08-26 22:56:51 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-12 05:21:15 +00:00
|
|
|
if (i == sc->numdefines) //otherwise
|
|
|
|
Q_strncpyz(token->string, readstring, sizeof(token->string));
|
|
|
|
|
|
|
|
StripCSyntax(token->string);
|
|
|
|
|
2020-03-07 09:00:40 +00:00
|
|
|
if (token->string[0] == '0' && (token->string[1] == 'x'||token->string[1] == 'X'))
|
2005-08-26 22:56:51 +00:00
|
|
|
{
|
2020-03-07 09:00:40 +00:00
|
|
|
token->intvalue = strtoul(token->string, NULL, 16);
|
|
|
|
token->floatvalue = token->intvalue;
|
2005-08-26 22:56:51 +00:00
|
|
|
token->type = TT_NUMBER;
|
2020-03-07 09:00:40 +00:00
|
|
|
token->subtype = 0x100;//TT_HEX;
|
2005-08-26 22:56:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-07 09:00:40 +00:00
|
|
|
token->intvalue = atoi(token->string);
|
|
|
|
token->floatvalue = atof(token->string);
|
|
|
|
if (token->floatvalue || *token->string == '0' || *token->string == '.')
|
2005-08-26 22:56:51 +00:00
|
|
|
{
|
2020-03-07 09:00:40 +00:00
|
|
|
token->type = TT_NUMBER;
|
|
|
|
token->subtype = 0;
|
2005-08-26 22:56:51 +00:00
|
|
|
}
|
2022-03-08 05:31:34 +00:00
|
|
|
else if (tokentype == TTP_STRING)
|
2005-08-26 22:56:51 +00:00
|
|
|
{
|
2020-03-07 09:00:40 +00:00
|
|
|
token->type = TT_STRING;
|
2005-08-26 22:56:51 +00:00
|
|
|
token->subtype = strlen(token->string);
|
|
|
|
}
|
2020-03-07 09:00:40 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (token->string[1] == '\0')
|
|
|
|
{
|
|
|
|
token->type = TT_PUNCTUATION;
|
|
|
|
token->subtype = token->string[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
token->type = TT_NAME;
|
|
|
|
token->subtype = strlen(token->string);
|
|
|
|
}
|
|
|
|
}
|
2005-08-26 22:56:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Con_Printf("Found %s (%i, %i)\n", token->string, token->type, token->subtype);
|
2022-03-08 05:31:34 +00:00
|
|
|
return tokentype != TTP_EOF;
|
2005-08-26 22:56:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Script_LoadFile(char *filename)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
script_t *sc;
|
|
|
|
for (i = 0; i < maxscripts; i++)
|
|
|
|
if (!scripts[i].stackdepth)
|
|
|
|
break;
|
|
|
|
if (i == maxscripts)
|
|
|
|
{
|
|
|
|
maxscripts++;
|
2022-03-08 05:31:34 +00:00
|
|
|
scripts = plugfuncs->Realloc(scripts, sizeof(script_t)*maxscripts);
|
2005-08-26 22:56:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sc = scripts+i;
|
|
|
|
memset(sc, 0, sizeof(*sc));
|
2022-03-08 05:31:34 +00:00
|
|
|
sc->filestack[0] = sc->originalfilestack[0] = fsfuncs->LoadFile(filename, NULL);
|
2006-03-12 05:21:15 +00:00
|
|
|
Q_strncpyz(sc->filename[sc->stackdepth], filename, MAX_QPATH);
|
2005-08-26 22:56:51 +00:00
|
|
|
sc->stackdepth = 1;
|
|
|
|
|
|
|
|
return i+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Script_Free(int handle)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
script_t *sc = scripts+handle-1;
|
|
|
|
if (sc->defines)
|
2022-03-08 05:31:34 +00:00
|
|
|
plugfuncs->Free(sc->defines);
|
2005-08-26 22:56:51 +00:00
|
|
|
|
|
|
|
for (i = 0; i < sc->stackdepth; i++)
|
2022-03-08 05:31:34 +00:00
|
|
|
plugfuncs->Free(sc->originalfilestack[i]);
|
2006-03-12 05:21:15 +00:00
|
|
|
|
|
|
|
sc->stackdepth = 0;
|
2005-08-26 22:56:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Script_Get_File_And_Line(int handle, char *filename, int *line)
|
|
|
|
{
|
|
|
|
script_t *sc = scripts+handle-1;
|
|
|
|
char *src;
|
|
|
|
char *start;
|
|
|
|
|
2006-03-12 05:21:15 +00:00
|
|
|
if (!sc->lastreaddepth)
|
|
|
|
{
|
|
|
|
*line = 0;
|
|
|
|
Q_strncpyz(filename, sc->filename[0], MAX_QPATH);
|
2005-08-26 22:56:51 +00:00
|
|
|
return;
|
2006-03-12 05:21:15 +00:00
|
|
|
}
|
2005-08-26 22:56:51 +00:00
|
|
|
*line = 1;
|
|
|
|
|
2006-03-12 05:21:15 +00:00
|
|
|
src = sc->lastreadptr;
|
|
|
|
start = sc->originalfilestack[sc->lastreaddepth-1];
|
2005-08-26 22:56:51 +00:00
|
|
|
|
|
|
|
while(start < src)
|
|
|
|
{
|
|
|
|
if (*start == '\n')
|
|
|
|
(*line)++;
|
|
|
|
start++;
|
|
|
|
}
|
|
|
|
|
2006-03-12 05:21:15 +00:00
|
|
|
Q_strncpyz(filename, sc->filename[sc->lastreaddepth-1], MAX_QPATH);
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
static vm_t *uivm;
|
|
|
|
|
2014-12-23 15:26:42 +00:00
|
|
|
#define MAX_PINGREQUESTS 32
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
static struct
|
2019-02-01 08:29:14 +00:00
|
|
|
{
|
|
|
|
unsigned int startms;
|
|
|
|
netadr_t adr;
|
2021-10-22 22:27:58 +00:00
|
|
|
char adrstring[64];
|
|
|
|
const char *broker;
|
2019-02-01 08:29:14 +00:00
|
|
|
} ui_pings[MAX_PINGREQUESTS];
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2005-08-07 13:18:43 +00:00
|
|
|
#define UITAGNUM 2452
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
struct q3refEntity_s {
|
2005-08-26 22:56:51 +00:00
|
|
|
refEntityType_t reType;
|
2004-08-23 00:15:46 +00:00
|
|
|
int renderfx;
|
|
|
|
|
2007-09-17 20:35:39 +00:00
|
|
|
int hModel; // opaque type outside refresh
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
// most recent data
|
|
|
|
vec3_t lightingOrigin; // so multi-part models can be lit identically (RF_LIGHTING_ORIGIN)
|
|
|
|
float shadowPlane; // projection shadows go here, stencils go slightly lower
|
|
|
|
|
|
|
|
vec3_t axis[3]; // rotation vectors
|
|
|
|
qboolean nonNormalizedAxes; // axis are not normalized, i.e. they have scale
|
|
|
|
float origin[3]; // also used as MODEL_BEAM's "from"
|
|
|
|
int frame; // also used as MODEL_BEAM's diameter
|
|
|
|
|
|
|
|
// previous data for frame interpolation
|
|
|
|
float oldorigin[3]; // also used as MODEL_BEAM's "to"
|
|
|
|
int oldframe;
|
|
|
|
float backlerp; // 0.0 = current, 1.0 = old
|
|
|
|
|
|
|
|
// texturing
|
|
|
|
int skinNum; // inline skin index
|
2022-03-08 05:31:34 +00:00
|
|
|
skinid_t customSkin; // NULL for default skin
|
|
|
|
int customShader; // use one image for the entire thing
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
// misc
|
|
|
|
qbyte shaderRGBA[4]; // colors used by rgbgen entity shaders
|
|
|
|
float shaderTexCoord[2]; // texture coordinates used by tcMod entity modifiers
|
|
|
|
float shaderTime; // subtracted from refdef time to control effect start times
|
|
|
|
|
|
|
|
// extra sprite information
|
|
|
|
float radius;
|
|
|
|
float rotation;
|
2009-11-04 21:16:50 +00:00
|
|
|
};
|
2004-12-24 08:45:56 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
struct q3polyvert_s
|
|
|
|
{
|
|
|
|
vec3_t org;
|
|
|
|
vec2_t tcoord;
|
|
|
|
qbyte colours[4];
|
|
|
|
};
|
2004-12-24 08:45:56 +00:00
|
|
|
|
2008-11-09 22:29:28 +00:00
|
|
|
#define Q3RF_MINLIGHT 1
|
2004-12-24 08:45:56 +00:00
|
|
|
#define Q3RF_THIRD_PERSON 2 // don't draw through eyes, only mirrors (player bodies, chat sprites)
|
|
|
|
#define Q3RF_FIRST_PERSON 4 // only draw through eyes (view weapon, damage blood blob)
|
|
|
|
#define Q3RF_DEPTHHACK 8 // for view weapon Z crunching
|
2008-11-09 22:29:28 +00:00
|
|
|
#define Q3RF_NOSHADOW 64
|
|
|
|
#define Q3RF_LIGHTING_ORIGIN 128
|
2007-09-17 20:35:39 +00:00
|
|
|
|
2020-03-07 09:00:40 +00:00
|
|
|
#define MAX_VMQ3_CACHED_STRINGS 2048
|
2022-03-08 05:31:34 +00:00
|
|
|
static char *stringcache[MAX_VMQ3_CACHED_STRINGS];
|
2007-09-17 20:35:39 +00:00
|
|
|
|
2013-06-23 02:17:02 +00:00
|
|
|
void VMQ3_FlushStringHandles(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_VMQ3_CACHED_STRINGS; i++)
|
|
|
|
{
|
|
|
|
if (stringcache[i])
|
|
|
|
{
|
|
|
|
Z_Free(stringcache[i]);
|
|
|
|
stringcache[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-17 20:35:39 +00:00
|
|
|
char *VMQ3_StringFromHandle(int handle)
|
|
|
|
{
|
|
|
|
if (!handle)
|
|
|
|
return "";
|
|
|
|
handle--;
|
|
|
|
if ((unsigned) handle >= MAX_VMQ3_CACHED_STRINGS)
|
|
|
|
return "";
|
|
|
|
return stringcache[handle];
|
|
|
|
}
|
|
|
|
|
|
|
|
int VMQ3_StringToHandle(char *str)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_VMQ3_CACHED_STRINGS; i++)
|
|
|
|
{
|
|
|
|
if (!stringcache[i])
|
|
|
|
break;
|
|
|
|
if (!strcmp(str, stringcache[i]))
|
|
|
|
return i+1;
|
|
|
|
}
|
|
|
|
if (i == MAX_VMQ3_CACHED_STRINGS)
|
|
|
|
{
|
|
|
|
Con_Printf("Q3VM out of string handle space\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
stringcache[i] = Z_Malloc(strlen(str)+1);
|
|
|
|
strcpy(stringcache[i], str);
|
|
|
|
return i+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define VM_TOSTRCACHE(a) VMQ3_StringToHandle(VM_POINTER(a))
|
|
|
|
#define VM_FROMSTRCACHE(a) VMQ3_StringFromHandle(a)
|
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
void VQ3_AddEntity(const q3refEntity_t *q3)
|
|
|
|
{
|
|
|
|
entity_t ent;
|
|
|
|
memset(&ent, 0, sizeof(ent));
|
2022-03-08 05:31:34 +00:00
|
|
|
ent.model = scenefuncs->ModelFromId(q3->hModel);
|
2008-12-23 02:55:20 +00:00
|
|
|
ent.framestate.g[FS_REG].frame[0] = q3->frame;
|
|
|
|
ent.framestate.g[FS_REG].frame[1] = q3->oldframe;
|
2004-12-21 04:29:14 +00:00
|
|
|
memcpy(ent.axis, q3->axis, sizeof(q3->axis));
|
2015-02-02 08:01:53 +00:00
|
|
|
ent.framestate.g[FS_REG].lerpweight[1] = q3->backlerp;
|
|
|
|
ent.framestate.g[FS_REG].lerpweight[0] = 1 - ent.framestate.g[FS_REG].lerpweight[1];
|
2014-02-11 17:51:29 +00:00
|
|
|
if (q3->reType == RT_SPRITE)
|
|
|
|
{
|
|
|
|
ent.scale = q3->radius;
|
|
|
|
ent.rotation = q3->rotation;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ent.scale = 1;
|
2005-08-26 22:56:51 +00:00
|
|
|
ent.rtype = q3->reType;
|
2005-08-07 13:18:43 +00:00
|
|
|
|
2014-03-30 08:55:06 +00:00
|
|
|
ent.customskin = q3->customSkin;
|
|
|
|
ent.skinnum = q3->skinNum;
|
2006-02-27 00:42:25 +00:00
|
|
|
|
|
|
|
ent.shaderRGBAf[0] = q3->shaderRGBA[0]/255.0f;
|
|
|
|
ent.shaderRGBAf[1] = q3->shaderRGBA[1]/255.0f;
|
|
|
|
ent.shaderRGBAf[2] = q3->shaderRGBA[2]/255.0f;
|
|
|
|
ent.shaderRGBAf[3] = q3->shaderRGBA[3]/255.0f;
|
2008-11-09 22:29:28 +00:00
|
|
|
|
2018-01-22 19:18:04 +00:00
|
|
|
/*don't set force-translucent etc, the shader is meant to already be correct*/
|
2008-11-09 22:29:28 +00:00
|
|
|
// if (ent.shaderRGBAf[3] <= 0)
|
|
|
|
// return;
|
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
ent.forcedshader = drawfuncs->ShaderFromId(q3->customShader);
|
2005-02-09 19:32:09 +00:00
|
|
|
ent.shaderTime = q3->shaderTime;
|
2020-12-14 00:35:06 +00:00
|
|
|
|
2020-12-25 03:07:07 +00:00
|
|
|
if (q3->renderfx & Q3RF_FIRST_PERSON)
|
|
|
|
ent.flags |= RF_FIRSTPERSON;
|
2004-12-24 08:45:56 +00:00
|
|
|
if (q3->renderfx & Q3RF_DEPTHHACK)
|
2014-03-31 17:06:41 +00:00
|
|
|
ent.flags |= RF_DEPTHHACK;
|
2004-12-24 08:45:56 +00:00
|
|
|
if (q3->renderfx & Q3RF_THIRD_PERSON)
|
2014-03-31 17:06:41 +00:00
|
|
|
ent.flags |= RF_EXTERNALMODEL;
|
2009-11-04 21:16:50 +00:00
|
|
|
if (q3->renderfx & Q3RF_NOSHADOW)
|
|
|
|
ent.flags |= RF_NOSHADOW;
|
|
|
|
|
2014-03-30 08:55:06 +00:00
|
|
|
ent.topcolour = TOP_DEFAULT;
|
|
|
|
ent.bottomcolour = BOTTOM_DEFAULT;
|
|
|
|
ent.playerindex = -1;
|
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
|
|
|
|
if ((q3->renderfx & Q3RF_LIGHTING_ORIGIN) && ent.model)
|
|
|
|
{
|
|
|
|
VectorCopy(q3->lightingOrigin, ent.origin);
|
|
|
|
scenefuncs->CalcModelLighting(&ent, ent.model);
|
|
|
|
}
|
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
VectorCopy(q3->origin, ent.origin);
|
2005-08-26 22:56:51 +00:00
|
|
|
VectorCopy(q3->oldorigin, ent.oldorigin);
|
2022-03-08 05:31:34 +00:00
|
|
|
|
|
|
|
scenefuncs->AddEntity(&ent);
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
void VQ3_AddPolys(shader_t *s, int numverts, q3polyvert_t *verts, size_t polycount)
|
2009-11-04 21:16:50 +00:00
|
|
|
{
|
|
|
|
unsigned int v;
|
2022-03-08 05:31:34 +00:00
|
|
|
|
|
|
|
for (; polycount-->0; verts += numverts)
|
2009-11-04 21:16:50 +00:00
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
vecV_t *vertcoord;
|
|
|
|
vec2_t *texcoord;
|
|
|
|
vec4_t *colour;
|
|
|
|
index_t *indexes;
|
|
|
|
index_t indexbias = scenefuncs->AddPolydata(s, BEF_NODLIGHT|BEF_NOSHADOWS, numverts, (numverts-2)*3, &vertcoord, &texcoord, &colour, &indexes);
|
|
|
|
|
|
|
|
//and splurge the data out.
|
|
|
|
for (v = 0; v < numverts; v++)
|
2009-11-04 21:16:50 +00:00
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
VectorCopy(verts[v].org, vertcoord[v]);
|
|
|
|
Vector2Copy(verts[v].tcoord, texcoord[v]);
|
|
|
|
Vector4Scale(verts[v].colours, (1/255.0f), colour[v]);
|
|
|
|
}
|
|
|
|
for (v = 2; v < numverts; v++)
|
|
|
|
{
|
|
|
|
*indexes++ = indexbias + 0;
|
|
|
|
*indexes++ = indexbias + (v-1);
|
|
|
|
*indexes++ = indexbias + v;
|
2009-11-04 21:16:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-24 08:45:56 +00:00
|
|
|
int VM_LerpTag(void *out, model_t *model, int f1, int f2, float l2, char *tagname)
|
|
|
|
{
|
|
|
|
int tagnum;
|
|
|
|
float *ang;
|
|
|
|
float *org;
|
|
|
|
|
2005-06-14 04:52:10 +00:00
|
|
|
float tr[12];
|
|
|
|
qboolean found;
|
2009-01-15 04:58:12 +00:00
|
|
|
framestate_t fstate;
|
2004-12-24 08:45:56 +00:00
|
|
|
|
|
|
|
org = (float*)out;
|
|
|
|
ang = ((float*)out+3);
|
|
|
|
|
2009-01-15 04:58:12 +00:00
|
|
|
memset(&fstate, 0, sizeof(fstate));
|
|
|
|
fstate.g[FS_REG].frame[0] = f1;
|
|
|
|
fstate.g[FS_REG].frame[1] = f2;
|
2015-02-02 08:01:53 +00:00
|
|
|
fstate.g[FS_REG].lerpweight[0] = 1 - l2;
|
|
|
|
fstate.g[FS_REG].lerpweight[1] = l2;
|
2009-01-15 04:58:12 +00:00
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
tagnum = scenefuncs->TagNumForName(model, tagname, 0);
|
|
|
|
found = scenefuncs->GetTag(model, tagnum, &fstate, tr);
|
2004-12-24 08:45:56 +00:00
|
|
|
|
2013-06-23 02:17:02 +00:00
|
|
|
if (found && tagnum)
|
2005-06-14 04:52:10 +00:00
|
|
|
{
|
|
|
|
ang[0] = tr[0];
|
|
|
|
ang[1] = tr[1];
|
|
|
|
ang[2] = tr[2];
|
|
|
|
org[0] = tr[3];
|
2005-08-26 22:56:51 +00:00
|
|
|
|
2005-06-14 04:52:10 +00:00
|
|
|
ang[3] = tr[4];
|
|
|
|
ang[4] = tr[5];
|
|
|
|
ang[5] = tr[6];
|
|
|
|
org[1] = tr[7];
|
2005-08-26 22:56:51 +00:00
|
|
|
|
2005-06-14 04:52:10 +00:00
|
|
|
ang[6] = tr[8];
|
|
|
|
ang[7] = tr[9];
|
|
|
|
ang[8] = tr[10];
|
|
|
|
org[2] = tr[11];
|
2004-12-24 08:45:56 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
org[0] = 0;
|
|
|
|
org[1] = 0;
|
|
|
|
org[2] = 0;
|
|
|
|
|
|
|
|
ang[0] = 1;
|
|
|
|
ang[1] = 0;
|
|
|
|
ang[2] = 0;
|
|
|
|
|
|
|
|
ang[3] = 0;
|
|
|
|
ang[4] = 1;
|
|
|
|
ang[5] = 0;
|
|
|
|
|
|
|
|
ang[6] = 0;
|
|
|
|
ang[7] = 0;
|
|
|
|
ang[8] = 1;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
#define MAX_RENDER_STRINGS 8
|
|
|
|
#define MAX_RENDER_STRING_LENGTH 32
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
struct q3refdef_s {
|
2004-08-23 00:15:46 +00:00
|
|
|
int x, y, width, height;
|
|
|
|
float fov_x, fov_y;
|
|
|
|
vec3_t vieworg;
|
|
|
|
vec3_t viewaxis[3]; // transformation matrix
|
|
|
|
|
|
|
|
// time in milliseconds for shader effects and other time dependent rendering issues
|
|
|
|
int time;
|
|
|
|
|
|
|
|
int rdflags; // RDF_NOWORLDMODEL, etc
|
|
|
|
|
|
|
|
// 1 bits will prevent the associated area from rendering at all
|
|
|
|
qbyte areamask[MAX_MAP_AREA_BYTES];
|
|
|
|
|
|
|
|
// text messages for deform text shaders
|
|
|
|
char text[MAX_RENDER_STRINGS][MAX_RENDER_STRING_LENGTH];
|
2009-11-04 21:16:50 +00:00
|
|
|
};
|
2022-03-08 05:31:34 +00:00
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
void VQ3_RenderView(const q3refdef_t *ref)
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
plugrefdef_t scene;
|
2018-01-22 19:18:04 +00:00
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
scene.flags = 0;
|
2017-11-30 17:59:11 +00:00
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
scene.rect.x = ref->x;
|
|
|
|
scene.rect.y = ref->y;
|
|
|
|
scene.rect.w = ref->width;
|
|
|
|
scene.rect.h = ref->height;
|
|
|
|
scene.fov[0] = scene.fov_viewmodel[0] = ref->fov_x;
|
|
|
|
scene.fov[1] = scene.fov_viewmodel[1] = ref->fov_y;
|
|
|
|
VectorCopy(ref->viewaxis[0], scene.viewaxisorg[0]);
|
|
|
|
VectorCopy(ref->viewaxis[1], scene.viewaxisorg[1]);
|
|
|
|
VectorCopy(ref->viewaxis[2], scene.viewaxisorg[2]);
|
|
|
|
VectorCopy(ref->vieworg, scene.viewaxisorg[3]);
|
|
|
|
scene.time = ref->time/1000.0f;
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2022-03-08 05:32:03 +00:00
|
|
|
if (ref->rdflags & 1/*Q3RDF_NOWORLDMODEL*/)
|
2022-03-08 05:31:34 +00:00
|
|
|
scene.flags |= RDF_NOWORLDMODEL;
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
scenefuncs->RenderScene(&scene, sizeof(ref->areamask), ref->areamask);
|
|
|
|
}
|
2005-08-26 22:56:51 +00:00
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
static void *Little4Block(void *out, qbyte *in, size_t count)
|
|
|
|
{
|
|
|
|
while (count-->0)
|
|
|
|
{
|
|
|
|
*(unsigned int*)out = (in[0]<<0)|(in[1]<<8)|(in[2]<<16)|(in[3]<<24);
|
|
|
|
out = (qbyte*)out + 4;
|
|
|
|
in+=4;
|
|
|
|
}
|
|
|
|
return in;
|
|
|
|
}
|
2005-08-26 22:56:51 +00:00
|
|
|
void UI_RegisterFont(char *fontName, int pointSize, fontInfo_t *font)
|
|
|
|
{
|
2005-12-17 16:52:22 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
char *c;
|
|
|
|
int *i;
|
|
|
|
float *f;
|
|
|
|
} in;
|
2005-08-26 22:56:51 +00:00
|
|
|
int i;
|
|
|
|
char name[MAX_QPATH];
|
2022-03-08 05:31:34 +00:00
|
|
|
void *filedata;
|
2014-10-05 20:04:11 +00:00
|
|
|
size_t sz;
|
2005-08-26 22:56:51 +00:00
|
|
|
|
2006-03-06 01:41:09 +00:00
|
|
|
snprintf(name, sizeof(name), "fonts/fontImage_%i.dat",pointSize);
|
2005-08-26 22:56:51 +00:00
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
in.c = filedata = fsfuncs->LoadFile(name, &sz);
|
2014-10-05 20:04:11 +00:00
|
|
|
if (sz == sizeof(fontInfo_t))
|
2005-08-26 22:56:51 +00:00
|
|
|
{
|
|
|
|
for(i=0; i<GLYPHS_PER_FONT; i++)
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
in.c = Little4Block(&font->glyphs[i].height, in.c, (int*)font->glyphs[i].shaderName-&font->glyphs[i].height);
|
2005-12-17 16:52:22 +00:00
|
|
|
memcpy(font->glyphs[i].shaderName, in.i, 32);
|
|
|
|
in.c += 32;
|
2005-08-26 22:56:51 +00:00
|
|
|
}
|
2022-03-08 05:31:34 +00:00
|
|
|
in.c = Little4Block(&font->glyphScale, in.c, 1);
|
2020-03-07 09:00:40 +00:00
|
|
|
memcpy(font->name, in.i, sizeof(font->name));
|
2005-08-26 22:56:51 +00:00
|
|
|
|
|
|
|
// Com_Memcpy(font, faceData, sizeof(fontInfo_t));
|
|
|
|
Q_strncpyz(font->name, name, sizeof(font->name));
|
|
|
|
for (i = GLYPH_START; i < GLYPH_END; i++)
|
2022-03-08 05:31:34 +00:00
|
|
|
font->glyphs[i].glyph = drawfuncs->LoadImage(font->glyphs[i].shaderName);
|
2005-08-26 22:56:51 +00:00
|
|
|
}
|
2022-03-08 05:31:34 +00:00
|
|
|
plugfuncs->Free(filedata);
|
2005-08-26 22:56:51 +00:00
|
|
|
}
|
|
|
|
|
2020-03-07 09:00:40 +00:00
|
|
|
static struct
|
|
|
|
{
|
|
|
|
int shaderhandle;
|
|
|
|
int x, y, w, h;
|
|
|
|
qboolean loop;
|
|
|
|
} uicinematics[16];
|
|
|
|
int UI_Cin_Play(const char *name, int x, int y, int w, int h, unsigned int flags)
|
|
|
|
{
|
|
|
|
int idx;
|
2022-03-08 05:31:34 +00:00
|
|
|
qhandle_t mediashader;
|
2022-03-08 05:32:15 +00:00
|
|
|
cin_t *cin;
|
2020-03-07 09:00:40 +00:00
|
|
|
for (idx = 0; ; idx++)
|
|
|
|
{
|
|
|
|
if (idx == countof(uicinematics))
|
|
|
|
return -1; //out of handles
|
|
|
|
if (uicinematics[idx].shaderhandle)
|
|
|
|
continue; //slot in use
|
|
|
|
break; //this slot is usable
|
|
|
|
}
|
|
|
|
|
2022-03-08 05:32:15 +00:00
|
|
|
mediashader = drawfuncs->LoadImageShader(name, va(
|
|
|
|
"{\n"
|
|
|
|
"program default2d\n"
|
|
|
|
"{\n"
|
|
|
|
"videomap \"video/%s\"\n"
|
|
|
|
"blendfunc gl_one gl_one_minus_src_alpha\n"
|
|
|
|
"}\n"
|
|
|
|
"}\n", name));
|
2020-03-07 09:00:40 +00:00
|
|
|
if (!mediashader)
|
|
|
|
return -1; //wtf?
|
2022-03-08 05:32:15 +00:00
|
|
|
cin = drawfuncs->media.GetCinematic(drawfuncs->ShaderFromId(mediashader));
|
2020-03-07 09:00:40 +00:00
|
|
|
if (cin)
|
2022-03-08 05:32:15 +00:00
|
|
|
drawfuncs->media.SetState(cin, CINSTATE_PLAY);
|
|
|
|
else
|
2020-03-07 09:00:40 +00:00
|
|
|
return -1; //FAIL!
|
|
|
|
|
|
|
|
uicinematics[idx].x = x;
|
|
|
|
uicinematics[idx].y = y;
|
|
|
|
uicinematics[idx].w = w;
|
|
|
|
uicinematics[idx].h = h;
|
|
|
|
uicinematics[idx].loop = !!(flags&1);
|
2022-03-08 05:31:34 +00:00
|
|
|
uicinematics[idx].shaderhandle = mediashader;
|
2020-03-07 09:00:40 +00:00
|
|
|
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
int UI_Cin_Stop(int idx)
|
|
|
|
{
|
|
|
|
if (idx >= 0 && idx < countof(uicinematics))
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
drawfuncs->UnloadImage(uicinematics[idx].shaderhandle);
|
2020-03-07 09:00:40 +00:00
|
|
|
uicinematics[idx].shaderhandle = 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int UI_Cin_Run(int idx)
|
|
|
|
{
|
|
|
|
enum {
|
|
|
|
FMV_IDLE,
|
|
|
|
FMV_PLAY, // play
|
|
|
|
FMV_EOF, // all other conditions, i.e. stop/EOF/abort
|
|
|
|
FMV_ID_BLT,
|
|
|
|
FMV_ID_IDLE,
|
|
|
|
FMV_LOOPED,
|
|
|
|
FMV_ID_WAIT
|
|
|
|
};
|
|
|
|
int ret = FMV_IDLE;
|
|
|
|
|
|
|
|
|
|
|
|
if (idx >= 0 && idx < countof(uicinematics))
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
shader_t *shader = drawfuncs->ShaderFromId(uicinematics[idx].shaderhandle);
|
2022-03-08 05:32:15 +00:00
|
|
|
cin_t *cin = drawfuncs->media.GetCinematic(shader);
|
2020-03-07 09:00:40 +00:00
|
|
|
if (cin)
|
|
|
|
{
|
2022-03-08 05:32:15 +00:00
|
|
|
switch((cinstates_t)drawfuncs->media.GetState(cin))
|
2020-03-07 09:00:40 +00:00
|
|
|
{
|
|
|
|
case CINSTATE_INVALID: ret = FMV_IDLE; break;
|
|
|
|
case CINSTATE_PLAY: ret = FMV_PLAY; break;
|
|
|
|
case CINSTATE_LOOP: ret = FMV_PLAY; break;
|
|
|
|
case CINSTATE_PAUSE: ret = FMV_PLAY; break;
|
|
|
|
case CINSTATE_ENDED:
|
2022-03-08 05:32:15 +00:00
|
|
|
drawfuncs->media.SetState(cin, CINSTATE_FLUSHED);
|
2020-03-07 09:00:40 +00:00
|
|
|
ret = FMV_EOF;
|
|
|
|
break;
|
|
|
|
case CINSTATE_FLUSHED:
|
|
|
|
//FIXME: roq decoder has no reset method!
|
2022-03-08 05:32:15 +00:00
|
|
|
drawfuncs->media.Reset(cin);
|
2020-03-07 09:00:40 +00:00
|
|
|
ret = FMV_LOOPED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
int UI_Cin_Draw(int idx)
|
|
|
|
{
|
|
|
|
if (idx >= 0 && idx < countof(uicinematics))
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
unsigned int size[2];
|
|
|
|
qhandle_t shader = uicinematics[idx].shaderhandle;
|
2020-03-07 09:00:40 +00:00
|
|
|
float x = uicinematics[idx].x;
|
|
|
|
float y = uicinematics[idx].y;
|
|
|
|
float w = uicinematics[idx].w;
|
|
|
|
float h = uicinematics[idx].h;
|
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
drawfuncs->GetVideoSize(NULL, size);
|
|
|
|
|
2020-03-07 09:00:40 +00:00
|
|
|
//gah! q3 compat sucks!
|
2022-03-08 05:31:34 +00:00
|
|
|
x *= size[0]/640.0;
|
|
|
|
w *= size[0]/640.0;
|
|
|
|
y *= size[1]/480.0;
|
|
|
|
h *= size[1]/480.0;
|
2020-03-07 09:00:40 +00:00
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
drawfuncs->Image(x, y, w, h, 0, 0, 1, 1, shader);
|
2020-03-07 09:00:40 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int UI_Cin_SetExtents(int idx, int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
if (idx >= 0 && idx < countof(uicinematics))
|
|
|
|
{
|
|
|
|
uicinematics[idx].x = x;
|
|
|
|
uicinematics[idx].y = y;
|
|
|
|
uicinematics[idx].w = w;
|
|
|
|
uicinematics[idx].h = h;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
static const char *Cvar_FixQ3Name (const char *var_name)
|
2019-03-12 05:04:27 +00:00
|
|
|
{
|
|
|
|
struct {
|
|
|
|
const char *q3;
|
|
|
|
const char *fte;
|
|
|
|
} cvarremaps[] =
|
|
|
|
{
|
|
|
|
{"s_musicvolume", "bgmvolume"},
|
|
|
|
{"r_gamma", "gamma"},
|
|
|
|
{"s_sdlSpeed", "s_khz"},
|
|
|
|
{"r_fullscreen", "vid_fullscreen"},
|
|
|
|
{"r_picmip", "gl_picmip"},
|
|
|
|
{"r_textureMode", "gl_texturemode"},
|
|
|
|
{"r_lodBias", "d_lodbias"},
|
|
|
|
{"r_colorbits", "vid_bpp"},
|
|
|
|
{"r_dynamiclight", "r_dynamic"},
|
|
|
|
{"r_finish", "gl_finish"},
|
2022-03-08 05:31:34 +00:00
|
|
|
{"protocol", "com_protocolversion"},
|
2019-03-12 05:04:27 +00:00
|
|
|
// {"r_glDriver", NULL},
|
|
|
|
// {"r_depthbits", NULL},
|
|
|
|
// {"r_stencilbits", NULL},
|
|
|
|
// {"s_compression", NULL},
|
|
|
|
// {"r_texturebits", NULL},
|
|
|
|
// {"r_allowExtensions",NULL},
|
|
|
|
// {"s_useOpenAL", NULL},
|
|
|
|
// {"sv_running", NULL},
|
|
|
|
// {"sv_killserver", NULL},
|
|
|
|
// {"color1", NULL},
|
|
|
|
// {"in_joystick", NULL},
|
|
|
|
// {"joy_threshold", NULL},
|
|
|
|
// {"cl_freelook", NULL},
|
|
|
|
// {"color1", NULL},
|
|
|
|
// {"r_availableModes",NULL},
|
|
|
|
// {"r_mode", NULL},
|
|
|
|
};
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < countof(cvarremaps); i++)
|
|
|
|
{
|
|
|
|
if (!strcmp(cvarremaps[i].q3, var_name))
|
2022-03-08 05:31:34 +00:00
|
|
|
return cvarremaps[i].fte;
|
2019-03-12 05:04:27 +00:00
|
|
|
}
|
2022-03-08 05:31:34 +00:00
|
|
|
return var_name;
|
2019-03-12 05:04:27 +00:00
|
|
|
}
|
2005-08-26 22:56:51 +00:00
|
|
|
|
2020-07-14 00:48:56 +00:00
|
|
|
static void UI_SimulateTextEntry(void *cb, const char *utf8)
|
2020-03-07 09:00:40 +00:00
|
|
|
{
|
|
|
|
const char *line = utf8;
|
|
|
|
unsigned int unicode;
|
|
|
|
int err;
|
|
|
|
while(*line)
|
|
|
|
{
|
|
|
|
unicode = utf8_decode(&err, line, &line);
|
|
|
|
if (uivm)
|
2022-03-08 05:31:34 +00:00
|
|
|
vmfuncs->Call(uivm, UI_KEY_EVENT, unicode|1024, true);
|
2020-03-07 09:00:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
#define VALIDATEPOINTER(o,l) if ((quintptr_t)o + l >= mask || VM_POINTER(o) < offset) plugfuncs->EndGame("Call to ui trap %i passes invalid pointer\n", (int)fn); //out of bounds.
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2010-11-02 23:17:25 +00:00
|
|
|
static qintptr_t UI_SystemCalls(void *offset, quintptr_t mask, qintptr_t fn, const qintptr_t *arg)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2020-03-07 09:00:40 +00:00
|
|
|
static int overstrikemode;
|
2004-08-23 00:15:46 +00:00
|
|
|
int ret=0;
|
|
|
|
|
|
|
|
//Remember to range check pointers.
|
|
|
|
//The QVM must not be allowed to write to anything outside it's memory.
|
|
|
|
//This includes getting the exe to copy it for it.
|
|
|
|
|
|
|
|
//don't bother with reading, as this isn't a virus risk.
|
|
|
|
//could be a cheat risk, but hey.
|
|
|
|
|
|
|
|
//make sure that any called functions are also range checked.
|
|
|
|
//like reading from files copies names into alternate buffers, allowing stack screwups.
|
|
|
|
|
2005-09-08 22:52:46 +00:00
|
|
|
switch((uiImport_t)fn)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
case UI_CVAR_CREATE: Con_Printf("Q3UI: Not implemented system trap: %s\n", "UI_CVAR_CREATE"); return 0;
|
|
|
|
case UI_CVAR_INFOSTRINGBUFFER: Con_Printf("Q3UI: Not implemented system trap: %s\n", "UI_CVAR_INFOSTRINGBUFFER"); return 0;
|
|
|
|
case UI_R_ADDPOLYTOSCENE: Con_Printf("Q3UI: Not implemented system trap: %s\n", "UI_R_ADDPOLYTOSCENE"); return 0;
|
|
|
|
case UI_R_REMAP_SHADER: Con_Printf("Q3UI: Not implemented system trap: %s\n", "UI_R_REMAP_SHADER"); return 0;
|
|
|
|
case UI_UPDATESCREEN: Con_Printf("Q3UI: Not implemented system trap: %s\n", "UI_UPDATESCREEN"); return 0;
|
|
|
|
case UI_CM_LOADMODEL: Con_Printf("Q3UI: Not implemented system trap: %s\n", "UI_CM_LOADMODEL"); return 0;
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_ERROR:
|
2009-11-04 21:16:50 +00:00
|
|
|
Con_Printf("%s", (char*)VM_POINTER(arg[0]));
|
2022-03-08 05:31:34 +00:00
|
|
|
UI_Stop();
|
|
|
|
plugfuncs->EndGame("UI error");
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
case UI_PRINT:
|
2009-11-04 21:16:50 +00:00
|
|
|
Con_Printf("%s", (char*)VM_POINTER(arg[0]));
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_MILLISECONDS:
|
2022-03-08 05:31:34 +00:00
|
|
|
VM_LONG(ret) = plugfuncs->GetMilliseconds();
|
2005-08-26 22:56:51 +00:00
|
|
|
break;
|
|
|
|
|
2005-09-08 22:52:46 +00:00
|
|
|
case UI_ARGC:
|
2022-03-08 05:31:34 +00:00
|
|
|
VM_LONG(ret) = cmdfuncs->Argc();
|
2005-09-08 22:52:46 +00:00
|
|
|
break;
|
|
|
|
case UI_ARGV:
|
|
|
|
// VALIDATEPOINTER(arg[1], arg[2]);
|
2022-03-08 05:31:34 +00:00
|
|
|
cmdfuncs->Argv(VM_LONG(arg[0]), VM_POINTER(arg[1]), VM_LONG(arg[2]));
|
2005-09-08 22:52:46 +00:00
|
|
|
break;
|
|
|
|
/* case UI_ARGS:
|
|
|
|
VALIDATEPOINTER(arg[0], arg[1]);
|
|
|
|
Q_strncpyz(VM_POINTER(arg[0]), Cmd_Args(), VM_LONG(arg[1]));
|
|
|
|
break;
|
|
|
|
*/
|
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
case UI_CVAR_SET:
|
2022-03-08 05:31:34 +00:00
|
|
|
cvarfuncs->SetString(Cvar_FixQ3Name(VM_POINTER(arg[0])), VM_POINTER(arg[1]));
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_CVAR_VARIABLEVALUE:
|
2022-03-08 05:31:34 +00:00
|
|
|
VM_FLOAT(ret) = cvarfuncs->GetFloat(Cvar_FixQ3Name(VM_POINTER(arg[0])));
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_CVAR_VARIABLESTRINGBUFFER:
|
2022-03-08 05:31:34 +00:00
|
|
|
if (arg[1] + arg[2] >= mask || VM_POINTER(arg[1]) < offset)
|
|
|
|
VM_LONG(ret) = -2; //out of bounds.
|
|
|
|
cvarfuncs->GetString(Cvar_FixQ3Name(VM_POINTER(arg[0])), VM_POINTER(arg[1]), VM_LONG(arg[2]));
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_CVAR_SETVALUE:
|
2022-03-08 05:31:34 +00:00
|
|
|
cvarfuncs->SetFloat(Cvar_FixQ3Name(VM_POINTER(arg[0])), VM_FLOAT(arg[1]));
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UI_CVAR_RESET: //cvar reset
|
2022-03-08 05:31:34 +00:00
|
|
|
cvarfuncs->SetString(Cvar_FixQ3Name(VM_POINTER(arg[0])), NULL);
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_CMD_EXECUTETEXT:
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2011-01-29 21:01:40 +00:00
|
|
|
char *cmdtext = VM_POINTER(arg[1]);
|
2012-04-09 19:12:12 +00:00
|
|
|
#ifdef CL_MASTER
|
2011-01-29 21:01:40 +00:00
|
|
|
if (!strncmp(cmdtext, "ping ", 5))
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
char token[1024];
|
2011-01-29 21:01:40 +00:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_PINGREQUESTS; i++)
|
2021-10-22 22:27:58 +00:00
|
|
|
if (ui_pings[i].adr.type == NA_INVALID && ui_pings[i].adr.prot == NP_INVALID)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2020-02-11 18:06:10 +00:00
|
|
|
const char *p = NULL;
|
2022-03-08 05:31:34 +00:00
|
|
|
cmdfuncs->ParseToken(cmdtext + 5, token, sizeof(token), NULL);
|
|
|
|
ui_pings[i].startms = plugfuncs->GetMilliseconds();
|
|
|
|
Q_strncpyz(ui_pings[i].adrstring, token, sizeof(ui_pings[i].adrstring));
|
|
|
|
if (masterfuncs->StringToAdr(ui_pings[i].adrstring, 0, &ui_pings[i].adr, 1, &p))
|
2011-01-29 21:01:40 +00:00
|
|
|
{
|
2021-10-22 22:27:58 +00:00
|
|
|
#ifdef HAVE_PACKET
|
2022-03-08 05:31:34 +00:00
|
|
|
serverinfo_t *info = masterfuncs->InfoForServer(&ui_pings[i].adr, p);
|
2016-02-15 06:01:17 +00:00
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
info->special |= SS_KEEPINFO;
|
|
|
|
info->sends++;
|
2022-03-08 05:31:34 +00:00
|
|
|
masterfuncs->QueryServer(info);
|
2016-02-15 06:01:17 +00:00
|
|
|
}
|
2021-10-22 22:27:58 +00:00
|
|
|
#endif
|
2011-01-29 21:01:40 +00:00
|
|
|
}
|
2021-10-22 22:27:58 +00:00
|
|
|
ui_pings[i].broker = p;
|
2011-01-29 21:01:40 +00:00
|
|
|
break;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
2011-01-29 21:01:40 +00:00
|
|
|
}
|
2012-04-09 19:12:12 +00:00
|
|
|
else
|
|
|
|
#endif
|
2022-03-08 05:31:34 +00:00
|
|
|
cmdfuncs->AddText(cmdtext, false);
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_FS_FOPENFILE: //fopen
|
2004-08-23 00:15:46 +00:00
|
|
|
if ((int)arg[1] + 4 >= mask || VM_POINTER(arg[1]) < offset)
|
|
|
|
break; //out of bounds.
|
2007-09-02 19:55:17 +00:00
|
|
|
VM_LONG(ret) = VM_fopen(VM_POINTER(arg[0]), VM_POINTER(arg[1]), VM_LONG(arg[2]), 0);
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UI_FS_READ: //fread
|
|
|
|
if ((int)arg[0] + VM_LONG(arg[1]) >= mask || VM_POINTER(arg[0]) < offset)
|
|
|
|
break; //out of bounds.
|
|
|
|
|
2007-09-02 19:55:17 +00:00
|
|
|
VM_LONG(ret) = VM_FRead(VM_POINTER(arg[0]), VM_LONG(arg[1]), VM_LONG(arg[2]), 0);
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
case UI_FS_WRITE: //fwrite
|
|
|
|
break;
|
2022-03-08 05:31:34 +00:00
|
|
|
case UI_FS_SEEK:
|
|
|
|
return VM_FSeek(arg[0], arg[1], arg[2], 0);
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_FS_FCLOSEFILE: //fclose
|
2007-09-02 19:55:17 +00:00
|
|
|
VM_fclose(VM_LONG(arg[0]), 0);
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_FS_GETFILELIST: //fs listing
|
2004-08-23 00:15:46 +00:00
|
|
|
if ((int)arg[2] + arg[3] >= mask || VM_POINTER(arg[2]) < offset)
|
|
|
|
break; //out of bounds.
|
2007-09-02 19:55:17 +00:00
|
|
|
return VM_GetFileList(VM_POINTER(arg[0]), VM_POINTER(arg[1]), VM_POINTER(arg[2]), VM_LONG(arg[3]));
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_R_REGISTERMODEL: //precache model
|
|
|
|
{
|
|
|
|
char *name = VM_POINTER(arg[0]);
|
2022-03-08 05:31:34 +00:00
|
|
|
model_t *mod = scenefuncs->LoadModel(name, MLV_SILENTSYNC);
|
2014-10-05 20:04:11 +00:00
|
|
|
if (!mod || mod->loadstate != MLS_LOADED || mod->type == mod_dummy)
|
2014-03-30 08:55:06 +00:00
|
|
|
VM_LONG(ret) = 0;
|
|
|
|
else
|
2022-03-08 05:31:34 +00:00
|
|
|
VM_LONG(ret) = scenefuncs->ModelToId(mod);
|
2006-03-12 05:21:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UI_R_MODELBOUNDS:
|
|
|
|
{
|
|
|
|
VALIDATEPOINTER(arg[1], sizeof(vec3_t));
|
|
|
|
VALIDATEPOINTER(arg[2], sizeof(vec3_t));
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
model_t *mod = scenefuncs->ModelFromId(arg[0]);
|
2006-03-12 05:21:15 +00:00
|
|
|
if (mod)
|
|
|
|
{
|
|
|
|
VectorCopy(mod->mins, ((float*)VM_POINTER(arg[1])));
|
|
|
|
VectorCopy(mod->maxs, ((float*)VM_POINTER(arg[2])));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VectorClear(((float*)VM_POINTER(arg[1])));
|
|
|
|
VectorClear(((float*)VM_POINTER(arg[2])));
|
|
|
|
}
|
|
|
|
}
|
2005-08-26 22:56:51 +00:00
|
|
|
}
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_R_REGISTERSKIN:
|
2022-03-08 05:31:34 +00:00
|
|
|
VM_LONG(ret) = scenefuncs->RegisterSkinFile(VM_POINTER(arg[0]));
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_R_REGISTERFONT: //register font
|
|
|
|
UI_RegisterFont(VM_POINTER(arg[0]), arg[1], VM_POINTER(arg[2]));
|
|
|
|
break;
|
|
|
|
case UI_R_REGISTERSHADERNOMIP:
|
2007-05-25 22:16:29 +00:00
|
|
|
if (!*(char*)VM_POINTER(arg[0]))
|
2004-08-23 00:15:46 +00:00
|
|
|
VM_LONG(ret) = 0;
|
2010-05-01 22:47:47 +00:00
|
|
|
else
|
2022-03-08 05:31:34 +00:00
|
|
|
VM_LONG(ret) = drawfuncs->LoadImage(VM_POINTER(arg[0]));
|
|
|
|
if (!drawfuncs->ImageSize(VM_LONG(ret), NULL, NULL))
|
|
|
|
VM_LONG(ret) = 0; //not found...
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_R_CLEARSCENE: //clear scene
|
2022-03-08 05:31:34 +00:00
|
|
|
scenefuncs->ClearScene();
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_R_ADDREFENTITYTOSCENE: //add ent to scene
|
2004-08-23 00:15:46 +00:00
|
|
|
VQ3_AddEntity(VM_POINTER(arg[0]));
|
|
|
|
break;
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_R_ADDLIGHTTOSCENE: //add light to scene.
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_R_RENDERSCENE: //render scene
|
2004-08-23 00:15:46 +00:00
|
|
|
VQ3_RenderView(VM_POINTER(arg[0]));
|
|
|
|
break;
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_R_SETCOLOR: //setcolour float*
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2004-12-21 04:29:14 +00:00
|
|
|
float *fl =VM_POINTER(arg[0]);
|
|
|
|
if (!fl)
|
2022-03-08 05:31:34 +00:00
|
|
|
drawfuncs->Colour4f(1, 1, 1, 1);
|
2004-08-23 00:15:46 +00:00
|
|
|
else
|
2022-03-08 05:31:34 +00:00
|
|
|
drawfuncs->Colour4f(fl[0], fl[1], fl[2], fl[3]);
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_R_DRAWSTRETCHPIC:
|
2022-03-08 05:31:34 +00:00
|
|
|
drawfuncs->Image(VM_FLOAT(arg[0]), VM_FLOAT(arg[1]), VM_FLOAT(arg[2]), VM_FLOAT(arg[3]), VM_FLOAT(arg[4]), VM_FLOAT(arg[5]), VM_FLOAT(arg[6]), VM_FLOAT(arg[7]), VM_LONG(arg[8]));
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_CM_LERPTAG: //Lerp tag...
|
2022-03-08 05:31:34 +00:00
|
|
|
VALIDATEPOINTER(arg[0], sizeof(float)*12);
|
|
|
|
VM_LONG(ret) = VM_LerpTag(VM_POINTER(arg[0]), scenefuncs->ModelFromId(arg[1]), VM_LONG(arg[2]), VM_LONG(arg[3]), VM_FLOAT(arg[4]), VM_POINTER(arg[5]));
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_S_REGISTERSOUND:
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
sfx_t *sfx;
|
2022-03-08 05:31:34 +00:00
|
|
|
sfx = audiofuncs->PrecacheSound(va("%s", (char*)VM_POINTER(arg[0])));
|
2004-08-23 00:15:46 +00:00
|
|
|
if (sfx)
|
2007-09-17 20:35:39 +00:00
|
|
|
VM_LONG(ret) = VM_TOSTRCACHE(arg[0]); //return handle is the parameter they just gave
|
2004-08-23 00:15:46 +00:00
|
|
|
else
|
|
|
|
VM_LONG(ret) = -1;
|
|
|
|
}
|
|
|
|
break;
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_S_STARTLOCALSOUND:
|
|
|
|
if (VM_LONG(arg[0]) != -1 && arg[0])
|
2022-03-08 05:31:34 +00:00
|
|
|
audiofuncs->LocalSound(VM_FROMSTRCACHE(arg[0]), CHAN_AUTO, 1.0); //now we can fix up the sound name
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
2020-03-07 09:00:40 +00:00
|
|
|
case UI_S_STARTBACKGROUNDTRACK:
|
2022-03-08 05:31:34 +00:00
|
|
|
audiofuncs->ChangeMusicTrack(VM_POINTER(arg[0]), VM_POINTER(arg[1]));
|
2020-03-07 09:00:40 +00:00
|
|
|
break;
|
|
|
|
case UI_S_STOPBACKGROUNDTRACK:
|
2022-03-08 05:31:34 +00:00
|
|
|
audiofuncs->ChangeMusicTrack(NULL, NULL);
|
2020-03-07 09:00:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
//q3 shares insert mode between its ui and console. whereas fte doesn't support it (FIXME: add to Key_EntryInsert).
|
|
|
|
case UI_KEY_SETOVERSTRIKEMODE:
|
|
|
|
overstrikemode = arg[0];
|
|
|
|
return 0;
|
2005-09-08 22:52:46 +00:00
|
|
|
case UI_KEY_GETOVERSTRIKEMODE:
|
2020-03-07 09:00:40 +00:00
|
|
|
return overstrikemode;
|
|
|
|
|
|
|
|
case UI_GETCLIPBOARDDATA:
|
|
|
|
if (VM_OOB(arg[0], VM_LONG(arg[1])))
|
|
|
|
break; //out of bounds.
|
|
|
|
//our clipboard doesn't allow us to simply query without blocking (would result in stalls on x11/wayland)
|
|
|
|
//so just return nothing - we can send the text as if it were regular text entry for a similar result.
|
|
|
|
Q_strncpyz(VM_POINTER(arg[0]), "", VM_LONG(arg[1]));
|
|
|
|
|
|
|
|
//but do we really want to let mods read the system clipboard? I suppose it SHOULD be okay if the UI was manually installed by the user.
|
|
|
|
//side note: q3's text entry logic is kinda flawed.
|
|
|
|
Sys_Clipboard_PasteText(CBT_CLIPBOARD, UI_SimulateTextEntry, NULL);
|
|
|
|
break;
|
2005-09-08 22:52:46 +00:00
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_KEY_KEYNUMTOSTRINGBUF:
|
2022-03-08 05:31:34 +00:00
|
|
|
if (VM_LONG(arg[0]) < 0 || VM_LONG(arg[0]) >= K_MAX || (int)arg[1] + VM_LONG(arg[2]) >= mask || VM_POINTER(arg[1]) < offset || VM_LONG(arg[2]) < 1)
|
2004-08-23 00:15:46 +00:00
|
|
|
break; //out of bounds.
|
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
Q_strncpyz(VM_POINTER(arg[1]), inputfuncs->GetKeyName(VM_LONG(arg[0]), 0), VM_LONG(arg[2]));
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_KEY_GETBINDINGBUF:
|
2022-03-08 05:31:34 +00:00
|
|
|
if (VM_LONG(arg[0]) < 0 || VM_LONG(arg[0]) >= K_MAX || (int)arg[1] + VM_LONG(arg[2]) >= mask || VM_POINTER(arg[1]) < offset || VM_LONG(arg[2]) < 1)
|
2004-08-23 00:15:46 +00:00
|
|
|
break; //out of bounds.
|
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
{
|
|
|
|
const char *binding = inputfuncs->GetKeyBind(0, VM_LONG(arg[0]), 0);
|
|
|
|
if (binding)
|
|
|
|
Q_strncpyz(VM_POINTER(arg[1]), binding, VM_LONG(arg[2]));
|
|
|
|
else
|
|
|
|
*(char *)VM_POINTER(arg[1]) = '\0';
|
|
|
|
}
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UI_KEY_SETBINDING:
|
2022-03-08 05:31:34 +00:00
|
|
|
inputfuncs->SetKeyBind(0, VM_LONG(arg[0]), 0, VM_POINTER(arg[1]));
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UI_KEY_ISDOWN:
|
2022-03-08 05:31:34 +00:00
|
|
|
VM_LONG(ret) = inputfuncs->IsKeyDown(VM_LONG(arg[0]));
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_KEY_CLEARSTATES:
|
2022-03-08 05:31:34 +00:00
|
|
|
inputfuncs->ClearKeyStates();
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_KEY_GETCATCHER:
|
2013-10-08 14:28:11 +00:00
|
|
|
if (Key_Dest_Has(kdm_console))
|
2005-08-26 22:56:51 +00:00
|
|
|
VM_LONG(ret) = keycatcher | 1;
|
|
|
|
else
|
|
|
|
VM_LONG(ret) = keycatcher;
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_KEY_SETCATCHER:
|
2019-09-04 07:59:40 +00:00
|
|
|
Q3_SetKeyCatcher(VM_LONG(arg[0]));
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_GETGLCONFIG: //get glconfig
|
2011-01-29 21:01:40 +00:00
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
q3glconfig_t *cfg;
|
|
|
|
float vsize[2] = {0,0};
|
|
|
|
if ((int)arg[0] + sizeof(q3glconfig_t) >= mask || VM_POINTER(arg[0]) < offset)
|
|
|
|
break; //out of bounds.
|
|
|
|
drawfuncs->GetVideoSize(vsize, NULL);
|
|
|
|
cfg = VM_POINTER(arg[0]);
|
|
|
|
|
|
|
|
//do any needed work
|
|
|
|
memset(cfg, 0, sizeof(*cfg));
|
|
|
|
|
|
|
|
Q_strncpyz(cfg->renderer_string, "", sizeof(cfg->renderer_string));
|
|
|
|
Q_strncpyz(cfg->vendor_string, "", sizeof(cfg->vendor_string));
|
|
|
|
Q_strncpyz(cfg->version_string, "", sizeof(cfg->version_string));
|
|
|
|
Q_strncpyz(cfg->extensions_string, "", sizeof(cfg->extensions_string));
|
|
|
|
|
|
|
|
cfg->colorBits = 32;
|
|
|
|
cfg->depthBits = 24;
|
|
|
|
cfg->stencilBits = 8;//sh_config.stencilbits;
|
|
|
|
cfg->textureCompression = true;//!!sh_config.texfmt[PTI_BC1_RGBA];
|
|
|
|
cfg->textureEnvAddAvailable = true;//sh_config.env_add;
|
|
|
|
|
|
|
|
//these are the only three that really matter.
|
|
|
|
cfg->vidWidth = vsize[0];
|
|
|
|
cfg->vidHeight = vsize[1];
|
|
|
|
cfg->windowAspect = vsize[0]/vsize[1];;
|
|
|
|
#if 0
|
2011-01-29 21:01:40 +00:00
|
|
|
char *cfg;
|
|
|
|
if ((int)arg[0] + 11332/*sizeof(glconfig_t)*/ >= mask || VM_POINTER(arg[0]) < offset)
|
|
|
|
break; //out of bounds.
|
|
|
|
cfg = VM_POINTER(arg[0]);
|
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
//do any needed work
|
|
|
|
memset(cfg, 0, 11304);
|
|
|
|
*(int *)(cfg+11304) = vsize[0];
|
|
|
|
*(int *)(cfg+11308) = vid.height;
|
|
|
|
*(float *)(cfg+11312) = (float)vsize[0]/vid.height;
|
|
|
|
memset(cfg+11316, 0, 11332-11316);
|
|
|
|
#endif
|
2011-01-29 21:01:40 +00:00
|
|
|
}
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_GETCLIENTSTATE: //get client state
|
2004-12-21 04:29:14 +00:00
|
|
|
//fixme: we need to fill in a structure.
|
2014-10-05 20:04:11 +00:00
|
|
|
// Con_Printf("ui_getclientstate\n");
|
|
|
|
VALIDATEPOINTER(arg[0], sizeof(uiClientState_t));
|
|
|
|
{
|
|
|
|
uiClientState_t *state = VM_POINTER(arg[0]);
|
|
|
|
state->connectPacketCount = 0;//clc.connectPacketCount;
|
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
switch(ccs.state)
|
2014-10-05 20:04:11 +00:00
|
|
|
{
|
|
|
|
case ca_disconnected:
|
|
|
|
if (CL_TryingToConnect())
|
|
|
|
state->connState = Q3CA_CONNECTING;
|
|
|
|
else
|
|
|
|
state->connState = Q3CA_DISCONNECTED;
|
|
|
|
break;
|
|
|
|
case ca_demostart:
|
|
|
|
state->connState = Q3CA_CONNECTING;
|
|
|
|
break;
|
|
|
|
case ca_connected:
|
|
|
|
state->connState = Q3CA_CONNECTED;
|
|
|
|
break;
|
|
|
|
case ca_onserver:
|
|
|
|
state->connState = Q3CA_PRIMED;
|
|
|
|
break;
|
|
|
|
case ca_active:
|
|
|
|
state->connState = Q3CA_ACTIVE;
|
|
|
|
break;
|
|
|
|
}
|
2022-03-08 05:31:34 +00:00
|
|
|
cvarfuncs->GetString("cl_servername", state->servername, sizeof(state->servername)); //error message from game server
|
|
|
|
Q_strncpyz(state->updateInfoString, "FTE!", sizeof(state->updateInfoString)); //warning/motd message from update server
|
|
|
|
cvarfuncs->GetString("com_errorMessage", state->messageString, sizeof(state->messageString)); //error message from game server
|
|
|
|
state->clientNum = ccs.playernum;
|
2014-10-05 20:04:11 +00:00
|
|
|
}
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_GETCONFIGSTRING:
|
2004-08-23 00:15:46 +00:00
|
|
|
if (arg[1] + VM_LONG(arg[2]) >= mask || VM_POINTER(arg[1]) < offset || VM_LONG(arg[2]) < 1)
|
|
|
|
{
|
|
|
|
VM_LONG(ret) = 0;
|
|
|
|
break; //out of bounds.
|
|
|
|
}
|
2005-08-26 23:55:09 +00:00
|
|
|
#ifdef VM_CG
|
2005-08-26 22:56:51 +00:00
|
|
|
Q_strncpyz(VM_POINTER(arg[1]), CG_GetConfigString(VM_LONG(arg[0])), VM_LONG(arg[2]));
|
2005-08-26 23:55:09 +00:00
|
|
|
#endif
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
2012-04-09 19:12:12 +00:00
|
|
|
#ifdef CL_MASTER
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_LAN_GETPINGQUEUECOUNT: //these four are master server polling.
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_PINGREQUESTS; i++)
|
2021-10-22 22:27:58 +00:00
|
|
|
if (ui_pings[i].adr.type != NA_INVALID || ui_pings[i].adr.prot != NP_INVALID)
|
2004-08-23 00:15:46 +00:00
|
|
|
VM_LONG(ret)++;
|
|
|
|
}
|
|
|
|
break;
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_LAN_CLEARPING: //clear ping
|
2004-08-23 00:15:46 +00:00
|
|
|
//void (int pingnum)
|
2014-12-23 15:26:42 +00:00
|
|
|
if (VM_LONG(arg[0])>= 0 && VM_LONG(arg[0]) < MAX_PINGREQUESTS)
|
2021-10-22 22:27:58 +00:00
|
|
|
ui_pings[VM_LONG(arg[0])].adr.type = NA_INVALID, ui_pings[VM_LONG(arg[0])].adr.prot = NP_INVALID;
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_LAN_GETPING:
|
2004-08-23 00:15:46 +00:00
|
|
|
//void (int pingnum, char *buffer, int buflen, int *ping)
|
|
|
|
if ((int)arg[1] + VM_LONG(arg[2]) >= mask || VM_POINTER(arg[1]) < offset)
|
|
|
|
break; //out of bounds.
|
|
|
|
if ((int)arg[3] + sizeof(int) >= mask || VM_POINTER(arg[3]) < offset)
|
|
|
|
break; //out of bounds.
|
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
masterfuncs->CheckPollSockets();
|
2014-12-23 15:26:42 +00:00
|
|
|
if (VM_LONG(arg[0])>= 0 && VM_LONG(arg[0]) < MAX_PINGREQUESTS)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2019-02-01 08:29:14 +00:00
|
|
|
int i = VM_LONG(arg[0]);
|
2004-08-23 00:15:46 +00:00
|
|
|
char *buf = VM_POINTER(arg[1]);
|
2019-02-01 08:29:14 +00:00
|
|
|
size_t bufsize = VM_LONG(arg[2]);
|
|
|
|
int *ping = VM_POINTER(arg[3]);
|
2021-10-22 22:27:58 +00:00
|
|
|
serverinfo_t *info;
|
|
|
|
if (ui_pings[i].adr.type != NA_INVALID || ui_pings[i].adr.prot != NP_INVALID)
|
2022-03-08 05:31:34 +00:00
|
|
|
info = masterfuncs->InfoForServer(&ui_pings[i].adr, ui_pings[i].broker);
|
2020-02-11 18:06:10 +00:00
|
|
|
else
|
2021-10-22 22:27:58 +00:00
|
|
|
info = NULL;
|
|
|
|
Q_strncpyz(buf, ui_pings[i].adrstring, bufsize);
|
2019-02-01 08:29:14 +00:00
|
|
|
|
2020-02-11 18:06:10 +00:00
|
|
|
if (info && /*(info->status & SRVSTATUS_ALIVE) &&*/ info->moreinfo)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2019-02-01 08:29:14 +00:00
|
|
|
VM_LONG(ret) = true;
|
2020-02-11 18:06:10 +00:00
|
|
|
*ping = (info->ping == PING_UNKNOWN)?1:info->ping;
|
2019-02-01 08:29:14 +00:00
|
|
|
break;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
2022-03-08 05:31:34 +00:00
|
|
|
i = plugfuncs->GetMilliseconds()-ui_pings[i].startms;
|
2019-02-01 08:29:14 +00:00
|
|
|
if (i < 999)
|
|
|
|
i = 0; //don't time out yet.
|
|
|
|
*ping = i;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_LAN_GETPINGINFO:
|
2019-02-01 08:29:14 +00:00
|
|
|
//void (int pingnum, char *buffer, int buflen)
|
2004-08-23 00:15:46 +00:00
|
|
|
if ((int)arg[1] + VM_LONG(arg[2]) >= mask || VM_POINTER(arg[1]) < offset)
|
|
|
|
break; //out of bounds.
|
|
|
|
if ((int)arg[3] + sizeof(int) >= mask || VM_POINTER(arg[3]) < offset)
|
|
|
|
break; //out of bounds.
|
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
masterfuncs->CheckPollSockets();
|
2014-12-23 15:26:42 +00:00
|
|
|
if (VM_LONG(arg[0])>= 0 && VM_LONG(arg[0]) < MAX_PINGREQUESTS)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2019-02-01 08:29:14 +00:00
|
|
|
int i = VM_LONG(arg[0]);
|
2004-08-23 00:15:46 +00:00
|
|
|
char *buf = VM_POINTER(arg[1]);
|
2019-02-01 08:29:14 +00:00
|
|
|
size_t bufsize = VM_LONG(arg[2]);
|
2004-08-23 00:15:46 +00:00
|
|
|
char *adr;
|
2022-03-08 05:31:34 +00:00
|
|
|
serverinfo_t *info = masterfuncs->InfoForServer(&ui_pings[i].adr, ui_pings[i].broker);
|
2021-10-22 22:27:58 +00:00
|
|
|
|
2020-02-11 18:06:10 +00:00
|
|
|
if (info && /*(info->status & SRVSTATUS_ALIVE) &&*/ info->moreinfo)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
adr = info->moreinfo->info;
|
|
|
|
if (!adr)
|
|
|
|
adr = "";
|
2019-02-01 08:29:14 +00:00
|
|
|
if (strlen(adr) < bufsize)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
strcpy(buf, adr);
|
2022-03-08 05:31:34 +00:00
|
|
|
worldfuncs->SetInfoKey(buf, "mapname", info->map, bufsize);
|
|
|
|
worldfuncs->SetInfoKey(buf, "hostname", info->name, bufsize);
|
|
|
|
worldfuncs->SetInfoKey(buf, "g_humanplayers", va("%i", info->numhumans), bufsize);
|
|
|
|
worldfuncs->SetInfoKey(buf, "sv_maxclients", va("%i", info->maxplayers), bufsize);
|
|
|
|
worldfuncs->SetInfoKey(buf, "clients", va("%i", info->players), bufsize);
|
2019-02-01 08:29:14 +00:00
|
|
|
if (info->adr.type == NA_IPV6 && info->adr.prot == NP_DGRAM)
|
2022-03-08 05:31:34 +00:00
|
|
|
worldfuncs->SetInfoKey(buf, "nettype", "2", bufsize);
|
2019-02-01 08:29:14 +00:00
|
|
|
else if (info->adr.type == NA_IP && info->adr.prot == NP_DGRAM)
|
2022-03-08 05:31:34 +00:00
|
|
|
worldfuncs->SetInfoKey(buf, "nettype", "1", bufsize);
|
2019-02-01 08:29:14 +00:00
|
|
|
else
|
2022-03-08 05:31:34 +00:00
|
|
|
worldfuncs->SetInfoKey(buf, "nettype", "", bufsize);
|
2004-08-23 00:15:46 +00:00
|
|
|
VM_LONG(ret) = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
strcpy(buf, "");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-03-07 09:00:40 +00:00
|
|
|
case UI_LAN_UPDATEVISIBLEPINGS:
|
2022-03-08 05:31:34 +00:00
|
|
|
return masterfuncs->QueryServers(); //return true while we're still going.
|
2020-03-07 09:00:40 +00:00
|
|
|
case UI_LAN_RESETPINGS:
|
|
|
|
return 0;
|
|
|
|
case UI_LAN_ADDSERVER:
|
|
|
|
return 0;
|
|
|
|
case UI_LAN_REMOVESERVER:
|
|
|
|
return 0;
|
|
|
|
case UI_LAN_SERVERSTATUS:
|
|
|
|
//*address, *status, statuslen
|
|
|
|
return 0;
|
|
|
|
case UI_LAN_COMPARESERVERS:
|
2005-08-26 22:56:51 +00:00
|
|
|
{
|
2020-03-07 09:00:40 +00:00
|
|
|
hostcachekey_t q3tofte[] = {SLKEY_NAME, SLKEY_MAP, SLKEY_NUMHUMANS, SLKEY_GAMEDIR, SLKEY_PING, 0};
|
|
|
|
qboolean keyisstring[] = {true, true, false, true, false, false};
|
|
|
|
//int source = VM_LONG(arg[0]);
|
|
|
|
int key = bound(0, VM_LONG(arg[1]), countof(q3tofte));
|
|
|
|
int sortdir = VM_LONG(arg[2]);
|
2022-03-08 05:31:34 +00:00
|
|
|
serverinfo_t *s1 = masterfuncs->InfoForNum(VM_LONG(arg[3]));
|
|
|
|
serverinfo_t *s2 = masterfuncs->InfoForNum(VM_LONG(arg[4]));
|
2020-03-07 09:00:40 +00:00
|
|
|
if (keyisstring[key])
|
2022-03-08 05:31:34 +00:00
|
|
|
ret = strcasecmp(masterfuncs->ReadKeyString(s2, q3tofte[key]), masterfuncs->ReadKeyString(s1, q3tofte[key]));
|
2020-03-07 09:00:40 +00:00
|
|
|
else
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
ret = masterfuncs->ReadKeyFloat(s2, q3tofte[key]) - masterfuncs->ReadKeyFloat(s1, q3tofte[key]);
|
2020-03-07 09:00:40 +00:00
|
|
|
if (ret < 0)
|
|
|
|
ret = -1;
|
|
|
|
else if (ret > 0)
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
if (sortdir)
|
|
|
|
ret = -ret;
|
2005-08-26 22:56:51 +00:00
|
|
|
}
|
2020-03-07 09:00:40 +00:00
|
|
|
return ret;
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_LAN_GETSERVERCOUNT: //LAN Get server count
|
2004-08-23 00:15:46 +00:00
|
|
|
//int (int source)
|
2022-03-08 05:31:34 +00:00
|
|
|
masterfuncs->CheckPollSockets();
|
|
|
|
VM_LONG(ret) = masterfuncs->TotalCount();
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_LAN_GETSERVERADDRESSSTRING: //LAN get server address
|
2004-08-23 00:15:46 +00:00
|
|
|
//void (int source, int svnum, char *buffer, int buflen)
|
|
|
|
if ((int)arg[2] + VM_LONG(arg[3]) >= mask || VM_POINTER(arg[2]) < offset)
|
|
|
|
break; //out of bounds.
|
|
|
|
{
|
|
|
|
char *buf = VM_POINTER(arg[2]);
|
|
|
|
char *adr;
|
2021-08-04 21:17:31 +00:00
|
|
|
char adrbuf[MAX_ADR_SIZE];
|
2022-03-08 05:31:34 +00:00
|
|
|
serverinfo_t *info = masterfuncs->InfoForNum(VM_LONG(arg[1]));
|
2021-10-22 22:27:58 +00:00
|
|
|
strcpy(buf, "");
|
2004-08-23 00:15:46 +00:00
|
|
|
if (info)
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
adr = masterfuncs->ServerToString(adrbuf, sizeof(adrbuf), info);
|
2004-08-23 00:15:46 +00:00
|
|
|
if (strlen(adr) < VM_LONG(arg[3]))
|
|
|
|
{
|
|
|
|
strcpy(buf, adr);
|
|
|
|
VM_LONG(ret) = true;
|
2020-03-07 09:00:40 +00:00
|
|
|
}
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_LAN_LOADCACHEDSERVERS:
|
|
|
|
break;
|
|
|
|
case UI_LAN_SAVECACHEDSERVERS:
|
|
|
|
break;
|
|
|
|
case UI_LAN_GETSERVERPING:
|
|
|
|
return 50;
|
|
|
|
case UI_LAN_GETSERVERINFO:
|
2020-03-07 09:00:40 +00:00
|
|
|
if (VM_OOB(arg[2], arg[3]) || !arg[3])
|
|
|
|
break; //out of bounds.
|
|
|
|
{
|
|
|
|
//int source = VM_LONG(arg[0]);
|
|
|
|
int servernum = VM_LONG(arg[1]);
|
|
|
|
char *out = VM_POINTER(arg[2]);
|
|
|
|
int maxsize = VM_LONG(arg[3]);
|
|
|
|
char adr[MAX_ADR_SIZE];
|
2022-03-08 05:31:34 +00:00
|
|
|
serverinfo_t *info = masterfuncs->InfoForNum(servernum);
|
2020-03-07 09:00:40 +00:00
|
|
|
*out = 0;
|
|
|
|
if (info)
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
worldfuncs->SetInfoKey(out, "hostname", info->name, maxsize);
|
|
|
|
worldfuncs->SetInfoKey(out, "mapname", info->map, maxsize);
|
|
|
|
worldfuncs->SetInfoKey(out, "clients", va("%i", info->players), maxsize);
|
|
|
|
worldfuncs->SetInfoKey(out, "sv_maxclients", va("%i", info->maxplayers), maxsize);
|
|
|
|
worldfuncs->SetInfoKey(out, "ping", va("%i", info->ping), maxsize);
|
|
|
|
// worldfuncs->SetInfoKey(out, "minping", info->map, maxsize);
|
|
|
|
// worldfuncs->SetInfoKey(out, "maxping", info->map, maxsize);
|
|
|
|
// worldfuncs->SetInfoKey(out, "game", info->map, maxsize);
|
|
|
|
// worldfuncs->SetInfoKey(out, "gametype", info->map, maxsize);
|
|
|
|
// worldfuncs->SetInfoKey(out, "nettype", info->map, maxsize);
|
|
|
|
worldfuncs->SetInfoKey(out, "addr", masterfuncs->AdrToString(adr, sizeof(adr), &info->adr), maxsize);
|
|
|
|
// worldfuncs->SetInfoKey(out, "punkbuster", info->map, maxsize);
|
|
|
|
// worldfuncs->SetInfoKey(out, "g_needpass", info->map, maxsize);
|
|
|
|
// worldfuncs->SetInfoKey(out, "g_humanplayers", info->map, maxsize);
|
2020-03-07 09:00:40 +00:00
|
|
|
}
|
|
|
|
}
|
2005-08-26 22:56:51 +00:00
|
|
|
break;
|
2020-03-07 09:00:40 +00:00
|
|
|
case UI_LAN_MARKSERVERVISIBLE:
|
|
|
|
/*not implemented*/
|
|
|
|
return 0;
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_LAN_SERVERISVISIBLE:
|
|
|
|
return 1;
|
2012-04-09 19:12:12 +00:00
|
|
|
#endif
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2020-03-07 09:00:40 +00:00
|
|
|
case UI_CVAR_REGISTER:
|
|
|
|
if (VM_OOB(arg[0], sizeof(q3vmcvar_t)))
|
|
|
|
break; //out of bounds.
|
|
|
|
return VMQ3_Cvar_Register(VM_POINTER(arg[0]), VM_POINTER(arg[1]), VM_POINTER(arg[2]), VM_LONG(arg[3]));
|
|
|
|
|
|
|
|
case UI_CVAR_UPDATE:
|
|
|
|
if (VM_OOB(arg[0], sizeof(q3vmcvar_t)))
|
|
|
|
break; //out of bounds.
|
|
|
|
return VMQ3_Cvar_Update(VM_POINTER(arg[0]));
|
|
|
|
|
|
|
|
case UI_MEMORY_REMAINING:
|
|
|
|
VM_LONG(ret) = 1024*1024*8;//Hunk_LowMemAvailable();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UI_GET_CDKEY: //get cd key
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
cvar_t *cvar = cvarfuncs->GetNVFDG("cl_cdkey", "", CVAR_ARCHIVE, "Quake3 auth", "Q3 Compat");
|
2020-03-07 09:00:40 +00:00
|
|
|
char *keydest = VM_POINTER(arg[0]);
|
2022-03-08 05:31:34 +00:00
|
|
|
if (!cvar || (int)arg[0] + VM_LONG(arg[1]) >= mask || VM_POINTER(arg[0]) < offset)
|
2020-03-07 09:00:40 +00:00
|
|
|
break; //out of bounds.
|
2022-03-08 05:31:34 +00:00
|
|
|
Q_strncpyz(keydest, cvar->string, VM_LONG(arg[1]));
|
2020-03-07 09:00:40 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UI_SET_CDKEY: //set cd key
|
|
|
|
{
|
|
|
|
char *keysrc = VM_POINTER(arg[0]);
|
|
|
|
if ((int)arg[0] + strlen(keysrc) >= mask || VM_POINTER(arg[0]) < offset)
|
|
|
|
break; //out of bounds.
|
2022-03-08 05:31:34 +00:00
|
|
|
cvarfuncs->SetString("cl_cdkey", keysrc);
|
2020-03-07 09:00:40 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UI_REAL_TIME:
|
|
|
|
VALIDATEPOINTER(arg[0], sizeof(q3time_t));
|
|
|
|
return Q3VM_GetRealtime(VM_POINTER(arg[0]));
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_VERIFY_CDKEY:
|
2004-08-23 00:15:46 +00:00
|
|
|
VM_LONG(ret) = true;
|
|
|
|
break;
|
|
|
|
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_SET_PBCLSTATUS:
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// standard Q3
|
|
|
|
case UI_MEMSET:
|
2011-01-29 21:01:40 +00:00
|
|
|
{
|
|
|
|
void *dest = VM_POINTER(arg[0]);
|
|
|
|
if ((int)arg[0] + arg[2] >= mask || dest < offset)
|
|
|
|
break; //out of bounds.
|
|
|
|
memset(dest, arg[1], arg[2]);
|
|
|
|
}
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_MEMCPY:
|
2011-01-29 21:01:40 +00:00
|
|
|
{
|
|
|
|
void *dest = VM_POINTER(arg[0]);
|
|
|
|
void *src = VM_POINTER(arg[1]);
|
|
|
|
if ((int)arg[0] + arg[2] >= mask || VM_POINTER(arg[0]) < offset)
|
|
|
|
break; //out of bounds.
|
|
|
|
memcpy(dest, src, arg[2]);
|
|
|
|
}
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
case UI_STRNCPY:
|
2011-01-29 21:01:40 +00:00
|
|
|
{
|
|
|
|
void *dest = VM_POINTER(arg[0]);
|
|
|
|
void *src = VM_POINTER(arg[1]);
|
|
|
|
if (arg[0] + arg[2] >= mask || VM_POINTER(arg[0]) < offset)
|
|
|
|
break; //out of bounds.
|
|
|
|
Q_strncpyS(dest, src, arg[2]);
|
|
|
|
}
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
case UI_SIN:
|
|
|
|
VM_FLOAT(ret)=(float)sin(VM_FLOAT(arg[0]));
|
|
|
|
break;
|
|
|
|
case UI_COS:
|
|
|
|
VM_FLOAT(ret)=(float)cos(VM_FLOAT(arg[0]));
|
|
|
|
break;
|
|
|
|
case UI_ATAN2:
|
|
|
|
VM_FLOAT(ret)=(float)atan2(VM_FLOAT(arg[0]), VM_FLOAT(arg[1]));
|
|
|
|
break;
|
|
|
|
case UI_SQRT:
|
|
|
|
VM_FLOAT(ret)=(float)sqrt(VM_FLOAT(arg[0]));
|
|
|
|
break;
|
|
|
|
case UI_FLOOR:
|
|
|
|
VM_FLOAT(ret)=(float)floor(VM_FLOAT(arg[0]));
|
|
|
|
break;
|
|
|
|
case UI_CEIL:
|
|
|
|
VM_FLOAT(ret)=(float)ceil(VM_FLOAT(arg[0]));
|
|
|
|
break;
|
2007-09-17 20:35:39 +00:00
|
|
|
/*
|
2004-08-23 00:15:46 +00:00
|
|
|
case UI_GETPLAYERINFO:
|
|
|
|
if (arg[1] + sizeof(vmuiclientinfo_t) >= mask || VM_POINTER(arg[1]) < offset)
|
|
|
|
break; //out of bounds.
|
|
|
|
if (VM_LONG(arg[0]) < -1 || VM_LONG(arg[0] ) >= MAX_CLIENTS)
|
|
|
|
break;
|
|
|
|
{
|
|
|
|
int i = VM_LONG(arg[0]);
|
|
|
|
vmuiclientinfo_t *vci = VM_POINTER(arg[1]);
|
|
|
|
if (i == -1)
|
|
|
|
{
|
|
|
|
i = cl.playernum[0];
|
|
|
|
if (i < 0)
|
|
|
|
{
|
|
|
|
memset(vci, 0, sizeof(*vci));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2007-07-23 18:52:11 +00:00
|
|
|
vci->bottomcolour = cl.players[i].rbottomcolor;
|
2004-08-23 00:15:46 +00:00
|
|
|
vci->frags = cl.players[i].frags;
|
2005-02-06 13:59:37 +00:00
|
|
|
Q_strncpyz(vci->name, cl.players[i].name, UIMAX_SCOREBOARDNAME);
|
2004-08-23 00:15:46 +00:00
|
|
|
vci->ping = cl.players[i].ping;
|
|
|
|
vci->pl = cl.players[i].pl;
|
|
|
|
vci->starttime = cl.players[i].entertime;
|
2007-07-23 18:52:11 +00:00
|
|
|
vci->topcolour = cl.players[i].rtopcolor;
|
2004-08-23 00:15:46 +00:00
|
|
|
vci->userid = cl.players[i].userid;
|
|
|
|
Q_strncpyz(vci->userinfo, cl.players[i].userinfo, sizeof(vci->userinfo));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UI_GETSTAT:
|
|
|
|
if (VM_LONG(arg[0]) < 0 || VM_LONG(arg[0]) >= MAX_CL_STATS)
|
|
|
|
VM_LONG(ret) = 0; //invalid stat num.
|
|
|
|
else
|
|
|
|
VM_LONG(ret) = cl.stats[0][VM_LONG(arg[0])];
|
|
|
|
break;
|
|
|
|
case UI_GETVIDINFO:
|
|
|
|
{
|
|
|
|
vidinfo_t *vi;
|
|
|
|
if (arg[0] + VM_LONG(arg[1]) >= mask || VM_POINTER(arg[1]) < offset)
|
|
|
|
{
|
|
|
|
VM_LONG(ret) = 0;
|
|
|
|
break; //out of bounds.
|
|
|
|
}
|
|
|
|
vi = VM_POINTER(arg[0]);
|
|
|
|
if (VM_LONG(arg[1]) < sizeof(vidinfo_t))
|
|
|
|
{
|
|
|
|
VM_LONG(ret) = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
VM_LONG(ret) = sizeof(vidinfo_t);
|
2022-03-08 05:31:34 +00:00
|
|
|
vi->width = vsize[0];
|
|
|
|
vi->height = vsize[1];
|
2004-08-23 00:15:46 +00:00
|
|
|
vi->refreshrate = 60;
|
|
|
|
vi->fullscreen = 1;
|
|
|
|
Q_strncpyz(vi->renderername, q_renderername, sizeof(vi->renderername));
|
|
|
|
}
|
|
|
|
break;
|
2007-09-17 20:35:39 +00:00
|
|
|
*/
|
2005-08-26 22:56:51 +00:00
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
#if 1//def BOTLIB_STATIC
|
|
|
|
case UI_PC_ADD_GLOBAL_DEFINE:
|
|
|
|
return botlib->PC_AddGlobalDefine(VM_POINTER(arg[0]));
|
|
|
|
case UI_PC_LOAD_SOURCE:
|
|
|
|
return botlib->PC_LoadSourceHandle(VM_POINTER(arg[0]));
|
|
|
|
case UI_PC_FREE_SOURCE:
|
|
|
|
return botlib->PC_FreeSourceHandle(VM_LONG(arg[0]));
|
|
|
|
case UI_PC_READ_TOKEN:
|
|
|
|
return botlib->PC_ReadTokenHandle(VM_LONG(arg[0]), VM_POINTER(arg[1]));
|
|
|
|
case UI_PC_SOURCE_FILE_AND_LINE:
|
|
|
|
return botlib->PC_SourceFileAndLine(VM_LONG(arg[0]), VM_POINTER(arg[1]), VM_POINTER(arg[2]));
|
|
|
|
#else
|
2005-08-26 22:56:51 +00:00
|
|
|
case UI_PC_ADD_GLOBAL_DEFINE:
|
|
|
|
Con_Printf("UI_PC_ADD_GLOBAL_DEFINE not supported\n");
|
|
|
|
break;
|
|
|
|
case UI_PC_SOURCE_FILE_AND_LINE:
|
|
|
|
Script_Get_File_And_Line(arg[0], VM_POINTER(arg[1]), VM_POINTER(arg[2]));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UI_PC_LOAD_SOURCE:
|
|
|
|
return Script_LoadFile(VM_POINTER(arg[0]));
|
|
|
|
case UI_PC_FREE_SOURCE:
|
|
|
|
Script_Free(arg[0]);
|
|
|
|
break;
|
|
|
|
case UI_PC_READ_TOKEN:
|
|
|
|
//fixme: memory protect.
|
|
|
|
return Script_Read(arg[0], VM_POINTER(arg[1]));
|
2022-03-08 05:31:34 +00:00
|
|
|
#endif
|
2005-08-26 22:56:51 +00:00
|
|
|
|
2006-03-06 01:41:09 +00:00
|
|
|
case UI_CIN_PLAYCINEMATIC:
|
2020-03-07 09:00:40 +00:00
|
|
|
return UI_Cin_Play(VM_POINTER(arg[0]), VM_LONG(arg[1]), VM_LONG(arg[2]), VM_LONG(arg[3]), VM_LONG(arg[4]), VM_LONG(arg[5]));
|
2006-03-06 01:41:09 +00:00
|
|
|
case UI_CIN_STOPCINEMATIC:
|
2020-03-07 09:00:40 +00:00
|
|
|
return UI_Cin_Stop(VM_LONG(arg[0]));
|
2006-03-06 01:41:09 +00:00
|
|
|
case UI_CIN_RUNCINEMATIC:
|
2020-03-07 09:00:40 +00:00
|
|
|
return UI_Cin_Run(VM_LONG(arg[0]));
|
2006-03-06 01:41:09 +00:00
|
|
|
case UI_CIN_DRAWCINEMATIC:
|
2020-03-07 09:00:40 +00:00
|
|
|
return UI_Cin_Draw(VM_LONG(arg[0]));
|
2006-03-06 01:41:09 +00:00
|
|
|
case UI_CIN_SETEXTENTS:
|
2020-03-07 09:00:40 +00:00
|
|
|
return UI_Cin_SetExtents(VM_LONG(arg[0]), VM_LONG(arg[1]), VM_LONG(arg[2]), VM_LONG(arg[3]), VM_LONG(arg[4]));
|
2006-03-06 01:41:09 +00:00
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _DEBUG
|
2004-08-23 00:15:46 +00:00
|
|
|
default:
|
2022-03-08 05:31:34 +00:00
|
|
|
#endif
|
2020-03-07 09:00:40 +00:00
|
|
|
Con_Printf("Q3UI: Unknown system trap: %i\n", (int)fn);
|
2005-08-26 22:56:51 +00:00
|
|
|
return 0;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-02 23:17:25 +00:00
|
|
|
static int UI_SystemCallsVM(void *offset, quintptr_t mask, int fn, const int *arg)
|
2004-08-23 00:15:46 +00:00
|
|
|
{ //this is so we can use edit and continue properly (vc doesn't like function pointers for edit+continue)
|
2011-01-29 21:01:40 +00:00
|
|
|
#if __WORDSIZE == 32
|
|
|
|
return UI_SystemCalls(offset, mask, fn, (qintptr_t*)arg);
|
|
|
|
#else
|
|
|
|
qintptr_t args[9];
|
|
|
|
|
|
|
|
args[0]=arg[0];
|
|
|
|
args[1]=arg[1];
|
|
|
|
args[2]=arg[2];
|
|
|
|
args[3]=arg[3];
|
|
|
|
args[4]=arg[4];
|
|
|
|
args[5]=arg[5];
|
|
|
|
args[6]=arg[6];
|
|
|
|
args[7]=arg[7];
|
|
|
|
args[8]=arg[8];
|
|
|
|
|
|
|
|
return UI_SystemCalls(offset, mask, fn, args);
|
|
|
|
#endif
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//I'm not keen on this.
|
|
|
|
//but dlls call it without saying what sort of vm it comes from, so I've got to have them as specifics
|
2010-11-02 23:17:25 +00:00
|
|
|
static qintptr_t EXPORT_FN UI_SystemCallsNative(qintptr_t arg, ...)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2010-07-11 02:22:39 +00:00
|
|
|
qintptr_t args[9];
|
2004-08-23 00:15:46 +00:00
|
|
|
va_list argptr;
|
|
|
|
|
|
|
|
va_start(argptr, arg);
|
2010-07-11 02:22:39 +00:00
|
|
|
args[0]=va_arg(argptr, qintptr_t);
|
|
|
|
args[1]=va_arg(argptr, qintptr_t);
|
|
|
|
args[2]=va_arg(argptr, qintptr_t);
|
|
|
|
args[3]=va_arg(argptr, qintptr_t);
|
|
|
|
args[4]=va_arg(argptr, qintptr_t);
|
|
|
|
args[5]=va_arg(argptr, qintptr_t);
|
|
|
|
args[6]=va_arg(argptr, qintptr_t);
|
|
|
|
args[7]=va_arg(argptr, qintptr_t);
|
|
|
|
args[8]=va_arg(argptr, qintptr_t);
|
2004-08-23 00:15:46 +00:00
|
|
|
va_end(argptr);
|
|
|
|
|
2010-11-02 23:17:25 +00:00
|
|
|
return UI_SystemCalls(NULL, ~(quintptr_t)0, arg, args);
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
|
2021-07-01 21:05:45 +00:00
|
|
|
static void UI_Release(menu_t *m, qboolean forced)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2019-09-04 07:59:40 +00:00
|
|
|
keycatcher &= ~2;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
2019-09-04 07:59:40 +00:00
|
|
|
static void UI_DrawMenu(menu_t *m)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
if (uivm)
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
float vsize[2];
|
|
|
|
|
|
|
|
if (drawfuncs->GetVideoSize(vsize, NULL) && (ui_size[0] != vsize[0] || ui_size[1] != vsize[1]))
|
2021-10-22 22:27:58 +00:00
|
|
|
{ //should probably just rescale stuff instead.
|
|
|
|
qboolean hadfocus = keycatcher&2;
|
|
|
|
keycatcher &= ~2;
|
2022-03-08 05:31:34 +00:00
|
|
|
ui_size[0] = vsize[0];
|
|
|
|
ui_size[1] = vsize[1];
|
|
|
|
vmfuncs->Call(uivm, UI_INIT);
|
2021-10-22 22:27:58 +00:00
|
|
|
if (hadfocus)
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
if (ccs.state)
|
|
|
|
vmfuncs->Call(uivm, UI_SET_ACTIVE_MENU, 2);
|
2021-10-22 22:27:58 +00:00
|
|
|
else
|
2022-03-08 05:31:34 +00:00
|
|
|
vmfuncs->Call(uivm, UI_SET_ACTIVE_MENU, 1);
|
2021-10-22 22:27:58 +00:00
|
|
|
}
|
2019-01-29 07:18:07 +00:00
|
|
|
}
|
2022-03-08 05:31:34 +00:00
|
|
|
vmfuncs->Call(uivm, UI_REFRESH, plugfuncs->GetMilliseconds());
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
uimenu.isopaque = vmfuncs->Call(uivm, UI_IS_FULLSCREEN);
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-04 07:59:40 +00:00
|
|
|
qboolean UI_KeyPress(struct menu_s *m, qboolean isdown, unsigned int devid, int key, int unicode)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2004-12-21 04:29:14 +00:00
|
|
|
// qboolean result;
|
2004-08-23 00:15:46 +00:00
|
|
|
if (!uivm)
|
|
|
|
return false;
|
2005-08-26 22:56:51 +00:00
|
|
|
// if (key_dest == key_menu)
|
|
|
|
// return false;
|
2004-08-23 00:15:46 +00:00
|
|
|
if (!(keycatcher&2))
|
|
|
|
{
|
2019-09-04 07:59:40 +00:00
|
|
|
if (key == K_ESCAPE && isdown)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2009-11-04 21:16:50 +00:00
|
|
|
UI_OpenMenu();
|
2006-09-17 00:59:22 +00:00
|
|
|
return true;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-07-22 07:17:30 +00:00
|
|
|
/* if you change this here, it'll have to be changed in cl_cg.c too */
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
/* all these get interpreted as enter in Q3's UI... */
|
|
|
|
case K_JOY1:
|
|
|
|
case K_JOY2:
|
|
|
|
case K_JOY3:
|
|
|
|
case K_JOY4:
|
|
|
|
case K_AUX1:
|
|
|
|
case K_AUX2:
|
|
|
|
case K_AUX3:
|
|
|
|
case K_AUX4:
|
|
|
|
case K_AUX5:
|
|
|
|
case K_AUX6:
|
|
|
|
case K_AUX7:
|
|
|
|
case K_AUX8:
|
|
|
|
case K_AUX9:
|
|
|
|
case K_AUX10:
|
|
|
|
case K_AUX11:
|
|
|
|
case K_AUX14:
|
|
|
|
case K_AUX15:
|
|
|
|
case K_AUX16:
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
/* Q3 doesn't know about these keys, remap them */
|
|
|
|
case K_GP_START:
|
|
|
|
key = K_ESCAPE;
|
|
|
|
break;
|
|
|
|
case K_GP_DPAD_UP:
|
|
|
|
key = K_UPARROW;
|
|
|
|
break;
|
|
|
|
case K_GP_DPAD_DOWN:
|
|
|
|
key = K_DOWNARROW;
|
|
|
|
break;
|
|
|
|
case K_GP_DPAD_LEFT:
|
|
|
|
key = K_LEFTARROW;
|
|
|
|
break;
|
|
|
|
case K_GP_DPAD_RIGHT:
|
|
|
|
key = K_RIGHTARROW;
|
|
|
|
break;
|
|
|
|
case K_GP_A:
|
|
|
|
key = K_ENTER;
|
|
|
|
break;
|
2021-07-23 13:36:18 +00:00
|
|
|
case K_GP_B:
|
|
|
|
key = K_ESCAPE;
|
|
|
|
break;
|
|
|
|
case K_GP_X:
|
|
|
|
key = K_BACKSPACE;
|
|
|
|
break;
|
2021-07-22 07:17:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-07 09:00:40 +00:00
|
|
|
if (key && key < 1024)
|
2022-03-08 05:31:34 +00:00
|
|
|
/*result = */vmfuncs->Call(uivm, UI_KEY_EVENT, key, isdown);
|
2020-03-07 09:00:40 +00:00
|
|
|
if (unicode && unicode < 1024)
|
2022-03-08 05:31:34 +00:00
|
|
|
/*result = */vmfuncs->Call(uivm, UI_KEY_EVENT, unicode|1024, isdown);
|
2004-12-21 04:29:14 +00:00
|
|
|
return true;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
static qboolean UI_MousePosition(struct menu_s *m, qboolean abs, unsigned int devid, float x, float y)
|
|
|
|
{ //q3ui is a peice of poo and only accepts relative mouse movements.
|
|
|
|
//which it then clamps arbitrarily
|
|
|
|
//which means we can't use hardware cursors
|
|
|
|
//which results in clumsyness when switching between q3ui and everything else.
|
|
|
|
|
|
|
|
if (uivm && !abs)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2019-09-04 07:59:40 +00:00
|
|
|
int px = x, py = y;
|
2022-03-08 05:31:34 +00:00
|
|
|
vmfuncs->Call(uivm, UI_MOUSE_EVENT, px, py);
|
2009-11-04 21:16:50 +00:00
|
|
|
return true;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
2009-11-04 21:16:50 +00:00
|
|
|
return false;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
void UI_Reset(void)
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
inputfuncs->Menu_Unlink(&uimenu, true);
|
2019-09-04 07:59:40 +00:00
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
if (!drawfuncs->GetVideoSize(NULL,NULL)) //no renderer loaded
|
2019-09-04 07:59:40 +00:00
|
|
|
UI_Stop();
|
|
|
|
else if (uivm)
|
2022-03-08 05:31:34 +00:00
|
|
|
vmfuncs->Call(uivm, UI_INIT);
|
2019-09-04 07:59:40 +00:00
|
|
|
}
|
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
void UI_Stop (void)
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
inputfuncs->Menu_Unlink(&uimenu, true);
|
2019-09-04 07:59:40 +00:00
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
if (uivm)
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
vmfuncs->Call(uivm, UI_SHUTDOWN);
|
|
|
|
vmfuncs->Destroy(uivm);
|
2007-09-02 19:55:17 +00:00
|
|
|
VM_fcloseall(0);
|
2004-08-23 00:15:46 +00:00
|
|
|
uivm = NULL;
|
2014-10-05 20:04:11 +00:00
|
|
|
|
|
|
|
//mimic Q3 and save the config if anything got changed.
|
|
|
|
//note that q3 checks every frame. we only check when the ui is closed.
|
2022-03-08 05:31:34 +00:00
|
|
|
cmdfuncs->AddText("cfg_save_ifmodified\n", true);
|
2019-08-03 01:58:03 +00:00
|
|
|
#if defined(CL_MASTER)
|
2022-03-08 05:31:34 +00:00
|
|
|
masterfuncs->WriteServers();
|
2019-08-03 01:58:03 +00:00
|
|
|
#endif
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI_Start (void)
|
|
|
|
{
|
2014-12-23 15:26:42 +00:00
|
|
|
int i;
|
2004-08-23 00:15:46 +00:00
|
|
|
int apiversion;
|
2022-03-08 05:31:34 +00:00
|
|
|
if (!cl_shownet_ptr)
|
|
|
|
return; //make sure UI_Init was called. if it wasn't then something messed up and we can't do client stuff.
|
|
|
|
if (!drawfuncs->GetVideoSize(ui_size,NULL))
|
2005-10-16 03:54:43 +00:00
|
|
|
return;
|
|
|
|
|
2013-03-12 23:03:04 +00:00
|
|
|
UI_Stop();
|
|
|
|
|
2014-12-23 15:26:42 +00:00
|
|
|
for (i = 0; i < MAX_PINGREQUESTS; i++)
|
2019-02-01 08:29:14 +00:00
|
|
|
ui_pings[i].adr.type = NA_INVALID;
|
2014-12-23 15:26:42 +00:00
|
|
|
|
2019-09-04 07:59:40 +00:00
|
|
|
uimenu.drawmenu = UI_DrawMenu;
|
|
|
|
uimenu.mousemove = UI_MousePosition;
|
|
|
|
uimenu.keyevent = UI_KeyPress;
|
|
|
|
uimenu.release = UI_Release;
|
2022-03-08 05:31:34 +00:00
|
|
|
uimenu.lowpriority = true;
|
2019-09-04 07:59:40 +00:00
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
SV_InitBotLib();
|
|
|
|
uivm = vmfuncs->Create("ui", cvarfuncs->GetFloat("com_gamedirnativecode")?UI_SystemCallsNative:NULL, "vm/ui", UI_SystemCallsVM);
|
2004-08-23 00:15:46 +00:00
|
|
|
if (uivm)
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
apiversion = vmfuncs->Call(uivm, UI_GETAPIVERSION, 6);
|
2007-09-17 20:35:39 +00:00
|
|
|
if (apiversion != 4 && apiversion != 6) //make sure we can run the thing
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2007-10-05 18:08:47 +00:00
|
|
|
Con_Printf("User-Interface VM uses incompatible API version (%i)\n", apiversion);
|
2022-03-08 05:31:34 +00:00
|
|
|
vmfuncs->Destroy(uivm);
|
2007-09-02 19:55:17 +00:00
|
|
|
VM_fcloseall(0);
|
2004-08-23 00:15:46 +00:00
|
|
|
uivm = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2022-03-08 05:31:34 +00:00
|
|
|
vmfuncs->Call(uivm, UI_INIT);
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
UI_OpenMenu();
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UI_Restart_f(void)
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
char arg1[256];
|
|
|
|
cmdfuncs->Argv(1, arg1, sizeof(arg1));
|
2004-08-23 00:15:46 +00:00
|
|
|
UI_Stop();
|
2022-03-08 05:31:34 +00:00
|
|
|
if (strcmp(arg1, "off"))
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2018-01-22 19:18:04 +00:00
|
|
|
UI_Start();
|
|
|
|
|
|
|
|
if (uivm)
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
if (ccs.state)
|
|
|
|
vmfuncs->Call(uivm, UI_SET_ACTIVE_MENU, 2);
|
2018-01-22 19:18:04 +00:00
|
|
|
else
|
2022-03-08 05:31:34 +00:00
|
|
|
vmfuncs->Call(uivm, UI_SET_ACTIVE_MENU, 1);
|
2018-01-22 19:18:04 +00:00
|
|
|
}
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
qboolean UI_OpenMenu(void)
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
if (!uivm)
|
|
|
|
UI_Start();
|
2009-11-04 21:16:50 +00:00
|
|
|
if (uivm)
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
if (ccs.state)
|
|
|
|
vmfuncs->Call(uivm, UI_SET_ACTIVE_MENU, 2);
|
2009-11-04 21:16:50 +00:00
|
|
|
else
|
2022-03-08 05:31:34 +00:00
|
|
|
vmfuncs->Call(uivm, UI_SET_ACTIVE_MENU, 1);
|
2009-11-04 21:16:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
qboolean UI_ConsoleCommand(void)
|
2005-09-08 22:52:46 +00:00
|
|
|
{
|
|
|
|
if (uivm)
|
2022-03-08 05:31:34 +00:00
|
|
|
return vmfuncs->Call(uivm, UI_CONSOLE_COMMAND, plugfuncs->GetMilliseconds());
|
2005-09-08 22:52:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-01 08:29:14 +00:00
|
|
|
qboolean UI_IsRunning(void)
|
|
|
|
{
|
|
|
|
if (uivm)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-03-08 05:31:34 +00:00
|
|
|
vm_t *UI_GetUIVM(void)
|
|
|
|
{
|
|
|
|
return uivm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
void UI_Init (void)
|
|
|
|
{
|
2022-03-08 05:31:34 +00:00
|
|
|
cl_shownet_ptr = cvarfuncs->GetNVFDG("cl_shownet", "", 0, NULL, "Q3 Compat");
|
|
|
|
cl_c2sdupe_ptr = cvarfuncs->GetNVFDG("cl_c2sdupe", "", 0, NULL, "Q3 Compat");
|
|
|
|
cl_nodelta_ptr = cvarfuncs->GetNVFDG("cl_nodelta", "", 0, NULL, "Q3 Compat");
|
|
|
|
|
|
|
|
cmdfuncs->AddCommand("ui_restart", UI_Restart_f, "Reload the Q3-based User Interface module");
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
#endif
|
2005-09-09 23:40:55 +00:00
|
|
|
|