view Mouse.cpp @ 212:9f349addbe00

Слияние
author Ritor1
date Sat, 16 Feb 2013 22:14:04 +0600
parents ee11772d0ad2
children 650d96af8855
line wrap: on
line source

#include "OSAPI.h"

#include "Mouse.h"
#include "Items.h"
#include "Party.h"
#include "LOD.h"
#include "Game.h"
#include "Texture.h"







Mouse *pMouse;
AsyncMouse *pAsyncMouse;





//----- (00469860) --------------------------------------------------------
void Mouse::GetClickPos(unsigned int *pX, unsigned int *pY)
{
  unsigned int v3; // eax@2

  if (pAsyncMouse)
  {
    *pX = *((int *)pAsyncMouse + 6);
    v3 = *((int *)pAsyncMouse + 7);
  }
  else
  {
    *pX = this->uMouseClickX;
    v3 = this->uMouseClickY;
  }
  *pY = v3;
}

//----- (004698A6) --------------------------------------------------------
void Mouse::RemoveHoldingItem()
{
  pParty->pPickedItem.Reset();
  if (strcmpi(pCurrentCursorName, "MICON2"))
    SetCursorBitmap("MICON1");
}

//----- (004698D8) --------------------------------------------------------
void Mouse::SetCursorBitmapFromItemID(unsigned int uItemID)
{
  pMouse->SetCursorBitmap(pItemsTable->pItems[uItemID].pIconName);
}

//----- (004698F6) --------------------------------------------------------
void Mouse::SetCurrentCursorBitmap()
{
  SetCursorBitmap(pCurrentCursorName);
}

//----- (00469903) --------------------------------------------------------
void Mouse::SetCursorBitmap(const char *pName)
{
  Mouse *v2; // esi@1
  HCURSOR v3; // eax@10
  int v4; // ecx@10
  double v5; // st7@11
  float v6; // ST04_4@12
  LONG v7; // eax@14
  LONG v8; // eax@17
  unsigned int v9; // eax@21
  float v10; // [sp+4h] [bp-18h]@11
  struct tagPOINT Point; // [sp+14h] [bp-8h]@20

  v2 = this;
  if ( !this->bInitialized || !pName )
    return;
  if ( _strcmpi("MICON2", pName) )
    pGame->uFlags2 &= 0xFFFFFFEFu;
  else
    pGame->uFlags2 |= 0x10u;
  if ( _strcmpi(v2->pCurrentCursorName, pName) )
    strcpy(v2->pCurrentCursorName, pName);
  ClearCursor();
  if ( _strnicmp(pName, "MICON1", 5u) )
  {
    v9 = pIcons_LOD->LoadTexture(pName, TEXTURE_16BIT_PALETTE);
    v2->uCursorTextureID = v9;
    v2->uCursorTextureID_2 = v9;
    v2->AllocCursorSystemMem();
    v2->field_C = 0;
    v2->field_14 = 1;
    v2->bActive = 1;
    if ( !areWeLoadingTexture )
    {
      if (uCursorTextureID != -1)
        pIcons_LOD->pTextures[uCursorTextureID].Release();
      pIcons_LOD->_40F9C5();
    }
    return;
  }
  v2->bActive = 0;
  v2->field_C = 1;
  if ( !strcmp(pName, "MICON1") )
  {
    v3 = LoadCursorA(GetModuleHandleW(nullptr), "Arrow");
    SetClassLongA(hWnd, GCL_HCURSOR, (LONG)v3);
    v4 = (int)pAsyncMouse;
    if (pAsyncMouse)
    {
      v10 = 0.0;
      v5 = 0.0;
LABEL_12:
      v6 = v5;
      pAsyncMouse->SetHotspot(v6, v10);
      goto LABEL_18;
    }
    goto LABEL_20;
  }
  if ( !strcmp(pName, "MICON2") )
  {
    v7 = (LONG)LoadCursorA(GetModuleHandleW(nullptr), "Target");
    SetClassLongA(hWnd, -12, v7);
    v4 = (int)pAsyncMouse;
    if (pAsyncMouse)
    {
      v10 = 14.0;
      v5 = 14.0;
      goto LABEL_12;
    }
LABEL_20:
    GetCursorPos(&Point);
    SetCursorPos(Point.x, Point.y);
    return;
  }
  if ( !strcmp(pName, "MICON3") )
  {
    v8 = (LONG)LoadCursorA(0, (LPCSTR)IDC_WAIT);
    SetClassLongA(hWnd, -12, v8);
  }
LABEL_18:
  if ( !pAsyncMouse || (pAsyncMouse->LoadCursor(pName), !pAsyncMouse) )
    goto LABEL_20;
}
// 506128: using guessed type int areWeLoadingTexture;

//----- (00469AE4) --------------------------------------------------------
LONG Mouse::_469AE4()
{
  Mouse *v1; // esi@1
  LONG v2; // ecx@2
  LONG result; // eax@2
  struct tagPOINT Point; // [sp+Ch] [bp-8h]@2

  v1 = this;
  this->field_8 = 1;
  if (pAsyncMouse)
  {
    v2 = *((int *)pAsyncMouse + 6);
    Point.x = *((int *)pAsyncMouse + 6);
    result = *((int *)pAsyncMouse + 7);
  }
  else
  {
    GetCursorPos(&Point);
    if ( pRenderer->bWindowMode )
      ScreenToClient(hWnd, &Point);
    result = Point.y;
    v2 = Point.x;
  }
  v1->uMouseClickX = v2;
  v1->uMouseClickY = result;
  if ( pRenderer->bWindowMode )
    goto LABEL_16;
  if (pAsyncMouse)
    goto LABEL_24;
  if ( v2 < 0 )
    v2 = 0;
  if ( result < 0 )
    result = 0;
  if ( v2 > 639 )
    v2 = 639;
  if ( result > 479 )
  {
    result = 479;
LABEL_16:
    if (pAsyncMouse)
      goto LABEL_24;
    if ( pRenderer->bWindowMode && (v2 < 0 || result < 0 || v2 > 639 || result > 479) )
      goto LABEL_23;
  }
  if ( v1->field_C )
LABEL_23:
    v1->bActive = 0;
LABEL_24:
  v1->field_8 = 0;
  return result;
}

//----- (00469BA3) --------------------------------------------------------
void Mouse::ClearCursor()
{
  Mouse *v1; // esi@1
  void *v2; // eax@1
  void **v3; // esi@5

  v1 = this;
  v2 = this->pCursorBitmap_sysmem;
  this->bActive = 0;
  if ( v2 )
  {
    free(v2);
    v1->pCursorBitmap_sysmem = 0;
  }
  if ( v1->pCursorBitmap2_sysmem )
  {
    free(v1->pCursorBitmap2_sysmem);
    v1->pCursorBitmap2_sysmem = 0;
  }
  v3 = &v1->ptr_90;
  if ( *v3 )
    free(*v3);
  *v3 = 0;
}

//----- (00469BE6) --------------------------------------------------------
void Mouse::AllocCursorSystemMem()
{
  bActive = 0;
  if (!pCursorBitmap_sysmem)
    pCursorBitmap_sysmem = (unsigned __int16 *)DoAllocCursorMem();
  if (!pCursorBitmap2_sysmem)
    pCursorBitmap2_sysmem = (unsigned __int8 *)DoAllocCursorMem();
}

//----- (00469C0D) --------------------------------------------------------
void *Mouse::DoAllocCursorMem()
{
  return malloc(4 * (this->uCursorTextureID != -1 ? pIcons_LOD->pTextures[this->uCursorTextureID].uTextureWidth : 24)
                  * (this->uCursorTextureID != -1 ? pIcons_LOD->pTextures[this->uCursorTextureID].uTextureHeight : 26));
}

//----- (00469C39) --------------------------------------------------------
POINT *Mouse::GetCursorPos(POINT *a2)
{
  void *v2; // edx@1
  POINT *result; // eax@1
  unsigned int v4; // ecx@2
  unsigned int v5; // edx@3

  v2 = pAsyncMouse;
  result = a2;
  if (pAsyncMouse)
  {
    a2->x = *((int *)pAsyncMouse + 6);
    v4 = *((int *)v2 + 7);
  }
  else
  {
    v5 = this->uMouseClickX;
    v4 = this->uMouseClickY;
    a2->x = v5;
  }
  a2->y = v4;
  return result;
}

//----- (00469C65) --------------------------------------------------------
void Mouse::Initialize(HWND hWnd)
{
  this->hWnd = hWnd;
  this->bActive = 0;
  this->bInitialized = 1;
  this->pCursorBitmapPos.x = 0;
  this->pCursorBitmapPos.y = 0;
  this->uMouseClickX = 0;
  this->uMouseClickY = 0;
  this->pCursorBitmap_sysmem = 0;
  this->field_34 = 0;
  this->pCursorBitmap2_sysmem = 0;

  SetCursorBitmap("MICON3");
  SetCursorBitmap("MICON2");
  SetCursorBitmap("MICON1");
}

//----- (00469CC2) --------------------------------------------------------
void Mouse::Deactivate()
{
  if (bInitialized)
    bActive = false;
}

//----- (00469CCD) --------------------------------------------------------
void Mouse::DrawCursor()
{
  Mouse *v1; // esi@1
  char v11; // zf@6
  signed int v3; // eax@6
  signed int v4; // ecx@6
  Vec4_int_ *v5; // edx@21
  int v6; // edi@21
  int v7; // ebx@21
  int v8; // eax@29
  unsigned int v9; // eax@31

  v1 = this;
  if ( this->bInitialized )
  {
    if ( !this->field_8 && this->bActive && !this->field_C )
      pMouse->_469AE4();
    v11 = v1->field_C == 0;
    v3 = v1->uMouseClickX;
    v4 = v1->uMouseClickY;
    v1->field_F4 = 1;
    if ( !v11 )
      goto LABEL_12;
    if ( pRenderer->bWindowMode )
    {
      if ( v3 < 0 || v4 < 0 || v3 > 639 || v4 > 479 )
      {
LABEL_12:
        v1->field_F4 = 0;
        return;
      }
    }
    else
    {
      if ( v3 < 0 )
        v3 = 0;
      if ( v4 < 0 )
        v4 = 0;
      if ( v3 > 639 )
        v3 = 639;
      if ( v4 > 479 )
        v4 = 479;
    }
    v5 = &v1->pCursorBitmapRect;
    v6 = v3 + v1->uCursorBitmapPitch;
    v7 = v4 + v1->field_5C[0];
    v1->pCursorBitmapRect.y = v4;
    v1->pCursorBitmapRect.x = v3;
    v1->pCursorBitmapRect.z = v6;
    v1->pCursorBitmapRect.w = v7;
    if ( v3 < 0 )
      v5->x = 0;
    if ( v4 < 0 )
      v1->pCursorBitmapRect.y = 0;
    if ( v6 > 640 )
      v1->pCursorBitmapRect.z = 640;
    if ( v7 > 480 )
      v1->pCursorBitmapRect.w = 480;
    v8 = v1->pCursorBitmapRect.z;
    v1->bActive = 0;
    v1->uCursorBitmapWidth = v8 - v5->x;
    v11 = v1->field_14 == 0;
    v1->uCursorBitmapHeight = v1->pCursorBitmapRect.w - v1->pCursorBitmapRect.y;
    if ( !v11 )
    {
      if ( pMouse->ptr_90 )
        v9 = 2 * pMouse->uCursorBitmapPitch;
      else
        v9 = 0;
      pRenderer->_4A6DF5(
        v1->pCursorBitmap_sysmem,
        v9,
        &v1->pCursorBitmapPos,
        pRenderer->pTargetSurface,
        pRenderer->uTargetSurfacePitch,
        &v1->pCursorBitmapRect);
      v1->field_14 = 0;
    }
  }
}

//----- (00469E1C) --------------------------------------------------------
void Mouse::_469E1C()
{
  bActive = true;
}

//----- (00469E24) --------------------------------------------------------
void Mouse::_469E24()
{
  if (pCursorBitmap3_sysmembits_16bit)
  {
    free(pCursorBitmap3_sysmembits_16bit);
    pCursorBitmap3_sysmembits_16bit = 0;
  }
}

//----- (00469E3B) --------------------------------------------------------
void Mouse::DrawCursorToTarget()
{
  if (!pCursorBitmap3_sysmembits_16bit)
    return;

  auto pSrc = pCursorBitmap3_sysmembits_16bit;
  for (uint y = field_44; y < field_4C; ++y)
    for (uint x = field_40; x < field_48; ++x)
      pRenderer->pTargetSurface[y * pRenderer->uTargetSurfacePitch + x] = *pSrc++;
}

//----- (00469EA4) --------------------------------------------------------
void Mouse::_469EA4()
{
  Mouse *v1; // esi@1
  unsigned int v2; // eax@2
  Texture *v3; // edi@2
  unsigned int v4; // ecx@3
  unsigned int v5; // eax@3
  unsigned int v6; // ebx@5
  int v7; // ecx@15
  int v8; // ecx@25
  int v9; // ebx@26
  unsigned int v10; // eax@26
  int v11; // edx@27
  unsigned __int16 *v12; // edx@29
  unsigned __int16 *v13; // ebx@29
  unsigned int a2; // [sp+Ch] [bp-1Ch]@5
  unsigned int v15; // [sp+10h] [bp-18h]@5
  unsigned int v16; // [sp+14h] [bp-14h]@25
  unsigned __int16 *v17; // [sp+18h] [bp-10h]@25
  int v18; // [sp+1Ch] [bp-Ch]@27
  int v19; // [sp+20h] [bp-8h]@15
  unsigned __int16 *v20; // [sp+20h] [bp-8h]@28
  int v21; // [sp+24h] [bp-4h]@12
  unsigned __int16 *v22; // [sp+24h] [bp-4h]@25

  v1 = this;
  if ( pParty->pPickedItem.uItemID )
  {
    v2 = pIcons_LOD->LoadTexture(
           pItemsTable->pItems[pParty->pPickedItem.uItemID].pIconName,
           TEXTURE_16BIT_PALETTE);
    v3 = (Texture *)(v2 != -1 ? (int)&pIcons_LOD->pTextures[v2] : 0);
    if (pAsyncMouse)
    {
      v4 = *((int *)pAsyncMouse + 6);
      v5 = *((int *)pAsyncMouse + 7);
    }
    else
    {
      v4 = pMouse->uMouseClickX;
      v5 = pMouse->uMouseClickY;
    }
    v6 = v5;
    a2 = v4;
    v15 = v5;
    if ( (signed int)v4 <= 639 && (signed int)v5 <= 479 )
    {
      if ( (v4 & 0x80000000u) != 0 )
        a2 = 0;
      if ( (v5 & 0x80000000u) != 0 )
      {
        v6 = 0;
        v15 = 0;
      }
      if ( (signed int)(v3->uTextureWidth + a2) <= 640 )
        v21 = v3->uTextureWidth;
      else
        v21 = 640 - a2;
      if ( (signed int)(v3->uTextureHeight + v6) <= 480 )
      {
        v19 = v3->uTextureHeight;
        v7 = v3->uTextureHeight;
      }
      else
      {
        v7 = 480 - v6;
        v19 = 480 - v6;
      }
      if ( !v1->pCursorBitmap3_sysmembits_16bit
        || a2 != v1->field_40
        || v6 != v1->field_44
        || a2 + v21 != v1->field_48
        || v6 + v7 != v1->field_4C )
      {
        if ( v1->pCursorBitmap3_sysmembits_16bit )
          free(v1->pCursorBitmap3_sysmembits_16bit);
        v1->pCursorBitmap3_sysmembits_16bit = (unsigned __int16 *)operator new(2 * v3->uTextureHeight
                                                                                 * v3->uTextureWidth);
        v1->field_40 = a2;
        v1->field_48 = a2 + v21;
        v1->field_44 = v6;
        v1->field_4C = v6 + v19;
      }
      v8 = v1->field_44;
      v22 = v1->pCursorBitmap3_sysmembits_16bit;
      v17 = pRenderer->pTargetSurface;
      v16 = pRenderer->uTargetSurfacePitch;
      if ( v8 < v1->field_4C )
      {
        v9 = v1->field_48;
        v10 = pRenderer->uTargetSurfacePitch * v8;
        do
        {
          v11 = v1->field_40;
          v18 = v1->field_40;
          if ( v11 < v9 )
          {
            v20 = &v17[v10 + v11];
            do
            {
              v12 = v20;
              v13 = v22;
              ++v18;
              ++v20;
              ++v22;
              *v13 = *v12;
              v9 = v1->field_48;
            }
            while ( v18 < v9 );
          }
          v10 += v16;
          ++v8;
        }
        while ( v8 < v1->field_4C );
        v6 = v15;
      }
      if ( pParty->pPickedItem.uAttributes & 2 )
      {
        pRenderer->_4A6776(a2, v6, v3);
      }
      else
      {
        if ( pParty->pPickedItem.uAttributes & 1 )
          pRenderer->DrawTextureTransparent(a2, v6, v3);
        else
          pRenderer->DrawTransparentGreenShade(a2, v6, v3);
      }
    }
  }
  else
  {
    if ( this->pCursorBitmap3_sysmembits_16bit )
    {
      free(this->pCursorBitmap3_sysmembits_16bit);
      v1->pCursorBitmap3_sysmembits_16bit = 0;
    }
  }
}

//----- (0046A080) --------------------------------------------------------
void Mouse::Activate(int bActive)
{
  bActive = bActive;
}

//----- (0046A08A) --------------------------------------------------------
void Mouse::SetMouseClick(int x, int y)
{
  uMouseClickX = x;
  uMouseClickY = y;
}


//----- (00409E3D) --------------------------------------------------------
void AsyncMouse::_409E3D(char a2)
{
  if ( *((unsigned char *)this + 128) & 1 )
    *((unsigned char *)this + 103) = 1;
  else
    *((unsigned char *)this + 103) = 0;
  if ( a2 )
    *((unsigned int *)this + 32) |= 1u;
  else
    *((unsigned int *)this + 32) &= 0xFFFFFFFEu;
}

//----- (00465C2C) --------------------------------------------------------
void AsyncMouse::Release()
{
  if (pAsyncMouse)
  {
    pAsyncMouse->Suspend();
    if (pAsyncMouse)
      (**(void (__stdcall ***)(int))pAsyncMouse)(1);
  }
  pAsyncMouse = 0;
}




//----- (0046ACA9) --------------------------------------------------------
AsyncMouse::AsyncMouse(IDirectDrawSurface *a2)
{
  IDirectDrawSurface *v2; // eax@1
  void *v3; // esi@1
  char *v4; // edi@1
  double v5; // ST14_8@3
  double v6; // ST14_8@3

  v2 = a2;
  v3 = this;
  *((int *)this + 16) = -1;
  *((int *)this + 3) = (int)v2;
  LOBYTE(v2) = BYTE3(a2);
  v4 = (char *)this + 104;
  *((int *)this + 1) = 0;
  *((char *)this + 20) = 0;
  *((int *)this + 17) = 0;
  *((int *)this + 18) = 0;
  *((char *)this + 88) = 1;
  *((char *)this + 91) = 0;
  *((char *)this + 93) = 0;
  *((char *)this + 94) = 0;
  *((char *)this + 95) = 0;
  *((char *)this + 96) = 0;
  *((char *)this + 97) = 0;
  *((char *)this + 98) = 0;
  *((char *)this + 99) = 0;
  *((char *)this + 100) = 0;
  *((char *)this + 101) = 0;
  *((char *)this + 102) = 0;
  *((char *)this + 104) = (char)v2;
  *((int *)this + 27) = (int)AsyncMouse::unk_46BD09(0, 0);
  *((int *)v4 + 2) = 0;
  *((char *)v3 + 116) = BYTE3(a2);
  *((int *)v3 + 30) = (int)AsyncMouse::unk_46BD09(0, 0);
  *((int *)v3 + 31) = 0;
  *((int *)v3 + 32) = 0;
  *((int *)v3 + 33) = 0;
  *(int *)v3 = 5080880;
  if ( !Initialize(this) )
  {
    MessageBoxW(nullptr, L"Could not initialize CMouseAsync object", nullptr, 0);
  }
  *((int *)v3 + 12) = 0;
  *((int *)v3 + 13) = 0;
  *((int *)v3 + 14) = 0;
  *((int *)v3 + 15) = 0;
  v5 = (float)0.0 + 6.7553994e15;
  *((int *)v3 + 10) = LODWORD(v5);
  v6 = (float)0.0 + 6.7553994e15;
  a2 = (IDirectDrawSurface *)LODWORD(v6);
  *((int *)v3 + 32) |= 1u;
  *((int *)v3 + 11) = LODWORD(v6);
  *((char *)v3 + 103) = 1;
}
// 4DBD94: using guessed type int dword_4DBD94;



//----- (0046ADE2) --------------------------------------------------------
AsyncMouse::~AsyncMouse()
{
  void *v1; // esi@1
  char *v2; // edi@1
  int v3; // ecx@1

  v1 = this;
  //*(int *)this = AsyncMouse_pvdtor;
  v2 = (char *)this + 132;
  v3 = *((int *)this + 33);
  if ( v3 )
    (**(void (__stdcall ***)(int))v3)(1);
  *(int *)v2 = 0;
  TerminateThread(*((HANDLE *)v1 + 4), 0xFAu);
  SetWindowPos(hWnd, (HWND)0xFFFFFFFE, uWindowX, uWindowY, 640, 480, 0);
  //AsyncMouse::dtor_sub_46BC73((int)((char *)v1 + 116));
  //AsyncMouse::dtor_sub_46BC73((int)((char *)v1 + 104));
}
// 4D8730: using guessed type int (__stdcall *AsyncMouse_pvdtor[2])(char);













//----- (0046AE6E) --------------------------------------------------------
char AsyncMouse::Initialize(LPVOID lpParameter)
{
  void *v1; // esi@1
  char result; // al@2

  v1 = lpParameter;
  if ( LoadCursorImage() && _46B072() )
    result = CreateDisrectInputMouse() != 0;
  else
    result = 0;
  return result;
}

//----- (0046AE97) --------------------------------------------------------
char AsyncMouse::LoadCursor(const char *pContainer)
{
  __debugbreak();
  return 0;
  /*
  void *v2; // esi@1
  int v3; // eax@1
  HRESULT v4; // eax@1
  char result; // al@3
  HRESULT a2; // [sp+8h] [bp-B0h]@1
  int v7; // [sp+58h] [bp-60h]@1
  char v9; // [sp+B4h] [bp-4h]@1

  v2 = this;
  EnterCriticalSection(&pGame->pThreadWardInstance->cs2);
  v3 = *((int *)v2 + 1);
  a2 = 100;
  v7 = 0;
  v4 = (*(int (__stdcall **)(int, int, int, int, signed int, HRESULT *))(*(int *)v3 + 20))(
         v3,
         0,
         0,
         0,
         1024,
         &a2);
  ErrHR(v4, "DirectInput", __FUNCTION__, __FILE__, __LINE__);
  
  Texture thisa; // [sp+6Ch] [bp-4Ch]@1
  //Texture::Texture(&thisa);

  if ( pIcons_LOD->LoadTextureFromLOD(&thisa, pContainer, TEXTURE_16BIT_PALETTE) != -1
    && DrawCursor(&thisa, *((IDirectDrawSurface4 **)v2 + 1), 0) )
  {
    thisa.Release();
    LeaveCriticalSection(&pGame->pThreadWardInstance->cs2);
    result = 1;
  }
  else
  {
    result = 0;
  }
  return result;*/
}

//----- (0046AF50) --------------------------------------------------------
char AsyncMouse::LoadCursorImage()
{
  void *v1; // ebx@1
  int v2; // eax@2
  int v3; // esi@4
  char result; // al@5
  //const char *v5; // eax@6
  //std::string v6; // [sp-18h] [bp-12Ch]@9
  const char *v7; // [sp-8h] [bp-11Ch]@9
  int v8; // [sp-4h] [bp-118h]@9
  DDSURFACEDESC2 Dst; // [sp+Ch] [bp-108h]@1
  int v10; // [sp+88h] [bp-8Ch]@2
  int v11; // [sp+8Ch] [bp-88h]@2
  int v12; // [sp+90h] [bp-84h]@2
  int v13; // [sp+94h] [bp-80h]@2
  char v14; // [sp+D0h] [bp-44h]@2
  int v15; // [sp+F0h] [bp-24h]@2
  int v16; // [sp+104h] [bp-10h]@4
  int v17; // [sp+108h] [bp-Ch]@4
  std::string *v18; // [sp+10Ch] [bp-8h]@9
  int a3; // [sp+113h] [bp-1h]@9

  v1 = this;
  memset(&Dst, 0, 0x7Cu);
  Dst.dwSize = 124;
  if ( pRenderer->pDirectDraw4->GetDisplayMode(&Dst)
    || (memset(&v10, 0, 0x7Cu),
        v10 = 124,
        v11 = 4103,
        v15 = 2112,
        v12 = 32,
        v13 = 32,
        v2 = *((int *)v1 + 3),
        memcpy(&v14, &Dst.ddpfPixelFormat, 0x20u),
        (*(int (__stdcall **)(int, int *, char *, int))(**(int **)v2 + 24))(
          *(int *)v2,
          &v10,
          (char *)v1 + 4,
          0))
    || (*(int (__stdcall **)(int, int *, char *, int))(***((int ***)v1 + 3) + 24))(
         **((int **)v1 + 3),
         &v10,
         (char *)v1 + 8,
         0)
    || (v3 = *((int *)v1 + 1),
        v16 = 0,
        v17 = 0,
        (*(int (__stdcall **)(int, signed int, int *))(*(int *)v3 + 116))(v3, 8, &v16)) )
  {
    result = 0;
    return false;
  }
  else
  {
    if ( !LoadCursor("micon1") )
    {
      MessageBoxW(nullptr, L"Could not load async mouse cursor image", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\MouseAsync.cpp:182", 0);
    }
    result = 1;
    return true;
  }
  return result;
}
// 4D86F0: using guessed type int dword_4D86F0;

//----- (0046B072) --------------------------------------------------------
char AsyncMouse::_46B072()
{
  DWORD v1; // esi@1
  HANDLE v2; // eax@1
  char result; // al@2
  DWORD ThreadId; // [sp+0h] [bp-4h]@1

  ThreadId = (DWORD)this;
  v1 = (DWORD)this;
  v2 = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)AsyncMouseThread, this, 4u, &ThreadId);
  *(int *)(v1 + 16) = (int)v2;
  if ( v2 )
    result = SetThreadPriority(v2, 15) != 0;
  else
    result = 0;
  return result;
}

//----- (0046B0A9) --------------------------------------------------------
char AsyncMouse::CreateDisrectInputMouse()
{
  __debugbreak();
  /*
  void *v1; // esi@1
  DirectInputMouse *v2; // ecx@1
  DirectInputMouse *v3; // eax@2

  v1 = this;
  v2 = (DirectInputMouse *)operator new(0x2Cu);
  if ( v2 )
    v3 = DirectInputMouse::DirectInputMouse(v2);
  else
    v3 = 0;
  *((int *)v1 + 33) = v3;
  return v3 != 0;*/
  return 0;
}

//----- (0046B0ED) --------------------------------------------------------
int AsyncMouse::_46B0ED()
{
  __debugbreak();
  /*
  int v1; // esi@1
  int v2; // ecx@1
  int result; // eax@2

  v1 = this + 132;
  v2 = *(int *)(this + 132);
  if ( v2 )
    result = (**(int (__stdcall ***)(int))v2)(1);
  *(int *)v1 = 0;
  return result;*/
  return 0;
}
// 46B0ED: using guessed type int __thiscall AsyncMouse__46B0ED(int);

//----- (0046B105) --------------------------------------------------------
void AsyncMouse::Resume()
{
  __debugbreak();
  /*
  void *v1; // esi@1

  v1 = this;
  EnterCriticalSection(&pGame->pThreadWardInstance->cs3);
  AsyncMouse::CreateDisrectInputMouse(v1);
  AsyncMouse::Clip();
  ResumeThread(*((HANDLE *)v1 + 4));
  *((char *)v1 + 88) = 0;
  LeaveCriticalSection(&pGame->pThreadWardInstance->cs3);*/
}

//----- (0046B14F) --------------------------------------------------------
void AsyncMouse::Suspend()
{
  void *v1; // esi@1
  Vis *v2; // eax@3
  std::string v3; // [sp-18h] [bp-24h]@2
  const char *v4; // [sp-8h] [bp-14h]@2
  int v5; // [sp-4h] [bp-10h]@2
  std::string *v6; // [sp+4h] [bp-8h]@2
  int a3; // [sp+Bh] [bp-1h]@2

  v1 = this;
  if ( *((int *)this + 33) )
  {
    v2 = pGame->pVisInstance;
    if ( v2 )
      v2->stru1.uNumPointers = 0;
    EnterCriticalSection(&pGame->pThreadWardInstance->cs3);
    SuspendThread(*((HANDLE *)v1 + 4));
    _46B0ED();
    LeaveCriticalSection(&pGame->pThreadWardInstance->cs3);
  }
  else
  {
      MessageBoxW(nullptr, L"DI_Mouse pointer invalid; bailing out from suspend()", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\MouseAsync.cpp:233", 0);
  }
}
// 46B0ED: using guessed type int __thiscall AsyncMouse__46B0ED(int);

//----- (0046B1DD) --------------------------------------------------------
char AsyncMouse::_46B1DD()
{
  *((char *)this + 20) = 1;
  Sleep(118);
  return 1;
}

//----- (0046B1EC) --------------------------------------------------------
bool AsyncMouse::DrawCursor(Texture *a1, IDirectDrawSurface4 *a2, int a3)
{
  __debugbreak();
  /*
  bool result; // eax@1
  unsigned __int16 *v5; // ebx@2
  unsigned __int8 *v6; // edx@2
  int v7; // esi@2
  int v8; // ecx@2
  LPVOID v9; // edi@2
  int v10; // ecx@5
  DDSURFACEDESC2 Dst; // [sp+0h] [bp-84h]@1
  __int32 v12; // [sp+7Ch] [bp-8h]@3
  int v13; // [sp+80h] [bp-4h]@3

  Dst.dwSize = 124;
  result = pRenderer->LockSurface_DDraw4(a2, &Dst, DDLOCK_WAIT);
  if ( result )
  {
    v5 = a1->pPalette16;
    v6 = a1->pLevelOfDetail0;
    v7 = a1->uTextureWidth;
    v8 = a1->uTextureHeight;
    v9 = Dst.lpSurface;
    if ( v8 > 0 )
    {
      v12 = 2 * (Dst.lPitch / 2 - v7);
      v13 = v8;
      do
      {
        if ( v7 > 0 )
        {
          v10 = v7;
          do
          {
            if ( v5[*v6] )
              *(short *)v9 = v5[*v6];
            v9 = (char *)v9 + 2;
            ++v6;
            --v10;
          }
          while ( v10 );
        }
        v9 = (char *)v9 + v12;
        --v13;
      }
      while ( v13 );
    }
    result = a2->Unlock(
               v6,
               a2,
               a3);
  }
  LOBYTE(result) = 1;
  return result;*/
  return 0;
}

//----- (0046B289) --------------------------------------------------------
bool AsyncMouse::_46B289(int a2, char a3)
{
  char v3; // dl@1
  bool result; // eax@33
  char v5; // [sp+2h] [bp-2h]@1
  char v6; // [sp+3h] [bp-1h]@1

  v3 = *((char *)this + 93);
  v6 = *((char *)this + 94);
  v5 = *((char *)this + 95);
  if ( a3 & 1 )
  {
    *((char *)this + 93) = 1;
  }
  else
  {
    if ( v3 )
      *((char *)this + 99) = 1;
    else
      *((char *)this + 99) = 0;
    *((char *)this + 93) = 0;
  }
  if ( a3 & 2 )
  {
    *((char *)this + 94) = 1;
  }
  else
  {
    if ( v6 )
      *((char *)this + 100) = 1;
    else
      *((char *)this + 100) = 0;
    *((char *)this + 94) = 0;
  }
  if ( a3 & 4 )
  {
    *((char *)this + 95) = 1;
  }
  else
  {
    if ( v5 )
      *((char *)this + 101) = 1;
    else
      *((char *)this + 101) = 0;
    *((char *)this + 95) = 0;
  }
  *((char *)this + 96) = v3 != *((char *)this + 93);
  *((char *)this + 97) = v6 != *((char *)this + 94);
  *((char *)this + 98) = v5 != *((char *)this + 95);
  if ( *((char *)this + 99) && *((char *)this + 96) || *((char *)this + 100) && *((char *)this + 97) )
    *((char *)this + 102) = 1;
  LOBYTE(result) = 1;
  return result;
}

//----- (0046B342) --------------------------------------------------------
void AsyncMouse::SetHotspot(float hotspotx, float hotspoty)
{
  double v3; // ST00_8@1
  double v4; // ST00_8@1

  v3 = hotspotx + 6.7553994e15;
  *(int *)(this + 40) = LODWORD(v3);
  v4 = hotspoty + 6.7553994e15;
  *(int *)(this + 44) = LODWORD(v4);
}

//----- (0046B37C) --------------------------------------------------------
int AsyncMouse::UpdateData(int a2)
{
  __debugbreak();
  /*
  void *v2; // edi@1
  int result; // eax@2
  int v4; // eax@3
  int v5; // esi@3
  std::string v6; // [sp-18h] [bp-28h]@2
  const char *v7; // [sp-8h] [bp-18h]@2
  int v8; // [sp-4h] [bp-14h]@2
  std::string *v9; // [sp+8h] [bp-8h]@2
  int a3; // [sp+Fh] [bp-1h]@2

  v2 = this;
  if ( *((int *)this + 33) )
  {
    EnterCriticalSection(&pGame->pThreadWardInstance->cs3);
    DirectInputMouse::_43BB89(*((DirectInputMouse **)v2 + 33));
    v4 = *((int *)v2 + 33);
    v5 = v4 + 32;
    _46B289(v4 + 32, *(int *)(v4 + 40));
    LeaveCriticalSection(&pGame->pThreadWardInstance->cs3);
    result = a2;
    *(int *)a2 = *(int *)v5;
    *(int *)(a2 + 4) = *(int *)(v5 + 4);
  }
  else
  {
    MessageBoxW(nullptr, L"DI_Mouse pointer invalid bailing out from update_mouse_data()", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\MouseAsync.cpp:446", 0);
    result = a2;
    *(int *)a2 = 0;
    *(int *)(a2 + 4) = 0;
  }
  return result;*/
  return 0;
}

//----- (0046B420) --------------------------------------------------------
char AsyncMouse::Thread()
{
  void *v1; // esi@1
  char result; // al@2
  int v3; // eax@3
  int v4; // ecx@3
  int v5; // eax@3
  int v6; // ecx@3
  int v7; // [sp+4h] [bp-8h]@3
  int v8; // [sp+8h] [bp-4h]@3

  v1 = this;
  if ( *((char *)this + 20) )
  {
    result = 0;
  }
  else
  {
    UpdateData((int)&v7);
    _46BA8D(v7, v8);
    _46B958(v7 - *((int *)v1 + 10), v8 - *((int *)v1 + 11));
    _46B492((int)&v7);
    _46B5D5((int)&v7);
    v3 = v7;
    v4 = v8;
    *((int *)v1 + 6) = v7;
    v5 = v3 - *((int *)v1 + 10);
    *((int *)v1 + 7) = v4;
    v6 = v4 - *((int *)v1 + 11);
    *((int *)v1 + 8) = v5;
    result = 1;
    *((int *)v1 + 9) = v6;
  }
  return result;
}

//----- (0046B492) --------------------------------------------------------
void AsyncMouse::_46B492(int a2)
{
  __debugbreak();
  /*
  void *v2; // edi@1
  int v3; // esi@3
  int v4; // eax@5
  int v5; // ecx@5
  int v6; // eax@8
  int v7; // ecx@8
  int v8; // eax@11
  int v9; // esi@11
  int v10; // [sp+Ch] [bp-1Ch]@5
  int v11; // [sp+10h] [bp-18h]@5
  int v12; // [sp+14h] [bp-14h]@5
  int v13; // [sp+18h] [bp-10h]@5
  int v14; // [sp+24h] [bp-4h]@5

  v2 = this;
  EnterCriticalSection(&pGame->pThreadWardInstance->csAsyncMouse);
  if ( *((int *)v2 + 28) > 0x80u )
    _46BCAB((char *)v2 + 104);
  v3 = a2;
  if ( *((char *)v2 + 93) && *((char *)v2 + 96) )
  {
    v4 = *(int *)a2;
    v5 = *(int *)(a2 + 4);
    v13 = 1;
    v10 = 5080884;
    v11 = v4;
    v12 = v5;
    v14 = 0;
    AsyncMouse::unk_46BCD2((char *)v2 + 104, (int)&a2, *((int *)v2 + 27), (int)&v10);
    v14 = -1;
  }
  if ( *((char *)v2 + 94) && *((char *)v2 + 97) )
  {
    v6 = *(int *)v3;
    v7 = *(int *)(v3 + 4);
    v13 = 2;
    v10 = 5080884;
    v11 = v6;
    v12 = v7;
    v14 = 1;
    AsyncMouse::unk_46BCD2((char *)v2 + 104, (int)&a2, *((int *)v2 + 27), (int)&v10);
    v14 = -1;
  }
  if ( *((char *)v2 + 95) && *((char *)v2 + 98) )
  {
    v8 = *(int *)v3;
    v9 = *(int *)(v3 + 4);
    v13 = 4;
    v10 = 5080884;
    v11 = v8;
    v12 = v9;
    v14 = 2;
    AsyncMouse::unk_46BCD2((char *)v2 + 104, (int)&a2, *((int *)v2 + 27), (int)&v10);
  }
  LeaveCriticalSection(&pGame->pThreadWardInstance->csAsyncMouse);*/
}

//----- (0046B5D5) --------------------------------------------------------
void AsyncMouse::_46B5D5(int a2)
{
  __debugbreak();
  /*
  void *v2; // esi@1
  DWORD v3; // eax@3
  char v4; // zf@3
  int v5; // edi@3
  int v6; // eax@6
  int v7; // ecx@6
  int v8; // eax@11
  int v9; // ecx@11
  int v10; // eax@16
  int v11; // edi@16
  int (__stdcall **v12)(char); // [sp+Ch] [bp-20h]@6
  int v13; // [sp+10h] [bp-1Ch]@6
  int v14; // [sp+14h] [bp-18h]@6
  int v15; // [sp+18h] [bp-14h]@6
  DWORD v16; // [sp+1Ch] [bp-10h]@3
  int v17; // [sp+28h] [bp-4h]@6

  v2 = this;
  EnterCriticalSection(&pGame->pThreadWardInstance->csAsyncMouse);
  if ( *((int *)v2 + 31) > 0x80u )
    _46BCAB((char *)v2 + 116);
  v3 = timeGetTime();
  v4 = *((char *)v2 + 93) == 0;
  v5 = a2;
  v16 = v3;
  if ( !v4 && *((char *)v2 + 96) )
  {
    if ( v3 - *((int *)v2 + 19) < 0xFA )
    {
      v6 = *(int *)a2;
      v7 = *(int *)(a2 + 4);
      v15 = 1;
      v12 = &AsyncMouse::unk::vdtor_ptr;
      v13 = v6;
      v14 = v7;
      v17 = 0;
      AsyncMouse::unk_46BCD2((char *)v2 + 116, (int)&a2, *((int *)v2 + 30), (int)&v12);
      v17 = -1;
      v3 = v16;
    }
    *((int *)v2 + 19) = v3;
  }
  if ( *((char *)v2 + 94) && *((char *)v2 + 97) )
  {
    if ( v3 - *((int *)v2 + 20) < 0xFA )
    {
      v8 = *(int *)v5;
      v9 = *(int *)(v5 + 4);
      v15 = 2;
      //v12 = &AsyncMouse::unk::vdtor_ptr;
      v13 = v8;
      v14 = v9;
      v17 = 1;
      AsyncMouse::unk_46BCD2((char *)v2 + 116, (int)&a2, *((int *)v2 + 30), (int)&v12);
      v17 = -1;
      v3 = v16;
    }
    *((int *)v2 + 20) = v3;
  }
  if ( *((char *)v2 + 95) && *((char *)v2 + 98) )
  {
    if ( v3 - *((int *)v2 + 21) < 0xFA )
    {
      v10 = *(int *)v5;
      v11 = *(int *)(v5 + 4);
      v15 = 4;
      //v12 = &AsyncMouse::unk::vdtor_ptr;
      v13 = v10;
      v14 = v11;
      v17 = 2;
      AsyncMouse::unk_46BCD2((char *)v2 + 116, (int)&a2, *((int *)v2 + 30), (int)&v12);
      v3 = v16;
    }
    *((int *)v2 + 21) = v3;
  }
  LeaveCriticalSection(&pGame->pThreadWardInstance->csAsyncMouse);*/
}

//----- (0046B736) --------------------------------------------------------
void AsyncMouse::_46B736_consume_click_lists(char a2)
{
  __debugbreak();
  /*
  void *v2; // esi@1

  v2 = this;
  _46B76F();
  _46B879();
  if ( a2 )
  {
    _46BCAB((char *)v2 + 104);
    _46BCAB((char *)v2 + 116);
  }
  if ( *((char *)v2 + 102) )
  {
    back_to_game();
    *((char *)v2 + 102) = 0;
  }*/
}

//----- (0046B76F) --------------------------------------------------------
void AsyncMouse::_46B76F()
{
  __debugbreak();
  /*
  char *v0; // ebx@1
  int v1; // eax@1
  int v2; // edi@1
  int v3; // eax@2
  unsigned int *v4; // esi@2
  unsigned int v5; // ST08_4@7
  unsigned int v6; // ST04_4@7
  float v7; // ST00_4@7
  unsigned int v8; // ST08_4@9
  unsigned int v9; // ST04_4@9
  float v10; // ST00_4@9

  EnterCriticalSection(&pGame->pThreadWardInstance->csAsyncMouse);
  v0 = (char *)pAsyncMouse + 108;
  v1 = *((int *)pAsyncMouse + 27);
  v2 = *(int *)v1;
  if ( *(int *)v1 != v1 )
  {
    do
    {
      v3 = *(int *)(v2 + 20);
      v4 = (unsigned int *)(v2 + 12);
      if ( v3 & 1 )
      {
        pGame->PickMouse(512.0, *v4, *(int *)(v2 + 16), 0, &a3, &a4);
        if ( GetCurrentMenuID() == 6 )
          sub_41CD4F(0x29u);
        UI_OnMouseLeftClick((int *)(v2 + 12));
      }
      else
      {
        if ( v3 & 2 )
        {
          v5 = *(int *)(v2 + 16);
          v6 = *v4;
          v7 = GetPickDepth();
          pGame->PickMouse(v7, v6, v5, 0, &stru_F93E30, &a5);
          sub_416D62_ShowPopupWindow_MonsterRecord_ItemInfo_etcsub_416D62((Vec2_int_ *)(v2 + 12));
        }
        else
        {
          if ( v3 & 4 )
          {
            v8 = *(int *)(v2 + 16);
            v9 = *v4;
            v10 = GetPickDepth();
            pGame->PickMouse(v10, v9, v8, 1, &a3, &a5);
          }
        }
      }
      v2 = *(int *)v2;
    }
    while ( v2 != *(int *)v0 );
  }
  LeaveCriticalSection(&pGame->pThreadWardInstance->csAsyncMouse);*/
}

//----- (0046B879) --------------------------------------------------------
void AsyncMouse::_46B879()
{
  __debugbreak();
  /*
  char *v0; // ebx@1
  int v1; // eax@1
  int v2; // edi@1
  int v3; // eax@2
  unsigned int *v4; // esi@2
  unsigned int v5; // ST08_4@5
  unsigned int v6; // ST04_4@5
  float v7; // ST00_4@5

  EnterCriticalSection(&pGame->pThreadWardInstance->csAsyncMouse);
  v0 = (char *)pAsyncMouse + 120;
  v1 = *((int *)pAsyncMouse + 30);
  v2 = *(int *)v1;
  if ( *(int *)v1 != v1 )
  {
    do
    {
      v3 = *(int *)(v2 + 20);
      v4 = (unsigned int *)(v2 + 12);
      if ( v3 & 1 )
      {
        pGame->PickMouse(512.0, *v4, *(int *)(v2 + 16), 0, &a3, &a4);
        sub_4178C4();
      }
      else
      {
        if ( v3 & 2 )
        {
          v5 = *(int *)(v2 + 16);
          v6 = *v4;
          v7 = GetPickDepth();
          pGame->PickMouse(v7, v6, v5, 0, &stru_F93E30, &a4);
          sub_4178E1();
        }
        else
        {
          if ( v3 & 4 )
            nullsub_1();
        }
      }
      v2 = *(int *)v2;
    }
    while ( v2 != *(int *)v0 );
  }
  LeaveCriticalSection(&pGame->pThreadWardInstance->csAsyncMouse);*/
}

//----- (0046B944) --------------------------------------------------------
int AsyncMouse::_46B944()
{
  __debugbreak();
  /*
  void *v1; // esi@1

  v1 = this;
  _46BCAB((char *)this + 104);
  return _46BCAB((char *)v1 + 116);*/
  return 0;
}
// 46BCAB: using guessed type int __thiscall AsyncMouse__46BCAB(int);

//----- (0046B958) --------------------------------------------------------
char AsyncMouse::_46B958(int a2, int a3)
{
  __debugbreak();
  /*
  void *v3; // esi@1
  char result; // al@3
  int v5; // edx@6
  int v6; // eax@6
  int v7; // eax@12
  int v8; // edi@13
  int v9; // eax@19
  struct IDirectDrawSurface4 *v10; // ST08_4@21
  DDBLTFX v11; // [sp+4h] [bp-74h]@21
  RECT v12; // [sp+68h] [bp-10h]@19

  v3 = this;
  if ( pRenderer->pFrontBuffer4 && !pRenderer->pFrontBuffer4->IsLost() )
  {
    EnterCriticalSection(&pGame->pThreadWardInstance->cs2);
    if ( *((char *)v3 + 88) )
      pRenderer->pFrontBuffer4->BltFast(
        *((int *)v3 + 8),
        *((int *)v3 + 9),
        (LPDIRECTDRAWSURFACE4)*((int *)v3 + 2),
        (LPRECT)((char *)v3 + 48),
        16u);
    v5 = 640 - a2;
    v6 = 640 - a2;
    if ( 640 - a2 >= 31 )
      v6 = 31;
    if ( v6 >= 0 )
    {
      if ( v5 >= 31 )
        v5 = 31;
    }
    else
    {
      v5 = 0;
    }
    v7 = 480 - a3;
    if ( 480 - a3 >= 31 )
      v8 = 31;
    else
      v8 = 480 - a3;
    if ( v8 >= 0 )
    {
      if ( v7 >= 31 )
        v7 = 31;
    }
    else
    {
      v7 = 0;
    }
    *((int *)v3 + 13) = 0;
    *((int *)v3 + 14) = v5;
    v12.right = a2 + v5;
    *((int *)v3 + 12) = 0;
    *((int *)v3 + 15) = v7;
    v12.left = a2;
    v12.bottom = a3 + v7;
    v9 = *((int *)v3 + 2);
    v12.top = a3;
    (*(void (__stdcall **)(int, int, int, IDirectDrawSurface4 *, RECT *, signed int))(*(int *)v9 + 28))(
      v9,
      0,
      0,
      pRenderer->pFrontBuffer4,
      &v12,
      16);
    if ( !*((char *)v3 + 90) || *((char *)v3 + 128) & 1 )
    {
      v10 = (struct IDirectDrawSurface4 *)*((int *)v3 + 1);
      v11.dwSize = 100;
      v11.dwDDFX = 8;
      pRenderer->pFrontBuffer4->Blt(
        &v12,
        v10,
        (LPRECT)((char *)v3 + 48),
        16812032u,
        &v11);
    }
    *((char *)v3 + 88) = 1;
    LeaveCriticalSection(&pGame->pThreadWardInstance->cs2);
    result = 1;
  }
  else
  {
    result = 0;
  }
  return result;*/
  return 0;
}

//----- (0046BA8D) --------------------------------------------------------
char AsyncMouse::_46BA8D(int a2, int a3)
{
  __debugbreak();
  /*
  void *v3; // esi@1
  DWORD v4; // eax@1

  v3 = this;
  v4 = timeGetTime();
  if ( v4 - *((int *)v3 + 16) <= 0x32 )
  {
    *((char *)v3 + 91) = *((char *)v3 + 90) == 1;
    *((char *)v3 + 90) = 0;
  }
  else
  {
    if ( *((char *)v3 + 90) )
      *((char *)v3 + 91) = 0;
    else
      *((char *)v3 + 91) = 1;
    *((char *)v3 + 90) = 1;
  }
  if ( a2 != *((int *)v3 + 17) || a3 != *((int *)v3 + 18) )
  {
    *((int *)v3 + 16) = v4;
    *((int *)v3 + 17) = a2;
    *((int *)v3 + 18) = a3;
  }
  return *((char *)v3 + 90);*/
  return 0;
}

//----- (0046BAEC) --------------------------------------------------------
void AsyncMouse::_46BAEC()
{
  void *v1; // esi@1

  v1 = this;
  EnterCriticalSection(&pGame->pThreadWardInstance->cs2);
  *((char *)v1 + 88) = 0;
}

//----- (0046BB0A) --------------------------------------------------------
void AsyncMouse::_46BB0A()
{
  __debugbreak();
  /*
  void *v1; // esi@1
  int v2; // eax@1
  int v3; // edx@1
  int v4; // ecx@1
  int v5; // edx@1
  int v6; // eax@1
  char v7; // zf@1
  struct IDirectDrawSurface4 *v8; // ST08_4@8
  int v9; // [sp+8h] [bp-74h]@8
  int v10; // [sp+Ch] [bp-70h]@8
  int v11; // [sp+6Ch] [bp-10h]@1
  int v12; // [sp+70h] [bp-Ch]@1
  int v13; // [sp+74h] [bp-8h]@1
  int v14; // [sp+78h] [bp-4h]@1

  v1 = this;
  v2 = *((int *)this + 17) - *((int *)this + 10);
  v3 = *((int *)this + 14);
  v4 = *((int *)this + 18) - *((int *)this + 11);
  v11 = v2;
  v5 = v2 + v3;
  v6 = *((int *)v1 + 15);
  v12 = v4;
  v7 = *((char *)v1 + 90) == 0;
  v13 = v5;
  v14 = v4 + v6;
  if ( v7 || *((char *)v1 + 128) & 1 )
  {
    if ( *((char *)v1 + 88) )
      pRenderer->pFrontBuffer4->BltFast(
        *((int *)v1 + 8),
        *((int *)v1 + 9),
        (LPDIRECTDRAWSURFACE4)*((int *)v1 + 2),
        (LPRECT)((char *)v1 + 48),
        16u);
    (*(void (__stdcall **)(int, int, int, IDirectDrawSurface4 *, int *, signed int))(**((int **)v1 + 2) + 28))(
      *((int *)v1 + 2),
      0,
      0,
      pRenderer->pFrontBuffer4,
      &v11,
      16);
  }
  if ( *((char *)v1 + 90) && !(*((char *)v1 + 128) & 1) )
  {
    v8 = (struct IDirectDrawSurface4 *)*((int *)v1 + 1);
    v9 = 100;
    v10 = 8;
    pRenderer->pFrontBuffer4->Blt(
      (LPRECT)&v11,
      v8,
      (LPRECT)((char *)v1 + 48),
      16812032u,
      (LPDDBLTFX)&v9);
  }
  LeaveCriticalSection(&pGame->pThreadWardInstance->cs2);*/
}

//----- (0046BBD0) --------------------------------------------------------
void *AsyncMouse::Clip()
{
  __debugbreak();
  /*
  void *result; // eax@1
  std::string v1; // [sp-18h] [bp-30h]@2
  const char *v2; // [sp-8h] [bp-20h]@2
  int v3; // [sp-4h] [bp-1Ch]@2
  RECT Rect; // [sp+0h] [bp-18h]@1
  std::string *v5; // [sp+10h] [bp-8h]@2
  int a3; // [sp+17h] [bp-1h]@2

  SetWindowPos(hWnd, HWND_MESSAGE|0x2, 320, 240, 640, 480, 0);
  Rect.left = 325;
  Rect.top = 245;
  Rect.right = 326;
  Rect.bottom = 246;
  result = (void *)ClipCursor(&Rect);
  if ( !result )
  {
          MessageBoxW(nullptr, L"Could not clip cursor to screen!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\MouseAsync.cpp:827", 0);
  }
  return result;*/
  return 0;
}

//----- (0046BC4E) --------------------------------------------------------
void __stdcall AsyncMouse::AsyncMouseThread(int a1)
{
  __debugbreak();
  /*
  while ( 1 )
  {
    while ( !pAsyncMouse )
      Sleep(1);
    if ( !AsyncMouse::Thread(pAsyncMouse) )
      ExitThread(0);
    Sleep(18);
  }*/
}

//----- (0046BC73) --------------------------------------------------------
void AsyncMouse::dtor_sub_46BC73()
{
  __debugbreak();
  /*
  int v1; // edi@1
  void **v2; // ebx@1
  void *v3; // esi@1
  void *v4; // eax@2
  int v5; // [sp+0h] [bp-4h]@1

  v5 = this;
  v1 = this;
  v2 = *(void ***)(this + 4);
  v3 = *v2;
  while ( v3 != v2 )
  {
    v4 = v3;
    v3 = *(void **)v3;
    AsyncMouse::unk_46BD2D((void *)v1, (int)&v5, v4);
  }
  free(*(void **)(v1 + 4));
  *(int *)(v1 + 4) = 0;
  *(int *)(v1 + 8) = 0;*/
}

//----- (0046BCAB) --------------------------------------------------------
int AsyncMouse::_46BCAB()
{
  __debugbreak();
  /*
  void *v1; // ebx@1
  void **v2; // edi@1
  void *v3; // esi@1
  void *v4; // eax@2
  int result; // eax@2
  int v6; // [sp+0h] [bp-4h]@1

  v6 = this;
  v1 = (void *)this;
  v2 = *(void ***)(this + 4);
  v3 = *v2;
  while ( v3 != v2 )
  {
    v4 = v3;
    v3 = *(void **)v3;
    result = AsyncMouse::unk_46BD2D(v1, (int)&v6, v4);
  }
  return result;*/
  return 0;
}
// 46BCAB: using guessed type int __thiscall AsyncMouse__46BCAB(int);

//----- (0046BCD2) --------------------------------------------------------
int AsyncMouse::unk_46BCD2(int a2, int a3, int a4)
{
  __debugbreak();
  /*
  void *v4; // edi@1
  void *v5; // eax@1
  void *v6; // esi@1
  int result; // eax@1

  v4 = this;
  v5 = AsyncMouse::unk_46BD09((void *)a3, *(void **)(a3 + 4));
  v6 = v5;
  *(int *)(a3 + 4) = v5;
  **((int **)v5 + 1) = v5;
  AsyncMouse::unk_46BD66((char *)v5 + 8, a4);
  result = a2;
  ++*((int *)v4 + 2);
  *(int *)a2 = v6;
  return result;*/
  return 0;
}
// 46BD66: using guessed type int __fastcall AsyncMouse__unk__46BD66(int, int);

//----- (0046BD09) --------------------------------------------------------
void *AsyncMouse::unk_46BD09(void *a1, void *a2)
{
  __debugbreak();
  /*
  void *result; // eax@1
  void *v3; // ecx@1
  void *v4; // ecx@3

  result = operator new(0x18u);
  v3 = a1;
  if ( !a1 )
    v3 = result;
  *(int *)result = v3;
  v4 = a2;
  if ( !a2 )
    v4 = result;
  *((int *)result + 1) = v4;
  return result;*/
  return 0;
}

//----- (0046BD2D) --------------------------------------------------------
int AsyncMouse::unk_46BD2D(int a2, void *a3)
{
  __debugbreak();
  /*
  void *v3; // edi@1
  int v4; // ebx@1
  int result; // eax@1

  v3 = this;
  v4 = *(int *)a3;
  **((int **)a3 + 1) = *(int *)a3;
  *(int *)(*(int *)a3 + 4) = *((int *)a3 + 1);
  (**((void (__stdcall ***)(int))a3 + 2))(0);
  free(a3);
  result = a2;
  --*((int *)v3 + 2);
  *(int *)a2 = v4;
  return result;*/
  return 0;
}

//----- (0046BD66) --------------------------------------------------------
int AsyncMouse::unk_46BD66(int a1, int a2)
{
  int result; // eax@2

  if ( a1 )
  {
    *(int *)(a1 + 4) = *(int *)(a2 + 4);
    *(int *)(a1 + 8) = *(int *)(a2 + 8);
    result = *(int *)(a2 + 12);
    *(int *)(a1 + 12) = result;
    //*(int *)a1 = &AsyncMouse::unk::vdtor_ptr;
  }
  return result;
}
// 46BD66: using guessed type int __fastcall AsyncMouse__unk__46BD66(int, int);
// 4D8734: using guessed type int (__stdcall *AsyncMouse__unk__vdtor_ptr)(char);



















/*
//----- (0043B9FF) --------------------------------------------------------
DirectInputMouse *__thiscall DirectInputMouse::DirectInputMouse(DirectInputMouse *this)
{
  DirectInputMouse *v1; // esi@1
  HRESULT v2; // eax@5
  signed int v4; // [sp-18h] [bp-24h]@3
  char *v5; // [sp-14h] [bp-20h]@3
  int v6; // [sp-10h] [bp-1Ch]@3
  const char *v7; // [sp-Ch] [bp-18h]@3
  int v8; // [sp-8h] [bp-14h]@3
  unsigned int v9; // [sp-4h] [bp-10h]@3
  CheckHRESULT_stru0 v10; // [sp+8h] [bp-4h]@5

  v1 = this;
  this->field_8 = 0;
  LOBYTE(this->field_1C) = 0;
  this->field_28 = 0;
  this->vdestructor_ptr = (int)&DirectInputMouse_pvdtor;
  if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
  {
    v9 = 1;
    v8 = 30;
    v7 = "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\DirectInputMouse.cpp";
    v6 = 0;
    v5 = (char *)&this->pDirectInput;
    v4 = 1280;
  }
  else
  {
    v9 = 1;
    v8 = 28;
    v7 = "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\DirectInputMouse.cpp";
    v6 = 0;
    v5 = (char *)&this->pDirectInput;
    v4 = 768;
  }
  v2 = DirectInputCreateA(hInstance, v4, v5, v6);
  CheckHRESULT(&v10, v2, v7, v8, v9);
  DirectInputMouse::CreateDevice(v1);
  DirectInputMouse::43BB18(v1);
  v1->field_20 = 0;
  v1->field_24 = 0;
  return v1;
}
// 4C8880: using guessed type int __stdcall DirectInputCreateA(int, int, int, int);
// 4D8608: using guessed type int (__stdcall *DirectInputMouse_pvdtor)(char);

//----- (0043BA80) --------------------------------------------------------
void *__thiscall DirectInputMouse::vdtor(void *this, bool a2)
{
  void *v2; // esi@1

  v2 = this;
  DirectInputMouse::dtor(this);
  if ( a2 & 1 )
    free(v2);
  return v2;
}

//----- (0043BA9C) --------------------------------------------------------
int __thiscall DirectInputMouse::dtor(void *this)
{
  void *v1; // esi@1
  int v2; // eax@1
  int result; // eax@3

  v1 = this;
  v2 = *((int *)this + 2);
  *(int *)this = &DirectInputMouse_pvdtor;
  if ( v2 )
  {
    (*(void (__stdcall **)(int))(*(int *)v2 + 32))(v2);
    (*(void (__stdcall **)(int))(**((int **)v1 + 2) + 8))(*((int *)v1 + 2));
    *((int *)v1 + 2) = 0;
  }
  result = (*(int (__stdcall **)(int))(**((int **)v1 + 1) + 8))(*((int *)v1 + 1));
  *((int *)v1 + 1) = 0;
  return result;
}
// 4D8608: using guessed type int (__stdcall *DirectInputMouse_pvdtor)(char);

//----- (0043BACE) --------------------------------------------------------
void __thiscall DirectInputMouse::CreateDevice(DirectInputMouse *this)
{
  DirectInputMouse *v1; // esi@1
  HRESULT v2; // eax@1
  CheckHRESULT_stru0 v3; // [sp+4h] [bp-4h]@1

  v1 = this;
  v2 = ((int (__stdcall *)(int, int, int, int, int))this->pDirectInput->lpVtbl->field_10)(
         this->pDirectInput,
         2,
         DirectInputMouse_enumerator,
         this,
         1);
  CheckHRESULT(&v3, v2, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\DirectInputMouse.cpp", 57, 1u);
  if ( !LOBYTE(v1->field_1C) )
  {
    v3.vdestructor_ptr = (void (__thiscall ***)(CheckHRESULT_stru0 *, bool))"Error: No mouse found";
    _CxxThrowException((int)&v3, (int)&dword_4DBD94);
  }
}
// 43BC61: using guessed type int __stdcall DirectInputMouse_enumerator(int, int);
// 4DBD94: using guessed type int dword_4DBD94;

//----- (0043BB18) --------------------------------------------------------
int __thiscall DirectInputMouse::43BB18(DirectInputMouse *this)
{
  char *v1; // esi@1
  HRESULT v2; // eax@1
  HRESULT v3; // eax@1
  HRESULT v4; // eax@1
  unsigned int v6; // [sp+0h] [bp-Ch]@0
  CheckHRESULT_stru0 v7; // [sp+8h] [bp-4h]@1

  v1 = (char *)&this->field_8;
  v2 = ((int (__stdcall *)(int, int, int, int, int))this->pDirectInput->lpVtbl->field_C)(
         this->pDirectInput,
         &this->field_C,
         &this->field_8,
         0,
         "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\DirectInputMouse.cpp");
  CheckHRESULT(&v7, v2, (const char *)0x40, 1, v6);
  v3 = (*(int (__stdcall **)(int, int))(**(int **)v1 + 44))(*(int *)v1, dword_4C9920);
  CheckHRESULT(&v7, v3, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\DirectInputMouse.cpp", 65, 1u);
  v4 = (*(int (__stdcall **)(int, int, int))(**(int **)v1 + 52))(*(int *)v1, hWnd, 6);
  CheckHRESULT(&v7, v4, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\DirectInputMouse.cpp", 66, 1u);
  return (*(int (__cdecl **)(int))(**(int **)v1 + 28))(*(int *)v1);
}
// 4C9920: using guessed type int dword_4C9920[16];

//----- (0043BB89) --------------------------------------------------------
bool __thiscall DirectInputMouse::43BB89(DirectInputMouse *this)
{
  DirectInputMouse *v1; // esi@1
  bool result; // eax@1
  HRESULT v3; // eax@5
  __int32 v4; // ecx@6
  __int32 v5; // eax@6
  __int32 v6; // edx@6
  int v7; // ecx@12
  bool v8; // ecx@12
  signed int v9; // edx@12
  HRESULT a2; // [sp+4h] [bp-14h]@3
  int v11; // [sp+8h] [bp-10h]@12
  char v12; // [sp+10h] [bp-8h]@18
  char v13; // [sp+11h] [bp-7h]@20
  char v14; // [sp+12h] [bp-6h]@22
  char v15; // [sp+13h] [bp-5h]@24
  char v18; // [sp+14h] [bp-4h]@5

  v1 = this;
  result = this->field_8;
  if ( result )
  {
    if ( (*(int (__stdcall **)(bool, signed int, HRESULT *))(*(int *)result + 36))(result, 16, &a2) == -2147024866
      && !(*(int (__stdcall **)(int))(*(int *)v1->field_8 + 28))(v1->field_8) )
    {
      v3 = (*(int (__stdcall **)(int, signed int, HRESULT *))(*(int *)v1->field_8 + 36))(v1->field_8, 16, &a2);
      CheckHRESULT((CheckHRESULT_stru0 *)&v18, v3, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\DirectInputMouse.cpp", 80, 1u);
    }
    v4 = v1->field_20 + a2;
    v5 = 640;
    v6 = v1->field_20 + a2;
    if ( v4 >= 640 )
      v6 = 640;
    if ( v6 >= 0 )
    {
      if ( v4 < 640 )
        v5 = v1->field_20 + a2;
    }
    else
    {
      v5 = 0;
    }
    v7 = v11;
    v1->field_20 = v5;
    v8 = v1->field_24 + v7;
    result = 480;
    v9 = v8;
    if ( v8 >= 480 )
      v9 = 480;
    if ( v9 >= 0 )
    {
      if ( v8 < 480 )
        result = v8;
    }
    else
    {
      result = 0;
    }
    v1->field_28 = 0;
    v1->field_24 = result;
    if ( v12 & 0x80 )
      v1->field_28 = 1;
    if ( v13 & 0x80 )
      v1->field_28 |= 2u;
    if ( v14 & 0x80 )
      v1->field_28 |= 4u;
    if ( v15 & 0x80 )
      v1->field_28 |= 8u;
    LOBYTE(result) = 1;
  }
  else
  {
    LOBYTE(result) = 0;
  }
  return result;
}

//----- (0043BC61) --------------------------------------------------------
signed int __stdcall DirectInputMouse_enumerator(int a1, int a2)
{
  signed int result; // eax@2

  if ( *(char *)(a1 + 36) & 2 )
  {
    *(int *)(a2 + 12) = *(int *)(a1 + 4);
    *(int *)(a2 + 16) = *(int *)(a1 + 8);
    *(int *)(a2 + 20) = *(int *)(a1 + 12);
    *(int *)(a2 + 24) = *(int *)(a1 + 16);
    *(char *)(a2 + 28) = 1;
    result = 0;
  }
  else
  {
    result = 1;
  }
  return result;
}
// 43BC61: using guessed type int __stdcall DirectInputMouse_enumerator(int, int);
*/