From 068760056afd6792949c487709e663cc686d7f5e Mon Sep 17 00:00:00 2001 From: Misha <106913236+MishaProductions@users.noreply.github.com> Date: Mon, 4 Mar 2024 17:00:38 -0500 Subject: [PATCH] fix bug in MxPresenter::CreateEntity (#626) * fix bug in MxPresenter::CreateEntity * Match 100% --------- Co-authored-by: Christian Semmler --- LEGO1/omni/include/mxpresenter.h | 2 +- LEGO1/omni/src/common/mxpresenter.cpp | 28 ++++++++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/LEGO1/omni/include/mxpresenter.h b/LEGO1/omni/include/mxpresenter.h index f0c3e1b8..62090b7f 100644 --- a/LEGO1/omni/include/mxpresenter.h +++ b/LEGO1/omni/include/mxpresenter.h @@ -107,7 +107,7 @@ class MxPresenter : public MxCore { virtual void Enable(MxBool p_enable); // vtable+0x54 - MxEntity* CreateEntity(const char* p_name); + MxEntity* CreateEntity(const char* p_defaultName); void SendToCompositePresenter(MxOmni*); MxBool IsEnabled(); diff --git a/LEGO1/omni/src/common/mxpresenter.cpp b/LEGO1/omni/src/common/mxpresenter.cpp index b0ec1bd9..96389b5f 100644 --- a/LEGO1/omni/src/common/mxpresenter.cpp +++ b/LEGO1/omni/src/common/mxpresenter.cpp @@ -239,24 +239,26 @@ const char* PresenterNameDispatch(const MxDSAction& p_action) } // FUNCTION: LEGO1 0x100b5410 -MxEntity* MxPresenter::CreateEntity(const char* p_name) +MxEntity* MxPresenter::CreateEntity(const char* p_defaultName) { - char buffer[512]; - char buffer2[512]; - strcpy(buffer, p_name); + // create an object from LegoObjectFactory based on OBJECT: value in extra data. + // If that is missing, p_defaultName is used - MxU16 extraLen = m_action->GetExtraLength(); + char objectName[512]; + strcpy(objectName, p_defaultName); - buffer[0] = extraLen; - buffer[1] = extraLen >> 8; - if (extraLen) { - extraLen &= MAXWORD; - memcpy(buffer2 + 2, m_action->GetExtraData(), extraLen); - buffer2[extraLen + 2] = 0; - KeyValueStringParse(buffer, g_strOBJECT, buffer2 + 2); + MxU16 extraLength; + char* extraData; + m_action->GetExtra(extraLength, extraData); + + if (extraLength & MAXWORD) { + char extraCopy[512]; + memcpy(extraCopy, extraData, extraLength & MAXWORD); + extraCopy[extraLength & MAXWORD] = '\0'; + KeyValueStringParse(objectName, g_strOBJECT, extraCopy); } - return (MxEntity*) ObjectFactory()->Create(buffer); + return (MxEntity*) ObjectFactory()->Create(objectName); } // FUNCTION: LEGO1 0x100b54c0