From f2e90ec4c2ef8f6d2ded8c1666099334d659e518 Mon Sep 17 00:00:00 2001 From: AdrienTD Date: Wed, 6 Apr 2022 00:21:56 +0200 Subject: [PATCH] View Life sector, view Squad markers, Empty node DFF import crash fix --- CKGroup.cpp | 10 ++++++---- CKGroup.h | 4 ++-- EditorInterface.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/CKGroup.cpp b/CKGroup.cpp index b22fbdc..a8342fc 100644 --- a/CKGroup.cpp +++ b/CKGroup.cpp @@ -143,8 +143,9 @@ void CKGrpSquad::deserialize(KEnvironment * kenv, File * file, size_t length) for (auto &ref : refs) ref = kenv->readObjRef(file); for (auto arr : { &sqUnk3, &sqUnk4 }) - for (float &f : *arr) - f = file->readFloat(); + for (Vector3& v : *arr) + for (float& f : v) + f = file->readFloat(); sqUnk5 = file->readUint32(); uint32_t numChoreographies = file->readUint32(); choreographies.resize(numChoreographies); @@ -198,8 +199,9 @@ void CKGrpSquad::serialize(KEnvironment * kenv, File * file) for (auto &ref : refs) kenv->writeObjRef(file, ref); for (auto arr : { &sqUnk3, &sqUnk4 }) - for (float &f : *arr) - file->writeFloat(f); + for (Vector3& v : *arr) + for (float& f : v) + file->writeFloat(f); file->writeUint32(sqUnk5); file->writeUint32(choreographies.size()); for (auto &ref : choreographies) diff --git a/CKGroup.h b/CKGroup.h index 99e3eb3..af25d1d 100644 --- a/CKGroup.h +++ b/CKGroup.h @@ -63,14 +63,14 @@ struct CKGrpSquad : CKSubclass { float sqUnk1; Vector3 sqUnk2; std::array, 4> refs; - std::array sqUnk3, sqUnk4; + std::array sqUnk3, sqUnk4; uint32_t sqUnk5; //uint32_t numChoreographies; std::vector> choreographies; //uint32_t numChoreoKeys; std::vector> choreoKeys; struct Bing { - uint32_t markerIndex; uint8_t b; + uint32_t markerIndex = 0; uint8_t b = 0; }; std::vector guardMarkers, spawnMarkers; std::vector fings; // seems to be always empty diff --git a/EditorInterface.cpp b/EditorInterface.cpp index e5efa24..cd34815 100644 --- a/EditorInterface.cpp +++ b/EditorInterface.cpp @@ -1229,8 +1229,8 @@ void EditorInterface::render() CKGrpSquadEnemy* squad = osquad->cast(); if (showSquadBoxes) { for (const auto& bb : { squad->sqUnk3, squad->sqUnk4 }) { - Vector3 v1(bb[0], bb[1], bb[2]); - Vector3 v2(bb[3], bb[4], bb[5]); + const Vector3& v1 = bb[0]; + const Vector3& v2 = bb[1]; drawBox(v1 - v2 * 0.5f, v1 + v2 * 0.5f); } } @@ -2600,7 +2600,7 @@ void EditorInterface::IGSceneNodeProperties() // Remove current geometry // TODO: Proper handling of duplicate geometries CKAnyGeometry *kgeo = geonode->geometry.get(); - CKObject* lightSetBackup = kgeo->lightSet.get(); + CKObject* lightSetBackup = kgeo ? kgeo->lightSet.get() : nullptr; geonode->geometry.reset(); while (kgeo) { if (CMaterial* mat = kgeo->material.get()) { @@ -3252,9 +3252,35 @@ void EditorInterface::IGSquadEditor() } ImGui::EndTabItem(); } + if (ImGui::BeginTabItem("Markers")) { + for (auto [name, list] : { std::make_pair("Spawning points", &squad->spawnMarkers), std::make_pair("Guard points",&squad->guardMarkers) }) { + ImGui::PushID(name); + if (ImGui::CollapsingHeader(name, ImGuiTreeNodeFlags_DefaultOpen)) { + if (ImGui::Button("Add")) { + list->emplace_back(); + } + ImGui::SameLine(); + if (ImGui::Button("Clear")) { + list->clear(); + } + for (auto& pnt : *list) { + ImGui::Separator(); + ImGui::PushID(&pnt); + ImGui::InputScalar("Marker Index", ImGuiDataType_U32, &pnt.markerIndex); + ImGui::InputScalar("Byte", ImGuiDataType_U8, &pnt.b); + // TODO: Modify marker properties directly here + ImGui::PopID(); + } + } + ImGui::PopID(); + } + ImGui::EndTabItem(); + } if (ImGui::BeginTabItem("MsgAction")) { ImGui::BeginChild("MsgActionWnd"); CKMsgAction *msgAction = squad->msgAction->cast(); + if (ImGui::Button("Clear")) + msgAction->mas1.clear(); for (auto &a : msgAction->mas1) { if (ImGui::TreeNodeEx(&a, ImGuiTreeNodeFlags_DefaultOpen, "%i", a.mas2.size())) { for (auto &b : a.mas2) { @@ -3709,6 +3735,21 @@ void EditorInterface::IGHookEditor() ImGui::EndDragDropSource(); } ImGui::Separator(); + if (selectedHook->life) { + // NOTE: Currently modifying life sector is dangerous + // (e.g. makes PostRef decoding fail since it relies on the + // life sectors) + ImGui::LabelText("Life value", "%08X", selectedHook->life->unk1); + int lifeSector = selectedHook->life->unk1 >> 2; + int lifeFlags = selectedHook->life->unk1 & 3; + bool lifeChanged = false; + lifeChanged |= ImGui::InputInt("Life sector", &lifeSector); + lifeChanged |= ImGui::InputInt("Life flags", &lifeFlags); + if (lifeChanged) { + selectedHook->life->unk1 = (lifeFlags & 3) | (lifeSector << 2); + } + ImGui::Separator(); + } ImGuiMemberListener ml(kenv, *this); selectedHook->virtualReflectMembers(ml, &kenv); }