134 Commits

Author SHA1 Message Date
Kawe Mazidjatari
b37a3bdeba Add comments on newly added code 2024-04-05 16:28:59 +02:00
Kawe Mazidjatari
cbf370019d Don't query JWT token if we connect to localhost
Localhost in many cases implies usage of listen server; these don't require auth on loopback connections.
2024-04-05 16:24:47 +02:00
Kawe Mazidjatari
cd2d47b959 Add configurable server cvars for auth system
The command execute is now guarded off on the client with the cvar 'sv_allowClientSideCfgExec' instead of 'sv_cheats'.
2024-04-05 16:24:46 +02:00
Kawe Mazidjatari
909977452e Client token authentication implementation
The game internally obtains a auth token from Origin. On connect to a gameserver, it will send it to the masterserver. The master server will create a JWT token and send this back to the client. The client stores this token in 3 userinfo cvars (token, sig1, sig2). the sig1 and sig2 cvars are there to compensate for the truncation caused by sending the cvar, as each cvar string length could be up to 255 (byte max). The server verifies this token (the signature, timestamp, expiry); if they are valid, the has successfully authenticated and will connect.
2024-04-05 16:24:45 +02:00
Kawe Mazidjatari
48256955af Null console commands past the 512th byte
A mistake has been made, certain area's of the engine actually do allow strings larger than 128 bytes, just one routine that doesn't (console commands). Tokenizer only tokenizes it up to 512 bytes, so null all the other bytes past this. This still fixes the flaw mentioned in the comment at the place where the nulling happens.
2024-04-05 15:57:33 +02:00
Kawe Mazidjatari
71d0332dca Add CCommonHostState to SDK
The previous 'interval_per_tick' global belongs to the 'g_pCommonHostState' singleton.
2023-09-17 16:44:18 +02:00
Kawe Mazidjatari
228b9222b3 Fix compiler error
Define this out for client dll.
2023-09-16 22:02:04 +02:00
Kawe Mazidjatari
00e79268d7 Fix infinite memalloc exploit in NET_SetConVar
Reported by Wanderer. Don't allow the creation of new ConVar entries in CClient::m_ConVars after the initial creation.
2023-09-16 16:18:18 +02:00
Kawe Mazidjatari
5bab1bc6af Move CClient pointer adjuster to separate function
All process methods have a shifted CClient pointer, so this will be used more often.
2023-09-16 12:18:32 +02:00
Kawe Mazidjatari
907e582f55 Remove latency markers
Some parts of the engine have to be rebuild in order to implement this correctly, therefore, it has been removed for now to avoid potential performance problems.

fps_max_rt and fps_max_gfx have been limited to 295 to avoid a contest with the engine's hard limit causing huge performance hits.
2023-09-13 17:37:09 +02:00
Kawe Mazidjatari
b87d7bf1c3 More improvements to the comment
Make a bit more sense.
2023-09-12 17:13:12 +02:00
Kawe Mazidjatari
bf29365e04 Fix typo
Should be tick as its possible to run more frames per simulation tick.
2023-09-12 17:09:19 +02:00
Kawe Mazidjatari
ea6c15df4c Initial implementation of NVIDIA Reflex Low Latency timing
Propagated latency markers in an attempt to further reduce input latency. Code is pending rigorous testing on several systems, including systems powered by an AMD GPU to make sure we are not impacting performance on systems that does NOT support NVIDIA Reflex.
2023-09-12 11:06:16 +02:00
Kawe Mazidjatari
d7448be952 Improve CClientState fields 2023-08-27 00:20:35 +02:00
Kawe Mazidjatari
4e1d99bf9d CClientState adjustments
Mapped out and aligned slightly more.
2023-08-26 01:25:07 +02:00
Kawe Mazidjatari
20cc4b1439 Rename CClientState field
Renamed to 'm_bUseLocalSendTableFile'. If set, the 'CClientState::ProcessSendTable()' method drops the SVC_SendTable message, and keeps using the local file instead.
2023-08-21 20:43:36 +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
545ccac064 Improve CClient class
Added:
 - m_nDisconnectTick
 - m_nSendtableCRC
- m_nMmDev

Fixed incorrect placement for:
- m_LastMovementTick
2023-08-21 16:33:45 +02:00
Amos
00f7415380 Fixup CClient types 2023-08-14 00:30:20 +02:00
Kawe Mazidjatari
30031e3275 Don't allow stringcmd's if client isn't active
Potential exploit vector, executing stringcmd's during signon states where it shouldn't be used.
2023-08-08 19:25:12 +02:00
Kawe Mazidjatari
9a9d6b290a Fix typo 2023-08-08 19:05:12 +02:00
Kawe Mazidjatari
89431cc61f Fix crasher by clamping stringcmd length before tokenizing it
Possible crasher is to send a stringcmd >= 512 in size with funny UTF8 characters and have CUtlBuffer::ParseToken() read past it. Apparently seems to be mostly a problem on 32bit? I was unable to initiate a crash, though one string caused interesting behavior before, and there was one report of the dedicated server being 'crashed' with this. There is no reason to tokenize it up to 512 bytes if the game is only ever going to allow 128, so clamp it to 129 and if the user exceeds it then they still get the message and we just jettison it.
2023-08-07 16:52:35 +02:00
Kawe Mazidjatari
f2783ae93f Make use of 'CConnectedNetConsoleData::m_bInputOnly' properly
This member was in the class when RCON was added to the r5sdk, but it was never utilized. Now, each netconsole can toggle whether they are input only or not, the server only sends logs to netconsoles that are not input only. This patch also contains a fix in which the listen server sends logs to the client of its own process, causing an infinite recursive call to DevMsg.
2023-08-04 17:28:01 +02:00
Kawe Mazidjatari
ddfe027677 Pass by reference
CConnectedNetConsoleData was allocated and deallocated manually, but std::vector is able to do it on its own. The vector type has been swapped out with CUtlVector as this removed the need of having to cast size types to a 32bit int to make it more compatible with the other sdk/engine types without throwing compiler warnings.
2023-08-04 10:48:22 +02:00
Kawe Mazidjatari
6d39d99941 Fix mistake in comment 2023-07-19 18:47:25 +02:00
Kawe Mazidjatari
ad6466fa6c Add 'engine_cl' project to SDK and fix compiler errors
The 'engine_cl' library defines 'CLIENT_DLL', which prunes server specific code. This is used for the 'client.dll' project. Also fixed a compile error in 'CClient::VActivatePlayer', as it used a server only cvar. Ideally, this entire file gets ifdef'd out for engine_cl, currently it doesn't matter as nothing gets compiled in.
2023-07-19 02:30:07 +02:00
Kawe Mazidjatari
d5f35349a8 Decouple script function registration
Nicely decouple them. Everything server and client are now grouped as they should. The Ui namespace has been merged with Client.
2023-07-19 02:12:56 +02:00
Kawe Mazidjatari
e7d7c47531 Make 'CClient::IsHumanPlayer' inline 2023-07-17 17:38:21 +02:00
Kawe Mazidjatari
b5f68df826 Fix rare crasher due to missing NULL check on netchan
Netchan could be NULL, add a check in.
2023-07-17 17:08:37 +02:00
Kawe Mazidjatari
a738e58985 Remove legacy code
The persistence enabled field was no longer needed a while ago, but never removed.
2023-07-16 13:47:07 +02:00
Amos
2f209ddb60 Remove 'g_pClient' pointer
The whole array is part of the CServer class.
2023-07-12 09:14:33 +02:00
Amos
c6a9b855a2 Make simple CClient getters, inline
Small enough to be inline.
2023-07-12 09:11:31 +02:00
Amos
ccdfed1c19 Use CServer's 'GetClient'
Use the CServer's 'GetClient' method for obtaining clients by index.
2023-07-12 08:56:17 +02:00
Amos
126091d3bc Update CServer class
CClient array is part of the CPlayer class. The array has been added, filling up most of the 'unknown' gap. Vtable override functions have been added as the array is static, and therefore requires an implementation of the vtable, these are just stubs however, since the vtable pointer points to the implementation in the engine.
2023-07-11 08:42:02 +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
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
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
0f5b171b67 Cleanup warning string on invalid string cmd
Remove the UTF-8 part.
2023-06-24 00:56:45 +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
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
d2fca23cf5 Fix typo in address logger
Technically not a pointer internally.
2023-06-19 01:46:05 +02:00
Kawe Mazidjatari
a33f569ad5 Proper fix for playlists reloading on disconnect
This fixes a crash/exception that would occur when getting disconnected from your own listenserver due to the playlists reload task dispatch. Moving this to client only code, in the disconnect routine (post disconnect) fixes this problem.
2023-06-18 17:13:42 +02:00
Kawe Mazidjatari
2ae8a74ad9 Remove duplicate call to 'CNetChan::SetChoked()'
Should only be called if client is active.
2023-06-05 08:07:04 +02:00
Kawe Mazidjatari
9f2b1b1bb5 Improve CL_Move rebuild
Ported the logic from the more recent builds into the SDK rebuild. Note that this isn't all that has changed in the live builds, but were the only things worth porting back. Frame times are now properly clamped on the client. Some testing revealed that the movement now feels identical to the live version of the game, which was the target. This commit also fixes a bug in CL_Move were the datagram was not send, and the next cmd time wasn't set if the client was NOT active, while it should have.
2023-06-05 00:27:36 +02:00
Kawe Mazidjatari
1afa75fec3 Fix >190FPS input system/simulation problems
Function 'CL_Move' has been fully rebuild in the SDK. Originally, the game checked if the delta time exceeded an amount defined by an immediate value, and dropped usercmd's if that was the case. This logic has been replaced with a more dynamic solution, and the console variable regulating this ('fps_input_max') is set to 200.0 by default (the same as the fix applied in the Season 9.1 Genesis update). This function also has been slightly optimized by removing duplicate operations that were performed in the original function. A second fix has been applied to 'CInput::JoyStickApplyMovement' that was also found changed in the Season 9.1 Genesis executable. In that function, an extraneous clamp was performed on the frame time causing viewstick problems when usercmd's get dropped in CL_Move.
2023-06-03 21:20:23 +02:00
Kawe Mazidjatari
b567d8d74f Add 'CHLClient::CreateMove' to SDK 2023-06-03 18:21:13 +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
cef62d7f4d Properly implement 'CClientState::IsPaused()'
Should check if host is initialized, and if the VGui system is paused as well. Also added 'CClientState::GetFrameTime()'.
2023-06-03 18:06:35 +02:00
Kawe Mazidjatari
619bbd161c Fix stringcmd replay exploit
This commit fixes an engine bug where netmessages are getting copied into the replay buffer, while these messages should never be replayed. The engine performs an internal check on 'CNetMessage::m_nGroup', and if its NOT 2, the message is getting copied into the replay buffer. All messages returning false in 'ShouldReplayMessage' are not getting copied into the replay buffer anymore. This exploit has been used in the past to route clients that were watching a replay to an arbitrary server, which essentially forms an info leak as the client attempts to connect to the arbitrary server on its own. The exploit also allows for some form of remote code execution, depending on if the client was launched in developer mode or not.
2023-05-30 23:01:46 +02:00
Kawe Mazidjatari
552f5f750c Fix crash in 'CClient::ActivatePlayer'
Set the persistence fields to 'ready' in 'CClient::ActivatePlayer', before executing the rest of the function. Previously, it was set in 'CVEngineServer::PersistenceAvailable', but this is too late. The function 'FairFight_Init' was actually 'CClient::ActivatePlayer', and thus it has been moved to the correct file, and the old file defining it previously has been removed.
2023-05-15 17:19:18 +02:00