From bc7c1a040ab092a72b587f08f13e5d25d35dc4b2 Mon Sep 17 00:00:00 2001 From: RektInator Date: Tue, 7 Jan 2020 16:47:50 +0100 Subject: [PATCH] Fix entity parsing --- src/IW4/Assets/AddonMapEnts.cpp | 7 +++---- src/IW4/Assets/ClipMap.cpp | 4 ++-- src/IW4/Assets/MapEnts.cpp | 13 +++++-------- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/IW4/Assets/AddonMapEnts.cpp b/src/IW4/Assets/AddonMapEnts.cpp index d79a50d..6e3e39e 100644 --- a/src/IW4/Assets/AddonMapEnts.cpp +++ b/src/IW4/Assets/AddonMapEnts.cpp @@ -30,12 +30,11 @@ namespace ZoneTool auto ents = mem->Alloc(); ents->name = mem->StrDup(name); - ents->numEntityChars = FileSystem::FileSize(file); + ents->numEntityChars = FileSystem::FileSize(file) + 1; - ents->entityString = mem->Alloc(ents->numEntityChars + 1); + ents->entityString = mem->Alloc(ents->numEntityChars); memset((char*)ents->entityString, 0, ents->numEntityChars); - fread((char*)ents->entityString, ents->numEntityChars, 1, file); - ents->numEntityChars++; + fread((char*)ents->entityString, ents->numEntityChars - 1, 1, file); // convert the mapents! IMapEnts::ConvertEnts(reinterpret_cast(ents), mem); diff --git a/src/IW4/Assets/ClipMap.cpp b/src/IW4/Assets/ClipMap.cpp index d52ded1..b9cbd65 100644 --- a/src/IW4/Assets/ClipMap.cpp +++ b/src/IW4/Assets/ClipMap.cpp @@ -109,7 +109,7 @@ namespace ZoneTool void IClipMap::init(const std::string& name, ZoneMemory* mem) { - this->name_ = "maps/"s + (currentzone.substr(0, 3) == "mp_" ? "mp/" : "") + ".d3dbsp"; // name; + this->name_ = "maps/"s + (currentzone.substr(0, 3) == "mp_" ? "mp/" : "") + currentzone + ".d3dbsp"; // name; this->asset_ = this->parse(name, mem); this->m_filename = name; @@ -197,7 +197,7 @@ namespace ZoneTool std::int32_t IClipMap::type() { - return col_map_mp; + return col_map_sp; } void IClipMap::write(IZone* zone, ZoneBuffer* buf) diff --git a/src/IW4/Assets/MapEnts.cpp b/src/IW4/Assets/MapEnts.cpp index f6b7a4a..b901d40 100644 --- a/src/IW4/Assets/MapEnts.cpp +++ b/src/IW4/Assets/MapEnts.cpp @@ -191,14 +191,11 @@ namespace ZoneTool // replace mapents if needed if (!newEntsString.empty()) { - ents->numEntityChars = newEntsString.size(); - ents->entityString = mem->Alloc(ents->numEntityChars + 1); - memcpy((void*)ents->entityString, &newEntsString[0], ents->numEntityChars); + ents->numEntityChars = newEntsString.size() + 1; + ents->entityString = mem->Alloc(ents->numEntityChars); + memset((void*)ents->entityString, 0, ents->numEntityChars); + memcpy((void*)ents->entityString, &newEntsString[0], ents->numEntityChars - 1); } - - //auto fp_ = fopen("output.d3dbsp.ents", "wb"); - //fwrite(ents->entityString, ents->numEntityChars, 1, fp_); - //fclose(fp_); } /*legacy zonetool code, refactor me!*/ @@ -281,7 +278,7 @@ namespace ZoneTool void IMapEnts::init(const std::string& name, ZoneMemory* mem) { - this->name_ = "maps/mp/" + currentzone + ".d3dbsp"; // name; + this->name_ = "maps/"s + (currentzone.substr(0, 3) == "mp_" ? "mp/" : "") + currentzone + ".d3dbsp"; // name; this->asset_ = this->parse(name, mem); if (!this->asset_)