Skip to content

Commit

Permalink
chore: clean up existing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
craftablescience committed Dec 3, 2023
1 parent 83566f8 commit e0c266b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
31 changes: 17 additions & 14 deletions include/studiomodelpp/studiomodelpp.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include <optional>
#include <string_view>
#include <vector>

#include "structs/MDL.h"
Expand All @@ -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<std::byte>& mdlData,
const std::vector<std::byte>& vtxData,
const std::vector<std::byte>& vvdData);
[[nodiscard]] bool open(const std::vector<std::byte>& mdlData,
const std::vector<std::byte>& vtxData,
const std::vector<std::byte>& vvdData);

bool open(const std::vector<unsigned char>& mdlData,
const std::vector<unsigned char>& vtxData,
const std::vector<unsigned char>& vvdData);
[[nodiscard]] bool open(const std::vector<unsigned char>& mdlData,
const std::vector<unsigned char>& vtxData,
const std::vector<unsigned char>& vvdData);

[[nodiscard]] explicit operator bool() const;

MDL::MDL mdl;
VTX::VTX vtx;
VVD::VVD vvd;

private:
bool opened = false;
};

} // namespace studiomodelpp
4 changes: 4 additions & 0 deletions src/structs/MDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down
7 changes: 6 additions & 1 deletion src/studiomodelpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ 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) ||
!this->vtx.open(vtxData, vtxSize, this->mdl.version, this->mdl.checksum)) ||
!this->vvd.open(vvdData, vvdSize, this->mdl.version, this->mdl.checksum)) {
return false;
}
this->opened = true;
return true;
}

Expand All @@ -39,3 +40,7 @@ bool StudioModel::open(const std::vector<unsigned char>& mdlData,
vtxData.data(), vtxData.size(),
vvdData.data(), vvdData.size());
}

StudioModel::operator bool() const {
return this->opened;
}

0 comments on commit e0c266b

Please sign in to comment.