Advertisement
Guest User

cmsghandler

a guest
Sep 8th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.89 KB | None | 0 0
  1. CMsgHandler::CMsgHandler()
  2. {
  3.     this->m_hWnd = NULL;
  4. }
  5.  
  6. CMsgHandler::~CMsgHandler()
  7. {
  8. }
  9.  
  10. BOOL CMsgHandler::Init(__in HINSTANCE hInstance)
  11. {
  12.     WNDCLASSEX wc = { 0 };
  13.  
  14.     wc.cbSize = sizeof(WNDCLASSEX);
  15.     wc.lpfnWndProc = CMsgHandler::WindowProc;
  16.     wc.hInstance = hInstance;
  17.     wc.lpszClassName = TEXT(CLASS_NAME);
  18.  
  19.     if (!RegisterClassEx(&wc))
  20.     {
  21.         // :'(
  22.         return FALSE;
  23.     }
  24.  
  25.     this->m_hWnd = CreateWindowEx(0, TEXT(CLASS_NAME), NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, hInstance, NULL);
  26.     if (!this->m_hWnd)
  27.     {
  28.         UnregisterClass(TEXT(CLASS_NAME), NULL);
  29.         return FALSE;
  30.     }
  31.  
  32.     this->m_hInstance = hInstance;
  33.  
  34.     // invisible window
  35.     ShowWindow(this->m_hWnd, SW_HIDE);
  36.  
  37.     return TRUE;
  38. }
  39.  
  40. VOID CMsgHandler::Destroy()
  41. {
  42.     if (this->m_hWnd != NULL)
  43.     {
  44.         DestroyWindow(this->m_hWnd);
  45.         this->m_hWnd = NULL;
  46.     }
  47.  
  48.     UnregisterClass(TEXT(CLASS_NAME), this->m_hInstance);
  49. }
  50.  
  51. HWND CMsgHandler::GetHandle()
  52. {
  53.     return this->m_hWnd;
  54. }
  55.  
  56. LRESULT CALLBACK CMsgHandler::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  57. {
  58.     CUserLocal *pUserLocal;
  59.     CWvsContext *pWvsContext;
  60.     CPortalList *pPortalList;
  61.     CharacterData *cd;
  62.     POINT pt;
  63.     CField *pField;
  64.  
  65.     switch (uMsg)
  66.     {
  67.         case WM_CLOSE:
  68.         {
  69.             CMsgHandler::GetInstance()->Destroy();
  70.             break;
  71.         }
  72.         case WM_GET_USER_POS:
  73.         {
  74.             LPPOINT lppt = (LPPOINT)lParam;
  75.             pUserLocal = CUserLocal::GetInstance();
  76.             if (!pUserLocal)
  77.             {
  78.                 lppt->x = 0;
  79.                 lppt->y = 0;
  80.                 return FALSE;
  81.             }
  82.             else
  83.             {
  84.                 pUserLocal->VecCtrl.vfptr->GetPos(&pUserLocal->VecCtrl, lppt);
  85.             }
  86.             break;
  87.         }
  88.         case WM_GET_MAPID:
  89.         {
  90.             *(DWORD*)lParam = get_field_id();
  91.             break;
  92.         }
  93.         case WM_TALK_NPC:
  94.         {
  95.             CNpcPool *pNpcPool = CNpcPool::GetInstance();
  96.             pUserLocal = CUserLocal::GetInstance();
  97.             if (!pNpcPool || !pUserLocal)
  98.                 return FALSE;
  99.  
  100.             CNpc *pNpc = pNpcPool->FindNpcByTemplateID(wParam);
  101.             if (!pNpc)
  102.                 return FALSE;
  103.  
  104.             ZRef<CNpc> ref;
  105.             ref.p = pNpc;
  106.             InterlockedIncrement(&pNpc->ZRefCounted._m_nRef);
  107.             pUserLocal->TalkToNpc(ref);
  108.             break;
  109.         }
  110.         case WM_OnKey:
  111.         {
  112.             CWndMan *pWndMan = CWndMan::GetInstance();
  113.             if (!pWndMan || !pWndMan->m_pFocus)
  114.             {
  115.                 return FALSE;
  116.             }
  117.             pWndMan->m_pFocus->vfptr->OnKey(pWndMan->m_pFocus, wParam, lParam);
  118.             break;
  119.         }
  120.         case WM_ChangeChannel:
  121.         {
  122.             int nTargetChannel;
  123.  
  124.             pUserLocal = CUserLocal::GetInstance();
  125.             pWvsContext = CWvsContext::GetInstance();
  126.             pField = get_field();
  127.             if (!pUserLocal || !pWvsContext || !pField ||
  128.                 !pWvsContext->CanSendExclRequest(500, FALSE))
  129.             {
  130.                 return FALSE;
  131.             }
  132.  
  133.             nTargetChannel = wParam;
  134.             if (nTargetChannel == -1)
  135.             {
  136.                 if (is_starplanet_field(get_field_id()))
  137.                     nTargetChannel = pWvsContext->m_nChannelID == 2 ? 3 : 2;
  138.                 else
  139.                     nTargetChannel = pWvsContext->m_nChannelID + 1; // lazy af
  140.             }
  141.  
  142.             if (pWvsContext->m_nChannelID == nTargetChannel)
  143.                 return FALSE;
  144.  
  145.             pField->SendTransferChannelRequest(nTargetChannel);
  146.             break;
  147.         }
  148.         default:
  149.             return DefWindowProc(hwnd, uMsg, wParam, lParam);
  150.     }
  151.  
  152.     return TRUE;
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement