From a329a41b9d5d3daac6e789e65e73494583da1278 Mon Sep 17 00:00:00 2001 From: doyaGu Date: Wed, 17 Jul 2024 20:28:58 +0800 Subject: [PATCH] Fix the issue that mod can't get real custom map name --- src/BMLMod.cpp | 4 ++++ src/BMLMod.h | 2 ++ src/ObjectLoadHook.cpp | 19 ++++++++++++++++--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/BMLMod.cpp b/src/BMLMod.cpp index 6e24020..d543082 100644 --- a/src/BMLMod.cpp +++ b/src/BMLMod.cpp @@ -526,6 +526,7 @@ bool MapListPage::OnDrawEntry(std::size_t index, bool *v) { } void BMLMod::OnLoad() { + m_DataShare = m_BML->GetDataShare(); m_CKContext = m_BML->GetCKContext(); m_RenderContext = m_BML->GetRenderContext(); m_TimeManager = m_BML->GetTimeManager(); @@ -764,6 +765,9 @@ void BMLMod::LoadMap(const std::wstring &path) { level--; SetParamValue(m_LevelRow, level); + std::string mapPath = utils::Utf16ToUtf8(path); + m_DataShare->Set("CustomMapName", mapPath.c_str(), mapPath.size() + 1); + CKMessageManager *mm = m_CKContext->GetMessageManager(); CKMessageType loadLevel = mm->AddMessageType((CKSTRING) "Load Level"); CKMessageType loadMenu = mm->AddMessageType((CKSTRING) "Menu_Load"); diff --git a/src/BMLMod.h b/src/BMLMod.h index 778bb97..bb0c8c2 100644 --- a/src/BMLMod.h +++ b/src/BMLMod.h @@ -218,6 +218,8 @@ class BMLMod : public IMod { void OnOpenMapMenu(); void OnCloseMapMenu(bool backToMenu = true); + BML::IDataShare *m_DataShare = nullptr; + CKContext *m_CKContext = nullptr; CKRenderContext *m_RenderContext = nullptr; CKTimeManager *m_TimeManager = nullptr; diff --git a/src/ObjectLoadHook.cpp b/src/ObjectLoadHook.cpp index de8ad66..b280593 100644 --- a/src/ObjectLoadHook.cpp +++ b/src/ObjectLoadHook.cpp @@ -21,12 +21,12 @@ int ObjectLoad(const CKBehaviorContext &behcontext) { if (ctx->GetCurrentLevel()->GetLevelScene() == scene) addtoscene = FALSE; - CKSTRING fname = (CKSTRING) beh->GetInputParameterReadDataPtr(0); - CKSTRING mastername = (CKSTRING) beh->GetInputParameterReadDataPtr(1); + auto fname = (const char *) beh->GetInputParameterReadDataPtr(0); + auto mastername = (const char *) beh->GetInputParameterReadDataPtr(1); CK_CLASSID cid = CKCID_3DOBJECT; beh->GetInputParameterValue(2, &cid); - CK_LOAD_FLAGS loadoptions = CK_LOAD_FLAGS(CK_LOAD_DEFAULT | CK_LOAD_AUTOMATICMODE); + auto loadoptions = (CK_LOAD_FLAGS) (CK_LOAD_DEFAULT | CK_LOAD_AUTOMATICMODE); if (dynamic) loadoptions = (CK_LOAD_FLAGS) (loadoptions | CK_LOAD_AS_DYNAMIC_OBJECT); @@ -121,6 +121,15 @@ int ObjectLoad(const CKBehaviorContext &behcontext) { CKBOOL isMap = strcmp(beh->GetOwnerScript()->GetName(), "Levelinit_build") == 0; + auto ds = BML_GetModManager()->GetDataShare(nullptr); + + if (isMap) { + auto mapName = (const char *) ds->Get("CustomMapName", nullptr); + if (mapName) { + fname = mapName; + } + } + BML_GetModManager()->BroadcastCallback(&IMod::OnLoadObject, fname, isMap, mastername, cid, addtoscene, reuseMeshes, @@ -136,6 +145,10 @@ int ObjectLoad(const CKBehaviorContext &behcontext) { } } } + + if (isMap) { + ds->Remove("CustomMapName"); + } } // Unloading