373 Commits

Author SHA1 Message Date
Kawe Mazidjatari
f609f16427 Don't compile debug code in cert builds 2024-04-05 16:41:11 +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
699a4ce464 Implement CCommandBuffer
Code is based on Valve's implementation, with the following changes:
- Usage of 64bit signed size types.
- Usage of const where possible.
- Removal of field 'CCommandBuffer::m_nLastUsedArgSSize'.
2024-04-05 16:39:22 +02:00
Kawe Mazidjatari
a8312517f4 CCommand adjustments
Moved inlines to header; made ArgC return 32bit integer instead.
2024-04-05 16:34:30 +02:00
Kawe Mazidjatari
4b7ca6b439 Use size types
Make code more portable and modern.
2023-08-29 22:05:20 +02:00
Kawe Mazidjatari
befd38bf51 Interface factory system rewrite
Removed all extraneous copies by adding the class 'InterfaceReg' which will construct a new interface, and link it to the engine's static register. The Source Engine macro 'EXPOSE_INTERFACE_FN' will help utilizing this. The game module from the plugin is not obtained through the process environment block, so the executable is no longer sensitive to names.
2023-08-22 01:11:49 +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
8c87ad219f Add more bitbuf inlines
Added:
- Tell()
- GetNumBitsLeft()
- GetNumBytesLeft()
2023-08-21 16:14:54 +02:00
Kawe Mazidjatari
0066b82da7 Light cleanup 2023-08-21 11:35:24 +02:00
Kawe Mazidjatari
c344dde672 Add bitbuf getters 2023-08-21 11:28:55 +02:00
Kawe Mazidjatari
26c10dfd11 Restructure concommandbase classes
Move all classes deriving from ConCommandBase to a single file, and split out CCommand, CCvar, CCvarUtilities etc to their own files. This makes it possible to use CCommand and stuff in external tools without linker errors/warnings.
2023-08-04 14:32:06 +02:00
Kawe Mazidjatari
21f64bc572 Adjust logging contexts
Adjust the context properly, some were wrong (e.g. 'ENGINE' in 'COMMON' code).
2023-07-22 21:14:04 +02:00
Kawe Mazidjatari
00f349c745 Use ICVar iterator for console partial suggest
Added public interface to ICVarIteratorInternal, this class also deals with the deletion of the iterator. This fixes the problem of cvars not showing up that have been registered after 'CModAppSystemGroup::Create()' has been called. Currently, no cvar is registered after it. This will/could change when the plugin system is utilized.

Additional changes:
- Cvar 'con_suggestion_flags_realtime' has been removed, as we no longer keep an early copy anymore; real time flags are always shows from now on.
 - Fixed a bug in 'CConsole::FindFromPartial()' where we would return in the loop when 'm_vSuggest.size() >= con_suggestion_limit->GetInt()', instead of breaking out, which skips the element sorting process.
2023-07-22 14:51:15 +02:00
Kawe Mazidjatari
15c293126e Use fast tolower/toupper defines instead 2023-07-22 14:40:47 +02:00
Kawe Mazidjatari
e8e600f553 Add missing convar flags
Added:
- FCVAR_ACCESSIBLE_FROM_THREADS [1<<25]
- FCVAR_STUDIO_SYSTEM [1<<26]
- FCVAR_SERVER_FRAME_THREAD [1<<27]
- FCVAR_PLATFORM_SYSTEM [1<<31]

This commit also removes the 'FCVAR_MATERIAL_THREAD_MASK' from the ConVarFlags class (which is a helper struct for displaying flags on the developer console), as this is a mask and would therefore be marked as such in case a single bit in the mask matches, and all these bits are already added to the list.
2023-07-20 21:02:27 +02:00
Kawe Mazidjatari
dbb18e586d Add 'V_ComparePath'
Add function to compare paths for equality, while ignoring case and path separators.
2023-07-10 19:16:12 +02:00
Kawe Mazidjatari
77299dd3de Remove extraneous 'V_FixSlashes' call
No need to fix slashes when stripping last dir. We can always fix them up on a subsequent call to 'V_FixSlashes' if we ever need to.
2023-07-05 22:08:32 +02:00
Kawe Mazidjatari
42d12a644e Fix bug in 'V_StripLastDir' and 'CUtlString::DirName'
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.
2023-07-05 21:50:36 +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
3e4d02afe1 Remove non-existent ConVar flag
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.
2023-07-03 14:32:52 +02:00
Kawe Mazidjatari
398c0f1ddc ConVar flags tools refactor
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.
2023-07-03 13:48:13 +02:00
Kawe Mazidjatari
f6f3c7f9a2 More code cleanup
- 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.
2023-07-03 02:14:39 +02:00
Kawe Mazidjatari
22f68ff22a Fix utlstring bug
Fixed V_strstr overloading by swapping order of parameters.
2023-07-03 02:06:40 +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
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
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
6361e64b5c Improve readability
Break up lines so they fit on a vertical monitor.
2023-06-19 22:42:25 +02:00
Kawe Mazidjatari
3f8baf6f68 Allow setting compile options for specific targets
Previously, it was all controlled from the global init (applied to all projects), but some projects need different options. With these changes, you can disable the common options applied in the 'add_module' macro, and set your own if desired.
2023-06-17 00:45:27 +02:00
Kawe Mazidjatari
4969a84030 Fix desync in CUtlbuffer::ParseToken
The if statement comparing 'nLen' with 'nMaxLen' increments 'nLen' first at all times, but the statement below that checks the delimiters seeks -1 from current pos, causing a desync. This could result in reading arbitrary memory on certain strings. This fix also fixes the useless need to 'snag' the delimiters from tokens.
2023-06-07 21:21:55 +02:00
Kawe Mazidjatari
8e1019a265 Make simple CNetAdr methods inline
Should be inline for their simplicity to improve performance.
2023-06-05 01:45:33 +02:00
Kawe Mazidjatari
63ca5d9d98 Make small bitbuf methods inline
Make inline to boost performance.
2023-06-03 18:04:38 +02:00
Kawe Mazidjatari
7f15b94cd9 String tools improvements
* Add 'V_IsValidPath'.
* Add optional parameter to 'V_StripLastDir', in which the new length of the string gets written into.
2023-05-29 21:37:15 +02:00
Kawe Mazidjatari
7e2b249ef6 CUtlString improvements
* 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'.
2023-05-29 21:35:12 +02:00
Kawe Mazidjatari
11864f8902 Add all public headers to CMake projects
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.
2023-05-15 14:47:03 +02:00
Kawe Mazidjatari
9f44bcc818 Treat compiler warnings as errors
Treat them as errors globally. Most of the time a warning is a bug, or problem in code that could be solved in a different (better) manner. Thirdparty code have this disabled. The warnings as errors option can be globally disabled through the CMake GUI, but this is not recommended.
2023-05-15 09:44:26 +02:00
Kawe Mazidjatari
6a86ae2606 Cleanup CMakeLists files
Light cleanup in CMakeLists files. Split protocols and improve filter names.
2023-05-14 17:36:08 +02:00
Kawe Mazidjatari
7248c8aab7 Fix compiler warning
Use size_t instead to avoid the type truncation warning.
2023-05-14 02:11:29 +02:00
Kawe Mazidjatari
d809a9f633 Use PCH generated from VPC globally
This reduced output code size with 40KiB, improved compile times and appeared to improve runtime performance as well.
2023-05-14 02:10:17 +02:00
Kawe Mazidjatari
7ef50395eb Remove unused header file 2023-05-13 14:02:16 +02:00
Kawe Mazidjatari
8dbc2024c6 CMake code improvements
Use the 'add_module' macro to add modules without creating duplicate code. This macro also takes a reuse PCH as parameter, so modules that need a precompiled header, could reuse those from different targets that compile them. This commit also restructures the group order of the generated solution files for easier code navigation.
2023-05-13 00:14:53 +02:00
Kawe Mazidjatari
ee636477ce Uncomment
Header file exists, but is stubbed; uncomment.
2023-05-11 21:35:54 +02:00
Kawe Mazidjatari
f120354e96 Initial port to CMake
* All libraries have been isolated from each other, and build into separate artifacts.
* Project has been restructured to support isolating libraries.
* CCrashHandler now calls a callback on crash (setup from core/dllmain.cpp, this can be setup in any way for any project. This callback is getting called when the apllication crashes. Useful for flushing buffers before closing handles to logging files for example).
* Tier0 'CoreMsgV' function now calls a callback sink, which could be set by the user (currently setup to the SDK's internal logger in core/dllmain.cpp).

TODO:
* Add a batch file to autogenerate all projects.
* Add support for dedicated server.
* Add support for client dll.

Bugs:
* Game crashes on the title screen after the UI script compiler has finished (root cause unknown).
* Curl error messages are getting logged twice for the dedicated server due to the removal of all "DEDICATED" preprocessor directives to support isolating projects. This has to be fixed properly!
2023-05-10 00:05:38 +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
39ccf8636d Force ConVar getters as inline 2023-05-03 23:59:33 +02:00
rexx
bcc51460bc
new new modsystem pr (#96)
* modsystem v2 initial commit

* call CModSystem::Init

* clean up custom cvar value handling

* add mod script compiling support

* add error check to script rson loading

yes this error is a duplicate but this one exits the game

* fix typo

* fix compile error
2023-05-02 19:26:49 +01:00
rexx
1055ba8994 add serverbrowser convars to fix script error 2023-05-01 20:41:27 +01:00
rexx
f90bba9d85 Fix compile
This assert was accidentally left in to catch any invalid calling of CNetAdr::ToString
2023-05-01 15:15:06 +01:00
Kawe Mazidjatari
366ff3fb4f Remove devonly flag from 'net_usesocketsforloopback' 2023-05-01 00:01:18 +02:00
Kawe Mazidjatari
ef20846314 Remove extraneous include 2023-04-30 21:43:08 +02:00