Slightly mapped out the structure more.
The function should now be compatible with earlier game dll's.
CStudioHWDataRef::SetFlags has to be rebuild as these are declared inline for earlier game dll's.
* Rebuild SetRestrictedServerCommand and SetRestrictedClientCommands
* Implemented new CMemory Function to walk through a VTable.
* pDetours->GetCon() gets called first now.
*
Before we used the stbsp's, but we don't need to copy these for each maps (we could load existing ones to get working texture streaming for maps that don't have this)
Note: this does not work reliably still.
The only way we could make this work 100% reliable would be to fully rebuild '0x140341D40' in the SDK and load our pak files among with the pre-existing g_pakLoadApi->AsyncLoad() call in this function, as this will ensure everything will be ran synchronously.
The current approach by taking some JT fifolock wrapper will only work reliably between one level change, unsure why the second and up fail.
Fixed 'MOD_PreloadPak()' being called recursively.
Fixed wrong datatype for pak handle.
Use new and better method of parsing JSON files.
Don't unload pak files if user issued 'ChangeLevel' to the same level.
NOTE: This is still not complete and currently under development.
Redacted most code to only perform operation to obtain studiohdr and staticprop material (read only operation, function does not modify memory used by the original 'v_BuildPropStaticFrustumCullMap()' implementation!)
The new function checks if pointer is within bounds (must stay within .data memory), if this isn't the case, the 'batch' is considered corrupt and function call to 'v_BuildPropStaticFrustumCullMap' won't proceed (note that the loop checks all bodygroups/LOD's of a model, it is possible that one doesn't have corrupt data, but a model where only one of its submeshes culls properly in the level is too much effort to fix as this function is based of disassembled output of the engine implementation, which in it self, comes with its own limitations).
For a better implementation we should proceed fully rebuilding the function (see commented function body).
The current and only problem with this is that it doesn't compute cull data properly (see bsplib.cpp line '222').
This has to be debugged still as the computed data does not match the one computed from the engine (this is the reason the larger maps show artifacts!)
* Fixed bug where the address of g_pStaticPropMgr wasn't properly dereferenced and passed to function via its reference (engine addr).
* Fixed dword dereference.
Problems: engine still culls models improperly.
Fixed rare crash in CMDLCache when buffer itteration returns invalid pointer (not null!) for handle.
Made all variables and functions used by BuildPropStaticFrustumCullMap searched dynamically (these should also work on s0, s1 and s2, they are compared but at the moment untested).
TODO: Fix deref crash properly (see bsplib.cpp l291).
This crash happens when the BSP is missing a lot of shaders and materials.
The call originates from 'R_DrawWorldMeshesDepthOnly()', but it is unclear which missing shader is causing the nullptr. checking for a nullptr here should be sufficient to deal with this kind of missing shader
Rare crash when the sqvm tries to look for an animation sequence on a missing prop_dynamic model (mdl/error.rmdl doesn't support animations), its purely to indicate there is a problem).
This is mainly for development only and in the event so many models/textures/shaders are missing, the engine would effectively crash otherwise (if some of these aren't disabled).
Only works for prop_static (for the time being)
Only works for the S3 game_dll.
In order to get this to work: you must set 'old_gather_props' to nun-null and (for certain maps) perform the patch to prevent the frustum culling code to deref a bad pointer (see command 'opcodes test').
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.