1.1 --- a/sourcemm/CSmmAPI.cpp Thu Feb 22 05:11:21 2007 +0000
1.2 +++ b/sourcemm/CSmmAPI.cpp Tue Feb 27 03:25:36 2007 +0000
1.3 @@ -513,16 +513,25 @@
1.4 // message indices. This is our answer to it. Yuck! <:-( //
1.5 //////////////////////////////////////////////////////////////////////
1.6 #ifdef OS_WIN32
1.7 - #define MSGCLASS_SIGLEN 7
1.8 - #define MSGCLASS_SIG "\x8B\x0D\x2A\x2A\x2A\x2A\x56"
1.9 - #define MSGCLASS_OFFS 2
1.10 + #define MSGCLASS_SIGLEN 7
1.11 + #define MSGCLASS_SIG "\x8B\x0D\x2A\x2A\x2A\x2A\x56"
1.12 + #define MSGCLASS_OFFS 2
1.13 +
1.14 + #define MSGCLASS2_SIGLEN 16
1.15 + #define MSGCLASS2_SIG "\x56\x8B\x74\x24\x2A\x85\xF6\x7C\x2A\x3B\x35\x2A\x2A\x2A\x2A\x7D"
1.16 + #define MSGCLASS2_OFFS 11
1.17 #elif defined OS_LINUX
1.18 - #define MSGCLASS_SIGLEN 14
1.19 - #define MSGCLASS_SIG "\x53\x83\xEC\x2A\x8B\x5C\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89"
1.20 - #define MSGCLASS_OFFS 9
1.21 + #define MSGCLASS_SIGLEN 14
1.22 + #define MSGCLASS_SIG "\x53\x83\xEC\x2A\x8B\x2A\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89"
1.23 + #define MSGCLASS_OFFS 9
1.24 +
1.25 + #define MSGCLASS2_SIGLEN 16
1.26 + #define MSGCLASS2_SIG "\x55\x89\xE5\x53\x83\xEC\x2A\x8B\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89"
1.27 + #define MSGCLASS2_OFFS 11
1.28 #endif
1.29
1.30 /* This is the ugliest function in all of SourceMM */
1.31 +/* :TODO: Make this prettier */
1.32 bool CSmmAPI::CacheUserMessages()
1.33 {
1.34 SourceHook::MemFuncInfo info = {true, -1, 0, 0};
1.35 @@ -541,14 +550,35 @@
1.36 vfunc = vtable[info.vtblindex];
1.37 }
1.38
1.39 + UserMsgDict *dict = NULL;
1.40 +
1.41 if (vcmp(vfunc, MSGCLASS_SIG, MSGCLASS_SIGLEN))
1.42 {
1.43 - // Get address of CUserMessages
1.44 + // Get address of CUserMessages instance
1.45 char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS_OFFS);
1.46
1.47 // Get address of CUserMessages::m_UserMessages
1.48 - UserMsgDict *dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
1.49 + dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
1.50 + } else if (vcmp(vfunc, MSGCLASS2_SIG, MSGCLASS2_SIGLEN)) {
1.51 + #ifdef OS_WIN32
1.52 + /* If we get here, the code is possibly inlined like in Dystopia */
1.53 +
1.54 + // Get the address of the CUtlRBTree
1.55 + char *rbtree = *reinterpret_cast<char **>(vfunc + MSGCLASS2_OFFS);
1.56
1.57 + // The CUtlDict should be 8 bytes before the CUtlRBTree (yeah I know this is hacky)
1.58 + dict = reinterpret_cast<UserMsgDict *>(rbtree - 8);
1.59 + #elif defined OS_LINUX
1.60 + // Get address of CUserMessages instance
1.61 + char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS2_OFFS);
1.62 +
1.63 + // Get address of CUserMessages::m_UserMessages
1.64 + dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
1.65 + #endif
1.66 + }
1.67 +
1.68 + if (dict)
1.69 + {
1.70 m_MsgCount = dict->Count();
1.71
1.72 // Make sure count falls within bounds of an unsigned byte (engine sends message types as such)
1.73 @@ -559,7 +589,7 @@
1.74 }
1.75
1.76 UserMessage *msg;
1.77 -
1.78 +
1.79 // Cache messages in our CUtlDict
1.80 for (int i = 0; i < m_MsgCount; i++)
1.81 {