From a95bdcc4ad205c7a89da32db0ef93dd6ae961391 Mon Sep 17 00:00:00 2001 From: Misha <106913236+MishaProductions@users.noreply.github.com> Date: Fri, 29 Dec 2023 10:22:18 -0500 Subject: [PATCH] Implement InvokeAction (#386) * push changes * Update legoutil.cpp * Fixes / match --------- Co-authored-by: Christian Semmler --- LEGO1/legoomni.cpp | 2 +- LEGO1/legoomni.h | 4 ++- LEGO1/legoutil.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++-- LEGO1/legoutil.h | 2 +- 4 files changed, 84 insertions(+), 5 deletions(-) diff --git a/LEGO1/legoomni.cpp b/LEGO1/legoomni.cpp index 8c9e5905..ddf0e454 100644 --- a/LEGO1/legoomni.cpp +++ b/LEGO1/legoomni.cpp @@ -390,7 +390,7 @@ void LegoOmni::Init() m_gifManager = NULL; m_worldList = NULL; m_currentWorld = NULL; - m_unk0x80 = FALSE; + m_exit = FALSE; m_currentVehicle = NULL; m_saveDataWriter = NULL; m_plantManager = NULL; diff --git a/LEGO1/legoomni.h b/LEGO1/legoomni.h index 7fb0a4f3..dff06fb5 100644 --- a/LEGO1/legoomni.h +++ b/LEGO1/legoomni.h @@ -116,6 +116,8 @@ class LegoOmni : public MxOmni { MxTransitionManager* GetTransitionManager() { return m_transitionManager; } MxDSAction& GetCurrentAction() { return m_action; } + inline void SetExit(MxBool p_exit) { m_exit = p_exit; }; + private: undefined4* m_unk0x68; // 0x68 MxUnknown100dbdbc* m_renderMgr; // 0x6c @@ -123,7 +125,7 @@ class LegoOmni : public MxOmni { GifManager* m_gifManager; // 0x74 LegoWorldList* m_worldList; // 0x78 LegoWorld* m_currentWorld; // 0x7c - MxBool m_unk0x80; // 0x80 + MxBool m_exit; // 0x80 LegoNavController* m_navController; // 0x84 IslePathActor* m_currentVehicle; // 0x88 LegoUnkSaveDataWriter* m_saveDataWriter; // 0x8c diff --git a/LEGO1/legoutil.cpp b/LEGO1/legoutil.cpp index 42d14dac..4941d968 100644 --- a/LEGO1/legoutil.cpp +++ b/LEGO1/legoutil.cpp @@ -1,8 +1,13 @@ #include "legoutil.h" +#include "legoomni.h" +#include "legoworld.h" +#include "mxdsaction.h" #include "mxomni.h" +#include "mxstreamer.h" #include "mxtypes.h" +#include #include // FUNCTION: LEGO1 0x1003e300 @@ -34,8 +39,79 @@ ExtraActionType MatchActionString(const char* p_str) return result; } -// STUB: LEGO1 0x1003e430 +MxBool CheckIfEntityExists(MxBool p_enable, const char* p_filename, MxS32 p_entityId); +void NotifyEntity(const char* p_filename, MxS32 p_entityId, LegoEntity* p_sender); + +// FUNCTION: LEGO1 0x1003e430 void InvokeAction(ExtraActionType p_actionId, MxAtomId& p_pAtom, int p_targetEntityId, LegoEntity* p_sender) +{ + MxDSAction action; + action.SetAtomId(p_pAtom); + action.SetObjectId(p_targetEntityId); + + switch (p_actionId) { + case ExtraActionType_opendisk: + if (!CheckIfEntityExists(TRUE, p_pAtom.GetInternal(), p_targetEntityId)) { + Streamer()->Open(p_pAtom.GetInternal(), MxStreamer::e_DiskStream); + Start(&action); + } + break; + case ExtraActionType_openram: + if (!CheckIfEntityExists(TRUE, p_pAtom.GetInternal(), p_targetEntityId)) { + Streamer()->Open(p_pAtom.GetInternal(), MxStreamer::e_RAMStream); + Start(&action); + } + break; + case ExtraActionType_close: + action.SetUnknown24(-2); + DeleteObject(action); + Streamer()->Close(p_pAtom.GetInternal()); + break; + case ExtraActionType_start: + if (!CheckIfEntityExists(TRUE, p_pAtom.GetInternal(), p_targetEntityId)) { + Start(&action); + } + break; + case ExtraActionType_stop: + action.SetUnknown24(-2); + if (!FUN_1003ee00(p_pAtom, p_targetEntityId)) { + DeleteObject(action); + } + break; + case ExtraActionType_run: + _spawnl(0, "\\lego\\sources\\main\\main.exe", "\\lego\\sources\\main\\main.exe", "/script", &p_pAtom, 0); + break; + case ExtraActionType_exit: + Lego()->SetExit(TRUE); + break; + case ExtraActionType_enable: + CheckIfEntityExists(TRUE, p_pAtom.GetInternal(), p_targetEntityId); + break; + case ExtraActionType_disable: + CheckIfEntityExists(FALSE, p_pAtom.GetInternal(), p_targetEntityId); + break; + case ExtraActionType_notify: + NotifyEntity(p_pAtom.GetInternal(), p_targetEntityId, p_sender); + break; + } +} + +// FUNCTION: LEGO1 0x1003e670 +MxBool CheckIfEntityExists(MxBool p_enable, const char* p_filename, MxS32 p_entityId) +{ + LegoWorld* world = + (LegoWorld*) FindEntityByAtomIdOrEntityId(MxAtomId(p_filename, LookupMode_LowerCase2), p_entityId); + if (world) { + world->VTable0x68(p_enable); + return TRUE; + } + else { + return FALSE; + } +} + +// STUB: LEGO1 0x1003e700 +void NotifyEntity(const char* p_filename, MxS32 p_entityId, LegoEntity* p_sender) { } @@ -108,8 +184,9 @@ void ConvertHSVToRGB(float p_h, float p_s, float p_v, float* p_rOut, float* p_bO } // STUB: LEGO1 0x1003ee00 -void FUN_1003ee00(MxAtomId& p_atomId, MxS32 p_id) +MxBool FUN_1003ee00(MxAtomId& p_atomId, MxS32 p_id) { + return TRUE; } // STUB: LEGO1 0x1003ef00 diff --git a/LEGO1/legoutil.h b/LEGO1/legoutil.h index bd7adae6..827b8488 100644 --- a/LEGO1/legoutil.h +++ b/LEGO1/legoutil.h @@ -58,7 +58,7 @@ inline void GetString(MxU8** p_source, char** p_dest, T* p_obj, void (T::*p_sett ExtraActionType MatchActionString(const char*); void InvokeAction(ExtraActionType p_actionId, MxAtomId& p_pAtom, int p_targetEntityId, LegoEntity* p_sender); void ConvertHSVToRGB(float p_h, float p_s, float p_v, float* p_rOut, float* p_bOut, float* p_gOut); -void FUN_1003ee00(MxAtomId& p_atomId, MxS32 p_id); +MxBool FUN_1003ee00(MxAtomId& p_atomId, MxS32 p_id); void FUN_1003ef00(MxBool); void SetAppCursor(WPARAM p_wparam); MxBool FUN_1003ef60();