Skip to content

Commit

Permalink
add a (completely untested) decoder for voobly mod SLPs
Browse files Browse the repository at this point in the history
  • Loading branch information
sandsmark committed Oct 31, 2020
1 parent 7b9aa31 commit b46e9be
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ set(EXTRACT_SRC src/tools/extract/datextract.cpp)
set(DRSTOOL_SRC src/tools/drstool/drstool.cpp)
set(CPXTOOL_SRC src/tools/cpxtool/cpxtool.cpp)
set(PCRIOTOOL_SRC src/tools/pcriotool/pcriotool.cpp)
set(VOOBLYDECODER_SRC src/tools/vooblydecoder/main.cpp)

set(BINCOMP_SRC src/tools/bincompare/bincomp.cpp
src/tools/bincompare/main.cpp)
Expand Down Expand Up @@ -305,6 +306,9 @@ if (GUTILS_TOOLS)

add_executable(genie-bindiff ${BINCOMP_SRC})
install(TARGETS genie-bindiff)

add_executable(genie-vooblydecoder ${VOOBLYDECODER_SRC})
install(TARGETS genie-vooblydecoder)
endif (GUTILS_TOOLS)

#------------------------------------------------------------------------------#
Expand Down
1 change: 1 addition & 0 deletions src/resource/SlpFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ int SlpFile::frameWidth(const size_t frame)
void SlpFile::serializeHeader()
{
serialize(version, 4);

serializeSize<uint32_t>(num_frames_, frames_.size());
serialize(comment, 24);
}
Expand Down
70 changes: 70 additions & 0 deletions src/tools/vooblydecoder/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <cstdio>
#include <filesystem>
#include <vector>
#include <cstdint>
#include <unistd.h>
#include <cstring>
#include <sys/stat.h>
#include <fcntl.h>

int main(int argc, char *argv[])
{
if (argc < 2) {
printf("Usage: %s <filename.slp>\n", argv[0]);
return 1;
}
if (!std::filesystem::exists(argv[1])) {
printf("Usage: %s <filename.slp>\n", argv[0]);
return 1;
}
int fd = open(argv[1], O_RDONLY);
if (fd < 0) {
perror("Failed to open filename");
return 1;
}
ssize_t size = lseek(fd, 0, SEEK_END) - 4; // 4 bytes header
if (size <= 0) {
perror("Failed to get size or too small");
close(fd);
return 1;
}

static const uint8_t vooblyHeader[4] = { 0xBE, 0xEF, 0x13, 0x37 };
uint8_t header[4];
read(fd, header, 4);
if (memcmp(header, vooblyHeader, 4) != 0) {
puts("Not a voobly encoded SLP");
close(fd);
return 1;
}

std::vector<uint8_t> buffer(size);
if (read(fd, buffer.data(), buffer.size()) != size) {
perror("Failed to read entire file");
close(fd);
return 1;
}
close(fd);

for (uint8_t &c : buffer) {
c = ' ' * ((c - 0x11) ^ '#') | (uint8_t((c - 0x11) ^ '#') >> 3);
}
const std::string outFile = std::filesystem::path(argv[1]).stem().string() + "-decoded.slp";
fd = open(outFile.c_str(), O_WRONLY);
if (fd < 0) {
perror("Failed to open filename");
return 1;
}

if (write(fd, buffer.data(), buffer.size()) != size) {
perror("Failed to write entire file");
close(fd);
return 1;
}
close(fd);

puts("Done.");

return 0;
}

0 comments on commit b46e9be

Please sign in to comment.