From 758f47ffc3cc103c428e82de1cc1b5cea93f72e5 Mon Sep 17 00:00:00 2001 From: Spoike Date: Sun, 19 Jun 2022 15:18:23 +0000 Subject: [PATCH] Fix ezhud images not loading. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@6271 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/cl_plugin.inc | 79 ++++++++++++++++++++++++++++++++++- engine/client/menu.h | 2 +- engine/client/r_2d.c | 2 +- engine/client/renderer.c | 2 +- engine/common/plugin.c | 13 +++--- plugins/cef/cef.c | 2 +- plugins/ezhud/ezquakeisms.c | 14 ++++--- plugins/irc/ircclient.c | 2 +- plugins/jabber/jabberclient.c | 2 +- plugins/plugin.h | 8 ++-- plugins/qi/qi.c | 2 +- 11 files changed, 107 insertions(+), 21 deletions(-) diff --git a/engine/client/cl_plugin.inc b/engine/client/cl_plugin.inc index 1bddf7101..e0490ef76 100644 --- a/engine/client/cl_plugin.inc +++ b/engine/client/cl_plugin.inc @@ -627,7 +627,7 @@ static size_t QDECL Plug_GetLocalPlayerNumbers(size_t first, size_t count, int * return count; } -static void QDECL Plug_GetServerInfo(char *outptr, size_t outlen) +static void QDECL Plug_GetServerInfoRaw(char *outptr, size_t outlen) { extern float demtime; @@ -664,11 +664,88 @@ static void QDECL Plug_GetServerInfo(char *outptr, size_t outlen) #endif Q_strncatz(outptr, va("\\matchstart\\%f", cl.matchgametimestart), outlen); } +static size_t QDECL Plug_GetServerInfoBlob(const char *key, void *outptr, size_t outsize) +{ + char tmp[32]; + size_t blobsize; + const char *blob = InfoBuf_BlobForKey(&cl.serverinfo, key, &blobsize, NULL); + if (!blob) + { //inescapable hacks + if (!strcmp(key, "matchstart")) + snprintf(tmp, sizeof(tmp), "%f", cl.playerview[0].statsf[STAT_MATCHSTARTTIME]?cl.playerview[0].statsf[STAT_MATCHSTARTTIME]/1000:cl.matchgametimestart), blob=tmp; + else if (!strcmp(key, "demotime")) + { + extern float demtime; + snprintf(tmp, sizeof(tmp), "%f", demtime-cls.demostarttime), blob=tmp; + } + else if (!strcmp(key, "demotype")) + { + switch(cls.demoplayback) + { + case DPB_NONE: + break; + case DPB_MVD: + case DPB_EZTV: + blob = "mvd"; + break; + case DPB_QUAKEWORLD: + blob = "qw"; + break; +#ifdef NQPROT + case DPB_NETQUAKE: + blob = "nq"; + break; +#endif +#ifdef Q2CLIENT + case DPB_QUAKE2: + blob = "q2"; + break; +#endif + } + } + else if (!strcmp(key, "intermission")) + snprintf(tmp, sizeof(tmp), "%i", cl.intermissionmode), blob=tmp; + if (blob) + blobsize = strlen(blob); + } + if (outptr) + { + if (blobsize > outsize) + return 0; //error + memcpy(outptr, blob, blobsize); + return blobsize; + } + else + return blobsize; +} static void QDECL Plug_SetUserInfo(int seat, const char *key, const char *value) { CL_SetInfo(seat, key, value); } +static void QDECL Plug_SetUserInfoBlob(int seat, const char *key, const void *value, size_t size) +{ + CL_SetInfoBlob(seat, key, value, size); +} + +static size_t QDECL Plug_GetUserInfoBlob(int seat, const char *key, void *outptr, size_t outsize) +{ + size_t blobsize; + const char *blob; + if (seat >= countof(cls.userinfo)) + blob = NULL, blobsize = 0; + else + blob = InfoBuf_BlobForKey(&cls.userinfo[seat], key, &blobsize, NULL); + if (outptr) + { + if (blobsize > outsize) + return 0; //error + memcpy(outptr, blob, blobsize); + return blobsize; + } + else + return blobsize; +} void QDECL Plug_CL_ClearState(void) { diff --git a/engine/client/menu.h b/engine/client/menu.h index e853c4c50..044579942 100644 --- a/engine/client/menu.h +++ b/engine/client/menu.h @@ -549,7 +549,7 @@ void Plug_DrawReloadImages(void); void Plug_Initialise(qboolean fromgamedir); void Plug_Shutdown(qboolean preliminary); qboolean Plug_Menu_Event(int eventtype, int keyparam, int unicodeparam); -void Plug_ResChanged(void); +void Plug_ResChanged(qboolean restarted); void Plug_SBar(playerview_t *pv); qboolean Plug_ServerMessage(char *buffer, int messagelevel); void Plug_Tick(void); diff --git a/engine/client/r_2d.c b/engine/client/r_2d.c index 1c4c49c05..5564f4134 100644 --- a/engine/client/r_2d.c +++ b/engine/client/r_2d.c @@ -1253,7 +1253,7 @@ void R2D_Font_Changed(void) mn_entry->Init(MI_RESOLUTION, vid.width, vid.height, vid.rotpixelwidth, vid.rotpixelheight); #endif #ifdef PLUGINS - Plug_ResChanged(); + Plug_ResChanged(false); #endif } diff --git a/engine/client/renderer.c b/engine/client/renderer.c index 034fc18d3..aa2c80f70 100644 --- a/engine/client/renderer.c +++ b/engine/client/renderer.c @@ -1761,7 +1761,7 @@ TRACE(("dbg: R_ApplyRenderer: clearing world\n")); } #endif #ifdef PLUGINS - Plug_ResChanged(); + Plug_ResChanged(true); #endif Cvar_ForceCallback(&r_particlesystem); #ifdef MENU_NATIVECODE diff --git a/engine/common/plugin.c b/engine/common/plugin.c index 903ed7964..94e3d3c1e 100644 --- a/engine/common/plugin.c +++ b/engine/common/plugin.c @@ -108,7 +108,7 @@ typedef struct plugin_s { int (QDECL *conexecutecommand)(qboolean isinsecure); qboolean (QDECL *menufunction)(int eventtype, int keyparam, int unicodeparm, float mousecursor_x, float mousecursor_y, float vidwidth, float vidheight); int (QDECL *sbarlevel[3])(int seat, float x, float y, float w, float h, unsigned int showscores); //0 - main sbar, 1 - supplementry sbar sections (make sure these can be switched off), 2 - overlays (scoreboard). menus kill all. - void (QDECL *reschange)(int width, int height); + void (QDECL *reschange)(int width, int height, qboolean restarted); //protocol-in-a-plugin int (QDECL *connectionlessclientpacket)(const char *buffer, size_t size, netadr_t *from); @@ -283,7 +283,7 @@ static plugin_t *Plug_Load(const char *file) #ifndef SERVERONLY if (newplug->reschange) - newplug->reschange(vid.width, vid.height); + newplug->reschange(vid.width, vid.height, false); #endif currentplug = NULL; @@ -1285,13 +1285,13 @@ void Plug_Tick(void) } #ifndef SERVERONLY -void Plug_ResChanged(void) +void Plug_ResChanged(qboolean restarted) { plugin_t *oldplug = currentplug; for (currentplug = plugs; currentplug; currentplug = currentplug->next) { if (currentplug->reschange) - currentplug->reschange(vid.width, vid.height); + currentplug->reschange(vid.width, vid.height, restarted); } currentplug = oldplug; } @@ -2111,8 +2111,11 @@ static void *QDECL PlugBI_GetEngineInterface(const char *interfacename, size_t s Plug_GetLocalPlayerNumbers, Plug_GetLocationName, Plug_GetLastInputFrame, - Plug_GetServerInfo, + Plug_GetServerInfoRaw, + Plug_GetServerInfoBlob, Plug_SetUserInfo, + Plug_SetUserInfoBlob, + Plug_GetUserInfoBlob, #if defined(HAVE_SERVER) && defined(HAVE_CLIENT) Plug_MapLog_Query, #else diff --git a/plugins/cef/cef.c b/plugins/cef/cef.c index 920f0dce7..2467fff30 100644 --- a/plugins/cef/cef.c +++ b/plugins/cef/cef.c @@ -358,7 +358,7 @@ static qboolean browser_handle_query(const char *req, char *buffer, size_t buffe { char serverinfo[4096]; char *e = buffer; - clientfuncs->GetServerInfo(serverinfo, sizeof(serverinfo)); + clientfuncs->GetServerInfoRaw(serverinfo, sizeof(serverinfo)); e = Info_JSONify(serverinfo, e, buffer + buffersize - e-1); if (e == buffer) e++; *buffer = '{'; diff --git a/plugins/ezhud/ezquakeisms.c b/plugins/ezhud/ezquakeisms.c index b7f296fbc..4871cffd7 100644 --- a/plugins/ezhud/ezquakeisms.c +++ b/plugins/ezhud/ezquakeisms.c @@ -21,10 +21,14 @@ float alphamul; cvar_t *scr_newHud; -static void QDECL EZHud_UpdateVideo(int width, int height) +void HUD_InitSbarImages(void); +static void QDECL EZHud_UpdateVideo(int width, int height, qboolean restarted) { vid.width = width; vid.height = height; + + if (restarted) + HUD_InitSbarImages(); } char *Cmd_Argv(int arg) @@ -88,14 +92,14 @@ char *TP_LocationName (const vec3_t location) void Draw_SPic(float x, float y, mpic_t *pic, float scale) { qhandle_t image = (intptr_t)pic; - float w, h; + float w=64, h=64; drawfuncs->ImageSize(image, &w, &h); drawfuncs->Image(x, y, w*scale, h*scale, 0, 0, 1, 1, image); } void Draw_SSubPic(float x, float y, mpic_t *pic, float s1, float t1, float s2, float t2, float scale) { qhandle_t image = (intptr_t)pic; - float w, h; + float w=64, h=64; drawfuncs->ImageSize(image, &w, &h); drawfuncs->Image(x, y, (s2-s1)*scale, (t2-t1)*scale, s1/w, t1/h, s2/w, t2/h, image); } @@ -125,7 +129,7 @@ void SCR_DrawWadString(float x, float y, float scale, char *str) void Draw_SAlphaSubPic2(float x, float y, mpic_t *pic, float s1, float t1, float s2, float t2, float sw, float sh, float alpha) { qhandle_t image = (intptr_t)pic; - float w, h; + float w=64, h=64; drawfuncs->ImageSize(image, &w, &h); drawfuncs->Colour4f(1, 1, 1, alpha * alphamul); drawfuncs->Image(x, y, (s2-s1)*sw, (t2-t1)*sh, s1/w, t1/h, s2/w, t2/h, image); @@ -617,7 +621,7 @@ int EZHud_Draw(int seat, float viewx, float viewy, float viewwidth, float viewhe clientfuncs->GetPlayerInfo(i, &cl.players[i]); clientfuncs->GetLocalPlayerNumbers(cl.splitscreenview, 1, &cl.playernum, &cl.tracknum); - clientfuncs->GetServerInfo(cl.serverinfo, sizeof(serverinfo)); + clientfuncs->GetServerInfoRaw(cl.serverinfo, sizeof(serverinfo)); cl.deathmatch = infofloat(cl.serverinfo, "deathmatch", 0); cl.teamplay = infofloat(cl.serverinfo, "teamplay", 0); cl.intermission = infofloat(cl.serverinfo, "intermission", 0); diff --git a/plugins/irc/ircclient.c b/plugins/irc/ircclient.c index 597e0ac2d..822ba53cb 100644 --- a/plugins/irc/ircclient.c +++ b/plugins/irc/ircclient.c @@ -63,7 +63,7 @@ static struct int width; int height; } pvid; -static void QDECL IRC_UpdateVideo(int width, int height) +static void QDECL IRC_UpdateVideo(int width, int height, qboolean restarted) { pvid.width = width; pvid.height = height; diff --git a/plugins/jabber/jabberclient.c b/plugins/jabber/jabberclient.c index 1aebbbb1a..8aa9f0068 100644 --- a/plugins/jabber/jabberclient.c +++ b/plugins/jabber/jabberclient.c @@ -891,7 +891,7 @@ int JCL_ConExecuteCommand(qboolean isinsecure); void JCL_Frame(double realtime, double gametime); void JCL_Shutdown(void); -static void QDECL JCL_UpdateVideo(int width, int height) +static void QDECL JCL_UpdateVideo(int width, int height, qboolean restarted) { pvid.width = width; pvid.height = height; diff --git a/plugins/plugin.h b/plugins/plugin.h index b5b045a03..6f46a4f9a 100644 --- a/plugins/plugin.h +++ b/plugins/plugin.h @@ -297,9 +297,11 @@ typedef struct //q1 client/network info F(size_t, GetLocalPlayerNumbers,(size_t firstseat, size_t numseats, int *playernums, int *spectracks)); F(void, GetLocationName, (const float *pos, char *outbuffer, size_t bufferlen)); F(qboolean, GetLastInputFrame, (int seat, usercmd_t *outcmd)); - F(void, GetServerInfo, (char *info, size_t infolen)); - + F(void, GetServerInfoRaw, (char *info, size_t infolen)); + F(size_t, GetServerInfoBlob, (const char *keyname, void *buf, size_t bufsize)); //pass null buf to query size, returns 0 if it would truncate. does not null terminate. F(void, SetUserInfo, (int seat, const char *key, const char *value)); + F(void, SetUserInfoBlob, (int seat, const char *key, const void *value, size_t size)); + F(size_t, GetUserInfoBlob, (int seat, const char *key, void *buf, size_t bufsize)); //pass null buf to query size, returns 0 if it would truncate. does not null terminate. //EBUILTIN(void, SCR_CenterPrint, (const char *s)); //FIXME: does this belong here? @@ -319,7 +321,7 @@ typedef struct //q1 client/network info qboolean (*DownloadBegun)(qdownload_t *dl); void (*DownloadFinished)(qdownload_t *dl); downloadlist_t *(*DownloadFailed)(const char *name, qdownload_t *qdl, enum dlfailreason_e failreason); -#define plugclientfuncs_name "Client" +#define plugclientfuncs_name "Client2" } plugclientfuncs_t; struct menu_s; diff --git a/plugins/qi/qi.c b/plugins/qi/qi.c index db188ecb8..0365c7c61 100644 --- a/plugins/qi/qi.c +++ b/plugins/qi/qi.c @@ -48,7 +48,7 @@ static struct int width; int height; } pvid; -static void QDECL QI_UpdateVideo(int width, int height) +static void QDECL QI_UpdateVideo(int width, int height, qboolean restarted) { pvid.width = width; pvid.height = height;