Skip to content

Commit

Permalink
Fix the issue that mod can't get real custom map name
Browse files Browse the repository at this point in the history
  • Loading branch information
doyaGu committed Jul 17, 2024
1 parent 5e497a3 commit a329a41
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/BMLMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions src/BMLMod.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 16 additions & 3 deletions src/ObjectLoadHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand All @@ -136,6 +145,10 @@ int ObjectLoad(const CKBehaviorContext &behcontext) {
}
}
}

if (isMap) {
ds->Remove("CustomMapName");
}
}

// Unloading
Expand Down

0 comments on commit a329a41

Please sign in to comment.