478 Commits

Author SHA1 Message Date
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
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
d5f74dc245 Add constants for script paths
Game script path and its compile list.
2023-07-09 20:12:09 +02:00
Kawe Mazidjatari
e2bf1b7a99 Add CUtlString less function
Used for CUtlMap.
2023-07-09 20:10:53 +02:00
Kawe Mazidjatari
4e8b27a1e9 Allow overriding path separator to list generated by 'RecursiveFindFilesMatchingName' 2023-07-09 20:05:47 +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
c215fcc171 VPK utility code improvements
- Only process referenced pack files, previously, if an entry in the VPK file was build into a pack of index 128, the code would generate a list of pack files from 0 to 128.
- Added documentation to VPK structure.
2023-07-06 00:49:17 +02:00
Kawe Mazidjatari
42d12a644e Fix bug in 'V_StripLastDir' and 'CUtlString::DirName'
In some code paths of 'V_StripLastDir', the string length value was never set. The return type of this function has changed to return always return the length of the new string. An additional bug in 'CUtlString::DirName' has been fixed, where the length was only set if the trailing slashed weren't stripped.
2023-07-05 21:50:36 +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
c330273508 Set correct return type for 'IFileSystem::CreateDirHierarchy'
Returns a 32bit int from the internal call to 'mkdir'.
2023-07-04 21:12:53 +02:00
Kawe Mazidjatari
261a9ea204 Reduced ConVar flags array size
This was supposed to be part of commit 3e4d02af.
2023-07-03 14:35:23 +02:00
Kawe Mazidjatari
3e4d02afe1 Remove non-existent ConVar flag
This flag doesn't exist in this game, and is also mapped to printableonly. The map order has also been corrected, from least significant to most significant.
2023-07-03 14:32:52 +02:00
Kawe Mazidjatari
398c0f1ddc ConVar flags tools refactor
Previously, we had 3 containers mapping ConVar flags for utilities, and none of them contained all flags. This refactor moved everything into a single container class where user can get strings by flags, or the other way around. The new class contains every flag. This also means that every flag can be used to list convars by flags using the command 'convar_findByFlags'. The 'ConVar_ParseFlagString' now also supports every flag. Code has been tested and confirmed to work as designed.
2023-07-03 13:48:13 +02:00
Kawe Mazidjatari
ed1b365c12 CUtlRBTree: Fix ambiguous overload compiler errors
Ambiguous overload caused by having 2 constructors who's parameters have types that are equal in size. Since these container size types have been explicitly converted to 64bits to align it with the code compiled in the engine, the compiler no longer knows which constructor to call. Added explicit casts to solve the problem. This error was triggered by declaring: static CUtlMap<const char*, int> s_ConVarFlags(DefLessFunc(const char*));
2023-07-03 11:02:42 +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
56da0576a6 Make static to source file
Should be made static to avoid unwanted bloat in compiled output, as each translation unit will create a new initializer/destructor. -10KiB compiled code for GameSDK.
2023-07-03 02:27:09 +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
a0419eec11 Add method for obtaining PEB
Inline method for obtaining process environment block.
2023-07-02 22:02:31 +02:00
Kawe Mazidjatari
9b74ac2e53 Improve threadtools
* Added and utilized auto lock/unlock mechanism.
* Rebuild CThreadFastMutex's 'Lock' and 'Unlock' methods in the SDK.
* Forced thread intrinsics and ID checkers as inline.
2023-07-02 11:38:36 +02:00
Kawe Mazidjatari
9e6b0e567f Port everything to CCommandLine
Before, we had to do a hack of capturing the command line using GetCommandLineA, and then checking if a certain argument is present. This was required due to how early the GameSDK dll was loaded (the g_CmdLine object was far from initialized in the engine). Due to the loader refactor, the commandline can be used directly after creation in the game's entry point (which is the time the SDK is getting loaded). Therefore, no copies of the command line are required anymore.
This commit contains the following changes:

- Correctly ordered the initialization, and deinitialization of systems (first init = last shutdown).
- Factored out command line string copy in favor of game's implementation.
- Factored the R5Reloaded emblem print into its own function.
- Removed 'SpdLog_PostInit()', we can now directly call DevMsg() once SpdLog_Init() has been called, the logger callback sink deals with the formatting of the output.
- Fixed a bug where the logger did not print the correct color for 'SYSTEM_WARNING' and 'SYSTEM_ERROR' in the external console.
- Fixed a bug where the command line did not work when the game wasn't launched with the '-launcher' parameter.
- Logs now equally appear on the external, and in-game console windows.
2023-07-01 01:20:47 +02:00
Kawe Mazidjatari
61bbd5e125 Debug context types cleanup
* Removed unused char array.
* Added default 'white' color to context table (used for eDLL_T::NONE).
2023-06-30 22:00:54 +02:00
Amos
939e101fe6 Properly override all malloc wrappers
This covers the entire source code, including thirdparty libraries if memstd.cpp is compiled.
Things left to be done:
- Utilize the debug methods of the CStdMemAlloc class by routing the debug variants to those.
- Move this to a standalone library, so tools and stuff not interfacing directly with the game engine can still link against tier0.
2023-06-28 10:03:10 +02:00
Kawe Mazidjatari
33dfe63f67 Fix incorrect ICVarIteratorInternal function order
The destructor is the last function.
2023-06-26 22:42:54 +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
ae52aa0081 Replace memalloc calls for Valve container types
Utilize new malloc system using the conventional approach, see commit 708a2495.
2023-06-26 21:18:44 +02:00
Kawe Mazidjatari
b76f4aa3bd CModule class improvements
*Use unordered_map to get mpdule sections instead, as this is more performant than comparing strings.
* Removed 'm_SectionName' field from ModuleSections_t, as the unordered map now keeps track of them.
* Removed all extraneous module section copies.
* Renamed 'GetImportedFunction' to 'GetImportedSymbol'.
* Renamed 'GetExportedFunction' to 'GetExportedSymbol'.
*Made a static version of 'GetImportedSymbol' and 'GetExportedSymbol', so it could be used on raw module base addresses.
*Created inlines for getting the DOS and NT headers.
*Improved formatting so the code could be read more easily on a vertical monitor.
2023-06-25 10:29:42 +02:00
Kawe Mazidjatari
59a3f50c00 Valve container fixups
* Fix missing "HasElement" method in CUtlRBTree.
* Change iterator types to "unsigned short" to avoid compiler warnings (default template argument for the index type is unsigned short).
2023-06-24 00:56:00 +02:00
Kawe Mazidjatari
d43ab4a850 Fix typo 2023-06-22 00:34:26 +02:00
Kawe Mazidjatari
f2615b10de Improve CClient class structure
* Added structure for send/recv datablocks vtable.
* Mapped out CClient structure more.
* Fixed incorrect tick member offsets for CClient.
2023-06-22 00:33:00 +02:00
Kawe Mazidjatari
bc995230fa Avoid extraneous string copy
Take raw pointer directly, this is currently the only way these functions get called with.
2023-06-19 22:36:46 +02:00
Kawe Mazidjatari
abe68def03 CMDLCache code improvements
Slightly mapped out the CMDLCache class, to the point the pointers to its members are no longer needed. Also fixed a bug were the studiodata pointer was dereferenced before checking if its not null, this check did exist, but was performed too late. Fully implemented the CUtlDict class for m_MDLDict. Slightly optimized the initialization of the error model handles.
2023-06-19 13:53:56 +02:00
Kawe Mazidjatari
2cfed900d0 Add full CUtlDict implementation
CUtlDict from the SourceSDK.
2023-06-19 11:23:22 +02:00
Kawe Mazidjatari
f024db1477 Use correct address logger
Should use the function logger instead.
2023-06-19 01:45:25 +02:00
Kawe Mazidjatari
18e4a262c8 Fix double crash dialog boxes bug
This occurs when the game's unhandled exception handler is getting called after ours. both will create a crashmsg process. This happened as CCrashHandler::End() was called before the in-game exception filter was fired, and therefore CCrashHandler::Handled would return false, and this fire the in-game exception filter. This commit removes the additional check, we just use our vectored exception handler entirely over the game's one, as this one captures everything an unhandled exception handler will capture, and more. The 'Handled' function/fields in CCrashHandler have been renamed to 'Handling', as this is a more appropriate name.
2023-06-19 01:35:10 +02:00
Kawe Mazidjatari
97a6b8b5cc Make CCrashHandler getters/setters inline
These could be just inline.
2023-06-19 01:19:47 +02:00
Kawe Mazidjatari
51ea9c7c4f CUserCmd hardening
Fix several exploitable bugs in the CUserCmd class. Some of these have been used to exploit/cheat in-game. Fixes contain:
- Camera position clamping (the only patch that hasn't been tested yet!)
- Weapon activity exploit, allowing player to infinitely throw ordnances, and perform other 'cheats'.
- Akimbo exploit + server crasher, allowing client to set multiple inventory weapons as active. The active weapon index bounds were also not checked, a properly crafter CUserCmd message would therefore be able to crash the server.

Note that this does not fix all issues related to the UserCmd class; further reversing and testing revealed there is more to be fixed, these fixes will get implemented with a future commit.
2023-06-13 17:43:32 +02:00
Kawe Mazidjatari
975c40876a CModule and CMemory class improvements
This commit significantly reduces output code size, and a noticeable increase in performance. Changes are:
- Removed all extraneous std::string and std::vector copy constructions; use raw pointers instead to boost performance.
- Marked simple getters in CModule inline.
- Marked several functions in CModule const.
- Slightly reordered CModule class.
- 'CMemory::CheckOpCodes' and 'CMemory::Patch' now take a const reference.
2023-06-12 18:40:16 +02:00
Kawe Mazidjatari
8e1019a265 Make simple CNetAdr methods inline
Should be inline for their simplicity to improve performance.
2023-06-05 01:45:33 +02:00
Kawe Mazidjatari
3d18be9ebb Add splitscreen types to SDK
R5 'MAX_SPLITSCREEN_CLIENTS' appears to be max 1.
2023-06-03 18:10:32 +02:00
Kawe Mazidjatari
63ca5d9d98 Make small bitbuf methods inline
Make inline to boost performance.
2023-06-03 18:04:38 +02:00
Kawe Mazidjatari
e891d74656 Fix cURL error logging for dedicated
Since this file no longer gets build along with the DLL project, but as a static lib instead, the 'DEDICATED' define no longer worked, and therefore this became broken after the CMake port. The 'CURLHandleError' helper function now takes a bool determining whether or not to log the error, and the caller disables it for dedicated (dedicated should only log the error once, this happens from within the caller class).
2023-06-02 00:05:23 +02:00
Kawe Mazidjatari
a8f7336d78 Fix default CFG file loading
After the CMake refactor, this became broken as the 'DEDICATED' define does not work in tier0 headers. These were the last ones; moved to the DLL project instead. This commit also fixes a bug where the command line file gets parsed twice, while there was already a global containing the args (initialized on DLL init).
2023-06-01 23:44:55 +02:00
Kawe Mazidjatari
7f15b94cd9 String tools improvements
* Add 'V_IsValidPath'.
* Add optional parameter to 'V_StripLastDir', in which the new length of the string gets written into.
2023-05-29 21:37:15 +02:00
Kawe Mazidjatari
7e2b249ef6 CUtlString improvements
* Add method for finding a substring ('CUtlString::Find').
* Add method for appending a slash ('CUtlString::AppendSlash').
* Add 'CUtlString' overload for 'CUtlString::IsEqual_CaseSensitive'.
* Add 'CUtlString' overload for 'CUtlString::IsEqual_CaseInsensitive'.
* Add optional parameter to strip trailing slashes in 'CUtlString::DirName'.
* Add optional parameter to strip trailing slashes in 'CUtlString::StripFilename'.
2023-05-29 21:35:12 +02:00
Kawe Mazidjatari
054b123004 Don't load certain lumps for dedicated
This significantly reduces disk size, and also reduces memory usage.
2023-05-29 01:03:27 +02:00
Kawe Mazidjatari
ceb438b7ca Add BSP header definitions 2023-05-22 12:29:23 +02:00
Kawe Mazidjatari
5fcf430be5 Add GameLump data types 2023-05-21 18:07:04 +02:00