1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/core/sourcehook/sourcehook_impl_cproto.cpp Fri Dec 17 22:22:44 2010 -0500
1.3 @@ -0,0 +1,145 @@
1.4 +/* ======== SourceHook ========
1.5 +* Copyright (C) 2004-2010 Metamod:Source Development Team
1.6 +* No warranties of any kind
1.7 +*
1.8 +* License: zlib/libpng
1.9 +*
1.10 +* Author(s): Pavol "PM OnoTo" Marko
1.11 +* ============================
1.12 +*/
1.13 +
1.14 +#include "sourcehook_impl.h"
1.15 +
1.16 +namespace SourceHook
1.17 +{
1.18 + namespace Impl
1.19 + {
1.20 + void CProto::Fill(const ProtoInfo *pProto)
1.21 + {
1.22 + if (pProto == NULL)
1.23 + m_Version = -1;
1.24 +
1.25 + m_ParamsPassInfo.clear();
1.26 +
1.27 + if (pProto->paramsPassInfo[0].size == 0)
1.28 + {
1.29 + // Version 1
1.30 + m_Version = 0;
1.31 + m_Convention = pProto->convention;
1.32 + m_NumOfParams = pProto->numOfParams;
1.33 +
1.34 + m_RetPassInfo.size = pProto->retPassInfo.size;
1.35 + m_RetPassInfo.type = pProto->retPassInfo.type;
1.36 + m_RetPassInfo.flags = GetRealFlags(pProto->retPassInfo);
1.37 +
1.38 + m_RetPassInfo.pNormalCtor = NULL;
1.39 + m_RetPassInfo.pCopyCtor = NULL;
1.40 + m_RetPassInfo.pDtor = NULL;
1.41 + m_RetPassInfo.pAssignOperator = NULL;
1.42 +
1.43 +
1.44 + m_ParamsPassInfo.resize(pProto->numOfParams);
1.45 +
1.46 + for (int i = 1; i <= pProto->numOfParams; ++i)
1.47 + {
1.48 + m_ParamsPassInfo[i-1].size = pProto->paramsPassInfo[i].size;
1.49 + m_ParamsPassInfo[i-1].type = pProto->paramsPassInfo[i].type;
1.50 + m_ParamsPassInfo[i-1].flags = GetRealFlags(pProto->paramsPassInfo[i]);
1.51 +
1.52 + m_ParamsPassInfo[i-1].pNormalCtor = NULL;
1.53 + m_ParamsPassInfo[i-1].pCopyCtor = NULL;
1.54 + m_ParamsPassInfo[i-1].pDtor = NULL;
1.55 + m_ParamsPassInfo[i-1].pAssignOperator = NULL;
1.56 + }
1.57 + }
1.58 + else if (pProto->paramsPassInfo[0].size == 1)
1.59 + {
1.60 + // Version 2
1.61 + m_Version = 1;
1.62 + m_Convention = pProto->convention;
1.63 + m_NumOfParams = pProto->numOfParams;
1.64 +
1.65 + m_RetPassInfo.size = pProto->retPassInfo.size;
1.66 + m_RetPassInfo.type = pProto->retPassInfo.type;
1.67 + m_RetPassInfo.flags = pProto->retPassInfo.flags;
1.68 +
1.69 + m_RetPassInfo.pNormalCtor = pProto->retPassInfo2.pNormalCtor;
1.70 + m_RetPassInfo.pCopyCtor = pProto->retPassInfo2.pCopyCtor;
1.71 + m_RetPassInfo.pDtor = pProto->retPassInfo2.pDtor;
1.72 + m_RetPassInfo.pAssignOperator = pProto->retPassInfo2.pAssignOperator;
1.73 +
1.74 + m_ParamsPassInfo.resize(pProto->numOfParams);
1.75 +
1.76 + for (int i = 1; i <= pProto->numOfParams; ++i)
1.77 + {
1.78 + m_ParamsPassInfo[i-1].size = pProto->paramsPassInfo[i].size;
1.79 + m_ParamsPassInfo[i-1].type = pProto->paramsPassInfo[i].type;
1.80 + m_ParamsPassInfo[i-1].flags = pProto->paramsPassInfo[i].flags;
1.81 +
1.82 + m_ParamsPassInfo[i-1].pNormalCtor = pProto->paramsPassInfo2[i].pNormalCtor;
1.83 + m_ParamsPassInfo[i-1].pCopyCtor = pProto->paramsPassInfo2[i].pCopyCtor;
1.84 + m_ParamsPassInfo[i-1].pDtor = pProto->paramsPassInfo2[i].pDtor;
1.85 + m_ParamsPassInfo[i-1].pAssignOperator = pProto->paramsPassInfo2[i].pAssignOperator;
1.86 + }
1.87 + }
1.88 + else
1.89 + {
1.90 + // Unknown
1.91 + m_Version = -1;
1.92 + }
1.93 + }
1.94 +
1.95 + // Basic compat test
1.96 + // Other than this, we assume that the plugins know what they're doing
1.97 + bool CProto::operator == (const CProto &other) const
1.98 + {
1.99 + if (m_Version < 0 || other.GetVersion() < 0)
1.100 + return false;
1.101 +
1.102 + if (m_NumOfParams != other.GetNumOfParams())
1.103 + return false;
1.104 +
1.105 + if (m_Convention != ProtoInfo::CallConv_Unknown && other.GetConvention() != ProtoInfo::CallConv_Unknown &&
1.106 + m_Convention != other.GetConvention())
1.107 + return false;
1.108 +
1.109 + if (GetRealSize(GetRet()) != GetRealSize(other.GetRet()))
1.110 + return false;
1.111 +
1.112 + for (int i = 0; i < m_NumOfParams; ++i)
1.113 + {
1.114 + if (GetRealSize(GetParam(i)) != GetRealSize(other.GetParam(i)))
1.115 + return false;
1.116 + if (GetParam(i).type != PassInfo::PassType_Unknown && other.GetParam(i).type != PassInfo::PassType_Unknown)
1.117 + {
1.118 + if (GetParam(i).type != other.GetParam(i).type)
1.119 + return false;
1.120 + if (GetParam(i).flags != other.GetParam(i).flags)
1.121 + return false;
1.122 + }
1.123 + }
1.124 +
1.125 + return true;
1.126 + }
1.127 +
1.128 + bool CProto::ExactlyEqual(const CProto &other) const
1.129 + {
1.130 + if (m_Version != other.m_Version ||
1.131 + m_NumOfParams != other.m_NumOfParams ||
1.132 + m_Convention != other.m_Convention ||
1.133 + GetRet() != other.GetRet())
1.134 + {
1.135 + return false;
1.136 + }
1.137 +
1.138 + for (int i = 0; i < m_NumOfParams; ++i)
1.139 + {
1.140 + if(GetParam(i) != other.GetParam(i))
1.141 + return false;
1.142 + }
1.143 +
1.144 + return true;
1.145 + }
1.146 +
1.147 + }
1.148 +}