Add dumper and reader for IW4 GfxLightDef

This commit is contained in:
Jan 2022-01-02 18:01:24 +01:00
parent 77b6b7c87a
commit daa7008038
8 changed files with 177 additions and 1 deletions

View File

@ -1878,6 +1878,29 @@ namespace IW4
FxElemDef* elemDefs; FxElemDef* elemDefs;
}; };
enum SamplerStateBits_e
{
SAMPLER_FILTER_SHIFT = 0x0,
SAMPLER_FILTER_NEAREST = 0x1,
SAMPLER_FILTER_LINEAR = 0x2,
SAMPLER_FILTER_ANISO2X = 0x3,
SAMPLER_FILTER_ANISO4X = 0x4,
SAMPLER_FILTER_MASK = 0x7,
SAMPLER_MIPMAP_SHIFT = 0x3,
SAMPLER_MIPMAP_DISABLED = 0x0,
SAMPLER_MIPMAP_NEAREST = 0x8,
SAMPLER_MIPMAP_LINEAR = 0x10,
SAMPLER_MIPMAP_COUNT = 0x3,
SAMPLER_MIPMAP_MASK = 0x18,
SAMPLER_CLAMP_U_SHIFT = 0x5,
SAMPLER_CLAMP_V_SHIFT = 0x6,
SAMPLER_CLAMP_W_SHIFT = 0x7,
SAMPLER_CLAMP_U = 0x20,
SAMPLER_CLAMP_V = 0x40,
SAMPLER_CLAMP_W = 0x80,
SAMPLER_CLAMP_MASK = 0xE0,
};
struct GfxLightImage struct GfxLightImage
{ {
GfxImage* image; GfxImage* image;

View File

@ -2428,6 +2428,43 @@ namespace T5
GfxHeroLightTree* heroLightTree; GfxHeroLightTree* heroLightTree;
}; };
enum SamplerStateBits_e
{
SAMPLER_FILTER_SHIFT = 0x0,
SAMPLER_FILTER_NEAREST = 0x1,
SAMPLER_FILTER_LINEAR = 0x2,
SAMPLER_FILTER_ANISO2X = 0x3,
SAMPLER_FILTER_ANISO4X = 0x4,
SAMPLER_FILTER_MASK = 0x7,
SAMPLER_MIPMAP_SHIFT = 0x3,
SAMPLER_MIPMAP_DISABLED = 0x0,
SAMPLER_MIPMAP_NEAREST = 0x8,
SAMPLER_MIPMAP_LINEAR = 0x10,
SAMPLER_MIPMAP_COUNT = 0x3,
SAMPLER_MIPMAP_MASK = 0x18,
SAMPLER_CLAMP_U_SHIFT = 0x5,
SAMPLER_CLAMP_V_SHIFT = 0x6,
SAMPLER_CLAMP_W_SHIFT = 0x7,
SAMPLER_CLAMP_U = 0x20,
SAMPLER_CLAMP_V = 0x40,
SAMPLER_CLAMP_W = 0x80,
SAMPLER_CLAMP_MASK = 0xE0,
SAMPLER_ANISO_SHIFT = 0x8,
SAMPLER_ANISO_1X = 0x0,
SAMPLER_ANISO_2X = 0x100,
SAMPLER_ANISO_4X = 0x200,
SAMPLER_ANISO_6X = 0x300,
SAMPLER_ANISO_8X = 0x400,
SAMPLER_ANISO_10X = 0x500,
SAMPLER_ANISO_12X = 0x600,
SAMPLER_ANISO_16X = 0x700,
SAMPLER_ANISO_MASK = 0x700,
SAMPLER_CONVOLUTION = 0x20000,
SAMPLER_GAMMA = 0x40000,
SAMPLER_UNNORMALIZED_UV = 0x80000,
SAMPLER_DIRECT_FILTER_UNNORMALIZED = 0x80000,
};
struct GfxLightImage struct GfxLightImage
{ {
GfxImage* image; GfxImage* image;

View File

@ -1,6 +1,8 @@
#include "AssetLoaderGfxLightDef.h" #include "AssetLoaderGfxLightDef.h"
#include <cstring> #include <cstring>
#include <iostream>
#include <sstream>
#include "ObjLoading.h" #include "ObjLoading.h"
#include "Game/IW4/IW4.h" #include "Game/IW4/IW4.h"
@ -8,6 +10,15 @@
using namespace IW4; using namespace IW4;
std::string AssetLoaderGfxLightDef::GetAssetFilename(const std::string& assetName)
{
std::ostringstream ss;
ss << "lights/" << assetName;
return ss.str();
}
void* AssetLoaderGfxLightDef::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) void* AssetLoaderGfxLightDef::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory)
{ {
auto* lightDef = memory->Create<GfxLightDef>(); auto* lightDef = memory->Create<GfxLightDef>();
@ -15,3 +26,46 @@ void* AssetLoaderGfxLightDef::CreateEmptyAsset(const std::string& assetName, Mem
lightDef->name = memory->Dup(assetName.c_str()); lightDef->name = memory->Dup(assetName.c_str());
return lightDef; return lightDef;
} }
bool AssetLoaderGfxLightDef::CanLoadFromRaw() const
{
return true;
}
bool AssetLoaderGfxLightDef::LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const
{
const auto filename = GetAssetFilename(assetName);
const auto file = searchPath->Open(filename);
if (!file.IsOpen())
return false;
const auto imageNameSize = file.m_length - sizeof(char) - sizeof(char);
if (imageNameSize < 0 || imageNameSize > MAX_IMAGE_NAME_SIZE)
return false;
std::string imageName(static_cast<size_t>(imageNameSize), '\0');
int8_t samplerState;
int8_t lmapLookupStart;
file.m_stream->read(reinterpret_cast<char*>(&samplerState), sizeof(int8_t));
file.m_stream->read(&imageName[0], static_cast<size_t>(imageNameSize));
file.m_stream->read(reinterpret_cast<char*>(&lmapLookupStart), sizeof(int8_t));
auto* imageDependency = reinterpret_cast<XAssetInfo<GfxImage>*>(manager->LoadDependency(ASSET_TYPE_IMAGE, imageName));
if(!imageDependency)
{
std::cerr << "Could not load GfxLightDef \"" << assetName << "\" due to missing image \"" << imageName << "\"\n";
return false;
}
auto* lightDef = memory->Create<GfxLightDef>();
lightDef->name = memory->Dup(assetName.c_str());
lightDef->attenuation.samplerState = samplerState;
lightDef->attenuation.image = imageDependency->Asset();
lightDef->lmapLookupStart = static_cast<int>(static_cast<uint8_t>(lmapLookupStart));
manager->AddAsset(ASSET_TYPE_LIGHT_DEF, assetName, lightDef);
return true;
}

View File

@ -8,7 +8,13 @@ namespace IW4
{ {
class AssetLoaderGfxLightDef final : public BasicAssetLoader<ASSET_TYPE_LIGHT_DEF, GfxLightDef> class AssetLoaderGfxLightDef final : public BasicAssetLoader<ASSET_TYPE_LIGHT_DEF, GfxLightDef>
{ {
static constexpr auto MAX_IMAGE_NAME_SIZE = 0x800;
static std::string GetAssetFilename(const std::string& assetName);
public: public:
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
_NODISCARD bool CanLoadFromRaw() const override;
bool LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override;
}; };
} }

View File

@ -648,6 +648,9 @@ namespace IW4
std::vector<MenuEventHandler*> elements; std::vector<MenuEventHandler*> elements;
ConvertEventHandlerElements(elements, eventHandlerSet, menu, item); ConvertEventHandlerElements(elements, eventHandlerSet, menu, item);
if (elements.empty())
return nullptr;
auto* outputSet = static_cast<MenuEventHandlerSet*>(m_memory->Alloc(sizeof(MenuEventHandlerSet) + sizeof(void*) * elements.size())); auto* outputSet = static_cast<MenuEventHandlerSet*>(m_memory->Alloc(sizeof(MenuEventHandlerSet) + sizeof(void*) * elements.size()));
auto* outputElements = reinterpret_cast<MenuEventHandler**>(reinterpret_cast<int8_t*>(outputSet) + sizeof(MenuEventHandlerSet)); auto* outputElements = reinterpret_cast<MenuEventHandler**>(reinterpret_cast<int8_t*>(outputSet) + sizeof(MenuEventHandlerSet));
memcpy(outputElements, &elements[0], sizeof(void*) * elements.size()); memcpy(outputElements, &elements[0], sizeof(void*) * elements.size());

View File

@ -0,0 +1,36 @@
#include "AssetDumperGfxLightDef.h"
#include <sstream>
using namespace IW4;
std::string AssetDumperGfxLightDef::GetAssetFilename(const std::string& assetName)
{
std::ostringstream ss;
ss << "lights/" << assetName;
return ss.str();
}
bool AssetDumperGfxLightDef::ShouldDump(XAssetInfo<GfxLightDef>* asset)
{
return true;
}
void AssetDumperGfxLightDef::DumpAsset(AssetDumpingContext& context, XAssetInfo<GfxLightDef>* asset)
{
const auto* lightDef = asset->Asset();
const auto assetFile = context.OpenAssetFile(GetAssetFilename(asset->m_name));
if (!assetFile || lightDef->attenuation.image == nullptr || lightDef->attenuation.image->name == nullptr)
return;
auto& stream = *assetFile;
const auto* imageName = lightDef->attenuation.image->name;
if (imageName[0] == ',')
imageName = &imageName[1];
stream << lightDef->attenuation.samplerState << imageName << static_cast<char>(lightDef->lmapLookupStart);
}

View File

@ -0,0 +1,16 @@
#pragma once
#include "Dumping/AbstractAssetDumper.h"
#include "Game/IW4/IW4.h"
namespace IW4
{
class AssetDumperGfxLightDef final : public AbstractAssetDumper<GfxLightDef>
{
static std::string GetAssetFilename(const std::string& assetName);
protected:
bool ShouldDump(XAssetInfo<GfxLightDef>* asset) override;
void DumpAsset(AssetDumpingContext& context, XAssetInfo<GfxLightDef>* asset) override;
};
}

View File

@ -6,6 +6,7 @@
#include "AssetDumpers/AssetDumperAddonMapEnts.h" #include "AssetDumpers/AssetDumperAddonMapEnts.h"
#include "AssetDumpers/AssetDumperGfxImage.h" #include "AssetDumpers/AssetDumperGfxImage.h"
#include "AssetDumpers/AssetDumperGfxLightDef.h"
#include "AssetDumpers/AssetDumperLoadedSound.h" #include "AssetDumpers/AssetDumperLoadedSound.h"
#include "AssetDumpers/AssetDumperLocalizeEntry.h" #include "AssetDumpers/AssetDumperLocalizeEntry.h"
#include "AssetDumpers/AssetDumperMenuDef.h" #include "AssetDumpers/AssetDumperMenuDef.h"
@ -56,7 +57,7 @@ bool ZoneDumper::DumpZone(AssetDumpingContext& context) const
// DUMP_ASSET_POOL(AssetDumperMapEnts, m_map_ents, ASSET_TYPE_MAP_ENTS) // DUMP_ASSET_POOL(AssetDumperMapEnts, m_map_ents, ASSET_TYPE_MAP_ENTS)
// DUMP_ASSET_POOL(AssetDumperFxWorld, m_fx_world, ASSET_TYPE_FXWORLD) // DUMP_ASSET_POOL(AssetDumperFxWorld, m_fx_world, ASSET_TYPE_FXWORLD)
// DUMP_ASSET_POOL(AssetDumperGfxWorld, m_gfx_world, ASSET_TYPE_GFXWORLD) // DUMP_ASSET_POOL(AssetDumperGfxWorld, m_gfx_world, ASSET_TYPE_GFXWORLD)
// DUMP_ASSET_POOL(AssetDumperGfxLightDef, m_gfx_light_def, ASSET_TYPE_LIGHT_DEF) DUMP_ASSET_POOL(AssetDumperGfxLightDef, m_gfx_light_def, ASSET_TYPE_LIGHT_DEF)
// DUMP_ASSET_POOL(AssetDumperFont_s, m_font, ASSET_TYPE_FONT) // DUMP_ASSET_POOL(AssetDumperFont_s, m_font, ASSET_TYPE_FONT)
DUMP_ASSET_POOL(AssetDumperMenuList, m_menu_list, ASSET_TYPE_MENULIST) DUMP_ASSET_POOL(AssetDumperMenuList, m_menu_list, ASSET_TYPE_MENULIST)
DUMP_ASSET_POOL(AssetDumperMenuDef, m_menu_def, ASSET_TYPE_MENU) DUMP_ASSET_POOL(AssetDumperMenuDef, m_menu_def, ASSET_TYPE_MENU)