100 Commits

Author SHA1 Message Date
Kawe Mazidjatari
99cabd2ac8 UserCmd: cleanup variable names and comments
Reversed some extra field names + adjusted comment for clamping ucmd->camerapos (this was tested and works, this field should be clamped).
2024-06-01 11:25:58 +02:00
Kawe Mazidjatari
381da23f44 VScript: properly handle internal errors during return
Must always check for internal error before returning out of a script function. The macro SCRIPT_CHECK_AND_RETURN will deal with this. Replaced all returns in each script func.
2024-04-05 18:35:05 +02:00
Kawe Mazidjatari
1c32339305 Squirrel: reverse more squirrel types and structures
This patch removes a lot of old code. Context is now exclusively grabbed from the CSquirrelVM instance. This patch also comes with a few new types: SQArray and SQTable!

The implementation also allows pushing Vector3D's on the stack, but these are handled slightly differently.. The largest field in tagSQObjectValue is 8 bytes, Vector3D is 12 bytes unaligned, but the tagSQObjectValue field in the tagSQObject struct is aligned to a 8 byte boundary while the field prior is only 4 bytes, Vector3D starts right after the type field in the tagSQObject (at the padding) to keep the whole structure the same size, therefore a new field has been added in between the padding (_pad) with a simple Vector3D accessor.

Also added a hook to allow registering proper script enums.
2024-04-05 18:31:06 +02:00
Kawe Mazidjatari
430b2877ad Cleanup/add some comments 2024-04-05 18:27:10 +02:00
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
ee82d5d8e0 Tier1: move KeyValues class to Tier1
The KeyValues class belongs here. Also reimplemented most loading methods for KeyValues, and adjusted the VPK building code to account for it. Pointers to the engine's implementation of KeyValues have been moved to a separate header ('keyvalues_iface.h'), as this allows external tools code to utilize the standalone KeyValues class implementation. Playlist utilities are completely separated from the KeyValues header; these have nothing to do with KeyValues other than manipulating a global KeyValues object for the playlists, and thus have been named as such and moved to rtech/playlists.
2024-04-05 17:42:05 +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
c1c01d2302 Swap SSE4.1 instruction with an SSE2 instruction
The min spec is SSSE3, using SSE4.1 instructions (_mm_extract_epi64) will break compatibility. The code containing the defect is debug only, and %90+ of the user base uses an SSE4.1 capable processor.
2024-04-05 15:57:33 +02:00
Kawe Mazidjatari
f2058c9ecd Fix typo
Second statement should be checking on vecMaxBound.
2024-04-05 15:57:33 +02:00
Kawe Mazidjatari
7b7177240d Improve NavMesh render performance 2024-04-05 15:57:33 +02:00
Kawe Mazidjatari
bc59f1349d Use CUtlVector for map list 2023-09-05 17:34:22 +02:00
Kawe Mazidjatari
25e5ea0c83 CAI_NetworkBuilder::SaveNetworkGraph() rewrite
- Use CUtlBuffer instead to construct the data.
- Dump traverse ex nodes as well (CAI_TraverseNode).
2023-08-28 20:01:45 +02:00
Kawe Mazidjatari
ea2c71242e Map out entity structures more
More types and improvements for base entity classes.
2023-08-27 00:20:23 +02:00
Amos
75e327e447 Normalize pitch angles
Prob not needed, but other unclamped angles/vectors were able to crash games in the past, so just normalize this too.
2023-08-15 20:19:38 +02:00
rexx
25bd407b39 add ScriptError script func 2023-08-12 22:41:48 +01:00
Kawe Mazidjatari
d59a320d69 Remove 'Error(EXIT_FAILURE)' call from 'CreateWeaponBolt()'
The bug has been fixed in the engine.
2023-08-09 02:56:58 +02:00
Kawe Mazidjatari
a0f0b79266 Add callback for registering script constants, and added 'LISTEN_SERVER'
All listen server code should be compiled out of the scripts using 'LISTEN_SERVER'. The constant must have a non-null value.
2023-07-19 18:52:00 +02:00
Kawe Mazidjatari
193abdc18a Remove scriptfunc stubs
Not really ideal, needs a different solution.
2023-07-19 17:17:38 +02:00
Kawe Mazidjatari
904352498c Fix missing 'arguments' parameter to stub macro 2023-07-19 16:18:04 +02:00
Kawe Mazidjatari
cb4a037433 Fix typo 2023-07-19 16:17:49 +02:00
Kawe Mazidjatari
f39de84d15 Create macro for scriptfunc definitions
Create a macro to make registration easier, by reducing the parameters.
2023-07-19 12:09:42 +02:00
Kawe Mazidjatari
6ccf3baa5a Split server/client specific game utils
Split into their respective libraries, this is to avoid linker errors regarding undefined symbols.
2023-07-19 02:27:28 +02:00
Kawe Mazidjatari
dccb897c27 Make 'sv_usercmd_dualwield_enable' server and client
Must be for server and client, as its used in shared code.
2023-07-19 02:14:09 +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
Amos
6e223d1730 Make shared code separate
The work is partial, and does not compile.
2023-07-18 21:05:29 +02:00
Kawe Mazidjatari
e33b566f88 Split server and client into separate libs
Work in progress; does not compile!
Moved script registration function to static gamedll libs instead, and used a pointer callback approach for calling them to avoid duplicate symbols during linkage.
2023-07-18 00:17:49 +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
64453b0661 Add CUserCmd constructor to SDK
Internal constructor from the engine.
2023-07-02 21:31:19 +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
c8648b9289 Fix typo
Typo.
2023-06-17 16:31:45 +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
c874b7c4d8 Implement 'SVC_UserMessage' print handler properly
Check if the actual message type is 'TextMsg' before printing, since other data is binary and could be read as 'HUD_PRINTCONSOLE', 'HUD_PRINTCENTER', etc.. resulting in printing binary data. This fix permanently solves that problem. The check has also been applied to the 'ShouldReplayMessage' function.
2023-06-12 02:02:29 +02:00
Kawe Mazidjatari
a2468bb184 Normalize view angles in client's usercmd
Must be normalized, bad values (NAN or FLT_MAX) will crash the game. There is more that needs to be clamped, but before we can do this CUserCmd has to be reversed more.
2023-06-06 00:53:05 +02:00
Kawe Mazidjatari
4ed2e7a12a Mark as const
Mark as const.
2023-06-05 01:37:00 +02:00
Kawe Mazidjatari
11fd49efde Fix speed hack exploit
The frame time send from CL_Move is not sanitized on the server; clamp it to the same cvars the client is clamping them to so players busting out the clamps cannot speed hack. The values are replicated between the server and client, so if someone wants to tweak the values, it won't mess up on either the server or client.
2023-06-05 01:24:23 +02:00
Kawe Mazidjatari
aac74c11b2 Use 'IsDedicated()' inline 2023-06-01 22:55:36 +02:00
Kawe Mazidjatari
8e379457bf Fix server code crasher in 'FireWeaponBolt'
The function 'FireWeaponBolt' calls 'CreateWeaponBolt' to create a bolt entity, but it can return NULL. 'FireWeaponBolt' does NOT check for NULL and derefs the pointer regardless. This rarely happens though; in all cases, it was caused by a defect in scripts. Code has been hooked to throw an engine error instead of crashing.
2023-05-31 23:58:10 +02:00
Kawe Mazidjatari
177cf2ca55 Add 'UTIL_GetEntityScriptInfo' to SDK
Retrieves information for an entity, formats it as <className> <scriptName> [<edict>] or <className> [<edict>].
2023-05-31 23:55:18 +02:00
Kawe Mazidjatari
ee636477ce Uncomment
Header file exists, but is stubbed; uncomment.
2023-05-11 21:35:54 +02:00
Kawe Mazidjatari
359820615f Move low level code to tier0/tier1
Moved to tier0/tier1 so it could be compiled into a static library in the future.
2023-05-06 22:59:01 +02:00
Kawe Mazidjatari
75ccebb4b6 Squirrel system restructure
Properly decouple squirrel and game code. This makes it easier to reverse engineer more of this squirrel system, and to compile them as individual libraries later on when moving to CMake to significantly decrease compile times.
2023-05-06 16:23:56 +02:00
Kawe Mazidjatari
b8035120de Assign unused constructor parameter 2023-04-16 01:23:38 +02:00
Kawe Mazidjatari
4079956356 Fix non-portable include paths
Portable include paths are case sensitive.
2023-04-08 18:52:33 +02:00
Kawe Mazidjatari
b0d2665550 /W4: Fix compiler compatibility
Clang doesn't support function-style casts with types containing a space.
2023-04-02 17:34:42 +02:00
Kawe Mazidjatari
4e7693bae6 /W4: Fix name shadowing warnings 2023-04-02 17:25:18 +02:00
Kawe Mazidjatari
42b3e49840 /W4: Properly pack server animation structures
Manually add fields to align structure properly. This suppresses many pesky compiler warnings.
2023-04-02 17:19:13 +02:00
Kawe Mazidjatari
a4a2f34c10 /W4: Fix signed/unsigned mismatch
This commit fixes warnings and bugs caused by signed/unsigned mismatch.
2023-04-02 12:09:43 +02:00
Kawe Mazidjatari
e9fac084fe Fix struct -> class compiler warning
'dtMeshTile' is defined as struct, but declared as class, causing a compiler warning. Fixed by declaring it as struct.
2023-04-02 01:23:07 +02:00