From a6f3acf5b7bd34468cdeb6906e6c27cae12c5f9e Mon Sep 17 00:00:00 2001 From: ecumber Date: Tue, 3 Oct 2023 10:53:22 -0700 Subject: [PATCH] LegoInputManager: some members and functions (#81) * Squashed commit of the following: commit 1fe03a4a787693616c56f59622bcaae8fd53b30b Author: ecumber Date: Thu Jul 6 21:04:15 2023 -0700 data types commit 7c8432f88236c42c17998d51e820b5e219f3c326 Author: ecumber Date: Thu Jul 6 12:39:13 2023 -0700 Destroy commit f60eb3923b24bc87bb31ba783676c6a50d48e9b8 Author: ecumber Date: Thu Jul 6 12:15:33 2023 -0700 compile fix commit e2f78d557f223c2552a046470578d154c29e473b Author: ecumber Date: Tue Jul 4 13:37:33 2023 -0700 Timer functions commit 447e234e6324a5b0958e9e94c5cda53703abada2 Author: ecumber Date: Thu Jul 6 02:40:10 2023 -0700 fix commit 4670fd790b16a15b5797d50bc3cd1f6e2c9e890d Author: ecumber Date: Thu Jul 6 02:39:04 2023 -0700 improvements commit 7f70bce1eefe550fe6bef193e7ee54948af354b6 Author: ecumber Date: Tue Jul 4 03:42:47 2023 -0700 Update legoinputmanager.cpp commit 0d3433a75d2b20a3fff1da8147ce502b279b1e9c Author: ecumber Date: Tue Jul 4 03:38:32 2023 -0700 Add ReleaseDX commit 72d27fd402efb37da1ce8c41a3350df66c99db1d Author: ecumber Date: Tue Jul 4 02:27:12 2023 -0700 Update CMakeLists.txt commit 09626a62f9d2c56a523ca582be95a4dfb29ee188 Author: ecumber Date: Mon Jul 3 13:48:46 2023 -0700 Move to new branch * Squashed commit of the following: commit d9148242a322ec54750c89357a0db2154310907d Author: ecumber Date: Sun Jul 16 23:56:54 2023 -0700 Update legoinputmanager.cpp commit 983d08650eb3df0b9103761b4023a6d3395686b2 Author: ecumber Date: Thu Jul 6 21:04:15 2023 -0700 data types commit 4e8aac36ece6f3d7cfff39432ebc4e731876fb75 Author: ecumber Date: Thu Jul 6 12:39:13 2023 -0700 Destroy commit 907801567a8c93ebd242b25b4aa2b00d38eaedc8 Author: ecumber Date: Thu Jul 6 12:15:33 2023 -0700 compile fix commit 91a5f75e938d796f153cc872e46acef2c342818c Author: ecumber Date: Tue Jul 4 13:37:33 2023 -0700 Timer functions commit e77f08f5358b6cc4ee41583f70281c40b95bea29 Author: ecumber Date: Thu Jul 6 02:40:10 2023 -0700 fix commit 30d204b7734a56b4140a3bf53c9825126a1f80c7 Author: ecumber Date: Thu Jul 6 02:39:04 2023 -0700 improvements commit dd4ff493355796c41a6fb328fda1892c0f1fec0a Author: ecumber Date: Tue Jul 4 03:42:47 2023 -0700 Update legoinputmanager.cpp commit 852658cdbc0e6f792a6a79dfc77df3539ea4a15a Author: ecumber Date: Tue Jul 4 03:38:32 2023 -0700 Add ReleaseDX commit 430d4e100811bc00dc983a9fe78aa1482fb92f7f Author: ecumber Date: Tue Jul 4 02:27:12 2023 -0700 Update CMakeLists.txt commit 6fb94f007613e920b1d64775b7b76cb721482884 Author: ecumber Date: Mon Jul 3 13:48:46 2023 -0700 Move to new branch * Fixes * Remove obsolete stuff * Fixes --------- Co-authored-by: Christian Semmler --- CMakeLists.txt | 4 +- LEGO1/legoinputmanager.cpp | 190 +++++++++++++++++++++++++++++++--- LEGO1/legoinputmanager.h | 53 +++++++--- LEGO1/mxtransitionmanager.cpp | 4 +- 4 files changed, 220 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bcdadc2e..0da82a25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -213,7 +213,7 @@ if (ISLE_USE_DX5) endif() # Link libraries -target_link_libraries(lego1 PRIVATE ddraw dsound dxguid winmm) +target_link_libraries(lego1 PRIVATE ddraw dsound dxguid dinput winmm) # Make sure filenames are ALL CAPS set_property(TARGET lego1 PROPERTY OUTPUT_NAME LEGO1) @@ -272,4 +272,4 @@ if (MSVC) set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "/incremental:no") set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "/incremental:no /debug") set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "/incremental:no") -endif() +endif() \ No newline at end of file diff --git a/LEGO1/legoinputmanager.cpp b/LEGO1/legoinputmanager.cpp index 7c6489ee..149af67b 100644 --- a/LEGO1/legoinputmanager.cpp +++ b/LEGO1/legoinputmanager.cpp @@ -1,25 +1,175 @@ #include "legoinputmanager.h" +#include "legocontrolmanager.h" +#include "legoomni.h" -#include "decomp.h" +#include "mxautolocker.h" -DECOMP_SIZE_ASSERT(LegoInputManager, 0x338); // 0x10059085 +DECOMP_SIZE_ASSERT(LegoInputManager, 0x338); -// OFFSET: LEGO1 0x1005b790 STUB +// OFFSET: LEGO1 0x1005b790 LegoInputManager::LegoInputManager() { - // TODO + m_unk0x5c = NULL; + m_unk0x64 = 0; + m_unk0x60 = 0; + m_unk0x68 = NULL; + m_unk0x80 = 0; + m_timer = 0; + m_unk0x6c = 0; + m_unk0x70 = 0; + m_controlManager = NULL; + m_unk0x81 = 0; + m_unk0x88 = FALSE; + m_directInput = NULL; + m_directInputDevice = NULL; + m_unk0x94 = 0; + m_unk0x195 = 0; + m_joyid = (UINT) -1; + m_joystickIndex = -1; + m_useJoystick = FALSE; + m_unk0x335 = 0; + m_unk0x336 = 0; + m_unk0x74 = 0x19; + m_timeout = 1000; } -// OFFSET: LEGO1 0x1005b8f0 STUB +// OFFSET: LEGO1 0x1005b8b0 STUB +MxResult LegoInputManager::Tickle() +{ + // TODO + return SUCCESS; +} + +// OFFSET: LEGO1 0x1005b8f0 LegoInputManager::~LegoInputManager() { - // TODO + Destroy(); } -// OFFSET: LEGO1 0x1005c740 STUB -void LegoInputManager::QueueEvent(NotificationId id, unsigned char p2, MxLong p3, MxLong p4, unsigned char p5) +// OFFSET: LEGO1 0x1005bfe0 +void LegoInputManager::Destroy() { - // TODO + ReleaseDX(); + + if (m_unk0x5c) + delete m_unk0x5c; + m_unk0x5c = NULL; + + if (m_unk0x68) + delete m_unk0x68; + m_unk0x68 = NULL; + + if (m_controlManager) + delete m_controlManager; +} + +// OFFSET: LEGO1 0x1005c030 +void LegoInputManager::CreateAndAcquireKeyboard(HWND hwnd) +{ + HINSTANCE hinstance = (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE); + HRESULT hresult = DirectInputCreate(hinstance, 0x500, &m_directInput, NULL); // 0x500 for DX5 + + if (hresult == DI_OK) { + HRESULT createdeviceresult = m_directInput->CreateDevice(GUID_SysKeyboard, &m_directInputDevice, NULL); + if (createdeviceresult == DI_OK) { + m_directInputDevice->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); + m_directInputDevice->SetDataFormat(&c_dfDIKeyboard); + m_directInputDevice->Acquire(); + } + } +} + +// OFFSET: LEGO1 0x1005c0a0 +void LegoInputManager::ReleaseDX() +{ + if (m_directInputDevice != NULL) { + m_directInputDevice->Unacquire(); + m_directInputDevice->Release(); + m_directInputDevice = NULL; + } + + if (m_directInput != NULL) { + m_directInput->Release(); + m_directInput = NULL; + } +} + +// OFFSET: LEGO1 0x1005c240 +MxResult LegoInputManager::GetJoystickId() +{ + JOYINFOEX joyinfoex; + + if (m_useJoystick != FALSE) { + MxS32 joyid = m_joystickIndex; + if (joyid >= 0) { + joyinfoex.dwSize = 0x34; + joyinfoex.dwFlags = 0xFF; + + if (joyGetPosEx(joyid, &joyinfoex) == JOYERR_NOERROR && joyGetDevCaps(joyid, &m_joyCaps, 0x194) == JOYERR_NOERROR) { + m_joyid = joyid; + return SUCCESS; + } + } + + for (joyid = JOYSTICKID1; joyid < 16; joyid++) { + joyinfoex.dwSize = 0x34; + joyinfoex.dwFlags = 0xFF; + if (joyGetPosEx(joyid, &joyinfoex) == JOYERR_NOERROR && joyGetDevCaps(joyid, &m_joyCaps, 0x194) == JOYERR_NOERROR) { + m_joyid = joyid; + return SUCCESS; + } + } + } + + return FAILURE; +} + +// OFFSET: LEGO1 0x1005c320 +MxResult LegoInputManager::GetJoystickState(MxU32 *joystick_x, MxU32 *joystick_y, DWORD *buttons_state, MxU32 *pov_position) +{ + if (m_useJoystick != FALSE) { + if (m_joyid < 0 && GetJoystickId() == -1) { + m_useJoystick = FALSE; + return FAILURE; + } + + JOYINFOEX joyinfoex; + joyinfoex.dwSize = 0x34; + joyinfoex.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNBUTTONS; + MxU32 capabilities = m_joyCaps.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_joyCaps.wXmin; + MxU32 ymax = m_joyCaps.wYmax; + MxU32 ymin = m_joyCaps.wYmin; + MxS32 ydiff = ymax - ymin; + *joystick_x = ((joyinfoex.dwXpos - xmin) * 100) / (m_joyCaps.wXmax - xmin); + *joystick_y = ((joyinfoex.dwYpos - m_joyCaps.wYmin) * 100) / ydiff; + if ((m_joyCaps.wCaps & (JOYCAPS_POV4DIR | JOYCAPS_POVCTS)) != 0) { + if (joyinfoex.dwPOV == JOY_POVCENTERED) { + *pov_position = (MxU32) -1; + return SUCCESS; + } + *pov_position = joyinfoex.dwPOV / 100; + return SUCCESS; + } + else { + *pov_position = (MxU32) -1; + return SUCCESS; + } + } + } + return FAILURE; } // OFFSET: LEGO1 0x1005c470 STUB @@ -34,11 +184,25 @@ void LegoInputManager::UnRegister(MxCore *) // TODO } -// OFFSET: LEGO1 0x1005b8b0 STUB -MxResult LegoInputManager::Tickle() +// OFFSET: LEGO1 0x1005c740 STUB +void LegoInputManager::QueueEvent(NotificationId id, unsigned char p2, MxLong p3, MxLong p4, unsigned char p5) { // TODO - - return 0; } +// OFFSET: LEGO1 0x1005cfb0 +void LegoInputManager::SetTimer() +{ + LegoOmni* omni = LegoOmni::GetInstance(); + UINT timer = ::SetTimer(omni->GetWindowHandle(), 1, m_timeout, NULL); + m_timer = timer; +} + +// OFFSET: LEGO1 0x1005cfd0 +void LegoInputManager::KillTimer() +{ + if (m_timer != 0) { + LegoOmni* omni = LegoOmni::GetInstance(); + ::KillTimer(omni->GetWindowHandle(), m_timer); + } +} diff --git a/LEGO1/legoinputmanager.h b/LEGO1/legoinputmanager.h index 56b77445..a44aef32 100644 --- a/LEGO1/legoinputmanager.h +++ b/LEGO1/legoinputmanager.h @@ -3,6 +3,9 @@ #include "decomp.h" #include "mxpresenter.h" +#include "mxlist.h" + +#include enum NotificationId { @@ -14,6 +17,8 @@ enum NotificationId TIMER = 15 }; +class LegoControlManager; + // VTABLE 0x100d8760 // SIZE 0x338 class LegoInputManager : public MxPresenter @@ -28,22 +33,42 @@ class LegoInputManager : public MxPresenter virtual MxResult Tickle() override; // vtable+0x8 - undefined m_pad40[0x48]; + void Destroy(); + void CreateAndAcquireKeyboard(HWND hwnd); + void ReleaseDX(); + MxResult GetJoystickId(); + MxResult GetJoystickState(MxU32 *joystick_x, MxU32 *joystick_y, DWORD *buttons_state, MxU32 *pov_position); + void SetTimer(); + void KillTimer(); - MxBool m_unk88; - undefined m_unk89[0x113]; - - // 0x19C - int m_joystickIndex; - - undefined m_pad1a0[0x194]; - - // 0x334 +//private: + MxCriticalSection m_criticalSection; + MxList *m_unk0x5c; // list or hash table + undefined4 m_unk0x60; + undefined4 m_unk0x64; + MxList *m_unk0x68; // list or hash table + undefined4 m_unk0x6c; + undefined4 m_unk0x70; + undefined4 m_unk0x74; + UINT m_timer; + UINT m_timeout; + undefined m_unk0x80; + undefined m_unk0x81; + LegoControlManager* m_controlManager; + MxBool m_unk0x88; + IDirectInput *m_directInput; + IDirectInputDevice *m_directInputDevice; + undefined m_unk0x94; + undefined4 m_unk0x98; + undefined m_unk0x9c[0xF8]; + undefined m_unk0x194; + MxBool m_unk0x195; + MxS32 m_joyid; + MxS32 m_joystickIndex; + JOYCAPS m_joyCaps; MxBool m_useJoystick; - - undefined m_unk335; - MxBool m_unk336; - undefined m_unk337; + MxBool m_unk0x335; + MxBool m_unk0x336; }; #endif // LEGOINPUTMANAGER_H diff --git a/LEGO1/mxtransitionmanager.cpp b/LEGO1/mxtransitionmanager.cpp index c5a0cb27..c3dfb035 100644 --- a/LEGO1/mxtransitionmanager.cpp +++ b/LEGO1/mxtransitionmanager.cpp @@ -83,8 +83,8 @@ MxResult MxTransitionManager::StartTransition(TransitionType p_animationType, Mx tickleManager->RegisterClient(this, p_speed); LegoInputManager *inputManager = InputManager(); - inputManager->m_unk88 = TRUE; - inputManager->m_unk336 = FALSE; + inputManager->m_unk0x88 = TRUE; + inputManager->m_unk0x336 = FALSE; LegoVideoManager *videoManager = VideoManager(); videoManager->SetUnkE4(FALSE);