17 Commits

Author SHA1 Message Date
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
054b123004 Don't load certain lumps for dedicated
This significantly reduces disk size, and also reduces memory usage.
2023-05-29 01:03:27 +02:00
Kawe Mazidjatari
78a962ed2f CMapLoadHelper: ctor cleanup
Slightly improved code, actual functionality hasn't changed.
2023-05-26 21:54:24 +02:00
Kawe Mazidjatari
bafaa1b7de Remove unused enum 2023-05-22 22:46:18 +02:00
Kawe Mazidjatari
b75c32903f Allow lumps to be read from filesystem cache
Only certain lumps can be cached; see switch case in 'IsLumpIdxCachable'. Attempting to load anything else from cache results in a code crash or invalid data.
2023-05-22 22:40:27 +02:00
Kawe Mazidjatari
4c6840be6c Light cleanup for 'CMapLoadHelper' ctor 2023-05-22 12:08:02 +02:00
Kawe Mazidjatari
2d0c033f95 Fix LUMP_GAME_LUMP not loading from the disk
Last lump to not load from the disk, see function 'AddGameLump' for details as to how this is performed.
2023-05-21 18:08:07 +02:00
Kawe Mazidjatari
27925d3b7d Fix compiler warning causing compile errors
Unused initialized local variable.
2023-05-21 01:59:37 +02:00
Kawe Mazidjatari
ecf7f973f8 Allow to load all lumps from disk
This commit allows for loading all lumps from disk, if the m_bExternal var is set, it also attempts to load the lumps listed in the function 'IsLumpTypeExternal' from the cache, but through a different code path, which causes a crash. Setting this to false allows for loading it in the ctor.
2023-05-20 21:44:53 +02:00
rexx
66f52dea23 fix missing valid external lump check
bsp_lump loading was missing a check for if the lump is supposed to be able to load from disk

also removes VERTEX lumps from loading from disk due to crashes that occur when they are kept
2023-05-20 14:54:00 +01:00
rexx
d7f0de9d40 fix external bsp_lump loading
previously the lump data was being freed immediately after loading. this sets m_pRawData to nullptr so that doesn't happen
2023-05-20 13:49:12 +01:00
Kawe Mazidjatari
4297cd9ce3 Experimental BSP_LUMP loading hook
The 'CMapLoadHelper' constructor has been rebuild to load lump files too (if they exist). Currently, the game only reads the packed BSP file, or lumps if they exist in the filesystem cache. The newly added logic also reads them from a file. This is currently broken, most likely due to alignment problems. Experimental.
2023-05-20 14:06:36 +02:00
rexx
d521c67367 Hook CMapLoadHelper ctor
This will be used for enabling bsp_lump file loading in the future
2023-05-19 20:21:11 +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
4b72afb74f Light refactor for logging
Moved logging functions to dbg.h (tier0) and export them from the dll.
Added additional functions for checking bad pointers (debug only!).
Reduced output code size.
2022-05-25 14:18:29 +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
Amos
6583e174de Implement custom paks loading per level
Game will check scripts/levels/mapname.json and load all rpaks in the rpak field.
Game now also unloads pak files loaded by the SDK preventing crashes and unnecessary memory usage.

VPK's and STBSP's are planned to be added as well.
2022-03-01 02:39:46 +01:00