36 Commits

Author SHA1 Message Date
Kawe Mazidjatari
2c94c9907d Tier0: extra malloc override constification 2024-06-26 00:37:36 +02:00
Kawe Mazidjatari
a2acc45c5e Tier0: remove extraneous memset in '_recalloc_base'
CStdMemAlloc::Realloc already nulls memory, no need to memset it.
2024-06-24 00:34:16 +02:00
Kawe Mazidjatari
a5e05d3996 NetworkSystem: significant performance improvements
Now uses new JSON member lookup utilities implemented in commit f6e93ee457876ce869ce04067fe9344ff81083ca. All lookups (typically 3 per member) have been reduced to 1 by caching and reusing all value pointers or iterators. Also added error strings for 2 missing error cases in CPylon::GetEULA(), previously it would only set the error string during fetch error, but not when the data is missing or the schema is incorrect.
2024-06-11 10:16:16 +02:00
Kawe Mazidjatari
ee39e0b014 Tier2: move random generator from tier0 to tier2
Moved into cryptutils.cpp.
2024-04-10 15:28:47 +02:00
Kawe Mazidjatari
f8dd1fe88c Engine: implement encryption for RCON protocol
RCON lacked encryption, added AES-CTR encryption on RCON frames. Slightly adjusted protocol to take this into account (sending nonces, encrypted data itself, etc).
2024-04-10 14:08:52 +02:00
Kawe Mazidjatari
40f2c1374a Tier0: split CPU feature checks into multiple functions 2024-04-05 19:35:41 +02:00
Kawe Mazidjatari
504d042e60 Core: fix several initialization bugs
- Don't free console if the process is being closed from the console, this will cause the process to freeze within the FreeConsole() call
- Properly check for CPU features in order, and moved all checks to a single function utilizing the CPUInformation struct.
- Made SDK_Init() and SDK_Shutdown() more resilient against mistakes with new checks and error messages (added since they are exported now).
2024-04-04 18:49:00 +02:00
Kawe Mazidjatari
e40a661bca Tier0: move GetUnixTimeStamp() to utility code 2024-04-03 02:06:10 +02:00
Kawe Mazidjatari
091e9efa96 Tier0: fix pattern precaching
Fix taken from IcePixelx/silver-bun@e11bfb7fa7

We should migrate to the new header only implementation once there's more time to mifrate the code + testing it.
2024-04-03 01:44:08 +02:00
Kawe Mazidjatari
32828e4e52 Tier0: add new thread tools
- Add ThreadInMainOrServerFrameThread()
- Add ThreadCouldDoServerWork()
- Add ThreadJoinServerJob()
- Properly implement ThreadInServerFrameThread()
- Export all these functions for external DLL usage (plugins, etc)
2024-04-01 00:46:21 +02:00
Kawe Mazidjatari
77c0f5031b Tier0: JobThreads improvements
- Add JobUserData_s for JT functions (used as arguments for JT callbacks).
- Add JT_GetCurrentJob().
- Add JT_WaitForJobAndOnlyHelpWithJobTypes().
2024-04-01 00:36:52 +02:00
Kawe Mazidjatari
21ec76979a Tier0: implement CThreadSpinRWLock
Implementation matches that of the game executable, this will be used for CUtlStringTableMT.
2024-03-14 02:33:57 +01:00
Kawe Mazidjatari
420cb7a68d Engine: make task queue singleton static
Compile it as static object & renamed to more correct names. Also made the integral type for frame delay an unsigned int instead
2024-02-28 00:43:57 +01:00
Kawe Mazidjatari
e967cb374b Engine: render ImGui in main thread and fix many threading bugs
ImGui drawing code now takes place in the main thread, a snapshot of the render data is created in CMaterialSystem::SwapBuffers(), and is being rendered in the render thread right before SpinPresent().

The reason why this was necessary, is because ConVar::GetString() isn't thread safe if its not marked FCVAR_MATERIAL_SYSTEM_THREAD or FCVAR_ACCESSIBLE_FROM_THREADS, and we used it for the console suggestions window, which iterates over every ConVar, accessible from threads or not.

This is overall also a better code architecture.

This change also forced changes in the ImGui server browser window, which contained a bunch of threading bugs too.

Engine changes:
- g_pCVar is no longer exported, as this wasn't necessary in the end.
- g_ThreadMainThreadID and g_ThreadServerFrameThreadID are now exported from the game executable, as these are required as soon as the DLL is loaded.
2024-02-25 20:12:56 +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
cc8c5ee6b0 utility: fix STL string formatter bug
Must reserve a buf size of len+1 before resizing it, else we are 1 byte too short when copying the entire string. Also just clear when 0.
2024-02-06 14:36:01 +01:00
Kawe Mazidjatari
e728877035 Tier0: crash handler refactor & bug fix
Fix syntax error on page protection flags check when determining whether we encountered a return address. Also limit the amount of dynamic memory allocation calls, offer a large enough static buffer where we can just write into when we crash without needing to alloc or realloc anything. Also removed some hacky code like the whitelist set, and made the module handle array static into the class as well. The CrashHandler singleton is now a static class instance.
2024-02-04 00:55:07 +01:00
Kawe Mazidjatari
b89f72ac36 Tier0: iostream light cleanup
- Take const char* directly instead of making extraneous copies
- Add overload for reading strings into fixed size buffers
2024-02-03 23:34:14 +01:00
Kawe Mazidjatari
89ff792dd3 IOStream: improve seeking logic
Instead of seeking to the very start again when GetSize() is called, seek back to the original position. Also added dedicated methods for seeking put or get instead of using the mode since this is a fstream
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
5c0e7a944f Utility: fix bug in CreateDirHierarchy
Fix bug where even the last path would be processed in the loop, making the return call always return an error as the path would've been created by that time. This ensures that we always return the value returned by mkdir when creating the last path
2024-01-29 23:00:17 +01:00
Kawe Mazidjatari
7a09219002 FileSystem: make CreateDirHierarchy and IsDirectory general function
Moved to general utility
2024-01-29 23:00:17 +01:00
Kawe Mazidjatari
c9a9b01bf2 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-01-21 20:23:25 +01:00
Kawe Mazidjatari
8ce0412405 Tier0: cleanup CThreadFastMutex 2024-01-16 21:21:08 +01:00
Kawe Mazidjatari
65cdc0c75b Tier0: fix CThreadFastMutex bug
Must break if ThreadInterlockedCompareExchange returns null.
2024-01-16 20:57:28 +01:00
Kawe Mazidjatari
05a84339ce Tools: check CPU for SSE2
SSE and SSE2 instructions are being used, check for them instead of crashing somewhere in the program.
2024-01-12 15:49:22 +01:00
Kawe Mazidjatari
d21cf191f0 Tier0: fix netconsole and revpk compile error in debug
CCommandLine isn't implemented in tools, thus unresolved external symbol errors will be thrown. HushAsserts() was unused and therefore removed which fixes these errors.
2024-01-12 01:58:35 +01:00
Kawe Mazidjatari
078c241a0d Tools: rename NETCONSOLE define to _TOOLS
Rename since this would actually be used for all tools. Also moved 'plat_time.cpp' to tier0 so anything could compile it.
2024-01-12 00:25:19 +01:00
Kawe Mazidjatari
e825a1e7a8 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-01-02 15:21:36 +01:00
Kawe Mazidjatari
e541814482 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.
2023-11-26 13:21:20 +01:00
Kawe Mazidjatari
9145faafd5 Bump sigcache version to 2.8 and rename methods
Bump version and rename CSigCache::LoadCache to CSigCache::ReacCache.
2023-10-15 16:29:26 +02:00
Kawe Mazidjatari
6b344ad52f Only compile signature results in dev mode 2023-10-15 10:32:35 +02:00
Kawe Mazidjatari
ab1d28c778 Improve CPU detection code
Structure now fully aligns with that of the engine, with exception of newly added fields for the SDK (new fields are marked in the structure definition).
2023-10-08 16:27:10 +02:00
Kawe Mazidjatari
ffedb41705 Constness 2023-10-08 15:52:16 +02:00
Kawe Mazidjatari
d2495be72a Make ICpuTopology methods virtual
Virtual in the engine we are working on; this should be virtual too.
2023-10-06 21:29:46 +02:00
Kawe Mazidjatari
fd3e227a86 Align folder structure with p4 2023-09-19 22:13:22 +02:00