Skip to content

Commit

Permalink
feat: parse hitboxes (correctly this time x2)
Browse files Browse the repository at this point in the history
  • Loading branch information
craftablescience committed Apr 9, 2024
1 parent 7784ccf commit 72cdb01
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/sourcepp/detail/BufferUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

void sourcepp::detail::readStringAtOffset(BufferStream& stream, std::string& str, std::ios::seekdir offsetFrom, std::size_t subtractFromOffset) {
int offset = stream.read<int>();
if (offset == 0) {
str = "";
return;
}

auto pos = stream.tell();
stream.seek(offset - subtractFromOffset, offsetFrom);
stream.read(str);
Expand Down
6 changes: 5 additions & 1 deletion src/studiomodelpp/structs/MDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ 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, std::ios::cur, sizeof(int) * 4 + sizeof(Vector3) * 2);

// note: we don't know what model versions use absolute vs. relative offsets here
// and this is unimportant, so skip parsing the bbox name here
//readStringAtOffset(stream, hitbox.name, std::ios::cur, sizeof(int) * 3 + sizeof(Vector3) * 2);
hitbox.name = "";

// _unused0
stream.skip<int>(8);
Expand Down
2 changes: 1 addition & 1 deletion src/thirdparty/bufferstream

0 comments on commit 72cdb01

Please sign in to comment.