Skip to content

Commit

Permalink
feat: add some more flags
Browse files Browse the repository at this point in the history
  • Loading branch information
craftablescience committed Dec 3, 2023
1 parent c4478d9 commit 10e1acc
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 14 deletions.
12 changes: 9 additions & 3 deletions include/studiomodelpp/structs/MDL.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ struct HitboxSet {
/*
struct AnimDesc {
enum Flags : int {
FLAG_NONE = 0,
// todo(flags): AnimDesc
FLAG_NONE = 0,
FLAG_RAW_POS = 1 << 0,
FLAG_RAW_ROT = 1 << 1,
FLAG_ANIM_POS = 1 << 2,
FLAG_ANIM_ROT = 1 << 3,
FLAG_DELTA = 1 << 4,
FLAG_RAW_ROT2 = 1 << 5,
};
//int basePointer;
Expand Down Expand Up @@ -109,7 +114,7 @@ struct AnimDesc {
struct SequenceDesc {
enum Flags : int {
FLAG_NONE = 0,
// todo(flags): SequenceDesc
FLAG_LOOPING = 1 << 0,
};
//int basePointer;
Expand Down Expand Up @@ -272,6 +277,7 @@ struct MDL {
FLAG_CAST_TEXTURE_SHADOWS = 1 << 18,
FLAG_SUBDIVISION_SURFACE = 1 << 19,
FLAG_VERT_ANIM_FIXED_POINT_SCALE = 1 << 21,
FLAG_EXTRA_VERTEX_DATA = 1 << 26,
};

//int id;
Expand Down
8 changes: 7 additions & 1 deletion include/studiomodelpp/structs/VTX.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

#include "../math/Vector.h"

namespace studiomodelpp::MDL {

class MDL;

} // namespace studiomodelpp::MDL

namespace studiomodelpp::VTX {

struct Vertex {
Expand Down Expand Up @@ -105,7 +111,7 @@ struct BodyPart {
};

struct VTX {
[[nodiscard]] bool open(const std::byte* data, std::size_t size, int mdlVersion, int mdlChecksum);
[[nodiscard]] bool open(const std::byte* data, std::size_t size, const MDL::MDL& mdl);

int version;
int vertexCacheSize;
Expand Down
8 changes: 7 additions & 1 deletion include/studiomodelpp/structs/VVD.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
#include "../math/Vector.h"
#include "Generic.h"

namespace studiomodelpp::MDL {

class MDL;

} // namespace studiomodelpp::MDL

namespace studiomodelpp::VVD {

struct Fixup {
Expand Down Expand Up @@ -36,7 +42,7 @@ struct Vertex {
};

struct VVD {
[[nodiscard]] bool open(const std::byte* data, std::size_t size, int mdlVersion, int mdlChecksum);
[[nodiscard]] bool open(const std::byte* data, std::size_t size, const MDL::MDL& mdl);

//int id;
int version;
Expand Down
11 changes: 6 additions & 5 deletions src/structs/VTX.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <studiomodelpp/structs/VTX.h>

#include <studiomodelpp/internal/BufferStream.h>
#include <studiomodelpp/structs/MDL.h>

using namespace studiomodelpp::VTX;
using namespace studiomodelpp::internal;

bool VTX::open(const std::byte* data, std::size_t size, int mdlVersion, int mdlChecksum) {
bool VTX::open(const std::byte* data, std::size_t size, const MDL::MDL& mdl) {
BufferStream stream{data, size};

stream.read(this->version);
Expand All @@ -15,7 +16,7 @@ bool VTX::open(const std::byte* data, std::size_t size, int mdlVersion, int mdlC
stream.read(this->maxBonesPerVertex);

int checksum = stream.read<int>();
if (checksum != mdlChecksum) {
if (checksum != mdl.checksum) {
return false;
}

Expand Down Expand Up @@ -69,7 +70,7 @@ bool VTX::open(const std::byte* data, std::size_t size, int mdlVersion, int mdlC

for (int m = 0; m < stripGroupCount; m++) {
int stripGroupNumInts = 6;
if (mdlVersion >= 49) {
if (mdl.version >= 49) {
stripGroupNumInts += 2;
}
auto stripGroupPos = stripGroupOffset + m * (sizeof(int) * stripGroupNumInts + sizeof(StripGroup::Flags));
Expand Down Expand Up @@ -111,7 +112,7 @@ bool VTX::open(const std::byte* data, std::size_t size, int mdlVersion, int mdlC

stream.read(stripGroup.flags);

if (mdlVersion >= 49) {
if (mdl.version >= 49) {
// mesh topology
stream.skip<int, 2>();
}
Expand All @@ -136,7 +137,7 @@ bool VTX::open(const std::byte* data, std::size_t size, int mdlVersion, int mdlC
// todo: bone stuff
stream.skip<int, 2>();

if (mdlVersion >= 49) {
if (mdl.version >= 49) {
// mesh topology
stream.skip<int, 2>();
}
Expand Down
5 changes: 3 additions & 2 deletions src/structs/VVD.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include <studiomodelpp/structs/VVD.h>

#include <studiomodelpp/internal/BufferStream.h>
#include <studiomodelpp/structs/MDL.h>

using namespace studiomodelpp::VVD;
using namespace studiomodelpp::internal;

constexpr int VVD_ID = 'I' + ('D' << 8) + ('S' << 16) + ('V' << 24);

bool VVD::open(const std::byte* data, std::size_t size, int /*mdlVersion*/, int mdlChecksum) {
bool VVD::open(const std::byte* data, std::size_t size, const MDL::MDL& mdl) {
BufferStream stream{data, size};

int id = stream.read<int>();
Expand All @@ -18,7 +19,7 @@ bool VVD::open(const std::byte* data, std::size_t size, int /*mdlVersion*/, int
stream.read(this->version);

int checksum = stream.read<int>();
if (checksum != mdlChecksum) {
if (checksum != mdl.checksum) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/studiomodelpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ bool StudioModel::open(const std::byte* mdlData, std::size_t mdlSize,
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)) {
!this->vtx.open(vtxData, vtxSize, this->mdl)) ||
!this->vvd.open(vvdData, vvdSize, this->mdl)) {
return false;
}
this->opened = true;
Expand Down

0 comments on commit 10e1acc

Please sign in to comment.