1 //-------------------------------------------------------------------------
2 /*
3 Copyright (C) 2010 EDuke32 developers and contributors
4 
5 This file is part of EDuke32.
6 
7 EDuke32 is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License version 2
9 as published by the Free Software Foundation.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 
15 See the GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 */
21 //-------------------------------------------------------------------------
22 
23 #include "compat.h"
24 #include "build.h"
25 #include "common.h"
26 #include "keyboard.h"
27 #include "control.h"
28 #include "fx_man.h"
29 #include "exhumed.h"
30 #include "config.h"
31 #include "osdcmds.h"
32 #include "view.h"
33 
34 #include "vfs.h"
35 
36 
osdcmd_god(osdcmdptr_t UNUSED (parm))37 static int osdcmd_god(osdcmdptr_t UNUSED(parm))
38 {
39     UNREFERENCED_CONST_PARAMETER(parm);
40 
41     if (!nNetPlayerCount && !bInDemo)
42     {
43         DoPassword(3);
44     }
45     else
46         OSD_Printf("god: Not in a single-player game.\n");
47 
48     return OSDCMD_OK;
49 }
50 
osdcmd_noclip(osdcmdptr_t UNUSED (parm))51 static int osdcmd_noclip(osdcmdptr_t UNUSED(parm))
52 {
53     UNREFERENCED_CONST_PARAMETER(parm);
54 
55     if (!nNetPlayerCount && !bInDemo)
56     {
57         DoPassword(6);
58     }
59     else
60     {
61         OSD_Printf("noclip: Not in a single-player game.\n");
62     }
63 
64     return OSDCMD_OK;
65 }
66 
osdcmd_changelevel(osdcmdptr_t parm)67 static int osdcmd_changelevel(osdcmdptr_t parm)
68 {
69     char* p;
70 
71     if (parm->numparms != 1) return OSDCMD_SHOWHELP;
72 
73     int nLevel = strtol(parm->parms[0], &p, 10);
74     if (p[0]) return OSDCMD_SHOWHELP;
75 
76     if (nLevel < 0) return OSDCMD_SHOWHELP;
77 
78     int nMaxLevels;
79 
80     if (!ISDEMOVER) {
81         nMaxLevels = 32;
82     }
83     else {
84         nMaxLevels = EXHUMED ? 3 : 4;
85     }
86 
87     if (nLevel > nMaxLevels)
88     {
89         OSD_Printf("changelevel: invalid level number\n");
90         return OSDCMD_SHOWHELP;
91     }
92 
93     levelnew = nLevel;
94     levelnum = nLevel;
95 
96     return OSDCMD_OK;
97 }
98 
osdcmd_quit(osdcmdptr_t UNUSED (parm))99 static inline int osdcmd_quit(osdcmdptr_t UNUSED(parm))
100 {
101     UNREFERENCED_CONST_PARAMETER(parm);
102     OSD_ShowDisplay(0);
103     ShutDown();
104     return OSDCMD_OK;
105 }
106 
107 
osdcmd_restartvid(osdcmdptr_t UNUSED (parm))108 int osdcmd_restartvid(osdcmdptr_t UNUSED(parm))
109 {
110     UNREFERENCED_CONST_PARAMETER(parm);
111     videoResetMode();
112     if (videoSetGameMode(gSetup.fullscreen,gSetup.xdim,gSetup.ydim,gSetup.bpp,0))
113         bail2dos("restartvid: Reset failed...\n");
114     onvideomodechange(gSetup.bpp>8);
115     UpdateScreenSize();
116 
117     return OSDCMD_OK;
118 }
119 
osdcmd_vidmode(osdcmdptr_t parm)120 static int osdcmd_vidmode(osdcmdptr_t parm)
121 {
122     int32_t newbpp = gSetup.bpp, newwidth = gSetup.xdim,
123             newheight = gSetup.ydim, newfs = gSetup.fullscreen;
124     int32_t tmp;
125 
126     if (parm->numparms < 1 || parm->numparms > 4) return OSDCMD_SHOWHELP;
127 
128     switch (parm->numparms)
129     {
130     case 1: // bpp switch
131         tmp = Batol(parm->parms[0]);
132         if (!(tmp==8 || tmp==16 || tmp==32))
133             return OSDCMD_SHOWHELP;
134         newbpp = tmp;
135         break;
136     case 2: // res switch
137         newwidth = Batol(parm->parms[0]);
138         newheight = Batol(parm->parms[1]);
139         break;
140     case 3: // res & bpp switch
141     case 4:
142         newwidth = Batol(parm->parms[0]);
143         newheight = Batol(parm->parms[1]);
144         tmp = Batol(parm->parms[2]);
145         if (!(tmp==8 || tmp==16 || tmp==32))
146             return OSDCMD_SHOWHELP;
147         newbpp = tmp;
148         if (parm->numparms == 4)
149             newfs = (Batol(parm->parms[3]) != 0);
150         break;
151     }
152 
153     if (videoSetGameMode(newfs,newwidth,newheight,newbpp,upscalefactor))
154     {
155         initprintf("vidmode: Mode change failed!\n");
156         if (videoSetGameMode(gSetup.fullscreen, gSetup.xdim, gSetup.ydim, gSetup.bpp, upscalefactor))
157             bail2dos("vidmode: Reset failed!\n");
158     }
159     gSetup.bpp = newbpp;
160     gSetup.xdim = newwidth;
161     gSetup.ydim = newheight;
162     gSetup.fullscreen = newfs;
163     onvideomodechange(gSetup.bpp>8);
164     UpdateScreenSize();
165     return OSDCMD_OK;
166 }
167 
osdcmd_addpath(osdcmdptr_t parm)168 static int osdcmd_addpath(osdcmdptr_t parm)
169 {
170     if (parm->numparms != 1)
171         return OSDCMD_SHOWHELP;
172 
173     addsearchpath(parm->parms[0]);
174 
175     return OSDCMD_OK;
176 }
177 
osdcmd_initgroupfile(osdcmdptr_t parm)178 static int osdcmd_initgroupfile(osdcmdptr_t parm)
179 {
180     if (parm->numparms != 1)
181         return OSDCMD_SHOWHELP;
182 
183     initgroupfile(parm->parms[0]);
184 
185     return OSDCMD_OK;
186 }
187 
onvideomodechange(int32_t newmode)188 void onvideomodechange(int32_t newmode)
189 {
190     uint8_t palid = BASEPAL;
191 
192 #if 0
193 #ifdef POLYMER
194     if (videoGetRenderMode() == REND_POLYMER)
195     {
196         int32_t i = 0;
197 
198         while (i < MAXSPRITES)
199         {
200             if (actor[i].lightptr)
201             {
202                 polymer_deletelight(actor[i].lightId);
203                 actor[i].lightptr = NULL;
204                 actor[i].lightId = -1;
205             }
206             i++;
207         }
208     }
209 #endif
210 #endif
211 
212     videoSetPalette(0, palid, 0);
213 }
214 
osdcmd_button(osdcmdptr_t parm)215 static int osdcmd_button(osdcmdptr_t parm)
216 {
217     static char const s_gamefunc_[] = "gamefunc_";
218     int constexpr strlen_gamefunc_  = ARRAY_SIZE(s_gamefunc_) - 1;
219 
220     char const *p = parm->name + strlen_gamefunc_;
221 
222 //    if (g_player[myconnectindex].ps->gm == MODE_GAME) // only trigger these if in game
223     CONTROL_ButtonFlags[CONFIG_FunctionNameToNum(p)] = 1; // FIXME
224 
225     return OSDCMD_OK;
226 }
227 
228 const char *const ConsoleButtons[] =
229 {
230     "mouse1", "mouse2", "mouse3", "mouse4", "mwheelup",
231     "mwheeldn", "mouse5", "mouse6", "mouse7", "mouse8"
232 };
233 
osdcmd_bind(osdcmdptr_t parm)234 static int osdcmd_bind(osdcmdptr_t parm)
235 {
236     char tempbuf[256];
237     if (parm->numparms==1 && !Bstrcasecmp(parm->parms[0],"showkeys"))
238     {
239         for (auto & s : sctokeylut)
240             OSD_Printf("%s\n", s.key);
241         for (auto ConsoleButton : ConsoleButtons)
242             OSD_Printf("%s\n",ConsoleButton);
243         return OSDCMD_OK;
244     }
245 
246     if (parm->numparms==0)
247     {
248         int j=0;
249 
250         OSD_Printf("Current key bindings:\n");
251 
252         for (int i=0; i<MAXBOUNDKEYS+MAXMOUSEBUTTONS; i++)
253             if (CONTROL_KeyIsBound(i))
254             {
255                 j++;
256                 OSD_Printf("%-9s %s\"%s\"\n", CONTROL_KeyBinds[i].key, CONTROL_KeyBinds[i].repeat?"":"norepeat ",
257                            CONTROL_KeyBinds[i].cmdstr);
258             }
259 
260         if (j == 0)
261             OSD_Printf("No binds found.\n");
262 
263         return OSDCMD_OK;
264     }
265 
266     int i, j, repeat;
267 
268     for (i=0; i < ARRAY_SSIZE(sctokeylut); i++)
269     {
270         if (!Bstrcasecmp(parm->parms[0], sctokeylut[i].key))
271             break;
272     }
273 
274     // didn't find the key
275     if (i == ARRAY_SSIZE(sctokeylut))
276     {
277         for (i=0; i<MAXMOUSEBUTTONS; i++)
278             if (!Bstrcasecmp(parm->parms[0],ConsoleButtons[i]))
279                 break;
280 
281         if (i >= MAXMOUSEBUTTONS)
282             return OSDCMD_SHOWHELP;
283 
284         if (parm->numparms < 2)
285         {
286             if (CONTROL_KeyBinds[MAXBOUNDKEYS + i].cmdstr && CONTROL_KeyBinds[MAXBOUNDKEYS + i ].key)
287                 OSD_Printf("%-9s %s\"%s\"\n", ConsoleButtons[i], CONTROL_KeyBinds[MAXBOUNDKEYS + i].repeat?"":"norepeat ",
288                 CONTROL_KeyBinds[MAXBOUNDKEYS + i].cmdstr);
289             else OSD_Printf("%s is unbound\n", ConsoleButtons[i]);
290             return OSDCMD_OK;
291         }
292 
293         j = 1;
294 
295         repeat = 1;
296         if (!Bstrcasecmp(parm->parms[j],"norepeat"))
297         {
298             repeat = 0;
299             j++;
300         }
301 
302         Bstrcpy(tempbuf,parm->parms[j++]);
303         for (; j<parm->numparms; j++)
304         {
305             Bstrcat(tempbuf," ");
306             Bstrcat(tempbuf,parm->parms[j++]);
307         }
308 
309         CONTROL_BindMouse(i, tempbuf, repeat, ConsoleButtons[i]);
310 
311         if (!OSD_ParsingScript())
312             OSD_Printf("%s\n",parm->raw);
313         return OSDCMD_OK;
314     }
315 
316     if (parm->numparms < 2)
317     {
318         if (CONTROL_KeyIsBound(sctokeylut[i].sc))
319             OSD_Printf("%-9s %s\"%s\"\n", sctokeylut[i].key, CONTROL_KeyBinds[sctokeylut[i].sc].repeat?"":"norepeat ",
320                        CONTROL_KeyBinds[sctokeylut[i].sc].cmdstr);
321         else OSD_Printf("%s is unbound\n", sctokeylut[i].key);
322 
323         return OSDCMD_OK;
324     }
325 
326     j = 1;
327 
328     repeat = 1;
329     if (!Bstrcasecmp(parm->parms[j],"norepeat"))
330     {
331         repeat = 0;
332         j++;
333     }
334 
335     Bstrcpy(tempbuf,parm->parms[j++]);
336     for (; j<parm->numparms; j++)
337     {
338         Bstrcat(tempbuf," ");
339         Bstrcat(tempbuf,parm->parms[j++]);
340     }
341 
342     CONTROL_BindKey(sctokeylut[i].sc, tempbuf, repeat, sctokeylut[i].key);
343 
344     char *cp = tempbuf;
345 
346     // Populate the keyboard config menu based on the bind.
347     // Take care of processing one-to-many bindings properly, too.
348     static char const s_gamefunc_[] = "gamefunc_";
349     int constexpr strlen_gamefunc_  = ARRAY_SIZE(s_gamefunc_) - 1;
350 
351     while ((cp = Bstrstr(cp, s_gamefunc_)))
352     {
353         cp += strlen_gamefunc_;
354 
355         char *semi = Bstrchr(cp, ';');
356 
357         if (semi)
358             *semi = 0;
359 
360         j = CONFIG_FunctionNameToNum(cp);
361 
362         if (semi)
363             cp = semi+1;
364 
365         if (j != -1)
366         {
367             KeyboardKeys[j][1] = KeyboardKeys[j][0];
368             KeyboardKeys[j][0] = sctokeylut[i].sc;
369 //            CONTROL_MapKey(j, sctokeylut[i].sc, ud.config.KeyboardKeys[j][0]);
370 
371             if (j == gamefunc_Show_Console)
372                 OSD_CaptureKey(sctokeylut[i].sc);
373         }
374     }
375 
376     if (!OSD_ParsingScript())
377         OSD_Printf("%s\n",parm->raw);
378 
379     return OSDCMD_OK;
380 }
381 
osdcmd_unbindall(osdcmdptr_t UNUSED (parm))382 static int osdcmd_unbindall(osdcmdptr_t UNUSED(parm))
383 {
384     UNREFERENCED_CONST_PARAMETER(parm);
385 
386     for (int i = 0; i < MAXBOUNDKEYS; ++i)
387         CONTROL_FreeKeyBind(i);
388 
389     for (int i = 0; i < MAXMOUSEBUTTONS; ++i)
390         CONTROL_FreeMouseBind(i);
391 
392     for (auto &KeyboardKey : KeyboardKeys)
393         KeyboardKey[0] = KeyboardKey[1] = 0xff;
394 
395     if (!OSD_ParsingScript())
396         OSD_Printf("unbound all controls\n");
397 
398     return OSDCMD_OK;
399 }
400 
osdcmd_unbind(osdcmdptr_t parm)401 static int osdcmd_unbind(osdcmdptr_t parm)
402 {
403     if (parm->numparms != 1)
404         return OSDCMD_SHOWHELP;
405 
406     for (auto & ConsoleKey : sctokeylut)
407     {
408         if (ConsoleKey.key && !Bstrcasecmp(parm->parms[0], ConsoleKey.key))
409         {
410             CONTROL_FreeKeyBind(ConsoleKey.sc);
411             OSD_Printf("unbound key %s\n", ConsoleKey.key);
412             return OSDCMD_OK;
413         }
414     }
415 
416     for (int i = 0; i < MAXMOUSEBUTTONS; i++)
417     {
418         if (!Bstrcasecmp(parm->parms[0], ConsoleButtons[i]))
419         {
420             CONTROL_FreeMouseBind(i);
421             OSD_Printf("unbound %s\n", ConsoleButtons[i]);
422             return OSDCMD_OK;
423         }
424     }
425 
426     return OSDCMD_SHOWHELP;
427 }
428 
osdcmd_unbound(osdcmdptr_t parm)429 static int osdcmd_unbound(osdcmdptr_t parm)
430 {
431     if (parm->numparms != 1)
432         return OSDCMD_OK;
433 
434     int const gameFunc = CONFIG_FunctionNameToNum(parm->parms[0]);
435 
436     if (gameFunc != -1)
437         KeyboardKeys[gameFunc][0] = 0;
438 
439     return OSDCMD_OK;
440 }
441 
osdcmd_screenshot(osdcmdptr_t parm)442 static int osdcmd_screenshot(osdcmdptr_t parm)
443 {
444 //    KB_ClearKeysDown();
445     static const char *fn = "capt0000.png";
446 
447     if (parm->numparms == 1 && !Bstrcasecmp(parm->parms[0], "tga"))
448         videoCaptureScreenTGA(fn, 0);
449     else videoCaptureScreen(fn, 0);
450 
451     return OSDCMD_OK;
452 }
453 
osdcmd_cvar_set_game(osdcmdptr_t parm)454 static int osdcmd_cvar_set_game(osdcmdptr_t parm)
455 {
456     int const r = osdcmd_cvar_set(parm);
457 
458     if (r != OSDCMD_OK) return r;
459 
460     // TODO:
461     /*if (!Bstrcasecmp(parm->name, "r_upscalefactor"))
462     {
463         if (in3dmode())
464         {
465             videoSetGameMode(fullscreen, xres, yres, bpp, ud.detail);
466         }
467     }
468     else if (!Bstrcasecmp(parm->name, "r_size"))
469     {
470         ud.statusbarmode = (ud.screen_size < 8);
471         G_UpdateScreenArea();
472     }*/
473     else if (!Bstrcasecmp(parm->name, "r_maxfps") || !Bstrcasecmp(parm->name, "r_maxfpsoffset"))
474     {
475         if (r_maxfps != 0) r_maxfps = clamp(r_maxfps, 30, 1000);
476         g_frameDelay = calcFrameDelay(r_maxfps + r_maxfpsoffset);
477     }/*
478     else if (!Bstrcasecmp(parm->name, "r_ambientlight"))
479     {
480         if (r_ambientlight == 0)
481             r_ambientlightrecip = 256.f;
482         else r_ambientlightrecip = 1.f/r_ambientlight;
483     }
484     else */if (!Bstrcasecmp(parm->name, "in_mouse"))
485     {
486         CONTROL_MouseEnabled = (gSetup.usemouse && CONTROL_MousePresent);
487     }
488     else if (!Bstrcasecmp(parm->name, "in_joystick"))
489     {
490         CONTROL_JoystickEnabled = (gSetup.usejoystick && CONTROL_JoyPresent);
491     }
492     else if (!Bstrcasecmp(parm->name, "vid_gamma"))
493     {
494         // TODO
495         //ud.brightness = GAMMA_CALC;
496         //ud.brightness <<= 2;
497         //videoSetPalette(ud.brightness>>2,g_player[myconnectindex].ps->palette,0);
498     }
499     else if (!Bstrcasecmp(parm->name, "vid_brightness") || !Bstrcasecmp(parm->name, "vid_contrast"))
500     {
501         // TODO
502         //videoSetPalette(ud.brightness>>2,g_player[myconnectindex].ps->palette,0);
503     }
504     //else if (!Bstrcasecmp(parm->name, "hud_scale")
505     //         || !Bstrcasecmp(parm->name, "hud_statusbarmode")
506     //         || !Bstrcasecmp(parm->name, "r_rotatespritenowidescreen"))
507     //{
508     //    G_UpdateScreenArea();
509     //}
510     //else if (!Bstrcasecmp(parm->name, "skill"))
511     //{
512     //    if (numplayers > 1)
513     //        return r;
514     //
515     //    ud.player_skill = ud.m_player_skill;
516     //}
517     //else if (!Bstrcasecmp(parm->name, "color"))
518     //{
519     //    ud.color = G_CheckPlayerColor(ud.color);
520     //    g_player[0].ps->palookup = g_player[0].pcolor = ud.color;
521     //}
522     //else if (!Bstrcasecmp(parm->name, "osdscale"))
523     //{
524     //    osdrscale = 1.f/osdscale;
525     //
526     //    if (xdim && ydim)
527     //        OSD_ResizeDisplay(xdim, ydim);
528     //}
529     //else if (!Bstrcasecmp(parm->name, "wchoice"))
530     //{
531     //    if (parm->numparms == 1)
532     //    {
533     //        if (g_forceWeaponChoice) // rewrite ud.wchoice because osdcmd_cvar_set already changed it
534     //        {
535     //            int j = 0;
536     //
537     //            while (j < 10)
538     //            {
539     //                ud.wchoice[j] = g_player[myconnectindex].wchoice[j] + '0';
540     //                j++;
541     //            }
542     //
543     //            ud.wchoice[j] = 0;
544     //        }
545     //        else
546     //        {
547     //            char const *c = parm->parms[0];
548     //
549     //            if (*c)
550     //            {
551     //                int j = 0;
552     //
553     //                while (*c && j < 10)
554     //                {
555     //                    g_player[myconnectindex].wchoice[j] = *c - '0';
556     //                    c++;
557     //                    j++;
558     //                }
559     //
560     //                while (j < 10)
561     //                {
562     //                    if (j == 9)
563     //                        g_player[myconnectindex].wchoice[9] = 1;
564     //                    else
565     //                        g_player[myconnectindex].wchoice[j] = 2;
566     //
567     //                    j++;
568     //                }
569     //            }
570     //        }
571     //
572     //        g_forceWeaponChoice = 0;
573     //    }
574     //
575     //    /*    Net_SendClientInfo();*/
576     //}
577 
578     return r;
579 }
580 
registerosdcommands(void)581 int32_t registerosdcommands(void)
582 {
583     FX_InitCvars();
584     char tempbuf[256];
585     static osdcvardata_t cvars_game[] =
586     {
587         // TODO:
588         //{ "benchmarkmode", "Set the benchmark mode (0: off, 1: performance test, 2: generate reference screenshots for correctness testing)", (void *) &g_BenchmarkMode, CVAR_INT|CVAR_NOSAVE, 0, 2 },
589 
590         { "crosshair", "enable/disable crosshair", (void *)&gShowCrosshair, CVAR_BOOL, 0, 1 },
591 
592         //{ "cl_autoaim", "enable/disable weapon autoaim", (void *)&ud.config.AutoAim, CVAR_INT|CVAR_MULTI, 0, 3 },
593         //{ "cl_automsg", "enable/disable automatically sending messages to all players", (void *)&ud.automsg, CVAR_BOOL, 0, 1 },
594         { "cl_autorun", "enable/disable autorun", (void *)&auto_run, CVAR_BOOL, 0, 1 },
595 
596         //{ "cl_autosave", "enable/disable autosaves", (void *) &ud.autosave, CVAR_BOOL, 0, 1 },
597         //{ "cl_autosavedeletion", "enable/disable automatic deletion of autosaves", (void *) &ud.autosavedeletion, CVAR_BOOL, 0, 1 },
598         //{ "cl_maxautosaves", "number of autosaves to keep before deleting the oldest", (void *) &ud.maxautosaves, CVAR_INT, 1, 100 },
599 
600         //{ "cl_autovote", "enable/disable automatic voting", (void *)&ud.autovote, CVAR_INT, 0, 2 },
601 
602         //{ "cl_cheatmask", "configure what cheats show in the cheats menu", (void *)&cl_cheatmask, CVAR_UINT, 0, ~0 },
603 
604         //{ "cl_obituaries", "enable/disable multiplayer death messages", (void *)&ud.obituaries, CVAR_BOOL, 0, 1 },
605         //{ "cl_democams", "enable/disable demo playback cameras", (void *)&ud.democams, CVAR_BOOL, 0, 1 },
606 
607         //{ "cl_idplayers", "enable/disable name display when aiming at opponents", (void *)&ud.idplayers, CVAR_BOOL, 0, 1 },
608 
609         { "cl_runmode", "enable/disable modernized run key operation", (void *)&runkey_mode, CVAR_BOOL, 0, 1 },
610 
611 //        { "cl_showcoords", "show your position in the game world", (void *)&ud.coords, CVAR_INT, 0,
612 //#ifdef USE_OPENGL
613 //          2
614 //#else
615 //          1
616 //#endif
617 //        },
618 
619         //{ "cl_viewbob", "enable/disable player head bobbing", (void *)&ud.viewbob, CVAR_BOOL, 0, 1 },
620 
621         //{ "cl_weaponsway", "enable/disable player weapon swaying", (void *)&ud.weaponsway, CVAR_BOOL, 0, 1 },
622         //{ "cl_weaponswitch", "enable/disable auto weapon switching", (void *)&ud.weaponswitch, CVAR_INT|CVAR_MULTI, 0, 7 },
623 
624         //{ "color", "changes player palette", (void *)&ud.color, CVAR_INT|CVAR_MULTI, 0, MAXPALOOKUPS-1 },
625 
626         //{ "crosshairscale","changes the size of the crosshair", (void *)&ud.crosshairscale, CVAR_INT, 10, 100 },
627 
628         //{ "demorec_diffs","enable/disable diff recording in demos",(void *)&demorec_diffs_cvar, CVAR_BOOL, 0, 1 },
629         //{ "demorec_force","enable/disable forced demo recording",(void *)&demorec_force_cvar, CVAR_BOOL|CVAR_NOSAVE, 0, 1 },
630         //{
631         //    "demorec_difftics","sets game tic interval after which a diff is recorded",
632         //    (void *)&demorec_difftics_cvar, CVAR_INT, 2, 60*REALGAMETICSPERSEC
633         //},
634         //{ "demorec_diffcompress","Compression method for diffs. (0: none, 1: KSLZW)",(void *)&demorec_diffcompress_cvar, CVAR_BOOL, 0, 1 },
635         //{ "demorec_synccompress","Compression method for input. (0: none, 1: KSLZW)",(void *)&demorec_synccompress_cvar, CVAR_BOOL, 0, 1 },
636         //{ "demorec_seeds","enable/disable recording of random seed for later sync checking",(void *)&demorec_seeds_cvar, CVAR_BOOL, 0, 1 },
637         //{ "demoplay_diffs","enable/disable application of diffs in demo playback",(void *)&demoplay_diffs, CVAR_BOOL, 0, 1 },
638         //{ "demoplay_showsync","enable/disable display of sync status",(void *)&demoplay_showsync, CVAR_BOOL, 0, 1 },
639 
640         { "fov", "change the field of view", (void *)&gFov, CVAR_INT|CVAR_FUNCPTR, 60, 140 },
641 
642         //{ "hud_althud", "enable/disable alternate mini-hud", (void *)&ud.althud, CVAR_BOOL, 0, 1 },
643         //{ "hud_custom", "change the custom hud", (void *)&ud.statusbarcustom, CVAR_INT, 0, ud.statusbarrange },
644         //{ "hud_position", "aligns the status bar to the bottom/top", (void *)&ud.hudontop, CVAR_BOOL, 0, 1 },
645         //{ "hud_bgstretch", "enable/disable background image stretching in wide resolutions", (void *)&ud.bgstretch, CVAR_BOOL, 0, 1 },
646         //{ "hud_messagetime", "length of time to display multiplayer chat messages", (void *)&ud.msgdisptime, CVAR_INT, 0, 3600 },
647         //{ "hud_numbertile", "first tile in alt hud number set", (void *)&althud_numbertile, CVAR_INT, 0, MAXUSERTILES-10 },
648         //{ "hud_numberpal", "pal for alt hud numbers", (void *)&althud_numberpal, CVAR_INT, 0, MAXPALOOKUPS-1 },
649         //{ "hud_shadows", "enable/disable althud shadows", (void *)&althud_shadows, CVAR_BOOL, 0, 1 },
650         //{ "hud_flashing", "enable/disable althud flashing", (void *)&althud_flashing, CVAR_BOOL, 0, 1 },
651         //{ "hud_glowingquotes", "enable/disable \"glowing\" quote text", (void *)&hud_glowingquotes, CVAR_BOOL, 0, 1 },
652         //{ "hud_scale","changes the hud scale", (void *)&ud.statusbarscale, CVAR_INT|CVAR_FUNCPTR, 36, 100 },
653         //{ "hud_showmapname", "enable/disable map name display on load", (void *)&hud_showmapname, CVAR_BOOL, 0, 1 },
654         //{ "hud_stats", "enable/disable level statistics display", (void *)&ud.levelstats, CVAR_BOOL, 0, 1 },
655         //{ "hud_textscale", "sets multiplayer chat message size", (void *)&ud.textscale, CVAR_INT, 100, 400 },
656         //{ "hud_weaponscale","changes the weapon scale", (void *)&ud.weaponscale, CVAR_INT, 10, 100 },
657         //{ "hud_statusbarmode", "change overlay mode of status bar", (void *)&ud.statusbarmode, CVAR_BOOL|CVAR_FUNCPTR, 0, 1 },
658 
659 //#ifdef EDUKE32_TOUCH_DEVICES
660 //        { "hud_hidestick", "hide the touch input stick", (void *)&droidinput.hideStick, CVAR_BOOL, 0, 1 },
661 //#endif
662 
663         { "in_joystick","enables input from the joystick if it is present",(void *)&gSetup.usejoystick, CVAR_BOOL|CVAR_FUNCPTR, 0, 1 },
664         { "in_mouse","enables input from the mouse if it is present",(void *)&gSetup.usemouse, CVAR_BOOL|CVAR_FUNCPTR, 0, 1 },
665 
666         { "in_aimmode", "0:toggle, 1:hold to aim", (void *)&mouseaiming, CVAR_BOOL, 0, 1 },
667         {
668             "in_mousebias", "emulates the original mouse code's weighting of input towards whichever axis is moving the most at any given time",
669             (void *)&MouseBias, CVAR_INT, 0, 32
670         },
671         { "in_mousedeadzone", "amount of mouse movement to filter out", (void *)&MouseDeadZone, CVAR_INT, 0, 512 },
672         { "in_mouseflip", "invert vertical mouse movement", (void *)&mouseflip, CVAR_BOOL, 0, 1 },
673         { "in_mousemode", "toggles vertical mouse view", (void *)&aimmode, CVAR_BOOL, 0, 1 },
674 
675         { "in_mousexscale", "scale modifier for mouse x axis", (void*)&CONTROL_MouseAxesScale[0], CVAR_INT, 1, 65536 },
676         { "in_mouseyscale", "scale modifier for mouse y axis", (void*)&CONTROL_MouseAxesScale[1], CVAR_INT, 1, 65536 },
677 
678         { "mus_enabled", "enables/disables music", (void *)&MusicToggle, CVAR_BOOL, 0, 1 },
679         { "mus_volume", "controls music volume", (void *)&MusicVolume, CVAR_INT, 0, 255 },
680 
681         //{ "osdhightile", "enable/disable hires art replacements for console text", (void *)&osdhightile, CVAR_BOOL, 0, 1 },
682         //{ "osdscale", "adjust console text size", (void *)&osdscale, CVAR_FLOAT|CVAR_FUNCPTR, 1, 4 },
683 
684         //{ "r_camrefreshdelay", "minimum delay between security camera sprite updates, 120 = 1 second", (void *)&ud.camera_time, CVAR_INT, 1, 240 },
685         //{ "r_drawweapon", "enable/disable weapon drawing", (void *)&ud.drawweapon, CVAR_INT, 0, 2 },
686         { "r_showfps", "show the frame rate counter", (void *)&r_showfps, CVAR_INT, 0, 3 },
687         //{ "r_showfpsperiod", "time in seconds before averaging min and max stats for r_showfps 2+", (void *)&ud.frameperiod, CVAR_INT, 0, 5 },
688         //{ "r_shadows", "enable/disable sprite and model shadows", (void *)&ud.shadows, CVAR_BOOL, 0, 1 },
689         //{ "r_size", "change size of viewable area", (void *)&ud.screen_size, CVAR_INT|CVAR_FUNCPTR, 0, 64 },
690         //{ "r_rotatespritenowidescreen", "pass bit 1024 to all CON rotatesprite calls", (void *)&g_rotatespriteNoWidescreen, CVAR_BOOL|CVAR_FUNCPTR, 0, 1 },
691         //{ "r_upscalefactor", "increase performance by rendering at upscalefactor less than the screen resolution and upscale to the full resolution in the software renderer", (void *)&ud.detail, CVAR_INT|CVAR_FUNCPTR, 1, 16 },
692         { "r_precache", "enable/disable the pre-level caching routine", (void *)&useprecache, CVAR_BOOL, 0, 1 },
693 
694        // { "r_ambientlight", "sets the global map light level",(void *)&r_ambientlight, CVAR_FLOAT|CVAR_FUNCPTR, 0, 10 },
695         { "r_maxfps", "limit the frame rate",(void *)&r_maxfps, CVAR_INT|CVAR_FUNCPTR, 0, 1000 },
696         { "r_maxfpsoffset", "menu-controlled offset for r_maxfps",(void *)&r_maxfpsoffset, CVAR_INT|CVAR_FUNCPTR, -10, 10 },
697 
698         { "sensitivity","changes the mouse sensitivity", (void *)&CONTROL_MouseSensitivity, CVAR_FLOAT|CVAR_FUNCPTR, 0, 25 },
699 
700         //{ "skill","changes the game skill setting", (void *)&ud.m_player_skill, CVAR_INT|CVAR_FUNCPTR|CVAR_NOSAVE/*|CVAR_NOMULTI*/, 0, 5 },
701 
702         //{ "snd_ambience", "enables/disables ambient sounds", (void *)&ud.config.AmbienceToggle, CVAR_BOOL, 0, 1 },
703         { "snd_enabled", "enables/disables sound effects", (void *)&SoundToggle, CVAR_BOOL, 0, 1 },
704         { "snd_fxvolume", "controls volume for sound effects", (void *)&FXVolume, CVAR_INT, 0, 255 },
705         { "snd_mixrate", "sound mixing rate", (void *)&MixRate, CVAR_INT, 0, 48000 },
706         { "snd_numchannels", "the number of sound channels", (void *)&NumChannels, CVAR_INT, 0, 2 },
707         { "snd_numvoices", "the number of concurrent sounds", (void *)&NumVoices, CVAR_INT, 1, 128 },
708         //{ "snd_reversestereo", "reverses the stereo channels", (void *)&ud.config.ReverseStereo, CVAR_BOOL, 0, 1 },
709         //{ "snd_speech", "enables/disables player speech", (void *)&ud.config.VoiceToggle, CVAR_INT, 0, 5 },
710 
711         //{ "team","change team in multiplayer", (void *)&ud.team, CVAR_INT|CVAR_MULTI, 0, 3 },
712 
713         { "vid_gamma","adjusts gamma component of gamma ramp",(void *)&g_videoGamma, CVAR_FLOAT|CVAR_FUNCPTR, 0, 10 },
714         { "vid_contrast","adjusts contrast component of gamma ramp",(void *)&g_videoContrast, CVAR_FLOAT|CVAR_FUNCPTR, 0, 10 },
715         { "vid_brightness","adjusts brightness component of gamma ramp",(void *)&g_videoBrightness, CVAR_FLOAT|CVAR_FUNCPTR, 0, 10 },
716         //{ "wchoice","sets weapon autoselection order", (void *)ud.wchoice, CVAR_STRING|CVAR_FUNCPTR, 0, MAX_WEAPONS },
717     };
718 
719     //osdcmd_cheatsinfo_stat.cheatnum = -1;
720 
721     for (auto & cv : cvars_game)
722     {
723         switch (cv.flags & (CVAR_FUNCPTR|CVAR_MULTI))
724         {
725             case CVAR_FUNCPTR:
726                 OSD_RegisterCvar(&cv, osdcmd_cvar_set_game); break;
727             //case CVAR_MULTI:
728             //case CVAR_FUNCPTR|CVAR_MULTI:
729             //    OSD_RegisterCvar(&cv, osdcmd_cvar_set_multi); break;
730             default:
731                 OSD_RegisterCvar(&cv, osdcmd_cvar_set); break;
732         }
733     }
734 
735     //if (VOLUMEONE)
736     OSD_RegisterFunction("changelevel","changelevel <level>: warps to the given level", osdcmd_changelevel);
737     //else
738     //{
739     //    OSD_RegisterFunction("changelevel","changelevel <volume> <level>: warps to the given level", osdcmd_changelevel);
740     //    OSD_RegisterFunction("map","map <mapfile>: loads the given user map", osdcmd_map);
741     //    OSD_RegisterFunction("demo","demo <demofile or demonum>: starts the given demo", osdcmd_demo);
742     //}
743 
744     OSD_RegisterFunction("addpath","addpath <path>: adds path to game filesystem", osdcmd_addpath);
745     OSD_RegisterFunction("bind",R"(bind <key> <string>: associates a keypress with a string of console input. Type "bind showkeys" for a list of keys and "listsymbols" for a list of valid console commands.)", osdcmd_bind);
746     //OSD_RegisterFunction("cmenu","cmenu <#>: jumps to menu", osdcmd_cmenu);
747     //OSD_RegisterFunction("crosshaircolor","crosshaircolor: changes the crosshair color", osdcmd_crosshaircolor);
748 
749     for (auto & func : gamefunctions)
750     {
751         if (func[0] == '\0')
752             continue;
753 
754 //        if (!Bstrcmp(gamefunctions[i],"Show_Console")) continue;
755 
756         Bsprintf(tempbuf, "gamefunc_%s", func);
757 
758         char *const t = Bstrtolower(Xstrdup(tempbuf));
759 
760         Bstrcat(tempbuf, ": game button");
761 
762         OSD_RegisterFunction(t, Xstrdup(tempbuf), osdcmd_button);
763     }
764 
765     //OSD_RegisterFunction("give","give <all|health|weapons|ammo|armor|keys|inventory>: gives requested item", osdcmd_give);
766     OSD_RegisterFunction("god","god: toggles god mode", osdcmd_god);
767     //OSD_RegisterFunction("activatecheat","activatecheat <id>: activates a cheat code", osdcmd_activatecheat);
768 
769     OSD_RegisterFunction("initgroupfile","initgroupfile <path>: adds a grp file into the game filesystem", osdcmd_initgroupfile);
770 //#ifdef DEBUGGINGAIDS
771 //    OSD_RegisterFunction("inittimer","debug", osdcmd_inittimer);
772 //#endif
773     //OSD_RegisterFunction("music","music E<ep>L<lev>: change music", osdcmd_music);
774 
775     OSD_RegisterFunction("noclip","noclip: toggles clipping mode", osdcmd_noclip);
776 
777 
778     //OSD_RegisterFunction("printtimes", "printtimes: prints VM timing statistics", osdcmd_printtimes);
779 
780     //OSD_RegisterFunction("purgesaves", "purgesaves: deletes obsolete and unreadable save files", osdcmd_purgesaves);
781 
782     //OSD_RegisterFunction("quicksave","quicksave: performs a quick save", osdcmd_quicksave);
783     //OSD_RegisterFunction("quickload","quickload: performs a quick load", osdcmd_quickload);
784     OSD_RegisterFunction("quit","quit: exits the game immediately", osdcmd_quit);
785     OSD_RegisterFunction("exit","exit: exits the game immediately", osdcmd_quit);
786 
787     //OSD_RegisterFunction("restartmap", "restartmap: restarts the current map", osdcmd_restartmap);
788     //OSD_RegisterFunction("restartsound","restartsound: reinitializes the sound system",osdcmd_restartsound);
789     OSD_RegisterFunction("restartvid","restartvid: reinitializes the video mode",osdcmd_restartvid);
790     OSD_RegisterFunction("screenshot","screenshot [format]: takes a screenshot.", osdcmd_screenshot);
791 
792     //OSD_RegisterFunction("spawn","spawn <picnum> [palnum] [cstat] [ang] [x y z]: spawns a sprite with the given properties",osdcmd_spawn);
793 
794     OSD_RegisterFunction("unbind","unbind <key>: unbinds a key", osdcmd_unbind);
795     OSD_RegisterFunction("unbindall","unbindall: unbinds all keys", osdcmd_unbindall);
796     OSD_RegisterFunction("unbound", NULL, osdcmd_unbound);
797 
798     OSD_RegisterFunction("vidmode","vidmode <xdim> <ydim> <bpp> <fullscreen>: change the video mode",osdcmd_vidmode);
799 #ifdef USE_OPENGL
800     baselayer_osdcmd_vidmode_func = osdcmd_vidmode;
801 #endif
802 
803     return 0;
804 }
805 
GAME_onshowosd(int shown)806 void GAME_onshowosd(int shown)
807 {
808     // G_UpdateScreenArea();
809 
810     mouseLockToWindow((!shown) + 2);
811 
812     //osdshown = shown;
813 
814     // XXX: it's weird to fake a keypress like this.
815 //    if (numplayers == 1 && ((shown && !ud.pause_on) || (!shown && ud.pause_on)))
816 //        KB_KeyDown[sc_Pause] = 1;
817 }
818 
GAME_clearbackground(int numcols,int numrows)819 void GAME_clearbackground(int numcols, int numrows)
820 {
821     COMMON_clearbackground(numcols, numrows);
822 }
823 
824