29 Commits

Author SHA1 Message Date
Kawe Mazidjatari
8c2400bab5 VScript: add 'sq_getentity' to SDK 2024-09-25 14:21:43 +02:00
Kawe Mazidjatari
8f384e424d VScript: constify callback parameters 2024-09-16 13:52:13 +02:00
Kawe Mazidjatari
2afa6d6c64 VScript: log duration of code callbacks 2024-09-16 13:46:36 +02:00
Kawe Mazidjatari
531fa21af1 VScript: add structures for closure and function proto 2024-09-16 13:37:08 +02:00
Kawe Mazidjatari
2896dc0d37 Engine: fix code bug when running "uiscript_reset" during init or load screens
Make sure this command cannot be executed before the UI VM is initialized or during load screens, doing so will hard crash the engine.
2024-07-01 01:30:01 +02:00
Kawe Mazidjatari
88ef6fdd8b VScript: add partially reversed 'SQClass' type 2024-06-16 20:24:00 +02:00
Kawe Mazidjatari
0634b6ded6 VScript: fix compiler error on VS2017
Compiler error only happens on VS2017's compiler "*\ found outside comment". Fixed error while also making the comment more clear.
2024-05-31 14:01:11 +02:00
Kawe Mazidjatari
7bc7c9d2f4 Engine: simplify "script" command callback for server
Code actually doesn't need to be ran in the server frame thread. All the code really does is preparation work. Run it in the main thread but do join the server frame thread (FCVAR_SERVER_FRAME_THREAD) as we can't do concurrent work on the server VM.
2024-04-20 01:33:34 +02:00
Kawe Mazidjatari
e7fd19cdf3 VScript: fix method order
More logical order of newly added methods.
2024-04-19 13:14:35 +02:00
Kawe Mazidjatari
f8f8be9870 Squirrel: fix struct name
bufCopy is actually bufPos as this indicated the current pos in the text buffer as it gets parsed out.
2024-04-19 13:13:17 +02:00
Kawe Mazidjatari
f70cc90eb9 VScript: move script run code to dedicated method 2024-04-19 13:12:35 +02:00
Kawe Mazidjatari
1455017419 VScript: properly implement script command callback
Previously we did sq_pushroottable() and a subsequent sq_call() after compiling the text buffer, but this didn't work for code that was threaded, or using Get/SetNetVar* functions.

The second issue was that the callback for the "script" command was ran in the main thread. Server script should always run in the server frame thread, the Set/GetNetVar* functions check thread id to retrieve the correct VM context, so running server script from the main thread ended up with Set/GetNetVar* functions retrieving the client VM context rather than server's, causing undefined behavior.

Script commands are now queued to the server frame thread, ultimately fixing this bug.

Also fixed a small bug with function 'sq_compilebuffer()'; it takes an extra argument but this wasn't taken into account in the SDK.
2024-04-19 12:56:10 +02:00
Kawe Mazidjatari
183a6e9c35 VScript: add CSquirrelVM::ExecuteFunction()
Executes script code by function handle.
2024-04-19 12:56:10 +02:00
Kawe Mazidjatari
42a8edc4cd Squirrel: add multiple SQ API functions
Added:
- sq_getstackobj
- sq_pop
- sq_addref
- sq_release
- SQVM::Pop
- RefTable::Get
- RefTable::AddRef
- RefTable::Release
2024-04-19 12:56:09 +02:00
Kawe Mazidjatari
785071d7bb VScript: map out CSquirrelVM structure more
More reversed fields.
2024-04-03 18:57:32 +02:00
Kawe Mazidjatari
5bbec8bdd9 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-03 18:30:57 +02:00
Kawe Mazidjatari
bcf994e210 VScript: add code for calling codecallbacks 2024-04-03 14:51:44 +02:00
Kawe Mazidjatari
83b1f43dbc Engine: properly deal with server frame thread commands/convars
Marked convars/concommands as FCVAR_SERVER_FRAME_THREAD and removed main thread dispatching code and comments that are no longer in effect. In the RCONServer execute handler, a ThreadJoinServerJob() is placed if the commandbase is flagged FCVAR_SERVER_FRAME_THREAD since RCON dispatches the command, or sets the convar directly.
2024-04-01 01:02:02 +02:00
Kawe Mazidjatari
cf93cb3101 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-03-31 17:01:32 +02:00
Kawe Mazidjatari
1836146efe 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-03-25 01:41:52 +01:00
Kawe Mazidjatari
c0879dc59c Squirrel: add more types and functions
More reversed types, more functions.
2024-03-16 11:36:49 +01:00
Kawe Mazidjatari
78e2a67e84 Squirrel: add functionality to register enums 2024-03-16 01:27:18 +01:00
Kawe Mazidjatari
420cb7a68d Engine: make task queue singleton static
Compile it as static object & renamed to more correct names. Also made the integral type for frame delay an unsigned int instead
2024-02-28 00:43:57 +01:00
Kawe Mazidjatari
6828901815 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-02-24 02:15:09 +01:00
Kawe Mazidjatari
1361bfb172 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-01-21 21:29:23 +01:00
Kawe Mazidjatari
c9a9b01bf2 RTech: major pak system overhaul and rebuild
* split rtech_game and rtech_utils cpp files into multiple files
* rebuilt several large pak load routines for debugging and custom implementations
* moved rson code to rtech_game
* reworked and improved engine and sdk pak precache system
* reversed more of the jobthreads system
2024-01-21 20:23:25 +01:00
Kawe Mazidjatari
e825a1e7a8 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-01-02 15:21:36 +01:00
Kawe Mazidjatari
e541814482 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.
2023-11-26 13:21:20 +01:00
Kawe Mazidjatari
fd3e227a86 Align folder structure with p4 2023-09-19 22:13:22 +02:00