r5sdk/r5dev/engine/staticpropmgr.cpp
rexx f520cab44b fix static prop exceptions
This fixes the exceptions that were caused by loading ported bsps with replaced models
CStaticProp::Init was using static prop lump data to request non-existent skins due to the replaced models, causing invalid material pointers to be fetched.
When encountered, these skins will be forced to 0 and an error will be printed.
Ideally these issues are fixed from within the bsp file before they are shipped.
2023-04-18 16:56:35 +01:00

38 lines
1.3 KiB
C++

#include "core/stdafx.h"
#include "datacache/mdlcache.h"
#include "engine/staticpropmgr.h"
//-----------------------------------------------------------------------------
// Purpose: initialises static props from the static prop gamelump
//-----------------------------------------------------------------------------
void* __fastcall CStaticProp_Init(int64_t thisptr, int64_t a2, unsigned int idx, unsigned int a4, StaticPropLump_t* lump, int64_t a6, int64_t a7)
{
MDLHandle_t handle = *reinterpret_cast<uint16_t*>(a7 + 0x140);
studiohdr_t* pStudioHdr = g_MDLCache->FindMDL(g_MDLCache, handle, nullptr);
if (lump->m_Skin >= pStudioHdr->numskinfamilies)
{
Error(eDLL_T::ENGINE, NO_ERROR,
"Invalid skin index for static prop %i with model '%s' (got %i, max %i)\n",
idx, pStudioHdr->name, lump->m_Skin, pStudioHdr->numskinfamilies-1);
lump->m_Skin = 0;
}
return v_CStaticProp_Init(thisptr, a2, idx, a4, lump, a6, a7);
}
void VStaticPropMgr::Attach() const
{
#ifndef DEDICATED
DetourAttach((LPVOID*)&v_CStaticProp_Init, &CStaticProp_Init);
#endif // !DEDICATED
}
void VStaticPropMgr::Detach() const
{
#ifndef DEDICATED
DetourDetach((LPVOID*)&v_CStaticProp_Init, &CStaticProp_Init);
#endif // !DEDICATED
}