diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d1439c45..332065dd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -68,6 +68,7 @@ add_subdirectory( inputsystem ) add_subdirectory( filesystem ) add_subdirectory( datacache ) add_subdirectory( studiorender ) +add_subdirectory( particles ) add_subdirectory( localize ) add_subdirectory( engine ) add_subdirectory( vguimatsurface ) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index b2b31069..ce0a3728 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -113,6 +113,8 @@ target_link_libraries( ${PROJECT_NAME} PRIVATE "vgui" "rui" + "particles" + "d3d11.lib" "${THIRDPARTY_SOURCE_DIR}/nvapi/amd64/nvapi64.lib" ) diff --git a/src/core/init.cpp b/src/core/init.cpp index 584198c3..1388e3e6 100644 --- a/src/core/init.cpp +++ b/src/core/init.cpp @@ -50,6 +50,7 @@ #include "vgui/vgui_fpspanel.h" #include "vgui/vgui_controls/RichText.h" #include "vguimatsurface/MatSystemSurface.h" +#include "particles/particles.h" #include "engine/client/vengineclient_impl.h" #include "engine/client/cdll_engine_int.h" #include "engine/client/datablock_receiver.h" @@ -573,6 +574,9 @@ void DetourRegister() // Register detour classes to be searched and hooked. REGISTER(VVGUIRichText); // REGISTER CLIENT ONLY! REGISTER(VMatSystemSurface); + // Particles + REGISTER(VParticles); + // Client REGISTER(HVEngineClient); REGISTER(VDll_Engine_Int); diff --git a/src/particles/CMakeLists.txt b/src/particles/CMakeLists.txt new file mode 100644 index 00000000..37a8fa35 --- /dev/null +++ b/src/particles/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required( VERSION 3.16 ) +add_module( "lib" "particles" "vpc" ${FOLDER_CONTEXT} TRUE TRUE ) + +start_sources() + +add_sources( SOURCE_GROUP "Runtime" + "particles.cpp" + "particles.h" +) + +end_sources() + +target_include_directories( ${PROJECT_NAME} PRIVATE "${ENGINE_SOURCE_DIR}/tier0/" "${ENGINE_SOURCE_DIR}/tier1/" ) diff --git a/src/particles/particles.cpp b/src/particles/particles.cpp new file mode 100644 index 00000000..f9642762 --- /dev/null +++ b/src/particles/particles.cpp @@ -0,0 +1,34 @@ +//===========================================================================// +// +// Purpose: particle system code +// +//===========================================================================// +#include "tier0/commandline.h" +#include "rtech/pak/pakstate.h" +#include "particles.h" + +static void ParticleSystem_Init() +{ + // Call the original function to load the core particle files, and then + // load our effects rpak afterwards to we can patch what is loaded in the + // effects.rpak loaded by the engine. + v_ParticleSystem_Init(); + + // This tells the engine to load the raw DMX files instead, which are + // listed inside the particles_manifest.txt file as PCF files. + const bool loadUnbaked = CommandLine()->FindParm("-tools") || CommandLine()->FindParm("-nobakedparticles"); + + if (!loadUnbaked || CommandLine()->FindParm("-bakedparticles")) + { + const char* const pakName = "effects_sdk.rpak"; + const PakHandle_t pakId = g_pakLoadApi->LoadAsyncAndWait(pakName, AlignedMemAlloc(), 3, nullptr); + + if (pakId == PAK_INVALID_HANDLE) + Error(eDLL_T::ENGINE, EXIT_FAILURE, "Failed to load pak file '%s'\n", pakName); + } +} + +void VParticles::Detour(const bool bAttach) const +{ + DetourSetup(&v_ParticleSystem_Init, ParticleSystem_Init, bAttach); +} diff --git a/src/particles/particles.h b/src/particles/particles.h new file mode 100644 index 00000000..82293374 --- /dev/null +++ b/src/particles/particles.h @@ -0,0 +1,28 @@ +//===========================================================================// +// +// Purpose: particle system definitions +// +//===========================================================================// +#ifndef PARTICLES_H +#define PARTICLES_H + +inline void (*v_ParticleSystem_Init)(void); + +/////////////////////////////////////////////////////////////////////////////// +class VParticles : public IDetour +{ + virtual void GetAdr(void) const + { + LogFunAdr("ParticleSystem_Init", v_ParticleSystem_Init); + } + virtual void GetFun(void) const + { + g_GameDll.FindPatternSIMD("48 89 4C 24 ?? 55 53 56 57 48 8D AC 24 ?? ?? ?? ?? 48 81 EC ?? ?? ?? ?? 33 F6").GetPtr(v_ParticleSystem_Init); + } + virtual void GetVar(void) const { } + virtual void GetCon(void) const { } + virtual void Detour(const bool bAttach) const; +}; +/////////////////////////////////////////////////////////////////////////////// + +#endif // PARTICLES_H