mirror of
https://github.com/isledecomp/isle.git
synced 2026-01-20 23:01:16 +00:00
commit d9148242a322ec54750c89357a0db2154310907d
Author: ecumber <ecumber05@gmail.com>
Date: Sun Jul 16 23:56:54 2023 -0700
Update legoinputmanager.cpp
commit 983d08650eb3df0b9103761b4023a6d3395686b2
Author: ecumber <ecumber05@gmail.com>
Date: Thu Jul 6 21:04:15 2023 -0700
data types
commit 4e8aac36ece6f3d7cfff39432ebc4e731876fb75
Author: ecumber <ecumber05@gmail.com>
Date: Thu Jul 6 12:39:13 2023 -0700
Destroy
commit 907801567a8c93ebd242b25b4aa2b00d38eaedc8
Author: ecumber <ecumber05@gmail.com>
Date: Thu Jul 6 12:15:33 2023 -0700
compile fix
commit 91a5f75e938d796f153cc872e46acef2c342818c
Author: ecumber <ecumber05@gmail.com>
Date: Tue Jul 4 13:37:33 2023 -0700
Timer functions
commit e77f08f5358b6cc4ee41583f70281c40b95bea29
Author: ecumber <ecumber05@gmail.com>
Date: Thu Jul 6 02:40:10 2023 -0700
fix
commit 30d204b7734a56b4140a3bf53c9825126a1f80c7
Author: ecumber <ecumber05@gmail.com>
Date: Thu Jul 6 02:39:04 2023 -0700
improvements
commit dd4ff493355796c41a6fb328fda1892c0f1fec0a
Author: ecumber <ecumber05@gmail.com>
Date: Tue Jul 4 03:42:47 2023 -0700
Update legoinputmanager.cpp
commit 852658cdbc0e6f792a6a79dfc77df3539ea4a15a
Author: ecumber <ecumber05@gmail.com>
Date: Tue Jul 4 03:38:32 2023 -0700
Add ReleaseDX
commit 430d4e100811bc00dc983a9fe78aa1482fb92f7f
Author: ecumber <ecumber05@gmail.com>
Date: Tue Jul 4 02:27:12 2023 -0700
Update CMakeLists.txt
commit 6fb94f007613e920b1d64775b7b76cb721482884
Author: ecumber <ecumber05@gmail.com>
Date: Mon Jul 3 13:48:46 2023 -0700
Move to new branch
208 lines
5.3 KiB
C++
208 lines
5.3 KiB
C++
#include "legoinputmanager.h"
|
|
|
|
#include "decomp.h"
|
|
#include "legoomni.h"
|
|
#include "mxautolocker.h"
|
|
|
|
//DECOMP_SIZE_ASSERT(LegoInputManager, 0x338); // 0x10059085
|
|
|
|
// OFFSET: LEGO1 0x1005b790
|
|
LegoInputManager::LegoInputManager()
|
|
{
|
|
m_unknown5C = 0;
|
|
m_unknown64 = NULL;
|
|
m_unknown60 = NULL;
|
|
m_unknown_classptr68 = NULL;
|
|
m_unknown80 = 0;
|
|
m_timer = 0;
|
|
m_unknown6C = 0;
|
|
m_unknown70 = 0;
|
|
m_controlManager = NULL;
|
|
m_bool81 = FALSE;
|
|
m_bool88 = FALSE;
|
|
m_directinputInterface = NULL;
|
|
m_directinputDeviceInterface = NULL;
|
|
m_unused94 = 0;
|
|
m_unknown195 = 0;
|
|
m_joyid = (UINT)-1;
|
|
m_unknown19C = (UINT)-1;
|
|
m_joystickIndex = 0;
|
|
m_useJoystick = FALSE;
|
|
m_unknown336 = 0;
|
|
m_unknown74 = 0x19;
|
|
m_timeout = 1000;
|
|
}
|
|
|
|
// OFFSET: LEGO1 0x1005b8f0 STUB
|
|
LegoInputManager::~LegoInputManager()
|
|
{
|
|
// TODO
|
|
}
|
|
|
|
// OFFSET: LEGO1 0x1005c740 STUB
|
|
void LegoInputManager::QueueEvent(NotificationId id, unsigned char p2, MxLong p3, MxLong p4, unsigned char p5)
|
|
{
|
|
// TODO
|
|
}
|
|
|
|
// OFFSET: LEGO1 0x1005c470 STUB
|
|
void LegoInputManager::Register(MxCore *)
|
|
{
|
|
MxAutoLocker* autolocker = new MxAutoLocker(&m_criticalsection);
|
|
}
|
|
|
|
// OFFSET: LEGO1 0x1005c5c0 STUB
|
|
void LegoInputManager::UnRegister(MxCore *)
|
|
{
|
|
// TODO
|
|
}
|
|
|
|
// OFFSET: LEGO1 0x1005b8b0 STUB
|
|
//MxLong LegoInputManager::Tickle()
|
|
//{
|
|
// // TODO
|
|
//
|
|
// return 0;
|
|
//}
|
|
|
|
void LegoInputManager::Destroy()
|
|
{
|
|
ReleaseDX();
|
|
// `scalar_deleting_destructor'
|
|
if (m_unknown_classptr68 != NULL) delete[] m_unknown_classptr68;
|
|
if (m_controlManager != NULL) delete[] m_controlManager;
|
|
return;
|
|
}
|
|
|
|
void LegoInputManager::SetTimer()
|
|
{
|
|
LegoOmni* omni = LegoOmni::GetInstance();
|
|
UINT timer = ::SetTimer(*omni->GetWindowHandle(), 1, m_timeout, NULL);
|
|
m_timer = timer;
|
|
}
|
|
|
|
void LegoInputManager::KillTimer()
|
|
{
|
|
if (m_timer != 0)
|
|
{
|
|
LegoOmni* omni = LegoOmni::GetInstance();
|
|
::KillTimer(*omni->GetWindowHandle(), m_timer);
|
|
}
|
|
}
|
|
|
|
// this function currently does not match 100% due to some member variables
|
|
// being at the wrong offsets, but the functionality is the same
|
|
|
|
// OFFSET: LEGO1 0x1005c030
|
|
void LegoInputManager::CreateAndAcquireKeyboard(HWND hwnd)
|
|
{
|
|
HINSTANCE hinstance = (HINSTANCE)GetWindowLongA(hwnd, GWL_HINSTANCE);
|
|
HRESULT hresult = DirectInputCreateA(hinstance, 0x500, &m_directinputInterface, NULL); // 0x500 for DX5
|
|
if (hresult == DI_OK)
|
|
{
|
|
HRESULT createdeviceresult = m_directinputInterface->CreateDevice(GUID_SysKeyboard, &m_directinputDeviceInterface, NULL);
|
|
if (createdeviceresult == DI_OK)
|
|
{
|
|
m_directinputDeviceInterface->RunControlPanel(hwnd, 6);
|
|
m_directinputDeviceInterface->SetDataFormat(&c_dfDIKeyboard);
|
|
m_directinputDeviceInterface->Acquire();
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
MxS32 LegoInputManager::GetJoystickState(unsigned int* joystick_x, unsigned int* joystick_y, DWORD* buttons_state, unsigned int* pov_position)
|
|
{
|
|
if ((m_joystickIndex != JOYSTICKID1) && (m_joyid < 0) && (GetJoystickId() == -1))
|
|
{
|
|
m_joystickIndex = 0;
|
|
return -1;
|
|
}
|
|
|
|
JOYINFOEX joyinfoex;
|
|
joyinfoex.dwSize = 0x34;
|
|
joyinfoex.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNBUTTONS;
|
|
MxU32 capabilities = m_joyCapsA.wCaps;
|
|
if ((capabilities & JOYCAPS_HASPOV) != 0)
|
|
{
|
|
joyinfoex.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNPOV | JOY_RETURNBUTTONS;
|
|
if ((capabilities & JOYCAPS_POVCTS) != 0)
|
|
{
|
|
joyinfoex.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNPOV | JOY_RETURNBUTTONS | JOY_RETURNPOVCTS;
|
|
}
|
|
}
|
|
MMRESULT mmresult = joyGetPosEx(m_joyid, &joyinfoex);
|
|
if (mmresult == MMSYSERR_NOERROR)
|
|
{
|
|
*buttons_state = joyinfoex.dwButtons;
|
|
MxU32 xmin = m_joyCapsA.wXmin;
|
|
MxU32 ymax = m_joyCapsA.wYmax;
|
|
MxU32 ymin = m_joyCapsA.wYmin;
|
|
*joystick_x = ((joyinfoex.dwXpos - xmin) * 100) / (m_joyCapsA.wXmax - xmin);
|
|
*joystick_y = ((joyinfoex.dwYpos - m_joyCapsA.wYmin) * 100) / (ymax - ymin);
|
|
if ((m_joyCapsA.wCaps & (JOYCAPS_POV4DIR | JOYCAPS_POVCTS)) == 0)
|
|
{
|
|
*pov_position = (MxU32)-1;
|
|
return 0;
|
|
}
|
|
if (joyinfoex.dwPOV == JOY_POVCENTERED)
|
|
{
|
|
*pov_position = (MxU32)-1;
|
|
return 0;
|
|
}
|
|
*pov_position = joyinfoex.dwPOV / 100;
|
|
return 0;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
// FIXME: there's 2 different variables for the joystick id??? also the lines that
|
|
// set dwSize and dwFlags result in incorrect offsets in the JOYINFOEX struct
|
|
|
|
// OFFSET: LEGO1 0x1005c240
|
|
MxS32 LegoInputManager::GetJoystickId()
|
|
{
|
|
JOYINFOEX joyinfoex;
|
|
if (m_joystickIndex != JOYSTICKID1)
|
|
{
|
|
MxS32 joyid = m_unknown19C;
|
|
if (-1 < joyid)
|
|
{
|
|
joyinfoex.dwSize = 0x34;
|
|
joyinfoex.dwFlags = 0xFF;
|
|
if (joyGetPosEx(joyid, &joyinfoex) == JOYERR_NOERROR && joyGetDevCapsA(joyid, &m_joyCapsA, 0x194) == JOYERR_NOERROR)
|
|
{
|
|
m_joyid = joyid;
|
|
return 0;
|
|
}
|
|
}
|
|
for (joyid = JOYSTICKID1; joyid < 16; joyid++)
|
|
{
|
|
joyinfoex.dwSize = 0x34;
|
|
joyinfoex.dwFlags = 0xFF;
|
|
if (joyGetPosEx(joyid, &joyinfoex) == JOYERR_NOERROR && joyGetDevCapsA(joyid, &m_joyCapsA, 0x194) == JOYERR_NOERROR)
|
|
{
|
|
m_joyid = joyid;
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
void LegoInputManager::ReleaseDX()
|
|
{
|
|
if (m_directinputDeviceInterface != NULL)
|
|
{
|
|
m_directinputDeviceInterface->Unacquire();
|
|
m_directinputDeviceInterface->Release();
|
|
m_directinputDeviceInterface = NULL;
|
|
}
|
|
if (m_directinputInterface != NULL)
|
|
{
|
|
m_directinputInterface->Release();
|
|
m_directinputInterface = NULL;
|
|
}
|
|
return;
|
|
}
|