2980 Commits

Author SHA1 Message Date
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
892fd19c4a Fix incorrect CPlayer member offset
Member offset for 'm_bGamePaused' did not align with the executable, moving the member 'm_hPlayerViewEntity' before the first bool in this row results in correct code generation (also aligns properly in the disassembly of the game's code).
2023-07-02 21:54:21 +02:00
Kawe Mazidjatari
32d28d4285 *::ProcessUserCmds rebuild
Rebuild of the 'CServerGameClients::ProcessUserCmds' and 'CPlayer::ProcessUserCmds' methods. The rebuild is pretty much identical to the original implementation, but with additional checks for the number of commands, and total commands in 'CServerGameClients::ProcessUserCmds'. In the future, additional clamps and checks between CPlayer and the recv'd UserCMD should be incorporated in these functions.
2023-07-02 21:49:35 +02:00
Kawe Mazidjatari
64453b0661 Add CUserCmd constructor to SDK
Internal constructor from the engine.
2023-07-02 21:31:19 +02:00
Kawe Mazidjatari
7d456b8b61 Add 'player_userCmdsQueueWarning' cvar to SDK
Will be used for the 'CPlayer::ProcessUserCmds' rebuild.
2023-07-02 21:28:49 +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
bfd093d22b Fix rare crash in 'ImGui_ImplWin32_WndProcHandler'
Don't run the 'ImGui_ImplWin32_WndProcHandler' if we are shutting down. During rare occasions when closing the game while hovering over the game window, 'ImGui_ImplWin32_WndProcHandler' is getting called while parts or all of the ImGui systems have been shut down, leading to a crash. The fix is to check if the engine is restarting or shutting down before running the ImGui window procedure logic.
2023-07-02 11:28:07 +02:00
Kawe Mazidjatari
be93929b26 Map out CKeyValuesSystem class
Mapped out members of the CKeyValuesSystem class. Singleton accessor has also been declared inline in this commit.
2023-07-02 02:51:12 +02:00
Kawe Mazidjatari
8ea2eac0fc Move launcher/loader consts
Move to shared PCH as these are low level defines.
2023-07-02 02:46:58 +02:00
Kawe Mazidjatari
0207c69b36 Fix SDK launcher compatibility with SDK loader
Since the SDK loader (loader.dll) is taking care of loading the DLL with the process, the SDK launcher no longer needs to inject it. Replaced call 'DetourCreateProcessWithDllsA' with 'CreateProcessA', and performed additional cleanup
2023-07-01 23:27:29 +02:00
Kawe Mazidjatari
c1a0276951 Fix unresolved external symbol errors for loader.dll
Moved CModule statics to a separate translation unit, preventing the linker to link unused stuff into the loader module, thus allowing us to drop the linkage of unused libraries.
2023-07-01 22:29:34 +02:00
Kawe Mazidjatari
a82b4c950c Compute MHz instead 2023-07-01 21:45:32 +02:00
Kawe Mazidjatari
71148b691c Mark the build id yellow 2023-07-01 21:27:37 +02:00
Kawe Mazidjatari
75a394a85f
Merge pull request #100 from Mauler125/cmdline_export
Cmdline export
2023-07-01 11:29:34 +02:00
Kawe Mazidjatari
d7245a04e4 Test recursive shutdown on global init bool
Test on this instead, it has to be unset anyways.
2023-07-01 11:20:44 +02:00
Kawe Mazidjatari
d37f12aa4f Don't recreate the command line
Don't recreate it in the engine (LauncherMain) if its already created in the SDK. This solution toggles a hybrid between creating it in the SDK, or in the engine when -noworkerdll is passed to the loader.
2023-07-01 02:11:39 +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
dfb61aff74 Attempt to load the startup CFG from platform
Attempt to load it from there as well on failure.
2023-07-01 01:04:23 +02:00
Kawe Mazidjatari
894eea12de Only force multiple when build in Debug
Debug only, required for reliable '_xxxx_dbg' CRT allocator function overrides.
2023-06-30 22:02:27 +02:00
Kawe Mazidjatari
bfd2f48cc0 Log QHull prints as 'COMMON' 2023-06-30 22:01:13 +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
Kawe Mazidjatari
e9518d8ff1 CCommandLine improvements
* Make accessor inline.
* Add method 'AppendParametersFromFile' (will be used in a future init refactor).
2023-06-30 21:59:16 +02:00
Kawe Mazidjatari
bb28e160cf Override debug malloc functions and fix bug
* Override debug malloc functions, doesn't seem to be properly supported by the visual studio libraries, but it has to be done, else we crash trying to initialize the DLL (must use the same allocator as the game), a linker flag '/FORCE:MULTIPLE' had to be set to make this work, this should be set for only DEBUG builds in the future!.
* Fixed a bug in '_recalloc_base' where the allocation size was not calculated properly. Only the size was taken into account, but it should had been multiplied by the count.
* Stubbed additional CRT debug only memory debugging code, it will crash on our implementation in debug.
2023-06-29 00:24:22 +02:00
Kawe Mazidjatari
99fe5b794a Make memoverride a separate lib
Else everything linked against tier0 will have to use the game's memalloc implementation, which requires it to run with the game process. Only limit this to DLL's that run with the game process.
2023-06-28 20:00:38 +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
130f67dbe8 CCommand improvements
- Uncommented 'CCommand::Tokenize' and changed size types to 64bits. CUtlBuffer has been implemented so this code can be used.
- Removed extraneous string copy from 'CCommand::HasOnlyDigits', just iterate over the raw character pointer.
2023-06-27 22:06:47 +02:00
Kawe Mazidjatari
84e3414d7c Add 'recalloc' replacement
Added recalloc. _expand should be replaced as well in the nearby future. The functions should override the _xxxx_base variants instead, and be moved to a separate lib to cover the executable globally.
2023-06-27 21:37:15 +02:00
Amos
48d81d2369 Add "PLATFORM_64NITS" define
Should be defined as platform is 64bits only.
2023-06-27 07:53:08 +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
d0bdbcd2b0 Mod_ProcessPakQueue cleanup
* Reset 'old_gather_props' cvar, so that we can re-evaluate on the next level load, and use the new one instead if no errors were found that time around.
* Removed extraneous operators.
2023-06-26 16:50:25 +02:00
Kawe Mazidjatari
31f4e562a8 Set correct mutex type for 'm_MDLMutex'
Should be 'CRITICAL_SECTION'.
2023-06-25 14:56:30 +02:00
Kawe Mazidjatari
420a41d095 Fix CMDLCache crash on missing models
CMDLCache::FindMDL missed a check for 'DC_INVALID_HANDLE'. Adding in this check solved the issue. Other functions have been slightly cleaned up/optimized.
2023-06-25 14:56:04 +02:00
Kawe Mazidjatari
708a249507 Internal memalloc replacement
This commit replaces the standard memalloc system with that of the game. This means we can share the same allocated memory objects between the game and SDK without having to use 'MemAllocSingleton()' and manually call the constructors/destructors. This also means we can create ConVar's and ConCommands in the global scope, and a bunch more cool stuff. The explanation in 'r5dev\loader\loader.cpp' documents the new loading system.
2023-06-25 11:37:52 +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
f31788c6c2 Add missing include guards
Causes compile errors.
2023-06-25 08:57:10 +02:00
Kawe Mazidjatari
15b78f966d Fix unreachable code in CMDLCache
This code was part of an invalid string check, but is no longer necessary and was causing the unreachable code bug. Removed.
2023-06-25 02:31:50 +02:00
Kawe Mazidjatari
884decd090 Set default debugger parameters
The debugger can now be immediately invoked on all runtime projects after generating the solution without having to set anything up.
2023-06-24 15:46:56 +02:00
Kawe Mazidjatari
0f5b171b67 Cleanup warning string on invalid string cmd
Remove the UTF-8 part.
2023-06-24 00:56:45 +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
cfa2172322 Undo CUtlBuffer::ParseToken patch
The bug was only reproduced on the compiled implementation in the game executable. The CUtlBuffer::ParseToken implementation in the SDK did not bug on the same input string. More research is required, and a possible good fix would be to just hook and replace the game's implementation with that of the SDK.
2023-06-23 00:27:24 +02:00
Kawe Mazidjatari
a93824b2db Discard invalid string commands
Must be UTF-8 encoded, currently there are no checks.
2023-06-22 23:45:19 +02:00
Amos
89458eb23e Fix dedicated server compiler error
Client exclusive, moved to client only group.
2023-06-22 18:26:29 +02:00
Amos
b13cc071a9 Improve ban commands
The ban commands have the 'sv_' prefix removed. CBaseEntity::InputKill expects 'kickid' to be present, it uses this to kick the player once the entity has been destroyed. Not doing so could lead into a crash or other undesired behavior.
2023-06-22 09:09:38 +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
Amos
ac4ab6aa1a Add reason parameter to kick/ban commands
Reason parameters are optional. For scripts, to use the default message, pass in an empty string. The function for the script system should be centralized soon to avoid more duplicate code.
2023-06-20 08:44:03 +02:00
Kawe Mazidjatari
6361e64b5c Improve readability
Break up lines so they fit on a vertical monitor.
2023-06-19 22:42:25 +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