Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CMsgHandler::CMsgHandler()
- {
- this->m_hWnd = NULL;
- }
- CMsgHandler::~CMsgHandler()
- {
- }
- BOOL CMsgHandler::Init(__in HINSTANCE hInstance)
- {
- WNDCLASSEX wc = { 0 };
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.lpfnWndProc = CMsgHandler::WindowProc;
- wc.hInstance = hInstance;
- wc.lpszClassName = TEXT(CLASS_NAME);
- if (!RegisterClassEx(&wc))
- {
- // :'(
- return FALSE;
- }
- this->m_hWnd = CreateWindowEx(0, TEXT(CLASS_NAME), NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, hInstance, NULL);
- if (!this->m_hWnd)
- {
- UnregisterClass(TEXT(CLASS_NAME), NULL);
- return FALSE;
- }
- this->m_hInstance = hInstance;
- // invisible window
- ShowWindow(this->m_hWnd, SW_HIDE);
- return TRUE;
- }
- VOID CMsgHandler::Destroy()
- {
- if (this->m_hWnd != NULL)
- {
- DestroyWindow(this->m_hWnd);
- this->m_hWnd = NULL;
- }
- UnregisterClass(TEXT(CLASS_NAME), this->m_hInstance);
- }
- HWND CMsgHandler::GetHandle()
- {
- return this->m_hWnd;
- }
- LRESULT CALLBACK CMsgHandler::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- CUserLocal *pUserLocal;
- CWvsContext *pWvsContext;
- CPortalList *pPortalList;
- CharacterData *cd;
- POINT pt;
- CField *pField;
- switch (uMsg)
- {
- case WM_CLOSE:
- {
- CMsgHandler::GetInstance()->Destroy();
- break;
- }
- case WM_GET_USER_POS:
- {
- LPPOINT lppt = (LPPOINT)lParam;
- pUserLocal = CUserLocal::GetInstance();
- if (!pUserLocal)
- {
- lppt->x = 0;
- lppt->y = 0;
- return FALSE;
- }
- else
- {
- pUserLocal->VecCtrl.vfptr->GetPos(&pUserLocal->VecCtrl, lppt);
- }
- break;
- }
- case WM_GET_MAPID:
- {
- *(DWORD*)lParam = get_field_id();
- break;
- }
- case WM_TALK_NPC:
- {
- CNpcPool *pNpcPool = CNpcPool::GetInstance();
- pUserLocal = CUserLocal::GetInstance();
- if (!pNpcPool || !pUserLocal)
- return FALSE;
- CNpc *pNpc = pNpcPool->FindNpcByTemplateID(wParam);
- if (!pNpc)
- return FALSE;
- ZRef<CNpc> ref;
- ref.p = pNpc;
- InterlockedIncrement(&pNpc->ZRefCounted._m_nRef);
- pUserLocal->TalkToNpc(ref);
- break;
- }
- case WM_OnKey:
- {
- CWndMan *pWndMan = CWndMan::GetInstance();
- if (!pWndMan || !pWndMan->m_pFocus)
- {
- return FALSE;
- }
- pWndMan->m_pFocus->vfptr->OnKey(pWndMan->m_pFocus, wParam, lParam);
- break;
- }
- case WM_ChangeChannel:
- {
- int nTargetChannel;
- pUserLocal = CUserLocal::GetInstance();
- pWvsContext = CWvsContext::GetInstance();
- pField = get_field();
- if (!pUserLocal || !pWvsContext || !pField ||
- !pWvsContext->CanSendExclRequest(500, FALSE))
- {
- return FALSE;
- }
- nTargetChannel = wParam;
- if (nTargetChannel == -1)
- {
- if (is_starplanet_field(get_field_id()))
- nTargetChannel = pWvsContext->m_nChannelID == 2 ? 3 : 2;
- else
- nTargetChannel = pWvsContext->m_nChannelID + 1; // lazy af
- }
- if (pWvsContext->m_nChannelID == nTargetChannel)
- return FALSE;
- pField->SendTransferChannelRequest(nTargetChannel);
- break;
- }
- default:
- return DefWindowProc(hwnd, uMsg, wParam, lParam);
- }
- return TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement