345 Commits

Author SHA1 Message Date
Kawe Mazidjatari
90e4711425 Tier2: move random generator from tier0 to tier2
Moved into cryptutils.cpp.
2024-06-01 11:25:58 +02:00
Kawe Mazidjatari
b26ed2f746 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-06-01 11:24:47 +02:00
Kawe Mazidjatari
f18829a487 Tier0: split CPU feature checks into multiple functions 2024-06-01 11:16:46 +02:00
Kawe Mazidjatari
bf5dd318a7 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-05 18:42:30 +02:00
Kawe Mazidjatari
1e8dd63e4c Tier0: move GetUnixTimeStamp() to utility code 2024-04-05 18:40:36 +02:00
Kawe Mazidjatari
a26e51ae00 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-05 18:40:36 +02:00
Kawe Mazidjatari
25e5bb667d 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-05 18:35:06 +02:00
Kawe Mazidjatari
fa421f259c Tier0: JobThreads improvements
- Add JobUserData_s for JT functions (used as arguments for JT callbacks).
- Add JT_GetCurrentJob().
- Add JT_WaitForJobAndOnlyHelpWithJobTypes().
2024-04-05 18:35:05 +02:00
Kawe Mazidjatari
615598c1b9 Tier0: implement CThreadSpinRWLock
Implementation matches that of the game executable, this will be used for CUtlStringTableMT.
2024-04-05 18:26:04 +02:00
Kawe Mazidjatari
23a3c8fc00 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-04-05 18:19:39 +02:00
Kawe Mazidjatari
6cf88dc16c 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.
2024-04-05 18:17:12 +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
115b8e214a 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-04-05 17:56:53 +02:00
Kawe Mazidjatari
6434b8abe9 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-04-05 17:56:51 +02:00
Kawe Mazidjatari
eae0d0964b Tier0: iostream light cleanup
- Take const char* directly instead of making extraneous copies
- Add overload for reading strings into fixed size buffers
2024-04-05 17:56:51 +02:00
Kawe Mazidjatari
f2e49c8a4a 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-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
3eb3c27975 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-04-05 17:56:48 +02:00
Kawe Mazidjatari
22431e903c FileSystem: make CreateDirHierarchy and IsDirectory general function
Moved to general utility
2024-04-05 17:56:48 +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
50761d24a8 Tier0: cleanup CThreadFastMutex 2024-04-05 17:46:56 +02:00
Kawe Mazidjatari
177078813b Tier0: fix CThreadFastMutex bug
Must break if ThreadInterlockedCompareExchange returns null.
2024-04-05 17:46:56 +02:00
Kawe Mazidjatari
abbed191c2 Tools: check CPU for SSE2
SSE and SSE2 instructions are being used, check for them instead of crashing somewhere in the program.
2024-04-05 17:46:52 +02:00
Kawe Mazidjatari
6f11fffe63 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-04-05 17:46:52 +02:00
Kawe Mazidjatari
b2ce189ba1 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-04-05 17:35:10 +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
967aa0dfd4 Bump sigcache version to 2.8 and rename methods
Bump version and rename CSigCache::LoadCache to CSigCache::ReacCache.
2024-04-05 16:24:46 +02:00
Kawe Mazidjatari
f8fe90874a Only compile signature results in dev mode 2024-04-05 16:24:45 +02:00
Kawe Mazidjatari
723052eb6f 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).
2024-04-05 16:21:45 +02:00
Kawe Mazidjatari
86ca562fb3 Constness 2024-04-05 16:21:45 +02:00
Kawe Mazidjatari
22bbb173fa Make ICpuTopology methods virtual
Virtual in the engine we are working on; this should be virtual too.
2024-04-05 15:57:33 +02:00
Kawe Mazidjatari
fce3b1f46a CCrashHandler: small code cleanup 2023-09-09 20:57:23 +02:00
Kawe Mazidjatari
b85003a9ac Replace JSON library with RapidJSON
Less copies and overall CPU time parsing/constructing JSON's as we are mostly still using string pointers rather than STL string container.
2023-09-07 11:17:05 +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
195b2a11d7 Variable rename
Its a suffix.
2023-08-01 14:48:08 +02:00
Kawe Mazidjatari
a4da4afd19 FormatBytes function bug fixes
- Use snprintf instead to avoid stack buffer overflow.
- Make sure nBytes has a value before using it to create an index for the suffix.
2023-08-01 14:45:55 +02:00
Kawe Mazidjatari
eb14469178 Create utility function for formatting bytes
Byte count to prettified representation as string.
2023-07-31 11:43:25 +02:00
Kawe Mazidjatari
b7b42786ab Add STL version of Appendslash 2023-07-28 14:45:04 +02:00
Kawe Mazidjatari
2b05edd374 Fix using incorrect member as bounds for looping exporteds
Fixes a crasher on certain modules as it could read oob; must use 'NumberOfNames' to iterate over export names.
2023-07-23 20:02:12 +02:00
Kawe Mazidjatari
c5e7c3e05d Move 'CPUInformation' struct
Move to the header it actually belongs to.
2023-07-15 10:28:49 +02:00
Kawe Mazidjatari
6f441292d0 CModule construction optimization
Moved construction logic to separate method, and call that from constructor instead. When willing to change the entire context on the same object, you can now just call 'InitFromXXXX()'. Previously, a whole new object would be generated and copied into ours, and then deleted again.
2023-07-10 13:54:00 +02:00
Kawe Mazidjatari
8b0fecf8bc Add aligned memalloc overrides
Make sure these are getting overridden with our implementation as well.
2023-07-10 13:51:14 +02:00
Kawe Mazidjatari
8cb46354e6 Permanently fix aligned memalloc crash
It was still crashing as the thisptr should actually be passed into the alloc callback. Changed and the function call is now identical to engine's impl. Tested in Debug, Profile and Release, Release has also been tested with LTCG.
2023-07-10 13:49:36 +02:00
Kawe Mazidjatari
248efc114b Fix aligned memalloc crash when compiled with LTCG
Crash occurred as the arguments to the alloc/free callbacks would involve the 'this' pointer, and therefore, the registers would shift and misalign. The fix is to just make the functions static and call the pointers directly from the singleton exposed by the engine. Additional cleanup has been performed by adding typedefs for the function pointers.
2023-07-09 20:03:57 +02:00
Kawe Mazidjatari
b4cd72034e CModule: light cleanup
Remove the option to disable dynamic init, it was broken anyways as the string was getting constructed, and therefore, dynamic memory could be allocated if string exceeds a certain size where it has to be moved from stack to heap. The only functions we were interested in, while not allocating anything have been made static instead in the last refactor round.
2023-07-08 03:01:54 +02:00
Kawe Mazidjatari
2afec89c2f CCrashHandler: light cleanup 2023-07-08 02:44:33 +02:00
Kawe Mazidjatari
819b3aeb16 Move and rename 'IsValidUTF8', 'UTF8CharLength'
Moved to strtools (tier1); utility will be renamed and decoupled into 'stl_utility' soon.
2023-07-04 23:01:13 +02:00
Kawe Mazidjatari
87958822b9 Fix debug compiler errors
Compiler errors when compiling in debug.
2023-07-03 10:59:29 +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