From eca863c87996be4178c8a405d93826eb00aea7a8 Mon Sep 17 00:00:00 2001 From: 0TheSpy Date: Wed, 16 Jun 2021 18:46:33 +0300 Subject: [PATCH] Add files via upload --- SpyCustom/sdk/IAppSystem.h | 84 + SpyCustom/sdk/IBorder.h | 54 + SpyCustom/sdk/IClientLeafSystem.h | 52 + SpyCustom/sdk/IClientPanel.h | 71 + SpyCustom/sdk/ICollideable.h | 58 + SpyCustom/sdk/IColorCorrection.h | 66 + SpyCustom/sdk/IEffects.h | 52 + SpyCustom/sdk/IEngineSound.h | 123 + SpyCustom/sdk/IEngineVgui.h | 55 + SpyCustom/sdk/IGameSystem.h | 186 + SpyCustom/sdk/IGameUI.h | 94 + SpyCustom/sdk/IHTML.h | 151 + SpyCustom/sdk/IImage.h | 54 + SpyCustom/sdk/IInput.h | 156 + SpyCustom/sdk/IKeyValuesSystem.h | 34 + SpyCustom/sdk/ILocalize.h | 371 ++ SpyCustom/sdk/IMesh.h | 3353 +++++++++++++++++ SpyCustom/sdk/IPanel.h | 118 + SpyCustom/sdk/IScheme.h | 85 + SpyCustom/sdk/ISurface.h | 378 ++ SpyCustom/sdk/ISystem.h | 86 + SpyCustom/sdk/IVGUI.h | 79 + SpyCustom/sdk/IVguiMatInfo.h | 17 + SpyCustom/sdk/IVguiMatInfoVar.h | 15 + SpyCustom/sdk/Image.h | 64 + SpyCustom/sdk/InputEnums.h | 82 + SpyCustom/sdk/KeyBindingMap.h | 206 + SpyCustom/sdk/KeyCode.h | 15 + SpyCustom/sdk/Label.h | 167 + SpyCustom/sdk/gametrace.h | 147 + SpyCustom/sdk/generichash.h | 84 + SpyCustom/sdk/globalvars_base.h | 73 + SpyCustom/sdk/groundlink.h | 14 + SpyCustom/sdk/htmlmessages.h | 105 + SpyCustom/sdk/hud.h | 171 + SpyCustom/sdk/hud_basechat.h | 405 ++ SpyCustom/sdk/hud_element_helper.h | 75 + SpyCustom/sdk/hudelement.h | 124 + SpyCustom/sdk/hudtexturehandle.h | 52 + SpyCustom/sdk/ichromehtmlwrapper.h | 52 + SpyCustom/sdk/iclassmap.h | 24 + SpyCustom/sdk/iclient.h | 141 + SpyCustom/sdk/icliententity.h | 73 + SpyCustom/sdk/icliententityinternal.h | 18 + SpyCustom/sdk/icliententitylist.h | 37 + SpyCustom/sdk/iclientmode.h | 112 + SpyCustom/sdk/iclientnetworkable.h | 63 + SpyCustom/sdk/iclientrenderable.h | 223 ++ SpyCustom/sdk/iclientshadowmgr.h | 99 + SpyCustom/sdk/iclientthinkable.h | 29 + SpyCustom/sdk/iclientunknown.h | 32 + SpyCustom/sdk/iclientvirtualreality.h | 35 + SpyCustom/sdk/icommandline.h | 45 + SpyCustom/sdk/iconvar.h | 71 + SpyCustom/sdk/icvar.h | 67 + SpyCustom/sdk/idatacache.h | 363 ++ SpyCustom/sdk/iefx.h | 49 + SpyCustom/sdk/ienginetrace.h | 152 + SpyCustom/sdk/ifilelist.h | 15 + SpyCustom/sdk/igameconsole.h | 28 + SpyCustom/sdk/igameevents.h | 131 + SpyCustom/sdk/ihandleentity.h | 20 + SpyCustom/sdk/iinputsystem.h | 83 + SpyCustom/sdk/imageformat.h | 439 +++ SpyCustom/sdk/imaterial.h | 493 +++ SpyCustom/sdk/imaterialsystem.h | 1632 ++++++++ SpyCustom/sdk/imaterialsystemhardwareconfig.h | 200 + SpyCustom/sdk/imdlcache.h | 169 + SpyCustom/sdk/imovehelper.h | 74 + SpyCustom/sdk/inetchannel.h | 85 + SpyCustom/sdk/inetchannelinfo.h | 64 + SpyCustom/sdk/inetmessage.h | 74 + SpyCustom/sdk/inetmsghandler.h | 21 + SpyCustom/sdk/interface.h | 139 + SpyCustom/sdk/interpolatedvar.h | 1429 +++++++ SpyCustom/sdk/ipredictionsystem.h | 152 + SpyCustom/sdk/irecipientfilter.h | 29 + SpyCustom/sdk/iscenetokenprocessor.h | 16 + SpyCustom/sdk/iserverentity.h | 32 + SpyCustom/sdk/iservernetworkable.h | 89 + SpyCustom/sdk/iserverplugin.h | 103 + SpyCustom/sdk/iserverunknown.h | 25 + SpyCustom/sdk/ishadowmgr.h | 116 + SpyCustom/sdk/ispatialpartition.h | 157 + SpyCustom/sdk/istudiorender.h | 290 ++ SpyCustom/sdk/item_selection_criteria.h | 202 + SpyCustom/sdk/itempents.h | 118 + SpyCustom/sdk/itexture.h | 93 + SpyCustom/sdk/itoolentity.h | 190 + SpyCustom/sdk/ivdebugoverlay.h | 44 + SpyCustom/sdk/iviewrender.h | 125 + SpyCustom/sdk/iviewrender_beams.h | 144 + SpyCustom/sdk/ivmodelinfo.h | 152 + SpyCustom/sdk/ivmodelrender.h | 131 + SpyCustom/sdk/ivrenderview.h | 310 ++ SpyCustom/sdk/jobthread.h | 1270 +++++++ SpyCustom/sdk/keyvalues.h | 420 +++ SpyCustom/sdk/l2cache.h | 38 + SpyCustom/sdk/lerp_functions.h | 157 + 99 files changed, 18760 insertions(+) create mode 100644 SpyCustom/sdk/IAppSystem.h create mode 100644 SpyCustom/sdk/IBorder.h create mode 100644 SpyCustom/sdk/IClientLeafSystem.h create mode 100644 SpyCustom/sdk/IClientPanel.h create mode 100644 SpyCustom/sdk/ICollideable.h create mode 100644 SpyCustom/sdk/IColorCorrection.h create mode 100644 SpyCustom/sdk/IEffects.h create mode 100644 SpyCustom/sdk/IEngineSound.h create mode 100644 SpyCustom/sdk/IEngineVgui.h create mode 100644 SpyCustom/sdk/IGameSystem.h create mode 100644 SpyCustom/sdk/IGameUI.h create mode 100644 SpyCustom/sdk/IHTML.h create mode 100644 SpyCustom/sdk/IImage.h create mode 100644 SpyCustom/sdk/IInput.h create mode 100644 SpyCustom/sdk/IKeyValuesSystem.h create mode 100644 SpyCustom/sdk/ILocalize.h create mode 100644 SpyCustom/sdk/IMesh.h create mode 100644 SpyCustom/sdk/IPanel.h create mode 100644 SpyCustom/sdk/IScheme.h create mode 100644 SpyCustom/sdk/ISurface.h create mode 100644 SpyCustom/sdk/ISystem.h create mode 100644 SpyCustom/sdk/IVGUI.h create mode 100644 SpyCustom/sdk/IVguiMatInfo.h create mode 100644 SpyCustom/sdk/IVguiMatInfoVar.h create mode 100644 SpyCustom/sdk/Image.h create mode 100644 SpyCustom/sdk/InputEnums.h create mode 100644 SpyCustom/sdk/KeyBindingMap.h create mode 100644 SpyCustom/sdk/KeyCode.h create mode 100644 SpyCustom/sdk/Label.h create mode 100644 SpyCustom/sdk/gametrace.h create mode 100644 SpyCustom/sdk/generichash.h create mode 100644 SpyCustom/sdk/globalvars_base.h create mode 100644 SpyCustom/sdk/groundlink.h create mode 100644 SpyCustom/sdk/htmlmessages.h create mode 100644 SpyCustom/sdk/hud.h create mode 100644 SpyCustom/sdk/hud_basechat.h create mode 100644 SpyCustom/sdk/hud_element_helper.h create mode 100644 SpyCustom/sdk/hudelement.h create mode 100644 SpyCustom/sdk/hudtexturehandle.h create mode 100644 SpyCustom/sdk/ichromehtmlwrapper.h create mode 100644 SpyCustom/sdk/iclassmap.h create mode 100644 SpyCustom/sdk/iclient.h create mode 100644 SpyCustom/sdk/icliententity.h create mode 100644 SpyCustom/sdk/icliententityinternal.h create mode 100644 SpyCustom/sdk/icliententitylist.h create mode 100644 SpyCustom/sdk/iclientmode.h create mode 100644 SpyCustom/sdk/iclientnetworkable.h create mode 100644 SpyCustom/sdk/iclientrenderable.h create mode 100644 SpyCustom/sdk/iclientshadowmgr.h create mode 100644 SpyCustom/sdk/iclientthinkable.h create mode 100644 SpyCustom/sdk/iclientunknown.h create mode 100644 SpyCustom/sdk/iclientvirtualreality.h create mode 100644 SpyCustom/sdk/icommandline.h create mode 100644 SpyCustom/sdk/iconvar.h create mode 100644 SpyCustom/sdk/icvar.h create mode 100644 SpyCustom/sdk/idatacache.h create mode 100644 SpyCustom/sdk/iefx.h create mode 100644 SpyCustom/sdk/ienginetrace.h create mode 100644 SpyCustom/sdk/ifilelist.h create mode 100644 SpyCustom/sdk/igameconsole.h create mode 100644 SpyCustom/sdk/igameevents.h create mode 100644 SpyCustom/sdk/ihandleentity.h create mode 100644 SpyCustom/sdk/iinputsystem.h create mode 100644 SpyCustom/sdk/imageformat.h create mode 100644 SpyCustom/sdk/imaterial.h create mode 100644 SpyCustom/sdk/imaterialsystem.h create mode 100644 SpyCustom/sdk/imaterialsystemhardwareconfig.h create mode 100644 SpyCustom/sdk/imdlcache.h create mode 100644 SpyCustom/sdk/imovehelper.h create mode 100644 SpyCustom/sdk/inetchannel.h create mode 100644 SpyCustom/sdk/inetchannelinfo.h create mode 100644 SpyCustom/sdk/inetmessage.h create mode 100644 SpyCustom/sdk/inetmsghandler.h create mode 100644 SpyCustom/sdk/interface.h create mode 100644 SpyCustom/sdk/interpolatedvar.h create mode 100644 SpyCustom/sdk/ipredictionsystem.h create mode 100644 SpyCustom/sdk/irecipientfilter.h create mode 100644 SpyCustom/sdk/iscenetokenprocessor.h create mode 100644 SpyCustom/sdk/iserverentity.h create mode 100644 SpyCustom/sdk/iservernetworkable.h create mode 100644 SpyCustom/sdk/iserverplugin.h create mode 100644 SpyCustom/sdk/iserverunknown.h create mode 100644 SpyCustom/sdk/ishadowmgr.h create mode 100644 SpyCustom/sdk/ispatialpartition.h create mode 100644 SpyCustom/sdk/istudiorender.h create mode 100644 SpyCustom/sdk/item_selection_criteria.h create mode 100644 SpyCustom/sdk/itempents.h create mode 100644 SpyCustom/sdk/itexture.h create mode 100644 SpyCustom/sdk/itoolentity.h create mode 100644 SpyCustom/sdk/ivdebugoverlay.h create mode 100644 SpyCustom/sdk/iviewrender.h create mode 100644 SpyCustom/sdk/iviewrender_beams.h create mode 100644 SpyCustom/sdk/ivmodelinfo.h create mode 100644 SpyCustom/sdk/ivmodelrender.h create mode 100644 SpyCustom/sdk/ivrenderview.h create mode 100644 SpyCustom/sdk/jobthread.h create mode 100644 SpyCustom/sdk/keyvalues.h create mode 100644 SpyCustom/sdk/l2cache.h create mode 100644 SpyCustom/sdk/lerp_functions.h diff --git a/SpyCustom/sdk/IAppSystem.h b/SpyCustom/sdk/IAppSystem.h new file mode 100644 index 0000000..4c620c7 --- /dev/null +++ b/SpyCustom/sdk/IAppSystem.h @@ -0,0 +1,84 @@ +#ifndef IAPPSYSTEM_H +#define IAPPSYSTEM_H + +#ifdef COMPILER_MSVC +#pragma once +#endif + +#include "interface.h" + + + +struct AppSystemInfo_t +{ + const char* m_pModuleName; + const char* m_pInterfaceName; +}; + + +enum InitReturnVal_t +{ + INIT_FAILED = 0, + INIT_OK, + + INIT_LAST_VAL, +}; + +enum AppSystemTier_t +{ + APP_SYSTEM_TIER0 = 0, + APP_SYSTEM_TIER1, + APP_SYSTEM_TIER2, + APP_SYSTEM_TIER3, + + APP_SYSTEM_TIER_OTHER, +}; + + +abstract_class IAppSystem +{ +public: + virtual bool Connect(CreateInterfaceFn factory) = 0; + virtual void Disconnect() = 0; + + virtual void* QueryInterface(const char* pInterfaceName) = 0; + + virtual InitReturnVal_t Init() = 0; + virtual void Shutdown() = 0; + + virtual const AppSystemInfo_t* GetDependencies() { return NULL; } + + virtual AppSystemTier_t GetTier() { return APP_SYSTEM_TIER_OTHER; } + + virtual void Reconnect(CreateInterfaceFn factory, const char* pInterfaceName) {} + virtual bool IsSingleton() { return true; } +}; + + +template< class IInterface > +class CBaseAppSystem : public IInterface +{ +public: + virtual bool Connect(CreateInterfaceFn factory) { return true; } + virtual void Disconnect() {} + + virtual void* QueryInterface(const char* pInterfaceName) { return NULL; } + + virtual InitReturnVal_t Init() { return INIT_OK; } + virtual void Shutdown() {} + + virtual const AppSystemInfo_t* GetDependencies() { return NULL; } + virtual AppSystemTier_t GetTier() { return APP_SYSTEM_TIER_OTHER; } + + virtual void Reconnect(CreateInterfaceFn factory, const char* pInterfaceName); +}; + + +template< class IInterface > +class CTier0AppSystem : public CBaseAppSystem< IInterface > +{ +}; + + +#endif + diff --git a/SpyCustom/sdk/IBorder.h b/SpyCustom/sdk/IBorder.h new file mode 100644 index 0000000..cd64c84 --- /dev/null +++ b/SpyCustom/sdk/IBorder.h @@ -0,0 +1,54 @@ +#ifndef IBORDER_H +#define IBORDER_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "VGUI.h" + +class KeyValues; + +namespace vgui +{ + + class IScheme; + + class IBorder + { + public: + IBorder() {} + virtual ~IBorder() {} + + virtual void Paint(VPANEL panel) = 0; + virtual void Paint(int x0, int y0, int x1, int y1) = 0; + virtual void Paint(int x0, int y0, int x1, int y1, int breakSide, int breakStart, int breakStop) = 0; + virtual void SetInset(int left, int top, int right, int bottom) = 0; + virtual void GetInset(int& left, int& top, int& right, int& bottom) = 0; + virtual void ApplySchemeSettings(IScheme* pScheme, KeyValues* inResourceData) = 0; + virtual const char* GetName() = 0; + virtual void SetName(const char* name) = 0; + + enum backgroundtype_e + { + BACKGROUND_FILLED, + BACKGROUND_TEXTURED, + BACKGROUND_ROUNDEDCORNERS, + }; + virtual backgroundtype_e GetBackgroundType() = 0; + + enum sides_e + { + SIDE_LEFT = 0, + SIDE_TOP = 1, + SIDE_RIGHT = 2, + SIDE_BOTTOM = 3 + }; + + virtual bool PaintFirst(void) = 0; + }; + +} + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/IClientLeafSystem.h b/SpyCustom/sdk/IClientLeafSystem.h new file mode 100644 index 0000000..8a3477f --- /dev/null +++ b/SpyCustom/sdk/IClientLeafSystem.h @@ -0,0 +1,52 @@ +#if !defined( ICLIENTLEAFSYSTEM_H ) +#define ICLIENTLEAFSYSTEM_H +#ifdef _WIN32 +#pragma once +#endif + + +#include "platform.h" +#include "client_render_handle.h" +#include "ivmodelinfo.h" + + +#define CLIENTLEAFSYSTEM_INTERFACE_VERSION "ClientLeafSystem002" + + +enum RenderableModelType_t +{ + RENDERABLE_MODEL_UNKNOWN_TYPE = -1, + RENDERABLE_MODEL_ENTITY = 0, + RENDERABLE_MODEL_STUDIOMDL, + RENDERABLE_MODEL_STATIC_PROP, + RENDERABLE_MODEL_BRUSH, +}; + +enum RenderGroup_t +{ + RENDER_GROUP_OPAQUE = 0, + RENDER_GROUP_TRANSLUCENT, + RENDER_GROUP_TRANSLUCENT_IGNOREZ, + RENDER_GROUP_COUNT, +}; + + +abstract_class IClientLeafSystemEngine +{ +public: + virtual void CreateRenderableHandle(IClientRenderable* pRenderable, bool bRenderWithViewModels, RenderableTranslucencyType_t nType, RenderableModelType_t nModelType, UINT32 nSplitscreenEnabled = 0xFFFFFFFF) = 0; + virtual void RemoveRenderable(ClientRenderHandle_t handle) = 0; + virtual void AddRenderableToLeaves(ClientRenderHandle_t renderable, int nLeafCount, unsigned short* pLeaves) = 0; + virtual void SetTranslucencyType(ClientRenderHandle_t handle, RenderableTranslucencyType_t nType) = 0; + +}; + + +#endif + + + + + + + diff --git a/SpyCustom/sdk/IClientPanel.h b/SpyCustom/sdk/IClientPanel.h new file mode 100644 index 0000000..8146330 --- /dev/null +++ b/SpyCustom/sdk/IClientPanel.h @@ -0,0 +1,71 @@ +#ifndef ICLIENTPANEL_H +#define ICLIENTPANEL_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "VGUI.h" + +#ifdef GetClassName +#undef GetClassName +#endif + +class KeyValues; + +namespace vgui +{ + + class Panel; + class SurfaceBase; + + enum EInterfaceID + { + ICLIENTPANEL_STANDARD_INTERFACE = 0, + }; + + class IClientPanel + { + public: + virtual VPANEL GetVPanel() = 0; + + virtual void Think() = 0; + virtual void PerformApplySchemeSettings() = 0; + virtual void PaintTraverse(bool forceRepaint, bool allowForce) = 0; + virtual void Repaint() = 0; + virtual VPANEL IsWithinTraverse(int x, int y, bool traversePopups) = 0; + virtual void GetInset(int& top, int& left, int& right, int& bottom) = 0; + virtual void GetClipRect(int& x0, int& y0, int& x1, int& y1) = 0; + virtual void OnChildAdded(VPANEL child) = 0; + virtual void OnSizeChanged(int newWide, int newTall) = 0; + + virtual void InternalFocusChanged(bool lost) = 0; + virtual bool RequestInfo(KeyValues* outputData) = 0; + virtual void RequestFocus(int direction) = 0; + virtual bool RequestFocusPrev(VPANEL existingPanel) = 0; + virtual bool RequestFocusNext(VPANEL existingPanel) = 0; + virtual void OnMessage(const KeyValues* params, VPANEL ifromPanel) = 0; + virtual VPANEL GetCurrentKeyFocus() = 0; + virtual int GetTabPosition() = 0; + + virtual const char* GetName() = 0; + virtual const char* GetClassName() = 0; + + virtual HScheme GetScheme() = 0; + virtual bool IsProportional() = 0; + virtual bool IsAutoDeleteSet() = 0; + virtual void DeletePanel() = 0; + + virtual void* QueryInterface(EInterfaceID id) = 0; + + virtual Panel* GetPanel() = 0; + + virtual const char* GetModuleName() = 0; + + virtual void OnTick() = 0; + }; + +} + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/ICollideable.h b/SpyCustom/sdk/ICollideable.h new file mode 100644 index 0000000..6076418 --- /dev/null +++ b/SpyCustom/sdk/ICollideable.h @@ -0,0 +1,58 @@ +#ifndef ENGINE_ICOLLIDEABLE_H +#define ENGINE_ICOLLIDEABLE_H +#ifdef _WIN32 +#pragma once +#endif + + +enum SolidType_t; +class IHandleEntity; +struct Ray_t; +struct model_t; +class Vector; +class QAngle; +class CGameTrace; +typedef CGameTrace trace_t; +class IClientUnknown; + + +abstract_class ICollideable +{ +public: + virtual IHandleEntity * GetEntityHandle() = 0; + + virtual const Vector& OBBMinsPreScaled() const = 0; + virtual const Vector& OBBMaxsPreScaled() const = 0; + virtual const Vector& OBBMins() const = 0; + virtual const Vector& OBBMaxs() const = 0; + + virtual void WorldSpaceTriggerBounds(Vector* pVecWorldMins, Vector* pVecWorldMaxs) const = 0; + + virtual bool TestCollision(const Ray_t& ray, unsigned int fContentsMask, trace_t& tr) = 0; + + virtual bool TestHitboxes(const Ray_t& ray, unsigned int fContentsMask, trace_t& tr) = 0; + + virtual int GetCollisionModelIndex() = 0; + + virtual const model_t* GetCollisionModel() = 0; + + virtual const Vector& GetCollisionOrigin() const = 0; + virtual const QAngle& GetCollisionAngles() const = 0; + virtual const matrix3x4_t& CollisionToWorldTransform() const = 0; + + virtual SolidType_t GetSolid() const = 0; + virtual int GetSolidFlags() const = 0; + + virtual IClientUnknown* GetIClientUnknown() = 0; + + virtual int GetCollisionGroup() const = 0; + + virtual void WorldSpaceSurroundingBounds(Vector* pVecMins, Vector* pVecMaxs) = 0; + + virtual bool ShouldTouchTrigger(int triggerSolidFlags) const = 0; + + virtual const matrix3x4_t* GetRootParentToWorldTransform() const = 0; +}; + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/IColorCorrection.h b/SpyCustom/sdk/IColorCorrection.h new file mode 100644 index 0000000..3035101 --- /dev/null +++ b/SpyCustom/sdk/IColorCorrection.h @@ -0,0 +1,66 @@ +#ifndef ICOLORCORRECTION_H +#define ICOLORCORRECTION_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "interface.h" +#include "imageformat.h" + +typedef unsigned int ColorCorrectionHandle_t; +struct ShaderColorCorrectionInfo_t; + +#define COLORCORRECTION_INTERFACE_VERSION "COLORCORRECTION_VERSION_1" + +abstract_class IColorCorrectionSystem +{ +public: + virtual void Init() = 0; + virtual void Shutdown() = 0; + + virtual ColorCorrectionHandle_t AddLookup(const char* pName) = 0; + virtual bool RemoveLookup(ColorCorrectionHandle_t handle) = 0; + + virtual void SetLookupWeight(ColorCorrectionHandle_t handle, float flWeight) = 0; + virtual float GetLookupWeight(ColorCorrectionHandle_t handle) = 0; + virtual float GetLookupWeight(int i) = 0; + + virtual void LockLookup() = 0; + virtual void LockLookup(ColorCorrectionHandle_t handle) = 0; + + virtual void UnlockLookup() = 0; + virtual void UnlockLookup(ColorCorrectionHandle_t handle) = 0; + + virtual void SetLookup(RGBX5551_t inColor, color24 outColor) = 0; + virtual void SetLookup(ColorCorrectionHandle_t handle, RGBX5551_t inColor, color24 outColor) = 0; + + virtual color24 GetLookup(RGBX5551_t inColor) = 0; + virtual color24 GetLookup(ColorCorrectionHandle_t handle, RGBX5551_t inColor) = 0; + + virtual void LoadLookup(const char* pLookupName) = 0; + virtual void LoadLookup(ColorCorrectionHandle_t handle, const char* pLookupName) = 0; + + virtual void CopyLookup(const color24* pSrcColorCorrection) = 0; + virtual void CopyLookup(ColorCorrectionHandle_t handle, const color24* pSrcColorCorrection) = 0; + + virtual void ResetLookup(ColorCorrectionHandle_t handle) = 0; + virtual void ResetLookup() = 0; + + virtual void ReleaseTextures() = 0; + virtual void RestoreTextures() = 0; + + virtual void ResetLookupWeights() = 0; + + virtual int GetNumLookups() = 0; + + virtual color24 ConvertToColor24(RGBX5551_t inColor) = 0; + + virtual void SetResetable(ColorCorrectionHandle_t handle, bool bResetable) = 0; + + virtual void EnableColorCorrection(bool bEnable) = 0; + + virtual void GetCurrentColorCorrection(ShaderColorCorrectionInfo_t* pInfo) = 0; +}; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/IEffects.h b/SpyCustom/sdk/IEffects.h new file mode 100644 index 0000000..d1e65eb --- /dev/null +++ b/SpyCustom/sdk/IEffects.h @@ -0,0 +1,52 @@ +#ifndef IEFFECTS_H +#define IEFFECTS_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "basetypes.h" +#include "vector.h" +#include "interface.h" +#include "ipredictionsystem.h" + +enum ShakeCommand_t; +class Vector; +class CGameTrace; +typedef CGameTrace trace_t; + + +#define IEFFECTS_INTERFACE_VERSION "IEffects001" +abstract_class IEffects : public IPredictionSystem +{ +public: + virtual ~IEffects() {}; + virtual void Beam(const Vector & Start, const Vector & End, int nModelIndex, + int nHaloIndex, unsigned char frameStart, unsigned char frameRate, + float flLife, unsigned char width, unsigned char endWidth, unsigned char fadeLength, + unsigned char noise, unsigned char red, unsigned char green, + unsigned char blue, unsigned char brightness, unsigned char speed) = 0; + + virtual void Smoke(const Vector& origin, int modelIndex, float scale, float framerate) = 0; + + virtual void Sparks(const Vector& position, int nMagnitude = 1, int nTrailLength = 1, const Vector* pvecDir = NULL) = 0; + + virtual void Dust(const Vector& pos, const Vector& dir, float size, float speed) = 0; + + virtual void MuzzleFlash(const Vector& vecOrigin, const Vector& vecAngles, float flScale, int iType) = 0; + + virtual void MetalSparks(const Vector& position, const Vector& direction) = 0; + + virtual void EnergySplash(const Vector& position, const Vector& direction, bool bExplosive = false) = 0; + + virtual void Ricochet(const Vector& position, const Vector& direction) = 0; + + virtual float Time() = 0; + virtual bool IsServer() = 0; + + virtual void SuppressEffectsSounds(bool bSuppress) = 0; +}; + + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/IEngineSound.h b/SpyCustom/sdk/IEngineSound.h new file mode 100644 index 0000000..f95fc9b --- /dev/null +++ b/SpyCustom/sdk/IEngineSound.h @@ -0,0 +1,123 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Client-server neutral sound interface +// +// $NoKeywords: $ +//=============================================================================// + +#ifndef IENGINESOUND_H +#define IENGINESOUND_H + +#ifdef _WIN32 +#pragma once +#endif + + +#include "basetypes.h" +#include "interface.h" +#include "soundflags.h" +#include "irecipientfilter.h" +#include "utlvector.h" +#include "SndInfo.h" + +//----------------------------------------------------------------------------- +// forward declaration +//----------------------------------------------------------------------------- +class Vector; + +// Handy defines for EmitSound +#define SOUND_FROM_UI_PANEL -2 // Sound being played inside a UI panel on the client +#define SOUND_FROM_LOCAL_PLAYER -1 +#define SOUND_FROM_WORLD 0 + + + +// These are used to feed a soundlevel to the sound system and have it use +// goldsrc-type attenuation. We should use this as little as possible and +// phase it out as soon as possible. + +// Take a regular sndlevel and convert it to compatibility mode. +#define SNDLEVEL_TO_COMPATIBILITY_MODE( x ) ((soundlevel_t)(int)( (x) + 256 )) + +// Take a compatibility-mode sndlevel and get the REAL sndlevel out of it. +#define SNDLEVEL_FROM_COMPATIBILITY_MODE( x ) ((soundlevel_t)(int)( (x) - 256 )) + +// Tells if the given sndlevel is marked as compatibility mode. +#define SNDLEVEL_IS_COMPATIBILITY_MODE( x ) ( (x) >= soundlevel_t(256) ) + + + +//----------------------------------------------------------------------------- +// Client-server neutral effects interface +//----------------------------------------------------------------------------- +#define IENGINESOUND_CLIENT_INTERFACE_VERSION "IEngineSoundClient003" +#define IENGINESOUND_SERVER_INTERFACE_VERSION "IEngineSoundServer003" + +abstract_class IEngineSound +{ +public: + // Precache a particular sample + virtual bool PrecacheSound(const char* pSample, bool bPreload = false, bool bIsUISound = false) = 0; + virtual bool IsSoundPrecached(const char* pSample) = 0; + virtual void PrefetchSound(const char* pSample) = 0; + + // Just loads the file header and checks for duration (not hooked up for .mp3's yet) + // Is accessible to server and client though + virtual float GetSoundDuration(const char* pSample) = 0; + + // Pitch of 100 is no pitch shift. Pitch > 100 up to 255 is a higher pitch, pitch < 100 + // down to 1 is a lower pitch. 150 to 70 is the realistic range. + // EmitSound with pitch != 100 should be used sparingly, as it's not quite as + // fast (the pitchshift mixer is not native coded). + + // NOTE: setting iEntIndex to -1 will cause the sound to be emitted from the local + // player (client-side only) + virtual void EmitSound(IRecipientFilter& filter, int iEntIndex, int iChannel, const char* pSample, + float flVolume, float flAttenuation, int iFlags = 0, int iPitch = PITCH_NORM, int iSpecialDSP = 0, + const Vector* pOrigin = NULL, const Vector* pDirection = NULL, CUtlVector< Vector >* pUtlVecOrigins = NULL, bool bUpdatePositions = true, float soundtime = 0.0f, int speakerentity = -1) = 0; + + virtual void EmitSound(IRecipientFilter& filter, int iEntIndex, int iChannel, const char* pSample, + float flVolume, soundlevel_t iSoundlevel, int iFlags = 0, int iPitch = PITCH_NORM, int iSpecialDSP = 0, + const Vector* pOrigin = NULL, const Vector* pDirection = NULL, CUtlVector< Vector >* pUtlVecOrigins = NULL, bool bUpdatePositions = true, float soundtime = 0.0f, int speakerentity = -1) = 0; + + virtual void EmitSentenceByIndex(IRecipientFilter& filter, int iEntIndex, int iChannel, int iSentenceIndex, + float flVolume, soundlevel_t iSoundlevel, int iFlags = 0, int iPitch = PITCH_NORM,int iSpecialDSP = 0, + const Vector* pOrigin = NULL, const Vector* pDirection = NULL, CUtlVector< Vector >* pUtlVecOrigins = NULL, bool bUpdatePositions = true, float soundtime = 0.0f, int speakerentity = -1) = 0; + + virtual void StopSound(int iEntIndex, int iChannel, const char* pSample) = 0; + + // stop all active sounds (client only) + virtual void StopAllSounds(bool bClearBuffers) = 0; + + // Set the room type for a player (client only) + virtual void SetRoomType(IRecipientFilter& filter, int roomType) = 0; + + // Set the dsp preset for a player (client only) + virtual void SetPlayerDSP(IRecipientFilter& filter, int dspType, bool fastReset) = 0; + + // emit an "ambient" sound that isn't spatialized + // only available on the client, assert on server + virtual void EmitAmbientSound(const char* pSample, float flVolume, int iPitch = PITCH_NORM, int flags = 0, float soundtime = 0.0f) = 0; + + + // virtual EntChannel_t CreateEntChannel() = 0; + + virtual float GetDistGainFromSoundLevel(soundlevel_t soundlevel, float dist) = 0; + + // Client .dll only functions + virtual int GetGuidForLastSoundEmitted() = 0; + virtual bool IsSoundStillPlaying(int guid) = 0; + virtual void StopSoundByGuid(int guid) = 0; + // Set's master volume (0.0->1.0) + virtual void SetVolumeByGuid(int guid, float fvol) = 0; + + // Retrieves list of all active sounds + virtual void GetActiveSounds(CUtlVector< SndInfo_t >& sndlist) = 0; + + virtual void PrecacheSentenceGroup(const char* pGroupName) = 0; + virtual void NotifyBeginMoviePlayback() = 0; + virtual void NotifyEndMoviePlayback() = 0; +}; + + +#endif // IENGINESOUND_H \ No newline at end of file diff --git a/SpyCustom/sdk/IEngineVgui.h b/SpyCustom/sdk/IEngineVgui.h new file mode 100644 index 0000000..171d069 --- /dev/null +++ b/SpyCustom/sdk/IEngineVgui.h @@ -0,0 +1,55 @@ +#if !defined( IENGINEVGUI_H ) +#define IENGINEVGUI_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "interface.h" +#include "VGUI.h" + +namespace vgui +{ + class Panel; +}; + +enum VGuiPanel_t +{ + PANEL_ROOT = 0, + PANEL_GAMEUIDLL, + PANEL_CLIENTDLL, + PANEL_TOOLS, + PANEL_INGAMESCREENS, + PANEL_GAMEDLL, + PANEL_CLIENTDLL_TOOLS +}; + +enum PaintMode_t +{ + PAINT_UIPANELS = (1 << 0), + PAINT_INGAMEPANELS = (1 << 1), + PAINT_CURSOR = (1 << 2), +}; + +abstract_class IEngineVGui +{ +public: + virtual ~IEngineVGui(void) { } + + virtual vgui::VPANEL GetPanel(VGuiPanel_t type) = 0; + + virtual bool IsGameUIVisible() = 0; +}; + +#define VENGINE_VGUI_VERSION "VEngineVGui001" + +#if defined(_STATIC_LINKED) && defined(CLIENT_DLL) +namespace Client +{ + extern IEngineVGui* enginevgui; +} +#else +extern IEngineVGui* g_pEnginevgui; +#endif + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/IGameSystem.h b/SpyCustom/sdk/IGameSystem.h new file mode 100644 index 0000000..05f1777 --- /dev/null +++ b/SpyCustom/sdk/IGameSystem.h @@ -0,0 +1,186 @@ +#ifndef IGAMESYSTEM_H +#define IGAMESYSTEM_H +#ifdef _WIN32 +#pragma once +#endif + + +class IGameSystem +{ +public: + virtual char const* Name() = 0; + + virtual bool Init() = 0; + virtual void PostInit() = 0; + virtual void Shutdown() = 0; + + virtual void LevelInitPreEntity() = 0; + virtual void LevelInitPostEntity() = 0; + + virtual void LevelShutdownPreClearSteamAPIContext() {}; + virtual void LevelShutdownPreEntity() = 0; + virtual void LevelShutdownPostEntity() = 0; + virtual void OnSave() = 0; + + virtual void OnRestore() = 0; + + virtual void SafeRemoveIfDesired() = 0; + + virtual bool IsPerFrame() = 0; + + virtual ~IGameSystem(); + + static char const* MapName(); + + static void Add(IGameSystem* pSys); + static void Remove(IGameSystem* pSys); + static void RemoveAll(); + + static bool InitAllSystems(); + static void PostInitAllSystems(); + static void ShutdownAllSystems(); + static void LevelInitPreEntityAllSystems(char const* pMapName); + static void LevelInitPostEntityAllSystems(); + static void LevelShutdownPreClearSteamAPIContextAllSystems(); + static void LevelShutdownPreEntityAllSystems(); + static void LevelShutdownPostEntityAllSystems(); + + static void OnSaveAllSystems(); + static void OnRestoreAllSystems(); + + static void SafeRemoveIfDesiredAllSystems(); + +#ifdef CLIENT_DLL + static void PreRenderAllSystems(); + static void UpdateAllSystems(float frametime); + static void PostRenderAllSystems(); +#else + static void FrameUpdatePreEntityThinkAllSystems(); + static void FrameUpdatePostEntityThinkAllSystems(); + static void PreClientUpdateAllSystems(); + + static CBasePlayer* RunCommandPlayer(); + static CUserCmd* RunCommandUserCmd(); +#endif +}; + +class IGameSystemPerFrame : public IGameSystem +{ +public: + virtual ~IGameSystemPerFrame(); + +#ifdef CLIENT_DLL + virtual void PreRender() = 0; + + virtual void Update(float frametime) = 0; + + virtual void PostRender() = 0; +#else + virtual void FrameUpdatePreEntityThink() = 0; + virtual void FrameUpdatePostEntityThink() = 0; + virtual void PreClientUpdate() = 0; +#endif +}; + +class CBaseGameSystem : public IGameSystem +{ +public: + + virtual char const* Name() { return "unnamed"; } + + virtual bool Init() { return true; } + virtual void PostInit() {} + virtual void Shutdown() {} + + virtual void LevelInitPreEntity() {} + virtual void LevelInitPostEntity() {} + virtual void LevelShutdownPreClearSteamAPIContext() {} + virtual void LevelShutdownPreEntity() {} + virtual void LevelShutdownPostEntity() {} + + virtual void OnSave() {} + virtual void OnRestore() {} + virtual void SafeRemoveIfDesired() {} + + virtual bool IsPerFrame() { return false; } +private: + +#ifdef CLIENT_DLL + virtual void PreRender() {} + + virtual void Update(float frametime) {} + + virtual void PostRender() {} +#else + virtual void FrameUpdatePreEntityThink() {} + virtual void FrameUpdatePostEntityThink() {} + virtual void PreClientUpdate() {} +#endif +}; + +class CBaseGameSystemPerFrame : public IGameSystemPerFrame +{ +public: + virtual char const* Name() { return "unnamed"; } + + virtual bool Init() { return true; } + virtual void PostInit() {} + virtual void Shutdown() {} + + virtual void LevelInitPreEntity() {} + virtual void LevelInitPostEntity() {} + virtual void LevelShutdownPreClearSteamAPIContext() {} + virtual void LevelShutdownPreEntity() {} + virtual void LevelShutdownPostEntity() {} + + virtual void OnSave() {} + virtual void OnRestore() {} + virtual void SafeRemoveIfDesired() {} + + virtual bool IsPerFrame() { return true; } + +#ifdef CLIENT_DLL + virtual void PreRender() { } + + virtual void Update(float frametime) { } + + virtual void PostRender() { } +#else + virtual void FrameUpdatePreEntityThink() { } + virtual void FrameUpdatePostEntityThink() { } + virtual void PreClientUpdate() { } +#endif +}; + +class CAutoGameSystem : public CBaseGameSystem +{ +public: + CAutoGameSystem(char const* name = NULL); + CAutoGameSystem* m_pNext; + + virtual char const* Name() { return m_pszName ? m_pszName : "unnamed"; } + +private: + char const* m_pszName; +}; + +class CAutoGameSystemPerFrame : public CBaseGameSystemPerFrame +{ +public: + CAutoGameSystemPerFrame(char const* name = NULL); + CAutoGameSystemPerFrame* m_pNext; + + virtual char const* Name() { return m_pszName ? m_pszName : "unnamed"; } + +private: + char const* m_pszName; +}; + + +class IToolFrameworkServer +{ +public: + virtual void PreSetupVisibility() = 0; +}; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/IGameUI.h b/SpyCustom/sdk/IGameUI.h new file mode 100644 index 0000000..c156532 --- /dev/null +++ b/SpyCustom/sdk/IGameUI.h @@ -0,0 +1,94 @@ +#ifndef IGAMEUI_H +#define IGAMEUI_H +#ifdef _WIN32 +#pragma once +#endif + +#include "interface.h" +#include "IPanel.h" + +#if !defined( _X360 ) +#include "xboxstubs.h" +#endif + +enum ESteamLoginFailure +{ + STEAMLOGINFAILURE_NONE, + STEAMLOGINFAILURE_BADTICKET, + STEAMLOGINFAILURE_NOSTEAMLOGIN, + STEAMLOGINFAILURE_VACBANNED, + STEAMLOGINFAILURE_LOGGED_IN_ELSEWHERE +}; + +enum ESystemNotify +{ + SYSTEMNOTIFY_STORAGEDEVICES_CHANGED, + SYSTEMNOTIFY_USER_SIGNEDIN, + SYSTEMNOTIFY_USER_SIGNEDOUT, + SYSTEMNOTIFY_XUIOPENING, + SYSTEMNOTIFY_XUICLOSED, + SYSTEMNOTIFY_INVITE_SHUTDOWN, +}; + +abstract_class IGameUI +{ +public: + virtual void Initialize(CreateInterfaceFn appFactory) = 0; + virtual void PostInit() = 0; + + virtual void Connect(CreateInterfaceFn gameFactory) = 0; + + virtual void Start() = 0; + virtual void Shutdown() = 0; + virtual void RunFrame() = 0; + + virtual void OnGameUIActivated() = 0; + virtual void OnGameUIHidden() = 0; + + virtual void OLD_OnConnectToServer(const char* game, int IP, int port) = 0; + + virtual void OnDisconnectFromServer_OLD(uint8 eSteamLoginFailure, const char* username) = 0; + virtual void OnLevelLoadingStarted(bool bShowProgressDialog) = 0; + virtual void OnLevelLoadingFinished(bool bError, const char* failureReason, const char* extendedReason) = 0; + + virtual bool UpdateProgressBar(float progress, const char* statusText) = 0; + virtual bool SetShowProgressText(bool show) = 0; + + virtual void ShowNewGameDialog(int chapter) = 0; + + virtual void SessionNotification(const int notification, const int param = 0) = 0; + virtual void SystemNotification(const int notification) = 0; + virtual void ShowMessageDialog(const uint nType, vgui::Panel* pOwner) = 0; + virtual void UpdatePlayerInfo(uint64 nPlayerId, const char* pName, int nTeam, byte cVoiceState, int nPlayersNeeded, bool bHost) = 0; + virtual void SessionSearchResult(int searchIdx, void* pHostData, XSESSION_SEARCHRESULT* pResult, int ping) = 0; + virtual void OnCreditsFinished(void) = 0; + + virtual void SetLoadingBackgroundDialog(vgui::VPANEL panel) = 0; + + virtual void BonusMapUnlock(const char* pchFileName = NULL, const char* pchMapName = NULL) = 0; + virtual void BonusMapComplete(const char* pchFileName = NULL, const char* pchMapName = NULL) = 0; + virtual void BonusMapChallengeUpdate(const char* pchFileName, const char* pchMapName, const char* pchChallengeName, int iBest) = 0; + virtual void BonusMapChallengeNames(char* pchFileName, char* pchMapName, char* pchChallengeName) = 0; + virtual void BonusMapChallengeObjectives(int& iBronze, int& iSilver, int& iGold) = 0; + virtual void BonusMapDatabaseSave(void) = 0; + virtual int BonusMapNumAdvancedCompleted(void) = 0; + virtual void BonusMapNumMedals(int piNumMedals[3]) = 0; + + virtual void OnConnectToServer2(const char* game, int IP, int connectionPort, int queryPort) = 0; + + virtual bool ValidateStorageDevice(int* pStorageDeviceValidated) = 0; + + virtual void SetProgressOnStart() = 0; + virtual void OnDisconnectFromServer(uint8 eSteamLoginFailure) = 0; + + virtual void OnConfirmQuit(void) = 0; + + virtual bool IsMainMenuVisible(void) = 0; + + virtual void SetMainMenuOverride(vgui::VPANEL panel) = 0; + virtual void SendMainMenuCommand(const char* pszCommand) = 0; +}; + +#define GAMEUI_INTERFACE_VERSION "GameUI011" + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/IHTML.h b/SpyCustom/sdk/IHTML.h new file mode 100644 index 0000000..8bbf4f1 --- /dev/null +++ b/SpyCustom/sdk/IHTML.h @@ -0,0 +1,151 @@ +#ifndef IHTML_H +#define IHTML_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "VGUI.h" +#include "MouseCode.h" +#include "KeyCode.h" +#include "Cursor.h" +#include "IImage.h" + +namespace vgui +{ + + class IHTML + { + public: + virtual void OpenURL(const char*) = 0; + + virtual bool StopLoading() = 0; + + virtual bool Refresh() = 0; + + virtual bool Show(bool shown) = 0; + + virtual const char* GetOpenedPage() = 0; + + virtual void Obsolete_OnSize(int x, int y, int w, int h) = 0; + + virtual void GetHTMLSize(int& wide, int& tall) = 0; + + + virtual void Clear() = 0; + + virtual void AddText(const char* text) = 0; + + enum MOUSE_STATE { UP, DOWN, MOVE, DBLCLICK }; + virtual void Obsolete_OnMouse(MouseCode code, MOUSE_STATE s, int x, int y) = 0; + virtual void Obsolete_OnChar(wchar_t unichar) = 0; + virtual void Obsolete_OnKeyDown(KeyCode code) = 0; + + virtual vgui::IImage* GetBitmap() = 0; + virtual void SetVisible(bool state) = 0; + + + virtual void SetSize(int wide, int tall) = 0; + + virtual void OnMouse(MouseCode code, MOUSE_STATE s, int x, int y, bool bPopupMenuMenu) = 0; + virtual void OnChar(wchar_t unichar, bool bPopupMenu) = 0; + virtual void OnKeyDown(KeyCode code, bool bPopupMenu) = 0; + + virtual void ScrollV(int nPixels) = 0; + virtual void ScrollH(int nPixels) = 0; + virtual void OnMouseWheeled(int delta, bool bPopupMenu) = 0; + + virtual void OnKeyUp(KeyCode code, bool bPopupMenu) = 0; + + + virtual void PostURL(const char* pchURL, const char* pchPostData) = 0; + + virtual void RunJavascript(const char* pchScript) = 0; + + virtual void SetMousePosition(int x, int y, bool bPopupMenu) = 0; + + virtual void SetUserAgentInfo(const wchar_t* pwchUserAgent) = 0; + + virtual void AddHeader(const char* pchHeader, const char* pchValue) = 0; + + virtual void SetFileDialogChoice(const char* pchFileName) = 0; + + virtual void HidePopup() = 0; + virtual void SetHTMLFocus() = 0; + virtual void KillHTMLFocus() = 0; + virtual void HorizontalScrollBarSize(int& x, int& y, int& wide, int& tall) = 0; + virtual void VerticalScrollBarSize(int& x, int& y, int& wide, int& tall) = 0; + virtual int HorizontalScroll() = 0; + virtual int VerticalScroll() = 0; + virtual int HorizontalScrollMax() = 0; + virtual int VerticalScrollMax() = 0; + virtual bool IsHorizontalScrollBarVisible() = 0; + virtual bool IsVeritcalScrollBarVisible() = 0; + virtual void SetHorizontalScroll(int scroll) = 0; + virtual void SetVerticalScroll(int scroll) = 0; + virtual void ViewSource() = 0; + virtual void Copy() = 0; + virtual void Paste() = 0; + + virtual bool IsIERender() = 0; + virtual void GetIDispatchPtr(void** pIDispatch) = 0; + virtual void GetHTMLScroll(int& top, int& left) = 0; + }; + + + enum EWebPageLoadError + { + eLoadErrorNone = 0, + eMimeTypeNotSupported, + eCacheMiss, + eBadURL, + eConnectionProblem, + eProxyConnectionProblem, + + eLoadErrorUnknown, + }; + + + class IHTMLEvents + { + public: + virtual bool Obsolete_OnStartURL(const char* url, const char* target, bool first) = 0; + virtual void Obsolete_OnFinishURL(const char* url) = 0; + virtual void Obsolete_OnProgressURL(long current, long maximum) = 0; + virtual void Obsolete_OnSetStatusText(const char* text) = 0; + virtual void Obsolete_OnUpdate() = 0; + virtual void Obsolete_OnLink() = 0; + virtual void Obsolete_OffLink() = 0; + + virtual void OnURLChanged(const char* url, const char* pchPostData, bool bIsRedirect) = 0; + virtual void OnFinishRequest(const char* url, const char* pageTitle) = 0; + + virtual bool OnStartRequestInternal(const char* url, const char* target, const char* pchPostData, bool bIsRedirect) = 0; + + virtual void ShowPopup(int x, int y, int wide, int tall) = 0; + virtual void HidePopup() = 0; + virtual bool OnPopupHTMLWindow(const char* pchURL, int x, int y, int wide, int tall) = 0; + virtual void SetHTMLTitle(const char* pchTitle) = 0; + virtual void OnLoadingResource(const char* pchURL) = 0; + virtual void OnSetStatusText(const char* text) = 0; + virtual void OnSetCursor(vgui::CursorCode cursor) = 0; + virtual void OnFileLoadDialog(const char* pchTitle, const char* pchInitialFile) = 0; + virtual void OnShowToolTip(const char* pchText) = 0; + virtual void OnUpdateToolTip(const char* pchText) = 0; + virtual void OnHideToolTip() = 0; + + + virtual bool BOnCreateNewWindow(void** ppDispatch) = 0; + virtual void OnLink() = 0; + virtual void OffLink() = 0; + virtual void OnCloseWindow() = 0; + virtual void OnUpdate() = 0; + virtual void OnProgressRequest(long current, long maximum) = 0; + + virtual bool OnOpenNewTab(const char* pchURL, bool bForeground) = 0; + }; + + +} + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/IImage.h b/SpyCustom/sdk/IImage.h new file mode 100644 index 0000000..789fc43 --- /dev/null +++ b/SpyCustom/sdk/IImage.h @@ -0,0 +1,54 @@ +#ifndef IIMAGE_H +#define IIMAGE_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "VGUI.h" + +class Color; + +namespace vgui +{ + + typedef unsigned long HTexture; + + enum iimage_rotation_t + { + ROTATED_UNROTATED = 0, + ROTATED_CLOCKWISE_90, + ROTATED_ANTICLOCKWISE_90, + ROTATED_FLIPPED, + }; + + class IImage + { + public: + virtual void Paint() = 0; + + virtual void SetPos(int x, int y) = 0; + + virtual void GetContentSize(int& wide, int& tall) = 0; + + virtual void GetSize(int& wide, int& tall) = 0; + + virtual void SetSize(int wide, int tall) = 0; + + virtual void SetColor(Color col) = 0; + + virtual ~IImage() {} + + virtual bool Evict() = 0; + + virtual int GetNumFrames() = 0; + virtual void SetFrame(int nFrame) = 0; + virtual HTexture GetID() = 0; + + virtual void SetRotation(int iRotation) = 0; + }; + +} + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/IInput.h b/SpyCustom/sdk/IInput.h new file mode 100644 index 0000000..462146f --- /dev/null +++ b/SpyCustom/sdk/IInput.h @@ -0,0 +1,156 @@ +#ifndef VGUI_IINPUT_H +#define VGUI_IINPUT_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "VGUI.h" +#include "interface.h" +#include "MouseCode.h" +#include "KeyCode.h" + +namespace vgui +{ + + class Cursor; + typedef unsigned long HCursor; + +#define VGUI_GCS_COMPREADSTR 0x0001 +#define VGUI_GCS_COMPREADATTR 0x0002 +#define VGUI_GCS_COMPREADCLAUSE 0x0004 +#define VGUI_GCS_COMPSTR 0x0008 +#define VGUI_GCS_COMPATTR 0x0010 +#define VGUI_GCS_COMPCLAUSE 0x0020 +#define VGUI_GCS_CURSORPOS 0x0080 +#define VGUI_GCS_DELTASTART 0x0100 +#define VGUI_GCS_RESULTREADSTR 0x0200 +#define VGUI_GCS_RESULTREADCLAUSE 0x0400 +#define VGUI_GCS_RESULTSTR 0x0800 +#define VGUI_GCS_RESULTCLAUSE 0x1000 +#define VGUI_CS_INSERTCHAR 0x2000 +#define VGUI_CS_NOMOVECARET 0x4000 + +#define MESSAGE_CURSOR_POS -1 +#define MESSAGE_CURRENT_KEYFOCUS -2 + + + class IInput : public IBaseInterface + { + public: + virtual void SetMouseFocus(VPANEL newMouseFocus) = 0; + virtual void SetMouseCapture(VPANEL panel) = 0; + + virtual void GetKeyCodeText(KeyCode code, OUT_Z_BYTECAP(buflen) char* buf, int buflen) = 0; + + virtual VPANEL GetFocus() = 0; + virtual VPANEL GetCalculatedFocus() = 0; + virtual VPANEL GetMouseOver() = 0; + + virtual void SetCursorPos(int x, int y) = 0; + virtual void GetCursorPos(int& x, int& y) = 0; + virtual bool WasMousePressed(MouseCode code) = 0; + virtual bool WasMouseDoublePressed(MouseCode code) = 0; + virtual bool IsMouseDown(MouseCode code) = 0; + + virtual void SetCursorOveride(HCursor cursor) = 0; + virtual HCursor GetCursorOveride() = 0; + + virtual bool WasMouseReleased(MouseCode code) = 0; + virtual bool WasKeyPressed(KeyCode code) = 0; + virtual bool IsKeyDown(KeyCode code) = 0; + virtual bool WasKeyTyped(KeyCode code) = 0; + virtual bool WasKeyReleased(KeyCode code) = 0; + + virtual VPANEL GetAppModalSurface() = 0; + virtual void SetAppModalSurface(VPANEL panel) = 0; + virtual void ReleaseAppModalSurface() = 0; + + virtual void GetCursorPosition(int& x, int& y) = 0; + + virtual void SetIMEWindow(void* hwnd) = 0; + virtual void* GetIMEWindow() = 0; + + virtual void OnChangeIME(bool forward) = 0; + virtual int GetCurrentIMEHandle() = 0; + virtual int GetEnglishIMEHandle() = 0; + + virtual void GetIMELanguageName(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t* buf, int unicodeBufferSizeInBytes) = 0; + virtual void GetIMELanguageShortCode(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t* buf, int unicodeBufferSizeInBytes) = 0; + + struct LanguageItem + { + wchar_t shortname[4]; + wchar_t menuname[128]; + int handleValue; + bool active; + }; + + struct ConversionModeItem + { + wchar_t menuname[128]; + int handleValue; + bool active; + }; + + struct SentenceModeItem + { + wchar_t menuname[128]; + int handleValue; + bool active; + }; + + virtual int GetIMELanguageList(LanguageItem* dest, int destcount) = 0; + virtual int GetIMEConversionModes(ConversionModeItem* dest, int destcount) = 0; + virtual int GetIMESentenceModes(SentenceModeItem* dest, int destcount) = 0; + + virtual void OnChangeIMEByHandle(int handleValue) = 0; + virtual void OnChangeIMEConversionModeByHandle(int handleValue) = 0; + virtual void OnChangeIMESentenceModeByHandle(int handleValue) = 0; + + virtual void OnInputLanguageChanged() = 0; + virtual void OnIMEStartComposition() = 0; + virtual void OnIMEComposition(int flags) = 0; + virtual void OnIMEEndComposition() = 0; + + virtual void OnIMEShowCandidates() = 0; + virtual void OnIMEChangeCandidates() = 0; + virtual void OnIMECloseCandidates() = 0; + virtual void OnIMERecomputeModes() = 0; + + virtual int GetCandidateListCount() = 0; + virtual void GetCandidate(int num, OUT_Z_BYTECAP(destSizeBytes) wchar_t* dest, int destSizeBytes) = 0; + virtual int GetCandidateListSelectedItem() = 0; + virtual int GetCandidateListPageSize() = 0; + virtual int GetCandidateListPageStart() = 0; + + virtual void SetCandidateWindowPos(int x, int y) = 0; + + virtual bool GetShouldInvertCompositionString() = 0; + virtual bool CandidateListStartsAtOne() = 0; + + virtual void SetCandidateListPageStart(int start) = 0; + + virtual void SetMouseCaptureEx(VPANEL panel, MouseCode captureStartMouseCode) = 0; + + virtual void RegisterKeyCodeUnhandledListener(VPANEL panel) = 0; + virtual void UnregisterKeyCodeUnhandledListener(VPANEL panel) = 0; + + virtual void OnKeyCodeUnhandled(int keyCode) = 0; + + virtual void SetModalSubTree(VPANEL subTree, VPANEL unhandledMouseClickListener, bool restrictMessagesToSubTree = true) = 0; + virtual void ReleaseModalSubTree() = 0; + virtual VPANEL GetModalSubTree() = 0; + + virtual void SetModalSubTreeReceiveMessages(bool state) = 0; + virtual bool ShouldModalSubTreeReceiveMessages() const = 0; + + virtual VPANEL GetMouseCapture() = 0; + }; + +#define VGUI_INPUT_INTERFACE_VERSION "VGUI_Input005" + +} + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/IKeyValuesSystem.h b/SpyCustom/sdk/IKeyValuesSystem.h new file mode 100644 index 0000000..c274bfc --- /dev/null +++ b/SpyCustom/sdk/IKeyValuesSystem.h @@ -0,0 +1,34 @@ +#ifndef VSTDLIB_IKEYVALUESSYSTEM_H +#define VSTDLIB_IKEYVALUESSYSTEM_H +#ifdef _WIN32 +#pragma once +#endif + +#include "vstdlib.h" + +typedef int HKeySymbol; +#define INVALID_KEY_SYMBOL (-1) + +class IKeyValuesSystem +{ +public: + virtual void RegisterSizeofKeyValues(int size) = 0; + + virtual void* AllocKeyValuesMemory(int size) = 0; + virtual void FreeKeyValuesMemory(void* pMem) = 0; + + virtual HKeySymbol GetSymbolForString(const char* name, bool bCreate = true) = 0; + virtual const char* GetStringForSymbol(HKeySymbol symbol) = 0; + + virtual void AddKeyValuesToMemoryLeakList(void* pMem, HKeySymbol name) = 0; + virtual void RemoveKeyValuesFromMemoryLeakList(void* pMem) = 0; + + virtual void SetKeyValuesExpressionSymbol(const char* name, bool bValue) = 0; + virtual bool GetKeyValuesExpressionSymbol(const char* name) = 0; + + virtual HKeySymbol GetSymbolForStringCaseSensitive(HKeySymbol& hCaseInsensitiveSymbol, const char* name, bool bCreate = true) = 0; +}; + +VSTDLIB_INTERFACE IKeyValuesSystem* KeyValuesSystem(); + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/ILocalize.h b/SpyCustom/sdk/ILocalize.h new file mode 100644 index 0000000..dac0b38 --- /dev/null +++ b/SpyCustom/sdk/ILocalize.h @@ -0,0 +1,371 @@ +#ifndef ILOCALIZE_H +#define ILOCALIZE_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "IAppSystem.h" +#include "KeyValues.h" + +#if !defined(_WCHAR_T_DEFINED) && !defined(GNUC) +typedef unsigned short wchar_t; +#define _WCHAR_T_DEFINED +#endif + + +typedef unsigned long StringIndex_t; +const unsigned long INVALID_LOCALIZE_STRING_INDEX = (StringIndex_t)-1; + +abstract_class ILocalize +{ +public: + virtual bool AddFile(const char* fileName, const char* pPathID = NULL, bool bIncludeFallbackSearchPaths = false) = 0; + + virtual void RemoveAll() = 0; + + virtual wchar_t* Find(char const* tokenName) = 0; + + virtual StringIndex_t FindIndex(const char* tokenName) = 0; + + virtual const char* GetNameByIndex(StringIndex_t index) = 0; + virtual wchar_t* GetValueByIndex(StringIndex_t index) = 0; + + virtual StringIndex_t GetFirstStringIndex() = 0; + virtual StringIndex_t GetNextStringIndex(StringIndex_t index) = 0; + + virtual void AddString(const char* tokenName, wchar_t* unicodeString, const char* fileName) = 0; + + virtual void SetValueByIndex(StringIndex_t index, wchar_t* newValue) = 0; + + virtual bool SaveToFile(const char* fileName) = 0; + + virtual int GetLocalizationFileCount() = 0; + virtual const char* GetLocalizationFileName(int index) = 0; + + virtual const char* GetFileNameByIndex(StringIndex_t index) = 0; + + virtual void ReloadLocalizationFiles() = 0; + + virtual const char* FindAsUTF8(const char* pchTokenName) = 0; + + virtual void ConstructString(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t* unicodeOutput, int unicodeBufferSizeInBytes, const char* tokenName, KeyValues* localizationVariables) = 0; + virtual void ConstructString(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t* unicodeOutput, int unicodeBufferSizeInBytes, StringIndex_t unlocalizedTextSymbol, KeyValues* localizationVariables) = 0; + + static int ConvertANSIToUnicode(const char* ansi, OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t* unicode, int unicodeBufferSizeInBytes); + + static int ConvertUnicodeToANSI(const wchar_t* unicode, OUT_Z_BYTECAP(ansiBufferSize) char* ansi, int ansiBufferSize); + + template < typename T > + static void ConstructString(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) T* unicodeOuput, int unicodeBufferSizeInBytes, const T* formatString, int numFormatParameters, ...) + { + va_list argList; + va_start(argList, numFormatParameters); + + ConstructStringVArgsInternal(unicodeOuput, unicodeBufferSizeInBytes, formatString, numFormatParameters, argList); + + va_end(argList); + } + + template < typename T > + static void ConstructStringVArgs(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) T* unicodeOuput, int unicodeBufferSizeInBytes, const T* formatString, int numFormatParameters, va_list argList) + { + ConstructStringVArgsInternal(unicodeOuput, unicodeBufferSizeInBytes, formatString, numFormatParameters, argList); + } + + template < typename T > + static void ConstructString(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) T* unicodeOutput, int unicodeBufferSizeInBytes, const T* formatString, KeyValues* localizationVariables) + { + ConstructStringKeyValuesInternal(unicodeOutput, unicodeBufferSizeInBytes, formatString, localizationVariables); + } + +private: + static void ConstructStringVArgsInternal(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) char* unicodeOutput, int unicodeBufferSizeInBytes, const char* formatString, int numFormatParameters, va_list argList); + static void ConstructStringVArgsInternal(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t* unicodeOutput, int unicodeBufferSizeInBytes, const wchar_t* formatString, int numFormatParameters, va_list argList); + + static void ConstructStringKeyValuesInternal(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) char* unicodeOutput, int unicodeBufferSizeInBytes, const char* formatString, KeyValues* localizationVariables); + static void ConstructStringKeyValuesInternal(OUT_Z_BYTECAP(unicodeBufferSizeInBytes) wchar_t* unicodeOutput, int unicodeBufferSizeInBytes, const wchar_t* formatString, KeyValues* localizationVariables); +}; + +#ifdef GC + +typedef char locchar_t; + +#define loc_snprintf Q_snprintf +#define loc_sprintf_safe V_sprintf_safe +#define loc_sncat Q_strncat +#define loc_scat_safe V_strcat_safe +#define loc_sncpy Q_strncpy +#define loc_scpy_safe V_strcpy_safe +#define loc_strlen Q_strlen +#define LOCCHAR( x ) x + +#else + +typedef wchar_t locchar_t; + +#define loc_snprintf V_snwprintf +#define loc_sprintf_safe V_swprintf_safe +#define loc_sncat V_wcsncat +#define loc_scat_safe V_wcscat_safe +#define loc_sncpy Q_wcsncpy +#define loc_scpy_safe V_wcscpy_safe +#define loc_strlen Q_wcslen +#define LOCCHAR(x) L ## x + +#endif + +template < typename T > +class TypedKeyValuesStringHelper +{ +public: + static const T* Read(KeyValues* pKeyValues, const char* pKeyName, const T* pDefaultValue); + static void Write(KeyValues* pKeyValues, const char* pKeyName, const T* pValue); +}; + +template < > +class TypedKeyValuesStringHelper +{ +public: + static const char* Read(KeyValues* pKeyValues, const char* pKeyName, const char* pDefaultValue) { return pKeyValues->GetString(pKeyName, pDefaultValue); } + static void Write(KeyValues* pKeyValues, const char* pKeyName, const char* pValue) { pKeyValues->SetString(pKeyName, pValue); } +}; + +template < > +class TypedKeyValuesStringHelper +{ +public: + static const wchar_t* Read(KeyValues* pKeyValues, const char* pKeyName, const wchar_t* pDefaultValue) { return pKeyValues->GetWString(pKeyName, pDefaultValue); } + static void Write(KeyValues* pKeyValues, const char* pKeyName, const wchar_t* pValue) { pKeyValues->SetWString(pKeyName, pValue); } +}; + +template < typename T > +class CLocalizedStringArg; + +template < typename T > +class CLocalizedStringArgStringImpl +{ +public: + enum { kIsValid = true }; + + CLocalizedStringArgStringImpl(const locchar_t* pStr) : m_pStr(pStr) { } + + const locchar_t* GetLocArg() const { Assert(m_pStr); return m_pStr; } + +private: + const locchar_t* m_pStr; +}; + +template < typename T > +class CLocalizedStringArg : public CLocalizedStringArgStringImpl +{ +public: + CLocalizedStringArg(const locchar_t* pStr) : CLocalizedStringArgStringImpl(pStr) { } +}; + +template < typename T > +class CLocalizedStringArgPrintfImpl +{ +public: + enum { kIsValid = true }; + + CLocalizedStringArgPrintfImpl(T value, const locchar_t* loc_Format) { loc_snprintf(m_cBuffer, kBufferSize, loc_Format, value); } + + const locchar_t* GetLocArg() const { return m_cBuffer; } + +private: + enum { kBufferSize = 128, }; + locchar_t m_cBuffer[kBufferSize]; +}; + +template < > +class CLocalizedStringArg : public CLocalizedStringArgPrintfImpl +{ +public: + CLocalizedStringArg(uint16 unValue) : CLocalizedStringArgPrintfImpl(unValue, LOCCHAR("%u")) { } +}; + +template < > +class CLocalizedStringArg : public CLocalizedStringArgPrintfImpl +{ +public: + CLocalizedStringArg(uint32 unValue) : CLocalizedStringArgPrintfImpl(unValue, LOCCHAR("%u")) { } +}; + +template < > +class CLocalizedStringArg : public CLocalizedStringArgPrintfImpl +{ +public: + CLocalizedStringArg(uint64 unValue) : CLocalizedStringArgPrintfImpl(unValue, LOCCHAR("%llu")) { } +}; + +template < > +class CLocalizedStringArg : public CLocalizedStringArgPrintfImpl +{ +public: + CLocalizedStringArg(float fValue) + : CLocalizedStringArgPrintfImpl(fValue, + fabsf(fValue) <= FLT_EPSILON || fabsf(fValue) >= 1.0f ? LOCCHAR("%.0f") : LOCCHAR("%.1f")) + { + } +}; + +class CConstructLocalizedString +{ +public: + template < typename T > + CConstructLocalizedString(const locchar_t* loc_Format, T arg0) + { + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + + m_loc_Buffer[0] = '\0'; + + if (loc_Format) + { + ::ILocalize::ConstructString(m_loc_Buffer, sizeof(m_loc_Buffer), loc_Format, 1, CLocalizedStringArg(arg0).GetLocArg()); + } + } + + template < typename T, typename U > + CConstructLocalizedString(const locchar_t* loc_Format, T arg0, U arg1) + { + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + + m_loc_Buffer[0] = '\0'; + + if (loc_Format) + { + ::ILocalize::ConstructString(m_loc_Buffer, sizeof(m_loc_Buffer), loc_Format, 2, CLocalizedStringArg(arg0).GetLocArg(), CLocalizedStringArg(arg1).GetLocArg()); + } + } + + template < typename T, typename U, typename V > + CConstructLocalizedString(const locchar_t* loc_Format, T arg0, U arg1, V arg2) + { + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + + m_loc_Buffer[0] = '\0'; + + if (loc_Format) + { + ::ILocalize::ConstructString(m_loc_Buffer, + sizeof(m_loc_Buffer), + loc_Format, + 3, + CLocalizedStringArg(arg0).GetLocArg(), + CLocalizedStringArg(arg1).GetLocArg(), + CLocalizedStringArg(arg2).GetLocArg()); + } + } + + template < typename T, typename U, typename V, typename W > + CConstructLocalizedString(const locchar_t* loc_Format, T arg0, U arg1, V arg2, W arg3) + { + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + + m_loc_Buffer[0] = '\0'; + + if (loc_Format) + { + ::ILocalize::ConstructString(m_loc_Buffer, + sizeof(m_loc_Buffer), + loc_Format, + 4, + CLocalizedStringArg(arg0).GetLocArg(), + CLocalizedStringArg(arg1).GetLocArg(), + CLocalizedStringArg(arg2).GetLocArg(), + CLocalizedStringArg(arg3).GetLocArg()); + } + } + + template < typename T, typename U, typename V, typename W, typename X, typename Y > + CConstructLocalizedString(const locchar_t* loc_Format, T arg0, U arg1, V arg2, W arg3, X arg4, Y arg5) + { + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + + m_loc_Buffer[0] = '\0'; + + if (loc_Format) + { + ::ILocalize::ConstructString(m_loc_Buffer, + sizeof(m_loc_Buffer), + loc_Format, + 6, + CLocalizedStringArg(arg0).GetLocArg(), + CLocalizedStringArg(arg1).GetLocArg(), + CLocalizedStringArg(arg2).GetLocArg(), + CLocalizedStringArg(arg3).GetLocArg(), + CLocalizedStringArg(arg4).GetLocArg(), + CLocalizedStringArg(arg5).GetLocArg()); + } + } + + template < typename T, typename U, typename V, typename W, typename X, typename Y, typename Z > + CConstructLocalizedString(const locchar_t* loc_Format, T arg0, U arg1, V arg2, W arg3, X arg4, Y arg5, Z arg6) + { + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + COMPILE_TIME_ASSERT(CLocalizedStringArg::kIsValid); + + m_loc_Buffer[0] = '\0'; + + if (loc_Format) + { + ::ILocalize::ConstructString(m_loc_Buffer, + sizeof(m_loc_Buffer), + loc_Format, + 7, + CLocalizedStringArg(arg0).GetLocArg(), + CLocalizedStringArg(arg1).GetLocArg(), + CLocalizedStringArg(arg2).GetLocArg(), + CLocalizedStringArg(arg3).GetLocArg(), + CLocalizedStringArg(arg4).GetLocArg(), + CLocalizedStringArg(arg5).GetLocArg(), + CLocalizedStringArg(arg6).GetLocArg()); + } + } + + CConstructLocalizedString(const locchar_t* loc_Format, KeyValues* pKeyValues) + { + m_loc_Buffer[0] = '\0'; + + if (loc_Format && pKeyValues) + { + ::ILocalize::ConstructString(m_loc_Buffer, sizeof(m_loc_Buffer), loc_Format, pKeyValues); + } + } + + operator const locchar_t* () const + { + return m_loc_Buffer; + } + +private: + enum { kBufferSize = 512, }; + locchar_t m_loc_Buffer[kBufferSize]; +}; +namespace vgui +{ + class ILocalize : public ::ILocalize { }; +} + +#define VGUI_LOCALIZE_INTERFACE_VERSION "VGUI_Localize005" + + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/IMesh.h b/SpyCustom/sdk/IMesh.h new file mode 100644 index 0000000..a4d43d2 --- /dev/null +++ b/SpyCustom/sdk/IMesh.h @@ -0,0 +1,3353 @@ +#ifndef IMESH_H +#define IMESH_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "interface.h" +#include "imaterial.h" +#include +#include +#include "dbg.h" +#include "meshutils.h" + +#include "imaterialsystem.h" + +#ifdef OSX +#endif + +class IMaterial; +class CMeshBuilder; +class IMaterialVar; +typedef uint64 VertexFormat_t; +struct ShaderStencilState_t; + + +#ifdef _DEBUG +#endif + + +enum +{ + VERTEX_MAX_TEXTURE_COORDINATES = 8, + BONE_MATRIX_INDEX_INVALID = 255 +}; + +enum +{ + INDEX_BUFFER_SIZE = 32768, + DYNAMIC_VERTEX_BUFFER_MEMORY = (1024 + 512) * 1024, + DYNAMIC_VERTEX_BUFFER_MEMORY_SMALL = 384 * 1024, +}; + +enum WriteCombineOrdering_t +{ + MB_FIELD_NONE = -1, + MB_FIELD_POSITION = 0, + MB_FIELD_BONE_WEIGHTS, + MB_FIELD_BONE_INDEX, + MB_FIELD_NORMAL, + MB_FIELD_COLOR, + MB_FIELD_SPECULAR, + MB_FIELD_TEXCOORD_FIRST, + MB_FIELD_TEXCOORD_LAST = MB_FIELD_TEXCOORD_FIRST + VERTEX_MAX_TEXTURE_COORDINATES - 1, + MB_FIELD_TANGENT_S, + MB_FIELD_TANGENT_T, + MB_FIELD_USERDATA, +}; + +#define MB_FIELD_TEXCOORD( nStage ) ( MB_FIELD_TEXCOORD_FIRST + ( nStage ) ) + +struct VertexDesc_t +{ + int m_VertexSize_Position; + int m_VertexSize_BoneWeight; + int m_VertexSize_BoneMatrixIndex; + int m_VertexSize_Normal; + int m_VertexSize_Color; + int m_VertexSize_Specular; + int m_VertexSize_TexCoord[VERTEX_MAX_TEXTURE_COORDINATES]; + int m_VertexSize_TangentS; + int m_VertexSize_TangentT; + int m_VertexSize_Wrinkle; + + int m_VertexSize_UserData; + + int m_ActualVertexSize; + VertexCompressionType_t m_CompressionType; + + int m_NumBoneWeights; + + float* m_pPosition; + + float* m_pBoneWeight; + +#ifndef NEW_SKINNING + unsigned char* m_pBoneMatrixIndex; +#else + float* m_pBoneMatrixIndex; +#endif + + float* m_pNormal; + + unsigned char* m_pColor; + unsigned char* m_pSpecular; + float* m_pTexCoord[VERTEX_MAX_TEXTURE_COORDINATES]; + + float* m_pTangentS; + float* m_pTangentT; + + float* m_pWrinkle; + + float* m_pUserData; + + int m_nFirstVertex; + + unsigned int m_nOffset; + +#ifdef DEBUG_WRITE_COMBINE + int m_nLastWrittenField; + unsigned char* m_pLastWrittenAddress; +#endif +}; + +struct IndexDesc_t +{ + unsigned short* m_pIndices; + + unsigned int m_nOffset; + + unsigned int m_nFirstIndex; + + unsigned int m_nIndexSize; +}; + + +struct MeshDesc_t : public VertexDesc_t, public IndexDesc_t +{ +}; + + +struct ModelVertexDX8_t +{ + Vector m_vecPosition; + Vector m_vecNormal; + Vector2D m_vecTexCoord; + Vector4D m_vecUserData; +}; + +struct QuadTessVertex_t +{ + Vector4D m_vTangent; + Vector4D m_vUV01; + Vector4D m_vUV23; +}; + +struct MeshBoneRemap_t +{ + DECLARE_BYTESWAP_DATADESC(); + int m_nActualBoneIndex; + int m_nSrcBoneIndex; +}; + +struct MeshInstanceData_t +{ + int m_nIndexOffset; + int m_nIndexCount; + int m_nBoneCount; + MeshBoneRemap_t* m_pBoneRemap; + matrix3x4_t* m_pPoseToWorld; + const ITexture* m_pEnvCubemap; + MaterialLightingState_t* m_pLightingState; + MaterialPrimitiveType_t m_nPrimType; + const IVertexBuffer* m_pVertexBuffer; + int m_nVertexOffsetInBytes; + const IIndexBuffer* m_pIndexBuffer; + const IVertexBuffer* m_pColorBuffer; + int m_nColorVertexOffsetInBytes; + ShaderStencilState_t* m_pStencilState; + Vector4D m_DiffuseModulation; +}; + +struct MeshBuffersAllocationSettings_t +{ + uint32 m_uiIbUsageFlags; +}; + +inline float* OffsetFloatPointer(float* pBufferPointer, int nVertexCount, int vertexSize) +{ + return reinterpret_cast( + reinterpret_cast(pBufferPointer) + + nVertexCount * vertexSize); +} + +inline const float* OffsetFloatPointer(const float* pBufferPointer, int nVertexCount, int vertexSize) +{ + return reinterpret_cast( + reinterpret_cast(pBufferPointer) + + nVertexCount * vertexSize); +} + +inline void IncrementFloatPointer(float*& pBufferPointer, int vertexSize) +{ + pBufferPointer = reinterpret_cast(reinterpret_cast(pBufferPointer) + vertexSize); +} + + +class CPrimList +{ +public: + CPrimList(); + CPrimList(int nFirstIndex, int nIndexCount); + + int m_FirstIndex; + int m_NumIndices; +}; + +inline CPrimList::CPrimList() +{ +} + +inline CPrimList::CPrimList(int nFirstIndex, int nIndexCount) +{ + m_FirstIndex = nFirstIndex; + m_NumIndices = nIndexCount; +} + +abstract_class IVertexBuffer +{ +public: + virtual int VertexCount() const = 0; + virtual VertexFormat_t GetVertexFormat() const = 0; + + virtual bool IsDynamic() const = 0; + + virtual void BeginCastBuffer(VertexFormat_t format) = 0; + virtual void EndCastBuffer() = 0; + + virtual int GetRoomRemaining() const = 0; + + virtual bool Lock(int nVertexCount, bool bAppend, VertexDesc_t& desc) = 0; + virtual void Unlock(int nVertexCount, VertexDesc_t& desc) = 0; + + virtual void Spew(int nVertexCount, const VertexDesc_t& desc) = 0; + + virtual void ValidateData(int nVertexCount, const VertexDesc_t& desc) = 0; +}; + +abstract_class IIndexBuffer +{ +public: + virtual int IndexCount() const = 0; + virtual MaterialIndexFormat_t IndexFormat() const = 0; + + virtual bool IsDynamic() const = 0; + + virtual void BeginCastBuffer(MaterialIndexFormat_t format) = 0; + virtual void EndCastBuffer() = 0; + + virtual int GetRoomRemaining() const = 0; + + virtual bool Lock(int nMaxIndexCount, bool bAppend, IndexDesc_t& desc) = 0; + virtual void Unlock(int nWrittenIndexCount, IndexDesc_t& desc) = 0; + + virtual void ModifyBegin(bool bReadOnly, int nFirstIndex, int nIndexCount, IndexDesc_t& desc) = 0; + virtual void ModifyEnd(IndexDesc_t& desc) = 0; + + virtual void Spew(int nIndexCount, const IndexDesc_t& desc) = 0; + + virtual void ValidateData(int nIndexCount, const IndexDesc_t& desc) = 0; + + virtual IMesh* GetMesh() = 0; +}; + +abstract_class ICachedPerFrameMeshData +{ +public: + virtual void Free() = 0; +}; + +abstract_class IMesh : public IVertexBuffer, public IIndexBuffer +{ +public: + virtual void SetPrimitiveType(MaterialPrimitiveType_t type) = 0; + + virtual void Draw(int firstIndex = -1, int numIndices = 0) = 0; + + virtual void SetColorMesh(IMesh* pColorMesh, int nVertexOffset) = 0; + + virtual void Draw(CPrimList* pLists, int nLists) = 0; + + virtual void CopyToMeshBuilder( + int iStartVert, + int nVerts, + int iStartIndex, + int nIndices, + int indexOffset, + CMeshBuilder& builder) = 0; + + virtual void Spew(int numVerts, int numIndices, const MeshDesc_t& desc) = 0; + + virtual void ValidateData(int numVerts, int numIndices, const MeshDesc_t& desc) = 0; + + virtual void LockMesh(int numVerts, int numIndices, MeshDesc_t& desc, MeshBuffersAllocationSettings_t* pSettings) = 0; + virtual void ModifyBegin(int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc) = 0; + virtual void ModifyEnd(MeshDesc_t& desc) = 0; + virtual void UnlockMesh(int numVerts, int numIndices, MeshDesc_t& desc) = 0; + + virtual void ModifyBeginEx(bool bReadOnly, int firstVertex, int numVerts, int firstIndex, int numIndices, MeshDesc_t& desc) = 0; + + virtual void SetFlexMesh(IMesh* pMesh, int nVertexOffset) = 0; + + virtual void DisableFlexMesh() = 0; + + virtual void MarkAsDrawn() = 0; + + virtual void DrawModulated(const Vector4D& vecDiffuseModulation, int firstIndex = -1, int numIndices = 0) = 0; + + virtual unsigned int ComputeMemoryUsed() = 0; + + virtual void* AccessRawHardwareDataStream(uint8 nRawStreamIndex, uint32 numBytes, uint32 uiFlags, void* pvContext) = 0; + + virtual ICachedPerFrameMeshData* GetCachedPerFrameMeshData() = 0; + virtual void ReconstructFromCachedPerFrameMeshData(ICachedPerFrameMeshData* pData) = 0; +}; + + +#include "meshreader.h" + +#define INVALID_BUFFER_OFFSET 0xFFFFFFFFUL + +#define VTX_HAVEPOS 1 +#define VTX_HAVENORMAL 2 +#define VTX_HAVECOLOR 4 +#define VTX_HAVEALL ( VTX_HAVEPOS | VTX_HAVENORMAL | VTX_HAVECOLOR ) + + +class CVertexBuilder : private VertexDesc_t +{ +public: + CVertexBuilder(); + CVertexBuilder(IVertexBuffer* pVertexBuffer, VertexFormat_t fmt = 0); + ~CVertexBuilder(); + + bool Lock(int nMaxIndexCount, bool bAppend = false); + void Unlock(); + + void SpewData(); + + int GetRoomRemaining() const; + + void Bind(IMatRenderContext* pContext, int nStreamID, VertexFormat_t usage = 0); + + int Offset() const; + + void SetCompressionType(VertexCompressionType_t compressionType); + void ValidateCompressionType(); + + void Begin(IVertexBuffer* pVertexBuffer, int nVertexCount, int* nFirstVertex); + void Begin(IVertexBuffer* pVertexBuffer, int nVertexCount); + + void End(bool bSpewData = false); + + void BeginModify(IVertexBuffer* pVertexBuffer, int nFirstVertex = 0, int nVertexCount = -1); + void EndModify(bool bSpewData = false); + + int VertexCount() const; + + int TotalVertexCount() const; + + void Reset(); + + int VertexSize() { return m_ActualVertexSize; } + + int TextureCoordinateSize(int nTexCoordNumber) { return m_VertexSize_TexCoord[nTexCoordNumber]; } + + void* BaseVertexData(); + + void SelectVertex(int idx); + + void AdvanceVertex(void); + template void AdvanceVertexF(void); + void AdvanceVertices(int nVerts); + + int GetCurrentVertex() const; + int GetFirstVertex() const; + + const float* Position() const; + + const float* Normal() const; + + unsigned int Color() const; + + unsigned char* Specular() const; + + const float* TexCoord(int stage) const; + + const float* TangentS() const; + const float* TangentT() const; + + const float* BoneWeight() const; + float Wrinkle() const; + + int NumBoneWeights() const; +#ifndef NEW_SKINNING + unsigned char* BoneMatrix() const; +#else + float* BoneMatrix() const; +#endif + + void Position3f(float x, float y, float z); + void Position3fv(const float* v); + + void Normal3f(float nx, float ny, float nz); + void Normal3fv(const float* n); + void NormalDelta3fv(const float* n); + void NormalDelta3f(float nx, float ny, float nz); + template void CompressedNormal3f(float nx, float ny, float nz); + template void CompressedNormal3fv(const float* n); + + void Color3f(float r, float g, float b); + void Color3fv(const float* rgb); + void Color4f(float r, float g, float b, float a); + void Color4fv(const float* rgba); + + void Color3ub(unsigned char r, unsigned char g, unsigned char b); + void Color3ubv(unsigned char const* rgb); + void Color4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a); + void Color4ubv(unsigned char const* rgba); + void Color4Packed(int packedColor); + int PackColor4(unsigned char r, unsigned char g, unsigned char b, unsigned char a); + + void Specular3f(float r, float g, float b); + void Specular3fv(const float* rgb); + void Specular4f(float r, float g, float b, float a); + void Specular4fv(const float* rgba); + + void Specular3ub(unsigned char r, unsigned char g, unsigned char b); + void Specular3ubv(unsigned char const* c); + void Specular4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a); + void Specular4ubv(unsigned char const* c); + + void TexCoord1f(int stage, float s); + void TexCoord2f(int stage, float s, float t); + void TexCoord2fv(int stage, const float* st); + void TexCoord3f(int stage, float s, float t, float u); + void TexCoord3fv(int stage, const float* stu); + void TexCoord4f(int stage, float s, float t, float u, float w); + void TexCoord4fv(int stage, const float* stuv); + + void TexCoordSubRect2f(int stage, float s, float t, float offsetS, float offsetT, float scaleS, float scaleT); + void TexCoordSubRect2fv(int stage, const float* st, const float* offset, const float* scale); + + void TangentS3f(float sx, float sy, float sz); + void TangentS3fv(const float* s); + + void TangentT3f(float tx, float ty, float tz); + void TangentT3fv(const float* t); + + void Wrinkle1f(float flWrinkle); + + void BoneWeight(int idx, float weight); + void BoneWeights2(float weight1, float weight2); + + template void CompressedBoneWeight3fv(const float* pWeights); + + void BoneMatrix(int idx, int matrixIndex); + void BoneMatrices4(int matrixIdx0, int matrixIdx1, int matrixIdx2, int matrixIdx3); + + void UserData(const float* pData); + template void CompressedUserData(const float* pData); + + void FastVertex(const ModelVertexDX8_t& vertex); + void FastVertexSSE(const ModelVertexDX8_t& vertex); + void FastQuadVertexSSE(const QuadTessVertex_t& vertex); + + void FastAdvanceNVertices(int n); + +#if defined( _X360 ) + void VertexDX8ToX360(const ModelVertexDX8_t& vertex); +#endif + + void AttachBegin(IMesh* pMesh, int nMaxVertexCount, const MeshDesc_t& desc); + void AttachEnd(); + void AttachBeginModify(IMesh* pMesh, int nFirstVertex, int nVertexCount, const MeshDesc_t& desc); + void AttachEndModify(); + +private: + IVertexBuffer* m_pVertexBuffer; + + bool m_bModify; + + int m_nMaxVertexCount; + + int m_nVertexCount; + + mutable int m_nCurrentVertex; + + mutable float* m_pCurrPosition; + mutable float* m_pCurrNormal; + mutable unsigned char* m_pCurrColor; + mutable float* m_pCurrTexCoord[VERTEX_MAX_TEXTURE_COORDINATES]; + + int m_nTotalVertexCount; + + unsigned int m_nBufferOffset; + unsigned int m_nBufferFirstVertex; + +#if ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 ) + bool m_bWrittenNormal : 1; + bool m_bWrittenUserData : 1; +#endif + + friend class CMeshBuilder; +}; + + +inline CVertexBuilder::CVertexBuilder() +{ + m_pVertexBuffer = NULL; + m_nBufferOffset = INVALID_BUFFER_OFFSET; + m_nBufferFirstVertex = 0; + m_nVertexCount = 0; + m_nCurrentVertex = 0; + m_nMaxVertexCount = 0; + m_nTotalVertexCount = 0; + m_CompressionType = VERTEX_COMPRESSION_INVALID; + +#ifdef _DEBUG + m_pCurrPosition = NULL; + m_pCurrNormal = NULL; + m_pCurrColor = NULL; + memset(m_pCurrTexCoord, 0, sizeof(m_pCurrTexCoord)); + m_bModify = false; +#endif +} + +inline CVertexBuilder::CVertexBuilder(IVertexBuffer* pVertexBuffer, VertexFormat_t fmt) +{ + m_pVertexBuffer = pVertexBuffer; + m_nBufferOffset = INVALID_BUFFER_OFFSET; + m_nBufferFirstVertex = 0; + m_nVertexCount = 0; + m_nCurrentVertex = 0; + m_nMaxVertexCount = 0; + m_nTotalVertexCount = 0; + m_CompressionType = VERTEX_COMPRESSION_INVALID; + + if (m_pVertexBuffer->IsDynamic()) + { + m_pVertexBuffer->BeginCastBuffer(fmt); + } + else + { + Assert(m_pVertexBuffer->GetVertexFormat() == fmt); + } + +#ifdef _DEBUG + m_pCurrPosition = NULL; + m_pCurrNormal = NULL; + m_pCurrColor = NULL; + memset(m_pCurrTexCoord, 0, sizeof(m_pCurrTexCoord)); + m_bModify = false; +#endif +} + +inline CVertexBuilder::~CVertexBuilder() +{ + if (m_pVertexBuffer && m_pVertexBuffer->IsDynamic()) + { + m_pVertexBuffer->EndCastBuffer(); + } +} + +inline bool CVertexBuilder::Lock(int nMaxVertexCount, bool bAppend) +{ + Assert(m_pVertexBuffer); + m_bModify = false; + m_nMaxVertexCount = nMaxVertexCount; + bool bFirstLock = (m_nBufferOffset == INVALID_BUFFER_OFFSET); + if (bFirstLock) + { + bAppend = false; + } + if (!bAppend) + { + m_nTotalVertexCount = 0; + } + + if (!m_pVertexBuffer->Lock(m_nMaxVertexCount, bAppend, *this)) + { + m_nMaxVertexCount = 0; + return false; + } + + Reset(); + + if (bFirstLock) + { + m_nBufferOffset = m_nOffset; + m_nBufferFirstVertex = m_nFirstVertex; + } + + return true; +} + +inline void CVertexBuilder::Unlock() +{ + Assert(!m_bModify && m_pVertexBuffer); + +#ifdef _DEBUG + m_pVertexBuffer->ValidateData(m_nVertexCount, *this); +#endif + + m_pVertexBuffer->Unlock(m_nVertexCount, *this); + m_nTotalVertexCount += m_nVertexCount; + + m_nMaxVertexCount = 0; + +#ifdef _DEBUG + m_pCurrPosition = NULL; + m_pCurrNormal = NULL; + m_pCurrColor = NULL; + memset(m_pCurrTexCoord, 0, sizeof(m_pCurrTexCoord)); + memset(static_cast(this), 0, sizeof(VertexDesc_t)); +#endif +} + +inline void CVertexBuilder::SpewData() +{ + m_pVertexBuffer->Spew(m_nVertexCount, *this); +} + + +inline void CVertexBuilder::Bind(IMatRenderContext* pContext, int nStreamID, VertexFormat_t usage) +{ + if (m_pVertexBuffer && (m_nBufferOffset != INVALID_BUFFER_OFFSET)) + { + pContext->BindVertexBuffer(nStreamID, m_pVertexBuffer, m_nBufferOffset, + m_nFirstVertex, m_nTotalVertexCount, usage ? usage : m_pVertexBuffer->GetVertexFormat()); + } + else + { + pContext->BindVertexBuffer(nStreamID, NULL, 0, 0, 0, 0); + } +} + + +inline int CVertexBuilder::Offset() const +{ + return m_nBufferOffset; +} + +inline int CVertexBuilder::GetFirstVertex() const +{ + return m_nBufferFirstVertex; +} + +inline void CVertexBuilder::SetCompressionType(VertexCompressionType_t compressionType) +{ + m_CompressionType = compressionType; +} + +inline void CVertexBuilder::ValidateCompressionType() +{ +#ifdef _DEBUG + VertexCompressionType_t vbCompressionType = CompressionType(m_pVertexBuffer->GetVertexFormat()); + if (vbCompressionType != VERTEX_COMPRESSION_NONE) + { + Assert(m_CompressionType == vbCompressionType); + if (m_CompressionType != vbCompressionType) + { + Warning("ERROR: CVertexBuilder::SetCompressionType() must be called to specify the same vertex compression type (%s) as the vertex buffer being modified." + "Junk vertices will be rendered, or there will be a crash in CVertexBuilder!\n", + vbCompressionType == VERTEX_COMPRESSION_ON ? "VERTEX_COMPRESSION_ON" : "VERTEX_COMPRESSION_NONE"); + } + Assert(!m_pVertexBuffer->IsDynamic()); + } +#endif +} + +inline void CVertexBuilder::Begin(IVertexBuffer* pVertexBuffer, int nVertexCount) +{ + Assert(pVertexBuffer && (!m_pVertexBuffer)); + + m_pVertexBuffer = pVertexBuffer; + m_bModify = false; + + m_nMaxVertexCount = nVertexCount; + m_nVertexCount = 0; + + ValidateCompressionType(); + + m_pVertexBuffer->Lock(m_nMaxVertexCount, false, *this); + + Reset(); +} + + +inline void CVertexBuilder::End(bool bSpewData) +{ + Assert(!m_bModify); + + if (bSpewData) + { + m_pVertexBuffer->Spew(m_nVertexCount, *this); + } + +#ifdef _DEBUG + m_pVertexBuffer->ValidateData(m_nVertexCount, *this); +#endif + + m_pVertexBuffer->Unlock(m_nVertexCount, *this); + + m_pVertexBuffer = 0; + m_nMaxVertexCount = 0; + + m_CompressionType = VERTEX_COMPRESSION_INVALID; + +#ifdef _DEBUG + m_pCurrPosition = NULL; + m_pCurrNormal = NULL; + m_pCurrColor = NULL; + memset(m_pCurrTexCoord, 0, sizeof(m_pCurrTexCoord)); + memset(static_cast(this), 0, sizeof(VertexDesc_t)); +#endif +} + + +inline void CVertexBuilder::AttachBegin(IMesh* pMesh, int nMaxVertexCount, const MeshDesc_t& desc) +{ + m_pVertexBuffer = pMesh; + memcpy(static_cast(this), static_cast(&desc), sizeof(VertexDesc_t)); + m_nMaxVertexCount = nMaxVertexCount; + m_NumBoneWeights = m_NumBoneWeights == 0 ? 0 : 2; + m_nVertexCount = 0; + m_bModify = false; + + ValidateCompressionType(); + + if (m_nBufferOffset == INVALID_BUFFER_OFFSET) + { + m_nTotalVertexCount = 0; + m_nBufferOffset = static_cast(&desc)->m_nOffset; + m_nBufferFirstVertex = desc.m_nFirstVertex; + } +} + +inline void CVertexBuilder::AttachEnd() +{ + Assert(!m_bModify); + + m_nMaxVertexCount = 0; + m_pVertexBuffer = NULL; + + m_CompressionType = VERTEX_COMPRESSION_INVALID; + +#ifdef _DEBUG + m_pCurrPosition = NULL; + m_pCurrNormal = NULL; + m_pCurrColor = NULL; + memset(m_pCurrTexCoord, 0, sizeof(m_pCurrTexCoord)); + memset(static_cast(this), 0, sizeof(VertexDesc_t)); +#endif +} + +inline void CVertexBuilder::AttachBeginModify(IMesh* pMesh, int nFirstVertex, int nVertexCount, const MeshDesc_t& desc) +{ + Assert(pMesh && (!m_pVertexBuffer)); + + m_pVertexBuffer = pMesh; + memcpy(static_cast(this), static_cast(&desc), sizeof(VertexDesc_t)); + m_nMaxVertexCount = m_nVertexCount = nVertexCount; + m_NumBoneWeights = m_NumBoneWeights == 0 ? 0 : 2; + m_bModify = true; + + ValidateCompressionType(); +} + +inline void CVertexBuilder::AttachEndModify() +{ + Assert(m_pVertexBuffer); + Assert(m_bModify); + + m_pVertexBuffer = 0; + m_nMaxVertexCount = 0; + + m_CompressionType = VERTEX_COMPRESSION_INVALID; + +#ifdef _DEBUG + m_pCurrPosition = NULL; + m_pCurrNormal = NULL; + m_pCurrColor = NULL; + memset(m_pCurrTexCoord, 0, sizeof(m_pCurrTexCoord)); + memset(static_cast(this), 0, sizeof(VertexDesc_t)); +#endif +} + + +inline unsigned char* FindMinAddress(void* pAddress1, void* pAddress2, int nAddress2Size) +{ + if (nAddress2Size == 0) + return (unsigned char*)pAddress1; + if (!pAddress1) + return (unsigned char*)pAddress2; + return (pAddress1 < pAddress2) ? (unsigned char*)pAddress1 : (unsigned char*)pAddress2; +} + +inline void CVertexBuilder::Reset() +{ + m_nCurrentVertex = 0; + + m_pCurrPosition = m_pPosition; + m_pCurrNormal = m_pNormal; + for (size_t i = 0; i < NELEMS(m_pCurrTexCoord); i++) + { + m_pCurrTexCoord[i] = m_pTexCoord[i]; + } + m_pCurrColor = m_pColor; + +#if ( defined( _DEBUG ) && ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 ) ) + m_bWrittenNormal = false; + m_bWrittenUserData = false; +#endif + +#ifdef DEBUG_WRITE_COMBINE + m_nLastWrittenField = MB_FIELD_NONE; + m_pLastWrittenAddress = NULL; + m_pLastWrittenAddress = FindMinAddress(m_pLastWrittenAddress, m_pPosition, m_VertexSize_Position); + m_pLastWrittenAddress = FindMinAddress(m_pLastWrittenAddress, m_pBoneWeight, m_VertexSize_BoneWeight); + m_pLastWrittenAddress = FindMinAddress(m_pLastWrittenAddress, m_pBoneMatrixIndex, m_VertexSize_BoneMatrixIndex); + m_pLastWrittenAddress = FindMinAddress(m_pLastWrittenAddress, m_pNormal, m_VertexSize_Normal); + m_pLastWrittenAddress = FindMinAddress(m_pLastWrittenAddress, m_pColor, m_VertexSize_Color); + m_pLastWrittenAddress = FindMinAddress(m_pLastWrittenAddress, m_pSpecular, m_VertexSize_Specular); + for (int i = 0; i < VERTEX_MAX_TEXTURE_COORDINATES; ++i) + { + m_pLastWrittenAddress = FindMinAddress(m_pLastWrittenAddress, m_pTexCoord[i], m_VertexSize_TexCoord[i]); + } + m_pLastWrittenAddress = FindMinAddress(m_pLastWrittenAddress, m_pTangentS, m_VertexSize_TangentS); + m_pLastWrittenAddress = FindMinAddress(m_pLastWrittenAddress, m_pTangentT, m_VertexSize_TangentT); + m_pLastWrittenAddress = FindMinAddress(m_pLastWrittenAddress, m_pUserData, m_VertexSize_UserData); +#endif +} + + +inline int CVertexBuilder::VertexCount() const +{ + return m_nVertexCount; +} + + +inline int CVertexBuilder::TotalVertexCount() const +{ + return m_nTotalVertexCount; +} + + +inline void* CVertexBuilder::BaseVertexData() +{ + Assert(m_pPosition); + return m_pPosition; +} + + +inline void CVertexBuilder::SelectVertex(int nIndex) +{ + Assert((nIndex >= 0) && (nIndex < m_nMaxVertexCount)); + m_nCurrentVertex = nIndex; + + m_pCurrPosition = OffsetFloatPointer(m_pPosition, m_nCurrentVertex, m_VertexSize_Position); + m_pCurrNormal = OffsetFloatPointer(m_pNormal, m_nCurrentVertex, m_VertexSize_Normal); + + COMPILE_TIME_ASSERT(VERTEX_MAX_TEXTURE_COORDINATES == 8); + m_pCurrTexCoord[0] = OffsetFloatPointer(m_pTexCoord[0], m_nCurrentVertex, m_VertexSize_TexCoord[0]); + m_pCurrTexCoord[1] = OffsetFloatPointer(m_pTexCoord[1], m_nCurrentVertex, m_VertexSize_TexCoord[1]); + m_pCurrTexCoord[2] = OffsetFloatPointer(m_pTexCoord[2], m_nCurrentVertex, m_VertexSize_TexCoord[2]); + m_pCurrTexCoord[3] = OffsetFloatPointer(m_pTexCoord[3], m_nCurrentVertex, m_VertexSize_TexCoord[3]); + m_pCurrTexCoord[4] = OffsetFloatPointer(m_pTexCoord[4], m_nCurrentVertex, m_VertexSize_TexCoord[4]); + m_pCurrTexCoord[5] = OffsetFloatPointer(m_pTexCoord[5], m_nCurrentVertex, m_VertexSize_TexCoord[5]); + m_pCurrTexCoord[6] = OffsetFloatPointer(m_pTexCoord[6], m_nCurrentVertex, m_VertexSize_TexCoord[6]); + m_pCurrTexCoord[7] = OffsetFloatPointer(m_pTexCoord[7], m_nCurrentVertex, m_VertexSize_TexCoord[7]); + m_pCurrColor = m_pColor + m_nCurrentVertex * m_VertexSize_Color; + +#if ( defined( _DEBUG ) && ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 ) ) + m_bWrittenNormal = false; + m_bWrittenUserData = false; +#endif +} + + +template FORCEINLINE void CVertexBuilder::AdvanceVertexF() +{ + if (++m_nCurrentVertex > m_nVertexCount) + { + m_nVertexCount = m_nCurrentVertex; + } + + if (nFlags & VTX_HAVEPOS) + IncrementFloatPointer(m_pCurrPosition, m_VertexSize_Position); + if (nFlags & VTX_HAVENORMAL) + IncrementFloatPointer(m_pCurrNormal, m_VertexSize_Normal); + if (nFlags & VTX_HAVECOLOR) + m_pCurrColor += m_VertexSize_Color; + + COMPILE_TIME_ASSERT(VERTEX_MAX_TEXTURE_COORDINATES == 8); + if (nNumTexCoords > 0) + IncrementFloatPointer(m_pCurrTexCoord[0], m_VertexSize_TexCoord[0]); + if (nNumTexCoords > 1) + IncrementFloatPointer(m_pCurrTexCoord[1], m_VertexSize_TexCoord[1]); + if (nNumTexCoords > 2) + IncrementFloatPointer(m_pCurrTexCoord[2], m_VertexSize_TexCoord[2]); + if (nNumTexCoords > 3) + IncrementFloatPointer(m_pCurrTexCoord[3], m_VertexSize_TexCoord[3]); + if (nNumTexCoords > 4) + IncrementFloatPointer(m_pCurrTexCoord[4], m_VertexSize_TexCoord[4]); + if (nNumTexCoords > 5) + IncrementFloatPointer(m_pCurrTexCoord[5], m_VertexSize_TexCoord[5]); + if (nNumTexCoords > 6) + IncrementFloatPointer(m_pCurrTexCoord[6], m_VertexSize_TexCoord[6]); + if (nNumTexCoords > 7) + IncrementFloatPointer(m_pCurrTexCoord[7], m_VertexSize_TexCoord[7]); + +#if ( defined( _DEBUG ) && ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 ) ) + m_bWrittenNormal = false; + m_bWrittenUserData = false; +#endif +} + +inline void CVertexBuilder::AdvanceVertex() +{ + AdvanceVertexF(); +} + + +inline void CVertexBuilder::AdvanceVertices(int nVerts) +{ + m_nCurrentVertex += nVerts; + if (m_nCurrentVertex > m_nVertexCount) + { + m_nVertexCount = m_nCurrentVertex; + } + + IncrementFloatPointer(m_pCurrPosition, m_VertexSize_Position * nVerts); + IncrementFloatPointer(m_pCurrNormal, m_VertexSize_Normal * nVerts); + + COMPILE_TIME_ASSERT(VERTEX_MAX_TEXTURE_COORDINATES == 8); + IncrementFloatPointer(m_pCurrTexCoord[0], m_VertexSize_TexCoord[0] * nVerts); + IncrementFloatPointer(m_pCurrTexCoord[1], m_VertexSize_TexCoord[1] * nVerts); + IncrementFloatPointer(m_pCurrTexCoord[2], m_VertexSize_TexCoord[2] * nVerts); + IncrementFloatPointer(m_pCurrTexCoord[3], m_VertexSize_TexCoord[3] * nVerts); + IncrementFloatPointer(m_pCurrTexCoord[4], m_VertexSize_TexCoord[4] * nVerts); + IncrementFloatPointer(m_pCurrTexCoord[5], m_VertexSize_TexCoord[5] * nVerts); + IncrementFloatPointer(m_pCurrTexCoord[6], m_VertexSize_TexCoord[6] * nVerts); + IncrementFloatPointer(m_pCurrTexCoord[7], m_VertexSize_TexCoord[7] * nVerts); + m_pCurrColor += m_VertexSize_Color * nVerts; + +#if ( defined( _DEBUG ) && ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 ) ) + m_bWrittenNormal = false; + m_bWrittenUserData = false; +#endif +} + + +inline void CVertexBuilder::FastAdvanceNVertices(int n) +{ + m_nCurrentVertex += n; + m_nVertexCount = m_nCurrentVertex; +} + +inline void CVertexBuilder::FastVertex(const ModelVertexDX8_t& vertex) +{ + Assert(m_CompressionType == VERTEX_COMPRESSION_NONE); + Assert(m_nCurrentVertex < m_nMaxVertexCount); + +#if defined( _WIN32 ) && !defined( _X360 ) + const void* pRead = &vertex; + void* pCurrPos = m_pCurrPosition; + __asm + { + mov esi, pRead + mov edi, pCurrPos + + movq mm0, [esi + 0] + movq mm1, [esi + 8] + movq mm2, [esi + 16] + movq mm3, [esi + 24] + movq mm4, [esi + 32] + movq mm5, [esi + 40] + + movntq[edi + 0], mm0 + movntq[edi + 8], mm1 + movntq[edi + 16], mm2 + movntq[edi + 24], mm3 + movntq[edi + 32], mm4 + movntq[edi + 40], mm5 + + emms + } +#elif defined(GNUC) + const void* pRead = &vertex; + void* pCurrPos = m_pCurrPosition; + __asm__ __volatile__( + "movq (%0), %%mm0\n" + "movq 8(%0), %%mm1\n" + "movq 16(%0), %%mm2\n" + "movq 24(%0), %%mm3\n" + "movq 32(%0), %%mm4\n" + "movq 40(%0), %%mm5\n" + "movq 48(%0), %%mm6\n" + "movq 56(%0), %%mm7\n" + "movntq %%mm0, (%1)\n" + "movntq %%mm1, 8(%1)\n" + "movntq %%mm2, 16(%1)\n" + "movntq %%mm3, 24(%1)\n" + "movntq %%mm4, 32(%1)\n" + "movntq %%mm5, 40(%1)\n" + "movntq %%mm6, 48(%1)\n" + "movntq %%mm7, 56(%1)\n" + "emms\n" + :: "r" (pRead), "r" (pCurrPos) : "memory"); +#else + Error("Implement CMeshBuilder::FastVertex(dx8)"); +#endif + + IncrementFloatPointer(m_pCurrPosition, m_VertexSize_Position); +#if ( defined( _DEBUG ) && ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 ) ) + m_bWrittenNormal = false; + m_bWrittenUserData = false; +#endif +} + +inline void CVertexBuilder::FastVertexSSE(const ModelVertexDX8_t& vertex) +{ + Assert(m_CompressionType == VERTEX_COMPRESSION_NONE); + Assert(m_nCurrentVertex < m_nMaxVertexCount); + +#if defined( _WIN32 ) && !defined( _X360 ) + const void* pRead = &vertex; + void* pCurrPos = m_pCurrPosition; + __asm + { + mov esi, pRead + mov edi, pCurrPos + + movaps xmm0, [esi + 0] + movaps xmm1, [esi + 16] + movaps xmm2, [esi + 32] + + movntps[edi + 0], xmm0 + movntps[edi + 16], xmm1 + movntps[edi + 32], xmm2 + } +#elif defined(GNUC) + const void* pRead = &vertex; + void* pCurrPos = m_pCurrPosition; + __asm__ __volatile__( + "movaps (%0), %%xmm0\n" + "movaps 16(%0), %%xmm1\n" + "movaps 32(%0), %%xmm2\n" + "movaps 48(%0), %%xmm3\n" + "movntps %%xmm0, (%1)\n" + "movntps %%xmm1, 16(%1)\n" + "movntps %%xmm2, 32(%1)\n" + "movntps %%xmm3, 48(%1)\n" + :: "r" (pRead), "r" (pCurrPos) : "memory"); +#else + Error("Implement CMeshBuilder::FastVertexSSE((dx8)"); +#endif + + IncrementFloatPointer(m_pCurrPosition, m_VertexSize_Position); +#if ( defined( _DEBUG ) && ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 ) ) + m_bWrittenNormal = false; + m_bWrittenUserData = false; +#endif +} + + +inline void CVertexBuilder::FastQuadVertexSSE(const QuadTessVertex_t& vertex) +{ + Assert(m_CompressionType == VERTEX_COMPRESSION_NONE); + Assert(m_nCurrentVertex < m_nMaxVertexCount); + +#if defined( _WIN32 ) && !defined( _X360 ) + const void* pRead = &vertex; + void* pCurrPos = m_pCurrPosition; + __asm + { + mov esi, pRead + mov edi, pCurrPos + + movaps xmm0, [esi + 0] + movaps xmm1, [esi + 16] + movaps xmm2, [esi + 32] + + movntps[edi + 0], xmm0 + movntps[edi + 16], xmm1 + movntps[edi + 32], xmm2 + } +#endif + + IncrementFloatPointer(m_pCurrPosition, m_VertexSize_Position); +#if ( defined( _DEBUG ) && ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 ) ) + m_bWrittenNormal = false; + m_bWrittenUserData = false; +#endif +} + + + +inline int CVertexBuilder::GetCurrentVertex() const +{ + return m_nCurrentVertex; +} + + +#if defined( _X360 ) +inline void CVertexBuilder::VertexDX8ToX360(const ModelVertexDX8_t& vertex) +{ + Assert(m_CompressionType == VERTEX_COMPRESSION_NONE); + Assert(m_nCurrentVertex < m_nMaxVertexCount); + + unsigned char* pDst = (unsigned char*)m_pCurrPosition; + + Assert(m_VertexSize_Position > 0); + Assert(GetVertexElementSize(VERTEX_ELEMENT_POSITION, VERTEX_COMPRESSION_NONE) == sizeof(vertex.m_vecPosition)); + memcpy(pDst, vertex.m_vecPosition.Base(), sizeof(vertex.m_vecPosition)); + pDst += sizeof(vertex.m_vecPosition); + + if (m_VertexSize_Normal) + { + Assert(GetVertexElementSize(VERTEX_ELEMENT_NORMAL, VERTEX_COMPRESSION_NONE) == sizeof(vertex.m_vecNormal)); + memcpy(pDst, vertex.m_vecNormal.Base(), sizeof(vertex.m_vecNormal)); + pDst += sizeof(vertex.m_vecNormal); + } + + if (m_VertexSize_TexCoord[0]) + { + Assert(GetVertexElementSize(VERTEX_ELEMENT_TEXCOORD2D_0, VERTEX_COMPRESSION_NONE) == sizeof(vertex.m_vecTexCoord)); + memcpy(pDst, vertex.m_vecTexCoord.Base(), sizeof(vertex.m_vecTexCoord)); + pDst += sizeof(vertex.m_vecTexCoord); + } + + if (m_VertexSize_UserData) + { + Assert(GetVertexElementSize(VERTEX_ELEMENT_USERDATA4, VERTEX_COMPRESSION_NONE) == sizeof(vertex.m_vecUserData)); + memcpy(pDst, vertex.m_vecUserData.Base(), sizeof(vertex.m_vecUserData)); + pDst += sizeof(vertex.m_vecUserData); + } + + Assert(pDst - (unsigned char*)m_pCurrPosition == m_VertexSize_Position); + + IncrementFloatPointer(m_pCurrPosition, m_VertexSize_Position); + +#if ( defined( _DEBUG ) && ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 ) ) + m_bWrittenNormal = false; + m_bWrittenUserData = false; +#endif +} +#endif + + +inline const float* CVertexBuilder::Position() const +{ + Assert(m_CompressionType == VERTEX_COMPRESSION_NONE); + Assert(m_nCurrentVertex < m_nMaxVertexCount); + return m_pCurrPosition; +} + +inline const float* CVertexBuilder::Normal() const +{ + Assert(m_CompressionType == VERTEX_COMPRESSION_NONE); + Assert(m_nCurrentVertex < m_nMaxVertexCount); + return m_pCurrNormal; +} + +inline unsigned int CVertexBuilder::Color() const +{ + Assert(m_CompressionType == VERTEX_COMPRESSION_NONE); + Assert(m_nCurrentVertex < m_nMaxVertexCount); + unsigned int color; + if (IsPC() || !IsX360()) + { + color = (m_pCurrColor[3] << 24) | (m_pCurrColor[0] << 16) | (m_pCurrColor[1] << 8) | (m_pCurrColor[2]); + } + else + { + color = (m_pCurrColor[1] << 24) | (m_pCurrColor[2] << 16) | (m_pCurrColor[3] << 8) | (m_pCurrColor[0]); + } + return color; +} + +inline unsigned char* CVertexBuilder::Specular() const +{ + Assert(m_CompressionType == VERTEX_COMPRESSION_NONE); + Assert(m_nCurrentVertex < m_nMaxVertexCount); + return m_pSpecular + m_nCurrentVertex * m_VertexSize_Specular; +} + +inline const float* CVertexBuilder::TexCoord(int stage) const +{ + Assert(m_CompressionType == VERTEX_COMPRESSION_NONE); + Assert(m_nCurrentVertex < m_nMaxVertexCount); + return m_pCurrTexCoord[stage]; +} + +inline const float* CVertexBuilder::TangentS() const +{ + Assert(m_CompressionType == VERTEX_COMPRESSION_NONE); + Assert(m_nCurrentVertex < m_nMaxVertexCount); + return OffsetFloatPointer(m_pTangentS, m_nCurrentVertex, m_VertexSize_TangentS); +} + +inline const float* CVertexBuilder::TangentT() const +{ + Assert(m_CompressionType == VERTEX_COMPRESSION_NONE); + Assert(m_nCurrentVertex < m_nMaxVertexCount); + return OffsetFloatPointer(m_pTangentT, m_nCurrentVertex, m_VertexSize_TangentT); +} + +inline float CVertexBuilder::Wrinkle() const +{ + Assert(m_CompressionType == VERTEX_COMPRESSION_NONE); + Assert(m_nCurrentVertex < m_nMaxVertexCount); + return *OffsetFloatPointer(m_pWrinkle, m_nCurrentVertex, m_VertexSize_Wrinkle); +} + +inline const float* CVertexBuilder::BoneWeight() const +{ + Assert(m_CompressionType == VERTEX_COMPRESSION_NONE); + Assert(m_nCurrentVertex < m_nMaxVertexCount); + return OffsetFloatPointer(m_pBoneWeight, m_nCurrentVertex, m_VertexSize_BoneWeight); +} + +inline int CVertexBuilder::NumBoneWeights() const +{ + return m_NumBoneWeights; +} + +#ifndef NEW_SKINNING +inline unsigned char* CVertexBuilder::BoneMatrix() const +{ + Assert(m_CompressionType == VERTEX_COMPRESSION_NONE); + Assert(m_nCurrentVertex < m_nMaxVertexCount); + return m_pBoneMatrixIndex + m_nCurrentVertex * m_VertexSize_BoneMatrixIndex; +} +#else +inline float* CVertexBuilder::BoneMatrix() const +{ + Assert(m_CompressionType == VERTEX_COMPRESSION_NONE); + Assert(m_nCurrentVertex < m_nMaxVertexCount); + return m_pBoneMatrixIndex + m_nCurrentVertex * m_VertexSize_BoneMatrixIndex; +} +#endif + + +inline void CVertexBuilder::Position3f(float x, float y, float z) +{ + Assert(m_pPosition && m_pCurrPosition); + Assert(IsFinite(x) && IsFinite(y) && IsFinite(z)); + float* pDst = m_pCurrPosition; + *pDst++ = x; + *pDst++ = y; + *pDst = z; +} + +inline void CVertexBuilder::Position3fv(const float* v) +{ + Assert(v); + Assert(m_pPosition && m_pCurrPosition); + + float* pDst = m_pCurrPosition; + *pDst++ = *v++; + *pDst++ = *v++; + *pDst = *v; +} + + +inline void CVertexBuilder::Normal3f(float nx, float ny, float nz) +{ + Assert(m_CompressionType == VERTEX_COMPRESSION_NONE); + Assert(m_pNormal); + Assert(IsFinite(nx) && IsFinite(ny) && IsFinite(nz)); + Assert(nx >= -1.05f && nx <= 1.05f); + Assert(ny >= -1.05f && ny <= 1.05f); + Assert(nz >= -1.05f && nz <= 1.05f); + + float* pDst = m_pCurrNormal; + *pDst++ = nx; + *pDst++ = ny; + *pDst = nz; +} + +inline void CVertexBuilder::Normal3fv(const float* n) +{ + Assert(m_CompressionType == VERTEX_COMPRESSION_NONE); + Assert(n); + Assert(m_pNormal && m_pCurrNormal); + Assert(IsFinite(n[0]) && IsFinite(n[1]) && IsFinite(n[2])); + Assert(n[0] >= -1.05f && n[0] <= 1.05f); + Assert(n[1] >= -1.05f && n[1] <= 1.05f); + Assert(n[2] >= -1.05f && n[2] <= 1.05f); + + float* pDst = m_pCurrNormal; + *pDst++ = *n++; + *pDst++ = *n++; + *pDst = *n; +} + +inline void CVertexBuilder::NormalDelta3f(float nx, float ny, float nz) +{ + Assert(m_CompressionType == VERTEX_COMPRESSION_NONE); + Assert(m_pNormal); + Assert(IsFinite(nx) && IsFinite(ny) && IsFinite(nz)); + + float* pDst = m_pCurrNormal; + *pDst++ = nx; + *pDst++ = ny; + *pDst = nz; +} + +inline void CVertexBuilder::NormalDelta3fv(const float* n) +{ + Assert(m_CompressionType == VERTEX_COMPRESSION_NONE); + Assert(n); + Assert(m_pNormal && m_pCurrNormal); + Assert(IsFinite(n[0]) && IsFinite(n[1]) && IsFinite(n[2])); + + float* pDst = m_pCurrNormal; + *pDst++ = *n++; + *pDst++ = *n++; + *pDst = *n; +} + +template inline void CVertexBuilder::CompressedNormal3f(float nx, float ny, float nz) +{ + Assert(T == m_CompressionType); + Assert(m_pNormal && m_pCurrNormal); + Assert(IsFinite(nx) && IsFinite(ny) && IsFinite(nz)); + Assert(nx >= -1.05f && nx <= 1.05f); + Assert(ny >= -1.05f && ny <= 1.05f); + Assert(nz >= -1.05f && nz <= 1.05f); + if (T == VERTEX_COMPRESSION_ON) + { +#if ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_SEPARATETANGENTS_SHORT2 ) + PackNormal_SHORT2(nx, ny, nz, (unsigned int*)m_pCurrNormal); + +#else +#ifdef _DEBUG + Assert(m_bWrittenUserData == false); + m_bWrittenNormal = true; +#endif + PackNormal_UBYTE4(nx, ny, nz, (unsigned int*)m_pCurrNormal); +#endif + } + else + { + float* pDst = m_pCurrNormal; + *pDst++ = nx; + *pDst++ = ny; + *pDst = nz; + } +} + +template inline void CVertexBuilder::CompressedNormal3fv(const float* n) +{ + Assert(n); + CompressedNormal3f(n[0], n[1], n[2]); +} + + +inline void CVertexBuilder::Color3f(float r, float g, float b) +{ + Assert(m_pColor && m_pCurrColor); + Assert(IsFinite(r) && IsFinite(g) && IsFinite(b)); + Assert((r >= 0.0) && (g >= 0.0) && (b >= 0.0)); + Assert((r <= 1.0) && (g <= 1.0) && (b <= 1.0)); + + int col = (FastFToC(b)) | (FastFToC(g) << 8) | (FastFToC(r) << 16) | 0xFF000000; + *(int*)m_pCurrColor = col; +} + +inline void CVertexBuilder::Color3fv(const float* rgb) +{ + Assert(rgb); + Assert(m_pColor && m_pCurrColor); + Assert(IsFinite(rgb[0]) && IsFinite(rgb[1]) && IsFinite(rgb[2])); + Assert((rgb[0] >= 0.0) && (rgb[1] >= 0.0) && (rgb[2] >= 0.0)); + Assert((rgb[0] <= 1.0) && (rgb[1] <= 1.0) && (rgb[2] <= 1.0)); + + int col = (FastFToC(rgb[2])) | (FastFToC(rgb[1]) << 8) | (FastFToC(rgb[0]) << 16) | 0xFF000000; + *(int*)m_pCurrColor = col; +} + +inline void CVertexBuilder::Color4f(float r, float g, float b, float a) +{ + Assert(m_pColor && m_pCurrColor); + Assert(IsFinite(r) && IsFinite(g) && IsFinite(b) && IsFinite(a)); + Assert((r >= 0.0) && (g >= 0.0) && (b >= 0.0) && (a >= 0.0)); + Assert((r <= 1.0) && (g <= 1.0) && (b <= 1.0) && (a <= 1.0)); + + int col = (FastFToC(b)) | (FastFToC(g) << 8) | (FastFToC(r) << 16) | (FastFToC(a) << 24); + *(int*)m_pCurrColor = col; +} + +inline void CVertexBuilder::Color4fv(const float* rgba) +{ + Assert(rgba); + Assert(m_pColor && m_pCurrColor); + Assert(IsFinite(rgba[0]) && IsFinite(rgba[1]) && IsFinite(rgba[2]) && IsFinite(rgba[3])); + Assert((rgba[0] >= 0.0) && (rgba[1] >= 0.0) && (rgba[2] >= 0.0) && (rgba[3] >= 0.0)); + Assert((rgba[0] <= 1.0) && (rgba[1] <= 1.0) && (rgba[2] <= 1.0) && (rgba[3] <= 1.0)); + + int col = (FastFToC(rgba[2])) | (FastFToC(rgba[1]) << 8) | (FastFToC(rgba[0]) << 16) | (FastFToC(rgba[3]) << 24); + *(int*)m_pCurrColor = col; +} + + +inline void CVertexBuilder::Color3ub(unsigned char r, unsigned char g, unsigned char b) +{ + Assert(m_pColor && m_pCurrColor); +#ifdef OPENGL_SWAP_COLORS + int col = r | (g << 8) | (b << 16) | 0xFF000000; +#else + int col = b | (g << 8) | (r << 16) | 0xFF000000; +#endif + + * (int*)m_pCurrColor = col; +} + +inline void CVertexBuilder::Color3ubv(unsigned char const* rgb) +{ + Assert(rgb); + Assert(m_pColor && m_pCurrColor); +#ifdef OPENGL_SWAP_COLORS + int col = rgb[0] | (rgb[1] << 8) | (rgb[2] << 16) | 0xFF000000; +#else + int col = rgb[2] | (rgb[1] << 8) | (rgb[0] << 16) | 0xFF000000; +#endif + + * (int*)m_pCurrColor = col; +} + +inline void CVertexBuilder::Color4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a) +{ + Assert(m_pColor && m_pCurrColor); +#ifdef OPENGL_SWAP_COLORS + int col = r | (g << 8) | (b << 16) | (a << 24); +#else + int col = b | (g << 8) | (r << 16) | (a << 24); +#endif + + * (int*)m_pCurrColor = col; +} + +inline void CVertexBuilder::Color4ubv(unsigned char const* rgba) +{ + Assert(rgba); + Assert(m_pColor && m_pCurrColor); +#ifdef OPENGL_SWAP_COLORS + int col = rgba[0] | (rgba[1] << 8) | (rgba[2] << 16) | (rgba[3] << 24); +#else + int col = rgba[2] | (rgba[1] << 8) | (rgba[0] << 16) | (rgba[3] << 24); +#endif + * (int*)m_pCurrColor = col; +} + +FORCEINLINE void CVertexBuilder::Color4Packed(int packedColor) +{ + *(int*)m_pCurrColor = packedColor; +} + +FORCEINLINE int CVertexBuilder::PackColor4(unsigned char r, unsigned char g, unsigned char b, unsigned char a) +{ + return b | (g << 8) | (r << 16) | (a << 24); +} + + +inline void CVertexBuilder::Specular3f(float r, float g, float b) +{ + Assert(m_pSpecular); + Assert(IsFinite(r) && IsFinite(g) && IsFinite(b)); + Assert((r >= 0.0) && (g >= 0.0) && (b >= 0.0)); + Assert((r <= 1.0) && (g <= 1.0) && (b <= 1.0)); + + unsigned char* pSpecular = &m_pSpecular[m_nCurrentVertex * m_VertexSize_Specular]; + int col = (FastFToC(b)) | (FastFToC(g) << 8) | (FastFToC(r) << 16) | 0xFF000000; + *(int*)pSpecular = col; +} + +inline void CVertexBuilder::Specular3fv(const float* rgb) +{ + Assert(rgb); + Assert(m_pSpecular); + Assert(IsFinite(rgb[0]) && IsFinite(rgb[1]) && IsFinite(rgb[2])); + Assert((rgb[0] >= 0.0) && (rgb[1] >= 0.0) && (rgb[2] >= 0.0)); + Assert((rgb[0] <= 1.0) && (rgb[1] <= 1.0) && (rgb[2] <= 1.0)); + + unsigned char* pSpecular = &m_pSpecular[m_nCurrentVertex * m_VertexSize_Specular]; + int col = (FastFToC(rgb[2])) | (FastFToC(rgb[1]) << 8) | (FastFToC(rgb[0]) << 16) | 0xFF000000; + *(int*)pSpecular = col; +} + +inline void CVertexBuilder::Specular4f(float r, float g, float b, float a) +{ + Assert(m_pSpecular); + Assert(IsFinite(r) && IsFinite(g) && IsFinite(b) && IsFinite(a)); + Assert((r >= 0.0) && (g >= 0.0) && (b >= 0.0) && (a >= 0.0)); + Assert((r <= 1.0) && (g <= 1.0) && (b <= 1.0) && (a <= 1.0f)); + + unsigned char* pSpecular = &m_pSpecular[m_nCurrentVertex * m_VertexSize_Specular]; + int col = (FastFToC(b)) | (FastFToC(g) << 8) | (FastFToC(r) << 16) | (FastFToC(a) << 24); + *(int*)pSpecular = col; +} + +inline void CVertexBuilder::Specular4fv(const float* rgb) +{ + Assert(rgb); + Assert(m_pSpecular); + Assert(IsFinite(rgb[0]) && IsFinite(rgb[1]) && IsFinite(rgb[2]) && IsFinite(rgb[3])); + Assert((rgb[0] >= 0.0) && (rgb[1] >= 0.0) && (rgb[2] >= 0.0) && (rgb[3] >= 0.0)); + Assert((rgb[0] <= 1.0) && (rgb[1] <= 1.0) && (rgb[2] <= 1.0) && (rgb[3] <= 1.0)); + + unsigned char* pSpecular = &m_pSpecular[m_nCurrentVertex * m_VertexSize_Specular]; + int col = (FastFToC(rgb[2])) | (FastFToC(rgb[1]) << 8) | (FastFToC(rgb[0]) << 16) | (FastFToC(rgb[3]) << 24); + *(int*)pSpecular = col; +} + +inline void CVertexBuilder::Specular3ub(unsigned char r, unsigned char g, unsigned char b) +{ + Assert(m_pSpecular); + unsigned char* pSpecular = &m_pSpecular[m_nCurrentVertex * m_VertexSize_Specular]; + +#ifdef OPENGL_SWAP_COLORS + int col = r | (g << 8) | (b << 16) | 0xFF000000; +#else + int col = b | (g << 8) | (r << 16) | 0xFF000000; +#endif + + * (int*)pSpecular = col; +} + +inline void CVertexBuilder::Specular3ubv(unsigned char const* c) +{ + Assert(m_pSpecular); + unsigned char* pSpecular = &m_pSpecular[m_nCurrentVertex * m_VertexSize_Specular]; + +#ifdef OPENGL_SWAP_COLORS + int col = c[0] | (c[1] << 8) | (c[2] << 16) | 0xFF000000; +#else + int col = c[2] | (c[1] << 8) | (c[0] << 16) | 0xFF000000; +#endif + + * (int*)pSpecular = col; +} + +inline void CVertexBuilder::Specular4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a) +{ + Assert(m_pSpecular); + unsigned char* pSpecular = &m_pSpecular[m_nCurrentVertex * m_VertexSize_Specular]; + +#ifdef OPENGL_SWAP_COLORS + int col = r | (g << 8) | (b << 16) | (a << 24); +#else + int col = b | (g << 8) | (r << 16) | (a << 24); +#endif + + * (int*)pSpecular = col; +} + +inline void CVertexBuilder::Specular4ubv(unsigned char const* c) +{ + Assert(m_pSpecular); + unsigned char* pSpecular = &m_pSpecular[m_nCurrentVertex * m_VertexSize_Specular]; + +#ifdef OPENGL_SWAP_COLORS + int col = c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24); +#else + int col = c[2] | (c[1] << 8) | (c[0] << 16) | (c[3] << 24); +#endif + + * (int*)pSpecular = col; +} + + +inline void CVertexBuilder::TexCoord1f(int nStage, float s) +{ + Assert(m_pTexCoord[nStage] && m_pCurrTexCoord[nStage]); + Assert(IsFinite(s)); + + float* pDst = m_pCurrTexCoord[nStage]; + *pDst = s; +} + +inline void CVertexBuilder::TexCoord2f(int nStage, float s, float t) +{ + Assert(m_pTexCoord[nStage] && m_pCurrTexCoord[nStage]); + Assert(IsFinite(s) && IsFinite(t)); + + float* pDst = m_pCurrTexCoord[nStage]; + *pDst++ = s; + *pDst = t; +} + +inline void CVertexBuilder::TexCoord2fv(int nStage, const float* st) +{ + Assert(st); + Assert(m_pTexCoord[nStage] && m_pCurrTexCoord[nStage]); + Assert(IsFinite(st[0]) && IsFinite(st[1])); + + float* pDst = m_pCurrTexCoord[nStage]; + *pDst++ = *st++; + *pDst = *st; +} + +inline void CVertexBuilder::TexCoord3f(int stage, float s, float t, float u) +{ + Assert(m_pTexCoord[stage] && m_pCurrTexCoord[stage]); + Assert(IsFinite(s) && IsFinite(t) && IsFinite(u)); + float* pDst = m_pCurrTexCoord[stage]; + *pDst++ = s; + *pDst++ = t; + *pDst = u; +} + +inline void CVertexBuilder::TexCoord3fv(int stage, const float* stu) +{ + Assert(stu); + Assert(m_pTexCoord[stage] && m_pCurrTexCoord[stage]); + Assert(IsFinite(stu[0]) && IsFinite(stu[1]) && IsFinite(stu[2])); + + float* pDst = m_pCurrTexCoord[stage]; + *pDst++ = *stu++; + *pDst++ = *stu++; + *pDst = *stu; +} + +inline void CVertexBuilder::TexCoord4f(int stage, float s, float t, float u, float v) +{ + Assert(m_pTexCoord[stage] && m_pCurrTexCoord[stage]); + Assert(IsFinite(s) && IsFinite(t) && IsFinite(u)); + float* pDst = m_pCurrTexCoord[stage]; + *pDst++ = s; + *pDst++ = t; + *pDst++ = u; + *pDst = v; +} + +inline void CVertexBuilder::TexCoord4fv(int stage, const float* stuv) +{ + Assert(stuv); + Assert(m_pTexCoord[stage] && m_pCurrTexCoord[stage]); + Assert(IsFinite(stuv[0]) && IsFinite(stuv[1]) && IsFinite(stuv[2])); + + float* pDst = m_pCurrTexCoord[stage]; + *pDst++ = *stuv++; + *pDst++ = *stuv++; + *pDst++ = *stuv++; + *pDst = *stuv; +} + + +inline void CVertexBuilder::TexCoordSubRect2f(int stage, float s, float t, float offsetS, float offsetT, float scaleS, float scaleT) +{ + Assert(m_pTexCoord[stage] && m_pCurrTexCoord[stage]); + Assert(IsFinite(s) && IsFinite(t)); + + float* pDst = m_pCurrTexCoord[stage]; + *pDst++ = (s * scaleS) + offsetS; + *pDst = (t * scaleT) + offsetT; +} + +inline void CVertexBuilder::TexCoordSubRect2fv(int stage, const float* st, const float* offset, const float* scale) +{ + Assert(st); + Assert(m_pTexCoord[stage] && m_pCurrTexCoord[stage]); + Assert(IsFinite(st[0]) && IsFinite(st[1])); + + float* pDst = m_pCurrTexCoord[stage]; + *pDst++ = (*st++ * *scale++) + *offset++; + *pDst = (*st * *scale) + *offset; +} + + +inline void CVertexBuilder::TangentS3f(float sx, float sy, float sz) +{ + Assert(m_pTangentS); + Assert(IsFinite(sx) && IsFinite(sy) && IsFinite(sz)); + + float* pTangentS = OffsetFloatPointer(m_pTangentS, m_nCurrentVertex, m_VertexSize_TangentS); + *pTangentS++ = sx; + *pTangentS++ = sy; + *pTangentS = sz; +} + +inline void CVertexBuilder::TangentS3fv(const float* s) +{ + Assert(s); + Assert(m_pTangentS); + Assert(IsFinite(s[0]) && IsFinite(s[1]) && IsFinite(s[2])); + + float* pTangentS = OffsetFloatPointer(m_pTangentS, m_nCurrentVertex, m_VertexSize_TangentS); + *pTangentS++ = *s++; + *pTangentS++ = *s++; + *pTangentS = *s; +} + +inline void CVertexBuilder::TangentT3f(float tx, float ty, float tz) +{ + Assert(m_pTangentT); + Assert(IsFinite(tx) && IsFinite(ty) && IsFinite(tz)); + + float* pTangentT = OffsetFloatPointer(m_pTangentT, m_nCurrentVertex, m_VertexSize_TangentT); + *pTangentT++ = tx; + *pTangentT++ = ty; + *pTangentT = tz; +} + +inline void CVertexBuilder::TangentT3fv(const float* t) +{ + Assert(t); + Assert(m_pTangentT); + Assert(IsFinite(t[0]) && IsFinite(t[1]) && IsFinite(t[2])); + + float* pTangentT = OffsetFloatPointer(m_pTangentT, m_nCurrentVertex, m_VertexSize_TangentT); + *pTangentT++ = *t++; + *pTangentT++ = *t++; + *pTangentT = *t; +} + + +inline void CVertexBuilder::Wrinkle1f(float flWrinkle) +{ + Assert(m_pWrinkle); + Assert(IsFinite(flWrinkle)); + + float* pWrinkle = OffsetFloatPointer(m_pWrinkle, m_nCurrentVertex, m_VertexSize_Wrinkle); + *pWrinkle = flWrinkle; +} + + +inline void CVertexBuilder::BoneWeight(int idx, float weight) +{ + Assert(m_pBoneWeight); + Assert(IsFinite(weight)); + Assert(idx >= 0); + Assert(m_NumBoneWeights == 2); + + if (idx < m_NumBoneWeights) + { + float* pBoneWeight = OffsetFloatPointer(m_pBoneWeight, m_nCurrentVertex, m_VertexSize_BoneWeight); + pBoneWeight[idx] = weight; + } +} + +inline void CVertexBuilder::BoneWeights2(float weight1, float weight2) +{ + Assert(m_pBoneWeight); + Assert(IsFinite(weight1) && IsFinite(weight2)); + AssertOnce(m_NumBoneWeights == 2); + + float* pBoneWeight = OffsetFloatPointer(m_pBoneWeight, m_nCurrentVertex, m_VertexSize_BoneWeight); + pBoneWeight[0] = weight1; + pBoneWeight[1] = weight2; +} + +inline void CVertexBuilder::BoneMatrix(int idx, int matrixIdx) +{ + Assert(m_pBoneMatrixIndex); + Assert(idx >= 0); + Assert(idx < 4); + + if (matrixIdx == BONE_MATRIX_INDEX_INVALID) + { + matrixIdx = 0; + } + Assert((matrixIdx >= 0) && (matrixIdx < 53)); + +#ifndef NEW_SKINNING + unsigned char* pBoneMatrix = &m_pBoneMatrixIndex[m_nCurrentVertex * m_VertexSize_BoneMatrixIndex]; + if (IsX360()) + { + idx = 3 - idx; + } + pBoneMatrix[idx] = (unsigned char)matrixIdx; +#else + float* pBoneMatrix = &m_pBoneMatrixIndex[m_nCurrentVertex * m_VertexSize_BoneMatrixIndex]; + pBoneMatrix[idx] = matrixIdx; +#endif +} + +inline void CVertexBuilder::BoneMatrices4(int matrixIdx0, int matrixIdx1, int matrixIdx2, int matrixIdx3) +{ + Assert(m_pBoneMatrixIndex); + + Assert(matrixIdx0 != BONE_MATRIX_INDEX_INVALID); + Assert(matrixIdx1 != BONE_MATRIX_INDEX_INVALID); + Assert(matrixIdx2 != BONE_MATRIX_INDEX_INVALID); + Assert(matrixIdx3 != BONE_MATRIX_INDEX_INVALID); + +#ifndef NEW_SKINNING + int nVal; + if (IsX360()) + { + nVal = matrixIdx3 | (matrixIdx2 << 8) | (matrixIdx1 << 16) | (matrixIdx0 << 24); + } + else + { + nVal = matrixIdx0 | (matrixIdx1 << 8) | (matrixIdx2 << 16) | (matrixIdx3 << 24); + } + int* pBoneMatrix = (int*)(&m_pBoneMatrixIndex[m_nCurrentVertex * m_VertexSize_BoneMatrixIndex]); + *pBoneMatrix = nVal; +#else + float* pBoneMatrix = &m_pBoneMatrixIndex[m_nCurrentVertex * m_VertexSize_BoneMatrixIndex]; + pBoneMatrix[0] = matrixIdx0; + pBoneMatrix[1] = matrixIdx1; + pBoneMatrix[2] = matrixIdx2; + pBoneMatrix[3] = matrixIdx3; +#endif +} + +template inline void CVertexBuilder::CompressedBoneWeight3fv(const float* pWeights) +{ + Assert(T == m_CompressionType); + Assert(m_pBoneWeight); + Assert(pWeights); + + float* pDestWeights = OffsetFloatPointer(m_pBoneWeight, m_nCurrentVertex, m_VertexSize_BoneWeight); + + if (T == VERTEX_COMPRESSION_ON) + { + Assert(m_NumBoneWeights <= 2); + + const int WEIGHT0_SHIFT = IsX360() ? 16 : 0; + const int WEIGHT1_SHIFT = IsX360() ? 0 : 16; + unsigned int* weights = (unsigned int*)pDestWeights; + + Assert(IsFinite(pWeights[0]) && (pWeights[0] >= 0.0f) && (pWeights[0] <= 1.0f)); + unsigned int weight0 = Float2Int(pWeights[0] * 32768.0f); + *weights = (0x0000FFFF & (weight0 - 1)) << WEIGHT0_SHIFT; + +#ifdef DEBUG + if (m_NumBoneWeights == 1) + { + Assert(IsFinite(pWeights[1]) && (pWeights[1] >= 0.0f) && (pWeights[1] <= 1.0f)); + unsigned int weight1 = Float2Int(pWeights[1] * 32768.0f); + Assert((weight0 + weight1) <= 32768); + } +#endif + + if (m_NumBoneWeights > 1) + { + Assert(m_NumBoneWeights == 2); + Assert(IsFinite(pWeights[1]) && (pWeights[1] >= 0.0f) && (pWeights[1] <= 1.0f)); + Assert(IsFinite(pWeights[2]) && (pWeights[2] >= 0.0f) && (pWeights[2] <= 1.0f)); + unsigned int weight1 = Float2Int(pWeights[1] * 32768.0f); + unsigned int weight2 = Float2Int(pWeights[2] * 32768.0f); + Assert((weight0 + weight1 + weight2) <= 32768); + unsigned int residual = 32768 - (weight0 + weight1 + weight2); + weight1 += residual; + *weights |= (0x0000FFFF & (weight1 - 1)) << WEIGHT1_SHIFT; + } + } + else + { + pDestWeights[0] = pWeights[0]; + pDestWeights[1] = pWeights[1]; + } +} + +inline void CVertexBuilder::UserData(const float* pData) +{ + Assert(m_CompressionType == VERTEX_COMPRESSION_NONE); + Assert(pData); + + int userDataSize = 4; + float* pUserData = OffsetFloatPointer(m_pUserData, m_nCurrentVertex, m_VertexSize_UserData); + memcpy(pUserData, pData, sizeof(float) * userDataSize); +} + +template inline void CVertexBuilder::CompressedUserData(const float* pData) +{ + Assert(T == m_CompressionType); + Assert(pData); + Assert(IsFinite(pData[0]) && IsFinite(pData[1]) && IsFinite(pData[2])); + Assert(pData[0] >= -1.05f && pData[0] <= 1.05f); + Assert(pData[1] >= -1.05f && pData[1] <= 1.05f); + Assert(pData[2] >= -1.05f && pData[2] <= 1.05f); + Assert(pData[3] == +1.0f || pData[3] == -1.0f); + if (T == VERTEX_COMPRESSION_ON) + { + float binormalSign = pData[3]; + +#if ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_SEPARATETANGENTS_SHORT2 ) + float* pUserData = OffsetFloatPointer(m_pUserData, m_nCurrentVertex, m_VertexSize_UserData); + PackNormal_SHORT2(pData, (unsigned int*)pUserData, binormalSign); +#else + unsigned int existingNormalData = *(unsigned int*)m_pCurrNormal; + Assert((existingNormalData & 0xFFFF0000) == 0); +#ifdef _DEBUG + Assert(m_bWrittenNormal == true); + m_bWrittenUserData = true; +#endif + bool bIsTangent = true; + unsigned int tangentData = 0; + PackNormal_UBYTE4(pData, &tangentData, bIsTangent, binormalSign); + *(unsigned int*)m_pCurrNormal = existingNormalData | tangentData; +#endif + } + else + { + int userDataSize = 4; + float* pUserData = OffsetFloatPointer(m_pUserData, m_nCurrentVertex, m_VertexSize_UserData); + memcpy(pUserData, pData, sizeof(float) * userDataSize); + } +} + + +class CIndexBuilder : private IndexDesc_t +{ +public: + CIndexBuilder(); + CIndexBuilder(IIndexBuffer* pIndexBuffer, MaterialIndexFormat_t fmt = MATERIAL_INDEX_FORMAT_UNKNOWN); + ~CIndexBuilder(); + + bool Lock(int nMaxIndexCount, int nIndexOffset, bool bAppend = false); + void Unlock(); + + void SpewData(); + + int GetRoomRemaining() const; + + void Bind(IMatRenderContext* pContext); + + int Offset() const; + + void Begin(IIndexBuffer* pIndexBuffer, int nMaxIndexCount, int nIndexOffset = 0); + void End(bool bSpewData = false); + + void BeginModify(IIndexBuffer* pIndexBuffer, int firstIndex = 0, int numIndices = 0, int nIndexOffset = 0); + void EndModify(bool bSpewData = false); + + int IndexCount() const; + + int TotalIndexCount() const; + + void Reset(); + + void SelectIndex(int nBufferIndex); + + void AdvanceIndex(); + void AdvanceIndices(int numIndices); + + int GetCurrentIndex(); + int GetFirstIndex() const; + + unsigned short const* Index() const; + + void Index(unsigned short nIndex); + + void FastIndex(unsigned short nIndex); + + void FastIndex2(unsigned short nIndex1, unsigned short nIndex2); + + void GenerateIndices(MaterialPrimitiveType_t primitiveType, int numIndices); + + void AttachBegin(IMesh* pMesh, int nMaxIndexCount, const MeshDesc_t& desc); + void AttachEnd(); + void AttachBeginModify(IMesh* pMesh, int firstIndex, int numIndices, const MeshDesc_t& desc); + void AttachEndModify(); + + void FastTriangle(int startVert); + void FastQuad(int startVert); + void FastPolygon(int startVert, int numTriangles); + void FastPolygonList(int startVert, int* pVertexCount, int polygonCount); + void FastIndexList(const unsigned short* pIndexList, int startVert, int indexCount); + +private: + IIndexBuffer* m_pIndexBuffer; + + int m_nMaxIndexCount; + + int m_nIndexCount; + + int m_nIndexOffset; + + mutable int m_nCurrentIndex; + + int m_nTotalIndexCount; + + unsigned int m_nBufferOffset; + unsigned int m_nBufferFirstIndex; + + bool m_bModify; +}; + + +inline CIndexBuilder::CIndexBuilder() : m_pIndexBuffer(0), m_nMaxIndexCount(0), +m_nIndexCount(0), m_nCurrentIndex(0) +{ + m_nTotalIndexCount = 0; + m_nBufferOffset = INVALID_BUFFER_OFFSET; + m_nBufferFirstIndex = 0; +#ifdef _DEBUG + m_bModify = false; +#endif +} + +inline CIndexBuilder::CIndexBuilder(IIndexBuffer* pIndexBuffer, MaterialIndexFormat_t fmt) +{ + m_pIndexBuffer = pIndexBuffer; + m_nBufferOffset = INVALID_BUFFER_OFFSET; + m_nBufferFirstIndex = 0; + m_nIndexCount = 0; + m_nCurrentIndex = 0; + m_nMaxIndexCount = 0; + m_nTotalIndexCount = 0; + if (m_pIndexBuffer->IsDynamic()) + { + m_pIndexBuffer->BeginCastBuffer(fmt); + } + else + { + Assert(m_pIndexBuffer->IndexFormat() == fmt); + } +#ifdef _DEBUG + m_bModify = false; +#endif +} + +inline CIndexBuilder::~CIndexBuilder() +{ + if (m_pIndexBuffer && m_pIndexBuffer->IsDynamic()) + { + m_pIndexBuffer->EndCastBuffer(); + } +} + + +inline bool CIndexBuilder::Lock(int nMaxIndexCount, int nIndexOffset, bool bAppend) +{ + Assert(m_pIndexBuffer); + m_bModify = false; + m_nIndexOffset = nIndexOffset; + m_nMaxIndexCount = nMaxIndexCount; + m_nIndexCount = 0; + bool bFirstLock = (m_nBufferOffset == INVALID_BUFFER_OFFSET); + if (bFirstLock) + { + bAppend = false; + } + if (!bAppend) + { + m_nTotalIndexCount = 0; + } + Reset(); + + if (!m_pIndexBuffer->Lock(m_nMaxIndexCount, bAppend, *this)) + { + m_nMaxIndexCount = 0; + return false; + } + + if (bFirstLock) + { + m_nBufferOffset = m_nOffset; + m_nBufferFirstIndex = m_nFirstIndex; + } + + return true; +} + +inline void CIndexBuilder::Unlock() +{ + Assert(!m_bModify && m_pIndexBuffer); + + m_pIndexBuffer->Unlock(m_nIndexCount, *this); + m_nTotalIndexCount += m_nIndexCount; + + m_nMaxIndexCount = 0; + +#ifdef _DEBUG + memset((IndexDesc_t*)this, 0, sizeof(IndexDesc_t)); +#endif +} + +inline void CIndexBuilder::SpewData() +{ + m_pIndexBuffer->Spew(m_nIndexCount, *this); +} + + +inline void CIndexBuilder::Bind(IMatRenderContext* pContext) +{ + if (m_pIndexBuffer && (m_nBufferOffset != INVALID_BUFFER_OFFSET)) + { + pContext->BindIndexBuffer(m_pIndexBuffer, m_nBufferOffset); + } + else + { + pContext->BindIndexBuffer(NULL, 0); + } +} + + +inline int CIndexBuilder::Offset() const +{ + return m_nBufferOffset; +} + +inline int CIndexBuilder::GetFirstIndex() const +{ + return m_nBufferFirstIndex; +} + + +inline void CIndexBuilder::Begin(IIndexBuffer* pIndexBuffer, int nMaxIndexCount, int nIndexOffset) +{ + Assert(pIndexBuffer && (!m_pIndexBuffer)); + + m_pIndexBuffer = pIndexBuffer; + m_nIndexCount = 0; + m_nMaxIndexCount = nMaxIndexCount; + m_nIndexOffset = nIndexOffset; + + m_bModify = false; + + m_pIndexBuffer->Lock(m_nMaxIndexCount, false, *this); + + Reset(); +} + +inline void CIndexBuilder::End(bool bSpewData) +{ + Assert(!m_bModify); + + if (bSpewData) + { + m_pIndexBuffer->Spew(m_nIndexCount, *this); + } + + m_pIndexBuffer->Unlock(m_nIndexCount, *this); + + m_pIndexBuffer = 0; + m_nMaxIndexCount = 0; + +#ifdef _DEBUG + memset((IndexDesc_t*)this, 0, sizeof(IndexDesc_t)); +#endif +} + + +inline void CIndexBuilder::BeginModify(IIndexBuffer* pIndexBuffer, int nFirstIndex, int nIndexCount, int nIndexOffset) +{ + m_pIndexBuffer = pIndexBuffer; + m_nIndexCount = nIndexCount; + m_nMaxIndexCount = nIndexCount; + m_nIndexOffset = nIndexOffset; + m_bModify = true; + + m_pIndexBuffer->ModifyBegin(false, nFirstIndex, nIndexCount, *this); + + Reset(); +} + +inline void CIndexBuilder::EndModify(bool bSpewData) +{ + Assert(m_pIndexBuffer); + Assert(m_bModify); + + if (bSpewData) + { + m_pIndexBuffer->Spew(m_nIndexCount, *this); + } + + m_pIndexBuffer->ModifyEnd(*this); + + m_pIndexBuffer = 0; + m_nMaxIndexCount = 0; + +#ifdef _DEBUG + memset((IndexDesc_t*)this, 0, sizeof(IndexDesc_t)); +#endif +} + + +inline void CIndexBuilder::AttachBegin(IMesh* pMesh, int nMaxIndexCount, const MeshDesc_t& desc) +{ + m_pIndexBuffer = pMesh; + m_nIndexCount = 0; + m_nMaxIndexCount = nMaxIndexCount; + + m_bModify = false; + + m_nIndexOffset = desc.m_nFirstVertex; + m_pIndices = desc.m_pIndices; + m_nIndexSize = desc.m_nIndexSize; + + Reset(); +} + +inline void CIndexBuilder::AttachEnd() +{ + Assert(m_pIndexBuffer); + Assert(!m_bModify); + + m_pIndexBuffer = 0; + m_nMaxIndexCount = 0; + +#ifdef _DEBUG + memset((IndexDesc_t*)this, 0, sizeof(IndexDesc_t)); +#endif +} + +inline void CIndexBuilder::AttachBeginModify(IMesh* pMesh, int nFirstIndex, int nIndexCount, const MeshDesc_t& desc) +{ + m_pIndexBuffer = pMesh; + m_nIndexCount = nIndexCount; + m_nMaxIndexCount = nIndexCount; + m_bModify = true; + + m_nIndexOffset = desc.m_nFirstVertex; + m_pIndices = desc.m_pIndices; + m_nIndexSize = desc.m_nIndexSize; + + Reset(); +} + +inline void CIndexBuilder::AttachEndModify() +{ + Assert(m_pIndexBuffer); + Assert(m_bModify); + + m_pIndexBuffer = 0; + m_nMaxIndexCount = 0; + +#ifdef _DEBUG + memset((IndexDesc_t*)this, 0, sizeof(IndexDesc_t)); +#endif +} + + +inline void CIndexBuilder::Reset() +{ + m_nCurrentIndex = 0; +} + + +inline int CIndexBuilder::IndexCount() const +{ + return m_nIndexCount; +} + + +inline int CIndexBuilder::TotalIndexCount() const +{ + return m_nTotalIndexCount; +} + + +inline void CIndexBuilder::AdvanceIndex() +{ + m_nCurrentIndex += m_nIndexSize; + if (m_nCurrentIndex > m_nIndexCount) + { + m_nIndexCount = m_nCurrentIndex; + } +} + +inline void CIndexBuilder::AdvanceIndices(int nIndices) +{ + m_nCurrentIndex += nIndices * m_nIndexSize; + if (m_nCurrentIndex > m_nIndexCount) + { + m_nIndexCount = m_nCurrentIndex; + } +} + + +inline int CIndexBuilder::GetCurrentIndex() +{ + return m_nCurrentIndex; +} + +inline unsigned short const* CIndexBuilder::Index() const +{ + Assert(m_nCurrentIndex < m_nMaxIndexCount); + return &m_pIndices[m_nCurrentIndex]; +} + +inline void CIndexBuilder::SelectIndex(int nIndex) +{ + Assert((nIndex >= 0) && (nIndex < m_nIndexCount)); + m_nCurrentIndex = nIndex * m_nIndexSize; +} + + +inline void CIndexBuilder::Index(unsigned short nIndex) +{ + Assert(m_pIndices); + Assert(m_nCurrentIndex < m_nMaxIndexCount); + m_pIndices[m_nCurrentIndex] = (unsigned short)(m_nIndexOffset + nIndex); +} + +inline void CIndexBuilder::FastIndex(unsigned short nIndex) +{ + Assert(m_pIndices); + Assert(m_nCurrentIndex < m_nMaxIndexCount); + m_pIndices[m_nCurrentIndex] = (unsigned short)(m_nIndexOffset + nIndex); + m_nCurrentIndex += m_nIndexSize; + m_nIndexCount = m_nCurrentIndex; +} + +FORCEINLINE void CIndexBuilder::FastTriangle(int startVert) +{ + startVert += m_nIndexOffset; + unsigned short* pIndices = &m_pIndices[m_nCurrentIndex]; + *pIndices++ = startVert++; + *pIndices++ = startVert++; + *pIndices++ = startVert; + AdvanceIndices(3); +} + +FORCEINLINE void CIndexBuilder::FastQuad(int startVert) +{ + startVert += m_nIndexOffset; + unsigned short* pIndices = &m_pIndices[m_nCurrentIndex]; + *pIndices++ = startVert++; + *pIndices++ = startVert++; + *pIndices++ = startVert; + + *pIndices++ = startVert - 2; + *pIndices++ = startVert++; + *pIndices++ = startVert; + AdvanceIndices(6); +} + +inline void CIndexBuilder::FastPolygon(int startVert, int triangleCount) +{ + unsigned short* pIndex = &m_pIndices[m_nCurrentIndex]; + startVert += m_nIndexOffset; + if (!IsX360()) + { + Assert(m_nIndexSize == 0 || m_nIndexSize == 1); + triangleCount *= m_nIndexSize; + } + for (int v = 0; v < triangleCount; ++v) + { + *pIndex++ = startVert; + *pIndex++ = startVert + v + 1; + *pIndex++ = startVert + v + 2; + } + AdvanceIndices(triangleCount * 3); +} + +inline void CIndexBuilder::FastPolygonList(int startVert, int* pVertexCount, int polygonCount) +{ + unsigned short* pIndex = &m_pIndices[m_nCurrentIndex]; + startVert += m_nIndexOffset; + int indexOut = 0; + + if (!IsX360()) + { + Assert(m_nIndexSize == 0 || m_nIndexSize == 1); + polygonCount *= m_nIndexSize; + } + + for (int i = 0; i < polygonCount; i++) + { + int vertexCount = pVertexCount[i]; + int triangleCount = vertexCount - 2; + for (int v = 0; v < triangleCount; ++v) + { + *pIndex++ = startVert; + *pIndex++ = startVert + v + 1; + *pIndex++ = startVert + v + 2; + } + startVert += vertexCount; + indexOut += triangleCount * 3; + } + AdvanceIndices(indexOut); +} + +inline void CIndexBuilder::FastIndexList(const unsigned short* pIndexList, int startVert, int indexCount) +{ + unsigned short* pIndexOut = &m_pIndices[m_nCurrentIndex]; + startVert += m_nIndexOffset; + if (!IsX360()) + { + Assert(m_nIndexSize == 0 || m_nIndexSize == 1); + indexCount *= m_nIndexSize; + } + for (int i = 0; i < indexCount; ++i) + { + pIndexOut[i] = startVert + pIndexList[i]; + } + AdvanceIndices(indexCount); +} + + +inline void CIndexBuilder::FastIndex2(unsigned short nIndex1, unsigned short nIndex2) +{ + Assert(m_pIndices); + Assert(m_nCurrentIndex < m_nMaxIndexCount - 1); +#ifndef _X360 + unsigned int nIndices = ((unsigned int)nIndex1 + m_nIndexOffset) | (((unsigned int)nIndex2 + m_nIndexOffset) << 16); +#else + unsigned int nIndices = ((unsigned int)nIndex2 + m_nIndexOffset) | (((unsigned int)nIndex1 + m_nIndexOffset) << 16); +#endif + + * (int*)(&m_pIndices[m_nCurrentIndex]) = nIndices; + m_nCurrentIndex += m_nIndexSize + m_nIndexSize; + m_nIndexCount = m_nCurrentIndex; +} + + +inline void CIndexBuilder::GenerateIndices(MaterialPrimitiveType_t primitiveType, int nIndexCount) +{ + if (m_nIndexSize == 0) + return; + + int nMaxIndices = m_nMaxIndexCount - m_nCurrentIndex; + nIndexCount = MIN(nMaxIndices, nIndexCount); + if (nIndexCount == 0) + return; + + unsigned short* pIndices = &m_pIndices[m_nCurrentIndex]; + + switch (primitiveType) + { + case MATERIAL_INSTANCED_QUADS: + Assert(0); + break; + case MATERIAL_QUADS: + GenerateQuadIndexBuffer(pIndices, nIndexCount, m_nIndexOffset); + break; + case MATERIAL_POLYGON: + GeneratePolygonIndexBuffer(pIndices, nIndexCount, m_nIndexOffset); + break; + case MATERIAL_LINE_STRIP: + GenerateLineStripIndexBuffer(pIndices, nIndexCount, m_nIndexOffset); + break; + case MATERIAL_LINE_LOOP: + GenerateLineLoopIndexBuffer(pIndices, nIndexCount, m_nIndexOffset); + break; + case MATERIAL_POINTS: + Assert(0); + break; + case MATERIAL_SUBD_QUADS_EXTRA: + case MATERIAL_SUBD_QUADS_REG: + default: + GenerateSequentialIndexBuffer(pIndices, nIndexCount, m_nIndexOffset); + break; + } + + AdvanceIndices(nIndexCount); +} + + +class CMeshBuilder : public MeshDesc_t +{ +public: + CMeshBuilder(); + ~CMeshBuilder() { Assert(!m_pMesh); } + + operator CIndexBuilder& () { return m_IndexBuilder; } + + void SetCompressionType(VertexCompressionType_t compressionType); + + void Begin(IMesh* pMesh, MaterialPrimitiveType_t type, int numPrimitives); + + void Begin(IMesh* pMesh, MaterialPrimitiveType_t type, int nVertexCount, int nIndexCount, int* nFirstVertex); + void Begin(IMesh* pMesh, MaterialPrimitiveType_t type, int nVertexCount, int nIndexCount); + + void Begin(IVertexBuffer* pVertexBuffer, MaterialPrimitiveType_t type, int numPrimitives); + void Begin(IVertexBuffer* pVertexBuffer, IIndexBuffer* pIndexBuffer, MaterialPrimitiveType_t type, int nVertexCount, int nIndexCount, int* nFirstVertex); + void Begin(IVertexBuffer* pVertexBuffer, IIndexBuffer* pIndexBuffer, MaterialPrimitiveType_t type, int nVertexCount, int nIndexCount); + + void End(bool bSpewData = false, bool bDraw = false); + + void BeginModify(IMesh* pMesh, int nFirstVertex = 0, int nVertexCount = -1, int nFirstIndex = 0, int nIndexCount = 0); + void EndModify(bool bSpewData = false); + + void DrawQuad(IMesh* pMesh, const float* v1, const float* v2, + const float* v3, const float* v4, unsigned char const* pColor, bool wireframe = false); + + int VertexCount() const; + int IndexCount() const; + + void Reset(); + + int VertexSize() { return m_ActualVertexSize; } + + int TextureCoordinateSize(int nTexCoordNumber) { return m_VertexSize_TexCoord[nTexCoordNumber]; } + + void* BaseVertexData(); + + void SelectVertex(int idx); + void SelectIndex(int idx); + + void SelectVertexFromIndex(int idx); + + void AdvanceVertex(); + template void AdvanceVertexF(); + void AdvanceVertices(int nVerts); + void AdvanceIndex(); + void AdvanceIndices(int nIndices); + + int GetCurrentVertex(); + int GetCurrentIndex(); + + const float* Position() const; + + const float* Normal() const; + + unsigned int Color() const; + + unsigned char* Specular() const; + + const float* TexCoord(int stage) const; + + const float* TangentS() const; + const float* TangentT() const; + + const float* BoneWeight() const; + float Wrinkle() const; + + int NumBoneWeights() const; +#ifndef NEW_SKINNING + unsigned char* BoneMatrix() const; +#else + float* BoneMatrix() const; +#endif + unsigned short const* Index() const; + + void Position3f(float x, float y, float z); + void Position3fv(const float* v); + + void Normal3f(float nx, float ny, float nz); + void Normal3fv(const float* n); + void NormalDelta3fv(const float* n); + void NormalDelta3f(float nx, float ny, float nz); + + template void CompressedNormal3f(float nx, float ny, float nz); + template void CompressedNormal3fv(const float* n); + + void Color3f(float r, float g, float b); + void Color3fv(const float* rgb); + void Color4f(float r, float g, float b, float a); + void Color4fv(const float* rgba); + + void Color3ub(unsigned char r, unsigned char g, unsigned char b); + void Color3ubv(unsigned char const* rgb); + void Color4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a); + void Color4ubv(unsigned char const* rgba); + void Color4Packed(int packedColor); + int PackColor4(unsigned char r, unsigned char g, unsigned char b, unsigned char a); + + void Specular3f(float r, float g, float b); + void Specular3fv(const float* rgb); + void Specular4f(float r, float g, float b, float a); + void Specular4fv(const float* rgba); + + void Specular3ub(unsigned char r, unsigned char g, unsigned char b); + void Specular3ubv(unsigned char const* c); + void Specular4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a); + void Specular4ubv(unsigned char const* c); + + void TexCoord1f(int stage, float s); + void TexCoord2f(int stage, float s, float t); + void TexCoord2fv(int stage, const float* st); + void TexCoord3f(int stage, float s, float t, float u); + void TexCoord3fv(int stage, const float* stu); + void TexCoord4f(int stage, float s, float t, float u, float w); + void TexCoord4fv(int stage, const float* stuv); + + void TexCoordSubRect2f(int stage, float s, float t, float offsetS, float offsetT, float scaleS, float scaleT); + void TexCoordSubRect2fv(int stage, const float* st, const float* offset, const float* scale); + + void TangentS3f(float sx, float sy, float sz); + void TangentS3fv(const float* s); + + void TangentT3f(float tx, float ty, float tz); + void TangentT3fv(const float* t); + + void Wrinkle1f(float flWrinkle); + + void BoneWeight(int idx, float weight); + void BoneWeights2(float weight1, float weight2); + + template void CompressedBoneWeight3fv(const float* pWeights); + + void BoneMatrix(int idx, int matrixIndex); + void BoneMatrices4(int matrixIdx0, int matrixIdx1, int matrixIdx2, int matrixIdx3); + + void UserData(const float* pData); + template void CompressedUserData(const float* pData); + + void Index(unsigned short index); + + void FastIndex2(unsigned short nIndex1, unsigned short nIndex2); + + void FastIndex(unsigned short index); + void FastQuad(int index); + + void FastVertex(const ModelVertexDX8_t& vertex); + void FastVertexSSE(const ModelVertexDX8_t& vertex); + void FastQuadVertexSSE(const QuadTessVertex_t& vertex); + + void FastAdvanceNVertices(int n); + +#if defined( _X360 ) + void VertexDX8ToX360(const ModelVertexDX8_t& vertex); +#endif + + FORCEINLINE void* GetVertexDataPtr(int nWhatSizeIThinkItIs) + { + if (m_VertexBuilder.m_VertexSize_Position != nWhatSizeIThinkItIs) + return NULL; + return m_VertexBuilder.m_pCurrPosition; + } + + +private: + void ComputeNumVertsAndIndices(int* pMaxVertices, int* pMaxIndices, + MaterialPrimitiveType_t type, int nPrimitiveCount); + int IndicesFromVertices(MaterialPrimitiveType_t type, int nVertexCount); + + IMesh* m_pMesh; + + MaterialPrimitiveType_t m_Type; + + bool m_bGenerateIndices; + + CIndexBuilder m_IndexBuilder; + CVertexBuilder m_VertexBuilder; +}; + + +inline void CMeshBuilder::Begin(IVertexBuffer* pVertexBuffer, MaterialPrimitiveType_t type, int numPrimitives) +{ + Assert(0); +} + +inline void CMeshBuilder::Begin(IVertexBuffer* pVertexBuffer, IIndexBuffer* pIndexBuffer, MaterialPrimitiveType_t type, int nVertexCount, int nIndexCount, int* nFirstVertex) +{ + Assert(0); +} + +inline void CMeshBuilder::Begin(IVertexBuffer* pVertexBuffer, IIndexBuffer* pIndexBuffer, MaterialPrimitiveType_t type, int nVertexCount, int nIndexCount) +{ + Assert(0); +} + + +inline CMeshBuilder::CMeshBuilder() : m_pMesh(0), m_bGenerateIndices(false) +{ +} + + +inline void CMeshBuilder::ComputeNumVertsAndIndices(int* pMaxVertices, int* pMaxIndices, + MaterialPrimitiveType_t type, int nPrimitiveCount) +{ + switch (type) + { + case MATERIAL_POINTS: + *pMaxVertices = *pMaxIndices = nPrimitiveCount; + break; + + case MATERIAL_LINES: + *pMaxVertices = *pMaxIndices = nPrimitiveCount * 2; + break; + + case MATERIAL_LINE_STRIP: + *pMaxVertices = nPrimitiveCount + 1; + *pMaxIndices = nPrimitiveCount * 2; + break; + + case MATERIAL_LINE_LOOP: + *pMaxVertices = nPrimitiveCount; + *pMaxIndices = nPrimitiveCount * 2; + break; + + case MATERIAL_TRIANGLES: + *pMaxVertices = *pMaxIndices = nPrimitiveCount * 3; + break; + + case MATERIAL_TRIANGLE_STRIP: + *pMaxVertices = *pMaxIndices = nPrimitiveCount + 2; + break; + + case MATERIAL_QUADS: + *pMaxVertices = nPrimitiveCount * 4; + *pMaxIndices = nPrimitiveCount * 6; + break; + + case MATERIAL_INSTANCED_QUADS: + *pMaxVertices = nPrimitiveCount; + *pMaxIndices = 0; + break; + + case MATERIAL_POLYGON: + *pMaxVertices = nPrimitiveCount; + *pMaxIndices = (nPrimitiveCount - 2) * 3; + break; + + default: + Assert(0); + } + + Assert(*pMaxVertices <= 32768); + Assert(*pMaxIndices <= 32768); +} + + +inline int CMeshBuilder::IndicesFromVertices(MaterialPrimitiveType_t type, int nVertexCount) +{ + switch (type) + { + case MATERIAL_QUADS: + Assert((nVertexCount & 0x3) == 0); + return (nVertexCount * 6) / 4; + + case MATERIAL_INSTANCED_QUADS: + return 0; + + case MATERIAL_POLYGON: + Assert(nVertexCount >= 3); + return (nVertexCount - 2) * 3; + + case MATERIAL_LINE_STRIP: + Assert(nVertexCount >= 2); + return (nVertexCount - 1) * 2; + + case MATERIAL_LINE_LOOP: + Assert(nVertexCount >= 3); + return nVertexCount * 2; + + default: + return nVertexCount; + } +} + +inline void CMeshBuilder::SetCompressionType(VertexCompressionType_t vertexCompressionType) +{ + m_CompressionType = vertexCompressionType; + m_VertexBuilder.SetCompressionType(vertexCompressionType); +} + +inline void CMeshBuilder::Begin(IMesh* pMesh, MaterialPrimitiveType_t type, int numPrimitives) +{ + Assert(pMesh && (!m_pMesh)); + Assert(type != MATERIAL_HETEROGENOUS); + + m_pMesh = pMesh; + m_bGenerateIndices = true; + m_Type = type; + + int nMaxVertexCount, nMaxIndexCount; + ComputeNumVertsAndIndices(&nMaxVertexCount, &nMaxIndexCount, type, numPrimitives); + + switch (type) + { + case MATERIAL_INSTANCED_QUADS: + m_pMesh->SetPrimitiveType(MATERIAL_INSTANCED_QUADS); + break; + + case MATERIAL_QUADS: + case MATERIAL_POLYGON: + m_pMesh->SetPrimitiveType(MATERIAL_TRIANGLES); + break; + + case MATERIAL_LINE_STRIP: + case MATERIAL_LINE_LOOP: + m_pMesh->SetPrimitiveType(MATERIAL_LINES); + break; + + default: + m_pMesh->SetPrimitiveType(type); + } + + m_pMesh->LockMesh(nMaxVertexCount, nMaxIndexCount, *this, NULL); + + m_IndexBuilder.AttachBegin(pMesh, nMaxIndexCount, *this); + m_VertexBuilder.AttachBegin(pMesh, nMaxVertexCount, *this); + + Reset(); +} + +inline void CMeshBuilder::Begin(IMesh* pMesh, MaterialPrimitiveType_t type, int nVertexCount, int nIndexCount, int* nFirstVertex) +{ + Begin(pMesh, type, nVertexCount, nIndexCount); + + *nFirstVertex = m_VertexBuilder.m_nFirstVertex * m_VertexBuilder.VertexSize(); +} + +inline void CMeshBuilder::Begin(IMesh* pMesh, MaterialPrimitiveType_t type, int nVertexCount, int nIndexCount) +{ + Assert(pMesh && (!m_pMesh)); + + Assert((type != MATERIAL_QUADS) && (type != MATERIAL_INSTANCED_QUADS) && (type != MATERIAL_POLYGON) && + (type != MATERIAL_LINE_STRIP) && (type != MATERIAL_LINE_LOOP)); + + Assert(type != MATERIAL_POINTS); + + m_pMesh = pMesh; + m_bGenerateIndices = false; + m_Type = type; + + m_pMesh->SetPrimitiveType(type); + + m_pMesh->LockMesh(nVertexCount, nIndexCount, *this, NULL); + + m_IndexBuilder.AttachBegin(pMesh, nIndexCount, *this); + m_VertexBuilder.AttachBegin(pMesh, nVertexCount, *this); + + Reset(); +} + + +inline void CMeshBuilder::End(bool bSpewData, bool bDraw) +{ + if (m_bGenerateIndices) + { + int nIndexCount = IndicesFromVertices(m_Type, m_VertexBuilder.VertexCount()); + m_IndexBuilder.GenerateIndices(m_Type, nIndexCount); + } + + if (bSpewData) + { + m_pMesh->Spew(m_VertexBuilder.VertexCount(), m_IndexBuilder.IndexCount(), *this); + } + +#ifdef _DEBUG + m_pMesh->ValidateData(m_VertexBuilder.VertexCount(), m_IndexBuilder.IndexCount(), *this); +#endif + + m_pMesh->UnlockMesh(m_VertexBuilder.VertexCount(), m_IndexBuilder.IndexCount(), *this); + + m_IndexBuilder.AttachEnd(); + m_VertexBuilder.AttachEnd(); + + if (bDraw) + { + m_pMesh->Draw(); + } + + m_pMesh = 0; + +#ifdef _DEBUG + memset((MeshDesc_t*)this, 0, sizeof(MeshDesc_t)); +#endif +} + + +inline void CMeshBuilder::BeginModify(IMesh* pMesh, int nFirstVertex, int nVertexCount, int nFirstIndex, int nIndexCount) +{ + Assert(pMesh && (!m_pMesh)); + + if (nVertexCount < 0) + { + nVertexCount = pMesh->VertexCount(); + } + + m_pMesh = pMesh; + m_bGenerateIndices = false; + + pMesh->ModifyBeginEx(false, nFirstVertex, nVertexCount, nFirstIndex, nIndexCount, *this); + + m_IndexBuilder.AttachBeginModify(pMesh, nFirstIndex, nIndexCount, *this); + m_VertexBuilder.AttachBeginModify(pMesh, nFirstVertex, nVertexCount, *this); + + Reset(); +} + +inline void CMeshBuilder::EndModify(bool bSpewData) +{ + Assert(m_pMesh); + + if (bSpewData) + { + m_pMesh->Spew(m_VertexBuilder.VertexCount(), m_IndexBuilder.IndexCount(), *this); + } +#ifdef _DEBUG + m_pMesh->ValidateData(m_VertexBuilder.VertexCount(), m_IndexBuilder.IndexCount(), *this); +#endif + + m_pMesh->ModifyEnd(*this); + m_pMesh = 0; + + m_IndexBuilder.AttachEndModify(); + m_VertexBuilder.AttachEndModify(); + +#ifdef _DEBUG + memset((MeshDesc_t*)this, 0, sizeof(MeshDesc_t)); +#endif +} + + +inline void CMeshBuilder::Reset() +{ + m_IndexBuilder.Reset(); + m_VertexBuilder.Reset(); +} + + +FORCEINLINE void CMeshBuilder::SelectVertex(int nIndex) +{ + m_VertexBuilder.SelectVertex(nIndex); +} + +inline void CMeshBuilder::SelectVertexFromIndex(int idx) +{ + int vertIdx = idx - m_nFirstVertex; + SelectVertex(vertIdx); +} + +FORCEINLINE void CMeshBuilder::SelectIndex(int idx) +{ + m_IndexBuilder.SelectIndex(idx); +} + + +template FORCEINLINE void CMeshBuilder::AdvanceVertexF() +{ + m_VertexBuilder.AdvanceVertexF(); +} +FORCEINLINE void CMeshBuilder::AdvanceVertex() +{ + m_VertexBuilder.AdvanceVertex(); +} + +FORCEINLINE void CMeshBuilder::AdvanceVertices(int nVertexCount) +{ + m_VertexBuilder.AdvanceVertices(nVertexCount); +} + +FORCEINLINE void CMeshBuilder::AdvanceIndex() +{ + m_IndexBuilder.AdvanceIndex(); +} + +FORCEINLINE void CMeshBuilder::AdvanceIndices(int nIndices) +{ + m_IndexBuilder.AdvanceIndices(nIndices); +} + +FORCEINLINE int CMeshBuilder::GetCurrentVertex() +{ + return m_VertexBuilder.GetCurrentVertex(); +} + +FORCEINLINE int CMeshBuilder::GetCurrentIndex() +{ + return m_IndexBuilder.GetCurrentIndex(); +} + + +inline void CMeshBuilder::DrawQuad(IMesh* pMesh, const float* v1, const float* v2, + const float* v3, const float* v4, unsigned char const* pColor, bool wireframe) +{ + if (!wireframe) + { + Begin(pMesh, MATERIAL_TRIANGLE_STRIP, 2); + + Position3fv(v1); + Color4ubv(pColor); + AdvanceVertexF(); + + Position3fv(v2); + Color4ubv(pColor); + AdvanceVertexF(); + + Position3fv(v4); + Color4ubv(pColor); + AdvanceVertexF(); + + Position3fv(v3); + Color4ubv(pColor); + AdvanceVertexF(); + } + else + { + Begin(pMesh, MATERIAL_LINE_LOOP, 4); + Position3fv(v1); + Color4ubv(pColor); + AdvanceVertexF(); + + Position3fv(v2); + Color4ubv(pColor); + AdvanceVertexF(); + + Position3fv(v3); + Color4ubv(pColor); + AdvanceVertexF(); + + Position3fv(v4); + Color4ubv(pColor); + AdvanceVertexF(); + } + + End(); + pMesh->Draw(); +} + + +FORCEINLINE int CMeshBuilder::VertexCount() const +{ + return m_VertexBuilder.VertexCount(); +} + +FORCEINLINE int CMeshBuilder::IndexCount() const +{ + return m_IndexBuilder.IndexCount(); +} + + +FORCEINLINE void* CMeshBuilder::BaseVertexData() +{ + return m_VertexBuilder.BaseVertexData(); +} + +FORCEINLINE const float* CMeshBuilder::Position() const +{ + return m_VertexBuilder.Position(); +} + +FORCEINLINE const float* CMeshBuilder::Normal() const +{ + return m_VertexBuilder.Normal(); +} + +FORCEINLINE unsigned int CMeshBuilder::Color() const +{ + return m_VertexBuilder.Color(); +} + +FORCEINLINE unsigned char* CMeshBuilder::Specular() const +{ + return m_VertexBuilder.Specular(); +} + +FORCEINLINE const float* CMeshBuilder::TexCoord(int nStage) const +{ + return m_VertexBuilder.TexCoord(nStage); +} + +FORCEINLINE const float* CMeshBuilder::TangentS() const +{ + return m_VertexBuilder.TangentS(); +} + +FORCEINLINE const float* CMeshBuilder::TangentT() const +{ + return m_VertexBuilder.TangentT(); +} + +FORCEINLINE float CMeshBuilder::Wrinkle() const +{ + return m_VertexBuilder.Wrinkle(); +} + +FORCEINLINE const float* CMeshBuilder::BoneWeight() const +{ + return m_VertexBuilder.BoneWeight(); +} + +FORCEINLINE int CMeshBuilder::NumBoneWeights() const +{ + return m_VertexBuilder.NumBoneWeights(); +} + +FORCEINLINE unsigned short const* CMeshBuilder::Index() const +{ + return m_IndexBuilder.Index(); +} + + +FORCEINLINE void CMeshBuilder::Index(unsigned short idx) +{ + m_IndexBuilder.Index(idx); +} + + +FORCEINLINE void CMeshBuilder::FastIndex(unsigned short idx) +{ + m_IndexBuilder.FastIndex(idx); +} + +FORCEINLINE void CMeshBuilder::FastIndex2(unsigned short nIndex1, unsigned short nIndex2) +{ + m_IndexBuilder.FastIndex2(nIndex1, nIndex2); +} + +FORCEINLINE void CMeshBuilder::FastQuad(int nIndex) +{ + m_IndexBuilder.FastQuad(nIndex); +} + +FORCEINLINE void CMeshBuilder::FastAdvanceNVertices(int nVertexCount) +{ + m_VertexBuilder.FastAdvanceNVertices(nVertexCount); +} + + +FORCEINLINE void CMeshBuilder::FastVertex(const ModelVertexDX8_t& vertex) +{ + m_VertexBuilder.FastVertex(vertex); +} + +FORCEINLINE void CMeshBuilder::FastVertexSSE(const ModelVertexDX8_t& vertex) +{ + m_VertexBuilder.FastVertexSSE(vertex); +} + +FORCEINLINE void CMeshBuilder::FastQuadVertexSSE(const QuadTessVertex_t& vertex) +{ + m_VertexBuilder.FastQuadVertexSSE(vertex); +} + + +#if defined( _X360 ) +inline void CMeshBuilder::VertexDX8ToX360(const ModelVertexDX8_t& vertex) +{ + m_VertexBuilder.VertexDX8ToX360(vertex); +} +#endif + +FORCEINLINE void CMeshBuilder::Position3f(float x, float y, float z) +{ + m_VertexBuilder.Position3f(x, y, z); +} + +FORCEINLINE void CMeshBuilder::Position3fv(const float* v) +{ + m_VertexBuilder.Position3fv(v); +} + +FORCEINLINE void CMeshBuilder::Normal3f(float nx, float ny, float nz) +{ + m_VertexBuilder.Normal3f(nx, ny, nz); +} + +FORCEINLINE void CMeshBuilder::Normal3fv(const float* n) +{ + m_VertexBuilder.Normal3fv(n); +} + +FORCEINLINE void CMeshBuilder::NormalDelta3f(float nx, float ny, float nz) +{ + m_VertexBuilder.NormalDelta3f(nx, ny, nz); +} + +FORCEINLINE void CMeshBuilder::NormalDelta3fv(const float* n) +{ + m_VertexBuilder.NormalDelta3fv(n); +} + +FORCEINLINE void CMeshBuilder::Color3f(float r, float g, float b) +{ + m_VertexBuilder.Color3f(r, g, b); +} + +FORCEINLINE void CMeshBuilder::Color3fv(const float* rgb) +{ + m_VertexBuilder.Color3fv(rgb); +} + +FORCEINLINE void CMeshBuilder::Color4f(float r, float g, float b, float a) +{ + m_VertexBuilder.Color4f(r, g, b, a); +} + +FORCEINLINE void CMeshBuilder::Color4fv(const float* rgba) +{ + m_VertexBuilder.Color4fv(rgba); +} + +FORCEINLINE void CMeshBuilder::Color3ub(unsigned char r, unsigned char g, unsigned char b) +{ + m_VertexBuilder.Color3ub(r, g, b); +} + +FORCEINLINE void CMeshBuilder::Color3ubv(unsigned char const* rgb) +{ + m_VertexBuilder.Color3ubv(rgb); +} + +FORCEINLINE void CMeshBuilder::Color4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a) +{ + m_VertexBuilder.Color4ub(r, g, b, a); +} + +FORCEINLINE void CMeshBuilder::Color4ubv(unsigned char const* rgba) +{ + m_VertexBuilder.Color4ubv(rgba); +} + +FORCEINLINE void CMeshBuilder::Color4Packed(int packedColor) +{ + m_VertexBuilder.Color4Packed(packedColor); +} + +FORCEINLINE int CMeshBuilder::PackColor4(unsigned char r, unsigned char g, unsigned char b, unsigned char a) +{ + return m_VertexBuilder.PackColor4(r, g, b, a); +} + +FORCEINLINE void CMeshBuilder::Specular3f(float r, float g, float b) +{ + m_VertexBuilder.Specular3f(r, g, b); +} + +FORCEINLINE void CMeshBuilder::Specular3fv(const float* rgb) +{ + m_VertexBuilder.Specular3fv(rgb); +} + +FORCEINLINE void CMeshBuilder::Specular4f(float r, float g, float b, float a) +{ + m_VertexBuilder.Specular4f(r, g, b, a); +} + +FORCEINLINE void CMeshBuilder::Specular4fv(const float* rgba) +{ + m_VertexBuilder.Specular4fv(rgba); +} + +FORCEINLINE void CMeshBuilder::Specular3ub(unsigned char r, unsigned char g, unsigned char b) +{ + m_VertexBuilder.Specular3ub(r, g, b); +} + +FORCEINLINE void CMeshBuilder::Specular3ubv(unsigned char const* c) +{ + m_VertexBuilder.Specular3ubv(c); +} + +FORCEINLINE void CMeshBuilder::Specular4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a) +{ + m_VertexBuilder.Specular4ub(r, g, b, a); +} + +FORCEINLINE void CMeshBuilder::Specular4ubv(unsigned char const* c) +{ + m_VertexBuilder.Specular4ubv(c); +} + +FORCEINLINE void CMeshBuilder::TexCoord1f(int nStage, float s) +{ + m_VertexBuilder.TexCoord1f(nStage, s); +} + +FORCEINLINE void CMeshBuilder::TexCoord2f(int nStage, float s, float t) +{ + m_VertexBuilder.TexCoord2f(nStage, s, t); +} + +FORCEINLINE void CMeshBuilder::TexCoord2fv(int nStage, const float* st) +{ + m_VertexBuilder.TexCoord2fv(nStage, st); +} + +FORCEINLINE void CMeshBuilder::TexCoord3f(int nStage, float s, float t, float u) +{ + m_VertexBuilder.TexCoord3f(nStage, s, t, u); +} + +FORCEINLINE void CMeshBuilder::TexCoord3fv(int nStage, const float* stu) +{ + m_VertexBuilder.TexCoord3fv(nStage, stu); +} + +FORCEINLINE void CMeshBuilder::TexCoord4f(int nStage, float s, float t, float u, float v) +{ + m_VertexBuilder.TexCoord4f(nStage, s, t, u, v); +} + +FORCEINLINE void CMeshBuilder::TexCoord4fv(int nStage, const float* stuv) +{ + m_VertexBuilder.TexCoord4fv(nStage, stuv); +} + +FORCEINLINE void CMeshBuilder::TexCoordSubRect2f(int nStage, float s, float t, float offsetS, float offsetT, float scaleS, float scaleT) +{ + m_VertexBuilder.TexCoordSubRect2f(nStage, s, t, offsetS, offsetT, scaleS, scaleT); +} + +FORCEINLINE void CMeshBuilder::TexCoordSubRect2fv(int nStage, const float* st, const float* offset, const float* scale) +{ + m_VertexBuilder.TexCoordSubRect2fv(nStage, st, offset, scale); +} + +FORCEINLINE void CMeshBuilder::TangentS3f(float sx, float sy, float sz) +{ + m_VertexBuilder.TangentS3f(sx, sy, sz); +} + +FORCEINLINE void CMeshBuilder::TangentS3fv(const float* s) +{ + m_VertexBuilder.TangentS3fv(s); +} + +FORCEINLINE void CMeshBuilder::TangentT3f(float tx, float ty, float tz) +{ + m_VertexBuilder.TangentT3f(tx, ty, tz); +} + +FORCEINLINE void CMeshBuilder::TangentT3fv(const float* t) +{ + m_VertexBuilder.TangentT3fv(t); +} + +FORCEINLINE void CMeshBuilder::Wrinkle1f(float flWrinkle) +{ + m_VertexBuilder.Wrinkle1f(flWrinkle); +} + +FORCEINLINE void CMeshBuilder::BoneWeight(int nIndex, float flWeight) +{ + m_VertexBuilder.BoneWeight(nIndex, flWeight); +} + +FORCEINLINE void CMeshBuilder::BoneWeights2(float weight1, float weight2) +{ + m_VertexBuilder.BoneWeights2(weight1, weight2); +} + +template FORCEINLINE void CMeshBuilder::CompressedBoneWeight3fv(const float* pWeights) +{ + m_VertexBuilder.CompressedBoneWeight3fv(pWeights); +} + +FORCEINLINE void CMeshBuilder::BoneMatrix(int nIndex, int nMatrixIdx) +{ + m_VertexBuilder.BoneMatrix(nIndex, nMatrixIdx); +} + +FORCEINLINE void CMeshBuilder::BoneMatrices4(int matrixIdx0, int matrixIdx1, int matrixIdx2, int matrixIdx3) +{ + m_VertexBuilder.BoneMatrices4(matrixIdx0, matrixIdx1, matrixIdx2, matrixIdx3); +} + +FORCEINLINE void CMeshBuilder::UserData(const float* pData) +{ + m_VertexBuilder.UserData(pData); +} + +template FORCEINLINE void CMeshBuilder::CompressedUserData(const float* pData) +{ + m_VertexBuilder.CompressedUserData(pData); +} + +template FORCEINLINE void CMeshBuilder::CompressedNormal3f(float nx, float ny, float nz) +{ + m_VertexBuilder.CompressedNormal3f(nx, ny, nz); +} + +template FORCEINLINE void CMeshBuilder::CompressedNormal3fv(const float* n) +{ + m_VertexBuilder.CompressedNormal3fv(n); +} + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/IPanel.h b/SpyCustom/sdk/IPanel.h new file mode 100644 index 0000000..09a7f20 --- /dev/null +++ b/SpyCustom/sdk/IPanel.h @@ -0,0 +1,118 @@ +#ifndef IPANEL_H +#define IPANEL_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "vgui.h" +#include "interface.h" +#include "utlvector.h" + +#ifdef SendMessage +#undef SendMessage +#endif + +class KeyValues; +struct DmxElementUnpackStructure_t; +class CDmxElement; + +namespace vgui +{ + + class SurfacePlat; + class IClientPanel; + + class Panel; + + class IPanel : public IBaseInterface + { + public: + virtual void Init(VPANEL vguiPanel, IClientPanel* panel) = 0; + + virtual void SetPos(VPANEL vguiPanel, int x, int y) = 0; + virtual void GetPos(VPANEL vguiPanel, int& x, int& y) = 0; + virtual void SetSize(VPANEL vguiPanel, int wide, int tall) = 0; + virtual void GetSize(VPANEL vguiPanel, int& wide, int& tall) = 0; + virtual void SetMinimumSize(VPANEL vguiPanel, int wide, int tall) = 0; + virtual void GetMinimumSize(VPANEL vguiPanel, int& wide, int& tall) = 0; + virtual void SetZPos(VPANEL vguiPanel, int z) = 0; + virtual int GetZPos(VPANEL vguiPanel) = 0; + + virtual void GetAbsPos(VPANEL vguiPanel, int& x, int& y) = 0; + virtual void GetClipRect(VPANEL vguiPanel, int& x0, int& y0, int& x1, int& y1) = 0; + virtual void SetInset(VPANEL vguiPanel, int left, int top, int right, int bottom) = 0; + virtual void GetInset(VPANEL vguiPanel, int& left, int& top, int& right, int& bottom) = 0; + + virtual void SetVisible(VPANEL vguiPanel, bool state) = 0; + virtual bool IsVisible(VPANEL vguiPanel) = 0; + virtual void SetParent(VPANEL vguiPanel, VPANEL newParent) = 0; + virtual int GetChildCount(VPANEL vguiPanel) = 0; + virtual VPANEL GetChild(VPANEL vguiPanel, int index) = 0; + virtual CUtlVector< VPANEL >& GetChildren(VPANEL vguiPanel) = 0; + virtual VPANEL GetParent(VPANEL vguiPanel) = 0; + virtual void MoveToFront(VPANEL vguiPanel) = 0; + virtual void MoveToBack(VPANEL vguiPanel) = 0; + virtual bool HasParent(VPANEL vguiPanel, VPANEL potentialParent) = 0; + virtual bool IsPopup(VPANEL vguiPanel) = 0; + virtual void SetPopup(VPANEL vguiPanel, bool state) = 0; + virtual bool IsFullyVisible(VPANEL vguiPanel) = 0; + + virtual HScheme GetScheme(VPANEL vguiPanel) = 0; + virtual bool IsProportional(VPANEL vguiPanel) = 0; + virtual bool IsAutoDeleteSet(VPANEL vguiPanel) = 0; + virtual void DeletePanel(VPANEL vguiPanel) = 0; + + virtual void SetKeyBoardInputEnabled(VPANEL vguiPanel, bool state) = 0; + virtual void SetMouseInputEnabled(VPANEL vguiPanel, bool state) = 0; + virtual bool IsKeyBoardInputEnabled(VPANEL vguiPanel) = 0; + virtual bool IsMouseInputEnabled(VPANEL vguiPanel) = 0; + + virtual void Solve(VPANEL vguiPanel) = 0; + + virtual const char* GetName(VPANEL vguiPanel) = 0; + virtual const char* GetClassName(VPANEL vguiPanel) = 0; + + virtual void SendMessage(VPANEL vguiPanel, KeyValues* params, VPANEL ifromPanel) = 0; + + virtual void Think(VPANEL vguiPanel) = 0; + virtual void PerformApplySchemeSettings(VPANEL vguiPanel) = 0; + virtual void PaintTraverse(VPANEL vguiPanel, bool forceRepaint, bool allowForce = true) = 0; + virtual void Repaint(VPANEL vguiPanel) = 0; + virtual VPANEL IsWithinTraverse(VPANEL vguiPanel, int x, int y, bool traversePopups) = 0; + virtual void OnChildAdded(VPANEL vguiPanel, VPANEL child) = 0; + virtual void OnSizeChanged(VPANEL vguiPanel, int newWide, int newTall) = 0; + + virtual void InternalFocusChanged(VPANEL vguiPanel, bool lost) = 0; + virtual bool RequestInfo(VPANEL vguiPanel, KeyValues* outputData) = 0; + virtual void RequestFocus(VPANEL vguiPanel, int direction = 0) = 0; + virtual bool RequestFocusPrev(VPANEL vguiPanel, VPANEL existingPanel) = 0; + virtual bool RequestFocusNext(VPANEL vguiPanel, VPANEL existingPanel) = 0; + virtual VPANEL GetCurrentKeyFocus(VPANEL vguiPanel) = 0; + virtual int GetTabPosition(VPANEL vguiPanel) = 0; + + virtual SurfacePlat* Plat(VPANEL vguiPanel) = 0; + virtual void SetPlat(VPANEL vguiPanel, SurfacePlat* Plat) = 0; + + virtual Panel* GetPanel(VPANEL vguiPanel, const char* destinationModule) = 0; + + virtual bool IsEnabled(VPANEL vguiPanel) = 0; + virtual void SetEnabled(VPANEL vguiPanel, bool state) = 0; + + virtual bool IsTopmostPopup(VPANEL vguiPanel) = 0; + virtual void SetTopmostPopup(VPANEL vguiPanel, bool state) = 0; + + virtual void SetMessageContextId(VPANEL vguiPanel, int nContextId) = 0; + virtual int GetMessageContextId(VPANEL vguiPanel) = 0; + + virtual const DmxElementUnpackStructure_t* GetUnpackStructure(VPANEL vguiPanel) const = 0; + virtual void OnUnserialized(VPANEL vguiPanel, CDmxElement* pElement) = 0; + + virtual void SetSiblingPin(VPANEL vguiPanel, VPANEL newSibling, byte iMyCornerToPin = 0, byte iSiblingCornerToPinTo = 0) = 0; + }; + + +} + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/IScheme.h b/SpyCustom/sdk/IScheme.h new file mode 100644 index 0000000..29fa437 --- /dev/null +++ b/SpyCustom/sdk/IScheme.h @@ -0,0 +1,85 @@ +#ifndef ISCHEME_H +#define ISCHEME_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "VGUI.h" +#include "interface.h" + +class Color; +class KeyValues; + +namespace vgui +{ + + typedef unsigned long HScheme; + typedef unsigned long HTexture; + + class IBorder; + class IImage; + + class IScheme : public IBaseInterface + { + public: + virtual const char* GetResourceString(const char* stringName) = 0; + + virtual IBorder* GetBorder(const char* borderName) = 0; + + virtual HFont GetFont(const char* fontName, bool proportional = false) = 0; + + virtual char const* GetFontName(const HFont& font) = 0; + + virtual Color GetColor(const char* colorName, Color defaultColor) = 0; + + virtual int GetBorderCount() const = 0; + + virtual IBorder* GetBorderAtIndex(int iIndex) = 0; + + virtual int GetFontCount() const = 0; + + virtual HFont GetFontAtIndex(int iIndex) = 0; + + virtual const KeyValues* GetColorData() const = 0; + }; + + + + class ISchemeManager : public IBaseInterface + { + public: + virtual HScheme LoadSchemeFromFile(const char* fileName, const char* tag) = 0; + + virtual void ReloadSchemes() = 0; + + virtual void ReloadFonts() = 0; + + virtual HScheme GetDefaultScheme() = 0; + + virtual HScheme GetScheme(const char* tag) = 0; + + virtual IImage* GetImage(const char* imageName, bool hardwareFiltered) = 0; + virtual HTexture GetImageID(const char* imageName, bool hardwareFiltered) = 0; + + virtual IScheme* GetIScheme(HScheme scheme) = 0; + + virtual void Shutdown(bool full = true) = 0; + + virtual int GetProportionalScaledValue(int normalizedValue) = 0; + virtual int GetProportionalNormalizedValue(int scaledValue) = 0; + + virtual HScheme LoadSchemeFromFileEx(VPANEL sizingPanel, const char* fileName, const char* tag) = 0; + virtual int GetProportionalScaledValueEx(HScheme scheme, int normalizedValue) = 0; + virtual int GetProportionalNormalizedValueEx(HScheme scheme, int scaledValue) = 0; + + virtual bool DeleteImage(const char* pImageName) = 0; + }; + +#define VGUI_SCHEME_INTERFACE_VERSION "VGUI_Scheme010" + + +} + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/ISurface.h b/SpyCustom/sdk/ISurface.h new file mode 100644 index 0000000..5d4a391 --- /dev/null +++ b/SpyCustom/sdk/ISurface.h @@ -0,0 +1,378 @@ +#ifndef ISURFACE_H +#define ISURFACE_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "VGUI.h" +#include "IHTML.h" +#include "interface.h" +#include "imageformat.h" + +#include "IAppSystem.h" +#include "vector2d.h" +#include "ichromehtmlwrapper.h" + +#include "IVguiMatInfo.h" + +#ifdef CreateFont +#undef CreateFont +#endif + +#ifdef PlaySound +#undef PlaySound +#endif + +class Color; +class ITexture; + +namespace vgui +{ + + class IImage; + class Image; + class Point; + + typedef unsigned long HCursor; + typedef unsigned long HTexture; + typedef unsigned long HFont; + + + + struct Vertex_t + { + Vertex_t() {} + Vertex_t(const Vector2D& pos, const Vector2D& coord = Vector2D(0, 0)) + { + m_Position = pos; + m_TexCoord = coord; + } + void Init(const Vector2D& pos, const Vector2D& coord = Vector2D(0, 0)) + { + m_Position = pos; + m_TexCoord = coord; + } + + Vector2D m_Position; + Vector2D m_TexCoord; + }; + + + enum FontDrawType_t + { + FONT_DRAW_DEFAULT = 0, + + FONT_DRAW_NONADDITIVE, + FONT_DRAW_ADDITIVE, + + FONT_DRAW_TYPE_COUNT = 2, + }; + + + struct CharRenderInfo + { + int x, y; + Vertex_t* verts; + int textureId; + int abcA; + int abcB; + int abcC; + int fontTall; + HFont currentFont; + FontDrawType_t drawType; + wchar_t ch; + + bool valid; + bool shouldclip; + }; + + + struct IntRect + { + int x0; + int y0; + int x1; + int y1; + }; + + + + struct DrawTexturedRectParms_t + { + DrawTexturedRectParms_t() + { + s0 = t0 = 0; + s1 = t1 = 1.0f; + alpha_ul = alpha_ur = alpha_lr = alpha_ll = 255; + angle = 0; + } + + int x0; + int y0; + int x1; + int y1; + + float s0; + float t0; + float s1; + float t1; + + unsigned char alpha_ul; + unsigned char alpha_ur; + unsigned char alpha_lr; + unsigned char alpha_ll; + + float angle; + }; + + + class ISurface : public IAppSystem + { + public: + virtual void Shutdown() = 0; + + virtual void RunFrame() = 0; + + virtual VPANEL GetEmbeddedPanel() = 0; + virtual void SetEmbeddedPanel(VPANEL pPanel) = 0; + + virtual void PushMakeCurrent(VPANEL panel, bool useInsets) = 0; + virtual void PopMakeCurrent(VPANEL panel) = 0; + + virtual void DrawSetColor(int r, int g, int b, int a) = 0; + virtual void DrawSetColor(Color col) = 0; + + virtual void DrawFilledRect(int x0, int y0, int x1, int y1) = 0; + virtual void DrawFilledRectArray(IntRect* pRects, int numRects) = 0; + virtual void DrawOutlinedRect(int x0, int y0, int x1, int y1) = 0; + + virtual void DrawLine(int x0, int y0, int x1, int y1) = 0; + virtual void DrawPolyLine(int* px, int* py, int numPoints) = 0; + + virtual void DrawSetApparentDepth(float depth) = 0; + virtual void DrawClearApparentDepth() = 0; + + virtual void DrawSetTextFont(HFont font) = 0; + virtual void DrawSetTextColor(int r, int g, int b, int a) = 0; + virtual void DrawSetTextColor(Color col) = 0; + virtual void DrawSetTextPos(int x, int y) = 0; + virtual void DrawGetTextPos(int& x, int& y) = 0; + virtual void DrawPrintText(const wchar_t* text, int textLen, FontDrawType_t drawType = FONT_DRAW_DEFAULT) = 0; + virtual void DrawUnicodeChar(wchar_t wch, FontDrawType_t drawType = FONT_DRAW_DEFAULT) = 0; + + virtual void DrawFlushText() = 0; + virtual IHTML* CreateHTMLWindow(vgui::IHTMLEvents* events, VPANEL context) = 0; + virtual void PaintHTMLWindow(vgui::IHTML* htmlwin) = 0; + virtual void DeleteHTMLWindow(IHTML* htmlwin) = 0; + + enum ETextureFormat + { + eTextureFormat_RGBA, + eTextureFormat_BGRA, + eTextureFormat_BGRA_Opaque, + }; + + virtual int DrawGetTextureId(char const* filename) = 0; + virtual bool DrawGetTextureFile(int id, char* filename, int maxlen) = 0; + virtual void DrawSetTextureFile(int id, const char* filename, int hardwareFilter, bool forceReload) = 0; + virtual void DrawSetTextureRGBA(int id, const unsigned char* rgba, int wide, int tall, int hardwareFilter, bool forceReload) = 0; + virtual void DrawSetTexture(int id) = 0; + virtual bool DeleteTextureByID(int id) = 0; + + virtual void DrawGetTextureSize(int id, int& wide, int& tall) = 0; + virtual void DrawTexturedRect(int x0, int y0, int x1, int y1) = 0; + virtual bool IsTextureIDValid(int id) = 0; + + virtual int CreateNewTextureID(bool procedural = false) = 0; + + virtual void GetScreenSize(int& wide, int& tall) = 0; + virtual void SetAsTopMost(VPANEL panel, bool state) = 0; + virtual void BringToFront(VPANEL panel) = 0; + virtual void SetForegroundWindow(VPANEL panel) = 0; + virtual void SetPanelVisible(VPANEL panel, bool state) = 0; + virtual void SetMinimized(VPANEL panel, bool state) = 0; + virtual bool IsMinimized(VPANEL panel) = 0; + virtual void FlashWindow(VPANEL panel, bool state) = 0; + virtual void SetTitle(VPANEL panel, const wchar_t* title) = 0; + virtual void SetAsToolBar(VPANEL panel, bool state) = 0; + + virtual void CreatePopup(VPANEL panel, bool minimised, bool showTaskbarIcon = true, bool disabled = false, bool mouseInput = true, bool kbInput = true) = 0; + virtual void SwapBuffers(VPANEL panel) = 0; + virtual void Invalidate(VPANEL panel) = 0; + virtual void SetCursor(HCursor cursor) = 0; + virtual bool IsCursorVisible() = 0; + virtual void ApplyChanges() = 0; + virtual bool IsWithin(int x, int y) = 0; + virtual bool HasFocus() = 0; + + enum SurfaceFeature_e + { + ANTIALIASED_FONTS = 1, + DROPSHADOW_FONTS = 2, + ESCAPE_KEY = 3, + OPENING_NEW_HTML_WINDOWS = 4, + FRAME_MINIMIZE_MAXIMIZE = 5, + OUTLINE_FONTS = 6, + DIRECT_HWND_RENDER = 7, + }; + virtual bool SupportsFeature(SurfaceFeature_e feature) = 0; + + virtual void RestrictPaintToSinglePanel(VPANEL panel) = 0; + + virtual void SetModalPanel(VPANEL) = 0; + virtual VPANEL GetModalPanel() = 0; + + virtual void UnlockCursor() = 0; + virtual void LockCursor() = 0; + virtual void SetTranslateExtendedKeys(bool state) = 0; + virtual VPANEL GetTopmostPopup() = 0; + + virtual void SetTopLevelFocus(VPANEL panel) = 0; + + virtual HFont CreateFont() = 0; + + enum EFontFlags + { + FONTFLAG_NONE, + FONTFLAG_ITALIC = 0x001, + FONTFLAG_UNDERLINE = 0x002, + FONTFLAG_STRIKEOUT = 0x004, + FONTFLAG_SYMBOL = 0x008, + FONTFLAG_ANTIALIAS = 0x010, + FONTFLAG_GAUSSIANBLUR = 0x020, + FONTFLAG_ROTARY = 0x040, + FONTFLAG_DROPSHADOW = 0x080, + FONTFLAG_ADDITIVE = 0x100, + FONTFLAG_OUTLINE = 0x200, + FONTFLAG_CUSTOM = 0x400, + FONTFLAG_BITMAP = 0x800, + }; + + virtual bool SetFontGlyphSet(HFont font, const char* windowsFontName, int tall, int weight, int blur, int scanlines, int flags, int nRangeMin = 0, int nRangeMax = 0) = 0; + + virtual bool AddCustomFontFile(const char* fontName, const char* fontFileName) = 0; + + virtual int GetFontTall(HFont font) = 0; + virtual int GetFontAscent(HFont font, wchar_t wch) = 0; + virtual bool IsFontAdditive(HFont font) = 0; + virtual void GetCharABCwide(HFont font, int ch, int& a, int& b, int& c) = 0; + virtual int GetCharacterWidth(HFont font, int ch) = 0; + virtual void GetTextSize(HFont font, const wchar_t* text, int& wide, int& tall) = 0; + + virtual VPANEL GetNotifyPanel() = 0; + virtual void SetNotifyIcon(VPANEL context, HTexture icon, VPANEL panelToReceiveMessages, const char* text) = 0; + + virtual void PlaySound(const char* fileName) = 0; + + virtual int GetPopupCount() = 0; + virtual VPANEL GetPopup(int index) = 0; + virtual bool ShouldPaintChildPanel(VPANEL childPanel) = 0; + virtual bool RecreateContext(VPANEL panel) = 0; + virtual void AddPanel(VPANEL panel) = 0; + virtual void ReleasePanel(VPANEL panel) = 0; + virtual void MovePopupToFront(VPANEL panel) = 0; + virtual void MovePopupToBack(VPANEL panel) = 0; + + virtual void SolveTraverse(VPANEL panel, bool forceApplySchemeSettings = false) = 0; + virtual void PaintTraverse(VPANEL panel) = 0; + + virtual void EnableMouseCapture(VPANEL panel, bool state) = 0; + + virtual void GetWorkspaceBounds(int& x, int& y, int& wide, int& tall) = 0; + + virtual void GetAbsoluteWindowBounds(int& x, int& y, int& wide, int& tall) = 0; + + virtual void GetProportionalBase(int& width, int& height) = 0; + + virtual void CalculateMouseVisible() = 0; + virtual bool NeedKBInput() = 0; + + virtual bool HasCursorPosFunctions() = 0; + virtual void SurfaceGetCursorPos(int& x, int& y) = 0; + virtual void SurfaceSetCursorPos(int x, int y) = 0; + + virtual void DrawTexturedLine(const Vertex_t& a, const Vertex_t& b) = 0; + virtual void DrawOutlinedCircle(int x, int y, int radius, int segments) = 0; + virtual void DrawTexturedPolyLine(const Vertex_t* p, int n) = 0; + virtual void DrawTexturedSubRect(int x0, int y0, int x1, int y1, float texs0, float text0, float texs1, float text1) = 0; + virtual void DrawTexturedPolygon(int n, Vertex_t* pVertice, bool bClipVertices = true) = 0; + virtual const wchar_t* GetTitle(VPANEL panel) = 0; + virtual bool IsCursorLocked(void) const = 0; + virtual void SetWorkspaceInsets(int left, int top, int right, int bottom) = 0; + + virtual void DrawWordBubble(int x0, int y0, int x1, int y1, int nBorderThickness, Color rgbaBackground, Color rgbaBorder, + bool bPointer = false, int nPointerX = 0, int nPointerY = 0, int nPointerBaseThickness = 16) = 0; + + + virtual bool DrawGetUnicodeCharRenderInfo(wchar_t ch, CharRenderInfo& info) = 0; + virtual void DrawRenderCharFromInfo(const CharRenderInfo& info) = 0; + + virtual void DrawSetAlphaMultiplier(float alpha ) = 0; + virtual float DrawGetAlphaMultiplier() = 0; + + virtual void SetAllowHTMLJavaScript(bool state) = 0; + + virtual void OnScreenSizeChanged(int nOldWidth, int nOldHeight) = 0; + + virtual vgui::HCursor CreateCursorFromFile(char const* curOrAniFile, char const* pPathID = 0) = 0; + + virtual IVguiMatInfo* DrawGetTextureMatInfoFactory(int id) = 0; + + virtual void PaintTraverseEx(VPANEL panel, bool paintPopups = false) = 0; + + virtual float GetZPos() const = 0; + + virtual void SetPanelForInput(VPANEL vpanel) = 0; + virtual void DrawFilledRectFastFade(int x0, int y0, int x1, int y1, int fadeStartPt, int fadeEndPt, unsigned int alpha0, unsigned int alpha1, bool bHorizontal) = 0; + virtual void DrawFilledRectFade(int x0, int y0, int x1, int y1, unsigned int alpha0, unsigned int alpha1, bool bHorizontal) = 0; + virtual void DrawSetTextureRGBAEx(int id, const unsigned char* rgba, int wide, int tall, ImageFormat imageFormat) = 0; + virtual void DrawSetTextScale(float sx, float sy) = 0; + virtual bool SetBitmapFontGlyphSet(HFont font, const char* windowsFontName, float scalex, float scaley, int flags) = 0; + virtual bool AddBitmapFontFile(const char* fontFileName) = 0; + virtual void SetBitmapFontName(const char* pName, const char* pFontFilename) = 0; + virtual const char* GetBitmapFontName(const char* pName) = 0; + virtual void ClearTemporaryFontCache(void) = 0; + + virtual IImage* GetIconImageForFullPath(char const* pFullPath) = 0; + virtual void DrawUnicodeString(const wchar_t* pwString, FontDrawType_t drawType = FONT_DRAW_DEFAULT) = 0; + virtual void PrecacheFontCharacters(HFont font, const wchar_t* pCharacters) = 0; + virtual const char* GetFontName(HFont font) = 0; + virtual bool ForceScreenSizeOverride(bool bState, int wide, int tall) = 0; + virtual bool ForceScreenPosOffset(bool bState, int x, int y) = 0; + virtual void OffsetAbsPos(int& x, int& y) = 0; + + virtual void SetAbsPosForContext(int id, int x, int y) = 0; + virtual void GetAbsPosForContext(int id, int& x, int& y) = 0; + + virtual void ResetFontCaches() = 0; + + virtual bool IsScreenSizeOverrideActive(void) = 0; + virtual bool IsScreenPosOverrideActive(void) = 0; + + virtual void DestroyTextureID(int id) = 0; + + virtual int GetTextureNumFrames(int id) = 0; + virtual void DrawSetTextureFrame(int id, int nFrame, unsigned int* pFrameCache) = 0; + + virtual void GetClipRect(int& x0, int& y0, int& x1, int& y1) = 0; + virtual void SetClipRect(int x0, int y0, int x1, int y1) = 0; + + virtual void DrawTexturedRectEx(DrawTexturedRectParms_t* pDrawParms) = 0; + + virtual void GetKernedCharWidth(HFont font, wchar_t ch, wchar_t chBefore, wchar_t chAfter, float& wide, float& abcA, float& abcC) = 0; + virtual void DrawUpdateRegionTextureRGBA(int nTextureID, int x, int y, const unsigned char* pchData, int wide, int tall, ImageFormat imageFormat) = 0; + virtual bool BHTMLWindowNeedsPaint(IHTML* htmlwin) = 0; + + virtual void DrawSetTextureRGBALinear(int id, const unsigned char* rgba, int wide, int tall) = 0; + + virtual const char* GetWebkitHTMLUserAgentString() = 0; + + virtual void* Deprecated_AccessChromeHTMLController() = 0; + }; + +} + +#define VGUI_SURFACE_INTERFACE_VERSION "VGUI_Surface030" + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/ISystem.h b/SpyCustom/sdk/ISystem.h new file mode 100644 index 0000000..e94d8b2 --- /dev/null +++ b/SpyCustom/sdk/ISystem.h @@ -0,0 +1,86 @@ +#ifndef ISYSTEM_H +#define ISYSTEM_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "interface.h" +#include "VGUI.h" +#include "KeyCode.h" + +#ifdef PlaySound +#undef PlaySound +#endif + +class KeyValues; + +namespace vgui +{ + + class ISystem : public IBaseInterface + { + public: + virtual void Shutdown() = 0; + + virtual void RunFrame() = 0; + + virtual void ShellExecute(const char* command, const char* file) = 0; + + virtual double GetFrameTime() = 0; + + virtual double GetCurrentTime() = 0; + + virtual long GetTimeMillis() = 0; + + virtual int GetClipboardTextCount() = 0; + virtual void SetClipboardText(const char* text, int textLen) = 0; + virtual void SetClipboardText(const wchar_t* text, int textLen) = 0; + virtual int GetClipboardText(int offset, char* buf, int bufLen) = 0; + virtual int GetClipboardText(int offset, wchar_t* buf, int bufLen) = 0; + + virtual bool SetRegistryString(const char* key, const char* value) = 0; + virtual bool GetRegistryString(const char* key, char* value, int valueLen) = 0; + virtual bool SetRegistryInteger(const char* key, int value) = 0; + virtual bool GetRegistryInteger(const char* key, int& value) = 0; + + virtual KeyValues* GetUserConfigFileData(const char* dialogName, int dialogID) = 0; + virtual void SetUserConfigFile(const char* fileName, const char* pathName) = 0; + virtual void SaveUserConfigFile() = 0; + + virtual bool SetWatchForComputerUse(bool state) = 0; + virtual double GetTimeSinceLastUse() = 0; + + virtual int GetAvailableDrives(char* buf, int bufLen) = 0; + + virtual bool CommandLineParamExists(const char* paramName) = 0; + + virtual const char* GetFullCommandLine() = 0; + + virtual KeyCode KeyCode_VirtualKeyToVGUI(int keyCode) = 0; + + virtual bool GetCurrentTimeAndDate(int* year, int* month, int* dayOfWeek, int* day, int* hour, int* minute, int* second) = 0; + + virtual double GetFreeDiskSpace(const char* path) = 0; + + virtual bool CreateShortcut(const char* linkFileName, const char* targetPath, const char* arguments, const char* workingDirectory, const char* iconFile) = 0; + virtual bool GetShortcutTarget(const char* linkFileName, char* targetPath, char* arguments, int destBufferSizes) = 0; + virtual bool ModifyShortcutTarget(const char* linkFileName, const char* targetPath, const char* arguments, const char* workingDirectory) = 0; + + virtual bool GetCommandLineParamValue(const char* paramName, char* value, int valueBufferSize) = 0; + + virtual bool DeleteRegistryKey(const char* keyName) = 0; + + virtual const char* GetDesktopFolderPath() = 0; + + virtual void ShellExecuteEx(const char* command, const char* file, const char* pParams) = 0; + + virtual void SetClipboardImage(void* pWnd, int x1, int y1, int x2, int y2) = 0; + }; + +} + +#define VGUI_SYSTEM_INTERFACE_VERSION "VGUI_System010" + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/IVGUI.h b/SpyCustom/sdk/IVGUI.h new file mode 100644 index 0000000..5eef332 --- /dev/null +++ b/SpyCustom/sdk/IVGUI.h @@ -0,0 +1,79 @@ +#ifndef IVGUI_H +#define IVGUI_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "interface.h" +#include "VGUI.h" + +#include "IAppSystem.h" + +class KeyValues; + +namespace vgui +{ + + typedef unsigned long HPanel; + typedef int HContext; + + enum + { + DEFAULT_VGUI_CONTEXT = ((vgui::HContext)~0) + }; + + typedef unsigned long HPanel; + + class IVGui : public IAppSystem + { + public: + virtual void Start() = 0; + + virtual void Stop() = 0; + + virtual bool IsRunning() = 0; + + virtual void RunFrame() = 0; + + virtual void ShutdownMessage(unsigned int shutdownID) = 0; + + virtual VPANEL AllocPanel() = 0; + virtual void FreePanel(VPANEL panel) = 0; + + virtual void DPrintf(PRINTF_FORMAT_STRING const char* format, ...) = 0; + virtual void DPrintf2(PRINTF_FORMAT_STRING const char* format, ...) = 0; + virtual void SpewAllActivePanelNames() = 0; + + virtual HPanel PanelToHandle(VPANEL panel) = 0; + virtual VPANEL HandleToPanel(HPanel index) = 0; + virtual void MarkPanelForDeletion(VPANEL panel) = 0; + + virtual void AddTickSignal(VPANEL panel, int intervalMilliseconds = 0) = 0; + virtual void RemoveTickSignal(VPANEL panel) = 0; + + virtual void PostMessage(VPANEL target, KeyValues* params, VPANEL from, float delaySeconds = 0.0f) = 0; + + virtual HContext CreateContext() = 0; + virtual void DestroyContext(HContext context) = 0; + + virtual void AssociatePanelWithContext(HContext context, VPANEL pRoot) = 0; + + virtual void ActivateContext(HContext context) = 0; + + virtual void SetSleep(bool state) = 0; + + virtual bool GetShouldVGuiControlSleep() = 0; + + virtual void SetVRMode(bool bVRMode) = 0; + virtual bool GetVRMode() = 0; + + virtual void AddTickSignalToHead(VPANEL panel, int intervalMilliseconds = 0) = 0; + }; + +#define VGUI_IVGUI_INTERFACE_VERSION "VGUI_ivgui008" + +}; + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/IVguiMatInfo.h b/SpyCustom/sdk/IVguiMatInfo.h new file mode 100644 index 0000000..1278a27 --- /dev/null +++ b/SpyCustom/sdk/IVguiMatInfo.h @@ -0,0 +1,17 @@ +#ifndef IVGUIMATINFO_H +#define IVGUIMATINFO_H + +#include "IVguiMatInfoVar.h" + +class IVguiMatInfo +{ +public: + virtual ~IVguiMatInfo() {} + + virtual IVguiMatInfoVar* FindVarFactory(const char* varName, bool* found) = 0; + + virtual int GetNumAnimationFrames() = 0; + +}; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/IVguiMatInfoVar.h b/SpyCustom/sdk/IVguiMatInfoVar.h new file mode 100644 index 0000000..806b0b2 --- /dev/null +++ b/SpyCustom/sdk/IVguiMatInfoVar.h @@ -0,0 +1,15 @@ +#ifndef IVGUIMATINFOVAR_H +#define IVGUIMATINFOVAR_H + + +class IVguiMatInfoVar +{ +public: + virtual ~IVguiMatInfoVar() {} + + virtual int GetIntValue(void) const = 0; + virtual void SetIntValue(int val) = 0; + +}; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/Image.h b/SpyCustom/sdk/Image.h new file mode 100644 index 0000000..878e692 --- /dev/null +++ b/SpyCustom/sdk/Image.h @@ -0,0 +1,64 @@ +#ifndef IMAGE_H +#define IMAGE_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "VGUI.h" +#include "Color.h" +#include "IImage.h" + +namespace vgui +{ + + class Panel; + + class Image : public IImage + { + public: + Image(); + virtual ~Image(); + + virtual void SetPos(int x, int y); + virtual void GetPos(int& x, int& y); + virtual void GetSize(int& wide, int& tall); + virtual void GetContentSize(int& wide, int& tall); + virtual void SetColor(Color color); + virtual void SetBkColor(Color color) { DrawSetColor(color); } + virtual Color GetColor(); + virtual bool Evict(); + virtual int GetNumFrames(); + virtual void SetFrame(int nFrame); + virtual HTexture GetID(); + virtual void SetRotation(int iRotation) { return; }; + + protected: + virtual void SetSize(int wide, int tall); + virtual void DrawSetColor(Color color); + virtual void DrawSetColor(int r, int g, int b, int a); + virtual void DrawFilledRect(int x0, int y0, int x1, int y1); + virtual void DrawOutlinedRect(int x0, int y0, int x1, int y1); + virtual void DrawLine(int x0, int y0, int x1, int y1); + virtual void DrawPolyLine(int* px, int* py, int numPoints); + virtual void DrawSetTextFont(HFont font); + virtual void DrawSetTextColor(Color color); + virtual void DrawSetTextColor(int r, int g, int b, int a); + virtual void DrawSetTextPos(int x, int y); + virtual void DrawPrintText(const wchar_t* str, int strlen); + virtual void DrawPrintText(int x, int y, const wchar_t* str, int strlen); + virtual void DrawPrintChar(wchar_t ch); + virtual void DrawPrintChar(int x, int y, wchar_t ch); + virtual void DrawSetTexture(int id); + virtual void DrawTexturedRect(int x0, int y0, int x1, int y1); + virtual void Paint() = 0; + + private: + int _pos[2]; + int _size[2]; + Color _color; + }; + +} + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/InputEnums.h b/SpyCustom/sdk/InputEnums.h new file mode 100644 index 0000000..cb53db1 --- /dev/null +++ b/SpyCustom/sdk/InputEnums.h @@ -0,0 +1,82 @@ +#ifndef INPUTENUMS_H +#define INPUTENUMS_H +#ifdef _WIN32 +#pragma once +#endif + +#define MAX_BUTTONSAMPLE 32768 + +#if !defined( _X360 ) +#define INVALID_USER_ID -1 +#else +#define INVALID_USER_ID XBX_INVALID_USER_ID +#endif + +enum +{ + MAX_JOYSTICKS = 1, + MOUSE_BUTTON_COUNT = 5, + MAX_NOVINT_DEVICES = 2, +}; + +#if defined( LINUX ) +enum JoystickAxis_t +{ + JOY_AXIS_X = 0, + JOY_AXIS_Y, + JOY_AXIS_Z, + JOY_AXIS_U, + JOY_AXIS_R, + JOY_AXIS_V, + MAX_JOYSTICK_AXES, +}; +#else +enum JoystickAxis_t +{ + JOY_AXIS_X = 0, + JOY_AXIS_Y, + JOY_AXIS_Z, + JOY_AXIS_R, + JOY_AXIS_U, + JOY_AXIS_V, + MAX_JOYSTICK_AXES, +}; +#endif + + + +enum +{ + MS_WM_XBUTTONDOWN = 0x020B, + MS_WM_XBUTTONUP = 0x020C, + MS_WM_XBUTTONDBLCLK = 0x020D, + MS_MK_BUTTON4 = 0x0020, + MS_MK_BUTTON5 = 0x0040, +}; + +enum InputEventType_t +{ + IE_ButtonPressed = 0, + IE_ButtonReleased, + IE_ButtonDoubleClicked, + IE_AnalogValueChanged, + + IE_FirstSystemEvent = 100, + IE_Quit = IE_FirstSystemEvent, + IE_ControllerInserted, + IE_ControllerUnplugged, + + IE_FirstVguiEvent = 1000, + IE_FirstAppEvent = 2000, +}; + +struct InputEvent_t +{ + int m_nType; + int m_nTick; + int m_nData; + int m_nData2; + int m_nData3; +}; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/KeyBindingMap.h b/SpyCustom/sdk/KeyBindingMap.h new file mode 100644 index 0000000..1fc0d95 --- /dev/null +++ b/SpyCustom/sdk/KeyBindingMap.h @@ -0,0 +1,206 @@ +#ifndef KEYBINDINGMAP_H +#define KEYBINDINGMAP_H +#ifdef _WIN32 +#pragma once +#endif + +#include "utlvector.h" + +namespace vgui +{ + + class Panel; + + enum + { + MODIFIER_SHIFT = (1 << 0), + MODIFIER_CONTROL = (1 << 1), + MODIFIER_ALT = (1 << 2), + }; + + struct BoundKey_t + { + BoundKey_t(); + BoundKey_t(const BoundKey_t& src); + ~BoundKey_t(); + BoundKey_t& operator =(const BoundKey_t& src); + + bool isbuiltin; + char const* bindingname; + int keycode; + int modifiers; + }; + + struct KeyBindingMap_t + { + KeyBindingMap_t(); + KeyBindingMap_t(const KeyBindingMap_t& src); + ~KeyBindingMap_t(); + + char const* bindingname; + ALIGN16 MessageFunc_t func; + char const* helpstring; + char const* docstring; + bool passive; + }; + +#define DECLARE_KEYBINDINGMAP( className ) \ + static void KB_AddToMap \ + ( \ + char const *bindingname, \ + vgui::KeyCode defaultcode, \ + int default_modifiers, \ + vgui::MessageFunc_t function, \ + char const *helpstring, \ + char const *docstring, \ + bool passive \ + ) \ + { \ + vgui::PanelKeyBindingMap *map = vgui::FindOrAddPanelKeyBindingMap( GetPanelClassName() ); \ + \ + vgui::KeyBindingMap_t entry; \ + entry.bindingname = bindingname; \ + \ + entry.func = function; \ + \ + entry.helpstring = helpstring; \ + entry.docstring = docstring; \ + \ + entry.passive = passive; \ + \ + map->entries.AddToTail( entry ); \ + \ + vgui::BoundKey_t kb; \ + kb.isbuiltin = true; \ + kb.bindingname = bindingname; \ + kb.keycode = defaultcode; \ + kb.modifiers = default_modifiers; \ + map->defaultkeys.AddToTail( kb ); \ + map->boundkeys.AddToTail( kb ); \ + } \ + \ + static void KB_ChainToMap( void ) \ + { \ + static bool chained = false; \ + if ( chained ) \ + return; \ + chained = true; \ + vgui::PanelKeyBindingMap *map = vgui::FindOrAddPanelKeyBindingMap( GetPanelClassName() ); \ + map->pfnClassName = &GetPanelClassName; \ + if ( map && GetPanelBaseClassName() && GetPanelBaseClassName()[0] ) \ + { \ + map->baseMap = vgui::FindOrAddPanelKeyBindingMap( GetPanelBaseClassName() ); \ + } \ + } \ + \ + static void KB_AddBoundKey \ + ( \ + char const *bindingname, \ + int keycode, \ + int modifiers \ + ) \ + { \ + vgui::PanelKeyBindingMap *map = vgui::FindOrAddPanelKeyBindingMap( GetPanelClassName() ); \ + vgui::BoundKey_t kb; \ + kb.isbuiltin = true; \ + kb.bindingname = bindingname; \ + kb.keycode = keycode; \ + kb.modifiers = modifiers; \ + map->defaultkeys.AddToTail( kb ); \ + map->boundkeys.AddToTail( kb ); \ + } \ + \ + class className##_RegisterKBMap; \ + friend class className##_RegisterKBMap; \ + class className##_RegisterKBMap \ + { \ + public: \ + className##_RegisterKBMap() \ + { \ + className::KB_ChainToMap(); \ + } \ + }; \ + className##_RegisterKBMap m_RegisterClassKB; \ + \ + virtual vgui::PanelKeyBindingMap *GetKBMap() \ + { \ + static vgui::PanelKeyBindingMap *s_pMap = vgui::FindOrAddPanelKeyBindingMap( GetPanelClassName() ); \ + return s_pMap; \ + } + +#define _KBMapFuncCommonFunc( name, keycode, modifiers, function, help, doc, passive ) \ + class PanelKBMapFunc_##name; \ + friend class PanelKBMapFunc_##name; \ + class PanelKBMapFunc_##name \ + { \ + public: \ + static void InitVar() \ + { \ + static bool bAdded = false; \ + if ( !bAdded ) \ + { \ + bAdded = true; \ + KB_AddToMap( #name, keycode, modifiers, (vgui::MessageFunc_t)&ThisClass::function, help, doc, passive ); \ + } \ + } \ + PanelKBMapFunc_##name() \ + { \ + PanelKBMapFunc_##name::InitVar(); \ + } \ + }; \ + PanelKBMapFunc_##name m_##name##_register; + +#define _KBBindKeyCommon( name, keycode, modifiers, _classname ) \ + class PanelKBBindFunc_##_classname; \ + friend class PanelKBBindFunc_##_classname; \ + class PanelKBBindFunc_##_classname \ + { \ + public: \ + static void InitVar() \ + { \ + static bool bAdded = false; \ + if ( !bAdded ) \ + { \ + bAdded = true; \ + KB_AddBoundKey( #name, keycode, modifiers ); \ + } \ + } \ + PanelKBBindFunc_##_classname() \ + { \ + PanelKBBindFunc_##_classname::InitVar(); \ + } \ + }; \ + PanelKBBindFunc_##_classname m_##_classname##_bindkey_register; + +#define KEYBINDING_FUNC( name, keycode, modifiers, function, help, doc ) _KBMapFuncCommonFunc( name, keycode, modifiers, function, help, doc, false ); virtual void function() +#define KEYBINDING_FUNC_NODECLARE( name, keycode, modifiers, function, help, doc ) _KBMapFuncCommonFunc( name, keycode, modifiers, function, help, doc, false ); +#define KEYBINDING_FUNC_PASSIVE( name, keycode, modifiers, function, help, doc ) _KBMapFuncCommonFunc( name, keycode, modifiers, function, help, doc, true ); virtual void function() +#define KEYBINDING_FUNC_PASSIVE_NODECLARE( name, keycode, modifiers, function, help, doc ) _KBMapFuncCommonFunc( name, keycode, modifiers, function, help, doc, true ); + +#define KEYBINDING_ADDBINDING( name, keycode, modifiers ) _KBBindKeyCommon( name, keycode, modifiers, name ); +#define KEYBINDING_ADDBINDING_MULTIPLE( name, keycode, modifiers, _classname ) _KBBindKeyCommon( name, keycode, modifiers, _classname ); + + struct PanelKeyBindingMap + { + PanelKeyBindingMap() + { + baseMap = NULL; + pfnClassName = NULL; + processed = false; + } + + CUtlVector< KeyBindingMap_t > entries; + bool processed; + PanelKeyBindingMap* baseMap; + CUtlVector< BoundKey_t > defaultkeys; + CUtlVector< BoundKey_t > boundkeys; + char const* (*pfnClassName)(void); + }; + + PanelKeyBindingMap* FindPanelKeyBindingMap(char const* className); + PanelKeyBindingMap* FindOrAddPanelKeyBindingMap(char const* className); + +} + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/KeyCode.h b/SpyCustom/sdk/KeyCode.h new file mode 100644 index 0000000..dc23cc4 --- /dev/null +++ b/SpyCustom/sdk/KeyCode.h @@ -0,0 +1,15 @@ +#ifndef KEYCODE_H +#define KEYCODE_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "ButtonCode.h" + +namespace vgui +{ + typedef ButtonCode_t KeyCode; +} + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/Label.h b/SpyCustom/sdk/Label.h new file mode 100644 index 0000000..028c62d --- /dev/null +++ b/SpyCustom/sdk/Label.h @@ -0,0 +1,167 @@ +#ifndef LABEL_H +#define LABEL_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "utlvector.h" +#include "VGUI.h" +#include "Panel.h" +#include "PHandle.h" + +namespace vgui +{ + + class Label : public Panel + { + DECLARE_CLASS_SIMPLE(Label, Panel); + + public: + Label(Panel* parent, const char* panelName, const char* text); + Label(Panel* parent, const char* panelName, const wchar_t* wszText); + ~Label(); + + public: + virtual void SetText(const char* tokenName); + + virtual void SetText(const wchar_t* unicodeString, bool bClearUnlocalizedSymbol = false); + + virtual void GetText(OUT_Z_BYTECAP(bufferLen) char* textOut, int bufferLen); + virtual void GetText(OUT_Z_BYTECAP(bufLenInBytes) wchar_t* textOut, int bufLenInBytes); + + virtual void GetContentSize(int& wide, int& tall); + + enum Alignment + { + a_northwest = 0, + a_north, + a_northeast, + a_west, + a_center, + a_east, + a_southwest, + a_south, + a_southeast, + }; + + virtual void SetContentAlignment(Alignment alignment); + virtual void SetEnabled(bool state); + virtual void SetTextInset(int xInset, int yInset); + virtual void GetTextInset(int* xInset, int* yInset); + + virtual void SetFgColor(Color color); + virtual Color GetFgColor(); + + virtual void SetDisabledFgColor1(Color color); + virtual void SetDisabledFgColor2(Color color); + virtual Color GetDisabledFgColor1(); + virtual Color GetDisabledFgColor2(); + + enum EColorState + { + CS_NORMAL, + CS_DULL, + CS_BRIGHT, + }; + virtual void SetTextColorState(EColorState state); + + virtual void SetFont(HFont font); + virtual HFont GetFont(); + + virtual Panel* HasHotkey(wchar_t key); + virtual void SetHotkey(wchar_t key); + virtual wchar_t GetHotKey(); + + virtual void SetAssociatedControl(Panel* control); + + virtual int AddImage(IImage* image, int preOffset); + virtual void SetImageAtIndex(int index, IImage* image, int preOffset); + virtual void SetImagePreOffset(int index, int preOffset); + virtual IImage* GetImageAtIndex(int index); + virtual int GetImageCount(); + virtual void ClearImages(); + virtual void ResetToSimpleTextImage(); + virtual void SetImageBounds(int index, int x, int width); + + virtual TextImage* GetTextImage(); + + virtual int SetTextImageIndex(int newIndex); + + virtual bool RequestInfo(KeyValues* outputData); + virtual void SizeToContents(); + + enum Padding + { + Content = 8, + }; + + void SetWrap(bool bWrap); + void SetCenterWrap(bool bWrap); + + void SetAllCaps(bool bAllCaps); + + protected: + virtual void PerformLayout(); + virtual wchar_t CalculateHotkey(const char* text); + virtual wchar_t CalculateHotkey(const wchar_t* text); + virtual void ComputeAlignment(int& tx0, int& ty0, int& tx1, int& ty1); + virtual void Paint(); + MESSAGE_FUNC_PARAMS(OnSetText, "SetText", params); + virtual void DrawDashedLine(int x0, int y0, int x1, int y1, int dashLen, int gapLen); + virtual void OnRequestFocus(VPANEL subFocus, VPANEL defaultPanel); + MESSAGE_FUNC(OnHotkeyPressed, "Hotkey"); + virtual void OnMousePressed(MouseCode code); + virtual void OnSizeChanged(int wide, int tall); + + virtual void EnsureImageCapacity(int maxIndex); + + virtual void ApplySchemeSettings(IScheme* pScheme); + virtual void GetSettings(KeyValues* outResourceData); + virtual void ApplySettings(KeyValues* inResourceData); + virtual const char* GetDescription(void); + + MESSAGE_FUNC_PARAMS(OnDialogVariablesChanged, "DialogVariables", dialogVariables); + + void HandleAutoSizing(void); + + private: + void Init(); + + Alignment _contentAlignment; + TextImage* _textImage; + struct TImageInfo + { + IImage* image; + short offset; + short xpos; + short width; + }; + CUtlVector _imageDar; + + int _textInset[2]; + Color _disabledFgColor1; + Color _disabledFgColor2; + Color _associateColor; + int _textImageIndex; + EColorState _textColorState; + + PHandle _associate; + char* _associateName; + + char* _fontOverrideName; + + wchar_t _hotkey; + + bool m_bWrap; + bool m_bCenterWrap; + bool m_bAllCaps; + bool m_bAutoWideToContents; + bool m_bAutoWideDirty; + bool m_bUseProportionalInsets; + + }; + +} + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/gametrace.h b/SpyCustom/sdk/gametrace.h new file mode 100644 index 0000000..4a2192e --- /dev/null +++ b/SpyCustom/sdk/gametrace.h @@ -0,0 +1,147 @@ +#ifndef GAMETRACE_H +#define GAMETRACE_H +#ifdef _WIN32 +#pragma once +#endif + + +#include "cmodel.h" +#include "utlvector.h" +#include "ihandleentity.h" +#include "ispatialpartition.h" + +#if defined( CLIENT_DLL ) +class C_BaseEntity; +#else +class CBaseEntity; +#endif + + +class CGameTrace : public CBaseTrace +{ +public: + + bool DidHitWorld() const; + + bool DidHitNonWorldEntity() const; + + int GetEntityIndex() const; + + bool DidHit() const; + + bool isVisible() const; + +#if defined( ENGINE_DLL ) + void SetEdict(edict_t* pEdict); + edict_t* GetEdict() const; +#endif + + +public: + + float fractionleftsolid; + csurface_t surface; + int hitgroup; + short physicsbone; + +#if defined( CLIENT_DLL ) + C_BaseEntity* m_pEnt; +#else + IClientEntity* m_pEnt; +#endif + + int hitbox; + + CGameTrace() {} + +private: + CGameTrace(const CGameTrace& vOther); +}; + + +inline bool CGameTrace::DidHit() const +{ + return fraction < 1 || allsolid || startsolid; +} + + +typedef CGameTrace trace_t; + +#define TLD_DEF_LEAF_MAX 256 +#define TLD_DEF_ENTITY_MAX 1024 + +class CTraceListData : public IPartitionEnumerator +{ +public: + + CTraceListData(int nLeafMax = TLD_DEF_LEAF_MAX, int nEntityMax = TLD_DEF_ENTITY_MAX) + { + MEM_ALLOC_CREDIT(); + m_nLeafCount = 0; + m_aLeafList.SetSize(nLeafMax); + + m_nEntityCount = 0; + m_aEntityList.SetSize(nEntityMax); + } + + ~CTraceListData() + { + m_nLeafCount = 0; + m_aLeafList.RemoveAll(); + + m_nEntityCount = 0; + m_aEntityList.RemoveAll(); + } + + void Reset(void) + { + m_nLeafCount = 0; + m_nEntityCount = 0; + } + + bool IsEmpty(void) const { return (m_nLeafCount == 0 && m_nEntityCount == 0); } + + int LeafCount(void) const { return m_nLeafCount; } + int LeafCountMax(void) const { return m_aLeafList.Count(); } + void LeafCountReset(void) { m_nLeafCount = 0; } + + int EntityCount(void) const { return m_nEntityCount; } + int EntityCountMax(void) const { return m_aEntityList.Count(); } + void EntityCountReset(void) { m_nEntityCount = 0; } + + void AddLeaf(int iLeaf) + { + if (m_nLeafCount >= m_aLeafList.Count()) + { + DevMsg("CTraceListData: Max leaf count along ray exceeded!\n"); + m_aLeafList.AddMultipleToTail(m_aLeafList.Count()); + } + + m_aLeafList[m_nLeafCount] = iLeaf; + m_nLeafCount++; + } + + IterationRetval_t EnumElement(IHandleEntity* pHandleEntity) + { + if (m_nEntityCount >= m_aEntityList.Count()) + { + DevMsg("CTraceListData: Max entity count along ray exceeded!\n"); + m_aEntityList.AddMultipleToTail(m_aEntityList.Count()); + } + + m_aEntityList[m_nEntityCount] = pHandleEntity; + m_nEntityCount++; + + return ITERATION_CONTINUE; + } + +public: + + int m_nLeafCount; + CUtlVector m_aLeafList; + + int m_nEntityCount; + CUtlVector m_aEntityList; +}; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/generichash.h b/SpyCustom/sdk/generichash.h new file mode 100644 index 0000000..f8380b8 --- /dev/null +++ b/SpyCustom/sdk/generichash.h @@ -0,0 +1,84 @@ +#ifndef GENERICHASH_H +#define GENERICHASH_H + +#if defined(_WIN32) +#pragma once +#endif + +unsigned FASTCALL HashString(const char* pszKey); +unsigned FASTCALL HashStringCaseless(const char* pszKey); +unsigned FASTCALL HashStringCaselessConventional(const char* pszKey); +unsigned FASTCALL Hash4(const void* pKey); +unsigned FASTCALL Hash8(const void* pKey); +unsigned FASTCALL Hash12(const void* pKey); +unsigned FASTCALL Hash16(const void* pKey); +unsigned FASTCALL HashBlock(const void* pKey, unsigned size); + +unsigned FASTCALL HashInt(const int key); + +FORCEINLINE uint32 HashIntAlternate(uint32 n) +{ + n = (n + 0x7ed55d16) + (n << 12); + n = (n ^ 0xc761c23c) ^ (n >> 19); + n = (n + 0x165667b1) + (n << 5); + n = (n + 0xd3a2646c) ^ (n << 9); + n = (n + 0xfd7046c5) + (n << 3); + n = (n ^ 0xb55a4f09) ^ (n >> 16); + return n; +} + +inline unsigned HashIntConventional(const int n) +{ + unsigned hash = 0xAAAAAAAA + (n & 0xFF); + hash = (hash << 5) + hash + ((n >> 8) & 0xFF); + hash = (hash << 5) + hash + ((n >> 16) & 0xFF); + hash = (hash << 5) + hash + ((n >> 24) & 0xFF); + + return hash; + +} + +template +inline unsigned HashItem(const T& item) +{ + if (sizeof(item) == 4) + return Hash4(&item); + else if (sizeof(item) == 8) + return Hash8(&item); + else if (sizeof(item) == 12) + return Hash12(&item); + else if (sizeof(item) == 16) + return Hash16(&item); + else + return HashBlock(&item, sizeof(item)); +} + +template <> inline unsigned HashItem(const int& key) +{ + return HashInt(key); +} + +template <> inline unsigned HashItem(const unsigned& key) +{ + return HashInt((int)key); +} + +template<> inline unsigned HashItem(const char* const& pszKey) +{ + return HashString(pszKey); +} + +template<> inline unsigned HashItem(char* const& pszKey) +{ + return HashString(pszKey); +} + + +uint32 MurmurHash2(const void* key, int len, uint32 seed); + +uint32 MurmurHash2LowerCase(char const* pString, uint32 nSeed); + +uint64 MurmurHash64(const void* key, int len, uint32 seed); + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/globalvars_base.h b/SpyCustom/sdk/globalvars_base.h new file mode 100644 index 0000000..8820414 --- /dev/null +++ b/SpyCustom/sdk/globalvars_base.h @@ -0,0 +1,73 @@ +#ifndef GLOBALVARS_BASE_H +#define GLOBALVARS_BASE_H + +#ifdef _WIN32 +#pragma once +#endif + +class CSaveRestoreData; + +class CGlobalVarsBase +{ +public: + + CGlobalVarsBase(bool bIsClient); + + bool IsClient() const; + + int GetNetworkBase(int nTick, int nEntity); + +public: + + float realtime; + int framecount; + float absoluteframetime; + + float absoluteframestarttimestddev; + + float curtime; + + float frametime; + int maxClients; + + int tickcount; + + float interval_per_tick; + + float interpolation_amount; + int simTicksThisFrame; + + int network_protocol; + + CSaveRestoreData* pSaveData; + +private: + bool m_bClient; + + bool m_bRemoteClient; + + int nTimestampNetworkingBase; + int nTimestampRandomizeWindow; + +}; + +inline int CGlobalVarsBase::GetNetworkBase(int nTick, int nEntity) +{ + int nEntityMod = nEntity % nTimestampRandomizeWindow; + int nBaseTick = nTimestampNetworkingBase * (int)((nTick - nEntityMod) / nTimestampNetworkingBase); + return nBaseTick; +} + +inline CGlobalVarsBase::CGlobalVarsBase(bool bIsClient) : + m_bClient(bIsClient), + nTimestampNetworkingBase(100), + nTimestampRandomizeWindow(32) +{ +} + +inline bool CGlobalVarsBase::IsClient() const +{ + return m_bClient; +} + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/groundlink.h b/SpyCustom/sdk/groundlink.h new file mode 100644 index 0000000..9851839 --- /dev/null +++ b/SpyCustom/sdk/groundlink.h @@ -0,0 +1,14 @@ +#ifndef GROUNDLINK_H +#define GROUNDLINK_H +#ifdef _WIN32 +#pragma once +#endif + +struct groundlink_t +{ + EHANDLE entity; + groundlink_t* nextLink; + groundlink_t* prevLink; +}; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/htmlmessages.h b/SpyCustom/sdk/htmlmessages.h new file mode 100644 index 0000000..e633076 --- /dev/null +++ b/SpyCustom/sdk/htmlmessages.h @@ -0,0 +1,105 @@ +#ifndef HTMLMESSAGES_H +#define HTMLMESSAGES_H + +#ifdef _WIN32 +#pragma once +#endif + +enum EHTMLCommands +{ + eHTMLCommands_KeyUp, + eHTMLCommands_KeyDown, + eHTMLCommands_KeyChar, + eHTMLCommands_MouseDown, + eHTMLCommands_MouseUp, + eHTMLCommands_MouseDblClick, + eHTMLCommands_MouseWheel, + eHTMLCommands_MouseMove, + eHTMLCommands_MouseLeave, + + eHTMLCommands_BrowserCreate, + eHTMLCommands_BrowserRemove, + eHTMLCommands_BrowserErrorStrings, + eHTMLCommands_BrowserSize, + eHTMLCommands_BrowserPosition, + eHTMLCommands_PostURL, + eHTMLCommands_StopLoad, + eHTMLCommands_Reload, + eHTMLCommands_GoForward, + eHTMLCommands_GoBack, + eHTMLCommands_Copy, + eHTMLCommands_Paste, + eHTMLCommands_ExecuteJavaScript, + eHTMLCommands_SetFocus, + eHTMLCommands_HorizontalScrollBarSize, + eHTMLCommands_VerticalScrollBarSize, + eHTMLCommands_Find, + eHTMLCommands_StopFind, + eHTMLCommands_SetHorizontalScroll, + eHTMLCommands_SetVerticalScroll, + eHTMLCommands_SetZoomLevel, + eHTMLCommands_ViewSource, + eHTMLCommands_NeedsPaintResponse, + eHTMLCommands_AddHeader, + eHTMLCommands_GetZoom, + eHTMLCommands_FileLoadDialogResponse, + eHTMLCommands_LinkAtPosition, + eHTMLCommands_ZoomToElementAtPosition, + eHTMLCommands_SavePageToJPEG, + eHTMLCommands_JSAlert, + eHTMLCommands_JSConfirm, + eHTMLCommands_CanGoBackandForward, + eHTMLCommands_OpenSteamURL, + eHTMLCommands_SizePopup, + eHTMLCommands_SetCookie, + eHTMLCommands_SetTargetFrameRate, + eHTMLCommands_FullRepaint, + eHTMLCommands_SetPageScale, + eHTMLCommands_RequestFullScreen, + eHTMLCommands_ExitFullScreen, + eHTMLCommands_GetCookiesForURL, + eHTMLCommands_ZoomToCurrentlyFocusedNode, + eHTMLCommands_CloseFullScreenFlashIfOpen, + eHTMLCommands_PauseFullScreenFlashMovieIfOpen, + eHTMLCommands_GetFocusedNodeValue, + + eHTMLCommands_BrowserCreateResponse, + eHTMLCommands_BrowserReady, + eHTMLCommands_URLChanged, + eHTMLCommands_FinishedRequest, + eHTMLCommands_StartRequest, + eHTMLCommands_ShowPopup, + eHTMLCommands_HidePopup, + eHTMLCommands_OpenNewTab, + eHTMLCommands_PopupHTMLWindow, + eHTMLCommands_PopupHTMLWindowResponse, + eHTMLCommands_SetHTMLTitle, + eHTMLCommands_LoadingResource, + eHTMLCommands_StatusText, + eHTMLCommands_SetCursor, + eHTMLCommands_FileLoadDialog, + eHTMLCommands_ShowToolTip, + eHTMLCommands_UpdateToolTip, + eHTMLCommands_HideToolTip, + eHTMLCommands_SearchResults, + eHTMLCommands_Close, + eHTMLCommands_VerticalScrollBarSizeResponse, + eHTMLCommands_HorizontalScrollBarSizeResponse, + eHTMLCommands_GetZoomResponse, + eHTMLCommands_StartRequestResponse, + eHTMLCommands_NeedsPaint, + eHTMLCommands_LinkAtPositionResponse, + eHTMLCommands_ZoomToElementAtPositionResponse, + eHTMLCommands_JSDialogResponse, + eHTMLCommands_ScaleToValueResponse, + eHTMLCommands_RequestFullScreenResponse, + eHTMLCommands_GetCookiesForURLResponse, + eHTMLCommands_NodeGotFocus, + eHTMLCommands_SavePageToJPEGResponse, + eHTMLCommands_GetFocusedNodeValueResponse, + + eHTMLCommands_None, + +}; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/hud.h b/SpyCustom/sdk/hud.h new file mode 100644 index 0000000..948c784 --- /dev/null +++ b/SpyCustom/sdk/hud.h @@ -0,0 +1,171 @@ +#ifndef HUD_H +#define HUD_H +#ifdef _WIN32 +#pragma once +#endif + +#include "utlvector.h" +#include "utldict.h" +#include "convar.h" +#include "VGUI.h" +#include "Color.h" +#include "bitbuf.h" + +namespace vgui +{ + class IScheme; +} + +typedef struct wrect_s +{ + int left; + int right; + int top; + int bottom; +} wrect_t; + +class CHudTexture +{ +public: + CHudTexture(); + CHudTexture& operator =(const CHudTexture& src); + virtual ~CHudTexture(); + + int Width() const + { + return rc.right - rc.left; + } + + int Height() const + { + return rc.bottom - rc.top; + } + + void Precache(void); + + int EffectiveWidth(float flScale) const; + int EffectiveHeight(float flScale) const; + + void DrawSelf(int x, int y, const Color& clr) const; + void DrawSelf(int x, int y, int w, int h, const Color& clr) const; + void DrawSelfCropped(int x, int y, int cropx, int cropy, int cropw, int croph, Color clr) const; + void DrawSelfCropped(int x, int y, int cropx, int cropy, int cropw, int croph, int finalWidth, int finalHeight, Color clr) const; + + char szShortName[64]; + char szTextureFile[64]; + + bool bRenderUsingFont; + bool bPrecached; + char cCharacterInFont; + vgui::HFont hFont; + + int textureId; + float texCoords[4]; + + wrect_t rc; +}; + +#include "hudtexturehandle.h" + +class CHudElement; +class CHudRenderGroup; + +class CHud +{ +public: + static const int HUDPB_HORIZONTAL; + static const int HUDPB_VERTICAL; + static const int HUDPB_HORIZONTAL_INV; + +public: + CHud(); + ~CHud(); + + void Init(void); + void VidInit(void); + void Shutdown(void); + void LevelInit(void); + void LevelShutdown(void); + + void ResetHUD(void); + + void OnRestore(); + + void Think(); + + void ProcessInput(bool bActive); + void UpdateHud(bool bActive); + + void InitColors(vgui::IScheme* pScheme); + + void AddHudElement(CHudElement* pHudElement); + void RemoveHudElement(CHudElement* pHudElement); + CHudElement* FindElement(const char* pName); + + bool IsHidden(int iHudFlags); + + float GetSensitivity(); + float GetFOVSensitivityAdjust(); + + void DrawProgressBar(int x, int y, int width, int height, float percentage, Color& clr, unsigned char type); + void DrawIconProgressBar(int x, int y, CHudTexture* icon, CHudTexture* icon2, float percentage, Color& clr, int type); + + CHudTexture* GetIcon(const char* szIcon); + + CHudTexture* AddUnsearchableHudIconToList(CHudTexture& texture); + CHudTexture* AddSearchableHudIconToList(CHudTexture& texture); + + void RefreshHudTextures(); + + void MsgFunc_ResetHUD(bf_read& msg); + void MsgFunc_SendAudio(bf_read& msg); + + int LookupRenderGroupIndexByName(const char* pszGroupName); + bool LockRenderGroup(int iGroupIndex, CHudElement* pLocker = NULL); + bool UnlockRenderGroup(int iGroupIndex, CHudElement* pLocker = NULL); + bool IsRenderGroupLockedFor(CHudElement* pHudElement, int iGroupIndex); + int RegisterForRenderGroup(const char* pszGroupName); + int AddHudRenderGroup(const char* pszGroupName); + bool DoesRenderGroupExist(int iGroupIndex); + + void SetScreenShotTime(float flTime) { m_flScreenShotTime = flTime; } + +public: + + int m_iKeyBits; +#ifndef _XBOX + float m_flMouseSensitivity; + float m_flMouseSensitivityFactor; +#endif + float m_flFOVSensitivityAdjust; + + Color m_clrNormal; + Color m_clrCaution; + Color m_clrYellowish; + + CUtlVector< CHudElement* > m_HudList; + +private: + void InitFonts(); + + void SetupNewHudTexture(CHudTexture* t); + + bool m_bHudTexturesLoaded; + + CUtlDict< CHudTexture*, int > m_Icons; + + CUtlVector< const char* > m_RenderGroupNames; + CUtlMap< int, CHudRenderGroup* > m_RenderGroups; + + float m_flScreenShotTime; +}; + +extern CHud gHUD; + +extern vgui::HFont g_hFontTrebuchet24; + +void LoadHudTextures(CUtlDict< CHudTexture*, int >& list, const char* szFilenameWithoutExtension, const unsigned char* pICEKey); + +void GetHudSize(int& w, int& h); + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/hud_basechat.h b/SpyCustom/sdk/hud_basechat.h new file mode 100644 index 0000000..23fe063 --- /dev/null +++ b/SpyCustom/sdk/hud_basechat.h @@ -0,0 +1,405 @@ +#ifndef HUD_BASECHAT_H +#define HUD_BASECHAT_H +#ifdef _WIN32 +#pragma once +#endif + +#include "hudelement.h" +#include "Panel.h" +#include "vgui_basepanel.h" +#include "Frame.h" +#include "TextEntry.h" +#include "RichText.h" +#include "Button.h" +#include "CheckButton.h" + +class CBaseHudChatInputLine; +class CBaseHudChatEntry; +class CHudChatFilterPanel; + +namespace vgui +{ + class IScheme; +}; + +#define CHATLINE_NUM_FLASHES 8.0f +#define CHATLINE_FLASH_TIME 5.0f +#define CHATLINE_FADE_TIME 1.0f + +#define CHAT_HISTORY_FADE_TIME 0.25f +#define CHAT_HISTORY_IDLE_TIME 15.0f +#define CHAT_HISTORY_IDLE_FADE_TIME 2.5f +#define CHAT_HISTORY_ALPHA 127 + +extern Color g_ColorBlue; +extern Color g_ColorRed; +extern Color g_ColorGreen; +extern Color g_ColorDarkGreen; +extern Color g_ColorYellow; +extern Color g_ColorGrey; + +extern ConVar cl_showtextmsg; + +enum ChatFilters +{ + CHAT_FILTER_NONE = 0, + CHAT_FILTER_JOINLEAVE = 0x000001, + CHAT_FILTER_NAMECHANGE = 0x000002, + CHAT_FILTER_PUBLICCHAT = 0x000004, + CHAT_FILTER_SERVERMSG = 0x000008, + CHAT_FILTER_TEAMCHANGE = 0x000010, + CHAT_FILTER_ACHIEVEMENT = 0x000020, + +}; + + +enum TextColor +{ + COLOR_NORMAL = 1, + COLOR_USEOLDCOLORS = 2, + COLOR_PLAYERNAME = 3, + COLOR_LOCATION = 4, + COLOR_ACHIEVEMENT = 5, + COLOR_CUSTOM = 6, + COLOR_HEXCODE = 7, + COLOR_HEXCODE_ALPHA = 8, + COLOR_MAX +}; + +struct TextRange +{ + TextRange() { preserveAlpha = false; } + int start; + int end; + Color color; + bool preserveAlpha; +}; + +void StripEndNewlineFromString(char* str); +void StripEndNewlineFromString(wchar_t* str); + +char* ConvertCRtoNL(char* str); +wchar_t* ConvertCRtoNL(wchar_t* str); +wchar_t* ReadLocalizedString(bf_read& msg, OUT_Z_BYTECAP(outSizeInBytes) wchar_t* pOut, int outSizeInBytes, bool bStripNewline, OUT_Z_CAP(originalSize) char* originalString = NULL, int originalSize = 0); +wchar_t* ReadChatTextString(bf_read& msg, OUT_Z_BYTECAP(outSizeInBytes) wchar_t* pOut, int outSizeInBytes); +char* RemoveColorMarkup(char* str); + +inline wchar_t* CloneWString(const wchar_t* str) +{ + const int nLen = V_wcslen(str) + 1; + wchar_t* cloneStr = new wchar_t[nLen]; + const int nSize = nLen * sizeof(wchar_t); + V_wcsncpy(cloneStr, str, nSize); + return cloneStr; +} + +class CBaseHudChatLine : public vgui::RichText +{ + typedef vgui::RichText BaseClass; + +public: + CBaseHudChatLine(vgui::Panel* parent, const char* panelName); + ~CBaseHudChatLine(); + + void SetExpireTime(void); + + bool IsReadyToExpire(void); + + void Expire(void); + + float GetStartTime(void); + + int GetCount(void); + + virtual void ApplySchemeSettings(vgui::IScheme* pScheme); + + vgui::HFont GetFont() { return m_hFont; } + + Color GetTextColor(void) { return m_clrText; } + void SetNameLength(int iLength) { m_iNameLength = iLength; } + void SetNameColor(Color cColor) { m_clrNameColor = cColor; } + + virtual void PerformFadeout(void); + virtual void InsertAndColorizeText(wchar_t* buf, int clientIndex); + virtual void Colorize(int alpha = 255); + + + void SetNameStart(int iStart) { m_iNameStart = iStart; } + +protected: + int m_iNameLength; + vgui::HFont m_hFont; + + Color m_clrText; + Color m_clrNameColor; + + float m_flExpireTime; + + CUtlVector< TextRange > m_textRanges; + wchar_t* m_text; + + int m_iNameStart; + +private: + float m_flStartTime; + int m_nCount; + + vgui::HFont m_hFontMarlett; + + +private: + CBaseHudChatLine(const CBaseHudChatLine&); +}; + + +class CHudChatHistory : public vgui::RichText +{ + DECLARE_CLASS_SIMPLE(CHudChatHistory, vgui::RichText); +public: + + CHudChatHistory(vgui::Panel* pParent, const char* panelName); + + virtual void ApplySchemeSettings(vgui::IScheme* pScheme); +}; + +class CHudChatFilterButton : public vgui::Button +{ + DECLARE_CLASS_SIMPLE(CHudChatFilterButton, vgui::Button); + +public: + + CHudChatFilterButton(vgui::Panel* pParent, const char* pName, const char* pText); + + virtual void DoClick(void); +}; + +class CHudChatFilterCheckButton : public vgui::CheckButton +{ + DECLARE_CLASS_SIMPLE(CHudChatFilterCheckButton, vgui::CheckButton); + +public: + + CHudChatFilterCheckButton(vgui::Panel* pParent, const char* pName, const char* pText, int iFlag); + + int GetFilterFlag(void) { return m_iFlag; } + +private: + + int m_iFlag; +}; + + +class CBaseHudChat : public CHudElement, public vgui::EditablePanel +{ + DECLARE_CLASS_SIMPLE(CBaseHudChat, vgui::EditablePanel); +public: + DECLARE_MULTIPLY_INHERITED(); + + enum + { + CHAT_INTERFACE_LINES = 6, + MAX_CHARS_PER_LINE = 128 + }; + + CBaseHudChat(const char* pElementName); + + virtual void CreateChatInputLine(void); + virtual void CreateChatLines(void); + + virtual void Init(void); + + void LevelInit(const char* newmap); + void LevelShutdown(void); + + void MsgFunc_TextMsg(const char* pszName, int iSize, void* pbuf); + + virtual void Printf(int iFilter, PRINTF_FORMAT_STRING const char* fmt, ...); + virtual void ChatPrintf(int iPlayerIndex, int iFilter, PRINTF_FORMAT_STRING const char* fmt, ...) FMTFUNCTION(4, 5); + + virtual void StartMessageMode(int iMessageModeType); + virtual void StopMessageMode(void); + void Send(void); + + MESSAGE_FUNC(OnChatEntrySend, "ChatEntrySend"); + MESSAGE_FUNC(OnChatEntryStopMessageMode, "ChatEntryStopMessageMode"); + + virtual void ApplySchemeSettings(vgui::IScheme* pScheme); + virtual void Paint(void); + virtual void OnTick(void); + virtual void Reset(); +#ifdef _XBOX + virtual bool ShouldDraw(); +#endif + vgui::Panel* GetInputPanel(void); + + static int m_nLineCounter; + + virtual int GetChatInputOffset(void); + + virtual void FireGameEvent(IGameEvent* event); + + CHudChatHistory* GetChatHistory(); + + void FadeChatHistory(); + float m_flHistoryFadeTime; + float m_flHistoryIdleTime; + + virtual void MsgFunc_SayText(bf_read& msg); + virtual void MsgFunc_SayText2(bf_read& msg); + virtual void MsgFunc_TextMsg(bf_read& msg); + virtual void MsgFunc_VoiceSubtitle(bf_read& msg); + + + CBaseHudChatInputLine* GetChatInput(void) { return m_pChatInput; } + CHudChatFilterPanel* GetChatFilterPanel(void); + + virtual int GetFilterFlags(void) { return m_iFilterFlags; } + void SetFilterFlag(int iFilter); + + virtual Color GetDefaultTextColor(void); + virtual Color GetTextColorForClient(TextColor colorNum, int clientIndex); + virtual Color GetClientColor(int clientIndex); + + virtual int GetFilterForString(const char* pString); + + virtual const char* GetDisplayedSubtitlePlayerName(int clientIndex); + + bool IsVoiceSubtitle(void) { return m_bEnteringVoice; } + void SetVoiceSubtitleState(bool bState) { m_bEnteringVoice = bState; } + int GetMessageMode(void) { return m_nMessageMode; } + + void SetCustomColor(Color colNew) { m_ColorCustom = colNew; } + void SetCustomColor(const char* pszColorName); + +protected: + CBaseHudChatLine* FindUnusedChatLine(void); + + CBaseHudChatInputLine* m_pChatInput; + CBaseHudChatLine* m_ChatLine; + int m_iFontHeight; + + CHudChatHistory* m_pChatHistory; + + CHudChatFilterButton* m_pFiltersButton; + CHudChatFilterPanel* m_pFilterPanel; + + Color m_ColorCustom; + +private: + void Clear(void); + + int ComputeBreakChar(int width, const char* text, int textlen); + + int m_nMessageMode; + + int m_nVisibleHeight; + + vgui::HFont m_hChatFont; + + int m_iFilterFlags; + bool m_bEnteringVoice; + +}; + +class CBaseHudChatEntry : public vgui::TextEntry +{ + typedef vgui::TextEntry BaseClass; +public: + CBaseHudChatEntry(vgui::Panel* parent, char const* panelName, vgui::Panel* pChat) + : BaseClass(parent, panelName) + { + SetCatchEnterKey(true); + SetAllowNonAsciiCharacters(true); + SetDrawLanguageIDAtLeft(true); + m_pHudChat = pChat; + } + + virtual void ApplySchemeSettings(vgui::IScheme* pScheme) + { + BaseClass::ApplySchemeSettings(pScheme); + + SetPaintBorderEnabled(false); + } + + virtual void OnKeyCodeTyped(vgui::KeyCode code) + { + if (code == KEY_ENTER || code == KEY_PAD_ENTER || code == KEY_ESCAPE) + { + if (code != KEY_ESCAPE) + { + if (m_pHudChat) + { + PostMessage(m_pHudChat, new KeyValues("ChatEntrySend")); + } + } + + if (m_pHudChat) + { + PostMessage(m_pHudChat, new KeyValues("ChatEntryStopMessageMode")); + } + } + else if (code == KEY_TAB) + { + return; + } + else + { + BaseClass::OnKeyCodeTyped(code); + } + } + +private: + vgui::Panel* m_pHudChat; +}; + +class CBaseHudChatInputLine : public vgui::Panel +{ + typedef vgui::Panel BaseClass; + +public: + CBaseHudChatInputLine(vgui::Panel* parent, char const* panelName); + + void SetPrompt(const wchar_t* prompt); + void ClearEntry(void); + void SetEntry(const wchar_t* entry); + void GetMessageText(OUT_Z_BYTECAP(buffersizebytes) wchar_t* buffer, int buffersizebytes); + + virtual void PerformLayout(); + virtual void ApplySchemeSettings(vgui::IScheme* pScheme); + + vgui::Panel* GetInputPanel(void); + virtual vgui::VPANEL GetCurrentKeyFocus() { return m_pInput->GetVPanel(); } + + virtual void Paint() + { + BaseClass::Paint(); + } + + vgui::Label* GetPrompt(void) { return m_pPrompt; } + +protected: + vgui::Label* m_pPrompt; + CBaseHudChatEntry* m_pInput; +}; + + +class CHudChatFilterPanel : public vgui::EditablePanel +{ + DECLARE_CLASS_SIMPLE(CHudChatFilterPanel, vgui::EditablePanel); + +public: + + CHudChatFilterPanel(vgui::Panel* pParent, const char* pName); + + virtual void ApplySchemeSettings(vgui::IScheme* pScheme); + MESSAGE_FUNC_PTR(OnFilterButtonChecked, "CheckButtonChecked", panel); + + CBaseHudChat* GetChatParent(void) { return dynamic_cast (GetParent()); } + + virtual void SetVisible(bool state); + +private: + +}; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/hud_element_helper.h b/SpyCustom/sdk/hud_element_helper.h new file mode 100644 index 0000000..e1d8c7d --- /dev/null +++ b/SpyCustom/sdk/hud_element_helper.h @@ -0,0 +1,75 @@ +#ifndef HUD_ELEMENT_HELPER_H +#define HUD_ELEMENT_HELPER_H +#ifdef _WIN32 +#pragma once +#endif + +class CHudElement; + +class CHudElementHelper +{ +public: + static CHudElementHelper* m_sHelpers; + static void CreateAllElements(void); + +public: + CHudElementHelper(CHudElement* (*pfnCreate)(void), int depth); + + CHudElementHelper* GetNext(void); + +private: + CHudElementHelper* m_pNext; + CHudElement* (*m_pfnCreate)(void); + + int m_iDepth; +}; + +#define DECLARE_HUDELEMENT( className ) \ + static CHudElement *Create_##className( void ) \ + { \ + return new className( #className ); \ + }; \ + static CHudElementHelper g_##className##_Helper( Create_##className, 50 ); + +#define DECLARE_HUDELEMENT_DEPTH( className, depth ) \ + static CHudElement *Create_##className( void ) \ + { \ + return new className( #className ); \ + }; \ + static CHudElementHelper g_##className##_Helper( Create_##className, depth ); + +#define DECLARE_NAMED_HUDELEMENT( className, panelName ) \ + static CHudElement *Create_##panelName( void ) \ + { \ + return new className( #panelName ); \ + }; \ + static CHudElementHelper g_##panelName##_Helper( Create_##panelName, 50 ); + +#define GET_HUDELEMENT( className ) \ + ( className *)gHUD.FindElement( #className ) + +#define GET_NAMED_HUDELEMENT( className, panelName ) \ + ( className *)gHUD.FindElement( #panelName ) + + +#define DECLARE_MULTIPLY_INHERITED() \ + void *operator new( size_t stAllocateBlock ) \ + { \ + return CHudElement::operator new ( stAllocateBlock ); \ + } \ + void* operator new( size_t stAllocateBlock, int nBlockUse, const char *pFileName, int nLine ) \ + { \ + return CHudElement::operator new ( stAllocateBlock, nBlockUse, pFileName, nLine ); \ + } \ + void operator delete( void *pMem ) \ + { \ + CHudElement::operator delete ( pMem ); \ + } \ + void operator delete( void *pMem, int nBlockUse, const char *pFileName, int nLine ) \ + { \ + CHudElement::operator delete ( pMem, nBlockUse, pFileName, nLine ); \ + } + +#define IMPLEMENT_OPERATORS_NEW_AND_DELETE DECLARE_MULTIPLY_INHERITED + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/hudelement.h b/SpyCustom/sdk/hudelement.h new file mode 100644 index 0000000..743a4b6 --- /dev/null +++ b/SpyCustom/sdk/hudelement.h @@ -0,0 +1,124 @@ +#if !defined( HUDELEMENT_H ) +#define HUDELEMENT_H +#ifdef _WIN32 +#pragma once +#endif + +#include "hud.h" +#include "hud_element_helper.h" +#include "networkvar.h" +#include "GameEventListener.h" +#include "memdbgon.h" +#undef new + +class CHudElement : public CGameEventListener +{ +public: + DECLARE_CLASS_NOBASE(CHudElement); + + CHudElement(const char* pElementName); + virtual ~CHudElement(); + + virtual void Init(void) { return; } + + virtual void VidInit(void) { return; } + + virtual void LevelInit(void) { return; }; + virtual void LevelShutdown(void) { return; }; + + virtual void Reset(void) { return; } + + virtual void ProcessInput(void) { return; } + virtual const char* GetName(void) const { return m_pElementName; }; + + virtual bool ShouldDraw(void); + + virtual bool IsActive(void) { return m_bActive; }; + virtual void SetActive(bool bActive); + + virtual void SetHiddenBits(int iBits); + + bool IsParentedToClientDLLRootPanel() const; + void SetParentedToClientDLLRootPanel(bool parented); + + void* operator new(size_t stAllocateBlock) + { + Assert(stAllocateBlock != 0); + void* pMem = malloc(stAllocateBlock); + memset(pMem, 0, stAllocateBlock); + return pMem; + } + + void* operator new(size_t stAllocateBlock, int nBlockUse, const char* pFileName, int nLine) + { + Assert(stAllocateBlock != 0); + void* pMem = MemAlloc_Alloc(stAllocateBlock, pFileName, nLine); + memset(pMem, 0, stAllocateBlock); + return pMem; + } + + void operator delete(void* pMem) + { +#if defined( _DEBUG ) + int size = _msize(pMem); + memset(pMem, 0xcd, size); +#endif + free(pMem); + } + + void operator delete(void* pMem, int nBlockUse, const char* pFileName, int nLine) + { + operator delete(pMem); + } + + void SetNeedsRemove(bool needsremove); + + void RegisterForRenderGroup(const char* pszName); + void UnregisterForRenderGroup(const char* pszGroupName); + void HideLowerPriorityHudElementsInGroup(const char* pszGroupName); + void UnhideLowerPriorityHudElementsInGroup(const char* pszGroupName); + + virtual int GetRenderGroupPriority(); + +public: + + virtual void FireGameEvent(IGameEvent* event) {} + +public: + + bool m_bActive; + +protected: + int m_iHiddenBits; + +private: + const char* m_pElementName; + bool m_bNeedsRemove; + bool m_bIsParentedToClientDLLRootPanel; + + CUtlVector< int > m_HudRenderGroups; +}; + +#include "utlpriorityqueue.h" + +inline bool RenderGroupLessFunc(CHudElement* const& lhs, CHudElement* const& rhs) +{ + return (lhs->GetRenderGroupPriority() < rhs->GetRenderGroupPriority()); +} + +class CHudRenderGroup +{ +public: + CHudRenderGroup() + { + m_pLockingElements.SetLessFunc(RenderGroupLessFunc); + bHidden = false; + } + + bool bHidden; + CUtlPriorityQueue< CHudElement* > m_pLockingElements; +}; + +#include "memdbgoff.h" + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/hudtexturehandle.h b/SpyCustom/sdk/hudtexturehandle.h new file mode 100644 index 0000000..d07d1c7 --- /dev/null +++ b/SpyCustom/sdk/hudtexturehandle.h @@ -0,0 +1,52 @@ +#ifndef HUDTEXTUREHANDLE_H +#define HUDTEXTUREHANDLE_H +#ifdef _WIN32 +#pragma once +#endif + +class CHudTexture; + +class CHudTextureHandle +{ +public: + CHudTextureHandle() + { + m_pValue = NULL; + } + + const CHudTextureHandle& operator=(const CHudTexture* t) + { + m_pValue = (CHudTexture*)t; + return *this; + } + + void Set(CHudTexture* t) + { + m_pValue = t; + } + + CHudTexture* Get() + { + return m_pValue; + } + + operator CHudTexture* () + { + return m_pValue; + } + + operator CHudTexture* () const + { + return m_pValue; + } + + CHudTexture* operator->() const + { + return m_pValue; + } + +private: + CHudTexture* m_pValue; +}; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/ichromehtmlwrapper.h b/SpyCustom/sdk/ichromehtmlwrapper.h new file mode 100644 index 0000000..1e66869 --- /dev/null +++ b/SpyCustom/sdk/ichromehtmlwrapper.h @@ -0,0 +1,52 @@ +#ifndef ICHROMEHTMLWRAPPER_H +#define ICHROMEHTMLWRAPPER_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "htmlmessages.h" + +class CUtlString; +class IHTMLResponses; +struct HTMLCommandBuffer_t; + + +class IHTMLChromeController +{ +public: + virtual ~IHTMLChromeController() {} + + virtual bool Init(const char* pchHTMLCacheDir, const char* pchCookiePath) = 0; + virtual void Shutdown() = 0; + virtual bool RunFrame() = 0; + + + virtual void SetWebCookie(const char* pchHostname, const char* pchKey, const char* pchValue, const char* pchPath, RTime32 nExpires = 0) = 0; + virtual void GetWebCookiesForURL(CUtlString* pstrValue, const char* pchURL, const char* pchName) = 0; + + virtual void SetClientBuildID(uint64 ulBuildID) = 0; + + virtual bool BHasPendingMessages() = 0; + + virtual void CreateBrowser(IHTMLResponses* pBrowser, bool bPopupWindow, const char* pchUserAgentIdentifier) = 0; + virtual void RemoveBrowser(IHTMLResponses* pBrowser) = 0; + + virtual void WakeThread() = 0; + virtual HTMLCommandBuffer_t* GetFreeCommandBuffer(EHTMLCommands eCmd, int iBrowser) = 0; + virtual void PushCommand(HTMLCommandBuffer_t*) = 0; + +#ifdef DBGFLAG_VALIDATE + virtual void Validate(CValidator& validator, const char* pchName) = 0; + + virtual bool ChromePrepareForValidate() = 0; + virtual bool ChromeResumeFromValidate() = 0; +#endif + + virtual void SetCefThreadTargetFrameRate(uint32 nFPS) = 0; +}; + +#define CHROMEHTML_CONTROLLER_INTERFACE_VERSION "ChromeHTML_Controller_001" + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/iclassmap.h b/SpyCustom/sdk/iclassmap.h new file mode 100644 index 0000000..071a0ed --- /dev/null +++ b/SpyCustom/sdk/iclassmap.h @@ -0,0 +1,24 @@ +#ifndef ICLASSMAP_H +#define ICLASSMAP_H +#ifdef _WIN32 +#pragma once +#endif + +class C_BaseEntity; +typedef C_BaseEntity* (*DISPATCHFUNCTION)(void); + +class IClassMap +{ +public: + virtual ~IClassMap() {} + + virtual void Add(const char* mapname, const char* classname, int size, DISPATCHFUNCTION factory = 0) = 0; + virtual char const* Lookup(const char* classname) = 0; + virtual C_BaseEntity* CreateEntity(const char* mapname) = 0; + virtual int GetClassSize(const char* classname) = 0; +}; + +extern IClassMap& GetClassMap(); + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/iclient.h b/SpyCustom/sdk/iclient.h new file mode 100644 index 0000000..7334022 --- /dev/null +++ b/SpyCustom/sdk/iclient.h @@ -0,0 +1,141 @@ +#ifndef ICLIENT_H +#define ICLIENT_H +#ifdef _WIN32 +#pragma once +#endif + +#include "inetmsghandler.h" +#include "platform.h" +#include "userid.h" +#include "utlvector.h" + +class IServer; +class INetMessage; +struct NetMessageCvar_t; +class CMsg_CVars; + +enum CrossPlayPlatform_t +{ + CROSSPLAYPLATFORM_UNKNOWN = 0, + CROSSPLAYPLATFORM_PC, + CROSSPLAYPLATFORM_X360, + CROSSPLAYPLATFORM_PS3, + + CROSSPLAYPLATFORM_LAST = CROSSPLAYPLATFORM_PS3, +}; + +inline bool IsCrossPlayPlatformAConsole(CrossPlayPlatform_t platform) +{ + return (platform == CROSSPLAYPLATFORM_X360) || (platform == CROSSPLAYPLATFORM_PS3); +} + +#if defined( _GAMECONSOLE ) +# if defined( PLATFORM_X360 ) +# define CROSSPLAYPLATFORM_THISPLATFORM CROSSPLAYPLATFORM_X360 +# elif defined( PLATFORM_PS3 ) +# define CROSSPLAYPLATFORM_THISPLATFORM CROSSPLAYPLATFORM_PS3 +# else +#pragma message( "Unknown console, please update this platform definition" ) +# define CROSSPLAYPLATFORM_THISPLATFORM CROSSPLAYPLATFORM_UNKNOWN +# endif +#else +# define CROSSPLAYPLATFORM_THISPLATFORM CROSSPLAYPLATFORM_PC +#endif + +struct HltvReplayParams_t +{ + HltvReplayParams_t() + { + m_nPrimaryTargetEntIndex = 0; + m_flPlaybackSpeed = 1.0f; + m_flDelay = 10.0f; + m_flStopAt = 0.0f; + m_flSlowdownBeginAt = 0; + m_flSlowdownEndAt = 0; + m_flSlowdownRate = 1.0f; + m_bAbortCurrentReplay = false; + } + int m_nPrimaryTargetEntIndex; + float m_flDelay; + float m_flStopAt; + float m_flPlaybackSpeed; + float m_flSlowdownBeginAt; + float m_flSlowdownEndAt; + float m_flSlowdownRate; + bool m_bAbortCurrentReplay; +}; + +abstract_class IClient : public INetChannelHandler +{ +public: + virtual ~IClient() {} + + virtual void Connect(const char* szName, int nUserID, INetChannel * pNetChannel, bool bFakePlayer, CrossPlayPlatform_t clientPlatform, const CMsg_CVars * pVecCvars = NULL) = 0; + + virtual void Inactivate(void) = 0; + + virtual void Reconnect(void) = 0; + + virtual void Disconnect(const char* reason) = 0; + + virtual bool ChangeSplitscreenUser(int nSplitScreenUserSlot) = 0; + + virtual int GetPlayerSlot() const = 0; + virtual int GetUserID() const = 0; + virtual const USERID_t GetNetworkID() const = 0; + virtual const char* GetClientName() const = 0; + virtual INetChannel* GetNetChannel() = 0; + virtual IServer* GetServer() = 0; + virtual const char* GetUserSetting(const char* cvar) const = 0; + virtual const char* GetNetworkIDString() const = 0; + + virtual void SetRate(int nRate, bool bForce) = 0; + virtual int GetRate(void) const = 0; + + virtual void SetUpdateRate(float fUpdateRate, bool bForce) = 0; + virtual float GetUpdateRate(void) const = 0; + + virtual void Clear(void) = 0; + + virtual int GetMaxAckTickCount() const = 0; + + virtual bool ExecuteStringCommand(const char* s) = 0; + virtual bool SendNetMsg(INetMessage& msg, bool bForceReliable = false, bool bVoice = false) = 0; + virtual void ClientPrintf(const char* fmt, ...) = 0; + +virtual bool IsConnected(void) const = 0; +virtual bool IsSpawned(void) const = 0; +virtual bool IsActive(void) const = 0; +virtual bool IsFakeClient(void) const = 0; +virtual bool IsHLTV(void) const = 0; +#if defined( REPLAY_ENABLED ) +virtual bool IsReplay(void) const = 0; +#endif +virtual bool IsHearingClient(int index) const = 0; +virtual bool IsProximityHearingClient(int index) const = 0; + +virtual void SetMaxRoutablePayloadSize(int nMaxRoutablePayloadSize) = 0; + +virtual bool IsSplitScreenUser(void) const = 0; + +virtual bool CheckConnect(void) = 0; + +virtual bool IsLowViolenceClient(void) const = 0; + +virtual IClient* GetSplitScreenOwner() = 0; + +virtual int GetNumPlayers() = 0; + +virtual bool IsHumanPlayer() const = 0; + +virtual CrossPlayPlatform_t GetClientPlatform() const = 0; + +virtual bool StartHltvReplay(const HltvReplayParams_t& params) = 0; +virtual void StopHltvReplay() = 0; +virtual int GetHltvReplayDelay() = 0; +virtual const char* GetHltvReplayStatus()const { return ""; } +virtual bool CanStartHltvReplay() = 0; +virtual void ResetReplayRequestTime() = 0; +}; + +#endif diff --git a/SpyCustom/sdk/icliententity.h b/SpyCustom/sdk/icliententity.h new file mode 100644 index 0000000..df91710 --- /dev/null +++ b/SpyCustom/sdk/icliententity.h @@ -0,0 +1,73 @@ +#ifndef ICLIENTENTITY_H +#define ICLIENTENTITY_H +#ifdef _WIN32 +#pragma once +#endif + + +#include "iclientrenderable.h" +#include "iclientnetworkable.h" +#include "iclientthinkable.h" +#include "string_t.h" + + + +struct Ray_t; +class CGameTrace; +typedef CGameTrace trace_t; +class CMouthInfo; +class IClientEntityInternal; +struct SpatializationInfo_t; + + + +abstract_class IClientEntity : public IClientUnknown, public IClientRenderable, public IClientNetworkable, public IClientThinkable +{ +public: + + + virtual void Release(void) = 0; + virtual void Unknown000(void) = 0; + const Vector& GetAbsOrigin() + { + typedef Vector& (__thiscall* GetAbsOriginFn)(void*); + return getvfunc(this, 10)(this); + } + + const Vector& GetAbsAngles(void) + { + typedef Vector& (__thiscall* GetAbsAnglesFn)(void*); + return getvfunc(this, 11)(this); + } + + const void SetModelIndex(int index) + { + typedef void (__thiscall* SetModelIndexFn)(void*, int); + return getvfunc(this, 75)(this, index); + } + + void preDataUpdate(int updateType) + { + typedef void(__thiscall* SetModelIndexFn)(void*, int); + return getvfunc(this, 2)(this + sizeof(uintptr_t) * 2, updateType); + } + + virtual CMouthInfo* GetMouth(void) = 0; + + virtual bool GetSoundSpatialization(SpatializationInfo_t& info) = 0; + + virtual bool IsBlurred(void) = 0; +#if 0 + virtual string_t GetModelName(void) const = 0; +#endif + + int GetIndex() + { + return *(int*)((uintptr_t)this + 0x64); + } + + +}; + + +#endif diff --git a/SpyCustom/sdk/icliententityinternal.h b/SpyCustom/sdk/icliententityinternal.h new file mode 100644 index 0000000..05ac3b1 --- /dev/null +++ b/SpyCustom/sdk/icliententityinternal.h @@ -0,0 +1,18 @@ +#ifndef ICLIENTENTITYINTERNAL_H +#define ICLIENTENTITYINTERNAL_H +#ifdef _WIN32 +#pragma once +#endif + +#include "icliententity.h" +#include "clientleafsystem.h" + +class ClientClass; + + +typedef CBaseHandle ClientEntityHandle_t; +typedef unsigned short SpatialPartitionHandle_t; + + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/icliententitylist.h b/SpyCustom/sdk/icliententitylist.h new file mode 100644 index 0000000..4d3989b --- /dev/null +++ b/SpyCustom/sdk/icliententitylist.h @@ -0,0 +1,37 @@ +#if !defined( ICLIENTENTITYLIST_H ) +#define ICLIENTENTITYLIST_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "interface.h" + +class IClientEntity; +class ClientClass; +class IClientNetworkable; +class CBaseHandle; +class IClientUnknown; + + +class IClientEntityList +{ +public: + virtual IClientNetworkable * GetClientNetworkable(int entnum) = 0; + virtual IClientNetworkable* GetClientNetworkableFromHandle(CBaseHandle hEnt) = 0; + virtual IClientUnknown* GetClientUnknownFromHandle(CBaseHandle hEnt) = 0; + + virtual IClientEntity* GetClientEntity(int entnum) = 0; + virtual IClientEntity* GetClientEntityFromHandle(CBaseHandle hEnt) = 0; + + virtual int NumberOfEntities(bool bIncludeNonNetworkable) = 0; + + virtual int GetHighestEntityIndex(void) = 0; + + virtual void SetMaxEntities(int maxents) = 0; + virtual int GetMaxEntities() = 0; +}; + +#define VCLIENTENTITYLIST_INTERFACE_VERSION "VClientEntityList003" + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/iclientmode.h b/SpyCustom/sdk/iclientmode.h new file mode 100644 index 0000000..886c5a2 --- /dev/null +++ b/SpyCustom/sdk/iclientmode.h @@ -0,0 +1,112 @@ +#ifndef ICLIENTMODE_H +#define ICLIENTMODE_H + +#include "VGUI.h" +#include "client_virtualreality.h" + +class CViewSetup; +class C_BaseEntity; +class C_BasePlayer; +class CUserCmd; + +namespace vgui +{ + class Panel; + class AnimationController; +} + +enum +{ + MM_NONE = 0, + MM_SAY, + MM_SAY_TEAM, +}; + +abstract_class IClientMode +{ + public: + + virtual ~IClientMode() {} + + virtual void InitViewport() = 0; + + virtual void Init() = 0; + + virtual void VGui_Shutdown() = 0; + + virtual void Shutdown() = 0; + + virtual void Enable() = 0; + + virtual void Disable() = 0; + + virtual void Layout() = 0; + + virtual vgui::Panel* GetViewport() = 0; + + virtual vgui::AnimationController* GetViewportAnimationController() = 0; + + virtual void ProcessInput(bool bActive) = 0; + + virtual bool ShouldDrawDetailObjects() = 0; + virtual bool ShouldDrawEntity(C_BaseEntity* pEnt) = 0; + virtual bool ShouldDrawLocalPlayer(C_BasePlayer* pPlayer) = 0; + virtual bool ShouldDrawParticles() = 0; + + virtual bool ShouldDrawFog(void) = 0; + + virtual void OverrideView(CViewSetup* pSetup) = 0; + virtual int KeyInput(int down, ButtonCode_t keynum, const char* pszCurrentBinding) = 0; + virtual void StartMessageMode(int iMessageModeType) = 0; + virtual vgui::Panel* GetMessagePanel() = 0; + virtual void OverrideMouseInput(float* x, float* y) = 0; + virtual bool CreateMove(float flInputSampleTime, CUserCmd* cmd) = 0; + + virtual void LevelInit(const char* newmap) = 0; + virtual void LevelShutdown(void) = 0; + + virtual bool ShouldDrawViewModel(void) = 0; + virtual bool ShouldDrawCrosshair(void) = 0; + + virtual void AdjustEngineViewport(int& x, int& y, int& width, int& height) = 0; + + virtual void PreRender(CViewSetup* pSetup) = 0; + + virtual void PostRender(void) = 0; + + virtual void PostRenderVGui() = 0; + + virtual void ActivateInGameVGuiContext(vgui::Panel* pPanel) = 0; + virtual void DeactivateInGameVGuiContext() = 0; + virtual float GetViewModelFOV(void) = 0; + + virtual bool CanRecordDemo(char* errorMsg, int length) const = 0; + + virtual void ComputeVguiResConditions(KeyValues* pkvConditions) = 0; + + virtual wchar_t* GetServerName() = 0; + virtual void SetServerName(wchar_t* name) = 0; + virtual wchar_t* GetMapName() = 0; + virtual void SetMapName(wchar_t* name) = 0; + + virtual bool DoPostScreenSpaceEffects(const CViewSetup* pSetup) = 0; + + virtual void DisplayReplayMessage(const char* pLocalizeName, float flDuration, bool bUrgent, + const char* pSound, bool bDlg) = 0; + + public: + + virtual void Update() = 0; + + virtual bool ShouldBlackoutAroundHUD() = 0; + + virtual HeadtrackMovementMode_t ShouldOverrideHeadtrackControl() = 0; + + virtual bool IsInfoPanelAllowed() = 0; + virtual void InfoPanelDisplayed() = 0; + virtual bool IsHTMLInfoPanelAllowed() = 0; +}; + +extern IClientMode* g_pClientMode; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/iclientnetworkable.h b/SpyCustom/sdk/iclientnetworkable.h new file mode 100644 index 0000000..a9261f6 --- /dev/null +++ b/SpyCustom/sdk/iclientnetworkable.h @@ -0,0 +1,63 @@ +#ifndef ICLIENTNETWORKABLE_H +#define ICLIENTNETWORKABLE_H +#ifdef _WIN32 +#pragma once +#endif + + +#include "iclientunknown.h" +#include "bitbuf.h" + + +class IClientEntity; +class ClientClass; + + +enum ShouldTransmitState_t +{ + SHOULDTRANSMIT_START = 0, + + SHOULDTRANSMIT_END +}; + +enum DataUpdateType_t +{ + DATA_UPDATE_CREATED = 0, +DATA_UPDATE_DATATABLE_CHANGED, +}; + +abstract_class IClientNetworkable +{ +public: + virtual IClientUnknown * GetIClientUnknown() = 0; + + virtual void Release() = 0; + + virtual ClientClass* GetClientClass() = 0; + + virtual void NotifyShouldTransmit(ShouldTransmitState_t state) = 0; + + + + virtual void OnPreDataChanged(DataUpdateType_t updateType) = 0; + virtual void OnDataChanged(DataUpdateType_t updateType) = 0; + + virtual void PreDataUpdate(DataUpdateType_t updateType) = 0; + virtual void PostDataUpdate(DataUpdateType_t updateType) = 0; + + virtual void __unkn(void) = 0; + virtual bool IsDormant(void) = 0; + + virtual int entindex(void) const = 0; + + virtual void ReceiveMessage(int classID, bf_read& msg) = 0; + + virtual void* GetDataTableBasePtr() = 0; + + virtual void SetDestroyedOnRecreateEntities(void) = 0; + + virtual void OnDataUnchangedInPVS() = 0; +}; + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/iclientrenderable.h b/SpyCustom/sdk/iclientrenderable.h new file mode 100644 index 0000000..ccb2860 --- /dev/null +++ b/SpyCustom/sdk/iclientrenderable.h @@ -0,0 +1,223 @@ +#ifndef ICLIENTRENDERABLE_H +#define ICLIENTRENDERABLE_H +#ifdef _WIN32 +#pragma once +#endif + +#include "mathlib.h" +#include "interface.h" +#include "iclientunknown.h" +#include "client_render_handle.h" +#include "ivmodelrender.h" + +struct model_t; +struct matrix3x4_t; + +extern void DefaultRenderBoundsWorldspace(IClientRenderable* pRenderable, Vector& absMins, Vector& absMaxs); + +typedef unsigned short ClientShadowHandle_t; + +enum +{ + CLIENTSHADOW_INVALID_HANDLE = (ClientShadowHandle_t)~0 +}; + +enum ShadowType_t +{ + SHADOWS_NONE = 0, + SHADOWS_SIMPLE, + SHADOWS_RENDER_TO_TEXTURE, + SHADOWS_RENDER_TO_TEXTURE_DYNAMIC, + SHADOWS_RENDER_TO_DEPTH_TEXTURE, +}; + + +abstract_class IPVSNotify +{ +public: + virtual void OnPVSStatusChanged(bool bInPVS) = 0; +}; + +struct RenderableInstance_t +{ + uint8 m_nAlpha; +}; + +abstract_class IClientRenderable +{ +public: + virtual IClientUnknown * GetIClientUnknown() = 0; + + virtual Vector const& GetRenderOrigin(void) = 0; + virtual QAngle const& GetRenderAngles(void) = 0; + virtual bool ShouldDraw(void) = 0; + virtual bool IsTransparent(void) = 0; + virtual bool UsesPowerOfTwoFrameBufferTexture() = 0; + virtual bool UsesFullFrameBufferTexture() = 0; + + virtual ClientShadowHandle_t GetShadowHandle() const = 0; + + virtual ClientRenderHandle_t& RenderHandle() = 0; + + virtual const model_t* GetModel() const = 0; + virtual int DrawModel(int flags) = 0; + + virtual int GetBody() = 0; + + virtual void ComputeFxBlend() = 0; + virtual int GetFxBlend(void) = 0; + + virtual void GetColorModulation(float* color) = 0; + + virtual bool LODTest() = 0; + + virtual bool SetupBones(matrix3x4_t* pBoneToWorldOut, int nMaxBones, int boneMask, float currentTime) = 0; + + virtual void SetupWeights(const matrix3x4_t* pBoneToWorld, int nFlexWeightCount, float* pFlexWeights, float* pFlexDelayedWeights) = 0; + virtual void DoAnimationEvents(void) = 0; + + virtual IPVSNotify* GetPVSNotifyInterface() = 0; + + virtual void GetRenderBounds(Vector& mins, Vector& maxs) = 0; + + virtual void GetRenderBoundsWorldspace(Vector& mins, Vector& maxs) = 0; + + virtual void GetShadowRenderBounds(Vector& mins, Vector& maxs, ShadowType_t shadowType) = 0; + + virtual bool ShouldReceiveProjectedTextures(int flags) = 0; + + virtual bool GetShadowCastDistance(float* pDist, ShadowType_t shadowType) const = 0; + virtual bool GetShadowCastDirection(Vector* pDirection, ShadowType_t shadowType) const = 0; + + virtual bool IsShadowDirty() = 0; + virtual void MarkShadowDirty(bool bDirty) = 0; + + virtual IClientRenderable* GetShadowParent() = 0; + virtual IClientRenderable* FirstShadowChild() = 0; + virtual IClientRenderable* NextShadowPeer() = 0; + + virtual ShadowType_t ShadowCastType() = 0; + + virtual void CreateModelInstance() = 0; + virtual ModelInstanceHandle_t GetModelInstance() = 0; + + virtual const matrix3x4_t& RenderableToWorldTransform() = 0; + + virtual int LookupAttachment(const char* pAttachmentName) = 0; + virtual bool GetAttachment(int number, Vector& origin, QAngle& angles) = 0; + virtual bool GetAttachment(int number, matrix3x4_t& matrix) = 0; + + virtual float* GetRenderClipPlane(void) = 0; + + virtual int GetSkin() = 0; + + virtual bool IsTwoPass(void) = 0; + + virtual void OnThreadedDrawSetup() = 0; + + virtual bool UsesFlexDelayedWeights() = 0; + + virtual void RecordToolMessage() = 0; + + virtual bool IgnoresZBuffer(void) const = 0; +}; + + +abstract_class CDefaultClientRenderable : public IClientUnknown, public IClientRenderable +{ +public: + CDefaultClientRenderable() + { + m_hRenderHandle = INVALID_CLIENT_RENDER_HANDLE; + } + + virtual const Vector & GetRenderOrigin(void) = 0; + virtual const QAngle& GetRenderAngles(void) = 0; + virtual const matrix3x4_t& RenderableToWorldTransform() = 0; + virtual bool ShouldDraw(void) = 0; + virtual void OnThreadedDrawSetup() {} + virtual int GetRenderFlags(void) { return 0; } + virtual ClientShadowHandle_t GetShadowHandle() const + { + return CLIENTSHADOW_INVALID_HANDLE; + } + + virtual ClientRenderHandle_t& RenderHandle() + { + return m_hRenderHandle; + } + + virtual int GetBody() { return 0; } + virtual int GetSkin() { return 0; } + virtual bool UsesFlexDelayedWeights() { return false; } + + virtual const model_t* GetModel() const { return NULL; } + virtual int DrawModel(int flags) { return 0; } + virtual bool LODTest() { return true; } + virtual bool SetupBones(matrix3x4_t* pBoneToWorldOut, int nMaxBones, int boneMask, float currentTime) { return true; } + virtual void SetupWeights(const matrix3x4_t* pBoneToWorld, int nFlexWeightCount, float* pFlexWeights, float* pFlexDelayedWeights) {} + virtual void DoAnimationEvents(void) {} + virtual IPVSNotify* GetPVSNotifyInterface() { return NULL; } + virtual void GetRenderBoundsWorldspace(Vector& absMins, Vector& absMaxs) { DefaultRenderBoundsWorldspace(this, absMins, absMaxs); } + + virtual void GetColorModulation(float* color) + { + Assert(color); + color[0] = color[1] = color[2] = 1.0f; + } + + virtual bool ShouldReceiveProjectedTextures(int flags) + { + return false; + } + + virtual bool GetShadowCastDistance(float* pDist, ShadowType_t shadowType) const { return false; } + virtual bool GetShadowCastDirection(Vector* pDirection, ShadowType_t shadowType) const { return false; } + + virtual void GetShadowRenderBounds(Vector& mins, Vector& maxs, ShadowType_t shadowType) + { + GetRenderBounds(mins, maxs); + } + + virtual bool IsShadowDirty() { return false; } + virtual void MarkShadowDirty(bool bDirty) {} + virtual IClientRenderable* GetShadowParent() { return NULL; } + virtual IClientRenderable* FirstShadowChild() { return NULL; } + virtual IClientRenderable* NextShadowPeer() { return NULL; } + virtual ShadowType_t ShadowCastType() { return SHADOWS_NONE; } + virtual void CreateModelInstance() {} + virtual ModelInstanceHandle_t GetModelInstance() { return MODEL_INSTANCE_INVALID; } + + virtual int LookupAttachment(const char* pAttachmentName) { return -1; } + virtual bool GetAttachment(int number, Vector& origin, QAngle& angles) { return false; } + virtual bool GetAttachment(int number, matrix3x4_t& matrix) { return false; } + virtual bool ComputeLightingOrigin(int nAttachmentIndex, Vector modelLightingCenter, const matrix3x4_t& matrix, Vector& transformedLightingCenter) { return false; } + + virtual float* GetRenderClipPlane() { return NULL; } + + virtual void RecordToolMessage() {} + virtual bool ShouldDrawForSplitScreenUser(int nSlot) { return true; } + virtual uint8 OverrideAlphaModulation(uint8 nAlpha) { return nAlpha; } + virtual uint8 OverrideShadowAlphaModulation(uint8 nAlpha) { return nAlpha; } + virtual void* GetClientModelRenderable() { return 0; } + + public: + virtual void SetRefEHandle(const CBaseHandle& handle) { Assert(false); } + virtual const CBaseHandle& GetRefEHandle() const { Assert(false); return *((CBaseHandle*)0); } + + virtual IClientUnknown* GetIClientUnknown() { return this; } + virtual ICollideable* GetCollideable() { return 0; } + virtual IClientRenderable* GetClientRenderable() { return this; } + virtual IClientNetworkable* GetClientNetworkable() { return 0; } + virtual IClientEntity* GetIClientEntity() { return 0; } + virtual C_BaseEntity* GetBaseEntity() { return 0; } + virtual IClientThinkable* GetClientThinkable() { return 0; } + virtual void* GetClientAlphaProperty() { return 0; } + + + public: + ClientRenderHandle_t m_hRenderHandle; +}; + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/iclientshadowmgr.h b/SpyCustom/sdk/iclientshadowmgr.h new file mode 100644 index 0000000..2baad21 --- /dev/null +++ b/SpyCustom/sdk/iclientshadowmgr.h @@ -0,0 +1,99 @@ +#ifndef ICLIENTSHADOWMGR_H +#define ICLIENTSHADOWMGR_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "igamesystem.h" +#include "icliententityinternal.h" +#include "ishadowmgr.h" +#include "ivrenderview.h" +#include "itoolentity.h" + +#include "IGameSystem.h" + +struct FlashlightState_t; + + +enum ShadowReceiver_t +{ + SHADOW_RECEIVER_BRUSH_MODEL = 0, + SHADOW_RECEIVER_STATIC_PROP, + SHADOW_RECEIVER_STUDIO_MODEL, +}; + + +class IClientShadowMgr : public IGameSystemPerFrame +{ +public: + virtual ClientShadowHandle_t CreateShadow(ClientEntityHandle_t entity, int nEntIndex, int flags, void* pSplitScreenBits = 0) = 0; + virtual void DestroyShadow(ClientShadowHandle_t handle) = 0; + + virtual ClientShadowHandle_t CreateFlashlight(const FlashlightState_t& lightState) = 0; + virtual void UpdateFlashlightState(ClientShadowHandle_t shadowHandle, const FlashlightState_t& lightState) = 0; + virtual void DestroyFlashlight(ClientShadowHandle_t handle) = 0; + + virtual ClientShadowHandle_t CreateProjection(const FlashlightState_t& lightState) = 0; + virtual void UpdateProjectionState(ClientShadowHandle_t shadowHandle, const FlashlightState_t& lightState) = 0; + virtual void DestroyProjection(ClientShadowHandle_t handle) = 0; + + virtual void UpdateProjectedTexture(ClientShadowHandle_t handle, bool force = false) = 0; + + virtual void AddToDirtyShadowList(ClientShadowHandle_t handle, bool force = false) = 0; + virtual void AddToDirtyShadowList(IClientRenderable* pRenderable, bool force = false) = 0; + + virtual void AddShadowToReceiver(ClientShadowHandle_t handle, + IClientRenderable* pRenderable, ShadowReceiver_t type) = 0; + + virtual void RemoveAllShadowsFromReceiver( + IClientRenderable* pRenderable, ShadowReceiver_t type) = 0; + + virtual void ComputeShadowTextures(const CViewSetup& view, int leafCount, WorldListLeafData_t* pLeafList) = 0; + + virtual void UnlockAllShadowDepthTextures() = 0; + + virtual void RenderShadowTexture(int w, int h) = 0; + + virtual void SetShadowDirection(const Vector& dir) = 0; + virtual const Vector& GetShadowDirection() const = 0; + + virtual void SetShadowColor(unsigned char r, unsigned char g, unsigned char b) = 0; + virtual void SetShadowDistance(float flMaxDistance) = 0; + virtual void SetShadowBlobbyCutoffArea(float flMinArea) = 0; + virtual void SetFalloffBias(ClientShadowHandle_t handle, unsigned char ucBias) = 0; + + virtual void MarkRenderToTextureShadowDirty(ClientShadowHandle_t handle) = 0; + + virtual void AdvanceFrame() = 0; + + virtual void SetFlashlightTarget(ClientShadowHandle_t shadowHandle, EHANDLE targetEntity) = 0; + + virtual void SetFlashlightLightWorld(ClientShadowHandle_t shadowHandle, bool bLightWorld) = 0; + + virtual void SetShadowsDisabled(bool bDisabled) = 0; + + virtual void ComputeShadowDepthTextures(const CViewSetup& pView, bool bSetup = false) = 0; + + virtual void DrawVolumetrics(const CViewSetup& view) = 0; + + virtual void SetShadowFromWorldLightsEnabled(bool bEnable) = 0; + + virtual void DrawDeferredShadows(const CViewSetup& view, int leafCount, WorldListLeafData_t* pLeafList) = 0; + + virtual void InitRenderTargets() = 0; + + virtual void ReprojectShadows() = 0; + + virtual void UpdateSplitscreenLocalPlayerShadowSkip() = 0; + + virtual void GetFrustumExtents(ClientShadowHandle_t handle, Vector& vecMin, Vector& vecMax) = 0; + + virtual void ShutdownRenderTargets(void) = 0; +}; + + + +extern IClientShadowMgr* g_pClientShadowMgr; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/iclientthinkable.h b/SpyCustom/sdk/iclientthinkable.h new file mode 100644 index 0000000..076614a --- /dev/null +++ b/SpyCustom/sdk/iclientthinkable.h @@ -0,0 +1,29 @@ +#ifndef ICLIENTTHINKABLE_H +#define ICLIENTTHINKABLE_H +#ifdef _WIN32 +#pragma once +#endif + + +#include "iclientunknown.h" + + +class CClientThinkHandlePtr; +typedef CClientThinkHandlePtr* ClientThinkHandle_t; + + +abstract_class IClientThinkable +{ +public: + virtual IClientUnknown * GetIClientUnknown() = 0; + + virtual void ClientThink() = 0; + + virtual ClientThinkHandle_t GetThinkHandle() = 0; + virtual void SetThinkHandle(ClientThinkHandle_t hThink) = 0; + + virtual void Release() = 0; +}; + + +#endif diff --git a/SpyCustom/sdk/iclientunknown.h b/SpyCustom/sdk/iclientunknown.h new file mode 100644 index 0000000..1c8b84b --- /dev/null +++ b/SpyCustom/sdk/iclientunknown.h @@ -0,0 +1,32 @@ +#ifndef ICLIENTUNKNOWN_H +#define ICLIENTUNKNOWN_H +#ifdef _WIN32 +#pragma once +#endif + + +#include "platform.h" +#include "ihandleentity.h" + +class IClientNetworkable; +class C_BaseEntity; +class IClientRenderable; +class ICollideable; +class IClientEntity; +class IClientThinkable; + + + +abstract_class IClientUnknown : public IHandleEntity +{ +public: + virtual ICollideable * GetCollideable() = 0; + virtual IClientNetworkable* GetClientNetworkable() = 0; + virtual IClientRenderable* GetClientRenderable() = 0; + virtual IClientEntity* GetIClientEntity() = 0; + virtual C_BaseEntity* GetBaseEntity() = 0; + virtual IClientThinkable* GetClientThinkable() = 0; +}; + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/iclientvirtualreality.h b/SpyCustom/sdk/iclientvirtualreality.h new file mode 100644 index 0000000..116ab04 --- /dev/null +++ b/SpyCustom/sdk/iclientvirtualreality.h @@ -0,0 +1,35 @@ +#ifndef ICLIENTVIRTUALREALITY_H +#define ICLIENTVIRTUALREALITY_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "interface.h" +#include "refcount.h" +#include "IAppSystem.h" + +#define CLIENTVIRTUALREALITY_INTERFACE_VERSION "ClientVirtualReality001" + + + +abstract_class IClientVirtualReality : public IAppSystem +{ +public: + virtual ~IClientVirtualReality() {} + + virtual bool Connect(CreateInterfaceFn factory) = 0; + virtual void Disconnect() = 0; + virtual void* QueryInterface(const char* pInterfaceName) = 0; + virtual InitReturnVal_t Init() = 0; + virtual void Shutdown() = 0; + + virtual void DrawMainMenu() = 0; +}; + + + +extern IClientVirtualReality* g_pClientVR; + + +#endif diff --git a/SpyCustom/sdk/icommandline.h b/SpyCustom/sdk/icommandline.h new file mode 100644 index 0000000..8643bab --- /dev/null +++ b/SpyCustom/sdk/icommandline.h @@ -0,0 +1,45 @@ +#ifndef TIER0_ICOMMANDLINE_H +#define TIER0_ICOMMANDLINE_H +#ifdef _WIN32 +#pragma once +#endif + +#include "platform.h" + + +abstract_class ICommandLine +{ +public: + virtual void CreateCmdLine(const char* commandline) = 0; + virtual void CreateCmdLine(int argc, char** argv) = 0; + virtual const char* GetCmdLine(void) const = 0; + + virtual const char* CheckParm(const char* psz, const char** ppszValue = 0) const = 0; + virtual bool HasParm(const char* psz) const = 0; + virtual void RemoveParm(const char* parm) = 0; + virtual void AppendParm(const char* pszParm, const char* pszValues) = 0; + + virtual const char* ParmValue(const char* psz, const char* pDefaultVal = 0) const = 0; + virtual int ParmValue(const char* psz, int nDefaultVal) const = 0; + virtual float ParmValue(const char* psz, float flDefaultVal) const = 0; + + virtual int ParmCount() const = 0; + virtual int FindParm(const char* psz) const = 0; + virtual const char* GetParm(int nIndex) const = 0; + + virtual void SetParm(int nIndex, char const* pNewParm) = 0; + + virtual const char** GetParms() const = 0; +}; + +PLATFORM_INTERFACE ICommandLine* CommandLine(); + + +PLATFORM_INTERFACE const tchar* Plat_GetCommandLine(); +#ifndef _WIN32 +PLATFORM_INTERFACE void Plat_SetCommandLine(const char* cmdLine); +#endif +PLATFORM_INTERFACE const char* Plat_GetCommandLineA(); + + +#endif diff --git a/SpyCustom/sdk/iconvar.h b/SpyCustom/sdk/iconvar.h new file mode 100644 index 0000000..473d8f6 --- /dev/null +++ b/SpyCustom/sdk/iconvar.h @@ -0,0 +1,71 @@ +#ifndef ICONVAR_H +#define ICONVAR_H + +#if _WIN32 +#pragma once +#endif + +#include "dbg.h" +#include "platform.h" +#include "strtools.h" + + +class IConVar; +class CCommand; + + +#define FCVAR_NONE 0 + +#define FCVAR_UNREGISTERED (1<<0) +#define FCVAR_DEVELOPMENTONLY (1<<1) +#define FCVAR_GAMEDLL (1<<2) +#define FCVAR_CLIENTDLL (1<<3) +#define FCVAR_HIDDEN (1<<4) + +#define FCVAR_PROTECTED (1<<5) +#define FCVAR_SPONLY (1<<6) +#define FCVAR_ARCHIVE (1<<7) +#define FCVAR_NOTIFY (1<<8) +#define FCVAR_USERINFO (1<<9) +#define FCVAR_CHEAT (1<<14) + +#define FCVAR_PRINTABLEONLY (1<<10) +#define FCVAR_UNLOGGED (1<<11) +#define FCVAR_NEVER_AS_STRING (1<<12) + +#define FCVAR_REPLICATED (1<<13) +#define FCVAR_DEMO (1<<16) +#define FCVAR_DONTRECORD (1<<17) +#define FCVAR_RELOAD_MATERIALS (1<<20) +#define FCVAR_RELOAD_TEXTURES (1<<21) + +#define FCVAR_NOT_CONNECTED (1<<22) +#define FCVAR_MATERIAL_SYSTEM_THREAD (1<<23) +#define FCVAR_ARCHIVE_XBOX (1<<24) + +#define FCVAR_ACCESSIBLE_FROM_THREADS (1<<25) + +#define FCVAR_SERVER_CAN_EXECUTE (1<<28) +#define FCVAR_SERVER_CANNOT_QUERY (1<<29) +#define FCVAR_CLIENTCMD_CAN_EXECUTE (1<<30) +#define FCVAR_MATERIAL_THREAD_MASK ( FCVAR_RELOAD_MATERIALS | FCVAR_RELOAD_TEXTURES | FCVAR_MATERIAL_SYSTEM_THREAD ) + +typedef void (*FnChangeCallback_t)(IConVar* var, const char* pOldValue, float flOldValue); + + +abstract_class IConVar +{ +public: + virtual void SetValue(const char* pValue) = 0; + virtual void SetValue(float flValue) = 0; + virtual void SetValue(int nValue) = 0; + + virtual void SetValue(Color value) = 0; + virtual const char* GetName(void) const = 0; + virtual const char* GetBaseName(void) const = 0; + virtual bool IsFlagSet(int nFlag) const = 0; + virtual int GetSplitScreenPlayerSlot() const = 0; +}; + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/icvar.h b/SpyCustom/sdk/icvar.h new file mode 100644 index 0000000..5c85e73 --- /dev/null +++ b/SpyCustom/sdk/icvar.h @@ -0,0 +1,67 @@ +#ifndef ICVAR_H +#define ICVAR_H +#ifdef _WIN32 +#pragma once +#endif + +#include "IAppSystem.h" +#include "iconvar.h" + +class ConCommandBase; +class ConCommand; +class ConVar; +class Color; + + +typedef int CVarDLLIdentifier_t; + + +abstract_class IConsoleDisplayFunc +{ +public: + virtual void ColorPrint(const Color & clr, const char* pMessage) = 0; + virtual void Print(const char* pMessage) = 0; + virtual void DPrint(const char* pMessage) = 0; +}; + + +#define CVAR_QUERY_INTERFACE_VERSION "VCvarQuery001" +abstract_class ICvarQuery : public IAppSystem +{ +public: + virtual bool AreConVarsLinkable(const ConVar * child, const ConVar * parent) = 0; +}; + + +class ICvar : public IAppSystem +{ +public: + virtual CVarDLLIdentifier_t AllocateDLLIdentifier() = 0; + virtual void RegisterConCommand(ConCommandBase* pCommandBase) = 0; + virtual void UnregisterConCommand(ConCommandBase* pCommandBase) = 0; + virtual void UnregisterConCommands(CVarDLLIdentifier_t id) = 0; + virtual const char* GetCommandLineValue(const char* pVariableName) = 0; + virtual ConCommandBase* FindCommandBase(const char* name) = 0; + virtual const ConCommandBase* FindCommandBase(const char* name) const = 0; + virtual ConVar* FindVar(const char* var_name) = 0; + virtual const ConVar* FindVar(const char* var_name) const = 0; + virtual ConCommand* FindCommand(const char* name) = 0; + virtual const ConCommand* FindCommand(const char* name) const = 0; + virtual void InstallGlobalChangeCallback(FnChangeCallback_t callback) = 0; + virtual void RemoveGlobalChangeCallback(FnChangeCallback_t callback) = 0; + virtual void CallGlobalChangeCallbacks(ConVar* var, const char* pOldString, float flOldValue) = 0; + virtual void InstallConsoleDisplayFunc(IConsoleDisplayFunc* pDisplayFunc) = 0; + virtual void RemoveConsoleDisplayFunc(IConsoleDisplayFunc* pDisplayFunc) = 0; + virtual void ConsoleColorPrintf(const Color& clr, const char* pFormat, ...) const = 0; + virtual void ConsolePrintf(const char* pFormat, ...) const = 0; + virtual void ConsoleDPrintf(const char* pFormat, ...) const = 0; + virtual void RevertFlaggedConVars(int nFlag) = 0; +}; + +#define CVAR_INTERFACE_VERSION "VEngineCvar004" + + +extern ICvar* g_pCVar; + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/idatacache.h b/SpyCustom/sdk/idatacache.h new file mode 100644 index 0000000..7ee9bb4 --- /dev/null +++ b/SpyCustom/sdk/idatacache.h @@ -0,0 +1,363 @@ +#ifndef IDATACACHE_H +#define IDATACACHE_H + +#ifdef _WIN32 +#pragma once +#endif + + +#include "dbg.h" +#include "IAppSystem.h" + +class IDataCache; + +#define DATACACHE_INTERFACE_VERSION "VDataCache003" + +typedef uint32 DataCacheClientID_t; + + +FORWARD_DECLARE_HANDLE(memhandle_t); +typedef memhandle_t DataCacheHandle_t; +#define DC_INVALID_HANDLE ((DataCacheHandle_t)0) + +struct DataCacheLimits_t +{ + DataCacheLimits_t(unsigned _nMaxBytes = (unsigned)-1, unsigned _nMaxItems = (unsigned)-1, unsigned _nMinBytes = 0, unsigned _nMinItems = 0) + : nMaxBytes(_nMaxBytes), + nMaxItems(_nMaxItems), + nMinBytes(_nMinBytes), + nMinItems(_nMinItems) + { + } + + unsigned nMaxBytes; + unsigned nMaxItems; + + unsigned nMinBytes; + unsigned nMinItems; +}; + +struct DataCacheStatus_t +{ + unsigned nBytes; + unsigned nItems; + + unsigned nBytesLocked; + unsigned nItemsLocked; + + unsigned nFindRequests; + unsigned nFindHits; +}; + +enum DataCacheOptions_t +{ + DC_TRACE_ACTIVITY = (1 << 0), + DC_FORCE_RELOCATE = (1 << 1), + DC_ALWAYS_MISS = (1 << 2), + DC_VALIDATE = (1 << 3), +}; + + +enum DataCacheReportType_t +{ + DC_SUMMARY_REPORT, + DC_DETAIL_REPORT, + DC_DETAIL_REPORT_LRU, +}; + + +enum DataCacheNotificationType_t +{ + DC_NONE, + + DC_AGE_DISCARD, + + DC_FLUSH_DISCARD, + + DC_REMOVED, + + DC_RELOCATE, + + DC_PRINT_INF0, +}; + +struct DataCacheNotification_t +{ + DataCacheNotificationType_t type; + const char* pszSectionName; + DataCacheClientID_t clientId; + const void* pItemData; + unsigned nItemSize; +}; + +const int DC_MAX_CLIENT_NAME = 15; +const int DC_MAX_ITEM_NAME = 511; + +enum DataCacheRemoveResult_t +{ + DC_OK, + DC_NOT_FOUND, + DC_LOCKED, +}; + +enum DataCacheAddFlags_t +{ + DCAF_LOCK = (1 << 0), + DCAF_DEFAULT = 0, +}; + + + +abstract_class IDataCacheSection +{ +public: + virtual IDataCache * GetSharedCache() = 0; + virtual const char* GetName() = 0; + + virtual void SetLimits(const DataCacheLimits_t& limits) = 0; + virtual void SetOptions(unsigned options) = 0; + + + virtual void GetStatus(DataCacheStatus_t* pStatus, DataCacheLimits_t* pLimits = NULL) = 0; + + + virtual void EnsureCapacity(unsigned nBytes, unsigned nItems = 1) = 0; + + + virtual bool Add(DataCacheClientID_t clientId, const void* pItemData, unsigned size, DataCacheHandle_t* pHandle) = 0; + + virtual DataCacheHandle_t Find(DataCacheClientID_t clientId) = 0; + + + virtual DataCacheRemoveResult_t Remove(DataCacheHandle_t handle, const void** ppItemData, unsigned* pItemSize = NULL, bool bNotify = false) = 0; + DataCacheRemoveResult_t Remove(DataCacheHandle_t handle, bool bNotify = false) { return Remove(handle, NULL, NULL, bNotify); } + + + virtual bool IsPresent(DataCacheHandle_t handle) = 0; + + + virtual void* Lock(DataCacheHandle_t handle) = 0; + + + virtual int Unlock(DataCacheHandle_t handle) = 0; + + + virtual void* Get(DataCacheHandle_t handle, bool bFrameLock = false) = 0; + virtual void* GetNoTouch(DataCacheHandle_t handle, bool bFrameLock = false) = 0; + + virtual int BeginFrameLocking() = 0; + virtual bool IsFrameLocking() = 0; + virtual void* FrameLock(DataCacheHandle_t handle) = 0; + virtual int EndFrameLocking() = 0; + virtual int* GetFrameUnlockCounterPtr() = 0; + + + virtual int GetLockCount(DataCacheHandle_t handle) = 0; + virtual int BreakLock(DataCacheHandle_t handle) = 0; + + + virtual bool Touch(DataCacheHandle_t handle) = 0; + + + virtual bool Age(DataCacheHandle_t handle) = 0; + + + virtual unsigned Flush(bool bUnlockedOnly = true, bool bNotify = true) = 0; + + + virtual unsigned Purge(unsigned nBytes) = 0; + + + virtual void OutputReport(DataCacheReportType_t reportType = DC_SUMMARY_REPORT) = 0; + + virtual void UpdateSize(DataCacheHandle_t handle, unsigned int nNewSize) = 0; + + + virtual void LockMutex() = 0; + virtual void UnlockMutex() = 0; + + virtual bool AddEx(DataCacheClientID_t clientId, const void* pItemData, unsigned size, unsigned flags, DataCacheHandle_t* pHandle) = 0; +}; + + +abstract_class IDataCacheClient +{ +public: + virtual bool HandleCacheNotification(const DataCacheNotification_t & notification) = 0; + + + virtual bool GetItemName(DataCacheClientID_t clientId, const void* pItem, char* pDest, unsigned nMaxLen) = 0; +}; + +class CDefaultDataCacheClient : public IDataCacheClient +{ +public: + virtual bool HandleCacheNotification(const DataCacheNotification_t& notification) + { + switch (notification.type) + { + case DC_AGE_DISCARD: + case DC_FLUSH_DISCARD: + case DC_REMOVED: + default: + Assert(0); + return false; + } + return false; + } + + virtual bool GetItemName(DataCacheClientID_t clientId, const void* pItem, char* pDest, unsigned nMaxLen) + { + return false; + } +}; + + +abstract_class IDataCache : public IAppSystem +{ +public: + virtual void SetSize(int nMaxBytes) = 0; + virtual void SetOptions(unsigned options) = 0; + virtual void SetSectionLimits(const char* pszSectionName, const DataCacheLimits_t& limits) = 0; + + + virtual void GetStatus(DataCacheStatus_t* pStatus, DataCacheLimits_t* pLimits = NULL) = 0; + + + virtual IDataCacheSection* AddSection(IDataCacheClient* pClient, const char* pszSectionName, const DataCacheLimits_t& limits = DataCacheLimits_t(), bool bSupportFastFind = false) = 0; + + + virtual void RemoveSection(const char* pszClientName, bool bCallFlush = true) = 0; + void RemoveSection(IDataCacheSection* pSection, bool bCallFlush = true) { if (pSection) RemoveSection(pSection->GetName()); } + + + virtual IDataCacheSection* FindSection(const char* pszClientName) = 0; + + + virtual unsigned Purge(unsigned nBytes) = 0; + + + virtual unsigned Flush(bool bUnlockedOnly = true, bool bNotify = true) = 0; + + + virtual void OutputReport(DataCacheReportType_t reportType = DC_SUMMARY_REPORT, const char* pszSection = NULL) = 0; +}; + +template< class STORAGE_TYPE, class CREATE_PARAMS, class LOCK_TYPE = STORAGE_TYPE* > +class CManagedDataCacheClient : public CDefaultDataCacheClient +{ +public: + typedef CManagedDataCacheClient CCacheClientBaseClass; + + CManagedDataCacheClient() + : m_pCache(NULL) + { + } + + void Init(IDataCache* pSharedCache, const char* pszSectionName, const DataCacheLimits_t& limits = DataCacheLimits_t(), bool bSupportFastFind = false) + { + if (!m_pCache) + { + m_pCache = pSharedCache->AddSection(this, pszSectionName, limits, bSupportFastFind); + } + } + + void Shutdown() + { + if (m_pCache) + { + m_pCache->GetSharedCache()->RemoveSection(m_pCache); + m_pCache = NULL; + } + } + + LOCK_TYPE CacheGet(DataCacheHandle_t handle, bool bFrameLock = true) + { + return (LOCK_TYPE)(((STORAGE_TYPE*)m_pCache->Get(handle, bFrameLock))->GetData()); + } + + LOCK_TYPE CacheGetNoTouch(DataCacheHandle_t handle) + { + return (LOCK_TYPE)(((STORAGE_TYPE*)m_pCache->GetNoTouch(handle))->GetData()); + } + + LOCK_TYPE CacheLock(DataCacheHandle_t handle) + { + return (LOCK_TYPE)(((STORAGE_TYPE*)m_pCache->Lock(handle))->GetData()); + } + + int CacheUnlock(DataCacheHandle_t handle) + { + return m_pCache->Unlock(handle); + } + + void CacheTouch(DataCacheHandle_t handle) + { + m_pCache->Touch(handle); + } + + void CacheRemove(DataCacheHandle_t handle, bool bNotify = true) + { + m_pCache->Remove(handle, bNotify); + } + + void CacheFlush() + { + m_pCache->Flush(); + } + + DataCacheHandle_t CacheCreate(const CREATE_PARAMS& createParams, unsigned flags = DCAF_DEFAULT) + { + m_pCache->EnsureCapacity(STORAGE_TYPE::EstimatedSize(createParams)); + STORAGE_TYPE* pStore = STORAGE_TYPE::CreateResource(createParams); + DataCacheHandle_t handle; + m_pCache->AddEx((DataCacheClientID_t)pStore, pStore, pStore->Size(), flags, &handle); + return handle; + } + + void CacheLockMutex() + { + m_pCache->LockMutex(); + } + + void CacheUnlockMutex() + { + m_pCache->UnlockMutex(); + } + + bool HandleCacheNotification(const DataCacheNotification_t& notification) + { + switch (notification.type) + { + case DC_AGE_DISCARD: + case DC_FLUSH_DISCARD: + case DC_REMOVED: + { + STORAGE_TYPE* p = (STORAGE_TYPE*)notification.clientId; + p->DestroyResource(); + } + return true; + default: + return CDefaultDataCacheClient::HandleCacheNotification(notification); + } + } + + +protected: + + ~CManagedDataCacheClient() + { + Shutdown(); + } + + IDataCacheSection* GetCacheSection() + { + return m_pCache; + } + +private: + IDataCacheSection* m_pCache; + +}; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/iefx.h b/SpyCustom/sdk/iefx.h new file mode 100644 index 0000000..9285f15 --- /dev/null +++ b/SpyCustom/sdk/iefx.h @@ -0,0 +1,49 @@ +#if !defined( IEFX_H ) +#define IEFX_H +#ifdef _WIN32 +#pragma once +#endif + +#include "interface.h" +#include "vector.h" +#include "dlight.h" + +struct model_t; +struct dlight_t; +class IMaterial; + +#define MAX_DLIGHTS 32 + +abstract_class IVEfx +{ +public: + virtual int Draw_DecalIndexFromName(char* name) = 0; + + virtual void DecalShoot(int textureIndex, int entity, + const model_t* model, const Vector& model_origin, const QAngle& model_angles, + const Vector& position, const Vector* saxis, int flags) = 0; + + virtual void DecalColorShoot(int textureIndex, int entity, + const model_t* model, const Vector& model_origin, const QAngle& model_angles, + const Vector& position, const Vector* saxis, int flags, const color32& rgbaColor) = 0; + + virtual void PlayerDecalShoot(IMaterial* material, void* userdata, int entity, const model_t* model, + const Vector& model_origin, const Vector& model_angles, + const Vector& position, const Vector* saxis, int flags, const color32& rgbaColor) = 0; + + virtual dlight_t* CL_AllocDlight(int key) = 0; + + virtual dlight_t* CL_AllocElight(int key) = 0; + + virtual int CL_GetActiveDLights(dlight_t* pList[MAX_DLIGHTS]) = 0; + + virtual const char* Draw_DecalNameFromIndex(int nIndex) = 0; + + virtual dlight_t* GetElightByKey(int key) = 0; +}; + +#define VENGINE_EFFECTS_INTERFACE_VERSION "VEngineEffects001" + +extern IVEfx* effects; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/ienginetrace.h b/SpyCustom/sdk/ienginetrace.h new file mode 100644 index 0000000..adea5ea --- /dev/null +++ b/SpyCustom/sdk/ienginetrace.h @@ -0,0 +1,152 @@ +#ifndef ENGINE_IENGINETRACE_H +#define ENGINE_IENGINETRACE_H +#ifdef _WIN32 +#pragma once +#endif + +#include "basehandle.h" +#include "utlvector.h" +#include "vector4d.h" + +#include "bspflags.h" + +class Vector; +class IHandleEntity; +struct Ray_t; +class CGameTrace; +typedef CGameTrace trace_t; +class ICollideable; +class QAngle; +class CTraceListData; +class CPhysCollide; +struct cplane_t; + +enum TraceType_t +{ + TRACE_EVERYTHING = 0, + TRACE_WORLD_ONLY, + TRACE_ENTITIES_ONLY, + TRACE_EVERYTHING_FILTER_PROPS, +}; + +abstract_class ITraceFilter +{ +public: + virtual bool ShouldHitEntity(IHandleEntity * pEntity, int contentsMask) = 0; + virtual TraceType_t GetTraceType() const = 0; +}; + + +class CTraceFilter : public ITraceFilter +{ +public: + bool ShouldHitEntity(IHandleEntity* pEntityHandle, int ) + { + return !(pEntityHandle == pSkip); + } + virtual TraceType_t GetTraceType() const + { + return TRACE_EVERYTHING; + } + void* pSkip; +}; + +class CTraceFilterEntitiesOnly : public ITraceFilter +{ +public: + virtual TraceType_t GetTraceType() const + { + return TRACE_ENTITIES_ONLY; + } +}; + + +class CTraceFilterWorldOnly : public ITraceFilter +{ +public: + bool ShouldHitEntity(IHandleEntity* pServerEntity, int contentsMask) + { + return false; + } + virtual TraceType_t GetTraceType() const + { + return TRACE_WORLD_ONLY; + } +}; + +class CTraceFilterWorldAndPropsOnly : public ITraceFilter +{ +public: + bool ShouldHitEntity(IHandleEntity* pServerEntity, int contentsMask) + { + return false; + } + virtual TraceType_t GetTraceType() const + { + return TRACE_EVERYTHING; + } +}; + +class CTraceFilterHitAll : public CTraceFilter +{ +public: + virtual bool ShouldHitEntity(IHandleEntity* pServerEntity, int contentsMask) + { + return true; + } +}; + + +abstract_class IEntityEnumerator +{ +public: + virtual bool EnumEntity(IHandleEntity * pHandleEntity) = 0; +}; + + +#define INTERFACEVERSION_ENGINETRACE_SERVER "EngineTraceServer003" +#define INTERFACEVERSION_ENGINETRACE_CLIENT "EngineTraceClient003" +abstract_class IEngineTrace +{ +public: + virtual int GetPointContents(const Vector& vecAbsPosition, int contentsMask = MASK_ALL, IHandleEntity** ppEntity = nullptr) = 0; + + + virtual int GetPointContents_WorldOnly(const Vector& vecAbsPosition, int contentsMask = MASK_ALL) = 0; + + virtual int GetPointContents_Collideable(ICollideable* pCollide, const Vector& vecAbsPosition) = 0; + + virtual void ClipRayToEntity(const Ray_t& ray, unsigned int fMask, IHandleEntity* pEnt, trace_t* pTrace) = 0; + + virtual void ClipRayToCollideable(const Ray_t& ray, unsigned int fMask, ICollideable* pCollide, trace_t* pTrace) = 0; + + virtual void TraceRay(const Ray_t& ray, unsigned int fMask, ITraceFilter* pTraceFilter, CGameTrace* pTrace) = 0; + + virtual void SetupLeafAndEntityListRay(const Ray_t& ray, CTraceListData& traceData) = 0; + virtual void SetupLeafAndEntityListBox(const Vector& vecBoxMin, const Vector& vecBoxMax, CTraceListData& traceData) = 0; + virtual void TraceRayAgainstLeafAndEntityList(const Ray_t& ray, CTraceListData& traceData, unsigned int fMask, ITraceFilter* pTraceFilter, trace_t* pTrace) = 0; + + virtual void SweepCollideable(ICollideable* pCollide, const Vector& vecAbsStart, const Vector& vecAbsEnd, + const QAngle& vecAngles, unsigned int fMask, ITraceFilter* pTraceFilter, trace_t* pTrace) = 0; + + virtual void EnumerateEntities(const Ray_t& ray, bool triggers, IEntityEnumerator* pEnumerator) = 0; + + virtual void EnumerateEntities(const Vector& vecAbsMins, const Vector& vecAbsMaxs, IEntityEnumerator* pEnumerator) = 0; + + virtual ICollideable* GetCollideable(IHandleEntity* pEntity) = 0; + + virtual int GetStatByIndex(int index, bool bClear) = 0; + + + virtual void GetBrushesInAABB(const Vector& vMins, const Vector& vMaxs, CUtlVector* pOutput, int iContentsMask = 0xFFFFFFFF) = 0; + + virtual CPhysCollide* GetCollidableFromDisplacementsInAABB(const Vector& vMins, const Vector& vMaxs) = 0; + + virtual bool GetBrushInfo(int iBrush, CUtlVector* pPlanesOut, int* pContentsOut) = 0; + + virtual bool PointOutsideWorld(const Vector& ptTest) = 0; + + virtual int GetLeafContainingPoint(const Vector& ptTest) = 0; +}; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/ifilelist.h b/SpyCustom/sdk/ifilelist.h new file mode 100644 index 0000000..da73a83 --- /dev/null +++ b/SpyCustom/sdk/ifilelist.h @@ -0,0 +1,15 @@ +#ifndef IFILELIST_H +#define IFILELIST_H +#ifdef _WIN32 +#endif + + +class IFileList +{ +public: + virtual bool IsFileInList(const char* pFilename) = 0; + virtual void Release() = 0; +}; + + +#endif diff --git a/SpyCustom/sdk/igameconsole.h b/SpyCustom/sdk/igameconsole.h new file mode 100644 index 0000000..7423bee --- /dev/null +++ b/SpyCustom/sdk/igameconsole.h @@ -0,0 +1,28 @@ +#ifndef IGAMECONSOLE_H +#define IGAMECONSOLE_H +#ifdef _WIN32 +#pragma once +#endif + +#include "interface.h" + + +class IGameConsole : public IBaseInterface +{ +public: + virtual void Activate() = 0; + + virtual void Initialize() = 0; + + virtual void Hide() = 0; + + virtual void Clear() = 0; + + virtual bool IsConsoleVisible() = 0; + + virtual void SetParent(int parent) = 0; +}; + +#define GAMECONSOLE_INTERFACE_VERSION "GameConsole004" + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/igameevents.h b/SpyCustom/sdk/igameevents.h new file mode 100644 index 0000000..a8c29cf --- /dev/null +++ b/SpyCustom/sdk/igameevents.h @@ -0,0 +1,131 @@ +#if !defined( IGAMEEVENTS_H ) +#define IGAMEEVENTS_H +#ifdef _WIN32 +#pragma once +#endif + +#include "interface.h" + + +#define INTERFACEVERSION_GAMEEVENTSMANAGER "GAMEEVENTSMANAGER001" +#define INTERFACEVERSION_GAMEEVENTSMANAGER2 "GAMEEVENTSMANAGER002" + +#include "bitbuf.h" +#define NULL 0x0 +#define EVENT_DEBUG_ID_INIT 42 +#define EVENT_DEBUG_ID_SHUTDOWN 13 + + +#define MAX_EVENT_NAME_LENGTH 32 +#define MAX_EVENT_BITS 9 +#define MAX_EVENT_NUMBER (1< + +enum NormalDecodeMode_t +{ + NORMAL_DECODE_NONE = 0, + NORMAL_DECODE_ATI2N = 1, + NORMAL_DECODE_ATI2N_ALPHA = 2 +}; + +#ifdef _WIN32 +typedef enum _D3DFORMAT D3DFORMAT; +#endif + +#pragma warning(disable : 4514) + +enum ImageFormat +{ + IMAGE_FORMAT_UNKNOWN = -1, + IMAGE_FORMAT_RGBA8888 = 0, + IMAGE_FORMAT_ABGR8888, + IMAGE_FORMAT_RGB888, + IMAGE_FORMAT_BGR888, + IMAGE_FORMAT_RGB565, + IMAGE_FORMAT_I8, + IMAGE_FORMAT_IA88, + IMAGE_FORMAT_P8, + IMAGE_FORMAT_A8, + IMAGE_FORMAT_RGB888_BLUESCREEN, + IMAGE_FORMAT_BGR888_BLUESCREEN, + IMAGE_FORMAT_ARGB8888, + IMAGE_FORMAT_BGRA8888, + IMAGE_FORMAT_DXT1, + IMAGE_FORMAT_DXT3, + IMAGE_FORMAT_DXT5, + IMAGE_FORMAT_BGRX8888, + IMAGE_FORMAT_BGR565, + IMAGE_FORMAT_BGRX5551, + IMAGE_FORMAT_BGRA4444, + IMAGE_FORMAT_DXT1_ONEBITALPHA, + IMAGE_FORMAT_BGRA5551, + IMAGE_FORMAT_UV88, + IMAGE_FORMAT_UVWQ8888, + IMAGE_FORMAT_RGBA16161616F, + IMAGE_FORMAT_RGBA16161616, + IMAGE_FORMAT_UVLX8888, + IMAGE_FORMAT_R32F, + IMAGE_FORMAT_RGB323232F, + IMAGE_FORMAT_RGBA32323232F, + + IMAGE_FORMAT_NV_DST16, + IMAGE_FORMAT_NV_DST24, + IMAGE_FORMAT_NV_INTZ, + IMAGE_FORMAT_NV_RAWZ, + IMAGE_FORMAT_ATI_DST16, + IMAGE_FORMAT_ATI_DST24, + IMAGE_FORMAT_NV_NULL, + + IMAGE_FORMAT_ATI2N, + IMAGE_FORMAT_ATI1N, + +#if defined( _X360 ) + IMAGE_FORMAT_X360_DST16, + IMAGE_FORMAT_X360_DST24, + IMAGE_FORMAT_X360_DST24F, + IMAGE_FORMAT_LINEAR_BGRX8888, + IMAGE_FORMAT_LINEAR_RGBA8888, + IMAGE_FORMAT_LINEAR_ABGR8888, + IMAGE_FORMAT_LINEAR_ARGB8888, + IMAGE_FORMAT_LINEAR_BGRA8888, + IMAGE_FORMAT_LINEAR_RGB888, + IMAGE_FORMAT_LINEAR_BGR888, + IMAGE_FORMAT_LINEAR_BGRX5551, + IMAGE_FORMAT_LINEAR_I8, + IMAGE_FORMAT_LINEAR_RGBA16161616, + + IMAGE_FORMAT_LE_BGRX8888, + IMAGE_FORMAT_LE_BGRA8888, +#endif + + NUM_IMAGE_FORMATS +}; + +#if defined( POSIX ) || defined( DX_TO_GL_ABSTRACTION ) +typedef enum _D3DFORMAT +{ + D3DFMT_INDEX16, + D3DFMT_D16, + D3DFMT_D24S8, + D3DFMT_A8R8G8B8, + D3DFMT_A4R4G4B4, + D3DFMT_X8R8G8B8, + D3DFMT_R5G6R5, + D3DFMT_X1R5G5B5, + D3DFMT_A1R5G5B5, + D3DFMT_L8, + D3DFMT_A8L8, + D3DFMT_A, + D3DFMT_DXT1, + D3DFMT_DXT3, + D3DFMT_DXT5, + D3DFMT_V8U8, + D3DFMT_Q8W8V8U8, + D3DFMT_X8L8V8U8, + D3DFMT_A16B16G16R16F, + D3DFMT_A16B16G16R16, + D3DFMT_R32F, + D3DFMT_A32B32G32R32F, + D3DFMT_R8G8B8, + D3DFMT_D24X4S4, + D3DFMT_A8, + D3DFMT_R5G6B5, + D3DFMT_D15S1, + D3DFMT_D24X8, + D3DFMT_VERTEXDATA, + D3DFMT_INDEX32, + + D3DFMT_NV_INTZ = 0x5a544e49, + D3DFMT_NV_RAWZ = 0x5a574152, + + D3DFMT_NV_NULL = 0x4c4c554e, + + D3DFMT_ATI_D16 = 0x36314644, + D3DFMT_ATI_D24S8 = 0x34324644, + + D3DFMT_ATI_2N = 0x32495441, + D3DFMT_ATI_1N = 0x31495441, + + D3DFMT_UNKNOWN +} D3DFORMAT; +#endif + +struct BGRA8888_t +{ + unsigned char b; + unsigned char g; + unsigned char r; + unsigned char a; + inline BGRA8888_t& operator=(const BGRA8888_t& in) + { + *(unsigned int*)this = *(unsigned int*)∈ + return *this; + } +}; + +struct RGBA8888_t +{ + unsigned char r; + unsigned char g; + unsigned char b; + unsigned char a; + inline RGBA8888_t& operator=(const BGRA8888_t& in) + { + r = in.r; + g = in.g; + b = in.b; + a = in.a; + return *this; + } +}; + +struct RGB888_t +{ + unsigned char r; + unsigned char g; + unsigned char b; + inline RGB888_t& operator=(const BGRA8888_t& in) + { + r = in.r; + g = in.g; + b = in.b; + return *this; + } + inline bool operator==(const RGB888_t& in) const + { + return (r == in.r) && (g == in.g) && (b == in.b); + } + inline bool operator!=(const RGB888_t& in) const + { + return (r != in.r) || (g != in.g) || (b != in.b); + } +}; + +struct BGR888_t +{ + unsigned char b; + unsigned char g; + unsigned char r; + inline BGR888_t& operator=(const BGRA8888_t& in) + { + r = in.r; + g = in.g; + b = in.b; + return *this; + } +}; + +#if defined( _X360 ) +#pragma bitfield_order( push, lsb_to_msb ) +#endif +struct BGR565_t +{ + unsigned short b : 5; + unsigned short g : 6; + unsigned short r : 5; + inline BGR565_t& operator=(const BGRA8888_t& in) + { + r = in.r >> 3; + g = in.g >> 2; + b = in.b >> 3; + return *this; + } + inline BGR565_t& Set(int red, int green, int blue) + { + r = red >> 3; + g = green >> 2; + b = blue >> 3; + return *this; + } +}; +#if defined( _X360 ) +#pragma bitfield_order( pop ) +#endif + +struct BGRA5551_t +{ + unsigned short b : 5; + unsigned short g : 5; + unsigned short r : 5; + unsigned short a : 1; + inline BGRA5551_t& operator=(const BGRA8888_t& in) + { + r = in.r >> 3; + g = in.g >> 3; + b = in.b >> 3; + a = in.a >> 7; + return *this; + } +}; + +struct BGRA4444_t +{ + unsigned short b : 4; + unsigned short g : 4; + unsigned short r : 4; + unsigned short a : 4; + inline BGRA4444_t& operator=(const BGRA8888_t& in) + { + r = in.r >> 4; + g = in.g >> 4; + b = in.b >> 4; + a = in.a >> 4; + return *this; + } +}; + +struct RGBX5551_t +{ + unsigned short r : 5; + unsigned short g : 5; + unsigned short b : 5; + unsigned short x : 1; + inline RGBX5551_t& operator=(const BGRA8888_t& in) + { + r = in.r >> 3; + g = in.g >> 3; + b = in.b >> 3; + return *this; + } +}; + +#define ARTWORK_GAMMA ( 2.2f ) +#define IMAGE_MAX_DIM ( 2048 ) + + +struct ImageFormatInfo_t +{ + const char* m_pName; + int m_NumBytes; + int m_NumRedBits; + int m_NumGreeBits; + int m_NumBlueBits; + int m_NumAlphaBits; + bool m_IsCompressed; +}; + + +namespace ImageLoader +{ + + bool GetInfo(const char* fileName, int* width, int* height, enum ImageFormat* imageFormat, float* sourceGamma); + int GetMemRequired(int width, int height, int depth, ImageFormat imageFormat, bool mipmap); + int GetMipMapLevelByteOffset(int width, int height, enum ImageFormat imageFormat, int skipMipLevels); + void GetMipMapLevelDimensions(int* width, int* height, int skipMipLevels); + int GetNumMipMapLevels(int width, int height, int depth = 1); + bool Load(unsigned char* imageData, const char* fileName, int width, int height, enum ImageFormat imageFormat, float targetGamma, bool mipmap); + bool Load(unsigned char* imageData, FILE* fp, int width, int height, + enum ImageFormat imageFormat, float targetGamma, bool mipmap); + + bool ConvertImageFormat(const unsigned char* src, enum ImageFormat srcImageFormat, + unsigned char* dst, enum ImageFormat dstImageFormat, + int width, int height, int srcStride = 0, int dstStride = 0); + + void PreConvertSwapImageData(unsigned char* pImageData, int nImageSize, ImageFormat imageFormat, int width = 0, int stride = 0); + void PostConvertSwapImageData(unsigned char* pImageData, int nImageSize, ImageFormat imageFormat, int width = 0, int stride = 0); + void ByteSwapImageData(unsigned char* pImageData, int nImageSize, ImageFormat imageFormat, int width = 0, int stride = 0); + bool IsFormatValidForConversion(ImageFormat fmt); + + ImageFormat D3DFormatToImageFormat(D3DFORMAT format); + D3DFORMAT ImageFormatToD3DFormat(ImageFormat format); + + enum + { + RESAMPLE_NORMALMAP = 0x1, + RESAMPLE_ALPHATEST = 0x2, + RESAMPLE_NICE_FILTER = 0x4, + RESAMPLE_CLAMPS = 0x8, + RESAMPLE_CLAMPT = 0x10, + RESAMPLE_CLAMPU = 0x20, + }; + + struct ResampleInfo_t + { + + ResampleInfo_t() : m_nFlags(0), m_flAlphaThreshhold(0.4f), m_flAlphaHiFreqThreshhold(0.4f), m_nSrcDepth(1), m_nDestDepth(1) + { + m_flColorScale[0] = 1.0f, m_flColorScale[1] = 1.0f, m_flColorScale[2] = 1.0f, m_flColorScale[3] = 1.0f; + m_flColorGoal[0] = 0.0f, m_flColorGoal[1] = 0.0f, m_flColorGoal[2] = 0.0f, m_flColorGoal[3] = 0.0f; + } + + unsigned char* m_pSrc; + unsigned char* m_pDest; + + int m_nSrcWidth; + int m_nSrcHeight; + int m_nSrcDepth; + + int m_nDestWidth; + int m_nDestHeight; + int m_nDestDepth; + + float m_flSrcGamma; + float m_flDestGamma; + + float m_flColorScale[4]; + float m_flColorGoal[4]; + + float m_flAlphaThreshhold; + float m_flAlphaHiFreqThreshhold; + + int m_nFlags; + }; + + bool ResampleRGBA8888(const ResampleInfo_t& info); + bool ResampleRGBA16161616(const ResampleInfo_t& info); + bool ResampleRGB323232F(const ResampleInfo_t& info); + + void ConvertNormalMapRGBA8888ToDUDVMapUVLX8888(const unsigned char* src, int width, int height, + unsigned char* dst_); + void ConvertNormalMapRGBA8888ToDUDVMapUVWQ8888(const unsigned char* src, int width, int height, + unsigned char* dst_); + void ConvertNormalMapRGBA8888ToDUDVMapUV88(const unsigned char* src, int width, int height, + unsigned char* dst_); + + void ConvertIA88ImageToNormalMapRGBA8888(const unsigned char* src, int width, + int height, unsigned char* dst, + float bumpScale); + + void NormalizeNormalMapRGBA8888(unsigned char* src, int numTexels); + + + void GammaCorrectRGBA8888(unsigned char* src, unsigned char* dst, + int width, int height, int depth, float srcGamma, float dstGamma); + + + void ConstructGammaTable(unsigned char* pTable, float srcGamma, float dstGamma); + + + void GammaCorrectRGBA8888(unsigned char* pSrc, unsigned char* pDst, + int width, int height, int depth, unsigned char* pGammaTable); + + + void GenerateMipmapLevels(unsigned char* pSrc, unsigned char* pDst, int width, + int height, int depth, ImageFormat imageFormat, float srcGamma, float dstGamma, + int numLevels = 0); + + + bool RotateImageLeft(const unsigned char* src, unsigned char* dst, + int widthHeight, ImageFormat imageFormat); + bool RotateImage180(const unsigned char* src, unsigned char* dst, + int widthHeight, ImageFormat imageFormat); + bool FlipImageVertically(void* pSrc, void* pDst, int nWidth, int nHeight, ImageFormat imageFormat, int nDstStride = 0); + bool FlipImageHorizontally(void* pSrc, void* pDst, int nWidth, int nHeight, ImageFormat imageFormat, int nDstStride = 0); + bool SwapAxes(unsigned char* src, + int widthHeight, ImageFormat imageFormat); + + + ImageFormatInfo_t const& ImageFormatInfo(ImageFormat fmt); + + + inline char const* GetName(ImageFormat fmt) + { + return ImageFormatInfo(fmt).m_pName; + } + + + inline int SizeInBytes(ImageFormat fmt) + { + return ImageFormatInfo(fmt).m_NumBytes; + } + + inline bool IsTransparent(ImageFormat fmt) + { + return ImageFormatInfo(fmt).m_NumAlphaBits > 0; + } + + + inline bool IsCompressed(ImageFormat fmt) + { + return ImageFormatInfo(fmt).m_IsCompressed; + } + + inline bool HasChannelLargerThan8Bits(ImageFormat fmt) + { + ImageFormatInfo_t info = ImageFormatInfo(fmt); + return (info.m_NumRedBits > 8 || info.m_NumGreeBits > 8 || info.m_NumBlueBits > 8 || info.m_NumAlphaBits > 8); + } + + +} + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/imaterial.h b/SpyCustom/sdk/imaterial.h new file mode 100644 index 0000000..d031f41 --- /dev/null +++ b/SpyCustom/sdk/imaterial.h @@ -0,0 +1,493 @@ +#ifndef IMATERIAL_H +#define IMATERIAL_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "imageformat.h" +#include "imaterialsystem.h" + +class IMaterialVar; +class ITexture; +class IMaterialProxy; +class Vector; + +#define VERTEX_POSITION 0x0001 +#define VERTEX_NORMAL 0x0002 +#define VERTEX_COLOR 0x0004 +#define VERTEX_SPECULAR 0x0008 + +#define VERTEX_TANGENT_S 0x0010 +#define VERTEX_TANGENT_T 0x0020 +#define VERTEX_TANGENT_SPACE ( VERTEX_TANGENT_S | VERTEX_TANGENT_T ) + +#define VERTEX_WRINKLE 0x0040 + +#define VERTEX_BONE_INDEX 0x0080 + +#define VERTEX_FORMAT_VERTEX_SHADER 0x0100 + +#define VERTEX_FORMAT_USE_EXACT_FORMAT 0x0200 + +#define VERTEX_FORMAT_COMPRESSED 0x400 + +#define VERTEX_LAST_BIT 10 + +#define VERTEX_BONE_WEIGHT_BIT (VERTEX_LAST_BIT + 1) +#define USER_DATA_SIZE_BIT (VERTEX_LAST_BIT + 4) +#define TEX_COORD_SIZE_BIT (VERTEX_LAST_BIT + 7) + +#define VERTEX_BONE_WEIGHT_MASK ( 0x7 << VERTEX_BONE_WEIGHT_BIT ) +#define USER_DATA_SIZE_MASK ( 0x7 << USER_DATA_SIZE_BIT ) + +#define VERTEX_FORMAT_FIELD_MASK 0x0FF + +#define VERTEX_FORMAT_UNKNOWN 0 + + + +#define VERTEX_BONEWEIGHT( _n ) ((_n) << VERTEX_BONE_WEIGHT_BIT) +#define VERTEX_USERDATA_SIZE( _n ) ((_n) << USER_DATA_SIZE_BIT) +#define VERTEX_TEXCOORD_MASK( _coord ) (( 0x7ULL ) << ( TEX_COORD_SIZE_BIT + 3 * (_coord) )) + +inline VertexFormat_t VERTEX_TEXCOORD_SIZE(int nIndex, int nNumCoords) +{ + uint64 n64 = nNumCoords; + uint64 nShift = TEX_COORD_SIZE_BIT + (3 * nIndex); + return n64 << nShift; +} + + + +inline int VertexFlags(VertexFormat_t vertexFormat) +{ + return static_cast (vertexFormat & ((1 << (VERTEX_LAST_BIT + 1)) - 1)); +} + +inline int NumBoneWeights(VertexFormat_t vertexFormat) +{ + return static_cast ((vertexFormat >> VERTEX_BONE_WEIGHT_BIT) & 0x7); +} + +inline int UserDataSize(VertexFormat_t vertexFormat) +{ + return static_cast ((vertexFormat >> USER_DATA_SIZE_BIT) & 0x7); +} + +inline int TexCoordSize(int nTexCoordIndex, VertexFormat_t vertexFormat) +{ + return static_cast ((vertexFormat >> (TEX_COORD_SIZE_BIT + 3 * nTexCoordIndex)) & 0x7); +} + +inline bool UsesVertexShader(VertexFormat_t vertexFormat) +{ + return (vertexFormat & VERTEX_FORMAT_VERTEX_SHADER) != 0; +} + +inline VertexCompressionType_t CompressionType(VertexFormat_t vertexFormat) +{ + if (vertexFormat & VERTEX_FORMAT_COMPRESSED) + return VERTEX_COMPRESSION_ON; + else + return VERTEX_COMPRESSION_NONE; +} + + +enum VertexElement_t +{ + VERTEX_ELEMENT_NONE = -1, + + VERTEX_ELEMENT_POSITION = 0, + VERTEX_ELEMENT_NORMAL = 1, + VERTEX_ELEMENT_COLOR = 2, + VERTEX_ELEMENT_SPECULAR = 3, + VERTEX_ELEMENT_TANGENT_S = 4, + VERTEX_ELEMENT_TANGENT_T = 5, + VERTEX_ELEMENT_WRINKLE = 6, + VERTEX_ELEMENT_BONEINDEX = 7, + VERTEX_ELEMENT_BONEWEIGHTS1 = 8, + VERTEX_ELEMENT_BONEWEIGHTS2 = 9, + VERTEX_ELEMENT_BONEWEIGHTS3 = 10, + VERTEX_ELEMENT_BONEWEIGHTS4 = 11, + VERTEX_ELEMENT_USERDATA1 = 12, + VERTEX_ELEMENT_USERDATA2 = 13, + VERTEX_ELEMENT_USERDATA3 = 14, + VERTEX_ELEMENT_USERDATA4 = 15, + VERTEX_ELEMENT_TEXCOORD1D_0 = 16, + VERTEX_ELEMENT_TEXCOORD1D_1 = 17, + VERTEX_ELEMENT_TEXCOORD1D_2 = 18, + VERTEX_ELEMENT_TEXCOORD1D_3 = 19, + VERTEX_ELEMENT_TEXCOORD1D_4 = 20, + VERTEX_ELEMENT_TEXCOORD1D_5 = 21, + VERTEX_ELEMENT_TEXCOORD1D_6 = 22, + VERTEX_ELEMENT_TEXCOORD1D_7 = 23, + VERTEX_ELEMENT_TEXCOORD2D_0 = 24, + VERTEX_ELEMENT_TEXCOORD2D_1 = 25, + VERTEX_ELEMENT_TEXCOORD2D_2 = 26, + VERTEX_ELEMENT_TEXCOORD2D_3 = 27, + VERTEX_ELEMENT_TEXCOORD2D_4 = 28, + VERTEX_ELEMENT_TEXCOORD2D_5 = 29, + VERTEX_ELEMENT_TEXCOORD2D_6 = 30, + VERTEX_ELEMENT_TEXCOORD2D_7 = 31, + VERTEX_ELEMENT_TEXCOORD3D_0 = 32, + VERTEX_ELEMENT_TEXCOORD3D_1 = 33, + VERTEX_ELEMENT_TEXCOORD3D_2 = 34, + VERTEX_ELEMENT_TEXCOORD3D_3 = 35, + VERTEX_ELEMENT_TEXCOORD3D_4 = 36, + VERTEX_ELEMENT_TEXCOORD3D_5 = 37, + VERTEX_ELEMENT_TEXCOORD3D_6 = 38, + VERTEX_ELEMENT_TEXCOORD3D_7 = 39, + VERTEX_ELEMENT_TEXCOORD4D_0 = 40, + VERTEX_ELEMENT_TEXCOORD4D_1 = 41, + VERTEX_ELEMENT_TEXCOORD4D_2 = 42, + VERTEX_ELEMENT_TEXCOORD4D_3 = 43, + VERTEX_ELEMENT_TEXCOORD4D_4 = 44, + VERTEX_ELEMENT_TEXCOORD4D_5 = 45, + VERTEX_ELEMENT_TEXCOORD4D_6 = 46, + VERTEX_ELEMENT_TEXCOORD4D_7 = 47, + + VERTEX_ELEMENT_NUMELEMENTS = 48 +}; + +inline void Detect_VertexElement_t_Changes(VertexElement_t element) +{ + Assert(VERTEX_ELEMENT_NUMELEMENTS == 48); + switch (element) + { + case VERTEX_ELEMENT_POSITION: Assert(VERTEX_ELEMENT_POSITION == 0); break; + case VERTEX_ELEMENT_NORMAL: Assert(VERTEX_ELEMENT_NORMAL == 1); break; + case VERTEX_ELEMENT_COLOR: Assert(VERTEX_ELEMENT_COLOR == 2); break; + case VERTEX_ELEMENT_SPECULAR: Assert(VERTEX_ELEMENT_SPECULAR == 3); break; + case VERTEX_ELEMENT_TANGENT_S: Assert(VERTEX_ELEMENT_TANGENT_S == 4); break; + case VERTEX_ELEMENT_TANGENT_T: Assert(VERTEX_ELEMENT_TANGENT_T == 5); break; + case VERTEX_ELEMENT_WRINKLE: Assert(VERTEX_ELEMENT_WRINKLE == 6); break; + case VERTEX_ELEMENT_BONEINDEX: Assert(VERTEX_ELEMENT_BONEINDEX == 7); break; + case VERTEX_ELEMENT_BONEWEIGHTS1: Assert(VERTEX_ELEMENT_BONEWEIGHTS1 == 8); break; + case VERTEX_ELEMENT_BONEWEIGHTS2: Assert(VERTEX_ELEMENT_BONEWEIGHTS2 == 9); break; + case VERTEX_ELEMENT_BONEWEIGHTS3: Assert(VERTEX_ELEMENT_BONEWEIGHTS3 == 10); break; + case VERTEX_ELEMENT_BONEWEIGHTS4: Assert(VERTEX_ELEMENT_BONEWEIGHTS4 == 11); break; + case VERTEX_ELEMENT_USERDATA1: Assert(VERTEX_ELEMENT_USERDATA1 == 12); break; + case VERTEX_ELEMENT_USERDATA2: Assert(VERTEX_ELEMENT_USERDATA2 == 13); break; + case VERTEX_ELEMENT_USERDATA3: Assert(VERTEX_ELEMENT_USERDATA3 == 14); break; + case VERTEX_ELEMENT_USERDATA4: Assert(VERTEX_ELEMENT_USERDATA4 == 15); break; + case VERTEX_ELEMENT_TEXCOORD1D_0: Assert(VERTEX_ELEMENT_TEXCOORD1D_0 == 16); break; + case VERTEX_ELEMENT_TEXCOORD1D_1: Assert(VERTEX_ELEMENT_TEXCOORD1D_1 == 17); break; + case VERTEX_ELEMENT_TEXCOORD1D_2: Assert(VERTEX_ELEMENT_TEXCOORD1D_2 == 18); break; + case VERTEX_ELEMENT_TEXCOORD1D_3: Assert(VERTEX_ELEMENT_TEXCOORD1D_3 == 19); break; + case VERTEX_ELEMENT_TEXCOORD1D_4: Assert(VERTEX_ELEMENT_TEXCOORD1D_4 == 20); break; + case VERTEX_ELEMENT_TEXCOORD1D_5: Assert(VERTEX_ELEMENT_TEXCOORD1D_5 == 21); break; + case VERTEX_ELEMENT_TEXCOORD1D_6: Assert(VERTEX_ELEMENT_TEXCOORD1D_6 == 22); break; + case VERTEX_ELEMENT_TEXCOORD1D_7: Assert(VERTEX_ELEMENT_TEXCOORD1D_7 == 23); break; + case VERTEX_ELEMENT_TEXCOORD2D_0: Assert(VERTEX_ELEMENT_TEXCOORD2D_0 == 24); break; + case VERTEX_ELEMENT_TEXCOORD2D_1: Assert(VERTEX_ELEMENT_TEXCOORD2D_1 == 25); break; + case VERTEX_ELEMENT_TEXCOORD2D_2: Assert(VERTEX_ELEMENT_TEXCOORD2D_2 == 26); break; + case VERTEX_ELEMENT_TEXCOORD2D_3: Assert(VERTEX_ELEMENT_TEXCOORD2D_3 == 27); break; + case VERTEX_ELEMENT_TEXCOORD2D_4: Assert(VERTEX_ELEMENT_TEXCOORD2D_4 == 28); break; + case VERTEX_ELEMENT_TEXCOORD2D_5: Assert(VERTEX_ELEMENT_TEXCOORD2D_5 == 29); break; + case VERTEX_ELEMENT_TEXCOORD2D_6: Assert(VERTEX_ELEMENT_TEXCOORD2D_6 == 30); break; + case VERTEX_ELEMENT_TEXCOORD2D_7: Assert(VERTEX_ELEMENT_TEXCOORD2D_7 == 31); break; + case VERTEX_ELEMENT_TEXCOORD3D_0: Assert(VERTEX_ELEMENT_TEXCOORD3D_0 == 32); break; + case VERTEX_ELEMENT_TEXCOORD3D_1: Assert(VERTEX_ELEMENT_TEXCOORD3D_1 == 33); break; + case VERTEX_ELEMENT_TEXCOORD3D_2: Assert(VERTEX_ELEMENT_TEXCOORD3D_2 == 34); break; + case VERTEX_ELEMENT_TEXCOORD3D_3: Assert(VERTEX_ELEMENT_TEXCOORD3D_3 == 35); break; + case VERTEX_ELEMENT_TEXCOORD3D_4: Assert(VERTEX_ELEMENT_TEXCOORD3D_4 == 36); break; + case VERTEX_ELEMENT_TEXCOORD3D_5: Assert(VERTEX_ELEMENT_TEXCOORD3D_5 == 37); break; + case VERTEX_ELEMENT_TEXCOORD3D_6: Assert(VERTEX_ELEMENT_TEXCOORD3D_6 == 38); break; + case VERTEX_ELEMENT_TEXCOORD3D_7: Assert(VERTEX_ELEMENT_TEXCOORD3D_7 == 39); break; + case VERTEX_ELEMENT_TEXCOORD4D_0: Assert(VERTEX_ELEMENT_TEXCOORD4D_0 == 40); break; + case VERTEX_ELEMENT_TEXCOORD4D_1: Assert(VERTEX_ELEMENT_TEXCOORD4D_1 == 41); break; + case VERTEX_ELEMENT_TEXCOORD4D_2: Assert(VERTEX_ELEMENT_TEXCOORD4D_2 == 42); break; + case VERTEX_ELEMENT_TEXCOORD4D_3: Assert(VERTEX_ELEMENT_TEXCOORD4D_3 == 43); break; + case VERTEX_ELEMENT_TEXCOORD4D_4: Assert(VERTEX_ELEMENT_TEXCOORD4D_4 == 44); break; + case VERTEX_ELEMENT_TEXCOORD4D_5: Assert(VERTEX_ELEMENT_TEXCOORD4D_5 == 45); break; + case VERTEX_ELEMENT_TEXCOORD4D_6: Assert(VERTEX_ELEMENT_TEXCOORD4D_6 == 46); break; + case VERTEX_ELEMENT_TEXCOORD4D_7: Assert(VERTEX_ELEMENT_TEXCOORD4D_7 == 47); break; + default: + Assert(0); + break; + } +} + +#define COMPRESSED_NORMALS_SEPARATETANGENTS_SHORT2 0 +#define COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 1 +#define COMPRESSED_NORMALS_TYPE COMPRESSED_NORMALS_COMBINEDTANGENTS_UBYTE4 + +inline int GetVertexElementSize(VertexElement_t element, VertexCompressionType_t compressionType) +{ + Detect_VertexElement_t_Changes(element); + + if (compressionType == VERTEX_COMPRESSION_ON) + { + switch (element) + { +#if ( COMPRESSED_NORMALS_TYPE == COMPRESSED_NORMALS_SEPARATETANGENTS_SHORT2 ) + case VERTEX_ELEMENT_NORMAL: + return (2 * sizeof(short)); + case VERTEX_ELEMENT_USERDATA4: + return (2 * sizeof(short)); +#else + case VERTEX_ELEMENT_NORMAL: + return (4 * sizeof(unsigned char)); + case VERTEX_ELEMENT_USERDATA4: + return (0); +#endif + case VERTEX_ELEMENT_BONEWEIGHTS1: + case VERTEX_ELEMENT_BONEWEIGHTS2: + return (2 * sizeof(short)); + default: + break; + } + } + + switch (element) + { + case VERTEX_ELEMENT_POSITION: return (3 * sizeof(float)); + case VERTEX_ELEMENT_NORMAL: return (3 * sizeof(float)); + case VERTEX_ELEMENT_COLOR: return (4 * sizeof(unsigned char)); + case VERTEX_ELEMENT_SPECULAR: return (4 * sizeof(unsigned char)); + case VERTEX_ELEMENT_TANGENT_S: return (3 * sizeof(float)); + case VERTEX_ELEMENT_TANGENT_T: return (3 * sizeof(float)); + case VERTEX_ELEMENT_WRINKLE: return (1 * sizeof(float)); + case VERTEX_ELEMENT_BONEINDEX: return (4 * sizeof(unsigned char)); + case VERTEX_ELEMENT_BONEWEIGHTS1: return (1 * sizeof(float)); + case VERTEX_ELEMENT_BONEWEIGHTS2: return (2 * sizeof(float)); + case VERTEX_ELEMENT_BONEWEIGHTS3: return (3 * sizeof(float)); + case VERTEX_ELEMENT_BONEWEIGHTS4: return (4 * sizeof(float)); + case VERTEX_ELEMENT_USERDATA1: return (1 * sizeof(float)); + case VERTEX_ELEMENT_USERDATA2: return (2 * sizeof(float)); + case VERTEX_ELEMENT_USERDATA3: return (3 * sizeof(float)); + case VERTEX_ELEMENT_USERDATA4: return (4 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD1D_0: return (1 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD1D_1: return (1 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD1D_2: return (1 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD1D_3: return (1 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD1D_4: return (1 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD1D_5: return (1 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD1D_6: return (1 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD1D_7: return (1 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD2D_0: return (2 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD2D_1: return (2 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD2D_2: return (2 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD2D_3: return (2 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD2D_4: return (2 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD2D_5: return (2 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD2D_6: return (2 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD2D_7: return (2 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD3D_0: return (3 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD3D_1: return (3 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD3D_2: return (3 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD3D_3: return (3 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD3D_4: return (3 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD3D_5: return (3 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD3D_6: return (3 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD3D_7: return (3 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD4D_0: return (4 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD4D_1: return (4 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD4D_2: return (4 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD4D_3: return (4 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD4D_4: return (4 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD4D_5: return (4 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD4D_6: return (4 * sizeof(float)); + case VERTEX_ELEMENT_TEXCOORD4D_7: return (4 * sizeof(float)); + default: + Assert(0); + return 0; + }; +} + + +enum MaterialVarFlags_t +{ + MATERIAL_VAR_DEBUG = (1 << 0), + MATERIAL_VAR_NO_DEBUG_OVERRIDE = (1 << 1), + MATERIAL_VAR_NO_DRAW = (1 << 2), + MATERIAL_VAR_USE_IN_FILLRATE_MODE = (1 << 3), + + MATERIAL_VAR_VERTEXCOLOR = (1 << 4), + MATERIAL_VAR_VERTEXALPHA = (1 << 5), + MATERIAL_VAR_SELFILLUM = (1 << 6), + MATERIAL_VAR_ADDITIVE = (1 << 7), + MATERIAL_VAR_ALPHATEST = (1 << 8), + MATERIAL_VAR_MULTIPASS = (1 << 9), + MATERIAL_VAR_ZNEARER = (1 << 10), + MATERIAL_VAR_MODEL = (1 << 11), + MATERIAL_VAR_FLAT = (1 << 12), + MATERIAL_VAR_NOCULL = (1 << 13), + MATERIAL_VAR_NOFOG = (1 << 14), + MATERIAL_VAR_IGNOREZ = (1 << 15), + MATERIAL_VAR_DECAL = (1 << 16), + MATERIAL_VAR_ENVMAPSPHERE = (1 << 17), + MATERIAL_VAR_NOALPHAMOD = (1 << 18), + MATERIAL_VAR_ENVMAPCAMERASPACE = (1 << 19), + MATERIAL_VAR_BASEALPHAENVMAPMASK = (1 << 20), + MATERIAL_VAR_TRANSLUCENT = (1 << 21), + MATERIAL_VAR_NORMALMAPALPHAENVMAPMASK = (1 << 22), + MATERIAL_VAR_NEEDS_SOFTWARE_SKINNING = (1 << 23), + MATERIAL_VAR_OPAQUETEXTURE = (1 << 24), + MATERIAL_VAR_ENVMAPMODE = (1 << 25), + MATERIAL_VAR_SUPPRESS_DECALS = (1 << 26), + MATERIAL_VAR_HALFLAMBERT = (1 << 27), + MATERIAL_VAR_WIREFRAME = (1 << 28), + MATERIAL_VAR_ALLOWALPHATOCOVERAGE = (1 << 29), + MATERIAL_VAR_IGNORE_ALPHA_MODULATION = (1 << 30), + +}; + + +enum MaterialVarFlags2_t +{ + MATERIAL_VAR2_LIGHTING_UNLIT = 0, + MATERIAL_VAR2_LIGHTING_VERTEX_LIT = (1 << 1), + MATERIAL_VAR2_LIGHTING_LIGHTMAP = (1 << 2), + MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP = (1 << 3), + MATERIAL_VAR2_LIGHTING_MASK = + (MATERIAL_VAR2_LIGHTING_VERTEX_LIT | + MATERIAL_VAR2_LIGHTING_LIGHTMAP | + MATERIAL_VAR2_LIGHTING_BUMPED_LIGHTMAP), + + MATERIAL_VAR2_DIFFUSE_BUMPMAPPED_MODEL = (1 << 4), + MATERIAL_VAR2_USES_ENV_CUBEMAP = (1 << 5), + MATERIAL_VAR2_NEEDS_TANGENT_SPACES = (1 << 6), + MATERIAL_VAR2_NEEDS_SOFTWARE_LIGHTING = (1 << 7), + MATERIAL_VAR2_BLEND_WITH_LIGHTMAP_ALPHA = (1 << 8), + MATERIAL_VAR2_NEEDS_BAKED_LIGHTING_SNAPSHOTS = (1 << 9), + MATERIAL_VAR2_USE_FLASHLIGHT = (1 << 10), + MATERIAL_VAR2_USE_FIXED_FUNCTION_BAKED_LIGHTING = (1 << 11), + MATERIAL_VAR2_NEEDS_FIXED_FUNCTION_FLASHLIGHT = (1 << 12), + MATERIAL_VAR2_USE_EDITOR = (1 << 13), + MATERIAL_VAR2_NEEDS_POWER_OF_TWO_FRAME_BUFFER_TEXTURE = (1 << 14), + MATERIAL_VAR2_NEEDS_FULL_FRAME_BUFFER_TEXTURE = (1 << 15), + MATERIAL_VAR2_IS_SPRITECARD = (1 << 16), + MATERIAL_VAR2_USES_VERTEXID = (1 << 17), + MATERIAL_VAR2_SUPPORTS_HW_SKINNING = (1 << 18), + MATERIAL_VAR2_SUPPORTS_FLASHLIGHT = (1 << 19), +}; + + +enum PreviewImageRetVal_t +{ + MATERIAL_PREVIEW_IMAGE_BAD = 0, + MATERIAL_PREVIEW_IMAGE_OK, + MATERIAL_NO_PREVIEW_IMAGE, +}; + + +abstract_class IMaterial +{ +public: + virtual const char* GetName() const = 0; + virtual const char* GetTextureGroupName() const = 0; + + virtual PreviewImageRetVal_t GetPreviewImageProperties(int* width, int* height, + ImageFormat* imageFormat, bool* isTranslucent) const = 0; + + virtual PreviewImageRetVal_t GetPreviewImage(unsigned char* data, + int width, int height, + ImageFormat imageFormat) const = 0; + virtual int GetMappingWidth() = 0; + virtual int GetMappingHeight() = 0; + + virtual int GetNumAnimationFrames() = 0; + + virtual bool InMaterialPage(void) = 0; + virtual void GetMaterialOffset(float* pOffset) = 0; + virtual void GetMaterialScale(float* pScale) = 0; + virtual IMaterial* GetMaterialPage(void) = 0; + + virtual IMaterialVar* FindVar(const char* varName, bool* found, bool complain = true) = 0; + + virtual void IncrementReferenceCount(void) = 0; + virtual void DecrementReferenceCount(void) = 0; + + inline void AddRef() { IncrementReferenceCount(); } + inline void Release() { DecrementReferenceCount(); } + + virtual int GetEnumerationID(void) const = 0; + + virtual void GetLowResColorSample(float s, float t, float* color) const = 0; + + virtual void RecomputeStateSnapshots() = 0; + + virtual bool IsTranslucent() = 0; + + virtual bool IsAlphaTested() = 0; + + virtual bool IsVertexLit() = 0; + + virtual VertexFormat_t GetVertexFormat() const = 0; + + virtual bool HasProxy(void) const = 0; + + virtual bool UsesEnvCubemap(void) = 0; + + virtual bool NeedsTangentSpace(void) = 0; + + virtual bool NeedsPowerOfTwoFrameBufferTexture(bool bCheckSpecificToThisFrame = true) = 0; + virtual bool NeedsFullFrameBufferTexture(bool bCheckSpecificToThisFrame = true) = 0; + + virtual bool NeedsSoftwareSkinning(void) = 0; + + virtual void AlphaModulate(float alpha) = 0; + virtual void ColorModulate(float r, float g, float b) = 0; + + virtual void SetMaterialVarFlag(MaterialVarFlags_t flag, bool on) = 0; + virtual bool GetMaterialVarFlag(MaterialVarFlags_t flag) const = 0; + + virtual void GetReflectivity(Vector& reflect) = 0; + + virtual bool GetPropertyFlag(MaterialPropertyTypes_t type) = 0; + + virtual bool IsTwoSided() = 0; + + virtual void SetShader(const char* pShaderName) = 0; + + virtual int GetNumPasses(void) = 0; + + virtual int GetTextureMemoryBytes(void) = 0; + + virtual void Refresh() = 0; + + virtual bool NeedsLightmapBlendAlpha(void) = 0; + + virtual bool NeedsSoftwareLighting(void) = 0; + + virtual int ShaderParamCount() const = 0; + virtual IMaterialVar** GetShaderParams(void) = 0; + + virtual bool IsErrorMaterial() const = 0; + + virtual void SetUseFixedFunctionBakedLighting(bool bEnable) = 0; + + virtual float GetAlphaModulation() = 0; + virtual void GetColorModulation(float* r, float* g, float* b) = 0; + + virtual MorphFormat_t GetMorphFormat() const = 0; + + virtual IMaterialVar* FindVarFast(char const* pVarName, unsigned int* pToken) = 0; + + virtual void SetShaderAndParams(KeyValues* pKeyValues) = 0; + virtual const char* GetShaderName() const = 0; + + virtual void DeleteIfUnreferenced() = 0; + + virtual bool IsSpriteCard() = 0; + + virtual void CallBindProxy(void* proxyData) = 0; + + virtual IMaterial* CheckProxyReplacement(void* proxyData) = 0; + + virtual void RefreshPreservingMaterialVars() = 0; + + virtual bool WasReloadedFromWhitelist() = 0; + + virtual bool IsPrecached() const = 0; +}; + + +inline bool IsErrorMaterial(IMaterial* pMat) +{ + return !pMat || pMat->IsErrorMaterial(); +} + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/imaterialsystem.h b/SpyCustom/sdk/imaterialsystem.h new file mode 100644 index 0000000..a672559 --- /dev/null +++ b/SpyCustom/sdk/imaterialsystem.h @@ -0,0 +1,1632 @@ +#ifndef IMATERIALSYSTEM_H +#define IMATERIALSYSTEM_H + +#ifdef _WIN32 +#pragma once +#endif + +#define OVERBRIGHT 2.0f +#define OO_OVERBRIGHT ( 1.0f / 2.0f ) +#define GAMMA 2.2f +#define TEXGAMMA 2.2f + +#include "interface.h" +#include "refcount.h" +#include "vector.h" +#include "vector4d.h" +#include "vmatrix.h" +#include "iappsystem.h" +#include "imageformat.h" +#include "texture_group_names.h" +#include "vtf.h" +#include "deformations.h" + +enum HDRType_t +{ + HDR_TYPE_NONE, + HDR_TYPE_INTEGER, + HDR_TYPE_FLOAT, +}; + +#include "imaterialsystemhardwareconfig.h" +#include "IColorCorrection.h" + +#if !defined( _GAMECONSOLE ) +#endif + +#if defined(_PS3) +typedef void* HPS3FONT; +class CPS3FontMetrics; +class CPS3CharMetrics; + +enum GpuDataTransferCache_t +{ + PS3GPU_DATA_TRANSFER_CREATECACHELINK = 0x80000000, + PS3GPU_DATA_TRANSFER_CACHE2REAL = 0x01000000, + PS3GPU_DATA_TRANSFER_REAL2CACHE = 0x02000000, + PS3GPU_DATA_TRANSFER_MASK = 0xFF000000, +}; +#endif + +class IMaterial; +class IMesh; +class IVertexBuffer; +class IIndexBuffer; +struct MaterialSystem_Config_t; +class VMatrix; +struct matrix3x4_t; +class ITexture; +struct MaterialSystemHardwareIdentifier_t; +class KeyValues; +class IShader; +class IVertexTexture; +class IMorph; +class IMatRenderContext; +class ICallQueue; +struct MorphWeight_t; +class IFileList; +struct VertexStreamSpec_t; +struct ShaderStencilState_t; +struct MeshInstanceData_t; +class IClientMaterialSystem; +class CPaintMaterial; +class IPaintmapDataManager; +class IPaintmapTextureManager; +struct GPUMemoryStats; +class ICustomMaterialManager; +class ICompositeTextureGenerator; + +typedef uint64 VertexFormat_t; + +enum ShaderParamType_t +{ + SHADER_PARAM_TYPE_TEXTURE, + SHADER_PARAM_TYPE_INTEGER, + SHADER_PARAM_TYPE_COLOR, + SHADER_PARAM_TYPE_VEC2, + SHADER_PARAM_TYPE_VEC3, + SHADER_PARAM_TYPE_VEC4, + SHADER_PARAM_TYPE_ENVMAP, + SHADER_PARAM_TYPE_FLOAT, + SHADER_PARAM_TYPE_BOOL, + SHADER_PARAM_TYPE_FOURCC, + SHADER_PARAM_TYPE_MATRIX, + SHADER_PARAM_TYPE_MATERIAL, + SHADER_PARAM_TYPE_STRING, +}; + +enum MaterialMatrixMode_t +{ + MATERIAL_VIEW = 0, + MATERIAL_PROJECTION, + + MATERIAL_MATRIX_UNUSED0, + MATERIAL_MATRIX_UNUSED1, + MATERIAL_MATRIX_UNUSED2, + MATERIAL_MATRIX_UNUSED3, + MATERIAL_MATRIX_UNUSED4, + MATERIAL_MATRIX_UNUSED5, + MATERIAL_MATRIX_UNUSED6, + MATERIAL_MATRIX_UNUSED7, + + MATERIAL_MODEL, + + NUM_MATRIX_MODES = MATERIAL_MODEL + 1, +}; + +const int NUM_MODEL_TRANSFORMS = 53; +const int MATERIAL_MODEL_MAX = MATERIAL_MODEL + NUM_MODEL_TRANSFORMS; + +enum MaterialPrimitiveType_t +{ + MATERIAL_POINTS = 0x0, + MATERIAL_LINES, + MATERIAL_TRIANGLES, + MATERIAL_TRIANGLE_STRIP, + MATERIAL_LINE_STRIP, + MATERIAL_LINE_LOOP, + MATERIAL_POLYGON, + MATERIAL_QUADS, + MATERIAL_SUBD_QUADS_EXTRA, + MATERIAL_SUBD_QUADS_REG, + MATERIAL_INSTANCED_QUADS, + + MATERIAL_HETEROGENOUS +}; + +enum TessellationMode_t +{ + TESSELLATION_MODE_DISABLED = 0, + TESSELLATION_MODE_ACC_PATCHES_EXTRA, + TESSELLATION_MODE_ACC_PATCHES_REG +}; + +enum MaterialPropertyTypes_t +{ + MATERIAL_PROPERTY_NEEDS_LIGHTMAP = 0, + MATERIAL_PROPERTY_OPACITY, + MATERIAL_PROPERTY_REFLECTIVITY, + MATERIAL_PROPERTY_NEEDS_BUMPED_LIGHTMAPS +}; + +enum MaterialPropertyOpacityTypes_t +{ + MATERIAL_ALPHATEST = 0, + MATERIAL_OPAQUE, + MATERIAL_TRANSLUCENT +}; + +enum MaterialBufferTypes_t +{ + MATERIAL_FRONT = 0, + MATERIAL_BACK +}; + +enum MaterialCullMode_t +{ + MATERIAL_CULLMODE_CCW, + MATERIAL_CULLMODE_CW, + MATERIAL_CULLMODE_NONE +}; + +enum MaterialIndexFormat_t +{ + MATERIAL_INDEX_FORMAT_UNKNOWN = -1, + MATERIAL_INDEX_FORMAT_16BIT = 0, + MATERIAL_INDEX_FORMAT_32BIT, +}; + +enum MaterialFogMode_t +{ + MATERIAL_FOG_NONE, + MATERIAL_FOG_LINEAR, + MATERIAL_FOG_LINEAR_BELOW_FOG_Z, +}; + +enum MaterialHeightClipMode_t +{ + MATERIAL_HEIGHTCLIPMODE_DISABLE, + MATERIAL_HEIGHTCLIPMODE_RENDER_ABOVE_HEIGHT, + MATERIAL_HEIGHTCLIPMODE_RENDER_BELOW_HEIGHT +}; + +enum MaterialNonInteractiveMode_t +{ + MATERIAL_NON_INTERACTIVE_MODE_NONE = -1, + MATERIAL_NON_INTERACTIVE_MODE_STARTUP = 0, + MATERIAL_NON_INTERACTIVE_MODE_LEVEL_LOAD, + + MATERIAL_NON_INTERACTIVE_MODE_COUNT, +}; + + +#define MATERIAL_MORPH_DECAL ( (IMorph*)1 ) + + +enum MaterialThreadMode_t +{ + MATERIAL_SINGLE_THREADED, + MATERIAL_QUEUED_SINGLE_THREADED, + MATERIAL_QUEUED_THREADED +}; + +enum MaterialContextType_t +{ + MATERIAL_HARDWARE_CONTEXT, + MATERIAL_QUEUED_CONTEXT, + MATERIAL_NULL_CONTEXT +}; + + +#include "lightdesc.h" + +enum +{ + MATERIAL_MAX_LIGHT_COUNT = 4, +}; + +struct MaterialLightingState_t +{ + Vector m_vecAmbientCube[6]; + Vector m_vecLightingOrigin; + int m_nLocalLightCount; + LightDesc_t m_pLocalLightDesc[MATERIAL_MAX_LIGHT_COUNT]; + + MaterialLightingState_t& operator=(const MaterialLightingState_t& src) + { + memcpy(this, &src, sizeof(MaterialLightingState_t) - MATERIAL_MAX_LIGHT_COUNT * sizeof(LightDesc_t)); + size_t byteCount = src.m_nLocalLightCount * sizeof(LightDesc_t); + Assert(byteCount <= sizeof(m_pLocalLightDesc)); + memcpy(m_pLocalLightDesc, &src.m_pLocalLightDesc, byteCount); + return *this; + } +}; + + + +#define CREATERENDERTARGETFLAGS_HDR 0x00000001 +#define CREATERENDERTARGETFLAGS_AUTOMIPMAP 0x00000002 +#define CREATERENDERTARGETFLAGS_UNFILTERABLE_OK 0x00000004 +#define CREATERENDERTARGETFLAGS_NOEDRAM 0x00000008 +#define CREATERENDERTARGETFLAGS_TEMP 0x00000010 +#define CREATERENDERTARGETFLAGS_ALIASCOLORANDDEPTHSURFACES 0x00000020 + + +struct MaterialBatchData_t +{ + IMaterial* m_pMaterial; + matrix3x4_t* m_pModelToWorld; + const ITexture* m_pEnvCubemap; + int m_nLightmapPageId; + MaterialPrimitiveType_t m_nPrimType; + int m_nIndexOffset; + int m_nIndexCount; + int m_nVertexOffsetInBytes; + const IIndexBuffer* m_pIndexBuffer; + const IVertexBuffer* m_pVertexBuffer; +}; + + +enum MorphFormatFlags_t +{ + MORPH_POSITION = 0x0001, + MORPH_NORMAL = 0x0002, + MORPH_WRINKLE = 0x0004, + MORPH_SPEED = 0x0008, + MORPH_SIDE = 0x0010, +}; + + +typedef unsigned int MorphFormat_t; + + +enum StandardLightmap_t +{ + MATERIAL_SYSTEM_LIGHTMAP_PAGE_WHITE = -1, + MATERIAL_SYSTEM_LIGHTMAP_PAGE_WHITE_BUMP = -2, + MATERIAL_SYSTEM_LIGHTMAP_PAGE_USER_DEFINED = -3, + MATERIAL_SYSTEM_LIGHTMAP_PAGE_INVALID = -4, +}; + + +struct MaterialSystem_SortInfo_t +{ + IMaterial* material; + int lightmapPageID; +}; + + +#define MAX_FB_TEXTURES 4 + +enum +{ + MATERIAL_ADAPTER_NAME_LENGTH = 512 +}; + +struct MaterialAdapterInfo_t +{ + char m_pDriverName[MATERIAL_ADAPTER_NAME_LENGTH]; + unsigned int m_VendorID; + unsigned int m_DeviceID; + unsigned int m_SubSysID; + unsigned int m_Revision; + int m_nDXSupportLevel; + int m_nMinDXSupportLevel; + int m_nMaxDXSupportLevel; + unsigned int m_nDriverVersionHigh; + unsigned int m_nDriverVersionLow; +}; + + +struct MaterialVideoMode_t +{ + int m_Width; + int m_Height; + ImageFormat m_Format; + int m_RefreshRate; +}; + + +struct UberlightState_t +{ + UberlightState_t() + { + m_fNearEdge = 2.0f; + m_fFarEdge = 100.0f; + m_fCutOn = 10.0f; + m_fCutOff = 650.0f; + m_fShearx = 0.0f; + m_fSheary = 0.0f; + m_fWidth = 0.3f; + m_fWedge = 0.05f; + m_fHeight = 0.3f; + m_fHedge = 0.05f; + m_fRoundness = 0.8f; + } + + float m_fNearEdge; + float m_fFarEdge; + float m_fCutOn; + float m_fCutOff; + float m_fShearx; + float m_fSheary; + float m_fWidth; + float m_fWedge; + float m_fHeight; + float m_fHedge; + float m_fRoundness; + + IMPLEMENT_OPERATOR_EQUAL(UberlightState_t); +}; + +struct FlashlightState_t +{ + FlashlightState_t() + { + m_bEnableShadows = false; + m_bDrawShadowFrustum = false; + m_flShadowMapResolution = 1024.0f; + m_flShadowFilterSize = 3.0f; + m_flShadowSlopeScaleDepthBias = 16.0f; + m_flShadowDepthBias = 0.0005f; + m_flShadowJitterSeed = 0.0f; + m_flShadowAtten = 0.0f; + m_flAmbientOcclusion = 0.0f; + m_nShadowQuality = 0; + m_bShadowHighRes = false; + + m_bScissor = false; + m_nLeft = -1; + m_nTop = -1; + m_nRight = -1; + m_nBottom = -1; + + m_bUberlight = false; + + m_bVolumetric = false; + m_flNoiseStrength = 0.8f; + m_flFlashlightTime = 0.0f; + m_nNumPlanes = 64; + m_flPlaneOffset = 0.0f; + m_flVolumetricIntensity = 1.0f; + + m_bOrtho = false; + m_fOrthoLeft = -1.0f; + m_fOrthoRight = 1.0f; + m_fOrthoTop = -1.0f; + m_fOrthoBottom = 1.0f; + + m_fBrightnessScale = 1.0f; + m_pSpotlightTexture = NULL; + m_pProjectedMaterial = NULL; + m_bShareBetweenSplitscreenPlayers = false; + } + + Vector m_vecLightOrigin; + Quaternion m_quatOrientation; + float m_NearZ; + float m_FarZ; + float m_fHorizontalFOVDegrees; + float m_fVerticalFOVDegrees; + bool m_bOrtho; + float m_fOrthoLeft; + float m_fOrthoRight; + float m_fOrthoTop; + float m_fOrthoBottom; + float m_fQuadraticAtten; + float m_fLinearAtten; + float m_fConstantAtten; + float m_FarZAtten; + float m_Color[4]; + float m_fBrightnessScale; + ITexture* m_pSpotlightTexture; + IMaterial* m_pProjectedMaterial; + int m_nSpotlightTextureFrame; + + bool m_bEnableShadows; + bool m_bDrawShadowFrustum; + float m_flShadowMapResolution; + float m_flShadowFilterSize; + float m_flShadowSlopeScaleDepthBias; + float m_flShadowDepthBias; + float m_flShadowJitterSeed; + float m_flShadowAtten; + float m_flAmbientOcclusion; + int m_nShadowQuality; + bool m_bShadowHighRes; + + float m_flProjectionSize; + float m_flProjectionRotation; + + bool m_bUberlight; + UberlightState_t m_uberlightState; + + bool m_bVolumetric; + float m_flNoiseStrength; + float m_flFlashlightTime; + int m_nNumPlanes; + float m_flPlaneOffset; + float m_flVolumetricIntensity; + bool m_bShareBetweenSplitscreenPlayers; + + bool DoScissor() const { return m_bScissor; } + int GetLeft() const { return m_nLeft; } + int GetTop() const { return m_nTop; } + int GetRight() const { return m_nRight; } + int GetBottom() const { return m_nBottom; } + +private: + + friend class CShadowMgr; + + bool m_bScissor; + int m_nLeft; + int m_nTop; + int m_nRight; + int m_nBottom; + + IMPLEMENT_OPERATOR_EQUAL(FlashlightState_t); +}; + +#define MAX_CASCADED_SHADOW_MAPPING_CASCADES (4) + +#define CASCADED_SHADOW_MAPPING_CONSTANT_BUFFER_SIZE (26) + +struct CascadedShadowMappingState_t +{ + uint m_nNumCascades; + bool m_bIsRenderingViewModels; + + Vector4D m_vLightColor; + + Vector m_vLightDir; + float m_flPadding1; + + struct + { + float m_flInvShadowTextureWidth; + float m_flInvShadowTextureHeight; + float m_flHalfInvShadowTextureWidth; + float m_flHalfInvShadowTextureHeight; + } m_TexParams; + + struct + { + float m_flShadowTextureWidth; + float m_flShadowTextureHeight; + float m_flSplitLerpFactorBase; + float m_flSplitLerpFactorInvRange; + } m_TexParams2; + + struct + { + float m_flDistLerpFactorBase; + float m_flDistLerpFactorInvRange; + float m_flUnused0; + float m_flUnused1; + } m_TexParams3; + + VMatrix m_matWorldToShadowTexMatrices[MAX_CASCADED_SHADOW_MAPPING_CASCADES]; + Vector4D m_vCascadeAtlasUVOffsets[MAX_CASCADED_SHADOW_MAPPING_CASCADES]; + + Vector4D m_vCamPosition; +}; + +enum MaterialInitFlags_t +{ + MATERIAL_INIT_ALLOCATE_FULLSCREEN_TEXTURE = 0x2, + MATERIAL_INIT_REFERENCE_RASTERIZER = 0x4, +}; + +enum MaterialRenderTargetDepth_t +{ + MATERIAL_RT_DEPTH_SHARED = 0x0, + MATERIAL_RT_DEPTH_SEPARATE = 0x1, + MATERIAL_RT_DEPTH_NONE = 0x2, + MATERIAL_RT_DEPTH_ONLY = 0x3, +}; + +enum RestoreChangeFlags_t +{ + MATERIAL_RESTORE_VERTEX_FORMAT_CHANGED = 0x1, + MATERIAL_RESTORE_RELEASE_MANAGED_RESOURCES = 0x2, +}; + + +enum RenderTargetSizeMode_t +{ + RT_SIZE_NO_CHANGE = 0, + RT_SIZE_DEFAULT = 1, + RT_SIZE_PICMIP = 2, + RT_SIZE_HDR = 3, + RT_SIZE_FULL_FRAME_BUFFER = 4, + RT_SIZE_OFFSCREEN = 5, + RT_SIZE_FULL_FRAME_BUFFER_ROUNDED_UP = 6 +}; + + +enum AntiAliasingHintEnum_t +{ + AA_HINT_MESHES, + AA_HINT_TEXT, + AA_HINT_DEBUG_TEXT, + AA_HINT_HEAVY_UI_OVERLAY, + AA_HINT_ALIASING_PUSH, + AA_HINT_ALIASING_POP, + AA_HINT_POSTPROCESS, + AA_HINT_MOVIE, + AA_HINT_MENU +}; + +typedef void (*MaterialBufferReleaseFunc_t)(int nChangeFlags); +typedef void (*MaterialBufferRestoreFunc_t)(int nChangeFlags); +typedef void (*ModeChangeCallbackFunc_t)(void); +typedef void (*EndFrameCleanupFunc_t)(void); +typedef void (*OnLevelShutdownFunc_t)(void* pUserData); +typedef bool (*EndFramePriorToNextContextFunc_t)(void); + +typedef unsigned short MaterialHandle_t; + +DECLARE_POINTER_HANDLE(OcclusionQueryObjectHandle_t); +#define INVALID_OCCLUSION_QUERY_OBJECT_HANDLE ( (OcclusionQueryObjectHandle_t)0 ) + +class IMaterialProxyFactory; +class ITexture; +class IMaterialSystemHardwareConfig; +class CShadowMgr; + +DECLARE_POINTER_HANDLE(MaterialLock_t); + +struct MaterialTextureInfo_t +{ + int iExcludeInformation; +}; + +struct ApplicationPerformanceCountersInfo_t +{ + float msMain; + float msMST; + float msGPU; + float msFlip; + float msTotal; +}; + +struct ApplicationInstantCountersInfo_t +{ + uint m_nCpuActivityMask; + uint m_nDeferredWordsAllocated; +}; + + +struct WorldListIndicesInfo_t +{ + uint m_nTotalIndices; + uint m_nMaxBatchIndices; +}; + +struct AspectRatioInfo_t +{ + bool m_bIsWidescreen; + bool m_bIsHidef; + float m_flFrameBufferAspectRatio; + float m_flPhysicalAspectRatio; + float m_flFrameBuffertoPhysicalScalar; + float m_flPhysicalToFrameBufferScalar; + bool m_bInitialized; + + AspectRatioInfo_t() : + m_bIsWidescreen(false), + m_bIsHidef(false), + m_flFrameBufferAspectRatio(4.0f / 3.0f), + m_flPhysicalAspectRatio(4.0f / 3.0f), + m_flFrameBuffertoPhysicalScalar(1.0f), + m_flPhysicalToFrameBufferScalar(1.0f), + m_bInitialized(false) + { + } +}; + +abstract_class IMaterialSystem : public IAppSystem +{ +public: + + virtual bool Connect(CreateInterfaceFn factory) = 0; + virtual void Disconnect() = 0; + virtual void* QueryInterface(const char* pInterfaceName) = 0; + virtual InitReturnVal_t Init() = 0; + virtual void Shutdown() = 0; + + virtual CreateInterfaceFn Init(char const* pShaderAPIDLL, + IMaterialProxyFactory* pMaterialProxyFactory, + CreateInterfaceFn fileSystemFactory, + CreateInterfaceFn cvarFactory = NULL) = 0; + + virtual void SetShaderAPI(char const* pShaderAPIDLL) = 0; + + virtual void SetAdapter(int nAdapter, int nFlags) = 0; + + virtual void ModInit() = 0; + virtual void ModShutdown() = 0; + + virtual void SetThreadMode(MaterialThreadMode_t mode, int nServiceThread = -1) = 0; + virtual MaterialThreadMode_t GetThreadMode() = 0; + virtual bool IsRenderThreadSafe() = 0; + virtual void ExecuteQueued() = 0; + #ifdef _CERT + static + #else + virtual + #endif + void OnDebugEvent(const char* pEvent = "") {} + + virtual IMaterialSystemHardwareConfig* GetHardwareConfig(const char* pVersion, int* returnCode) = 0; + + + virtual bool UpdateConfig(bool bForceUpdate) = 0; + + virtual bool OverrideConfig(const MaterialSystem_Config_t& config, bool bForceUpdate) = 0; + + virtual const MaterialSystem_Config_t& GetCurrentConfigForVideoCard() const = 0; + + virtual bool GetRecommendedConfigurationInfo(int nDXLevel, KeyValues* pKeyValues) = 0; + + + virtual int GetDisplayAdapterCount() const = 0; + + virtual int GetCurrentAdapter() const = 0; + + virtual void GetDisplayAdapterInfo(int adapter, MaterialAdapterInfo_t& info) const = 0; + + virtual int GetModeCount(int adapter) const = 0; + + virtual void GetModeInfo(int adapter, int mode, MaterialVideoMode_t& info) const = 0; + + virtual void AddModeChangeCallBack(ModeChangeCallbackFunc_t func) = 0; + + virtual void GetDisplayMode(MaterialVideoMode_t& mode) const = 0; + + virtual bool SetMode(void* hwnd, const MaterialSystem_Config_t& config) = 0; + + virtual bool SupportsMSAAMode(int nMSAAMode) = 0; + + virtual const MaterialSystemHardwareIdentifier_t& GetVideoCardIdentifier(void) const = 0; + + virtual void SpewDriverInfo() const = 0; + + virtual void GetBackBufferDimensions(int& width, int& height) const = 0; + virtual ImageFormat GetBackBufferFormat() const = 0; + virtual const AspectRatioInfo_t& GetAspectRatioInfo() const = 0; + + virtual bool SupportsHDRMode(HDRType_t nHDRModede) = 0; + + + virtual bool AddView(void* hwnd) = 0; + virtual void RemoveView(void* hwnd) = 0; + + virtual void SetView(void* hwnd) = 0; + + + virtual void BeginFrame(float frameTime) = 0; + virtual void EndFrame() = 0; + virtual void Flush(bool flushHardware = false) = 0; + virtual uint32 GetCurrentFrameCount() = 0; + + virtual void SwapBuffers() = 0; + + virtual void EvictManagedResources() = 0; + + virtual void ReleaseResources(void) = 0; + virtual void ReacquireResources(void) = 0; + + + virtual void AddReleaseFunc(MaterialBufferReleaseFunc_t func) = 0; + virtual void RemoveReleaseFunc(MaterialBufferReleaseFunc_t func) = 0; + + virtual void AddRestoreFunc(MaterialBufferRestoreFunc_t func) = 0; + virtual void RemoveRestoreFunc(MaterialBufferRestoreFunc_t func) = 0; + + virtual void AddEndFrameCleanupFunc(EndFrameCleanupFunc_t func) = 0; + virtual void RemoveEndFrameCleanupFunc(EndFrameCleanupFunc_t func) = 0; + + virtual void OnLevelShutdown() = 0; + virtual bool AddOnLevelShutdownFunc(OnLevelShutdownFunc_t func, void* pUserData) = 0; + virtual bool RemoveOnLevelShutdownFunc(OnLevelShutdownFunc_t func, void* pUserData) = 0; + + virtual void OnLevelLoadingComplete() = 0; + + virtual void ResetTempHWMemory(bool bExitingLevel = false) = 0; + + virtual void HandleDeviceLost() = 0; + + + virtual int ShaderCount() const = 0; + virtual int GetShaders(int nFirstShader, int nMaxCount, IShader** ppShaderList) const = 0; + + virtual int ShaderFlagCount() const = 0; + virtual const char* ShaderFlagName(int nIndex) const = 0; + + virtual void GetShaderFallback(const char* pShaderName, char* pFallbackShader, int nFallbackLength) = 0; + + + virtual IMaterialProxyFactory* GetMaterialProxyFactory() = 0; + + virtual void SetMaterialProxyFactory(IMaterialProxyFactory* pFactory) = 0; + + + virtual void EnableEditorMaterials() = 0; + virtual void EnableGBuffers() = 0; + + virtual void SetInStubMode(bool bInStubMode) = 0; + + + virtual void DebugPrintUsedMaterials(const char* pSearchSubString, bool bVerbose) = 0; + virtual void DebugPrintUsedTextures(void) = 0; + + virtual void ToggleSuppressMaterial(char const* pMaterialName) = 0; + virtual void ToggleDebugMaterial(char const* pMaterialName) = 0; + + + virtual bool UsingFastClipping(void) = 0; + + virtual int StencilBufferBits(void) = 0; + + + virtual void UncacheAllMaterials() = 0; + + virtual void UncacheUnusedMaterials(bool bRecomputeStateSnapshots = false) = 0; + + virtual void CacheUsedMaterials() = 0; + + virtual void ReloadTextures() = 0; + + virtual void ReloadMaterials(const char* pSubString = NULL) = 0; + + virtual IMaterial* CreateMaterial(const char* pMaterialName, KeyValues* pVMTKeyValues) = 0; + + virtual IMaterial* FindMaterial(char const* pMaterialName, const char* pTextureGroupName, bool complain = true, const char* pComplainPrefix = NULL) = 0; + + virtual bool LoadKeyValuesFromVMTFile(KeyValues& vmtKeyValues, const char* pMaterialName, bool bUsesUNCFilename) = 0; + + virtual MaterialHandle_t FirstMaterial() const = 0; + + virtual MaterialHandle_t NextMaterial(MaterialHandle_t h) const = 0; + + virtual MaterialHandle_t InvalidMaterial() const = 0; + + virtual IMaterial* GetMaterial(MaterialHandle_t h) const = 0; + + virtual int GetNumMaterials() const = 0; + + virtual ITexture* FindTexture(char const* pTextureName, const char* pTextureGroupName, bool complain = true, int nAdditionalCreationFlags = 0) = 0; + + virtual bool IsTextureLoaded(char const* pTextureName) const = 0; + + virtual ITexture* CreateProceduralTexture(const char* pTextureName, + const char* pTextureGroupName, + int w, + int h, + ImageFormat fmt, + int nFlags) = 0; + + #if defined( _X360 ) + + virtual ITexture* CreateGamerpicTexture(const char* pTextureName, + const char* pTextureGroupName, + int nFlags) = 0; + + virtual bool UpdateLocalGamerpicTexture(ITexture* pTexture, DWORD userIndex) = 0; + + virtual bool UpdateRemoteGamerpicTexture(ITexture* pTexture, XUID xuid) = 0; + + #endif + + virtual void BeginRenderTargetAllocation() = 0; + virtual void EndRenderTargetAllocation() = 0; + + virtual ITexture* CreateRenderTargetTexture(int w, + int h, + RenderTargetSizeMode_t sizeMode, + ImageFormat format, + MaterialRenderTargetDepth_t depth = MATERIAL_RT_DEPTH_SHARED) = 0; + + virtual ITexture* CreateNamedRenderTargetTextureEx(const char* pRTName, + int w, + int h, + RenderTargetSizeMode_t sizeMode, + ImageFormat format, + MaterialRenderTargetDepth_t depth = MATERIAL_RT_DEPTH_SHARED, + unsigned int textureFlags = TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT, + unsigned int renderTargetFlags = 0) = 0; + + virtual ITexture* CreateNamedRenderTargetTexture(const char* pRTName, + int w, + int h, + RenderTargetSizeMode_t sizeMode, + ImageFormat format, + MaterialRenderTargetDepth_t depth = MATERIAL_RT_DEPTH_SHARED, + bool bClampTexCoords = true, + bool bAutoMipMap = false) = 0; + + virtual ITexture* CreateNamedRenderTargetTextureEx2(const char* pRTName, + int w, + int h, + RenderTargetSizeMode_t sizeMode, + ImageFormat format, + MaterialRenderTargetDepth_t depth = MATERIAL_RT_DEPTH_SHARED, + unsigned int textureFlags = TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT, + unsigned int renderTargetFlags = 0) = 0; + + virtual void BeginLightmapAllocation() = 0; + virtual void EndLightmapAllocation() = 0; + + virtual void CleanupLightmaps() = 0; + + virtual int AllocateLightmap(int width, int height, + int offsetIntoLightmapPage[2], + IMaterial* pMaterial) = 0; + virtual int AllocateWhiteLightmap(IMaterial* pMaterial) = 0; + + virtual void UpdateLightmap(int lightmapPageID, int lightmapSize[2], + int offsetIntoLightmapPage[2], + float* pFloatImage, float* pFloatImageBump1, + float* pFloatImageBump2, float* pFloatImageBump3) = 0; + + virtual int GetNumSortIDs() = 0; + virtual void GetSortInfo(MaterialSystem_SortInfo_t* sortInfoArray) = 0; + + virtual void GetLightmapPageSize(int lightmap, int* width, int* height) const = 0; + + virtual void ResetMaterialLightmapPageInfo() = 0; + + virtual bool IsStereoSupported() = 0; + virtual bool IsStereoActiveThisFrame() const = 0; + virtual void NVStereoUpdate() = 0; + + virtual void ClearBuffers(bool bClearColor, bool bClearDepth, bool bClearStencil = false) = 0; + + #if defined( _X360 ) + virtual void ListUsedMaterials(void) = 0; + virtual HXUIFONT OpenTrueTypeFont(const char* pFontname, int tall, int style) = 0; + virtual void CloseTrueTypeFont(HXUIFONT hFont) = 0; + virtual bool GetTrueTypeFontMetrics(HXUIFONT hFont, wchar_t wchFirst, wchar_t wchLast, XUIFontMetrics* pFontMetrics, XUICharMetrics* pCharMetrics) = 0; + virtual bool GetTrueTypeGlyphs(HXUIFONT hFont, int numChars, wchar_t* pWch, int* pOffsetX, int* pOffsetY, int* pWidth, int* pHeight, unsigned char* pRGBA, int* pRGBAOffset) = 0; + virtual void PersistDisplay() = 0; + virtual void* GetD3DDevice() = 0; + virtual bool OwnGPUResources(bool bEnable) = 0; + #elif defined(_PS3) + virtual void ListUsedMaterials(void) = 0; + virtual HPS3FONT OpenTrueTypeFont(const char* pFontname, int tall, int style) = 0; + virtual void CloseTrueTypeFont(HPS3FONT hFont) = 0; + virtual bool GetTrueTypeFontMetrics(HPS3FONT hFont, int nFallbackTall, wchar_t wchFirst, wchar_t wchLast, CPS3FontMetrics* pFontMetrics, CPS3CharMetrics* pCharMetrics) = 0; + virtual bool GetTrueTypeGlyphs(HPS3FONT hFont, int nFallbackTall, int numChars, wchar_t* pWch, int* pOffsetX, int* pOffsetY, int* pWidth, int* pHeight, unsigned char* pRGBA, int* pRGBAOffset) = 0; + + virtual bool PS3InitFontLibrary(unsigned fontFileCacheSizeInBytes, unsigned maxNumFonts) { return false; }; + virtual void PS3DumpFontLibrary() { return; } + virtual void* PS3GetFontLibPtr() { return NULL; } + #if 0 + struct PS3FontLibraryRAII + { + PS3FontLibraryRAII(IMaterialSystem* imatsys, + unsigned int fontFileCacheSizeInBytes = 256 * 1024, unsigned int maxNumFonts = 64) : m_pmatsys(imatsys) + { + imatsys->PS3InitFontLibrary(fontFileCacheSizeInBytes, maxNumFonts); +} +~PS3FontLibraryRAII() + { +m_pmatsys->PS3DumpFontLibrary(); +} + +IMaterialSystem* m_pmatsys; +}; +#endif + enum VRAMScreenShotInfoColorFormat_t + { + kX8R8G8B8 = 0, kX8B8G8R8 = 1, kR16G16B16X16 = 2 +}; +virtual void TransmitScreenshotToVX() = 0; + +virtual void CompactRsxLocalMemory(char const* szReason) = 0; +virtual void SetFlipPresentFrequency(int nNumVBlanks) = 0; +#endif + + virtual void SpinPresent(uint nFrames) = 0; + + virtual IMatRenderContext* GetRenderContext() = 0; + + virtual void BeginUpdateLightmaps(void) = 0; + virtual void EndUpdateLightmaps(void) = 0; + + virtual MaterialLock_t Lock() = 0; + virtual void Unlock(MaterialLock_t) = 0; + + virtual IMatRenderContext* CreateRenderContext(MaterialContextType_t type) = 0; + + virtual IMatRenderContext* SetRenderContext(IMatRenderContext*) = 0; + + virtual bool SupportsCSAAMode(int nNumSamples, int nQualityLevel) = 0; + + virtual void RemoveModeChangeCallBack(ModeChangeCallbackFunc_t func) = 0; + + virtual IMaterial* FindProceduralMaterial(const char* pMaterialName, const char* pTextureGroupName, KeyValues* pVMTKeyValues = NULL) = 0; + + virtual void AddTextureAlias(const char* pAlias, const char* pRealName) = 0; + virtual void RemoveTextureAlias(const char* pAlias) = 0; + + virtual int AllocateDynamicLightmap(int lightmapSize[2], int* pOutOffsetIntoPage, int frameID) = 0; + + virtual void SetExcludedTextures(const char* pScriptName, bool bUsingWeaponModelCache) = 0; + virtual void UpdateExcludedTextures(void) = 0; + virtual void ClearForceExcludes(void) = 0; + + virtual bool IsInFrame() const = 0; + + virtual void CompactMemory() = 0; + + virtual void GetGPUMemoryStats(GPUMemoryStats& stats) = 0; + + virtual void ReloadFilesInList(IFileList* pFilesToReload) = 0; + + virtual bool GetTextureInformation(char const* szTextureName, MaterialTextureInfo_t& info) const = 0; + + virtual void FinishRenderTargetAllocation(void) = 0; + + virtual void ReEnableRenderTargetAllocation_IRealizeIfICallThisAllTexturesWillBeUnloadedAndLoadTimeWillSufferHorribly(void) = 0; + virtual bool AllowThreading(bool bAllow, int nServiceThread) = 0; + + virtual bool GetRecommendedVideoConfig(KeyValues* pKeyValues) = 0; + + virtual IClientMaterialSystem* GetClientMaterialSystemInterface() = 0; + + virtual bool CanDownloadTextures() const = 0; + virtual int GetNumLightmapPages() const = 0; + + virtual void RegisterPaintmapDataManager(IPaintmapDataManager* pDataManager) = 0; + virtual void BeginUpdatePaintmaps(void) = 0; + virtual void EndUpdatePaintmaps(void) = 0; + virtual void UpdatePaintmap(int paintmap, BYTE* pPaintData, int numRects, Rect_t* pRects) = 0; + + virtual ITexture* CreateNamedMultiRenderTargetTexture(const char* pRTName, + int w, + int h, + RenderTargetSizeMode_t sizeMode, + ImageFormat format, + MaterialRenderTargetDepth_t depth = MATERIAL_RT_DEPTH_SHARED, + unsigned int textureFlags = TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT, + unsigned int renderTargetFlags = 0) = 0; + + virtual void RefreshFrontBufferNonInteractive() = 0; + + virtual uint32 GetFrameTimestamps(ApplicationPerformanceCountersInfo_t& apci, ApplicationInstantCountersInfo_t& aici) = 0; + +#if defined( DX_TO_GL_ABSTRACTION ) && !defined( _GAMECONSOLE ) + virtual void DoStartupShaderPreloading(void) = 0; +#endif + + virtual void AddEndFramePriorToNextContextFunc(EndFramePriorToNextContextFunc_t func) = 0; + virtual void RemoveEndFramePriorToNextContextFunc(EndFramePriorToNextContextFunc_t func) = 0; + + virtual ICustomMaterialManager* GetCustomMaterialManager() = 0; + virtual ICompositeTextureGenerator* GetCompositeTextureGenerator() = 0; +}; + + +abstract_class IMatRenderContext : public IRefCounted +{ +public: + virtual void BeginRender() = 0; + virtual void EndRender() = 0; + + virtual void Flush(bool flushHardware = false) = 0; + + virtual void BindLocalCubemap(ITexture* pTexture) = 0; + + virtual void SetRenderTarget(ITexture* pTexture) = 0; + virtual ITexture* GetRenderTarget(void) = 0; + + virtual void GetRenderTargetDimensions(int& width, int& height) const = 0; + + virtual void Bind(IMaterial* material, void* proxyData = 0) = 0; + virtual void BindLightmapPage(int lightmapPageID) = 0; + + virtual void DepthRange(float zNear, float zFar) = 0; + + virtual void ClearBuffers(bool bClearColor, bool bClearDepth, bool bClearStencil = false) = 0; + + virtual void ReadPixels(int x, int y, int width, int height, unsigned char* data, ImageFormat dstFormat, ITexture* pRenderTargetTexture = NULL) = 0; + virtual void ReadPixelsAsync(int x, int y, int width, int height, unsigned char* data, ImageFormat dstFormat, ITexture* pRenderTargetTexture = NULL, CThreadEvent* pPixelsReadEvent = NULL) = 0; + virtual void ReadPixelsAsyncGetResult(int x, int y, int width, int height, unsigned char* data, ImageFormat dstFormat, CThreadEvent* pGetResultEvent = NULL) = 0; + + virtual void SetLightingState(const MaterialLightingState_t& state) = 0; + virtual void SetLights(int nCount, const LightDesc_t* pLights) = 0; + + virtual void SetAmbientLightCube(Vector4D cube[6]) = 0; + + virtual void CopyRenderTargetToTexture(ITexture* pTexture) = 0; + + virtual void SetFrameBufferCopyTexture(ITexture* pTexture, int textureIndex = 0) = 0; + virtual ITexture* GetFrameBufferCopyTexture(int textureIndex) = 0; + + virtual void MatrixMode(MaterialMatrixMode_t matrixMode) = 0; + virtual void PushMatrix(void) = 0; + virtual void PopMatrix(void) = 0; + virtual void LoadMatrix(VMatrix const& matrix) = 0; + virtual void LoadMatrix(matrix3x4_t const& matrix) = 0; + virtual void MultMatrix(VMatrix const& matrix) = 0; + virtual void MultMatrix(matrix3x4_t const& matrix) = 0; + virtual void MultMatrixLocal(VMatrix const& matrix) = 0; + virtual void MultMatrixLocal(matrix3x4_t const& matrix) = 0; + virtual void GetMatrix(MaterialMatrixMode_t matrixMode, VMatrix* matrix) = 0; + virtual void GetMatrix(MaterialMatrixMode_t matrixMode, matrix3x4_t* matrix) = 0; + virtual void LoadIdentity(void) = 0; + virtual void Ortho(double left, double top, double right, double bottom, double zNear, double zFar) = 0; + virtual void PerspectiveX(double fovx, double aspect, double zNear, double zFar) = 0; + virtual void PickMatrix(int x, int y, int width, int height) = 0; + virtual void Rotate(float angle, float x, float y, float z) = 0; + virtual void Translate(float x, float y, float z) = 0; + virtual void Scale(float x, float y, float z) = 0; + virtual void Viewport(int x, int y, int width, int height) = 0; + virtual void GetViewport(int& x, int& y, int& width, int& height) const = 0; + + virtual void CullMode(MaterialCullMode_t cullMode) = 0; + virtual void FlipCullMode(void) = 0; + + virtual void BeginGeneratingCSMs() = 0; + virtual void EndGeneratingCSMs() = 0; + virtual void PerpareForCascadeDraw(int cascade, float fShadowSlopeScaleDepthBias, float fShadowDepthBias) = 0; + + virtual void SetHeightClipMode(MaterialHeightClipMode_t nHeightClipMode) = 0; + virtual void SetHeightClipZ(float z) = 0; + + virtual void FogMode(MaterialFogMode_t fogMode) = 0; + virtual void FogStart(float fStart) = 0; + virtual void FogEnd(float fEnd) = 0; + virtual void SetFogZ(float fogZ) = 0; + virtual MaterialFogMode_t GetFogMode(void) = 0; + + virtual void FogColor3f(float r, float g, float b) = 0; + virtual void FogColor3fv(float const* rgb) = 0; + virtual void FogColor3ub(unsigned char r, unsigned char g, unsigned char b) = 0; + virtual void FogColor3ubv(unsigned char const* rgb) = 0; + + virtual void GetFogColor(unsigned char* rgb) = 0; + + virtual void SetNumBoneWeights(int numBones) = 0; + + virtual IMesh* CreateStaticMesh(VertexFormat_t fmt, const char* pTextureBudgetGroup, IMaterial* pMaterial = NULL, VertexStreamSpec_t* pStreamSpec = NULL) = 0; + virtual void DestroyStaticMesh(IMesh* mesh) = 0; + + virtual IMesh* GetDynamicMesh( + bool buffered = true, + IMesh* pVertexOverride = 0, + IMesh* pIndexOverride = 0, + IMaterial* pAutoBind = 0) = 0; + + virtual IVertexBuffer* CreateStaticVertexBuffer(VertexFormat_t fmt, int nVertexCount, const char* pTextureBudgetGroup) = 0; + virtual IIndexBuffer* CreateStaticIndexBuffer(MaterialIndexFormat_t fmt, int nIndexCount, const char* pTextureBudgetGroup) = 0; + virtual void DestroyVertexBuffer(IVertexBuffer*) = 0; + virtual void DestroyIndexBuffer(IIndexBuffer*) = 0; + virtual IVertexBuffer* GetDynamicVertexBuffer(int streamID, VertexFormat_t vertexFormat, bool bBuffered = true) = 0; + virtual IIndexBuffer* GetDynamicIndexBuffer() = 0; + virtual void BindVertexBuffer(int streamID, IVertexBuffer* pVertexBuffer, int nOffsetInBytes, int nFirstVertex, int nVertexCount, VertexFormat_t fmt, int nRepetitions = 1) = 0; + virtual void BindIndexBuffer(IIndexBuffer* pIndexBuffer, int nOffsetInBytes) = 0; + virtual void Draw(MaterialPrimitiveType_t primitiveType, int firstIndex, int numIndices) = 0; + virtual int SelectionMode(bool selectionMode) = 0; + virtual void SelectionBuffer(unsigned int* pBuffer, int size) = 0; + virtual void ClearSelectionNames() = 0; + virtual void LoadSelectionName(int name) = 0; + virtual void PushSelectionName(int name) = 0; + virtual void PopSelectionName() = 0; + + virtual void ClearColor3ub(unsigned char r, unsigned char g, unsigned char b) = 0; + virtual void ClearColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a) = 0; + + virtual void OverrideDepthEnable(bool bEnable, bool bDepthWriteEnable, bool bDepthTestEnable = true) = 0; + + virtual void DrawScreenSpaceQuad(IMaterial* pMaterial) = 0; + + virtual void SyncToken(const char* pToken) = 0; + + virtual float ComputePixelWidthOfSphere(const Vector& origin, float flRadius) = 0; + + virtual OcclusionQueryObjectHandle_t CreateOcclusionQueryObject(void) = 0; + virtual void DestroyOcclusionQueryObject(OcclusionQueryObjectHandle_t) = 0; + + virtual void BeginOcclusionQueryDrawing(OcclusionQueryObjectHandle_t) = 0; + virtual void EndOcclusionQueryDrawing(OcclusionQueryObjectHandle_t) = 0; + + virtual int OcclusionQuery_GetNumPixelsRendered(OcclusionQueryObjectHandle_t) = 0; + + virtual void SetFlashlightMode(bool bEnable) = 0; + + virtual void SetFlashlightState(const FlashlightState_t& state, const VMatrix& worldToTexture) = 0; + + virtual bool IsCascadedShadowMapping() const = 0; + virtual void SetCascadedShadowMapping(bool bEnable) = 0; + virtual void SetCascadedShadowMappingState(const CascadedShadowMappingState_t& state, ITexture* pDepthTextureAtlas) = 0; + + virtual MaterialHeightClipMode_t GetHeightClipMode() = 0; + + virtual float ComputePixelDiameterOfSphere(const Vector& vecAbsOrigin, float flRadius) = 0; + + virtual void EnableUserClipTransformOverride(bool bEnable) = 0; + virtual void UserClipTransform(const VMatrix& worldToView) = 0; + + virtual bool GetFlashlightMode() const = 0; + + virtual bool IsCullingEnabledForSinglePassFlashlight() const = 0; + virtual void EnableCullingForSinglePassFlashlight(bool bEnable) = 0; + + virtual void ResetOcclusionQueryObject(OcclusionQueryObjectHandle_t) = 0; + + virtual IMorph* CreateMorph(MorphFormat_t format, const char* pDebugName) = 0; + virtual void DestroyMorph(IMorph* pMorph) = 0; + + virtual void BindMorph(IMorph* pMorph) = 0; + + virtual void SetFlexWeights(int nFirstWeight, int nCount, const MorphWeight_t* pWeights) = 0; + + virtual void* LockRenderData(int nSizeInBytes) = 0; + virtual void UnlockRenderData(void* pData) = 0; + + template< class E > E* LockRenderDataTyped(int nCount, const E* pSrcData = NULL); + + virtual void AddRefRenderData() = 0; + virtual void ReleaseRenderData() = 0; + + virtual bool IsRenderData(const void* pData) const = 0; + + virtual void ReadPixelsAndStretch(Rect_t* pSrcRect, Rect_t* pDstRect, unsigned char* pBuffer, ImageFormat dstFormat, int nDstStride) = 0; + + virtual void GetWindowSize(int& width, int& height) const = 0; + + virtual void DrawScreenSpaceRectangle( + IMaterial* pMaterial, + int destx, int desty, + int width, int height, + float src_texture_x0, float src_texture_y0, + float src_texture_x1, float src_texture_y1, + int src_texture_width, int src_texture_height, + void* pClientRenderable = NULL, + int nXDice = 1, + int nYDice = 1) = 0; + + virtual void LoadBoneMatrix(int boneIndex, const matrix3x4_t& matrix) = 0; + + virtual void PushRenderTargetAndViewport() = 0; + + virtual void PushRenderTargetAndViewport(ITexture* pTexture) = 0; + + virtual void PushRenderTargetAndViewport(ITexture* pTexture, int nViewX, int nViewY, int nViewW, int nViewH) = 0; + + virtual void PushRenderTargetAndViewport(ITexture* pTexture, ITexture* pDepthTexture, int nViewX, int nViewY, int nViewW, int nViewH) = 0; + + virtual void PopRenderTargetAndViewport(void) = 0; + + virtual void BindLightmapTexture(ITexture* pLightmapTexture) = 0; + + virtual void CopyRenderTargetToTextureEx(ITexture* pTexture, int nRenderTargetID, Rect_t* pSrcRect, Rect_t* pDstRect = NULL) = 0; + virtual void CopyTextureToRenderTargetEx(int nRenderTargetID, ITexture* pTexture, Rect_t* pSrcRect, Rect_t* pDstRect = NULL) = 0; + + virtual void PerspectiveOffCenterX(double fovx, double aspect, double zNear, double zFar, double bottom, double top, double left, double right) = 0; + + virtual void SetFloatRenderingParameter(int parm_number, float value) = 0; + virtual void SetIntRenderingParameter(int parm_number, int value) = 0; + virtual void SetVectorRenderingParameter(int parm_number, Vector const& value) = 0; + + virtual void SetStencilState(const ShaderStencilState_t& state) = 0; + virtual void ClearStencilBufferRectangle(int xmin, int ymin, int xmax, int ymax,int value) = 0; + + virtual void SetRenderTargetEx(int nRenderTargetID, ITexture* pTexture) = 0; + + virtual void PushCustomClipPlane(const float* pPlane) = 0; + virtual void PopCustomClipPlane(void) = 0; + + virtual void GetMaxToRender(IMesh* pMesh, bool bMaxUntilFlush, int* pMaxVerts, int* pMaxIndices) = 0; + + virtual int GetMaxVerticesToRender(IMaterial* pMaterial) = 0; + virtual int GetMaxIndicesToRender() = 0; + virtual void DisableAllLocalLights() = 0; + virtual int CompareMaterialCombos(IMaterial* pMaterial1, IMaterial* pMaterial2, int lightMapID1, int lightMapID2) = 0; + + virtual IMesh* GetFlexMesh() = 0; + + virtual void SetFlashlightStateEx(const FlashlightState_t& state, const VMatrix& worldToTexture, ITexture* pFlashlightDepthTexture) = 0; + + virtual ITexture* GetLocalCubemap() = 0; + + virtual void ClearBuffersObeyStencil(bool bClearColor, bool bClearDepth) = 0; + + virtual bool EnableClipping(bool bEnable) = 0; + + virtual void GetFogDistances(float* fStart, float* fEnd, float* fFogZ) = 0; + + virtual void BeginPIXEvent(unsigned long color, const char* szName) = 0; + virtual void EndPIXEvent() = 0; + virtual void SetPIXMarker(unsigned long color, const char* szName) = 0; + + virtual void BeginBatch(IMesh* pIndices) = 0; + virtual void BindBatch(IMesh* pVertices, IMaterial* pAutoBind = NULL) = 0; + virtual void DrawBatch(MaterialPrimitiveType_t primType, int firstIndex, int numIndices) = 0; + virtual void EndBatch() = 0; + + virtual ICallQueue* GetCallQueue() = 0; + + virtual void GetWorldSpaceCameraPosition(Vector* pCameraPos) = 0; + virtual void GetWorldSpaceCameraVectors(Vector* pVecForward, Vector* pVecRight, Vector* pVecUp) = 0; + + virtual void SetToneMappingScaleLinear(const Vector& scale) = 0; + virtual Vector GetToneMappingScaleLinear(void) = 0; + + virtual void SetShadowDepthBiasFactors(float fSlopeScaleDepthBias, float fDepthBias) = 0; + + virtual void PerformFullScreenStencilOperation(void) = 0; + + virtual void SetLightingOrigin(Vector vLightingOrigin) = 0; + + virtual void PushScissorRect(const int nLeft, const int nTop, const int nRight, const int nBottom) = 0; + virtual void PopScissorRect() = 0; + + virtual void BeginMorphAccumulation() = 0; + virtual void EndMorphAccumulation() = 0; + virtual void AccumulateMorph(IMorph* pMorph, int nMorphCount, const MorphWeight_t* pWeights) = 0; + + virtual void PushDeformation(DeformationBase_t const* Deformation) = 0; + virtual void PopDeformation() = 0; + virtual int GetNumActiveDeformations() const = 0; + + virtual bool GetMorphAccumulatorTexCoord(Vector2D* pTexCoord, IMorph* pMorph, int nVertex) = 0; + + virtual IMesh* GetDynamicMeshEx(VertexFormat_t vertexFormat, bool bBuffered = true, + IMesh* pVertexOverride = 0, IMesh* pIndexOverride = 0, IMaterial* pAutoBind = 0) = 0; + + virtual void FogMaxDensity(float flMaxDensity) = 0; + +#if defined( _X360 ) + virtual void PushVertexShaderGPRAllocation(int iVertexShaderCount = 64) = 0; + virtual void PopVertexShaderGPRAllocation(void) = 0; + + virtual void FlushHiStencil() = 0; + +#endif + +#if defined( _GAMECONSOLE ) + virtual void BeginConsoleZPass(const WorldListIndicesInfo_t& indicesInfo) = 0; + virtual void BeginConsoleZPass2(int nSlack) = 0; + virtual void EndConsoleZPass() = 0; +#endif + +#if defined( _PS3 ) + virtual void FlushTextureCache() = 0; +#endif + virtual void AntiAliasingHint(int nHint) = 0; + + virtual IMaterial* GetCurrentMaterial() = 0; + virtual int GetCurrentNumBones() const = 0; + virtual void* GetCurrentProxy() = 0; + + virtual void EnableColorCorrection(bool bEnable) = 0; + virtual ColorCorrectionHandle_t AddLookup(const char* pName) = 0; + virtual bool RemoveLookup(ColorCorrectionHandle_t handle) = 0; + virtual void LockLookup(ColorCorrectionHandle_t handle) = 0; + virtual void LoadLookup(ColorCorrectionHandle_t handle, const char* pLookupName) = 0; + virtual void UnlockLookup(ColorCorrectionHandle_t handle) = 0; + virtual void SetLookupWeight(ColorCorrectionHandle_t handle, float flWeight) = 0; + virtual void ResetLookupWeights() = 0; + virtual void SetResetable(ColorCorrectionHandle_t handle, bool bResetable) = 0; + + virtual void SetFullScreenDepthTextureValidityFlag(bool bIsValid) = 0; + + virtual void SetNonInteractiveLogoTexture(ITexture* pTexture, float flNormalizedX, float flNormalizedY, float flNormalizedW, float flNormalizedH) = 0; + virtual void SetNonInteractivePacifierTexture(ITexture* pTexture, float flNormalizedX, float flNormalizedY, float flNormalizedSize) = 0; + virtual void SetNonInteractiveTempFullscreenBuffer(ITexture* pTexture, MaterialNonInteractiveMode_t mode) = 0; + virtual void EnableNonInteractiveMode(MaterialNonInteractiveMode_t mode) = 0; + virtual void RefreshFrontBufferNonInteractive() = 0; + + virtual void FlipCulling(bool bFlipCulling) = 0; + + virtual void SetTextureRenderingParameter(int parm_number, ITexture* pTexture) = 0; + + virtual void EnableSinglePassFlashlightMode(bool bEnable) = 0; + + virtual bool SinglePassFlashlightModeEnabled() const = 0; + + virtual void DrawInstances(int nInstanceCount, const MeshInstanceData_t* pInstance) = 0; + + virtual void OverrideAlphaWriteEnable(bool bOverrideEnable, bool bAlphaWriteEnable) = 0; + virtual void OverrideColorWriteEnable(bool bOverrideEnable, bool bColorWriteEnable) = 0; + + virtual void ClearBuffersObeyStencilEx(bool bClearColor, bool bClearAlpha, bool bClearDepth) = 0; + + virtual int GetSubDBufferWidth() = 0; + virtual float* LockSubDBuffer(int nNumRows) = 0; + virtual void UnlockSubDBuffer() = 0; + + virtual void UpdateGameTime(float flTime) = 0; + + virtual void PrintfVA(char* fmt, va_list vargs) = 0; + virtual void Printf(char* fmt, ...) = 0; + virtual float Knob(char* knobname, float* setvalue = NULL) = 0; + +#if defined( INCLUDE_SCALEFORM ) + virtual void SetScaleformSlotViewport(int slot, int x, int y, int w, int h) = 0; + virtual void RenderScaleformSlot(int slot) = 0; + virtual void ForkRenderScaleformSlot(int slot) = 0; + virtual void JoinRenderScaleformSlot(int slot) = 0; + + virtual void SetScaleformCursorViewport(int x, int y, int w, int h) = 0; + virtual void RenderScaleformCursor() = 0; + + virtual void AdvanceAndRenderScaleformSlot(int slot) = 0; + virtual void AdvanceAndRenderScaleformCursor() = 0; +#endif + + virtual void SetRenderingPaint(bool bEnable) = 0; + + virtual ColorCorrectionHandle_t FindLookup(const char* pName) = 0; +}; + + +template< class E > inline E* IMatRenderContext::LockRenderDataTyped(int nCount, const E* pSrcData) +{ + int nSizeInBytes = nCount * sizeof(E); + E* pDstData = (E*)LockRenderData(nSizeInBytes); + if (pSrcData && pDstData) + { + memcpy(pDstData, pSrcData, nSizeInBytes); + } + return pDstData; +} + + +abstract_class IClientMaterialSystem +{ +public: + virtual unsigned int GetCurrentRecordingEntity() = 0; + virtual void PostToolMessage(unsigned int hEntity, KeyValues* pMsg) = 0; + virtual void SetMaterialProxyData(void* pProxyData) = 0; +}; + +#define VCLIENTMATERIALSYSTEM_INTERFACE_VERSION "VCLIENTMATERIALSYSTEM001" + + +class CMatRenderDataReference +{ +public: + CMatRenderDataReference(); + CMatRenderDataReference(IMatRenderContext* pRenderContext); + ~CMatRenderDataReference(); + void Lock(IMatRenderContext* pRenderContext); + void Release(); + +private: + IMatRenderContext* m_pRenderContext; +}; + + +inline CMatRenderDataReference::CMatRenderDataReference() +{ + m_pRenderContext = NULL; +} + +inline CMatRenderDataReference::CMatRenderDataReference(IMatRenderContext* pRenderContext) +{ + m_pRenderContext = NULL; + Lock(pRenderContext); +} + +inline CMatRenderDataReference::~CMatRenderDataReference() +{ + Release(); +} + +inline void CMatRenderDataReference::Lock(IMatRenderContext* pRenderContext) +{ + if (!m_pRenderContext) + { + m_pRenderContext = pRenderContext; + m_pRenderContext->AddRefRenderData(); + } +} + +inline void CMatRenderDataReference::Release() +{ + if (m_pRenderContext) + { + m_pRenderContext->ReleaseRenderData(); + m_pRenderContext = NULL; + } +} + + +template< typename E > +class CMatRenderData +{ +public: + CMatRenderData(IMatRenderContext* pRenderContext); + CMatRenderData(IMatRenderContext* pRenderContext, int nCount, const E* pSrcData = NULL); + ~CMatRenderData(); + E* Lock(int nCount, const E* pSrcData = NULL); + void Release(); + bool IsValid() const; + const E* Base() const; + E* Base(); + const E& operator[](int i) const; + E& operator[](int i); + +private: + IMatRenderContext* m_pRenderContext; + E* m_pRenderData; + int m_nCount; + bool m_bNeedsUnlock; +}; + +template< typename E > +inline CMatRenderData::CMatRenderData(IMatRenderContext* pRenderContext) +{ + m_pRenderContext = pRenderContext; + m_nCount = 0; + m_pRenderData = 0; + m_bNeedsUnlock = false; +} + +template< typename E > +inline CMatRenderData::CMatRenderData(IMatRenderContext* pRenderContext, int nCount, const E* pSrcData) +{ + m_pRenderContext = pRenderContext; + m_nCount = 0; + m_pRenderData = 0; + m_bNeedsUnlock = false; + Lock(nCount, pSrcData); +} + +template< typename E > +inline CMatRenderData::~CMatRenderData() +{ + Release(); +} + +template< typename E > +inline bool CMatRenderData::IsValid() const +{ + return m_pRenderData != NULL; +} + +template< typename E > +inline E* CMatRenderData::Lock(int nCount, const E* pSrcData) +{ + m_nCount = nCount; + if (pSrcData && m_pRenderContext->IsRenderData(pSrcData)) + { + m_pRenderData = const_cast(pSrcData); + m_pRenderContext->AddRefRenderData(); + m_bNeedsUnlock = false; + return m_pRenderData; + } + m_pRenderData = m_pRenderContext->LockRenderDataTyped(nCount, pSrcData); + m_bNeedsUnlock = true; + return m_pRenderData; +} + +template< typename E > +inline void CMatRenderData::Release() +{ + if (m_pRenderContext && m_pRenderData) + { + if (m_bNeedsUnlock) + { + m_pRenderContext->UnlockRenderData(m_pRenderData); + } + else + { + m_pRenderContext->ReleaseRenderData(); + } + } + m_pRenderData = NULL; + m_nCount = 0; + m_bNeedsUnlock = false; +} + +template< typename E > +inline E* CMatRenderData::Base() +{ + return m_pRenderData; +} + +template< typename E > +inline const E* CMatRenderData::Base() const +{ + return m_pRenderData; +} + +template< typename E > +inline E& CMatRenderData::operator[](int i) +{ + Assert((i >= 0) && (i < m_nCount)); + return m_pRenderData[i]; +} + +template< typename E > +inline const E& CMatRenderData::operator[](int i) const +{ + Assert((i >= 0) && (i < m_nCount)); + return m_pRenderData[i]; +} + + +class CMatRenderContextPtr : public CRefPtr +{ + typedef CRefPtr BaseClass; +public: + CMatRenderContextPtr() {} + CMatRenderContextPtr(IMatRenderContext* pInit) : BaseClass(pInit) { if (BaseClass::m_pObject) BaseClass::m_pObject->BeginRender(); } + CMatRenderContextPtr(IMaterialSystem* pFrom) : BaseClass(pFrom->GetRenderContext()) { if (BaseClass::m_pObject) BaseClass::m_pObject->BeginRender(); } + ~CMatRenderContextPtr() { if (BaseClass::m_pObject) BaseClass::m_pObject->EndRender(); } + + IMatRenderContext* operator=(IMatRenderContext* p) { if (p) p->BeginRender(); return BaseClass::operator=(p); } + + void SafeRelease() { if (BaseClass::m_pObject) BaseClass::m_pObject->EndRender(); BaseClass::SafeRelease(); } + void AssignAddRef(IMatRenderContext* pFrom) { if (BaseClass::m_pObject) BaseClass::m_pObject->EndRender(); BaseClass::AssignAddRef(pFrom); BaseClass::m_pObject->BeginRender(); } + + void GetFrom(IMaterialSystem* pFrom) { AssignAddRef(pFrom->GetRenderContext()); } + + +private: + CMatRenderContextPtr(const CMatRenderContextPtr& from); + void operator=(const CMatRenderContextPtr& from); + +}; + +#define PIX_VALVE_ORANGE 0xFFF5940F + +class PIXEvent +{ +public: + PIXEvent(IMatRenderContext* pRenderContext, const char* szName, unsigned long color = PIX_VALVE_ORANGE) + { + m_pRenderContext = pRenderContext; + Assert(m_pRenderContext); + Assert(szName); + m_pRenderContext->BeginPIXEvent(color, szName); + } + ~PIXEvent() + { + m_pRenderContext->EndPIXEvent(); + } +private: + IMatRenderContext* m_pRenderContext; +}; + + +#if ( defined( _X360 ) && ( defined( PROFILE ) || defined( _DEBUG ) ) ) +#define PIX_ENABLE 1 +#else +#define PIX_ENABLE 0 +#endif + + +#if PIX_ENABLE +# define PIXEVENT PIXEvent _pixEvent +#else +# define PIXEVENT +#endif + +#ifdef MATERIAL_SYSTEM_DEBUG_CALL_QUEUE +#include "tier1/callqueue.h" +#include "tier1/fmtstr.h" +static void DoMatSysQueueMark(IMaterialSystem* pMaterialSystem, const char* psz) +{ + CMatRenderContextPtr pRenderContext(pMaterialSystem); + if (pRenderContext->GetCallQueue()) + pRenderContext->GetCallQueue()->QueueCall(Plat_DebugString, CUtlEnvelope(psz)); +} + +#define MatSysQueueMark( pMaterialSystem, ...) DoMatSysQueueMark( pMaterialSystem, CFmtStr( __VA_ARGS__ ) ) +#else +#define MatSysQueueMark( msg, ...) ((void)0) +#endif + +#ifdef _GAMECONSOLE +#define MS_NO_DYNAMIC_BUFFER_COPY 1 +#endif + +#endif diff --git a/SpyCustom/sdk/imaterialsystemhardwareconfig.h b/SpyCustom/sdk/imaterialsystemhardwareconfig.h new file mode 100644 index 0000000..6fb81b9 --- /dev/null +++ b/SpyCustom/sdk/imaterialsystemhardwareconfig.h @@ -0,0 +1,200 @@ +#ifndef IMATERIALSYSTEMHARDWARECONFIG_H +#define IMATERIALSYSTEMHARDWARECONFIG_H + +#ifdef _WIN32 +#pragma once +#endif + +#if defined( DX_TO_GL_ABSTRACTION ) +#define IsPlatformOpenGL() true +#else +#define IsPlatformOpenGL() false +#endif + +#include "interface.h" +#include "imageformat.h" +#include "imaterialsystem.h" +FORCEINLINE bool IsOpenGL(void) +{ + return IsPlatformOpenGL(); +} + +enum VertexCompressionType_t +{ + VERTEX_COMPRESSION_INVALID = 0xFFFFFFFF, + + VERTEX_COMPRESSION_NONE = 0, + + VERTEX_COMPRESSION_ON = 1 +}; + + +#ifdef _GAMECONSOLE +#define DEFCONFIGMETHOD( ret_type, method, xbox_return_value ) \ +FORCEINLINE ret_type method const \ +{ \ + return xbox_return_value; \ +} + + +#else +#define DEFCONFIGMETHOD( ret_type, method, xbox_return_value ) \ +virtual ret_type method const = 0; +#endif + +enum ShadowFilterMode_t +{ + SHADOWFILTERMODE_DEFAULT = 0, + + NVIDIA_PCF = 0, + ATI_NO_PCF_FETCH4 = 1, + NVIDIA_PCF_CHEAP = 2, + ATI_NOPCF = 3, + + GAMECONSOLE_NINE_TAP_PCF = 0, + GAMECONSOLE_SINGLE_TAP_PCF = 1, + +#if defined( _GAMECONSOLE ) + SHADOWFILTERMODE_FIRST_CHEAP_MODE = GAMECONSOLE_SINGLE_TAP_PCF, +#else + SHADOWFILTERMODE_FIRST_CHEAP_MODE = NVIDIA_PCF_CHEAP, +#endif +}; + +enum CSMQualityMode_t +{ + CSMQUALITY_VERY_LOW, + CSMQUALITY_LOW, + CSMQUALITY_MEDIUM, + CSMQUALITY_HIGH, + + CSMQUALITY_TOTAL_MODES +}; + +enum CSMShaderMode_t +{ + CSMSHADERMODE_LOW_OR_VERY_LOW = 0, + CSMSHADERMODE_MEDIUM = 1, + CSMSHADERMODE_HIGH = 2, + CSMSHADERMODE_ATIFETCH4 = 3, + + CSMSHADERMODE_TOTAL_MODES +}; + +class IMaterialSystemHardwareConfig +{ +public: + virtual int GetFrameBufferColorDepth() const = 0; + virtual int GetSamplerCount() const = 0; + virtual bool HasSetDeviceGammaRamp() const = 0; + DEFCONFIGMETHOD(bool, SupportsStaticControlFlow(), true); + virtual VertexCompressionType_t SupportsCompressedVertices() const = 0; + virtual int MaximumAnisotropicLevel() const = 0; + virtual int MaxTextureWidth() const = 0; + virtual int MaxTextureHeight() const = 0; + virtual int TextureMemorySize() const = 0; + virtual bool SupportsMipmappedCubemaps() const = 0; + + virtual int NumVertexShaderConstants() const = 0; + virtual int NumPixelShaderConstants() const = 0; + virtual int MaxNumLights() const = 0; + virtual int MaxTextureAspectRatio() const = 0; + virtual int MaxVertexShaderBlendMatrices() const = 0; + virtual int MaxUserClipPlanes() const = 0; + virtual bool UseFastClipping() const = 0; + + DEFCONFIGMETHOD(int, GetDXSupportLevel(), 98); + virtual const char* GetShaderDLLName() const = 0; + + virtual bool ReadPixelsFromFrontBuffer() const = 0; + + virtual bool PreferDynamicTextures() const = 0; + + DEFCONFIGMETHOD(bool, SupportsHDR(), true); + + virtual bool NeedsAAClamp() const = 0; + virtual bool NeedsATICentroidHack() const = 0; + + virtual int GetMaxDXSupportLevel() const = 0; + + virtual bool SpecifiesFogColorInLinearSpace() const = 0; + + DEFCONFIGMETHOD(bool, SupportsSRGB(), true); + DEFCONFIGMETHOD(bool, FakeSRGBWrite(), false); + DEFCONFIGMETHOD(bool, CanDoSRGBReadFromRTs(), true); + + virtual bool SupportsGLMixedSizeTargets() const = 0; + + virtual bool IsAAEnabled() const = 0; + + virtual int GetVertexSamplerCount() const = 0; + virtual int GetMaxVertexTextureDimension() const = 0; + + virtual int MaxTextureDepth() const = 0; + + virtual HDRType_t GetHDRType() const = 0; + virtual HDRType_t GetHardwareHDRType() const = 0; + + virtual bool SupportsStreamOffset() const = 0; + + virtual int StencilBufferBits() const = 0; + virtual int MaxViewports() const = 0; + + virtual void OverrideStreamOffsetSupport(bool bOverrideEnabled, bool bEnableSupport) = 0; + + virtual ShadowFilterMode_t GetShadowFilterMode(bool bForceLowQualityShadows, bool bPS30) const = 0; + + virtual int NeedsShaderSRGBConversion() const = 0; + + DEFCONFIGMETHOD(bool, UsesSRGBCorrectBlending(), IsX360()); + + virtual bool HasFastVertexTextures() const = 0; + virtual int MaxHWMorphBatchCount() const = 0; + + virtual bool SupportsHDRMode(HDRType_t nHDRMode) const = 0; + + virtual bool GetHDREnabled(void) const = 0; + virtual void SetHDREnabled(bool bEnable) = 0; + + virtual bool SupportsBorderColor(void) const = 0; + virtual bool SupportsFetch4(void) const = 0; + + virtual float GetShadowDepthBias() const = 0; + virtual float GetShadowSlopeScaleDepthBias() const = 0; + + virtual bool PreferZPrepass() const = 0; + + virtual bool SuppressPixelShaderCentroidHackFixup() const = 0; + virtual bool PreferTexturesInHWMemory() const = 0; + virtual bool PreferHardwareSync() const = 0; + virtual bool ActualHasFastVertexTextures() const = 0; + + virtual bool SupportsShadowDepthTextures(void) const = 0; + virtual ImageFormat GetShadowDepthTextureFormat(void) const = 0; + virtual ImageFormat GetHighPrecisionShadowDepthTextureFormat(void) const = 0; + virtual ImageFormat GetNullTextureFormat(void) const = 0; + virtual int GetMinDXSupportLevel() const = 0; + virtual bool IsUnsupported() const = 0; + + virtual float GetLightMapScaleFactor() const = 0; + + virtual bool SupportsCascadedShadowMapping() const = 0; + virtual CSMQualityMode_t GetCSMQuality() const = 0; + virtual bool SupportsBilinearPCFSampling() const = 0; + virtual CSMShaderMode_t GetCSMShaderMode(CSMQualityMode_t nQualityLevel) const = 0; + virtual bool GetCSMAccurateBlending(void) const = 0; + virtual void SetCSMAccurateBlending(bool bEnable) = 0; + + virtual bool SupportsResolveDepth() const = 0; + virtual bool HasFullResolutionDepthTexture() const = 0; + +#if defined ( STDSHADER_DBG_DLL_EXPORT ) || defined( STDSHADER_DX9_DLL_EXPORT ) + inline bool SupportsPixelShaders_2_b() const { return GetDXSupportLevel() >= 92; } + inline bool SupportsPixelShaders_3_0() const { return GetDXSupportLevel() >= 95; } +#endif + + inline bool ShouldAlwaysUseShaderModel2bShaders() const { return IsOpenGL(); } + inline bool PlatformRequiresNonNullPixelShaders() const { return IsOpenGL(); } +}; + +#endif diff --git a/SpyCustom/sdk/imdlcache.h b/SpyCustom/sdk/imdlcache.h new file mode 100644 index 0000000..b7e96ea --- /dev/null +++ b/SpyCustom/sdk/imdlcache.h @@ -0,0 +1,169 @@ +#ifndef IMDLCACHE_H +#define IMDLCACHE_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "IAppSystem.h" + +struct studiohdr_t; +struct studiohwdata_t; +struct vcollide_t; +struct virtualmodel_t; +struct vertexFileHeader_t; + +namespace OptimizedModel +{ + struct FileHeader_t; +} + + +typedef unsigned short MDLHandle_t; + +enum +{ + MDLHANDLE_INVALID = (MDLHandle_t)~0 +}; + + +enum MDLCacheDataType_t +{ + MDLCACHE_STUDIOHDR = 0, + MDLCACHE_STUDIOHWDATA, + MDLCACHE_VCOLLIDE, + + MDLCACHE_ANIMBLOCK, + MDLCACHE_VIRTUALMODEL, + MDLCACHE_VERTEXES, + MDLCACHE_DECODEDANIMBLOCK, +}; + +abstract_class IMDLCacheNotify +{ +public: + virtual void OnDataLoaded(MDLCacheDataType_t type, MDLHandle_t handle) = 0; + + virtual void OnDataUnloaded(MDLCacheDataType_t type, MDLHandle_t handle) = 0; +}; + + +enum MDLCacheFlush_t +{ + MDLCACHE_FLUSH_STUDIOHDR = 0x01, + MDLCACHE_FLUSH_STUDIOHWDATA = 0x02, + MDLCACHE_FLUSH_VCOLLIDE = 0x04, + MDLCACHE_FLUSH_ANIMBLOCK = 0x08, + MDLCACHE_FLUSH_VIRTUALMODEL = 0x10, + MDLCACHE_FLUSH_AUTOPLAY = 0x20, + MDLCACHE_FLUSH_VERTEXES = 0x40, + + MDLCACHE_FLUSH_IGNORELOCK = 0x80000000, + MDLCACHE_FLUSH_ALL = 0xFFFFFFFF +}; + +#define MDLCACHE_INTERFACE_VERSION "MDLCache004" + +abstract_class IMDLCache : public IAppSystem +{ +public: + virtual void SetCacheNotify(IMDLCacheNotify * pNotify) = 0; + + virtual MDLHandle_t FindMDL(const char* pMDLRelativePath) = 0; + + virtual int AddRef(MDLHandle_t handle) = 0; + virtual int Release(MDLHandle_t handle) = 0; + virtual int GetRef(MDLHandle_t handle) = 0; + + virtual studiohdr_t* GetStudioHdr(MDLHandle_t handle) = 0; + virtual studiohwdata_t* GetHardwareData(MDLHandle_t handle) = 0; + virtual vcollide_t* GetVCollide(MDLHandle_t handle) = 0; + virtual unsigned char* GetAnimBlock(MDLHandle_t handle, int nBlock) = 0; + virtual virtualmodel_t* GetVirtualModel(MDLHandle_t handle) = 0; + virtual int GetAutoplayList(MDLHandle_t handle, unsigned short** pOut) = 0; + virtual vertexFileHeader_t* GetVertexData(MDLHandle_t handle) = 0; + + virtual void TouchAllData(MDLHandle_t handle) = 0; + + virtual void SetUserData(MDLHandle_t handle, void* pData) = 0; + virtual void* GetUserData(MDLHandle_t handle) = 0; + + virtual bool IsErrorModel(MDLHandle_t handle) = 0; + + virtual void Flush(MDLCacheFlush_t nFlushFlags = MDLCACHE_FLUSH_ALL) = 0; + + virtual void Flush(MDLHandle_t handle, int nFlushFlags = MDLCACHE_FLUSH_ALL) = 0; + + virtual const char* GetModelName(MDLHandle_t handle) = 0; + + virtual virtualmodel_t* GetVirtualModelFast(const studiohdr_t* pStudioHdr, MDLHandle_t handle) = 0; + + virtual void BeginLock() = 0; + + virtual void EndLock() = 0; + + virtual int* GetFrameUnlockCounterPtrOLD() = 0; + + virtual void FinishPendingLoads() = 0; + + virtual vcollide_t* GetVCollideEx(MDLHandle_t handle, bool synchronousLoad = true) = 0; + virtual bool GetVCollideSize(MDLHandle_t handle, int* pVCollideSize) = 0; + + virtual bool GetAsyncLoad(MDLCacheDataType_t type) = 0; + virtual bool SetAsyncLoad(MDLCacheDataType_t type, bool bAsync) = 0; + + virtual void BeginMapLoad() = 0; + virtual void EndMapLoad() = 0; + virtual void MarkAsLoaded(MDLHandle_t handle) = 0; + + virtual void InitPreloadData(bool rebuild) = 0; + virtual void ShutdownPreloadData() = 0; + + virtual bool IsDataLoaded(MDLHandle_t handle, MDLCacheDataType_t type) = 0; + + virtual int* GetFrameUnlockCounterPtr(MDLCacheDataType_t type) = 0; + + virtual studiohdr_t* LockStudioHdr(MDLHandle_t handle) = 0; + virtual void UnlockStudioHdr(MDLHandle_t handle) = 0; + + virtual bool PreloadModel(MDLHandle_t handle) = 0; + + virtual void ResetErrorModelStatus(MDLHandle_t handle) = 0; + + virtual void MarkFrame() = 0; +}; + + +class CMDLCacheCriticalSection +{ +public: + CMDLCacheCriticalSection(IMDLCache* pCache) : m_pCache(pCache) + { + m_pCache->BeginLock(); + } + + ~CMDLCacheCriticalSection() + { + m_pCache->EndLock(); + } + +private: + IMDLCache* m_pCache; +}; + +#define MDCACHE_FINE_GRAINED 1 + +#if defined(MDCACHE_FINE_GRAINED) +#define MDLCACHE_CRITICAL_SECTION_( pCache ) CMDLCacheCriticalSection cacheCriticalSection(pCache) +#define MDLCACHE_COARSE_LOCK_( pCache ) ((void)(0)) +#elif defined(MDLCACHE_LEVEL_LOCKED) +#define MDLCACHE_CRITICAL_SECTION_( pCache ) ((void)(0)) +#define MDLCACHE_COARSE_LOCK_( pCache ) ((void)(0)) +#else +#define MDLCACHE_CRITICAL_SECTION_( pCache ) ((void)(0)) +#define MDLCACHE_COARSE_LOCK_( pCache ) CMDLCacheCriticalSection cacheCriticalSection(pCache) +#endif +#define MDLCACHE_CRITICAL_SECTION() MDLCACHE_CRITICAL_SECTION_(mdlcache) +#define MDLCACHE_COARSE_LOCK() MDLCACHE_COARSE_LOCK_(mdlcache) + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/imovehelper.h b/SpyCustom/sdk/imovehelper.h new file mode 100644 index 0000000..32432c4 --- /dev/null +++ b/SpyCustom/sdk/imovehelper.h @@ -0,0 +1,74 @@ +#ifndef IMOVEHELPER_H +#define IMOVEHELPER_H + +#ifdef _WIN32 +#pragma once +#endif + + +enum PLAYER_ANIM; +class IPhysicsSurfaceProps; +class Vector; +struct model_t; +struct cmodel_t; +struct vcollide_t; +class CGameTrace; +enum soundlevel_t; + +enum +{ + WL_NotInWater = 0, + WL_Feet, + WL_Waist, + WL_Eyes +}; + + +typedef CBaseHandle EntityHandle_t; + + +#define INVALID_ENTITY_HANDLE INVALID_EHANDLE_INDEX + +abstract_class IMoveHelper +{ +public: + static IMoveHelper * GetSingleton() { return sm_pSingleton; } + + virtual char const* GetName(EntityHandle_t handle) const = 0; + + virtual void ResetTouchList(void) = 0; + virtual bool AddToTouched(const CGameTrace& tr, const Vector& impactvelocity) = 0; + virtual void ProcessImpacts(void) = 0; + + virtual void Con_NPrintf(int idx, PRINTF_FORMAT_STRING char const* fmt, ...) = 0; + + virtual void StartSound(const Vector& origin, int channel, char const* sample, float volume, soundlevel_t soundlevel, int fFlags, int pitch) = 0; + virtual void StartSound(const Vector& origin, const char* soundname) = 0; + virtual void PlaybackEventFull(int flags, int clientindex, unsigned short eventindex, float delay, Vector& origin, Vector& angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2) = 0; + + virtual bool PlayerFallingDamage(void) = 0; + + virtual void PlayerSetAnimation(PLAYER_ANIM playerAnim) = 0; + + virtual IPhysicsSurfaceProps* GetSurfaceProps(void) = 0; + + virtual bool IsWorldEntity(const CBaseHandle& handle) = 0; + +protected: + static void SetSingleton(IMoveHelper* pMoveHelper) { sm_pSingleton = pMoveHelper; } + + virtual ~IMoveHelper() {} + + static IMoveHelper* sm_pSingleton; +}; + +#define IMPLEMENT_MOVEHELPER() \ + IMoveHelper* IMoveHelper::sm_pSingleton = 0 + +inline IMoveHelper* MoveHelper() +{ + return IMoveHelper::GetSingleton(); +} + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/inetchannel.h b/SpyCustom/sdk/inetchannel.h new file mode 100644 index 0000000..fe5e64a --- /dev/null +++ b/SpyCustom/sdk/inetchannel.h @@ -0,0 +1,85 @@ +#ifndef INETCHANNEL_H +#define INETCHANNEL_H +#ifdef _WIN32 +#pragma once +#endif + +#include "platform.h" +#include "inetchannelinfo.h" +#include "bitbuf.h" + +class IDemoRecorder; +class INetMessage; +class INetChannelHandler; +class INetChannelInfo; +typedef struct netpacket_s netpacket_t; +typedef struct netadr_s netadr_t; + +abstract_class INetChannel : public INetChannelInfo +{ +public: + virtual ~INetChannel(void) {}; + + virtual void SetDataRate(float rate) = 0; + virtual bool RegisterMessage(INetMessage* msg) = 0; + virtual bool UnregisterMessage(INetMessageBinder* msg) = 0; + virtual bool StartStreaming(unsigned int challengeNr) = 0; + virtual void ResetStreaming(void) = 0; + virtual void SetTimeout(float seconds) = 0; + virtual void SetDemoRecorder(IDemoRecorder* recorder) = 0; + virtual void SetChallengeNr(unsigned int chnr) = 0; + + virtual void Reset(void) = 0; + virtual void Clear(void) = 0; + virtual void Shutdown(const char* reason) = 0; + + virtual void ProcessPlayback(void) = 0; + virtual bool ProcessStream(void) = 0; + virtual void ProcessPacket(struct netpacket_s* packet, bool bHasHeader) = 0; + + virtual bool SendNetMsg(INetMessage& msg, bool bForceReliable = false, bool bVoice = false) = 0; +#ifdef POSIX + FORCEINLINE bool SendNetMsg(INetMessage const& msg, bool bForceReliable = false, bool bVoice = false) { return SendNetMsg(*((INetMessage*)&msg), bForceReliable, bVoice); } +#endif + virtual bool SendData(bf_write& msg, bool bReliable = true) = 0; + virtual bool SendFile(const char* filename, unsigned int transferID) = 0; + virtual void DenyFile(const char* filename, unsigned int transferID) = 0; + virtual void RequestFile_OLD(const char* filename, unsigned int transferID) = 0; + virtual void SetChoked(void) = 0; + virtual int SendDatagram(bf_write* data) = 0; + virtual bool Transmit(bool onlyReliable = false) = 0; + + virtual const netadr_t& GetRemoteAddress(void) const = 0; + virtual INetChannelHandler* GetMsgHandler(void) const = 0; + virtual int GetDropNumber(void) const = 0; + virtual int GetSocket(void) const = 0; + virtual unsigned int GetChallengeNr(void) const = 0; + virtual void GetSequenceData(int& nOutSequenceNr, int& nInSequenceNr, int& nOutSequenceNrAck) = 0; + virtual void SetSequenceData(int nOutSequenceNr, int nInSequenceNr, int nOutSequenceNrAck) = 0; + + virtual void UpdateMessageStats(int msggroup, int bits) = 0; + virtual bool CanPacket(void) const = 0; + virtual bool IsOverflowed(void) const = 0; + virtual bool IsTimedOut(void) const = 0; + virtual bool HasPendingReliableData(void) = 0; + + virtual void SetFileTransmissionMode(bool bBackgroundMode) = 0; + virtual void SetCompressionMode(bool bUseCompression) = 0; + virtual unsigned int RequestFile(const char* filename) = 0; + virtual float GetTimeSinceLastReceived(void) const = 0; + + virtual void SetMaxBufferSize(bool bReliable, int nBytes, bool bVoice = false) = 0; + + virtual bool IsNull() const = 0; + virtual int GetNumBitsWritten(bool bReliable) = 0; + virtual void SetInterpolationAmount(float flInterpolationAmount) = 0; + virtual void SetRemoteFramerate(float flFrameTime, float flFrameTimeStdDeviation) = 0; + + virtual void SetMaxRoutablePayloadSize(int nSplitSize) = 0; + virtual int GetMaxRoutablePayloadSize() = 0; + + virtual int GetProtocolVersion() = 0; +}; + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/inetchannelinfo.h b/SpyCustom/sdk/inetchannelinfo.h new file mode 100644 index 0000000..7300c4c --- /dev/null +++ b/SpyCustom/sdk/inetchannelinfo.h @@ -0,0 +1,64 @@ +#if !defined( INETCHANNELINFO_H ) +#define INETCHANNELINFO_H +#ifdef _WIN32 +#pragma once +#endif + + +#define FLOW_OUTGOING 0 +#define FLOW_INCOMING 1 +#define MAX_FLOWS 2 + +class INetChannelInfo +{ +public: + + enum { + GENERIC = 0, + LOCALPLAYER, + OTHERPLAYERS, + ENTITIES, + SOUNDS, + EVENTS, + USERMESSAGES, + ENTMESSAGES, + VOICE, + STRINGTABLE, + MOVE, + STRINGCMD, + SIGNON, + TOTAL, + }; + + virtual const char* GetName(void) const = 0; + virtual const char* GetAddress(void) const = 0; + virtual float GetTime(void) const = 0; + virtual float GetTimeConnected(void) const = 0; + virtual int GetBufferSize(void) const = 0; + virtual int GetDataRate(void) const = 0; + + virtual bool IsLoopback(void) const = 0; + virtual bool IsTimingOut(void) const = 0; + virtual bool IsPlayback(void) const = 0; + + virtual float GetLatency(int flow) const = 0; + virtual float GetAvgLatency(int flow) const = 0; + virtual float GetAvgLoss(int flow) const = 0; + virtual float GetAvgChoke(int flow) const = 0; + virtual float GetAvgData(int flow) const = 0; + virtual float GetAvgPackets(int flow) const = 0; + virtual int GetTotalData(int flow) const = 0; + virtual int GetSequenceNr(int flow) const = 0; + virtual bool IsValidPacket(int flow, int frame_number) const = 0; + virtual float GetPacketTime(int flow, int frame_number) const = 0; + virtual int GetPacketBytes(int flow, int frame_number, int group) const = 0; + virtual bool GetStreamProgress(int flow, int* received, int* total) const = 0; + virtual float GetTimeSinceLastReceived(void) const = 0; + virtual float GetCommandInterpolationAmount(int flow, int frame_number) const = 0; + virtual void GetPacketResponseLatency(int flow, int frame_number, int* pnLatencyMsecs, int* pnChoke) const = 0; + virtual void GetRemoteFramerate(float* pflFrameTime, float* pflFrameTimeStdDeviation) const = 0; + + virtual float GetTimeoutSeconds() const = 0; +}; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/inetmessage.h b/SpyCustom/sdk/inetmessage.h new file mode 100644 index 0000000..c2fa5a8 --- /dev/null +++ b/SpyCustom/sdk/inetmessage.h @@ -0,0 +1,74 @@ +#ifndef INETMESSAGE_H +#define INETMESSAGE_H + +#include "bitbuf.h" + +class INetMsgHandler; +class INetMessage; +class INetChannel; + +class INetMessage +{ +public: + virtual ~INetMessage() {}; + + virtual void SetNetChannel(INetChannel* netchan) { DebuggerBreak(); return; } + virtual void SetReliable(bool state) = 0; + + virtual bool Process(void) { DebuggerBreak(); return false; } + + virtual bool ReadFromBuffer(bf_read& buffer) = 0; + virtual bool WriteToBuffer(bf_write& buffer) const = 0; + + virtual bool IsReliable(void) const = 0; + + virtual int GetType(void) const = 0; + virtual int GetGroup(void) const = 0; + virtual const char* GetName(void) const = 0; + + virtual INetChannel* GetNetChannel(void) const { DebuggerBreak(); return NULL; } + + virtual const char* ToString(void) const = 0; + virtual size_t GetSize() const = 0; +}; + +class INetMessageBinder +{ +public: + virtual ~INetMessageBinder() {}; + + virtual int GetType(void) const = 0; + virtual void SetNetChannel(INetChannel* netchan) = 0; + virtual INetMessage* CreateFromBuffer(bf_read& buffer) = 0; + virtual bool Process(const INetMessage& src) = 0; +}; + +class INetChannelHandler +{ +public: + virtual ~INetChannelHandler(void) {}; + + virtual void ConnectionStart(INetChannel* chan) = 0; + virtual void ConnectionStop() = 0; + + virtual void ConnectionClosing(const char* reason) = 0; + + virtual void ConnectionCrashed(const char* reason) = 0; + + virtual void PacketStart(int incoming_sequence, int outgoing_acknowledged) = 0; + + virtual void PacketEnd(void) = 0; + + virtual void FileRequested(const char* fileName, unsigned int transferID, bool isReplayDemoFile) = 0; + + virtual void FileReceived(const char* fileName, unsigned int transferID, bool isReplayDemoFile) = 0; + + virtual void FileDenied(const char* fileName, unsigned int transferID, bool isReplayDemoFile) = 0; + + virtual void FileSent(const char* fileName, unsigned int transferID, bool isReplayDemoFile) = 0; + + virtual bool ChangeSplitscreenUser(int nSplitScreenUserSlot) = 0; +}; + +#endif + diff --git a/SpyCustom/sdk/inetmsghandler.h b/SpyCustom/sdk/inetmsghandler.h new file mode 100644 index 0000000..9f89f9c --- /dev/null +++ b/SpyCustom/sdk/inetmsghandler.h @@ -0,0 +1,21 @@ +#if !defined( INETMSGHANDLER_H ) +#define INETMSGHANDLER_H +#ifdef _WIN32 +#pragma once +#endif + +#include "inetmessage.h" + +class INetChannel; +typedef struct netpacket_s netpacket_t; + +class IConnectionlessPacketHandler +{ +public: + virtual ~IConnectionlessPacketHandler(void) {}; + + virtual bool ProcessConnectionlessPacket(netpacket_t* packet) = 0; +}; + + +#endif diff --git a/SpyCustom/sdk/interface.h b/SpyCustom/sdk/interface.h new file mode 100644 index 0000000..43a88e8 --- /dev/null +++ b/SpyCustom/sdk/interface.h @@ -0,0 +1,139 @@ +#ifndef INTERFACE_H +#define INTERFACE_H + +#ifdef _WIN32 +#pragma once +#endif + +class IBaseInterface +{ +public: + virtual ~IBaseInterface() {} +}; + +#if !defined( _X360 ) +#define CREATEINTERFACE_PROCNAME "CreateInterface" +#else +#define CREATEINTERFACE_PROCNAME ((const char*)1) +#endif + +typedef void* (*CreateInterfaceFn)(const char* pName, int* pReturnCode); +typedef void* (*InstantiateInterfaceFn)(); + +class InterfaceReg +{ +public: + InterfaceReg(InstantiateInterfaceFn fn, const char* pName); + +public: + InstantiateInterfaceFn m_CreateFn; + const char* m_pName; + + InterfaceReg* m_pNext; + static InterfaceReg* s_pInterfaceRegs; +}; + +#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM) +#define EXPOSE_INTERFACE_FN(functionName, interfaceName, versionName) \ + static InterfaceReg __g_Create##interfaceName##_reg(functionName, versionName); +#else +#define EXPOSE_INTERFACE_FN(functionName, interfaceName, versionName) \ + namespace _SUBSYSTEM \ + { \ + static InterfaceReg __g_Create##interfaceName##_reg(functionName, versionName); \ + } +#endif + +#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM) +#define EXPOSE_INTERFACE(className, interfaceName, versionName) \ + static void* __Create##className##_interface() {return static_cast( new className );} \ + static InterfaceReg __g_Create##className##_reg(__Create##className##_interface, versionName ); +#else +#define EXPOSE_INTERFACE(className, interfaceName, versionName) \ + namespace _SUBSYSTEM \ + { \ + static void* __Create##className##_interface() {return static_cast( new className );} \ + static InterfaceReg __g_Create##className##_reg(__Create##className##_interface, versionName ); \ + } +#endif + +#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM) +#define EXPOSE_SINGLE_INTERFACE_GLOBALVAR_WITH_NAMESPACE(className, interfaceNamespace, interfaceName, versionName, globalVarName) \ + static void* __Create##className##interfaceName##_interface() {return static_cast( &globalVarName );} \ + static InterfaceReg __g_Create##className##interfaceName##_reg(__Create##className##interfaceName##_interface, versionName); +#else +#define EXPOSE_SINGLE_INTERFACE_GLOBALVAR_WITH_NAMESPACE(className, interfaceNamespace, interfaceName, versionName, globalVarName) \ + namespace _SUBSYSTEM \ + { \ + static void* __Create##className##interfaceName##_interface() {return static_cast( &globalVarName );} \ + static InterfaceReg __g_Create##className##interfaceName##_reg(__Create##className##interfaceName##_interface, versionName); \ + } +#endif + +#define EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, globalVarName) \ + EXPOSE_SINGLE_INTERFACE_GLOBALVAR_WITH_NAMESPACE(className, , interfaceName, versionName, globalVarName) + +#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM) +#define EXPOSE_SINGLE_INTERFACE(className, interfaceName, versionName) \ + static className __g_##className##_singleton; \ + EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, __g_##className##_singleton) +#else +#define EXPOSE_SINGLE_INTERFACE(className, interfaceName, versionName) \ + namespace _SUBSYSTEM \ + { \ + static className __g_##className##_singleton; \ + } \ + EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, __g_##className##_singleton) +#endif + +class CSysModule; + +enum +{ + IFACE_OK = 0, + IFACE_FAILED +}; + +void* CreateInterface(const char* pName, int* pReturnCode); + +#if defined( _X360 ) +DLL_EXPORT void* CreateInterfaceThunk(const char* pName, int* pReturnCode); +#endif + +extern CreateInterfaceFn Sys_GetFactory(CSysModule* pModule); +extern CreateInterfaceFn Sys_GetFactory(const char* pModuleName); +extern CreateInterfaceFn Sys_GetFactoryThis(void); + +enum Sys_Flags +{ + SYS_NOFLAGS = 0x00, + SYS_NOLOAD = 0x01 +}; + +extern CSysModule* Sys_LoadModule(const char* pModuleName, Sys_Flags flags = SYS_NOFLAGS); +extern void Sys_UnloadModule(CSysModule* pModule); + +bool Sys_LoadInterface( + const char* pModuleName, + const char* pInterfaceVersionName, + CSysModule** pOutModule, + void** pOutInterface); + +bool Sys_IsDebuggerPresent(); + +class CDllDemandLoader +{ +public: + CDllDemandLoader(char const* pchModuleName); + virtual ~CDllDemandLoader(); + CreateInterfaceFn GetFactory(); + void Unload(); + +private: + + char const* m_pchModuleName; + CSysModule* m_hModule; + bool m_bLoadAttempted; +}; + +#endif diff --git a/SpyCustom/sdk/interpolatedvar.h b/SpyCustom/sdk/interpolatedvar.h new file mode 100644 index 0000000..2bfdecc --- /dev/null +++ b/SpyCustom/sdk/interpolatedvar.h @@ -0,0 +1,1429 @@ +#ifndef INTERPOLATEDVAR_H +#define INTERPOLATEDVAR_H +#ifdef _WIN32 +#pragma once +#endif + +#include "utllinkedlist.h" +#include "rangecheckedvar.h" +#include "lerp_functions.h" +#include "animationlayer.h" +#include "convar.h" + + +#include "memdbgon.h" + +#define COMPARE_HISTORY(a,b) \ + ( memcmp( m_VarHistory[a].GetValue(), m_VarHistory[b].GetValue(), sizeof(Type)*GetMaxCount() ) == 0 ) + + +#define LATCH_ANIMATION_VAR (1<<0) +#define LATCH_SIMULATION_VAR (1<<1) + +#define EXCLUDE_AUTO_LATCH (1<<2) +#define EXCLUDE_AUTO_INTERPOLATE (1<<3) + +#define INTERPOLATE_LINEAR_ONLY (1<<4) +#define INTERPOLATE_OMIT_UPDATE_LAST_NETWORKED (1<<5) + + + +#define EXTRA_INTERPOLATION_HISTORY_STORED 0.05f +extern float g_flLastPacketTimestamp; + +inline void Interpolation_SetLastPacketTimeStamp(float timestamp) +{ + Assert(timestamp > 0); + g_flLastPacketTimestamp = timestamp; +} + + +class CInterpolationContext +{ +public: + + CInterpolationContext() + { + m_bOldAllowExtrapolation = s_bAllowExtrapolation; + m_flOldLastTimeStamp = s_flLastTimeStamp; + + s_bAllowExtrapolation = false; + + m_pNext = s_pHead; + s_pHead = this; + } + + ~CInterpolationContext() + { + s_bAllowExtrapolation = m_bOldAllowExtrapolation; + s_flLastTimeStamp = m_flOldLastTimeStamp; + + Assert(s_pHead == this); + s_pHead = m_pNext; + } + + static void EnableExtrapolation(bool state) + { + s_bAllowExtrapolation = state; + } + + static bool IsThereAContext() + { + return s_pHead != NULL; + } + + static bool IsExtrapolationAllowed() + { + return s_bAllowExtrapolation; + } + + static void SetLastTimeStamp(float timestamp) + { + s_flLastTimeStamp = timestamp; + } + + static float GetLastTimeStamp() + { + return s_flLastTimeStamp; + } + + +private: + + CInterpolationContext* m_pNext; + bool m_bOldAllowExtrapolation; + float m_flOldLastTimeStamp; + + static CInterpolationContext* s_pHead; + static bool s_bAllowExtrapolation; + static float s_flLastTimeStamp; +}; + + +extern ConVar cl_extrapolate_amount; + + +template< class T > +inline T ExtrapolateInterpolatedVarType(const T& oldVal, const T& newVal, float divisor, float flExtrapolationAmount) +{ + return newVal; +} + +inline Vector ExtrapolateInterpolatedVarType(const Vector& oldVal, const Vector& newVal, float divisor, float flExtrapolationAmount) +{ + return Lerp(1.0f + flExtrapolationAmount * divisor, oldVal, newVal); +} + +inline float ExtrapolateInterpolatedVarType(const float& oldVal, const float& newVal, float divisor, float flExtrapolationAmount) +{ + return Lerp(1.0f + flExtrapolationAmount * divisor, oldVal, newVal); +} + +inline QAngle ExtrapolateInterpolatedVarType(const QAngle& oldVal, const QAngle& newVal, float divisor, float flExtrapolationAmount) +{ + return Lerp(1.0f + flExtrapolationAmount * divisor, oldVal, newVal); +} + + +abstract_class IInterpolatedVar +{ +public: + virtual ~IInterpolatedVar() {} + + virtual void Setup(void* pValue, int type) = 0; + virtual void SetInterpolationAmount(float seconds) = 0; + + virtual void NoteLastNetworkedValue() = 0; + virtual bool NoteChanged(float changetime, bool bUpdateLastNetworkedValue) = 0; + virtual void Reset() = 0; + + virtual int Interpolate(float currentTime) = 0; + + virtual int GetType() const = 0; + virtual void RestoreToLastNetworked() = 0; + virtual void Copy(IInterpolatedVar* pSrc) = 0; + + virtual const char* GetDebugName() = 0; + virtual void SetDebugName(const char* pName) = 0; + + virtual void SetDebug(bool bDebug) = 0; +}; + +template< typename Type, bool IS_ARRAY > +struct CInterpolatedVarEntryBase +{ + CInterpolatedVarEntryBase() + { + value = NULL; + count = 0; + changetime = 0; + } + ~CInterpolatedVarEntryBase() + { + delete[] value; + value = NULL; + } + + void FastTransferFrom(CInterpolatedVarEntryBase& src) + { + Assert(!value); + value = src.value; + count = src.count; + changetime = src.changetime; + src.value = 0; + src.count = 0; + } + + CInterpolatedVarEntryBase& operator=(const CInterpolatedVarEntryBase& src) + { + delete[] value; + value = NULL; + count = 0; + if (src.value) + { + count = src.count; + value = new Type[count]; + for (int i = 0; i < count; i++) + { + value[i] = src.value[i]; + } + } + return *this; + } + + Type* GetValue() { return value; } + const Type* GetValue() const { return value; } + + void Init(int maxCount) + { + if (!maxCount) + { + DeleteEntry(); + } + else + { + if (maxCount != count) + { + DeleteEntry(); + } + + if (!value) + { + count = maxCount; + value = new Type[maxCount]; + } + } + Assert(count == maxCount); + } + Type* NewEntry(const Type* pValue, int maxCount, float time) + { + changetime = time; + Init(maxCount); + if (value && maxCount) + { + memcpy(value, pValue, maxCount * sizeof(Type)); + } + return value; + } + + void DeleteEntry() + { + delete[] value; + value = NULL; + count = 0; + } + + float changetime; + int count; + Type* value; + +private: + CInterpolatedVarEntryBase(const CInterpolatedVarEntryBase& src); +}; + +template +struct CInterpolatedVarEntryBase +{ + CInterpolatedVarEntryBase() {} + ~CInterpolatedVarEntryBase() {} + + const Type* GetValue() const { return &value; } + Type* GetValue() { return &value; } + + void Init(int maxCount) + { + Assert(maxCount == 1); + } + Type* NewEntry(const Type* pValue, int maxCount, float time) + { + Assert(maxCount == 1); + changetime = time; + memcpy(&value, pValue, maxCount * sizeof(Type)); + return &value; + } + void FastTransferFrom(CInterpolatedVarEntryBase& src) + { + *this = src; + } + + void DeleteEntry() {} + + float changetime; + Type value; +}; + +template +class CSimpleRingBuffer +{ +public: + CSimpleRingBuffer(int startSize = 4) + { + m_pElements = 0; + m_maxElement = 0; + m_firstElement = 0; + m_count = 0; + m_growSize = 16; + EnsureCapacity(startSize); + } + ~CSimpleRingBuffer() + { + delete[] m_pElements; + m_pElements = NULL; + } + + inline int Count() const { return m_count; } + + int Head() const { return (m_count > 0) ? 0 : InvalidIndex(); } + + bool IsIdxValid(int i) const { return (i >= 0 && i < m_count) ? true : false; } + bool IsValidIndex(int i) const { return IsIdxValid(i); } + static int InvalidIndex() { return -1; } + + T& operator[](int i) + { + Assert(IsIdxValid(i)); + i += m_firstElement; + i = WrapRange(i); + return m_pElements[i]; + } + + const T& operator[](int i) const + { + Assert(IsIdxValid(i)); + i += m_firstElement; + i = WrapRange(i); + return m_pElements[i]; + } + + void EnsureCapacity(int capSize) + { + if (capSize > m_maxElement) + { + int newMax = m_maxElement + ((capSize + m_growSize - 1) / m_growSize) * m_growSize; + T* pNew = new T[newMax]; + for (int i = 0; i < m_maxElement; i++) + { + pNew[i].FastTransferFrom(m_pElements[WrapRange(i + m_firstElement)]); + } + m_firstElement = 0; + m_maxElement = newMax; + delete[] m_pElements; + m_pElements = pNew; + } + } + + int AddToHead() + { + EnsureCapacity(m_count + 1); + int i = m_firstElement + m_maxElement - 1; + m_count++; + i = WrapRange(i); + m_firstElement = i; + return 0; + } + + int AddToHead(const T& elem) + { + AddToHead(); + m_pElements[m_firstElement] = elem; + return 0; + } + + int AddToTail() + { + EnsureCapacity(m_count + 1); + m_count++; + return WrapRange(m_firstElement + m_count - 1); + } + + void RemoveAll() + { + m_count = 0; + m_firstElement = 0; + } + + void RemoveAtHead() + { + if (m_count > 0) + { + m_firstElement = WrapRange(m_firstElement + 1); + m_count--; + } + } + + void Truncate(int newLength) + { + if (newLength < m_count) + { + Assert(newLength >= 0); + m_count = newLength; + } + } + +private: + inline int WrapRange(int i) const + { + return (i >= m_maxElement) ? (i - m_maxElement) : i; + } + + T* m_pElements; + unsigned short m_maxElement; + unsigned short m_firstElement; + unsigned short m_count; + unsigned short m_growSize; +}; + +template< typename Type, bool IS_ARRAY> +class CInterpolatedVarArrayBase : public IInterpolatedVar +{ +public: + friend class CInterpolatedVarPrivate; + + CInterpolatedVarArrayBase(const char* pDebugName = "no debug name"); + virtual ~CInterpolatedVarArrayBase(); + + +public: + + virtual void Setup(void* pValue, int type); + virtual void SetInterpolationAmount(float seconds); + virtual void NoteLastNetworkedValue(); + virtual bool NoteChanged(float changetime, bool bUpdateLastNetworkedValue); + virtual void Reset(); + virtual int Interpolate(float currentTime); + virtual int GetType() const; + virtual void RestoreToLastNetworked(); + virtual void Copy(IInterpolatedVar* pInSrc); + virtual const char* GetDebugName() { return m_pDebugName; } + + +public: + + bool NoteChanged(float changetime, float interpolation_amount, bool bUpdateLastNetworkedValue); + int Interpolate(float currentTime, float interpolation_amount); + + void DebugInterpolate(Type* pOut, float currentTime); + + void GetDerivative(Type* pOut, float currentTime); + void GetDerivative_SmoothVelocity(Type* pOut, float currentTime); + + void ClearHistory(); + void AddToHead(float changeTime, const Type* values, bool bFlushNewer); + const Type& GetPrev(int iArrayIndex = 0) const; + const Type& GetCurrent(int iArrayIndex = 0) const; + + float GetInterval() const; + bool IsValidIndex(int i); + Type* GetHistoryValue(int index, float& changetime, int iArrayIndex = 0); + int GetHead() { return 0; } + int GetNext(int i) + { + int next = i + 1; + if (!m_VarHistory.IsValidIndex(next)) + return m_VarHistory.InvalidIndex(); + return next; + } + + void SetHistoryValuesForItem(int item, Type& value); + void SetLooping(bool looping, int iArrayIndex = 0); + + void SetMaxCount(int newmax); + int GetMaxCount() const; + + float GetOldestEntry(); + + void SetDebugName(const char* pName) { m_pDebugName = pName; } + virtual void SetDebug(bool bDebug) { m_bDebug = bDebug; } + bool GetInterpolationInfo(float currentTime, int* pNewer, int* pOlder, int* pOldest); + +protected: + + typedef CInterpolatedVarEntryBase CInterpolatedVarEntry; + typedef CSimpleRingBuffer< CInterpolatedVarEntry > CVarHistory; + friend class CInterpolationInfo; + + class CInterpolationInfo + { + public: + bool m_bHermite; + int oldest; + int older; + int newer; + float frac; + }; + + +protected: + + void RemoveOldEntries(float oldesttime); + void RemoveEntriesPreviousTo(float flTime); + + bool GetInterpolationInfo( + CInterpolationInfo* pInfo, + float currentTime, + float interpolation_amount, + int* pNoMoreChanges); + + void TimeFixup_Hermite( + CInterpolatedVarEntry& fixup, + CInterpolatedVarEntry*& prev, + CInterpolatedVarEntry*& start, + CInterpolatedVarEntry*& end); + + void TimeFixup2_Hermite( + CInterpolatedVarEntry& fixup, + CInterpolatedVarEntry*& prev, + CInterpolatedVarEntry*& start, + float dt + ); + + void _Extrapolate( + Type* pOut, + CInterpolatedVarEntry* pOld, + CInterpolatedVarEntry* pNew, + float flDestinationTime, + float flMaxExtrapolationAmount + ); + + void _Interpolate(Type* out, float frac, CInterpolatedVarEntry* start, CInterpolatedVarEntry* end); + void _Interpolate_Hermite(Type* out, float frac, CInterpolatedVarEntry* pOriginalPrev, CInterpolatedVarEntry* start, CInterpolatedVarEntry* end, bool looping = false); + + void _Derivative_Hermite(Type* out, float frac, CInterpolatedVarEntry* pOriginalPrev, CInterpolatedVarEntry* start, CInterpolatedVarEntry* end); + void _Derivative_Hermite_SmoothVelocity(Type* out, float frac, CInterpolatedVarEntry* b, CInterpolatedVarEntry* c, CInterpolatedVarEntry* d); + void _Derivative_Linear(Type* out, CInterpolatedVarEntry* start, CInterpolatedVarEntry* end); + + bool ValidOrder(); + +protected: + Type* m_pValue; + CVarHistory m_VarHistory; + Type* m_LastNetworkedValue; + float m_LastNetworkedTime; + byte m_fType; + byte m_nMaxCount; + byte* m_bLooping; + float m_InterpolationAmount; + const char* m_pDebugName; + bool m_bDebug : 1; +}; + + +template< typename Type, bool IS_ARRAY > +inline CInterpolatedVarArrayBase::CInterpolatedVarArrayBase(const char* pDebugName) +{ + m_pDebugName = pDebugName; + m_pValue = NULL; + m_fType = LATCH_ANIMATION_VAR; + m_InterpolationAmount = 0.0f; + m_nMaxCount = 0; + m_LastNetworkedTime = 0; + m_LastNetworkedValue = NULL; + m_bLooping = NULL; + m_bDebug = false; +} + +template< typename Type, bool IS_ARRAY > +inline CInterpolatedVarArrayBase::~CInterpolatedVarArrayBase() +{ + ClearHistory(); + delete[] m_bLooping; + delete[] m_LastNetworkedValue; +} + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::Setup(void* pValue, int type) +{ + m_pValue = (Type*)pValue; + m_fType = type; +} + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::SetInterpolationAmount(float seconds) +{ + m_InterpolationAmount = seconds; +} + +template< typename Type, bool IS_ARRAY > +inline int CInterpolatedVarArrayBase::GetType() const +{ + return m_fType; +} + +template< typename Type, bool IS_ARRAY > +void CInterpolatedVarArrayBase::NoteLastNetworkedValue() +{ + memcpy(m_LastNetworkedValue, m_pValue, m_nMaxCount * sizeof(Type)); + m_LastNetworkedTime = g_flLastPacketTimestamp; +} + +template< typename Type, bool IS_ARRAY > +inline bool CInterpolatedVarArrayBase::NoteChanged(float changetime, float interpolation_amount, bool bUpdateLastNetworkedValue) +{ + Assert(m_pValue); + + bool bRet = true; + if (m_VarHistory.Count()) + { + if (memcmp(m_pValue, m_VarHistory[0].GetValue(), sizeof(Type) * m_nMaxCount) == 0) + { + bRet = false; + } + } + + if (m_bDebug) + { + char const* pDiffString = bRet ? "differs" : "identical"; + + } + + AddToHead(changetime, m_pValue, true); + + if (bUpdateLastNetworkedValue) + { + NoteLastNetworkedValue(); + } + +#if 0 + RemoveOldEntries(gpGlobals->curtime - interpolation_amount - 2.0f); +#else +#endif + + return bRet; +} + + +template< typename Type, bool IS_ARRAY > +inline bool CInterpolatedVarArrayBase::NoteChanged(float changetime, bool bUpdateLastNetworkedValue) +{ + return NoteChanged(changetime, m_InterpolationAmount, bUpdateLastNetworkedValue); +} + + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::RestoreToLastNetworked() +{ + Assert(m_pValue); + memcpy(m_pValue, m_LastNetworkedValue, m_nMaxCount * sizeof(Type)); +} + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::ClearHistory() +{ + for (int i = 0; i < m_VarHistory.Count(); i++) + { + m_VarHistory[i].DeleteEntry(); + } + m_VarHistory.RemoveAll(); +} + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::AddToHead(float changeTime, const Type* values, bool bFlushNewer) +{ + MEM_ALLOC_CREDIT_CLASS(); + int newslot; + + if (bFlushNewer) + { + while (m_VarHistory.Count()) + { + if ((m_VarHistory[0].changetime + 0.0001f) > changeTime) + { + m_VarHistory.RemoveAtHead(); + } + else + { + break; + } + } + + newslot = m_VarHistory.AddToHead(); + } + else + { + newslot = m_VarHistory.AddToHead(); + for (int i = 1; i < m_VarHistory.Count(); i++) + { + if (m_VarHistory[i].changetime <= changeTime) + break; + m_VarHistory[newslot].FastTransferFrom(m_VarHistory[i]); + newslot = i; + } + } + + CInterpolatedVarEntry* e = &m_VarHistory[newslot]; + e->NewEntry(values, m_nMaxCount, changeTime); +} + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::Reset() +{ + ClearHistory(); + + if (m_pValue) + { + memcpy(m_LastNetworkedValue, m_pValue, m_nMaxCount * sizeof(Type)); + } +} + + +template< typename Type, bool IS_ARRAY > +inline float CInterpolatedVarArrayBase::GetOldestEntry() +{ + float lastVal = 0; + if (m_VarHistory.Count()) + { + lastVal = m_VarHistory[m_VarHistory.Count() - 1].changetime; + } + return lastVal; +} + + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::RemoveOldEntries(float oldesttime) +{ + int newCount = m_VarHistory.Count(); + for (int i = m_VarHistory.Count(); --i > 2; ) + { + if (m_VarHistory[i].changetime > oldesttime) + break; + newCount = i; + } + m_VarHistory.Truncate(newCount); +} + + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::RemoveEntriesPreviousTo(float flTime) +{ + for (int i = 0; i < m_VarHistory.Count(); i++) + { + if (m_VarHistory[i].changetime < flTime) + { + m_VarHistory.Truncate(i + 3); + break; + } + } +} + + +template< typename Type, bool IS_ARRAY > +inline bool CInterpolatedVarArrayBase::GetInterpolationInfo( + typename CInterpolatedVarArrayBase::CInterpolationInfo* pInfo, + float currentTime, + float interpolation_amount, + int* pNoMoreChanges +) +{ + Assert(m_pValue); + + CVarHistory& varHistory = m_VarHistory; + + float targettime = currentTime - interpolation_amount; + + pInfo->m_bHermite = false; + pInfo->frac = 0; + pInfo->oldest = pInfo->older = pInfo->newer = varHistory.InvalidIndex(); + + for (int i = 0; i < varHistory.Count(); i++) + { + pInfo->older = i; + + float older_change_time = m_VarHistory[i].changetime; + if (older_change_time == 0.0f) + break; + + if (targettime < older_change_time) + { + pInfo->newer = pInfo->older; + continue; + } + + if (pInfo->newer == varHistory.InvalidIndex()) + { + pInfo->newer = pInfo->older; + + if (pNoMoreChanges) + *pNoMoreChanges = 1; + return true; + } + + float newer_change_time = varHistory[pInfo->newer].changetime; + float dt = newer_change_time - older_change_time; + if (dt > 0.0001f) + { + pInfo->frac = (targettime - older_change_time) / (newer_change_time - older_change_time); + pInfo->frac = MIN(pInfo->frac, 2.0f); + + int oldestindex = i + 1; + + if (!(m_fType & INTERPOLATE_LINEAR_ONLY) && varHistory.IsIdxValid(oldestindex)) + { + pInfo->oldest = oldestindex; + float oldest_change_time = varHistory[oldestindex].changetime; + float dt2 = older_change_time - oldest_change_time; + if (dt2 > 0.0001f) + { + pInfo->m_bHermite = true; + } + } + + if (pNoMoreChanges && pInfo->newer == m_VarHistory.Head()) + { + if (COMPARE_HISTORY(pInfo->newer, pInfo->older)) + { + if (!pInfo->m_bHermite || COMPARE_HISTORY(pInfo->newer, pInfo->oldest)) + *pNoMoreChanges = 1; + } + } + } + return true; + } + + if (pInfo->newer != varHistory.InvalidIndex()) + { + pInfo->older = pInfo->newer; + return true; + } + + + pInfo->newer = pInfo->older; + return (pInfo->older != varHistory.InvalidIndex()); +} + + +template< typename Type, bool IS_ARRAY > +inline bool CInterpolatedVarArrayBase::GetInterpolationInfo(float currentTime, int* pNewer, int* pOlder, int* pOldest) +{ + CInterpolationInfo info; + bool result = GetInterpolationInfo(&info, currentTime, m_InterpolationAmount, NULL); + + if (pNewer) + *pNewer = (int)info.newer; + + if (pOlder) + *pOlder = (int)info.older; + + if (pOldest) + *pOldest = (int)info.oldest; + + return result; +} + + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::DebugInterpolate(Type* pOut, float currentTime) +{ + float interpolation_amount = m_InterpolationAmount; + + int noMoreChanges = 0; + + CInterpolationInfo info; + GetInterpolationInfo(&info, currentTime, interpolation_amount, &noMoreChanges); + + CVarHistory& history = m_VarHistory; + + if (info.m_bHermite) + { + _Interpolate_Hermite(pOut, info.frac, &history[info.oldest], &history[info.older], &history[info.newer]); + } + else if (info.newer == info.older) + { + int realOlder = info.newer + 1; + if (CInterpolationContext::IsExtrapolationAllowed() && + IsValidIndex(realOlder) && + history[realOlder].changetime != 0.0 && + interpolation_amount > 0.000001f && + CInterpolationContext::GetLastTimeStamp() <= m_LastNetworkedTime) + { + _Extrapolate(pOut, &history[realOlder], &history[info.newer], currentTime - interpolation_amount, cl_extrapolate_amount.GetFloat()); + } + else + { + _Interpolate(pOut, info.frac, &history[info.older], &history[info.newer]); + } + } + else + { + _Interpolate(pOut, info.frac, &history[info.older], &history[info.newer]); + } +} + +template< typename Type, bool IS_ARRAY > +inline int CInterpolatedVarArrayBase::Interpolate(float currentTime, float interpolation_amount) +{ + int noMoreChanges = 0; + + CInterpolationInfo info; + if (!GetInterpolationInfo(&info, currentTime, interpolation_amount, &noMoreChanges)) + return noMoreChanges; + + + CVarHistory& history = m_VarHistory; + + if (m_bDebug) + { + Msg("%s Interpolate at %f%s\n", GetDebugName(), currentTime, noMoreChanges ? " [value will hold]" : ""); + } + + +#ifdef INTERPOLATEDVAR_PARANOID_MEASUREMENT + Type* backupValues = (Type*)_alloca(m_nMaxCount * sizeof(Type)); + memcpy(backupValues, m_pValue, sizeof(Type) * m_nMaxCount); +#endif + + if (info.m_bHermite) + { + _Interpolate_Hermite(m_pValue, info.frac, &history[info.oldest], &history[info.older], &history[info.newer]); + } + else if (info.newer == info.older) + { + int realOlder = info.newer + 1; + if (CInterpolationContext::IsExtrapolationAllowed() && + IsValidIndex(realOlder) && + history[realOlder].changetime != 0.0 && + interpolation_amount > 0.000001f && + CInterpolationContext::GetLastTimeStamp() <= m_LastNetworkedTime) + { + _Extrapolate(m_pValue, &history[realOlder], &history[info.newer], currentTime - interpolation_amount, cl_extrapolate_amount.GetFloat()); + } + else + { + _Interpolate(m_pValue, info.frac, &history[info.older], &history[info.newer]); + } + } + else + { + _Interpolate(m_pValue, info.frac, &history[info.older], &history[info.newer]); + } + +#ifdef INTERPOLATEDVAR_PARANOID_MEASUREMENT + if (memcmp(backupValues, m_pValue, sizeof(Type) * m_nMaxCount) != 0) + { + extern int g_nInterpolatedVarsChanged; + extern bool g_bRestoreInterpolatedVarValues; + + ++g_nInterpolatedVarsChanged; + + if (g_bRestoreInterpolatedVarValues) + { + memcpy(m_pValue, backupValues, sizeof(Type) * m_nMaxCount); + return noMoreChanges; + } + } +#endif + + RemoveEntriesPreviousTo(currentTime - interpolation_amount - EXTRA_INTERPOLATION_HISTORY_STORED); + return noMoreChanges; +} + + +template< typename Type, bool IS_ARRAY > +void CInterpolatedVarArrayBase::GetDerivative(Type* pOut, float currentTime) +{ + CInterpolationInfo info; + if (!GetInterpolationInfo(&info, currentTime, m_InterpolationAmount, NULL)) + return; + + if (info.m_bHermite) + { + _Derivative_Hermite(pOut, info.frac, &m_VarHistory[info.oldest], &m_VarHistory[info.older], &m_VarHistory[info.newer]); + } + else + { + _Derivative_Linear(pOut, &m_VarHistory[info.older], &m_VarHistory[info.newer]); + } +} + + +template< typename Type, bool IS_ARRAY > +void CInterpolatedVarArrayBase::GetDerivative_SmoothVelocity(Type* pOut, float currentTime) +{ + CInterpolationInfo info; + if (!GetInterpolationInfo(&info, currentTime, m_InterpolationAmount, NULL)) + return; + + CVarHistory& history = m_VarHistory; + bool bExtrapolate = false; + int realOlder = 0; + + if (info.m_bHermite) + { + _Derivative_Hermite_SmoothVelocity(pOut, info.frac, &history[info.oldest], &history[info.older], &history[info.newer]); + return; + } + else if (info.newer == info.older && CInterpolationContext::IsExtrapolationAllowed()) + { + realOlder = info.newer + 1; + if (IsValidIndex(realOlder) && history[realOlder].changetime != 0.0) + { + if (m_InterpolationAmount > 0.000001f && + CInterpolationContext::GetLastTimeStamp() <= (currentTime - m_InterpolationAmount)) + { + bExtrapolate = true; + } + } + } + + if (bExtrapolate) + { + _Derivative_Linear(pOut, &history[realOlder], &history[info.newer]); + + float flDestTime = currentTime - m_InterpolationAmount; + float diff = flDestTime - history[info.newer].changetime; + diff = clamp(diff, 0.f, cl_extrapolate_amount.GetFloat() * 2); + if (diff > cl_extrapolate_amount.GetFloat()) + { + float scale = 1 - (diff - cl_extrapolate_amount.GetFloat()) / cl_extrapolate_amount.GetFloat(); + for (int i = 0; i < m_nMaxCount; i++) + { + pOut[i] *= scale; + } + } + } + else + { + _Derivative_Linear(pOut, &history[info.older], &history[info.newer]); + } + +} + + +template< typename Type, bool IS_ARRAY > +inline int CInterpolatedVarArrayBase::Interpolate(float currentTime) +{ + return Interpolate(currentTime, m_InterpolationAmount); +} + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::Copy(IInterpolatedVar* pInSrc) +{ + CInterpolatedVarArrayBase* pSrc = dynamic_cast*>(pInSrc); + + if (!pSrc || pSrc->m_nMaxCount != m_nMaxCount) + { + if (pSrc) + { + AssertMsg3(false, "pSrc->m_nMaxCount (%i) != m_nMaxCount (%i) for %s.", pSrc->m_nMaxCount, m_nMaxCount, m_pDebugName); + } + else + { + AssertMsg(false, "pSrc was null in CInterpolatedVarArrayBase::Copy."); + } + + return; + } + + Assert((m_fType & ~EXCLUDE_AUTO_INTERPOLATE) == (pSrc->m_fType & ~EXCLUDE_AUTO_INTERPOLATE)); + Assert(m_pDebugName == pSrc->GetDebugName()); + + for (int i = 0; i < m_nMaxCount; i++) + { + m_LastNetworkedValue[i] = pSrc->m_LastNetworkedValue[i]; + m_bLooping[i] = pSrc->m_bLooping[i]; + } + + m_LastNetworkedTime = pSrc->m_LastNetworkedTime; + + m_VarHistory.RemoveAll(); + + for (int i = 0; i < pSrc->m_VarHistory.Count(); i++) + { + int newslot = m_VarHistory.AddToTail(); + + CInterpolatedVarEntry* dest = &m_VarHistory[newslot]; + CInterpolatedVarEntry* src = &pSrc->m_VarHistory[i]; + dest->NewEntry(src->GetValue(), m_nMaxCount, src->changetime); + } +} + +template< typename Type, bool IS_ARRAY > +inline const Type& CInterpolatedVarArrayBase::GetPrev(int iArrayIndex) const +{ + Assert(m_pValue); + Assert(iArrayIndex >= 0 && iArrayIndex < m_nMaxCount); + + if (m_VarHistory.Count() > 1) + { + return m_VarHistory[1].GetValue()[iArrayIndex]; + } + return m_pValue[iArrayIndex]; +} + +template< typename Type, bool IS_ARRAY > +inline const Type& CInterpolatedVarArrayBase::GetCurrent(int iArrayIndex) const +{ + Assert(m_pValue); + Assert(iArrayIndex >= 0 && iArrayIndex < m_nMaxCount); + + if (m_VarHistory.Count() > 0) + { + return m_VarHistory[0].GetValue()[iArrayIndex]; + } + return m_pValue[iArrayIndex]; +} + +template< typename Type, bool IS_ARRAY > +inline float CInterpolatedVarArrayBase::GetInterval() const +{ + if (m_VarHistory.Count() > 1) + { + return m_VarHistory[0].changetime - m_VarHistory[1].changetime; + } + + return 0.0f; +} + +template< typename Type, bool IS_ARRAY > +inline bool CInterpolatedVarArrayBase::IsValidIndex(int i) +{ + return m_VarHistory.IsValidIndex(i); +} + +template< typename Type, bool IS_ARRAY > +inline Type* CInterpolatedVarArrayBase::GetHistoryValue(int index, float& changetime, int iArrayIndex) +{ + Assert(iArrayIndex >= 0 && iArrayIndex < m_nMaxCount); + if (m_VarHistory.IsIdxValid(index)) + { + CInterpolatedVarEntry* entry = &m_VarHistory[index]; + changetime = entry->changetime; + return &entry->GetValue()[iArrayIndex]; + } + else + { + changetime = 0.0f; + return NULL; + } +} + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::SetHistoryValuesForItem(int item, Type& value) +{ + Assert(item >= 0 && item < m_nMaxCount); + + for (int i = 0; i < m_VarHistory.Count(); i++) + { + CInterpolatedVarEntry* entry = &m_VarHistory[i]; + entry->GetValue()[item] = value; + } +} + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::SetLooping(bool looping, int iArrayIndex) +{ + Assert(iArrayIndex >= 0 && iArrayIndex < m_nMaxCount); + m_bLooping[iArrayIndex] = looping; +} + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::SetMaxCount(int newmax) +{ + bool changed = (newmax != m_nMaxCount) ? true : false; + + newmax = MAX(1, newmax); + + m_nMaxCount = newmax; + if (changed) + { + delete[] m_bLooping; + delete[] m_LastNetworkedValue; + m_bLooping = new byte[m_nMaxCount]; + m_LastNetworkedValue = new Type[m_nMaxCount]; + memset(m_bLooping, 0, sizeof(byte) * m_nMaxCount); + memset(m_LastNetworkedValue, 0, sizeof(Type) * m_nMaxCount); + + Reset(); + } +} + + +template< typename Type, bool IS_ARRAY > +inline int CInterpolatedVarArrayBase::GetMaxCount() const +{ + return m_nMaxCount; +} + + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::_Interpolate(Type* out, float frac, CInterpolatedVarEntry* start, CInterpolatedVarEntry* end) +{ + Assert(start); + Assert(end); + + if (start == end) + { + for (int i = 0; i < m_nMaxCount; i++) + { + out[i] = end->GetValue()[i]; + Lerp_Clamp(out[i]); + } + return; + } + + Assert(frac >= 0.0f && frac <= 1.0f); + + for (int i = 0; i < m_nMaxCount; i++) + { + if (m_bLooping[i]) + { + out[i] = LoopingLerp(frac, start->GetValue()[i], end->GetValue()[i]); + } + else + { + out[i] = Lerp(frac, start->GetValue()[i], end->GetValue()[i]); + } + Lerp_Clamp(out[i]); + } +} + + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::_Extrapolate( + Type* pOut, + CInterpolatedVarEntry* pOld, + CInterpolatedVarEntry* pNew, + float flDestinationTime, + float flMaxExtrapolationAmount +) +{ + if (fabs(pOld->changetime - pNew->changetime) < 0.001f || flDestinationTime <= pNew->changetime) + { + for (int i = 0; i < m_nMaxCount; i++) + pOut[i] = pNew->GetValue()[i]; + } + else + { + float flExtrapolationAmount = MIN(flDestinationTime - pNew->changetime, flMaxExtrapolationAmount); + + float divisor = 1.0f / (pNew->changetime - pOld->changetime); + for (int i = 0; i < m_nMaxCount; i++) + { + pOut[i] = ExtrapolateInterpolatedVarType(pOld->GetValue()[i], pNew->GetValue()[i], divisor, flExtrapolationAmount); + } + } +} + + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::TimeFixup2_Hermite( + typename CInterpolatedVarArrayBase::CInterpolatedVarEntry& fixup, + typename CInterpolatedVarArrayBase::CInterpolatedVarEntry*& prev, + typename CInterpolatedVarArrayBase::CInterpolatedVarEntry*& start, + float dt1 +) +{ + float dt2 = start->changetime - prev->changetime; + + if (fabs(dt1 - dt2) > 0.0001f && + dt2 > 0.0001f) + { + float frac = dt1 / dt2; + + fixup.changetime = start->changetime - dt1; + + for (int i = 0; i < m_nMaxCount; i++) + { + if (m_bLooping[i]) + { + fixup.GetValue()[i] = LoopingLerp(1 - frac, prev->GetValue()[i], start->GetValue()[i]); + } + else + { + fixup.GetValue()[i] = Lerp(1 - frac, prev->GetValue()[i], start->GetValue()[i]); + } + } + + prev = &fixup; + } +} + + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::TimeFixup_Hermite( + typename CInterpolatedVarArrayBase::CInterpolatedVarEntry& fixup, + typename CInterpolatedVarArrayBase::CInterpolatedVarEntry*& prev, + typename CInterpolatedVarArrayBase::CInterpolatedVarEntry*& start, + typename CInterpolatedVarArrayBase::CInterpolatedVarEntry*& end) +{ + TimeFixup2_Hermite(fixup, prev, start, end->changetime - start->changetime); +} + + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::_Interpolate_Hermite( + Type* out, + float frac, + CInterpolatedVarEntry* prev, + CInterpolatedVarEntry* start, + CInterpolatedVarEntry* end, + bool looping) +{ + Assert(start); + Assert(end); + + CDisableRangeChecks disableRangeChecks; + + CInterpolatedVarEntry fixup; + fixup.Init(m_nMaxCount); + TimeFixup_Hermite(fixup, prev, start, end); + + for (int i = 0; i < m_nMaxCount; i++) + { + if (m_bLooping[i]) + { + out[i] = LoopingLerp_Hermite(frac, prev->GetValue()[i], start->GetValue()[i], end->GetValue()[i]); + } + else + { + out[i] = Lerp_Hermite(frac, prev->GetValue()[i], start->GetValue()[i], end->GetValue()[i]); + } + + Lerp_Clamp(out[i]); + } +} + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::_Derivative_Hermite( + Type* out, + float frac, + CInterpolatedVarEntry* prev, + CInterpolatedVarEntry* start, + CInterpolatedVarEntry* end) +{ + Assert(start); + Assert(end); + + CDisableRangeChecks disableRangeChecks; + + CInterpolatedVarEntry fixup; + fixup.value = (Type*)_alloca(sizeof(Type) * m_nMaxCount); + TimeFixup_Hermite(fixup, prev, start, end); + + float divisor = 1.0f / (end->changetime - start->changetime); + + for (int i = 0; i < m_nMaxCount; i++) + { + Assert(!m_bLooping[i]); + out[i] = Derivative_Hermite(frac, prev->GetValue()[i], start->GetValue()[i], end->GetValue()[i]); + out[i] *= divisor; + } +} + + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::_Derivative_Hermite_SmoothVelocity( + Type* out, + float frac, + CInterpolatedVarEntry* b, + CInterpolatedVarEntry* c, + CInterpolatedVarEntry* d) +{ + CInterpolatedVarEntry fixup; + fixup.Init(m_nMaxCount); + TimeFixup_Hermite(fixup, b, c, d); + for (int i = 0; i < m_nMaxCount; i++) + { + Type prevVel = (c->GetValue()[i] - b->GetValue()[i]) / (c->changetime - b->changetime); + Type curVel = (d->GetValue()[i] - c->GetValue()[i]) / (d->changetime - c->changetime); + out[i] = Lerp(frac, prevVel, curVel); + } +} + + +template< typename Type, bool IS_ARRAY > +inline void CInterpolatedVarArrayBase::_Derivative_Linear( + Type* out, + CInterpolatedVarEntry* start, + CInterpolatedVarEntry* end) +{ + if (start == end || fabs(start->changetime - end->changetime) < 0.0001f) + { + for (int i = 0; i < m_nMaxCount; i++) + { + out[i] = start->GetValue()[i] * 0; + } + } + else + { + float divisor = 1.0f / (end->changetime - start->changetime); + for (int i = 0; i < m_nMaxCount; i++) + { + out[i] = (end->GetValue()[i] - start->GetValue()[i]) * divisor; + } + } +} + + +template< typename Type, bool IS_ARRAY > +inline bool CInterpolatedVarArrayBase::ValidOrder() +{ + float newestchangetime = 0.0f; + bool first = true; + for (int i = 0; i < m_VarHistory.Count(); i++) + { + CInterpolatedVarEntry* entry = &m_VarHistory[i]; + if (first) + { + first = false; + newestchangetime = entry->changetime; + continue; + } + + if (entry->changetime > newestchangetime) + { + Assert(0); + return false; + } + + newestchangetime = entry->changetime; + } + + return true; +} + +template< typename Type, int COUNT > +class CInterpolatedVarArray : public CInterpolatedVarArrayBase +{ +public: + CInterpolatedVarArray(const char* pDebugName = "no debug name") + : CInterpolatedVarArrayBase(pDebugName) + { + this->SetMaxCount(COUNT); + } +}; + + +template< typename Type > +class CInterpolatedVar : public CInterpolatedVarArrayBase< Type, false > +{ +public: + CInterpolatedVar(const char* pDebugName = NULL) + : CInterpolatedVarArrayBase< Type, false >(pDebugName) + { + this->SetMaxCount(1); + } +}; + +#include "memdbgoff.h" + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/ipredictionsystem.h b/SpyCustom/sdk/ipredictionsystem.h new file mode 100644 index 0000000..1c8ff7f --- /dev/null +++ b/SpyCustom/sdk/ipredictionsystem.h @@ -0,0 +1,152 @@ +#ifndef IPREDICTIONSYSTEM_H +#define IPREDICTIONSYSTEM_H +#ifdef _WIN32 +#pragma once +#endif + +#include "predictable_entity.h" + +class CBaseEntity; + +class IPredictionSystem +{ +public: + IPredictionSystem() + { + m_pNextSystem = g_pPredictionSystems; + g_pPredictionSystems = this; + + m_bSuppressEvent = false; + m_pSuppressHost = NULL; + + m_nStatusPushed = 0; + }; + + virtual ~IPredictionSystem() {}; + + IPredictionSystem* GetNext() + { + return m_pNextSystem; + } + + void SetSuppressEvent(bool state) + { + m_bSuppressEvent = state; + } + + void SetSuppressHost(CBaseEntity* host) + { + m_pSuppressHost = host; + } + + CBaseEntity const* GetSuppressHost(void) + { + if (DisableFiltering()) + { + return NULL; + } + + return m_pSuppressHost; + } + + bool CanPredict(void) const + { + if (DisableFiltering()) + { + return false; + } + + return !m_bSuppressEvent; + } + + static IPredictionSystem* g_pPredictionSystems; + + static void SuppressEvents(bool state) + { + IPredictionSystem* sys = g_pPredictionSystems; + while (sys) + { + sys->SetSuppressEvent(state); + sys = sys->GetNext(); + } + } + + static void SuppressHostEvents(CBaseEntity* host) + { + IPredictionSystem* sys = g_pPredictionSystems; + while (sys) + { + sys->SetSuppressHost(host); + sys = sys->GetNext(); + } + } + +private: + + static void Push(void) + { + IPredictionSystem* sys = g_pPredictionSystems; + while (sys) + { + sys->_Push(); + sys = sys->GetNext(); + } + } + + static void Pop(void) + { + IPredictionSystem* sys = g_pPredictionSystems; + while (sys) + { + sys->_Pop(); + sys = sys->GetNext(); + } + } + + void _Push(void) + { + ++m_nStatusPushed; + } + void _Pop(void) + { + --m_nStatusPushed; + } + + bool DisableFiltering(void) const + { + return (m_nStatusPushed > 0) ? true : false; + } + + IPredictionSystem* m_pNextSystem; + bool m_bSuppressEvent; + CBaseEntity* m_pSuppressHost; + + int m_nStatusPushed; + + friend class CDisablePredictionFiltering; +}; + +class CDisablePredictionFiltering +{ +public: + CDisablePredictionFiltering(bool disable = true) + { + m_bDisabled = disable; + if (m_bDisabled) + { + IPredictionSystem::Push(); + } + } + + ~CDisablePredictionFiltering(void) + { + if (m_bDisabled) + { + IPredictionSystem::Pop(); + } + } +private: + bool m_bDisabled; +}; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/irecipientfilter.h b/SpyCustom/sdk/irecipientfilter.h new file mode 100644 index 0000000..59b5b6e --- /dev/null +++ b/SpyCustom/sdk/irecipientfilter.h @@ -0,0 +1,29 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#ifndef IRECIPIENTFILTER_H +#define IRECIPIENTFILTER_H +#ifdef _WIN32 +#pragma once +#endif + +//----------------------------------------------------------------------------- +// Purpose: Generic interface for routing messages to users +//----------------------------------------------------------------------------- +class IRecipientFilter +{ +public: + virtual ~IRecipientFilter() {} + + virtual bool IsReliable(void) const = 0; + virtual bool IsInitMessage(void) const = 0; + + virtual int GetRecipientCount(void) const = 0; + virtual int GetRecipientIndex(int slot) const = 0; +}; + +#endif // IRECIPIENTFILTER_H \ No newline at end of file diff --git a/SpyCustom/sdk/iscenetokenprocessor.h b/SpyCustom/sdk/iscenetokenprocessor.h new file mode 100644 index 0000000..7b7ed20 --- /dev/null +++ b/SpyCustom/sdk/iscenetokenprocessor.h @@ -0,0 +1,16 @@ +#ifndef ISCENETOKENPROCESSOR_H +#define ISCENETOKENPROCESSOR_H +#ifdef _WIN32 +#pragma once +#endif + +class ISceneTokenProcessor +{ +public: + virtual const char* CurrentToken(void) = 0; + virtual bool GetToken(bool crossline) = 0; + virtual bool TokenAvailable(void) = 0; + virtual void Error(PRINTF_FORMAT_STRING const char* fmt, ...) = 0; +}; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/iserverentity.h b/SpyCustom/sdk/iserverentity.h new file mode 100644 index 0000000..44661e9 --- /dev/null +++ b/SpyCustom/sdk/iserverentity.h @@ -0,0 +1,32 @@ +#ifndef ISERVERENTITY_H +#define ISERVERENTITY_H +#ifdef _WIN32 +#pragma once +#endif + + +#include "iserverunknown.h" +#include "string_t.h" + + + +struct Ray_t; +class ServerClass; +class ICollideable; +class IServerNetworkable; +class Vector; +class QAngle; + +class IServerEntity : public IServerUnknown +{ +public: + virtual ~IServerEntity() {} + + virtual int GetModelIndex(void) const = 0; + virtual string_t GetModelName(void) const = 0; + + virtual void SetModelIndex(int index) = 0; +}; + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/iservernetworkable.h b/SpyCustom/sdk/iservernetworkable.h new file mode 100644 index 0000000..6742005 --- /dev/null +++ b/SpyCustom/sdk/iservernetworkable.h @@ -0,0 +1,89 @@ +#ifndef ISERVERNETWORKABLE_H +#define ISERVERNETWORKABLE_H +#ifdef _WIN32 +#pragma once +#endif + + +#include "ihandleentity.h" +#include "basetypes.h" +#include "bitvec.h" +#include "const.h" +#include "bspfile.h" + + + +#define MAX_FAST_ENT_CLUSTERS 4 +#define MAX_ENT_CLUSTERS 64 +#define MAX_WORLD_AREAS 8 + + +class ServerClass; +class SendTable; +struct edict_t; +class CBaseEntity; +class CSerialEntity; +class CBaseNetworkable; + + +class CCheckTransmitInfo +{ +public: + edict_t* m_pClientEnt; + byte m_PVS[PAD_NUMBER(MAX_MAP_CLUSTERS, 8) / 8]; + int m_nPVSSize; + + CBitVec* m_pTransmitEdict; + CBitVec* m_pTransmitAlways; + + int m_AreasNetworked; + int m_Areas[MAX_WORLD_AREAS]; + + byte m_AreaFloodNums[MAX_MAP_AREAS]; + int m_nMapAreas; +}; + +struct PVSInfo_t +{ + short m_nHeadNode; + + short m_nClusterCount; + + unsigned short* m_pClusters; + + short m_nAreaNum; + short m_nAreaNum2; + + float m_vCenter[3]; + +private: + unsigned short m_pClustersInline[MAX_FAST_ENT_CLUSTERS]; + + friend class CVEngineServer; +}; + + +class IServerNetworkable +{ +public: + virtual IHandleEntity* GetEntityHandle() = 0; + + virtual ServerClass* GetServerClass() = 0; + + virtual edict_t* GetEdict() const = 0; + + virtual const char* GetClassName() const = 0; + virtual void Release() = 0; + + virtual int AreaNum() const = 0; + + virtual CBaseNetworkable* GetBaseNetworkable() = 0; + virtual CBaseEntity* GetBaseEntity() = 0; + virtual PVSInfo_t* GetPVSInfo() = 0; + +protected: + virtual ~IServerNetworkable() {} +}; + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/iserverplugin.h b/SpyCustom/sdk/iserverplugin.h new file mode 100644 index 0000000..652fb15 --- /dev/null +++ b/SpyCustom/sdk/iserverplugin.h @@ -0,0 +1,103 @@ +#ifndef ISERVERPLUGIN_H +#define ISERVERPLUGIN_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "edict.h" +#include "interface.h" +#include "KeyValues.h" + +class CCommand; + +typedef enum +{ + PLUGIN_CONTINUE = 0, + PLUGIN_OVERRIDE, + PLUGIN_STOP, +} PLUGIN_RESULT; + + +typedef enum +{ + eQueryCvarValueStatus_ValueIntact = 0, + eQueryCvarValueStatus_CvarNotFound = 1, + eQueryCvarValueStatus_NotACvar = 2, + eQueryCvarValueStatus_CvarProtected = 3 +} EQueryCvarValueStatus; + + +typedef int QueryCvarCookie_t; +#define InvalidQueryCvarCookie -1 + + +#define INTERFACEVERSION_ISERVERPLUGINCALLBACKS_VERSION_1 "ISERVERPLUGINCALLBACKS001" +#define INTERFACEVERSION_ISERVERPLUGINCALLBACKS_VERSION_2 "ISERVERPLUGINCALLBACKS002" +#define INTERFACEVERSION_ISERVERPLUGINCALLBACKS "ISERVERPLUGINCALLBACKS003" + +abstract_class IServerPluginCallbacks +{ +public: + virtual bool Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory) = 0; + + virtual void Unload(void) = 0; + + virtual void Pause(void) = 0; + + virtual void UnPause(void) = 0; + + virtual const char* GetPluginDescription(void) = 0; + + virtual void LevelInit(char const* pMapName) = 0; + + virtual void ServerActivate(edict_t* pEdictList, int edictCount, int clientMax) = 0; + + virtual void GameFrame(bool simulating) = 0; + + virtual void LevelShutdown(void) = 0; + + virtual void ClientActive(edict_t* pEntity) = 0; + + virtual void ClientDisconnect(edict_t* pEntity) = 0; + + virtual void ClientPutInServer(edict_t* pEntity, char const* playername) = 0; + + virtual void SetCommandClient(int index) = 0; + + virtual void ClientSettingsChanged(edict_t* pEdict) = 0; + + virtual PLUGIN_RESULT ClientConnect(bool* bAllowConnect, edict_t* pEntity, const char* pszName, const char* pszAddress, char* reject, int maxrejectlen) = 0; + + virtual PLUGIN_RESULT ClientCommand(edict_t* pEntity, const CCommand& args) = 0; + + virtual PLUGIN_RESULT NetworkIDValidated(const char* pszUserName, const char* pszNetworkID) = 0; + + virtual void OnQueryCvarValueFinished(QueryCvarCookie_t iCookie, edict_t* pPlayerEntity, EQueryCvarValueStatus eStatus, const char* pCvarName, const char* pCvarValue) = 0; + + virtual void OnEdictAllocated(edict_t* edict) = 0; + virtual void OnEdictFreed(const edict_t* edict) = 0; +}; + +#define INTERFACEVERSION_ISERVERPLUGINHELPERS "ISERVERPLUGINHELPERS001" + + +typedef enum +{ + DIALOG_MSG = 0, + DIALOG_MENU, + DIALOG_TEXT, + DIALOG_ENTRY, + DIALOG_ASKCONNECT +} DIALOG_TYPE; + +abstract_class IServerPluginHelpers +{ +public: + virtual void CreateMessage(edict_t * pEntity, DIALOG_TYPE type, KeyValues * data, IServerPluginCallbacks * plugin) = 0; + virtual void ClientCommand(edict_t* pEntity, const char* cmd) = 0; + + virtual QueryCvarCookie_t StartQueryCvarValue(edict_t* pEntity, const char* pName) = 0; +}; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/iserverunknown.h b/SpyCustom/sdk/iserverunknown.h new file mode 100644 index 0000000..9c0bf4f --- /dev/null +++ b/SpyCustom/sdk/iserverunknown.h @@ -0,0 +1,25 @@ +#ifndef ISERVERUNKNOWN_H +#define ISERVERUNKNOWN_H + +#ifdef _WIN32 +#pragma once +#endif + + +#include "ihandleentity.h" + +class ICollideable; +class IServerNetworkable; +class CBaseEntity; + + +class IServerUnknown : public IHandleEntity +{ +public: + virtual ICollideable* GetCollideable() = 0; + virtual IServerNetworkable* GetNetworkable() = 0; + virtual CBaseEntity* GetBaseEntity() = 0; +}; + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/ishadowmgr.h b/SpyCustom/sdk/ishadowmgr.h new file mode 100644 index 0000000..b0ccdf7 --- /dev/null +++ b/SpyCustom/sdk/ishadowmgr.h @@ -0,0 +1,116 @@ +#ifndef ISHADOWMGR_H +#define ISHADOWMGR_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "interface.h" +#include "vmatrix.h" + + +class IMaterial; +class Vector; +class Vector2D; +struct model_t; +typedef unsigned short ModelInstanceHandle_t; +class IClientRenderable; +class ITexture; + +#define ENGINE_SHADOWMGR_INTERFACE_VERSION "VEngineShadowMgr002" + + +enum ShadowFlags_t +{ + SHADOW_FLAGS_FLASHLIGHT = (1 << 0), + SHADOW_FLAGS_SHADOW = (1 << 1), + SHADOW_FLAGS_LAST_FLAG = SHADOW_FLAGS_SHADOW +}; + +#define SHADOW_FLAGS_PROJECTED_TEXTURE_TYPE_MASK ( SHADOW_FLAGS_FLASHLIGHT | SHADOW_FLAGS_SHADOW ) + + + +typedef unsigned short ShadowHandle_t; + +enum +{ + SHADOW_HANDLE_INVALID = (ShadowHandle_t)~0 +}; + + +enum ShadowCreateFlags_t +{ + SHADOW_CACHE_VERTS = (1 << 0), + SHADOW_FLASHLIGHT = (1 << 1), + + SHADOW_LAST_FLAG = SHADOW_FLASHLIGHT, +}; + + +struct ShadowInfo_t +{ + VMatrix m_WorldToShadow; + + float m_FalloffOffset; + float m_MaxDist; + float m_FalloffAmount; + Vector2D m_TexOrigin; + Vector2D m_TexSize; + unsigned char m_FalloffBias; +}; + +struct FlashlightState_t; + +abstract_class IShadowMgr +{ +public: + virtual ShadowHandle_t CreateShadow(IMaterial * pMaterial, IMaterial * pModelMaterial, void* pBindProxy, int creationFlags) = 0; + virtual void DestroyShadow(ShadowHandle_t handle) = 0; + + virtual void SetShadowMaterial(ShadowHandle_t handle, IMaterial* pMaterial, IMaterial* pModelMaterial, void* pBindProxy) = 0; + + virtual void ProjectShadow(ShadowHandle_t handle, const Vector& origin, + const Vector& projectionDir, const VMatrix& worldToShadow, const Vector2D& size, + int nLeafCount, const int* pLeafList, + float maxHeight, float falloffOffset, float falloffAmount, const Vector& vecCasterOrigin) = 0; + + virtual void ProjectFlashlight(ShadowHandle_t handle, const VMatrix& worldToShadow, int nLeafCount, const int* pLeafList) = 0; + + virtual const ShadowInfo_t& GetInfo(ShadowHandle_t handle) = 0; + + virtual const Frustum_t& GetFlashlightFrustum(ShadowHandle_t handle) = 0; + + virtual void AddShadowToBrushModel(ShadowHandle_t handle, + model_t* pModel, const Vector& origin, const QAngle& angles) = 0; + + virtual void RemoveAllShadowsFromBrushModel(model_t* pModel) = 0; + + virtual void SetShadowTexCoord(ShadowHandle_t handle, float x, float y, float w, float h) = 0; + + virtual void AddShadowToModel(ShadowHandle_t shadow, ModelInstanceHandle_t instance) = 0; + virtual void RemoveAllShadowsFromModel(ModelInstanceHandle_t instance) = 0; + + virtual void ClearExtraClipPlanes(ShadowHandle_t shadow) = 0; + virtual void AddExtraClipPlane(ShadowHandle_t shadow, const Vector& normal, float dist) = 0; + + virtual void EnableShadow(ShadowHandle_t shadow, bool bEnable) = 0; + + virtual void SetFalloffBias(ShadowHandle_t shadow, unsigned char ucBias) = 0; + + virtual void UpdateFlashlightState(ShadowHandle_t shadowHandle, const FlashlightState_t& lightState) = 0; + + virtual void DrawFlashlightDepthTexture() = 0; + + virtual void AddFlashlightRenderable(ShadowHandle_t shadow, IClientRenderable* pRenderable) = 0; + virtual ShadowHandle_t CreateShadowEx(IMaterial* pMaterial, IMaterial* pModelMaterial, void* pBindProxy, int creationFlags) = 0; + + virtual void SetFlashlightDepthTexture(ShadowHandle_t shadowHandle, ITexture* pFlashlightDepthTexture, unsigned char ucShadowStencilBit) = 0; + + virtual const FlashlightState_t& GetFlashlightState(ShadowHandle_t handle) = 0; + + virtual void SetFlashlightRenderState(ShadowHandle_t handle) = 0; +}; + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/ispatialpartition.h b/SpyCustom/sdk/ispatialpartition.h new file mode 100644 index 0000000..0d4cd56 --- /dev/null +++ b/SpyCustom/sdk/ispatialpartition.h @@ -0,0 +1,157 @@ +#ifndef ISPATIALPARTITION_H +#define ISPATIALPARTITION_H + +#include "interface.h" + +class Vector; +struct Ray_t; +class IHandleEntity; + + +#define INTERFACEVERSION_SPATIALPARTITION "SpatialPartition001" + +enum +{ + PARTITION_ENGINE_SOLID_EDICTS = (1 << 0), + PARTITION_ENGINE_TRIGGER_EDICTS = (1 << 1), + PARTITION_CLIENT_SOLID_EDICTS = (1 << 2), + PARTITION_CLIENT_RESPONSIVE_EDICTS = (1 << 3), + PARTITION_ENGINE_NON_STATIC_EDICTS = (1 << 4), + PARTITION_CLIENT_STATIC_PROPS = (1 << 5), + PARTITION_ENGINE_STATIC_PROPS = (1 << 6), + PARTITION_CLIENT_NON_STATIC_EDICTS = (1 << 7), +}; + +#define PARTITION_ALL_CLIENT_EDICTS ( \ + PARTITION_CLIENT_NON_STATIC_EDICTS | \ + PARTITION_CLIENT_STATIC_PROPS | \ + PARTITION_CLIENT_RESPONSIVE_EDICTS | \ + PARTITION_CLIENT_SOLID_EDICTS \ + ) + + +#define PARTITION_CLIENT_GAME_EDICTS (PARTITION_ALL_CLIENT_EDICTS & ~PARTITION_CLIENT_STATIC_PROPS) +#define PARTITION_SERVER_GAME_EDICTS (PARTITION_ENGINE_SOLID_EDICTS|PARTITION_ENGINE_TRIGGER_EDICTS|PARTITION_ENGINE_NON_STATIC_EDICTS) + +enum IterationRetval_t +{ + ITERATION_CONTINUE = 0, + ITERATION_STOP, +}; + + +typedef unsigned short SpatialPartitionHandle_t; + +typedef int SpatialPartitionListMask_t; + +typedef int SpatialTempHandle_t; + + +class IPartitionEnumerator +{ +public: + virtual IterationRetval_t EnumElement(IHandleEntity* pHandleEntity) = 0; +}; + + +class IPartitionQueryCallback +{ +public: + virtual void OnPreQuery_V1() = 0; + virtual void OnPreQuery(SpatialPartitionListMask_t listMask) = 0; + virtual void OnPostQuery(SpatialPartitionListMask_t listMask) = 0; +}; + + +enum +{ + PARTITION_INVALID_HANDLE = (SpatialPartitionHandle_t)~0 +}; + + +abstract_class ISpatialPartition +{ +public: + virtual ~ISpatialPartition() {} + + virtual SpatialPartitionHandle_t CreateHandle(IHandleEntity * pHandleEntity) = 0; + + virtual SpatialPartitionHandle_t CreateHandle(IHandleEntity* pHandleEntity, + SpatialPartitionListMask_t listMask, const Vector& mins, const Vector& maxs) = 0; + + virtual void DestroyHandle(SpatialPartitionHandle_t handle) = 0; + + virtual void Insert(SpatialPartitionListMask_t listMask, + SpatialPartitionHandle_t handle) = 0; + virtual void Remove(SpatialPartitionListMask_t listMask, + SpatialPartitionHandle_t handle) = 0; + + virtual void RemoveAndInsert(SpatialPartitionListMask_t removeMask, SpatialPartitionListMask_t insertMask, + SpatialPartitionHandle_t handle) = 0; + + virtual void Remove(SpatialPartitionHandle_t handle) = 0; + + virtual void ElementMoved(SpatialPartitionHandle_t handle, + const Vector& mins, const Vector& maxs) = 0; + + virtual SpatialTempHandle_t HideElement(SpatialPartitionHandle_t handle) = 0; + virtual void UnhideElement(SpatialPartitionHandle_t handle, SpatialTempHandle_t tempHandle) = 0; + + virtual void InstallQueryCallback_V1(IPartitionQueryCallback* pCallback) = 0; + virtual void RemoveQueryCallback(IPartitionQueryCallback* pCallback) = 0; + + virtual void EnumerateElementsInBox( + SpatialPartitionListMask_t listMask, + const Vector& mins, + const Vector& maxs, + bool coarseTest, + IPartitionEnumerator* pIterator + ) = 0; + + virtual void EnumerateElementsInSphere( + SpatialPartitionListMask_t listMask, + const Vector& origin, + float radius, + bool coarseTest, + IPartitionEnumerator* pIterator + ) = 0; + + virtual void EnumerateElementsAlongRay( + SpatialPartitionListMask_t listMask, + const Ray_t& ray, + bool coarseTest, + IPartitionEnumerator* pIterator + ) = 0; + + virtual void EnumerateElementsAtPoint( + SpatialPartitionListMask_t listMask, + const Vector& pt, + bool coarseTest, + IPartitionEnumerator* pIterator + ) = 0; + + virtual void SuppressLists(SpatialPartitionListMask_t nListMask, bool bSuppress) = 0; + virtual SpatialPartitionListMask_t GetSuppressedLists() = 0; + + virtual void RenderAllObjectsInTree(float flTime) = 0; + virtual void RenderObjectsInPlayerLeafs(const Vector& vecPlayerMin, const Vector& vecPlayerMax, float flTime) = 0; + virtual void RenderLeafsForRayTraceStart(float flTime) = 0; + virtual void RenderLeafsForRayTraceEnd(void) = 0; + virtual void RenderLeafsForHullTraceStart(float flTime) = 0; + virtual void RenderLeafsForHullTraceEnd(void) = 0; + virtual void RenderLeafsForBoxStart(float flTime) = 0; + virtual void RenderLeafsForBoxEnd(void) = 0; + virtual void RenderLeafsForSphereStart(float flTime) = 0; + virtual void RenderLeafsForSphereEnd(void) = 0; + + virtual void RenderObjectsInBox(const Vector& vecMin, const Vector& vecMax, float flTime) = 0; + virtual void RenderObjectsInSphere(const Vector& vecCenter, float flRadius, float flTime) = 0; + virtual void RenderObjectsAlongRay(const Ray_t& ray, float flTime) = 0; + + virtual void ReportStats(const char* pFileName) = 0; + + virtual void InstallQueryCallback(IPartitionQueryCallback* pCallback) = 0; +}; + +#endif + diff --git a/SpyCustom/sdk/istudiorender.h b/SpyCustom/sdk/istudiorender.h new file mode 100644 index 0000000..134fef6 --- /dev/null +++ b/SpyCustom/sdk/istudiorender.h @@ -0,0 +1,290 @@ +#ifndef ISTUDIORENDER_H +#define ISTUDIORENDER_H +#ifdef _WIN32 +#pragma once +#endif + +#include "interface.h" +#include "vector.h" +#include "vector4d.h" +#include "utlbuffer.h" +#include "utlvector.h" +#include "imaterial.h" +#include "imaterialsystem.h" +#include "IAppSystem.h" +#include "imdlcache.h" +#include "studio.h" + + +struct studiohdr_t; +struct studiomeshdata_t; +class Vector; +struct LightDesc_t; +class IMaterial; +struct studiohwdata_t; +struct Ray_t; +class Vector4D; +class IMaterialSystem; +struct matrix3x4_t; +class IMesh; +struct vertexFileHeader_t; +struct FlashlightState_t; +class VMatrix; +namespace OptimizedModel { struct FileHeader_t; } +class IPooledVBAllocator; + +typedef void (*StudioRender_Printf_t)(PRINTF_FORMAT_STRING const char* fmt, ...); + +struct StudioRenderConfig_t +{ + float fEyeShiftX; + float fEyeShiftY; + float fEyeShiftZ; + float fEyeSize; + float fEyeGlintPixelWidthLODThreshold; + + int maxDecalsPerModel; + int drawEntities; + int skin; + int fullbright; + + bool bEyeMove : 1; + bool bSoftwareSkin : 1; + bool bNoHardware : 1; + bool bNoSoftware : 1; + bool bTeeth : 1; + bool bEyes : 1; + bool bFlex : 1; + bool bWireframe : 1; + bool bDrawNormals : 1; + bool bDrawTangentFrame : 1; + bool bDrawZBufferedWireframe : 1; + bool bSoftwareLighting : 1; + bool bShowEnvCubemapOnly : 1; + bool bWireframeDecals : 1; + + int m_nReserved[4]; +}; + + + +DECLARE_POINTER_HANDLE(StudioDecalHandle_t); +#define STUDIORENDER_DECAL_INVALID ( (StudioDecalHandle_t)0 ) + +enum +{ + ADDDECAL_TO_ALL_LODS = -1 +}; + + +enum +{ + STUDIORENDER_DRAW_ENTIRE_MODEL = 0, + STUDIORENDER_DRAW_OPAQUE_ONLY = 0x01, + STUDIORENDER_DRAW_TRANSLUCENT_ONLY = 0x02, + STUDIORENDER_DRAW_GROUP_MASK = 0x03, + + STUDIORENDER_DRAW_NO_FLEXES = 0x04, + STUDIORENDER_DRAW_STATIC_LIGHTING = 0x08, + + STUDIORENDER_DRAW_ACCURATETIME = 0x10, + STUDIORENDER_DRAW_NO_SHADOWS = 0x20, + STUDIORENDER_DRAW_GET_PERF_STATS = 0x40, + + STUDIORENDER_DRAW_WIREFRAME = 0x80, + + STUDIORENDER_DRAW_ITEM_BLINK = 0x100, + + STUDIORENDER_SHADOWDEPTHTEXTURE = 0x200, + + STUDIORENDER_SSAODEPTHTEXTURE = 0x1000, + + STUDIORENDER_GENERATE_STATS = 0x8000, +}; + + +#define VERTEX_TEXCOORD0_2D ( ( (uint64) 2 ) << ( TEX_COORD_SIZE_BIT + ( 3*0 ) ) ) +enum MaterialVertexFormat_t +{ + MATERIAL_VERTEX_FORMAT_MODEL_SKINNED = (VertexFormat_t)VERTEX_POSITION | VERTEX_COLOR | VERTEX_NORMAL | VERTEX_TEXCOORD0_2D | VERTEX_BONEWEIGHT(2) | VERTEX_BONE_INDEX | VERTEX_USERDATA_SIZE(4), + MATERIAL_VERTEX_FORMAT_MODEL_SKINNED_DX7 = (VertexFormat_t)VERTEX_POSITION | VERTEX_COLOR | VERTEX_NORMAL | VERTEX_TEXCOORD0_2D | VERTEX_BONEWEIGHT(2) | VERTEX_BONE_INDEX, + MATERIAL_VERTEX_FORMAT_MODEL = (VertexFormat_t)VERTEX_POSITION | VERTEX_COLOR | VERTEX_NORMAL | VERTEX_TEXCOORD0_2D | VERTEX_USERDATA_SIZE(4), + MATERIAL_VERTEX_FORMAT_MODEL_DX7 = (VertexFormat_t)VERTEX_POSITION | VERTEX_COLOR | VERTEX_NORMAL | VERTEX_TEXCOORD0_2D, + MATERIAL_VERTEX_FORMAT_COLOR = (VertexFormat_t)VERTEX_SPECULAR +}; + + +enum OverrideType_t +{ + OVERRIDE_NORMAL = 0, + OVERRIDE_BUILD_SHADOWS, + OVERRIDE_DEPTH_WRITE, + OVERRIDE_SSAO_DEPTH_WRITE, +}; + + +enum +{ + USESHADOWLOD = -2, +}; + +#define MAX_DRAW_MODEL_INFO_MATERIALS 8 + +struct DrawModelResults_t +{ + int m_ActualTriCount; + int m_TextureMemoryBytes; + int m_NumHardwareBones; + int m_NumBatches; + int m_NumMaterials; + int m_nLODUsed; + int m_flLODMetric; + CFastTimer m_RenderTime; + CUtlVectorFixed m_Materials; +}; + +struct ColorMeshInfo_t +{ + IMesh* m_pMesh; + IPooledVBAllocator* m_pPooledVBAllocator; + int m_nVertOffsetInBytes; + int m_nNumVerts; +}; + +struct DrawModelInfo_t +{ + studiohdr_t* m_pStudioHdr; + studiohwdata_t* m_pHardwareData; + StudioDecalHandle_t m_Decals; + int m_Skin; + int m_Body; + int m_HitboxSet; + void* m_pClientEntity; + int m_Lod; + ColorMeshInfo_t* m_pColorMeshes; + bool m_bStaticLighting; + Vector m_vecAmbientCube[6]; + int m_nLocalLightCount; + LightDesc_t m_LocalLightDescs[4]; +}; + +struct GetTriangles_Vertex_t +{ + Vector m_Position; + Vector m_Normal; + Vector4D m_TangentS; + Vector2D m_TexCoord; + Vector4D m_BoneWeight; + int m_BoneIndex[4]; + int m_NumBones; +}; + +struct GetTriangles_MaterialBatch_t +{ + IMaterial* m_pMaterial; + CUtlVector m_Verts; + CUtlVector m_TriListIndices; +}; + +struct GetTriangles_Output_t +{ + CUtlVector m_MaterialBatches; + matrix3x4_t m_PoseToWorld[MAXSTUDIOBONES]; +}; + + +struct model_array_instance_t +{ + matrix3x4_t modelToWorld; + +}; + +#define STUDIO_DATA_CACHE_INTERFACE_VERSION "VStudioDataCache005" + +abstract_class IStudioDataCache : public IAppSystem +{ +public: + virtual bool VerifyHeaders(studiohdr_t * pStudioHdr) = 0; + virtual vertexFileHeader_t* CacheVertexData(studiohdr_t* pStudioHdr) = 0; +}; + + +#define STUDIO_RENDER_INTERFACE_VERSION "VStudioRender025" + +abstract_class IStudioRender : public IAppSystem +{ +public: + virtual void BeginFrame(void) = 0; + virtual void EndFrame(void) = 0; + + virtual void Mat_Stub(IMaterialSystem* pMatSys) = 0; + + virtual void UpdateConfig(const StudioRenderConfig_t& config) = 0; + virtual void GetCurrentConfig(StudioRenderConfig_t& config) = 0; + + virtual bool LoadModel(studiohdr_t* pStudioHdr, void* pVtxData, studiohwdata_t* pHardwareData) = 0; + virtual void UnloadModel(studiohwdata_t* pHardwareData) = 0; + + virtual void RefreshStudioHdr(studiohdr_t* pStudioHdr, studiohwdata_t* pHardwareData) = 0; + + virtual void SetEyeViewTarget(const studiohdr_t* pStudioHdr, int nBodyIndex, const Vector& worldPosition) = 0; + + virtual int GetNumAmbientLightSamples() = 0; + virtual const Vector* GetAmbientLightDirections() = 0; + virtual void SetAmbientLightColors(const Vector4D* pAmbientOnlyColors) = 0; + virtual void SetAmbientLightColors(const Vector* pAmbientOnlyColors) = 0; + virtual void SetLocalLights(int numLights, const LightDesc_t* pLights) = 0; + + virtual void SetViewState(const Vector& viewOrigin, const Vector& viewRight, + const Vector& viewUp, const Vector& viewPlaneNormal) = 0; + + virtual void LockFlexWeights(int nWeightCount, float** ppFlexWeights, float** ppFlexDelayedWeights = NULL) = 0; + virtual void UnlockFlexWeights() = 0; + + virtual matrix3x4_t* LockBoneMatrices(int nBoneCount) = 0; + virtual void UnlockBoneMatrices() = 0; + + virtual int GetNumLODs(const studiohwdata_t& hardwareData) const = 0; + virtual float GetLODSwitchValue(const studiohwdata_t& hardwareData, int lod) const = 0; + virtual void SetLODSwitchValue(studiohwdata_t& hardwareData, int lod, float switchValue) = 0; + + virtual void SetColorModulation(float const* pColor) = 0; + virtual void SetAlphaModulation(float flAlpha) = 0; + + virtual void DrawModel(DrawModelResults_t* pResults, const DrawModelInfo_t& info, + matrix3x4_t* pBoneToWorld, float* pFlexWeights, float* pFlexDelayedWeights, const Vector& modelOrigin, int flags = STUDIORENDER_DRAW_ENTIRE_MODEL) = 0; + + virtual void DrawModelStaticProp(const DrawModelInfo_t& drawInfo, const matrix3x4_t& modelToWorld, int flags = STUDIORENDER_DRAW_ENTIRE_MODEL) = 0; + virtual void DrawStaticPropDecals(const DrawModelInfo_t& drawInfo, const matrix3x4_t& modelToWorld) = 0; + virtual void DrawStaticPropShadows(const DrawModelInfo_t& drawInfo, const matrix3x4_t& modelToWorld, int flags) = 0; + + virtual void ForcedMaterialOverride(IMaterial* newMaterial, OverrideType_t nOverrideType = OVERRIDE_NORMAL) = 0; + + virtual StudioDecalHandle_t CreateDecalList(studiohwdata_t* pHardwareData) = 0; + virtual void DestroyDecalList(StudioDecalHandle_t handle) = 0; + + virtual void AddDecal(StudioDecalHandle_t handle, studiohdr_t* pStudioHdr, matrix3x4_t* pBoneToWorld, + const Ray_t& ray, const Vector& decalUp, IMaterial* pDecalMaterial, float radius, int body, bool noPokethru = false, int maxLODToDecal = ADDDECAL_TO_ALL_LODS) = 0; + + virtual void ComputeLighting(const Vector* pAmbient, int lightCount, + LightDesc_t* pLights, const Vector& pt, const Vector& normal, Vector& lighting) = 0; + + virtual void ComputeLightingConstDirectional(const Vector* pAmbient, int lightCount, + LightDesc_t* pLights, const Vector& pt, const Vector& normal, Vector& lighting, float flDirectionalAmount) = 0; + + virtual void AddShadow(IMaterial* pMaterial, void* pProxyData, FlashlightState_t* m_pFlashlightState = NULL, VMatrix* pWorldToTexture = NULL, ITexture* pFlashlightDepthTexture = NULL) = 0; + virtual void ClearAllShadows() = 0; + + virtual int ComputeModelLod(studiohwdata_t* pHardwareData, float unitSphereSize, float* pMetric = NULL) = 0; + + virtual void GetPerfStats(DrawModelResults_t* pResults, const DrawModelInfo_t& info, CUtlBuffer* pSpewBuf = NULL) const = 0; + virtual void GetTriangles(const DrawModelInfo_t& info, matrix3x4_t* pBoneToWorld, GetTriangles_Output_t& out) = 0; + + virtual int GetMaterialList(studiohdr_t* pStudioHdr, int count, IMaterial** ppMaterials) = 0; + virtual int GetMaterialListFromBodyAndSkin(MDLHandle_t studio, int nSkin, int nBody, int nCountOutputMaterials, IMaterial** ppOutputMaterials) = 0; + virtual void DrawModelArray(const DrawModelInfo_t& drawInfo, int arrayCount, model_array_instance_t* pInstanceData, int instanceStride, int flags = STUDIORENDER_DRAW_ENTIRE_MODEL) = 0; +}; + +extern IStudioRender* g_pStudioRender; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/item_selection_criteria.h b/SpyCustom/sdk/item_selection_criteria.h new file mode 100644 index 0000000..6636535 --- /dev/null +++ b/SpyCustom/sdk/item_selection_criteria.h @@ -0,0 +1,202 @@ +#ifndef ITEM_SELECTION_CRITERIA_H +#define ITEM_SELECTION_CRITERIA_H +#ifdef _WIN32 +#pragma once +#endif + +#include "game_item_schema.h" + +const int k_cchCreateItemLen = 64; + +enum EItemCriteriaOperator +{ + k_EOperator_String_EQ = 0, + k_EOperator_Not = 1, + k_EOperator_String_Not_EQ = 1, + k_EOperator_Float_EQ = 2, + k_EOperator_Float_Not_EQ = 3, + k_EOperator_Float_LT = 4, + k_EOperator_Float_Not_LT = 5, + k_EOperator_Float_LTE = 6, + k_EOperator_Float_Not_LTE = 7, + k_EOperator_Float_GT = 8, + k_EOperator_Float_Not_GT = 9, + k_EOperator_Float_GTE = 10, + k_EOperator_Float_Not_GTE = 11, + k_EOperator_Subkey_Contains = 12, + k_EOperator_Subkey_Not_Contains = 13, + + k_EItemCriteriaOperator_Count = 14, +}; + + +EItemCriteriaOperator EItemCriteriaOperatorFromName(const char* pch); +const char* PchNameFromEItemCriteriaOperator(int eItemCriteriaOperator); + +class CEconItemSchema; +class CEconItemDefinition; +class CEconItem; +class CSOItemCriteria; +class CSOItemCriteriaCondition; + +const uint8 k_unItemRarity_Any = 0xF; +const uint8 k_unItemQuality_Any = 0xF; + + +class CItemSelectionCriteria +{ +public: + CItemSelectionCriteria() : + m_bItemLevelSet(false), + m_unItemLevel(0), + m_bQualitySet(false), + m_nItemQuality(k_unItemQuality_Any), + m_bRaritySet(false), + m_nItemRarity(k_unItemRarity_Any), + m_unInitialInventory(0), + m_unInitialQuantity(1), + m_bForcedQualityMatch(false), + m_bIgnoreEnabledFlag(false), + m_bRecentOnly(false), + m_bIsLootList(false) + { + } + + CItemSelectionCriteria(const CItemSelectionCriteria& that); + CItemSelectionCriteria& operator=(const CItemSelectionCriteria& rhs); + ~CItemSelectionCriteria(); + + bool BItemLevelSet(void) const { return m_bItemLevelSet; } + uint32 GetItemLevel(void) const { Assert(m_bItemLevelSet); return m_unItemLevel; } + void SetItemLevel(uint32 unLevel) { m_unItemLevel = unLevel; m_bItemLevelSet = true; } + bool BQualitySet(void) const { return m_bQualitySet; } + int32 GetQuality(void) const { Assert(m_bQualitySet); return m_nItemQuality; } + void SetQuality(int32 nQuality) { m_nItemQuality = nQuality; m_bQualitySet = true; } + bool BRaritySet(void) const { return m_bRaritySet; } + int32 GetRarity(void) const { Assert(m_bRaritySet); return m_nItemRarity; } + void SetRarity(int32 nRarity) { m_nItemRarity = nRarity; m_bRaritySet = true; } + uint32 GetInitialInventory(void) const { return m_unInitialInventory; } + void SetInitialInventory(uint32 unInventory) { m_unInitialInventory = unInventory; } + uint32 GetInitialQuantity(void) const { return m_unInitialQuantity; } + void SetInitialQuantity(uint32 unQuantity) { m_unInitialQuantity = unQuantity; } + void SetExplicitQualityMatch(bool bExplicit) { m_bForcedQualityMatch = bExplicit; } + void SetIgnoreEnabledFlag(bool bIgnore) { m_bIgnoreEnabledFlag = bIgnore; } + void SetRecentOnly(bool bCheck) { m_bRecentOnly = bCheck; } + bool IsLootList(void) const { return m_bIsLootList; } + + bool BAddCondition(const char* pszField, EItemCriteriaOperator eOp, float flValue, bool bRequired); + bool BAddCondition(const char* pszField, EItemCriteriaOperator eOp, const char* pszValue, bool bRequired); + int GetConditionsCount() { return m_vecConditions.Count(); } + const char* GetValueForFirstConditionOfFieldName(const char* pchName) const; + + bool BInitFromKV(KeyValues* pKVCriteria, const CEconItemSchema& schemaa); + bool BInitFromItemAndPaint(int nItemDef, int nPaintID, const CEconItemSchema& schemaa); + + bool BSerializeToMsg(CSOItemCriteria& msg) const; + bool BDeserializeFromMsg(const CSOItemCriteria& msg); + + bool BEvaluate(const CEconItemDefinition* pItemDef, const CEconItemSchema& pschema) const; + bool BEvaluate(const CEconItem* pItem, const CEconItemSchema& pschema) const; + +private: + class CCondition + { + public: + CCondition(const char* pszField, EItemCriteriaOperator eOp, bool bRequired) + : m_sField(pszField), m_EOp(eOp), m_bRequired(bRequired) + { + } + + virtual ~CCondition() { } + + bool BEvaluate(KeyValues* pKVItem) const; + + virtual bool BSerializeToMsg(CSOItemCriteriaCondition& msg) const; + + EItemCriteriaOperator GetEOp(void) const { return m_EOp; } + virtual const char* GetField(void) { return m_sField.Get(); } + virtual const char* GetValue(void) { Assert(0); return NULL; } + + protected: + virtual bool BInternalEvaluate(KeyValues* pKVItem) const = 0; + + CUtlString m_sField; + EItemCriteriaOperator m_EOp; + bool m_bRequired; + }; + + + class CStringCondition : public CCondition + { + public: + CStringCondition(const char* pszField, EItemCriteriaOperator eOp, const char* pszValue, bool bRequired) + : CCondition(pszField, eOp, bRequired), m_sValue(pszValue) + { + } + + virtual ~CStringCondition() { } + + virtual const char* GetValue(void) { return m_sValue.Get(); } + + protected: + virtual bool BInternalEvaluate(KeyValues* pKVItem) const; + virtual bool BSerializeToMsg(CSOItemCriteriaCondition& msg) const; + + CUtlString m_sValue; + }; + + + class CFloatCondition : public CCondition + { + public: + CFloatCondition(const char* pszField, EItemCriteriaOperator eOp, float flValue, bool bRequired) + : CCondition(pszField, eOp, bRequired), m_flValue(flValue) + { + } + + virtual ~CFloatCondition() { } + + protected: + virtual bool BInternalEvaluate(KeyValues* pKVItem) const; + virtual bool BSerializeToMsg(CSOItemCriteriaCondition& msg) const; + + float m_flValue; + }; + + + class CSetCondition : public CCondition + { + public: + CSetCondition(const char* pszField, EItemCriteriaOperator eOp, const char* pszValue, bool bRequired) + : CCondition(pszField, eOp, bRequired), m_sValue(pszValue) + { + } + + virtual ~CSetCondition() { } + + protected: + virtual bool BInternalEvaluate(KeyValues* pKVItem) const; + + virtual bool BSerializeToMsg(CSOItemCriteriaCondition& msg) const; + + CUtlString m_sValue; + }; + + bool m_bItemLevelSet; + uint32 m_unItemLevel; + bool m_bQualitySet; + int32 m_nItemQuality; + bool m_bRaritySet; + int32 m_nItemRarity; + uint32 m_unInitialInventory; + uint32 m_unInitialQuantity; + bool m_bForcedQualityMatch; + bool m_bIgnoreEnabledFlag; + bool m_bRecentOnly; + bool m_bIsLootList; + + CUtlVector m_vecConditions; +}; + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/itempents.h b/SpyCustom/sdk/itempents.h new file mode 100644 index 0000000..1a6fbbb --- /dev/null +++ b/SpyCustom/sdk/itempents.h @@ -0,0 +1,118 @@ +#if !defined( ITEMPENTS_H ) +#define ITEMPENTS_H +#ifdef _WIN32 +#pragma once +#endif + +#include "ipredictionsystem.h" +#include "shattersurfacetypes.h" +#include "irecipientfilter.h" + +class CEffectData; +class KeyValues; + + +abstract_class ITempEntsSystem : public IPredictionSystem +{ +public: + virtual bool SuppressTE(IRecipientFilter & filter) = 0; + virtual void ArmorRicochet(IRecipientFilter& filer, float delay, + const Vector* pos, const Vector* dir) = 0; + virtual void BeamEntPoint(IRecipientFilter& filer, float delay, + int nStartEntity, const Vector* start, int nEndEntity, const Vector* end, + int modelindex, int haloindex, int startframe, int framerate, + float life, float width, float endWidth, int fadeLength, float amplitude, + int r, int g, int b, int a, int speed) = 0; + virtual void BeamEnts(IRecipientFilter& filer, float delay, + int start, int end, int modelindex, int haloindex, int startframe, int framerate, + float life, float width, float endWidth, int fadeLength, float amplitude, + int r, int g, int b, int a, int speed) = 0; + virtual void BeamFollow(IRecipientFilter& filter, float delay, + int iEntIndex, int modelIndex, int haloIndex, float life, float width, float endWidth, + float fadeLength, float r, float g, float b, float a) = 0; + virtual void BeamPoints(IRecipientFilter& filer, float delay, + const Vector* start, const Vector* end, int modelindex, int haloindex, int startframe, int framerate, + float life, float width, float endWidth, int fadeLength, float amplitude, + int r, int g, int b, int a, int speed) = 0; + virtual void BeamLaser(IRecipientFilter& filer, float delay, + int start, int end, int modelindex, int haloindex, int startframe, int framerate, + float life, float width, float endWidth, int fadeLength, float amplitude, int r, int g, int b, int a, int speed) = 0; + virtual void BeamRing(IRecipientFilter& filer, float delay, + int start, int end, int modelindex, int haloindex, int startframe, int framerate, + float life, float width, int spread, float amplitude, int r, int g, int b, int a, int speed, int flags = 0) = 0; + virtual void BeamRingPoint(IRecipientFilter& filer, float delay, + const Vector& center, float start_radius, float end_radius, int modelindex, int haloindex, int startframe, int framerate, + float life, float width, int spread, float amplitude, int r, int g, int b, int a, int speed, int flags = 0) = 0; + virtual void BeamSpline(IRecipientFilter& filer, float delay, + int points, Vector* rgPoints) = 0; + virtual void BloodStream(IRecipientFilter& filer, float delay, + const Vector* org, const Vector* dir, int r, int g, int b, int a, int amount) = 0; + virtual void BloodSprite(IRecipientFilter& filer, float delay, + const Vector* org, const Vector* dir, int r, int g, int b, int a, int size) = 0; + virtual void BreakModel(IRecipientFilter& filer, float delay, + const Vector& pos, const QAngle& angle, const Vector& size, const Vector& vel, + int modelindex, int randomization, int count, float time, int flags) = 0; + virtual void BSPDecal(IRecipientFilter& filer, float delay, + const Vector* pos, int entity, int index) = 0; + virtual void ProjectDecal(IRecipientFilter& filter, float delay, + const Vector* pos, const QAngle* angles, float distance, int index) = 0; + virtual void Bubbles(IRecipientFilter& filer, float delay, + const Vector* mins, const Vector* maxs, float height, int modelindex, int count, float speed) = 0; + virtual void BubbleTrail(IRecipientFilter& filer, float delay, + const Vector* mins, const Vector* maxs, float height, int modelindex, int count, float speed) = 0; + virtual void Decal(IRecipientFilter& filer, float delay, + const Vector* pos, const Vector* start, int entity, int hitbox, int index) = 0; + virtual void DynamicLight(IRecipientFilter& filer, float delay, + const Vector* org, int r, int g, int b, int exponent, float radius, float time, float decay) = 0; + virtual void Explosion(IRecipientFilter& filer, float delay, + const Vector* pos, int modelindex, float scale, int framerate, int flags, int radius, int magnitude, const Vector* normal = NULL, unsigned char materialType = 'C') = 0; + virtual void ShatterSurface(IRecipientFilter& filer, float delay, + const Vector* pos, const QAngle* angle, const Vector* vForce, const Vector* vForcePos, + float width, float height, float shardsize, ShatterSurface_t surfacetype, + int front_r, int front_g, int front_b, int back_r, int back_g, int back_b) = 0; + virtual void GlowSprite(IRecipientFilter& filer, float delay, + const Vector* pos, int modelindex, float life, float size, int brightness) = 0; + virtual void FootprintDecal(IRecipientFilter& filer, float delay, const Vector* origin, const Vector* right, + int entity, int index, unsigned char materialType) = 0; + virtual void Fizz(IRecipientFilter& filer, float delay, + const CBaseEntity* ed, int modelindex, int density, int current) = 0; + virtual void KillPlayerAttachments(IRecipientFilter& filer, float delay, + int player) = 0; + virtual void LargeFunnel(IRecipientFilter& filer, float delay, + const Vector* pos, int modelindex, int reversed) = 0; + virtual void MetalSparks(IRecipientFilter& filer, float delay, + const Vector* pos, const Vector* dir) = 0; + virtual void EnergySplash(IRecipientFilter& filer, float delay, + const Vector* pos, const Vector* dir, bool bExplosive) = 0; + virtual void PlayerDecal(IRecipientFilter& filer, float delay, + const Vector* pos, int player, int entity) = 0; + virtual void ShowLine(IRecipientFilter& filer, float delay, + const Vector* start, const Vector* end) = 0; + virtual void Smoke(IRecipientFilter& filer, float delay, + const Vector* pos, int modelindex, float scale, int framerate) = 0; + virtual void Sparks(IRecipientFilter& filer, float delay, + const Vector* pos, int nMagnitude, int nTrailLength, const Vector* pDir) = 0; + virtual void Sprite(IRecipientFilter& filer, float delay, + const Vector* pos, int modelindex, float size, int brightness) = 0; + virtual void SpriteSpray(IRecipientFilter& filer, float delay, + const Vector* pos, const Vector* dir, int modelindex, int speed, float noise, int count) = 0; + virtual void WorldDecal(IRecipientFilter& filer, float delay, + const Vector* pos, int index) = 0; + virtual void MuzzleFlash(IRecipientFilter& filer, float delay, + const Vector& start, const QAngle& angles, float scale, int type) = 0; + virtual void Dust(IRecipientFilter& filer, float delay, + const Vector& pos, const Vector& dir, float size, float speed) = 0; + virtual void GaussExplosion(IRecipientFilter& filer, float delay, + const Vector& pos, const Vector& dir, int type) = 0; + virtual void PhysicsProp(IRecipientFilter& filter, float delay, int modelindex, int skin, + const Vector& pos, const QAngle& angles, const Vector& vel, int flags, int effects) = 0; + + virtual void TriggerTempEntity(KeyValues* pKeyValues) = 0; + + virtual void ClientProjectile(IRecipientFilter& filter, float delay, + const Vector* vecOrigin, const Vector* vecVelocity, int modelindex, int lifetime, CBaseEntity* pOwner) = 0; +}; + +extern ITempEntsSystem* te; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/itexture.h b/SpyCustom/sdk/itexture.h new file mode 100644 index 0000000..891de98 --- /dev/null +++ b/SpyCustom/sdk/itexture.h @@ -0,0 +1,93 @@ +#ifndef ITEXTURE_H +#define ITEXTURE_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "platform.h" +#include "imageformat.h" + +class IVTFTexture; +class ITexture; +struct Rect_t; + +abstract_class ITextureRegenerator +{ +public: + virtual void RegenerateTextureBits(ITexture * pTexture, IVTFTexture * pVTFTexture, Rect_t * pRect) = 0; + + virtual void Release() = 0; + +}; + +abstract_class ITexture +{ +public: + virtual const char* GetName(void) const = 0; + virtual int GetMappingWidth() const = 0; + virtual int GetMappingHeight() const = 0; + virtual int GetActualWidth() const = 0; + virtual int GetActualHeight() const = 0; + virtual int GetNumAnimationFrames() const = 0; + virtual bool IsTranslucent() const = 0; + virtual bool IsMipmapped() const = 0; + + virtual void GetLowResColorSample(float s, float t, float* color) const = 0; + + virtual void* GetResourceData(uint32 eDataType, size_t* pNumBytes) const = 0; + + virtual void IncrementReferenceCount(void) = 0; + virtual void DecrementReferenceCount(void) = 0; + + inline void AddRef() { IncrementReferenceCount(); } + inline void Release() { DecrementReferenceCount(); } + + virtual void SetTextureRegenerator(ITextureRegenerator* pTextureRegen) = 0; + + virtual void Download(Rect_t* pRect = 0, int nAdditionalCreationFlags = 0) = 0; + + virtual int GetApproximateVidMemBytes(void) const = 0; + + virtual bool IsError() const = 0; + + virtual bool IsVolumeTexture() const = 0; + virtual int GetMappingDepth() const = 0; + virtual int GetActualDepth() const = 0; + + virtual ImageFormat GetImageFormat() const = 0; + virtual NormalDecodeMode_t GetNormalDecodeMode() const = 0; + + virtual bool IsRenderTarget() const = 0; + virtual bool IsCubeMap() const = 0; + virtual bool IsNormalMap() const = 0; + virtual bool IsProcedural() const = 0; + + virtual void DeleteIfUnreferenced() = 0; + +#if defined( _X360 ) + virtual bool ClearTexture(int r, int g, int b, int a) = 0; + virtual bool CreateRenderTargetSurface(int width, int height, ImageFormat format, bool bSameAsTexture) = 0; +#endif + + virtual void SwapContents(ITexture* pOther) = 0; + + virtual unsigned int GetFlags(void) const = 0; + + virtual void ForceLODOverride(int iNumLodsOverrideUpOrDown) = 0; + + virtual bool SaveToFile(const char* fileName) = 0; + + virtual void CopyToStagingTexture(ITexture* pDstTex) = 0; + + virtual void SetErrorTexture(bool bIsErrorTexture) = 0; +}; + + +inline bool IsErrorTexture(ITexture* pTex) +{ + return !pTex || pTex->IsError(); +} + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/itoolentity.h b/SpyCustom/sdk/itoolentity.h new file mode 100644 index 0000000..26f6b32 --- /dev/null +++ b/SpyCustom/sdk/itoolentity.h @@ -0,0 +1,190 @@ +#ifndef ITOOLENTITY_H +#define ITOOLENTITY_H +#ifdef _WIN32 +#pragma once +#endif + +#include "interface.h" +#include "utlvector.h" +#include "Color.h" +#include "basehandle.h" +#include "iclientrenderable.h" +#include "ishadowmgr.h" + + +class IServerEntity; +class IClientEntity; +class IToolSystem; +class IClientRenderable; +class Vector; +class QAngle; +class CBaseEntity; +class CBaseAnimating; +class CTakeDamageInfo; +class ITempEntsSystem; +class IEntityFactoryDictionary; + + +typedef unsigned int HTOOLHANDLE; +enum +{ + HTOOLHANDLE_INVALID = 0 +}; + + +enum ClientShadowFlags_t +{ + SHADOW_FLAGS_USE_RENDER_TO_TEXTURE = (SHADOW_FLAGS_LAST_FLAG << 1), + SHADOW_FLAGS_ANIMATING_SOURCE = (SHADOW_FLAGS_LAST_FLAG << 2), + SHADOW_FLAGS_USE_DEPTH_TEXTURE = (SHADOW_FLAGS_LAST_FLAG << 3), + CLIENT_SHADOW_FLAGS_LAST_FLAG = SHADOW_FLAGS_USE_DEPTH_TEXTURE +}; + + +typedef void* EntitySearchResult; + + +class IClientTools : public IBaseInterface +{ +public: + virtual HTOOLHANDLE AttachToEntity(EntitySearchResult entityToAttach) = 0; + virtual void DetachFromEntity(EntitySearchResult entityToDetach) = 0; + + virtual bool IsValidHandle(HTOOLHANDLE handle) = 0; + + virtual int GetNumRecordables() = 0; + virtual HTOOLHANDLE GetRecordable(int index) = 0; + + virtual EntitySearchResult NextEntity(EntitySearchResult currentEnt) = 0; + EntitySearchResult FirstEntity() { return NextEntity(NULL); } + + virtual void SetEnabled(HTOOLHANDLE handle, bool enabled) = 0; + virtual void SetRecording(HTOOLHANDLE handle, bool recording) = 0; + virtual bool ShouldRecord(HTOOLHANDLE handle) = 0; + + virtual HTOOLHANDLE GetToolHandleForEntityByIndex(int entindex) = 0; + + virtual int GetModelIndex(HTOOLHANDLE handle) = 0; + virtual const char* GetModelName(HTOOLHANDLE handle) = 0; + virtual const char* GetClassname(HTOOLHANDLE handle) = 0; + + virtual void AddClientRenderable(IClientRenderable* pRenderable, int renderGroup) = 0; + virtual void RemoveClientRenderable(IClientRenderable* pRenderable) = 0; + virtual void SetRenderGroup(IClientRenderable* pRenderable, int renderGroup) = 0; + virtual void MarkClientRenderableDirty(IClientRenderable* pRenderable) = 0; + virtual void UpdateProjectedTexture(ClientShadowHandle_t h, bool bForce) = 0; + + virtual bool DrawSprite(IClientRenderable* pRenderable, float scale, float frame, int rendermode, int renderfx, const Color& color, float flProxyRadius, int* pVisHandle) = 0; + + virtual EntitySearchResult GetLocalPlayer() = 0; + virtual bool GetLocalPlayerEyePosition(Vector& org, QAngle& ang, float& fov) = 0; + + virtual ClientShadowHandle_t CreateShadow(CBaseHandle handle, int nFlags) = 0; + virtual void DestroyShadow(ClientShadowHandle_t h) = 0; + + virtual ClientShadowHandle_t CreateFlashlight(const FlashlightState_t& lightState) = 0; + virtual void DestroyFlashlight(ClientShadowHandle_t h) = 0; + virtual void UpdateFlashlightState(ClientShadowHandle_t h, const FlashlightState_t& lightState) = 0; + + virtual void AddToDirtyShadowList(ClientShadowHandle_t h, bool force = false) = 0; + virtual void MarkRenderToTextureShadowDirty(ClientShadowHandle_t h) = 0; + + virtual void EnableRecordingMode(bool bEnable) = 0; + virtual bool IsInRecordingMode() const = 0; + + virtual void TriggerTempEntity(KeyValues* pKeyValues) = 0; + + virtual int GetOwningWeaponEntIndex(int entindex) = 0; + virtual int GetEntIndex(EntitySearchResult entityToAttach) = 0; + + virtual int FindGlobalFlexcontroller(char const* name) = 0; + virtual char const* GetGlobalFlexControllerName(int idx) = 0; + + virtual EntitySearchResult GetOwnerEntity(EntitySearchResult currentEnt) = 0; + + virtual bool IsPlayer(EntitySearchResult currentEnt) = 0; + virtual bool IsBaseCombatCharacter(EntitySearchResult currentEnt) = 0; + virtual bool IsNPC(EntitySearchResult currentEnt) = 0; + + virtual Vector GetAbsOrigin(HTOOLHANDLE handle) = 0; + virtual QAngle GetAbsAngles(HTOOLHANDLE handle) = 0; + + virtual void ReloadParticleDefintions(const char* pFileName, const void* pBufData, int nLen) = 0; + + virtual void PostToolMessage(KeyValues* pKeyValues) = 0; + + virtual void EnableParticleSystems(bool bEnable) = 0; + + virtual bool IsRenderingThirdPerson() const = 0; +}; + +#define VCLIENTTOOLS_INTERFACE_VERSION "VCLIENTTOOLS001" + + +class IServerTools : public IBaseInterface +{ +public: + virtual IServerEntity* GetIServerEntity(IClientEntity* pClientEntity) = 0; + virtual bool SnapPlayerToPosition(const Vector& org, const QAngle& ang, IClientEntity* pClientPlayer = NULL) = 0; + virtual bool GetPlayerPosition(Vector& org, QAngle& ang, IClientEntity* pClientPlayer = NULL) = 0; + virtual bool SetPlayerFOV(int fov, IClientEntity* pClientPlayer = NULL) = 0; + virtual int GetPlayerFOV(IClientEntity* pClientPlayer = NULL) = 0; + virtual bool IsInNoClipMode(IClientEntity* pClientPlayer = NULL) = 0; + + virtual CBaseEntity* FirstEntity(void) = 0; + virtual CBaseEntity* NextEntity(CBaseEntity* pEntity) = 0; + virtual CBaseEntity* FindEntityByHammerID(int iHammerID) = 0; + + virtual bool GetKeyValue(CBaseEntity* pEntity, const char* szField, char* szValue, int iMaxLen) = 0; + virtual bool SetKeyValue(CBaseEntity* pEntity, const char* szField, const char* szValue) = 0; + virtual bool SetKeyValue(CBaseEntity* pEntity, const char* szField, float flValue) = 0; + virtual bool SetKeyValue(CBaseEntity* pEntity, const char* szField, const Vector& vecValue) = 0; + + virtual CBaseEntity* CreateEntityByName(const char* szClassName) = 0; + virtual void DispatchSpawn(CBaseEntity* pEntity) = 0; + + virtual void ReloadParticleDefintions(const char* pFileName, const void* pBufData, int nLen) = 0; + + virtual void AddOriginToPVS(const Vector& org) = 0; + virtual void MoveEngineViewTo(const Vector& vPos, const QAngle& vAngles) = 0; + + virtual bool DestroyEntityByHammerId(int iHammerID) = 0; + virtual CBaseEntity* GetBaseEntityByEntIndex(int iEntIndex) = 0; + virtual void RemoveEntity(CBaseEntity* pEntity) = 0; + virtual void RemoveEntityImmediate(CBaseEntity* pEntity) = 0; + virtual IEntityFactoryDictionary* GetEntityFactoryDictionary(void) = 0; + + virtual void SetMoveType(CBaseEntity* pEntity, int val) = 0; + virtual void SetMoveType(CBaseEntity* pEntity, int val, int moveCollide) = 0; + virtual void ResetSequence(CBaseAnimating* pEntity, int nSequence) = 0; + virtual void ResetSequenceInfo(CBaseAnimating* pEntity) = 0; + + virtual void ClearMultiDamage(void) = 0; + virtual void ApplyMultiDamage(void) = 0; + virtual void AddMultiDamage(const CTakeDamageInfo& pTakeDamageInfo, CBaseEntity* pEntity) = 0; + virtual void RadiusDamage(const CTakeDamageInfo& info, const Vector& vecSrc, float flRadius, int iClassIgnore, CBaseEntity* pEntityIgnore) = 0; + + virtual ITempEntsSystem* GetTempEntsSystem(void) = 0; +}; + +typedef IServerTools IServerTools001; + +#define VSERVERTOOLS_INTERFACE_VERSION_1 "VSERVERTOOLS001" +#define VSERVERTOOLS_INTERFACE_VERSION "VSERVERTOOLS002" +#define VSERVERTOOLS_INTERFACE_VERSION_INT 2 + +class IServerChoreoTools : public IBaseInterface +{ +public: + + virtual EntitySearchResult NextChoreoEntity(EntitySearchResult currentEnt) = 0; + EntitySearchResult FirstChoreoEntity() { return NextChoreoEntity(NULL); } + virtual const char* GetSceneFile(EntitySearchResult sr) = 0; + + virtual int GetEntIndex(EntitySearchResult sr) = 0; + virtual void ReloadSceneFromDisk(int entindex) = 0; +}; + +#define VSERVERCHOREOTOOLS_INTERFACE_VERSION "VSERVERCHOREOTOOLS001" + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/ivdebugoverlay.h b/SpyCustom/sdk/ivdebugoverlay.h new file mode 100644 index 0000000..e1253af --- /dev/null +++ b/SpyCustom/sdk/ivdebugoverlay.h @@ -0,0 +1,44 @@ +#ifndef IVDEBUGOVERLAY_H +#define IVDEBUGOVERLAY_H + +#ifdef _WIN32 +#pragma once +#endif + +class Vector; + +#define VDEBUG_OVERLAY_INTERFACE_VERSION "VDebugOverlay003" + +#define NDEBUG_PERSIST_TILL_NEXT_SERVER (0.0f) + +class OverlayText_t; + +abstract_class IVDebugOverlay +{ +public: + virtual void __unkn() = 0; + virtual void AddEntityTextOverlay(int ent_index, int line_offset, float duration, int r, int g, int b, int a, const char* format, ...) = 0; + virtual void AddBoxOverlay(const Vector& origin, const Vector& mins, const Vector& max, Vector const& orientation, int r, int g, int b, int a, float duration) = 0; + virtual void AddSphereOverlay(const Vector& vOrigin, float flRadius, int nTheta, int nPhi, int r, int g, int b, int a, float flDuration) = 0; + virtual void AddTriangleOverlay(const Vector& p1, const Vector& p2, const Vector& p3, int r, int g, int b, int a, bool noDepthTest, float duration) = 0; + virtual void AddLineOverlay(const Vector& origin, const Vector& dest, int r, int g, int b, bool noDepthTest, float duration) = 0; + virtual void AddTextOverlay(const Vector& origin, float duration, const char* format, ...) = 0; + virtual void AddTextOverlay(const Vector& origin, int line_offset, float duration, const char* format, ...) = 0; + virtual void AddScreenTextOverlay(float flXPos, float flYPos, float flDuration, int r, int g, int b, int a, const char* text) = 0; + virtual void AddSweptBoxOverlay(const Vector& start, const Vector& end, const Vector& mins, const Vector& max, const QAngle& angles, int r, int g, int b, int a, float flDuration) = 0; + virtual void AddGridOverlay(const Vector& origin) = 0; + virtual void AddCoordFrameOverlay(const matrix3x4_t& frame, float flScale, int vColorTable[3][3] = NULL) = 0; + virtual int ScreenPosition(const Vector& point, Vector& screen) = 0; + virtual int ScreenPosition(float flXPos, float flYPos, Vector& screen) = 0; + virtual OverlayText_t* GetFirst(void) = 0; + virtual OverlayText_t* GetNext(OverlayText_t* current) = 0; + virtual void ClearDeadOverlays(void) = 0; + virtual void ClearAllOverlays() = 0; + virtual void AddTextOverlayRGB(const Vector& origin, int line_offset, float duration, float r, float g, float b, float alpha, const char* format, ...) = 0; + virtual void AddTextOverlayRGB(const Vector& origin, int line_offset, float duration, int r, int g, int b, int a, const char* format, ...) = 0; + virtual void AddLineOverlayAlpha(const Vector& origin, const Vector& dest, int r, int g, int b, int a, bool noDepthTest, float duration) = 0; + virtual void AddBoxOverlay2(const Vector& origin, const Vector& mins, const Vector& max, QAngle const& orientation, const Color& faceColor, const Color& edgeColor, float duration) = 0; + virtual void PurgeTextOverlays() = 0; + virtual void DrawPill(const Vector& mins, const Vector& max, float& diameter, int r, int g, int b, int a, float duration) = 0; +}; +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/iviewrender.h b/SpyCustom/sdk/iviewrender.h new file mode 100644 index 0000000..505f8dc --- /dev/null +++ b/SpyCustom/sdk/iviewrender.h @@ -0,0 +1,125 @@ +#if !defined( IVIEWRENDER_H ) +#define IVIEWRENDER_H +#ifdef _WIN32 +#pragma once +#endif + + +#include "ivrenderview.h" + + +#define MAX_DEPTH_TEXTURE_SHADOWS 1 +#define MAX_DEPTH_TEXTURE_HIGHRES_SHADOWS 0 + +#define MAX_DEPTH_TEXTURE_SHADOWS_TOOLS 8 +#define MAX_DEPTH_TEXTURE_HIGHRES_SHADOWS_TOOLS 0 + + +enum DrawFlags_t +{ + DF_RENDER_REFRACTION = 0x1, + DF_RENDER_REFLECTION = 0x2, + + DF_CLIP_Z = 0x4, + DF_CLIP_BELOW = 0x8, + + DF_RENDER_UNDERWATER = 0x10, + DF_RENDER_ABOVEWATER = 0x20, + DF_RENDER_WATER = 0x40, + + DF_SSAO_DEPTH_PASS = 0x80, + + DF_RENDER_PSEUDO_TRANSLUCENT_WATER = 0x100, + DF_WATERHEIGHT = 0x200, + DF_DRAW_SSAO = 0x400, + DF_DRAWSKYBOX = 0x800, + + DF_FUDGE_UP = 0x1000, + + DF_DRAW_ENTITITES = 0x2000, + + DF_SKIP_WORLD = 0x4000, + DF_SKIP_WORLD_DECALS_AND_OVERLAYS = 0x8000, + + DF_UNUSED5 = 0x10000, + DF_SAVEGAMESCREENSHOT = 0x20000, + DF_CLIP_SKYBOX = 0x40000, + + DF_DRAW_SIMPLE_WORLD_MODEL = 0x80000, + + DF_SHADOW_DEPTH_MAP = 0x100000, + + DF_FAST_ENTITY_RENDERING = 0x200000, + DF_DRAW_SIMPLE_WORLD_MODEL_WATER = 0x400000, +}; + +class CViewSetup; +class C_BaseEntity; +struct vrect_t; +class C_BaseViewModel; + +abstract_class IViewRender +{ +public: + virtual void Init(void) = 0; + + virtual void LevelInit(void) = 0; + virtual void LevelShutdown(void) = 0; + + virtual void Shutdown(void) = 0; + + virtual void OnRenderStart() = 0; + + virtual void Render(vrect_t* rect) = 0; + + virtual void RenderView(const CViewSetup& view, const CViewSetup& hudViewSetup, int nClearFlags, int whatToDraw) = 0; + + virtual int GetDrawFlags() = 0; + + virtual void StartPitchDrift(void) = 0; + virtual void StopPitchDrift(void) = 0; + + virtual VPlane* GetFrustum() = 0; + + virtual bool ShouldDrawBrushModels(void) = 0; + + virtual const CViewSetup* GetPlayerViewSetup(int nSlot = -1) const = 0; + virtual const CViewSetup* GetViewSetup(void) const = 0; + + virtual void DisableVis(void) = 0; + + virtual int BuildWorldListsNumber() const = 0; + + virtual void SetCheapWaterStartDistance(float flCheapWaterStartDistance) = 0; + virtual void SetCheapWaterEndDistance(float flCheapWaterEndDistance) = 0; + + virtual void GetWaterLODParams(float& flCheapWaterStartDistance, float& flCheapWaterEndDistance) = 0; + + virtual void DriftPitch(void) = 0; + + virtual void SetScreenOverlayMaterial(IMaterial* pMaterial) = 0; + virtual IMaterial* GetScreenOverlayMaterial() = 0; + + virtual void WriteSaveGameScreenshot(const char* pFilename) = 0; + virtual void WriteSaveGameScreenshotOfSize(const char* pFilename, int width, int height) = 0; + + virtual void QueueOverlayRenderView(const CViewSetup& view, int nClearFlags, int whatToDraw) = 0; + + virtual float GetZNear() = 0; + virtual float GetZFar() = 0; + + virtual void GetScreenFadeDistances(float* pMin, float* pMax, float* pScale) = 0; + + virtual C_BaseEntity* GetCurrentlyDrawingEntity() = 0; + virtual void SetCurrentlyDrawingEntity(C_BaseEntity* pEnt) = 0; + + virtual bool UpdateShadowDepthTexture(ITexture* pRenderTarget, ITexture* pDepthTexture, const CViewSetup& shadowView, bool bRenderWorldAndObjects = true, bool bRenderViewModels = false) = 0; + + virtual void FreezeFrame(float flFreezeTime) = 0; + + virtual void InitFadeData(void) = 0; +}; + +extern IViewRender* view; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/iviewrender_beams.h b/SpyCustom/sdk/iviewrender_beams.h new file mode 100644 index 0000000..73f17a2 --- /dev/null +++ b/SpyCustom/sdk/iviewrender_beams.h @@ -0,0 +1,144 @@ +#if !defined( IVIEWRENDER_BEAMS_H ) +#define IVIEWRENDER_BEAMS_H +#ifdef _WIN32 +#pragma once +#endif + +#include "vector.h" +#include "beam_flags.h" +#include "tempentity.h" + +extern void SetBeamCreationAllowed(bool state); +extern bool BeamCreationAllowed(void); + + +class C_Beam; +class Beam_t; + +struct BeamTrail_t +{ + BeamTrail_t* next; + float die; + Vector org; + Vector vel; +}; + +struct BeamInfo_t +{ + int m_nType; + + C_BaseEntity* m_pStartEnt; + int m_nStartAttachment; + C_BaseEntity* m_pEndEnt; + int m_nEndAttachment; + + Vector m_vecStart; + Vector m_vecEnd; + + int m_nModelIndex; + const char* m_pszModelName; + + int m_nHaloIndex; + const char* m_pszHaloName; + float m_flHaloScale; + + float m_flLife; + float m_flWidth; + float m_flEndWidth; + float m_flFadeLength; + float m_flAmplitude; + + float m_flBrightness; + float m_flSpeed; + + int m_nStartFrame; + float m_flFrameRate; + + float m_flRed; + float m_flGreen; + float m_flBlue; + + bool m_bRenderable; + + int m_nSegments; + + int m_nFlags; + + Vector m_vecCenter; + float m_flStartRadius; + float m_flEndRadius; + + BeamInfo_t() + { + m_nType = TE_BEAMPOINTS; + m_nSegments = -1; + m_pszModelName = NULL; + m_pszHaloName = NULL; + m_nModelIndex = -1; + m_nHaloIndex = -1; + m_bRenderable = true; + m_nFlags = 0; + } +}; + + +abstract_class IViewRenderBeams +{ +public: +public: +public: + virtual void InitBeams(void) = 0; + virtual void ShutdownBeams(void) = 0; + virtual void ClearBeams(void) = 0; + + virtual void UpdateTempEntBeams() = 0; + + + virtual void DrawBeam(C_Beam* pbeam, ITraceFilter* pEntityBeamTraceFilter = NULL) = 0; + virtual void DrawBeam(Beam_t* pbeam) = 0; + + + virtual void KillDeadBeams(CBaseEntity* pEnt) = 0; + + virtual Beam_t* CreateBeamEnts(BeamInfo_t& beamInfo) = 0; + virtual Beam_t* CreateBeamEntPoint(BeamInfo_t& beamInfo) = 0; + virtual Beam_t* CreateBeamPoints(BeamInfo_t& beamInfo) = 0; + virtual Beam_t* CreateBeamRing(BeamInfo_t& beamInfo) = 0; + virtual Beam_t* CreateBeamRingPoint(BeamInfo_t& beamInfo) = 0; + virtual Beam_t* CreateBeamCirclePoints(BeamInfo_t& beamInfo) = 0; + virtual Beam_t* CreateBeamFollow(BeamInfo_t& beamInfo) = 0; + + virtual void FreeBeam(Beam_t* pBeam) = 0; + virtual void UpdateBeamInfo(Beam_t* pBeam, BeamInfo_t& beamInfo) = 0; + + virtual void CreateBeamEnts(int startEnt, int endEnt, int modelIndex, int haloIndex, float haloScale, + float life, float width, float m_nEndWidth, float m_nFadeLength, float amplitude, + float brightness, float speed, int startFrame, + float framerate, float r, float g, float b, int type = -1) = 0; + virtual void CreateBeamEntPoint(int nStartEntity, const Vector* pStart, int nEndEntity, const Vector* pEnd, + int modelIndex, int haloIndex, float haloScale, + float life, float width, float m_nEndWidth, float m_nFadeLength, float amplitude, + float brightness, float speed, int startFrame, + float framerate, float r, float g, float b) = 0; + virtual void CreateBeamPoints(Vector& start, Vector& end, int modelIndex, int haloIndex, float haloScale, + float life, float width, float m_nEndWidth, float m_nFadeLength, float amplitude, + float brightness, float speed, int startFrame, + float framerate, float r, float g, float b) = 0; + virtual void CreateBeamRing(int startEnt, int endEnt, int modelIndex, int haloIndex, float haloScale, + float life, float width, float m_nEndWidth, float m_nFadeLength, float amplitude, + float brightness, float speed, int startFrame, + float framerate, float r, float g, float b, int flags = 0) = 0; + virtual void CreateBeamRingPoint(const Vector& center, float start_radius, float end_radius, int modelIndex, int haloIndex, float haloScale, + float life, float width, float m_nEndWidth, float m_nFadeLength, float amplitude, + float brightness, float speed, int startFrame, + float framerate, float r, float g, float b, int flags = 0) = 0; + virtual void CreateBeamCirclePoints(int type, Vector& start, Vector& end, + int modelIndex, int haloIndex, float haloScale, float life, float width, + float m_nEndWidth, float m_nFadeLength, float amplitude, float brightness, float speed, + int startFrame, float framerate, float r, float g, float b) = 0; + virtual void CreateBeamFollow(int startEnt, int modelIndex, int haloIndex, float haloScale, + float life, float width, float m_nEndWidth, float m_nFadeLength, float r, float g, float b, + float brightness) = 0; +}; + +#endif diff --git a/SpyCustom/sdk/ivmodelinfo.h b/SpyCustom/sdk/ivmodelinfo.h new file mode 100644 index 0000000..f1f236a --- /dev/null +++ b/SpyCustom/sdk/ivmodelinfo.h @@ -0,0 +1,152 @@ +#ifndef IVMODELINFO_H +#define IVMODELINFO_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "platform.h" +#include "dbg.h" + +class IMaterial; +class KeyValues; +struct vcollide_t; +struct model_t; +class Vector; +class QAngle; +class CGameTrace; +struct cplane_t; +typedef CGameTrace trace_t; +struct studiohdr_t; +struct virtualmodel_t; +typedef unsigned char byte; +struct virtualterrainparams_t; +class CPhysCollide; +typedef unsigned short MDLHandle_t; +class CUtlBuffer; +class IClientRenderable; + +class CStudioHdr; +enum RenderableTranslucencyType_t +{ + RENDERABLE_IS_OPAQUE = 0, + RENDERABLE_IS_TRANSLUCENT, + RENDERABLE_IS_TWO_PASS, +}; + +abstract_class IModelLoadCallback +{ +public: + virtual void OnModelLoadComplete(const model_t * pModel) = 0; + +protected: + ~IModelLoadCallback(); +}; + + +class CRefCountedModelIndex +{ +private: + int m_nIndex; +public: + CRefCountedModelIndex() : m_nIndex(-1) { } + ~CRefCountedModelIndex() { Set(-1); } + + CRefCountedModelIndex(const CRefCountedModelIndex& src) : m_nIndex(-1) { Set(src.m_nIndex); } + CRefCountedModelIndex& operator=(const CRefCountedModelIndex& src) { Set(src.m_nIndex); return *this; } + + explicit CRefCountedModelIndex(int i) : m_nIndex(-1) { Set(i); } + CRefCountedModelIndex& operator=(int i) { Set(i); return *this; } + + int Get() const { return m_nIndex; } + void Set(int i); + void Clear() { Set(-1); } + + operator int() const { return m_nIndex; } +}; + + +#define VMODELINFO_CLIENT_INTERFACE_VERSION "VModelInfoClient006" +#define VMODELINFO_SERVER_INTERFACE_VERSION_3 "VModelInfoServer003" +#define VMODELINFO_SERVER_INTERFACE_VERSION "VModelInfoServer004" + +inline bool IsDynamicModelIndex(int modelindex) { return modelindex < -1; } +inline bool IsClientOnlyModelIndex(int modelindex) { return modelindex < -1 && (modelindex & 1); } + + +class IVModelInfo +{ +public: + virtual ~IVModelInfo(void) {} + virtual const model_t* GetModel(int modelindex) const = 0; + virtual int GetModelIndex(const char* name) const = 0; + virtual const char* GetModelName(const model_t* model) const = 0; + virtual vcollide_t* GetVCollide(const model_t* model) const = 0; + virtual vcollide_t* GetVCollide(int modelindex) const = 0; + virtual void GetModelBounds(const model_t* model, Vector& mins, Vector& maxs) const = 0; + virtual void GetModelRenderBounds(const model_t* model, Vector& mins, Vector& maxs) const = 0; + virtual int GetModelFrameCount(const model_t* model) const = 0; + virtual int GetModelType(const model_t* model) const = 0; + virtual void* GetModelExtraData(const model_t* model) = 0; + virtual bool ModelHasMaterialProxy(const model_t* model) const = 0; + virtual bool IsTranslucent(model_t const* model) const = 0; + virtual bool IsTranslucentTwoPass(const model_t* model) const = 0; + virtual void Unused0() {}; + virtual void UNUSED() = 0; + virtual void UNUSE11D() = 0; + virtual RenderableTranslucencyType_t ComputeTranslucencyType(const model_t* model, int nSkin, int nBody) = 0; + virtual int GetModelMaterialCount(const model_t* model) const = 0; + virtual void GetModelMaterials(const model_t* model, int count, IMaterial** ppMaterial) = 0; + virtual bool IsModelVertexLit(const model_t* model) const = 0; + virtual const char* GetModelKeyValueText(const model_t* model) = 0; + virtual bool GetModelKeyValue(const model_t* model, CUtlBuffer& buf) = 0; + virtual float GetModelRadius(const model_t* model) = 0; + virtual CStudioHdr* GetStudioHdr(MDLHandle_t handle) = 0; + virtual const studiohdr_t* FindModel(const studiohdr_t* pStudioHdr, void** cache, const char* modelname) const = 0; + virtual const studiohdr_t* FindModel(void* cache) const = 0; + virtual virtualmodel_t* GetVirtualModel(const studiohdr_t* pStudioHdr) const = 0; + virtual uint8_t* GetAnimBlock(const studiohdr_t* pStudioHdr, int iBlock) const = 0; + virtual void GetModelMaterialColorAndLighting(const model_t* model, Vector const& origin, QAngle const& angles, trace_t* pTrace, Vector& lighting, Vector& matColor) = 0; + virtual void GetIlluminationPoint(const model_t* model, IClientRenderable* pRenderable, Vector const& origin, QAngle const& angles, Vector* pLightingCenter) = 0; + virtual int GetModelContents(int modelIndex) const = 0; + virtual studiohdr_t* GetStudiomodel(const model_t* mod) = 0; + virtual int GetModelSpriteWidth(const model_t* model) const = 0; + virtual int GetModelSpriteHeight(const model_t* model) const = 0; + virtual void SetLevelScreenFadeRange(float flMinSize, float flMaxSize) = 0; + virtual void GetLevelScreenFadeRange(float* pMinArea, float* pMaxArea) const = 0; + virtual void SetViewScreenFadeRange(float flMinSize, float flMaxSize) = 0; + virtual unsigned char ComputeLevelScreenFade(const Vector& vecAbsOrigin, float flRadius, float flFadeScale) const = 0; + virtual unsigned char ComputeViewScreenFade(const Vector& vecAbsOrigin, float flRadius, float flFadeScale) const = 0; + virtual int GetAutoplayList(const studiohdr_t* pStudioHdr, unsigned short** pAutoplayList) const = 0; + virtual CPhysCollide* GetCollideForVirtualTerrain(int index) = 0; + virtual bool IsUsingFBTexture(const model_t* model, int nSkin, int nBody, IClientRenderable** pClientRenderable) const = 0; + virtual const model_t* FindOrLoadModel(const char* name) const = 0; + virtual MDLHandle_t GetCacheHandle(const model_t* model) const = 0; + virtual int GetBrushModelPlaneCount(const model_t* model) const = 0; + virtual void GetBrushModelPlane(const model_t* model, int nIndex, cplane_t& plane, Vector* pOrigin) const = 0; + virtual int GetSurfacepropsForVirtualTerrain(int index) = 0; + virtual bool UsesEnvCubemap(const model_t* model) const = 0; + virtual bool UsesStaticLighting(const model_t* model) const = 0; +}; + +typedef IVModelInfo IVModelInfo003; + + +abstract_class IVModelInfoClient : public IVModelInfo +{ +public: + virtual void OnDynamicModelsStringTableChange(int nStringIndex, const char* pString, const void* pData) = 0; + + virtual const model_t* FindOrLoadModel(const char* name) = 0; +}; + + +struct virtualterrainparams_t +{ + int index; +}; + + + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/ivmodelrender.h b/SpyCustom/sdk/ivmodelrender.h new file mode 100644 index 0000000..56f17ca --- /dev/null +++ b/SpyCustom/sdk/ivmodelrender.h @@ -0,0 +1,131 @@ +#ifndef IVMODELRENDER_H +#define IVMODELRENDER_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "interface.h" +#include "mathlib.h" +#include "istudiorender.h" +#include "idatacache.h" + +struct mstudioanimdesc_t; +struct mstudioseqdesc_t; +struct model_t; +class IClientRenderable; +class Vector; +struct studiohdr_t; +class IMaterial; +class CStudioHdr; +struct MaterialLightingState_t; + +FORWARD_DECLARE_HANDLE(LightCacheHandle_t); + + +struct DrawModelState_t +{ + studiohdr_t* m_pStudioHdr; + studiohwdata_t* m_pStudioHWData; + IClientRenderable* m_pRenderable; + const matrix3x4_t* m_pModelToWorld; + StudioDecalHandle_t m_decals; + int m_drawFlags; + int m_lod; +}; + + +#define VENGINE_HUDMODEL_INTERFACE_VERSION "VEngineModel016" + +typedef unsigned short ModelInstanceHandle_t; + +enum +{ + MODEL_INSTANCE_INVALID = (ModelInstanceHandle_t)~0 +}; + + +struct ModelRenderInfo_t +{ + Vector origin; + Vector angles; + char pad[4]; + IClientRenderable* pRenderable; + const model_t* pModel; + const matrix3x4_t* pModelToWorld; + const matrix3x4_t* pLightingOffset; + const Vector* pLightingOrigin; + int flags; + int entity_index; + int skin; + int body; + int hitboxset; + ModelInstanceHandle_t instance; + + ModelRenderInfo_t() + { + pModelToWorld = NULL; + pLightingOffset = NULL; + pLightingOrigin = NULL; + } +}; + +struct StaticPropRenderInfo_t +{ + const matrix3x4_t* pModelToWorld; + const model_t* pModel; + IClientRenderable* pRenderable; + Vector* pLightingOrigin; + short skin; + ModelInstanceHandle_t instance; +}; + +struct LightingQuery_t +{ +Vector m_LightingOrigin; +ModelInstanceHandle_t m_InstanceHandle; +bool m_bAmbientBoost; +}; + +struct StaticLightingQuery_t : public LightingQuery_t +{ +IClientRenderable * m_pRenderable; +}; +class IVModelRender +{ +public: + virtual int DrawModel(int flags, IClientRenderable* pRenderable, ModelInstanceHandle_t instance, int entity_index, const model_t* model, Vector const& origin, QAngle const& angles, int skin, int body, int hitboxset, const matrix3x4_t* modelToWorld = NULL, const matrix3x4_t* pLightingOffset = NULL) = 0; + virtual void ForcedMaterialOverride(IMaterial* newMaterial, OverrideType_t nOverrideType = OVERRIDE_NORMAL, int nOverrides = 0) = 0; + virtual bool IsForcedMaterialOverride(void) = 0; + virtual void SetViewTarget(const CStudioHdr* pStudioHdr, int nBodyIndex, const Vector& target) = 0; + virtual ModelInstanceHandle_t CreateInstance(IClientRenderable* pRenderable, LightCacheHandle_t* pCache = NULL) = 0; + virtual void DestroyInstance(ModelInstanceHandle_t handle) = 0; + virtual void SetStaticLighting(ModelInstanceHandle_t handle, LightCacheHandle_t* pHandle) = 0; + virtual LightCacheHandle_t GetStaticLighting(ModelInstanceHandle_t handle) = 0; + virtual bool ChangeInstance(ModelInstanceHandle_t handle, IClientRenderable* pRenderable) = 0; + virtual void AddDecal(ModelInstanceHandle_t handle, Ray_t const& ray, Vector const& decalUp, int decalIndex, int body, bool noPokeThru, int maxLODToDecal) = 0; + virtual void RemoveAllDecals(ModelInstanceHandle_t handle) = 0; + virtual bool ModelHasDecals(ModelInstanceHandle_t handle) = 0; + virtual void RemoveAllDecalsFromAllModels() = 0; + virtual matrix3x4_t* DrawModelShadowSetup(IClientRenderable* pRenderable, int body, int skin, DrawModelInfo_t* pInfo, matrix3x4_t* pCustomBoneToWorld = NULL) = 0; + virtual void DrawModelShadow(IClientRenderable* pRenderable, const DrawModelInfo_t& info, matrix3x4_t* pCustomBoneToWorld = NULL) = 0; + virtual bool RecomputeStaticLighting(ModelInstanceHandle_t handle) = 0; + virtual void ReleaseAllStaticPropColorData(void) = 0; + virtual void RestoreAllStaticPropColorData(void) = 0; + virtual int DrawModelEx(ModelRenderInfo_t& pInfo) = 0; + virtual int DrawModelExStaticProp(ModelRenderInfo_t& pInfo) = 0; + virtual bool DrawModelSetup(ModelRenderInfo_t& pInfo, DrawModelState_t* pState, matrix3x4_t** ppBoneToWorldOut) = 0; + virtual void DrawModelExecute(IMatRenderContext* ctx, const DrawModelState_t& state, const ModelRenderInfo_t& pInfo, matrix3x4_t* pCustomBoneToWorld = NULL) = 0; + virtual void SetupLighting(const Vector& vecCenter) = 0; + virtual int DrawStaticPropArrayFast(StaticPropRenderInfo_t* pProps, int count, bool bShadowDepth) = 0; + virtual void SuppressEngineLighting(bool bSuppress) = 0; + virtual void SetupColorMeshes(int nTotalVerts) = 0; + virtual void SetupLightingEx(const Vector& vecCenter, ModelInstanceHandle_t handle) = 0; + virtual bool GetBrightestShadowingLightSource(const Vector& vecCenter, Vector& lightPos, Vector& lightBrightness, bool bAllowNonTaggedLights) = 0; + virtual void ComputeLightingState(int nCount, const LightingQuery_t* pQuery, MaterialLightingState_t* pState, ITexture** ppEnvCubemapTexture) = 0; + virtual void GetModelDecalHandles(StudioDecalHandle_t* pDecals, int nDecalStride, int nCount, const ModelInstanceHandle_t* pHandles) = 0; + virtual void ComputeStaticLightingState(int nCount, const StaticLightingQuery_t* pQuery, MaterialLightingState_t* pState, MaterialLightingState_t* pDecalState, ColorMeshInfo_t** ppStaticLighting, ITexture** ppEnvCubemapTexture, DataCacheHandle_t* pColorMeshHandles) = 0; + virtual void CleanupStaticLightingState(int nCount, DataCacheHandle_t* pColorMeshHandles) = 0; +}; + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/ivrenderview.h b/SpyCustom/sdk/ivrenderview.h new file mode 100644 index 0000000..12f031c --- /dev/null +++ b/SpyCustom/sdk/ivrenderview.h @@ -0,0 +1,310 @@ +#if !defined( IVRENDERVIEW_H ) +#define IVRENDERVIEW_H +#ifdef _WIN32 +#pragma once +#endif + +#include "basetypes.h" +#include "vplane.h" +#include "interface.h" +#include "imaterialsystem.h" +#include "const.h" +#include "vertexcolor.h" +#include "refcount.h" + + + +class CViewSetup; +class CEngineSprite; +class IClientEntity; +class IMaterial; +struct model_t; +class IClientRenderable; +class IMatRenderContext; +class CVolumeCuller; + + +enum +{ + DRAWWORLDLISTS_DRAW_STRICTLYABOVEWATER = 0x001, + DRAWWORLDLISTS_DRAW_STRICTLYUNDERWATER = 0x002, + DRAWWORLDLISTS_DRAW_INTERSECTSWATER = 0x004, + DRAWWORLDLISTS_DRAW_WATERSURFACE = 0x008, + DRAWWORLDLISTS_DRAW_SKYBOX = 0x010, + DRAWWORLDLISTS_DRAW_CLIPSKYBOX = 0x020, + DRAWWORLDLISTS_DRAW_SHADOWDEPTH = 0x040, + DRAWWORLDLISTS_DRAW_REFRACTION = 0x080, + DRAWWORLDLISTS_DRAW_REFLECTION = 0x100, + DRAWWORLDLISTS_DRAW_WORLD_GEOMETRY = 0x200, + DRAWWORLDLISTS_DRAW_DECALS_AND_OVERLAYS = 0x400, + DRAWWORLDLISTS_DRAW_SIMPLE_WORLD_MODEL = 0x800, + DRAWWORLDLISTS_DRAW_SIMPLE_WORLD_MODEL_WATER = 0x1000, + DRAWWORLDLISTS_DRAW_SKIP_DISPLACEMENTS = 0x2000, + DRAWWORLDLISTS_DRAW_SSAO = 0x4000, +}; + +enum +{ + MAT_SORT_GROUP_STRICTLY_ABOVEWATER = 0, + MAT_SORT_GROUP_STRICTLY_UNDERWATER, + MAT_SORT_GROUP_INTERSECTS_WATER_SURFACE, + MAT_SORT_GROUP_WATERSURFACE, + + MAX_MAT_SORT_GROUPS +}; + +enum ERenderDepthMode_t +{ + DEPTH_MODE_NORMAL = 0, + DEPTH_MODE_SHADOW = 1, + DEPTH_MODE_SSA0 = 2, + + DEPTH_MODE_MAX +}; + + +static const char* s_pMatSortGroupsString[] = +{ + "Sort: Abovewater", + "Sort: Underwater", + "Sort: IntersectsWater", + "Sort: WaterSurface", +}; + +typedef VPlane Frustum[FRUSTUM_NUMPLANES]; + + +typedef unsigned short LeafIndex_t; +enum +{ + INVALID_LEAF_INDEX = (LeafIndex_t)~0 +}; + + +#if 1 +struct WorldListLeafData_t +{ + LeafIndex_t leafIndex; + int16 waterData; + uint16 firstTranslucentSurface; + uint16 translucentSurfaceCount; +}; +#else +struct WorldListLeafData_t +{ + uint32 leafIndex; + int32 waterData; + uint32 firstTranslucentSurface; + uint32 translucentSurfaceCount; +}; +#endif +struct WorldListInfo_t +{ + int m_ViewFogVolume; + int m_LeafCount; + bool m_bHasWater; + WorldListLeafData_t* m_pLeafDataList; +}; + +class IWorldRenderList : public IRefCounted +{ +}; + +struct VisibleFogVolumeInfo_t +{ + int m_nVisibleFogVolume; + int m_nVisibleFogVolumeLeaf; + bool m_bEyeInFogVolume; + float m_flDistanceToWater; + float m_flWaterHeight; + IMaterial* m_pFogVolumeMaterial; +}; + + +struct BrushVertex_t +{ + Vector m_Pos; + Vector m_Normal; + Vector m_TangentS; + Vector m_TangentT; + Vector2D m_TexCoord; + Vector2D m_LightmapCoord; + +private: + BrushVertex_t(const BrushVertex_t& src); +}; + +struct VisOverrideData_t +{ + Vector m_vecVisOrigin; + float m_fDistToAreaPortalTolerance; + + Vector m_vPortalCorners[4]; + bool m_bTrimFrustumToPortalCorners; + + Vector m_vPortalOrigin; + Vector m_vPortalForward; + float m_flPortalRadius; + +}; + + +class IBrushSurface +{ +public: + virtual void ComputeTextureCoordinate(Vector const& worldPos, Vector2D& texCoord) = 0; + virtual void ComputeLightmapCoordinate(Vector const& worldPos, Vector2D& lightmapCoord) = 0; + + virtual int GetVertexCount() const = 0; + virtual void GetVertexData(BrushVertex_t* pVerts) = 0; + + virtual IMaterial* GetMaterial() = 0; +}; + + +class IBrushRenderer +{ +public: + virtual bool RenderBrushModelSurface(IClientEntity* pBaseEntity, IBrushSurface* pBrushSurface) = 0; +}; + + +#define MAX_VIS_LEAVES 32 +enum DrawBrushModelMode_t +{ + DBM_DRAW_ALL = 0, + DBM_DRAW_OPAQUE_ONLY, + DBM_DRAW_TRANSLUCENT_ONLY, +}; + + +struct BrushArrayInstanceData_t +{ + matrix3x4a_t* m_pBrushToWorld; + const model_t* m_pBrushModel; + Vector4D m_DiffuseModulation; + ShaderStencilState_t* m_pStencilState; +}; + + +class IVRenderView +{ +public: + + virtual void DrawBrushModel( + IClientEntity* baseentity, + model_t* model, + const Vector& origin, + const QAngle& angles, + bool bUnused) = 0; + + virtual void DrawIdentityBrushModel(IWorldRenderList* pList, model_t* model) = 0; + + virtual void TouchLight(struct dlight_t* light) = 0; + virtual void Draw3DDebugOverlays(void) = 0; + virtual void SetBlend(float blend) = 0; + virtual float GetBlend(void) = 0; + + virtual void SetColorModulation(float const* blend) = 0; + virtual void GetColorModulation(float* blend) = 0; + + virtual void SceneBegin(void) = 0; + virtual void SceneEnd(void) = 0; + + virtual void GetVisibleFogVolume(const Vector& eyePoint, const VisOverrideData_t* pVisOverrideData, VisibleFogVolumeInfo_t* pInfo) = 0; + + virtual IWorldRenderList* CreateWorldList() = 0; +#if defined(_PS3) + virtual IWorldRenderList* CreateWorldList_PS3(int viewID) = 0; + virtual void BuildWorldLists_PS3_Epilogue(IWorldRenderList* pList, WorldListInfo_t* pInfo, bool bShadowDepth) = 0; +#else + virtual void BuildWorldLists_Epilogue(IWorldRenderList* pList, WorldListInfo_t* pInfo, bool bShadowDepth) = 0; +#endif + virtual void BuildWorldLists(IWorldRenderList* pList, WorldListInfo_t* pInfo, int iForceFViewLeaf, const VisOverrideData_t* pVisData = NULL, bool bShadowDepth = false, float* pReflectionWaterHeight = NULL) = 0; + virtual void DrawWorldLists(IMatRenderContext* pRenderContext, IWorldRenderList* pList, unsigned long flags, float waterZAdjust) = 0; + virtual void GetWorldListIndicesInfo(WorldListIndicesInfo_t* pIndicesInfoOut, IWorldRenderList* pList, unsigned long nFlags) = 0; + + virtual void DrawTopView(bool enable) = 0; + virtual void TopViewNoBackfaceCulling(bool bDisable) = 0; + virtual void TopViewNoVisCheck(bool bDisable) = 0; + virtual void TopViewBounds(Vector2D const& mins, Vector2D const& maxs) = 0; + virtual void SetTopViewVolumeCuller(const CVolumeCuller* pVolumeCuller) = 0; + + virtual void DrawLights(void) = 0; + virtual void DrawMaskEntities(void) = 0; + + virtual void DrawTranslucentSurfaces(IMatRenderContext* pRenderContext, IWorldRenderList* pList, int* pSortList, int sortCount, unsigned long flags) = 0; + + virtual void DrawLineFile(void) = 0; + virtual void DrawLightmaps(IWorldRenderList* pList, int pageId) = 0; + virtual void ViewSetupVis(bool novis, int numorigins, const Vector origin[]) = 0; + + virtual bool AreAnyLeavesVisible(int* leafList, int nLeaves) = 0; + + virtual void VguiPaint(void) = 0; + virtual void ViewDrawFade(byte* color, IMaterial* pMaterial, bool mapFullTextureToScreen = true) = 0; + virtual void OLD_SetProjectionMatrix(float fov, float zNear, float zFar) = 0; + virtual colorVec GetLightAtPoint(Vector& pos) = 0; + virtual int GetViewEntity(void) = 0; + virtual bool IsViewEntity(int entindex) = 0; + virtual float GetFieldOfView(void) = 0; + virtual unsigned char** GetAreaBits(void) = 0; + + virtual void SetFogVolumeState(int nVisibleFogVolume, bool bUseHeightFog) = 0; + + virtual void InstallBrushSurfaceRenderer(IBrushRenderer* pBrushRenderer) = 0; + + virtual void DrawBrushModelShadow(IClientRenderable* pRenderable) = 0; + + virtual bool LeafContainsTranslucentSurfaces(IWorldRenderList* pList, int sortIndex, unsigned long flags) = 0; + + virtual bool DoesBoxIntersectWaterVolume(const Vector& mins, const Vector& maxs, int leafWaterDataID) = 0; + + virtual void SetAreaState( + unsigned char chAreaBits[MAX_AREA_STATE_BYTES], + unsigned char chAreaPortalBits[MAX_AREA_PORTAL_STATE_BYTES]) = 0; + + virtual void VGui_Paint(int mode) = 0; + + virtual void Push3DView(IMatRenderContext* pRenderContext, const CViewSetup& view, int nFlags, ITexture* pRenderTarget, Frustum frustumPlanes) = 0; + virtual void Push2DView(IMatRenderContext* pRenderContext, const CViewSetup& view, int nFlags, ITexture* pRenderTarget, Frustum frustumPlanes) = 0; + virtual void PopView(IMatRenderContext* pRenderContext, Frustum frustumPlanes) = 0; + + virtual void SetMainView(const Vector& vecOrigin, const QAngle& angles) = 0; + + enum + { + VIEW_SETUP_VIS_EX_RETURN_FLAGS_USES_RADIAL_VIS = 0x00000001 + }; + + virtual void ViewSetupVisEx(bool novis, int numorigins, const Vector origin[], unsigned int& returnFlags) = 0; + + virtual void OverrideViewFrustum(Frustum custom) = 0; + + virtual void DrawBrushModelShadowDepth(IClientEntity* baseentity, model_t* model, const Vector& origin, const QAngle& angles, ERenderDepthMode_t DepthMode) = 0; + virtual void UpdateBrushModelLightmap(model_t* model, IClientRenderable* pRenderable) = 0; + virtual void BeginUpdateLightmaps(void) = 0; + virtual void EndUpdateLightmaps() = 0; + virtual void OLD_SetOffCenterProjectionMatrix(float fov, float zNear, float zFar, float flAspectRatio, float flBottom, float flTop, float flLeft, float flRight) = 0; + virtual void OLD_SetProjectionMatrixOrtho(float left, float top, float right, float bottom, float zNear, float zFar) = 0; + virtual void Push3DView(IMatRenderContext* pRenderContext, const CViewSetup& view, int nFlags, ITexture* pRenderTarget, Frustum frustumPlanes, ITexture* pDepthTexture) = 0; + virtual void GetMatricesForView(const CViewSetup& view, VMatrix* pWorldToView, VMatrix* pViewToProjection, VMatrix* pWorldToProjection, VMatrix* pWorldToPixels) = 0; + virtual void DrawBrushModelEx(IClientEntity* baseentity, model_t* model, const Vector& origin, const QAngle& angles, DrawBrushModelMode_t mode) = 0; + + virtual bool DoesBrushModelNeedPowerOf2Framebuffer(const model_t* model) = 0; + + virtual void DrawBrushModelArray(IMatRenderContext* pContext, int nCount, const BrushArrayInstanceData_t* pInstanceData, int nModelTypeFlags) = 0; +}; + +#define VENGINE_RENDERVIEW_INTERFACE_VERSION "VEngineRenderView014" + +#if defined(_STATIC_LINKED) && defined(CLIENT_DLL) +namespace Client +{ + extern IVRenderView* render; +} +#else +extern IVRenderView* render; +#endif + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/jobthread.h b/SpyCustom/sdk/jobthread.h new file mode 100644 index 0000000..d254370 --- /dev/null +++ b/SpyCustom/sdk/jobthread.h @@ -0,0 +1,1270 @@ +#include +#include "threadtools.h" +#include "refcount.h" +#include "utllinkedlist.h" +#include "utlvector.h" +#include "functors.h" + +#include "vstdlib.h" + +#ifndef JOBTHREAD_H +#define JOBTHREAD_H + +#ifdef AddJob +#undef AddJob +#undef GetJob +#endif + +#ifdef VSTDLIB_DLL_EXPORT +#define JOB_INTERFACE DLL_EXPORT +#define JOB_OVERLOAD DLL_GLOBAL_EXPORT +#define JOB_CLASS DLL_CLASS_EXPORT +#else +#define JOB_INTERFACE DLL_IMPORT +#define JOB_OVERLOAD DLL_GLOBAL_IMPORT +#define JOB_CLASS DLL_CLASS_IMPORT +#endif + +#if defined( _WIN32 ) +#pragma once +#endif + +class CJob; + +enum JobStatusEnum_t +{ + JOB_OK, + JOB_STATUS_PENDING, + JOB_STATUS_INPROGRESS, + JOB_STATUS_ABORTED, + JOB_STATUS_UNSERVICED, +}; + +typedef int JobStatus_t; + +enum JobFlags_t +{ + JF_IO = (1 << 0), + JF_BOOST_THREAD = (1 << 1), + JF_SERIAL = (1 << 2), + JF_QUEUE = (1 << 3), +}; + +enum JobPriority_t +{ + JP_LOW, + JP_NORMAL, + JP_HIGH, + JP_IMMEDIATE, + + JP_NUM_PRIORITIES, + + JP_FRAME = JP_NORMAL, + JP_FRAME_SEGMENT = JP_HIGH, +}; + +#define TP_MAX_POOL_THREADS 64 +struct ThreadPoolStartParams_t +{ + ThreadPoolStartParams_t(bool bIOThreads = false, unsigned nThreads = (unsigned)-1, int* pAffinities = NULL, ThreeState_t fDistribute = TRS_NONE, unsigned nStackSize = (unsigned)-1, int iThreadPriority = SHRT_MIN) + : bIOThreads(bIOThreads), nThreads(nThreads), nThreadsMax(-1), fDistribute(fDistribute), nStackSize(nStackSize), iThreadPriority(iThreadPriority) + { + bExecOnThreadPoolThreadsOnly = false; +#if defined( DEDICATED ) && IsPlatformLinux() + bEnableOnLinuxDedicatedServer = false; +#endif + + bUseAffinityTable = (pAffinities != NULL) && (fDistribute == TRS_TRUE) && (nThreads != (unsigned)-1); + if (bUseAffinityTable) + { + nThreads = MIN(TP_MAX_POOL_THREADS, nThreads); + for (unsigned int i = 0; i < nThreads; i++) + { + iAffinityTable[i] = pAffinities[i]; + } + } + } + + int nThreads; + int nThreadsMax; + ThreeState_t fDistribute; + int nStackSize; + int iThreadPriority; + int iAffinityTable[TP_MAX_POOL_THREADS]; + + bool bIOThreads : 1; + bool bUseAffinityTable : 1; + bool bExecOnThreadPoolThreadsOnly : 1; +#if defined( DEDICATED ) && IsPlatformLinux() + bool bEnableOnLinuxDedicatedServer : 1; +#endif +}; + +typedef bool (*JobFilter_t)(CJob*); + +enum ThreadPoolMessages_t +{ + TPM_EXIT, + TPM_SUSPEND, +}; + +#ifdef Yield +#undef Yield +#endif + +abstract_class IThreadPool : public IRefCounted +{ +public: + virtual ~IThreadPool() {}; + + virtual bool Start(const ThreadPoolStartParams_t& startParams = ThreadPoolStartParams_t()) = 0; + virtual bool Stop(int timeout = TT_INFINITE) = 0; + + virtual unsigned GetJobCount() = 0; + virtual int NumThreads() = 0; + virtual int NumIdleThreads() = 0; + + virtual int SuspendExecution() = 0; + virtual int ResumeExecution() = 0; + + virtual int YieldWait(CThreadEvent** pEvents, int nEvents, bool bWaitAll = true, unsigned timeout = TT_INFINITE) = 0; + virtual int YieldWait(CJob**, int nJobs, bool bWaitAll = true, unsigned timeout = TT_INFINITE) = 0; + virtual void Yield(unsigned timeout) = 0; + + bool YieldWait(CThreadEvent& event, unsigned timeout = TT_INFINITE); + bool YieldWait(CJob*, unsigned timeout = TT_INFINITE); + + virtual void AddJob(CJob*) = 0; + + virtual void AddFunctor(CFunctor* pFunctor, CJob** ppJob = NULL, const char* pszDescription = NULL, unsigned flags = 0) { AddFunctorInternal(RetAddRef(pFunctor), ppJob, pszDescription, flags); } + + virtual void ChangePriority(CJob* p, JobPriority_t priority) = 0; + + int ExecuteAll(JobFilter_t pfnFilter = NULL) { return ExecuteToPriority(JP_LOW, pfnFilter); } + virtual int ExecuteToPriority(JobPriority_t toPriority, JobFilter_t pfnFilter = NULL) = 0; + virtual int AbortAll() = 0; + + virtual void AddPerFrameJob(CJob*) = 0; + + #define DEFINE_NONMEMBER_ADD_CALL(N) \ + template \ + CJob *AddCall(FUNCTION_RETTYPE (*pfnProxied)( FUNC_BASE_TEMPLATE_FUNC_PARAMS_##N ) FUNC_ARG_FORMAL_PARAMS_##N ) \ + { \ + CJob *pJob; \ + if ( !NumIdleThreads() ) \ + { \ + pJob = GetDummyJob(); \ + FunctorDirectCall( pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ); \ + } \ + else \ + { \ + AddFunctorInternal( CreateFunctor( pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ), &pJob ); \ + } \ + \ + return pJob; \ + } + + #define DEFINE_MEMBER_ADD_CALL(N) \ + template \ + CJob *AddCall(OBJECT_TYPE *pObject, FUNCTION_RETTYPE ( FUNCTION_CLASS::*pfnProxied )( FUNC_BASE_TEMPLATE_FUNC_PARAMS_##N ) FUNC_ARG_FORMAL_PARAMS_##N ) \ + { \ + CJob *pJob; \ + if ( !NumIdleThreads() ) \ + { \ + pJob = GetDummyJob(); \ + FunctorDirectCall( pObject, pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ); \ + } \ + else \ + { \ + AddFunctorInternal( CreateFunctor( pObject, pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ), &pJob ); \ + } \ + \ + return pJob; \ + } + + #define DEFINE_CONST_MEMBER_ADD_CALL(N) \ + template \ + CJob *AddCall(OBJECT_TYPE *pObject, FUNCTION_RETTYPE ( FUNCTION_CLASS::*pfnProxied )( FUNC_BASE_TEMPLATE_FUNC_PARAMS_##N ) const FUNC_ARG_FORMAL_PARAMS_##N ) \ + { \ + CJob *pJob; \ + if ( !NumIdleThreads() ) \ + { \ + pJob = GetDummyJob(); \ + FunctorDirectCall( pObject, pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ); \ + } \ + else \ + { \ + AddFunctorInternal( CreateFunctor( pObject, pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ), &pJob ); \ + } \ + \ + return pJob; \ + } + + #define DEFINE_REF_COUNTING_MEMBER_ADD_CALL(N) \ + template \ + CJob *AddRefCall(OBJECT_TYPE *pObject, FUNCTION_RETTYPE ( FUNCTION_CLASS::*pfnProxied )( FUNC_BASE_TEMPLATE_FUNC_PARAMS_##N ) FUNC_ARG_FORMAL_PARAMS_##N ) \ + { \ + CJob *pJob; \ + if ( !NumIdleThreads() ) \ + { \ + pJob = GetDummyJob(); \ + FunctorDirectCall( pObject, pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ); \ + } \ + else \ + { \ + AddFunctorInternal( CreateRefCountingFunctor( pObject, pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ), &pJob ); \ + } \ + \ + return pJob; \ + } + + #define DEFINE_REF_COUNTING_CONST_MEMBER_ADD_CALL(N) \ + template \ + CJob *AddRefCall(OBJECT_TYPE *pObject, FUNCTION_RETTYPE ( FUNCTION_CLASS::*pfnProxied )( FUNC_BASE_TEMPLATE_FUNC_PARAMS_##N ) const FUNC_ARG_FORMAL_PARAMS_##N ) \ + { \ + CJob *pJob; \ + if ( !NumIdleThreads() ) \ + { \ + pJob = GetDummyJob(); \ + FunctorDirectCall( pObject, pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ); \ + } \ + else \ + { \ + AddFunctorInternal( CreateRefCountingFunctor( pObject, pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ), &pJob ); \ + } \ + \ + return pJob; \ + } + + #define DEFINE_NONMEMBER_QUEUE_CALL(N) \ + template \ + CJob *QueueCall(FUNCTION_RETTYPE (*pfnProxied)( FUNC_BASE_TEMPLATE_FUNC_PARAMS_##N ) FUNC_ARG_FORMAL_PARAMS_##N ) \ + { \ + CJob *pJob; \ + AddFunctorInternal( CreateFunctor( pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ), &pJob, NULL, JF_QUEUE ); \ + return pJob; \ + } + + #define DEFINE_MEMBER_QUEUE_CALL(N) \ + template \ + CJob *QueueCall(OBJECT_TYPE *pObject, FUNCTION_RETTYPE ( FUNCTION_CLASS::*pfnProxied )( FUNC_BASE_TEMPLATE_FUNC_PARAMS_##N ) FUNC_ARG_FORMAL_PARAMS_##N ) \ + { \ + CJob *pJob; \ + AddFunctorInternal( CreateFunctor( pObject, pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ), &pJob, NULL, JF_QUEUE ); \ + return pJob; \ + } + + #define DEFINE_CONST_MEMBER_QUEUE_CALL(N) \ + template \ + CJob *QueueCall(OBJECT_TYPE *pObject, FUNCTION_RETTYPE ( FUNCTION_CLASS::*pfnProxied )( FUNC_BASE_TEMPLATE_FUNC_PARAMS_##N ) const FUNC_ARG_FORMAL_PARAMS_##N ) \ + { \ + CJob *pJob; \ + AddFunctorInternal( CreateFunctor( pObject, pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ), &pJob, NULL, JF_QUEUE ); \ + return pJob; \ + } + + #define DEFINE_REF_COUNTING_MEMBER_QUEUE_CALL(N) \ + template \ + CJob *QueueRefCall(OBJECT_TYPE *pObject, FUNCTION_RETTYPE ( FUNCTION_CLASS::*pfnProxied )( FUNC_BASE_TEMPLATE_FUNC_PARAMS_##N ) FUNC_ARG_FORMAL_PARAMS_##N ) \ + { \ + CJob *pJob; \ + AddFunctorInternal( CreateRefCountingFunctor( pObject, pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ), &pJob, NULL, JF_QUEUE ); \ + return pJob; \ + } + + #define DEFINE_REF_COUNTING_CONST_MEMBER_QUEUE_CALL(N) \ + template \ + CJob *QueueRefCall(OBJECT_TYPE *pObject, FUNCTION_RETTYPE ( FUNCTION_CLASS::*pfnProxied )( FUNC_BASE_TEMPLATE_FUNC_PARAMS_##N ) const FUNC_ARG_FORMAL_PARAMS_##N ) \ + { \ + CJob *pJob; \ + AddFunctorInternal( CreateRefCountingFunctor( pObject, pfnProxied FUNC_FUNCTOR_CALL_ARGS_##N ), &pJob, NULL, JF_QUEUE ); \ + \ + return pJob; \ + } + + FUNC_GENERATE_ALL(DEFINE_NONMEMBER_ADD_CALL); + FUNC_GENERATE_ALL(DEFINE_MEMBER_ADD_CALL); + FUNC_GENERATE_ALL(DEFINE_CONST_MEMBER_ADD_CALL); + FUNC_GENERATE_ALL(DEFINE_REF_COUNTING_MEMBER_ADD_CALL); + FUNC_GENERATE_ALL(DEFINE_REF_COUNTING_CONST_MEMBER_ADD_CALL); + FUNC_GENERATE_ALL(DEFINE_NONMEMBER_QUEUE_CALL); + FUNC_GENERATE_ALL(DEFINE_MEMBER_QUEUE_CALL); + FUNC_GENERATE_ALL(DEFINE_CONST_MEMBER_QUEUE_CALL); + FUNC_GENERATE_ALL(DEFINE_REF_COUNTING_MEMBER_QUEUE_CALL); + FUNC_GENERATE_ALL(DEFINE_REF_COUNTING_CONST_MEMBER_QUEUE_CALL); + + #undef DEFINE_NONMEMBER_ADD_CALL + #undef DEFINE_MEMBER_ADD_CALL + #undef DEFINE_CONST_MEMBER_ADD_CALL + #undef DEFINE_REF_COUNTING_MEMBER_ADD_CALL + #undef DEFINE_REF_COUNTING_CONST_MEMBER_ADD_CALL + #undef DEFINE_NONMEMBER_QUEUE_CALL + #undef DEFINE_MEMBER_QUEUE_CALL + #undef DEFINE_CONST_MEMBER_QUEUE_CALL + #undef DEFINE_REF_COUNTING_MEMBER_QUEUE_CALL + #undef DEFINE_REF_COUNTING_CONST_MEMBER_QUEUE_CALL + +private: + virtual void AddFunctorInternal(CFunctor*, CJob** = NULL, const char* pszDescription = NULL, unsigned flags = 0) = 0; + + friend class CJob; + + virtual CJob* GetDummyJob() = 0; + +public: + virtual void Distribute(bool bDistribute = true, int* pAffinityTable = NULL) = 0; + + virtual bool Start(const ThreadPoolStartParams_t& startParams, const char* pszNameOverride) = 0; + + virtual int YieldWaitPerFrameJobs() = 0; +}; + +JOB_INTERFACE IThreadPool* CreateNewThreadPool(); +JOB_INTERFACE void DestroyThreadPool(IThreadPool* pPool); + +JOB_INTERFACE void RunThreadPoolTests(); + +JOB_INTERFACE IThreadPool* g_pThreadPool; +#ifdef _X360 +JOB_INTERFACE IThreadPool* g_pAlternateThreadPool; +#endif + +DECLARE_POINTER_HANDLE(ThreadPoolData_t); +#define JOB_NO_DATA ((ThreadPoolData_t)-1) + +class CJob : public CRefCounted1 +{ +public: + CJob(JobPriority_t priority = JP_NORMAL) + : m_status(JOB_STATUS_UNSERVICED), + m_ThreadPoolData(JOB_NO_DATA), + m_priority(priority), + m_flags(0), + m_pThreadPool(NULL), + m_CompleteEvent(true), + m_iServicingThread(-1) + { + } + + void SetPriority(JobPriority_t priority) { m_priority = priority; } + JobPriority_t GetPriority() const { return m_priority; } + + void SetFlags(unsigned flags) { m_flags = flags; } + unsigned GetFlags() const { return m_flags; } + + void SetServiceThread(int iServicingThread) { m_iServicingThread = (char)iServicingThread; } + int GetServiceThread() const { return m_iServicingThread; } + void ClearServiceThread() { m_iServicingThread = -1; } + + bool Executed() const { return (m_status == JOB_OK); } + bool CanExecute() const { return (m_status == JOB_STATUS_PENDING || m_status == JOB_STATUS_UNSERVICED); } + bool IsFinished() const { return (m_status != JOB_STATUS_PENDING && m_status != JOB_STATUS_INPROGRESS && m_status != JOB_STATUS_UNSERVICED); } + JobStatus_t GetStatus() const { return m_status; } + + bool TryLock() { return m_mutex.TryLock(); } + void Lock() { m_mutex.Lock(); } + void Unlock() { m_mutex.Unlock(); } + + bool WaitForFinish(uint32 dwTimeout = TT_INFINITE) { if (!this) return true; return (!IsFinished()) ? g_pThreadPool->YieldWait(this, dwTimeout) : true; } + bool WaitForFinishAndRelease(uint32 dwTimeout = TT_INFINITE) { if (!this) return true; bool bResult = WaitForFinish(dwTimeout); Release(); return bResult; } + CThreadEvent* AccessEvent() { return &m_CompleteEvent; } + + JobStatus_t Execute(); + JobStatus_t TryExecute(); + JobStatus_t ExecuteAndRelease() { JobStatus_t status = Execute(); Release(); return status; } + JobStatus_t TryExecuteAndRelease() { JobStatus_t status = TryExecute(); Release(); return status; } + + JobStatus_t Abort(bool bDiscard = true); + + virtual char const* Describe() { return "Job"; } + +private: + friend class CThreadPool; + + JobStatus_t m_status; + JobPriority_t m_priority; + CThreadMutex m_mutex; + unsigned char m_flags; + char m_iServicingThread; + short m_reserved; + ThreadPoolData_t m_ThreadPoolData; + IThreadPool* m_pThreadPool; + CThreadEvent m_CompleteEvent; + +#if defined( THREAD_PARENT_STACK_TRACE_ENABLED ) + void* m_ParentStackTrace[THREAD_PARENT_STACK_TRACE_LENGTH]; +#endif + +private: + CJob(const CJob& fromRequest); + void operator=(const CJob& fromRequest); + + virtual JobStatus_t DoExecute() = 0; + virtual JobStatus_t DoAbort(bool bDiscard) { return JOB_STATUS_ABORTED; } + virtual void DoCleanup() {} +}; + +class CFunctorJob : public CJob +{ +public: + CFunctorJob(CFunctor* pFunctor, const char* pszDescription = NULL) + : m_pFunctor(pFunctor) + { + if (pszDescription) + { + Q_strncpy(m_szDescription, pszDescription, sizeof(m_szDescription)); + } + else + { + m_szDescription[0] = 0; + } + } + + virtual JobStatus_t DoExecute() + { + (*m_pFunctor)(); + return JOB_OK; + } + + const char* Describe() + { + return m_szDescription; + } + +private: + CRefPtr m_pFunctor; + char m_szDescription[16]; +}; + +class CJobSet +{ +public: + CJobSet(CJob* pJob = NULL) + { + if (pJob) + { + m_jobs.AddToTail(pJob); + } + } + + CJobSet(CJob** ppJobs, int nJobs) + { + if (ppJobs) + { + m_jobs.AddMultipleToTail(nJobs, ppJobs); + } + } + + ~CJobSet() + { + for (int i = 0; i < m_jobs.Count(); i++) + { + m_jobs[i]->Release(); + } + } + + void operator+=(CJob* pJob) + { + m_jobs.AddToTail(pJob); + } + + void operator-=(CJob* pJob) + { + m_jobs.FindAndRemove(pJob); + } + + void Execute(bool bRelease = true) + { + for (int i = 0; i < m_jobs.Count(); i++) + { + m_jobs[i]->Execute(); + if (bRelease) + { + m_jobs[i]->Release(); + } + } + + if (bRelease) + { + m_jobs.RemoveAll(); + } + } + + void Abort(bool bRelease = true) + { + for (int i = 0; i < m_jobs.Count(); i++) + { + m_jobs[i]->Abort(); + if (bRelease) + { + m_jobs[i]->Release(); + } + } + + if (bRelease) + { + m_jobs.RemoveAll(); + } + } + + void WaitForFinish(bool bRelease = true) + { + for (int i = 0; i < m_jobs.Count(); i++) + { + m_jobs[i]->WaitForFinish(); + if (bRelease) + { + m_jobs[i]->Release(); + } + } + + if (bRelease) + { + m_jobs.RemoveAll(); + } + } + + void WaitForFinish(IThreadPool* pPool, bool bRelease = true) + { + pPool->YieldWait(m_jobs.Base(), m_jobs.Count()); + + if (bRelease) + { + for (int i = 0; i < m_jobs.Count(); i++) + { + m_jobs[i]->Release(); + } + + m_jobs.RemoveAll(); + } + } + +private: + CUtlVectorFixed m_jobs; +}; + +#define ThreadExecute g_pThreadPool->QueueCall +#define ThreadExecuteRef g_pThreadPool->QueueRefCall + +#define BeginExecuteParallel() do { CJobSet jobSet +#define EndExecuteParallel() jobSet.WaitForFinish( g_pThreadPool ); } while (0) + +#define ExecuteParallel jobSet += g_pThreadPool->QueueCall +#define ExecuteRefParallel jobSet += g_pThreadPool->QueueCallRef + + +#pragma warning(push) +#pragma warning(disable:4389) +#pragma warning(disable:4018) +#pragma warning(disable:4701) + +#define DEFINE_NON_MEMBER_ITER_RANGE_PARALLEL(N) \ + template \ + void IterRangeParallel(FUNCTION_RETTYPE ( FUNCTION_CLASS::*pfnProxied )( ITERTYPE1, ITERTYPE2 FUNC_SEPARATOR_##N FUNC_BASE_TEMPLATE_FUNC_PARAMS_##N ), ITERTYPE1 from, ITERTYPE2 to FUNC_ARG_FORMAL_PARAMS_##N ) \ + { \ + const int MAX_THREADS = 16; \ + int nIdle = g_pThreadPool->NumIdleThreads(); \ + ITERTYPE1 range = to - from; \ + int nThreads = min( nIdle + 1, range ); \ + if ( nThreads > MAX_THREADS ) \ + { \ + nThreads = MAX_THREADS; \ + } \ + if ( nThreads < 2 ) \ + { \ + FunctorDirectCall( pfnProxied, from, to FUNC_FUNCTOR_CALL_ARGS_##N ); \ + } \ + else \ + { \ + ITERTYPE1 nIncrement = range / nThreads; \ + \ + CJobSet jobSet; \ + while ( --nThreads ) \ + { \ + ITERTYPE2 thisTo = from + nIncrement; \ + jobSet += g_pThreadPool->AddCall( pfnProxied, from, thisTo FUNC_FUNCTOR_CALL_ARGS_##N ); \ + from = thisTo; \ + } \ + FunctorDirectCall( pfnProxied, from, to FUNC_FUNCTOR_CALL_ARGS_##N ); \ + jobSet.WaitForFinish( g_pThreadPool ); \ + } \ + \ + } + +FUNC_GENERATE_ALL(DEFINE_NON_MEMBER_ITER_RANGE_PARALLEL); + +#define DEFINE_MEMBER_ITER_RANGE_PARALLEL(N) \ + template \ + void IterRangeParallel(OBJECT_TYPE *pObject, FUNCTION_RETTYPE ( FUNCTION_CLASS::*pfnProxied )( ITERTYPE1, ITERTYPE2 FUNC_SEPARATOR_##N FUNC_BASE_TEMPLATE_FUNC_PARAMS_##N ), ITERTYPE1 from, ITERTYPE2 to FUNC_ARG_FORMAL_PARAMS_##N ) \ + { \ + const int MAX_THREADS = 16; \ + int nIdle = g_pThreadPool->NumIdleThreads(); \ + ITERTYPE1 range = to - from; \ + int nThreads = min( nIdle + 1, range ); \ + if ( nThreads > MAX_THREADS ) \ + { \ + nThreads = MAX_THREADS; \ + } \ + if ( nThreads < 2 ) \ + { \ + FunctorDirectCall( pObject, pfnProxied, from, to FUNC_FUNCTOR_CALL_ARGS_##N ); \ + } \ + else \ + { \ + ITERTYPE1 nIncrement = range / nThreads; \ + \ + CJobSet jobSet; \ + while ( --nThreads ) \ + { \ + ITERTYPE2 thisTo = from + nIncrement; \ + jobSet += g_pThreadPool->AddCall( pObject, pfnProxied, from, thisTo FUNC_FUNCTOR_CALL_ARGS_##N ); \ + from = thisTo; \ + } \ + FunctorDirectCall( pObject, pfnProxied, from, to FUNC_FUNCTOR_CALL_ARGS_##N ); \ + jobSet.WaitForFinish( g_pThreadPool ); \ + } \ + \ + } + +FUNC_GENERATE_ALL(DEFINE_MEMBER_ITER_RANGE_PARALLEL); + + +template +class CJobItemProcessor +{ +public: + typedef T ItemType_t; + void Begin() {} + void End() {} +}; + +template +class CFuncJobItemProcessor : public CJobItemProcessor +{ +public: + void Init(void (*pfnProcess)(T&), void (*pfnBegin)() = NULL, void (*pfnEnd)() = NULL) + { + m_pfnProcess = pfnProcess; + m_pfnBegin = pfnBegin; + m_pfnEnd = pfnEnd; + } + + void Begin() { if (m_pfnBegin) (*m_pfnBegin)(); } + void Process(T& item) { (*m_pfnProcess)(item); } + void End() { if (m_pfnEnd) (*m_pfnEnd)(); } + +protected: + void (*m_pfnProcess)(T&); + void (*m_pfnBegin)(); + void (*m_pfnEnd)(); +}; + +template +class CMemberFuncJobItemProcessor : public CJobItemProcessor +{ +public: + void Init(OBJECT_TYPE* pObject, void (FUNCTION_CLASS::* pfnProcess)(T&), void (FUNCTION_CLASS::* pfnBegin)() = NULL, void (FUNCTION_CLASS::* pfnEnd)() = NULL) + { + m_pObject = pObject; + m_pfnProcess = pfnProcess; + m_pfnBegin = pfnBegin; + m_pfnEnd = pfnEnd; + } + + void Begin() { if (m_pfnBegin) ((*m_pObject).*m_pfnBegin)(); } + void Process(T& item) { ((*m_pObject).*m_pfnProcess)(item); } + void End() { if (m_pfnEnd) ((*m_pObject).*m_pfnEnd)(); } + +protected: + OBJECT_TYPE* m_pObject; + + void (FUNCTION_CLASS::* m_pfnProcess)(T&); + void (FUNCTION_CLASS::* m_pfnBegin)(); + void (FUNCTION_CLASS::* m_pfnEnd)(); +}; + +template +class CLoopFuncJobItemProcessor : public CJobItemProcessor +{ +public: + void Init(void (*pfnProcess)(T*, int, int), void (*pfnBegin)() = NULL, void (*pfnEnd)() = NULL) + { + m_pfnProcess = pfnProcess; + m_pfnBegin = pfnBegin; + m_pfnEnd = pfnEnd; + } + + void Begin() { if (m_pfnBegin) (*m_pfnBegin)(); } + void Process(T* pContext, int nFirst, int nCount) { (*m_pfnProcess)(pContext, nFirst, nCount); } + void End() { if (m_pfnEnd) (*m_pfnEnd)(); } + +protected: + void (*m_pfnProcess)(T*, int, int); + void (*m_pfnBegin)(); + void (*m_pfnEnd)(); +}; + +template +class CLoopMemberFuncJobItemProcessor : public CJobItemProcessor +{ +public: + void Init(OBJECT_TYPE* pObject, void (FUNCTION_CLASS::* pfnProcess)(T*, int, int), void (FUNCTION_CLASS::* pfnBegin)() = NULL, void (FUNCTION_CLASS::* pfnEnd)() = NULL) + { + m_pObject = pObject; + m_pfnProcess = pfnProcess; + m_pfnBegin = pfnBegin; + m_pfnEnd = pfnEnd; + } + + void Begin() { if (m_pfnBegin) ((*m_pObject).*m_pfnBegin)(); } + void Process(T* item, int nFirst, int nCount) { ((*m_pObject).*m_pfnProcess)(item, nFirst, nCount); } + void End() { if (m_pfnEnd) ((*m_pObject).*m_pfnEnd)(); } + +protected: + OBJECT_TYPE* m_pObject; + + void (FUNCTION_CLASS::* m_pfnProcess)(T*, int, int); + void (FUNCTION_CLASS::* m_pfnBegin)(); + void (FUNCTION_CLASS::* m_pfnEnd)(); +}; + + +#pragma warning(push) +#pragma warning(disable:4189) + +template +class CParallelProcessor +{ +public: + CParallelProcessor() + { + m_pItems = m_pLimit = 0; + } + + void Run(ITEM_TYPE* pItems, unsigned nItems, int nChunkSize = 1, int nMaxParallel = INT_MAX, IThreadPool* pThreadPool = NULL) + { + if (nItems == 0) + return; + +#if defined(_X360) + volatile int ignored = ID_TO_PREVENT_COMDATS_IN_PROFILES; +#endif + + m_nChunkSize = nChunkSize; + if (!pThreadPool) + { + pThreadPool = g_pThreadPool; + } + + m_pItems = pItems; + m_pLimit = pItems + nItems; + + int nJobs = nItems - 1; + + if (nJobs > nMaxParallel) + { + nJobs = nMaxParallel; + } + + if (!pThreadPool) + { + DoExecute(); + return; + } + + int nThreads = pThreadPool->NumThreads(); + if (nJobs > nThreads) + { + nJobs = nThreads; + } + + if (nJobs > 0) + { + CJob** jobs = (CJob**)stackalloc(nJobs * sizeof(CJob**)); + int i = nJobs; + + while (i--) + { + jobs[i] = pThreadPool->QueueCall(this, &CParallelProcessor::DoExecute); + } + + DoExecute(); + + for (i = 0; i < nJobs; i++) + { + jobs[i]->Abort(); + jobs[i]->Release(); + } + } + else + { + DoExecute(); + } + } + + ITEM_PROCESSOR_TYPE m_ItemProcessor; + +private: + void DoExecute() + { + if (m_pItems < m_pLimit) + { +#if defined(_X360) + volatile int ignored = ID_TO_PREVENT_COMDATS_IN_PROFILES; +#endif + m_ItemProcessor.Begin(); + + ITEM_TYPE* pLimit = m_pLimit; + + int nChunkSize = m_nChunkSize; + for (;;) + { + ITEM_TYPE* pCurrent = m_pItems.AtomicAdd(nChunkSize); + ITEM_TYPE* pLast = MIN(pLimit, pCurrent + nChunkSize); + while (pCurrent < pLast) + { + m_ItemProcessor.Process(*pCurrent); + pCurrent++; + } + if (pCurrent >= pLimit) + { + break; + } + } + m_ItemProcessor.End(); + } + } + CInterlockedPtr m_pItems; + ITEM_TYPE* m_pLimit; + int m_nChunkSize; + +}; + +#pragma warning(pop) + +template +inline void ParallelProcess(ITEM_TYPE* pItems, unsigned nItems, void (*pfnProcess)(ITEM_TYPE&), void (*pfnBegin)() = NULL, void (*pfnEnd)() = NULL, int nMaxParallel = INT_MAX) +{ + CParallelProcessor > processor; + processor.m_ItemProcessor.Init(pfnProcess, pfnBegin, pfnEnd); + processor.Run(pItems, nItems, 1, nMaxParallel); +} + +template +inline void ParallelProcess(ITEM_TYPE* pItems, unsigned nItems, OBJECT_TYPE* pObject, void (FUNCTION_CLASS::* pfnProcess)(ITEM_TYPE&), void (FUNCTION_CLASS::* pfnBegin)() = NULL, void (FUNCTION_CLASS::* pfnEnd)() = NULL, int nMaxParallel = INT_MAX) +{ + CParallelProcessor > processor; + processor.m_ItemProcessor.Init(pObject, pfnProcess, pfnBegin, pfnEnd); + processor.Run(pItems, nItems, 1, nMaxParallel); +} + +template +inline void ParallelProcess(IThreadPool* pPool, ITEM_TYPE* pItems, unsigned nItems, void (*pfnProcess)(ITEM_TYPE&), void (*pfnBegin)() = NULL, void (*pfnEnd)() = NULL, int nMaxParallel = INT_MAX) +{ + CParallelProcessor > processor; + processor.m_ItemProcessor.Init(pfnProcess, pfnBegin, pfnEnd); + processor.Run(pItems, nItems, 1, nMaxParallel, pPool); +} + +template +inline void ParallelProcess(IThreadPool* pPool, ITEM_TYPE* pItems, unsigned nItems, OBJECT_TYPE* pObject, void (FUNCTION_CLASS::* pfnProcess)(ITEM_TYPE&), void (FUNCTION_CLASS::* pfnBegin)() = NULL, void (FUNCTION_CLASS::* pfnEnd)() = NULL, int nMaxParallel = INT_MAX) +{ + CParallelProcessor > processor; + processor.m_ItemProcessor.Init(pObject, pfnProcess, pfnBegin, pfnEnd); + processor.Run(pItems, nItems, 1, nMaxParallel, pPool); +} + +template +inline void ParallelProcessChunks(ITEM_TYPE* pItems, unsigned nItems, void (*pfnProcess)(ITEM_TYPE&), int nChunkSize, int nMaxParallel = INT_MAX) +{ + CParallelProcessor > processor; + processor.m_ItemProcessor.Init(pfnProcess, NULL, NULL); + processor.Run(pItems, nItems, nChunkSize, nMaxParallel); +} + +template +inline void ParallelProcessChunks(ITEM_TYPE* pItems, unsigned nItems, OBJECT_TYPE* pObject, void (FUNCTION_CLASS::* pfnProcess)(ITEM_TYPE&), int nChunkSize, int nMaxParallel = INT_MAX) +{ + CParallelProcessor > processor; + processor.m_ItemProcessor.Init(pObject, pfnProcess, NULL, NULL); + processor.Run(pItems, nItems, nChunkSize, nMaxParallel); +} + +template +inline void ParallelProcessChunks(IThreadPool* pPool, ITEM_TYPE* pItems, unsigned nItems, OBJECT_TYPE* pObject, void (FUNCTION_CLASS::* pfnProcess)(ITEM_TYPE&), int nChunkSize, int nMaxParallel = INT_MAX) +{ + CParallelProcessor > processor; + processor.m_ItemProcessor.Init(pObject, pfnProcess, NULL, NULL); + processor.Run(pItems, nItems, nChunkSize, nMaxParallel, pPool); +} + + +template +class CParallelLoopProcessor +{ +public: + CParallelLoopProcessor() + { + m_nIndex = m_nLimit = 0; + m_nChunkCount = 0; + m_nActive = 0; + } + + void Run(CONTEXT_TYPE* pContext, int nBegin, int nItems, int nChunkCount, int nMaxParallel = INT_MAX, IThreadPool* pThreadPool = NULL) + { + if (!nItems) + return; + + if (!pThreadPool) + { + pThreadPool = g_pThreadPool; + } + + m_pContext = pContext; + m_nIndex = nBegin; + m_nLimit = nBegin + nItems; + nChunkCount = MAX(MIN(nItems, nChunkCount), 1); + m_nChunkCount = (nItems + nChunkCount - 1) / nChunkCount; + int nJobs = (nItems + m_nChunkCount - 1) / m_nChunkCount; + if (nJobs > nMaxParallel) + { + nJobs = nMaxParallel; + } + + if (!pThreadPool) + { + DoExecute(); + return; + } + + int nThreads = pThreadPool->NumThreads(); + if (nJobs > nThreads) + { + nJobs = nThreads; + } + + if (nJobs > 0) + { + CJob** jobs = (CJob**)stackalloc(nJobs * sizeof(CJob**)); + int i = nJobs; + + while (i--) + { + jobs[i] = pThreadPool->QueueCall(this, &CParallelLoopProcessor::DoExecute); + } + + DoExecute(); + + for (i = 0; i < nJobs; i++) + { + jobs[i]->Abort(); + jobs[i]->Release(); + } + } + else + { + DoExecute(); + } + } + + ITEM_PROCESSOR_TYPE m_ItemProcessor; + +private: + void DoExecute() + { + m_ItemProcessor.Begin(); + for (;;) + { + int nIndex = m_nIndex.AtomicAdd(m_nChunkCount); + if (nIndex < m_nLimit) + { + int nCount = MIN(m_nChunkCount, m_nLimit - nIndex); + m_ItemProcessor.Process(m_pContext, nIndex, nCount); + } + else + { + break; + } + } + m_ItemProcessor.End(); + --m_nActive; + } + + CONTEXT_TYPE* m_pContext; + CInterlockedInt m_nIndex; + int m_nLimit; + int m_nChunkCount; + CInterlockedInt m_nActive; +}; + +template < typename CONTEXT_TYPE > +inline void ParallelLoopProcess(IThreadPool* pPool, CONTEXT_TYPE* pContext, int nStart, int nCount, void (*pfnProcess)(CONTEXT_TYPE*, int, int), void (*pfnBegin)() = NULL, void (*pfnEnd)() = NULL, int nMaxParallel = INT_MAX) +{ + CParallelLoopProcessor< CONTEXT_TYPE, CLoopFuncJobItemProcessor< CONTEXT_TYPE > > processor; + processor.m_ItemProcessor.Init(pfnProcess, pfnBegin, pfnEnd); + processor.Run(pContext, nStart, nCount, 1, nMaxParallel, pPool); +} + +template < typename CONTEXT_TYPE, typename OBJECT_TYPE, typename FUNCTION_CLASS > +inline void ParallelLoopProcess(IThreadPool* pPool, CONTEXT_TYPE* pContext, int nStart, int nCount, OBJECT_TYPE* pObject, void (FUNCTION_CLASS::* pfnProcess)(CONTEXT_TYPE*, int, int), void (FUNCTION_CLASS::* pfnBegin)() = NULL, void (FUNCTION_CLASS::* pfnEnd)() = NULL, int nMaxParallel = INT_MAX) +{ + CParallelLoopProcessor< CONTEXT_TYPE, CLoopMemberFuncJobItemProcessor > processor; + processor.m_ItemProcessor.Init(pObject, pfnProcess, pfnBegin, pfnEnd); + processor.Run(pContext, nStart, nCount, 1, nMaxParallel, pPool); +} + +template < typename CONTEXT_TYPE > +inline void ParallelLoopProcessChunks(IThreadPool* pPool, CONTEXT_TYPE* pContext, int nStart, int nCount, int nChunkSize, void (*pfnProcess)(CONTEXT_TYPE*, int, int), void (*pfnBegin)() = NULL, void (*pfnEnd)() = NULL, int nMaxParallel = INT_MAX) +{ + CParallelLoopProcessor< CONTEXT_TYPE, CLoopFuncJobItemProcessor< CONTEXT_TYPE > > processor; + processor.m_ItemProcessor.Init(pfnProcess, pfnBegin, pfnEnd); + processor.Run(pContext, nStart, nCount, nChunkSize, nMaxParallel, pPool); +} + +template < typename CONTEXT_TYPE, typename OBJECT_TYPE, typename FUNCTION_CLASS > +inline void ParallelLoopProcessChunks(IThreadPool* pPool, CONTEXT_TYPE* pContext, int nStart, int nCount, int nChunkSize, OBJECT_TYPE* pObject, void (FUNCTION_CLASS::* pfnProcess)(CONTEXT_TYPE*, int, int), void (FUNCTION_CLASS::* pfnBegin)() = NULL, void (FUNCTION_CLASS::* pfnEnd)() = NULL, int nMaxParallel = INT_MAX) +{ + CParallelLoopProcessor< CONTEXT_TYPE, CLoopMemberFuncJobItemProcessor > processor; + processor.m_ItemProcessor.Init(pObject, pfnProcess, pfnBegin, pfnEnd); + processor.Run(pContext, nStart, nCount, nChunkSize, nMaxParallel, pPool); +} + +template +class CParallelProcessorBase +{ +protected: + typedef CParallelProcessorBase ThisParallelProcessorBase_t; + typedef Derived ThisParallelProcessorDerived_t; + +public: + CParallelProcessorBase() + { + m_nActive = 0; + } + +protected: + void Run(int nMaxParallel = INT_MAX, int threadOverride = -1) + { + int i = g_pThreadPool->NumIdleThreads(); + + if (nMaxParallel < i) + { + i = nMaxParallel; + } + + while (i-- > 0) + { + if (threadOverride == -1 || i == threadOverride - 1) + { + ++m_nActive; + ThreadExecute(this, &ThisParallelProcessorBase_t::DoExecute)->Release(); + } + } + + if (threadOverride == -1 || threadOverride == 0) + { + ++m_nActive; + DoExecute(); + } + + while (m_nActive) + { + ThreadPause(); + } + } + +protected: + void OnBegin() {} + bool OnProcess() { return false; } + void OnEnd() {} + +private: + void DoExecute() + { + static_cast(this)->OnBegin(); + + while (static_cast(this)->OnProcess()) + continue; + + static_cast(this)->OnEnd(); + + --m_nActive; + } + + CInterlockedInt m_nActive; +}; + + + + +inline uintp FunctorExecuteThread(void* pParam) +{ + CFunctor* pFunctor = (CFunctor*)pParam; + (*pFunctor)(); + pFunctor->Release(); + return 0; +} + +inline ThreadHandle_t ThreadExecuteSoloImpl(CFunctor* pFunctor, const char* pszName = NULL); + + +inline ThreadHandle_t ThreadExecuteSolo(CJob* pJob) { return ThreadExecuteSoloImpl(CreateFunctor(pJob, &CJob::Execute), pJob->Describe()); } + +template +inline ThreadHandle_t ThreadExecuteSolo(const char* pszName, T1 a1) { return ThreadExecuteSoloImpl(CreateFunctor(a1), pszName); } + +template +inline ThreadHandle_t ThreadExecuteSolo(const char* pszName, T1 a1, T2 a2) { return ThreadExecuteSoloImpl(CreateFunctor(a1, a2), pszName); } + +template +inline ThreadHandle_t ThreadExecuteSolo(const char* pszName, T1 a1, T2 a2, T3 a3) { return ThreadExecuteSoloImpl(CreateFunctor(a1, a2, a3), pszName); } + +template +inline ThreadHandle_t ThreadExecuteSolo(const char* pszName, T1 a1, T2 a2, T3 a3, T4 a4) { return ThreadExecuteSoloImpl(CreateFunctor(a1, a2, a3, a4), pszName); } + +template +inline ThreadHandle_t ThreadExecuteSolo(const char* pszName, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) { return ThreadExecuteSoloImpl(CreateFunctor(a1, a2, a3, a4, a5), pszName); } + +template +inline ThreadHandle_t ThreadExecuteSolo(const char* pszName, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6) { return ThreadExecuteSoloImpl(CreateFunctor(a1, a2, a3, a4, a5, a6), pszName); } + +template +inline ThreadHandle_t ThreadExecuteSolo(const char* pszName, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7) { return ThreadExecuteSoloImpl(CreateFunctor(a1, a2, a3, a4, a5, a6, a7), pszName); } + +template +inline ThreadHandle_t ThreadExecuteSolo(const char* pszName, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8) { return ThreadExecuteSoloImpl(CreateFunctor(a1, a2, a3, a4, a5, a6, a7, a8), pszName); } + +template +inline ThreadHandle_t ThreadExecuteSoloRef(const char* pszName, T1 a1, T2 a2) { return ThreadExecuteSoloImpl(CreateRefCountingFunctor(a1, a2), pszName); } + +template +inline ThreadHandle_t ThreadExecuteSoloRef(const char* pszName, T1 a1, T2 a2, T3 a3) { return ThreadExecuteSoloImpl(CreateRefCountingFunctor(a1, a2, a3), pszName); } + +template +inline ThreadHandle_t ThreadExecuteSoloRef(const char* pszName, T1 a1, T2 a2, T3 a3, T4 a4) { return ThreadExecuteSoloImpl(CreateRefCountingFunctor(a1, a2, a3, a4), pszName); } + +template +inline ThreadHandle_t ThreadExecuteSoloRef(const char* pszName, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) { return ThreadExecuteSoloImpl(CreateRefCountingFunctor(a1, a2, a3, a4, a5), pszName); } + +template +inline ThreadHandle_t ThreadExecuteSoloRef(const char* pszName, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6) { return ThreadExecuteSoloImpl(CreateRefCountingFunctor(a1, a2, a3, a4, a5, a6), pszName); } + +template +inline ThreadHandle_t ThreadExecuteSoloRef(const char* pszName, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7) { return ThreadExecuteSoloImpl(CreateRefCountingFunctor(a1, a2, a3, a4, a5, a6, a7), pszName); } + +template +inline ThreadHandle_t ThreadExecuteSoloRef(const char* pszName, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8) { return ThreadExecuteSoloImpl(CreateRefCountingFunctor(a1, a2, a3, a4, a5, a6, a7, a8), pszName); } + +inline bool IThreadPool::YieldWait(CThreadEvent& theEvent, unsigned timeout) +{ + CThreadEvent* pEvent = &theEvent; + return (YieldWait(&pEvent, 1, true, timeout) != TW_TIMEOUT); +} + +inline bool IThreadPool::YieldWait(CJob* pJob, unsigned timeout) +{ + return (YieldWait(&pJob, 1, true, timeout) != TW_TIMEOUT); +} + +inline JobStatus_t CJob::Execute() +{ + if (IsFinished()) + { + return m_status; + } + + AUTO_LOCK(m_mutex); + AddRef(); + + JobStatus_t result; + + switch (m_status) + { + case JOB_STATUS_UNSERVICED: + case JOB_STATUS_PENDING: + { + m_status = JOB_STATUS_INPROGRESS; + +#if defined( THREAD_PARENT_STACK_TRACE_ENABLED ) + { + CStackTop_ReferenceParentStack stackTop(m_ParentStackTrace, ARRAYSIZE(m_ParentStackTrace)); + result = m_status = DoExecute(); + } +#else + result = m_status = DoExecute(); +#endif + + DoCleanup(); + m_CompleteEvent.Set(); + break; + } + + case JOB_STATUS_INPROGRESS: + AssertMsg(0, "Mutex Should have protected use while processing"); + case JOB_OK: + case JOB_STATUS_ABORTED: + result = m_status; + break; + + default: + AssertMsg(m_status < JOB_OK, "Unknown job state"); + result = m_status; + } + + Release(); + + return result; +} + + +inline JobStatus_t CJob::TryExecute() +{ + if (!IsFinished() && TryLock()) + { + Execute(); + Unlock(); + } + return m_status; +} + +inline JobStatus_t CJob::Abort(bool bDiscard) +{ + if (IsFinished()) + { + return m_status; + } + + AUTO_LOCK(m_mutex); + AddRef(); + + JobStatus_t result; + + switch (m_status) + { + case JOB_STATUS_UNSERVICED: + case JOB_STATUS_PENDING: + { + result = m_status = DoAbort(bDiscard); + if (bDiscard) + DoCleanup(); + m_CompleteEvent.Set(); + } + break; + + case JOB_STATUS_ABORTED: + case JOB_STATUS_INPROGRESS: + case JOB_OK: + result = m_status; + break; + + default: + AssertMsg(m_status < JOB_OK, "Unknown job state"); + result = m_status; + } + + Release(); + + return result; +} + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/keyvalues.h b/SpyCustom/sdk/keyvalues.h new file mode 100644 index 0000000..ad5c2d2 --- /dev/null +++ b/SpyCustom/sdk/keyvalues.h @@ -0,0 +1,420 @@ +#ifndef KEYVALUES_H +#define KEYVALUES_H + +#ifdef _WIN32 +#pragma once +#endif + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#include "utlvector.h" +#include "color.h" +#include "exprevaluator.h" + +#define TRACK_KV_ADD( ptr, name ) track.AddKv( ptr, name ) +#define SPLIT_3_BYTES_INTO_1_AND_2( x1, x2, x3 ) do { x1 = (uint8)(x3); x2 = (uint16)( (x3) >> 8 ); } while( 0 ) + + +#define FOR_EACH_SUBKEY( kvRoot, kvSubKey ) \ + for ( KeyValues * kvSubKey = kvRoot->GetFirstSubKey(); kvSubKey != NULL; kvSubKey = kvSubKey->GetNextKey() ) + +#define FOR_EACH_TRUE_SUBKEY( kvRoot, kvSubKey ) \ + for ( KeyValues * kvSubKey = kvRoot->GetFirstTrueSubKey(); kvSubKey != NULL; kvSubKey = kvSubKey->GetNextTrueSubKey() ) + +#define FOR_EACH_VALUE( kvRoot, kvValue ) \ + for ( KeyValues * kvValue = kvRoot->GetFirstValue(); kvValue != NULL; kvValue = kvValue->GetNextValue() ) + + +class IBaseFileSystem; +class CUtlBuffer; +class Color; +class CKeyValuesTokenReader; +class KeyValues; +class IKeyValuesDumpContext; +typedef void* FileHandle_t; +class CKeyValuesGrowableStringTable; + + +#define KV_BINARY_POOLED_FORMAT 0xAA + + +#define FOR_EACH_SUBKEY( kvRoot, kvSubKey ) \ + for ( KeyValues * kvSubKey = kvRoot->GetFirstSubKey(); kvSubKey != NULL; kvSubKey = kvSubKey->GetNextKey() ) + +#define FOR_EACH_TRUE_SUBKEY( kvRoot, kvSubKey ) \ + for ( KeyValues * kvSubKey = kvRoot->GetFirstTrueSubKey(); kvSubKey != NULL; kvSubKey = kvSubKey->GetNextTrueSubKey() ) + +#define FOR_EACH_VALUE( kvRoot, kvValue ) \ + for ( KeyValues * kvValue = kvRoot->GetFirstValue(); kvValue != NULL; kvValue = kvValue->GetNextValue() ) + + +class KeyValues +{ + friend class CKeyValuesTokenReader; + +public: + static void SetUseGrowableStringTable(bool bUseGrowableTable); + + explicit KeyValues(const char* setName); + + class AutoDelete + { + public: + explicit inline AutoDelete(KeyValues* pKeyValues) : m_pKeyValues(pKeyValues) {} + explicit inline AutoDelete(const char* pchKVName) : m_pKeyValues(new KeyValues(pchKVName)) {} + inline ~AutoDelete(void) { delete m_pKeyValues; } + inline void Assign(KeyValues* pKeyValues) { m_pKeyValues = pKeyValues; } + inline KeyValues* Detach() { KeyValues* retval = m_pKeyValues; Assign(NULL); return retval; } + KeyValues* operator->() { return m_pKeyValues; } + operator KeyValues* () { return m_pKeyValues; } + private: + AutoDelete(AutoDelete const& x); + AutoDelete& operator= (AutoDelete const& x); + protected: + KeyValues* m_pKeyValues; + }; + + class AutoDeleteInline : public AutoDelete + { + public: + explicit inline AutoDeleteInline(KeyValues* pKeyValues) : AutoDelete(pKeyValues) {} + inline operator KeyValues* () const { return m_pKeyValues; } + inline KeyValues* Get() const { return m_pKeyValues; } + }; + + KeyValues(const char* setName, const char* firstKey, const char* firstValue); + KeyValues(const char* setName, const char* firstKey, const wchar_t* firstValue); + KeyValues(const char* setName, const char* firstKey, int firstValue); + KeyValues(const char* setName, const char* firstKey, const char* firstValue, const char* secondKey, const char* secondValue); + KeyValues(const char* setName, const char* firstKey, int firstValue, const char* secondKey, int secondValue); + + ~KeyValues(); + + const char* GetName() const; + void SetName(const char* setName); + + int GetNameSymbol() const; + int GetNameSymbolCaseSensitive() const; + + void UsesEscapeSequences(bool state); + bool LoadFromFile(IBaseFileSystem* filesystem, const char* resourceName, const char* pathID = NULL); + + bool SaveToFile(IBaseFileSystem* filesystem, const char* resourceName, const char* pathID = NULL, bool bWriteEmptySubkeys = false); + + bool LoadFromBuffer(char const* resourceName, const char* pBuffer, IBaseFileSystem* pFileSystem = NULL, const char* pPathID = NULL); + + bool LoadFromBuffer(char const* resourceName, CUtlBuffer& buf, IBaseFileSystem* pFileSystem = NULL, const char* pPathID = NULL); + + + + KeyValues* FindKey(const char* keyName, bool bCreate = false); + KeyValues* FindKey(int keySymbol) const; + KeyValues* CreateNewKey(); + void AddSubKey(KeyValues* pSubkey); + void RemoveSubKey(KeyValues* subKey); + void InsertSubKey(int nIndex, KeyValues* pSubKey); + bool ContainsSubKey(KeyValues* pSubKey); + void SwapSubKey(KeyValues* pExistingSubKey, KeyValues* pNewSubKey); + void ElideSubKey(KeyValues* pSubKey); + KeyValues* CreateKey(const char* keyName); + KeyValues* CreatePeerKey(const char* keyName); + + KeyValues* GetFirstSubKey() { return m_pSub; } + KeyValues* GetNextKey() { return m_pPeer; } + void SetNextKey(KeyValues* pDat); + + KeyValues* FindLastSubKey(); + + KeyValues* GetFirstTrueSubKey(); + KeyValues* GetNextTrueSubKey(); + + KeyValues* GetFirstValue(); + KeyValues* GetNextValue(); + + + int GetInt(const char* keyName = NULL, int defaultValue = 0); + uint64 GetUint64(const char* keyName = NULL, uint64 defaultValue = 0); + float GetFloat(const char* keyName = NULL, float defaultValue = 0.0f); + const char* GetString(const char* keyName = NULL, const char* defaultValue = ""); + const wchar_t* GetWString(const char* keyName = NULL, const wchar_t* defaultValue = L""); + void* GetPtr(const char* keyName = NULL, void* defaultValue = (void*)0); + Color GetColor(const char* keyName = NULL, const Color& defaultColor = Color(0, 0, 0, 0)); + bool GetBool(const char* keyName = NULL, bool defaultValue = false) { return GetInt(keyName, defaultValue ? 1 : 0) ? true : false; } + bool IsEmpty(const char* keyName = NULL); + + int GetInt(int keySymbol, int defaultValue = 0); + uint64 GetUint64(int keySymbol, uint64 defaultValue = 0); + float GetFloat(int keySymbol, float defaultValue = 0.0f); + const char* GetString(int keySymbol, const char* defaultValue = ""); + const wchar_t* GetWString(int keySymbol, const wchar_t* defaultValue = L""); + void* GetPtr(int keySymbol, void* defaultValue = (void*)0); + Color GetColor(int keySymbol ); + bool GetBool(int keySymbol, bool defaultValue = false) { return GetInt(keySymbol, defaultValue ? 1 : 0) ? true : false; } + bool IsEmpty(int keySymbol); + + void SetWString(const char* keyName, const wchar_t* value); + void SetString(const char* keyName, const char* value); + void SetInt(const char* keyName, int value); + void SetUint64(const char* keyName, uint64 value); + void SetFloat(const char* keyName, float value); + void SetPtr(const char* keyName, void* value); + void SetColor(const char* keyName, Color value); + void SetBool(const char* keyName, bool value) { SetInt(keyName, value ? 1 : 0); } + + void* operator new(size_t iAllocSize); + void* operator new(size_t iAllocSize, int nBlockUse, const char* pFileName, int nLine); + void operator delete(void* pMem); + void operator delete(void* pMem, int nBlockUse, const char* pFileName, int nLine); + + KeyValues& operator=(KeyValues& src); + + bool IsEqual(KeyValues* pRHS); + + void ChainKeyValue(KeyValues* pChain); + + void RecursiveSaveToFile(CUtlBuffer& buf, int indentLevel); + + bool WriteAsBinary(CUtlBuffer& buffer) const; + bool ReadAsBinary(CUtlBuffer& buffer, int nStackDepth = 0); + + bool WriteAsBinaryFiltered(CUtlBuffer& buffer); + bool ReadAsBinaryFiltered(CUtlBuffer& buffer, int nStackDepth = 0); + + KeyValues* MakeCopy(void) const; + + void CopySubkeys(KeyValues* pParent) const; + + void Clear(void); + + enum types_t + { + TYPE_NONE = 0, + TYPE_STRING, + TYPE_INT, + TYPE_FLOAT, + TYPE_PTR, + TYPE_WSTRING, + TYPE_COLOR, + TYPE_UINT64, + TYPE_COMPILED_INT_BYTE, + TYPE_COMPILED_INT_0, + TYPE_COMPILED_INT_1, + TYPE_NUMTYPES, + }; + types_t GetDataType(const char* keyName = NULL); + types_t GetDataType() const; + + void deleteThis(); + + void SetStringValue(char const* strValue); + + void UnpackIntoStructure(struct KeyValuesUnpackStructure const* pUnpackTable, void* pDest); + + bool ProcessResolutionKeys(const char* pResString); + + bool Dump(IKeyValuesDumpContext* pDump, int nIndentLevel = 0); + + enum MergeKeyValuesOp_t + { + MERGE_KV_ALL, + MERGE_KV_UPDATE, + MERGE_KV_DELETE, + MERGE_KV_BORROW, + }; + void MergeFrom(KeyValues* kvMerge, MergeKeyValuesOp_t eOp = MERGE_KV_ALL); + + static KeyValues* FromString(char const* szName, char const* szStringVal, char const** ppEndOfParse = NULL); + + KeyValues* CreateKeyUsingKnownLastChild(const char* keyName, KeyValues* pLastChild); + void AddSubkeyUsingKnownLastChild(KeyValues* pSubKey, KeyValues* pLastChild); + + KeyValues(KeyValues&); + + + void RecursiveCopyKeyValues(KeyValues& src); + void RemoveEverything(); + void RecursiveSaveToFile(IBaseFileSystem* filesystem, FileHandle_t f, CUtlBuffer* pBuf, int indentLevel, bool bWriteEmptySubkeys = false); + void WriteConvertedString(IBaseFileSystem* filesystem, FileHandle_t f, CUtlBuffer* pBuf, const char* pszString); + + void RecursiveLoadFromBuffer(char const* resourceName, CUtlBuffer& buf); + + void AppendIncludedKeys(CUtlVector< KeyValues* >& includedKeys); + void ParseIncludedKeys(char const* resourceName, const char* filetoinclude, + IBaseFileSystem* pFileSystem, const char* pPathID, CUtlVector< KeyValues* >& includedKeys); + + void MergeBaseKeys(CUtlVector< KeyValues* >& baseKeys); + void RecursiveMergeKeyValues(KeyValues* baseKV); + + void InternalWrite(IBaseFileSystem* filesystem, FileHandle_t f, CUtlBuffer* pBuf, const void* pData, int len); + + void Init(); + const char* ReadToken(CUtlBuffer& buf, bool& wasQuoted, bool& wasConditional); + void WriteIndents(IBaseFileSystem* filesystem, FileHandle_t f, CUtlBuffer* pBuf, int indentLevel); + + void FreeAllocatedValue(); + void AllocateValueBlock(int size); + + bool ReadAsBinaryPooledFormat(CUtlBuffer& buf, IBaseFileSystem* pFileSystem, unsigned int poolKey, GetSymbolProc_t pfnEvaluateSymbolProc); + + bool EvaluateConditional(const char* str); + + uint32 m_iKeyName : 24; + uint32 m_iKeyNameCaseSensitive1 : 8; + + char* m_sValue; + wchar_t* m_wsValue; + + union + { + int m_iValue; + float m_flValue; + void* m_pValue; + unsigned char m_Color[4]; + }; + + char m_iDataType; + char m_bHasEscapeSequences; + uint16 m_iKeyNameCaseSensitive2; + + KeyValues* m_pPeer; + KeyValues* m_pSub; + KeyValues* m_pChain; + + GetSymbolProc_t m_pExpressionGetSymbolProc; + +private: + static int (*s_pfGetSymbolForString)(const char* name, bool bCreate); + static const char* (*s_pfGetStringForSymbol)(int symbol); + static CKeyValuesGrowableStringTable* s_pGrowableStringTable; + +public: + static int GetSymbolForStringClassic(const char* name, bool bCreate = true); + static const char* GetStringForSymbolClassic(int symbol); + + static int GetSymbolForStringGrowable(const char* name, bool bCreate = true); + static const char* GetStringForSymbolGrowable(int symbol); +}; + +typedef KeyValues::AutoDelete KeyValuesAD; + +enum KeyValuesUnpackDestinationTypes_t +{ + UNPACK_TYPE_FLOAT, + UNPACK_TYPE_VECTOR, + UNPACK_TYPE_VECTOR_COLOR, + UNPACK_TYPE_STRING, + UNPACK_TYPE_INT, + UNPACK_TYPE_FOUR_FLOATS, + UNPACK_TYPE_TWO_FLOATS, +}; + +#define UNPACK_FIXED( kname, kdefault, dtype, ofs ) { kname, kdefault, dtype, ofs, 0 } +#define UNPACK_VARIABLE( kname, kdefault, dtype, ofs, sz ) { kname, kdefault, dtype, ofs, sz } +#define UNPACK_END_MARKER { NULL, NULL, UNPACK_TYPE_FLOAT, 0 } + +struct KeyValuesUnpackStructure +{ + char const* m_pKeyName; + char const* m_pKeyDefault; + KeyValuesUnpackDestinationTypes_t m_eDataType; + size_t m_nFieldOffset; + size_t m_nFieldSize; +}; + +inline int KeyValues::GetInt(int keySymbol, int defaultValue) +{ + KeyValues* dat = FindKey(keySymbol); + return dat ? dat->GetInt((const char*)NULL, defaultValue) : defaultValue; +} + +inline uint64 KeyValues::GetUint64(int keySymbol, uint64 defaultValue) +{ + KeyValues* dat = FindKey(keySymbol); + return dat ? dat->GetUint64((const char*)NULL, defaultValue) : defaultValue; +} + +inline float KeyValues::GetFloat(int keySymbol, float defaultValue) +{ + KeyValues* dat = FindKey(keySymbol); + return dat ? dat->GetFloat((const char*)NULL, defaultValue) : defaultValue; +} + +inline const char* KeyValues::GetString(int keySymbol, const char* defaultValue) +{ + KeyValues* dat = FindKey(keySymbol); + return dat ? dat->GetString((const char*)NULL, defaultValue) : defaultValue; +} + +inline const wchar_t* KeyValues::GetWString(int keySymbol, const wchar_t* defaultValue) +{ + KeyValues* dat = FindKey(keySymbol); + return dat ? dat->GetWString((const char*)NULL, defaultValue) : defaultValue; +} + +inline void* KeyValues::GetPtr(int keySymbol, void* defaultValue) +{ + KeyValues* dat = FindKey(keySymbol); + return dat ? dat->GetPtr((const char*)NULL, defaultValue) : defaultValue; +} + +inline Color KeyValues::GetColor(int keySymbol) +{ + Color defaultValue(0, 0, 0, 0); + KeyValues* dat = FindKey(keySymbol); + return dat ? dat->GetColor() : defaultValue; +} + +inline bool KeyValues::IsEmpty(int keySymbol) +{ + KeyValues* dat = FindKey(keySymbol); + return dat ? dat->IsEmpty() : true; +} + + +class IKeyValuesDumpContext +{ +public: + virtual bool KvBeginKey(KeyValues* pKey, int nIndentLevel) = 0; + virtual bool KvWriteValue(KeyValues* pValue, int nIndentLevel) = 0; + virtual bool KvEndKey(KeyValues* pKey, int nIndentLevel) = 0; +}; + +class IKeyValuesDumpContextAsText : public IKeyValuesDumpContext +{ +public: + virtual bool KvBeginKey(KeyValues* pKey, int nIndentLevel); + virtual bool KvWriteValue(KeyValues* pValue, int nIndentLevel); + virtual bool KvEndKey(KeyValues* pKey, int nIndentLevel); + +public: + virtual bool KvWriteIndent(int nIndentLevel); + virtual bool KvWriteText(char const* szText) = 0; +}; + +class CKeyValuesDumpContextAsDevMsg : public IKeyValuesDumpContextAsText +{ +public: + CKeyValuesDumpContextAsDevMsg(int nDeveloperLevel = 1) : m_nDeveloperLevel(nDeveloperLevel) {} + +public: + virtual bool KvBeginKey(KeyValues* pKey, int nIndentLevel); + virtual bool KvWriteText(char const* szText); + +protected: + int m_nDeveloperLevel; +}; + +inline bool KeyValuesDumpAsDevMsg(KeyValues* pKeyValues, int nIndentLevel = 0, int nDeveloperLevel = 1) +{ + CKeyValuesDumpContextAsDevMsg ctx(nDeveloperLevel); + return pKeyValues->Dump(&ctx, nIndentLevel); +} + + +#endif \ No newline at end of file diff --git a/SpyCustom/sdk/l2cache.h b/SpyCustom/sdk/l2cache.h new file mode 100644 index 0000000..8e9d523 --- /dev/null +++ b/SpyCustom/sdk/l2cache.h @@ -0,0 +1,38 @@ +#ifndef CL2CACHE_H +#define CL2CACHE_H +#ifdef _WIN32 +#pragma once +#endif + +class P4Event_BSQ_cache_reference; + +class CL2Cache +{ +public: + + CL2Cache(); + ~CL2Cache(); + + void Start(void); + void End(void); + + int GetL2CacheMisses(void) + { + return m_iL2CacheMissCount; + } + +#ifdef DBGFLAG_VALIDATE + void Validate(CValidator& validator, tchar* pchName); +#endif + +private: + + int m_nID; + + P4Event_BSQ_cache_reference* m_pL2CacheEvent; + int64 m_i64Start; + int64 m_i64End; + int m_iL2CacheMissCount; +}; + +#endif diff --git a/SpyCustom/sdk/lerp_functions.h b/SpyCustom/sdk/lerp_functions.h new file mode 100644 index 0000000..659df5d --- /dev/null +++ b/SpyCustom/sdk/lerp_functions.h @@ -0,0 +1,157 @@ +#ifndef LERP_FUNCTIONS_H +#define LERP_FUNCTIONS_H +#ifdef _WIN32 +#pragma once +#endif + + +template +inline T LoopingLerp(float flPercent, T flFrom, T flTo) +{ + T s = flTo * flPercent + flFrom * (1.0f - flPercent); + return s; +} + +template <> +inline float LoopingLerp(float flPercent, float flFrom, float flTo) +{ + if (fabs(flTo - flFrom) >= 0.5f) + { + if (flFrom < flTo) + flFrom += 1.0f; + else + flTo += 1.0f; + } + + float s = flTo * flPercent + flFrom * (1.0f - flPercent); + + s = s - (int)(s); + if (s < 0.0f) + s = s + 1.0f; + + return s; +} + +template +inline T Lerp_Hermite(const T& , float t, const T& p0, const T& p1, const T& p2) +{ + T d1 = p1 - p0; + T d2 = p2 - p1; + + T output; + float tSqr = t * t; + float tCube = t * tSqr; + + output = p1 * (2 * tCube - 3 * tSqr + 1); + output += p2 * (-2 * tCube + 3 * tSqr); + output += d1 * (tCube - 2 * tSqr + t); + output += d2 * (tCube - tSqr); + + return output; +} + + +template +inline T Derivative_Hermite(float t, const T& p0, const T& p1, const T& p2) +{ + T d1 = p1 - p0; + T d2 = p2 - p1; + + T output; + float tSqr = t * t; + + output = p1 * (6 * tSqr - 6 * t); + output += p2 * (-6 * tSqr + 6 * t); + output += d1 * (3 * tSqr - 4 * t + 1); + output += d2 * (3 * tSqr - 2 * t); + + return output; +} + + +inline void Lerp_Clamp(int val) +{ +} + +inline void Lerp_Clamp(float val) +{ +} + +inline void Lerp_Clamp(const Vector& val) +{ +} + +inline void Lerp_Clamp(const QAngle& val) +{ +} + + +template< class T, int minValue, int maxValue, int startValue > +inline void Lerp_Clamp(CRangeCheckedVar& val) +{ + val.Clamp(); +} + + +template<> +inline QAngle Lerp_Hermite(const QAngle&, float t, const QAngle& p0, const QAngle& p1, const QAngle& p2) +{ + return Lerp(t, p1, p2); +} + +template +inline T LoopingLerp_Hermite(T current, float t, T p0, T p1, T p2) +{ + return Lerp_Hermite(current, t, p0, p1, p2); +} + +template <> +inline float LoopingLerp_Hermite(float , float t, float p0, float p1, float p2) +{ + if (fabs(p1 - p0) > 0.5f) + { + if (p0 < p1) + p0 += 1.0f; + else + p1 += 1.0f; + } + + if (fabs(p2 - p1) > 0.5f) + { + if (p1 < p2) + { + p1 += 1.0f; + + if (abs(p1 - p0) > 0.5) + { + if (p0 < p1) + p0 += 1.0f; + else + p1 += 1.0f; + } + } + else + { + p2 += 1.0f; + } + } + + float s = Lerp_Hermite( 0.0f, t, p0, p1, p2); + + s = s - (int)(s); + if (s < 0.0f) + { + s = s + 1.0f; + } + + return s; +} + +template< int minValue, int maxValue, int startValue > +inline CRangeCheckedVar LoopingLerp_Hermite(CRangeCheckedVar current, float t, CRangeCheckedVar p0, CRangeCheckedVar p1, CRangeCheckedVar p2) +{ + return LoopingLerp_Hermite((float)current, t, (float)p0, (float)p1, (float)p2); +} + + +#endif \ No newline at end of file