From e0c266b28d88bd9db9c4d6263617a5e955c15174 Mon Sep 17 00:00:00 2001 From: craftablescience Date: Sun, 3 Dec 2023 03:44:50 -0500 Subject: [PATCH] chore: clean up existing stuff --- include/studiomodelpp/studiomodelpp.h | 31 +++++++++++++++------------ src/structs/MDL.cpp | 4 ++++ src/studiomodelpp.cpp | 7 +++++- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/include/studiomodelpp/studiomodelpp.h b/include/studiomodelpp/studiomodelpp.h index a78828dad..ab34743c2 100644 --- a/include/studiomodelpp/studiomodelpp.h +++ b/include/studiomodelpp/studiomodelpp.h @@ -1,7 +1,5 @@ #pragma once -#include -#include #include #include "structs/MDL.h" @@ -11,25 +9,30 @@ namespace studiomodelpp { struct StudioModel { - bool open(const std::byte* mdlData, std::size_t mdlSize, - const std::byte* vtxData, std::size_t vtxSize, - const std::byte* vvdData, std::size_t vvdSize); + [[nodiscard]] bool open(const std::byte* mdlData, std::size_t mdlSize, + const std::byte* vtxData, std::size_t vtxSize, + const std::byte* vvdData, std::size_t vvdSize); - bool open(const unsigned char* mdlData, std::size_t mdlSize, - const unsigned char* vtxData, std::size_t vtxSize, - const unsigned char* vvdData, std::size_t vvdSize); + [[nodiscard]] bool open(const unsigned char* mdlData, std::size_t mdlSize, + const unsigned char* vtxData, std::size_t vtxSize, + const unsigned char* vvdData, std::size_t vvdSize); - bool open(const std::vector& mdlData, - const std::vector& vtxData, - const std::vector& vvdData); + [[nodiscard]] bool open(const std::vector& mdlData, + const std::vector& vtxData, + const std::vector& vvdData); - bool open(const std::vector& mdlData, - const std::vector& vtxData, - const std::vector& vvdData); + [[nodiscard]] bool open(const std::vector& mdlData, + const std::vector& vtxData, + const std::vector& vvdData); + + [[nodiscard]] explicit operator bool() const; MDL::MDL mdl; VTX::VTX vtx; VVD::VVD vvd; + +private: + bool opened = false; }; } // namespace studiomodelpp diff --git a/src/structs/MDL.cpp b/src/structs/MDL.cpp index 86da09ade..493320559 100644 --- a/src/structs/MDL.cpp +++ b/src/structs/MDL.cpp @@ -17,6 +17,10 @@ bool MDL::open(const std::byte* data, std::size_t size) { } stream.read(this->version); + if (this->version < 44 || this->version > 49) { + return false; + } + stream.read(this->checksum); auto nameBytes = stream.readBytes<64>(); diff --git a/src/studiomodelpp.cpp b/src/studiomodelpp.cpp index ffabf9eed..041e00369 100644 --- a/src/studiomodelpp.cpp +++ b/src/studiomodelpp.cpp @@ -5,7 +5,7 @@ using namespace studiomodelpp; bool StudioModel::open(const std::byte* mdlData, std::size_t mdlSize, const std::byte* vtxData, std::size_t vtxSize, const std::byte* vvdData, std::size_t vvdSize) { - if (!mdlData || !vtxData || !vvdData || !mdlSize || !vtxSize || !vvdSize) { + if (this->opened || !mdlData || !vtxData || !vvdData || !mdlSize || !vtxSize || !vvdSize) { return false; } if ((!this->mdl.open(mdlData, mdlSize) || @@ -13,6 +13,7 @@ bool StudioModel::open(const std::byte* mdlData, std::size_t mdlSize, !this->vvd.open(vvdData, vvdSize, this->mdl.version, this->mdl.checksum)) { return false; } + this->opened = true; return true; } @@ -39,3 +40,7 @@ bool StudioModel::open(const std::vector& mdlData, vtxData.data(), vtxData.size(), vvdData.data(), vvdData.size()); } + +StudioModel::operator bool() const { + return this->opened; +}