42 Commits

Author SHA1 Message Date
Kawe Mazidjatari
250fd504af VScript: properly implement 'sq_getstring' and 'sq_getinteger' + more
sq_getstring and sq_getinteger are now properly implemented (code matches squirrel code, and generated assembly matches that of the game). Adjusted call sites to accommodate the new implementation and added a few extra checks. Also added:
* sq_getfloat
* sq_getbool
* sq_getthread
2024-04-05 18:40:37 +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
b8178e9299 NetworkSystem: fix numerous issues
This patch splits host logic from CServerListManager. CServerListManager is actually meant for the client to manage the server list to which the client could connect to. The hosting logic has been moved to the new CServerHostManager class.

Previously, we stored all the hosting details in CServerListManager, with connection criteria in CPylon, this data has been moved over to CServerHostManager as well.

Previously, we also needed a mutex to access the server host data, function HostState_KeepAlive() has been refactored to the point this mutex is no longer necessary as the only threaded process is the actual request, the rest is being applied in the main thread. We also now only construct a NetGameServer_t struct if we actually plan to host.

Access to CPylon::m_Language is now also protected by a mutex, as the change callback of cvar 'language' and the threaded method 'CPylon::QueryServer()' are competing for access.
2024-04-05 18:24:36 +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
d6b14fa12c Statically construct all ConCommand
Properly implement the ConCommandBase and ConCommand classes so we could statically construct all ConCommand objects in the global scope of each translation unit, this way we don't need to put them in a global file and deal with preprocessor directives to compile then in/out for certain projects.
2024-04-05 18:13:31 +02:00
Kawe Mazidjatari
dbec4be848 NetworkSystem: rename NetGameServer_t member vars 2024-04-05 17:52:58 +02:00
Kawe Mazidjatari
fcf3a09418 Make singletons use static memory
Avoid heap memory allocation and a level of indirection. This allows the compiler to optimize the program even more. No logic has been changed in this patch.
2024-04-05 17:52:57 +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
fa76747baa Show a more detailed error if the EULA request failed 2024-04-05 16:34:29 +02:00
Kawe Mazidjatari
22c82d6f1d EULA dialog implementation
Display the EULA (fetched from masterserver), which the end user MUST accept before they can make use of the multiplayer features of R5Reloaded. NOTE: user doesn't need to agree to this to use the listenserver.
2024-04-05 16:26:18 +02:00
Kawe Mazidjatari
0eaa226dce Change JSON field types send to master server
They were all strings; changed them to what made most sense for each field type. Changes:
"hidden": string -> bool
"port": string -> int
"checksum": string -> uint
"playerCount": string -> int
"maxPlayers": string -> int
2024-04-05 16:24:46 +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
193abdc18a Remove scriptfunc stubs
Not really ideal, needs a different solution.
2023-07-19 17:17:38 +02:00
Kawe Mazidjatari
ee1fdca7a9 Register admin panel/core server scriptfunc stubs for client.dll
Stubbed to avoid compile errors.
2023-07-19 16:19:34 +02:00
Kawe Mazidjatari
d860c43f79 Deduplicate code
Small deduplication.
2023-07-19 12:25:43 +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
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
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
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
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
c2efdb59ae Move CViewRender vtable init to GetCon 2023-01-31 23:43:29 +01:00
Kawe Mazidjatari
b33c8794a0 Reorder registration order
Slight reorder, removed 'VStudioRenderContext' from dedicated.
2023-01-31 17:21:16 +01:00
Amos
d76ed1098a Improve VFTable address logging
More standardized VFTable address logging.
2023-01-25 11:19:53 +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
e281aea990 Fix client.dll/dedicated.dll compile errors 2023-01-24 18:39:12 +01:00
Kawe Mazidjatari
1d8e61ebff Fixup 'CMoveHelperServer' and 'CMoveHelperClient'
Uncomment field.
2023-01-20 17:21:34 +01:00
Kawe Mazidjatari
dcf05a0adf CClientEntityList reversal
Slightly reversed CClientEntityList while looking around its singleton.
2023-01-20 00:28:49 +01:00
Kawe Mazidjatari
05748e6184 Add client movehelper to SDK
Structure and vftable align 100%.
2023-01-19 19:39:15 +01:00
Kawe Mazidjatari
7279039226 Delete empty files 2023-01-19 18:57:28 +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
Marvin D
d00aaa933d CRenderView init, GetWorldMatrixForView()
* Fixed .gitignore for root /game/
* Fixed bug in WalkVTable where it would offset self.
* General clean up: VAR -> CON, CON -> VAR
2022-11-10 00:53:12 +01:00
Kawe Mazidjatari
50fee7414d Missing material error logging
This commit implements missing material error logging.
When a material does not exist, it will get replaced with an error material, we log which material is missing, and with which error material it gets replaced with.
This commit also comes with some updates regarding the CMaterialGlue class, and some new types used by this class from the RePak project.
2022-10-13 02:22:50 +02:00
Kawe Mazidjatari
329621c6ad Move all public headers into root of 'public' 2022-08-09 17:18:07 +02:00
Kawe Mazidjatari
8c6ee8a834 Remove 'm' prefix from dll globals
Large commit.
2022-08-09 03:02:00 +02:00
Kawe Mazidjatari
799dac882a Add 'MainViewOrigin()' and 'MainViewAngles()'
Implemented g_vecRenderOrigin and g_vecRenderAngles to SDK.
2022-07-25 12:46:57 +02:00
Kawe Mazidjatari
f314b9b4e7 Start of C_Player reversing 2022-07-24 12:59:40 +02:00
Kawe Mazidjatari
3cb4976c23 Start or 'mdl/error.rmdl' fallback implementation (see description)
In 'datacache/mdlcache.cpp' the function 'CMDLCache::FindMDL' attempts to find 'mdl/error.rmdl' and assigns the studiohdr and handle to the members of CMDLFallback.

In 'CMDLCache::FindUncachedMDL' we check if a model exists, if a model does not exist, we replace the studiohdr with the one of error.rmdl we stored in the CMDLFallback structure.

This does actually work (on the dedicated server it doesn't crash at all!), but on the client it crashes when trying to gather props (right before rendering), setting the ConVar* 'old_gather_props' does interesting things (check IDA around this ConVar*). setting this to 1 causes it to crash in another CMDLCache method when trying to deref something in the global cache pool.

This method is easy to rebuild. I will do this soon and attempt to return error.rmdl parts from here as well if results are null (this might actually just work).

Leaving 'old_gather_props' to 0 causes it to crash in the middle of the function which is supposed to gather the props the 'new' way.

The gather props functions are kind of daunting

NOTE: Currently only confirmed to work somewhat properly on the dedicated server for prop_static. prop_dynamic is unconfirmed. And (almost?) works on the client.
2022-04-29 05:30:06 +02:00
Kawe Mazidjatari
f4b263b412 Cleanup 2022-04-05 01:13:27 +02:00