diff --git a/r5dev/core/init.cpp b/r5dev/core/init.cpp index 8e6684c2..a7e49164 100644 --- a/r5dev/core/init.cpp +++ b/r5dev/core/init.cpp @@ -100,6 +100,7 @@ #include "public/include/edict.h" #endif // !CLIENT_DLL #ifndef DEDICATED +#include "public/include/idebugoverlay.h" #include "inputsystem/inputsystem.h" #include "windows/id3dx.h" #endif // !DEDICATED diff --git a/r5dev/public/include/idebugoverlay.h b/r5dev/public/include/idebugoverlay.h new file mode 100644 index 00000000..f18f78da --- /dev/null +++ b/r5dev/public/include/idebugoverlay.h @@ -0,0 +1,65 @@ +//===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======// +// +// Purpose: Debug overlay engine interface. +// +//===========================================================================// +// +/////////////////////////////////////////////////////////////////////////////// +#ifndef IDEBUGOVERLAY_H +#define IDEBUGOVERLAY_H + +#include "mathlib/vector.h" +class IVDebugOverlay +{ + void* __vftable /*VFT*/; +}; + +class CIVDebugOverlay : public IVDebugOverlay +{ +public: + void AddBoxOverlay(__m128i& vTransforms, const Vector3D& vMins, const Vector3D& vMaxs, int r, int g, int b, int a, bool bZBuffer, float flDuration) + { + static int index = 1; + CallVFunc(index, this, vTransforms, vMins, vMaxs, r, g, b, a, bZBuffer, flDuration); + } + void AddSphereOverlay(const Vector3D& vOrigin, float flRadius, int nTheta, int nPhi, int r, int g, int b, int a, float flDuration) + { + static int index = 3; + CallVFunc(index, this, vOrigin, flRadius, nTheta, nPhi, r, g, b, a, flDuration); + } + void AddLineOverlay(const Vector3D& vStart, const Vector3D& vEnd, int r, int g, int b, char bZBuffer, float flDuration) + { + static int index = 5; + CallVFunc(index, this, vStart, vEnd, r, g, b, bZBuffer, flDuration); + } + void AddCapsuleOverlay(const Vector3D& vStart, const Vector3D& vEnd, const Vector3D& vRadius, const Vector3D& vTop, const Vector3D& vBottom, int r, int g, int b, int a, float flDuration) + { + static int index = 12; + CallVFunc(index, this, vStart, vEnd, vRadius, vTop, vBottom, r, g, b, a, flDuration); + } +}; + +inline CIVDebugOverlay* g_pDebugOverlay = nullptr; + +/////////////////////////////////////////////////////////////////////////////// +class VDebugOverlayBase : public IDetour +{ + virtual void GetAdr(void) const + { + spdlog::debug("| VAR: g_pDebugOverlay : {:#18x} |\n", reinterpret_cast(g_pDebugOverlay)); + spdlog::debug("+----------------------------------------------------------------+\n"); + } + virtual void GetFun(void) const { } + virtual void GetVar(void) const + { + g_pDebugOverlay = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x8D\x05\x00\x00\x00\x00\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x48\x8D\x05\x00\x00\x00\x00\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x48\x83\xEC\x28\xF3\x0F\x10\x41\x00"), "xxx????xxxxxxxxxxxx????xxxxxxxxxxxxxxxxx?") + .ResolveRelativeAddressSelf(0x3, 0x7).RCast(); + } + virtual void GetCon(void) const { } + virtual void Attach(void) const { } + virtual void Detach(void) const { } +}; +/////////////////////////////////////////////////////////////////////////////// + +REGISTER(VDebugOverlayBase); +#endif // IDEBUGOVERLAY_H \ No newline at end of file diff --git a/r5dev/tier1/cmd.cpp b/r5dev/tier1/cmd.cpp index bf729b1f..48021ed3 100644 --- a/r5dev/tier1/cmd.cpp +++ b/r5dev/tier1/cmd.cpp @@ -124,6 +124,13 @@ ConCommand::ConCommand(const char* pszName, const char* pszHelpString, int nFlag //----------------------------------------------------------------------------- void ConCommand::Init(void) { + //------------------------------------------------------------------------- + // ENGINE DLL | +#ifndef DEDICATED + new ConCommand("line", "Draw a debug line.", FCVAR_GAMEDLL | FCVAR_CHEAT, Line_f, nullptr); + new ConCommand("sphere", "Draw a debug sphere.", FCVAR_GAMEDLL | FCVAR_CHEAT, Sphere_f, nullptr); + new ConCommand("capsule", "Draw a debug capsule.", FCVAR_GAMEDLL | FCVAR_CHEAT, Capsule_f, nullptr); +#endif //!DEDICATED //------------------------------------------------------------------------- // SERVER DLL | new ConCommand("script", "Run input code as SERVER script on the VM.", FCVAR_GAMEDLL | FCVAR_CHEAT, SQVM_ServerScript_f, nullptr); diff --git a/r5dev/vproj/clientsdk.vcxproj b/r5dev/vproj/clientsdk.vcxproj index cd3f7e24..38b39072 100644 --- a/r5dev/vproj/clientsdk.vcxproj +++ b/r5dev/vproj/clientsdk.vcxproj @@ -236,6 +236,7 @@ + diff --git a/r5dev/vproj/clientsdk.vcxproj.filters b/r5dev/vproj/clientsdk.vcxproj.filters index 9151d79a..f9459dfe 100644 --- a/r5dev/vproj/clientsdk.vcxproj.filters +++ b/r5dev/vproj/clientsdk.vcxproj.filters @@ -1616,6 +1616,9 @@ sdk\mathlib + + sdk\public\include + diff --git a/r5dev/vproj/gamesdk.vcxproj b/r5dev/vproj/gamesdk.vcxproj index 0f60db53..63417f27 100644 --- a/r5dev/vproj/gamesdk.vcxproj +++ b/r5dev/vproj/gamesdk.vcxproj @@ -257,6 +257,7 @@ + diff --git a/r5dev/vproj/gamesdk.vcxproj.filters b/r5dev/vproj/gamesdk.vcxproj.filters index 492eec31..c5b41b6d 100644 --- a/r5dev/vproj/gamesdk.vcxproj.filters +++ b/r5dev/vproj/gamesdk.vcxproj.filters @@ -1694,6 +1694,9 @@ sdk\server + + sdk\public\include + diff --git a/r5dev/vstdlib/callback.cpp b/r5dev/vstdlib/callback.cpp index afbd22f2..91f49fc0 100644 --- a/r5dev/vstdlib/callback.cpp +++ b/r5dev/vstdlib/callback.cpp @@ -30,6 +30,7 @@ #include "vstdlib/callback.h" #ifndef DEDICATED #include "materialsystem/cmaterialglue.h" +#include "public/include/idebugoverlay.h" #endif // !DEDICATED @@ -897,4 +898,85 @@ void Mat_CrossHair_f(const CCommand& args) DevMsg(eDLL_T::MS, "%s - No Material found >:(\n", __FUNCTION__); } } -#endif // !DEDICATED \ No newline at end of file + +/* +===================== +Line_f + + Draws a line at + start end. +===================== +*/ +void Line_f(const CCommand& args) +{ + if (args.ArgC() != 7) + { + DevMsg(eDLL_T::CLIENT, "Usage 'line': start(vector) end(vector)\n"); + return; + } + + Vector3D start, end; + for (int i = 0; i < 3; ++i) + { + start[i] = atof(args[i + 1]); + end[i] = atof(args[i + 4]); + } + + g_pDebugOverlay->AddLineOverlay(start, end, 255, 255, 0, r_debug_overlay_zbuffer->GetBool(), 100); +} + +/* +===================== +Sphere_f + + Draws a sphere at origin(x1 y1 z1) + radius(float) theta(int) phi(int). +===================== +*/ +void Sphere_f(const CCommand& args) +{ + if (args.ArgC() != 7) + { + DevMsg(eDLL_T::CLIENT, "Usage 'sphere': origin(vector) radius(float) theta(int) phi(int)\n"); + return; + } + + Vector3D start; + for (int i = 0; i < 3; ++i) + { + start[i] = atof(args[i + 1]); + } + + float radius = atof(args[4]); + int theta = atoi(args[5]); + int phi = atoi(args[6]); + + g_pDebugOverlay->AddSphereOverlay(start, radius, theta, phi, 20, 210, 255, 0, 100); +} + +/* +===================== +Capsule_f + + Draws a capsule at start + end radius . +===================== +*/ +void Capsule_f(const CCommand& args) +{ + if (args.ArgC() != 10) + { + DevMsg(eDLL_T::CLIENT, "Usage 'capsule': start(vector) end(vector) radius(vector)\n"); + return; + } + + Vector3D start, end, radius; + for (int i = 0; i < 3; ++i) + { + start[i] = atof(args[i + 1]); + end[i] = atof(args[i + 4]); + radius[i] = atof(args[i + 7]); + } + g_pDebugOverlay->AddCapsuleOverlay(start, end, radius, { 0,0,0 }, { 0,0,0 }, 141, 233, 135, 0, 100); +} +#endif // !DEDICATED diff --git a/r5dev/vstdlib/callback.h b/r5dev/vstdlib/callback.h index 32c34d0c..9e91f39c 100644 --- a/r5dev/vstdlib/callback.h +++ b/r5dev/vstdlib/callback.h @@ -43,6 +43,9 @@ void SQVM_ServerScript_f(const CCommand& args); void SQVM_ClientScript_f(const CCommand& args); void SQVM_UIScript_f(const CCommand& args); void Mat_CrossHair_f(const CCommand& args); +void Line_f(const CCommand& args); +void Sphere_f(const CCommand& args); +void Capsule_f(const CCommand& args); #endif // !DEDICATED /////////////////////////////////////////////////////////////////////////////// class VCallback : public IDetour