From ba3b4c33a0cf82c0ac0a83e0af6620ce5c6417fc Mon Sep 17 00:00:00 2001 From: craftablescience Date: Thu, 18 Jul 2024 01:53:18 -0400 Subject: [PATCH] feat(bsppp): add getter/setter for lump versions --- include/bsppp/bsppp.h | 4 ++++ src/bsppp/bsppp.cpp | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/bsppp/bsppp.h b/include/bsppp/bsppp.h index 1cc088fb5..9b4e83021 100644 --- a/include/bsppp/bsppp.h +++ b/include/bsppp/bsppp.h @@ -139,6 +139,10 @@ class BSP { [[nodiscard]] bool hasLump(BSPLump lumpIndex) const; + [[nodiscard]] int32_t getLumpVersion(BSPLump lumpIndex) const; + + void setLumpVersion(BSPLump lumpIndex, int32_t version); + [[nodiscard]] std::optional> readLump(BSPLump lumpIndex) const; void writeLump(BSPLump lumpIndex, const std::vector& data); diff --git a/src/bsppp/bsppp.cpp b/src/bsppp/bsppp.cpp index 3be2edc38..a233d8d98 100644 --- a/src/bsppp/bsppp.cpp +++ b/src/bsppp/bsppp.cpp @@ -94,6 +94,18 @@ bool BSP::hasLump(BSPLump lumpIndex) const { return this->header.lumps[lump].length != 0 && this->header.lumps[lump].offset != 0; } +int32_t BSP::getLumpVersion(BSPLump lumpIndex) const { + if (this->path.empty()) { + return 0; + } + return this->header.lumps[static_cast(lumpIndex)].version; +} + +void BSP::setLumpVersion(BSPLump lumpIndex, int32_t version) { + this->header.lumps[static_cast(lumpIndex)].version = version; + this->writeHeader(); +} + std::optional> BSP::readLump(BSPLump lump) const { if (this->path.empty() || !this->hasLump(lump)) { return std::nullopt;