Esempio n. 1
0
void SetResolution(int width, int height)
{
  if ( !isCorrectVersion )
    return;

  // Resize game screen data buffer
  void *newBuf = SMAlloc(width * height);
  void *oldBuf = BW::BWDATA_GameScreenBuffer->data;
  SetBitmap(BW::BWDATA_GameScreenBuffer, width, height, newBuf);
  if ( oldBuf )
    SMFree(oldBuf);

  // Set new screen limits
  BW::BWDATA_ScreenLayers[5].width  = (WORD)width;
  BW::BWDATA_ScreenLayers[5].height = (WORD)height;
  SetRect(BW::BWDATA_ScrLimit, 0, 0, width - 1, height - 1);
  SetRect(BW::BWDATA_ScrSize,  0, 0, width,     height);

  // Resize game screen console (HUD) buffer
  newBuf = SMAlloc(width * height);
  oldBuf = BW::BWDATA_GameScreenConsole->data;
  SetBitmap(BW::BWDATA_GameScreenConsole, width, height, newBuf);
  if ( oldBuf )
    SMFree(oldBuf);

  // Recreate STrans thingy
  BW::BlizzVectorEntry<BW::TransVectorEntry> *transEntry = BW::BWDATA_TransMaskVector->begin;
  if ( (u32)transEntry && (u32)transEntry != (u32)&BW::BWDATA_TransMaskVector->begin )
  {
    HANDLE oldTrans = transEntry->container.hTrans;
    SetRect(&transEntry->container.info, 0, 0, width, height);
    STransCreateE(newBuf, width, height, 8, 0, 0, &transEntry->container.hTrans);
    if ( oldTrans )
      STransDelete(oldTrans);

    // call a function that does some weird stuff
    BW::BWFXN_UpdateBltMasks();
  }

  STransSetDirtyArrayInfo(width, height, 16, 16);

  // re-initialize w-mode or ddraw, this function can do both
  SetWMode(width, height, wmode);
}
Esempio n. 2
0
void __stdcall DrawDialogHook(BW::bitmap *pSurface, BW::bounds *pBounds)
{
  if ( BW::pOldDrawDialogProc && !hideHUD )
    BW::pOldDrawDialogProc(pSurface, pBounds);

  if ( *BW::BWDATA_gwGameMode == BW::GAME_GLUES )
    BWAPI::BroodwarImpl.onMenuFrame();

  BW::dialog *timeout = BW::FindDialogGlobal("TimeOut");
  if ( timeout )
  {
    BW::dialog *dropbtn = timeout->findIndex(2);
    if ( !dropbtn->isDisabled() )
      BWAPI::BroodwarImpl.dropPlayers();
  }

  // NOSOUND config option
  if ( !nosound )
  {
    nosound = true;
    if ( LoadConfigString("starcraft", "sound", "ON") == "OFF" )
      BW::BWDATA_DSoundDestroy();
  }

  // WMODE config option
  if ( switchToWMode && ghMainWnd )
  {
    switchToWMode = false;
    SetWMode(windowRect.right, windowRect.bottom, true);
  }

  //click the menu dialog that pops up when you win/lose a game
  BW::dialog *endDialog = BW::FindDialogGlobal("LMission");
  if ( !endDialog )
    endDialog = BW::FindDialogGlobal("WMission");
  if ( endDialog )
    endDialog->findIndex(-2)->activate();
}
Esempio n. 3
0
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  if ( wmode )
  {
    // Perform W-Mode only functionality
    switch ( uMsg )
    {
    case WM_SIZING:
      {
        SIZE border;
        GetBorderSize(hWnd, &border);

        RECT *rct = (RECT*)lParam;
        SIZE ws   = { rct->right - rct->left - border.cx, rct->bottom - rct->top - border.cy };
        if ( ws.cx < WMODE_MIN_WIDTH )
        {
          ws.cx = WMODE_MIN_WIDTH;
          CorrectWindowWidth(wParam, &ws, rct, &border);
        }
        if ( ws.cy < WMODE_MIN_HEIGHT )
        {
          ws.cy = WMODE_MIN_HEIGHT;
          CorrectWindowHeight(wParam, &ws, rct, &border);
        }

        if ( GetKeyState(VK_CONTROL) & 0x8000 && ws.cy != ws.cx * 3 / 4 )
        {
          if ( wParam == WMSZ_TOP || wParam == WMSZ_BOTTOM )
          {
            ws.cx = ws.cy * 4 / 3;
            CorrectWindowWidth(WMSZ_RIGHT, &ws, rct, &border);
          }
          else
          {
            ws.cy = ws.cx * 3 / 4;
            CorrectWindowHeight( (wParam == WMSZ_RIGHT || wParam == WMSZ_LEFT) ? WMSZ_BOTTOM : wParam, &ws, rct, &border);
          }
        }

        if ( isCorrectVersion ) // must be correct version to reference BWDATA
        {
          if ( ws.cx >= BW::BWDATA::GameScreenBuffer.width() - WMODE_SNAP_RANGE &&
               ws.cx <= BW::BWDATA::GameScreenBuffer.width() + WMODE_SNAP_RANGE )
          {
            ws.cx = BW::BWDATA::GameScreenBuffer.width();
            CorrectWindowWidth( (wParam == WMSZ_TOP || wParam == WMSZ_BOTTOM) ? WMSZ_RIGHT : wParam, &ws, rct, &border);
          }
          if ( ws.cy >= BW::BWDATA::GameScreenBuffer.height() - WMODE_SNAP_RANGE &&
               ws.cy <= BW::BWDATA::GameScreenBuffer.height() + WMODE_SNAP_RANGE )
          {
            ws.cy = BW::BWDATA::GameScreenBuffer.height();
            CorrectWindowHeight( (wParam == WMSZ_RIGHT || wParam == WMSZ_LEFT) ? WMSZ_BOTTOM : wParam, &ws, rct, &border);
          }
        }
        break;
      } // case WM_SIZING
    case WM_SIZE:
      {
        switch ( wParam )
        {
        case SIZE_RESTORED:
          {
            RECT tempRect;
            GetClientRect(hWnd, &tempRect);
            windowRect.right  = tempRect.right;
            windowRect.bottom = tempRect.bottom;
            WriteConfig("window", "width", tempRect.right);
            WriteConfig("window", "height", tempRect.bottom);
            break;
          }
        }// wParam switch
        break;
      } // case WM_SIZE
    case WM_MOVE:
      {
        RECT tempRect;
        GetWindowRect(hWnd, &tempRect);
        if ( tempRect.right > 0 && 
             tempRect.bottom > 0 && 
             tempRect.left < GetSystemMetrics(SM_CXFULLSCREEN) &&
             tempRect.top  < GetSystemMetrics(SM_CYFULLSCREEN) )
        {
          windowRect.left = tempRect.left;
          windowRect.top  = tempRect.top;
          WriteConfig("window", "left", tempRect.left);
          WriteConfig("window", "top",  tempRect.top);
        }
        break;
      } // case WM_MOVE
    case WM_PAINT:
      if ( gbWantUpdate && pBits)
      {
        static DWORD dwLastUpdate = 0;
        DWORD dwNewTick = GetTickCount();
        if ( dwLastUpdate + (IsIconic(hWnd) ? 200 : 20) > dwNewTick )
          break;
        dwLastUpdate = dwNewTick;
        gbWantUpdate = false;

        // begin paint
        PAINTSTRUCT paint;
        HDC hdc = BeginPaint(hWnd, &paint);

        if ( isCorrectVersion ) // must be correct version, @todo: make independent
        {
          // Blit to the screen
          RECT cRect;
          GetClientRect(hWnd, &cRect);        
          if ( cRect.right == BW::BWDATA::GameScreenBuffer.width() && cRect.bottom == BW::BWDATA::GameScreenBuffer.height() )
          {
            BitBlt(hdc, 0, 0, BW::BWDATA::GameScreenBuffer.width(), BW::BWDATA::GameScreenBuffer.height(), hdcMem, 0, 0, SRCCOPY);
          }
          else
          {
            SetStretchBltMode(hdc, HALFTONE);
            //StretchBlt(hdc, 0, 0, cRect.right, cRect.bottom, hdcMem, 0, 0, BW::BWDATA::GameScreenBuffer->wid, BW::BWDATA::GameScreenBuffer->ht, SRCCOPY);
            StretchDIBits(hdc, 0, 0, cRect.right, cRect.bottom, 0, 0, BW::BWDATA::GameScreenBuffer.width(), BW::BWDATA::GameScreenBuffer.height(), pBits, (BITMAPINFO*)&wmodebmp, DIB_RGB_COLORS, SRCCOPY);
          }
        }

        // end paint
        EndPaint(hWnd, &paint);
      } // data
      break;
    case WM_NCMOUSEMOVE:
      SetCursorShowState(true);
      break;
    case WM_MOUSEMOVE:
      SetCursorShowState(false);
      lParam = FixPoints(lParam);
      break;
    case WM_LBUTTONDOWN:
    case WM_RBUTTONDOWN:
    case WM_MBUTTONDOWN:
      {
        RECT clientRct;
        GetClientRect(hWnd, &clientRct);
        ClientToScreen(hWnd, (LPPOINT)&clientRct.left);
        ClientToScreen(hWnd, (LPPOINT)&clientRct.right);
        ClipCursor(&clientRct);
        lParam = FixPoints(lParam);
        break;
      }
    case WM_MBUTTONUP:
    case WM_LBUTTONUP:
    case WM_RBUTTONUP:
      ClipCursor(NULL);
      lParam = FixPoints(lParam);
      break;
    case WM_MOUSEWHEEL:
    case WM_RBUTTONDBLCLK:
    case WM_LBUTTONDBLCLK:
    case WM_MBUTTONDBLCLK:
      lParam = FixPoints(lParam);
      break;
    case WM_ACTIVATEAPP:
      if ( wOriginalProc )
        return CallWindowProc(wOriginalProc, hWnd, WM_ACTIVATEAPP, (WPARAM)1, NULL);
    case WM_SETCURSOR:
    case WM_ERASEBKGND:
      return DefWindowProc(hWnd, uMsg, wParam, lParam);
    case WM_SYSKEYDOWN:
    case WM_KEYDOWN:
      if ( wParam == VK_MENU && !(lParam & 0x40000000))
      {
        RECT rct;
        GetClientRect(hWnd, &rct);
        ClientToScreen(hWnd, (LPPOINT)&rct.left);
        ClientToScreen(hWnd, (LPPOINT)&rct.right);
        ClipCursor(&rct);
        gbHoldingAlt = true;
      }
      break;
    case WM_SYSKEYUP:
    case WM_KEYUP:
      if ( wParam == VK_MENU )
      {
        ClipCursor(NULL);
        gbHoldingAlt = false;
      }
      break;
    } // switch
  } // if wmode

  if ( isCorrectVersion )
  {
    // Perform BWAPI-added functionality
    switch ( uMsg )
    {
    case WM_SYSKEYDOWN:
      if ( wParam == VK_RETURN && (lParam & 0x20000000) && !(lParam & 0x40000000) )
      {
        SetWMode(BW::BWDATA::GameScreenBuffer.width(), BW::BWDATA::GameScreenBuffer.height(), !wmode);
        return TRUE;
      }
      break;
    case WM_MOUSEMOVE:
      if ( GetWindowLong(ghMainWnd, GWL_STYLE) & WS_SYSMENU ) // Compatibility for Xen W-Mode
      {
        BW::BWDATA::InputFlags |= 1;
        POINTS pt = MAKEPOINTS(lParam);
        BW::BWDATA::Mouse.x = pt.x;
        BW::BWDATA::Mouse.y = pt.y;
        return TRUE;
      }
      break;
    case WM_LBUTTONDOWN:
    case WM_LBUTTONUP:
    case WM_LBUTTONDBLCLK:
    case WM_RBUTTONDOWN:
    case WM_RBUTTONUP:
    case WM_RBUTTONDBLCLK:
    case WM_MBUTTONDOWN:
    case WM_MBUTTONUP:
    case WM_MBUTTONDBLCLK:
      if ( GetWindowLong(ghMainWnd, GWL_STYLE) & WS_SYSMENU ) // Compatibility for Xen W-Mode
      {
        ButtonEvent(uMsg - WM_MOUSEFIRST + BW_EVN_MOUSEFIRST, lParam);
        return TRUE;
      }
      break;
    case WM_SYSCOMMAND:
      if ( wParam == SC_MAXIMIZE )
      {
        SetWMode(BW::BWDATA::GameScreenBuffer.width(), BW::BWDATA::GameScreenBuffer.height(), false);
        return TRUE;
      }
      break;
    }
  }

  // Register Broodwar thread name
  RegisterThreadName("Broodwar Main");

  // Call the original WndProc
  if ( wOriginalProc )
    return CallWindowProc(wOriginalProc, hWnd, uMsg, wParam, lParam);
  return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
Esempio n. 4
0
HWND WINAPI _CreateWindowExA(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
{
  HWND hWndReturn = NULL;
  if ( strcmp(lpClassName, "SWarClass") == 0 )
  {
    char szNewWindowName[256];
    strcpy(szNewWindowName, lpWindowName);

    size_t pos = strlen(szNewWindowName);
    if ( gdwProcNum )
      sprintf_s(&szNewWindowName[pos], 256 - pos, " Instance %u", gdwProcNum);

    detourCreateWindow = true;
    if ( switchToWMode )
    {
      HackUtil::CallPatch(BW::BWDATA_DDrawInitCallPatch, &DDInit);
      if ( _CreateWindowExAOld )
        hWndReturn = _CreateWindowExAOld(dwExStyle, 
                                          lpClassName, 
                                          szNewWindowName,
                                          dwStyle | WS_OVERLAPPEDWINDOW, 
                                          windowRect.left, 
                                          windowRect.top, 
                                          windowRect.right, 
                                          windowRect.bottom, 
                                          hWndParent, 
                                          hMenu, 
                                          hInstance, 
                                          lpParam);
      else
        hWndReturn = CreateWindowEx(dwExStyle, 
                                    lpClassName, 
                                    szNewWindowName,
                                    dwStyle | WS_OVERLAPPEDWINDOW, 
                                    windowRect.left, 
                                    windowRect.top, 
                                    windowRect.right, 
                                    windowRect.bottom, 
                                    hWndParent, 
                                    hMenu, 
                                    hInstance, 
                                    lpParam);
      ghMainWnd = hWndReturn;
      SetWMode(windowRect.right, windowRect.bottom, true);
    }
    else
    {
      if ( _CreateWindowExAOld )
        hWndReturn = _CreateWindowExAOld(dwExStyle, lpClassName, szNewWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
      else
        hWndReturn = CreateWindowEx(dwExStyle, lpClassName, szNewWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
      ghMainWnd = hWndReturn;
    }
    switchToWMode = false;
    // Obtain/hack WndProc
    wOriginalProc = (WNDPROC)GetWindowLong(hWndReturn, GWLP_WNDPROC);
    SetWindowLong(ghMainWnd, GWLP_WNDPROC, (LONG)&WindowProc);
  }
  else
  {
    if ( _CreateWindowExAOld )
      hWndReturn = _CreateWindowExAOld(dwExStyle, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
    else
      hWndReturn = CreateWindowEx(dwExStyle, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
  }
  return hWndReturn;
}