summaryrefslogtreecommitdiff
path: root/cheat/tf2/dt_recv.h
diff options
context:
space:
mode:
authorboris <wzn@moneybot.cc>2018-11-28 16:00:02 +1300
committerboris <wzn@moneybot.cc>2018-11-28 16:00:02 +1300
commit3d412a4b30a9f7c7f51ea6562e694315948bd3da (patch)
tree26d67dfd1f3e5fd12903ad13e85d0cb8bcf8f21c /cheat/tf2/dt_recv.h
parente4729e4393d90271a3814c7a79950a660c48325a (diff)
cleaned up
in short, the cheat and loader are now separate solutions. unused stuff was moved into the legacy solution in case anyone wants to compile it or whatever. i can change this back if you want to. also, i configured the loader to compile in x64, and have separate build types for linux and win64
Diffstat (limited to 'cheat/tf2/dt_recv.h')
-rw-r--r--cheat/tf2/dt_recv.h479
1 files changed, 479 insertions, 0 deletions
diff --git a/cheat/tf2/dt_recv.h b/cheat/tf2/dt_recv.h
new file mode 100644
index 0000000..47f945b
--- /dev/null
+++ b/cheat/tf2/dt_recv.h
@@ -0,0 +1,479 @@
+#pragma once
+
+#include "dt_common.h"
+
+#define ADDRESSPROXY_NONE -1
+
+class RecvTable;
+class RecvProp;
+
+/*
+// This is passed into RecvProxy functions.
+class CRecvProxyData
+{
+public:
+ const RecvProp* m_pRecvProp; // The property it's receiving.
+ DVariant m_Value; // The value given to you to store.
+ int m_iElement; // Which array element you're getting.
+ int m_ObjectID; // The object being referred to.
+};
+*/
+
+struct CRecvProxyData {
+ const RecvProp* m_pRecvProp;
+ DVariant m_Value;
+ int m_iElement;
+ int m_ObjectID;
+};
+
+//-----------------------------------------------------------------------------
+// pStruct = the base structure of the datatable this variable is in (like C_BaseEntity)
+// pOut = the variable that this this proxy represents (like C_BaseEntity::m_SomeValue).
+//
+// Convert the network-standard-type value in m_Value into your own format in pStruct/pOut.
+//-----------------------------------------------------------------------------
+typedef void (*RecvVarProxyFn)(const CRecvProxyData* pData, void* pStruct, void* pOut);
+
+// ------------------------------------------------------------------------ //
+// ArrayLengthRecvProxies are optionally used to get the length of the
+// incoming array when it changes.
+// ------------------------------------------------------------------------ //
+typedef void (*ArrayLengthRecvProxyFn)(void* pStruct, int objectID, int currentArrayLength);
+
+// NOTE: DataTable receive proxies work differently than the other proxies.
+// pData points at the object + the recv table's offset.
+// pOut should be set to the location of the object to unpack the data table into.
+// If the parent object just contains the child object, the default proxy just does *pOut = pData.
+// If the parent object points at the child object, you need to dereference the pointer here.
+// NOTE: don't ever return null from a DataTable receive proxy function. Bad things will happen.
+typedef void (*DataTableRecvVarProxyFn)(const RecvProp* pProp, void** pOut, void* pData, int objectID);
+
+// This is used to fork over the standard proxy functions to the engine so it can
+// make some optimizations.
+class CStandardRecvProxies
+{
+public:
+ CStandardRecvProxies();
+
+ RecvVarProxyFn m_Int32ToInt8;
+ RecvVarProxyFn m_Int32ToInt16;
+ RecvVarProxyFn m_Int32ToInt32;
+ RecvVarProxyFn m_FloatToFloat;
+ RecvVarProxyFn m_VectorTovec3_t;
+};
+
+extern CStandardRecvProxies g_StandardRecvProxies;
+
+class CRecvDecoder;
+
+class RecvProp
+{
+ // This info comes from the receive data table.
+public:
+ RecvProp();
+
+ void InitArray(int nElements, int elementStride);
+
+ int GetNumElements() const;
+ void SetNumElements(int nElements);
+
+ int GetElementStride() const;
+ void SetElementStride(int stride);
+
+ int GetFlags() const;
+
+ const char* GetName() const;
+ SendPropType GetType() const;
+
+ RecvTable* GetDataTable() const;
+ void SetDataTable(RecvTable* pTable);
+
+ RecvVarProxyFn GetProxyFn() const;
+ void SetProxyFn(RecvVarProxyFn fn);
+
+ DataTableRecvVarProxyFn GetDataTableProxyFn() const;
+ void SetDataTableProxyFn(DataTableRecvVarProxyFn fn);
+
+ int GetOffset() const;
+ void SetOffset(int o);
+
+ // Arrays only.
+ RecvProp* GetArrayProp() const;
+ void SetArrayProp(RecvProp* pProp);
+
+ // Arrays only.
+ void SetArrayLengthProxy(ArrayLengthRecvProxyFn proxy);
+ ArrayLengthRecvProxyFn GetArrayLengthProxy() const;
+
+ bool IsInsideArray() const;
+ void SetInsideArray();
+
+ // Some property types bind more data to the prop in here.
+ const void* GetExtraData() const;
+ void SetExtraData(const void* pData);
+
+ // If it's one of the numbered "000", "001", etc properties in an array, then
+ // these can be used to get its array property name for debugging.
+ const char* GetParentArrayPropName();
+ void SetParentArrayPropName(const char* pArrayPropName);
+
+public:
+ const char* m_pVarName;
+ SendPropType m_RecvType;
+ int m_Flags;
+ int m_StringBufferSize;
+
+ bool m_bInsideArray; // Set to true by the engine if this property sits inside an array.
+
+ // Extra data that certain special property types bind to the property here.
+ const void* m_pExtraData;
+
+ // If this is an array (DPT_Array).
+ RecvProp* m_pArrayProp;
+ ArrayLengthRecvProxyFn m_ArrayLengthProxy;
+
+ RecvVarProxyFn m_ProxyFn;
+ DataTableRecvVarProxyFn m_DataTableProxyFn; // For RDT_DataTable.
+
+ RecvTable* m_pDataTable; // For RDT_DataTable.
+ int m_Offset;
+
+ int m_ElementStride;
+ int m_nElements;
+
+ // If it's one of the numbered "000", "001", etc properties in an array, then
+ // these can be used to get its array property name for debugging.
+ const char* m_pParentArrayPropName;
+};
+
+class RecvTable
+{
+public:
+ using PropType = RecvProp;
+
+ RecvTable();
+ RecvTable(RecvProp* pProps, int nProps, const char* pNetTableName);
+ ~RecvTable();
+
+ void Construct(RecvProp* pProps, int nProps, const char* pNetTableName);
+
+ int GetNumProps();
+ RecvProp* GetProp(int i);
+
+ const char* GetName();
+
+ // Used by the engine while initializing array props.
+ void SetInitialized(bool bInitialized);
+ bool IsInitialized() const;
+
+ // Used by the engine.
+ void SetInMainList(bool bInList);
+ bool IsInMainList() const;
+
+public:
+ // Properties described in a table.
+ RecvProp* m_pProps;
+ int m_nProps;
+
+ // The decoder. NOTE: this covers each RecvTable AND all its children (ie: its children
+ // will have their own decoders that include props for all their children).
+ CRecvDecoder* m_pDecoder;
+
+ const char* m_pNetTableName; // The name matched between client and server.
+
+private:
+ bool m_bInitialized;
+ bool m_bInMainList;
+};
+
+inline int RecvTable::GetNumProps()
+{
+ return m_nProps;
+}
+
+inline RecvProp* RecvTable::GetProp(int i)
+{
+ // Assert( i >= 0 && i < m_nProps );
+ return &m_pProps[i];
+}
+
+inline const char* RecvTable::GetName()
+{
+ return m_pNetTableName;
+}
+
+inline void RecvTable::SetInitialized(bool bInitialized)
+{
+ m_bInitialized = bInitialized;
+}
+
+inline bool RecvTable::IsInitialized() const
+{
+ return m_bInitialized;
+}
+
+inline void RecvTable::SetInMainList(bool bInList)
+{
+ m_bInMainList = bInList;
+}
+
+inline bool RecvTable::IsInMainList() const
+{
+ return m_bInMainList;
+}
+
+#define RECVINFO(varName) #varName, offsetof(currentRecvDTClass, varName), sizeof(((currentRecvDTClass*)0)->varName)
+#define RECVINFO_NAME(varName, remoteVarName) #remoteVarName, offsetof(currentRecvDTClass, varName), sizeof(((currentRecvDTClass*)0)->varName)
+#define RECVINFO_STRING(varName) #varName, offsetof(currentRecvDTClass, varName), STRINGBUFSIZE(currentRecvDTClass, varName)
+#define RECVINFO_BASECLASS(tableName) RecvPropDataTable("this", 0, 0, &REFERENCE_RECV_TABLE(tableName))
+#define RECVINFO_ARRAY(varName) #varName, offsetof(currentRecvDTClass, varName), sizeof(((currentRecvDTClass*)0)->varName[0]), sizeof(((currentRecvDTClass*)0)->varName)/sizeof(((currentRecvDTClass*)0)->varName[0])
+
+// Just specify the name and offset. Used for strings and data tables.
+#define RECVINFO_NOSIZE(varName) #varName, offsetof(currentRecvDTClass, varName)
+#define RECVINFO_DT(varName) RECVINFO_NOSIZE(varName)
+#define RECVINFO_DTNAME(varName,remoteVarName) #remoteVarName, offsetof(currentRecvDTClass, varName)
+
+void RecvProxy_FloatToFloat(const CRecvProxyData* pData, void* pStruct, void* pOut);
+void RecvProxy_VectorToVector(const CRecvProxyData* pData, void* pStruct, void* pOut);
+void RecvProxy_QuaternionToQuaternion(const CRecvProxyData* pData, void* pStruct, void* pOut);
+void RecvProxy_Int32ToInt8(const CRecvProxyData* pData, void* pStruct, void* pOut);
+void RecvProxy_Int32ToInt16(const CRecvProxyData* pData, void* pStruct, void* pOut);
+void RecvProxy_StringToString(const CRecvProxyData* pData, void* pStruct, void* pOut);
+void RecvProxy_Int32ToInt32(const CRecvProxyData* pData, void* pStruct, void* pOut);
+
+// StaticDataTable does *pOut = pData.
+void DataTableRecvProxy_StaticDataTable(const RecvProp* pProp, void** pOut, void* pData, int objectID);
+
+// PointerDataTable does *pOut = *((void**)pData) (ie: pData is a pointer to the object to decode into).
+void DataTableRecvProxy_PointerDataTable(const RecvProp* pProp, void** pOut, void* pData, int objectID);
+
+RecvProp RecvPropFloat(
+ const char* pVarName,
+ int offset,
+ int sizeofVar = SIZEOF_IGNORE, // Handled by RECVINFO macro, but set to SIZEOF_IGNORE if you don't want to bother.
+ int flags = 0,
+ RecvVarProxyFn varProxy = RecvProxy_FloatToFloat
+);
+
+RecvProp RecvPropVector(
+ const char* pVarName,
+ int offset,
+ int sizeofVar = SIZEOF_IGNORE, // Handled by RECVINFO macro, but set to SIZEOF_IGNORE if you don't want to bother.
+ int flags = 0,
+ RecvVarProxyFn varProxy = RecvProxy_VectorToVector
+);
+
+// This is here so the RecvTable can look more like the SendTable.
+#define RecvPropQAngles RecvPropVector
+
+RecvProp RecvPropInt(
+ const char* pVarName,
+ int offset,
+ int sizeofVar = SIZEOF_IGNORE, // Handled by RECVINFO macro, but set to SIZEOF_IGNORE if you don't want to bother.
+ int flags = 0,
+ RecvVarProxyFn varProxy = 0
+);
+
+RecvProp RecvPropString(
+ const char* pVarName,
+ int offset,
+ int bufferSize,
+ int flags = 0,
+ RecvVarProxyFn varProxy = RecvProxy_StringToString
+);
+
+RecvProp RecvPropDataTable(
+ const char* pVarName,
+ int offset,
+ int flags,
+ RecvTable* pTable,
+ DataTableRecvVarProxyFn varProxy = DataTableRecvProxy_StaticDataTable
+);
+
+RecvProp RecvPropArray3(
+ const char* pVarName,
+ int offset,
+ int sizeofVar,
+ int elements,
+ RecvProp pArrayProp,
+ DataTableRecvVarProxyFn varProxy = DataTableRecvProxy_StaticDataTable
+);
+
+// Use the macro to let it automatically generate a table name. You shouldn't
+// ever need to reference the table name. If you want to exclude this array, then
+// reference the name of the variable in varTemplate.
+RecvProp InternalRecvPropArray(
+ const int elementCount,
+ const int elementStride,
+ const char* pName,
+ ArrayLengthRecvProxyFn proxy
+);
+
+//
+// Use this if you want to completely manage the way the array data is stored.
+// You'll need to provide a proxy inside varTemplate that looks for 'iElement'
+// to figure out where to store the specified element.
+//
+#define RecvPropVirtualArray( arrayLengthProxy, maxArrayLength, varTemplate, propertyName ) \
+ varTemplate, \
+ InternalRecvPropArray( \
+ maxArrayLength, \
+ 0, \
+ #propertyName, \
+ arrayLengthProxy \
+ )
+
+// Use this and pass the array name and it will figure out the count and stride automatically.
+#define RecvPropVariableLengthArray( arrayLengthProxy, varTemplate, arrayName ) \
+ varTemplate, \
+ InternalRecvPropArray( \
+ sizeof(((currentRecvDTClass*)0)->arrayName) / PROPSIZEOF(currentRecvDTClass, arrayName[0]), \
+ PROPSIZEOF(currentRecvDTClass, arrayName[0]), \
+ #arrayName, \
+ arrayLengthProxy \
+ )
+
+// Use this and pass the array name and it will figure out the count and stride automatically.
+#define RecvPropArray( varTemplate, arrayName ) \
+ RecvPropVariableLengthArray( 0, varTemplate, arrayName )
+
+// Use this one to specify the element count and stride manually.
+#define RecvPropArray2( arrayLengthProxy, varTemplate, elementCount, elementStride, arrayName ) \
+ varTemplate, \
+ InternalRecvPropArray( elementCount, elementStride, #arrayName, arrayLengthProxy )
+
+// ---------------------------------------------------------------------------------------- //
+// Inlines.
+// ---------------------------------------------------------------------------------------- //
+
+inline void RecvProp::InitArray(int nElements, int elementStride)
+{
+ m_RecvType = DPT_Array;
+ m_nElements = nElements;
+ m_ElementStride = elementStride;
+}
+
+inline int RecvProp::GetNumElements() const
+{
+ return m_nElements;
+}
+
+inline void RecvProp::SetNumElements(int nElements)
+{
+ m_nElements = nElements;
+}
+
+inline int RecvProp::GetElementStride() const
+{
+ return m_ElementStride;
+}
+
+inline void RecvProp::SetElementStride(int stride)
+{
+ m_ElementStride = stride;
+}
+
+inline int RecvProp::GetFlags() const
+{
+ return m_Flags;
+}
+
+inline const char* RecvProp::GetName() const
+{
+ return m_pVarName;
+}
+
+inline SendPropType RecvProp::GetType() const
+{
+ return m_RecvType;
+}
+
+inline RecvTable* RecvProp::GetDataTable() const
+{
+ return m_pDataTable;
+}
+
+inline void RecvProp::SetDataTable(RecvTable* pTable)
+{
+ m_pDataTable = pTable;
+}
+
+inline RecvVarProxyFn RecvProp::GetProxyFn() const
+{
+ return m_ProxyFn;
+}
+
+inline void RecvProp::SetProxyFn(RecvVarProxyFn fn)
+{
+ m_ProxyFn = fn;
+}
+
+inline DataTableRecvVarProxyFn RecvProp::GetDataTableProxyFn() const
+{
+ return m_DataTableProxyFn;
+}
+
+inline void RecvProp::SetDataTableProxyFn(DataTableRecvVarProxyFn fn)
+{
+ m_DataTableProxyFn = fn;
+}
+
+inline int RecvProp::GetOffset() const
+{
+ return m_Offset;
+}
+
+inline void RecvProp::SetOffset(int o)
+{
+ m_Offset = o;
+}
+
+inline RecvProp* RecvProp::GetArrayProp() const
+{
+ return m_pArrayProp;
+}
+
+inline void RecvProp::SetArrayProp(RecvProp* pProp)
+{
+ m_pArrayProp = pProp;
+}
+
+inline void RecvProp::SetArrayLengthProxy(ArrayLengthRecvProxyFn proxy)
+{
+ m_ArrayLengthProxy = proxy;
+}
+
+inline ArrayLengthRecvProxyFn RecvProp::GetArrayLengthProxy() const
+{
+ return m_ArrayLengthProxy;
+}
+
+inline bool RecvProp::IsInsideArray() const
+{
+ return m_bInsideArray;
+}
+
+inline void RecvProp::SetInsideArray()
+{
+ m_bInsideArray = true;
+}
+
+inline const void* RecvProp::GetExtraData() const
+{
+ return m_pExtraData;
+}
+
+inline void RecvProp::SetExtraData(const void* pData)
+{
+ m_pExtraData = pData;
+}
+
+inline const char* RecvProp::GetParentArrayPropName()
+{
+ return m_pParentArrayPropName;
+}
+
+inline void RecvProp::SetParentArrayPropName(const char* pArrayPropName)
+{
+ m_pParentArrayPropName = pArrayPropName;
+}