2022-03-02 01:16:35 +01:00
|
|
|
//===========================================================================//
|
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
//
|
|
|
|
//===========================================================================//
|
|
|
|
#include "core/stdafx.h"
|
2022-04-09 16:16:40 +02:00
|
|
|
#include "tier1/cvar.h"
|
2022-08-18 02:15:23 +02:00
|
|
|
#include "rtech/rtech_utils.h"
|
2022-08-31 03:01:45 +02:00
|
|
|
#include "filesystem/filesystem.h"
|
2022-03-26 01:04:20 +01:00
|
|
|
#include "materialsystem/cmaterialsystem.h"
|
2022-03-02 01:16:35 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: loads and processes STBSP files
|
|
|
|
// (overrides level name if stbsp field has value in prerequisites file)
|
2022-06-23 20:08:07 +02:00
|
|
|
// Input : *pszLevelName -
|
2022-03-02 01:16:35 +01:00
|
|
|
//---------------------------------------------------------------------------------
|
2022-06-23 20:08:07 +02:00
|
|
|
void StreamDB_Init(const char* pszLevelName)
|
2022-03-02 01:16:35 +01:00
|
|
|
{
|
2022-05-27 22:31:52 +02:00
|
|
|
ostringstream ostream;
|
2022-08-31 03:01:45 +02:00
|
|
|
ostream << "scripts/levels/settings/" << pszLevelName << ".json";
|
2022-03-02 01:16:35 +01:00
|
|
|
|
2022-09-01 01:05:15 +02:00
|
|
|
FileHandle_t pFile = FileSystem()->Open(ostream.str().c_str(), "rt");
|
2022-08-31 03:01:45 +02:00
|
|
|
if (pFile)
|
2022-03-02 01:16:35 +01:00
|
|
|
{
|
2022-08-31 03:01:45 +02:00
|
|
|
uint32_t nLen = FileSystem()->Size(pFile);
|
|
|
|
uint8_t* pBuf = MemAllocSingleton()->Alloc<uint8_t>(nLen);
|
|
|
|
|
2022-09-01 01:05:15 +02:00
|
|
|
int nRead = FileSystem()->Read(pBuf, nLen, pFile);
|
2022-08-31 03:01:45 +02:00
|
|
|
FileSystem()->Close(pFile);
|
|
|
|
|
2022-09-01 01:05:15 +02:00
|
|
|
pBuf[nRead] = '\0';
|
|
|
|
|
2022-03-02 01:16:35 +01:00
|
|
|
try
|
|
|
|
{
|
2022-08-31 03:01:45 +02:00
|
|
|
nlohmann::json jsIn = nlohmann::json::parse(pBuf);
|
2022-03-02 01:16:35 +01:00
|
|
|
if (!jsIn.is_null())
|
|
|
|
{
|
2022-08-11 11:07:45 +02:00
|
|
|
if (!jsIn[STREAM_DB_EXT].is_null())
|
2022-03-02 01:16:35 +01:00
|
|
|
{
|
2022-08-11 11:07:45 +02:00
|
|
|
string svStreamDBFile = jsIn[STREAM_DB_EXT].get<string>();
|
|
|
|
DevMsg(eDLL_T::MS, "%s: Loading override STBSP file '%s.%s'\n", __FUNCTION__, svStreamDBFile.c_str(), STREAM_DB_EXT);
|
2022-08-31 03:01:45 +02:00
|
|
|
|
2022-05-27 22:31:52 +02:00
|
|
|
v_StreamDB_Init(svStreamDBFile.c_str());
|
2022-08-31 03:01:45 +02:00
|
|
|
MemAllocSingleton()->Free(pBuf);
|
|
|
|
|
2022-03-02 01:16:35 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
{
|
2022-08-31 03:01:45 +02:00
|
|
|
Warning(eDLL_T::MS, "%s: Exception while parsing STBSP override:\n%s\n", __FUNCTION__, ex.what());
|
2022-03-02 01:16:35 +01:00
|
|
|
}
|
2022-08-31 03:01:45 +02:00
|
|
|
|
|
|
|
MemAllocSingleton()->Free(pBuf);
|
2022-03-02 01:16:35 +01:00
|
|
|
}
|
2022-08-31 03:01:45 +02:00
|
|
|
|
2022-08-11 11:07:45 +02:00
|
|
|
DevMsg(eDLL_T::MS, "%s: Loading STBSP file '%s.%s'\n", __FUNCTION__, pszLevelName, STREAM_DB_EXT);
|
2022-06-23 20:08:07 +02:00
|
|
|
v_StreamDB_Init(pszLevelName);
|
2022-03-02 01:16:35 +01:00
|
|
|
}
|
|
|
|
|
2022-04-30 20:35:08 +02:00
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: draw frame
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1)
|
2022-05-18 01:22:59 +02:00
|
|
|
void* __fastcall DispatchDrawCall(int64_t a1, uint64_t a2, int a3, int a4, char a5, int a6, uint8_t a7, int64_t a8, uint32_t a9, uint32_t a10, __m128* a11, int a12)
|
2022-04-30 20:35:08 +02:00
|
|
|
#elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3)
|
|
|
|
void* __fastcall DispatchDrawCall(int64_t a1, uint64_t a2, int a3, int a4, int64_t a5, int a6, uint8_t a7, int64_t a8, uint32_t a9, uint32_t a10, int a11, __m128* a12, int a13, int64_t a14)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
// This only happens when the BSP is in a horrible condition (bad depth buffer draw calls!)
|
|
|
|
// but allows you to load BSP's with virtually all missing shaders/materials and models
|
|
|
|
// being replaced with 'material_for_aspect/error.rpak' and 'mdl/error.rmdl'.
|
|
|
|
if (!s_pRenderContext.GetValue<void*>())
|
|
|
|
return nullptr;
|
|
|
|
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1)
|
|
|
|
return v_DispatchDrawCall(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12);
|
|
|
|
#elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3)
|
|
|
|
return v_DispatchDrawCall(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-03-02 01:16:35 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
void CMaterialSystem_Attach()
|
|
|
|
{
|
2022-05-27 22:31:52 +02:00
|
|
|
DetourAttach((LPVOID*)&v_StreamDB_Init, &StreamDB_Init);
|
2022-04-30 20:35:08 +02:00
|
|
|
DetourAttach((LPVOID*)&v_DispatchDrawCall, &DispatchDrawCall);
|
2022-03-02 01:16:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMaterialSystem_Detach()
|
|
|
|
{
|
2022-05-27 22:31:52 +02:00
|
|
|
DetourDetach((LPVOID*)&v_StreamDB_Init, &StreamDB_Init);
|
2022-04-30 20:35:08 +02:00
|
|
|
DetourDetach((LPVOID*)&v_DispatchDrawCall, &DispatchDrawCall);
|
2022-03-02 01:16:35 +01:00
|
|
|
}
|