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.
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.
- 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.
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.
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.
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.
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*));
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.
- 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.
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.
* 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.
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.
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.
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.
*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.
* 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).
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.
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.
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.
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.
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).
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).
* 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'.
Properly fix the aligned memalloc singleton in the SDK; the implementation now uses a callback based approach for calling the allocator and deallocator.
Added all public headers to CMake projects, also moved some files around in the public directory. Translation units have been moved to the libraries that were responsible for implementing them, as this game is monolithic.