diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index 552dd646..bc72e1b2 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -33,6 +33,7 @@ namespace Components Loader::Register(new FileSystem()); Loader::Register(new QuickPatch()); Loader::Register(new ServerList()); + Loader::Register(new ZoneBuilder()); Loader::Register(new AssetHandler()); Loader::Register(new Localization()); Loader::Register(new MusicalTalent()); diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index 08af4696..5522fa6f 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -46,6 +46,7 @@ namespace Components #include "Modules\FileSystem.hpp" #include "Modules\QuickPatch.hpp" #include "Modules\ServerList.hpp" +#include "Modules\ZoneBuilder.hpp" #include "Modules\AssetHandler.hpp" #include "Modules\Localization.hpp" #include "Modules\MusicalTalent.hpp" diff --git a/src/Components/Modules/FastFiles.cpp b/src/Components/Modules/FastFiles.cpp index 0b75a025..85126f1b 100644 --- a/src/Components/Modules/FastFiles.cpp +++ b/src/Components/Modules/FastFiles.cpp @@ -17,6 +17,9 @@ namespace Components info.name = "dlc2_ui_mp"; data.push_back(info); + info.name = "penis"; + data.push_back(info); + Game::DB_LoadXAssets(data.data(), data.size(), sync); } diff --git a/src/Components/Modules/Singleton.cpp b/src/Components/Modules/Singleton.cpp index 4c6eea96..93ff4612 100644 --- a/src/Components/Modules/Singleton.cpp +++ b/src/Components/Modules/Singleton.cpp @@ -11,7 +11,7 @@ namespace Components Singleton::Singleton() { - if (Dedicated::IsDedicated()) return; + if (Dedicated::IsDedicated() || ZoneBuilder::IsEnabled()) return; Singleton::FirstInstance = (CreateMutex(NULL, FALSE, "iw4x_mutex") && GetLastError() != ERROR_ALREADY_EXISTS); diff --git a/src/Components/Modules/ZoneBuilder.cpp b/src/Components/Modules/ZoneBuilder.cpp new file mode 100644 index 00000000..f4c9e6b9 --- /dev/null +++ b/src/Components/Modules/ZoneBuilder.cpp @@ -0,0 +1,78 @@ +#include "STDInclude.hpp" + +namespace Components +{ + std::string ZoneBuilder::Zone::Build() + { + static_assert(sizeof(XFileHeader) == 21, "Invalid XFileHeader structure!"); + static_assert(sizeof(XFile) == 40, "Invalid XFile structure!"); + + std::string buffer; + + XFileHeader header = { XFILE_MAGIC_UNSIGNED, XFILE_VERSION, 0, 0, 0 }; + + FILETIME fileTime; + GetSystemTimeAsFileTime(&fileTime); + + header.lowDateTime = fileTime.dwLowDateTime; + header.highDateTime = fileTime.dwHighDateTime; + + buffer.append((char*)&header, sizeof(header)); + + std::string zoneBuffer; + zoneBuffer.resize(sizeof(XFile)); + + // Fill zone + XAssetList list; + list.assetCount = 0; + list.assets = 0; + list.stringList.count = 0; + list.stringList.strings = 0; + + zoneBuffer.append((char*)&list, sizeof(list)); + + XFile* zone = (XFile*)zoneBuffer.data(); + ZeroMemory(zone, sizeof(XFile)); + + zone->size = zoneBuffer.size() - sizeof(XFile); + + auto compressedData = Utils::Compression::ZLib::Compress(zoneBuffer); + buffer.append(compressedData); + + return buffer; + } + + ZoneBuilder::Zone::Zone(std::string zoneName) : ZoneName(zoneName) + { + + } + + ZoneBuilder::Zone::~Zone() + { + + } + + bool ZoneBuilder::IsEnabled() + { + return Flags::HasFlag("zonebuilder"); + } + + ZoneBuilder::ZoneBuilder() + { + if (ZoneBuilder::IsEnabled()) + { + auto data = Zone("").Build(); + + FILE* fp; + fopen_s(&fp, "penis.ff", "wb"); + + if (fp) + { + fwrite(data.data(), 1, data.size(), fp); + fclose(fp); + } + + ExitProcess(0); + } + } +} diff --git a/src/Components/Modules/ZoneBuilder.hpp b/src/Components/Modules/ZoneBuilder.hpp new file mode 100644 index 00000000..472fdf65 --- /dev/null +++ b/src/Components/Modules/ZoneBuilder.hpp @@ -0,0 +1,57 @@ +#define XFILE_MAGIC_UNSIGNED 0x3030317566665749 +#define XFILE_VERSION 276 + +#pragma pack(push, 1) +struct XFileHeader +{ + uint64_t magic; + uint32_t version; + uint8_t flag; + DWORD highDateTime; + DWORD lowDateTime; +}; +#pragma pack(pop) + +struct XFile +{ + unsigned int size; + unsigned int externalSize; + unsigned int blockSize[8]; +}; + +struct ScriptStringList +{ + int count; + const char **strings; +}; + +struct XAssetList +{ + ScriptStringList stringList; + int assetCount; + Game::XAsset *assets; +}; + +namespace Components +{ + class ZoneBuilder : public Component + { + public: + class Zone + { + public: + Zone(std::string zoneName); + ~Zone(); + + std::string Build(); + + private: + std::string ZoneName; + }; + + ZoneBuilder(); + const char* GetName() { return "ZoneBuilder"; }; + + static bool IsEnabled(); + }; +} diff --git a/src/STDInclude.hpp b/src/STDInclude.hpp index ca36ebb3..ce9f3a85 100644 --- a/src/STDInclude.hpp +++ b/src/STDInclude.hpp @@ -26,9 +26,13 @@ #include #include +#define ZLIB_CONST +#include + #include "Utils\Utils.hpp" #include "Utils\WebIO.hpp" #include "Utils\Hooking.hpp" +#include "Utils\Compression.hpp" #include "Steam\Steam.hpp" diff --git a/src/Utils/Compression.cpp b/src/Utils/Compression.cpp new file mode 100644 index 00000000..9b69f99b --- /dev/null +++ b/src/Utils/Compression.cpp @@ -0,0 +1,51 @@ +#include "STDInclude.hpp" + +namespace Utils +{ + namespace Compression + { + std::string ZLib::Compress(std::string data) + { + z_stream stream; + ZeroMemory(&stream, sizeof(stream)); + + char* buffer = new char[data.size() * 2]; + + if (deflateInit(&stream, Z_BEST_COMPRESSION) != Z_OK) + { + delete[] buffer; + return ""; + } + + stream.next_out = reinterpret_cast(buffer); + stream.next_in = reinterpret_cast(data.data()); + stream.avail_out = data.size() * 2; + stream.avail_in = data.size(); + + if (deflate(&stream, Z_FINISH) != Z_STREAM_END) + { + delete[] buffer; + return ""; + } + + if (deflateEnd(&stream) != Z_OK) + { + delete[] buffer; + return ""; + } + + data.clear(); + data.append(buffer, stream.total_out); + + delete[] buffer; + + return data; + } + + std::string ZLib::Decompress(std::string data) + { + //#error "Not implemented yet!" + return data; + } + }; +} diff --git a/src/Utils/Compression.hpp b/src/Utils/Compression.hpp new file mode 100644 index 00000000..2679f617 --- /dev/null +++ b/src/Utils/Compression.hpp @@ -0,0 +1,12 @@ +namespace Utils +{ + namespace Compression + { + class ZLib + { + public: + static std::string Compress(std::string data); + static std::string Decompress(std::string data); + }; + }; +}