182 Commits

Author SHA1 Message Date
Kawe Mazidjatari
7a331284eb 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 18:42:31 +02:00
Kawe Mazidjatari
65eaade807 RTech: disable LiveAPI by default 2024-04-05 18:42:30 +02:00
Kawe Mazidjatari
873e20c121 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-05 18:42:29 +02:00
Kawe Mazidjatari
e91b8cfcec 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-05 18:39:36 +02:00
Kawe Mazidjatari
999ce009a8 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-05 18:35:06 +02:00
Kawe Mazidjatari
54ef6a78e8 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-04-05 18:33:09 +02:00
Kawe Mazidjatari
bea1deeb9d LiveAPI: initial WebSocket implementation
Working WebSocket implementation (foundation for game LiveAPI).
2024-04-05 18:30:22 +02:00
Kawe Mazidjatari
e141c529ac RTech: mark cvars FCVAR_ACCESSIBLE_FROM_THREADS
Must be FCVAR_ACCESSIBLE_FROM_THREADS since they are used from different threads.
2024-04-05 18:19:38 +02:00
Kawe Mazidjatari
609d705a0c 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-04-05 18:13:32 +02:00
Kawe Mazidjatari
d6b14fa12c 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-04-05 18:13:31 +02:00
Kawe Mazidjatari
6e7bfab4bd 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-04-05 18:13:31 +02:00
Kawe Mazidjatari
6edd80e506 RTech: mark const 2024-04-05 17:56:51 +02:00
Kawe Mazidjatari
63f55578eb RTech: rename AsyncHandleTracker_t fields
Better names
2024-04-05 17:56:50 +02:00
Kawe Mazidjatari
f78d04dda8 RTech: use Max() from our own headers 2024-04-05 17:56:50 +02:00
Kawe Mazidjatari
0b7805101c RTech: cleanup & const correctness 2024-04-05 17:56:50 +02:00
Kawe Mazidjatari
b92c2daea1 RTech: fix bug when string is NULL
Fixes a crash because string can be NULL when this is called
2024-04-05 17:56:50 +02:00
Kawe Mazidjatari
f5a8ca3e7a 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-04-05 17:56:49 +02:00
Kawe Mazidjatari
4d74dc5052 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-04-05 17:56:49 +02:00
Kawe Mazidjatari
082a8e4ef7 RTech: minor cleanup and renaming 2024-04-05 17:56:49 +02:00
Kawe Mazidjatari
3b9626612f 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-04-05 17:56:49 +02:00
Kawe Mazidjatari
c7471dc472 RTech: add several new pak tools
Added tools to reduce noise in pak code in a planned refactor
2024-04-05 17:56:49 +02:00
Kawe Mazidjatari
1c2b02b972 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-04-05 17:56:48 +02:00
Kawe Mazidjatari
5ea886ab65 RTech: move ZStd free code to actual decoder
Let the decoder free it to avoid memory leaks
2024-04-05 17:56:48 +02:00
Kawe Mazidjatari
e1c889719a 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-04-05 17:56:48 +02:00
Kawe Mazidjatari
e90349cc0f 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-04-05 17:56:48 +02:00
Kawe Mazidjatari
a529a16822 RTech: add helpers for parsing patch header data
Should significantly reduce noise in code
2024-04-05 17:56:48 +02:00
Kawe Mazidjatari
f16bf580f4 RTech: use define for invalid async file handle 2024-04-05 17:56:47 +02:00
Kawe Mazidjatari
7a03238fc9 RTech: add simple pak encoder command
Encodes a pak file with ZSTD.
2024-04-05 17:54:06 +02:00
Kawe Mazidjatari
3020abeed7 RTech: remove temp debugging code 2024-04-05 17:54:06 +02:00
Kawe Mazidjatari
da0ecd8ae1 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-04-05 17:54:06 +02:00
Kawe Mazidjatari
c4691448c1 RTech: initial custom pak compression implementation
Allows paks compressed with ZSTD, to be stream decoded at run time. Currently seems to work pretty good, but needs to be further battle tested + cleaned up still.
2024-04-05 17:54:05 +02:00
Kawe Mazidjatari
4662995f2e Playlists: fix resource/memory leak
Remove workaround that was implemented to counter a crash during the beginning of this project, this issue was long solved but the workaround was never removed. Clearing the last precached VPK name prevents the engine from helping other threads to properly unload existing handles, if at all.
2024-04-05 17:52:57 +02:00
Kawe Mazidjatari
fe2a95e4ec RTech: major pak system overhaul and rebuild
* split rtech_game and rtech_utils cpp files into multiple files
* rebuilt several large pak load routines for debugging and custom implementations
* moved rson code to rtech_game
* reworked and improved engine and sdk pak precache system
* reversed more of the jobthreads system
2024-04-05 17:51:19 +02:00
Kawe Mazidjatari
ee82d5d8e0 Tier1: move KeyValues class to Tier1
The KeyValues class belongs here. Also reimplemented most loading methods for KeyValues, and adjusted the VPK building code to account for it. Pointers to the engine's implementation of KeyValues have been moved to a separate header ('keyvalues_iface.h'), as this allows external tools code to utilize the standalone KeyValues class implementation. Playlist utilities are completely separated from the KeyValues header; these have nothing to do with KeyValues other than manipulating a global KeyValues object for the playlists, and thus have been named as such and moved to rtech/playlists.
2024-04-05 17:42:05 +02:00
Kawe Mazidjatari
edc52ad669 IDetour: remove extraneous pointer assignments
Originally, we store the search results in a CMemory instance which we then assign to the actual function pointer. CMemory is just a pointer class; we can assign the results directly to the actual function pointer. This commit reduces a lot of code verbosity, and also reduced roughly 2KiB worth of static pointers in the resulting executable. This commit also officially deprecates the support for any GameDLL's below S3 (Season 3), since it makes more sense to port the assets from earlier/later games back to the version this SDK supports.
2024-04-05 17:19:32 +02:00
Kawe Mazidjatari
144d5f62e1 IDetour: code refactor
Utilize the new IDetour::DetourSetup() code, IDetour::Attach and IDetour::Detach have been removed in favor of this (significantly reduces chance of user error). Since the template check happens in the idetour header, it is much more aggressive on type mismatches, such as a difference in parameter types, between the function and detour, will now raise a compile time error. As a result, some type mismatches have been fixed in this commit as well.
2024-04-05 16:41:09 +02:00
Kawe Mazidjatari
3b81e9e589 Pak load code refactor and improvements
Make pak code more consistent.
* Added 'Pak_CloseFile' to SDK.
* Added partial rebuild of 'Pak_ProcessPakFile' to SDK.
* Added compile time assert for 'PakFileHeader_t' structure.
2024-04-05 15:57:33 +02:00
Kawe Mazidjatari
d6fd782601 Add new RPak types and rename existing
Rename to enforce consistency.
2024-04-05 15:57:33 +02:00
Kawe Mazidjatari
3fd898bf30 Fix crash during RPak load
* Added missing parameter to 'PakLoadFuncs_s::WaitAsync'.
* Fix offset to 'g_pakLoadApi'.
2023-09-09 20:57:00 +02:00
Kawe Mazidjatari
9cfc2b4b6a Use actual pakLoadApi pointer
Actual pakLoadApi pointer used internally.
2023-09-08 23:52:00 +02:00
Kawe Mazidjatari
71b0781715 Utilize 'DevMsg()' for uncertain builds only
Only uncertain builds will contain DevMsg()/DevWarning() prints. For retail, Msg() and Warning() should be used instead.
2023-08-21 19:12:29 +02:00
Kawe Mazidjatari
2118ee6b48 Move RPak types to public header 2023-07-17 02:40:06 +02:00
Kawe Mazidjatari
f6f3c7f9a2 More code cleanup
- Set character set to multi-byte (this is because the game is also build with it).
- Utility function 'FileExists' now takes a raw string pointer, this avoids having to construct a fs::path each time its getting called (which is quite a lot!).
- Performed overall cleanup to code containing logic to override load paths. Mostly removing unnecessary copy constructions.
2023-07-03 02:14:39 +02:00
Kawe Mazidjatari
46390ba875 Additional reduction of untyped variables
These were not caught by the regex due to typos, or additional symbols that were not taken into account when making the regex.
2023-07-03 00:02:08 +02:00
Kawe Mazidjatari
87f9420889 Globally reduce the use of auto for function pointer declarations
Find regex pattern:
inline auto ([a-zA-Z0-9_]+) = ([a-zA-Z0-9_]+)\.RCast<([a-zA-Z0-9_:<>*]+) *\(\*\)\(([^)]*)\)>\(\);
Replace regex pattern:
inline $3(*$1)($4);

This commit also removes the unnecessary initialization (which was required to type the auto variables),
and therefore removed 6kb of unnecessary dynamic initialization code.
2023-07-02 23:01:29 +02:00
Kawe Mazidjatari
ef69611435 Replace memalloc calls throughout entire SDK
Global 'direct' usage of 'MemAllocSingleton()' has been jettisoned. Where possible, smart pointers were used instead. During the refactor, the following bugs were addressed and fixed:
- The virtual destructor of 'CCVarIteratorInternal' was NOT called on destruction.
- Class function 'KeyValues::MakeCopy' did NOT calculate the buffer size of the wide string correctly, the original calculation was 'len+1*sizeof(wchar_t)', but should've been '(len+1)*sizeof(wchar_t)'.

Some other code changes include:
- Tier0 include 'memstd.h' has been moved above all thirdparty includes, to make sure the memalloc functions get shadowed with ours in third party libraries as well.
- RPak file paths string literals are now defines.
- 'DestroyOverlay' has been refactored to match the assembly of the game.
2023-06-26 22:34:24 +02:00
Kawe Mazidjatari
3f8baf6f68 Allow setting compile options for specific targets
Previously, it was all controlled from the global init (applied to all projects), but some projects need different options. With these changes, you can disable the common options applied in the 'add_module' macro, and set your own if desired.
2023-06-17 00:45:27 +02:00
Kawe Mazidjatari
8acfad5556 Fix aligned memalloc singleton
Properly fix the aligned memalloc singleton in the SDK; the implementation now uses a callback based approach for calling the allocator and deallocator.
2023-05-15 20:47:17 +02:00
Kawe Mazidjatari
9f44bcc818 Treat compiler warnings as errors
Treat them as errors globally. Most of the time a warning is a bug, or problem in code that could be solved in a different (better) manner. Thirdparty code have this disabled. The warnings as errors option can be globally disabled through the CMake GUI, but this is not recommended.
2023-05-15 09:44:26 +02:00
Kawe Mazidjatari
8d38de1ce0 Move client only code from rtech libraries
Moved, and renamed to 'CreateTextureResource'. Reason for move was that the rtech libraries is used by server and client, and using this on dedicated requires linking directx libraries, as it has to be hooked (even when not used). Moved to client only code to avoid having to hook it. Material system is no longer linked to the dedicated server module, as nothing from it was getting used.
2023-05-13 18:03:48 +02:00