58 Commits

Author SHA1 Message Date
Kawe Mazidjatari
72c71fac8b RTech: use Pak_UnloadAsyncAndWait for pak swap
Use the actual api as this allows for helping other jobs as well rather than burning all cpu in our own thread.
2024-11-17 11:51:45 +01:00
Kawe Mazidjatari
7a40db4d85 RTech: reverse engineer and document most of pak load api
Most of the pak load functions are now reverse engineered, documented and ready to be used from the API handle. Structure is confirmed to align with the engine.
2024-11-17 02:20:40 +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
35c6655e20 RTech: change async handle status struct name suffix
Changed suffix from '_t' to '_s' to maintain consistency throughout the rest of the RTech project.
2024-11-17 02:03:31 +01:00
Kawe Mazidjatari
1c36dfa484 RTech: rename member variables
The streaming asset counter only counts for optional assets. PakMemoryData_s::guidDescriptors should also be pageDescriptors.
2024-11-17 02:01:51 +01:00
Kawe Mazidjatari
3d56934cc0 RTech: reverse more fields for pak load system
Reversed more fields and cleaned up rebuilded routines. This will make debugging the system a lot easier.
2024-11-16 21:35:09 +01:00
Kawe Mazidjatari
19896857e2 RTech: disable assertion for log channels in FS_CloseAsyncFile
FS_OpenAsyncFile is inline in StreamDB_Init, and in our implementation, FS_OpenAsyncFile is the only place channel id's get mapped to file slots, so it will be null for stbsp's. Commented assert out as there isn't anything we could do about this besides rebuilding StreamDB_Init which is a large task.
2024-11-16 21:33:00 +01:00
Kawe Mazidjatari
1ec3df5874 RTech: add note for improvements in Pak_Swap_f
Should use the wait version of unload as that allows for helping other jobs and speeding up the process.
2024-11-16 15:41:06 +01:00
Kawe Mazidjatari
3f3b69e2bb RTech: use log channel of to-swap pak file
Reuse the channel id.
2024-11-16 15:40:19 +01:00
Kawe Mazidjatari
5d20256f10 RTech: user or script requested paks should use channel 8 2024-11-16 15:39:55 +01:00
Kawe Mazidjatari
03d19344fe RTech: implement pak and async read logging per channel
The engine assigns channel ID's to paks, which it then uses to determine whether to error out or warn when a certain pak file failed to load.

Paks loaded with a higher channel ID, such as the load screens or gladiator cards, won't call Error() in the engine if the loading thereof failed, where paks with a lower channel ID, such as common.rpak will.

Paks with a higher channel ID are quite verbose in the console, as the game often switches between gladiator card rpaks from scripts to update the banners in the world dynamically. User can now explicitly set the channel ID, with the default being 4 which only logs core engine and sdk paks, along with preloaded and level paks.

The async file read system uses a similar concept, this was confirmed when reversing Pak_SetupBuffersAndLoad as this calls FS_OpenAsyncFile for its patch files with the log channel that was assigned during Pak_LoadAsync. This code already had logging, but has been adjusted to follow the design of the system. Async file reads however are disabled by default as these are very verbose and will degrade performance of the game.
2024-11-16 15:28:53 +01:00
Kawe Mazidjatari
abe5578557 RTech: add param to LoadFromFile for parse failures
Gets set if parsing failed.
2024-11-14 13:38:28 +01:00
Kawe Mazidjatari
d95d071afd Tier1: properly implement ConVar change callbacks
Change callbacks actually take a structure of 2 pointers, one being for the callback itself, and the other being 'userdata' which typically is used to sync the ConVar with VGUI slider elements. This issue was noticed after implementing the ADS scalars and attempting to hook them up to VGUI, only to find out it would crash due to this lacking detail. All change callback prototypes had to be adjusted.
2024-08-05 00:45:30 +02:00
Kawe Mazidjatari
5223ac8631 RTech: refactor playlists reloading/caching
Mutex is technically no longer needed as imgui now draws in main and gets buffer swapped / rendered in the render thread just like the rest of the game. But the mutex was still in because of the shared script function 'Script_GetAvailablePlaylists' that can be used on the server. Both the 'playlist_reload' and 'downloadPlaylists' commands will now join the active server job if ran to prevent crashing in the engine or sdk when ran during the game.

There was also a performance difference between 'playlist_reload' and 'downloadPlaylists' while the commands are identical. There was a bug where the 'playlist_reload' one called 'Playlists_SDKInit' twice. This has also been fixed in this commit.
2024-08-03 12:06:42 +02:00
Kawe Mazidjatari
a1c9f3e49e RTech: enforce naming consistency in define names
renamed PLATFORM_PAK_PATH and PLATFORM_PAK_OVERRIDE_PATH.
2024-05-27 14:26:39 +02:00
Kawe Mazidjatari
bdca1a1644 RTech: improve concommand strings
Improve readability.
2024-05-26 22:21:02 +02:00
Kawe Mazidjatari
3f01894bfa RTech: fixed streamed pak decoding progression bug
During beta tests on a Linux system, we encountered an issue where the I/O could be slower and thus result in not enough bytes being streamed by the time we invoke the decoder (lenStreamed == bufSizeNeeded at this point), after 16 calls with lenStreamed == bufSizeNeeded, the engine errors as ZSTD_NO_FORWARD_PROGRESS_MAX would be reached. Added value of 'ZSTD_nextSrcSizeToDecompress()' to 'PakDecoder_s::bufferSizeNeeded' to make sure we never call the decoder without any new streamed bytes. Also increased the value of ZSTD_NO_FORWARD_PROGRESS_MAX to 1024 since this fixed the issue without applying the aforementioned patch, this was increased as a hardening measure.
2024-04-16 02:17:41 +02:00
Kawe Mazidjatari
2a85c7e5ac RTech: remove extraneous trailing semi-colon 2024-04-13 15:50:30 +02:00
Kawe Mazidjatari
b699fe431e RTech: use more consistent type names
Force consistency between type names (follow scheme used in tier0 and rtech_game export symbols).
2024-04-11 02:19:36 +02:00
Kawe Mazidjatari
e639cb3f5f RTech: rename pak defines
More correct and consistent naming.
2024-04-11 01:42:55 +02:00
Kawe Mazidjatari
5621976b33 RTech: take string pointer alignment into account
There are 2 versions of this function, one requires the string ptr to be aligned by 4.
2024-04-05 15:30:02 +02:00
Kawe Mazidjatari
eee86140f7 RTech: disable LiveAPI by default 2024-04-04 15:13:59 +02:00
Kawe Mazidjatari
47acaee320 RTech: implement Nucleus ID hashing for LiveAPI events
The field was supposed to be hashed, added cheap hashing logic and an option to truncate it to reduce overhead.
2024-04-04 01:56:31 +02:00
Kawe Mazidjatari
b916e11543 RTech: implement custom events and slight adjustments/improvements
Implemented CustomEvent in code, which supports:
- bool|int|float|string|vector|array|table
- nested arrays and tables, up to a depth of 64

Also improved foundation code for LiveAPI:
- added ability to log liveapi events to a file on the disk (rotates between each match or round, depending on how the abstracted functions are called in scripts)
- when the system is enabled through cvars, code will be invoked on the fly
- when the system is disabled through cvars, the system will be shutdown properly on the fly (properly handling socket closing, log file finishing, etc)
- if the socket system is enabled/disabled on the fly using cvars, related code will be called to initiate or shutdown the connections.

The generated proto.cpp/h file has been moved to the protoc project as it was causing some compiler warnings that we suppress on the thirdparty (vendored) code.
2024-04-03 01:26:53 +02:00
Kawe Mazidjatari
83b1f43dbc Engine: properly deal with server frame thread commands/convars
Marked convars/concommands as FCVAR_SERVER_FRAME_THREAD and removed main thread dispatching code and comments that are no longer in effect. In the RCONServer execute handler, a ThreadJoinServerJob() is placed if the commandbase is flagged FCVAR_SERVER_FRAME_THREAD since RCON dispatches the command, or sets the convar directly.
2024-04-01 01:02:02 +02:00
Kawe Mazidjatari
c4a0c0d6c8 RTech: finalize decouple of websocket system + improvements
The WebSocket system is now fully split up. The global network module initialization is moved to DLL init so the websocket class could be used for anything. The LiveAPI system now also mostly runs in the server frame thread, the convar change callbacks still need to be latched to the server frame thread however.
2024-03-31 16:13:03 +02:00
Kawe Mazidjatari
2d084db3a3 LiveAPI: initial WebSocket implementation
Working WebSocket implementation (foundation for game LiveAPI).
2024-03-25 01:26:33 +01:00
Kawe Mazidjatari
bd6ffaf226 RTech: mark cvars FCVAR_ACCESSIBLE_FROM_THREADS
Must be FCVAR_ACCESSIBLE_FROM_THREADS since they are used from different threads.
2024-02-25 21:16:39 +01:00
Kawe Mazidjatari
6828901815 Tier1: static construction of ConVar objects during link time
Fully implemented ConVar class so we could statically construct all SDK convars, this avoids a level of indirection, and allows for creating ConVar's everywhere in the project.

This patch also removed the settings tab of the ImGui server browser, as it has threading issues, while it technically never caused a crash yet, it has been removed as there was no point keeping it vs the work required to make it thread save (it only managed 2 convars which are perfectly manageable through cfg's or the in-game console).

Also temporarily disabled the creation of ConVar's in the mod system due to a memory leak, we would allocate and register a convar based on details parsed out of a mod file definition, but never unregister and free it.
2024-02-24 02:15:09 +01:00
Kawe Mazidjatari
3d36c87b08 Statically construct all ConCommand
Properly implement the ConCommandBase and ConCommand classes so we could statically construct all ConCommand objects in the global scope of each translation unit, this way we don't need to put them in a global file and deal with preprocessor directives to compile then in/out for certain projects.
2024-02-23 00:12:06 +01:00
Kawe Mazidjatari
79f8b46d62 RTech: major cleanup of pak globals and improvement
Add missing types to fully mapped out PakGlobals_s struct, which is a 13MiB+ structure! This covers the vast majority of the pakfile system which is why we had to change a bunch of stuff for this patch. This patch also comes with:

- Reversed 'JobFifoLock_s' structure
- Reversed 'PakTracker_s' structure
- Reversed 'PakAssetTracker_s' structure

Many globals have been dropped as they were covered by the large PakGlobals_s singleton.

The pak decoder logic has been changed up as well, we now use a decode mode enumerant which will make it easier to add in more decoders for the pak files in the future.
2024-02-22 02:09:28 +01:00
Kawe Mazidjatari
bed3bc87a0 RTech: mark const 2024-02-04 00:55:48 +01:00
Kawe Mazidjatari
e154762746 RTech: rename AsyncHandleTracker_t fields
Better names
2024-01-30 13:46:52 +01:00
Kawe Mazidjatari
07af98abd9 RTech: use Max() from our own headers 2024-01-30 13:46:31 +01:00
Kawe Mazidjatari
2a9ad5b382 RTech: cleanup & const correctness 2024-01-29 23:00:18 +01:00
Kawe Mazidjatari
82860e164b RTech: fix bug when string is NULL
Fixes a crash because string can be NULL when this is called
2024-01-29 23:00:18 +01:00
Kawe Mazidjatari
0452720cf8 RTech: fix numeric overflow caused by massive pak files
Pak files above 4GB caused the async file system to throw an error about failing to load audio banks, removed casts and promoted everything correctly. Also removed irrelevant comments in the public pakfile header.
2024-01-29 23:00:18 +01:00
Kawe Mazidjatari
52edcc6d84 RTech: fix bug when trying to print fourcc as string
The printf specifier does not allow limiting buffer reads. Made the FourCCToString more performant by using a fixed size stack array and creating the fourcc into that which we now use to properly print out the asset magic.
2024-01-29 23:00:18 +01:00
Kawe Mazidjatari
5ddf69c764 RTech: minor cleanup and renaming 2024-01-29 23:00:18 +01:00
Kawe Mazidjatari
a2d869d572 RTech: add buffered decompress function, cleanup and bug fixes
The pak_decompress callback has been fully moved to a dedicated buffered pak decoder function, also added descriptive error to the buffered pak encode function. Fixed a bug in the streamed pak decoder where the next required streamed buffer size would always be below actually required on any subsequent patch rpaks that are getting loaded. Also fixed assert in Pak_ZStreamDecode, as the inbuf position can equal total streamed size, but shall never exceed it!
2024-01-29 23:00:18 +01:00
Kawe Mazidjatari
511c700fde RTech: add several new pak tools
Added tools to reduce noise in pak code in a planned refactor
2024-01-29 23:00:18 +01:00
Kawe Mazidjatari
26ce3c50c2 RTech: cleanup ZStd pak decoder and fix bugs
* Pak_InitDecoder() now takes the output buf and mask as parameters.
* Pak_InitDecoder() checks if provided masks are a power of 2 (required).
* Pak_ComputeRingBufferFrame() now uses the bit mask instead of modulo to determine # bytes used.
* Fixed a bug where PakDecoder_t::bufferSizeNeeded could be bigger than the file stream, causing a deadlock.
2024-01-29 23:00:17 +01:00
Kawe Mazidjatari
86f9dbe30f RTech: move ZStd free code to actual decoder
Let the decoder free it to avoid memory leaks
2024-01-29 23:00:17 +01:00
Kawe Mazidjatari
9b9562c8d9 RTech: properly implement ring buffer stream decode for Zstd decoder
The new decoder can now decode patched and custom rpaks files, all issues so far have been fixed. The code still needs some testing and bench marking to make sure
2024-01-29 23:00:17 +01:00
Kawe Mazidjatari
e2898802e8 RTech: properly deal with patch headers when encoding pak files
Patch header must be updated to accommodate the new pak file sizes the patch pak patches.
2024-01-29 23:00:17 +01:00
Kawe Mazidjatari
b65d74e8c7 RTech: add helpers for parsing patch header data
Should significantly reduce noise in code
2024-01-29 23:00:17 +01:00
Kawe Mazidjatari
f61e2e1201 RTech: use define for invalid async file handle 2024-01-29 23:00:16 +01:00
Kawe Mazidjatari
31e9042eee RTech: add simple pak encoder command
Encodes a pak file with ZSTD.
2024-01-29 23:00:16 +01:00
Kawe Mazidjatari
1e949056ac RTech: remove temp debugging code 2024-01-29 23:00:16 +01:00
Kawe Mazidjatari
095f41bbe2 RTech: fix bug in decompress error format
Must not include pak header size since we parse compressed frame header and determine actual frame size from there, else we get 2 equal number that somehow don't equal (Pak_InitDecoder returns frame size + pak header size)
2024-01-29 23:00:16 +01:00