Skip to content

Commit

Permalink
feat: pull bufferstream into a new repository
Browse files Browse the repository at this point in the history
  • Loading branch information
craftablescience committed Dec 6, 2023
1 parent d237d30 commit 5bda05e
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 166 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/thirdparty/bufferstream"]
path = src/thirdparty/bufferstream
url = https://github.com/craftablescience/BufferStream
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ set(CMAKE_CXX_STANDARD 20)

option(STUDIOMODELPP_BUILD_TESTS "Build tests for studiomodelpp" OFF)

add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/thirdparty/bufferstream")

list(APPEND ${PROJECT_NAME}_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/include/studiomodelpp/internal/BufferStream.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/studiomodelpp/internal/Helpers.h"

"${CMAKE_CURRENT_SOURCE_DIR}/include/studiomodelpp/math/Matrix.h"
Expand All @@ -18,7 +19,6 @@ list(APPEND ${PROJECT_NAME}_SOURCES

"${CMAKE_CURRENT_SOURCE_DIR}/include/studiomodelpp/studiomodelpp.h"

"${CMAKE_CURRENT_SOURCE_DIR}/src/internal/BufferStream.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/internal/Helpers.cpp"

"${CMAKE_CURRENT_SOURCE_DIR}/src/structs/MDL.cpp"
Expand All @@ -27,6 +27,9 @@ list(APPEND ${PROJECT_NAME}_SOURCES

"${CMAKE_CURRENT_SOURCE_DIR}/src/studiomodelpp.cpp")
add_library(${PROJECT_NAME} STATIC ${${PROJECT_NAME}_SOURCES})

target_link_libraries(${PROJECT_NAME} PRIVATE bufferstream)

target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")

if(STUDIOMODELPP_BUILD_TESTS)
Expand Down
98 changes: 0 additions & 98 deletions include/studiomodelpp/internal/BufferStream.h

This file was deleted.

4 changes: 2 additions & 2 deletions include/studiomodelpp/internal/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include <fstream>
#include <string>

namespace studiomodelpp::internal {

class BufferStream;

namespace studiomodelpp::internal {

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

} // namespace studiomodelpp::internal
39 changes: 0 additions & 39 deletions src/internal/BufferStream.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion src/internal/Helpers.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <studiomodelpp/internal/Helpers.h>

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

using namespace studiomodelpp;

Expand Down
26 changes: 11 additions & 15 deletions src/structs/MDL.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <studiomodelpp/structs/MDL.h>

#include <studiomodelpp/internal/BufferStream.h>
#include <BufferStream.h>
#include <studiomodelpp/internal/Helpers.h>

using namespace studiomodelpp::MDL;
Expand All @@ -22,9 +22,7 @@ bool MDL::open(const std::byte* data, std::size_t size) {
}

stream.read(this->checksum);

auto nameBytes = stream.readBytes<64>();
this->name = std::string{reinterpret_cast<const char*>(nameBytes.data())};
stream.read(this->name, 64);

// dataLength
stream.skip<int>();
Expand All @@ -44,17 +42,17 @@ bool MDL::open(const std::byte* data, std::size_t size) {
int boneControllerOffset = stream.read<int>();

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

//int animDescCount = stream.read<int>();
//int animDescOffset = stream.read<int>();
stream.skip<int, 2>();
stream.skip<int>(2);

//int sequenceDescCount = stream.read<int>();
//int sequenceDescOffset = stream.read<int>();
stream.skip<int, 2>();
stream.skip<int>(2);

stream.read(this->activityListVersion);
stream.read(this->eventsIndexed);
Expand All @@ -66,7 +64,7 @@ bool MDL::open(const std::byte* data, std::size_t size) {
int materialDirOffset = stream.read<int>();

// todo: skins
stream.skip<int, 3>();
stream.skip<int>(3);

int bodyPartCount = stream.read<int>();
int bodyPartOffset = stream.read<int>();
Expand Down Expand Up @@ -95,15 +93,15 @@ bool MDL::open(const std::byte* data, std::size_t size) {
stream.read(bone.contents);

// _unused0
stream.skip<int, 8>();
stream.skip<int>(8);
}

stream.seek(boneControllerOffset);
for (int i = 0; i < boneControllerCount; i++) {
this->boneControllers.push_back(stream.read<BoneController>());

// _unused0
stream.skip<int, 8>();
stream.skip<int>(8);
}

// todo: hitbox names are being read incorrectly causing rare crashes, disabled for now
Expand Down Expand Up @@ -163,7 +161,7 @@ bool MDL::open(const std::byte* data, std::size_t size) {
// used
stream.skip<int>();
// _unused0
stream.skip<int, 13>();
stream.skip<int>(13);
}

stream.seek(materialDirOffset);
Expand Down Expand Up @@ -191,9 +189,7 @@ bool MDL::open(const std::byte* data, std::size_t size) {

auto& model = bodyPart.models.emplace_back();

auto modelNameBytes = stream.readBytes<64>();
model.name = std::string{reinterpret_cast<const char*>(modelNameBytes.data())};

stream.read(model.name, 64);
stream.read(model.type);
stream.read(model.boundingRadius);

Expand All @@ -213,7 +209,7 @@ bool MDL::open(const std::byte* data, std::size_t size) {
stream.skip<int>();
stream.read(mesh.verticesCount);
stream.read(mesh.verticesOffset);
stream.skip<int, 2>();
stream.skip<int>(2);
stream.read(mesh.materialType);
stream.read(mesh.materialParam);
stream.read(mesh.meshID);
Expand Down
13 changes: 6 additions & 7 deletions src/structs/VTX.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include <studiomodelpp/structs/VTX.h>

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

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

bool VTX::open(const std::byte* data, std::size_t size, const MDL::MDL& mdl) {
BufferStream stream{data, size};
Expand Down Expand Up @@ -90,12 +89,12 @@ bool VTX::open(const std::byte* data, std::size_t size, const MDL::MDL& mdl) {
auto& vertex = stripGroup.vertices.emplace_back();

// todo: process bone data
stream.skip<unsigned char, 4>();
stream.skip<unsigned char>(4);

stream.read(vertex.meshVertexID);

// ditto
stream.skip<char, 3>();
stream.skip<char>(3);
}
stream.seek(stripGroupCurrentPos);

Expand All @@ -117,7 +116,7 @@ bool VTX::open(const std::byte* data, std::size_t size, const MDL::MDL& mdl) {

if (mdl.version >= 49) {
// mesh topology
stream.skip<int, 2>();
stream.skip<int>(2);
}

stream.seek(bodyPartPos + modelPos + modelLODPos + meshPos + stripGroupPos + stripOffset);
Expand All @@ -138,11 +137,11 @@ bool VTX::open(const std::byte* data, std::size_t size, const MDL::MDL& mdl) {
stream.read(strip.flags);

// todo: bone stuff
stream.skip<int, 2>();
stream.skip<int>(2);

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

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

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

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

Expand Down
1 change: 1 addition & 0 deletions src/thirdparty/bufferstream
Submodule bufferstream added at d31eee

0 comments on commit 5bda05e

Please sign in to comment.