Properly unescape escaped characters in save file when loading (#185)
Modified PRVM_ED_ParseEdict to determine whether it is loading a save or
not, and unescape variables if loading a save.
Fixes https://github.com/DarkPlacesEngine/darkplaces/issues/81
bones_was_here [Tue, 28 May 2024 20:19:11 +0000 (06:19 +1000)]
Improve robustness of Con_CenterPrintf()
This code was OK, but if someone were to change the buffer size(s) such
that line[] were smaller than msg[], or were to call Con_CenterPrintf()
with a maxLineLength > 40, then a buffer overflow would have become
possible. This patch prevents it.
See https://github.com/DarkPlacesEngine/darkplaces/pull/159
James O'Neill [Tue, 28 May 2024 10:28:16 +0000 (19:28 +0900)]
Print centerprint messages to the console (#159)
Add new function `Con_CenterPrint` which can be used to print messages
to the console, without showing onscreen, and with a "horizontal rule"
above and below. Use `Con_CenterPrint` to log centerprint messages to
the console.
bones_was_here [Wed, 8 May 2024 21:16:53 +0000 (07:16 +1000)]
Refactor game/mod cvar defaults
Adds gamegroup defaults.
This avoids the need to specify the same Quake defaults for every Quake
expansion/mod.
Fixes newly-added Quake mods (quake15, ad) having global defaults
instead of Quake defaults.
Moves comments in front of the cvars they refer to, some were unclear.
bones_was_here [Tue, 7 May 2024 16:30:09 +0000 (02:30 +1000)]
particles: fix bugs in cl_particles_quake
There was a segfault when CL_NewQuakeParticle->CL_NewParticle returned
NULL, and a missing break; in case pt_snow: in R_RenderParticles causing
fall-through to pt_explode.
Introduced in 58dc7879146968c2c07e1ffd2c521487a5e768d9, I missed them in
code review, oops.
Could have just added checks for NULL in CL_ParticleExplosion but these
kinds of exceptions can get messy if several accumulate so it seemed
better to merge them into the API which also made NULL checks redundant.
Changes the particle_t comments to doxygen comments.
Fixes indenting.
bones_was_here [Tue, 7 May 2024 01:23:16 +0000 (11:23 +1000)]
PVS: dynamically allocate all FatPVS buffers
Some were dynamic, others weren't...
Fixes invisible entities and monsters ignoring the player on big/complex
maps, and undefined behaviour (reading past the end of the buffer).
Fixes https://gitlab.com/xonotic/darkplaces/-/issues/322
Adds Mem_Size() for retrieving the size of an allocation.
Simplifies some checks (we can check the pointer now so we dont need to
store byte counts just to see if there's any data).
bones_was_here [Mon, 6 May 2024 01:15:40 +0000 (11:15 +1000)]
sprites: fix misaligned memory access while loading (v2)
This reverts commit 0d5f8f0edd073d7ff233bde3995b529c0fcb67ff, that
approach didn't solve it for the other code path (used in mod "quake15")
so we need to memcpy each struct.
bones_was_here [Sun, 5 May 2024 19:13:34 +0000 (05:13 +1000)]
net: fix UB in VM_CL_getstati() and when sending the `items` stat
Simplifies the shifting in VM_CL_getstati() to avoid signed integer
overflow when the high bits are read with the arguments 23 and 9 (as
done in "quake15" and "ad" mods).
Refactors VM_CL_getstati() slightly, returns 0 when the index is out of
range (instead of whatever happened to be in that memory).
Masks off the bits that will overflow when packing the `items` stat for
sending (otherwise corruption of the low bits could occur on x86).
Q1BSP: add a workaround cvar for the Rogue lava men, use it when playing Rogue
This doesn't fix them, it just changes the behaviour of the map bug so
that they're stuck like in the original Quake engine. Fixing them
properly requires moving them, a .ent file is convenient for that.
Fixes MVM getgamedirinfo() builtin returning stale data (wasn't updated
by fs_rescan).
Fixes `startdemos` not working when changing to a mod that uses it,
after previously having had a map loaded.
Fixes `menu_main` being unavailable to quake.rc when changing to a mod
that uses it instead of `startdemos`.
Fixes `menu_restart` not performing the full MR_Init() (updates video
modes etc).
Fixes a race where it was possible to segfault by handling keyboard
events meant for MENU QC after MR_Shutdown() but before MR_Init() (by
calling directly instead of adding `menu_restart` to the cbuf).
Fixes an inconsistent extern declaration found by ubsan.
fs: recognise mods by -game cmdline args, deduplicate gamedirs, refactoring
Players often start mods using -game even when they have their own
cmdline option, and modders often provide scripts which use -game.
This was already implemented but only for the `gamedir` command.
Refactoring was required to avoid chicken vs egg problems when doing it
with cmdline gamedirs too.
Fixes a bug: the first gamedir (in the cmdline or `gamedir` args) was
used to identify the mod but it needs to be the last one that matches
because the last gamedir is the primary (first in the search path, and
where files are saved).
Includes supported game and mod directories in the main gamedir list for
interface consistency, less special cases, and to support deduplication.
Refactoring was required in the menu modlist where there was also an
opportunity to simplify.
Fixes inability to change from a supported mod (eg rogue) back to id1.
Bugs came from 270f020888c5a03b98cc7752957243e6123c1132 trying to use
NudgeOutOfSolid on Q1BSP which currently isn't possible, combined with
a map bug on alk_caustic, and unsticking unfortunately being an
essential part of Q1BSP player physics.
Adjusts cvar defaults to match Quake behaviour.
Improves documentation.
James O'Neill [Sun, 21 Apr 2024 15:28:29 +0000 (00:28 +0900)]
Accept "ctrl" + "=" for increasing console text size (#167)
Can't use the "=+" key to increase the console text size because the
code only wants "+"; ctrl+shift+= also does not work. Keypad + works.
This patch makes it accept the = key as well as +.
Fixes #110 .
See https://github.com/DarkPlacesEngine/darkplaces/pull/167
James O'Neill [Sun, 21 Apr 2024 15:07:23 +0000 (00:07 +0900)]
Merge PR 'Compare Q1BSP sky textures properly when loading'
Fixes https://github.com/DarkPlacesEngine/darkplaces/issues/58 by loading sky textures with CRC checking, previously they
were always considered duplicates by `R_SkinFrame_LoadInternalBGRA`
because they reuse the same names.
James O'Neill [Sun, 21 Apr 2024 14:44:09 +0000 (23:44 +0900)]
Merge PR 'Add support for a "give a" command to give player armour'
Allows the command `give a #` to give the player armour, just like the
other `give` commands. Based on the example code provided by Baker7.
Fixes #132 .
See https://github.com/DarkPlacesEngine/darkplaces/pull/136
Implements hardware refresh rate modesetting, this wasn't implemented
yet for SDL2 (although it was partially supported in c03b106680122333189e42294c4fb3c385307631).
Implements colour depth modesetting but leaves it disabled because
almost all display hardware supports 24bpp only.
Properly integrates desktopfullscreen and display selection into the
modesetting design.
Changes the modesetting design to better suit SDL2 (see comments),
using the code for immediately applying cvar changes in the startup path
too.
Disables immediate-apply of display cvar changes when hardware
modesetting is active and the player is accessing a menu, because
traditional menu designs don't support it: they make players scroll
through a list of resolutions, setting the cvars at each step.
Enables modesetting on Linux: turns out it does still work in SDL2 even
though exclusive fullscreen support was removed. SDL2 replaced
exclusive fullscreen with desktopfullscreen combined with an xrandr
modeset (behaves like desktopfullscreen IF the mode is the same
as the desktop one).
Replaces the 640x480 modesetting fallback with desktopfullscreen, should
be nicer and should always work (the old fallback is still there but
should never be reached).
Adds a debug print of all modes supported by the display (at startup).
Updates modesetting console prints.
Works around an SDL bug when increasing hardware resolution.
Works around an SDL bug where it doesn't set the error string in
SDL_GetClosestDisplayMode() so SDL_GetError would return some unrelated
message.
This uses a viddef_mode_t `vid.mode` in the global viddef_t `vid`
instead of having a separate declaration of each var there, makes
copying it more efficient.
Moves setting of cvars from VID_Mode into VID_Restart_f because we only
need to do it if a vid_restart fails after changes were made, during
normal startup the only source of config changes is the fallbacks cvar
array which already sets them as they're tested.
This avoids unnecessary clobbering and callbacks under normal
circumstances and makes vid_restart code more self-contained.
Refers to cvars by pointer instead of string for robustness.
Removes persistent storage of last known good mode, it's only needed in
VID_Restart_f and it would be verbose and error-prone to keep it updated
as well as the current mode when applying cvar changes and SDL events.
VS2019: get more of the targets to build (needed to specify modern C
standard for all of them, and SDK "10.0" seems to mean "use latest
version installed").
VS2019: improve README.md instructions.
Makefile: fix PEDANTIC=1 test builds and warning spam.
sys: properly fix warnings related to SDL's wrapping of main() for all
platforms.
James O'Neill [Fri, 12 Apr 2024 12:53:38 +0000 (21:53 +0900)]
Merge PR 'Make particles solid squares when cl_particles_quake is set to 2'
This creates a new function, CL_NewQuakeParticle, that is used instead of CL_NewParticle when cl_particles_quake is enabled. The function calls CL_NewParticle with a some hardcoded defaults to make the particle texture a disc, or solid square, based on the value of cl_particles_quake.
Improves particle function documentation.
See https://github.com/DarkPlacesEngine/darkplaces/pull/137
Updates .gitignore to exclude all generated build objects and the
downloaded NuGet packages (VS downloads them automatically if missing,
seems better than storing old versions here).
Removes files from legacy VS versions.
The resulting build isn't usable for playing (see README.md).
Maybe someone who uses this platform can fix it.
d33a1d0ffb434270de498c386271e484f90e6716 didn't actually work cos I
hadn't found where the good SDL documentation was, and didn't have a
high DPI Windows test machine.
Uses CLOCK_MONOTONIC_RAW on Linux, this is unaffected by synchronisation
adjustments and is used by SDL_GetPerformanceCounter() (we'll use it
directly to support dedicated servers without SDL).
Removes gettimeofday() and usleep() which were marked obsolete and
removed in POSIX.1-2008 so the old comment // FIXME improve this check
was impossible to address. The gettimeofday() replacement is very well
tested now (sys_useclockgettime 1 is default even in div0-stable).
Removes host_maxwait as the problems it worked around were fixed.
For 231beb2c234914f942166eb152c44e55b5b01f86 I tested incorrectly, using
Task Manager inside the VM which reports low CPU load even when spinning.
DP's `status` command showed the correct result.
Changes the default path from select() to: usleep() on POSIX, Sleep() on
Windows.
bones_was_here [Thu, 7 Mar 2024 20:31:33 +0000 (06:31 +1000)]
sys: allow the platform to handle crashes after DP does
As suggested by divVerent in chat.
In SDL builds (including when using -dedicated on the cmdline) the OS
handler runs after the user clicks OK on the SDL dialog.
bones_was_here [Thu, 7 Mar 2024 18:32:06 +0000 (04:32 +1000)]
Make the Sys_Error() message more informative
Re: 24550510e6ff331c1749707df7fad608f618bdd3 as discussed in chat, there
was a good reason to change this word: it indicates DP deliberately
stopped execution, whereas "Error" is generic (most problems that can
happen on a computer are some form of error). Also "Engine Error"
makes it sound like there's a bug in DP, which isn't necessarily the
case: there are several scenarios where user error can trigger this.
This message was already different from Quake's "Quake Error".
Pragmatically speaking, absent any good reason otherwise, naming conventions for functions like Sys_Error should remain consistent with Quake for developer sanity.
bones_was_here [Sun, 11 Feb 2024 13:54:39 +0000 (23:54 +1000)]
PRVM: refactor error handling
Cleans up PRVM_Crash() calling and removes redundant code.
Directs menu errors to stderr instead of stdout.
Aborts if a loop is detected in MVM_error_cmd(), matching Host_Error().
Prevents QC's CSQC_Shutdown() being called when CSQC crashes.
Makes cvar prvm_errordump ignore MENUQC crashes.
Improves some messages and comments.
bones_was_here [Sun, 25 Feb 2024 22:27:35 +0000 (08:27 +1000)]
PRVM: don't break csqc when menuqc has a problem
Fixes a regression in 3d84db99ed9d8234809d237512f44cfa6d7ce1a0 caused by
moving this line such that it executes even for MVM errors. We don't
need it because it's done by Host_Error->CL_DisconnectEx->CL_VM_ShutDown