core/sourcehook/sourcehook_impl_cproto.cpp
author Nicholas Hastings <skamonkey@gmail.com>
Thu Aug 23 00:08:00 2012 -0400 (2012-08-23)
changeset 797 f9f87775019a
parent 733 2365240861a2
permissions -rw-r--r--
Triggering build.
     1 /* ======== SourceHook ========
     2 * Copyright (C) 2004-2010 Metamod:Source Development Team
     3 * No warranties of any kind
     4 *
     5 * License: zlib/libpng
     6 *
     7 * Author(s): Pavol "PM OnoTo" Marko
     8 * ============================
     9 */
    10 
    11 #include "sourcehook_impl.h"
    12 
    13 namespace SourceHook
    14 {
    15 	namespace Impl
    16 	{
    17 		void CProto::Fill(const ProtoInfo *pProto)
    18 		{
    19 			if (pProto == NULL)
    20 				m_Version = -1;
    21 
    22 			m_ParamsPassInfo.clear();
    23 
    24 			if (pProto->paramsPassInfo[0].size == 0)
    25 			{
    26 				// Version 1
    27 				m_Version = 0;
    28 				m_Convention = pProto->convention;
    29 				m_NumOfParams = pProto->numOfParams;
    30 
    31 				m_RetPassInfo.size = pProto->retPassInfo.size;
    32 				m_RetPassInfo.type = pProto->retPassInfo.type;
    33 				m_RetPassInfo.flags = GetRealFlags(pProto->retPassInfo);
    34 
    35 				m_RetPassInfo.pNormalCtor = NULL;
    36 				m_RetPassInfo.pCopyCtor = NULL;
    37 				m_RetPassInfo.pDtor = NULL;
    38 				m_RetPassInfo.pAssignOperator = NULL;
    39 
    40 				
    41 				m_ParamsPassInfo.resize(pProto->numOfParams);
    42 
    43 				for (int i = 1; i <= pProto->numOfParams; ++i)
    44 				{
    45 					m_ParamsPassInfo[i-1].size = pProto->paramsPassInfo[i].size;
    46 					m_ParamsPassInfo[i-1].type = pProto->paramsPassInfo[i].type;
    47 					m_ParamsPassInfo[i-1].flags = GetRealFlags(pProto->paramsPassInfo[i]);
    48 
    49 					m_ParamsPassInfo[i-1].pNormalCtor = NULL;
    50 					m_ParamsPassInfo[i-1].pCopyCtor = NULL;
    51 					m_ParamsPassInfo[i-1].pDtor = NULL;
    52 					m_ParamsPassInfo[i-1].pAssignOperator = NULL;
    53 				}
    54 			}
    55 			else if (pProto->paramsPassInfo[0].size == 1)
    56 			{
    57 				// Version 2
    58 				m_Version = 1;
    59 				m_Convention = pProto->convention;
    60 				m_NumOfParams = pProto->numOfParams;
    61 
    62 				m_RetPassInfo.size = pProto->retPassInfo.size;
    63 				m_RetPassInfo.type = pProto->retPassInfo.type;
    64 				m_RetPassInfo.flags = pProto->retPassInfo.flags;
    65 
    66 				m_RetPassInfo.pNormalCtor = pProto->retPassInfo2.pNormalCtor;
    67 				m_RetPassInfo.pCopyCtor = pProto->retPassInfo2.pCopyCtor;
    68 				m_RetPassInfo.pDtor = pProto->retPassInfo2.pDtor;
    69 				m_RetPassInfo.pAssignOperator = pProto->retPassInfo2.pAssignOperator;
    70 
    71 				m_ParamsPassInfo.resize(pProto->numOfParams);
    72 
    73 				for (int i = 1; i <= pProto->numOfParams; ++i)
    74 				{
    75 					m_ParamsPassInfo[i-1].size = pProto->paramsPassInfo[i].size;
    76 					m_ParamsPassInfo[i-1].type = pProto->paramsPassInfo[i].type;
    77 					m_ParamsPassInfo[i-1].flags = pProto->paramsPassInfo[i].flags;
    78 
    79 					m_ParamsPassInfo[i-1].pNormalCtor = pProto->paramsPassInfo2[i].pNormalCtor;
    80 					m_ParamsPassInfo[i-1].pCopyCtor = pProto->paramsPassInfo2[i].pCopyCtor;
    81 					m_ParamsPassInfo[i-1].pDtor = pProto->paramsPassInfo2[i].pDtor;
    82 					m_ParamsPassInfo[i-1].pAssignOperator = pProto->paramsPassInfo2[i].pAssignOperator;
    83 				}
    84 			}
    85 			else
    86 			{
    87 				// Unknown
    88 				m_Version = -1;
    89 			}
    90 		}
    91 
    92 		// Basic compat test
    93 		// Other than this, we assume that the plugins know what they're doing
    94 		bool CProto::operator == (const CProto &other) const
    95 		{
    96 			if (m_Version < 0 || other.GetVersion() < 0)
    97 				return false;
    98 
    99 			if (m_NumOfParams != other.GetNumOfParams())
   100 				return false;
   101 
   102 			if (m_Convention != ProtoInfo::CallConv_Unknown && other.GetConvention() != ProtoInfo::CallConv_Unknown &&
   103 				m_Convention != other.GetConvention())
   104 				return false;
   105 
   106 			if (GetRealSize(GetRet()) != GetRealSize(other.GetRet()))
   107 				return false;
   108 
   109 			for (int i = 0; i < m_NumOfParams; ++i)
   110 			{
   111 				if (GetRealSize(GetParam(i)) != GetRealSize(other.GetParam(i)))
   112 					return false;
   113 				if (GetParam(i).type != PassInfo::PassType_Unknown && other.GetParam(i).type != PassInfo::PassType_Unknown)
   114 				{
   115 					if (GetParam(i).type != other.GetParam(i).type)
   116 						return false;
   117 					if (GetParam(i).flags != other.GetParam(i).flags)
   118 						return false;
   119 				}
   120 			}
   121 
   122 			return true;
   123 		}
   124 
   125 		bool CProto::ExactlyEqual(const CProto &other) const
   126 		{
   127 			if (m_Version != other.m_Version ||
   128 				m_NumOfParams != other.m_NumOfParams ||
   129 				m_Convention != other.m_Convention ||
   130 				GetRet() != other.GetRet())
   131 			{
   132 				return false;
   133 			}
   134 
   135 			for (int i = 0; i < m_NumOfParams; ++i)
   136 			{
   137 				if(GetParam(i) != other.GetParam(i))
   138 					return false;
   139 			}
   140 
   141 			return true;
   142 		}
   143 		
   144 	}
   145 }