From: <go...@us...> - 2002-08-28 20:55:37
|
Update of /cvsroot/decaldev/source/Decal In directory usw-pr-cvs1:/tmp/cvs-serv24605/Decal Modified Files: ACHooks.cpp ACHooks.h DecalCP.h Log Message: Added hooks for screen size Updated version numbers for new Beta Index: ACHooks.cpp =================================================================== RCS file: /cvsroot/decaldev/source/Decal/ACHooks.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** ACHooks.cpp 27 Aug 2002 19:41:18 -0000 1.13 --- ACHooks.cpp 28 Aug 2002 20:55:03 -0000 1.14 *************** *** 10,15 **** --- 10,23 ---- void (*pfnMoveItemEx)( DWORD, DWORD, DWORD ) = NULL; + extern void ObjectDestroyedHook (); + extern DWORD HookCall (DWORD dwCallAddress, DWORD dwReplacement); + + // statics + cACHooks* cACHooks::s_pACHooks = NULL; + long g_lObjectDestroyedProc = 0; + cACHooks::cACHooks() { + s_pACHooks = this; USES_CONVERSION; *************** *** 251,254 **** --- 259,302 ---- m_Hooks |= eFaceHeading; } + + /* + // While the address of ObjectDestroyed is interesting, it isn't actually needed. + // We can't assume that the calls we're hooking call to this address, as they + // might have already been hooked! + if( QueryMemLoc( _bstr_t( "ObjectDestroyed"), &Val ) == S_OK ) + { + } + */ + + long lCall1 = 0, lCall2 = 0; + if( QueryMemLoc( _bstr_t( "ObjectDestroyed_Call1"), &Val ) == S_OK ) + { + lCall1 = Val; + } + + if( QueryMemLoc( _bstr_t( "ObjectDestroyed_Call2"), &Val ) == S_OK ) + { + lCall2 = Val; + } + + if (lCall1 && lCall2) + { + DWORD dwFunc1 = HookCall (lCall1, (DWORD) ObjectDestroyedHook); + DWORD dwFunc2 = HookCall (lCall2, (DWORD) ObjectDestroyedHook); + + _ASSERTE (dwFunc1 && (dwFunc1 == dwFunc2)); + + if (dwFunc1 && (dwFunc1 != dwFunc2)) + { + // Doh, okay put them back, something's wrong. + HookCall (lCall1, dwFunc1); + HookCall (lCall2, dwFunc2); + } + else + { + m_Hooks |= eObjectDestroyed; + g_lObjectDestroyedProc = dwFunc1; + } + } } *************** *** 1070,1071 **** --- 1118,1191 ---- } + void cACHooks::InternalObjectDestroyed (DWORD dwGuid) + { + Fire_ObjectDestroyed (dwGuid); + } + + void OnObjectDestroyed (DWORD dwGuid) + { + if (cACHooks::s_pACHooks) + { + cACHooks::s_pACHooks->InternalObjectDestroyed (dwGuid); + } + } + + void __declspec (naked) ObjectDestroyedHook () + { + _asm + { + mov eax,[esp+8] + push eax + push ecx + + push eax + call OnObjectDestroyed + + add esp,4 + pop ecx + pop eax + mov [esp+8],eax + + jmp g_lObjectDestroyedProc + } + } + + // Returns the function which previously was being called, after replacing it with the new call. + DWORD HookCall (DWORD dwCallAddress, DWORD dwReplacement) + { + DWORD* pTemp = (DWORD *) (dwCallAddress + 1); + + HANDLE hProcess = OpenProcess + ( + PROCESS_VM_WRITE | PROCESS_VM_OPERATION, + FALSE, + GetCurrentProcessId () + ); + + DWORD dwOriginal = 0; + + if (hProcess) + { + dwOriginal = (*pTemp) + dwCallAddress + 5; + + DWORD dwTemp = dwReplacement - (dwCallAddress + 5); + if (WriteProcessMemory + ( + hProcess, + pTemp, + &dwTemp, + sizeof (DWORD), + NULL + )) + { + } + else + { + dwOriginal = 0; + } + + CloseHandle (hProcess); + } + + return dwOriginal ; + } Index: ACHooks.h =================================================================== RCS file: /cvsroot/decaldev/source/Decal/ACHooks.h,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** ACHooks.h 27 Aug 2002 19:41:19 -0000 1.14 --- ACHooks.h 28 Aug 2002 20:55:03 -0000 1.15 *************** *** 151,154 **** --- 151,157 ---- STDMETHOD(get_Area3DHeight)(long *pVal); STDMETHOD(ItemIsKnown)(long lGUID, VARIANT_BOOL* pRetval) ; + + static cACHooks* s_pACHooks; + void InternalObjectDestroyed (DWORD dwGuid); }; Index: DecalCP.h =================================================================== RCS file: /cvsroot/decaldev/source/Decal/DecalCP.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DecalCP.h 26 May 2002 21:31:22 -0000 1.2 --- DecalCP.h 28 Aug 2002 20:55:03 -0000 1.3 *************** *** 7,10 **** --- 7,36 ---- //Warning this class may be recreated by the wizard. public: + HRESULT Fire_ObjectDestroyed(LONG guid) + { + CComVariant varResult; + T* pT = static_cast<T*>(this); + int nConnectionIndex; + CComVariant* pvars = new CComVariant[1]; + int nConnections = m_vec.GetSize(); + + for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++) + { + pT->Lock(); + CComPtr<IUnknown> sp = m_vec.GetAt(nConnectionIndex); + pT->Unlock(); + IDispatch* pDispatch = reinterpret_cast<IDispatch*>(sp.p); + if (pDispatch != NULL) + { + VariantClear(&varResult); + pvars[0] = guid; + DISPPARAMS disp = { pvars, NULL, 1, 0 }; + pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL); + } + } + delete[] pvars; + return varResult.scode; + + } }; #endif |