2022-03-02 01:16:35 +01:00
|
|
|
//===========================================================================//
|
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
//
|
|
|
|
//===========================================================================//
|
|
|
|
#include "core/stdafx.h"
|
2023-01-31 22:13:40 +01:00
|
|
|
#include "tier0/crashhandler.h"
|
2023-12-20 22:21:31 +01:00
|
|
|
#include "tier0/commandline.h"
|
2022-04-09 16:16:40 +02:00
|
|
|
#include "tier1/cvar.h"
|
2024-04-05 17:42:05 +02:00
|
|
|
#include "tier1/keyvalues.h"
|
2024-04-05 17:51:19 +02:00
|
|
|
#include "rtech/pak/pakparse.h"
|
2022-11-24 11:10:46 +01:00
|
|
|
#include "engine/cmodel_bsp.h"
|
2023-12-26 02:37:07 +01:00
|
|
|
#include "engine/sys_engine.h"
|
2023-12-20 22:21:31 +01:00
|
|
|
#include "geforce/reflex.h"
|
2023-07-17 11:54:14 +02:00
|
|
|
#ifndef MATERIALSYSTEM_NODX
|
2024-04-05 16:45:05 +02:00
|
|
|
#include "windows/id3dx.h"
|
2022-10-05 01:59:22 +02:00
|
|
|
#include "materialsystem/cmaterialglue.h"
|
2023-07-17 11:54:14 +02:00
|
|
|
#endif // !MATERIALSYSTEM_NODX
|
2022-03-26 01:04:20 +01:00
|
|
|
#include "materialsystem/cmaterialsystem.h"
|
2022-03-02 01:16:35 +01:00
|
|
|
|
2023-12-20 22:21:31 +01:00
|
|
|
#ifndef MATERIALSYSTEM_NODX
|
2024-04-05 16:45:05 +02:00
|
|
|
PCLSTATS_DEFINE()
|
2023-12-20 22:21:31 +01:00
|
|
|
#endif // MATERIALSYSTEM_NODX
|
|
|
|
|
2023-07-17 11:54:14 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: initialization of the material system
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
InitReturnVal_t CMaterialSystem::Init(CMaterialSystem* thisptr)
|
|
|
|
{
|
|
|
|
#ifdef MATERIALSYSTEM_NODX
|
|
|
|
// Only load the 'startup.rpak' file, as 'common_early.rpak' has assets
|
|
|
|
// that references assets in 'startup.rpak'.
|
2023-09-19 20:43:01 +02:00
|
|
|
PakHandle_t pakHandle = g_pakLoadApi->LoadAsync("startup.rpak", AlignedMemAlloc(), 5, 0);
|
2023-09-09 20:57:00 +02:00
|
|
|
g_pakLoadApi->WaitAsync(pakHandle, nullptr);
|
2023-07-17 11:54:14 +02:00
|
|
|
|
|
|
|
// Trick: return INIT_FAILED to disable the loading of hardware
|
|
|
|
// configuration data, since we don't need it on the dedi.
|
|
|
|
return INIT_FAILED;
|
|
|
|
#else
|
|
|
|
// Initialize as usual.
|
2023-12-20 22:21:31 +01:00
|
|
|
GFX_EnableLowLatencySDK(!CommandLine()->CheckParm("-gfx_nvnDisableLowLatency"));
|
|
|
|
|
2024-04-05 16:45:05 +02:00
|
|
|
if (GFX_IsLowLatencySDKEnabled())
|
|
|
|
{
|
|
|
|
PCLSTATS_INIT(0);
|
|
|
|
}
|
2023-12-20 22:21:31 +01:00
|
|
|
|
2023-07-17 11:54:14 +02:00
|
|
|
return CMaterialSystem__Init(thisptr);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-12-20 22:21:31 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: shutdown of the material system
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
int CMaterialSystem::Shutdown(CMaterialSystem* thisptr)
|
|
|
|
{
|
2023-12-27 13:22:33 +01:00
|
|
|
#ifndef MATERIALSYSTEM_NODX
|
2024-04-05 16:45:05 +02:00
|
|
|
if (GFX_IsLowLatencySDKEnabled())
|
|
|
|
{
|
|
|
|
PCLSTATS_SHUTDOWN();
|
|
|
|
}
|
2023-12-27 13:22:33 +01:00
|
|
|
#endif
|
2023-12-20 22:21:31 +01:00
|
|
|
|
|
|
|
return CMaterialSystem__Shutdown(thisptr);
|
|
|
|
}
|
|
|
|
|
2023-07-17 11:54:14 +02:00
|
|
|
#ifndef MATERIALSYSTEM_NODX
|
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-11-24 11:58:32 +01:00
|
|
|
KeyValues* pSettingsKV = Mod_GetLevelSettings(pszLevelName);
|
2022-03-02 01:16:35 +01:00
|
|
|
|
2022-11-24 11:10:46 +01:00
|
|
|
if (pSettingsKV)
|
2022-03-02 01:16:35 +01:00
|
|
|
{
|
2022-11-24 11:10:46 +01:00
|
|
|
KeyValues* pStreamKV = pSettingsKV->FindKey("StreamDB");
|
2022-08-31 03:01:45 +02:00
|
|
|
|
2022-11-24 11:10:46 +01:00
|
|
|
if (pStreamKV)
|
2022-03-02 01:16:35 +01:00
|
|
|
{
|
2022-11-24 11:10:46 +01:00
|
|
|
const char* pszColumnName = pStreamKV->GetString();
|
2023-08-21 19:12:29 +02:00
|
|
|
Msg(eDLL_T::MS, "StreamDB_Init: Loading override STBSP file '%s.stbsp'\n", pszColumnName);
|
2022-08-31 03:01:45 +02:00
|
|
|
|
2022-11-24 11:10:46 +01:00
|
|
|
v_StreamDB_Init(pszColumnName);
|
|
|
|
return;
|
2022-03-02 01:16:35 +01:00
|
|
|
}
|
|
|
|
}
|
2022-08-31 03:01:45 +02:00
|
|
|
|
2023-08-21 19:12:29 +02:00
|
|
|
Msg(eDLL_T::MS, "StreamDB_Init: Loading STBSP file '%s.stbsp'\n", pszLevelName);
|
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
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
// 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'.
|
2024-01-02 15:21:36 +01:00
|
|
|
if (!*s_pRenderContext)
|
2022-04-30 20:35:08 +02:00
|
|
|
return nullptr;
|
2024-01-02 15:21:36 +01:00
|
|
|
|
2022-04-30 20:35:08 +02:00
|
|
|
return v_DispatchDrawCall(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14);
|
|
|
|
}
|
|
|
|
|
2024-04-05 16:45:05 +02:00
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: run IDXGISwapChain::Present
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
ssize_t SpinPresent(void)
|
|
|
|
{
|
2023-12-26 02:37:07 +01:00
|
|
|
// TODO[ AMOS ]: move imgui code to a separate file.
|
|
|
|
extern void DrawImGui();
|
|
|
|
extern void ImGui_Init();
|
|
|
|
|
|
|
|
if (!g_bImGuiInitialized)
|
|
|
|
{
|
|
|
|
ImGui_Init();
|
|
|
|
g_ThreadRenderThreadID = GetCurrentThreadId();
|
|
|
|
g_bImGuiInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_pEngine->GetQuitting() == IEngine::QUIT_NOTQUITTING)
|
|
|
|
DrawImGui();
|
|
|
|
|
2024-04-05 16:45:05 +02:00
|
|
|
const ssize_t val = v_SpinPresent();
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2022-10-13 02:22:50 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: finds a material
|
|
|
|
// Input : *pMatSys -
|
|
|
|
// *pMaterialName -
|
|
|
|
// nMaterialType -
|
|
|
|
// nUnk -
|
|
|
|
// bComplain -
|
|
|
|
// Output : pointer to material
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
CMaterialGlue* CMaterialSystem::FindMaterialEx(CMaterialSystem* pMatSys, const char* pMaterialName, uint8_t nMaterialType, int nUnk, bool bComplain)
|
|
|
|
{
|
|
|
|
CMaterialGlue* pMaterial = CMaterialSystem__FindMaterialEx(pMatSys, pMaterialName, nMaterialType, nUnk, bComplain);
|
2022-10-21 21:49:10 +02:00
|
|
|
|
|
|
|
if ((bComplain || mat_alwaysComplain->GetBool()) && pMaterial->IsErrorMaterial())
|
2022-10-13 02:22:50 +02:00
|
|
|
{
|
|
|
|
Error(eDLL_T::MS, NO_ERROR, "Material \"%s\" not found; replacing with \"%s\".\n", pMaterialName, pMaterial->GetName());
|
|
|
|
}
|
|
|
|
return pMaterial;
|
|
|
|
}
|
2022-10-23 01:20:49 +02:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: get screen size
|
|
|
|
// Input : *pMatSys -
|
|
|
|
// Output : Vector2D screen size
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
Vector2D CMaterialSystem::GetScreenSize(CMaterialSystem* pMatSys)
|
|
|
|
{
|
|
|
|
Vector2D vecScreenSize;
|
|
|
|
|
2024-01-02 15:21:36 +01:00
|
|
|
CMaterialSystem__GetScreenSize(pMatSys, &vecScreenSize.x, &vecScreenSize.y);
|
2022-10-23 01:20:49 +02:00
|
|
|
|
|
|
|
return vecScreenSize;
|
|
|
|
}
|
2023-07-17 11:54:14 +02:00
|
|
|
#endif // !MATERIALSYSTEM_NODX
|
2022-10-13 02:22:50 +02:00
|
|
|
|
2022-03-02 01:16:35 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2023-11-26 13:21:20 +01:00
|
|
|
void VMaterialSystem::Detour(const bool bAttach) const
|
2022-03-02 01:16:35 +01:00
|
|
|
{
|
2023-11-26 13:21:20 +01:00
|
|
|
DetourSetup(&CMaterialSystem__Init, &CMaterialSystem::Init, bAttach);
|
2023-12-20 22:21:31 +01:00
|
|
|
DetourSetup(&CMaterialSystem__Shutdown, &CMaterialSystem::Shutdown, bAttach);
|
2023-07-17 11:54:14 +02:00
|
|
|
#ifndef MATERIALSYSTEM_NODX
|
2023-11-26 13:21:20 +01:00
|
|
|
DetourSetup(&v_StreamDB_Init, &StreamDB_Init, bAttach);
|
|
|
|
DetourSetup(&v_DispatchDrawCall, &DispatchDrawCall, bAttach);
|
2024-04-05 16:45:05 +02:00
|
|
|
DetourSetup(&v_SpinPresent, &SpinPresent, bAttach);
|
2023-11-26 13:21:20 +01:00
|
|
|
DetourSetup(&CMaterialSystem__FindMaterialEx, &CMaterialSystem::FindMaterialEx, bAttach);
|
2023-07-17 11:54:14 +02:00
|
|
|
#endif // !MATERIALSYSTEM_NODX
|
2022-03-02 01:16:35 +01:00
|
|
|
}
|