Skip to content

Commit

Permalink
fix: temporarily disable parsing hitboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
craftablescience committed Dec 4, 2023
1 parent 90d8b1a commit a215868
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
3 changes: 2 additions & 1 deletion include/studiomodelpp/internal/Helpers.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#pragma once

#include <cstddef>
#include <fstream>
#include <string>

namespace studiomodelpp::internal {

class BufferStream;

void readStringAtOffset(BufferStream& stream, std::string& str, std::ios::seekdir offsetFrom = std::ios::cur);
void readStringAtOffset(BufferStream& stream, std::string& str, std::ios::seekdir offsetFrom = std::ios::cur, std::size_t subtractFromOffset = 0);

} // namespace studiomodelpp::internal
2 changes: 1 addition & 1 deletion include/studiomodelpp/structs/MDL.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ struct MDL {

//int hitboxCount;
//int hitboxOffset;
std::vector<HitboxSet> hitboxSets;
//std::vector<HitboxSet> hitboxSets;

//int localAnimationCount;
//int localAnimationOffset;
Expand Down
4 changes: 2 additions & 2 deletions src/internal/Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

using namespace studiomodelpp;

void internal::readStringAtOffset(BufferStream& stream, std::string& str, std::ios::seekdir offsetFrom) {
void internal::readStringAtOffset(BufferStream& stream, std::string& str, std::ios::seekdir offsetFrom, std::size_t subtractFromOffset) {
int offset = stream.read<int>();
auto pos = stream.tell();
stream.seek(offset, offsetFrom);
stream.seek(offset - subtractFromOffset, offsetFrom);
stream.read(str);
stream.seek(pos);
}
23 changes: 13 additions & 10 deletions src/structs/MDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ bool MDL::open(const std::byte* data, std::size_t size) {
int boneControllerCount = stream.read<int>();
int boneControllerOffset = stream.read<int>();

int hitboxSetCount = stream.read<int>();
int hitboxSetOffset = stream.read<int>();
// todo: hitboxes
stream.skip<int, 2>();
//int hitboxSetCount = stream.read<int>();
//int hitboxSetOffset = stream.read<int>();

//int animDescCount = stream.read<int>();
//int animDescOffset = stream.read<int>();
Expand Down Expand Up @@ -104,6 +106,8 @@ bool MDL::open(const std::byte* data, std::size_t size) {
stream.skip<int, 8>();
}

// todo: hitbox names are being read incorrectly causing rare crashes, disabled for now
/*
for (int i = 0; i < hitboxSetCount; i++) {
auto hitboxSetPos = hitboxSetOffset + i * (sizeof(int) * 3);
stream.seek(hitboxSetPos);
Expand All @@ -124,12 +128,16 @@ bool MDL::open(const std::byte* data, std::size_t size) {
stream.read(hitbox.group);
stream.read(hitbox.bboxMin);
stream.read(hitbox.bboxMax);
readStringAtOffset(stream, hitbox.name);
// Needs to be read from the base of the data structure
// !!! this is wrong !!!
//readStringAtOffset(stream, hitbox.name, std::ios::cur, sizeof(int) * 2 + sizeof(Vector3) * 2);
// _unused0
stream.skip<int, 8>();
}
}
*/

/*
stream.seek(animDescOffset);
Expand All @@ -147,13 +155,8 @@ bool MDL::open(const std::byte* data, std::size_t size) {
for (int i = 0; i < materialCount; i++) {
auto& material = this->materials.emplace_back();

// regular readStringAtOffset cuts off 4 characters in the beginning
// why??? who the hell knows
int materialNameOffset = stream.read<int>();
auto pos = stream.tell();
stream.seek(materialNameOffset - 4, std::ios::cur);
stream.read(material.name);
stream.seek(pos);
// Needs to be read from the base of the data structure
readStringAtOffset(stream, material.name, std::ios::cur, sizeof(int));

stream.read(material.flags);

Expand Down

0 comments on commit a215868

Please sign in to comment.