Skip to content

Commit 0b375a6

Browse files
wip
1 parent f491764 commit 0b375a6

5 files changed

Lines changed: 49 additions & 12 deletions

File tree

ext/_ext.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ endif()
3333

3434
# gdeflate
3535
if(SOURCEPP_USE_VPKPP)
36-
add_sourcepp_remote_library(gdeflate https://github.com/craftablescience/gdeflate 315d565f65b41791eaf9504fae41f0208929f950)
36+
add_sourcepp_remote_library(gdeflate https://github.com/craftablescience/gdeflate dcb637f984ece258909a451d31457896f9ecc7f5)
3737
endif()
3838

3939

include/sourcepp/parser/Text.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,17 @@ using EscapeSequenceMap = std::unordered_map<char, char>;
8181
/**
8282
* Eat all whitespace after the current stream position.
8383
* @param stream The BufferStream to modify.
84+
* @return The number of characters eaten.
8485
*/
85-
void eatWhitespace(BufferStream& stream);
86+
uint32_t eatWhitespace(BufferStream& stream);
8687

8788
/**
8889
* If a single line comment is detected, eat its contents.
8990
* This function does not handle the detection of single line comments!
9091
* @param stream The BufferStream to modify.
92+
* @return The number of characters eaten.
9193
*/
92-
void eatSingleLineComment(BufferStream& stream);
94+
uint32_t eatSingleLineComment(BufferStream& stream);
9395

9496
/**
9597
* If a multi line comment is detected, eat its contents.

src/sourcepp/parser/Text.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,21 @@ std::string parser::text::convertEscapesToSpecialChars(std::string_view str, con
9090
return out;
9191
}
9292

93-
void parser::text::eatWhitespace(BufferStream& stream) {
94-
while (isWhitespace(stream.read<char>())) {}
93+
uint32_t parser::text::eatWhitespace(BufferStream& stream) {
94+
uint32_t count = 0;
95+
while (stream.tell() != stream.size() && isWhitespace(stream.read<char>())) {
96+
count++;
97+
}
9598
stream.seek(-1, std::ios::cur);
99+
return count;
96100
}
97101

98-
void parser::text::eatSingleLineComment(BufferStream& stream) {
99-
while (!isNewLine(stream.read<char>())) {}
102+
uint32_t parser::text::eatSingleLineComment(BufferStream& stream) {
103+
uint32_t count = 0;
104+
while (stream.tell() != stream.size() && !isNewLine(stream.read<char>())) {
105+
count++;
106+
}
107+
return count;
100108
}
101109

102110
void parser::text::eatMultiLineComment(BufferStream& stream, std::string_view multiLineCommentEnd) {
@@ -137,7 +145,7 @@ void parser::text::eatWhitespaceAndComments(BufferStream& stream, std::string_vi
137145
}
138146

139147
bool parser::text::tryToEatChar(BufferStream& stream, char c) {
140-
if (stream.peek<char>() != c) {
148+
if (stream.tell() == stream.size() || stream.peek<char>() != c) {
141149
return false;
142150
}
143151
stream.skip();

src/vpkpp/format/PKG.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ using namespace vpkpp;
1414

1515
namespace {
1616

17+
//NOLINTBEGIN(*-branch-clone)
18+
1719
// Convert some Vulkan 1.0 formats to corresponding DXGI formats
1820
[[nodiscard]] constexpr uint32_t mapVkFormatToDXGIFormat(uint32_t format) {
1921
switch (format) {
@@ -214,6 +216,8 @@ namespace {
214216
return false;
215217
}
216218

219+
//NOLINTEND(*-branch-clone)
220+
217221
} // namespace
218222

219223
uint32_t PKG::Asset::getBlobIndex(int frame, int face, int mip) const {
@@ -241,8 +245,10 @@ std::unique_ptr<PackFile> PKG::open(const std::string& path, const EntryCallback
241245

242246
if (path.length() >= 7 && string::matches(path.substr(path.length() - 7, path.length()), "_%d%d.pkg")) {
243247
for (int i = 0; true; i++) {
244-
const auto numberedPath = pkg->getTruncatedFilepath() + "_" + string::padNumber(i, 2) + PKG_EXTENSION.data();
245-
if (!pkg->openNumbered(i, numberedPath, callback)) {
248+
if (
249+
const auto numberedPath = pkg->getTruncatedFilepath() + "_" + string::padNumber(i, 2) + PKG_EXTENSION.data();
250+
!pkg->openNumbered(i, numberedPath, callback)
251+
) {
246252
if (i == 0) {
247253
return nullptr;
248254
}
@@ -371,8 +377,7 @@ std::optional<std::vector<std::byte>> PKG::readEntry(const std::string& path_) c
371377

372378
// Add blobs
373379
const auto readBlob = [&stream, &blobs, &writer](uint32_t i, uint64_t blobUncompressedSize) {
374-
const auto& blob = blobs[i];
375-
switch (blob.compression) {
380+
switch (const auto& blob = blobs[i]; blob.compression) {
376381
case Blob::Compression::NONE: {
377382
writer << stream.seek_in_u(blob.offset).read_bytes(blob.size);
378383
break;

test/vpkpp.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
#include <vpkpp/vpkpp.h>
44

5+
#include <sourcepp/parser/Text.h>
6+
7+
#include "BufferStream.h"
8+
59
using namespace sourcepp;
610
using namespace vpkpp;
711

@@ -27,6 +31,24 @@ TEST(vpkpp, ore_read) {
2731
EXPECT_TRUE(ore->hasEntry("startup.cfg"));
2832
}
2933

34+
TEST(vpkpp, pkg_read) {
35+
const auto pkg = PackFile::open("/home/lxlewis/.local/share/Steam/steamapps/common/PortalRTX/rtx-remix/mods/gameReadyAssets/mod_00.pkg");
36+
ASSERT_TRUE(pkg);
37+
VPKPP_PRINT_ALL_PATHS(pkg);
38+
39+
//ASSERT_TRUE(pkg->hasEntry("SubUSDs/textures/0901F01E92F1E81C.dds"));
40+
//const auto data = pkg->readEntry("SubUSDs/textures/0901F01E92F1E81C.dds");
41+
//ASSERT_TRUE(data);
42+
//fs::writeFileBuffer("/home/lxlewis/.local/share/Steam/steamapps/common/PortalRTX/rtx-remix/mods/gameReadyAssets/mod_spp/SubUSDs/textures/0901F01E92F1E81C.dds", *data);
43+
44+
ASSERT_TRUE(pkg->hasEntry("SubUSDs/textures/T_Fixture_Platform_Folding_A1_Albedo.dds"));
45+
const auto data2 = pkg->readEntry("SubUSDs/textures/T_Fixture_Platform_Folding_A1_Albedo.dds");
46+
ASSERT_TRUE(data2);
47+
fs::writeFileBuffer("/home/lxlewis/.local/share/Steam/steamapps/common/PortalRTX/rtx-remix/mods/gameReadyAssets/mod_spp/SubUSDs/textures/T_Fixture_Platform_Folding_A1_Albedo.dds", *data2);
48+
49+
//ASSERT_TRUE(pkg->extractAll("/home/lxlewis/.local/share/Steam/steamapps/common/PortalRTX/rtx-remix/mods/gameReadyAssets/"));
50+
}
51+
3052
TEST(vpkpp, vpp_v1_read) {
3153
const auto vpp = PackFile::open(ASSET_ROOT "vpkpp/vpp/v1.vpp");
3254
ASSERT_TRUE(vpp);

0 commit comments

Comments
 (0)