202 Commits

Author SHA1 Message Date
Kawe Mazidjatari
dea3888973 Engine: improve type usage consistency
RCON was using buffer types and size types inconsistently, which required having to do many casts. Normalized type usage to reduce the number of casts required.
2025-02-09 19:04:48 +01:00
Kawe Mazidjatari
f2e332efa0 Common: improve type name consistency
CConnectedNetConsoleData is a struct and thus renamed to ConnectedNetConsoleData_s.
2025-02-09 17:10:53 +01:00
Kawe Mazidjatari
7de9196d7d Engine: optimize and harden RCON message processor
- Directly copy available bytes into message buffer instead of 1 per iteration.
- Use an actual frame header and make desync error detection more robust.
2025-02-09 17:05:41 +01:00
Kawe Mazidjatari
905f496474 NetCon: add new net console types
Will be used to replace the current frame prefix header.
2025-02-09 16:56:14 +01:00
Kawe Mazidjatari
5d7c94ae2f Engine: improve CNetConBase::Recv
- ::recv with MSG_PEEK still needs to know the full buffer length.
- Improve disconnect reason.
2025-02-09 16:36:08 +01:00
Kawe Mazidjatari
3c30d959dd Engine: fix uncontrolled format string vulnerability
This code is only ever used by the master server, but we should still avoid uncontrolled format strings from anything providing it remotely.
2025-02-09 02:07:19 +01:00
Kawe Mazidjatari
b0423ee74b Engine: use a more sane limit for desync check
m_RecvBuffer.max_size() can be very large, just check on RCON_MAX_PAYLOAD_SIZE (1 MiB), if its larger than that, then the stream has definitely being desynced or malformed. Also drop the client on null payloads because the payload should never be 0.
2025-02-09 01:58:32 +01:00
Kawe Mazidjatari
fdab5dea84 Engine: clamp sv_rcon_maxframesize
Make sure it cannot be set to very high numbers, making the protection guard useless.
2025-02-09 01:38:07 +01:00
Kawe Mazidjatari
f491f3dfe3 Engine: fix regression in message processor
Old regression that was caused by implementing the ability to disconnect the socket from anywhere in the rcon code, but it was never accounted for in CNetConBase::ProcessBuffer() and CNetConBase::Recv(). ProcessBuffer() must return directly when ProcessMessage() failed, and Recv() must break out if ProcessBuffer() returned false.
2025-02-09 01:37:09 +01:00
Kawe Mazidjatari
b1d81e2dc5 Engine: strong optimizations for RCON system
- All serializations now expect exact buffer lengths (which we knew for every call, but didn't make use of).
- The prefix is now also constructed directly into the send buffer
- The send buffer copies have been completely removed, the data that has been rendered into the only existing buffer will be used directly.
2025-02-09 01:23:05 +01:00
Kawe Mazidjatari
e223cec9c2 Engine: don't grow the string buffer
Just switch the format string instead, avoids reallocs.
2025-02-09 00:52:32 +01:00
Kawe Mazidjatari
7607ca073f Engine: fix typo 2025-02-09 00:51:51 +01:00
Kawe Mazidjatari
ff303d5de8 Engine: add pak to load after common_early
common_roots.rpak is loaded directly after common_early.rpak, and is necessary to store player layouts (these must be loaded before common.rpak is loaded to preserve the correct order of the linked list).
2025-02-05 00:47:04 +01:00
Kawe Mazidjatari
eaf313ab7a Engine: don't wait on ui_sdk.rpak for dedicated
Dedicated shouldn't load any ui pak file.
2025-02-04 17:32:20 +01:00
Kawe Mazidjatari
e8fc542907 Engine: light cleanup for Mod_QueuedPakCacheFrame 2025-02-04 17:30:57 +01:00
Kawe Mazidjatari
e55975100e Engine: wait for all paks before releasing FIFO lock
Make sure that every pak is fully loaded before we continue with the level load. Previously we would only wait on paks loaded by CommonPakData_s, but we should also wait on paks loaded by CustomPakData_s. This fixes all rare crash cases caused by this.
2025-02-03 21:15:42 +01:00
Kawe Mazidjatari
949b71a162 Engine: unload paks in FILO order
Due to the rework on repak and the ability to rebuilt entire map rpaks in original quality, we no longer need to do the hack of unloading paks in FIFO order. Properly unload all SDK paks in the same order engine paks are unloaded, which is FILO.
Custom level paks are now also loaded after mp_lobby.rpak, this allows custom level paks to use assets from mp_lobby too without having to copy them over.
2025-02-03 15:43:58 +01:00
Kawe Mazidjatari
c4bf79376e Engine: enforce type name consistency on runtime pak symbols
Make it consistent with the rest of the code base.
2025-02-03 14:06:45 +01:00
Kawe Mazidjatari
d810768895 Engine: use correct method for detouring datablock processor
Should be using DetourSetup here as that one handles attaching and detaching.
2025-02-03 13:22:37 +01:00
Kawe Mazidjatari
c8ee0d4333 Core: improve logger performance
- Drop the need for the ImGui logger sink, we can just use the buffer we already rendered into for the terminal sink.
- Remove ANSI rows inserted by the logger before file logging using offsets and ranges to significantly improve the performance.
- For ANSI row constants, use std::string so appending can use the precomputed string length instead of running strlen() each time internally.
2025-02-02 14:47:57 +01:00
Kawe Mazidjatari
c8c321e924 Server: use dedicated types for nucleus ID
This isn't a bug fix but a style fix as we should use NucleusID_t for anything that is a nucleus ID. This type is also of uint64.
2025-01-26 11:55:36 +01:00
Kawe Mazidjatari
18f2e27409 Engine: implement support for loading ui_mainmenu.rpak
For future updates, this allows for customizing the main menu to its full extend without modifying larger ui rpak files as we separate all title screen assets and put it into this new pak.
2025-01-09 17:08:47 +01:00
Kawe Mazidjatari
03dd7046a6 Engine: use correct format specifiers for edict_t
edict_t is an u16 and will always be as that is the type it uses in the engine itself.
2025-01-09 17:06:29 +01:00
Kawe Mazidjatari
eee6aed033 Engine: qualify functions as static where possible 2025-01-09 17:05:28 +01:00
Kawe Mazidjatari
c2deaaf3e8 DebugSurface: implement new texture streaming debug overlay
Implement a new imgui based texture streaming overlay. The old one typically clips out of the screen and cannot be explored.
2025-01-08 21:44:14 +01:00
Kawe Mazidjatari
6a8eb40930 Engine: light cleanup on CVEngineServer 2024-12-05 20:05:39 +01:00
Kawe Mazidjatari
8c85e1ec68 Revert "Engine: properly detect if we are in single player mode"
This reverts commit 9939d963efa13332a1b9c2cf0d53bd90bc772ed1. It turns out we actually should check on !g_pServer->IsActive() as we shouldn't restrict on our listen server. Development code heavily relies on this.
2024-12-05 20:05:13 +01:00
Kawe Mazidjatari
9939d963ef Engine: properly detect if we are in single player mode
This check is meant to drop the restrictions if we are in single player mode, we should however properly check in this by checking the actual game mode rather than if the listen server is running.
2024-12-05 15:57:48 +01:00
Kawe Mazidjatari
3209af9a6c Engine: large server host code refactor
This code was written at the start of the project before much of the engine was reverse engineered. There were some design problems where core server functions were shared with UI script.

A second problem was that not everything was properly synced between another; CServerHostManager held its own instance of the server name and server description, while the engine has actual convars to store these. So scripters weren't able to get the server name and server description if the server was a listen server and launched through the title screen.

The CServerHostManager class has been reworked to not keep a second instance, and the script functions for creating the servers have been reworked to always store the name and description in aforementioned convars.

Also moved the CreateServer and DestroyServer function to the UI namespace of scripts, and it is now only registered in UI context. The server should use GameRules_ChangeMap() to switch levels instead.

UI script also no longer registers core server functions, this was a design mistake and has been fully factored out in this patch.

The server script function 'SetClassVarSynced' has also been deprecated and removed, since calling this sends a netmsg to all connected clients, and running this once will not apply the new class var values to clients connecting afterwards. This should be managed through player.SetClassVar in the connect codecallbacks in scripts.
2024-12-05 15:53:40 +01:00
Kawe Mazidjatari
77851d9ad7 ImguiSystem: reset keydown state properly once window closes
In commit 1fd4c25cd0188f96c7d1fe7b0a8b072763eed032, an attempt was made to fix this by calling the message handler with WM_NULL, but WM_KILLFOCUS should've been passed instead, as Dear ImGui clears the keydown state with this message. WM_NULL does nothing.
2024-11-28 00:26:15 +01:00
Kawe Mazidjatari
c8e8bea154 Windows: remove extraneous code
PostMessage hooks are no longer needed as we properly handle the messages when the imgui window procedure is running. The g_nWindowRect global is also no longer necessary because we now properly update the CGame's window size members as of commit 7ec1e679fd2676cde8e286812a0f5bec454f7d92.
2024-11-24 14:52:31 +01:00
Kawe Mazidjatari
7ee1626233 Engine: add setters for game window rect 2024-11-24 14:45:02 +01:00
Kawe Mazidjatari
fd04eef1ce ImguiSystem: add method for checking if we have an active surface 2024-11-24 14:02:37 +01:00
Kawe Mazidjatari
c09e6d6948 Engine: expose Host_Error
Should be callable by other code.
2024-11-24 12:12:38 +01:00
Kawe Mazidjatari
ec77faeb97 Engine: fix incorrect function pointer for sigscan debugger 2024-11-24 12:07:43 +01:00
Kawe Mazidjatari
ab0ec34e80 Engine: fix underflow vulnerability in CL_CopyNewEntity
Code only checked upper bounds, this patch adds an additional lower bounds check.
2024-11-24 12:05:49 +01:00
Kawe Mazidjatari
2128b0ad04 Engine: properly handle under/overflows in CL_CopyExistingEntity
The engine expects the pbError parameter to be set when there is an error. Also call Host_Error to let the user know why we errored out.
2024-11-24 12:03:08 +01:00
Kawe Mazidjatari
10b466bde7 Engine: use new reverse engineered types for CL_CopyExistingEntity 2024-11-24 11:59:55 +01:00
Kawe Mazidjatari
ffbbbfc483 Engine: fully reverse engineer CEntityInfo & CEntityReadInfo 2024-11-24 11:55:53 +01:00
Kawe Mazidjatari
1fd4c25cd0 Engine: fix imgui regression causing inputs to be stuck
Holding a key while closing the panel will keep the message in the event queue, the next time one of the windows are opened, the message will be spammed. Send a null msg to clear it properly.
2024-11-24 00:40:44 +01:00
Kawe Mazidjatari
f212e96a96 Engine: decouple imgui window procedure from main
Light cleanup.
2024-11-20 17:12:42 +01:00
Kawe Mazidjatari
3eea52b199 RTech: rename pak fifo lock state pointer
Should be called g_bPakFifoLockAcquiredInMainThread, as the system has to account for the lock depth if the lock was acquired in the main thread.
2024-11-17 02:19:54 +01:00
Kawe Mazidjatari
d4d2244b93 Engine: inherit IEngineAPI through CTier1AppSystem
Must be inherited through CTier1AppSystem to match the game's interface. Removed extraneous IAppSystem virtual method declarations as they are no longer needed to pad the vftable out.
2024-11-15 15:24:55 +01:00
Kawe Mazidjatari
1e7bfcde2e AppFrameWork: adjust IAppSystem interface
In this engine, GetTier() doesn't exist, GetDependencies() however does exist (confirmed by the vftable for CInputStackSystem) and therefore we should adjust all interfaces to make it use this instead.
2024-11-15 14:58:57 +01:00
Kawe Mazidjatari
bc54931408 Engine: detour function CEngineAPI::OnStartup()
Allows for initializing SDK code before or after CEngineAPI::OnStartup().
2024-11-15 13:49:29 +01:00
Kawe Mazidjatari
f0fcb821a8 Engine: only call ImguiSystem message handler when imgui surface is active
Save even more performance by not calling the ImguiSystem message handler at all when the imgui surface isn't active; we don't need to track input movement at all when this isn't active. Also dropped the blockage of all window messages except 'WM_SETCURSOR', added a detailed comment as to why this is blocked.
2024-11-15 13:40:39 +01:00
Kawe Mazidjatari
36bee21784 Engine: set correct type for member variable
Member variable 'm_pInputContext_Maybe' is confirmed to be 'm_hInputContext', set correct type.
2024-11-15 13:38:02 +01:00
Kawe Mazidjatari
14e0c8f5e4 Engine: separate server and client offline configuration files
Dedicated server or Client only builds will warn to the console if something is trying to set a convar, or execute a concommand that doesn't exist. Dedicated server builds don't have client commands/convars, and visa versa.
2024-11-14 15:49:57 +01:00
Kawe Mazidjatari
3d5ddd2bed Client: update the "name" convar in "cl_setname" concommand callback
Update the name everywhere in code.
2024-11-14 15:44:27 +01:00
Kawe Mazidjatari
e8fe12b4fd Engine: fix heap buffer overflow
Should always leave 1 byte for the null terminator in the persona name buffer.
2024-11-14 15:26:40 +01:00