Implement experimental zone building.
This commit is contained in:
parent
b2d5d3d870
commit
d31b21ab9b
@ -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());
|
||||
|
@ -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"
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
78
src/Components/Modules/ZoneBuilder.cpp
Normal file
78
src/Components/Modules/ZoneBuilder.cpp
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
57
src/Components/Modules/ZoneBuilder.hpp
Normal file
57
src/Components/Modules/ZoneBuilder.hpp
Normal file
@ -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();
|
||||
};
|
||||
}
|
@ -26,9 +26,13 @@
|
||||
#include <chrono>
|
||||
#include <future>
|
||||
|
||||
#define ZLIB_CONST
|
||||
#include <zlib.h>
|
||||
|
||||
#include "Utils\Utils.hpp"
|
||||
#include "Utils\WebIO.hpp"
|
||||
#include "Utils\Hooking.hpp"
|
||||
#include "Utils\Compression.hpp"
|
||||
|
||||
#include "Steam\Steam.hpp"
|
||||
|
||||
|
51
src/Utils/Compression.cpp
Normal file
51
src/Utils/Compression.cpp
Normal file
@ -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<uint8_t*>(buffer);
|
||||
stream.next_in = reinterpret_cast<const uint8_t*>(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;
|
||||
}
|
||||
};
|
||||
}
|
12
src/Utils/Compression.hpp
Normal file
12
src/Utils/Compression.hpp
Normal file
@ -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);
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user