Skip to content

Commit 5d0910d

Browse files
committed
fix maps with no rooms crashing on room add
1 parent a1fe77c commit 5d0910d

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

include/DOM/MapDOMNode.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class LRoomDOMNode;
1616
// DOM node representing an entire map, including rooms and objects.
1717
class LMapDOMNode : public LDOMNodeBase
1818
{
19+
uint32_t mMapNum;
1920
std::shared_ptr<Archive::Rarc> mMapArchive;
2021
LJmpIO JmpIOManagers[LEntityType_Max];
2122
LStaticMapDataIO mStaticMapIO;
@@ -42,6 +43,7 @@ class LMapDOMNode : public LDOMNodeBase
4243
std::shared_ptr<LRoomDOMNode> GetRoomByIndex(int32_t index);
4344
std::weak_ptr<Archive::Rarc> GetArchive() { return mMapArchive; };
4445
void SetArchive(std::shared_ptr<Archive::Rarc> arc) { mMapArchive = arc; };
46+
uint32_t GetMapNumber() { return mMapNum; }
4547

4648
/*=== Type operations ===*/
4749
// Returns whether this node is of the given type, or derives from a node of that type.

src/DOM/MapDOMNode.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ bool LMapDOMNode::LoadMap(std::filesystem::path file_path)
7070

7171
mMapArchive = Archive::Rarc::Create();
7272

73+
char mapname[5];
74+
std::sscanf(file_path.string().c_str(), "%3s%d", &mapname[0], &mMapNum);
75+
7376
// Make sure file path is valid
7477
if (!std::filesystem::exists(file_path))
7578
{
@@ -113,10 +116,10 @@ bool LMapDOMNode::LoadMap(std::filesystem::path file_path)
113116
std::string eventName = archive.path().stem().string();
114117
std::string csvName = eventName;
115118

116-
char* eventNm[5];
119+
char eventNm[5];
117120
int eventNo = 0;
118121

119-
std::sscanf(eventName.c_str(), "%5s%3d", &eventNm, &eventNo);
122+
std::sscanf(eventName.c_str(), "%5s%3d", &eventNm[0], &eventNo);
120123
csvName = std::format("message{}", eventNo);
121124
std::shared_ptr<LEventDataDOMNode> eventData = std::make_shared<LEventDataDOMNode>(eventName);
122125

@@ -155,6 +158,19 @@ bool LMapDOMNode::LoadMap(std::filesystem::path file_path)
155158
}
156159
}
157160

161+
// Load Collision
162+
LGenUtility::Log << "[MapDOMNode] Loading Map Collision" << std::endl;
163+
std::shared_ptr<LMapCollisionDOMNode> collision = std::make_shared<LMapCollisionDOMNode>("Collision");
164+
165+
std::shared_ptr<Archive::File> collisionFile = mMapArchive->GetFile("col.mp");
166+
167+
if (collisionFile != nullptr)
168+
{
169+
bStream::CMemoryStream collisionMemStream(collisionFile->GetData(), collisionFile->GetSize(), bStream::Endianess::Big, bStream::OpenMode::In);
170+
collision->Load(&collisionMemStream);
171+
AddChild(collision);
172+
}
173+
158174
if (!ReadStaticData(roomsMap))
159175
{
160176
LGenUtility::Log << std::format("[MapDOMNode]: Failed to open static data from {0}", roomsMap.string()) << std::endl;
@@ -208,18 +224,6 @@ bool LMapDOMNode::LoadMap(std::filesystem::path file_path)
208224
LoadStaticData(rooms);
209225

210226

211-
// Load Collision
212-
LGenUtility::Log << "[MapDOMNode] Loading Map Collision" << std::endl;
213-
std::shared_ptr<LMapCollisionDOMNode> collision = std::make_shared<LMapCollisionDOMNode>("Collision");
214-
215-
std::shared_ptr<Archive::File> collisionFile = mMapArchive->GetFile("col.mp");
216-
217-
if (collisionFile != nullptr)
218-
{
219-
bStream::CMemoryStream collisionMemStream(collisionFile->GetData(), collisionFile->GetSize(), bStream::Endianess::Big, bStream::OpenMode::In);
220-
collision->Load(&collisionMemStream);
221-
AddChild(collision);
222-
}
223227

224228
LGenUtility::Log << "[MapDOMNode] Loading JMP Files" << std::endl;
225229

src/modes/ActorMode.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ void LActorMode::RenderSceneHierarchy(std::shared_ptr<LMapDOMNode> current_map,
6868
std::shared_ptr<LRoomDOMNode> newRoom = std::make_shared<LRoomDOMNode>(std::format("Room {}", rooms.size() + 1));
6969
std::shared_ptr<LRoomDataDOMNode> newRoomData = std::make_shared<LRoomDataDOMNode>(std::format("Room {}", rooms.size() + 1));
7070

71-
std::string resourcePathRoot = std::filesystem::path(rooms[0]->GetChildrenOfType<LRoomDataDOMNode>(EDOMNodeType::RoomData)[0]->GetResourcePath()).parent_path().string();
71+
std::string resourcePathRoot = "";
72+
if(rooms.size() == 0){
73+
resourcePathRoot = std::filesystem::path("Iwamoto") / std::format("map{}", current_map->GetMapNumber());
74+
} else {
75+
resourcePathRoot = std::filesystem::path(rooms[0]->GetChildrenOfType<LRoomDataDOMNode>(EDOMNodeType::RoomData)[0]->GetResourcePath()).parent_path().string();
76+
}
7277

7378
newRoomData->SetRoomResourcePath(std::format("{}/room_{:02}.arc", resourcePathRoot, rooms.size() + 1));
7479

0 commit comments

Comments
 (0)