47 Commits

Author SHA1 Message Date
Kawe Mazidjatari
609d705a0c Tier1: static construction of ConVar objects during link time
Fully implemented ConVar class so we could statically construct all SDK convars, this avoids a level of indirection, and allows for creating ConVar's everywhere in the project.

This patch also removed the settings tab of the ImGui server browser, as it has threading issues, while it technically never caused a crash yet, it has been removed as there was no point keeping it vs the work required to make it thread save (it only managed 2 convars which are perfectly manageable through cfg's or the in-game console).

Also temporarily disabled the creation of ConVar's in the mod system due to a memory leak, we would allocate and register a convar based on details parsed out of a mod file definition, but never unregister and free it.
2024-04-05 18:13:32 +02:00
Kawe Mazidjatari
74da5c7c20 Engine: cleanup data block sender/receiver and add types
* Move member vars to correct place, to match it with the engine.
* Added out-of-band network message ID's for the R5 engine.

Also implemented 'ServerDataBlockSender::SendDataBlock()' and 'ClientDataBlockReceiver::AcknowledgeTransmission()'. NOTE that these are currently not tested, and also not in use! The code uses the version stored in the vftable which is what the engine itself provides. These have been implemented for reference only. If they need to be used, they need to be thoroughly tested first!
2024-04-05 18:06:36 +02:00
Kawe Mazidjatari
f18a4c17a4 Engine: rebuild CClientState::ProcessCreateStringTable()
Rebuild CClientState::ProcessCreateStringTable() and add notes for multiple 'potential' exploit vectors that are currently in place. Also add wrappers for compressing/decompressing net packets.
2024-04-05 17:59:53 +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
d528ec69f1 Add wrapper for reading netmsg types 2023-08-21 16:28:04 +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
693b378618 Remove left over function declaration
This function no longer exists.
2023-06-03 18:11:59 +02:00
Kawe Mazidjatari
53788d5ba5 Potential fix for intermittent crash during playlists reload
This should fix a rare crash that happens when the playlists file is reloaded during disconnect. The client fetches the playlists from the server on connect. On disconnect, we want to reload the one from the client so that if the player want's to create his own game, that he would have his own playlists. The fix is to delay the reload of the playlists file to the beginning of the next frame.
2023-05-16 00:44:59 +02:00
Kawe Mazidjatari
abf74d71a0 Add missing definition for 'NET_Config' 2023-04-16 00:32:11 +02:00
Kawe Mazidjatari
fe15a1c745 Add 'NET_Config' to SDK
Signature matches among all builds between S0 and S3.
2023-04-16 00:30:29 +02:00
Kawe Mazidjatari
129637e8e6 Fix incorrect netmsg constant
Should be '7' based on the calls to 'bf_write::WriteUBitLong' in the game executable.
2023-04-10 14:58:21 +02:00
Kawe Mazidjatari
874faea430 Add hook to CLZSS::SafeUncompress
Added hook to use the SDK implementation of 'CLZSS::SafeUncompress' instead, since the one in the game executable does not check bounds on the iterator pointer. This fixes the problem of people crashing servers with malicious packets.
2023-04-06 00:28:58 +02:00
Kawe Mazidjatari
fc1a773836 Add 'g_NetTime' to SDK
Official name = 'net_time'.
2023-02-15 20:47:58 +01:00
Kawe Mazidjatari
1db53a135f Fix dedicated.dll compile error
'g_svNetKey' no longer exists.
2023-02-12 11:49:39 +01:00
Kawe Mazidjatari
236eb861d5 Add global netadr to SDK
Global from engine used in the 'status' command etc..
2023-02-12 11:32:05 +01:00
Kawe Mazidjatari
e98a6c31e9 Improve netkey logic
Removed extraneous copy of the base64 netkey. The base64 key is now directly obtained from the netkey singleton.
2023-02-12 02:28:03 +01:00
Kawe Mazidjatari
0734d56fe2 Add reversed 'CNetKey' class
Confirmed size, mostly unknown still. But some of this seems to be data related to OpenSSL.
2023-02-12 02:15:58 +01:00
Kawe Mazidjatari
60ab35b5c4 Light optimizations for string utils
* Changed 'CreateDirectories' to only copy sanitized path if pointer to string is passed.
* Changed 'IsValidBase64' to only tokenize base64 value if pointer to string is passed.
2023-02-04 15:59:45 +01:00
Kawe Mazidjatari
ffcefdd64e Rename 'g_pNetKey' to 'g_NetKey'
Not a pointer in engine code, only in SDK.
2023-01-31 23:44:01 +01:00
Kawe Mazidjatari
6df498e5c8 Rename 'v_netadr_t' to 'netadr_t'
Name was used for compatibility reasons. No longer necessary.
2023-01-29 15:12:27 +01:00
Amos
b965e04dd4 Update signature for 'g_pNetKey' 2023-01-27 10:36:38 +01:00
Kawe Mazidjatari
a618990937 Detour code refactor
This change was planned for a long time. This moves all REGISTER calls to a single translation unit, this is required as we currently added a very dirty workaround for not registering duplicates by checking if VFTable pointer was already present in the vector... Registering from single translation unit prevents duplicate instances that gets created if header is included by more cpp files.
Reworking this reduced 100kb+ of compiled code. This commit also reworked the way functions/variables/constant gets logged with their addresses; the new code formats them on the fly, and allows for resize at any time. Formatting is no longer required by programmer.

TODO: currently there are some compile errors for dedicated and client dll's. These will be resolved very soon as they need to be properly worked out still (server & client only stuff needs to be properly split). Use the 'main' (stable) branch for the time being if you need to compile these dll's.
2023-01-25 02:26:52 +01:00
Kawe Mazidjatari
2501c37044 Globally convert all byte patterns to strings
These get reconverted to masked byte patterns at runtime. With the signature map cache system, this will only happen when building the cache.
2022-12-01 22:44:55 +01:00
Kawe Mazidjatari
fdd74aa622 Implement net message processing budget
Implement net message process budget (channel gets removed if value is exceeded).
Use 'net_processLimit' to enable the implementation on the server. It will get enabled by default after testing and some cleanup. This helps against people trying to slow the server down by spamming net messages with a higher rate, e.g. using 'bind "mousewheel_up" "status"'.
2022-09-18 23:19:50 +02:00
Kawe Mazidjatari
885e6fa94e Proper NET_SetKey sanity checks
* Checks if input encoded key is 24 characters long.
* Checks if the input data is a valid base64.
2022-08-30 20:04:59 +02:00
Kawe Mazidjatari
f8f4504966 NetKey system improvements
* Installed change callback 'NET_UseRandomKeyChanged_f' for cvar 'net_useRandomKey' (when set, it will generate a random key as this is needed when this is enabled!).
2022-08-30 12:10:07 +02:00
Kawe Mazidjatari
8712f7db81 Fix concurrency of g_svNetKey
* Fix concurrency of g_svNetKey.
* Improve logging.
* Overall code cleanup.
2022-08-30 01:22:53 +02:00
Kawe Mazidjatari
e6f45aaa9b CBitBuf improvements
* Use proper types reflecting assembly from the engine in 'CBitRead::Seek' (some values are 64bit, either changed by Respawn or the compiler used by Respawn).
* Confirmed changes made to NETMSG_TYPE_BITS (now 511 instead of 255) and NETMSG_LENGTH_BITS (now 12 which is 511 max instead of 255).
* Confirmed msg HUD types.
* Enforce NET_MIN_MESSAGE on 'SVC_UserMessage::Process'.
* Remove unnecessary padding and add proper symbols where padding was actually used.
2022-08-15 02:59:41 +02:00
Kawe Mazidjatari
8c6ee8a834 Remove 'm' prefix from dll globals
Large commit.
2022-08-09 03:02:00 +02:00
Kawe Mazidjatari
ebf4921063 Ban system improvements
NucleusID/OriginID is an unsigned type, changed all types to uint64_t and cleaned up redundant code.
2022-06-14 20:56:55 +02:00
Kawe Mazidjatari
5aeac9f72a rename 'g_szNetKey' to 'g_svNetKey'
sv = string variable
2022-05-27 02:24:34 +02:00
Kawe Mazidjatari
62f3108909 Cleanup 'NET_DisconnectClient()' 2022-05-21 18:56:56 +02:00
Kawe Mazidjatari
efb7c36408 Light project restructure
Moved server/client headers and implementations into dedicated subfolder.
Renamed Some classes to match the game binary (e.g. CBaseClient is now CClient).
Removed redundant files.
2022-05-20 11:52:19 +02:00
Kawe Mazidjatari
3144227ec8 Update GetAdr implementations to feature spdlog
Fixed all alignments and reduced code verbosity
2022-05-13 14:53:25 +02:00
Kawe Mazidjatari
2424545c52 Update unknown parameter names 2022-05-12 01:20:19 +02:00
Kawe Mazidjatari
3736d71bb1 Implement 'net_encryptionEnable' ConVar
This ConVar governs the use of encryption on game packets.
Also removed 'net_toggletrace' ConCommand and added 'net_tracePayload' ConVar as we can no longer hook on-demand as we bound the encryption parameter of the function to a ConVar.
2022-04-27 18:22:08 +02:00
Kawe Mazidjatari
82261f6c56 Small improvements 2022-04-24 19:32:47 +02:00
Kawe Mazidjatari
e32cc6ae6a Code overhaul
Moved every pattern to IDetour interface. This allows for debugging patterns scans more easily, and create threads during pattern searching (Operation is now fired in APIENTRY).

Also cleaned up some unused code/extraneous comments.
Slightly increased performance by purging duplicate patterns.
Made variable search less dependent from other results (except if pattern-to-scan results is within the same header)
2022-04-18 03:35:08 +02:00
Kawe Mazidjatari
092b7e9d43 Start of migration to IDetour interface
Migrating to this to initialize all patterns and prototypes in Systems_Init() instead.
This should make debugging missing/not found patterns easier and allow for opting out variable/constant search (some of these require other patterns to be found, thus resulting in seg faults..).

Also added check to detect if user has a eligible CPU to run this SDK.
The game requires SSE and SSE2 instruction sets. Our SDK requires this too due to the use of SSE intrinsics, so we cannot let the game handle this. We have to check it ourselves.
2022-04-11 01:44:30 +02:00
Kawe Mazidjatari
8c1dfb50f4 Address class cleanup/improvements
* Move most definitions to implementation file to avoid recompiling whole program for small changes
* Pass strings by reference for where possible.
* Split Module class to dedicated file.
* Add const qualifiers to all eligible methods for address/module class
* Some renaming
2022-04-10 19:59:34 +02:00
Kawe Mazidjatari
b3631facbe Update all function casts 2022-04-09 06:05:47 +02:00
Kawe Mazidjatari
e2f06a8a68 Massive performance improvements
Inline every signature defined in the SDK (previously each translation unit had its own copy of the signature and function prototype). DLL init is near instant now (85% speed improvements).
2022-04-09 02:18:57 +02:00
Kawe Mazidjatari
aa57170e0d Start of pattern search refactor 2022-04-09 01:14:22 +02:00
Kawe Mazidjatari
6feb41c285 Partial CNetChan class rebuild and implementation (see description)
* Adapt codebase to new class to reduce rune-like code.
* Fixed several bugs where the global CClient pointer was used instead of the instance in question to issue bans and display information about a certain client in CBanSystem and Pylon.
* Upgraded CBanSystem and Pylon to use IPv6 instead (including IPv4 mapped IPv6 addresses). This breaks all existing banlist files! All bans have to be re-issued or the existing file has to be updated to use IPv4 mapped IPv6 addresses and renamed to 'banlist.json', and moved to the root of the 'platform' folder.
2022-04-02 02:48:54 +02:00
Amos
c187bed4c5 RCON implementation (see description)
* Fully rewritten protocol agnostic CNetAdr class
* Fully rebuilded legacy CNetAdr class
* Fully rebuilded dual-stack CSocketCreator class
* New project "netconsole" added (lightweight netconsole for RCON)

RCON is still work in progress
2022-02-06 16:48:52 +01:00