Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef DATATABLE_ENCODE_H
  8. #define DATATABLE_ENCODE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "dt_send.h"
  13. #include "dt_recv.h"
  14. class DecodeInfo : public CRecvProxyData
  15. {
  16. public:
  17. // Copy everything except val.
  18. void CopyVars( const DecodeInfo *pOther );
  19. public:
  20. //
  21. // NOTE: it's valid to pass in m_pRecvProp and m_pData and m_pSrtuct as null, in which
  22. // case the buffer is advanced but the property is not stored anywhere.
  23. //
  24. // This is used by SendTable_CompareDeltas.
  25. //
  26. void *m_pStruct; // Points at the base structure
  27. void *m_pData; // Points at where the variable should be encoded.
  28. const SendProp *m_pProp; // Provides the client's info on how to decode and its proxy.
  29. bf_read *m_pIn; // The buffer to get the encoded data from.
  30. char m_TempStr[DT_MAX_STRING_BUFFERSIZE]; // m_Value.m_pString is set to point to this.
  31. };
  32. typedef struct
  33. {
  34. // Encode a value.
  35. // pStruct : points at the base structure
  36. // pVar : holds data in the correct type (ie: PropVirtualsInt will have DVariant::m_Int set).
  37. // pProp : describes the property to be encoded.
  38. // pOut : the buffer to encode into.
  39. // objectID: for debug output.
  40. void (*Encode)( const unsigned char *pStruct, DVariant *pVar, const SendProp *pProp, bf_write *pOut, int objectID );
  41. // Decode a value.
  42. // See the DecodeInfo class for a description of the parameters.
  43. void (*Decode)( DecodeInfo *pInfo );
  44. // Compare the deltas in the two buffers. The property in both buffers must be fully decoded
  45. int (*CompareDeltas)( const SendProp *pProp, bf_read *p1, bf_read *p2 );
  46. // Used for the local single-player connection to copy the data straight from the server ent into the client ent.
  47. void (*FastCopy)(
  48. const SendProp *pSendProp,
  49. const RecvProp *pRecvProp,
  50. const unsigned char *pSendData,
  51. unsigned char *pRecvData,
  52. int objectID );
  53. // Return a string with the name of the type ("DPT_Float", "DPT_Int", etc).
  54. const char* (*GetTypeNameString)();
  55. // Returns true if the property's value is zero.
  56. // NOTE: this does NOT strictly mean that it would encode to zeros. If it were a float with
  57. // min and max values, a value of zero could encode to some other integer value.
  58. bool (*IsZero)( const unsigned char *pStruct, DVariant *pVar, const SendProp *pProp );
  59. // This writes a zero value in (ie: a value that would make IsZero return true).
  60. void (*DecodeZero)( DecodeInfo *pInfo );
  61. // This reades this property from stream p and returns true, if it's a zero value
  62. bool (*IsEncodedZero) ( const SendProp *pProp, bf_read *p );
  63. void (*SkipProp) ( const SendProp *pProp, bf_read *p );
  64. } PropTypeFns;
  65. extern PropTypeFns g_PropTypeFns[DPT_NUMSendPropTypes];
  66. // This is used for comparing packed buffers. Just extracts the raw bits for the
  67. // data and returns the number of bits used to encode the data.
  68. int DecodeBits( DecodeInfo *pInfo, unsigned char *pOut );
  69. #endif // DATATABLE_ENCODE_H