Skip to content

Commit

Permalink
chore(ext): bump bufferstream yet again
Browse files Browse the repository at this point in the history
  • Loading branch information
craftablescience committed Nov 11, 2024
1 parent 72c60ed commit 7c31df9
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 27 deletions.
2 changes: 1 addition & 1 deletion ext/bufferstream
5 changes: 2 additions & 3 deletions include/sourcepp/parser/Binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
#include <string>
#include <string_view>

#include <BufferStream.h>
#include <sourcepp/Math.h>

class BufferStream;

namespace sourcepp::parser::binary {

/**
Expand All @@ -28,6 +27,6 @@ consteval uint32_t makeFourCC(const char fourCC[4]) {
* @param subtractFromOffset This offset is subtracted from the read integer. Defaults to the size of an
* integer since an integer was read from the stream before seeking to the string.
*/
void readStringAtOffset(BufferStream& stream, std::string& str, std::ios::seekdir offsetFrom = std::ios::cur, std::size_t subtractFromOffset = sizeof(int32_t));
void readStringAtOffset(BufferStream& stream, std::string& str, BufferStream::BufferStreamSeekDir offsetFrom = BufferStream::SEEKDIR_CUR, std::size_t subtractFromOffset = sizeof(int32_t));

} // namespace sourcepp::parser::binary
4 changes: 2 additions & 2 deletions src/mdlpp/structs/MDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ bool MDL::open(const std::byte* data, std::size_t size) {
.read(bone.procType)
.read(bone.procIndex)
.read(bone.physicsBone);
parser::binary::readStringAtOffset(stream, bone.surfacePropName, std::ios::cur, sizeof(int32_t) * 12 + sizeof(math::Vec3f) * 4 + sizeof(math::Quat) * 2 + sizeof(math::Mat3x4f) + sizeof(Bone::Flags));
parser::binary::readStringAtOffset(stream, bone.surfacePropName, BufferStream::SEEKDIR_CUR, sizeof(int32_t) * 12 + sizeof(math::Vec3f) * 4 + sizeof(math::Quat) * 2 + sizeof(math::Mat3x4f) + sizeof(Bone::Flags));
stream.read(bone.contents);

// _unused0
Expand Down Expand Up @@ -164,7 +164,7 @@ bool MDL::open(const std::byte* data, std::size_t size) {
for (int i = 0; i < materialDirCount; i++) {
auto& materialDir = this->materialDirectories.emplace_back();

parser::binary::readStringAtOffset(stream, materialDir, std::ios::beg, 0);
parser::binary::readStringAtOffset(stream, materialDir, BufferStream::SEEKDIR_BEG, 0);
}

stream.seek(skinReferenceOffset);
Expand Down
4 changes: 1 addition & 3 deletions src/sourcepp/parser/Binary.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#include <sourcepp/parser/Binary.h>

#include <BufferStream.h>

using namespace sourcepp;

void parser::binary::readStringAtOffset(BufferStream& stream, std::string& str, std::ios::seekdir offsetFrom, std::size_t subtractFromOffset) {
void parser::binary::readStringAtOffset(BufferStream& stream, std::string& str, BufferStream::BufferStreamSeekDir offsetFrom, std::size_t subtractFromOffset) {
const auto offset = stream.read<int32_t>();
if (offset == 0) {
str = "";
Expand Down
8 changes: 4 additions & 4 deletions src/sourcepp/parser/Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ std::string parser::text::convertEscapesToSpecialChars(std::string_view str, con

void parser::text::eatWhitespace(BufferStream& stream) {
while (isWhitespace(stream.read<char>())) {}
stream.seek(-1, std::ios::cur);
stream.seek(-1, BufferStream::SEEKDIR_CUR);
}

void parser::text::eatSingleLineComment(BufferStream& stream) {
Expand All @@ -99,7 +99,7 @@ void parser::text::eatSingleLineComment(BufferStream& stream) {

void parser::text::eatMultiLineComment(BufferStream& stream, std::string_view multiLineCommentEnd) {
while (!std::ranges::equal(stream.read_span<char>(multiLineCommentEnd.length()), multiLineCommentEnd)) {
stream.seek(-static_cast<int64_t>(multiLineCommentEnd.length() - 1), std::ios::cur);
stream.seek(-static_cast<int64_t>(multiLineCommentEnd.length() - 1), BufferStream::SEEKDIR_CUR);
}
}

Expand All @@ -121,7 +121,7 @@ void parser::text::eatWhitespaceAndComments(BufferStream& stream, std::string_vi
eatWhitespaceAndComments(stream, singleLineCommentStart, multiLineCommentStart);
return;
}
stream.seek(-static_cast<int64_t>(singleLineCommentStart.length()), std::ios::cur);
stream.seek(-static_cast<int64_t>(singleLineCommentStart.length()), BufferStream::SEEKDIR_CUR);
}

if (!multiLineCommentStart.empty()) {
Expand All @@ -130,7 +130,7 @@ void parser::text::eatWhitespaceAndComments(BufferStream& stream, std::string_vi
eatWhitespaceAndComments(stream, singleLineCommentStart, multiLineCommentStart);
return;
}
stream.seek(-static_cast<int64_t>(multiLineCommentStart.length()), std::ios::cur);
stream.seek(-static_cast<int64_t>(multiLineCommentStart.length()), BufferStream::SEEKDIR_CUR);
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/toolpp/FGD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ constexpr auto INVALID_CLASS_MSG = "Invalid class found in FGD!";
while (true) {
char c = stream.read<char>();
if (c != '\"') {
stream.seek(-1, std::ios::cur);
stream.seek(-1, BufferStream::SEEKDIR_CUR);
const auto out = parser::text::readUnquotedStringToBuffer(stream, backing, ":", parser::text::NO_ESCAPE_SEQUENCES);
if (stream.seek(-1, std::ios::cur).peek<char>() != ':') {
if (stream.seek(-1, BufferStream::SEEKDIR_CUR).peek<char>() != ':') {
stream.skip();
parser::text::eatWhitespaceAndSingleLineComments(stream);
}
Expand Down Expand Up @@ -70,7 +70,7 @@ constexpr auto INVALID_CLASS_MSG = "Invalid class found in FGD!";
}
}

if (stream.seek(-1, std::ios::cur).peek<char>() != ':') {
if (stream.seek(-1, BufferStream::SEEKDIR_CUR).peek<char>() != ':') {
stream.skip();
parser::text::eatWhitespaceAndSingleLineComments(stream);
}
Expand All @@ -80,7 +80,7 @@ constexpr auto INVALID_CLASS_MSG = "Invalid class found in FGD!";
}

void readVersion(BufferStreamReadOnly& stream, BufferStream& backing, int& version) {
if (stream.seek(-1, std::ios::cur).peek<char>() != '(') {
if (stream.seek(-1, BufferStream::SEEKDIR_CUR).peek<char>() != '(') {
parser::text::eatWhitespace(stream);
if (stream.peek<char>() != '(') {
throw parser::text::syntax_error{INVALID_SYNTAX_MSG};
Expand All @@ -92,7 +92,7 @@ void readVersion(BufferStreamReadOnly& stream, BufferStream& backing, int& versi
}

void readMapSize(BufferStreamReadOnly& stream, BufferStream& backing, math::Vec2i& mapSize) {
if (stream.seek(-1, std::ios::cur).peek<char>() != '(') {
if (stream.seek(-1, BufferStream::SEEKDIR_CUR).peek<char>() != '(') {
parser::text::eatWhitespace(stream);
if (stream.peek<char>() != '(') {
throw parser::text::syntax_error{INVALID_SYNTAX_MSG};
Expand Down Expand Up @@ -151,7 +151,7 @@ void readClassProperties(BufferStreamReadOnly& stream, BufferStream& backing, FG
classProperty.name = parser::text::readUnquotedStringToBuffer(stream, backing, "(", parser::text::NO_ESCAPE_SEQUENCES);
classProperty.arguments = "";

if (stream.seek(-1, std::ios::cur).peek<char>() != '(') {
if (stream.seek(-1, BufferStream::SEEKDIR_CUR).peek<char>() != '(') {
parser::text::eatWhitespace(stream);
if (stream.peek<char>() != '(') {
entity.classProperties.push_back(classProperty);
Expand All @@ -171,7 +171,7 @@ void readClassProperties(BufferStreamReadOnly& stream, BufferStream& backing, FG
void readEntityIO(BufferStreamReadOnly& stream, BufferStream& backing, FGD::Entity& entity, bool input) {
auto& io = input ? entity.inputs.emplace_back() : entity.outputs.emplace_back();
io.name = parser::text::readUnquotedStringToBuffer(stream, backing, "(", parser::text::NO_ESCAPE_SEQUENCES);
if (stream.seek(-1, std::ios::cur).peek<char>() != '(') {
if (stream.seek(-1, BufferStream::SEEKDIR_CUR).peek<char>() != '(') {
parser::text::eatWhitespace(stream);
if (stream.peek<char>() != '(') {
throw parser::text::syntax_error{INVALID_SYNTAX_MSG};
Expand Down Expand Up @@ -200,7 +200,7 @@ void readEntityFieldModifiers(BufferStreamReadOnly& stream, BufferStream& backin
reportable = true;
return;
} else {
stream.seek(-static_cast<int64_t>(modifier.length()), std::ios::cur);
stream.seek(-static_cast<int64_t>(modifier.length()), BufferStream::SEEKDIR_CUR);
return;
}
}
Expand All @@ -209,7 +209,7 @@ void readEntityFieldModifiers(BufferStreamReadOnly& stream, BufferStream& backin
if (const auto modifier = parser::text::readUnquotedStringToBuffer(stream, backing); modifier == "report") {
reportable = true;
} else {
stream.seek(-static_cast<int64_t>(modifier.length()), std::ios::cur);
stream.seek(-static_cast<int64_t>(modifier.length()), BufferStream::SEEKDIR_CUR);
//return;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/vcryptpp/VFONT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ using namespace vcryptpp;
std::vector<std::byte> VFONT::decrypt(std::span<const std::byte> data) {
BufferStreamReadOnly reader{data.data(), data.size()};

if (reader.seek(IDENTIFIER.length(), std::ios::end).read_string(IDENTIFIER.length()) != IDENTIFIER) {
if (reader.seek(IDENTIFIER.length(), BufferStream::SEEKDIR_END).read_string(IDENTIFIER.length()) != IDENTIFIER) {
return {};
}
reader.seek(IDENTIFIER.length() + sizeof(uint8_t), std::ios::end);
reader.seek(IDENTIFIER.length() + sizeof(uint8_t), BufferStream::SEEKDIR_END);

auto bytes = reader.read<uint8_t>();

std::vector<std::byte> out;
out.resize(reader.size() - IDENTIFIER.length() - bytes);

reader.seek(-static_cast<int>(bytes), std::ios::cur);
reader.seek(-static_cast<int>(bytes), BufferStream::SEEKDIR_CUR);
uint8_t magic = MAGIC;
for (int i = 0; i < bytes - 1; i++) {
magic ^= reader.read<uint8_t>() + MAGIC;
Expand Down
2 changes: 1 addition & 1 deletion src/vtfpp/PPL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ std::vector<std::byte> PPL::bake() {
writer.seek_u(seekPoint);
currentOffset += image.data.size() + alignment;
}
writer.seek(0, std::ios::end);
writer.seek(0, BufferStream::SEEKDIR_END);

out.resize(writer.size());
return out;
Expand Down
2 changes: 1 addition & 1 deletion src/vtfpp/VTF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ std::vector<std::byte> VTF::bake() const {
static constexpr auto writeNonLocalResource = [](BufferStream& writer_, Resource::Type type, std::span<const std::byte> data) {
writer_.write<uint32_t>(type);
const auto resourceOffsetPos = writer_.tell();
writer_.seek(0, std::ios::end);
writer_.seek(0, BufferStream::SEEKDIR_END);
const auto resourceOffsetValue = writer_.tell();
writer_.write(data);
writer_.seek_u(resourceOffsetPos).write<uint32_t>(resourceOffsetValue);
Expand Down

0 comments on commit 7c31df9

Please sign in to comment.