From f941679769ddc2821b852be1694601611284b17d Mon Sep 17 00:00:00 2001 From: Misha <106913236+MishaProductions@users.noreply.github.com> Date: Sat, 16 Dec 2023 11:15:01 -0500 Subject: [PATCH] LegoOmni functions --- CMakeLists.txt | 1 + LEGO1/lego3dmanager.h | 2 +- LEGO1/lego3dview.cpp | 9 +++ LEGO1/lego3dview.h | 4 + LEGO1/legoomni.cpp | 120 ++++++++++++++++++++++++---- LEGO1/legoomni.h | 34 ++++---- LEGO1/legoworld.cpp | 7 ++ LEGO1/legoworld.h | 2 + LEGO1/mxactionnotificationparam.cpp | 12 +++ LEGO1/mxactionnotificationparam.h | 42 ++++++++++ LEGO1/mxdsobject.h | 2 + LEGO1/mxomni.cpp | 44 +++++++++- LEGO1/mxomni.h | 27 ++++--- LEGO1/mxstreamcontroller.cpp | 17 ++++ LEGO1/mxstreamcontroller.h | 1 + 15 files changed, 276 insertions(+), 48 deletions(-) create mode 100644 LEGO1/lego3dview.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ed3c29cf..1b161d18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -224,6 +224,7 @@ add_library(lego1 SHARED LEGO1/towtrackmissionstate.cpp LEGO1/viewmanager/viewmanager.cpp LEGO1/viewmanager/viewroi.cpp + LEGO1/lego3dview.cpp ) if (MINGW) target_compile_definitions(lego1 PRIVATE DIRECTINPUT_VERSION=0x0500) diff --git a/LEGO1/lego3dmanager.h b/LEGO1/lego3dmanager.h index f7638649..68583e28 100644 --- a/LEGO1/lego3dmanager.h +++ b/LEGO1/lego3dmanager.h @@ -10,7 +10,7 @@ class Lego3DManager { private: int m_unk0x00; int m_unk0x04; - Lego3DView* m_3dView; + Lego3DView* m_3dView; // 0x08 }; #endif // LEGO3DMANAGER_H diff --git a/LEGO1/lego3dview.cpp b/LEGO1/lego3dview.cpp new file mode 100644 index 00000000..14fcfaaa --- /dev/null +++ b/LEGO1/lego3dview.cpp @@ -0,0 +1,9 @@ +#include "lego3dview.h" +#include "legoroi.h" + +// STUB: LEGO1 0x1003dd70 +LegoROI* Lego3DView::PickROI(MxLong p_a, MxLong p_b) +{ + // TODO + return NULL; +} diff --git a/LEGO1/lego3dview.h b/LEGO1/lego3dview.h index e62a220f..a16e3f35 100644 --- a/LEGO1/lego3dview.h +++ b/LEGO1/lego3dview.h @@ -2,10 +2,14 @@ #define LEGO3DVIEW_H #include "viewmanager/viewmanager.h" +#include "mxtypes.h" + +class LegoROI; class Lego3DView { public: inline ViewManager* GetViewManager() { return this->m_viewManager; } + LegoROI* PickROI(MxLong p_a, MxLong p_b); private: char m_pad[0x88]; diff --git a/LEGO1/legoomni.cpp b/LEGO1/legoomni.cpp index d195957d..b5dc68b5 100644 --- a/LEGO1/legoomni.cpp +++ b/LEGO1/legoomni.cpp @@ -8,10 +8,12 @@ #include "legoobjectfactory.h" #include "legoplantmanager.h" #include "legosoundmanager.h" +#include "legounksavedatawriter.h" #include "legoutil.h" #include "legovideomanager.h" #include "legoworld.h" #include "legoworldlist.h" +#include "mxactionnotificationparam.h" #include "mxautolocker.h" #include "mxbackgroundaudiomanager.h" #include "mxdsfile.h" @@ -173,7 +175,7 @@ IslePathActor* GetCurrentVehicle() // FUNCTION: LEGO1 0x100157a0 LegoWorld* GetCurrentWorld() { - return LegoOmni::GetInstance()->GetCurrentWorld(); + return LegoOmni::GetInstance()->GetCurrentOmniWorld(); } // FUNCTION: LEGO1 0x100157e0 @@ -227,13 +229,15 @@ void PlayMusic(MxU32 p_index) void FUN_1001a700() { // TODO + + // This function seems to populate an unknown structure, and then calls 0x1001b230 } -// STUB: LEGO1 0x1003dd70 -LegoROI* PickROI(MxLong, MxLong) +// FUNCTION: LEGO1 0x1003dd70 +LegoROI* PickROI(MxLong p_a, MxLong p_b) { - // TODO - return NULL; + LegoVideoManager* vid = VideoManager(); + return vid->Get3DManager()->GetLego3DView()->PickROI(p_a, p_b); } // STUB: LEGO1 0x1003ddc0 @@ -379,10 +383,83 @@ void LegoOmni::Init() m_transitionManager = NULL; } -// STUB: LEGO1 0x10058c30 +// FUNCTION: LEGO1 0x10058c30 void LegoOmni::Destroy() { - // TODO + MxAutoLocker lock(&this->m_criticalsection); + + m_notificationManager->Unregister(this); + + if (m_worldList) { + delete m_worldList; + m_worldList = NULL; + } + + if (m_gameState) { + delete m_gameState; + m_gameState = NULL; + } + + if (m_animationManager) { + delete m_animationManager; + m_animationManager = NULL; + } + + if (m_saveDataWriter) { + delete m_saveDataWriter; + m_saveDataWriter = NULL; + } + + if (m_plantManager) { + delete m_plantManager; + m_plantManager = NULL; + } + + if (m_buildingManager) { + delete m_buildingManager; + m_buildingManager = NULL; + } + + if (m_gifManager) { + delete m_gifManager; + m_gifManager = NULL; + } + + if (m_unk0x6c) { + // delete m_unk0x6c; // TODO + m_unk0x6c = NULL; + } + + if (m_inputMgr) { + delete m_inputMgr; + m_inputMgr = NULL; + } + + if (m_inputMgr) { + delete m_inputMgr; + m_inputMgr = NULL; + } + + // todo FUN_10046de0 + + if (m_bkgAudioManager) { + m_bkgAudioManager->Stop(); + + delete m_bkgAudioManager; + m_bkgAudioManager = NULL; + } + + if (m_transitionManager) { + delete m_transitionManager; + m_transitionManager = NULL; + } + + m_action.ClearAtom(); + UnregisterScripts(); + + delete[] m_unk0x68; + + MxOmni::Destroy(); } // FUNCTION: LEGO1 0x10058e70 @@ -527,11 +604,14 @@ MxBool LegoOmni::DoesEntityExist(MxDSAction& p_dsAction) return FALSE; } -// STUB: LEGO1 0x1005b400 -int LegoOmni::GetCurrPathInfo(LegoPathBoundary**, int&) +// FUNCTION: LEGO1 0x1005b400 +int LegoOmni::GetCurrPathInfo(LegoPathBoundary** p_path, int& p_value) { - // TODO - return 0; + if (GetCurrentWorld() == NULL) { + return -1; + } + + return GetCurrentWorld()->GetCurrPathInfo(p_path, p_value); } // FUNCTION: LEGO1 0x1005b560 @@ -551,11 +631,23 @@ MxResult LegoOmni::Start(MxDSAction* p_dsAction) return result; } -// STUB: LEGO1 0x1005b5f0 +// FUNCTION: LEGO1 0x1005b5f0 MxLong LegoOmni::Notify(MxParam& p_param) { - // TODO - return 0; + MxBool isCD = FALSE; + + if (((MxNotificationParam&) p_param).GetType() == c_notificationEndAction && + ((MxActionNotificationParam&) p_param).GetAction()->GetAtomId() == *g_nocdSourceName) { + isCD = TRUE; + } + + MxLong result = MxOmni::Notify(p_param); + if (isCD) { + // Exit the game if nocd.si ended + PostMessageA(m_windowHandle, WM_CLOSE, 0, 0); + } + + return result; } // FUNCTION: LEGO1 0x1005b640 diff --git a/LEGO1/legoomni.h b/LEGO1/legoomni.h index f8e61946..2f882f76 100644 --- a/LEGO1/legoomni.h +++ b/LEGO1/legoomni.h @@ -103,7 +103,7 @@ class LegoOmni : public MxOmni { LegoInputManager* GetInputManager() { return m_inputMgr; } GifManager* GetGifManager() { return m_gifManager; } - LegoWorld* GetCurrentWorld() { return m_currentWorld; } + LegoWorld* GetCurrentOmniWorld() { return m_currentWorld; } LegoNavController* GetNavController() { return m_navController; } IslePathActor* GetCurrentVehicle() { return m_currentVehicle; } LegoPlantManager* GetLegoPlantManager() { return m_plantManager; } @@ -115,24 +115,24 @@ class LegoOmni : public MxOmni { MxDSAction& GetCurrentAction() { return m_action; } private: - undefined4 m_unk0x68; - undefined4 m_unk0x6c; - LegoInputManager* m_inputMgr; // 0x70 - GifManager* m_gifManager; - LegoWorldList* m_worldList; // 0x78 - LegoWorld* m_currentWorld; - MxBool m_unk0x80; - LegoNavController* m_navController; // 0x84 - IslePathActor* m_currentVehicle; // 0x88 - LegoUnkSaveDataWriter* m_saveDataWriter; - LegoPlantManager* m_plantManager; // 0x90 - LegoAnimationManager* m_animationManager; - LegoBuildingManager* m_buildingManager; // 0x98 - LegoGameState* m_gameState; // 0x9c - MxDSAction m_action; + undefined4* m_unk0x68; // 0x68 + undefined4 m_unk0x6c; // 0x6c + LegoInputManager* m_inputMgr; // 0x70 + GifManager* m_gifManager; // 0x74 + LegoWorldList* m_worldList; // 0x78 + LegoWorld* m_currentWorld; // 0x7c + MxBool m_unk0x80; // 0x80 + LegoNavController* m_navController; // 0x84 + IslePathActor* m_currentVehicle; // 0x88 + LegoUnkSaveDataWriter* m_saveDataWriter; // 0x8c + LegoPlantManager* m_plantManager; // 0x90 + LegoAnimationManager* m_animationManager; // 0x94 + LegoBuildingManager* m_buildingManager; // 0x98 + LegoGameState* m_gameState; // 0x9c + MxDSAction m_action; // 0xa0 MxBackgroundAudioManager* m_bkgAudioManager; // 0x134 MxTransitionManager* m_transitionManager; // 0x138 - MxBool m_unk0x13c; + MxBool m_unk0x13c; // 0x13c }; __declspec(dllexport) MxBackgroundAudioManager* BackgroundAudioManager(); diff --git a/LEGO1/legoworld.cpp b/LEGO1/legoworld.cpp index 6f14b43f..9cf5266c 100644 --- a/LEGO1/legoworld.cpp +++ b/LEGO1/legoworld.cpp @@ -91,6 +91,13 @@ void LegoWorld::FUN_1001fc80(IslePathActor* p_actor) { } +// STUB: LEGO1 0x10020120 +int LegoWorld::GetCurrPathInfo(LegoPathBoundary** p_path, int& p_value) +{ + // TODO + return 0; +} + // STUB: LEGO1 0x10020220 void LegoWorld::VTable0x58(MxCore* p_object) { diff --git a/LEGO1/legoworld.h b/LEGO1/legoworld.h index 6752ca9a..70e025fb 100644 --- a/LEGO1/legoworld.h +++ b/LEGO1/legoworld.h @@ -8,6 +8,7 @@ #include "mxpresenterlist.h" class IslePathActor; +class LegoPathBoundary; // VTABLE: LEGO1 0x100d6280 // SIZE 0xf8 @@ -50,6 +51,7 @@ class LegoWorld : public LegoEntity { MxBool FUN_10072980(MxU32, Vector3Data& p_loc, Vector3Data& p_dir, Vector3Data& p_up); void FUN_10073400(); void FUN_10073430(); + int GetCurrPathInfo(LegoPathBoundary** p_path, int& p_value); protected: LegoPathControllerList m_list0x68; // 0x68 diff --git a/LEGO1/mxactionnotificationparam.cpp b/LEGO1/mxactionnotificationparam.cpp index 2122ba0d..0bd93281 100644 --- a/LEGO1/mxactionnotificationparam.cpp +++ b/LEGO1/mxactionnotificationparam.cpp @@ -9,8 +9,20 @@ MxNotificationParam* MxActionNotificationParam::Clone() return new MxActionNotificationParam(this->m_type, this->m_sender, this->m_action, this->m_realloc); } +// FUNCTION: LEGO1 0x100b0300 +MxNotificationParam* MxStartActionNotificationParam::Clone() +{ + return new MxEndActionNotificationParam(c_notificationStartAction, this->m_sender, this->m_action, this->m_realloc); +} + // FUNCTION: LEGO1 0x10051270 MxNotificationParam* MxEndActionNotificationParam::Clone() { return new MxEndActionNotificationParam(c_notificationEndAction, this->m_sender, this->m_action, this->m_realloc); } + +// FUNCTION: LEGO1 0x100b04f0 +MxNotificationParam* MxType4NotificationParam::Clone() +{ + return new MxType4NotificationParam(this->m_sender, this->m_action, this->m_unk0x14); +} diff --git a/LEGO1/mxactionnotificationparam.h b/LEGO1/mxactionnotificationparam.h index cbe73fe2..68c136c4 100644 --- a/LEGO1/mxactionnotificationparam.h +++ b/LEGO1/mxactionnotificationparam.h @@ -50,6 +50,23 @@ class MxActionNotificationParam : public MxNotificationParam { MxBool m_realloc; // 0x10 }; +// VTABLE: LEGO1 0x100dc210 +// SIZE 0x14 +class MxStartActionNotificationParam : public MxActionNotificationParam { +public: + inline MxStartActionNotificationParam( + NotificationId p_type, + MxCore* p_sender, + MxDSAction* p_action, + MxBool p_reallocAction + ) + : MxActionNotificationParam(p_type, p_sender, p_action, p_reallocAction) + { + } + + virtual MxNotificationParam* Clone() override; // vtable+0x4 +}; + // VTABLE: LEGO1 0x100d8358 // SIZE 0x14 class MxEndActionNotificationParam : public MxActionNotificationParam { @@ -67,7 +84,32 @@ class MxEndActionNotificationParam : public MxActionNotificationParam { virtual MxNotificationParam* Clone() override; // vtable+0x4 }; +// VTABLE: LEGO1 0x100dc208 +// SIZE 0x18 +class MxType4NotificationParam : public MxActionNotificationParam { +public: + inline MxType4NotificationParam( + MxCore* p_sender, + MxDSAction* p_action, + undefined4 p_unk0x14 + ) + : MxActionNotificationParam(TYPE4, p_sender, p_action, FALSE) + { + m_unk0x14 = p_unk0x14; + } + + virtual MxNotificationParam* Clone() override; // vtable+0x4 + +private: + undefined4 m_unk0x14; // 0x14 +}; + +// SYNTHETIC: LEGO1 0x100b0430 +// MxStartActionNotificationParam::`scalar deleting destructor' + // SYNTHETIC: LEGO1 0x100513a0 // MxEndActionNotificationParam::`scalar deleting destructor' +// SYNTHETIC: LEGO1 0x100b05c0 +// MxType4NotificationParam::`scalar deleting destructor' #endif diff --git a/LEGO1/mxdsobject.h b/LEGO1/mxdsobject.h index dfa967cf..1a398af0 100644 --- a/LEGO1/mxdsobject.h +++ b/LEGO1/mxdsobject.h @@ -45,6 +45,8 @@ class MxDSObject : public MxCore { inline void SetUnknown24(MxS16 p_unk0x24) { this->m_unk0x24 = p_unk0x24; } inline void SetUnknown28(undefined4 p_unk0x28) { this->m_unk0x28 = p_unk0x28; } + inline void ClearAtom() { m_atomId.Clear(); } + private: MxU32 m_sizeOnDisk; // 0x8 MxU16 m_type; // 0xc diff --git a/LEGO1/mxomni.cpp b/LEGO1/mxomni.cpp index 7a7560a5..c298629c 100644 --- a/LEGO1/mxomni.cpp +++ b/LEGO1/mxomni.cpp @@ -1,5 +1,6 @@ #include "mxomni.h" +#include "mxactionnotificationparam.h" #include "mxatomidcounter.h" #include "mxautolocker.h" #include "mxeventmanager.h" @@ -7,6 +8,7 @@ #include "mxnotificationmanager.h" #include "mxobjectfactory.h" #include "mxomnicreateparam.h" +#include "mxpresenter.h" #include "mxsoundmanager.h" #include "mxstreamer.h" #include "mxticklemanager.h" @@ -317,10 +319,46 @@ MxResult MxOmni::DeleteObject(MxDSAction& p_dsAction) return FAILURE; } -// STUB: LEGO1 0x100b00e0 -void MxOmni::Vtable0x2c() +// FUNCTION: LEGO1 0x100b00e0 +MxResult MxOmni::CreatePresenter(MxStreamController* p_controller, MxDSAction& p_action) { - // TODO + MxResult result = FAILURE; + MxPresenter* object = (MxPresenter*) m_objectFactory->Create(PresenterNameDispatch(p_action)); + if (object == NULL) { + return result; + } + + if (object->AddToManager() == SUCCESS) { + MxPresenter* sender = (MxPresenter*) p_action.GetUnknown28(); + if (sender == NULL && (sender = (MxPresenter*) p_controller->FUN_100c1e70(p_action)) == NULL) { + if (p_action.GetOrigin() == NULL) { + p_action.SetOrigin(this); + } + + object->SetCompositePresenter(NULL); + } + else { + p_action.SetOrigin(sender); + object->SetCompositePresenter((MxCompositePresenter*) sender); + } + + if (object->StartAction(p_controller, &p_action) == SUCCESS) { + if (sender) { + NotificationManager()->Send(p_action.GetUnknown84(), &MxType4NotificationParam(this, &p_action, FALSE)); + } + + if (p_action.GetUnknown84()) { + NotificationManager()->Send( + p_action.GetUnknown84(), + &MxStartActionNotificationParam(c_notificationStartAction, this, &p_action, FALSE) + ); + } + } + + result = SUCCESS; + } + + return result; } // FUNCTION: LEGO1 0x100b0680 diff --git a/LEGO1/mxomni.h b/LEGO1/mxomni.h index 2f8f1efd..0ac78acb 100644 --- a/LEGO1/mxomni.h +++ b/LEGO1/mxomni.h @@ -22,6 +22,7 @@ class MxTimer; class MxVariableTable; class MxVideoManager; class MxEntity; +class MxStreamController; // VTABLE: LEGO1 0x100dc168 // SIZE 0x68 @@ -39,19 +40,19 @@ class MxOmni : public MxCore { MxOmni(); virtual ~MxOmni() override; - virtual MxLong Notify(MxParam& p_param) override; // vtable+04 - virtual void Init(); // vtable+14 - virtual MxResult Create(MxOmniCreateParam& p_param); // vtable+18 - virtual void Destroy(); // vtable+1c - virtual MxResult Start(MxDSAction* p_dsAction); // vtable+20 - virtual MxResult DeleteObject(MxDSAction& p_dsAction); // vtable+24 - virtual MxBool DoesEntityExist(MxDSAction& p_dsAction); // vtable+28 - virtual void Vtable0x2c(); // vtable+2c - virtual MxEntity* FindWorld(const char*, MxS32, MxPresenter*); // vtable+30 - virtual void NotifyCurrentEntity(MxNotificationParam* p_param); // vtable+34 - virtual void StartTimer(); // vtable+38 - virtual void StopTimer(); // vtable+3c - virtual MxBool IsTimerRunning(); // vtable+40 + virtual MxLong Notify(MxParam& p_param) override; // vtable+04 + virtual void Init(); // vtable+14 + virtual MxResult Create(MxOmniCreateParam& p_param); // vtable+18 + virtual void Destroy(); // vtable+1c + virtual MxResult Start(MxDSAction* p_dsAction); // vtable+20 + virtual MxResult DeleteObject(MxDSAction& p_dsAction); // vtable+24 + virtual MxBool DoesEntityExist(MxDSAction& p_dsAction); // vtable+28 + virtual MxResult CreatePresenter(MxStreamController* p_controller, MxDSAction& p_action); // vtable+2c + virtual MxEntity* FindWorld(const char*, MxS32, MxPresenter*); // vtable+30 + virtual void NotifyCurrentEntity(MxNotificationParam* p_param); // vtable+34 + virtual void StartTimer(); // vtable+38 + virtual void StopTimer(); // vtable+3c + virtual MxBool IsTimerRunning(); // vtable+40 static void SetInstance(MxOmni* p_instance); HWND GetWindowHandle() const { return this->m_windowHandle; } MxObjectFactory* GetObjectFactory() const { return this->m_objectFactory; } diff --git a/LEGO1/mxstreamcontroller.cpp b/LEGO1/mxstreamcontroller.cpp index 9357ebf6..a29c2740 100644 --- a/LEGO1/mxstreamcontroller.cpp +++ b/LEGO1/mxstreamcontroller.cpp @@ -140,6 +140,23 @@ MxResult MxStreamController::FUN_100c1f00(MxDSAction* p_action) return FAILURE; } +// FUNCTION: LEGO1 0x100c1e70 +MxCore* MxStreamController::FUN_100c1e70(MxDSAction& p_obj) +{ + MxAutoLocker locker(&m_criticalSection); + MxCore* result = NULL; + if (p_obj.GetObjectId() != -1) + { + MxDSAction* action = m_unk0x3c.Find(&p_obj, FALSE); + if (action != NULL) + { + result = (MxCore*)action->GetUnknown28(); + } + } + + return result; +} + // STUB: LEGO1 0x100c20d0 MxBool MxStreamController::FUN_100c20d0(MxDSObject& p_obj) { diff --git a/LEGO1/mxstreamcontroller.h b/LEGO1/mxstreamcontroller.h index a4d90b86..fc651797 100644 --- a/LEGO1/mxstreamcontroller.h +++ b/LEGO1/mxstreamcontroller.h @@ -44,6 +44,7 @@ class MxStreamController : public MxCore { MxResult FUN_100c1800(MxDSAction* p_action, MxU32 p_val); MxBool FUN_100c20d0(MxDSObject& p_obj); MxResult FUN_100c1a00(MxDSAction* p_action, MxU32 p_bufferval); + MxCore* FUN_100c1e70(MxDSAction& p_obj); MxResult FUN_100c1f00(MxDSAction* p_action); inline MxAtomId& GetAtom() { return m_atom; };