2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-07-02 22:08:11 +00:00

feat: T4 RawFile and MapEnts loading (#870)

This commit is contained in:
mo
2026-06-29 18:27:16 +01:00
committed by GitHub
parent 62ee9dab40
commit c9595794a3
7 changed files with 137 additions and 4 deletions
+3 -3
View File
@@ -142,17 +142,17 @@ using `Linker`):
| ComWorld | ❌ | ❌ | |
| GameWorldSp | ❌ | ❌ | |
| GameWorldMp | ❌ | ❌ | |
| MapEnts | ✅ | | |
| MapEnts | ✅ | | |
| GfxWorld | ❌ | ❌ | |
| GfxLightDef | ❌ | ❌ | |
| Font_s | ❌ | ❌ | |
| MenuList | ❌ | ❌ | |
| menuDef_t | ❌ | ❌ | |
| LocalizeEntry | ✅ | | |
| LocalizeEntry | ✅ | | |
| WeaponDef | ❌ | ❌ | |
| FxEffectDef | ❌ | ❌ | |
| FxImpactTable | ❌ | ❌ | |
| RawFile | ✅ | | |
| RawFile | ✅ | | |
| StringTable | ✅ | ❌ | |
| PackIndex | ❌ | ❌ | |
@@ -0,0 +1,52 @@
#include "MapEntsLoaderT4.h"
#include "Game/T4/T4.h"
#include "Maps/MapEntsCommon.h"
using namespace T4;
namespace
{
class MapEntsLoader final : public AssetCreator<AssetMapEnts>
{
public:
MapEntsLoader(MemoryManager& memory, ISearchPath& searchPath)
: m_memory(memory),
m_search_path(searchPath)
{
}
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto file = m_search_path.Open(map_ents::GetEntsFileNameForAssetName(assetName));
if (!file.IsOpen())
return AssetCreationResult::NoAction();
auto* mapEnts = m_memory.Alloc<MapEnts>();
mapEnts->name = m_memory.Dup(assetName.c_str());
mapEnts->numEntityChars = static_cast<int>(file.m_length + 1);
auto* fileBuffer = m_memory.Alloc<char>(static_cast<size_t>(file.m_length + 1));
file.m_stream->read(fileBuffer, file.m_length);
if (file.m_stream->gcount() != file.m_length)
return AssetCreationResult::Failure();
fileBuffer[static_cast<size_t>(file.m_length)] = '\0';
mapEnts->entityString = fileBuffer;
return AssetCreationResult::Success(context.AddAsset<AssetMapEnts>(assetName, mapEnts));
}
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
namespace map_ents
{
std::unique_ptr<AssetCreator<AssetMapEnts>> CreateLoaderT4(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<MapEntsLoader>(memory, searchPath);
}
} // namespace map_ents
@@ -0,0 +1,13 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/T4/T4.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace map_ents
{
std::unique_ptr<AssetCreator<T4::AssetMapEnts>> CreateLoaderT4(MemoryManager& memory, ISearchPath& searchPath);
} // namespace map_ents
+4
View File
@@ -5,6 +5,8 @@
#include "Game/T4/T4.h"
#include "Game/T4/XAnim/XAnimLoaderT4.h"
#include "Localize/AssetLoaderLocalizeT4.h"
#include "Maps/MapEntsLoaderT4.h"
#include "RawFile/AssetLoaderRawFileT4.h"
using namespace T4;
@@ -88,6 +90,8 @@ namespace
collection.AddAssetCreator(xanim::CreateLoaderT4(memory, searchPath, zone));
collection.AddAssetCreator(localize::CreateLoaderT4(memory, searchPath, zone));
collection.AddAssetCreator(map_ents::CreateLoaderT4(memory, searchPath));
collection.AddAssetCreator(raw_file::CreateLoaderT4(memory, searchPath));
}
} // namespace
@@ -0,0 +1,51 @@
#include "AssetLoaderRawFileT4.h"
#include "Game/T4/T4.h"
using namespace T4;
namespace
{
class RawFileLoader final : public AssetCreator<AssetRawFile>
{
public:
RawFileLoader(MemoryManager& memory, ISearchPath& searchPath)
: m_memory(memory),
m_search_path(searchPath)
{
}
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto file = m_search_path.Open(assetName);
if (!file.IsOpen())
return AssetCreationResult::NoAction();
auto* rawFile = m_memory.Alloc<RawFile>();
rawFile->name = m_memory.Dup(assetName.c_str());
rawFile->len = static_cast<int>(file.m_length);
auto* fileBuffer = m_memory.Alloc<char>(static_cast<size_t>(file.m_length + 1));
file.m_stream->read(fileBuffer, file.m_length);
if (file.m_stream->gcount() != file.m_length)
return AssetCreationResult::Failure();
fileBuffer[rawFile->len] = '\0';
rawFile->buffer = fileBuffer;
return AssetCreationResult::Success(context.AddAsset<AssetRawFile>(assetName, rawFile));
}
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
namespace raw_file
{
std::unique_ptr<AssetCreator<AssetRawFile>> CreateLoaderT4(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<RawFileLoader>(memory, searchPath);
}
} // namespace raw_file
@@ -0,0 +1,13 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/T4/T4.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace raw_file
{
std::unique_ptr<AssetCreator<T4::AssetRawFile>> CreateLoaderT4(MemoryManager& memory, ISearchPath& searchPath);
} // namespace raw_file
@@ -15,6 +15,6 @@ namespace map_ents
return;
auto& stream = *assetFile;
stream.write(mapEnts->entityString, mapEnts->numEntityChars);
stream.write(mapEnts->entityString, std::max(mapEnts->numEntityChars - 1, 0));
}
} // namespace map_ents