From eaa935f646266cc62c75e364b260ff8a87f09f30 Mon Sep 17 00:00:00 2001 From: Misha <106913236+MishaProductions@users.noreply.github.com> Date: Tue, 19 Mar 2024 14:44:42 -0400 Subject: [PATCH] Finish LegoVariables class (#698) * Finish LegoVariables class * Update legonavcontroller.cpp * Update legobackgroundcolor.cpp * Match functions, style, refactor visible * Use MxBool * Merge/fix --------- Co-authored-by: Christian Semmler --- .../legoomni/include/legomodelpresenter.h | 2 +- .../lego/legoomni/include/legonavcontroller.h | 1 + LEGO1/lego/legoomni/include/misc.h | 2 +- .../src/common/legocharactermanager.cpp | 2 +- .../legoomni/src/common/legovariables.cpp | 97 +++++++++++++++++-- LEGO1/lego/legoomni/src/common/misc.cpp | 4 +- .../legoomni/src/entity/legonavcontroller.cpp | 6 ++ .../legoomni/src/input/legoinputmanager.cpp | 2 +- .../legoomni/src/video/legoanimpresenter.cpp | 6 +- .../legoomni/src/video/legomodelpresenter.cpp | 4 +- LEGO1/lego/legoomni/src/worlds/infocenter.cpp | 14 +-- LEGO1/lego/legoomni/src/worlds/isle.cpp | 12 +-- .../legoomni/src/worlds/registrationbook.cpp | 2 +- LEGO1/lego/sources/roi/legoroi.cpp | 2 +- LEGO1/library_msvc.h | 3 + LEGO1/omni/include/mxstring.h | 1 + LEGO1/realtime/roi.h | 12 +-- LEGO1/viewmanager/viewmanager.cpp | 2 +- 18 files changed, 135 insertions(+), 39 deletions(-) diff --git a/LEGO1/lego/legoomni/include/legomodelpresenter.h b/LEGO1/lego/legoomni/include/legomodelpresenter.h index 480de885..8bc784a4 100644 --- a/LEGO1/lego/legoomni/include/legomodelpresenter.h +++ b/LEGO1/lego/legoomni/include/legomodelpresenter.h @@ -36,7 +36,7 @@ class LegoModelPresenter : public MxVideoPresenter { void ParseExtra() override; // vtable+0x30 void Destroy() override; // vtable+0x38 - MxResult FUN_1007ff70(MxDSChunk& p_chunk, LegoEntity* p_entity, undefined p_modelUnknown0x34, LegoWorld* p_world); + MxResult FUN_1007ff70(MxDSChunk& p_chunk, LegoEntity* p_entity, MxBool p_roiVisible, LegoWorld* p_world); inline void Reset() { diff --git a/LEGO1/lego/legoomni/include/legonavcontroller.h b/LEGO1/lego/legoomni/include/legonavcontroller.h index 1621efac..f5f0d44f 100644 --- a/LEGO1/lego/legoomni/include/legonavcontroller.h +++ b/LEGO1/lego/legoomni/include/legonavcontroller.h @@ -71,6 +71,7 @@ class LegoNavController : public MxCore { MxBool p_urs ); static void SetLocation(MxU32 p_location); + static void UpdateCameraLocation(const char* p_location); // SYNTHETIC: LEGO1 0x10054c10 // LegoNavController::`scalar deleting destructor' diff --git a/LEGO1/lego/legoomni/include/misc.h b/LEGO1/lego/legoomni/include/misc.h index 7ff00f83..98d4b352 100644 --- a/LEGO1/lego/legoomni/include/misc.h +++ b/LEGO1/lego/legoomni/include/misc.h @@ -64,7 +64,7 @@ void SetIsWorldActive(MxBool p_isWorldActive); void DeleteObjects(MxAtomId* p_id, MxS32 p_first, MxS32 p_last); void SetCurrentWorld(LegoWorld* p_world); void FUN_10015820(MxBool p_disable, MxU16 p_flags); -void SetROIUnknown0x0c(const char* p_name, undefined p_unk0x0c); +void SetROIVisible(const char* p_name, MxBool p_visible); void SetCurrentActor(IslePathActor* p_currentActor); #endif // MISC_H diff --git a/LEGO1/lego/legoomni/src/common/legocharactermanager.cpp b/LEGO1/lego/legoomni/src/common/legocharactermanager.cpp index d7b5aca4..8b466c41 100644 --- a/LEGO1/lego/legoomni/src/common/legocharactermanager.cpp +++ b/LEGO1/lego/legoomni/src/common/legocharactermanager.cpp @@ -113,7 +113,7 @@ LegoROI* LegoCharacterManager::GetROI(const char* p_key, MxBool p_createEntity) if (character == NULL) { LegoROI* roi = CreateROI(p_key); - roi->SetUnknown0x0c(0); + roi->SetVisibility(FALSE); if (roi != NULL) { character = new LegoCharacter(roi); diff --git a/LEGO1/lego/legoomni/src/common/legovariables.cpp b/LEGO1/lego/legoomni/src/common/legovariables.cpp index e157e3c4..d4689af5 100644 --- a/LEGO1/lego/legoomni/src/common/legovariables.cpp +++ b/LEGO1/lego/legoomni/src/common/legovariables.cpp @@ -2,8 +2,12 @@ #include "legobuildingmanager.h" #include "legocharactermanager.h" +#include "legogamestate.h" +#include "legonavcontroller.h" #include "legoplantmanager.h" +#include "legovideomanager.h" #include "misc.h" +#include "roi/legoroi.h" DECOMP_SIZE_ASSERT(VisibilityVariable, 0x24) DECOMP_SIZE_ASSERT(CameraLocationVariable, 0x24) @@ -27,16 +31,81 @@ const char* g_varCURSOR = "CURSOR"; // STRING: LEGO1 0x100f3a1c const char* g_varWHOAMI = "WHO_AM_I"; -// STUB: LEGO1 0x10037d00 +// GLOBAL: LEGO1 0x100f3a50 +// STRING: LEGO1 0x100f3a18 +const char* g_delimiter2 = " \t"; + +// GLOBAL: LEGO1 0x100f3a54 +// STRING: LEGO1 0x100f3a10 +const char* g_varHIDE = "HIDE"; + +// GLOBAL: LEGO1 0x100f3a58 +// STRING: LEGO1 0x100f3a08 +const char* g_varSHOW = "SHOW"; + +// GLOBAL: LEGO1 0x100f3a5c +// STRING: LEGO1 0x100f3a00 +const char* g_papa = "Papa"; + +// GLOBAL: LEGO1 0x100f3a60 +// STRING: LEGO1 0x100f39f8 +const char* g_mama = "Mama"; + +// GLOBAL: LEGO1 0x100f3a64 +// STRING: LEGO1 0x100f39f0 +const char* g_pepper = "Pepper"; + +// GLOBAL: LEGO1 0x100f3a68 +// STRING: LEGO1 0x100f39e8 +const char* g_nick = "Nick"; + +// GLOBAL: LEGO1 0x100f3a6c +// STRING: LEGO1 0x100f39e0 +const char* g_laura = "Laura"; + +// FUNCTION: LEGO1 0x10037d00 void VisibilityVariable::SetValue(const char* p_value) { - // TODO + MxVariable::SetValue(p_value); + + if (p_value) { + char* instruction = strtok(m_value.GetDataPtr(), g_delimiter2); + char* name = strtok(NULL, g_delimiter2); + MxBool show; + + if (!strcmpi(instruction, g_varHIDE)) { + show = FALSE; + } + else if (!strcmpi(instruction, g_varSHOW)) { + show = TRUE; + } + else { + return; + } + + LegoROI* roi = FindROI(name); + if (roi) { + roi->SetVisibility(show); + } + } } -// STUB: LEGO1 0x10037d80 +// FUNCTION: LEGO1 0x10037d80 void CameraLocationVariable::SetValue(const char* p_value) { - // TODO + char buffer[256]; + MxVariable::SetValue(p_value); + + strcpy(buffer, p_value); + + char* location = strtok(buffer, ","); + NavController()->UpdateCameraLocation(location); + + location = strtok(NULL, ","); + if (location) { + MxFloat pov = (MxFloat) atof(location); + VideoManager()->Get3DManager()->SetFrustrum(pov, 0.1f, 250.0f); + } } // FUNCTION: LEGO1 0x10037e30 @@ -44,10 +113,26 @@ void CursorVariable::SetValue(const char* p_value) { } -// STUB: LEGO1 0x10037e40 +// FUNCTION: LEGO1 0x10037e40 void WhoAmIVariable::SetValue(const char* p_value) { - // TODO + MxVariable::SetValue(p_value); + + if (!strcmpi(p_value, g_papa)) { + GameState()->SetActorId(3); + } + else if (!strcmpi(p_value, g_mama)) { + GameState()->SetActorId(2); + } + else if (!strcmpi(p_value, g_pepper)) { + GameState()->SetActorId(1); + } + else if (!strcmpi(p_value, g_nick)) { + GameState()->SetActorId(4); + } + else if (!strcmpi(p_value, g_laura)) { + GameState()->SetActorId(5); + } } // FUNCTION: LEGO1 0x10085aa0 diff --git a/LEGO1/lego/legoomni/src/common/misc.cpp b/LEGO1/lego/legoomni/src/common/misc.cpp index cf917a62..b5bb13e1 100644 --- a/LEGO1/lego/legoomni/src/common/misc.cpp +++ b/LEGO1/lego/legoomni/src/common/misc.cpp @@ -124,12 +124,12 @@ LegoROI* FindROI(const char* p_name) } // FUNCTION: LEGO1 0x10015860 -void SetROIUnknown0x0c(const char* p_name, undefined p_unk0x0c) +void SetROIVisible(const char* p_name, MxBool p_visible) { LegoROI* roi = FindROI(p_name); if (roi) { - roi->SetUnknown0x0c(p_unk0x0c); + roi->SetVisibility(p_visible); } } diff --git a/LEGO1/lego/legoomni/src/entity/legonavcontroller.cpp b/LEGO1/lego/legoomni/src/entity/legonavcontroller.cpp index 7a6ad696..a6578c3d 100644 --- a/LEGO1/lego/legoomni/src/entity/legonavcontroller.cpp +++ b/LEGO1/lego/legoomni/src/entity/legonavcontroller.cpp @@ -361,6 +361,12 @@ MxBool LegoNavController::CalculateNewPosDir( return changed; } +// STUB: LEGO1 0x10055500 +void LegoNavController::UpdateCameraLocation(const char* p_location) +{ + // TODO +} + // STUB: LEGO1 0x10055620 void LegoNavController::SetLocation(MxU32 p_location) { diff --git a/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp b/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp index 61f6c815..02a89518 100644 --- a/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp +++ b/LEGO1/lego/legoomni/src/input/legoinputmanager.cpp @@ -388,7 +388,7 @@ MxBool LegoInputManager::ProcessOneEvent(LegoEventNotificationParam& p_param) LegoROI* roi = PickROI(p_param.GetX(), p_param.GetY()); p_param.SetROI(roi); - if (roi && roi->GetUnknown0x0c() == 1) { + if (roi && roi->GetVisibility()) { for (OrientableROI* parent = roi->GetParentROI(); parent; parent = parent->GetParentROI()) { roi = (LegoROI*) parent; } diff --git a/LEGO1/lego/legoomni/src/video/legoanimpresenter.cpp b/LEGO1/lego/legoomni/src/video/legoanimpresenter.cpp index 6cddadaf..e3b73b4f 100644 --- a/LEGO1/lego/legoomni/src/video/legoanimpresenter.cpp +++ b/LEGO1/lego/legoomni/src/video/legoanimpresenter.cpp @@ -162,7 +162,7 @@ void LegoAnimPresenter::FUN_100692b0() roi = CharacterManager()->GetROI(src, TRUE); if (roi != NULL && str[0] == '*') { - roi->SetUnknown0x0c(0); + roi->SetVisibility(FALSE); } } else if (unk0x04 == 4) { @@ -174,7 +174,7 @@ void LegoAnimPresenter::FUN_100692b0() roi = CharacterManager()->FUN_10085a80(und, src, 1); if (roi != NULL) { - roi->SetUnknown0x0c(0); + roi->SetVisibility(FALSE); } delete[] src; @@ -198,7 +198,7 @@ void LegoAnimPresenter::FUN_100692b0() roi = CharacterManager()->FUN_10085210(und, src, 1); if (roi != NULL) { - roi->SetUnknown0x0c(0); + roi->SetVisibility(FALSE); } delete[] src; diff --git a/LEGO1/lego/legoomni/src/video/legomodelpresenter.cpp b/LEGO1/lego/legoomni/src/video/legomodelpresenter.cpp index b1c26b0f..8693bf36 100644 --- a/LEGO1/lego/legoomni/src/video/legomodelpresenter.cpp +++ b/LEGO1/lego/legoomni/src/video/legomodelpresenter.cpp @@ -208,7 +208,7 @@ MxResult LegoModelPresenter::CreateROI(MxDSChunk* p_chunk) MxResult LegoModelPresenter::FUN_1007ff70( MxDSChunk& p_chunk, LegoEntity* p_entity, - undefined p_modelUnknown0x34, + MxBool p_roiVisible, LegoWorld* p_world ) { @@ -222,7 +222,7 @@ MxResult LegoModelPresenter::FUN_1007ff70( } if (m_roi != NULL) { - m_roi->SetUnknown0x0c(p_modelUnknown0x34); + m_roi->SetVisibility(p_roiVisible); } if (p_entity != NULL) { diff --git a/LEGO1/lego/legoomni/src/worlds/infocenter.cpp b/LEGO1/lego/legoomni/src/worlds/infocenter.cpp index bdea2fd2..88a04570 100644 --- a/LEGO1/lego/legoomni/src/worlds/infocenter.cpp +++ b/LEGO1/lego/legoomni/src/worlds/infocenter.cpp @@ -296,8 +296,8 @@ MxLong Infocenter::HandleEndAction(MxEndActionNotificationParam& p_param) m_currentCutscene = e_noIntro; return 1; case 2: - SetROIUnknown0x0c(g_object2x4red, 0); - SetROIUnknown0x0c(g_object2x4grn, 0); + SetROIVisible(g_object2x4red, FALSE); + SetROIVisible(g_object2x4grn, FALSE); BackgroundAudioManager()->RaiseVolume(); return 1; case 4: @@ -329,7 +329,7 @@ MxLong Infocenter::HandleEndAction(MxEndActionNotificationParam& p_param) } m_infocenterState->SetUnknown0x74(2); - SetROIUnknown0x0c("infoman", 1); + SetROIVisible("infoman", TRUE); return 1; case 12: if (action->GetObjectId() == m_currentInfomainScript) { @@ -1067,15 +1067,15 @@ MxLong Infocenter::HandleNotification0(MxNotificationParam& p_param) } PlayAction(objectId); - SetROIUnknown0x0c(g_object2x4red, 0); - SetROIUnknown0x0c(g_object2x4grn, 0); + SetROIVisible(g_object2x4red, FALSE); + SetROIVisible(g_object2x4grn, FALSE); return 1; } case 6: if (m_infocenterState->GetUnknown0x74() == 8) { StopCurrentAction(); - SetROIUnknown0x0c(g_object2x4red, 0); - SetROIUnknown0x0c(g_object2x4grn, 0); + SetROIVisible(g_object2x4red, FALSE); + SetROIVisible(g_object2x4grn, FALSE); m_infocenterState->SetUnknown0x74(2); PlayAction(InfomainScript::c_iicb28in_RunAnim); return 1; diff --git a/LEGO1/lego/legoomni/src/worlds/isle.cpp b/LEGO1/lego/legoomni/src/worlds/isle.cpp index 85d87809..ce5cf365 100644 --- a/LEGO1/lego/legoomni/src/worlds/isle.cpp +++ b/LEGO1/lego/legoomni/src/worlds/isle.cpp @@ -773,11 +773,11 @@ void Isle::Enable(MxBool p_enable) FUN_10015820(FALSE, LegoOmni::c_disableInput | LegoOmni::c_disable3d | LegoOmni::c_clearScreen); } - SetROIUnknown0x0c("stretch", 0); - SetROIUnknown0x0c("bird", 0); - SetROIUnknown0x0c("rcred", 0); - SetROIUnknown0x0c("towtk", 0); - SetROIUnknown0x0c("pizpie", 0); + SetROIVisible("stretch", FALSE); + SetROIVisible("bird", FALSE); + SetROIVisible("rcred", FALSE); + SetROIVisible("towtk", FALSE); + SetROIVisible("pizpie", FALSE); } else { if (InputManager()->GetWorld() == this) { @@ -828,7 +828,7 @@ MxLong Isle::HandleTransitionEnd() switch (m_destLocation) { case LegoGameState::e_infomain: - ((LegoEntity*) Find(*g_isleScript, IsleScript::c_InfoCenter_Entity))->GetROI()->SetUnknown0x0c(1); + ((LegoEntity*) Find(*g_isleScript, IsleScript::c_InfoCenter_Entity))->GetROI()->SetVisibility(TRUE); GameState()->SwitchArea(m_destLocation); m_destLocation = LegoGameState::e_undefined; break; diff --git a/LEGO1/lego/legoomni/src/worlds/registrationbook.cpp b/LEGO1/lego/legoomni/src/worlds/registrationbook.cpp index 1f9fb1e1..3f0a6108 100644 --- a/LEGO1/lego/legoomni/src/worlds/registrationbook.cpp +++ b/LEGO1/lego/legoomni/src/worlds/registrationbook.cpp @@ -324,7 +324,7 @@ void RegistrationBook::ReadyWorld() LegoROI* infoman = FindROI(g_infoman); if (infoman != NULL) { - infoman->SetUnknown0x0c(0); + infoman->SetVisibility(FALSE); } } else { diff --git a/LEGO1/lego/sources/roi/legoroi.cpp b/LEGO1/lego/sources/roi/legoroi.cpp index 8635408b..8543a4a0 100644 --- a/LEGO1/lego/sources/roi/legoroi.cpp +++ b/LEGO1/lego/sources/roi/legoroi.cpp @@ -394,7 +394,7 @@ LegoResult LegoROI::FUN_100a8da0(LegoTreeNode* p_node, const Matrix4& p_matrix, roi->VTable0x1c(); LegoBool und = data->FUN_100a0990(p_time); - roi->SetUnknown0x0c(und); + roi->SetVisibility(und); for (LegoU32 i = 0; i < p_node->GetNumChildren(); i++) { FUN_100a8da0(p_node->GetChild(i), roi->m_local2world, p_time, roi); diff --git a/LEGO1/library_msvc.h b/LEGO1/library_msvc.h index 8ca06710..4ef49f94 100644 --- a/LEGO1/library_msvc.h +++ b/LEGO1/library_msvc.h @@ -45,6 +45,9 @@ // LIBRARY: LEGO1 0x1008b680 // _strncmp +// LIBRARY: LEGO1 0x1008b6c0 +// _atof + // LIBRARY: LEGO1 0x1008b730 // _fprintf diff --git a/LEGO1/omni/include/mxstring.h b/LEGO1/omni/include/mxstring.h index f2a5c95a..7cb486df 100644 --- a/LEGO1/omni/include/mxstring.h +++ b/LEGO1/omni/include/mxstring.h @@ -21,6 +21,7 @@ class MxString : public MxCore { inline MxS8 Compare(const MxString& p_str) const { return strcmp(m_data, p_str.m_data); } inline const char* GetData() const { return m_data; } + inline char* GetDataPtr() const { return m_data; } inline const MxU16 GetLength() const { return m_length; } // SYNTHETIC: LEGO1 0x100ae280 diff --git a/LEGO1/realtime/roi.h b/LEGO1/realtime/roi.h index 7a5ff69a..e0a9a6da 100644 --- a/LEGO1/realtime/roi.h +++ b/LEGO1/realtime/roi.h @@ -90,7 +90,7 @@ class ROI { { comp = 0; lods = 0; - m_unk0x0c = 1; + m_visible = true; } virtual ~ROI() { @@ -112,16 +112,16 @@ class ROI { int GetLODCount() const { return lods ? lods->Size() : 0; } const CompoundObject* GetComp() const { return comp; } - inline undefined GetUnknown0x0c() { return m_unk0x0c; } - inline void SetUnknown0x0c(undefined p_unk0x0c) { m_unk0x0c = p_unk0x0c; } + inline unsigned char GetVisibility() { return m_visible; } + inline void SetVisibility(unsigned char p_visible) { m_visible = p_visible; } // SYNTHETIC: LEGO1 0x100a5d60 // ROI::`scalar deleting destructor' protected: - CompoundObject* comp; // 0x04 - LODListBase* lods; // 0x08 - undefined m_unk0x0c; // 0x0c + CompoundObject* comp; // 0x04 + LODListBase* lods; // 0x08 + unsigned char m_visible; // 0x0c }; // TEMPLATE: LEGO1 0x10084930 diff --git a/LEGO1/viewmanager/viewmanager.cpp b/LEGO1/viewmanager/viewmanager.cpp index 31302284..588fb21d 100644 --- a/LEGO1/viewmanager/viewmanager.cpp +++ b/LEGO1/viewmanager/viewmanager.cpp @@ -185,7 +185,7 @@ void ViewManager::FUN_100a66a0(ViewROI* p_roi) // FUNCTION: LEGO1 0x100a66f0 inline void ViewManager::FUN_100a66f0(ViewROI* p_roi, int p_und) { - if (p_roi->GetUnknown0x0c() == FALSE && p_und != -2) { + if (!p_roi->GetVisibility() && p_und != -2) { FUN_100a66f0(p_roi, -2); } else {