mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-05-16 23:11:42 +00:00
feat: add iw5 gfxlight dumper and loader
This commit is contained in:
@@ -103,7 +103,7 @@ The following section specify which assets are supported to be dumped to disk (u
|
||||
| MapEnts | ❌ | ❌ | |
|
||||
| FxWorld | ❌ | ❌ | |
|
||||
| GfxWorld | ❌ | ❌ | |
|
||||
| GfxLightDef | ❌ | ❌ | |
|
||||
| GfxLightDef | ✅ | ✅ | |
|
||||
| Font_s | ❌ | ❌ | |
|
||||
| MenuList | ✅ | ✅ | The output is decompiled. The result will not be the same as the input. |
|
||||
| menuDef_t | ✅ | ✅ | See menulist. |
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
#include "LightDefLoaderIW5.h"
|
||||
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "LightDef/LightDefCommon.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr auto MAX_IMAGE_NAME_SIZE = 0x800;
|
||||
|
||||
class LoaderLightDef final : public AssetCreator<AssetLightDef>
|
||||
{
|
||||
public:
|
||||
LoaderLightDef(MemoryManager& memory, ISearchPath& searchPath)
|
||||
: m_memory(memory),
|
||||
m_search_path(searchPath)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
||||
{
|
||||
const auto filename = light_def::GetFileNameForAsset(assetName);
|
||||
const auto file = m_search_path.Open(filename);
|
||||
if (!file.IsOpen())
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
auto* lightDef = m_memory.Alloc<GfxLightDef>();
|
||||
lightDef->name = m_memory.Dup(assetName.c_str());
|
||||
|
||||
AssetRegistration<AssetLightDef> registration(assetName, lightDef);
|
||||
|
||||
int8_t attenuationSamplerState;
|
||||
file.m_stream->read(reinterpret_cast<char*>(&attenuationSamplerState), sizeof(int8_t));
|
||||
|
||||
std::string attenuationName = "";
|
||||
unsigned char letter;
|
||||
file.m_stream->read(reinterpret_cast<char*>(&letter), sizeof(int8_t));
|
||||
while (letter != '\0')
|
||||
{
|
||||
attenuationName += letter;
|
||||
|
||||
file.m_stream->read(reinterpret_cast<char*>(&letter), sizeof(int8_t));
|
||||
}
|
||||
|
||||
auto* attenuationImageDependency = context.LoadDependency<AssetImage>(attenuationName);
|
||||
if (!attenuationImageDependency)
|
||||
{
|
||||
con::error("Could not load GfxLightDef \"{}\" due to missing attenuation image \"{}\"", assetName, attenuationName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
registration.AddDependency(attenuationImageDependency);
|
||||
|
||||
int8_t cucolorisSamplerState;
|
||||
file.m_stream->read(reinterpret_cast<char*>(&cucolorisSamplerState), sizeof(int8_t));
|
||||
|
||||
std::string cucolorisName = "";
|
||||
file.m_stream->read(reinterpret_cast<char*>(&letter), sizeof(int8_t));
|
||||
while (letter != '\0')
|
||||
{
|
||||
cucolorisName += letter;
|
||||
|
||||
file.m_stream->read(reinterpret_cast<char*>(&cucolorisName), sizeof(int8_t));
|
||||
}
|
||||
|
||||
auto* cucolorisImageDependency = context.LoadDependency<AssetImage>(cucolorisName);
|
||||
if (!cucolorisImageDependency)
|
||||
{
|
||||
con::error("Could not load GfxLightDef \"{}\" due to missing cucoloris image \"{}\"", assetName, cucolorisName);
|
||||
return AssetCreationResult::Failure();
|
||||
}
|
||||
registration.AddDependency(cucolorisImageDependency);
|
||||
|
||||
int8_t lmapLookupStart;
|
||||
file.m_stream->read(reinterpret_cast<char*>(&lmapLookupStart), sizeof(int8_t));
|
||||
|
||||
lightDef->attenuation.samplerState = attenuationSamplerState;
|
||||
lightDef->attenuation.image = attenuationImageDependency->Asset();
|
||||
lightDef->cucoloris.samplerState = cucolorisSamplerState;
|
||||
lightDef->cucoloris.image = cucolorisImageDependency->Asset();
|
||||
lightDef->lmapLookupStart = static_cast<int>(static_cast<uint8_t>(lmapLookupStart));
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
|
||||
}
|
||||
|
||||
private:
|
||||
MemoryManager& m_memory;
|
||||
ISearchPath& m_search_path;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace light_def
|
||||
{
|
||||
std::unique_ptr<AssetCreator<AssetLightDef>> CreateLoaderIW5(MemoryManager& memory, ISearchPath& searchPath)
|
||||
{
|
||||
return std::make_unique<LoaderLightDef>(memory, searchPath);
|
||||
}
|
||||
} // namespace light_def
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetCreator.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace light_def
|
||||
{
|
||||
std::unique_ptr<AssetCreator<IW5::AssetLightDef>> CreateLoaderIW5(MemoryManager& memory, ISearchPath& searchPath);
|
||||
} // namespace light_def
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "Game/IW5/Techset/VertexShaderLoaderIW5.h"
|
||||
#include "Game/IW5/XModel/LoaderXModelIW5.h"
|
||||
#include "Leaderboard/LoaderLeaderboardIW5.h"
|
||||
#include "LightDef/LightDefLoaderIW5.h"
|
||||
#include "Localize/LoaderLocalizeIW5.h"
|
||||
#include "Material/LoaderMaterialIW5.h"
|
||||
#include "Menu/LoaderMenuListIW5.h"
|
||||
@@ -151,7 +152,7 @@ namespace
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderMapEnts>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderFxWorld>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderGfxWorld>(memory));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderLightDef>(memory));
|
||||
collection.AddAssetCreator(light_def::CreateLoaderIW5(memory, searchPath));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderFont>(memory));
|
||||
collection.AddAssetCreator(menu::CreateMenuListLoaderIW5(memory, searchPath));
|
||||
// collection.AddAssetCreator(std::make_unique<AssetLoaderMenu>(memory));
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#include "LightDefDumperIW5.h"
|
||||
|
||||
#include "LightDef/LightDefCommon.h"
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
namespace light_def
|
||||
{
|
||||
void DumperIW5::DumpAsset(AssetDumpingContext& context, const XAssetInfo<AssetLightDef::Type>& asset)
|
||||
{
|
||||
const auto* lightDef = asset.Asset();
|
||||
const auto assetFile = context.OpenAssetFile(GetFileNameForAsset(asset.m_name));
|
||||
|
||||
if (!assetFile || lightDef->attenuation.image == nullptr || lightDef->attenuation.image->name == nullptr || lightDef->cucoloris.image == nullptr
|
||||
|| lightDef->cucoloris.image->name == nullptr)
|
||||
return;
|
||||
|
||||
auto& stream = *assetFile;
|
||||
|
||||
const auto* attenuationImageName = lightDef->attenuation.image->name;
|
||||
if (attenuationImageName[0] == ',')
|
||||
attenuationImageName = &attenuationImageName[1];
|
||||
|
||||
const auto* cucolorisImageName = lightDef->cucoloris.image->name;
|
||||
if (cucolorisImageName[0] == ',')
|
||||
cucolorisImageName = &cucolorisImageName[1];
|
||||
|
||||
stream << lightDef->attenuation.samplerState << attenuationImageName << '\0' << lightDef->cucoloris.samplerState << cucolorisImageName
|
||||
<< static_cast<char>(lightDef->lmapLookupStart);
|
||||
}
|
||||
} // namespace light_def
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
|
||||
namespace light_def
|
||||
{
|
||||
class DumperIW5 final : public AbstractAssetDumper<IW5::AssetLightDef>
|
||||
{
|
||||
protected:
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<IW5::AssetLightDef::Type>& asset) override;
|
||||
};
|
||||
} // namespace light_def
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "Game/IW5/XModel/XModelDumperIW5.h"
|
||||
#include "Image/ImageDumperIW5.h"
|
||||
#include "Leaderboard/LeaderboardJsonDumperIW5.h"
|
||||
#include "LightDef/LightDefDumperIW5.h"
|
||||
#include "Localize/LocalizeDumperIW5.h"
|
||||
#include "Maps/AddonMapEntsDumperIW5.h"
|
||||
#include "Menu/MenuDumperIW5.h"
|
||||
@@ -51,7 +52,7 @@ void ObjWriter::RegisterAssetDumpers(AssetDumpingContext& context)
|
||||
// REGISTER_DUMPER(AssetDumperMapEnts)
|
||||
// REGISTER_DUMPER(AssetDumperFxWorld)
|
||||
// REGISTER_DUMPER(AssetDumperGfxWorld)
|
||||
// REGISTER_DUMPER(AssetDumperGfxLightDef)
|
||||
RegisterAssetDumper(std::make_unique<light_def::DumperIW5>());
|
||||
// REGISTER_DUMPER(AssetDumperFont_s)
|
||||
RegisterAssetDumper(std::make_unique<menu::MenuListDumperIW5>());
|
||||
RegisterAssetDumper(std::make_unique<menu::MenuDumperIW5>());
|
||||
|
||||
Reference in New Issue
Block a user