2017-01-20 08:36:52 -05:00
|
|
|
#pragma once
|
|
|
|
|
2017-01-19 16:23:59 -05:00
|
|
|
#define XFILE_MAGIC_UNSIGNED 0x3030317566665749
|
|
|
|
#define XFILE_VERSION 276
|
|
|
|
|
|
|
|
#define XFILE_HEADER_IW4X 0x78345749 // 'IW4x'
|
2017-07-03 10:32:10 -04:00
|
|
|
#define XFILE_VERSION_IW4X 3
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
class ZoneBuilder : public Component
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class Zone
|
|
|
|
{
|
|
|
|
public:
|
2017-06-05 15:03:04 -04:00
|
|
|
class AssetRecursionMarker
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AssetRecursionMarker(Zone* _builder) : builder(_builder)
|
|
|
|
{
|
|
|
|
this->builder->increaseAssetDepth();
|
|
|
|
}
|
|
|
|
|
|
|
|
~AssetRecursionMarker()
|
|
|
|
{
|
|
|
|
this->builder->decreaseAssetDepth();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Zone* builder;
|
|
|
|
};
|
|
|
|
|
2018-12-17 08:29:18 -05:00
|
|
|
Zone(const std::string& zoneName);
|
2017-01-19 16:23:59 -05:00
|
|
|
~Zone();
|
|
|
|
|
|
|
|
void build();
|
|
|
|
|
|
|
|
Utils::Stream* getBuffer();
|
|
|
|
Utils::Memory::Allocator* getAllocator();
|
|
|
|
|
|
|
|
bool hasPointer(const void* pointer);
|
|
|
|
void storePointer(const void* pointer);
|
|
|
|
|
|
|
|
template<typename T>
|
2022-11-16 12:25:21 -05:00
|
|
|
T* getPointer(const T* pointer) { return reinterpret_cast<T*>(this->safeGetPointer(pointer)); }
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
int findAsset(Game::XAssetType type, std::string name);
|
|
|
|
Game::XAssetHeader findSubAsset(Game::XAssetType type, std::string name);
|
|
|
|
Game::XAsset* getAsset(int index);
|
|
|
|
uint32_t getAssetTableOffset(int index);
|
|
|
|
|
|
|
|
bool hasAlias(Game::XAsset asset);
|
|
|
|
Game::XAssetHeader saveSubAsset(Game::XAssetType type, void* ptr);
|
2018-12-17 08:29:18 -05:00
|
|
|
bool loadAssetByName(Game::XAssetType type, const std::string& name, bool isSubAsset = true);
|
2017-01-19 16:23:59 -05:00
|
|
|
bool loadAsset(Game::XAssetType type, void* data, bool isSubAsset = true);
|
|
|
|
|
|
|
|
int addScriptString(unsigned short gameIndex);
|
2018-12-17 08:29:18 -05:00
|
|
|
int addScriptString(const std::string& str);
|
|
|
|
int findScriptString(const std::string& str);
|
2022-11-16 12:25:21 -05:00
|
|
|
void addRawAsset(Game::XAssetType type, void* ptr);
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2022-12-14 03:40:15 -05:00
|
|
|
void mapScriptString(unsigned short& gameIndex);
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2018-12-17 08:29:18 -05:00
|
|
|
void renameAsset(Game::XAssetType type, const std::string& asset, const std::string& newName);
|
|
|
|
std::string getAssetName(Game::XAssetType type, const std::string& asset);
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
void store(Game::XAssetHeader header);
|
|
|
|
|
|
|
|
void incrementExternalSize(unsigned int size);
|
|
|
|
|
2017-06-05 15:03:04 -04:00
|
|
|
void increaseAssetDepth() { ++this->assetDepth; }
|
|
|
|
void decreaseAssetDepth() { --this->assetDepth; }
|
|
|
|
bool isPrimaryAsset() { return this->assetDepth <= 1; }
|
|
|
|
|
2017-01-19 16:23:59 -05:00
|
|
|
private:
|
2022-12-18 16:47:59 -05:00
|
|
|
void loadFastFiles() const;
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
bool loadAssets();
|
2018-12-17 08:29:18 -05:00
|
|
|
bool loadAssetByName(const std::string& type, std::string name, bool isSubAsset = true);
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
void saveData();
|
|
|
|
void writeZone();
|
|
|
|
|
|
|
|
unsigned int getAlias(Game::XAsset asset);
|
|
|
|
void storeAlias(Game::XAsset asset);
|
|
|
|
|
|
|
|
void addBranding();
|
|
|
|
|
|
|
|
uint32_t safeGetPointer(const void* pointer);
|
|
|
|
|
|
|
|
int indexStart;
|
|
|
|
unsigned int externalSize;
|
|
|
|
Utils::Stream buffer;
|
|
|
|
|
|
|
|
std::string zoneName;
|
|
|
|
Utils::CSV dataMap;
|
|
|
|
|
|
|
|
Utils::Memory::Allocator memAllocator;
|
|
|
|
|
|
|
|
std::vector<Game::XAsset> loadedAssets;
|
|
|
|
std::vector<Game::XAsset> markedAssets;
|
|
|
|
std::vector<Game::XAsset> loadedSubAssets;
|
|
|
|
std::vector<std::string> scriptStrings;
|
2022-11-16 12:25:21 -05:00
|
|
|
|
2017-01-19 16:23:59 -05:00
|
|
|
std::map<unsigned short, unsigned int> scriptStringMap;
|
|
|
|
|
|
|
|
std::map<std::string, std::string> renameMap[Game::XAssetType::ASSET_TYPE_COUNT];
|
|
|
|
|
|
|
|
std::map<const void*, uint32_t> pointerMap;
|
|
|
|
std::vector<std::pair<Game::XAsset, uint32_t>> aliasList;
|
|
|
|
|
|
|
|
Game::RawFile branding;
|
2017-06-05 15:03:04 -04:00
|
|
|
|
|
|
|
size_t assetDepth;
|
2017-01-19 16:23:59 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
ZoneBuilder();
|
|
|
|
~ZoneBuilder();
|
|
|
|
|
|
|
|
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
|
2017-04-27 16:03:05 -04:00
|
|
|
bool unitTest() override;
|
2017-01-19 16:23:59 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static bool IsEnabled();
|
|
|
|
|
|
|
|
static std::string TraceZone;
|
|
|
|
static std::vector<std::pair<Game::XAssetType, std::string>> TraceAssets;
|
|
|
|
|
2018-12-17 08:29:18 -05:00
|
|
|
static void BeginAssetTrace(const std::string& zone);
|
2017-01-19 16:23:59 -05:00
|
|
|
static std::vector<std::pair<Game::XAssetType, std::string>> EndAssetTrace();
|
|
|
|
|
2018-12-17 08:29:18 -05:00
|
|
|
static Game::XAssetHeader GetEmptyAssetIfCommon(Game::XAssetType type, const std::string& name, Zone* builder);
|
2021-09-05 18:20:16 -04:00
|
|
|
static Dvar::Var PreferDiskAssetsDvar;
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
static int StoreTexture(Game::GfxImageLoadDef **loadDef, Game::GfxImage *image);
|
|
|
|
static void ReleaseTexture(Game::XAssetHeader header);
|
2017-05-21 17:00:39 -04:00
|
|
|
|
2018-12-17 08:29:18 -05:00
|
|
|
static std::string FindMaterialByTechnique(const std::string& name);
|
2022-12-14 03:40:15 -05:00
|
|
|
static void ReallocateLoadedSounds(void*& data, void* a2);
|
2017-05-26 15:41:40 -04:00
|
|
|
|
2022-12-18 16:47:59 -05:00
|
|
|
static BOOL APIENTRY EntryPoint(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nShowCmd*/);
|
2022-06-12 17:07:53 -04:00
|
|
|
static void HandleError(Game::errorParm_t code, const char* fmt, ...);
|
2017-05-26 15:41:40 -04:00
|
|
|
static void SoftErrorAssetOverflow();
|
|
|
|
|
|
|
|
static void AssumeMainThreadRole();
|
|
|
|
static void ResetThreadRole();
|
|
|
|
|
|
|
|
static bool IsThreadMainThreadHook();
|
2022-12-24 15:41:23 -05:00
|
|
|
static Game::Sys_File Sys_CreateFile_Stub(const char* dir, const char* filename);
|
2017-05-26 15:41:40 -04:00
|
|
|
|
2022-06-12 18:02:20 -04:00
|
|
|
static void Com_Quitf_t();
|
|
|
|
|
2022-12-18 16:47:59 -05:00
|
|
|
static void CommandThreadCallback();
|
|
|
|
|
2017-05-27 09:38:12 -04:00
|
|
|
static bool MainThreadInterrupted;
|
|
|
|
static DWORD InterruptingThreadId;
|
|
|
|
|
2022-12-18 16:47:59 -05:00
|
|
|
static volatile bool CommandThreadTerminate;
|
2017-05-27 09:38:12 -04:00
|
|
|
static std::thread CommandThread;
|
2017-01-19 16:23:59 -05:00
|
|
|
};
|
|
|
|
}
|