#include "Global.h" #include "WndProcEater.h" WndProcEater::WndProcEater() { hWndEaten = 0; eatenWndProc = 0; extraProcs = 0; numExtraProcs = 0; hMutex = CreateMutex(0, 0, L"LilyPad"); } WndProcEater::~WndProcEater() throw() { if (hMutex) { ReleaseMutex(hMutex); CloseHandle(hMutex); } } void WndProcEater::ReleaseExtraProc(ExtraWndProc proc) { // Probably isn't needed, but just in case... if (hMutex) WaitForSingleObject(hMutex, 100); //printf( "(Lilypad) Regurgitating! -> 0x%x\n", proc ); for (int i=0; i res) res = res2; } } if (res != NO_WND_PROC) { if (out == WM_DESTROY) { Release(); } if (res == CONTINUE_BLISSFULLY) out = CallWindowProc(eatenWndProc, hWnd, uMsg, wParam, lParam); else if (res == USE_DEFAULT_WND_PROC) out = DefWindowProc(hWnd, uMsg, wParam, lParam); } return out; } static LRESULT CALLBACK OverrideWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { WndProcEater* obj = (WndProcEater*)GetProp(hWnd, L"LilyHaxxor"); return (obj == NULL) ? DefWindowProc(hWnd, uMsg, wParam, lParam) : obj->_OverrideWndProc( hWnd, uMsg, wParam, lParam ); } bool WndProcEater::SetWndHandle(HWND hWnd) { if(hWnd == hWndEaten) return true; //printf( "(Lilypad) (Re)-Setting window handle! -> this=0x%08x, hWnd=0x%08x\n", this, hWnd ); Release(); SetProp(hWnd, L"LilyHaxxor", (HANDLE)this); eatenWndProc = (WNDPROC) SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)OverrideWndProc); hWndEaten = (eatenWndProc) ? hWnd : 0; return !!hWndEaten; } void WndProcEater::Eat(ExtraWndProc proc, DWORD flags) { // check if Subclassing failed to init during SetWndHandle if (!hWndEaten) return; // Probably isn't needed, but just in case... if (hMutex) WaitForSingleObject(hMutex, 100); //printf( "(Lilypad) EatingWndProc! -> 0x%x\n", proc ); extraProcs = (ExtraWndProcInfo*) realloc(extraProcs, sizeof(ExtraWndProcInfo)*(numExtraProcs+1)); extraProcs[numExtraProcs].proc = proc; extraProcs[numExtraProcs].flags = flags; numExtraProcs++; }