diff --git a/header/gMod_FileLoader.h b/header/gMod_FileLoader.h index 6bc6da3..5fce0ad 100644 --- a/header/gMod_FileLoader.h +++ b/header/gMod_FileLoader.h @@ -18,7 +18,7 @@ struct TpfEntry { class gMod_FileLoader { std::string file_name; std::ifstream stream; - static constexpr std::vector TPF_PASSWORD{ + const std::vector TPF_PASSWORD{ 0x73, 0x2A, 0x63, 0x7D, 0x5F, 0x0A, 0xA6, 0xBD, 0x7D, 0x65, 0x7E, 0x67, 0x61, 0x2A, 0x7F, 0x7F, 0x74, 0x61, 0x67, 0x5B, 0x60, 0x70, 0x45, 0x74, @@ -26,7 +26,7 @@ class gMod_FileLoader { 0x77, 0x6E, 0x46, 0x47, 0x77, 0x49, 0x0C, 0x4B, 0x46, 0x6F }; - static constexpr std::string ENCODED_PASSWORD = std::string(TPF_PASSWORD.begin(), TPF_PASSWORD.end()); + const std::string ENCODED_PASSWORD = std::string(TPF_PASSWORD.begin(), TPF_PASSWORD.end()); std::vector entry_cache{}; bool loaded = false; diff --git a/header/gMod_XorStream.h b/header/gMod_XorStream.h index 03600ec..28a37bf 100644 --- a/header/gMod_XorStream.h +++ b/header/gMod_XorStream.h @@ -1,7 +1,8 @@ -#pragma once +#pragma once #include #include +#include class gMod_XorStream : public std::streambuf { public: @@ -10,7 +11,10 @@ public: throw std::invalid_argument("Provided stream needs to have SEEK set to True"); } - originalStreamLength = innerStream.tellg(); + innerStream.seekg(0, std::ios::end); + std::streampos file_size = innerStream.tellg(); + innerStream.seekg(0, std::ios::beg); + originalStreamLength = file_size; innerStream.seekg(originalStreamLength - 1); while (innerStream.tellg() > 0) { @@ -52,6 +56,15 @@ public: return traits_type::eof(); } + std::vector ReadToEnd() { + std::vector buffer(length); + for (auto c = ReadByte(); c != traits_type::eof(); c = ReadByte()) { + buffer.push_back(static_cast(c)); + } + + return buffer; + } + private: std::istream& innerStream; long originalStreamLength; diff --git a/source/gMod_FileLoader.cpp b/source/gMod_FileLoader.cpp index f94d843..61d8492 100644 --- a/source/gMod_FileLoader.cpp +++ b/source/gMod_FileLoader.cpp @@ -1,3 +1,4 @@ +#include #include #include "gMod_FileLoader.h" #include "gMod_XorStream.h" @@ -31,9 +32,13 @@ std::vector gMod_FileLoader::GetTpfContents() std::vector entries; try { auto istream = std::ifstream(file_name, std::ios::binary); - const auto xorstream = gMod_XorStream(istream); - // todo from xorstream - libzippp::ZipArchive zipArchive(file_name, ENCODED_PASSWORD); + auto xorstream = gMod_XorStream(istream); + + const std::string password(TPF_PASSWORD.begin(), TPF_PASSWORD.end()); + libzippp::ZipArchive zipArchive(file_name, password); + zipArchive.setErrorHandlerCallback([](const std::string& message, const std::string& strerror, int zip_error_code, int system_error_code) -> void { + Message("GetTpfContents: %s %s %d %d\n", message.c_str(), strerror.c_str(), zip_error_code, system_error_code); + }); zipArchive.open(); LoadEntries(zipArchive, entries); } diff --git a/source/uMod_DX9_dll.cpp b/source/uMod_DX9_dll.cpp index 0fd8fc3..0dd3e36 100644 --- a/source/uMod_DX9_dll.cpp +++ b/source/uMod_DX9_dll.cpp @@ -84,7 +84,7 @@ void InitInstance(HINSTANCE hModule) std::array uMod{}; GetModuleFileNameA(hModule, uMod.data(), MAX_PATH); - Message("InitInstance: %s\n", uMod); + Message("InitInstance: %s\n", uMod.data()); gl_TextureServer = std::make_unique(game, uMod.data()); //create the server which listen on the pipe and prepare the update for the texture clients LoadOriginalDll(); if (gl_hOriginalDll) {