mirror of
https://github.com/gwdevhub/gMod.git
synced 2026-07-15 15:09:30 +00:00
ab2d8cdb0a
* toggle use_folders on
* Rename pipelines
* its a strcpy :(
* add miniz, add xorstream, add non-working ziploader
* start integrating libzip (WIP)
* use ExternalProject test (doesnt work maybe?!)
* further work in integrating libzippp [WIP]
can't build libzip yet (neither manually nor in the vs build), as it doesn't find zlib
* LibZip build script
* make libzip build too
todo: specify cmake find_library to check the paths we install to
* prepare everything in cmake
* fix rebuilding of libzip/zlib
* fix stupid double quotes
* libzippp works
* Setup libzippp archive loading
* Remove allocation of new data when adding file to TextureServer
* Enable CI on dev
* Create LICENSE (#5)
* add mbedtls
* fix cmake (forgot to substitute, woops)
* fix %lu warnings for printing addresses
* enable debug messages, some formatting
* remove mbedtls, fix libzip for /MD(d)
* some code changes
* fix cmake logic, str replace min cmake version in libzip-src/CMakeLists.txt to 3.15
* linker errors in release
* c++ify a little
* remove unnecessary duplicate c++23 definition
* Fixes to gMod_XorStream when calculating stream length
* Fix loading tpf contents with password
* Implemented complete parsing
* Cleanup file loading
* Change to NI
* Revert "Change to NI"
This reverts commit 19b511d907.
* update XorStreamReader to read whole file, then xor
* delete a lot of unused code
* loading logic
* rename console window
* 1.5.4
* remove pointless mutex
* wtf is this code
---------
Co-authored-by: Alex Macocian <amacocian@yahoo.com>
52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <fstream>
|
|
#include <vector>
|
|
|
|
class XorStreamReader {
|
|
public:
|
|
XorStreamReader(const std::string& path)
|
|
{
|
|
file_stream = std::ifstream(path, std::ios::binary);
|
|
if (!file_stream.seekg(0, std::ios::end).good() || !file_stream.seekg(0, std::ios::beg).good()) {
|
|
throw std::invalid_argument("Provided stream needs to have SEEK set to True");
|
|
}
|
|
}
|
|
|
|
~XorStreamReader()
|
|
{
|
|
file_stream.close();
|
|
}
|
|
|
|
std::vector<char> ReadToEnd()
|
|
{
|
|
file_stream.seekg(0, std::ios::end);
|
|
line_length = file_stream.tellg();
|
|
file_stream.seekg(0, std::ios::beg); // Go to the beginning of the stream
|
|
|
|
std::vector<char> data(line_length);
|
|
file_stream.read(data.data(), line_length);
|
|
for (auto i = 0; i < data.size(); i++) {
|
|
data[i] = XOR(data[i], i);
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
private:
|
|
std::ifstream file_stream;
|
|
long line_length;
|
|
|
|
[[nodiscard]] char XOR(const char b, const long position) const
|
|
{
|
|
if (position > line_length - 4) {
|
|
return b ^ TPF_XOREven;
|
|
}
|
|
|
|
return position % 2 == 0 ? b ^ TPF_XOREven : b ^ TPF_XOROdd;
|
|
}
|
|
|
|
static constexpr char TPF_XOROdd = 0x3F;
|
|
static constexpr char TPF_XOREven = static_cast<char>(0xA4);
|
|
};
|